/* chat.css - Professional Styles with Animations - v1.14 */
/* Floating Button & Shockwave */
#chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4285f4, #34a853);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(66, 133, 244, 0.3);
    z-index: 9997;
    font-size: 24px;
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: float 3s ease-in-out infinite;
}
#chatbot-toggle .shockwave {
    position: absolute;
    border-radius: 50%;
    width: 100%;
    height: 100%;
    background: inherit;
    animation: shockwave 2s infinite;
    opacity: 0.5;
    z-index: -1;
}
#chatbot-toggle:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 35px rgba(66, 133, 244, 0.4);
}
#chatbot-toggle.active .shockwave {
    animation: none;
}
/* Unread Badge */
#unread-badge {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    z-index: 9998;
    animation: pulse 2s infinite;
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.3);
    transition: all 0.3s ease;
}
#unread-badge:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 16px rgba(255, 71, 87, 0.4);
}
#unread-badge::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    right: 0;
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 10002;
    margin-bottom: 5px;
}
#unread-badge:hover::after {
    opacity: 1;
    visibility: visible;
}
/* Chat Window - Desktop */
#chatbot-window {
    position: fixed;
    bottom: -600px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
    transition: bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(66, 133, 244, 0.1);
    visibility: hidden;
    height: 0;
}
#chatbot-window.open {
    bottom: 100px;
    visibility: visible !important;
    height: 600px !important;
}
/* === NEW MOBILE LAYOUT START (Replaces old @media query) === */
@media (max-width: 768px) {
    /* 1. Base window (closed) - starts off-screen */
    #chatbot-window {
        position: fixed !important;
        visibility: hidden !important;
        width: 100dvw !important;
        height: 100dvh !important; /* Use 100vh for the 'closed' state */
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        display: flex;
        flex-direction: column;
        /* Use transform for slide animation */
        transform: translateY(100vh);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9998;
    }
    /* 2. Open state - Let JS handle exact height for keyboard */
    #chatbot-window.open {
        visibility: visible !important;
        height: auto !important;  /* CHANGED: From 100dvh to auto; JS sets precise px */
        min-height: 100dvh !important;  /* Fallback for no JS */
        transform: translateY(0);
        bottom: 0 !important; /* Lock to bottom */
    }
    /* 3. Sticky Header (NEW: Pins to top on resize/scroll) */
    #chat-header {
        position: sticky !important;  /* NEW: Make it sticky */
        top: 0 !important;
        z-index: 10 !important;
        background: white !important;
        border-bottom: 1px solid #ddd !important;  /* Ensure border stays visible */
        flex-shrink: 0; /* Prevents header from shrinking */
        /* Add slight shadow for depth when scrolling messages */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    /* 4. Scrolling Message Area (Fills space and scrolls) */
    #chat-messages {
        flex: 1; /* FIX: This makes it fill all available space */
        overflow-y: auto; /* FIX: This makes *only* the message area scroll */
        padding-bottom: 16px; /* Add space at the bottom */
        /*
         * FIX: Stop scroll chaining
         * This stops the 'scroll leak' to the main page.
        */
        overscroll-behavior: contain;
        /* NEW: Prevent any bleed on resize */
        will-change: transform;
    }
   
    /* 5. Stable Input Container (Not fixed, just a flex item) */
    #chat-input-container {
        position: relative !important; /* No longer fixed */
        bottom: 0;
        z-index: 20;
        background: white;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px) + 4px);  /* CHANGED: +4px buffer */
        border-top: 1px solid #ddd;
        flex-shrink: 0; /* Prevents input from shrinking */
    }
}
/* === NEW MOBILE LAYOUT END === */
/* Header - User's Exact CSS, Light Border */
#chat-header {
    background: white;
    border-bottom: 1px solid #ddd;
    color: #000;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 16px;
}
#chat-header > div {
    display: flex;
    flex-direction: column;
    gap: 0;
}
#chat-header span:first-child {
    font-size: 16px;
    color: #000;
}
#chat-header .status {
    font-size: 11px !important;
    color: #4caf50 !important;
    opacity: 0.9;
}
#bot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(0, 0, 0, 0.1);
}
.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #000;
    font-size: 18px;
}
#close-chat {
    margin-left: auto;
    cursor: pointer;
    font-size: 20px;
    color: #666;
    opacity: 0.8;
    transition: opacity 0.2s;
}
#close-chat:hover {
    opacity: 1;
    color: #000;
}
/* Messages - Instructions Panel, White Background */
#chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: white !important;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#instructions-panel {
    background: rgba(66, 133, 244, 0.1);
    border-left: 4px solid #4285f4;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
}
#instructions-panel ul {
    margin: 0;
    padding-left: 18px;
    color: #333;
    font-size: 13px;
    line-height: 1.4;
}
#instructions-panel li {
    margin-bottom: 4px;
}
/* Typing Indicator */
.typing {
    display: flex !important;
    align-items: flex-start;
    gap: 8px;
    margin-left: 0;
    margin-right: auto;
}
.typing .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}
.typing .text {
    background: #fff3e0 !important;
    border-radius: 18px;
    padding: 10px 14px;
    color: black;
    font-style: italic;
    font-size: 14px;
    line-height: 1.4;
    white-space: nowrap;
}
.typing-dots-text::after {
    content: '';
    animation: typing-dots 1.5s steps(4) infinite;
}
@keyframes typing-dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}
/* Messages */
.message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    margin-left: 0;
    margin-right: auto;
}
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-left: auto;
    margin-right: 0;
}
.message.visible {
    opacity: 1;
    transform: translateY(0);
}
.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 24px;
    overflow: hidden;
}
.message.user .avatar {
    font-size: 24px;
}
.message.bot .avatar img {
    display: block !important;
    object-fit: cover !important;
    object-position: center !important;
    mask: radial-gradient(circle, black 100%, transparent 0);
    -webkit-mask: radial-gradient(circle, black 100%, transparent 0);
    clip-path: circle(50% at 50% 50%);
    width: 100% !important;
    height: 100% !important;
}
.message .text {
    max-width: 280px;
    padding: 10px 14px;
    border-radius: 18px;
    background: transparent !important;
    border: none !important;
    color: #000;
    line-height: 1.4;
    font-size: 14px;
    word-wrap: break-word;
    box-shadow: none !important;
    line-height: 1.5;
    text-align: left !important;
}
.message.user .text {
    background: #f5f5ff !important; /* Changed to f5f5ff for a subtle blue tint */
}
.message.bot .text {
    background: #fff3e0 !important;
}
.message.error .text {
    background: #ffebee !important;
}
.message .text a {
    color: #4285f4;
    text-decoration: none;
}
.message .text a:hover {
    text-decoration: underline;
}
.message .text strong {
    font-weight: bold;
}
.message .text em {
    font-style: italic;
}
/* Input */
#chat-input-container {
    padding: 16px;
    border-top: 1px solid #ddd;
    background: white;
    display: flex;
    gap: 0;
    align-items: center;
}
#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: none !important;
    border-radius: 0;
    font-size: 14px;
    outline: none;
    transition: none;
    color: #000;
    background: white;
    height: 100%;
    box-sizing: border-box;
}
#chat-input:focus {
    background: white;
}
#send-message {
    padding: 12px;
    background: transparent !important;
    color: #ff9800 !important;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.3s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    transform: translateX(100%);
    opacity: 0;
}
#send-message svg {
    width: 16px;
    height: 16px;
}
#send-message:hover {
    transform: translateX(0) scale(1.05);
    opacity: 1;
}
/* Animations */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}
@keyframes shockwave {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}