/* Modern Chat Widget - Professional & Elegant Design */
/* Restored with original color scheme */
:root {
    --chat-primary: #706d9c;
    --chat-primary-dark: #5a577d;
    --chat-secondary: #926ecc;
    --chat-bg: #f4f7f9;
    --chat-surface: #ffffff;
    --user-msg-bg: #926ecc;
    --ai-msg-bg: #f1f1f1;
    --agent-msg-bg: #e3f2fd;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px rgba(0,0,0,0.1);
}

#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* Prevent horizontal overflow on small screens by ensuring the container
       doesn't exceed the viewport width (minus some padding). */
    max-width: calc(100% - 40px);
}

/* Chat Bubble - Modern floating action button */
#chat-bubble {
    width: 60px;
    height: 60px;
    background-color: var(--chat-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: all 0.3s ease-in-out;
}

#chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

#chat-bubble svg {
    width: 32px;
    height: 32px;
}

/* Chat Window - Modern card design */
#chat-window {
    width: 100%;
    max-width: 350px; /* Use max-width for responsiveness */
    /* Allow the window to shrink on viewports narrower than 350px */
    max-height: 600px; /* Increased for better viewing on modern devices */
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease-in-out;
}

#chat-window.hidden {
    display: none;
}

/* Chat Header - Clean and modern */
#chat-header {
    background: var(--chat-primary);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Make the entire header a clickable area to close the chat */
    cursor: pointer;
}

#chat-header h3 {
    margin: 0;
    font-size: 1.1em;
    font-weight: 600;
    /* Allow clicks to pass through the title to the header below,
       expanding the clickable close area. */
    pointer-events: none;
    /* Prevent accidental text selection on the title when closing. */
    user-select: none;
}

#close-chat {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

#close-chat:hover {
    background: rgba(255, 255, 255, 0.2);
}

#close-chat:active {
    transform: scale(0.95);
}

#close-chat svg {
    width: 24px;
    height: 24px;
}

/* Messages Container - Clean scrollable area */
#chat-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: var(--chat-bg);
    /* Fix for flexbox overflow. This ensures that the message
       container shrinks correctly and becomes scrollable on its own, 
       preventing the entire chat window from scrolling on mobile. */
    min-height: 0;
}

/* Custom Scrollbar */
#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.1); border-radius: 3px; }
#chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.2); }

/* Message Bubbles - Modern design */
.message {
    padding: 10px 15px;
    border-radius: 18px;
    margin-bottom: 10px;
    max-width: 80%;
    line-height: 1.4;
    animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user, .message.user-message {
    background-color: var(--user-msg-bg);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    margin-left: auto;
}

.message.ai, .message.ai-message {
    background-color: white;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.message.agent-message {
    background: var(--agent-msg-bg);
    border: 1px solid #2196f3;
    align-self: flex-start;
}

.message.agent-message small {
    display: block;
    font-size: 0.75em;
    color: #2196f3;
    margin-bottom: 4px;
}

.message.system-message {
    text-align: center;
    font-style: italic;
    color: #666;
    font-size: 0.9em;
    margin: 5px 0;
}

/* START: UPDATED INPUT STYLES */

#chat-input-container {
    padding: 10px;
    border-top: 1px solid #ddd;
}

#chat-form {
    display: flex;
    align-items: center;
}

/* Wrapper for input and upload button */
#chat-input-wrapper {
    flex-grow: 1;
    display: flex;
    align-items: center;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding-left: 15px;
    transition: all 0.2s;
}

#chat-input-wrapper:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(112, 109, 156, 0.1);
}

/* The actual text input field */
#chat-input {
    flex-grow: 1;
    border: none;
    padding: 10px 0;
    font-size: 1em;
    background: transparent;
    /* No cursor or background-image properties needed anymore */
}

#chat-input:focus {
    outline: none;
}

/* The new upload button */
#upload-btn {
    background: transparent;
    border: none;
    padding: 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
}

#upload-btn svg {
    width: 24px;
    height: 24px;
}

/* END: UPDATED INPUT STYLES */


.file-selected-container {
    display: flex;
    align-items: center;
    background-color: #f1f1f1;
    border-radius: 20px;
    padding: 5px 10px;
    margin-bottom: 5px;
}

.file-name {
    flex-grow: 1;
    font-size: 0.9em;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clear-file-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 5px;
}

/* Send Button - Modern design */
#send-btn {
    background: var(--chat-primary);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#send-btn:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

#send-btn svg {
    width: 24px;
    height: 24px;
}

/* Typing Indicator - Modern animation */
#typing-indicator {
    padding: 0 10px 5px;
}

#typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: #999;
    border-radius: 50%;
    display: inline-block;
    animation: bob 1.4s infinite ease-in-out both;
}

#typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
#typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
#typing-indicator span:nth-child(3) { animation-delay: -0.16s; }

@keyframes bob {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Hidden utility class */
.hidden {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    #chat-widget-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
    
    #chat-window {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    
    #chat-bubble {
        bottom: 10px;
        right: 10px;
        position: fixed;
        width: 56px;
        height: 56px;
    }
    
    #chat-bubble svg {
        width: 28px;
        height: 28px;
    }

    #chat-header {
        padding: 12px 15px;
    }

    #chat-header h3 {
        font-size: 1em;
    }

    #close-chat {
        width: 40px;
        height: 40px;
        background: rgba(0, 0, 0, 0.15);
    }

    #close-chat:hover {
        background: rgba(0, 0, 0, 0.25);
    }

    #chat-messages {
        padding: 10px;
    }

    .message {
        padding: 8px 12px;
        font-size: 0.95em;
        max-width: 85%; /* Allow slightly wider messages */
    }

    #chat-input-container {
        padding: 8px;
    }

    #chat-input {
        padding: 8px 0;
        font-size: 0.95em;
    }

    #send-btn {
        width: 38px;
        height: 38px;
        margin-left: 6px; /* Reduce margin on mobile for better spacing */
    }
}

/* Smooth hover effects for interactive elements */
button, input, .message {
    transition: all 0.2s ease;
}

/* Focus styles for accessibility */
button:focus-visible, input:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

/* In chat.css - REPLACE the original @media (max-width: 480px) block */
@media (max-width: 480px) {
    /* 
     *  CORRECTION: The container no longer needs to be full-screen.
     *  This was creating an invisible layer that blocked all clicks.
     *  The #chat-bubble and #chat-window are positioned relative to the viewport anyway.
     */
    #chat-widget-container {
        /* The container itself remains in the corner, but does not expand. */
    }
    
    /* Make the chat window itself full-screen when it's open */
    #chat-window {
        position: fixed; /* Ensure it's fixed */
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    
    /* The bubble remains a fixed-position button */
    #chat-bubble {
        position: fixed;
        bottom: 15px;
        right: 15px;
        width: 56px;
        height: 56px;
    }
    
    #chat-bubble svg {
        width: 28px;
        height: 28px;
    }

    #chat-header {
        padding: 12px 15px;
    }

    #chat-header h3 {
        font-size: 1em;
    }
    
    /* Note: The old #close-chat styles seem to have been removed. 
       Let's ensure it's visible and works on mobile. */
    #close-chat {
        width: 40px;
        height: 40px;
    }
    
    #close-chat:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    #chat-messages {
        padding: 10px;
    }

    .message {
        padding: 8px 12px;
        font-size: 0.95em;
        max-width: 85%; /* Allow slightly wider messages */
    }

    #chat-input-container {
        padding: 8px;
    }

    #chat-input {
        padding: 8px 0;
        font-size: 0.95em;
    }

    #send-btn {
        width: 38px;
        height: 38px;
        margin-left: 6px; /* Reduce margin on mobile for better spacing */
    }
}