/* ==========================================================================
   dotsignal panel — design system
   1. fonts  2. tokens  3. base  4. app shell  5. components  6. pages
   7. responsive  8. motion / a11y
   ========================================================================== */

/* 1. fonts (self-hosted, no external requests) ---------------------------- */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.ttf") format("truetype");
  font-weight: 100 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.ttf") format("truetype");
  font-weight: 600 900;
  font-style: normal;
  font-display: swap;
}

/* 2. tokens ---------------------------------------------------------------- */
:root {
  /* type scale */
  --font: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --fs-2xs: .6875rem;  /* 11 */
  --fs-xs: .75rem;     /* 12 */
  --fs-sm: .8125rem;   /* 13 */
  --fs-md: .9375rem;   /* 15 */
  --fs-lg: 1.0625rem;  /* 17 */
  --fs-xl: 1.25rem;    /* 20 */
  --fs-2xl: 1.5rem;    /* 24 */
  --fs-3xl: 1.875rem;  /* 30 */
  --lh-tight: 1.35;
  --lh-base: 1.8;

  /* spacing scale (4px rhythm) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;

  /* radii */
  --r-xs: 6px; --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-pill: 999px;

  /* layout */
  --sidebar-w: 268px;
  --topbar-h: 56px;
  --container: 1240px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 160ms;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-text);

  /* dark theme (default) */
  --bg: #0a0d14;
  --surface: #111620;
  --surface-2: #171d2a;
  --surface-3: #1e2635;
  --sidebar: #0d111a;
  --border: #232b3b;
  --border-strong: #324057;
  --text: #eaeef6;
  --text-2: #b9c2d3;
  --muted: #8f9ab0;
  --accent: #3b63e6;
  --accent-hover: #4a72f2;
  --accent-fg: #ffffff;
  --accent-text: #8fb0ff;
  --accent-soft: rgba(91, 135, 255, .15);
  --up: #34d399;
  --up-strong: #0f9f6e;
  --up-soft: rgba(52, 211, 153, .13);
  --down: #ff7373;
  --down-strong: #d83a3a;
  --down-soft: rgba(255, 115, 115, .13);
  --warn: #f6bd4b;
  --warn-soft: rgba(246, 189, 75, .13);
  --info: #5fc4ff;
  --info-soft: rgba(95, 196, 255, .13);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-3: 0 24px 64px rgba(0, 0, 0, .55);
  --grid: rgba(143, 154, 176, .14);
  --scrim: rgba(3, 6, 12, .66);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --surface-3: #e9edf4;
  --sidebar: #ffffff;
  --border: #e1e6ee;
  --border-strong: #c9d1de;
  --text: #121a29;
  --text-2: #3c485c;
  --muted: #586478;
  --accent: #2c55d6;
  --accent-hover: #2447bb;
  --accent-fg: #ffffff;
  --accent-text: #2447bb;
  --accent-soft: rgba(44, 85, 214, .09);
  --up: #0b7a54;
  --up-strong: #0b7a54;
  --up-soft: rgba(11, 122, 84, .1);
  --down: #c22b32;
  --down-strong: #c22b32;
  --down-soft: rgba(194, 43, 50, .09);
  --warn: #8a5600;
  --warn-soft: rgba(196, 123, 0, .13);
  --info: #0b6aa2;
  --info-soft: rgba(11, 106, 162, .1);
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-2: 0 8px 24px rgba(16, 24, 40, .1), 0 2px 6px rgba(16, 24, 40, .06);
  --shadow-3: 0 24px 64px rgba(16, 24, 40, .22);
  --grid: rgba(88, 100, 120, .16);
  --scrim: rgba(15, 22, 36, .5);
  color-scheme: light;
}
/* no-JS fallback: follow the OS when the theme attribute was never set */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f3f5f9; --surface: #fff; --surface-2: #f4f6fa; --surface-3: #e9edf4; --sidebar: #fff;
    --border: #e1e6ee; --border-strong: #c9d1de; --text: #121a29; --text-2: #3c485c; --muted: #586478;
    --accent: #2c55d6; --accent-hover: #2447bb; --accent-text: #2447bb; --accent-soft: rgba(44, 85, 214, .09);
    --up: #0b7a54; --down: #c22b32; --warn: #8a5600; --info: #0b6aa2; color-scheme: light;
  }
}

/* 3. base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: 700; letter-spacing: 0; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { max-width: 100%; }
button { font: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }
code, pre, textarea.code { font-family: var(--mono); direction: ltr; text-align: left; }
pre { margin: 0; white-space: pre-wrap; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: var(--r-xs); }
::selection { background: var(--accent-soft); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.num-ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { flex: none; vertical-align: middle; }
.flip { transform: scaleX(-1); }
.skip-link {
  position: fixed; inset-block-start: var(--s-2); inset-inline-start: var(--s-2); z-index: 200;
  background: var(--accent); color: var(--accent-fg); padding: var(--s-2) var(--s-4); border-radius: var(--r-sm);
  transform: translateY(-200%); transition: transform var(--dur) var(--ease);
}
.skip-link:focus { transform: none; text-decoration: none; }

/* 4. app shell: fixed 100vh frame, sidebar and content scroll independently - */
body.app { overflow: hidden; }
.shell {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh; height: 100dvh; overflow: hidden;
}
.sidebar {
  display: flex; flex-direction: column; min-height: 0; height: 100vh; height: 100dvh;
  background: var(--sidebar); border-inline-end: 1px solid var(--border);
  padding: var(--s-4) var(--s-3) var(--s-3);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding-inline: var(--s-2); margin-block-end: var(--s-4); }
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: var(--text); font-weight: 800; font-size: var(--fs-lg); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; padding: 7px; color: #fff;
  background: linear-gradient(145deg, #5b87ff, #3252d4); box-shadow: 0 4px 14px rgba(59, 99, 230, .4);
}
.icon-btn.drawer-close { display: none; }

.switcher {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 3px; margin-block-end: var(--s-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.switcher a {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px;
  border-radius: 9px; color: var(--muted); font-size: var(--fs-sm); font-weight: 600;
  transition: background var(--dur), color var(--dur);
}
.switcher a:hover { color: var(--text); text-decoration: none; }
.switcher a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); outline: 1px solid var(--border-strong); outline-offset: -1px; }
.switcher a.on .icon { color: var(--accent-text); }

.sb-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-block-end: var(--s-3); scrollbar-width: thin; }
.shell-tag {
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-2); margin-block: var(--s-1) var(--s-1);
  font-size: var(--fs-2xs); color: var(--muted); font-weight: 700; letter-spacing: .02em;
}
.shell-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-text); }
[data-shell="admin"] .shell-tag .dot { background: var(--warn); }
.sb-group { margin-block-end: var(--s-2); }
.sb-label { padding: var(--s-3) var(--s-3) var(--s-1); font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.sb-link {
  position: relative; display: flex; align-items: center; gap: var(--s-3); padding: 9px var(--s-3); margin-block: 1px;
  border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-md);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sb-link .icon { color: var(--muted); transition: color var(--dur); }
.sb-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sb-link:hover .icon { color: var(--text); }
.sb-link.active { background: var(--accent-soft); color: var(--text); font-weight: 700; }
.sb-link.active .icon { color: var(--accent-text); }
.sb-link.active::before {
  content: ""; position: absolute; inset-inline-start: -12px; inset-block: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent-text);
}
[dir="rtl"] .sb-link.active::before { border-radius: 3px 0 0 3px; }

.sb-foot { border-top: 1px solid var(--border); padding: var(--s-3) var(--s-2) 0; display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.who { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface-3); color: var(--text); font-weight: 800; border: 1px solid var(--border-strong);
}
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.4; }
.who-text strong { font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { color: var(--muted); font-size: var(--fs-xs); }
.sb-actions { display: flex; gap: 2px; }
.sb-actions form { margin: 0; }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; height: 100dvh; }
.topbar {
  flex: none; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3); padding-inline: var(--s-6);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border); position: relative; z-index: 20;
}
.icon-btn.menu-btn { display: none; }
.crumbs { min-width: 0; flex: 1; }
.crumbs ol { display: flex; align-items: center; gap: 0; list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs li { display: inline-flex; align-items: center; min-width: 0; }
.crumbs li + li::before { content: "\2039"; margin-inline: var(--s-2); color: var(--border-strong); font-size: 1.2em; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs [aria-current] { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar-end { display: flex; align-items: center; gap: var(--s-2); }
.shell-switch {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); background: var(--surface);
  transition: border-color var(--dur), color var(--dur);
}
.shell-switch:hover { border-color: var(--accent-text); color: var(--text); text-decoration: none; }

.main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; scrollbar-gutter: stable; }
.main:focus { outline: none; }
.container { max-width: var(--container); margin-inline: auto; padding: var(--s-8) var(--s-6) var(--s-16); }
.bottom-nav { display: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); flex: none;
  background: transparent; color: var(--text-2); border: 1px solid transparent; cursor: pointer;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.sm { width: 28px; height: 28px; }
[data-theme="dark"] .i-sun, :root:not([data-theme]) .i-sun { display: inline; }
[data-theme="dark"] .i-moon { display: none; }
[data-theme="light"] .i-sun { display: none; }
[data-theme="light"] .i-moon { display: inline; }
:root:not([data-theme]) .i-moon { display: none; }
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 90; opacity: 0; transition: opacity 200ms var(--ease); }
.scrim.show { opacity: 1; }

/* 5. components ------------------------------------------------------------ */

/* page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-block-end: var(--s-6); }
.page-title { min-width: 0; }
.page-title h1 { font-size: var(--fs-2xl); display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.page-title p { color: var(--muted); margin-block-start: var(--s-1); max-width: 72ch; font-size: var(--fs-md); }
.page-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.page-actions form, form.inline { display: inline-flex; margin: 0; }
.section { margin-block-start: var(--s-6); }
.stack { display: grid; gap: var(--s-4); }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: var(--s-5);
}
.card.flush { padding: 0; overflow: hidden; }
.card h2 { font-size: var(--fs-lg); margin-block-end: var(--s-3); }
.card h3 { font-size: var(--fs-md); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-block-end: var(--s-4); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush > .card-head { padding: var(--s-4) var(--s-5); margin: 0; border-bottom: 1px solid var(--border); }
.card.flush > .table-wrap + .card-foot, .card-foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--muted); }
.grid { display: grid; gap: var(--s-4); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

/* KPI cards */
.kpis { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpis.k6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-4) var(--s-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden;
}
.kpi::after { content: ""; position: absolute; inset-inline: 0; inset-block-start: 0; height: 2px; background: transparent; }
.kpi.good::after { background: var(--up); }
.kpi.bad::after { background: var(--down); }
.kpi.warn::after { background: var(--warn); }
.kpi-label { color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }
.kpi-value { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.3; letter-spacing: -.01em; }
.kpi.bad .kpi-value { color: var(--down); }
.kpi-foot { display: flex; align-items: center; gap: var(--s-2); min-height: 24px; flex-wrap: wrap; }
.kpi-sub { color: var(--muted); font-size: var(--fs-xs); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); color: var(--text-2); line-height: 1.7;
}
.chip.up { background: var(--up-soft); color: var(--up); }
.chip.down { background: var(--down-soft); color: var(--down); }

/* pills (status) and badges (labels) */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.7;
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.pill.ok { background: var(--up-soft); color: var(--up); }
.pill.bad { background: var(--down-soft); color: var(--down); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.live i { box-shadow: 0 0 0 0 currentColor; animation: pulse 2.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.8;
}
.badge.ok { background: var(--up-soft); color: var(--up); }
.badge.bad { background: var(--down-soft); color: var(--down); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }

/* buttons */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 38px; padding: 0 var(--s-4); border-radius: var(--r-sm); cursor: pointer; white-space: nowrap;
  font-family: inherit; font-size: var(--fs-md); font-weight: 600; line-height: 1;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  transition: background var(--dur) var(--ease), border-color var(--dur), transform 80ms, box-shadow var(--dur);
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--down-strong); border-color: var(--down-strong); color: #fff; }
.btn.danger:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger-outline { background: transparent; border-color: var(--down); color: var(--down); }
.btn.danger-outline:hover { background: var(--down-soft); }
.btn.sm, .btn.small { min-height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn.lg { min-height: 46px; padding: 0 var(--s-6); font-size: var(--fs-lg); }
.btn.block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .6; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { color: transparent !important; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--text-2); border-top-color: transparent; animation: spin .7s linear infinite;
}
.btn.primary.is-loading::after { border-color: #fff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

/* forms */
.form-grid { display: grid; gap: var(--s-4) var(--s-5); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, label.lbl { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); line-height: 1.7; }
.field .error-text { font-size: var(--fs-xs); color: var(--down); display: flex; gap: 6px; align-items: center; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  font: inherit; font-size: var(--fs-md); color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 0 var(--s-3); min-height: 40px; width: 100%;
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
textarea { padding: var(--s-3); min-height: 96px; line-height: 1.6; }
select { padding-inline-end: var(--s-8); appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238f9ab0' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1.5 1.5 4.5 5 4.5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
input[aria-invalid="true"], .field.invalid input { border-color: var(--down); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }
input[type=file] { font: inherit; font-size: var(--fs-sm); color: var(--text-2); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--r-sm); padding: var(--s-2); width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; margin-inline-end: var(--s-3); padding: 4px var(--s-3); border: 1px solid var(--border-strong); border-radius: var(--r-xs); background: var(--surface-3); color: var(--text); cursor: pointer; }
textarea.code { min-height: 340px; font-size: var(--fs-sm); line-height: 1.6; tab-size: 2; }
.form-section { margin-block-start: var(--s-6); }
.form-actions { display: flex; gap: var(--s-2); align-items: center; margin-block-start: var(--s-6); flex-wrap: wrap; }
/* switch */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; font-size: var(--fs-md); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 22px; border-radius: var(--r-pill); background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; transition: background var(--dur), border-color var(--dur); flex: none; }
.switch .track::after { content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: transform var(--dur) var(--ease), background var(--dur); }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { background: #fff; transform: translateX(-18px); }
[dir="ltr"] .switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.switch input:disabled + .track { opacity: .5; }

/* tabs and segmented controls */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); margin-block-end: var(--s-5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; padding: var(--s-3) var(--s-4); background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; transition: color var(--dur);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab[aria-current] { color: var(--text); }
.tab[aria-selected="true"]::after, .tab[aria-current]::after { content: ""; position: absolute; inset-inline: var(--s-2); inset-block-end: -1px; height: 2px; border-radius: 2px; background: var(--accent-text); }
.tab-count { margin-inline-start: 6px; font-size: var(--fs-xs); color: var(--muted); }
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); flex-wrap: wrap; }
.segmented a { padding: 4px 14px; border-radius: 9px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a[aria-current] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); outline: 1px solid var(--border-strong); outline-offset: -1px; }
[role="tabpanel"][hidden] { display: none; }

/* tables */
.table-wrap { overflow: auto; max-width: 100%; }
.card.flush .table-wrap { max-height: 640px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
th, td { text-align: start; padding: 11px var(--s-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  position: sticky; inset-block-start: 0; z-index: 2; background: var(--surface-2); color: var(--muted);
  font-weight: 700; font-size: var(--fs-xs); white-space: nowrap; border-bottom: 1px solid var(--border-strong);
}
tbody tr { transition: background var(--dur); }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td strong a, td a strong { color: var(--text); }
th.num, td.num { text-align: end; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num > * { unicode-bidi: isolate; }
td.num.up, td.num.down { font-weight: 700; }
td.spark-cell { width: 130px; padding-block: 6px; }
td.empty, .empty { text-align: center; color: var(--muted); }
table.compact th, table.compact td { padding: 8px var(--s-3); }
.row-link { color: var(--text); font-weight: 700; }

/* empty states */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); padding: var(--s-10) var(--s-6); color: var(--muted); }
.empty-state.compact { padding: var(--s-6) var(--s-4); }
.empty-state strong { color: var(--text); font-size: var(--fs-md); }
.empty-state p { max-width: 46ch; font-size: var(--fs-sm); }
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--muted); margin-block-end: var(--s-2); }
.empty-state .btn { margin-block-start: var(--s-3); }

/* callouts */
.callout { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: var(--text); }
.callout > .icon { color: var(--warn); margin-block-start: 5px; }
.callout strong { display: block; color: var(--warn); }
.callout.danger { background: var(--down-soft); border-color: color-mix(in srgb, var(--down) 35%, transparent); }
.callout.danger > .icon, .callout.danger strong { color: var(--down); }
.callout.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.callout.info > .icon, .callout.info strong { color: var(--info); }
.callout .body { min-width: 0; flex: 1; font-size: var(--fs-sm); }
.callout-stack { display: grid; gap: var(--s-3); margin-block-end: var(--s-5); }

/* toast */
.toasts { position: fixed; inset-block-start: calc(var(--topbar-h) + var(--s-3)); inset-inline-end: var(--s-6); z-index: 120; display: grid; gap: var(--s-2); width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-2); animation: toast-in 260ms var(--ease);
}
.toast-icon { margin-block-start: 3px; }
.toast.ok { border-inline-start: 3px solid var(--up); } .toast.ok .toast-icon { color: var(--up); }
.toast.warn { border-inline-start: 3px solid var(--warn); } .toast.warn .toast-icon { color: var(--warn); }
.toast.error { border-inline-start: 3px solid var(--down); } .toast.error .toast-icon { color: var(--down); }
.toast-body { flex: 1; font-size: var(--fs-sm); font-weight: 600; line-height: 1.8; }
.toast.leaving { opacity: 0; transform: translateY(-8px); transition: opacity 200ms, transform 200ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* confirm dialog */
.dialog { border: 1px solid var(--border-strong); border-radius: var(--r-xl); background: var(--surface); color: var(--text); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-3); }
.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
.dialog[open] { animation: dialog-in 200ms var(--ease); }
.dialog form { padding: var(--s-6); display: grid; gap: var(--s-2); justify-items: start; }
.dialog-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--down-soft); color: var(--down); margin-block-end: var(--s-2); }
.dialog h2 { font-size: var(--fs-xl); }
.dialog p { color: var(--text-2); }
.dialog-actions { display: flex; gap: var(--s-2); justify-content: flex-start; margin-block-start: var(--s-4); width: 100%; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }

/* key-value */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0; margin: 0; font-size: var(--fs-sm); }
.kv dt, .kv dd { padding: 9px 0; border-bottom: 1px dashed var(--border); margin: 0; }
.kv dt { color: var(--muted); padding-inline-end: var(--s-6); }
.kv dd { font-weight: 600; text-align: end; }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: 0; }
details summary { cursor: pointer; color: var(--accent-text); font-size: var(--fs-sm); font-weight: 600; }
details summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.votes { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 6px; }
.vote { font-size: var(--fs-xs); border: 1px solid var(--border-strong); border-radius: var(--r-xs); padding: 1px 8px; color: var(--text-2); }
.vote.LONG { border-color: var(--up); color: var(--up); }
.vote.SHORT { border-color: var(--down); color: var(--down); }
.report-body { white-space: pre-wrap; margin-block: var(--s-3); line-height: 2; color: var(--text-2); }

/* charts */
.eq { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) 54px; gap: var(--s-2); height: var(--eq-h, 220px); grid-template-rows: minmax(0, 1fr); }
.eq-plot { position: relative; min-width: 0; }
.eq-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.eq .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; stroke-dasharray: 2 4; }
.eq .base { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; stroke-dasharray: 5 4; opacity: .7; }
.eq .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.eq .is-up .line { stroke: var(--up); } .eq .is-down .line { stroke: var(--down); }
.eq-dot { position: absolute; inset-inline-end: -4px; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; border: 2px solid var(--surface); }
.eq-dot.is-up { background: var(--up); } .eq-dot.is-down { background: var(--down); }
.eq-axis { position: relative; font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.eq-axis span { position: absolute; inset-inline-start: 0; transform: translateY(-50%); white-space: nowrap; }
.eq-axis span.base { color: var(--text-2); font-weight: 700; }
.dd { margin: 0; height: calc(var(--dd-h, 96px) + 28px); display: flex; flex-direction: column; gap: var(--s-2); }
.dd svg { flex: 1; width: 100%; min-height: 0; margin-inline-end: 62px; width: calc(100% - 62px); overflow: visible; }
.dd .grid { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.dd .line { fill: none; stroke: var(--down); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.dd figcaption { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--muted); padding-inline-end: 62px; }
.dd figcaption strong { font-weight: 700; color: var(--text-2); }
.spark { display: block; width: var(--sw, 120px); height: var(--sh, 36px); max-width: 100%; overflow: visible; }
.spark .line { fill: none; stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.spark.is-up .line { stroke: var(--up); } .spark.is-down .line { stroke: var(--down); }
.spark.is-up .area { fill: var(--up-soft); } .spark.is-down .area { fill: var(--down-soft); }
.spark-empty { color: var(--muted); }
.legend { display: flex; gap: var(--s-4); font-size: var(--fs-xs); color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 2px; margin-inline-end: 6px; vertical-align: middle; background: var(--muted); }

/* progress (drawdown vs limit) */
.meter { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--up); transition: width .4s var(--ease); }
.meter.mid > span { background: var(--warn); } .meter.high > span { background: var(--down); }

/* 6. pages ------------------------------------------------------------------ */

/* user dashboard: account cards */
.acct-card {
  display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-5); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  transition: border-color var(--dur), transform var(--dur) var(--ease), box-shadow var(--dur);
}
.acct-card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-2); text-decoration: none; }
.acct-card:focus-visible { outline-offset: 3px; border-radius: var(--r-lg); }
.acct-top { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3); }
.acct-name { font-weight: 800; font-size: var(--fs-lg); line-height: 1.5; }
.acct-meta { color: var(--muted); font-size: var(--fs-xs); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-block-start: 2px; }
.acct-main { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); }
.acct-equity small { display: block; color: var(--muted); font-size: var(--fs-xs); }
.acct-equity strong { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.3; display: block; }
.acct-spark { flex: 1; min-width: 0; display: flex; justify-content: flex-end; }
.acct-spark .spark { width: 100%; height: 56px; max-width: 200px; }
.acct-figs { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); padding-block-start: var(--s-4); border-top: 1px solid var(--border); }
.acct-figs span { display: block; color: var(--muted); font-size: var(--fs-xs); }
.acct-figs strong { font-size: var(--fs-md); font-weight: 700; }
.acct-dd { display: grid; gap: 6px; }
.acct-dd-head { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--muted); }

/* overview: health strip, feed */
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.health-item { background: var(--surface); padding: var(--s-4) var(--s-5); display: flex; flex-direction: column; gap: 2px; }
.health-item .k { color: var(--muted); font-size: var(--fs-xs); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.health-item .v { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.3; }
.health-item .s { font-size: var(--fs-xs); color: var(--muted); }
.health-item.alert .v { color: var(--down); }
.health-item .led { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.health-item .led.ok { background: var(--up); } .health-item .led.bad { background: var(--down); } .health-item .led.warn { background: var(--warn); }
.layout-2 { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 10px 1fr; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .pt { width: 8px; height: 8px; border-radius: 50%; margin-block-start: 9px; background: var(--muted); }
.feed .pt.bad { background: var(--down); } .feed .pt.warn { background: var(--warn); } .feed .pt.info { background: var(--info); }
.feed .msg { font-size: var(--fs-sm); line-height: 1.8; }
.feed .meta { display: flex; gap: var(--s-2); align-items: center; color: var(--muted); font-size: var(--fs-xs); margin-block-end: 2px; }

/* chart & signal */
.ask { display: flex; gap: var(--s-3); align-items: flex-end; flex-wrap: wrap; }
.ask .field { flex: 1; min-width: 260px; }
.ask-input { position: relative; }
.ask-input .icon { position: absolute; inset-inline-start: var(--s-3); inset-block-start: 11px; color: var(--muted); pointer-events: none; }
.ask-input input { padding-inline-start: 40px !important; min-height: 46px !important; font-size: var(--fs-lg) !important; }
.examples { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-block-start: var(--s-3); align-items: center; font-size: var(--fs-xs); color: var(--muted); }
.example { padding: 3px 12px; border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; }
.example:hover { border-color: var(--accent-text); color: var(--text); text-decoration: none; }
.signal-grid { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1.65fr) minmax(320px, 1fr); align-items: start; }
.chart-frame { background: #0b0e14; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); }
.chart-frame img { display: block; width: 100%; height: auto; }
.tg {
  --tg-bg: #0e1621; --tg-bubble: #182533; --tg-text: #f5f5f5; --tg-meta: #7f91a4; --tg-link: #6ab3f3;
  border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--border); background: var(--tg-bg);
  background-image: radial-gradient(circle at 20% 10%, rgba(106, 179, 243, .08), transparent 40%), radial-gradient(circle at 80% 90%, rgba(106, 179, 243, .06), transparent 45%);
}
.tg-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); background: #17212b; border-bottom: 1px solid rgba(255, 255, 255, .06); color: var(--tg-text); }
.tg-av { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, #5b87ff, #3252d4); color: #fff; padding: 8px; flex: none; }
.tg-head strong { display: block; font-size: var(--fs-sm); line-height: 1.4; }
.tg-head small { color: var(--tg-meta); font-size: var(--fs-xs); }
.tg-body { padding: var(--s-4); display: grid; gap: var(--s-2); }
.tg-bubble { background: var(--tg-bubble); color: var(--tg-text); border-radius: 14px 14px 14px 4px; overflow: hidden; max-width: 100%; box-shadow: 0 1px 1px rgba(0, 0, 0, .25); }
[dir="rtl"] .tg-bubble { border-radius: 14px 14px 4px 14px; }
.tg-bubble img { display: block; width: 100%; height: auto; }
.tg-text { padding: var(--s-2) var(--s-3) var(--s-1); font-size: var(--fs-sm); line-height: 1.9; white-space: pre-wrap; word-break: break-word; font-family: inherit; direction: rtl; text-align: start; }
.tg-time { padding: 0 var(--s-3) var(--s-2); text-align: end; color: var(--tg-meta); font-size: var(--fs-2xs); display: flex; justify-content: flex-end; gap: 8px; }
.explain { white-space: pre-wrap; line-height: 2.05; color: var(--text-2); font-family: inherit; font-size: var(--fs-md); max-width: 74ch; }
.send-row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-4); border-top: 1px solid var(--border); background: var(--surface); }
.send-row p { flex: 1; min-width: 200px; font-size: var(--fs-xs); color: var(--muted); }

/* auto setup presets */
.presets { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.preset { display: flex; flex-direction: column; gap: var(--s-4); }
.preset-head { display: flex; align-items: center; gap: var(--s-3); }
.preset-ic { width: 42px; height: 42px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); flex: none; }
.preset h3 { font-size: var(--fs-lg); }
.preset form { display: grid; gap: var(--s-4); margin-block-start: auto; }

/* login */
body.bare { overflow: auto; }
.theme-float { position: fixed; inset-block-start: var(--s-4); inset-inline-end: var(--s-4); z-index: 10; background: var(--surface); border-color: var(--border); }
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.auth-hero {
  position: relative; overflow: hidden; padding: var(--s-12); display: flex; flex-direction: column; justify-content: space-between; color: #eaf0ff;
  background: radial-gradient(1200px 600px at 100% 0%, rgba(91, 135, 255, .35), transparent 60%), radial-gradient(900px 500px at 0% 100%, rgba(52, 211, 153, .18), transparent 60%), #0a1020;
}
.auth-hero .brand { color: #fff; font-size: var(--fs-xl); }
.auth-hero h2 { font-size: var(--fs-3xl); line-height: 1.5; max-width: 16em; margin-block-end: var(--s-4); }
.auth-hero p { color: #b8c4e0; max-width: 34em; }
.auth-points { list-style: none; padding: 0; margin: var(--s-6) 0 0; display: grid; gap: var(--s-3); }
.auth-points li { display: flex; gap: var(--s-3); align-items: center; color: #d5def5; font-size: var(--fs-sm); }
.auth-points .icon { color: #34d399; }
.auth-art { position: absolute; inset-inline: 0; inset-block-end: 0; height: 30%; opacity: .75; pointer-events: none; z-index: 0; }
.auth-art path.l { fill: none; stroke: #34d399; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.auth-art path.a { fill: url(#au-g); }
.auth-copy { position: relative; z-index: 1; margin-block: auto; padding-block-end: 12%; }
.auth-hero .brand { position: relative; z-index: 1; }
.auth-form-side { display: grid; place-items: center; padding: var(--s-8) var(--s-6); background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: var(--s-6); }
.auth-card h1 { font-size: var(--fs-2xl); }
.auth-card .lead { color: var(--muted); margin-block-start: var(--s-1); }
.auth-card form { display: grid; gap: var(--s-4); }
.auth-mobile-brand { display: none; }
.auth-foot { color: var(--muted); font-size: var(--fs-xs); text-align: center; }
.alert { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--down-soft); color: var(--down); border: 1px solid color-mix(in srgb, var(--down) 35%, transparent); font-size: var(--fs-sm); font-weight: 600; }

/* guide («راهنما») */
.guide-search { position: relative; margin-block-end: var(--s-4); }
.guide-search input { min-height: 46px !important; padding-inline-start: 42px !important; font-size: var(--fs-md) !important; }
.guide-search .icon { position: absolute; inset-inline-start: var(--s-3); inset-block-start: 14px; color: var(--muted); }
.guide-search #guide-count { position: absolute; inset-inline-end: var(--s-3); inset-block-start: 10px; }
.guide-toc { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-block-end: var(--s-8); }
.guide-toc a { padding: 5px 14px; border: 1px solid var(--border); border-radius: var(--r-pill); font-size: var(--fs-sm); color: var(--text-2); background: var(--surface); font-weight: 600; }
.guide-toc a:hover { border-color: var(--accent-text); color: var(--text); text-decoration: none; }
.guide-section { margin-block-end: var(--s-8); scroll-margin-top: var(--s-4); }
.guide-section > h2 { font-size: var(--fs-xl); margin-block-end: var(--s-1); display: flex; gap: var(--s-2); align-items: center; }
.guide-section > p { margin-block-end: var(--s-4); }
.guide-topic { position: relative; padding: 0; margin-block-end: var(--s-3); scroll-margin-top: var(--s-4); transition: border-color var(--dur); }
.guide-topic:hover { border-color: var(--border-strong); }
.guide-topic summary { cursor: pointer; list-style: none; padding: var(--s-4) var(--s-5); padding-inline-end: var(--s-12); display: flex; flex-direction: column; gap: 2px; color: var(--text); }
.guide-topic summary:hover { text-decoration: none; }
.guide-topic summary::-webkit-details-marker { display: none; }
.guide-topic summary::after { content: ""; position: absolute; inset-inline-end: var(--s-5); inset-block-start: 24px; width: 8px; height: 8px; border-inline-end: 2px solid var(--muted); border-block-end: 2px solid var(--muted); transform: rotate(45deg); transition: transform var(--dur) var(--ease); }
.guide-topic[open] summary::after { transform: rotate(225deg); }
.guide-topic summary span { font-size: var(--fs-sm); font-weight: 400; color: var(--muted); }
.guide-body { border-top: 1px solid var(--border); padding: var(--s-4) var(--s-5) var(--s-5); display: grid; gap: var(--s-4); justify-items: start; }
.guide-steps { margin: 0; list-style: persian; padding-inline-start: var(--s-6); display: grid; gap: var(--s-2); color: var(--text-2); }
.guide-steps li::marker { color: var(--accent-text); font-weight: 700; }
.guide-tips { margin: 0; padding: var(--s-3) var(--s-4); padding-inline-start: var(--s-8); background: var(--info-soft); border-radius: var(--r-md); display: grid; gap: var(--s-1); width: 100%; font-size: var(--fs-sm); color: var(--text-2); }
.guide-fixes { margin: 0; display: grid; gap: var(--s-1); }
.guide-fixes dt { font-weight: 700; margin-block-start: var(--s-3); }
.guide-fixes dd { margin: 0; }

/* 7. responsive ------------------------------------------------------------- */
@media (max-width: 1180px) {
  .kpis.k6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout-2 { grid-template-columns: 1fr; }
  .signal-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 100; width: min(320px, 86vw);
    transform: translateX(105%); visibility: hidden; box-shadow: var(--shadow-3);
    transition: transform 240ms var(--ease), visibility 0s linear 240ms; padding-top: max(var(--s-4), env(safe-area-inset-top));
  }
  [dir="ltr"] .sidebar { transform: translateX(-105%); }
  .sidebar.open { transform: none; visibility: visible; transition: transform 240ms var(--ease), visibility 0s; }
  .icon-btn.drawer-close { display: inline-grid; }
  .icon-btn.menu-btn { display: inline-grid; }
  .topbar { padding-inline: var(--s-3); }
  .shell-switch span { display: none; }
  .shell-switch { padding: 6px; }
  .container { padding: var(--s-5) var(--s-4) var(--s-8); }
  .bottom-nav {
    flex: none; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--sidebar); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; background: none; border: 0; color: var(--muted);
    font-size: var(--fs-2xs); font-weight: 600; cursor: pointer; min-height: 54px; justify-content: center;
  }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav .active, .bottom-nav [aria-current] { color: var(--accent-text); }
  .toasts { inset-inline: var(--s-3); width: auto; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .grid.cards { grid-template-columns: 1fr; }
  .page-title h1 { font-size: var(--fs-xl); }
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-mobile-brand { display: flex; justify-content: center; }
}
@media (max-width: 560px) {
  .kpis.k6 .kpi:first-child, .health-item:last-child { grid-column: 1 / -1; }
  .health { grid-template-columns: repeat(2, 1fr); }
  .crumbs li:not(:last-child) { display: none; }
  .crumbs li + li::before { display: none; }
  .shell-switch { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .kpi { padding: var(--s-3) var(--s-4); }
  .kpi-value { font-size: var(--fs-xl); }
  .page-actions { width: 100%; }
  .card { padding: var(--s-4); }
  .acct-main { flex-direction: column; align-items: stretch; }
  .acct-spark .spark { max-width: none; }
  th, td { padding: 10px var(--s-3); }
  .form-grid { grid-template-columns: 1fr; }
  .eq { grid-template-columns: minmax(0, 1fr) 44px; }
  .dd svg { width: calc(100% - 52px); margin-inline-end: 52px; }
  .dd figcaption { padding-inline-end: 52px; }
}

/* 8. motion and accessibility ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .sb-link.active { outline: 2px solid Highlight; }
  .btn.primary { border: 2px solid ButtonText; }
}

/* flex-column value cells hug the start edge (right in RTL) */
.kpi-value, .health-item .v, .acct-equity strong { align-self: flex-start; }
