/* ConnectHair Assistant Chat Widget */
/* Modern Minimalist Design - White, Pink, Black */
.cha-widget {
    --cha-primary: #FFC0CB;
    --cha-primary-dark: #FFB0BD;
    --cha-text-dark: #333333;
    --cha-text-light: #666666;
    --cha-bg: #FFFFFF;
    --cha-bg-light: #FAFAFA;
    --cha-border: #F0F0F0;
    --cha-size: 60px;
    
    position: fixed;
    bottom: 25px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.cha-widget.cha-right { right: 25px; }
.cha-widget.cha-left { left: 25px; }

/* Toggle Button */
.cha-toggle {
    width: var(--cha-size);
    height: var(--cha-size);
    border-radius: 50%;
    border: none;
    background: var(--cha-primary);
    color: #333;
    cursor: pointer;
    position: relative;
    z-index: 3;
    box-shadow: 0 4px 24px rgba(255, 192, 203, 0.4);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55), box-shadow 0.3s ease;
}

.cha-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 32px rgba(255, 192, 203, 0.5);
}

.cha-toggle:active {
    transform: scale(0.95);
}

/* Icons */
.cha-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 26px;
    height: 26px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.cha-icon svg {
    width: 100%;
    height: 100%;
    stroke: #333;
}

.cha-icon-close {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-90deg) scale(0.5);
}

.cha-widget.active .cha-icon-chat {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(90deg) scale(0.5);
}

.cha-widget.active .cha-icon-close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0) scale(1);
}

/* Pulse Animation */
.cha-pulse .cha-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--cha-primary);
    z-index: -1;
    animation: cha-pulse-anim 2s ease-out infinite;
}

.cha-widget.active .cha-toggle::before {
    animation: none;
    opacity: 0;
}

@keyframes cha-pulse-anim {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Wobble Animation */
.cha-pulse:not(.active) .cha-toggle {
    animation: cha-wobble 4s ease-in-out infinite;
    animation-delay: 3s;
}

@keyframes cha-wobble {
    0%, 100% { transform: rotate(0deg); }
    2% { transform: rotate(-12deg); }
    4% { transform: rotate(12deg); }
    6% { transform: rotate(-8deg); }
    8% { transform: rotate(8deg); }
    10% { transform: rotate(0deg); }
}

/* Backdrop */
.cha-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1;
}

.cha-widget.active .cha-backdrop {
    opacity: 1;
    visibility: visible;
}

/* Chat Window */
.cha-window {
    position: absolute;
    bottom: calc(var(--cha-size) + 15px);
    width: 380px;
    max-height: 580px;
    background: var(--cha-bg);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--cha-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
}

.cha-widget.cha-right .cha-window { right: 0; }
.cha-widget.cha-left .cha-window { left: 0; }

.cha-widget.active .cha-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.cha-header {
    background: var(--cha-bg);
    color: var(--cha-text-dark);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid var(--cha-border);
}

.cha-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.cha-avatar {
    width: 44px;
    height: 44px;
    background: var(--cha-primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.cha-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cha-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--cha-text-dark);
}

.cha-status {
    font-size: 13px;
    color: var(--cha-text-light);
    display: flex;
    align-items: center;
    gap: 6px;
}

.cha-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ADE80;
    border-radius: 50%;
    display: inline-block;
}

.cha-minimize {
    background: var(--cha-bg-light);
    border: 1px solid var(--cha-border);
    color: var(--cha-text-light);
    cursor: pointer;
    padding: 10px;
    border-radius: 12px;
    transition: all 0.2s;
}

.cha-minimize:hover {
    background: var(--cha-border);
    color: var(--cha-text-dark);
}

.cha-minimize svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Intro Form */
.cha-intro {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 32px 28px;
    background: var(--cha-bg);
}

.cha-intro.hidden {
    display: none !important;
}

.cha-widget:not(.cha-session-active) .cha-messages,
.cha-widget:not(.cha-session-active) .cha-typing,
.cha-widget:not(.cha-session-active) .cha-input-area,
.cha-widget:not(.cha-session-active) .cha-operator-active {
    display: none !important;
}

.cha-widget.cha-session-active .cha-intro {
    display: none !important;
}

.cha-intro-text {
    margin: 0 0 24px 0;
    color: var(--cha-text-light);
    font-size: 15px;
    line-height: 1.6;
    text-align: center;
}

.cha-intro-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cha-intro-form input {
    padding: 14px 18px;
    border: 1px solid var(--cha-border);
    border-radius: 14px;
    font-size: 15px;
    transition: all 0.2s;
    background: var(--cha-bg);
    color: var(--cha-text-dark);
}

.cha-intro-form input:focus {
    outline: none;
    border-color: var(--cha-primary);
    box-shadow: 0 0 0 4px rgba(255, 192, 203, 0.25);
}

.cha-intro-form input::placeholder {
    color: #B0B0B0;
}

.cha-btn {
    background: var(--cha-primary);
    color: var(--cha-text-dark);
    border: none;
    padding: 16px 24px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.cha-btn:hover {
    background: var(--cha-primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 192, 203, 0.4);
}

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

.cha-btn-link {
    background: transparent;
    border: none;
    color: var(--cha-text-light);
    font-size: 14px;
    cursor: pointer;
    padding: 12px;
    transition: color 0.2s;
}

.cha-btn-link:hover {
    color: var(--cha-text-dark);
}

/* Messages */
.cha-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 200px;
    max-height: 350px;
    background: var(--cha-bg-light);
}

.cha-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 20px;
    animation: cha-fade-in 0.3s ease;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
}

@keyframes cha-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cha-message-user {
    background: var(--cha-primary);
    color: var(--cha-text-dark);
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.cha-message-assistant {
    background: var(--cha-bg);
    color: var(--cha-text-dark);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.cha-message-operator {
    background: var(--cha-bg);
    color: var(--cha-text-dark);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding-left: 44px;
    position: relative;
}

.cha-message-operator::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: url('https://www.connecthair.fi/wp-content/themes/connecthair/images/logo_symbol.svg') no-repeat center;
    background-size: contain;
}

/* Typing Indicator */
.cha-typing {
    padding: 0 24px 16px;
    display: none;
    align-items: center;
    gap: 6px;
}

.cha-typing.visible {
    display: flex;
}

.cha-typing span {
    width: 8px;
    height: 8px;
    background: var(--cha-primary);
    border-radius: 50%;
    animation: cha-bounce 1.4s ease-in-out infinite both;
}

.cha-typing span:nth-child(1) { animation-delay: -0.32s; }
.cha-typing span:nth-child(2) { animation-delay: -0.16s; }
.cha-typing span:nth-child(3) { animation-delay: 0s; }

@keyframes cha-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.cha-input-area {
    padding: 20px 24px;
    background: var(--cha-bg);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    border-top: 1px solid var(--cha-border);
}

#cha-input {
    flex: 1;
    border: 1px solid var(--cha-border);
    border-radius: 20px;
    padding: 14px 20px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
    background: var(--cha-bg-light);
    color: var(--cha-text-dark);
    transition: all 0.2s;
}

#cha-input:focus {
    outline: none;
    border-color: var(--cha-primary);
    background: var(--cha-bg);
    box-shadow: 0 0 0 4px rgba(255, 192, 203, 0.2);
}

#cha-input::placeholder {
    color: #B0B0B0;
}

#cha-send {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    border: none;
    background: var(--cha-primary);
    color: var(--cha-text-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#cha-send:hover {
    transform: scale(1.05);
    background: var(--cha-primary-dark);
    box-shadow: 0 6px 20px rgba(255, 192, 203, 0.4);
}

#cha-send:active {
    transform: scale(0.95);
}

#cha-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#cha-send svg {
    width: 20px;
    height: 20px;
}

/* Operator indicator */
.cha-operator-active {
    padding: 12px 20px;
    background: linear-gradient(135deg, rgba(255, 192, 203, 0.15), rgba(255, 192, 203, 0.08));
    color: var(--cha-text-dark);
    font-size: 13px;
    text-align: center;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 1px solid var(--cha-border);
}

/* Notification Badge */
.cha-toggle .cha-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #FF6B6B;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: cha-badge-pulse 2s infinite;
}

@keyframes cha-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Scrollbar */
.cha-messages::-webkit-scrollbar {
    width: 6px;
}

.cha-messages::-webkit-scrollbar-track {
    background: transparent;
}

.cha-messages::-webkit-scrollbar-thumb {
    background: var(--cha-border);
    border-radius: 3px;
}

.cha-messages::-webkit-scrollbar-thumb:hover {
    background: #DDD;
}

/* Mobile */
@media (max-width: 767px) {
    .cha-widget {
        --cha-size: 56px;
        bottom: 16px;
    }
    
    .cha-widget.cha-right { right: 16px; }
    .cha-widget.cha-left { left: 16px; }
    
    .cha-window {
        width: calc(100vw - 32px);
        max-width: 380px;
        max-height: calc(100vh - 100px);
        bottom: calc(var(--cha-size) + 12px);
    }
    
    .cha-icon {
        width: 24px;
        height: 24px;
    }
    
    .cha-messages {
        max-height: calc(100vh - 320px);
    }
    
    .cha-header {
        padding: 16px 20px;
    }
    
    .cha-intro {
        padding: 24px 20px;
    }
    
    .cha-input-area {
        padding: 16px 20px;
    }
}

@media (max-width: 380px) {
    .cha-widget {
        --cha-size: 52px;
        bottom: 12px;
    }
    
    .cha-widget.cha-right { right: 12px; }
    .cha-widget.cha-left { left: 12px; }
}

@media (min-width: 1400px) {
    .cha-widget {
        --cha-size: 64px;
        bottom: 32px;
    }
    
    .cha-widget.cha-right { right: 32px; }
    .cha-widget.cha-left { left: 32px; }
    
    .cha-icon {
        width: 28px;
        height: 28px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .cha-toggle,
    .cha-icon,
    .cha-window,
    .cha-message,
    .cha-backdrop {
        transition-duration: 0.01ms !important;
    }
    
    .cha-pulse .cha-toggle::before,
    .cha-pulse:not(.active) .cha-toggle {
        animation: none !important;
    }
}
