/* Contact Chat Widget Pro Styles */

/* CSS Variables for theming - These will be overridden by theme settings */
:root {
    --ccw-primary: #007cba;
    --ccw-secondary: #005a87;
    --ccw-text: #2c3e50;
    --ccw-background: #ffffff;
    --ccw-border: #e1e5e9;
    --ccw-success: #4caf50;
    --ccw-error: #f44336;
    --ccw-accent-color: #007cba;
    --ccw-font-family: inherit;
}

/* Floating Button */
.ccw-widget {
    position: fixed;
    z-index: 9999;
    font-family: var(--ccw-font-family, inherit);
}

.ccw-button {
    min-width: 60px;
    min-height: 60px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    background: var(--ccw-primary, #007cba);
    color: white;
    padding: 8px 12px;
    gap: 8px;
}

.ccw-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    background: var(--ccw-secondary, #005a87);
}

.ccw-button-text {
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    display: block;
    white-space: nowrap;
    margin: 0;
}

.ccw-button-icon {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.ccw-close-icon {
    color: white;
    font-size: 24px;
    font-weight: bold;
    display: none;
}

/* Button States */
.ccw-widget.ccw-open .ccw-button-text {
    display: block;
}

.ccw-widget.ccw-open .ccw-close-icon {
    display: block;
}

.ccw-widget.ccw-open .ccw-button {
    width: auto;
    height: auto;
    min-width: 200px;
    min-height: 50px;
    border-radius: 25px;
    padding: 12px 20px;
}

/* Position Classes */
.ccw-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.ccw-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.ccw-position-top-right {
    top: 20px;
    right: 20px;
}

.ccw-position-top-left {
    top: 20px;
    left: 20px;
}

/* Popup */
.ccw-popup {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    max-width: 90vw;
    background: var(--ccw-background, #ffffff);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    color: var(--ccw-text, #2c3e50);
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    border: 1px solid var(--ccw-border, #e1e5e9);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    overflow-y: auto;
}

.ccw-widget.ccw-open .ccw-popup {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Position adjustments for popup */
.ccw-position-bottom-left .ccw-popup {
    right: auto;
    left: 0;
}

.ccw-position-top-right .ccw-popup {
    bottom: auto;
    top: 80px;
}

.ccw-position-top-left .ccw-popup {
    bottom: auto;
    top: 80px;
    right: auto;
    left: 0;
}

/* Popup Header */
.ccw-popup-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--ccw-border, #e1e5e9);
    margin-bottom: 0;
    position: relative;
}

.ccw-popup-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--ccw-text, #2c3e50);
    flex: 1;
    text-align: center;
}

.ccw-close-popup {
    background: none;
    border: none;
    font-size: 24px;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.ccw-close-popup:hover {
    background-color: #f8f9fa;
    color: var(--ccw-text, #2c3e50);
}

/* Form */
.ccw-form {
    padding: 0 20px 20px 20px;
    flex: 1; /* Take available space */
    display: flex;
    flex-direction: column;
}

.ccw-form-group {
    margin-bottom: 16px;
}

.ccw-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ccw-text, #2c3e50);
}

.ccw-form-group input,
.ccw-form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.ccw-form-group input:focus,
.ccw-form-group textarea:focus {
    outline: none !important;
    border-color: var(--ccw-accent-color, #007cba) !important;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1) !important;
}

.ccw-form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.ccw-submit-btn {
    width: 100%;
    padding: 14px;
    background-color: var(--ccw-primary, #007cba) !important;
    color: white !important;
    border: none !important;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: auto; /* Push to bottom */
}

.ccw-submit-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.ccw-submit-btn:active {
    transform: translateY(0);
}

.ccw-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Message Area */
.ccw-message-area {
    padding: 0 20px 20px 20px;
    margin-top: 16px;
}

.ccw-message {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.ccw-message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.ccw-message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Loading State */
.ccw-loading {
    position: relative;
    pointer-events: none;
}

.ccw-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #ffffff;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: ccw-spin 1s linear infinite;
}

@keyframes ccw-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .ccw-popup {
        width: 320px;
        right: 10px;
        max-height: 70vh;
    }
    
    .ccw-position-bottom-left .ccw-popup {
        right: auto;
        left: 10px;
    }
    
    .ccw-position-top-right .ccw-popup {
        right: 10px;
    }
    
    .ccw-position-top-left .ccw-popup {
        right: auto;
        left: 10px;
    }
    
    /* Widget button margin for mobile */
    .ccw-position-bottom-right,
    .ccw-position-top-right {
        right: 12px;
    }
    
    .ccw-position-bottom-left,
    .ccw-position-top-left {
        left: 12px;
    }
    
    .ccw-position-bottom-right,
    .ccw-position-bottom-left {
        bottom: 15px;
    }
    
    .ccw-widget.ccw-open .ccw-button {
        min-width: 180px;
    }
}

@media (max-width: 480px) {
    .ccw-popup {
        width: 280px;
        right: 8px;
        max-height: 65vh;
    }
    
    .ccw-position-bottom-left .ccw-popup {
        right: auto;
        left: 8px;
    }
    
    .ccw-position-top-right .ccw-popup {
        right: 8px;
    }
    
    .ccw-position-top-left .ccw-popup {
        right: auto;
        left: 8px;
    }
    
    /* Widget button margin for small mobile */
    .ccw-position-bottom-right,
    .ccw-position-top-right {
        right: 10px;
    }
    
    .ccw-position-bottom-left,
    .ccw-position-top-left {
        left: 10px;
    }
    
    .ccw-position-bottom-right,
    .ccw-position-bottom-left {
        bottom: 12px;
    }
    
    .ccw-button {
        min-width: 50px;
        min-height: 50px;
        padding: 6px 10px;
    }
    
    .ccw-button-text {
        font-size: 12px;
    }
    
    .ccw-button-icon {
        font-size: 18px;
    }
    
    .ccw-logo img {
        max-width: 60px;
        max-height: 60px;
    }
    
    .ccw-contact-options {
        padding: 8px 12px;
    }
    
    .ccw-contact-buttons {
        gap: 6px;
    }
    
    .ccw-contact-btn {
        padding: 6px 4px;
        gap: 4px;
    }
    
    .ccw-contact-icon {
        font-size: 14px;
    }
    
    .ccw-contact-label {
        font-size: 9px;
    }
    
    .ccw-widget.ccw-open .ccw-button {
        min-width: 160px;
        min-height: 45px;
    }
}

/* Animation for button icon */

/* Chat-style Interface */
.ccw-chat-container {
    display: flex;
    flex-direction: column;
    background: var(--ccw-background-color);
    flex: 1; /* Take available space */
    overflow: hidden;
}

.ccw-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 300px;
}

.ccw-chat-message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    animation: ccw-message-slide-in 0.3s ease-out;
}

.ccw-chat-message.bot {
    justify-content: flex-start;
}

.ccw-chat-message.user {
    justify-content: flex-end;
}

.ccw-message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.ccw-message-bubble.bot {
    background: #f1f3f4;
    color: var(--ccw-text-color);
    border-bottom-left-radius: 4px;
}

.ccw-message-bubble.user {
    background: var(--ccw-accent-color) !important;
    color: white !important;
    border-bottom-right-radius: 4px;
}

.ccw-message-choices {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.ccw-choice-btn {
    background: white !important;
    border: 2px solid var(--ccw-accent-color) !important;
    color: var(--ccw-accent-color) !important;
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    text-align: left;
}

.ccw-choice-btn:hover {
    background: var(--ccw-accent-color) !important;
    color: white !important;
    transform: translateY(-1px);
}

.ccw-chat-input {
    padding: 16px 20px;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 8px;
    align-items: center;
}

.ccw-chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ccw-chat-input input:focus {
    border-color: var(--ccw-accent-color) !important;
}

.ccw-send-btn {
    background: var(--ccw-accent-color) !important;
    color: white !important;
    border: none !important;
    padding: 12px 16px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    transition: all 0.2s ease;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ccw-send-icon {
    font-size: 18px;
    line-height: 1;
}

.ccw-send-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Contact Options */
.ccw-contact-options {
    padding: 12px 16px;
    border-top: 1px solid var(--ccw-border, #e1e5e9);
    background: #f8f9fa;
    margin-top: auto; /* Push to bottom */
    flex-shrink: 0; /* Don't shrink */
}

.ccw-contact-options h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    color: var(--ccw-text-color);
    text-align: center;
}

.ccw-contact-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ccw-contact-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 6px;
    background: white !important;
    border: 2px solid #e1e5e9 !important;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--ccw-text-color) !important;
}

.ccw-contact-btn:hover {
    border-color: var(--ccw-accent-color) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ccw-contact-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.ccw-contact-label {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
}

/* Ribbon positions */
.ccw-position-right-ribbon .ccw-button {
    width: 50px;
    height: 200px;
    border-radius: 0 8px 8px 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    display: flex;
    align-items: center;
    justify-content: center;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.ccw-position-left-ribbon .ccw-button {
    width: 50px;
    height: 200px;
    border-radius: 8px 0 0 8px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    display: flex;
    align-items: center;
    justify-content: center;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.ccw-position-right-ribbon .ccw-popup {
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    bottom: auto;
}

.ccw-position-left-ribbon .ccw-popup {
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    bottom: auto;
    right: auto;
}

/* Logo styling */
.ccw-logo {
    margin: 0;
    flex-shrink: 0;
}

.ccw-logo img {
    max-width: 80px;
    max-height: 80px;
    width: auto;
    height: auto;
    border-radius: 8px;
    object-fit: contain;
}

/* Typing indicator */
.ccw-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #f1f3f4;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 60px;
}

.ccw-typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: ccw-typing 1.4s infinite ease-in-out;
}

.ccw-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ccw-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

/* Animations */
@keyframes ccw-message-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ccw-typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile optimizations for chat */
@media (max-width: 768px) {
    
    .ccw-chat-messages {
        padding: 16px;
    }
    
    .ccw-message-bubble {
        max-width: 90%;
        font-size: 13px;
    }
    
    .ccw-contact-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .ccw-position-right-ribbon .ccw-button,
    .ccw-position-left-ribbon .ccw-button {
        height: 150px;
        width: 40px;
    }
}

/* Perinteiset popup-tyypit */
.ccw-popup-type-auto_open .ccw-popup,
.ccw-popup-type-scroll_trigger .ccw-popup,
.ccw-popup-type-selector_trigger .ccw-popup,
.ccw-popup-type-exit_intent .ccw-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10000;
    width: 400px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

.ccw-popup-type-auto_open.ccw-open .ccw-popup,
.ccw-popup-type-scroll_trigger.ccw-open .ccw-popup,
.ccw-popup-type-selector_trigger.ccw-open .ccw-popup,
.ccw-popup-type-exit_intent.ccw-open .ccw-popup {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* Overlay for perinteiset popupit */
.ccw-popup-type-auto_open.ccw-open::before,
.ccw-popup-type-scroll_trigger.ccw-open::before,
.ccw-popup-type-selector_trigger.ccw-open::before,
.ccw-popup-type-exit_intent.ccw-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    animation: ccw-fade-in 0.3s ease;
}

@keyframes ccw-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Perinteiset popupit eivät näytä floating buttonia */
.ccw-popup-type-auto_open .ccw-button,
.ccw-popup-type-scroll_trigger .ccw-button,
.ccw-popup-type-selector_trigger .ccw-button,
.ccw-popup-type-exit_intent .ccw-button {
    display: none;
}

/* Mobile optimizations for perinteiset popupit */
@media (max-width: 768px) {
    .ccw-popup-type-auto_open .ccw-popup,
    .ccw-popup-type-scroll_trigger .ccw-popup,
    .ccw-popup-type-selector_trigger .ccw-popup,
    .ccw-popup-type-exit_intent .ccw-popup {
        width: 95vw;
        max-height: 80vh;
        margin: 20px;
    }
}

@media (max-width: 480px) {
    .ccw-popup-type-auto_open .ccw-popup,
    .ccw-popup-type-scroll_trigger .ccw-popup,
    .ccw-popup-type-selector_trigger .ccw-popup,
    .ccw-popup-type-exit_intent .ccw-popup {
        width: 95vw;
        max-height: 75vh;
        margin: 10px;
    }
}

/* Smooth transitions */
* {
    box-sizing: border-box;
}

.ccw-widget * {
    box-sizing: border-box;
}
