/* AI Belajar Qanun Asasi PBNU — design system (lihat design.md). Komponen hanya memakai token semantik. */

/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #FBFAF5;
  --surface: #FFFFFF;
  --surface-2: #F2F5EF;
  --surface-3: #EEF7F1;
  --border: #E1E6DE;
  --border-strong: #C9D3C6;
  --text: #1A2620;
  --text-muted: #55635B;
  --text-on-primary: #FFFFFF;
  --primary: #077A37;
  --primary-hover: #05652D;
  --brand-mark: #099543;
  --accent: #C9A227;
  --accent-text: #8A6D0F;
  --link: #05652D;
  --highlight: #D6EEDF;
  --danger: #C62828;
  --ring: #099543;
  --grad-greeting: linear-gradient(90deg, #099543 0%, #3DBE74 45%, #C9A227 100%);
  --grad-thinking: conic-gradient(from 0deg, #099543, #C9A227, #3DBE74, #099543);
  --shadow-input: 0 1px 2px rgba(11, 59, 36, .06), 0 4px 16px rgba(11, 59, 36, .06);
  --shadow-pop: 0 8px 24px rgba(11, 59, 36, .12);
  --pattern-opacity: .04;
  --scrim: rgba(14, 21, 18, .38);

  --r-sm: 8px; --r-md: 12px; --r-lg: 20px; --r-pill: 28px; --r-full: 9999px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ar: "Amiri", "Noto Naskh Arabic", "Traditional Arabic", serif;
  --font-serif: "EB Garamond", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sidebar-w: 280px; --rail-w: 72px; --panel-w: 400px;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --scale: 1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1512; --surface: #16201B; --surface-2: #1C2822; --surface-3: #0B3B24;
    --border: #26342D; --border-strong: #34463C;
    --text: #E8EDE9; --text-muted: #A3B0A8; --text-on-primary: #0E1512;
    --primary: #3DBE74; --primary-hover: #5ACB88; --brand-mark: #3DBE74;
    --accent: #E0C060; --accent-text: #E0C060; --link: #5ACB88; --highlight: #0B3B24;
    --ring: #3DBE74; --shadow-input: none; --shadow-pop: none; --pattern-opacity: .06;
    --scrim: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1512; --surface: #16201B; --surface-2: #1C2822; --surface-3: #0B3B24;
  --border: #26342D; --border-strong: #34463C;
  --text: #E8EDE9; --text-muted: #A3B0A8; --text-on-primary: #0E1512;
  --primary: #3DBE74; --primary-hover: #5ACB88; --brand-mark: #3DBE74;
  --accent: #E0C060; --accent-text: #E0C060; --link: #5ACB88; --highlight: #0B3B24;
  --ring: #3DBE74; --shadow-input: none; --shadow-pop: none; --pattern-opacity: .06;
  --scrim: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(16px * var(--scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1rem/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--link); }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--primary); color: var(--text-on-primary); padding: 10px 16px; border-radius: var(--r-sm); text-decoration: none; font-weight: 600; transition: top 150ms ease-out; }
.skip-link:focus { top: 12px; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
[lang="ar"], .ar { font-family: var(--font-ar); letter-spacing: 0 !important; }

.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: var(--r-full);
  color: var(--text-muted); transition: background-color 150ms ease-out, color 150ms ease-out;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--primary); }
.text-btn { min-height: 44px; padding: 0 12px; border-radius: var(--r-full); color: var(--text-muted); font-size: .875rem; font-weight: 600; transition: background-color 150ms ease-out; }
.text-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------------------------------------------------------------- layout */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface-2); display: flex; flex-direction: column;
  padding: 12px; gap: 8px; overflow: hidden; transition: width 250ms var(--ease);
  border-right: 1px solid transparent;
}
.app[data-sidebar="closed"] .sidebar { width: var(--rail-w); }
.app[data-sidebar="closed"] .sidebar .hide-rail { display: none; }
.sb-top { display: flex; align-items: center; gap: 4px; min-height: 52px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: .95rem; line-height: 1.2; min-width: 0; }
.brand img { height: 32px; width: auto; }
.brand small { display: block; font-weight: 500; color: var(--text-muted); font-size: .75rem; }
.new-chat {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: var(--r-full);
  background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: .9rem; color: var(--text);
  transition: background-color 150ms ease-out; white-space: nowrap; margin-top: 4px;
}
.new-chat:hover { background: var(--surface-3); }
.new-chat .i { color: var(--primary); }
.app[data-sidebar="closed"] .new-chat { width: 48px; padding: 0; justify-content: center; }

.history { flex: 1; overflow-y: auto; margin: 8px -4px 0; padding: 0 4px; scrollbar-width: thin; }
.history h2 { font-size: .75rem; font-weight: 600; color: var(--text-muted); margin: 16px 12px 6px; letter-spacing: .02em; }
.history .empty { font-size: .875rem; color: var(--text-muted); padding: 8px 12px; line-height: 1.5; }
.h-item { position: relative; display: flex; align-items: center; border-radius: var(--r-full); }
.h-item > a {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 44px 0 14px;
  font-size: .875rem; line-height: 1.5; color: var(--text); text-decoration: none; border-radius: var(--r-full);
}
.h-item > a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-item > a .i { width: 14px; height: 14px; color: var(--accent-text); }
.h-item:hover > a { background: var(--surface-3); }
.h-item.active > a { background: var(--surface-3); color: var(--primary); font-weight: 600; }
.h-item .h-more { position: absolute; right: 2px; width: 40px; height: 40px; opacity: 0; }
.h-item:hover .h-more, .h-item.active .h-more, .h-item .h-more:focus-visible, .h-item .h-more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .h-item .h-more { opacity: 1; } }

.sb-bottom { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.sb-link { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-full); font-size: .875rem; color: var(--text); white-space: nowrap; text-align: left; }
.sb-link:hover { background: var(--surface-3); }
.sb-link .i { color: var(--text-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { height: 64px; flex: none; display: flex; align-items: center; gap: 4px; padding: 0 12px; position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); }
.topbar .spacer { flex: 1; }
.mobile-only { display: none; }
.mode-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border-radius: var(--r-sm); font-size: 1.1rem; font-weight: 600; color: var(--text); }
.mode-btn:hover { background: var(--surface-3); }
.mode-btn .mode-title, .mode-btn .mode-name { white-space: nowrap; }
.mode-btn .mode-name { font-size: .8rem; font-weight: 600; color: var(--accent-text); background: var(--surface-3); border-radius: var(--r-full); padding: 2px 10px; }
.mode-btn .i { width: 16px; height: 16px; color: var(--text-muted); }
.zoom-group { display: inline-flex; align-items: center; }
.zoom-group .text-btn { padding: 0 10px; min-width: 44px; font-size: .9rem; }

/* ---------------------------------------------------------------- chat area */
.chat { flex: 1; overflow-y: auto; position: relative; scroll-behavior: smooth; }
.column { max-width: 760px; margin: 0 auto; padding: 0 24px; }

.welcome { position: relative; min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 24px 0 48px; }
.welcome::before {
  content: ""; position: absolute; inset: -64px 0 0; pointer-events: none; opacity: var(--pattern-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23099543' stroke-width='1.4'%3E%3Crect x='28' y='28' width='40' height='40'/%3E%3Crect x='28' y='28' width='40' height='40' transform='rotate(45 48 48)'/%3E%3Ccircle cx='48' cy='48' r='9'/%3E%3Cpath d='M0 48h20M76 48h20M48 0v20M48 76v20'/%3E%3Crect x='-12' y='-12' width='24' height='24' transform='rotate(45 0 0)'/%3E%3Crect x='84' y='-12' width='24' height='24' transform='rotate(45 96 0)'/%3E%3Crect x='-12' y='84' width='24' height='24' transform='rotate(45 0 96)'/%3E%3Crect x='84' y='84' width='24' height='24' transform='rotate(45 96 96)'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 45%, #000 20%, transparent 75%);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 45%, #000 20%, transparent 75%);
}
:root[data-theme="dark"] .welcome::before { filter: brightness(1.6); }
.welcome > * { position: relative; }
.greeting {
  font-size: 2.75rem; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; margin: 0;
  background: var(--grad-greeting); background-size: 200% 100%; background-position: 100% 0;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: greet-in 600ms var(--ease) both;
}
@keyframes greet-in { from { background-position: 0 0; opacity: 0; transform: translateY(6px); } to { background-position: 100% 0; opacity: 1; transform: none; } }
.subtitle { font-size: 1.75rem; line-height: 1.25; font-weight: 600; color: var(--text-muted); margin: 4px 0 32px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.card {
  position: relative; min-height: 120px; text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 6px;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.card:hover { background: var(--surface-3); border-color: var(--border-strong); }
.card .label { font-size: .75rem; font-weight: 600; color: var(--accent-text); letter-spacing: .02em; }
.card .prompt { font-size: .875rem; line-height: 1.5; color: var(--text); }
.card .i { position: absolute; right: 12px; bottom: 12px; color: var(--brand-mark); width: 22px; height: 22px; }

/* ---------------------------------------------------------------- messages */
.messages { padding: 24px 0 24px; display: flex; flex-direction: column; gap: 28px; }
.msg { animation: msg-in 200ms ease-out both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { display: flex; justify-content: flex-end; }
.user-bubble {
  max-width: 80%; background: var(--surface-3); border-radius: var(--r-lg) 6px var(--r-lg) var(--r-lg); padding: 12px 16px;
  white-space: pre-wrap; overflow-wrap: anywhere; position: relative;
}
.user-wrap { display: flex; align-items: flex-start; gap: 4px; max-width: 100%; justify-content: flex-end; }
.user-tools { display: flex; opacity: 0; transition: opacity 150ms ease-out; }
.user-wrap:hover .user-tools, .user-tools:focus-within { opacity: 1; }
.user-tools .icon-btn { width: 40px; height: 40px; }
.user-tools .i { width: 18px; height: 18px; }

.msg.ai { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 16px; }
.ai-avatar { width: 28px; height: 28px; color: var(--brand-mark); margin-top: 2px; position: relative; }
.ai-avatar svg { width: 28px; height: 28px; display: block; }
.msg.ai.busy .ai-avatar::before {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; background: var(--grad-thinking);
  -webkit-mask: radial-gradient(circle, transparent 62%, #000 64%); mask: radial-gradient(circle, transparent 62%, #000 64%);
  animation: spin 4s linear infinite;
}
.msg.ai.busy .ai-avatar svg { animation: spin 4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.thinking { font-size: .875rem; color: var(--text-muted); min-height: 28px; display: flex; flex-direction: column; gap: 4px; }
.thinking .stage { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.thinking .stage-text { animation: stage-in 200ms ease-out both; }
@keyframes stage-in { from { opacity: 0; } to { opacity: 1; } }
.found { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px 0 10px; border-radius: var(--r-full); background: var(--surface-2); font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.found:hover { background: var(--surface-3); color: var(--text); }
.found .i { width: 16px; height: 16px; transition: transform 150ms ease-out; }
.found[aria-expanded="true"] .i.chev { transform: rotate(180deg); }
.found-list { margin: 4px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; font-size: .8rem; }
.found-list li { color: var(--text-muted); }
.verified { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; font-weight: 500; color: var(--text-muted); margin-top: 6px; }
.verified .i { width: 14px; height: 14px; color: var(--brand-mark); }

/* jawaban markdown */
.answer { overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 .9em; }
.answer h1, .answer h2 { font-size: 1.375rem; line-height: 1.3; font-weight: 600; margin: 1.2em 0 .5em; }
.answer h3, .answer h4 { font-size: 1.125rem; line-height: 1.4; font-weight: 600; margin: 1.1em 0 .4em; }
.answer ul, .answer ol { padding-left: 1.4em; margin: 0 0 .9em; }
.answer li { margin: .25em 0; }
.answer li::marker { color: var(--accent-text); }
.answer strong { font-weight: 700; }
.answer blockquote { margin: 0 0 .9em; padding: 4px 0 4px 16px; border-left: 3px solid var(--accent); color: var(--text-muted); }
.answer table { border-collapse: collapse; width: 100%; margin: 0 0 1em; font-size: .9rem; display: block; overflow-x: auto; }
.answer th, .answer td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.answer code { font-family: var(--font-mono); font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.answer.refusal { color: var(--text); }
.answer.refusal p:first-child::before { content: ""; }
.caret { display: inline-block; width: .55em; height: 1.1em; vertical-align: -.18em; background: var(--brand-mark); margin-left: 2px; border-radius: 1px; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.cite {
  display: inline-grid; place-items: center; min-width: 1.45em; height: 1.45em; padding: 0 .3em; margin: 0 1px;
  font-size: .72em; font-weight: 700; line-height: 1; vertical-align: .35em; border-radius: 6px;
  background: var(--surface-3); color: var(--link); border: 1px solid transparent; transition: border-color 150ms ease-out;
  position: relative;
}
.cite::after { content: ""; position: absolute; inset: -10px -4px; }  /* perbesar target sentuh */
.cite:hover { border-color: var(--link); }

/* blok kutipan Arab */
.arab-block { margin: 1.1em 0; background: var(--surface); border-radius: var(--r-md); padding: 8px 24px 16px; border: 1px solid var(--border); }
.gold-rule { display: flex; align-items: center; gap: 10px; color: var(--accent); margin: 8px 0; }
.gold-rule::before, .gold-rule::after { content: ""; flex: 1; height: 1px; background: var(--accent); opacity: .8; }
.gold-rule span { font-size: 10px; line-height: 1; }
.arab-text { font-family: var(--font-ar); font-size: 1.5rem; line-height: 2; text-align: right; margin: 8px 0; white-space: pre-line; color: var(--text); }
.arab-tr { font-style: italic; color: var(--text-muted); margin: 4px 0; }
.arab-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; margin-top: 4px; }
.arab-src { font-size: .75rem; font-weight: 500; color: var(--accent-text); line-height: 1.4; }
.arab-tools { display: flex; align-items: center; gap: 2px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-full); padding: 2px; }
.seg button { min-height: 32px; padding: 0 10px; border-radius: var(--r-full); font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--primary); }
.arab-tools .icon-btn { width: 40px; height: 40px; }
.arab-tools .icon-btn .i { width: 18px; height: 18px; }
.arab-block[data-view="ar"] .arab-tr { display: none; }
.arab-block[data-view="tr"] .arab-text { display: none; }
.ocr-note { font-size: .75rem; color: var(--accent-text); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: var(--r-sm); padding: 2px 8px; }

/* chip rujukan */
.src-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.src-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; max-width: 100%; padding: 6px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface); font-size: .8rem; line-height: 1.35; color: var(--text); text-align: left;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.src-chip:hover { background: var(--surface-3); border-color: var(--border-strong); }
.src-chip .n { font-weight: 700; color: var(--link); }
.src-chip .i { width: 16px; height: 16px; color: var(--brand-mark); }
.src-chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 10px 0 0 -10px; }
.actions .icon-btn { width: 40px; height: 40px; }
.actions .text-btn { min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
.actions .icon-btn[aria-pressed="true"] { color: var(--primary); background: var(--surface-3); }

/* ---------------------------------------------------------------- composer */
.composer { flex: none; padding: 0 24px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer .column { padding: 0; }
.pill {
  background: var(--surface-2); border-radius: var(--r-pill); border: 2px solid transparent; padding: 8px 8px 8px 20px;
  box-shadow: var(--shadow-input); transition: border-color 150ms ease-out;
}
.pill:focus-within { border-color: var(--ring); }
.pill textarea {
  display: block; width: 100%; resize: none; border: 0; background: transparent; outline: none; padding: 8px 4px 4px 0;
  min-height: 40px; max-height: 200px; line-height: 1.5; font-size: 1rem; color: var(--text);
}
.pill textarea::placeholder { color: var(--text-muted); }
.pill-row { display: flex; align-items: center; gap: 4px; margin-left: -12px; }
.pill-row .spacer { flex: 1; }
.src-filter { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border-radius: var(--r-full); font-size: .8rem; font-weight: 600; color: var(--text-muted); max-width: 60vw; }
.src-filter span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-filter:hover { background: var(--surface-3); color: var(--text); }
.src-filter .i { width: 16px; height: 16px; }
.send {
  width: 40px; height: 40px; border-radius: var(--r-full); display: grid; place-items: center; flex: none;
  background: var(--primary); color: var(--text-on-primary); transition: background-color 150ms ease-out, opacity 150ms ease-out;
}
.send:hover { background: var(--primary-hover); }
.send:disabled { background: var(--border-strong); color: var(--surface); cursor: default; opacity: .7; }
.send .i { width: 20px; height: 20px; stroke-width: 2.2; }
.send.stop .i { fill: currentColor; stroke: none; width: 14px; height: 14px; }
.disclaimer { margin: 8px 0 0; font-size: .75rem; line-height: 1.4; text-align: center; color: var(--text-muted); font-weight: 500; }

/* ---------------------------------------------------------------- menu & popover */
.menu {
  position: fixed; z-index: 60; min-width: 220px; max-width: min(360px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop); padding: 6px; animation: pop-in 150ms ease-out both;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu [role="menuitem"], .menu [role="menuitemradio"] {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 6px 12px; border-radius: var(--r-sm);
  font-size: .875rem; text-align: left; color: var(--text); line-height: 1.35;
}
.menu [role^="menuitem"]:hover, .menu [role^="menuitem"]:focus-visible { background: var(--surface-3); outline: none; }
.menu .i { width: 18px; height: 18px; color: var(--text-muted); }
.menu .check { margin-left: auto; color: var(--primary); visibility: hidden; }
.menu [aria-checked="true"] .check { visibility: visible; }
.menu .desc { display: block; font-size: .75rem; color: var(--text-muted); }
.menu .danger, .menu .danger .i { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------------------------------------------------------------- panel rujukan */
.source-panel {
  width: var(--panel-w); flex: none; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column;
  animation: panel-in 250ms var(--ease) both;
}
.source-panel.closing { animation: panel-out 180ms ease-in both; }
@keyframes panel-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes panel-out { to { transform: translateX(24px); opacity: 0; } }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 20px; border-bottom: 1px solid var(--border); min-height: 64px; }
.panel-head h2 { flex: 1; margin: 0; font-size: 1.125rem; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.src-card { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; background: var(--surface); transition: background-color 250ms ease-out, border-color 250ms ease-out; scroll-margin: 16px; }
.src-card.active { background: var(--highlight); border-color: var(--brand-mark); }
.src-card header { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.src-card .num { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-sm); background: var(--surface-3); color: var(--link); font-weight: 700; font-size: .8rem; }
.src-card.active .num { background: var(--surface); }
.src-card .title { font-weight: 600; font-size: .9rem; line-height: 1.4; }
.src-card .meta { font-size: .75rem; color: var(--text-muted); line-height: 1.4; margin-top: 2px; }
.src-card .open-pdf { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; font-size: .8rem; font-weight: 600; color: var(--link); text-decoration: none; }
.src-card .open-pdf .i { width: 16px; height: 16px; }
.src-body { font-size: .9rem; line-height: 1.7; }
.src-body p { margin: 0 0 .7em; white-space: pre-line; }
.src-body h3 { font-size: .85rem; font-weight: 700; margin: .8em 0 .3em; color: var(--accent-text); }
.src-body .arab-text { font-size: 1.3rem; }
.src-body .arab-block { padding: 4px 16px 12px; }
.src-toggle { min-height: 36px; font-size: .8rem; font-weight: 600; color: var(--link); padding: 0; }
.src-card.collapsed .src-body { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }

/* ---------------------------------------------------------------- dialog & toast */
dialog {
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); color: var(--text); padding: 0;
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: var(--scrim); }
dialog[open] { animation: pop-in 180ms ease-out both; }
.dlg { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font-size: 1.375rem; line-height: 1.3; font-weight: 600; }
.dlg p { margin: 0; color: var(--text-muted); font-size: .9rem; }
.dlg label { font-size: .875rem; font-weight: 600; }
.dlg input[type="text"], .dlg textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--bg); padding: 10px 12px; min-height: 44px; font-size: 1rem;
}
.dlg textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.dlg input:focus, .dlg textarea:focus { outline: 2px solid var(--ring); outline-offset: 0; border-color: transparent; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.btn { min-height: 44px; padding: 0 20px; border-radius: var(--r-full); font-weight: 600; font-size: .9rem; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); transition: background-color 150ms ease-out; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--text-on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.reasons { display: flex; flex-wrap: wrap; gap: 8px; }
.reasons button { min-height: 40px; padding: 0 14px; border-radius: var(--r-full); border: 1px solid var(--border-strong); font-size: .8rem; font-weight: 500; }
.reasons button[aria-pressed="true"] { background: var(--surface-3); border-color: var(--primary); color: var(--primary); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.setting-row .seg button { min-height: 40px; padding: 0 14px; font-size: .8rem; }

.about { width: min(640px, calc(100vw - 32px)); }
.about .dlg { gap: 12px; }
.about-head { display: flex; align-items: center; gap: 14px; }
.about-head img { height: 48px; width: auto; }
.about h2 { font-family: var(--font-serif); font-size: 1.75rem; font-weight: 600; }
.about h3 { margin: 8px 0 0; font-size: 1rem; font-weight: 600; }
.about p, .about li { color: var(--text); font-size: .925rem; line-height: 1.7; }
.about ul { margin: 0; padding-left: 1.2em; }
.about .cite-line { font-size: .75rem; color: var(--accent-text); font-weight: 500; }
.about .rule { margin: 4px 0; }

.toasts { position: fixed; z-index: 80; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-left: 3px solid var(--brand-mark); border-radius: var(--r-md); padding: 10px 10px 10px 14px; box-shadow: var(--shadow-pop); font-size: .875rem; line-height: 1.45;
  animation: pop-in 180ms ease-out both;
}
.toast.error { border-left-color: var(--danger); }
.toast span { flex: 1; }
.toast .btn { min-height: 36px; padding: 0 14px; font-size: .8rem; }

.scrim { display: none; }

/* ---------------------------------------------------------------- responsif */
@media (max-width: 1279px) {
  .source-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow-pop); max-width: 100vw; }
}
@media (max-width: 1023px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; width: var(--sidebar-w) !important; transform: translateX(-100%); transition: transform 250ms var(--ease); box-shadow: var(--shadow-pop); }
  .app[data-drawer="open"] .sidebar { transform: none; }
  .app[data-sidebar="closed"] .sidebar .hide-rail { display: revert; }
  .app[data-sidebar="closed"] .new-chat { width: auto; padding: 0 14px; justify-content: flex-start; }
  .app[data-drawer="open"] .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: var(--scrim); }
  .mobile-only { display: inline-grid; }
  .desktop-only { display: none !important; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 767px) {
  .column { padding: 0 16px; }
  .composer { padding: 0 12px calc(8px + env(safe-area-inset-bottom)); }
  .greeting { font-size: 2.125rem; }
  .subtitle { font-size: 1.375rem; margin-bottom: 24px; }
  .card { min-height: 104px; padding: 12px 14px 36px; }
  .msg.ai { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .user-bubble { max-width: 88%; }
  .zoom-group { display: none; }
  .mode-btn { font-size: 1rem; padding: 0 8px; min-width: 0; }
  .mode-btn .mode-title { display: none; }
  .source-panel { top: auto; left: 0; width: 100%; height: min(78dvh, 640px); border-left: 0; border-top: 1px solid var(--border); border-radius: var(--r-lg) var(--r-lg) 0 0; animation-name: sheet-in; }
  .source-panel.closing { animation-name: sheet-out; }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes sheet-out { to { transform: translateY(40px); opacity: 0; } }
  .arab-block { padding: 6px 14px 12px; }
  .arab-text { font-size: 1.375rem; }
  .toasts { bottom: calc(120px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 100ms !important; animation-iteration-count: 1 !important; transition-duration: 100ms !important; scroll-behavior: auto !important; }
  .msg.ai.busy .ai-avatar svg, .msg.ai.busy .ai-avatar::before { animation: none !important; }
  .source-panel, .source-panel.closing { animation-name: fade-in !important; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
}
