/* ================================================================
   MIZAN – Chat UI Stylesheet
   ================================================================
   File:    static/css/chat.css
   Themes:
     :root / [data-theme="dark"]   →  dark background
     [data-theme="light"]          →  light background

   Accent colours (admin-controlled via UI_ACCENT setting):
     [data-accent="blue"]  (default) — primary   #126dec
     [data-accent="teal"]            — backup     #0ea882

   CSS variable groups:
     Background · Containers · Sidebar · Text ·
     Accent · Messages · Borders · Input · Glow ·
     Status · Scrollbar · Misc. semantic
   ================================================================ */


/* ── 1. THEME VARIABLES ───────────────────────────────────────── */

/* ── 1a. Dark mode background (default) ── */
:root,
[data-theme="dark"] {

  /* ── Background ── */
  --bg-base:              #0f172a;
  --bg-gradient:          none;

  /* ── Containers ── */
  --container-bg:         rgba(18, 25, 40, 0.18);
  --header-bg:            rgba(18, 25, 40, 0.30);
  --bg-modal:             rgba(12, 18, 32, 0.96);
  --bg-input:             rgba(20, 28, 44, 0.58);
  --input-bg:             rgba(20, 28, 44, 0.58);
  --msg-bot-bg:           rgba(16, 24, 38, 0.62);
  --sidebar-bg:           rgba(12, 18, 30, 0.95);
  --sidebar-icons-bg:     rgba(20, 28, 44, 0.80);
  --sidebar-section-bg:   rgba(16, 24, 38, 0.90);
  --code-bg:              rgba(8, 14, 24, 0.90);

  /* ── Text ── */
  --text-primary:         #edf5f4;
  --text-secondary:       #8a9db0;
  --text-muted:           #5a6a78;
  --text-light:           #f0f6f5;

  /* ── Borders (neutral — accent overrides border-accent below) ── */
  --border-primary:       rgba(180, 160, 130, 0.12);

  /* ── Accent — BLUE default ── */
  --accent-primary:       #126dec;
  --accent-primary-hover: #0d5dbf;
  --accent-primary-rgb:   18, 109, 236;
  --accent-dark:          #0848a0;
  --heading-accent:       #5aadff;
  --title-gradient:       linear-gradient(135deg, #5aadff 0%, #126dec 100%);

  /* ── Interactive elements (blue-on-dark) ── */
  --user-msg-bg:          rgba(18, 80, 190, 0.35);
  --user-msg-border:      rgba(18, 109, 236, 0.30);
  --sources-bg:           rgba(10, 50, 130, 0.55);
  --chip-bg:              rgba(18, 80, 180, 0.30);
  --chip-color:           #7dc0ff;
  --menu-btn-bg:          rgba(18, 109, 236, 0.22);
  --menu-btn-hover-bg:    rgba(18, 109, 236, 0.40);

  /* ── Borders (accent-dependent) ── */
  --border-accent:        rgba(18, 109, 236, 0.25);

  /* ── Input ── */
  --input-border:         rgba(18, 109, 236, 0.20);
  --input-focus-border:   rgba(18, 109, 236, 0.60);
  --input-focus-glow:     0 0 0 3px rgba(18, 109, 236, 0.15);

  /* ── Glow / canvas ── */
  --glow-rgb:             18, 109, 236;
  --container-glow-rgb:   18, 109, 236;
  --bottom-glow-rgb:      18, 109, 236;
  --pc-dark-rgb:          40, 80, 160;
  --pc-mid-rgb:           18, 109, 236;

  /* ── Status ── */
  --error-text:           #e05555;
  --error-bg:             rgba(80, 20, 20, 0.8);
  --success-text:         #4a9e6e;
  --success-bg:           rgba(20, 60, 35, 0.8);

  /* ── Scrollbar ── */
  --scrollbar-thumb:      rgba(18, 109, 236, 0.25);
  --scrollbar-hover:      rgba(18, 109, 236, 0.45);

  /* ── Send button (semantic red — fixed in both themes) ── */
  --send-btn-bg:          #b7472a;
  --send-btn-hover:       #c95235;

  /* ── Feedback button hover ── */
  --feedback-hover-bg:    rgba(255, 255, 255, 0.07);
}

/* ── 1b. Light mode: background overrides + light-specific blue interaction vars ── */
[data-theme="light"] {

  /* ── Background ── */
  --bg-base:              #fcf4e9;
  --bg-gradient:          linear-gradient(180deg, #fcf4e9 0%, #ddeaff 100%);

  /* ── Containers ── */
  --container-bg:         rgba(255, 255, 255, 0.15);
  --header-bg:            rgba(255, 255, 255, 0.18);
  --bg-modal:             rgba(250, 247, 242, 0.97);
  --bg-input:             rgba(248, 244, 239, 0.92);
  --input-bg:             rgba(255, 252, 248, 0.55);
  --msg-bot-bg:           rgba(255, 255, 255, 0.18);
  --sidebar-bg:           rgba(248, 244, 238, 0.88);
  --sidebar-icons-bg:     rgba(232, 222, 208, 0.80);
  --sidebar-section-bg:   rgba(240, 236, 230, 0.90);
  --code-bg:              rgba(20, 30, 50, 0.88);

  /* ── Text ── */
  --text-primary:         #1f1813;
  --text-secondary:       #6b6560;
  --text-muted:           #9a9390;
  --text-light:           #2a231a;

  /* ── Borders ── */
  --border-primary:       rgba(18, 109, 236, 0.10);

  /* ── Status ── */
  --error-text:           #c84545;
  --error-bg:             rgba(245, 230, 230, 0.80);
  --success-text:         #1a7f5a;
  --success-bg:           rgba(230, 245, 240, 0.85);

  /* ── Feedback button hover ── */
  --feedback-hover-bg:    rgba(0, 0, 0, 0.06);

  /* ── Interactive elements: blue-on-light overrides ── */
  --heading-accent:       #126dec;
  --user-msg-bg:          rgba(180, 215, 255, 0.18);
  --user-msg-border:      rgba(18, 109, 236, 0.25);
  --sources-bg:           rgba(180, 215, 255, 0.28);
  --chip-bg:              rgba(255, 255, 255, 0.88);
  --chip-color:           #126dec;
  --menu-btn-bg:          rgba(18, 109, 236, 0.12);
  --menu-btn-hover-bg:    rgba(18, 109, 236, 0.25);
  --input-border:         rgba(18, 109, 236, 0.35);
  --input-focus-border:   rgba(18, 109, 236, 0.75);
  --input-focus-glow:     0 0 0 3px rgba(18, 109, 236, 0.18);
  --border-accent:        rgba(18, 109, 236, 0.28);
  --scrollbar-thumb:      rgba(18, 109, 236, 0.25);
  --scrollbar-hover:      rgba(18, 109, 236, 0.45);
}

/* ── 1c. Teal accent overrides (admin-controlled, works in both themes) ── */
[data-accent="teal"] {
  --accent-primary:       #0ea882;
  --accent-primary-hover: #13c49c;
  --accent-primary-rgb:   14, 168, 130;
  --accent-dark:          #0a7262;
  --glow-rgb:             30, 160, 140;
  --container-glow-rgb:   30, 160, 140;
  --bottom-glow-rgb:      30, 160, 140;
  --pc-dark-rgb:          20, 70, 50;
  --pc-mid-rgb:           30, 160, 140;
  --scrollbar-thumb:      rgba(30, 160, 140, 0.25);
  --scrollbar-hover:      rgba(30, 160, 140, 0.45);
  --border-accent:        rgba(14, 168, 130, 0.25);
  --input-border:         rgba(14, 168, 130, 0.18);
  --input-focus-border:   rgba(14, 168, 130, 0.55);
  --input-focus-glow:     0 0 0 3px rgba(14, 168, 130, 0.15);
}

/* Teal-on-dark specific (heading and interaction colours) */
[data-theme="dark"][data-accent="teal"] {
  --heading-accent:       #1ed8b0;
  --title-gradient:       linear-gradient(135deg, #1ed8b0 0%, #0ea882 100%);
  --user-msg-bg:          rgba(30, 110, 100, 0.45);
  --user-msg-border:      rgba(14, 168, 130, 0.25);
  --sources-bg:           rgba(18, 60, 56, 0.60);
  --chip-bg:              rgba(22, 80, 76, 0.50);
  --chip-color:           #5ad4b8;
  --menu-btn-bg:          rgba(30, 160, 140, 0.35);
  --menu-btn-hover-bg:    rgba(30, 160, 140, 0.55);
  --border-primary:       rgba(180, 160, 130, 0.12);
}

/* Teal-on-light specific */
[data-theme="light"][data-accent="teal"] {
  --heading-accent:       #0a8c6e;
  --title-gradient:       linear-gradient(135deg, #1ed8b0 0%, #0ea882 100%);
  --user-msg-bg:          rgba(14, 168, 130, 0.12);
  --user-msg-border:      rgba(14, 168, 130, 0.25);
  --sources-bg:           rgba(14, 168, 130, 0.18);
  --chip-bg:              rgba(255, 255, 255, 0.88);
  --chip-color:           #0a8c6e;
  --menu-btn-bg:          rgba(14, 168, 130, 0.12);
  --menu-btn-hover-bg:    rgba(14, 168, 130, 0.25);
  --border-accent:        rgba(14, 168, 130, 0.30);
  --border-primary:       rgba(14, 168, 130, 0.10);
}



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


/* ── 3. BACKGROUND ELEMENTS ───────────────────────────────────── */

#circuit-bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
}

#bg-bottom-glow {
    /*
     * Bottom-edge atmospheric glow — shown only for themes with bottomGlow set.
     * Tuning:
     *   W% (200%) — horizontal spread: 200% = extends beyond viewport width
     *   H% (130%) — vertical reach
     *   X% (50%)  — centred horizontally
     *   Y% (100%) — pinned to bottom edge
     * Color stops use --bottom-glow-rgb (set by JS from theme object).
     */
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(
        ellipse 200% 130% at 50% 100%,
        rgba(var(--bottom-glow-rgb, 30,160,140), 0.55) 0%,
        rgba(var(--bottom-glow-rgb, 30,160,140), 0.09) 50%,
        transparent 100%
    );
}


/* ── 4. BODY & LAYOUT ─────────────────────────────────────────── */

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-base, #0f172a);
    background-image: var(--bg-gradient, none);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.7;
    margin: 0;
    padding: 0;
    color: var(--text-primary);
}

.container {
    display: flex;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}


/* ── 5. SIDEBAR ───────────────────────────────────────────────── */

.sidebar {
    width: 54px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0;
    box-shadow: 2px 0 20px rgba(0,0,0,0.40);
    overflow-y: visible;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100vh;
    z-index: 100;
    border-right: 1px solid var(--border-primary);
}

.sidebar-icons-top {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 12px;
}

.sidebar-icons-bottom {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.sidebar-icon {
    width: 36px;
    height: 36px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    background: transparent;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    box-shadow: none;
    color: var(--text-secondary);
}

.sidebar-icon:hover,
.sidebar-icon.active {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(var(--accent-primary-rgb), 0.15);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 18px;
    border-bottom: 2px solid var(--border-primary);
}

.sidebar-logo {
    height: 44px;
    width: auto;
    object-fit: contain;
}

.sidebar-section {
    background: var(--sidebar-section-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 14px;
    padding: 20px 18px;
    border: 1px solid var(--border-primary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.30), 0 0 12px rgba(var(--pc-mid-rgb), 0.08);
}

.sidebar-section h3 {
    color: var(--accent-primary);
    font-size: 14px;
    margin-bottom: 12px;
    font-weight: 700;
}

.stat-number {
    font-size: 26px;
    font-weight: bold;
    color: var(--accent-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 7px;
}

.topic-group { margin-bottom: 6px; }

.topic-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(var(--accent-primary-rgb), 0.12);
    font-size: 13px;
    font-weight: 600;
    color: var(--heading-accent);
    user-select: none;
}

.topic-header:hover {
    background: rgba(var(--accent-primary-rgb), 0.22);
}

.topic-arrow { font-size: 10px; transition: transform 0.2s; display: inline-block; }
.topic-header.open .topic-arrow { transform: rotate(180deg); }
.topic-docs { display: none; padding: 4px 0 4px 8px; }
.topic-docs.open { display: block; }

.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 4px;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.doc-item:last-child { border-bottom: none; }
.doc-name { flex: 1; padding-left: 8px; line-height: 1.4; }
.doc-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; padding-right: 2px; }

.docs-search {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 8px;
    margin-bottom: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-accent);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    direction: rtl;
}

.docs-search::placeholder { color: var(--text-muted); }
.docs-search:focus { border-color: var(--accent-primary); }


/* ── 6. CHAT CONTAINER ────────────────────────────────────────── */

.chat-container {
    width: 60vw;
    min-width: 320px;
    max-width: 800px;
    background: var(--container-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    padding: 0 0 8px 0;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    border: 1px solid var(--border-accent);
    transition: box-shadow 0.4s ease, border-color 0.4s ease, backdrop-filter 0.4s ease;
    min-height: 0;
    max-height: calc(100vh - 40px);
    overflow: hidden;
    margin: 20px 0;
}

.chat-header {
    padding: 16px 24px;
    margin-bottom: 0;
    border-bottom: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-radius: 20px 20px 0 0;
}

.header-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
    display: block;
}

#mainChat {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

#mainChat[style*="flex"] {
    display: flex !important;
}


/* ── 7. CHAT MESSAGES ─────────────────────────────────────────── */

.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 20px 8px 20px;
    margin-bottom: 12px;
    border: none;
    border-radius: 0;
    background: transparent;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

/* Webkit scrollbar */
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 10px;
    margin: 5px 0;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    border: none;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}
/* Firefox */
.chat-messages {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Sidebar mobile tab scrollbar — thin, themed, appears only on overflow */
.sidebar-mobile-content .info-tab-content::-webkit-scrollbar { width: 4px; }
.sidebar-mobile-content .info-tab-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-mobile-content .info-tab-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
.sidebar-mobile-content .info-tab-content::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

.message {
    margin-bottom: 8px;
    padding: 14px 18px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.user-message {
    background: var(--user-msg-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-primary);
    border-left: none;
    margin-left: auto;
    width: fit-content;
    max-width: 75%;
    border-radius: 20px 20px 20px 6px;
    border: 1px solid var(--user-msg-border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.35), 0 0 20px rgba(var(--accent-primary-rgb), 0.12);
}

.bot-message {
    background: var(--msg-bot-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-left: none;
    margin-left: auto;
    max-width: 92%;
    border-radius: 20px 20px 6px 20px;
    border: 1px solid var(--border-primary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.35), 0 0 24px rgba(var(--pc-mid-rgb), 0.08);
    white-space: normal;
}

.bot-message p { margin-top: 0; margin-bottom: 10px; }
.bot-message > *:last-child { margin-bottom: 0; }
.bot-message ul, .bot-message ol { margin: 10px 0; padding-right: 20px; }
.bot-message li { margin-bottom: 5px; }
.bot-message br { display: block; margin: 5px 0; content: ""; }

/* Markdown headings */
.bot-message h1, .bot-message h2, .bot-message h3,
.bot-message h4, .bot-message h5, .bot-message h6 {
    color: var(--heading-accent);
    font-weight: 600;
    margin-top: 16px;
    margin-bottom: 12px;
    line-height: 1.3;
}
.bot-message h1 { font-size: 1.8em; }
.bot-message h2 { font-size: 1.5em; }
.bot-message h3 { font-size: 1.25em; }
.bot-message h4 { font-size: 1.1em; }
.bot-message h5 { font-size: 1em; font-weight: 700; }
.bot-message h6 { font-size: 0.95em; font-weight: 700; }
.bot-message h1:first-child, .bot-message h2:first-child,
.bot-message h3:first-child, .bot-message h4:first-child { margin-top: 0; }

.bot-message strong { font-weight: 700; color: var(--heading-accent); }
.bot-message em { font-style: italic; color: var(--text-secondary); }

.bot-message ul ul, .bot-message ol ul,
.bot-message ul ol, .bot-message ol ol { margin-top: 5px; margin-bottom: 5px; padding-right: 20px; }
.bot-message li p { margin-bottom: 5px; }

.bot-message code {
    background: var(--code-bg);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}
.bot-message pre {
    background: var(--code-bg);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}
.bot-message pre code { background: none; padding: 0; }

.bot-message blockquote {
    border-right: 3px solid var(--accent-dark);
    margin: 10px 0;
    padding: 10px 15px;
    background: var(--code-bg);
    font-style: italic;
}

.bot-message hr {
    border: none;
    border-top: 2px solid var(--border-primary);
    margin: 20px 0;
}

.system-message {
    background: rgba(50, 45, 25, 0.80);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(180, 160, 60, 0.30);
    border-radius: 10px !important;
    font-style: italic;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    max-width: 80%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.stage-message {
    background: var(--msg-bot-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.22);
    border-radius: 12px !important;
    text-align: right;
    font-style: normal;
    color: var(--text-secondary);
    margin-left: auto;
    max-width: 85%;
    box-shadow: 0 3px 12px rgba(0,0,0,0.15), 0 0 16px rgba(var(--accent-primary-rgb), 0.08);
    animation: progressPulse 1s ease-in-out infinite;
}

.stage-message strong {
    color: var(--heading-accent);
    font-weight: 600;
}

/* Loading */
.loading-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--heading-accent);
    font-weight: 600;
    font-style: normal;
}

.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
    animation: loadingDot 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loadingDot {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Sources reveal animation */
@keyframes sourcesRevealDown {
    from { clip-path: inset(0% 0% 100% 0%); }
    to   { clip-path: inset(0% 0% 0% 0%); }
}

.sources {
    margin-top: 15px;
    padding: 15px;
    background: var(--sources-bg);
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid rgba(var(--accent-primary-rgb), 0.35);
    animation: sourcesRevealDown 0.5s ease-out 0.05s both;
}

.answer-container { position: relative; }
.answer-content {}

sup.source-ref {
    font-size: 0.85em;
    vertical-align: super;
    margin-left: 4px;
    color: var(--accent-dark);
    cursor: pointer;
}

.sources ol { margin-top: 8px; padding-inline-start: 18px; }
.sources .source-group-header { margin: 10px 0 2px; font-weight: bold; color: var(--accent-primary); }
.sources ol:first-of-type { margin-top: 4px; }
.sources .source-preview { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }


/* ── 8. INPUT AREA ────────────────────────────────────────────── */

.input-container {
    display: flex;
    direction: ltr;
    gap: 8px;
    align-items: flex-end;
    padding: 12px 16px 12px 16px;
    position: relative;
    background: var(--input-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 999px;
    border: 1.5px solid var(--input-border);
    box-shadow: 0 2px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06),
                0 0 18px rgba(var(--glow-rgb), 0.10),
                0 0 40px rgba(var(--glow-rgb), 0.06);
    margin: 0 16px 8px 16px;
    transition: border-color 0.3s, box-shadow 0.3s, backdrop-filter 0.3s;
}

@keyframes containerGlow {
    0%, 100% {
        box-shadow: 0 8px 40px rgba(0,0,0,0.4), 0 1px 6px rgba(0,0,0,0.2),
                    0 0 18px rgba(var(--container-glow-rgb), 0.15);
        border-color: rgba(var(--container-glow-rgb), 0.18);
    }
    50% {
        box-shadow: 0 8px 40px rgba(0,0,0,0.4), 0 1px 6px rgba(0,0,0,0.2),
                    0 0 36px rgba(var(--container-glow-rgb), 0.35);
        border-color: rgba(var(--container-glow-rgb), 0.4);
    }
}

.chat-container.processing { animation: containerGlow 1.8s ease-in-out infinite; }

.input-container:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 2px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05),
                var(--input-focus-glow),
                0 0 14px rgba(var(--glow-rgb), 0.18);
}

.query-input {
    flex: 1;
    min-height: 44px;
    max-height: 160px;
    padding: 10px 14px 10px 4px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    line-height: 1.5;
    direction: rtl;
    resize: none;
    font-family: inherit;
    background: transparent;
    color: var(--text-primary);
    overflow-y: hidden;
}

.query-input::placeholder { color: var(--text-muted); }
.query-input.recording::placeholder { color: transparent; }
.query-input:focus { outline: none; border-color: transparent; box-shadow: none; }

.send-button {
    padding: 0;
    background: var(--send-btn-bg);
    color: #f8f6f0;
    border: 1px solid rgba(var(--glow-rgb), 0.22);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 10px rgba(183, 71, 42, 0.3), 0 0 10px rgba(var(--glow-rgb), 0.12);
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover {
    background: var(--send-btn-hover);
    transform: scale(1.03);
    box-shadow: 0 5px 16px rgba(183, 71, 42, 0.42), 0 0 16px rgba(var(--glow-rgb), 0.2);
    border-color: rgba(var(--glow-rgb), 0.38);
}

.send-button:active { transform: scale(0.98); }
.send-button:disabled {
    background: rgba(50, 48, 52, 0.8);
    cursor: not-allowed;
    color: var(--text-muted);
    transform: none;
    box-shadow: none;
    border-color: transparent;
}

.send-icon-wrap { position: relative; width: 20px; height: 20px; flex-shrink: 0; }
#sendArrowIcon, #sendSpinnerIcon { position: absolute; top: 0; left: 0; }
#sendSpinnerIcon { transform-origin: center; }

/* Answer mode toggle */
.answer-mode-wrapper {
    display: flex;
    justify-content: flex-start;
    margin: 0 16px 4px 16px;
}

.answer-mode-toggle {
    display: inline-flex;
    background: var(--input-bg);
    border: 1px solid var(--border-accent);
    border-radius: 20px;
    padding: 3px;
    gap: 2px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid transparent;
    border-radius: 16px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
    line-height: 1;
}

.mode-btn:hover { color: var(--text-primary); }

.mode-btn.active {
    background: var(--accent-primary);
    color: #ffffff;
    border-color: var(--accent-dark);
    font-weight: 600;
}

.mode-btn svg { flex-shrink: 0; }

/* Info / limit banners */
.limit-banner-message {
    background: var(--sources-bg);
    border: 1px solid var(--border-accent);
    border-radius: 12px;
    padding: 14px 20px;
    margin: 15px 20px;
    text-align: center;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    direction: rtl;
}

.limit-banner-cta {
    background: none;
    border: none;
    color: var(--heading-accent);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    margin-right: 4px;
}
.limit-banner-cta:hover { color: var(--accent-primary-hover); }

.query-input:disabled { cursor: not-allowed; opacity: 0.5; }
.input-container:has(.query-input:disabled) { opacity: 0.7; pointer-events: none; }


/* ── 9. VOICE INPUT ───────────────────────────────────────────── */

.textarea-wrapper { flex: 1; position: relative; display: flex; }

.voice-button {
    padding: 10px;
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.40);
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    position: relative;
    flex-shrink: 0;
}

.voice-button:hover {
    background: rgba(var(--accent-primary-rgb), 0.12);
    border-color: rgba(var(--accent-primary-rgb), 0.55);
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(var(--accent-primary-rgb), 0.2);
}

.voice-button.recording-send {
    background: rgba(26, 127, 90, 0.15);
    color: #28a745;
    border-color: #28a745;
    transform: scale(1.1);
    animation: sendPulse 1s infinite;
}

@keyframes sendPulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(40, 167, 69, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(40, 167, 69, 0.1); }
}

.voice-button.recording-cancel {
    background: rgba(220, 53, 69, 0.12);
    color: #dc3545;
    border-color: #dc3545;
    transform: scale(0.95);
    animation: cancelShake 0.4s ease-in-out;
}

@keyframes cancelShake {
    0%, 100% { transform: scale(0.95) rotate(0deg); }
    25% { transform: scale(0.95) rotate(-3deg); }
    75% { transform: scale(0.95) rotate(3deg); }
}

.voice-button.processing {
    background: rgba(40, 38, 42, 0.8);
    color: var(--text-muted);
    border-color: var(--border-primary);
    cursor: wait;
    pointer-events: none;
}

.voice-button.processing .voice-icon { animation: spin 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
.voice-button:disabled { opacity: 0.5; cursor: not-allowed; }

.slide-hint {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}
.voice-button.recording-send .slide-hint { display: flex; }
.slide-hint svg { animation: slideArrow 1s ease-in-out infinite; }
@keyframes slideArrow {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.recording-indicator {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px;
    background: var(--input-bg);
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 14px;
    color: var(--heading-accent);
    transition: background 0.2s, color 0.2s;
    z-index: 10;
}
.recording-indicator.cancel {
    background: rgba(35, 15, 15, 0.96);
    color: #a06070;
}

.voice-icon { width: 24px; height: 24px; transition: transform 0.2s; }
.voice-button:hover .voice-icon { transform: scale(1.1); }

.audio-waveform { flex: 1; height: 100%; min-height: 0; border-radius: 6px; background: transparent; }
#recordingTime { font-variant-numeric: tabular-nums; transition: color 0.3s; }
#recordingTime.recording-time-urgent { color: #e05252; }

.cancel-recording {
    background: transparent;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}
.cancel-recording:hover { background: rgba(220, 53, 69, 0.1); }

.disclaimer {
    background: rgba(50, 45, 25, 0.8);
    border: 1px solid rgba(180, 155, 60, 0.3);
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    font-size: 13px;
    color: #c0a040;
}


/* ── 10. FEEDBACK WIDGET ──────────────────────────────────────── */

.feedback-wrapper {
    margin-top: 12px;
    display: flex !important;
    align-items: center;
    gap: 4px;
    visibility: visible !important;
    opacity: 1 !important;
}

.feedback-container {
    display: flex !important;
    align-items: center;
    gap: 4px;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 100;
}

.feedback-buttons { display: flex; gap: 4px; }

.feedback-icon-btn {
    position: relative;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    visibility: visible !important;
    opacity: 1 !important;
    color: #8c8c8c;
    flex-shrink: 0;
    padding: 0;
}

.feedback-icon-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.feedback-icon-btn:hover {
    background: var(--feedback-hover-bg);
    border-color: var(--border-primary);
    color: var(--text-secondary);
}
.feedback-icon-btn.copy-btn:hover    { color: var(--accent-dark); }
.feedback-icon-btn.helpful-btn:hover { color: var(--accent-dark); }
.feedback-icon-btn.not-helpful-btn:hover { color: #c0392b; }
.feedback-icon-btn.copy-success { color: var(--accent-dark); }
.feedback-icon-btn.copy-fail    { color: #c0392b; }

/* Tooltip */
.feedback-icon-btn[data-tooltip] { position: relative; }
.feedback-icon-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 200;
    font-family: inherit;
}
.feedback-icon-btn[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 200;
}
.feedback-icon-btn[data-tooltip]:hover::after,
.feedback-icon-btn[data-tooltip]:hover::before { opacity: 1; }

.feedback-thanks { color: var(--heading-accent); font-size: 13px; font-weight: 600; }

/* Mode-switch pill button (inside feedback-wrapper, appears after the icon buttons) */
.mode-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border: 1px solid var(--accent-primary);
    border-radius: 12px;
    background: var(--accent-primary);
    color: #fff;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    white-space: nowrap;
    margin-inline-start: 6px; /* gap from icon buttons (RTL: appears on the left) */
}
.mode-switch-btn:hover {
    background: var(--accent-primary-hover, var(--accent-primary));
    border-color: var(--accent-primary-hover, var(--accent-primary));
}
.mode-switch-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Deep search button */
.search-deeper-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border: 1px solid #0d9488;
    border-radius: 12px;
    background: #0d9488;
    color: #fff;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    white-space: nowrap;
    margin-inline-start: 6px;
}
.search-deeper-btn:hover {
    background: #0f766e;
    border-color: #0f766e;
}
.search-deeper-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Deep search progress indicator */
.deep-search-progress {
    padding: 12px 16px;
    color: #0d9488;
    font-size: 13px;
    direction: rtl;
    animation: deepSearchPulse 1.5s ease-in-out infinite;
}
@keyframes deepSearchPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Feedback modal */
.feedback-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.feedback-modal.show { display: flex; }

.feedback-modal-content {
    background: var(--bg-modal);
    border: 1px solid var(--border-primary);
    border-radius: 15px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

.feedback-modal-title { color: var(--heading-accent); font-size: 18px; margin-bottom: 15px; font-weight: 600; }
.feedback-name-section { margin-bottom: 15px; }

.feedback-modal-name {
    width: 100%; padding: 12px;
    border: 2px solid var(--border-primary);
    border-radius: 8px;
    font-family: inherit; font-size: 14px;
    direction: rtl; text-align: right;
    background: var(--bg-input);
    color: var(--text-primary);
}
.feedback-modal-name:focus { outline: none; border-color: var(--accent-dark); }
.feedback-modal-name.error { border-color: #d32f2f; }

.feedback-name-error { color: #d32f2f; font-size: 12px; margin-top: 5px; direction: rtl; text-align: right; }

.feedback-modal-textarea {
    width: 100%; min-height: 80px; padding: 12px;
    border: 2px solid var(--border-primary);
    border-radius: 8px;
    font-family: inherit; font-size: 14px;
    resize: vertical; margin-bottom: 15px;
    background: var(--bg-input);
    color: var(--text-primary);
}
.feedback-modal-textarea:focus { outline: none; border-color: var(--accent-dark); }

.rating-section { margin: 15px 0; padding: 15px; background: var(--sidebar-section-bg); border-radius: 8px; }
.rating-question { color: var(--heading-accent); font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.star-rating { display: flex; gap: 5px; direction: ltr; }
.star { font-size: 24px; color: var(--text-muted); cursor: pointer; transition: all 0.3s; }
.star:hover { transform: scale(1.2); }
.star.active { color: #d4af37; }

.feedback-modal-buttons { display: flex; gap: 10px; margin-top: 15px; }
.feedback-modal-btn { flex: 1; padding: 12px 20px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; transition: all 0.3s; }
.feedback-modal-submit { background: var(--accent-dark); color: var(--text-light); }
.feedback-modal-submit:hover { background: var(--accent-primary); }
.feedback-modal-skip { background: var(--sidebar-section-bg); color: var(--text-secondary); }
.feedback-modal-skip:hover { background: var(--bg-input); }


/* ── 11. INFO MODAL (About) ───────────────────────────────────── */

.info-modal {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    align-items: center;
    justify-content: center;
}
.info-modal.show { display: flex; }

.info-modal-content {
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-accent);
    border-radius: 15px;
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
    overflow: hidden;
}

.info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
    background: transparent;
}

.info-modal-title { color: var(--heading-accent); font-size: 18px; font-weight: 700; margin: 0; }

.info-modal-close {
    background: none; border: none;
    cursor: pointer; color: var(--text-secondary);
    padding: 6px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.info-modal-close:hover {
    background: rgba(var(--accent-primary-rgb), 0.12);
    color: var(--heading-accent);
}

.info-tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border-primary);
    padding: 0 24px;
    flex-shrink: 0;
    background: transparent;
}

.info-tab {
    padding: 12px 20px;
    border: none; background: none; cursor: pointer;
    font-family: inherit; font-size: 14px; font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
}
.info-tab.active { color: var(--heading-accent); border-bottom-color: var(--heading-accent); }
.info-tab:hover:not(.active) { color: var(--heading-accent); }

.info-tab-content { display: none; overflow-y: auto; padding: 20px 24px; }
.info-tab-content.active { display: block; }

/* Mobile sidebar: absolute panels, opacity fade — zero layout shift on tab switch */
.sidebar-mobile-content .info-tab-content {
    position: absolute;
    inset: 0;
    display: block;
    overflow-y: auto;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.12s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}
.sidebar-mobile-content .info-tab-content.active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

/* Mobile sidebar: stretch all tabs equally to accommodate up to 3 tabs */
.sidebar-mobile-content .info-tab {
    flex: 1;
    text-align: center;
    padding: 10px 4px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
}

.info-stats-row { display: flex; gap: 12px; margin-bottom: 20px; }
.info-stat-pill {
    background: rgba(var(--accent-primary-rgb), 0.10);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.18);
    border-radius: 20px; padding: 12px 16px; text-align: center; flex: 1;
    display: flex; flex-direction: column; align-items: center;
}
.info-stat-pill .stat-number { font-size: 22px; display: block; }
.info-stat-pill .stat-label { font-size: 12px; margin-top: 4px; white-space: nowrap; }

.info-about-section {
    margin-bottom: 16px; padding-bottom: 16px;
    border-bottom: 1px solid var(--border-primary);
}
.info-about-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.info-about-section h3 { color: var(--heading-accent); font-size: 14px; font-weight: 700; margin: 0 0 8px; }
.info-about-section p { font-size: 13px; color: var(--text-secondary); line-height: 1.7; margin: 0; }

.info-about-warning {
    background: rgba(var(--accent-primary-rgb), 0.06);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.20);
    border-radius: 10px;
    padding: 14px 16px;
}
.info-about-section.info-about-warning { padding: 14px 16px; }
.info-about-warning h3 { color: var(--heading-accent); }
.info-about-warning p  { color: var(--text-secondary); }

.info-modal-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--border-primary);
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    flex-shrink: 0;
    background: transparent;
}


/* ── 12. AUTH MODAL ───────────────────────────────────────────── */

.auth-modal-overlay {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 2100;
    align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
    direction: rtl;
}

.auth-modal-container {
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-accent);
    border-radius: 18px;
    padding: 36px 32px 28px;
    max-width: 400px;
    width: 92%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.25),
                0 0 20px rgba(var(--pc-mid-rgb), 0.15);
    direction: rtl;
    text-align: right;
}

.auth-modal-title { color: var(--heading-accent); font-size: 19px; font-weight: 700; margin: 0 0 6px 0; line-height: 1.4; }
.auth-modal-subtitle { color: var(--text-secondary); font-size: 13px; margin: 0 0 22px 0; }

.auth-modal-input {
    width: 100%; padding: 11px 14px;
    border: 2px solid var(--border-accent);
    border-radius: 8px; font-family: inherit; font-size: 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
    box-sizing: border-box; margin-bottom: 10px; direction: rtl;
}
.auth-modal-input:focus { outline: none; border-color: var(--accent-dark); }
.auth-modal-input::placeholder { color: var(--text-muted); }

.auth-modal-btn {
    width: 100%; padding: 11px 20px;
    background: var(--accent-dark);
    color: var(--text-light);
    border: none; border-radius: 8px;
    cursor: pointer; font-size: 14px; font-family: inherit; font-weight: 600;
    transition: background 0.2s; margin-top: 4px;
}
.auth-modal-btn:hover:not(:disabled) { background: var(--menu-btn-hover-bg); }
.auth-modal-btn:disabled { opacity: 0.6; cursor: not-allowed; }
/* Light mode: accent-dark bg is still dark enough — force white text for contrast */
[data-theme="light"] .auth-modal-btn { color: #fff; }

.auth-modal-btn-google {
    width: 100%; padding: 11px 20px;
    background: rgba(var(--pc-mid-rgb), 0.12);
    color: var(--text-primary);
    border: 1px solid var(--border-accent);
    border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit; font-weight: 500;
    transition: background 0.2s, border-color 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.auth-modal-btn-google:hover {
    background: rgba(var(--pc-mid-rgb), 0.22);
    border-color: rgba(var(--accent-primary-rgb), 0.30);
}

.auth-modal-divider {
    display: flex; align-items: center; gap: 12px;
    margin: 16px 0;
    color: var(--text-muted); font-size: 13px;
}
.auth-modal-divider::before,
.auth-modal-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-primary); }

.auth-modal-link {
    background: none; border: none;
    color: var(--heading-accent); font-size: 13px; font-family: inherit;
    cursor: pointer; padding: 0;
    text-decoration: underline; text-underline-offset: 2px;
}
.auth-modal-link:hover { color: var(--accent-primary); }

.auth-modal-error {
    display: none;
    color: var(--error-text); font-size: 13px;
    margin-top: 10px; padding: 8px 12px;
    background: var(--error-bg);
    border-radius: 6px;
    border: 1px solid rgba(200, 80, 80, 0.35);
}
.auth-modal-dismiss {
    background: none; border: none; color: var(--text-secondary);
    font-size: 13px; font-family: inherit; cursor: pointer; padding: 0; text-decoration: none; margin-top: 8px;
}
.auth-modal-dismiss:hover { color: var(--text-primary); }

.auth-modal-footer { margin-top: 18px; text-align: center; }

.auth-modal-forgot {
    background: none; border: none; color: var(--text-secondary);
    font-size: 12px; font-family: inherit; cursor: pointer;
    padding: 0 0 8px 0; text-decoration: underline; text-underline-offset: 2px;
    display: block; text-align: right;
}
.auth-modal-forgot:hover { color: var(--heading-accent); }

.auth-reset-success {
    color: var(--success-text); font-size: 13px;
    margin-top: 10px; padding: 8px 12px;
    background: var(--success-bg);
    border-radius: 6px;
    border: 1px solid rgba(var(--accent-primary-rgb), 0.35);
}

.auth-logged-in {
    background: var(--heading-accent) !important;
    color: #fff !important;
    font-size: 14px !important; font-weight: 700 !important;
}


/* ── 13. ADMIN LOGIN MODAL ────────────────────────────────────── */

.admin-login-modal {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 2000;
    align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
}
.admin-login-modal.show { display: flex; }

.admin-login-content {
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-accent);
    border-radius: 16px;
    padding: 36px 32px 28px;
    max-width: 360px; width: 90%;
    box-shadow: 0 16px 48px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.25),
                0 0 20px rgba(var(--pc-mid-rgb), 0.15);
    direction: ltr; text-align: left;
}

.admin-login-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.admin-login-header svg { color: var(--accent-dark); flex-shrink: 0; }
.admin-login-title { color: var(--heading-accent); font-size: 18px; font-weight: 700; margin: 0; }
.admin-login-subtitle { color: var(--text-secondary); font-size: 13px; margin: 0 0 20px 0; }
.admin-login-label { display: block; color: var(--heading-accent); font-size: 13px; font-weight: 600; margin-bottom: 6px; }

.admin-login-input {
    width: 100%; padding: 11px 14px;
    border: 2px solid var(--border-accent);
    border-radius: 8px; font-family: inherit; font-size: 14px;
    background: var(--bg-input); color: var(--text-primary);
    transition: border-color 0.2s; box-sizing: border-box;
}
.admin-login-input:focus { outline: none; border-color: var(--accent-dark); }

.admin-login-error {
    display: none; color: var(--error-text); font-size: 13px;
    margin-top: 8px; padding: 8px 12px;
    background: var(--error-bg); border-radius: 6px;
    border: 1px solid rgba(200, 80, 80, 0.35);
}
.admin-login-error.show { display: block; }

.admin-login-buttons { display: flex; gap: 10px; margin-top: 20px; }

.admin-login-submit {
    flex: 1; padding: 11px 20px;
    background: var(--accent-dark); color: var(--text-light);
    border: none; border-radius: 8px;
    cursor: pointer; font-size: 14px; font-family: inherit; font-weight: 600;
    transition: background 0.2s;
}
.admin-login-submit:hover:not(:disabled) { background: var(--menu-btn-hover-bg); }
.admin-login-submit:disabled { opacity: 0.6; cursor: not-allowed; }
[data-theme="light"] .admin-login-submit { color: #fff; }

.admin-login-cancel {
    padding: 11px 18px;
    background: rgba(var(--pc-mid-rgb), 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.20);
    border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
    transition: background 0.2s;
}
.admin-login-cancel:hover { background: rgba(var(--pc-mid-rgb), 0.25); }


/* ── 14. MISC. UI ELEMENTS ────────────────────────────────────── */

.setup-prompt {
    background: rgba(60, 50, 20, 0.8);
    border: 1px solid rgba(200, 160, 50, 0.3);
    border-radius: 10px; padding: 20px; margin: 20px 0; text-align: center;
}
.setup-prompt h3 { color: #c0a040; margin-bottom: 10px; }
.setup-prompt p  { color: #c0a040; margin-bottom: 15px; }

.trial-badge {
    background: rgba(80, 55, 10, 0.85);
    padding: 4px 10px; border-radius: 6px;
    font-size: 10px; color: #e07040;
    border: 1px solid rgba(212,175,55,0.35);
    font-weight: 600; display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; } 50% { opacity: 0.7; } 100% { opacity: 1; }
}

@keyframes blink {
    0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; }
}

.streaming-message { min-height: 20px; }


/* ── 15. WELCOME STATE ────────────────────────────────────────── */

.welcome-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 0 24px; text-align: center; flex: 1; gap: 12px;
}

.welcome-icon {
    font-size: 48px; margin-bottom: 4px;
    filter: drop-shadow(0 2px 8px rgba(var(--accent-primary-rgb), 0.15));
}

.welcome-title { font-size: 20px; font-weight: 700; color: var(--heading-accent); margin: 0; }
.welcome-subtitle { font-size: 14px; color: var(--text-secondary); margin: 0; line-height: 1.5; }
.keyboard-hint { font-size: 14px; color: var(--text-secondary); margin: 0; text-align: center; }

.example-chips {
    display: flex; flex-wrap: wrap; gap: 6px;
}

.example-chip {
    padding: 5px 12px;
    background: var(--chip-bg);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.25);
    border-radius: 24px; font-family: inherit; font-size: 12px;
    color: var(--chip-color);
    cursor: pointer; transition: all 0.2s ease;
    direction: rtl; text-align: right; line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    white-space: nowrap;
}

.example-chip:hover {
    background: var(--accent-dark);
    color: #ffffff;
    border-color: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--accent-primary-rgb), 0.35);
}


/* ── 16. MOBILE MENU ──────────────────────────────────────────── */

.mobile-menu-button {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 40px; height: 40px;
    border-radius: 10px; cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    align-items: center; justify-content: center;
    padding: 0; flex-shrink: 0;
}

.mobile-menu-button:hover {
    background: var(--menu-btn-bg);
    transform: scale(1.05);
}
.mobile-menu-button:active { transform: scale(0.92); }
.mobile-menu-button svg { width: 22px; height: 22px; display: block; }

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999; opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

.mobile-only  { display: none; }
.desktop-only { display: flex; }

/* Never let the mobile new-conv button show on desktop, even when JS sets inline display */
@media (min-width: 901px) {
    #new-conv-icon-mobile { display: none !important; }
    #home-icon-mobile      { display: none !important; }
}

.sidebar-mobile-content { padding: 20px 15px; }

.sidebar-mobile-top-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}


/* ── 17. HISTORY PANEL ────────────────────────────────────────── */

.history-panel {
    display: none;
    position: fixed;
    top: 0;
    right: 54px;
    width: 340px;
    height: 100%;
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1500;
    overflow: hidden;
    flex-direction: column;
    padding: 20px;
    box-shadow: -4px 0 24px rgba(0,0,0,0.6);
    transition: transform 0.3s ease;
    direction: rtl;
    border-left: 1px solid var(--border-primary);
}

/* Resize handle — left edge of history / conv-viewer panels */
.history-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 10px;
    height: 100%;
    cursor: ew-resize;
    z-index: 5;
    background: transparent;
    transition: background 0.15s;
}
/* Three-dot grip indicator centered on the handle */
.history-resize-handle::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 36px;
    background-image: radial-gradient(circle, var(--text-secondary) 1.5px, transparent 1.5px);
    background-size: 4px 12px;
    background-repeat: repeat-y;
    opacity: 0.45;
    transition: opacity 0.15s;
}
.history-resize-handle:hover {
    background: rgba(var(--accent-primary-rgb), 0.08);
}
.history-resize-handle:hover::after,
.history-resize-handle.dragging::after {
    opacity: 1;
    background-image: radial-gradient(circle, var(--accent-primary) 1.5px, transparent 1.5px);
}

/* Scrollable body inside history panel */
.history-panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    direction: ltr; /* puts scrollbar on right side */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}
.history-panel-body::-webkit-scrollbar { width: 4px; }
.history-panel-body::-webkit-scrollbar-track { background: transparent; }
.history-panel-body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
.history-panel-body::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

.history-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.history-panel-title {
    color: var(--text-primary);
    margin: 0;
    font-size: 17px;
}

.history-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    padding: 2px 6px;
}
.history-panel-close:hover { color: var(--text-secondary); }

.history-item {
    background: rgba(var(--accent-primary-rgb), 0.04);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    border: 1px solid var(--border-primary);
    transition: background 0.15s;
}
.history-item:hover {
    background: rgba(var(--accent-primary-rgb), 0.09);
}

.history-item-multi {
    border-color: rgba(var(--accent-primary-rgb), 0.3);
}

.history-item-query {
    color: var(--text-primary);
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    overflow-wrap: break-word;
    word-break: break-word;
}

.history-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    direction: ltr;
}

.history-item-date {
    color: var(--text-muted);
    margin: 0;
    font-size: 12px;
}

.history-turn-badge {
    display: inline-block;
    background: rgba(var(--accent-primary-rgb), 0.15);
    color: var(--accent-primary);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
}

/* ── 17b. CONVERSATION VIEWER ─────────────────────────────────── */

.conv-viewer {
    display: none;
    position: fixed;
    top: 0;
    right: 54px;
    width: 340px;
    height: 100%;
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1600;
    overflow: hidden;
    flex-direction: column;
    padding: 20px;
    box-shadow: -4px 0 24px rgba(0,0,0,0.6);
    direction: rtl;
    border-left: 1px solid var(--border-primary);
}

/* Scrollable body inside conv-viewer */
.conv-viewer-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    direction: ltr; /* puts scrollbar on right side */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}
.conv-viewer-body::-webkit-scrollbar { width: 4px; }
.conv-viewer-body::-webkit-scrollbar-track { background: transparent; }
.conv-viewer-body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}
.conv-viewer-body::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

.conv-viewer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.conv-viewer-back {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.conv-viewer-back:hover { color: var(--text-secondary); background: rgba(255,255,255,0.05); }

/* ── Header row for assistant messages in viewer ── */
.conv-viewer-msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.conv-viewer-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: inherit;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
}
.conv-viewer-copy-btn:hover { opacity: 1; color: var(--text-secondary); }
.conv-viewer-copy-btn.copied { color: var(--accent-primary); opacity: 1; }

.conv-viewer-copy-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.conv-viewer-title {
    color: var(--text-primary);
    margin: 0;
    font-size: 17px;
}

.conv-viewer-msg {
    margin-bottom: 16px;
    direction: rtl;
    text-align: right;
}

.conv-viewer-role {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.conv-viewer-msg-user {
    background: rgba(var(--accent-primary-rgb), 0.1);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.conv-viewer-msg-bot {
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}
.conv-viewer-msg-bot p { margin-top: 0; margin-bottom: 8px; }
.conv-viewer-msg-bot > *:last-child { margin-bottom: 0; }
.conv-viewer-msg-bot ul,
.conv-viewer-msg-bot ol { margin: 8px 0; padding-right: 20px; }
.conv-viewer-msg-bot li { margin-bottom: 4px; }
.conv-viewer-msg-bot ul ul, .conv-viewer-msg-bot ol ul,
.conv-viewer-msg-bot ul ol, .conv-viewer-msg-bot ol ol { margin-top: 4px; margin-bottom: 4px; padding-right: 20px; }
.conv-viewer-msg-bot strong { font-weight: 700; color: var(--heading-accent); }
.conv-viewer-msg-bot em { font-style: italic; color: var(--text-secondary); }

@media (max-width: 768px) {
    .conv-viewer {
        right: 0;
        width: 100%;
        z-index: 2200;
    }
    .history-resize-handle { display: none; }
}


/* ── 18. PROFILE BUBBLE ───────────────────────────────────────── */

.profile-bubble {
    display: none;
    position: fixed;
    top: 12px;
    right: 54px;
    background: var(--bg-modal);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1600;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    border: 1px solid var(--border-primary);
    width: 280px;
    direction: rtl;
}

@media (max-width: 900px) {
    .profile-bubble {
        right: 8px;
        top: 56px;
        left: auto;
        width: min(280px, calc(100vw - 16px));
    }
}

.profile-bubble-title {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 12px;
}

.profile-bubble-section {
    border-top: 1px solid var(--border-primary);
    padding-top: 10px;
    margin-bottom: 10px;
}

.profile-bubble-label {
    color: var(--text-secondary);
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
}

.profile-bubble-email {
    color: var(--text-primary);
    margin: 0;
    font-size: 13px;
    word-break: break-all;
}

.profile-bubble-btn {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.2s;
    margin-bottom: 8px;
}

.profile-bubble-btn-reset {
    background: rgba(var(--accent-primary-rgb), 0.15);
    border: 1px solid rgba(var(--accent-primary-rgb), 0.35);
    color: var(--heading-accent);
}
.profile-bubble-btn-reset:hover { background: rgba(var(--accent-primary-rgb), 0.25); }

.profile-bubble-btn-logout {
    background: rgba(200, 80, 80, 0.15);
    border: 1px solid rgba(200, 80, 80, 0.35);
    color: #d9a9a9;
    margin-bottom: 0;
}
.profile-bubble-btn-logout:hover { background: rgba(200, 80, 80, 0.25); }

/* ── Mobile inline profile panel (inside sidebar, above tabs) ── */
.mobile-profile-panel {
    margin: 12px 0 4px;
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--bg-modal, rgba(18,15,20,0.55));
    border: 1px solid var(--border-primary);
    direction: rtl;
}


/* ── 19. THEME TOGGLE ─────────────────────────────────────────── */

.theme-toggle-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    color: var(--text-secondary);
    padding: 0;
}

.theme-toggle-btn:hover {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(var(--accent-primary-rgb), 0.15);
}

/* Hide the appropriate icon based on current theme */
/* Fallback defaults first (lowest priority — theme rules below override) */
:root .icon-sun  { display: block; }
:root .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: block; }
[data-theme="dark"]  .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }


/* ── 20. RESPONSIVE ───────────────────────────────────────────── */

@media (max-width: 900px) {
    html {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
        overscroll-behavior: none;
    }
    body {
        overflow: hidden;
        overscroll-behavior: none;
    }
    .mobile-only  { display: block; }
    .desktop-only { display: none; }
    .mobile-menu-button { display: flex; position: static; }

    .container {
        position: fixed;
        bottom: 0;
        left: 0;
        flex-direction: column;
        width: var(--vw, 100%);
        height: var(--vh, 100dvh);
        max-height: var(--vh, 100dvh);
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0; left: -100%;
        width: 85%; max-width: 340px;
        height: 100vh; z-index: 1000;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
        transition: left 0.3s ease-in-out;
        overflow-y: auto; padding: 0;
        display: flex; flex-direction: column;
    }
    .sidebar.open { left: 0; }
    .sidebar-mobile-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; width: 100%; }
    .mobile-tab-panels { flex: 1; position: relative; min-height: 0; }

    .main-content { padding: 10px 10px 0 10px; width: 100%; flex: 1; min-height: 0; overflow-x: hidden; }
    .chat-container { padding: 20px 10px; flex: 1; min-height: 0; max-height: none; margin: 0; }
    .chat-header {
        flex-direction: row; align-items: center; justify-content: space-between;
        gap: 16px; position: sticky; top: 0; z-index: 100;
    }

    /* Home button: visible in chat mode, hidden on landing */
    #home-icon-mobile { display: none; }
    body:not(.is-landing) #home-icon-mobile { display: flex; }
}

@media (max-width: 600px) {
    .sidebar { width: 90%; max-width: 320px; }
    .sidebar-mobile-content { padding: 15px 12px; }
    .sidebar-logo { height: 40px; }
    .sidebar-section   { padding: 14px 12px; }
    .main-content { padding: 12px !important; width: 100%; }
    .chat-container {
        width: 100% !important; min-width: auto !important; max-width: 100% !important;
        padding: 0; border-radius: 12px;
        background: var(--container-bg);
    }
    .chat-header {
        flex-direction: row; align-items: center; justify-content: space-between;
        gap: 12px; padding: 12px 12px; border-radius: 12px 12px 0 0;
        position: sticky; top: 0; z-index: 100;
    }
    .header-logo { height: 36px; }
    .chat-messages { padding: 12px; }
    .input-container { gap: 8px; padding: 10px; margin: 0 12px 8px 12px; }
    .query-input { font-size: 15px; min-height: 44px; padding: 10px 12px; }
    .voice-button { width: 44px; height: 44px; padding: 0; min-width: 44px; min-height: 44px; flex: 0 0 auto; }
    .recording-indicator { font-size: 12px; padding: 6px 10px; }
    .send-button { width: 44px; height: 44px; padding: 0; flex: 0 0 auto; }
    .stat-number { font-size: 22px; }
    .stat-label  { font-size: 11px; }
    .message { font-size: 14px; padding: 12px 14px; }
    .setup-prompt { padding: 20px; margin: 20px; }
    .setup-prompt h3 { font-size: 18px; }
    .setup-prompt p  { font-size: 13px; }
    .welcome-state { padding: 0 4px; gap: 14px; justify-content: center; }
    .welcome-title  { font-size: 22px; }
    .welcome-subtitle { font-size: 14px; max-width: 280px; }
    .welcome-chips-wrapper { padding-left: 12px; padding-right: 16px; }
    .example-chips { gap: 5px; }
    .example-chip  { font-size: 11px; padding: 5px 10px; }

    /* Swap welcome content for a short hint while mobile keyboard is open */
    .keyboard-hint { display: none; }
    body.keyboard-open .welcome-title,
    body.keyboard-open .welcome-subtitle,
    body.keyboard-open .landing-chips-label,
    body.keyboard-open .example-chips { display: none; }
    body.keyboard-open .keyboard-hint { display: block; }
}


/* ── 22. MOBILE PERFORMANCE ───────────────────────────────────────
   Hides the canvas background on narrow screens — particle animations
   are power-hungry and distract on small displays. The JS loader also
   checks window.__PARTICLES.enabled, but this CSS rule ensures the
   canvas never shows even if the JS path is slow.
   ─────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    /* Kill canvas particles — keep CSS bottom glow (it's cheap, not GPU) */
    #circuit-bg-canvas { display: none !important; }

    /* Solid backgrounds in place of expensive backdrop-filter */
    .sidebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--sidebar-bg);
    }
    .chat-container {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--container-bg);
    }
    .input-container {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .sidebar-icons-top,
    .sidebar-icons-bottom {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .user-message,
    .bot-message {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .info-modal-content,
    .auth-modal-container,
    .admin-login-content,
    .feedback-modal-content,
    .history-panel,
    .profile-bubble {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* Tighten pulsing container glow (still works without canvas) */
    .chat-container.processing {
        animation-duration: 2.4s;
    }
}


/* ── 23. REDUCED MOTION ───────────────────────────────────────────
   Respects the OS accessibility setting. Kills decorative animations;
   keeps functional transitions (panel slides, button states).
   ─────────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    /* Kill all decorative keyframe animations */
    .stage-message,
    .chat-container.processing,
    .loading-dots span,
    .trial-badge,
    .voice-button.recording-send,
    .voice-button.recording-cancel,
    .slide-hint svg {
        animation: none !important;
    }

    /* Instant transitions instead of eased ones */
    .sidebar,
    .sidebar-overlay,
    .mode-btn,
    .mode-switch-btn,
    .search-deeper-btn,
    .example-chip,
    .send-button,
    .feedback-icon-btn,
    .sidebar-icon,
    .theme-toggle-btn {
        transition: none !important;
    }

    /* Sources appear immediately */
    .sources { animation: none; }
}

/* ── 24. LANDING STATE ─────────────────────────────────────────────
   Styles for the pre-query landing experience. Driven by body.is-landing.
   All landing sections are hidden by default; shown only during landing.
   ─────────────────────────────────────────────────────────────── */

/* Landing sections: hidden by default, shown when body has is-landing */
.landing-section {
    display: none;
    padding: 32px 16px 40px;
}
body.is-landing .landing-section {
    display: block;
}

/* Persistent page sections: always visible (features, FAQ, footer) */
.page-section {
    display: block;
    padding: 32px 16px 40px;
    /* main-content uses align-items:center (flex column), which shrinks children
       to content-width. width:100% overrides that so sections always fill the
       available space — critical for overflow:clip on the marquee to work. */
    width: 100%;
    box-sizing: border-box;
}

/* On mobile, page-sections (features/FAQ/footer) are landing-only content.
   They must be hidden in chat mode — if left visible they consume all the flex
   space in .main-content and collapse the chat-container to zero height. */
@media (max-width: 900px) {
    .page-section { display: none; }
    body.is-landing .page-section { display: block; }
}

/* .main-content is always scrollable (features/FAQ/footer persist in chat mode).
   On mobile landing state, stretch children to full width and restore the
   full-viewport container; form + chips are pushed to the bottom by flex. */
@media (max-width: 900px) {
    body.is-landing .main-content {
        align-items: stretch;
    }
    body.is-landing .chat-container {
        flex: 0 0 calc(var(--vh, 100dvh) - 20px);
    }
    /* mainChat fills the container so chat-messages can push form to bottom */
    body.is-landing #mainChat {
        flex: 1;
    }
    /* Welcome text area expands to fill the middle; content is vertically centered */
    body.is-landing .chat-messages {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        overflow-y: hidden;
    }
}

/* Hero welcome state: size to content on landing */
body.is-landing .welcome-state {
    min-height: 0;
    flex: 0 0 auto;
    padding: 40px 24px 28px;
    gap: 14px;
}

/* Desktop landing: collapse everything to content height so the glass card
   doesn't leave a transparent ghost behind the sections below */
@media (min-width: 901px) {
    body.is-landing .chat-messages {
        flex: 0 0 auto;
        overflow-y: hidden;
    }
    body.is-landing #mainChat {
        flex: 0 0 auto;
    }
}

/* Status pill */
.landing-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(var(--accent-primary-rgb), 0.45);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    background: rgba(var(--accent-primary-rgb), 0.06);
}

.landing-status-pill .status-dot {
    color: #28a745;
}

/* Hero heading */
.landing-hero-heading {
    font-size: clamp(26px, 4vw, 40px);
    font-weight: 700;
    line-height: 1.25;
    margin: 0;
    padding-bottom: 0.15em;
    background: var(--title-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Hero subtitle */
.landing-hero-subtitle {
    font-size: 15px;
    max-width: 480px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin: 0;
}

/* "جرب سؤالاً" inline label beside chips */
.landing-chips-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Sample question chips — inside chat container, below input, shown on landing only */
.welcome-chips-wrapper {
    display: none;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 26px 6px 16px;
}
body.is-landing .welcome-chips-wrapper {
    display: flex;
}

/* Section header block */
.landing-section-header {
    max-width: 720px;
    margin: 0 auto 24px;
    text-align: center;
}
.landing-section-title {
    font-size: clamp(20px, 3vw, 28px);
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary, #e8eaf0);
}
.landing-section-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 0 0 12px;
}
.landing-section-intro {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.65;
    margin: 0;
}

/* Features grid */
.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 860px;
    margin: 0 auto;
}

.feature-card {
    background: var(--msg-bot-bg);
    border: 1px solid var(--border-primary);
    border-radius: 14px;
    padding: 18px;
}
.feature-card-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: rgba(var(--accent-primary-rgb), 0.12);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
    color: var(--accent-primary);
    flex-shrink: 0;
}
.feature-card-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary, #e8eaf0);
}
.feature-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* ── LEGISLATION MARQUEE ──────────────────────────────────────── */
.legislation-marquee {
    overflow: clip;
    padding: 4px 0;
    /* Must be LTR so the wider-than-viewport tracks are left-aligned.
       Without this, RTL block layout right-aligns the tracks and the
       animation slides them off-screen on narrow (mobile) viewports. */
    direction: ltr;
    /* mask-image + overflow:hidden + animated transforms can fail to composite
       on mobile — apply the edge fade only on desktop where it's reliable */
}
@media (min-width: 901px) {
    .legislation-marquee {
        mask-image: linear-gradient(to right, transparent 0%, black 8%, black 92%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, transparent 0%, black 8%, black 92%, transparent 100%);
    }
}

.legislation-track {
    display: flex;
    direction: ltr;
    width: max-content;
    margin-bottom: 10px;
    gap: 10px;
    opacity: 0;
    will-change: transform;
}
.marquee-ready .legislation-track {
    opacity: 1;
    transition: opacity .3s ease;
}
.legislation-track:last-child { margin-bottom: 0; }

.legislation-track--fwd {
    animation: marquee-fwd 55s linear infinite;
    animation-play-state: paused;
}
.legislation-track--rev {
    animation: marquee-rev 55s linear infinite;
    animation-play-state: paused;
}
.marquee-ready .legislation-track--fwd,
.marquee-ready .legislation-track--rev {
    animation-play-state: running;
}
.legislation-marquee:hover .legislation-track {
    animation-play-state: paused !important;
}

@keyframes marquee-fwd {
    from { transform: translateX(0); }
    to   { transform: translateX(var(--marquee-shift, -50%)); }
}
@keyframes marquee-rev {
    from { transform: translateX(var(--marquee-shift, -50%)); }
    to   { transform: translateX(0); }
}

.legislation-pill {
    white-space: nowrap;
    padding: 6px 16px;
    border-radius: 24px;
    font-size: 13px;
    direction: rtl;
    color: var(--text-secondary);
    background: var(--msg-bot-bg);
    border: 1px solid var(--border-primary);
    user-select: none;
}

/* FAQ section */
#faqSection {
    max-width: 720px;
    margin: 0 auto;
    border-top: 1px solid var(--border-primary);
    background: var(--msg-bot-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    border: 1px solid var(--border-primary);
    padding: 0 20px;
}
.faq-note {
    font-size: 13px;
    font-style: italic;
    color: var(--text-muted);
    margin: 0 0 16px;
}
.faq-list {
    display: flex;
    flex-direction: column;
}
.faq-item {
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
    user-select: none;
}
.faq-question {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 4px;
    font-size: 14px;
    font-weight: 500;
    gap: 12px;
}
.faq-toggle {
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.faq-item.open .faq-toggle {
    transform: rotate(45deg);
}
.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.faq-item.open .faq-answer {
    max-height: 200px;
}
.faq-answer p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin: 0 0 14px;
    padding: 0 4px;
}

/* Responsive: tablet → 2-col features */
@media (max-width: 768px) {
    .features-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive: mobile → 1-col features, smaller heading */
@media (max-width: 520px) {
    .features-grid {
        grid-template-columns: 1fr;
    }
    .landing-hero-heading {
        font-size: clamp(22px, 6vw, 28px);
    }
    .example-chips {
        flex-wrap: wrap;
    }
}

/* ── 25. SITE FOOTER ────────────────────────────────────────────────
   Shown only in landing state (inherits .landing-section show/hide).
   Centered layout: logo → nav row → copyright.
   ─────────────────────────────────────────────────────────────── */
.site-footer {
    padding: 32px 16px 40px;
    border-top: 1px solid var(--border-primary);
}
.site-footer-inner {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    text-align: center;
}
.site-footer-logo {
    opacity: 0.60;
    display: block;
}
.site-footer-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0;
}
/* Bullet-separated links — no default browser link colours */
.site-footer-link,
.site-footer-link:link,
.site-footer-link:visited {
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 2px 14px;
    transition: color 0.15s ease;
}
.site-footer-link:hover {
    color: var(--text-primary);
}
/* Divider dots between links */
.site-footer-link + .site-footer-link {
    border-inline-start: 1px solid var(--border-primary);
}
.site-footer-copy {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

/* ── 26. SCROLL-TO-TOP BUTTON ────────────────────────────────────── */
.scroll-to-top-btn {
    position: fixed;
    bottom: 24px;
    inset-inline-end: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.22s ease, transform 0.22s ease, background 0.15s ease;
    z-index: 200;
    box-shadow: 0 3px 12px rgba(var(--accent-primary-rgb), 0.40);
}
.scroll-to-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.scroll-to-top-btn:hover {
    background: var(--accent-primary-hover);
}
