/* Chat Widget Styles - Premium Design */
:root {
    --chat-primary: #2FA56C;
    --chat-primary-dark: #1E7A4D;
    --chat-gradient: linear-gradient(135deg, #2FA56C 0%, #1E7A4D 100%);
    --chat-bg: #FFFFFF;
    --chat-text: #2D2D2D;
    --chat-gray: #F0F2F5;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --z-chat: 9999;
}

/* Floating Action Button */
.chat-fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: var(--chat-gradient);
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(47, 165, 108, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: var(--z-chat);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    outline: none;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(47, 165, 108, 0.5);
}

.chat-fab svg {
    width: 32px;
    height: 32px;
    fill: white;
    transition: transform 0.3s ease;
}

.chat-fab.active svg {
    transform: rotate(90deg);
}

.chat-fab .notification-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    background: #FF4444;
    border: 2px solid white;
    border-radius: 50%;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

/* Chat Window */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: 20px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--z-chat);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.chat-header {
    background: var(--chat-gradient);
    padding: 20px;
    color: white;
    position: relative;
    flex-shrink: 0;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.agent-avatar {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--chat-primary);
    position: relative;
}

.agent-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #2ECC71;
    border: 2px solid white;
    border-radius: 50%;
}

.chat-info h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-info p {
    margin: 2px 0 0 0;
    font-size: 13px;
    opacity: 1;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

/* Menu View */
.chat-menu {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    background: var(--chat-gray);
}

.menu-item {
    background: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    color: var(--chat-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.menu-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    color: var(--chat-primary);
}

.menu-item i {
    font-size: 18px;
    color: var(--chat-primary);
}

/* Conversation View */
.chat-conversation {
    flex: 1;
    display: none;
    /* Hidden by default */
    flex-direction: column;
    height: 100%;
    min-height: 0;
    /* Important for flex scrolling */
    overflow: hidden;
}

.chat-conversation.active {
    display: flex;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #F9F9F9;
    min-height: 0;
    /* Key for flex-grow scrolling */
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: messageSlide 0.3s ease forwards;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    background: white;
    color: var(--chat-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message.user {
    background: var(--chat-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.typing-indicator {
    padding: 12px 16px;
    background: white;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    display: none;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #CCC;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

/* Queue Screen */
.chat-queue {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    background: white;
    display: none;
    /* Hidden by default */
}

.queue-loader {
    width: 50px;
    height: 50px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--chat-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.queue-text h3 {
    margin: 0 0 10px 0;
    color: var(--chat-text);
}

.queue-text p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Input Area - Fixed at Bottom */
.chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    /* Never shrink - always visible */
    position: relative;
    z-index: 10;
}

.chat-input {
    flex: 1;
    border: 1px solid #E0E0E0;
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--chat-primary);
}

.chat-send {
    width: 48px;
    height: 48px;
    background: var(--chat-gradient);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(47, 165, 108, 0.3);
}

.chat-send svg {
    width: 22px;
    height: 22px;
    fill: white;
}

.chat-send:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(47, 165, 108, 0.4);
}

.chat-send:disabled {
    background: #E0E0E0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Mobile Responsive Premium Redesign */
@media (max-width: 480px) {

    /* Backdrop Overlay */
    .chat-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        touch-action: none;
        /* Prevent scroll on backdrop touch */
        -webkit-overflow-scrolling: touch;
    }

    .chat-backdrop.active {
        opacity: 1;
        visibility: visible;
    }

    /* Bottom Sheet Window */
    .chat-window {
        width: 100%;
        height: 70vh !important;
        max-height: 70vh;
        bottom: 0;
        right: 0;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
        z-index: 9999;
        transform: translateY(110%);
        transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
        border: none;
    }

    .chat-window.open {
        transform: translateY(0);
    }

    .chat-header {
        border-radius: 24px 24px 0 0;
        padding: 20px;
        background: var(--chat-gradient);
    }

    /* Floating Close Button - Highly Visible */
    .close-chat {
        position: absolute;
        top: -60px;
        /* Above the window */
        right: 20px;
        background: white;
        color: #333;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        border: none;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
        opacity: 0;
        transform: translateY(20px);
        transition: all 0.3s ease 0.1s;
        z-index: 10000;
        pointer-events: all;
    }

    .chat-window.open .close-chat {
        opacity: 1;
        transform: translateY(0);
    }

    /* Hide the default header close button on mobile if needed, 
       but we are reusing the same ID. We just moved it via CSS. */

    .chat-fab {
        bottom: 20px;
        right: 20px;
    }
}