/*
════════════════════════════════════════════════════════════════════════════════
FILE    : ui.css
PURPOSE : All styling for the EWA AI Assistant web chat widget (ui.html).
          Extracted verbatim from ui.html's inline <style> block during the
          Sep 2026 restructuring pass (no visual change) so the markup file
          itself stays small and readable. Served as a static asset by
          api_main.py's StaticFiles mount at /static/ui.css.
SECTIONS (in order):
  1. Reset + page background        — full-page gradient behind the widget
  2. Main content area              — static feature-description text
  3. Floating chat widget shell      — fixed-position container, header bar
  4. Scrollable message list        — bubbles, scrollbar, thinking-dots
  5. Text input area + buttons      — textarea, Send/Speak/Call/Mic buttons
  6. LiveKit call UI                — call button states, status bar, mic hint
  7. Choice option buttons          — clickable buttons below assistant bubbles
  8. Status/error messages, spinner, RTL/LTR helpers
  9. Mobile responsive breakpoint + minimize/maximize state
USED BY : ui.html via <link rel="stylesheet" href="/static/ui.css">
════════════════════════════════════════════════════════════════════════════════
*/

        /* ── Reset ─────────────────────────────────────────────────────────── */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* ── Page background ────────────────────────────────────────────────
           The full-page purple gradient is the background canvas.
           The actual chat widget floats on top of it (position: fixed).       */
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            overflow-x: hidden;
        }

        /* ── Main content area (feature description behind the widget) ──────*/
        .main-content {
            width: 100vw;
            height: 100vh;
            color: white;
            padding: 2.5rem;
            overflow-y: auto;
            position: relative;
        }

        .main-content h1 {
            font-size: 3em;
            margin-bottom: 1.25rem;
            text-shadow: 0.125rem 0.125rem 0.25rem rgba(0,0,0,0.3);
        }

        .main-content h2 {
            font-size: 1.5em;
            margin-bottom: 1.875rem;
            opacity: 0.9;
        }

        /* Semi-transparent frosted-glass cards for the feature list */
        .feature-box {
            background: rgba(255,255,255,0.1);
            padding: 1.875rem;
            border-radius: 0.9375rem;
            margin: 1.875rem 0;
            backdrop-filter: blur(0.625rem);
        }

        .feature-box h3 {
            font-size: 2em;
            margin-bottom: 1.25rem;
        }

        .feature-box ul {
            font-size: 1.3em;
            line-height: 1.8;
        }

        .feature-box p {
            font-size: 1.3em;
            line-height: 1.6;
        }

        /* ── Floating chat widget ───────────────────────────────────────────
           Fixed position so it stays in the bottom-right corner regardless
           of how far the user has scrolled the background page.               */
        .floating-chat {
            position: fixed;
            bottom: 1.25rem;
            right: 1.25rem;
            width: 21.875rem;
            height: 35.25rem;
            background: white;
            border-radius: 0.75rem;
            box-shadow: 0 0.625rem 1.875rem rgba(0,0,0,0.3);
            z-index: 9999;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* Blue header bar with the widget title and minimize button */
        .chat-header {
            background: #007AFF;
            color: white;
            padding: 0.75rem;
            font-weight: bold;
            border-radius: 0.75rem 0.75rem 0 0;
            text-align: center;
        }

        /* ── Scrollable message list ────────────────────────────────────────*/
        .chat-messages {
            flex: 1;
            overflow-y: auto;
            background: white;
            padding: 0.5rem;
            min-height: 21rem;
            border: 1px solid #e0e0e0;
            margin: 0 0.5rem;
            border-radius: 0.75rem;
            scroll-behavior: smooth;
            position: relative;
            overscroll-behavior: contain;
            overscroll-behavior-y: contain;
        }

        /* Custom scrollbar styling for WebKit browsers */
        .chat-messages::-webkit-scrollbar {
            width: 0.5rem;
        }

        .chat-messages::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 0.25rem;
        }

        .chat-messages::-webkit-scrollbar-thumb {
            background: #007AFF;
            border-radius: 0.25rem;
        }

        .chat-messages::-webkit-scrollbar-thumb:hover {
            background: #0056b3;
        }

        /* Inner flex column — messages stack from top, newest at bottom */
        .messages-container {
            display: flex;
            flex-direction: column;
            min-height: 100%;
            justify-content: flex-start;
        }

        /* Pushes messages down when there are only a few — keeps them at top */
        .spacer {
            flex-grow: 1;
        }

        /* ── Message bubbles ─────────────────────────────────────────────── */
        .message {
            margin: 0.25rem 0;
            display: flex;
        }

        /* User messages right-aligned; assistant messages left-aligned */
        .message.user {
            justify-content: flex-end;
        }

        .message.assistant {
            justify-content: flex-start;
        }

        .message-bubble {
            max-width: 80%;
            padding: 0.5rem 0.75rem;
            border-radius: 0.75rem;
            font-size: 0.875rem;
            line-height: 1.3;
            word-wrap: break-word;
        }

        /* Blue bubble for user messages, grey for assistant */
        .message-bubble.user {
            background-color: #007AFF;
            color: white;
        }

        .message-bubble.assistant {
            background-color: #f0f0f0;
            color: #333;
        }

        /* Enrollment / identify passage the caller should read aloud */
        .message-bubble .voice-phrase {
            font-weight: 700;
            font-size: 1rem; /* one step up from bubble 0.875rem */
            line-height: 1.4;
        }

        .thinking-dots {
            display: flex;
            gap: 5px;
            align-items: center;
            padding: 12px 16px;
            background-color: #f0f0f0;
            border-radius: 18px;
            width: fit-content;
        }
        .thinking-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: #aaa;
            animation: thinking-bounce 1.4s infinite ease-in-out;
        }
        .thinking-dot:nth-child(1) { animation-delay: 0s; }
        .thinking-dot:nth-child(2) { animation-delay: 0.2s; }
        .thinking-dot:nth-child(3) { animation-delay: 0.4s; }
        @keyframes thinking-bounce {
            0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
            30%            { transform: translateY(-6px); opacity: 1; }
        }

        .welcome-message {
            text-align: center;
            color: #666;
            margin: 1.25rem;
            font-size: 0.875rem;
        }

        /* ── Text input area ────────────────────────────────────────────────*/
        .chat-input-area {
            background: white;
            padding: 0.5rem;
            border-top: 1px solid #e0e0e0;
            border-radius: 0 0 0.75rem 0.75rem;
        }

        /* Auto-resizing textarea — grows up to 100px then scrolls */
        .chat-textbox {
            width: 100%;
            border: 2px solid #ddd;
            border-radius: 0.75rem;
            padding: 0.5rem 0.75rem;
            font-size: 0.875rem;
            resize: none;
            outline: none;
            font-family: inherit;
            max-height: 100px;
        }

        .chat-textbox:focus {
            border-color: #007AFF;
            box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
        }

        /* ── Action buttons ─────────────────────────────────────────────────
           Two buttons in a row: Send | Speak. The Speak button relabels to
           Stop while recording or while the assistant is speaking. */
        .chat-buttons {
            margin-top: 0.5rem;
            display: flex;
            gap: 0.5rem;
            flex-wrap: nowrap;
            align-items: stretch;
        }

        .btn {
            flex: 1;
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 0.5rem;
            font-size: 0.875rem;
            cursor: pointer;
            font-family: inherit;
            transition: background-color 0.2s;
        }

        .send-btn {
            background: #007AFF;
            color: white;
        }

        .send-btn:hover {
            background: #0056b3;
        }

        .send-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
        }

        /* Voice button changes colour to reflect its current state:
           default (green) → listening (red) → processing (yellow) → speaking (green) */
        .voice-btn {
            background: #28a745;
            color: white;
        }

        .voice-btn:hover {
            background: #1e7e34;
        }

        .voice-btn.listening {
            background: #ff6b6b;
        }

        .voice-btn.listening:hover {
            background: #ff5252;
        }

        .voice-btn.processing {
            background: #ffc107;
            color: #000;
        }

        .voice-btn.processing:hover {
            background: #e0a800;
        }

        .voice-btn.speaking {
            background: #28a745;
            color: white;
        }

        .voice-btn.speaking:hover {
            background: #1e7e34;
        }


        /* ── LiveKit call button ───────────────────────────────────────────
           Fixed height + nowrap so Speak / Listening / Wait.. never resize
           the hit target mid-hold (long labels used to wrap and jump). */
        .call-btn {
            background: #007AFF;
            color: white;
            min-height: 2.5rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .call-btn:hover { background: #005ecb; }
        .call-btn.in-call {
            background: #dc3545;
        }
        .call-btn.in-call:hover { background: #b02030; }
        .call-btn.in-call.speaking {
            background: #28a745;
            animation: pulseGreen 1.5s infinite;
        }
        .call-btn.in-call.speaking:hover { background: #1e7e34; }

        /* ── Mic PTT / status button (shown during a LiveKit call) ─────────── */
        .mic-btn { background: #6c757d; color: white; }
        .mic-btn.mic-on  { background: #28a745; animation: pulseGreen 1.5s infinite; }
        .mic-btn.mic-off { background: #6c757d; }
        .mic-btn:disabled { opacity: 1; cursor: default; }

        @keyframes pulse {
            0%   { box-shadow: 0 0 0 0 rgba(220,53,69,.5); }
            70%  { box-shadow: 0 0 0 6px rgba(220,53,69,0); }
            100% { box-shadow: 0 0 0 0 rgba(220,53,69,0); }
        }
        @keyframes pulseGreen {
            0%   { box-shadow: 0 0 0 0 rgba(40,167,69,.5); }
            70%  { box-shadow: 0 0 0 6px rgba(40,167,69,0); }
            100% { box-shadow: 0 0 0 0 rgba(40,167,69,0); }
        }

        /* ── Timing label on agent voice bubble ─────────────────────────── */
        .timing-label {
            display: block;
            margin-top: 4px;
            font-size: 0.70rem;
            opacity: 0.55;
            font-family: monospace;
        }

        /* ── Choice option buttons (rendered below an assistant bubble) ──────
           Shown when USE_BUTTON_FOR_CHOICES=true and the agent presents a
           bounded list of options (branch names, service subtypes, time slots).
           The customer clicks a button instead of typing their selection.       */
        @keyframes optionPopIn {
            from { opacity: 0; transform: scale(0.80) translateY(8px); }
            to   { opacity: 1; transform: scale(1)    translateY(0);   }
        }
        .option-label {
            font-size: 0.72rem;
            font-weight: 600;
            color: #555;
            margin-bottom: 4px;
            letter-spacing: 0.02em;
        }
        .option-buttons {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            padding: 2px 4px 6px 4px;
        }
        .option-btn {
            background: #fff;
            color: #1a1a1a;
            border: 1.5px solid #444;
            border-radius: 6px;
            padding: 5px 12px;
            font-size: 0.78rem;
            cursor: pointer;
            font-family: inherit;
            transition: background 0.15s, border-color 0.15s;
            word-break: break-word;
            animation: optionPopIn 0.22s ease-out both;
        }
        .option-btn:hover {
            background: #f0f0f0;
            border-color: #111;
        }

        /* ── LiveKit call status bar (shown while in call) ───────────────── */
        .call-status-bar {
            display: none;
            align-items: center;
            gap: 6px;
            padding: 5px 12px;
            background: #e8f5e9;
            border-top: 1px solid #c8e6c9;
            font-size: 0.78rem;
            color: #2e7d32;
        }
        .call-status-bar.active { display: flex; }
        .call-dot {
            width: 8px; height: 8px;
            border-radius: 50%;
            background: #28a745;
            animation: pulse 1.5s infinite;
            flex-shrink: 0;
        }

        /* ── Status and error messages ───────────────────────────────────── */
        .status-message {
            text-align: center;
            color: #666;
            font-style: italic;
            margin: 0.5rem;
            font-size: 0.8rem;
        }

        /* ── Spinner animation ───────────────────────────────────────────── */
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid #f3f3f3;
            border-top: 3px solid #007AFF;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* ── RTL / LTR text direction ──────────────────────────────────────
           Applied dynamically by JS from the reply language. unicode-bidi:
           isolate so an Arabic name inside an English greeting cannot
           right-justify the rest of the bubble. */
        .rtl {
            direction: rtl;
            text-align: right;
            unicode-bidi: isolate;
        }

        .ltr {
            direction: ltr;
            text-align: left;
            unicode-bidi: isolate;
        }

        .error-message {
            color: #dc3545;
            text-align: center;
            margin: 0.5rem;
            font-size: 0.8rem;
        }

        /* ── Mobile responsive ─────────────────────────────────────────────
           On small screens the widget expands to fill almost the full screen  */
        @media (max-width: 768px) {
            .main-content {
                padding: 1rem;
            }

            .main-content h1 {
                font-size: 2em;
            }

            .floating-chat {
                width: calc(100vw - 1rem);
                height: calc(100vh - 1rem);
                bottom: 0.5rem;
                right: 0.5rem;
                left: 0.5rem;
            }

            .feature-box {
                padding: 1rem;
                margin: 1rem 0;
            }

            .feature-box h3 {
                font-size: 1.5em;
            }

            .feature-box ul, .feature-box p {
                font-size: 1.1em;
            }
        }

        /* ── Minimize / maximize ───────────────────────────────────────────
           When minimized, only the blue header bar remains visible.           */
        .chat-controls {
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            z-index: 10;
        }

        .control-btn {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            border: none;
            border-radius: 50%;
            width: 2rem;
            height: 2rem;
            cursor: pointer;
            margin-left: 0.25rem;
            font-size: 0.875rem;
        }

        .control-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .floating-chat.minimized {
            height: 3rem;
        }

        /* Hide message list and input when minimized */
        .floating-chat.minimized .chat-messages,
        .floating-chat.minimized .chat-input-area {
            display: none;
        }
