/* ============================================================
   Hammurabi Tax — Saudi Tax Intelligence
   Dark theme · IBM Plex Sans (Arabic support) · Green-gold accent
   ============================================================ */

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

:root {
    --bg: #0c0f14;
    --bg-elevated: #12161e;
    --card: #181d28;
    --card-hover: #1e2433;
    --border: #242a3a;
    --text: #E8E6E3;
    --text-secondary: #9E9BAD;
    --text-muted: #5E5C6E;
    --accent: #2E7D32;
    --accent-light: #4CAF50;
    --accent-dim: rgba(46, 125, 50, 0.12);
    --gold: #C9A96E;
    --gold-dim: rgba(201, 169, 110, 0.12);
    --danger: #EF5350;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'IBM Plex Sans', 'IBM Plex Sans Arabic', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --sidebar-width: 280px;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }
html, body { height: 100%; height: 100dvh; overflow: hidden; margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--gold); }


/* ── Login ── */

.login-page {
    display: flex; align-items: center; justify-content: center;
    height: 100dvh; padding: 20px; overflow-y: auto;
}

.login-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 40px; width: 100%; max-width: 380px;
}

.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand .brand-icon { font-size: 2.5rem; margin-bottom: 12px; }
.login-brand h1 { font-size: 1.5rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.login-subtitle { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }
.login-error { background: rgba(239,83,80,0.1); border: 1px solid rgba(239,83,80,0.3); border-radius: var(--radius-sm); padding: 10px; color: var(--danger); font-size: 0.85rem; margin-bottom: 16px; text-align: center; }

.form-input {
    width: 100%; padding: 12px 14px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 0.9rem;
    margin-bottom: 12px; transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 20px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 0.875rem; font-weight: 600; border: none; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-full { width: 100%; }
.btn-icon { background: none; border: 1px solid var(--border); color: var(--text-secondary); width: 32px; height: 32px; border-radius: var(--radius-sm); cursor: pointer; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.btn-icon:hover { background: var(--card-hover); color: var(--text); }


/* ── Chat Layout ── */

.chat-layout {
    display: flex; height: 100dvh; overflow: hidden;
}

.chat-sidebar {
    width: var(--sidebar-width); background: var(--bg-elevated); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
}

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

.sidebar-brand { color: var(--text); font-weight: 700; font-size: 0.95rem; letter-spacing: -0.01em; }
.sidebar-brand:hover { color: var(--gold); }

.sidebar-conversations { flex: 1; overflow-y: auto; padding: 8px; }

.conv-item {
    display: block; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-secondary);
    font-size: 0.82rem; margin-bottom: 2px; transition: all 0.1s; text-decoration: none;
}
.conv-item:hover { background: var(--card); color: var(--text); }
.conv-item.active { background: var(--accent-dim); color: var(--accent-light); }
.conv-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-date { display: block; font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

.sidebar-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 0.8rem; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-link { display: block; padding: 6px 0; font-size: 0.8rem; color: var(--text-muted); }
.sidebar-link:hover { color: var(--text); }

/* Language toggle */
.lang-toggle {
    display: flex; gap: 4px; margin-bottom: 10px;
}

.lang-btn {
    flex: 1; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: none; color: var(--text-muted); font-family: var(--font); font-size: 0.75rem;
    font-weight: 600; cursor: pointer; text-align: center; transition: all 0.15s;
}

.lang-btn.active {
    background: var(--accent-dim); color: var(--accent-light); border-color: var(--accent);
}

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

/* RTL layout support */
[dir="rtl"] .chat-layout { flex-direction: row-reverse; }
[dir="rtl"] .chat-sidebar { border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .message-user .message-content { margin-left: 0; margin-right: 40px; }
[dir="rtl"] .input-row { flex-direction: row-reverse; }
[dir="rtl"] .example-btn { text-align: right; }
[dir="rtl"] .chat-welcome { text-align: right; }
[dir="rtl"] .chat-welcome h2 { text-align: center; }
[dir="rtl"] .input-footer { direction: rtl; }
[dir="rtl"] .sidebar-conversations { direction: rtl; }
[dir="rtl"] .conv-item { text-align: right; }
[dir="rtl"] .sidebar-footer { direction: rtl; }
[dir="rtl"] .sidebar-link { text-align: right; }
[dir="rtl"] .confidence-badge { direction: ltr; }
[dir="rtl"] .rendered-md ul, [dir="rtl"] .rendered-md ol { padding-left: 0; padding-right: 24px; }
/* Tables must explicitly get direction — browsers don't propagate dir into tables */
.rendered-md[dir="rtl"] table { direction: rtl; }
.rendered-md[dir="rtl"] th, .rendered-md[dir="rtl"] td { text-align: right; }
.rendered-md[dir="ltr"] table { direction: ltr; }
.rendered-md[dir="ltr"] th, .rendered-md[dir="ltr"] td { text-align: left; }

/* Message text direction is set per-message based on content language */
.message-text { unicode-bidi: isolate; }


/* ── Chat Main ── */

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.chat-mobile-header {
    display: flex; padding: 10px 16px; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
    align-items: center; gap: 12px; font-weight: 600; flex-shrink: 0;
}

/* User avatar + dropdown */
.user-menu { position: relative; margin-left: auto; }
[dir="rtl"] .user-menu { margin-left: 0; margin-right: auto; }

.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--accent-dim);
    color: var(--accent-light); display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700; cursor: pointer; border: 1px solid var(--border);
    transition: all 0.15s;
}
.user-avatar:hover { border-color: var(--accent); }

.user-dropdown {
    display: none; position: absolute; top: 100%; right: 0;
    margin-top: 6px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    padding: 10px; min-width: 180px; z-index: 300;
}
[dir="rtl"] .user-dropdown { right: auto; left: 0; }
.user-menu.open .user-dropdown { display: block; }

.user-dropdown-name { font-size: 0.75rem; color: var(--text-muted); padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-dropdown-link { display: block; padding: 6px 0; font-size: 0.8rem; color: var(--text-secondary); text-decoration: none; }
.user-dropdown-link:hover { color: var(--accent-light); }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}


/* ── Welcome State ── */

.chat-welcome {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex: 1; text-align: center; padding: 40px 20px;
}

.welcome-icon { font-size: 3rem; margin-bottom: 16px; }
.chat-welcome h2 { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 8px; letter-spacing: -0.02em; }
.chat-welcome p { font-size: 0.9rem; color: var(--text-secondary); max-width: 500px; margin-bottom: 28px; }

.welcome-examples { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 520px; }

.example-btn {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 16px; color: var(--text-secondary); font-family: var(--font); font-size: 0.82rem;
    text-align: left; cursor: pointer; transition: all 0.15s; line-height: 1.4;
}
.example-btn:hover { background: var(--card-hover); border-color: var(--accent); color: var(--text); }


/* ── Messages ── */

.message { max-width: 800px; width: 100%; margin: 0 auto; }

.message-user .message-content {
    background: var(--accent-dim); border: 1px solid rgba(46,125,50,0.2); border-radius: var(--radius);
    padding: 14px 18px; margin-left: 40px;
}

.message-assistant .message-content {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px;
}

.message-text {
    font-size: 0.9rem; line-height: 1.6; word-wrap: break-word;
}

.message-user .message-text { white-space: pre-wrap; }

.message-meta { margin-top: 12px; display: flex; gap: 8px; align-items: center; }

.confidence-badge {
    font-size: 0.7rem; font-weight: 600; padding: 3px 10px; border-radius: 20px;
    text-transform: uppercase; letter-spacing: 0.03em;
}
.confidence-high { background: rgba(46,125,50,0.15); color: #66BB6A; }
.confidence-moderate { background: var(--gold-dim); color: var(--gold); }
.confidence-low { background: rgba(239,83,80,0.12); color: var(--danger); }

.model-badge { font-size: 0.65rem; color: var(--text-muted); font-family: var(--font-mono); }

/* Thinking indicator */
.thinking-dots {
    font-size: 0.85rem; color: var(--text-muted); font-style: italic;
    display: flex; align-items: center; gap: 4px;
}

.dots-anim::after {
    content: ''; display: inline-block; width: 20px; text-align: left;
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* Fallback for browsers that don't animate content */
.dots-anim {
    display: inline-block; min-width: 16px;
    animation: pulse-opacity 1.5s ease-in-out infinite;
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Rendered markdown inside messages */
.rendered-md h1 { font-size: 1.15rem; font-weight: 700; color: var(--text); margin: 16px 0 8px; }
.rendered-md h2 { font-size: 1.05rem; font-weight: 700; color: var(--gold); margin: 14px 0 6px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.rendered-md h3 { font-size: 0.95rem; font-weight: 600; color: var(--text); margin: 12px 0 4px; }
.rendered-md p { margin: 4px 0; }
.rendered-md p:empty { display: none; }
.rendered-md br + br { display: none; }
.rendered-md > *:first-child { margin-top: 0; }
.rendered-md > *:last-child { margin-bottom: 0; }
.rendered-md ul, .rendered-md ol { padding-left: 24px; margin: 6px 0; }
.rendered-md ul { list-style: disc outside !important; }
.rendered-md ol { list-style: decimal outside !important; }
.rendered-md li { margin: 3px 0; display: list-item; line-height: 1.5; }
.rendered-md li p { margin: 2px 0; display: inline; }
.rendered-md strong { font-weight: 700; color: #fff; }
.rendered-md em { font-style: italic; color: var(--text-secondary); }
.rendered-md table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.82rem; }
.rendered-md th, .rendered-md td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.rendered-md th { background: var(--bg-elevated); font-weight: 600; color: var(--text-secondary); font-size: 0.75rem; text-transform: uppercase; }
.rendered-md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.rendered-md code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.85em; white-space: pre-wrap; word-break: break-word; overflow-wrap: break-word; }
.message-text { overflow-wrap: break-word; word-wrap: break-word; }
.rendered-md blockquote { border-left: 3px solid var(--gold); padding-left: 12px; color: var(--text-secondary); margin: 12px 0; font-style: italic; }

/* Message footer: confidence + action icons */
.message-footer {
    display: flex; align-items: center; justify-content: flex-end;
    margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border);
}

[dir="rtl"] .message-footer { flex-direction: row-reverse; }

.message-actions {
    display: flex; gap: 4px;
}

.action-icon {
    width: 28px; height: 28px; border: none; border-radius: var(--radius-sm);
    background: none; color: var(--text-muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; padding: 0;
}

.action-icon:hover { background: var(--card-hover); color: var(--accent-light); }

.action-btn {
    padding: 4px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: none; color: var(--text-muted); font-family: var(--font); font-size: 0.7rem;
    cursor: pointer; transition: all 0.15s;
}

.action-btn:hover { background: var(--card-hover); color: var(--text); border-color: var(--accent); }

.citations-panel { margin-top: 12px; }
.citations-panel summary { font-size: 0.75rem; color: var(--text-muted); cursor: pointer; }
.citations-panel summary:hover { color: var(--accent-light); }
.citations-list { margin-top: 8px; }
.citation-item { display: flex; gap: 8px; padding: 4px 0; font-size: 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.04); }
.citation-id { color: var(--accent-light); font-weight: 600; font-family: var(--font-mono); min-width: 100px; }
.citation-doc { color: var(--text-secondary); }


/* ── Input Area ── */

.chat-input-area { padding: 12px 16px 14px; border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; }

.input-row { display: flex; gap: 10px; max-width: 800px; margin: 0 auto; align-items: flex-end; }

#question-input {
    flex: 1; padding: 10px 14px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text); font-family: var(--font); font-size: 0.9rem;
    resize: none; line-height: 1.5; max-height: 120px; transition: border-color 0.15s;
    min-width: 0;
}
#question-input:focus { outline: none; border-color: var(--accent); }
#question-input::placeholder { color: var(--text-muted); font-size: 0.82rem; }

.btn-send {
    width: 40px; height: 40px; border-radius: var(--radius-sm); background: var(--accent);
    color: #fff; border: none; cursor: pointer; display: flex; align-items: center;
    justify-content: center; transition: background 0.15s; flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-light); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.input-footer {
    text-align: center; font-size: 0.6rem; color: var(--text-muted); margin-top: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}


/* ── Sources Page ── */

.sources-page { max-width: 900px; margin: 0 auto; padding: 24px; height: 100dvh; overflow-y: auto; }
.sources-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.back-link { font-size: 0.85rem; color: var(--text-secondary); }
.back-link:hover { color: var(--accent-light); }
.nav-title { font-weight: 700; color: var(--text); }
.sources-content h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 4px; }
.sources-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 24px; }

/* ── Corpus Hero ── */
.sources-hero {
    margin-bottom: 28px;
}

.sources-hero h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 6px;
}

/* Category detail header */
.catdetail-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.catdetail-icon {
    font-size: 2rem;
    line-height: 1;
}

/* ── Category Index Grid ── */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

@media (max-width: 480px) {
    .category-grid {
        grid-template-columns: 1fr;
    }
}

.category-card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.category-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.category-card-icon {
    font-size: 1.8rem;
    margin-bottom: 12px;
    line-height: 1;
}

.category-card-body {
    flex: 1;
}

.category-card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 6px 0;
    line-height: 1.3;
}

.category-card-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0;
}

.category-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.category-card-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-light);
}

.category-card-arrow {
    font-size: 1rem;
    color: var(--accent-light);
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s;
}

.category-card:hover .category-card-arrow {
    opacity: 1;
    transform: translateX(3px);
}

/* ── Corpus Section (per category) ── */
.corpus-section {
    margin-bottom: 36px;
}

.corpus-section-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.corpus-section-icon {
    font-size: 1.5rem;
    line-height: 1;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-dim);
    border-radius: 8px;
}

.corpus-section-info {
    flex: 1;
}

.corpus-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.corpus-count-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--accent-light);
    background: var(--accent-dim);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.corpus-section-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0;
}

/* ── Corpus Cards ── */
.corpus-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.corpus-card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.corpus-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.corpus-card-body {
    flex: 1;
}

.corpus-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
    margin: 0;
}

.corpus-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.04);
}

.corpus-card-lang {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--accent-light);
    background: var(--accent-dim);
    padding: 2px 7px;
    border-radius: 4px;
}

.corpus-card-lang-ar {
    color: #81C784;
    background: rgba(129,199,132,0.1);
}

.corpus-card-langs {
    display: flex;
    gap: 4px;
}

.corpus-card-size {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* Arabic card variant */
.corpus-card-ar {
    border-left: 2px solid rgba(129,199,132,0.3);
}

/* Language divider */
.corpus-lang-divider {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 14px 0 10px;
    padding-left: 4px;
}

/* Overflow / show more */
.corpus-overflow {
    display: none;
}

.corpus-show-more {
    display: block;
    margin: 10px auto 0;
    padding: 8px 20px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--accent-light);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}

.corpus-show-more:hover {
    background: var(--accent-dim);
    border-color: var(--accent-light);
}

/* Empty state */
.corpus-empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Mobile responsive */
@media (max-width: 480px) {
    .corpus-cards {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .corpus-section-header {
        gap: 10px;
    }
    .corpus-section-icon {
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }
    .corpus-section-title {
        font-size: 1rem;
    }
    .corpus-card {
        padding: 12px 14px;
    }
    .corpus-card-title {
        font-size: 0.85rem;
    }
    .sources-page {
        padding: 16px;
    }
}

/* Legacy compatibility */
.source-meta { font-size: 0.7rem; color: var(--text-muted); display: flex; gap: 12px; }

/* Document detail view */
.doc-chunks { display: flex; flex-direction: column; gap: 12px; }
.doc-chunk {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; transition: border-color 0.15s;
}
.doc-chunk:hover { border-color: rgba(46,125,50,0.3); }
.chunk-header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.chunk-num { font-size: 0.65rem; font-weight: 700; color: var(--accent-light); min-width: 28px; }
.chunk-article { font-size: 0.7rem; font-weight: 600; color: var(--text); background: var(--accent-dim); padding: 2px 8px; border-radius: 4px; }
.chunk-citation { font-size: 0.6rem; color: var(--text-muted); font-family: var(--font-mono, monospace); margin-left: auto; }
.chunk-text { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }


/* ── Landing Page ── */

.landing-page {
    display: flex; flex-direction: column;
    align-items: center; padding: 0 20px 40px;
    flex: 1; overflow-y: auto;
    min-height: 0;
}

/* Override body overflow:hidden for landing and sources pages */
html.page-landing, html.page-landing body { overflow-y: auto !important; height: auto !important; }

.landing-top-bar {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; flex-shrink: 0;
    padding: 12px 24px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

@media (min-width: 768px) {
    .landing-top-bar { padding: 14px 48px; }
}

.lang-toggle-landing { display: flex; gap: 4px; }
.lang-btn-landing {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: none; color: var(--text-muted); font-family: var(--font); font-size: 0.75rem;
    font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.lang-btn-landing.active { background: var(--accent-dim); color: var(--accent-light); border-color: var(--accent); }

.landing-auth-btn {
    padding: 8px 20px; border: 1px solid var(--accent); border-radius: var(--radius-sm);
    color: var(--accent-light); font-size: 0.82rem; font-weight: 600; text-decoration: none;
    transition: all 0.15s;
}
.landing-auth-btn:hover { background: var(--accent-dim); }

/* Landing page user avatar */
.user-menu-landing { position: relative; }
.user-avatar-landing {
    width: 36px; height: 36px; border-radius: 50%; background: var(--accent-dim);
    color: var(--accent-light); display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700; cursor: pointer; border: 1px solid var(--border);
    transition: all 0.15s;
}
.user-avatar-landing:hover { border-color: var(--accent); }
.user-dropdown-landing {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 6px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4); padding: 10px; min-width: 140px; z-index: 300;
}
.user-menu-landing.open .user-dropdown-landing { display: block; }
.dropdown-name { font-size: 0.75rem; color: var(--text-muted); padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown-link { display: block; padding: 6px 0; font-size: 0.8rem; color: var(--text-secondary); text-decoration: none; }
.dropdown-link:hover { color: var(--accent-light); }

.landing-header { text-align: center; margin-bottom: 36px; margin-top: auto; }
.landing-icon { font-size: 3.5rem; display: block; margin-bottom: 16px; }
.landing-header h1 { font-size: 2.5rem; font-weight: 700; color: var(--text); letter-spacing: -0.03em; margin-bottom: 8px; }
.landing-tagline { font-size: 1.1rem; color: var(--text-secondary); }
.landing-tagline-ar { font-size: 1rem; color: var(--text-muted); direction: rtl; margin-top: 4px; font-family: 'IBM Plex Sans Arabic', sans-serif; }

.landing-modules {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px; max-width: 1100px; width: 100%; padding: 0 20px;
}

.module-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 28px 24px; text-decoration: none; transition: all 0.2s;
    border-top: 3px solid var(--module-color, var(--accent));
}

.module-card:hover {
    transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    border-color: var(--module-color, var(--accent));
}

.module-icon { font-size: 2rem; margin-bottom: 12px; }
.module-card h2 { font-size: 1.15rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
/* Module Arabic name hidden — language toggle handles it */
.module-desc { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; }

.landing-footer { text-align: center; margin-top: auto; padding: 32px 20px 0; max-width: 600px; }
.landing-footer p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; }
.landing-footer-ar { direction: rtl; font-family: 'IBM Plex Sans Arabic', sans-serif; margin-top: 8px; }


/* ── Mobile ── */

@media (max-width: 768px) {
    .chat-sidebar { position: fixed; top: 0; bottom: 0; z-index: 200; width: 280px; transition: left 0.2s, right 0.2s; left: -100%; right: auto; }
    .chat-sidebar.open { left: 0; }

    [dir="rtl"] .chat-sidebar { left: auto; right: -100%; }
    [dir="rtl"] .chat-sidebar.open { right: 0; }

    .sidebar-overlay {
        display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5); z-index: 150;
        -webkit-tap-highlight-color: transparent;
    }
    .sidebar-overlay.visible { display: block; }
    /* Mobile: sidebar hidden, header already visible */

    .message-user .message-content { margin-left: 0; }

    #question-input { font-size: 16px; padding: 10px 12px; }
    #question-input::placeholder { font-size: 0.78rem; }

    .chat-input-area { padding: 10px 12px 14px; }
    .input-row { gap: 8px; }
    .input-footer { font-size: 0.55rem; }

    .welcome-examples { max-width: 100%; }
    .example-btn { font-size: 0.8rem; }
}
