/* GenBI web UI — the "Generative BI" design on the Nocturne system.
   Tokens are the design's own; every size below is taken from it. */

@font-face { font-family: 'Vazirmatn'; src: url('/static/Vazirmatn.woff2') format('woff2');
             font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/static/JetBrainsMono.woff2') format('woff2');
             font-weight: 400; font-display: swap; }

:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161826; --bg2: #1a1c2a; --surface: #212331; --surface2: #2a2c3b;
  --text: #e9e9ed; --muted: #b2b6ca; --faint: #8b8fa3;
  --line: rgba(233,233,237,.1); --line2: rgba(233,233,237,.18);
  --purple: #9d91e6; --purple-ink: #d2cefd; --purple-soft: #2b2741; --purple-mid: #5d5294; --purple2: #c7bfff;
  --green: oklch(0.74 0.13 162); --green-ink: oklch(0.87 0.08 162); --green-soft: oklch(0.28 0.045 165);
  --green2: oklch(0.62 0.1 170); --green3: oklch(0.85 0.1 150);
  --warn: #e0a458; --danger: #e8837a;
  --shadow: 0 0 0 1px #33364a;
  --shadow-lg: 0 0 0 1px #4a4e60, 0 14px 36px rgba(0,0,0,.45);
  --code: #12131e;
  --backdrop: rgba(10,11,18,.62);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f8; --bg2: #ededf2; --surface: #fcfcfd; --surface2: #f0f0f5;
  --text: #1d1f2b; --muted: #565a6a; --faint: #7c8091;
  --line: rgba(29,31,43,.09); --line2: rgba(29,31,43,.17);
  --purple: #6557bd; --purple-ink: #4a3f97; --purple-soft: #eeebfb; --purple-mid: #cbc4f5; --purple2: #9d91e6;
  --green: oklch(0.56 0.12 162); --green-ink: oklch(0.42 0.1 162); --green-soft: oklch(0.95 0.03 162);
  --green2: oklch(0.68 0.11 170); --green3: oklch(0.44 0.08 150);
  --warn: #9a5b00; --danger: #b8392f;
  --shadow: 0 0 0 1px rgba(29,31,43,.08), 0 1px 2px rgba(29,31,43,.04);
  --shadow-lg: 0 0 0 1px rgba(29,31,43,.09), 0 14px 34px rgba(29,31,43,.12);
  --code: #f0f0f5;
  --backdrop: rgba(29,31,43,.32);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: Vazirmatn, system-ui, sans-serif; font-size: 14px; line-height: 1.7;
       scrollbar-color: var(--line2) transparent; -webkit-font-smoothing: antialiased; }
input, button, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
a { color: var(--purple); } a:hover { color: var(--purple-ink); }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
::selection { background: var(--purple-mid); color: var(--text); }
.ph, .ph-bold { line-height: 1; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- shell */
.app { min-height: 100vh; display: flex; background: var(--bg); color: var(--text); }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--faint); }

.aside { width: 272px; flex: none; display: flex; flex-direction: column; gap: 18px; padding: 18px 14px;
         background: var(--bg2); border-left: 1px solid var(--line); position: sticky; top: 0; height: 100vh; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--purple-soft); display: grid;
              place-items: center; box-shadow: inset 0 0 0 1px var(--purple-mid); flex: none; }
.brand-mark i { font-size: 17px; color: var(--green); }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text b { font-weight: 600; font-size: 14px; }
.brand-text span { font-size: 11.5px; color: var(--faint); }

.btn-new { display: flex; align-items: center; justify-content: center; gap: 8px; height: 38px; border-radius: 8px;
           border: 1px solid var(--purple); background: transparent; color: var(--purple); font-size: 13.5px; font-weight: 500; }
.btn-new:hover { background: var(--purple-soft); }
.btn-new:active { background: var(--purple-mid); color: var(--purple-ink); }

.search { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: 8px;
          background: var(--surface); box-shadow: var(--shadow); color: var(--faint); font-size: 13px; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 13px; color: var(--text); padding: 0; }
.search input::placeholder { color: var(--faint); }
.search:focus-within { box-shadow: 0 0 0 1px var(--purple); }

.chat-list { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.group-label { font-size: 11.5px; color: var(--faint); padding: 4px 10px; }
.group-label + .chat-row { margin-top: 0; }
.chat-list .group-label:not(:first-child) { padding-top: 12px; }
.chat-row { position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px;
            font-size: 13px; color: var(--muted); cursor: pointer; border: 0; background: transparent; text-align: right; width: 100%; }
.chat-row:hover { background: var(--surface2); }
.chat-row.active { background: var(--surface2); color: var(--text); }
.chat-row > .ph { font-size: 14px; opacity: .7; flex: none; }
.chat-row .title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-row .row-actions { display: none; gap: 2px; flex: none; }
.chat-row:hover .row-actions, .chat-row:focus-within .row-actions { display: flex; }
.chat-row:hover .row-busy { display: none; }
.icon-mini { width: 24px; height: 24px; border-radius: 6px; border: 0; background: transparent; color: var(--faint);
             display: grid; place-items: center; font-size: 13px; }
.icon-mini:hover { background: var(--surface); color: var(--text); }
.chat-rename { flex: 1; min-width: 0; border: 0; outline: none; background: var(--surface); border-radius: 5px;
               box-shadow: 0 0 0 1px var(--purple); padding: 1px 6px; font-size: 13px; color: var(--text); }
.empty-note { font-size: 12.5px; color: var(--faint); padding: 6px 10px; }

.aside-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.foot-link { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; font-size: 13px;
             color: var(--muted); border: 0; background: transparent; text-align: right; width: 100%; }
.foot-link:hover { background: var(--surface2); color: var(--text); }
.profile { display: flex; align-items: center; gap: 10px; padding: 10px 10px 2px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--green-soft); color: var(--green-ink);
          display: grid; place-items: center; font-size: 14px; flex: none; }
.profile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.profile-text span:first-child { font-size: 13px; }
.profile-text span:last-child { font-size: 11px; color: var(--faint); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.gear { width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--faint);
        font-size: 16px; display: grid; place-items: center; }
.gear:hover { background: var(--surface2); color: var(--text); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); flex: none; }
.topbar .conv-title { font-weight: 500; font-size: 14.5px; min-width: 0; flex: 0 1 auto; overflow: hidden;
                      white-space: nowrap; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 3px 10px;
        border-radius: 6px; background: var(--surface2); white-space: nowrap; flex: none; }
.pill .ph { color: var(--green); }
.spacer { flex: 1; }
.btn-icon { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line2); background: transparent;
            color: var(--muted); display: grid; place-items: center; flex: none; }
.btn-icon .ph { font-size: 16px; }
.btn-icon:hover { background: var(--surface2); }
.btn-outline { text-decoration: none; display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px;
               border: 1px solid var(--line2); background: transparent; color: var(--text); font-size: 13px;
               white-space: nowrap; flex: none; }
.btn-outline:hover { background: var(--surface2); }
.menu-toggle { display: none; }

.scroll { flex: 1; overflow: auto; overflow-anchor: none; }
.thread { max-width: 880px; margin: 0 auto; padding: 32px 28px 40px; display: flex; flex-direction: column; gap: 28px; }

/* ---------------------------------------------------------------- welcome */
.welcome { display: flex; flex-direction: column; gap: 28px; padding-top: 6vh; animation: rise .3s ease both; }
.welcome-head { display: flex; flex-direction: column; gap: 8px; }
.core-picker { display: flex; flex-direction: column; gap: 10px; }
.core-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.core-label { flex-shrink: 0; }
.fresh { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; font-size: 12px; color: var(--green-ink);
         background: var(--green-soft); padding: 3px 10px; border-radius: 6px; white-space: nowrap; }
.welcome h1 { margin: 0; font-size: 32px; font-weight: 600; line-height: 1.35; letter-spacing: 0; }
.welcome p { margin: 0; color: var(--muted); font-size: 15px; max-width: 600px; text-wrap: pretty; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line);
         border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.stat { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; }
.stat span:first-child { font-size: 12px; color: var(--faint); }
.stat span:last-child { font-size: 22px; font-weight: 600; }
.starters { display: flex; flex-direction: column; gap: 10px; }
.starters > span { font-size: 13px; color: var(--faint); }
.starter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.starter { text-align: right; display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px;
           border: 0; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.starter:hover { box-shadow: 0 0 0 1px var(--purple); }
.starter:active { box-shadow: 0 0 0 1.5px var(--purple); }
.tone-box { width: 32px; height: 32px; flex: none; border-radius: 8px; display: grid; place-items: center; }
.tone-box .ph { font-size: 16px; }
.tone-purple { background: var(--purple-soft); color: var(--purple); }
.tone-green { background: var(--green-soft); color: var(--green); }
.starter-text { display: flex; flex-direction: column; gap: 2px; }
.starter-text span:first-child { font-size: 11.5px; color: var(--faint); }
.starter-text span:last-child { font-size: 14px; line-height: 1.6; }

/* ---------------------------------------------------------------- messages */
.q-row { display: flex; justify-content: flex-start; animation: rise .25s ease both; scroll-margin-top: 20px; }
.q-bubble { max-width: 75%; padding: 10px 16px; border-radius: 14px 14px 14px 4px; background: var(--purple-soft);
            color: var(--text); font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.q-bubble.system { background: transparent; box-shadow: inset 0 0 0 1px var(--line2); color: var(--muted); font-size: 13px; }
.a-row { display: flex; gap: 14px; animation: rise .25s ease both; }
.a-mark { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--green-soft); display: grid; place-items: center; }
.a-mark .ph { color: var(--green); font-size: 16px; }
.a-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 18px; }

.prose { font-size: 15px; line-height: 1.95; text-wrap: pretty; max-width: 720px; overflow-wrap: anywhere; }
.prose p { margin: 0 0 .55em; } .prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin: .2em 0 .6em; padding-inline-start: 1.3em; }
.prose li { margin: .1em 0; }
.prose strong { font-weight: 600; }
.prose code { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; background: var(--surface2);
              padding: 1px 6px; border-radius: 5px; direction: ltr; unicode-bidi: isolate; }
.prose h3, .prose h4 { font-size: 15px; font-weight: 600; margin: .6em 0 .3em; }
.prose.small { font-size: 14px; line-height: 1.9; }
.muted-note { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); }
.muted-note .ph { margin-top: 4px; }

/* interpretation */
.reading { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.reading-label { color: var(--faint); white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 6px; border: 1px dashed var(--line2);
        background: transparent; color: var(--text); font-size: 12.5px; white-space: nowrap; max-width: 100%; }
.chip > span { overflow: hidden; text-overflow: ellipsis; }
.chip .ph { font-size: 12px; color: var(--faint); }
button.chip:hover, button.chip[aria-expanded="true"] { border-color: var(--purple); }
button.chip .ph-caret-down { font-size: 11px; }
.chip-wrap { position: relative; max-width: 100%; }
.menu { position: absolute; top: 32px; right: 0; z-index: 30; min-width: 220px; max-width: 360px; padding: 6px; border-radius: 10px;
        background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.menu.left { right: auto; left: 0; }
.menu-note { font-size: 11.5px; color: var(--faint); padding: 4px 10px 6px; line-height: 1.6; }
.menu-item { text-align: right; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 0; border-radius: 6px;
             background: transparent; color: var(--text); font-size: 13px; }
.menu-item:hover:not(:disabled) { background: var(--surface2); }
.menu-item .ph { color: var(--purple); width: 14px; flex: none; }
.menu-item.selected { color: var(--purple-ink); }
.menu-item:disabled { opacity: 1; color: var(--faint); }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 8px; border-radius: 5px; white-space: nowrap; }
.tag-green { color: var(--green-ink); background: var(--green-soft); }
.tag-purple { color: var(--purple-ink); background: var(--purple-soft); }
.tag-neutral { color: var(--muted); background: var(--surface2); }
.tag-warn { color: var(--warn); background: color-mix(in oklab, var(--warn) 14%, transparent); }
.link-btn { display: inline-flex; align-items: center; gap: 5px; border: 0; background: transparent; color: var(--purple);
            font-size: 12.5px; padding: 2px 4px; border-radius: 5px; }
.link-btn:hover { color: var(--purple-ink); background: var(--purple-soft); }

/* headline */
.headline { display: flex; flex-direction: column; gap: 6px; }
.headline-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.headline-value { font-size: 36px; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
.headline-unit { font-size: 14px; color: var(--muted); }

/* figures */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.figure { padding: 14px 16px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
          display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.figure-label { font-size: 12px; color: var(--faint); }
.figure-value { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 4px; overflow-wrap: anywhere; }
.figure-sub { font-size: 12px; color: var(--muted); }
.figure-sub.up { color: var(--green-ink); }
.trend-up { color: var(--green); } .trend-down { color: var(--purple); }

/* cards */
.card { border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); padding: 18px 20px;
        display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-titles { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.card-title { font-weight: 600; font-size: 15px; }
.card-sub { font-size: 12.5px; color: var(--faint); }
.card-foot { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.card-foot .source { margin-right: auto; color: var(--faint); display: inline-flex; align-items: center; gap: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; padding: 5px 12px; font-size: 12.5px; background: transparent; color: var(--muted); }
.seg button:hover:not(.on):not(:disabled) { background: var(--surface2); color: var(--text); }
.seg button.on { background: var(--purple-soft); color: var(--purple); }
/* A ranking's or trend's split, focus and scale, under its title */
.chart-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; margin-top: -4px; }
.tool { display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.tool-label { font-size: 12px; color: var(--faint); flex: none; }
.chart-tools .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex-shrink: 1; }
.chart-tools .seg button { padding: 5px 10px; white-space: nowrap; flex: none; }
.seg-count { margin-inline-start: 5px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.seg button.on .seg-count { color: inherit; opacity: .7; }
.select.sm { height: 28px; width: auto; min-width: 150px; max-width: 100%; font-size: 12.5px; }
.tab-about { margin: 0; display: flex; gap: 6px; align-items: flex-start; font-size: 12.5px; color: var(--muted); line-height: 1.8; }
.tab-about .ph { margin-top: 4px; flex: none; color: var(--faint); }
.btn-square { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line2); background: transparent;
              color: var(--muted); display: grid; place-items: center; flex: none; }
.btn-square:hover, .btn-square[aria-expanded="true"] { background: var(--surface2); color: var(--text); }
.chart-box { position: relative; min-height: 120px; }
.chart-canvas { width: 100%; direction: ltr; }
.chart-html { direction: rtl; overflow: auto; max-height: 520px; }
.chart-error { color: var(--muted); font-size: 13px; padding: 12px 0; }
.chart-busy { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in oklab, var(--surface) 55%, transparent);
              border-radius: 8px; }
.note-line { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--faint); line-height: 1.7; }
.note-line .ph { margin-top: 3px; flex: none; }

/* HTML charts from the adapter: KPI and table */
.kpi-card { padding: 4px 0; }
/* The card head already shows the chart's title and subtitle. */
.chart-html .kpi-title, .chart-html .kpi-badge, .chart-html .table-title, .chart-html .table-subtitle { display: none; }
.chart-html .table-wrapper > div:first-child { display: none; }
.kpi-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.kpi-badge, .kpi-x-badge { display: inline-block; font-size: 12px; color: var(--muted); background: var(--surface2);
                           border-radius: 6px; padding: 2px 10px; }
.kpi-x-badge { color: var(--purple-ink); background: var(--purple-soft); }
.kpi-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: stretch; }
.kpi-sub { flex: 1 1 170px; min-width: 150px; display: flex; flex-direction: column; justify-content: space-between;
           align-items: center; background: var(--surface2); border-radius: 10px; padding: 16px 12px; }
.kpi-sub-label { font-size: 12px; color: var(--faint); margin-bottom: 10px; text-align: center; line-height: 1.4; }
.kpi-sub-value { font-weight: 600; text-align: center; direction: rtl; white-space: nowrap; }
.table-title { margin: 0; font-size: 14px; font-weight: 600; }
.table-subtitle { margin: 4px 0 0; font-size: 12px; color: var(--faint); }
.custom-table, .data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.custom-table th, .data-table th { color: var(--faint); font-weight: 500; font-size: 12px; padding: 8px 10px; text-align: right;
                                   border-bottom: 1px solid var(--line2); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.custom-table td, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.custom-table tr:last-child td, .data-table tr:last-child td { border-bottom: 0; }
.custom-table th.sortable { cursor: pointer; user-select: none; }
.custom-table th.sortable:hover { color: var(--text); }
.custom-table th[data-sort='desc']::after { content: ' ▾'; }
.custom-table th[data-sort='asc']::after { content: ' ▴'; }
.table-scroll { overflow: auto; max-height: 420px; border-radius: 10px; }

/* chart settings panel */
.panel { border-radius: 12px; background: var(--bg2); box-shadow: inset 0 0 0 1px var(--line); padding: 14px 16px;
         display: flex; flex-direction: column; gap: 14px; }
.panel-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 12px; color: var(--faint); }
.input, .select { height: 32px; border-radius: 8px; border: 0; box-shadow: var(--shadow); background: var(--surface);
                  color: var(--text); padding: 0 10px; font-size: 13px; outline: none; width: 100%; }
.input:focus, .select:focus { box-shadow: 0 0 0 1px var(--purple); }
textarea.input { height: auto; padding: 10px 12px; font-family: 'JetBrains Mono', monospace; font-size: 12px; line-height: 1.6;
                 direction: ltr; text-align: left; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 7px; font-size: 12.5px;
         border: 1px solid var(--line2); background: transparent; color: var(--muted); }
.check:hover { border-color: var(--purple); color: var(--text); }
.check.on { background: var(--purple-soft); border-color: var(--purple-mid); color: var(--purple-ink); }
.check .ph { font-size: 13px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); border: 0; background: transparent; padding: 2px 0; text-align: right; }
.switch .track { width: 30px; height: 18px; border-radius: 9px; background: var(--surface2); box-shadow: inset 0 0 0 1px var(--line2);
                 position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; right: 3px; width: 12px; height: 12px; border-radius: 50%;
                        background: var(--faint); transition: right .15s, background .15s; }
.switch.on .track { background: var(--purple-soft); box-shadow: inset 0 0 0 1px var(--purple-mid); }
.switch.on .track::after { right: 15px; background: var(--purple); }
.switch.on { color: var(--text); }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-primary { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 16px; border-radius: 8px;
               border: 1px solid var(--purple); background: transparent; color: var(--purple); font-weight: 500; font-size: 13.5px; }
.btn-primary:hover:not(:disabled) { background: var(--purple-soft); }
.btn-primary:active:not(:disabled) { background: var(--purple-mid); color: var(--purple-ink); }
.btn-primary.sm, .btn-ghost.sm, .btn-outline.sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 0;
             background: transparent; color: var(--muted); font-size: 13px; }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-ghost.danger { color: var(--danger); }

/* item picker */
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker-box { position: relative; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 10px;
              background: var(--surface); box-shadow: var(--shadow); min-height: 40px; }
.picker-box:focus-within { box-shadow: 0 0 0 1px var(--purple); }
.token { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border-radius: 6px; font-size: 12.5px;
         background: var(--purple-soft); color: var(--purple-ink); }
.token button { width: 18px; height: 18px; border: 0; border-radius: 4px; background: transparent; color: inherit;
                display: grid; place-items: center; font-size: 11px; opacity: .75; }
.token button:hover { opacity: 1; background: var(--purple-mid); }
.picker-input { flex: 1; min-width: 120px; border: 0; outline: none; background: transparent; font-size: 13px; color: var(--text); padding: 3px 2px; }
.picker-list { position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 30; max-height: 260px; overflow: auto;
               padding: 6px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-lg); }
.picker-list .menu-item { width: 100%; }
.picker-list .menu-item .level { margin-right: auto; font-size: 11px; color: var(--faint); }

/* deeper look */
.deeper { display: flex; flex-direction: column; gap: 14px; }
.deeper-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.deeper-head b { font-weight: 600; font-size: 15px; }
.deeper-head span { font-size: 12.5px; color: var(--faint); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { display: flex; align-items: center; gap: 6px; padding: 8px 12px; margin-bottom: -1px; border: 0;
       border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap; flex: none; }
.tab:hover { color: var(--text); }
.tab.on { border-bottom-color: var(--purple); color: var(--text); }
.tab-body { display: flex; flex-direction: column; gap: 12px; animation: rise .2s ease both; }
.info-card { display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.info-card > .ph { font-size: 18px; margin-top: 2px; flex: none; }
.info-card div { display: flex; flex-direction: column; }
.info-card b { font-weight: 500; }
.info-card span { font-size: 13px; color: var(--muted); }
.disclosure { display: flex; flex-direction: column; gap: 10px; }
.disclosure > button { align-self: flex-start; }

/* actions */
.actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.act { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
       display: grid; place-items: center; }
.act:hover:not(:disabled) { background: var(--surface2); }
.act.up { color: var(--green); } .act.down { color: var(--purple); }
.act-text { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 8px; border: 0;
            background: transparent; color: var(--faint); font-size: 12.5px; }
.act-text:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.act-text .ph-caret-down, .act-text .ph-caret-up { font-size: 11px; }

/* technical details */
.tech { border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); padding: 16px 18px; display: flex;
        flex-direction: column; gap: 14px; min-width: 0; animation: rise .2s ease both; }
.tech-facts { display: flex; gap: 24px; flex-wrap: wrap; font-size: 12.5px; }
.tech-facts > span { display: flex; flex-direction: column; }
.tech-facts > span > span:first-child { color: var(--faint); }
.tech-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tech-block-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--faint); }
.code { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--code); font-family: 'JetBrains Mono', monospace;
        font-size: 12px; line-height: 1.7; color: var(--muted); overflow: auto; text-align: left; direction: ltr;
        white-space: pre; max-height: 360px; }
.code.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.code .kw { color: var(--purple); } .code .str { color: var(--green); } .code .numlit { color: var(--purple-ink); }
.call { border-radius: 10px; box-shadow: inset 0 0 0 1px var(--line); }
.call > button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 0; background: transparent;
                 color: var(--text); font-size: 12.5px; text-align: right; border-radius: 10px; }
.call > button:hover { background: var(--surface2); }
.call-meta { margin-right: auto; color: var(--faint); font-size: 11.5px; direction: ltr; unicode-bidi: isolate; }
.call-body { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; font-size: 12.5px; }

/* clarify */
.options { display: flex; flex-direction: column; gap: 8px; }
.options.compact { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.options.compact .option { padding: 9px 12px; align-items: center; }
.options.compact .radio, .options.compact .box { margin-top: 0; }
.option { text-align: right; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; border: 0;
          background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.option.on { box-shadow: 0 0 0 1.5px var(--purple); }
.option:hover:not(.on):not(:disabled) { box-shadow: 0 0 0 1px var(--line2); }
.option:disabled { opacity: 1; }
.radio { width: 16px; height: 16px; margin-top: 4px; flex: none; border-radius: 50%; border: 1.5px solid var(--line2); }
.option.on .radio { border-color: var(--purple); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 8px var(--purple); }
.box { width: 16px; height: 16px; margin-top: 4px; flex: none; border-radius: 4px; border: 1.5px solid var(--line2);
       display: grid; place-items: center; font-size: 11px; color: transparent; }
.option.on .box { border-color: var(--purple); background: var(--purple); color: var(--surface); }
.option-text { display: flex; flex-direction: column; gap: 2px; }
.option-text b { font-weight: 500; }
.option-text span { font-size: 12.5px; color: var(--muted); }
.option .tag { margin-right: auto; align-self: flex-start; }
.issue { display: flex; flex-direction: column; gap: 10px; }
.issue + .issue { padding-top: 6px; }
.warning { display: flex; gap: 10px; padding: 10px 14px; border-radius: 10px; font-size: 13px; color: var(--text);
           background: color-mix(in oklab, var(--warn) 10%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--warn) 30%, transparent); }
.warning .ph { color: var(--warn); font-size: 16px; margin-top: 3px; flex: none; }
.error-box { display: flex; gap: 10px; padding: 10px 14px; border-radius: 10px; font-size: 13px;
             background: color-mix(in oklab, var(--danger) 10%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--danger) 30%, transparent); }
.error-box .ph { color: var(--danger); font-size: 16px; margin-top: 3px; flex: none; }
.settled { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 10px; box-shadow: inset 0 0 0 1px var(--line); }
.settled-line { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* thinking */
.steps { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.step { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.step-mark { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
.step-mark .ph-bold { color: var(--green); font-size: 14px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line2); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--purple-soft); border-top-color: var(--purple); border-radius: 50%;
           display: inline-block; animation: spin .8s linear infinite; }
.step-label { flex: 1; } .step-label.pending { color: var(--faint); }
.step-detail { font-size: 12px; color: var(--faint); }
.skeleton { display: flex; flex-direction: column; gap: 8px; }
.skeleton div { border-radius: 4px; background: var(--surface2); animation: pulse 1.4s ease-in-out infinite; }
.progress-line { font-size: 12px; color: var(--faint); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* composer */
.composer { flex: none; padding: 0 28px 18px; }
.composer-inner { max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.composer-box { border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-lg); padding: 10px 12px 10px 10px;
                display: flex; flex-direction: column; gap: 8px; }
.composer-box:focus-within { box-shadow: 0 0 0 1px var(--purple-mid), 0 14px 36px rgba(0,0,0,.25); }
.composer-input { border: 0; outline: none; background: transparent; color: var(--text); font-size: 15px; padding: 6px; width: 100%;
                  resize: none; line-height: 1.7; max-height: 160px; min-height: 38px; font-family: inherit; }
.composer-input::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; gap: 8px; }
.hint { font-size: 11.5px; color: var(--faint); white-space: nowrap; }
.send { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--purple); background: var(--purple-soft);
        color: var(--purple); display: grid; place-items: center; flex: none; }
.send .ph-bold { font-size: 16px; }
.send:hover:not(:disabled) { background: var(--purple-mid); color: var(--purple-ink); }
.disclaimer { text-align: center; font-size: 11px; color: var(--faint); }

/* dialogs */
.backdrop { position: fixed; inset: 0; z-index: 50; background: var(--backdrop); display: grid; place-items: center; padding: 16px;
            animation: rise .15s ease both; }
.dialog { width: min(640px, 100%); max-height: min(86vh, 900px); display: flex; flex-direction: column; border-radius: 14px;
          background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden; }
.dialog.wide { width: min(900px, 100%); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head b { font-weight: 600; font-size: 15px; flex: 1; }
.dialog-body { padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 20px; border-top: 1px solid var(--line); }
.section-label { font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 6px; }
.sample-list { display: flex; flex-direction: column; gap: 6px; }
.sample { text-align: right; padding: 9px 12px; border-radius: 9px; border: 0; background: var(--bg2); color: var(--text);
          font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.sample:hover { box-shadow: 0 0 0 1px var(--purple); }
.sample .ph { color: var(--purple); }
.concept { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 10px; background: var(--bg2); }
.concept-head { display: flex; align-items: center; gap: 8px; }
.concept-head b { font-weight: 600; flex: 1; }
.concept-items { font-size: 12.5px; color: var(--muted); }
.radio-row { display: flex; flex-direction: column; gap: 8px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; padding: 28px; border-radius: 14px;
              background: var(--surface); box-shadow: var(--shadow-lg); }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.5; }
.login-card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.login-card .input { height: 40px; font-size: 14px; }
.login-card .btn-primary { justify-content: center; height: 40px; }

/* toast */
.toasts { position: fixed; bottom: 18px; left: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; background: var(--surface);
         box-shadow: var(--shadow-lg); font-size: 13px; animation: rise .2s ease both; }
.toast .ph { margin-top: 3px; color: var(--green); }
.toast.error .ph { color: var(--danger); }

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 900px) {
  .aside { position: fixed; top: 0; right: 0; transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .app.drawer .aside { transform: none; }
  .drawer-shade { position: fixed; inset: 0; z-index: 19; background: var(--backdrop); }
  .menu-toggle { display: grid; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .topbar .pill { display: none; }
  .thread { padding: 20px 16px 28px; }
  .composer { padding: 0 16px 12px; }
  .welcome { padding-top: 2vh; }
  .welcome h1 { font-size: 24px; }
  .hint { display: none; }
  .q-bubble { max-width: 90%; }
  .a-row { gap: 10px; }
  .a-mark { display: none; }
  .btn-outline .label { display: none; }
}


/* Model-written comparison tables: safe Markdown, full RTL and responsive width. */
.prose { min-width: 0; }
.prose .md-table-card { width: 100%; min-width: 0; margin: 20px 0; overflow: hidden;
  border: 1px solid var(--line2); border-radius: 14px; background: var(--surface);
  box-shadow: 0 6px 22px rgba(0,0,0,.06); }
.prose .md-table-scroll { overflow-x: auto; max-width: 100%; scrollbar-width: thin;
  scrollbar-color: var(--purple) var(--surface2); }
.prose .md-table-scroll:focus-visible { outline: 2px solid var(--purple); outline-offset: -2px; }
.prose .md-table { width: 100%; min-width: 460px; border-collapse: separate; border-spacing: 0;
  font-size: 13px; line-height: 1.9; }
.prose .md-table th { padding: 15px 18px; color: var(--text); font-weight: 650;
  background: var(--purple-soft); border-bottom: 1px solid var(--line2); vertical-align: middle; }
.prose .md-table td { padding: 13px 18px; color: var(--muted); border-bottom: 1px solid var(--line);
  vertical-align: middle; transition: background .15s; }
.prose .md-table tbody tr:nth-child(even) td { background: var(--surface2); }
.prose .md-table tbody tr:hover td { background: var(--purple-soft); color: var(--text); }
.prose .md-table tbody tr:last-child td { border-bottom: 0; }
.prose .md-table td:first-child { color: var(--text); font-weight: 500; }
.prose .md-table .align-start { text-align: start; }
.prose .md-table .align-left { text-align: left; }
.prose .md-table .align-right { text-align: right; }
.prose .md-table .align-center { text-align: center; }
.prose .md-table .is-number { direction: ltr; unicode-bidi: isolate; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.prose .md-code { overflow-x: auto; background: var(--surface2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px; direction: ltr; text-align: left; }
@media (max-width: 600px) {
  .prose .md-table th, .prose .md-table td { padding: 11px 13px; }
  .prose .md-table-card { border-radius: 10px; margin: 15px 0; }
}
