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

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dde1e8;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --user-bubble: #e8efff;
  --danger: #b42318;
  --ok: #16a34a;
  --code-bg: #f1f3f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #4f8cff;
    --accent-text: #0b0d11;
    --user-bubble: #1d2a45;
    --danger: #f97066;
    --ok: #4ade80;
    --code-bg: #0b0d11;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.75 "Vazirmatn", Tahoma, system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.btn-primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: .55rem 1.2rem; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: .25rem .7rem; cursor: pointer; color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.brand { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: .5rem; direction: ltr; justify-content: flex-end; }
.brand-dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--accent); }

/* ---------- ورود ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem 1.5rem;
}
.login-card .brand { justify-content: flex-start; }
.login-card form { display: grid; gap: 1rem; margin-top: 1.25rem; }
.login-card label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
.login-card input {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.alert { margin-top: 1rem; padding: .6rem .8rem; border-radius: 10px; color: var(--danger); border: 1px solid var(--danger); font-size: .9rem; }

/* ---------- قاب اصلی ---------- */
.shell { display: grid; grid-template-columns: 270px 1fr; height: 100dvh; }
.sidebar {
  background: var(--surface); border-inline-start: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem; gap: 1rem; min-height: 0;
}
.sidebar .brand { justify-content: flex-start; }
.nav { display: grid; gap: .15rem; }
.nav-item { display: flex; justify-content: space-between; align-items: center; padding: .4rem .6rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .92rem; }
.nav-item.active { background: var(--surface-2); font-weight: 600; }
.nav-item.soon { color: var(--muted); }
.nav-item small { font-size: .72rem; border: 1px solid var(--border); border-radius: 6px; padding: 0 .35rem; }
.side-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.conv-list li { display: flex; align-items: center; gap: .25rem; border-radius: 8px; }
.conv-list li:hover, .conv-list li.active { background: var(--surface-2); }
.conv-list a { flex: 1; padding: .35rem .6rem; color: var(--text); text-decoration: none; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .del { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 .5rem; }
.conv-list li:hover .del { opacity: 1; }
.side-foot { display: grid; gap: .5rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.side-foot form { margin: 0; }
.side-foot .btn-ghost { width: 100%; }
.status { display: flex; align-items: center; gap: .45rem; font-size: .8rem; color: var(--muted); }
.status .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--ok); }
.status.bad .dot { background: var(--danger); }

/* ---------- چت ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-head select { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .25rem .5rem; direction: ltr; }
.toggle { display: flex; align-items: center; gap: .35rem; font-size: .9rem; color: var(--muted); cursor: pointer; }
.menu { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 1rem; }
.empty { margin: auto; text-align: center; }
.empty h1 { margin: 0 0 .25rem; font-size: 1.6rem; }
.msg { max-width: 820px; width: 100%; margin-inline: auto; }
.msg .bubble { padding: .7rem 1rem; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); width: fit-content; max-width: 85%; margin-inline-start: auto; white-space: pre-wrap; }
.msg.assistant .bubble { background: transparent; padding-inline: 0; }
.msg .meta { font-size: .75rem; color: var(--muted); margin-top: .2rem; direction: ltr; text-align: end; }
.msg.error .bubble { color: var(--danger); }
.msg details { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.msg details summary { cursor: pointer; }
.msg details div { white-space: pre-wrap; border-inline-start: 2px solid var(--border); padding-inline-start: .75rem; margin-top: .3rem; }
.bubble p { margin: 0 0 .6rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: .75rem; overflow-x: auto; direction: ltr; text-align: left; }
.bubble code { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: .88em; }
.bubble :not(pre) > code { background: var(--code-bg); padding: .05rem .3rem; border-radius: 5px; }
.bubble ul, .bubble ol { margin: 0 0 .6rem; padding-inline-start: 1.4rem; }
.bubble h3, .bubble h4 { margin: .8rem 0 .3rem; }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

.composer { display: flex; gap: .5rem; padding: .75rem 1rem 1rem; max-width: 852px; width: 100%; margin-inline: auto; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 40vh; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: .65rem .9rem; line-height: 1.6;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- صفحه‌های داده ---------- */
.page { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.page-body { flex: 1; overflow-y: auto; padding: 1.25rem 1rem 2rem; width: 100%; max-width: 980px; margin-inline: auto; }
.page-body h2 { font-size: 1.05rem; margin: 1.5rem 0 .25rem; }
.note { background: var(--surface-2); border-radius: 10px; padding: .7rem 1rem; font-size: .9rem; }
.small { font-size: .82rem; margin: 0 0 .5rem; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.page-body table { width: 100%; border-collapse: collapse; font-size: .88rem; white-space: nowrap; }
.page-body th { text-align: start; color: var(--muted); font-weight: 500; }
.page-body th, .page-body td { padding: .45rem .75rem; border-bottom: 1px solid var(--border); }
.page-body tr:last-child td { border-bottom: 0; }
.page-body tr.baseline { background: var(--surface-2); font-weight: 600; }
.page-body details summary { cursor: pointer; color: var(--muted); margin-bottom: .5rem; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

@media (max-width: 760px) {
  .page-body { padding: 1rem 16px 2rem; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 82%; max-width: 300px; z-index: 10; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .4); }
  .menu { display: inline-block; }
  .messages { padding: 1rem 16px; }
  .composer { padding: .5rem 16px 1rem; }
}
