/* =====================================================================
   FanBazar console — design tokens + components
   Style: clean "Swiss" minimal dashboard, indigo/violet accent, RTL-first.
   Font: Vazirmatn (self-hosted variable font, no external requests).
   ===================================================================== */

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  /* surfaces */
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e8ebf4;
  --line: #e2e6f0;
  --line-strong: #cdd3e4;
  /* text */
  --text: #131a2e;
  --text-2: #3b4562;
  --muted: #5b6684;
  /* brand */
  --brand: #4f46e5;          /* text / icon accent */
  --brand-fill: #4f46e5;     /* solid fills (white text on top, >= 4.5:1) */
  --brand-hover: #4338ca;
  --accent: #7c3aed;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
  --brand-ring: color-mix(in srgb, var(--brand) 32%, transparent);
  --grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  /* status */
  --ok: #107a43; --warn: #a15c00; --bad: #c62828;
  --ok-bg: color-mix(in srgb, var(--ok) 11%, transparent);
  --bad-bg: color-mix(in srgb, var(--bad) 10%, transparent);
  /* document types (text colours; backgrounds are tinted) */
  --supply: #0b7a6b; --demand: #b83e0a; --service: #6d33d6;
  /* misc */
  --code-bg: #0c1124; --code-text: #d9e0f7; --code-line: #1b2442;
  --shadow-sm: 0 1px 2px rgba(19, 26, 46, .06);
  --shadow: 0 1px 2px rgba(19, 26, 46, .05), 0 8px 24px -8px rgba(19, 26, 46, .10);
  --shadow-lg: 0 24px 60px -12px rgba(19, 26, 46, .28);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6684' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  /* type & shape */
  --font: "Vazirmatn", "Vazir", Tahoma, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-xl: 22px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --topbar-h: 68px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090d19;
  --surface: #11172a;
  --surface-2: #171f37;
  --surface-3: #202a47;
  --line: #222c49;
  --line-strong: #323f66;
  --text: #e9edf8;
  --text-2: #c3cbe3;
  --muted: #94a0c0;
  --brand: #a5acff;
  --brand-fill: #5b5ff0;
  --brand-hover: #6d71f5;
  --grad: linear-gradient(135deg, #5b5ff0 0%, #8b5cf6 100%);
  --ok: #4ade80; --warn: #fbbf24; --bad: #ff8585;
  --supply: #3ddbc4; --demand: #ff9d6c; --service: #b79cff;
  --code-bg: #060a16; --code-line: #151d37;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 32px -10px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 70px -12px rgba(0, 0, 0, .7);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a0c0' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { height: 100%; scroll-padding-top: calc(var(--topbar-h) + 12px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.9; font-weight: 400;
  font-feature-settings: "ss01" 0; text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
::selection { background: color-mix(in srgb, var(--brand-fill) 30%, transparent); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code, .mono { font-family: var(--mono); direction: ltr; unicode-bidi: plaintext; }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 0 6px; border-radius: 6px; font-size: .84em; color: var(--text-2); }
h1, h2, h3, h4 { line-height: 1.5; margin: 0 0 .5em; font-weight: 700; letter-spacing: 0; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
kbd { font-family: var(--font); font-size: 11px; background: var(--surface-2); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; color: var(--text-2); }

/* visible keyboard focus everywhere */
:focus-visible { outline: 2px solid var(--brand-fill); outline-offset: 2px; border-radius: var(--r-sm); }
.skip-link { position: fixed; top: -60px; inset-inline-start: 12px; z-index: 100; background: var(--brand-fill); color: #fff; padding: 8px 16px; border-radius: var(--r-sm); transition: top .2s var(--ease); }
.skip-link:focus { top: 12px; }

i[data-i] { display: inline-flex; width: 1.2em; height: 1.2em; flex: none; }
i[data-i] svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------------------- layout ----------------------------- */
.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--line);
  padding: 20px 14px 16px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 2px 8px 16px; border-bottom: 1px solid var(--line); }
.logo { width: 42px; height: 42px; border-radius: 13px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 8px 18px -6px rgba(79, 70, 229, .55), inset 0 1px 0 rgba(255, 255, 255, .25); flex: none; }
.logo svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.brand-title { font-weight: 800; font-size: 16px; line-height: 1.4; }
.brand-sub { color: var(--muted); font-size: 12px; line-height: 1.5; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 14px 12px 6px; }
.nav-label:first-child { padding-top: 4px; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 9px 12px; min-height: 42px;
  border-radius: var(--r); color: var(--text-2); font-weight: 500; font-size: 14.5px;
  transition: background-color .18s var(--ease), color .18s var(--ease);
}
.nav a i { color: var(--muted); transition: color .18s var(--ease); }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav a.on i { color: var(--brand); }
.nav a.on::before { content: ""; position: absolute; inset-block: 9px; inset-inline-start: -14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--brand-fill); }
[dir="rtl"] .nav a.on::before { border-radius: 4px 0 0 4px; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.status-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.status-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; line-height: 1.6; padding: 2px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.pill b { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill.ok { color: var(--text-2); }
.pill.ok b { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 24%, transparent); }
.pill.bad b { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.side-links { display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.side-links a { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; border-radius: var(--r-sm); color: var(--muted); }
.side-links a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.side-links i { width: 1em; height: 1em; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.page-head { flex: 1; min-width: 0; }
.topbar h1 { font-size: 19px; margin: 0; line-height: 1.4; font-weight: 800; }
.page-sub { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn.menu-btn { display: none; }
.content { padding: 24px 28px 32px; max-width: 1320px; width: 100%; margin: 0 auto; outline: none; }
.tab { animation: tab-in .28s var(--ease); }
@keyframes tab-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----------------------------- primitives ----------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { font-size: 15.5px; margin-bottom: 14px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.card h3 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.row.wrap { flex-wrap: wrap; align-items: flex-end; }
.row.between { justify-content: space-between; }
.row:last-child { margin-bottom: 0; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; line-height: 1.5; }

input, select, textarea {
  font: inherit; font-size: 14.5px; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: 8px 13px; min-height: 42px; width: 100%; outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background-color .15s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line-strong)); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--brand-fill); box-shadow: 0 0 0 4px var(--brand-ring); }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: var(--select-arrow); background-repeat: no-repeat; background-position: left 12px center; background-size: 16px;
  padding-inline-end: 13px; padding-inline-start: 38px;
}
select option { background: var(--surface); color: var(--text); }
select.mono-select, select.mono-select option { font-family: var(--mono); font-size: 13px; direction: ltr; }
select.mono-select { text-align: left; padding-inline-start: 13px; padding-inline-end: 38px; background-position: right 12px center; }
textarea { resize: vertical; line-height: 1.8; }
textarea.mono, input.mono { font-size: 13px; line-height: 1.7; }
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; display: inline-flex; gap: 8px; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: var(--r); padding: 8px 18px; min-height: 42px; line-height: 1.4; cursor: pointer; white-space: nowrap;
  transition: background-color .16s var(--ease), border-color .16s var(--ease), box-shadow .16s var(--ease), transform .12s var(--ease), color .16s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand-fill); color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .15), inset 0 1px 0 rgba(255, 255, 255, .18); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--brand) 40%, var(--line-strong)); color: var(--text); }
.btn.danger { background: #c62828; color: #fff; }
.btn.danger:hover { background: #b01f1f; }
.btn.sm { padding: 4px 12px; font-size: 13px; min-height: 36px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--text-2); width: 40px; height: 40px; border-radius: var(--r);
  display: inline-grid; place-items: center; cursor: pointer; flex: none; transition: background-color .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: 13px; font-weight: 600; background: transparent; color: var(--muted); border: 0; border-radius: 9px; padding: 4px 14px; min-height: 34px; cursor: pointer;
  transition: background-color .16s var(--ease), color .16s var(--ease), box-shadow .16s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 13.5px; cursor: pointer; min-height: 42px; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.switch span { width: 40px; height: 23px; background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: 99px; position: relative; transition: .2s var(--ease); flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: .2s var(--ease); }
.switch input:checked + span { background: var(--brand-fill); border-color: var(--brand-fill); }
.switch input:checked + span::after { inset-inline-start: 19px; }
.switch input:focus-visible + span { outline: 2px solid var(--brand-fill); outline-offset: 2px; }

.badge { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 700; line-height: 1.7; padding: 0 10px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); border: 1px solid color-mix(in srgb, var(--c) 28%, transparent); white-space: nowrap; }
.badge.supply { --c: var(--supply); } .badge.demand { --c: var(--demand); } .badge.service { --c: var(--service); }
.tag { display: inline-block; font-size: 12px; line-height: 1.7; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; color: var(--text-2); }
.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); padding: 2px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); }
.conn b { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.on b { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 24%, transparent); }
.conn.busy b { background: var(--warn); }
.conn em { font-style: normal; }

/* skeleton loading */
.skel { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); min-height: 14px; }
.skel::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); transform: translateX(-100%); animation: shimmer 1.4s infinite; }
[dir="rtl"] .skel::after { animation-name: shimmer-rtl; transform: translateX(100%); }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes shimmer-rtl { to { transform: translateX(-100%); } }
.skel-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; display: grid; gap: 10px; }

/* ----------------------------- chat ----------------------------- */
.chat-shell { padding: 0; display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 56px); height: calc(100dvh - var(--topbar-h) - 56px); min-height: 460px; overflow: hidden; margin-bottom: 0; }
.chat-bar { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.chat-bar select { width: auto; min-height: 38px; padding-block: 4px; font-size: 13.5px; }
.chat-bar .btn { margin-inline-start: auto; }
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 22px; scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.welcome { margin: auto; text-align: center; width: min(720px, 100%); padding: 8px 0 24px; }
.welcome-ic { width: 68px; height: 68px; border-radius: 22px; display: grid; place-items: center; margin: 0 auto 18px; background: var(--grad); color: #fff; box-shadow: 0 14px 30px -10px rgba(79, 70, 229, .55), inset 0 1px 0 rgba(255, 255, 255, .25); }
.welcome-ic i { width: 32px; height: 32px; }
.welcome h2 { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.welcome p { color: var(--muted); max-width: 560px; margin: 0 auto 24px; font-size: 14.5px; }
.examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: start; }
.ex {
  font: inherit; font-size: 13.5px; line-height: 1.8; display: flex; gap: 12px; align-items: center; justify-content: space-between; text-align: start;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2); border-radius: var(--r); padding: 12px 16px; cursor: pointer;
  transition: border-color .18s var(--ease), background-color .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease);
}
.ex i { color: var(--muted); transition: color .18s var(--ease), transform .18s var(--ease); }
.ex:hover { border-color: var(--brand-fill); background: var(--brand-soft); color: var(--text); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.ex:hover i { color: var(--brand); transform: translateX(-3px); }

.msg { display: flex; gap: 12px; width: min(820px, 100%); margin-inline: auto; animation: msg-in .3s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg .av { width: 34px; height: 34px; border-radius: 11px; flex: none; display: grid; place-items: center; background: var(--grad); color: #fff; box-shadow: 0 6px 14px -6px rgba(79, 70, 229, .6); }
.msg .av i { width: 18px; height: 18px; }
.msg.user { justify-content: flex-start; }
.msg .bubble { min-width: 0; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-lg); border-start-start-radius: 4px; padding: 10px 16px; max-width: 86%; color: var(--text); }
.msg.bot .bubble { flex: 1; padding-top: 3px; }
.bubble .txt { white-space: pre-wrap; line-height: 2; }
.bubble .err { color: var(--bad); background: var(--bad-bg); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); border-radius: var(--r); padding: 6px 12px; display: inline-block; }
.typing { display: inline-flex; gap: 5px; align-items: center; vertical-align: middle; }
.typing i { width: 7px; height: 7px; background: var(--brand-fill); border-radius: 50%; animation: bl 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bl { 0%, 80%, 100% { opacity: .25; transform: scale(.75); } 40% { opacity: 1; transform: scale(1); } }
.cite { display: inline-block; font-size: 11px; font-weight: 700; line-height: 1.7; background: var(--brand-soft); color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent); border-radius: 7px; padding: 0 7px; margin: 0 2px; cursor: pointer; vertical-align: baseline; transition: background-color .15s var(--ease); }
.cite:hover { background: color-mix(in srgb, var(--brand) 20%, transparent); text-decoration: none; }
.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.sources-title { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--muted); }
.src {
  font: inherit; font-size: 12.5px; line-height: 1.7; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 12px; cursor: pointer; color: var(--text); text-align: start; transition: border-color .16s var(--ease), box-shadow .16s var(--ease), transform .16s var(--ease);
}
.src:hover { border-color: var(--brand-fill); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.src .src-top { display: flex; gap: 8px; align-items: center; width: 100%; justify-content: space-between; }
.src .src-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-weight: 500; }
.src em { font-style: normal; color: var(--muted); font-family: var(--mono); font-size: 11px; direction: ltr; }
.meta-line { margin-top: 12px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; line-height: 1.7; }
.meta-line b { color: var(--text-2); font-weight: 600; }
.msg-actions { display: flex; gap: 6px; margin-top: 10px; }
.mini-btn { font: inherit; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; min-height: 30px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; transition: .15s var(--ease); }
.mini-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.mini-btn i { width: 14px; height: 14px; }

.composer { padding: 6px 20px 14px; background: linear-gradient(to top, var(--surface) 70%, transparent); }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; width: min(820px, 100%); margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-xl); padding: 8px 8px 8px 10px;
  box-shadow: var(--shadow); transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.composer-box:focus-within { border-color: var(--brand-fill); box-shadow: var(--shadow), 0 0 0 4px var(--brand-ring); }
.composer textarea { border: 0; background: transparent; box-shadow: none !important; max-height: 168px; resize: none; padding: 8px 10px; min-height: 40px; border-radius: 0; }
.composer textarea:hover { border: 0; }
.send-btn { width: 42px; height: 42px; border-radius: 14px; border: 0; background: var(--brand-fill); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; transition: background-color .16s var(--ease), transform .12s var(--ease), box-shadow .16s var(--ease); box-shadow: 0 6px 14px -6px rgba(79, 70, 229, .7); }
.send-btn:hover { background: var(--brand-hover); }
.send-btn:active { transform: scale(.94); }
.send-btn i { width: 19px; height: 19px; }
[dir="rtl"] #send i svg { transform: scaleX(-1); }
.send-btn.stop { background: #c62828; box-shadow: 0 6px 14px -6px rgba(198, 40, 40, .7); }
.send-btn.stop:hover { background: #b01f1f; }
.composer-hint { width: min(820px, 100%); margin: 8px auto 0; font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ----------------------------- search ----------------------------- */
.search-row { display: flex; gap: 10px; margin-bottom: 14px; }
.search-input { position: relative; flex: 1; min-width: 0; }
.search-input i { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input input { padding-inline-start: 42px; min-height: 48px; font-size: 15px; border-radius: 14px; }
.search-row .btn { min-height: 48px; border-radius: 14px; padding-inline: 28px; }
.result-meta { color: var(--muted); font-size: 13px; margin: 4px 4px 14px; display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; }
.result-meta span:first-child { color: var(--text); font-weight: 700; }
.results { display: grid; gap: 12px; }
.res {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; cursor: pointer;
  transition: border-color .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease); animation: msg-in .3s var(--ease) both;
}
.res:hover { border-color: var(--brand-fill); transform: translateY(-2px); box-shadow: var(--shadow); }
.res:focus-visible { outline-offset: 3px; }
.res-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.res-head h4 { margin: 0; font-size: 15.5px; flex: 1; min-width: 200px; }
.res .snip { color: var(--muted); font-size: 13.5px; line-height: 1.95; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.res .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.score { font-family: var(--mono); font-size: 11.5px; color: var(--muted); direction: ltr; background: var(--surface-2); border-radius: 6px; padding: 0 8px; }
.pager { display: flex; gap: 12px; justify-content: center; margin: 22px 0 4px; align-items: center; color: var(--muted); font-size: 13.5px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.filter-bar { align-items: flex-end; }

/* ----------------------------- stats & status ----------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.kpi .ic { position: absolute; inset-block-start: 14px; inset-inline-end: 14px; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--brand)) 12%, transparent); color: var(--c, var(--brand)); }
.kpi .ic i { width: 18px; height: 18px; }
.kpi .l { color: var(--muted); font-size: 13px; padding-inline-end: 44px; line-height: 1.6; }
.kpi .v { font-size: 28px; font-weight: 800; line-height: 1.5; font-variant-numeric: tabular-nums; }
.kpi .v.sm { font-size: 18px; }
.kpi.ok { --c: var(--ok); } .kpi.bad { --c: var(--bad); }
.kpi.supply { --c: var(--supply); } .kpi.demand { --c: var(--demand); } .kpi.service { --c: var(--service); }
.kpi.ok .v { color: var(--ok); } .kpi.bad .v { color: var(--bad); }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 12px; align-items: center; font-size: 13.5px; cursor: pointer; padding: 4px 8px; margin-inline: -8px; border-radius: 10px; transition: background-color .15s var(--ease); }
.bar:hover, .bar:focus-visible { background: var(--surface-2); }
.bar:hover .fill { filter: brightness(1.12); }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar .track { background: var(--surface-3); border-radius: 99px; height: 8px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--grad); border-radius: 99px; display: block; transform-origin: right; animation: grow-x .7s var(--ease) both; }
@keyframes grow-x { from { transform: scaleX(0); } }
.bar .n { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 28px; text-align: end; }
.kv { display: grid; grid-template-columns: 240px 1fr; gap: 0; font-size: 14px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.kv .k, .kv .v { padding: 9px 14px; border-bottom: 1px solid var(--line); }
.kv .k { color: var(--muted); background: var(--surface-2); }
.kv .k:nth-last-child(2), .kv .v:last-child { border-bottom: 0; }
.kv .v { font-family: var(--mono); font-size: 13px; direction: ltr; text-align: left; overflow-wrap: anywhere; }
.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.links-grid a { display: block; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; background: var(--surface); color: var(--text); transition: border-color .16s var(--ease), box-shadow .16s var(--ease), transform .16s var(--ease); }
.links-grid a:hover { border-color: var(--brand-fill); box-shadow: var(--shadow-sm); transform: translateY(-1px); text-decoration: none; }
.links-grid a b { color: var(--brand); }
.links-grid a small { display: block; color: var(--muted); }

/* ----------------------------- console ----------------------------- */
.params { display: grid; gap: 10px; margin-bottom: 12px; }
.params .field { min-width: 0; }
.params small { color: var(--muted); font-weight: 400; }
pre.mono { margin: 0; background: var(--code-bg); color: var(--code-text); border: 1px solid var(--code-line); border-radius: var(--r); padding: 14px 16px; overflow: auto; font-size: 12.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; text-align: left; scrollbar-width: thin; }
.curl { margin-top: 12px; max-height: 140px; font-size: 12px; }
.resp { min-height: 260px; max-height: 520px; }
.resp[data-empty] { display: grid; place-items: center; text-align: center; color: #8d99bd; font-family: var(--font); direction: rtl; }
.resp-badge { font-size: 12px; padding: 0 10px; border-radius: 99px; background: var(--surface-2); font-weight: 600; font-family: var(--mono); line-height: 1.8; }
.resp-badge:empty { display: none; }
.resp-badge.ok { color: var(--ok); background: var(--ok-bg); } .resp-badge.bad { color: var(--bad); background: var(--bad-bg); }
.wlog { background: var(--code-bg); color: var(--code-text); border: 1px solid var(--code-line); border-radius: var(--r); padding: 12px 14px; height: 300px; overflow: auto; font-size: 12.5px; margin-top: 4px; text-align: left; scrollbar-width: thin; }
.wlog div { white-space: pre-wrap; word-break: break-all; padding: 2px 0; border-bottom: 1px solid var(--code-line); line-height: 1.7; }
.wlog .out { color: #8cd0ff; } .wlog .in { color: #9be7a6; } .wlog .sys { color: #f1c667; } .wlog .tok { color: #6b7799; }

/* ----------------------------- docs ----------------------------- */
.docs-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.docs-layout > .card { margin-bottom: 0; }
.toc { position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 40px); overflow: auto; padding: 10px; scrollbar-width: thin; }
.toc a { display: block; padding: 4px 12px; border-radius: var(--r-sm); color: var(--text-2); font-size: 13.5px; line-height: 1.8; }
.toc a.h2 { font-weight: 600; margin-top: 4px; }
.toc a.h3 { padding-inline-start: 26px; color: var(--muted); font-size: 12.5px; }
.toc a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.docs { padding: 32px 40px; line-height: 2; }
.docs h2 { font-size: 22px; margin-top: 2em; padding-bottom: .45em; border-bottom: 1px solid var(--line); }
.docs h2:first-child { margin-top: 0; }
.docs h3 { font-size: 17px; margin-top: 1.7em; display: block; }
.docs h4 { font-size: 14.5px; color: var(--muted); margin-top: 1.3em; }
.docs table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 12px 0 18px; font-size: 13.5px; display: block; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
.docs th, .docs td { border-bottom: 1px solid var(--line); padding: 8px 14px; text-align: start; vertical-align: top; }
.docs tr:last-child td { border-bottom: 0; }
.docs th { background: var(--surface-2); white-space: nowrap; font-weight: 700; }
.docs pre { position: relative; margin: 12px 0 18px; background: var(--code-bg); color: var(--code-text); border: 1px solid var(--code-line); border-radius: var(--r); padding: 16px 18px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.75; direction: ltr; text-align: left; }
.docs pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.docs .copy { position: absolute; top: 8px; inset-inline-end: 8px; font: 11.5px var(--font); background: #1d2748; color: #b7c2e6; border: 1px solid #2b3764; border-radius: 7px; padding: 1px 10px; cursor: pointer; transition: .15s var(--ease); }
.docs .copy:hover { background: #2a3766; color: #fff; }
.docs .note { background: var(--brand-soft); border-inline-start: 4px solid var(--brand-fill); border-radius: var(--r-sm); padding: 10px 16px; margin: 14px 0; }
.docs .warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border-inline-start: 4px solid var(--warn); border-radius: var(--r-sm); padding: 10px 16px; margin: 14px 0; }
.docs .method { display: inline-block; font-family: var(--mono); font-weight: 700; font-size: 12px; padding: 0 10px; border-radius: 7px; color: #fff; margin-inline-end: 8px; direction: ltr; line-height: 1.9; }
.docs .method.get { background: #1864ab; } .docs .method.post { background: #2b8a3e; } .docs .method.ws { background: #6741d9; }
.docs .path { font-family: var(--mono); direction: ltr; unicode-bidi: plaintext; }
.docs ul, .docs ol { padding-inline-start: 24px; }
.docs li { margin-bottom: .2em; }

/* ----------------------------- modal & toast ----------------------------- */
.modal { position: fixed; inset: 0; background: rgba(6, 9, 20, .62); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); z-index: 60; display: grid; place-items: center; padding: 20px; animation: fade .18s var(--ease); }
@keyframes fade { from { opacity: 0; } }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); width: min(860px, 100%); max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column; padding: 22px; box-shadow: var(--shadow-lg); animation: pop .24s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-box.small { width: min(460px, 100%); gap: 10px; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.modal-head h3 { margin: 0; font-size: 17.5px; display: block; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.modal-body { flex: 1; overflow: auto; margin: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; font: inherit; white-space: pre-wrap; line-height: 2; scrollbar-width: thin; }
.modal-foot { margin-top: 14px; display: flex; justify-content: flex-end; }
.toast { position: fixed; bottom: 26px; inset-inline-start: 50%; transform: translateX(50%); background: var(--text); color: var(--bg); padding: 9px 22px; border-radius: 99px; z-index: 90; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in .25s var(--ease); }
[dir="ltr"] .toast { transform: translateX(-50%); }
@keyframes toast-in { from { opacity: 0; margin-bottom: -12px; } }
.scrim { position: fixed; inset: 0; background: rgba(6, 9, 20, .55); z-index: 35; animation: fade .2s var(--ease); }

/* scrollbars (webkit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ----------------------------- responsive ----------------------------- */
@media (max-width: 1100px) {
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: 290px; max-width: 86vw; z-index: 40; transform: translateX(100%); transition: transform .26s var(--ease), visibility 0s .26s; box-shadow: var(--shadow-lg); visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; transition-delay: 0s; }
  .nav a.on::before { inset-inline-start: -14px; }
  .icon-btn.menu-btn { display: inline-grid; }
  .docs-layout { grid-template-columns: 1fr; }
  .toc { position: static; max-height: 220px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 14px 14px 24px; }
  .chat-shell { height: calc(100vh - var(--topbar-h) - 28px); height: calc(100dvh - var(--topbar-h) - 28px); }
  .docs { padding: 20px 18px; }
  .kv { grid-template-columns: 1fr; }
  .kv .k { border-bottom: 0; padding-bottom: 0; background: transparent; }
  .kv .v { background: var(--surface); }
}
@media (max-width: 640px) {
  .page-sub, .top-actions .btn span { display: none; }
  .top-actions .btn { padding: 0; width: 40px; }
  .examples { grid-template-columns: 1fr; }
  .chat-bar { gap: 8px; padding: 8px 12px; }
  .chat-bar .btn { padding: 0; width: 38px; min-height: 38px; }
  .chat-bar .btn span { display: none; }
  .seg button { padding-inline: 10px; }
  .welcome h2 { font-size: 22px; }
  .search-row { flex-direction: column; }
  .composer { padding: 4px 12px 10px; }
  .composer-hint { display: none; }
  .messages { padding: 16px 12px 8px; }
  .msg.user .bubble { max-width: 94%; }
  .card { padding: 16px; }
  .bar { grid-template-columns: minmax(70px, 34%) 1fr auto; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
