:root {
            /* Light Mode (Default) - Ochre & Earth Theme */
            --widget-bg-color: #FFFFFF;
            --header-gradient-start: #a98b57; /* Darker Ochre */
            --header-gradient-end: #d4ba8a; /* Golden Ochre */
            --header-text-color: #3D3526; /* Dark Brown for contrast */
            --online-indicator-color: #6A994E; /* Earthy Green */
            --message-area-bg: #FFFFFF;
            --assistant-bubble-bg: #F8F5EE; /* Warm Off-white */
            --assistant-text-color: #050505;
            --user-bubble-bg: #d4ba8a; /* Golden Ochre */
            --user-text-color: #3D3526; /* Dark Brown for contrast */
            --quick-reply-border: #d4ba8a;
            --quick-reply-text: #a98b57;
            --quick-reply-bg: #FFFFFF;
            --quick-reply-bg-hover: #F8F5EE;
            --quick-reply-bg-active: #d4ba8a;
            --quick-reply-text-active: #3D3526;
            --input-placeholder-color: #9E9382; /* Muted Warm Gray */
            --input-text-color: #212529;
            --input-area-border-color: #E8E2D7; /* Warm Gray */
            --send-button-gradient-start: #a98b57;
            --send-button-gradient-end: #d4ba8a;
            --icon-color: #6F6350; /* Muted Brown/Gray */
            --widget-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
            --widget-border-radius: 20px;
            --dropdown-bg: #FFFFFF;
            --dropdown-shadow: 0 4px 12px rgba(0,0,0,0.1);
            --dropdown-item-hover-bg: #F8F5EE;
            --dropdown-text-color: #212529;
            --code-bg: #E8E2D7;
            --code-text: #212529;
            --link-color: #a98b57;
            --body-bg: #F5F1E9; /* Warm Off-white */
            --dark-mode-toggle-bg: #F8F5EE;
            --dark-mode-toggle-icon: #6F6350;
            --dark-mode-toggle-bg-hover: #E8E2D7;
        }

        html[data-theme="dark"] {
            /* Dark Mode Overrides - Sepia & Ochre Theme */
            --widget-bg-color: #2A251E; /* Dark Sepia */
            --header-gradient-start: #a98b57;
            --header-gradient-end: #c4a877;
            --header-text-color: #F5F1E9; /* Light Cream */
            /* --online-indicator-color: #6A994E; // Stays the same from light */
            --message-area-bg: #2A251E;
            --assistant-bubble-bg: #383228; /* Lighter Dark Brown */
            --assistant-text-color: #EAE3D9; /* Light Cream */
            --user-bubble-bg: #a98b57;
            --user-text-color: #F5F1E9; /* Light Cream */
            --quick-reply-border: #d4ba8a;
            --quick-reply-text: #d4ba8a;
            --quick-reply-bg: #383228;
            --quick-reply-bg-hover: #4A4236;
            --quick-reply-bg-active: #d4ba8a;
            --quick-reply-text-active: #3D3526;
            --input-placeholder-color: #A19582; /* Muted Cream */
            --input-text-color: #EAE3D9;
            --input-area-border-color: #4A4236;
            --send-button-gradient-start: #a98b57;
            --send-button-gradient-end: #c4a877;
            --icon-color: #BDB2A2; /* Muted Cream */
            --widget-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
            /* --widget-border-radius: 20px; // Stays the same */
            --dropdown-bg: #383228;
            --dropdown-shadow: 0 4px 12px rgba(0,0,0,0.25);
            --dropdown-item-hover-bg: #4A4236;
            --dropdown-text-color: #EAE3D9;
            --code-bg: #383228;
            --code-text: #EAE3D9;
            --link-color: #e9d8b4; /* Lighter Ochre for visibility */
            --body-bg: #1A1610; /* Very Dark Sepia */
            --dark-mode-toggle-bg: #383228;
            --dark-mode-toggle-icon: #BDB2A2;
            --dark-mode-toggle-bg-hover: #4A4236;
        }


        @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

        html, body {
            height: 100%;
            margin: 0;
        }

        body {
            font-family: 'Roboto', Arial, sans-serif;
            background-color: var(--body-bg);
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 0;
            box-sizing: border-box;
            transition: background-color 0.3s ease;
        }

        .chat-widget {
            width: 700px;
            height: 800px;
            max-height: 90vh;
            background-color: var(--widget-bg-color);
            border-radius: var(--widget-border-radius);
            box-shadow: var(--widget-shadow);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
            transition: background-color 0.3s ease, box-shadow 0.3s ease;
        }

        .widget-header {
            background: linear-gradient(135deg, var(--header-gradient-start), var(--header-gradient-end));
            color: var(--header-text-color);
            padding: 20px 25px;
            display: flex;
            flex-direction: column;
            position: relative;
            border-top-left-radius: var(--widget-border-radius);
            border-top-right-radius: var(--widget-border-radius);
            z-index: 10;
            padding-bottom: 45px;
            transition: background 0.3s ease;
        }

        .widget-header::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30px;
            background-color: var(--message-area-bg);
            border-top-left-radius: 50% 20px;
            border-top-right-radius: 50% 20px;
            transform: translateY(1px);
            transition: background-color 0.3s ease;
        }


        .header-main-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: relative;
            z-index: 1;
        }

        .header-avatar-title {
            display: flex;
            align-items: center;
        }

        .header-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #FFF; /* Kept light for contrast */
            margin-right: 15px;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
            border: 2px solid rgba(255,255,255,0.5);
        }
        .header-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .header-title {
            font-size: 1.25rem;
            font-weight: 500;
            color: var(--header-text-color); /* Explicitly set */
        }

        .header-actions {
            display: flex;
            align-items: center;
            position: relative;
        }
        .header-actions .icon-button {
            background: none;
            border: none;
            color: var(--header-text-color);
            padding: 7px;
            margin-left: 12px;
            cursor: pointer;
            opacity: 0.9;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
        }
        .header-actions .icon-button:hover {
            opacity: 1;
            background-color: rgba(255,255,255,0.1);
        }
        .header-actions .icon-button svg {
            width: 24px;
            height: 24px;
            fill: currentColor;
        }
        /* Dark Mode Toggle Button Specific Styles */
        #darkModeToggle {
            margin-left: 0; /* Adjust as it's the first in its group now */
            padding: 8px;
            background-color: var(--dark-mode-toggle-bg);
            border-radius: 50%;
            color: var(--dark-mode-toggle-icon);
            transition: background-color 0.2s ease, color 0.2s ease;
        }
        #darkModeToggle:hover {
            background-color: var(--dark-mode-toggle-bg-hover);
        }


/* New styles for the recognition status indicator */
        .header-status-row {
            margin-top: 10px;
            display: flex;
            align-items: center;
            justify-content: center; /* Center the text */
            font-size: 0.85rem;
            opacity: 0; /* Hidden by default */
            max-height: 0; /* Hidden by default */
            overflow: hidden;
            transition: opacity 0.4s ease, max-height 0.4s ease, margin-top 0.4s ease;
            color: var(--header-text-color);
            position: relative;
            z-index: 1;
            padding: 0 15px; /* Add some padding */
            border-radius: 12px;
            background-color: rgba(255, 255, 255, 0.15); /* Subtle background */
        }

        .header-status-row.active {
            opacity: 1;
            max-height: 40px; /* Animate height */
            margin-top: 15px; /* Add space when visible */
            padding: 6px 15px; /* Animate padding */
        }
        
        .header-status-row .icon {
            margin-right: 8px;
            font-size: 1rem;
        }

        .online-indicator {
            width: 10px;
            height: 10px;
            background-color: var(--online-indicator-color);
            border-radius: 50%;
            margin-right: 8px;
            box-shadow: 0 0 6px var(--online-indicator-color);
        }

        .dropdown-menu {
            display: none;
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            background-color: var(--dropdown-bg);
            border-radius: 8px;
            box-shadow: var(--dropdown-shadow);
            padding: 8px 0;
            z-index: 100;
            min-width: 190px;
            list-style: none;
            margin: 0;
            transition: background-color 0.3s ease, box-shadow 0.3s ease;
        }
        .dropdown-menu.active { display: block; }
        .dropdown-menu li {
            padding: 10px 18px;
            font-size: 0.95rem;
            color: var(--dropdown-text-color);
            cursor: pointer;
            display: flex;
            align-items: center;
            transition: background-color 0.2s ease, color 0.3s ease;
        }
        .dropdown-menu li:hover { background-color: var(--dropdown-item-hover-bg); }
        .dropdown-menu li .flag-icon {
            width: 22px;
            height: 22px; /* Task #2: Make height same as width for circle */
            margin-right: 12px;
            border: 1px solid #DDD; /* Keep subtle border */
            border-radius: 50%; /* Task #2: Circular flags */
            object-fit: cover; /* Ensure flag content fits well in circle */
            flex-shrink: 0;
        }


        .chat-messages-container {
            flex-grow: 1;
            background-color: var(--message-area-bg);
            padding: 20px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 18px;
            scroll-behavior: smooth;
            position: relative;
            z-index: 1;
            transition: background-color 0.3s ease;
        }
        .chat-messages-container::-webkit-scrollbar { display: none; }
        .chat-messages-container { -ms-overflow-style: none; scrollbar-width: none; }

        .message-wrapper { display: flex; flex-direction: column; max-width: 85%; }
        .message-bubble {
            margin-top: 0;
            padding: 12px 18px;
            border-radius: 18px;
            font-size: 0.95rem;
            line-height: 1.5;
            word-wrap: break-word;
            transition: background-color 0.3s ease, color 0.3s ease;
        }
        .assistant-message { align-self: flex-start; }
        .assistant-message .message-bubble {
            background-color: var(--assistant-bubble-bg);
            color: var(--assistant-text-color);
            border-bottom-left-radius: 6px;
        }
        .user-message { align-self: flex-end; }
        .user-message .message-bubble {
            background-color: var(--user-bubble-bg);
            color: var(--user-text-color);
            border-bottom-right-radius: 6px;
        }
        .message-bubble p:last-child { margin-bottom: 0; }
        .message-bubble ul, .message-bubble ol { padding-left: 20px; margin: 0.5em 0; }
        .message-bubble li { margin-bottom: 0.25em; }
        .message-bubble a { color: var(--link-color); text-decoration: underline; transition: color 0.3s ease; }
        .message-bubble code {
            background-color: var(--code-bg); color: var(--code-text);
            padding: 0.2em 0.4em; border-radius: 4px; font-size: 0.9em;
            font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
            transition: background-color 0.3s ease, color 0.3s ease;
        }
        .message-bubble pre {
            background-color: var(--code-bg); color: var(--code-text);
            padding: 0.8em; border-radius: 6px; overflow-x: auto; margin: 0.5em 0;
            font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
            font-size: 0.9em;
            transition: background-color 0.3s ease, color 0.3s ease;
        }
        .message-bubble pre code { background-color: transparent; padding: 0; }
        .message-bubble h1, .message-bubble h2, .message-bubble h3 { margin-top: 0.8em; margin-bottom: 0.4em; line-height: 1.3; }
        .message-animation { animation: fadeIn 0.3s ease-out; }
        @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

        .widget-input-area {
            background-color: var(--widget-bg-color);
            padding: 15px 20px;
            border-top: 1px solid var(--input-area-border-color);
            display: flex;
            align-items: center;
            gap: 12px;
            position: relative;
            z-index: 5;
            border-bottom-left-radius: var(--widget-border-radius);
            border-bottom-right-radius: var(--widget-border-radius);
            transition: background-color 0.3s ease, border-top-color 0.3s ease;
        }
        .widget-input-area .icon-button { background: none; border: none; padding: 8px; cursor: pointer; color: var(--icon-color); display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: color 0.3s ease; }
        .widget-input-area .icon-button:hover svg { fill: var(--send-button-gradient-start); }
        .widget-input-area .icon-button svg { width: 24px; height: 24px; fill: currentColor; transition: fill 0.2s ease-in-out; }
        .widget-input-area input[type="text"] {
            flex-grow: 1; border: none; outline: none; background-color: transparent;
            font-size: 1rem; color: var(--input-text-color); padding: 10px 0;
            font-family: 'Roboto', Arial, sans-serif;
            transition: color 0.3s ease;
        }
        .widget-input-area input[type="text"]::placeholder { color: var(--input-placeholder-color); font-weight: 400; transition: color 0.3s ease; }
        .send-button {
            width: 44px; height: 44px; border-radius: 50%;
            background: linear-gradient(135deg, var(--send-button-gradient-start), var(--send-button-gradient-end));
            color: white; border: none; cursor: pointer; display: flex; align-items: center;
            justify-content: center; flex-shrink: 0;
            box-shadow: 0 3px 8px rgba(169, 139, 87, 0.4);
            transition: transform 0.1s ease-out, box-shadow 0.1s ease-out, background 0.3s ease;
        }
        .send-button:hover { box-shadow: 0 4px 12px rgba(169, 139, 87, 0.5); }
        .send-button:active { transform: scale(0.95); box-shadow: 0 2px 5px rgba(169, 139, 87, 0.3); }
        .send-button svg { width: 20px; height: 20px; fill: currentColor; }
        .speech-status { display: none; }

        @media (max-width: 600px) {
            body { padding: 0; align-items: flex-start; }
            .chat-widget { width: 100%; height: 100%; max-height: 100%; border-radius: 0; box-shadow: none; }
            .widget-header, .widget-input-area { border-radius: 0; }
            .widget-header::after { border-top-left-radius: 30% 20px; border-top-right-radius: 30% 20px; }
            .header-title { font-size: 1.1rem; }
            .header-avatar { width: 40px; height: 40px; margin-right: 12px;}
            .widget-header { padding: 15px 18px 40px 18px; }
            .header-actions .icon-button svg { width: 22px; height: 22px; }
            .chat-messages-container { padding: 15px; gap: 12px; }
            .message-bubble { padding: 10px 15px; font-size: 0.9rem; }
            .widget-input-area { padding: 12px 15px; gap: 10px;}
            .widget-input-area input[type="text"] { font-size: 0.95rem; }
            .widget-input-area .icon-button svg { width: 22px; height: 22px; }
            .send-button { width: 40px; height: 40px; }
            .send-button svg { width: 18px; height: 18px; }
        }
        @media (min-width: 601px) and (max-width: 900px) {
            .chat-widget { width: 450px; height: 70vh; max-height: 650px; }
            .header-title { font-size: 1.15rem; }
            .widget-header { padding-bottom: 40px; }
        }

        /* Typing Indicator dots */
        .message-wrapper .typing-dot {
            width: 8px;
            height: 8px;
            margin: 0 3px;
            background-color: var(--assistant-text-color); /* Uses the text color variable, which adapts to light/dark mode */
            border-radius: 50%;
            display: inline-block;
            animation: pulse 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 pulse {
            0%, 100% { opacity: 1; transform: scale(1); }
            50% { opacity: 0.5; transform: scale(0.75); }
        }

        .mic-button.mic-active svg {
            fill: var(--accent-color, #a98b57); /* Use a color from the new palette */
        }

        .speech-status {
            font-size: 0.75rem;
            color: var(--text-secondary-color);
            text-align: center;
            padding-top: 4px; /* Adjust as needed */
            min-height: 1.2em;
            visibility: hidden; /* Initially hidden, controlled by JS */
        }

        /* Additional UI Components */
        .message-bubble {
            display: flex;
            align-items: flex-start;
        }

        .message-text-content {
            flex-grow: 1;
            word-break: break-word;
        }

        .tts-stop-icon {
            width: 16px;
            height: 16px;
            fill: currentColor;
            margin-left: 8px;
            cursor: pointer;
            opacity: 0.6;
            flex-shrink: 0;
            transition: opacity 0.2s ease;
        }

        .tts-stop-icon:hover {
            opacity: 1;
        }

        /* Modal Overlay */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.6);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }

        .modal-overlay.hidden {
            display: none;
        }

        .modal-content {
            background: var(--widget-bg-color);
            color: var(--assistant-text-color);
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
            max-width: 450px;
            width: 90%;
            text-align: center;
            z-index: 1001;
            transition: background-color 0.3s ease, color 0.3s ease;
        }

        .modal-content h2 {
            margin-top: 0;
            margin-bottom: 15px;
            color: var(--header-gradient-start); /* Uses ochre color */
        }

        .modal-content p {
            margin-bottom: 25px;
            line-height: 1.6;
            font-size: 0.95rem;
        }

        .modal-content button {
            padding: 12px 25px;
            border: none;
            border-radius: 5px;
            background: linear-gradient(135deg, var(--send-button-gradient-start), var(--send-button-gradient-end));
            color: var(--header-text-color);
            cursor: pointer;
            font-size: 1rem;
            font-weight: 500;
            transition: background 0.2s ease, transform 0.1s ease;
        }

        .modal-content button:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(169, 139, 87, 0.3);
        }

        .modal-content button:active {
            transform: translateY(0);
        }

        /* Performance optimizations */
        .message-wrapper {
            will-change: transform;
            contain: layout style paint;
        }

        /* Optimistic UI */
        .optimistic {
            opacity: 1;
            transition: opacity 0.2s;
        }

        .optimistic.confirmed {
            opacity: 1;
        }

        /* Status Indicator */
        .status-indicator {
            position: fixed;
            bottom: 80px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 8px 16px;
            border-radius: 20px;
            font-size: 0.85rem;
            z-index: 999;
            pointer-events: none;
        }

        .status-indicator.hidden {
            display: none;
        }

    /* --- START: Speech Recognition Visualizer Styles --- */

    .widget-input-area {
        /* Ensure the parent has a position context for the absolute overlay */
        position: relative;
    }

    #speechRecognitionOverlay {
        position: absolute;
        top: 1px; /* Align with border */
        left: 60px; /* Space for mic button */
        right: 20px; /* Space from the edge */
        bottom: 1px;
        background-color: var(--background-color); /* Koristi boju pozadine teme */
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        z-index: 6; /* Must be above the input field */

        /* Hidden by default */
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease-in-out, background-color 0.3s ease;
    }

    #speechRecognitionText {
        font-size: 0.95rem;
        color: var(--input-placeholder-color);
        transition: color 0.3s ease;
    }

    #speechVisualizer {
        width: 100%; /* Neka zauzme celu širinu overlay-a */
        height: 30px; /* ili koja god visina vam odgovara */
    }

    /* State when recording is active */
    .widget-input-area.recording #userInput {
        /* Hide the original input field */
        opacity: 0;
        pointer-events: none;
    }

    .widget-input-area.recording #speechRecognitionOverlay {
        /* Show the overlay */
        opacity: 1;
        pointer-events: all;
    }

    /* Optional: Add a subtle pulse to the mic button while recording */
    .widget-input-area.recording #micButton svg {
        animation: micPulse 1.5s infinite ease-in-out;
    }

    @keyframes micPulse {
        0% { transform: scale(1); }
        50% { transform: scale(1.1); }
        100% { transform: scale(1); }
    }

    @media (max-width: 600px) {
        #speechRecognitionOverlay {
            left: 55px; /* Adjust for smaller mic button */
            right: 15px;
        }
    }

    /* --- END: Speech Recognition Visualizer Styles --- */

