/* ==========================================================================
   Algorist design system
   --------------------------------------------------------------------------
   Tokens (custom properties) for light + dark themes, layout shell, and
   components: cards, KPI tiles, tables, badges, tabs, buttons, forms, modals,
   toasts, empty states, skeletons, code blocks, drawer, dropzone.
   Live reference: /design-system  ·  Jinja macros: templates/_components.html
   Theme: <html data-theme="light|dark"> (set by js/theme-init.js; falls back to
   prefers-color-scheme when no data-theme is present).
   ========================================================================== */

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/fonts/inter-latin-wght-normal.woff2") format("woff2-variations");
}
@font-face {
  font-family: "JetBrains Mono Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  src: url("../vendor/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2-variations");
}

/* ---------------------------------------------------------------- tokens */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --font-sans: "Inter Variable", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono Variable", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #e3e8ef;
  --border-strong: #cfd6e0;
  --text: #0f1729;
  --text-2: #475569;
  --text-3: #5b6b80; /* WCAG AA (>= 4.5:1) on every surface, incl. --surface-3 */

  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #eaf1ff;
  --brand-text: #1d4ed8;
  --on-brand: #ffffff;

  --pos: #0a7350;
  --pos-soft: #e2f5ec;
  --neg: #c0283a;
  --neg-soft: #fdebed;
  --warn: #935b00;
  --warn-soft: #fdf2dc;
  --info: #0866a3;
  --info-soft: #e1f1fb;
  --neutral: #556275;
  --neutral-soft: #eef1f5;

  --sev-critical: #b4232f;
  --sev-high: #a83c14;
  --sev-medium: #7d5900;
  --sev-low: #1d4ed8;
  --sev-info: #556275;

  /* chart palette (charts.js reads these) */
  --chart-strategy: #2563eb;
  --chart-benchmark: #8a94a6;
  --chart-pos: #12a26f;
  --chart-neg: #e0414f;
  --chart-grid: #edf1f5;
  --chart-axis: #64748b;
  --chart-series-3: #7c3aed;
  --chart-series-4: #0891b2;
  --chart-series-5: #d97706;
  --chart-series-6: #db2777;

  --sidebar-bg: #0b1324;
  --sidebar-bg-2: #0f1a30;
  --sidebar-text: #a6b1c4;
  --sidebar-text-strong: #f3f6fb;
  --sidebar-section: #5f6d86;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(84, 145, 255, 0.16);
  --sidebar-border: rgba(255, 255, 255, 0.07);

  --shadow-sm: 0 1px 2px rgba(15, 23, 41, 0.05);
  --shadow-md: 0 4px 14px -4px rgba(15, 23, 41, 0.1), 0 2px 4px -2px rgba(15, 23, 41, 0.05);
  --shadow-lg: 0 20px 48px -12px rgba(15, 23, 41, 0.24), 0 4px 12px -4px rgba(15, 23, 41, 0.08);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.25);
  --overlay: rgba(8, 13, 24, 0.5);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --sidebar-w: 236px;
  /* the top bar grows by the safe-area inset (notch / status bar of an installed app; 0 elsewhere),
     so everything sticky under it (tabs, editor bars, side panels) follows */
  --topbar-h: calc(56px + env(safe-area-inset-top, 0px));
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0f18;
  --surface: #111827;
  --surface-2: #0e1521;
  --surface-3: #182233;
  --border: #1f2a3b;
  --border-strong: #2c3a50;
  --text: #e6ebf3;
  --text-2: #a3aec0;
  --text-3: #8794aa;

  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: rgba(77, 141, 255, 0.14);
  --brand-text: #8db5ff;
  --on-brand: #ffffff;

  --pos: #3ccf95;
  --pos-soft: rgba(60, 207, 149, 0.13);
  --neg: #f4666f;
  --neg-soft: rgba(244, 102, 111, 0.13);
  --warn: #e9ad3c;
  --warn-soft: rgba(233, 173, 60, 0.13);
  --info: #4db1ec;
  --info-soft: rgba(77, 177, 236, 0.13);
  --neutral: #94a3b8;
  --neutral-soft: rgba(148, 163, 184, 0.12);

  --sev-critical: #ff6b75;
  --sev-high: #ff8a4c;
  --sev-medium: #f2c14e;
  --sev-low: #6ea2ff;
  --sev-info: #94a3b8;

  --chart-strategy: #5b9bff;
  --chart-benchmark: #8792a6;
  --chart-pos: #3ccf95;
  --chart-neg: #f4666f;
  --chart-grid: #1b2536;
  --chart-axis: #7a879c;
  --chart-series-3: #a78bfa;
  --chart-series-4: #22d3ee;
  --chart-series-5: #fbbf24;
  --chart-series-6: #f472b6;

  --sidebar-bg: #070c15;
  --sidebar-bg-2: #0a111d;
  --sidebar-border: rgba(255, 255, 255, 0.06);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 18px -6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, 0.65);
  --focus: 0 0 0 3px rgba(91, 155, 255, 0.35);
  --overlay: rgba(2, 6, 12, 0.66);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0a0f18; --surface: #111827; --surface-2: #0e1521; --surface-3: #182233;
    --border: #1f2a3b; --border-strong: #2c3a50; --text: #e6ebf3; --text-2: #a3aec0; --text-3: #8794aa;
    --brand: #2563eb; --brand-hover: #1d4ed8; --brand-soft: rgba(77, 141, 255, 0.14); --brand-text: #8db5ff;
    --pos: #3ccf95; --pos-soft: rgba(60, 207, 149, 0.13); --neg: #f4666f; --neg-soft: rgba(244, 102, 111, 0.13);
    --warn: #e9ad3c; --warn-soft: rgba(233, 173, 60, 0.13); --info: #4db1ec; --info-soft: rgba(77, 177, 236, 0.13);
    --neutral: #94a3b8; --neutral-soft: rgba(148, 163, 184, 0.12);
    --chart-strategy: #5b9bff; --chart-benchmark: #8792a6; --chart-pos: #3ccf95; --chart-neg: #f4666f;
    --chart-grid: #1b2536; --chart-axis: #7a879c; --sidebar-bg: #070c15; --sidebar-bg-2: #0a111d;
    --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, 0.65); --overlay: rgba(2, 6, 12, 0.66);
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-sans);
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
/* Links inside running text are underlined, not told apart by colour alone (WCAG 1.4.1). */
p a:not(.btn):not(.badge):not(.chip), li > p a:not(.btn), .callout a:not(.btn), .help a, .prose a,
.text-sm a:not(.btn):not(.badge), .analyst-note a { text-decoration: underline; text-underline-offset: 2px;
  text-decoration-thickness: 1px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 0.75em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
img, svg { vertical-align: middle; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--brand) 25%, transparent); }
.icon { flex: none; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
  /* paint the sidebar column to the bottom of long pages (the sidebar itself is sticky) */
  background: linear-gradient(90deg, var(--sidebar-bg-2) 0 var(--sidebar-w), transparent var(--sidebar-w));
}
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  padding: 14px 12px 12px;
  z-index: 50;
  scrollbar-width: thin;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--sidebar-text-strong); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 60%, #1e3a8a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px -4px rgba(37, 99, 235, 0.7);
  color: #fff;
}
.brand-name { font-weight: 700; font-size: 15.5px; letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { display: block; font-size: 11px; font-weight: 500; color: var(--sidebar-section); letter-spacing: 0.04em; text-transform: uppercase; }
.nav-section { padding: 6px 0 4px; }
.nav-section-title {
  font-size: 10.5px; font-weight: 650; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--sidebar-section); padding: 8px 12px 6px;
}
.nav-link {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 7px 12px; margin: 1px 0; border-radius: 8px;
  color: var(--sidebar-text); font-size: 13.5px; font-weight: 500; text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav-link .icon { opacity: 0.85; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link.active .icon { opacity: 1; color: #8fb7ff; }
.nav-link.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: #5b9bff;
}
.sidebar-footer { margin-top: auto; padding: 12px 8px 2px; border-top: 1px solid var(--sidebar-border); display: flex; flex-direction: column; gap: 8px; }
.sidebar-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 550;
  color: #b9c6dc; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--sidebar-border);
  padding: 4px 8px; border-radius: 999px; width: fit-content;
}
a.sidebar-chip { text-decoration: none; }
a.sidebar-chip:hover { color: var(--sidebar-text-strong); background: var(--sidebar-hover); text-decoration: none; }
.sidebar-meta { font-size: 11px; color: var(--sidebar-section); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  --topbar-px: 24px;
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: env(safe-area-inset-top, 0px) max(var(--topbar-px), env(safe-area-inset-right, 0px)) 0 max(var(--topbar-px), env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.workspace-pill {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  font-weight: 600; font-size: 13.5px; color: var(--text);
}
.workspace-pill .ws-icon {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; flex: none;
  background: var(--brand-soft); color: var(--brand-text); font-size: 12px; font-weight: 700;
}
.topbar-crumb { color: var(--text-3); font-size: 13px; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn.menu-toggle { display: none; }
.content {
  --content-px: 28px; --content-pb: 56px;
  width: 100%; max-width: 1480px; margin: 0 auto;
  padding: 24px max(var(--content-px), env(safe-area-inset-right, 0px)) calc(var(--content-pb) + env(safe-area-inset-bottom, 0px)) max(var(--content-px), env(safe-area-inset-left, 0px));
}
.sidebar-backdrop { display: none; }

/* ---------------------------------------------------------------- page header */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header-text { min-width: 0; }
.eyebrow { font-size: 11.5px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-text); margin-bottom: 4px; }
.page-title { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; }
.page-subtitle { color: var(--text-2); margin: 4px 0 0; max-width: 760px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- layout utils */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-nowrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main-side { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
.kpi-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi-grid.dense { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mono, code, kbd, pre { font-family: var(--font-mono); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.flat { color: var(--text-2); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.w-full { width: 100%; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); min-width: 0;
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.card-header.bordered { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14.5px; font-weight: 640; display: flex; align-items: center; gap: 8px; }
.card-subtitle { color: var(--text-3); font-size: 12.5px; margin: 3px 0 0; }
.card-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 0; }
.card-body.flush-top { padding-top: 0; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.card.interactive { transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.card.interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }

/* ---------------------------------------------------------------- KPI tiles */
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px 15px; box-shadow: var(--shadow-sm);
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12.5px; font-weight: 550; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.kpi-icon {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--brand-soft); color: var(--brand-text);
}
.kpi-value { font-size: 26px; font-weight: 680; letter-spacing: -0.025em; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value.pos { color: var(--pos); } .kpi-value.neg { color: var(--neg); }
.kpi-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 22px; }
.delta {
  display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.delta.pos { color: var(--pos); background: var(--pos-soft); }
.delta.neg { color: var(--neg); background: var(--neg-soft); }
.delta.flat { color: var(--text-2); background: var(--neutral-soft); }
.kpi-sub { font-size: 12px; color: var(--text-3); }

/* tooltip: <span data-tip="Explanation">…</span> */
[data-tip] { position: relative; }
.tip-trigger { display: inline-grid; place-items: center; color: var(--text-3); cursor: help; border-radius: 50%; }
.tip-trigger:hover, .tip-trigger:focus-visible { color: var(--text); }
[data-tip]:hover::after, [data-tip]:focus-visible::after, [data-tip].tip-open::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  width: max-content; max-width: 260px; padding: 7px 10px; border-radius: 8px;
  background: #0f1729; color: #eef2f8; font-size: 12px; font-weight: 450; line-height: 1.45;
  text-align: left; white-space: normal; box-shadow: var(--shadow-md); z-index: 80; pointer-events: none;
  letter-spacing: 0; text-transform: none;
}
:root[data-theme="dark"] [data-tip]:hover::after, :root[data-theme="dark"] [data-tip].tip-open::after { background: #253047; }
/* touch screens: a tap toggles .tip-open (app.js), which gets an explicit box inside the screen
   (--tip-left / --tip-w); the sticky :hover a tap leaves behind shows nothing */
@media (hover: none) {
  [data-tip]:hover:not(.tip-open)::after, [data-tip]:focus-visible:not(.tip-open)::after { content: none; }
  [data-tip].tip-open::after { left: var(--tip-left, 0px); width: var(--tip-w, 260px); max-width: none; transform: none; }
}

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table-wrap.borderless { border: 0; border-radius: 0; }
.table-wrap.sticky { max-height: var(--table-max-h, 620px); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  position: sticky; top: 0; z-index: 2; text-align: left; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-3) 55%, transparent); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.table td.shrink, .table th.shrink { width: 1%; white-space: nowrap; }
.table.compact td { padding: 7px 12px; } .table.compact th { padding: 7px 12px; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th[data-sort]::after { content: "↕"; opacity: 0.35; margin-left: 6px; font-size: 11px; }
.table th[aria-sort="ascending"]::after { content: "↑"; opacity: 0.9; }
.table th[aria-sort="descending"]::after { content: "↓"; opacity: 0.9; }
.table a.row-link { color: var(--text); font-weight: 560; }
.table a.row-link:hover { color: var(--brand-text); }
.table .cell-sub { display: block; font-size: 12px; color: var(--text-3); font-weight: 400; }
.table td.name-cell { min-width: 180px; }
.card-body.bordered-top { border-top: 1px solid var(--border); }
.table .cell-sub.show-xs, .show-xs { display: none; }
/* Scrollable tables: a fade on the side that has more columns (set by app.js), and keyboard-focusable. */
.table-wrap[data-overflow="right"] { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); mask-image: linear-gradient(to right, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); }
.table-wrap[data-overflow="left"] { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); mask-image: linear-gradient(to left, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); }
.table-wrap[data-overflow="both"] { -webkit-mask-image: linear-gradient(to right, rgba(0, 0, 0, 0.18), #000 56px, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); mask-image: linear-gradient(to right, rgba(0, 0, 0, 0.18), #000 56px, #000 calc(100% - 56px), rgba(0, 0, 0, 0.18)); }
.table-wrap[data-overflow]:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.table-scroll-hint { display: none; font-size: 12px; color: var(--text-3); padding: 6px 16px 0; }
.table-scroll-hint.show { display: block; }
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge-xs { height: 17px; padding: 0 6px; font-size: 10.5px; }
.table tr.group-row td {
  background: var(--surface-2); font-weight: 600; padding-top: 9px; padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
}
.table tr.group-row:hover td { background: var(--surface-2); }
.table tr.group-row > td { max-width: 0; }
.table tr.member td:first-child { padding-left: 34px; position: relative; }
.table tr.member td:first-child::before {
  content: ""; position: absolute; left: 18px; top: 0; bottom: 0; width: 2px; background: color-mix(in srgb, var(--brand) 35%, var(--border));
}
.table tr.member.last td:first-child::before { bottom: 50%; }
.table tr.member td:first-child::after {
  content: ""; position: absolute; left: 18px; top: 50%; width: 9px; height: 2px; background: color-mix(in srgb, var(--brand) 35%, var(--border));
}
.table tr.is-hidden { display: none; }
.table-empty { padding: 28px; text-align: center; color: var(--text-3); }
.table-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.toolbar-search { flex: 1 1 240px; max-width: 360px; }
.select.toolbar-select { width: auto; min-width: var(--select-min, 150px); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1; white-space: nowrap;
  background: var(--neutral-soft); color: var(--text-2); border: 1px solid transparent; vertical-align: middle;
  letter-spacing: 0.01em;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-outline { background: transparent; border-color: var(--border-strong); }
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-pos, .badge-completed, .badge-success { background: var(--pos-soft); color: var(--pos); }
.badge-neg, .badge-failed, .badge-error { background: var(--neg-soft); color: var(--neg); }
.badge-warn, .badge-waiting_input { background: var(--warn-soft); color: var(--warn); }
.badge-info, .badge-running { background: var(--info-soft); color: var(--info); }
.badge-queued { background: var(--neutral-soft); color: var(--text-2); }
.badge-stopped { background: var(--neutral-soft); color: var(--text-3); }
.badge-running .dot { animation: pulse 1.4s ease-in-out infinite; }
.badge-critical { background: color-mix(in srgb, var(--sev-critical) 14%, transparent); color: var(--sev-critical); border-color: color-mix(in srgb, var(--sev-critical) 30%, transparent); }
.badge-high { background: color-mix(in srgb, var(--sev-high) 13%, transparent); color: var(--sev-high); }
.badge-medium { background: color-mix(in srgb, var(--sev-medium) 15%, transparent); color: var(--sev-medium); }
.badge-low { background: color-mix(in srgb, var(--sev-low) 12%, transparent); color: var(--sev-low); }
.badge-sev-info { background: var(--neutral-soft); color: var(--sev-info); }
.badge-count { height: 18px; min-width: 18px; padding: 0 5px; justify-content: center; font-size: 11px; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 550 13.5px/1 var(--font-sans); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, color 0.12s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--neg) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-soft { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); box-shadow: none; }
.btn-soft:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14.5px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }
.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading { pointer-events: none; opacity: 0.8; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; display: inline-block; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ari {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, var(--surface)) 0%, var(--surface) 100%);
  border-color: color-mix(in srgb, var(--brand) 40%, var(--border-strong)); color: var(--brand-text);
}
.btn-ari:hover { background: var(--brand-soft); }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--radius); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-btn .badge-count { position: absolute; top: 2px; right: 1px; background: var(--neg); color: #fff; border: 2px solid var(--surface); height: 18px; }

/* ---------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; gap: 16px 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 580; color: var(--text); display: flex; align-items: center; gap: 8px; }
.label .badge { height: 18px; font-size: 10.5px; }
.help { font-size: 12.5px; color: var(--text-3); line-height: 1.45; }
.field-error { font-size: 12.5px; color: var(--neg); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 14px var(--font-sans); transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input:disabled, .select:disabled { background: var(--surface-3); color: var(--text-3); }
.input.mono { font-family: var(--font-mono); font-size: 13px; }
.textarea { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237c8aa0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input-group { position: relative; display: flex; align-items: center; }
.input.control-sm, .select.control-sm { height: 34px; } /* compact field in a toolbar (44 px on touch screens) */
.input-group > .icon { position: absolute; left: 11px; color: var(--text-3); pointer-events: none; }
.input-group > .input { padding-left: 36px; }
.checkbox { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13.5px; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand); margin: 0; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background 0.15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.secret-row { display: flex; gap: 8px; align-items: center; }
.secret-row .input { flex: 1; }
.form-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

/* ---------------------------------------------------------------- callouts */
.callout { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); border: 1px solid; font-size: 13px; line-height: 1.5; }
.callout > .icon { margin-top: 1px; }
.callout-title { font-weight: 640; margin-bottom: 2px; }
.callout-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 28%, transparent); color: var(--text); }
.callout-info > .icon { color: var(--info); }
.callout-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.callout-warn > .icon { color: var(--warn); }
.callout-error { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.callout-error > .icon { color: var(--neg); }
.callout-success { background: var(--pos-soft); border-color: color-mix(in srgb, var(--pos) 30%, transparent); }
.callout-success > .icon { color: var(--pos); }
.callout-readonly { background: var(--surface-2); border-color: var(--border-strong); }
.callout-readonly > .icon { color: var(--brand-text); }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 10px 12px; font: 550 13.5px var(--font-sans); color: var(--text-2); cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--brand); border-radius: 6px 6px 0 0; }
.tab-panel { padding-top: 16px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-3); }
.segmented button { appearance: none; border: 0; background: transparent; color: var(--text-2); font: 550 12.5px var(--font-sans); padding: 5px 10px; border-radius: 7px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------- side nav (settings) */
.subnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + 16px); }
.subnav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 550; font-size: 13.5px; }
.subnav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.subnav a.active { background: var(--brand-soft); color: var(--brand-text); }
.settings-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-section { scroll-margin-top: calc(var(--topbar-h) + 16px); }

/* ---------------------------------------------------------------- modal */
dialog.modal {
  border: 1px solid var(--border); padding: 0; border-radius: var(--radius-xl); background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
dialog.modal.modal-lg { width: min(760px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: modal-in 0.16s ease-out; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 4px; }
.modal-title { font-size: 16px; font-weight: 650; }
.modal-body { padding: 10px 20px 14px; color: var(--text-2); }
.modal-body .form { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 12px 12px 12px 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); font-size: 13.5px; line-height: 1.45; animation: toast-in 0.18s ease-out;
  border-left: 3px solid var(--brand);
}
.toast .icon { margin-top: 1px; }
.toast-body { flex: 1; min-width: 0; word-wrap: break-word; }
.toast-title { font-weight: 620; }
.toast-success { border-left-color: var(--pos); } .toast-success > .icon { color: var(--pos); }
.toast-error { border-left-color: var(--neg); } .toast-error > .icon { color: var(--neg); }
.toast-warn { border-left-color: var(--warn); } .toast-warn > .icon { color: var(--warn); }
.toast-info > .icon { color: var(--brand-text); }
.toast.leaving { animation: toast-out 0.16s ease-in forwards; }
.toast .toast-close { width: 24px; height: 24px; flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- empty + skeleton */
.empty { text-align: center; padding: 40px 24px; color: var(--text-2); }
.empty-icon { width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); }
.empty-title { font-size: 15px; font-weight: 640; color: var(--text); margin-bottom: 4px; }
.empty-text { max-width: 440px; margin: 0 auto 16px; font-size: 13.5px; }
.skeleton {
  display: block; height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 25%, color-mix(in srgb, var(--surface-3) 40%, var(--surface)) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton + .skeleton { margin-top: 10px; }
.skeleton.lg { height: 26px; width: 55%; }
.skeleton.block { height: 220px; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- code */
:not(pre) > code { font-size: 0.88em; background: var(--surface-3); color: var(--text); padding: 1.5px 5px; border-radius: 5px; border: 1px solid var(--border); }
kbd { font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--surface); color: var(--text-2); }
.code-block { position: relative; }
.code-block pre, pre.code {
  margin: 0; padding: 14px 16px; overflow: auto; border-radius: var(--radius);
  background: #0c1322; color: #d6deeb; font-size: 12.5px; line-height: 1.6; border: 1px solid #1b263a;
}
.code-block .copy-btn { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity 0.12s; background: rgba(255, 255, 255, 0.08); color: #c9d4e5; border-color: transparent; box-shadow: none; }
.code-block:hover .copy-btn, .code-block .copy-btn:focus-visible { opacity: 1; }
.code-lang { position: absolute; top: 8px; right: 44px; font-size: 10.5px; color: #7f8ca3; text-transform: uppercase; letter-spacing: 0.06em; }

/* rendered markdown */
.prose { font-size: 14px; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; } .prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 { margin: 1.1em 0 0.45em; }
.prose h1 { font-size: 18px; } .prose h2 { font-size: 16px; } .prose h3 { font-size: 14.5px; }
.prose p, .prose ul, .prose ol { margin: 0 0 0.7em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose table { border-collapse: collapse; font-size: 12.5px; margin: 0.6em 0; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose pre { background: #0c1322; color: #d6deeb; padding: 12px 14px; border-radius: var(--radius); overflow: auto; font-size: 12.5px; }
.prose blockquote { margin: 0 0 0.7em; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }

/* ---------------------------------------------------------------- menus / popovers */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 45; min-width: 220px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 6px; animation: modal-in 0.12s ease-out;
}
.popover.wide { width: min(360px, calc(100vw - 24px)); }
.popover-header { padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); margin: -6px -6px 6px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; border: 0;
  background: none; color: var(--text); font: 500 13.5px var(--font-sans); text-align: left; cursor: pointer; text-decoration: none;
}
.menu-item:hover { background: var(--surface-3); text-decoration: none; }
.menu-item .icon { color: var(--text-3); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.user-chip:hover { border-color: var(--border-strong); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #6366f1, #2563eb); color: #fff; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
}
.user-chip-name { font-size: 13px; font-weight: 580; max-width: 120px; }
.notif-list { max-height: min(360px, calc(100dvh - var(--topbar-h) - 90px)); overflow: auto; overscroll-behavior: contain; }
.notif { display: flex; gap: 10px; padding: 9px 10px; border-radius: 8px; }
.notif:hover { background: var(--surface-2); }
.notif-title { font-weight: 580; font-size: 13px; }
.notif-meta { font-size: 11.5px; color: var(--text-3); }

/* ---------------------------------------------------------------- dropzone + upload */
.dropzone {
  position: relative; display: flex; align-items: center; gap: 20px; padding: 26px 28px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-xl); background: var(--surface);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s; cursor: pointer;
}
.dropzone:hover { border-color: color-mix(in srgb, var(--brand) 60%, var(--border-strong)); }
.dropzone:focus-visible { outline: none; box-shadow: var(--focus); }
.dropzone.is-dragover { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 12%, transparent); }
.dropzone.is-busy { cursor: progress; }
.dropzone-icon {
  width: 52px; height: 52px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-soft), color-mix(in srgb, var(--brand) 22%, transparent)); color: var(--brand-text);
}
.dropzone-title { font-size: 15px; font-weight: 640; }
.dropzone-text { color: var(--text-2); font-size: 13px; margin: 2px 0 0; }
.dropzone-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dropzone input[type="file"] { display: none; }
.dropzone.compact { padding: 18px 20px; }
.upload-list { display: flex; flex-direction: column; gap: 10px; }
.upload-item { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 14px 16px; }
.upload-item-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.upload-item-name { font-weight: 600; min-width: 0; }
.upload-item-body { margin-top: 10px; font-size: 13px; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; width: 0; background: var(--brand); border-radius: inherit; transition: width 0.2s ease; }
.progress.indeterminate > span { width: 35%; animation: indeterminate 1.1s ease-in-out infinite; }
@keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.warning-list { margin: 8px 0 0; padding-left: 18px; color: var(--warn); font-size: 12.5px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: 320px; min-width: 0; }
.chart.sm { height: 220px; } .chart.lg { height: 420px; }
.chart-placeholder { display: grid; place-items: center; color: var(--text-3); font-size: 13px; height: 100%; border: 1px dashed var(--border); border-radius: var(--radius); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend-swatch { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---------------------------------------------------------------- dashboard bits */
.hero {
  position: relative; overflow: hidden; border-radius: var(--radius-xl); padding: 22px 24px;
  background: radial-gradient(1200px 300px at 100% 0%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 60%),
              linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
}
.checklist { display: flex; flex-direction: column; gap: 4px; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 13.5px; }
.check-item:hover { background: var(--surface-2); text-decoration: none; }
.check-dot { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-strong); display: grid; place-items: center; flex: none; color: transparent; }
.check-item.done { color: var(--text-3); }
.check-item.done .check-dot { background: var(--pos); border-color: var(--pos); color: #fff; }
.family-count { font-weight: 600; color: var(--text-3); font-size: 12px; }
.stat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px 20px; margin: 0; }
.stat-list dt { font-size: 12px; color: var(--text-3); font-weight: 550; }
.stat-list dd { margin: 2px 0 0; font-size: 15px; font-weight: 620; font-variant-numeric: tabular-nums; }
.service-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-3); }
.service-dot.running { background: var(--pos); } .service-dot.failed { background: var(--neg); } .service-dot.unavailable { background: var(--warn); }

/* ---------------------------------------------------------------- Ari drawer */
.drawer {
  position: fixed; top: var(--vvt, 0px); right: 0; height: 100vh; height: var(--vvh, 100dvh); width: min(460px, 100vw); z-index: 90;
  padding-right: env(safe-area-inset-right, 0px);
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); transform: translateX(105%); transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 85; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer-header { display: flex; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px; border-bottom: 1px solid var(--border); }
.ari-avatar {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: none; color: #fff;
  background: linear-gradient(135deg, #7c3aed 0%, #2563eb 55%, #0ea5e9 100%);
  box-shadow: 0 6px 16px -6px rgba(37, 99, 235, 0.7);
}
.drawer-title { font-weight: 650; font-size: 15px; }
.drawer-sub { font-size: 12px; color: var(--text-3); }
.drawer-context { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 12.5px; color: var(--text-2); align-items: center; }
.drawer-messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg-user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg-assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-system { align-self: center; max-width: 100%; text-align: center; color: var(--text-3); font-size: 12.5px; padding: 4px 8px; }
.msg-tool { align-self: flex-start; font-size: 12px; color: var(--text-2); display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border-radius: 999px; background: var(--surface-3); }
.msg-thinking { align-self: flex-start; font-size: 12.5px; color: var(--text-3); font-style: italic; border-left: 2px solid var(--border-strong); padding: 2px 10px; max-width: 88%; }
.ari-suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.ari-suggestion { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 9px 12px; cursor: pointer; color: var(--text); font: 500 13px var(--font-sans); }
.ari-suggestion:hover { border-color: var(--brand); background: var(--brand-soft); }
.drawer-composer { border-top: 1px solid var(--border); padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; align-items: flex-end; background: var(--surface); }
.drawer-composer .textarea { min-height: 42px; max-height: 160px; resize: none; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.15s; } .typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------------------------------------------------------------- auth pages */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-aside {
  position: relative; overflow: hidden; color: #e5ecf7; padding: 44px 48px; display: flex; flex-direction: column;
  background:
    radial-gradient(900px 500px at 0% 0%, rgba(59, 130, 246, 0.28), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(124, 58, 237, 0.22), transparent 60%),
    linear-gradient(160deg, #0b1324 0%, #0a1730 55%, #0d1b3a 100%);
}
.auth-aside .brand { padding: 0; }
.auth-aside h2 { font-size: 30px; line-height: 1.2; letter-spacing: -0.025em; margin: 56px 0 12px; max-width: 480px; color: #fff; }
.auth-aside p { color: #a9b6cc; max-width: 460px; font-size: 15px; }
.auth-points { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; gap: 12px; }
.auth-points li { display: flex; gap: 10px; align-items: flex-start; color: #cdd7e8; font-size: 14px; }
.auth-points .icon { color: #7fb0ff; margin-top: 2px; }
.auth-curve { position: absolute; left: 0; right: 0; bottom: 44px; height: 40%; opacity: 0.9; pointer-events: none; }
.auth-foot { margin-top: auto; position: relative; z-index: 1; font-size: 12px; color: #7d8ba3; }
.auth-main { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.auth-card { width: min(420px, 100%); }
.auth-card .card-body { padding: 28px; }
.auth-heading { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-mobile-brand { display: none; margin-bottom: 20px; }
.auth-mobile-brand .brand-name { color: var(--text); }
/* two-factor sign-in (login_enrol / login_verify / recovery codes) */
.otp-input { font-family: var(--font-mono); font-size: 20px; letter-spacing: 0.18em; text-align: center; height: 48px; }
.enrol-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 16px; font-size: 14px; line-height: 1.5; }
.enrol-steps > li::marker { font-weight: 650; color: var(--brand-text); }
.qr-box { display: flex; justify-content: center; margin: 12px 0; }
.qr-box svg { display: block; width: min(220px, 100%); height: auto; aspect-ratio: 1; border-radius: 8px; }
.auth-more > summary { cursor: pointer; font-size: 13px; color: var(--text-2); text-align: center; list-style-position: inside; }
.recovery-codes pre { columns: 2; column-gap: 24px; font-size: 15px; line-height: 1.8; }

/* ---------------------------------------------------------------- theme toggle icons */
.theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: inline-flex; }
:root[data-theme="dark"] .theme-icon-dark { display: none; }
.theme-icon-light, .theme-icon-dark { align-items: center; }

/* ---------------------------------------------------------------- misc */
.status-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.swatch { width: 100%; height: 44px; border-radius: 8px; border: 1px solid var(--border); }
.coming-soon-art { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; margin: 0 auto 18px; color: var(--brand-text); background: var(--brand-soft); }
.error-code { font-size: 56px; font-weight: 750; letter-spacing: -0.04em; color: var(--text-3); line-height: 1; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .grid-main-side { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: calc(272px + env(safe-area-inset-left, 0px)); height: 100vh; height: 100dvh;
    transform: translateX(-102%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg); z-index: 95;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    overscroll-behavior: contain;
  }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 94; }
  .icon-btn.menu-toggle { display: inline-grid; }
  .shell { background: none; }
  .topbar { --topbar-px: 16px; }
  .content { --content-px: 20px; --content-pb: 48px; padding-top: 20px; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .subnav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .subnav a { white-space: nowrap; }
  .auth-page { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .auth-mobile-brand { display: flex; }
}
@media (max-width: 1680px) {
  .grid-2.grid-2-wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1600px) {
  .hide-lg { display: none !important; }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .hide-sm { display: none !important; }
  .dropzone { flex-direction: column; text-align: center; padding: 24px 18px; }
  .dropzone-actions { margin-left: 0; justify-content: center; }
  .page-title { font-size: 20px; }
  .kpi-value { font-size: 23px; }
}
@media (max-width: 480px) {
  .content { --content-px: 12px; --content-pb: 40px; padding-top: 16px; }
  .topbar { --topbar-px: 10px; gap: 4px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi-value { font-size: 20px; }
  .kpi-icon { display: none; }
  .card-header { padding: 14px 14px 0; }
  .card-body { padding: 14px; }
  .btn-ari .btn-label, .user-chip-name, .workspace-pill .ws-name-text { display: none; }
  .user-chip { padding: 3px; }
  .auth-card .card-body { padding: 22px 18px; }
  .table th, .table td { padding: 8px 10px; }
  .hide-xs { display: none !important; }
  .table td.name-cell { min-width: 0; }
  .table .cell-sub.show-xs, .show-xs { display: block; }
  .table .tag-row { display: none; }
}
/* ---------------------------------------------------------------- touch screens and phones
   Phones and tablets (coarse pointer, i.e. a finger): tap targets of 40-44 CSS px, form fields at
   16 px (iOS Safari zooms the page into any smaller field it focuses) and no double-tap delay.
   Desktop (mouse) layouts are unchanged. */
@media (pointer: coarse) {
  a, button, summary, label, input, select, textarea, [role="button"], [data-tab] { touch-action: manipulation; }
  .btn { height: 44px; }
  .btn-sm { height: 40px; padding: 0 12px; }
  .btn-lg { height: 48px; }
  .btn-icon { width: 44px; } .btn-icon.btn-sm { width: 40px; }
  .btn-ari.btn-sm { min-width: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .input, .select, .input.control-sm, .select.control-sm { height: 44px; font-size: 16px; }
  .textarea, .input.mono { font-size: 16px; }
  .input.otp-input { height: 48px; font-size: 20px; } /* the sign-in code field keeps its own size */
  .nav-link { padding-top: 11px; padding-bottom: 11px; }
  .menu-item { min-height: 44px; }
  .user-chip { min-height: 44px; padding-right: 10px; }
  .tab { min-height: 44px; }
  .segmented button { min-height: 40px; padding: 6px 12px; }
  .checkbox, .switch { min-height: 40px; }
  .checkbox input { width: 20px; height: 20px; }
  .tip-trigger { padding: 8px; margin: -8px; }
  .check-item { padding-top: 11px; padding-bottom: 11px; }
  .ari-suggestion { padding: 12px 14px; }
  .subnav a { padding-top: 12px; padding-bottom: 12px; }
  .toast .toast-close { width: 36px; height: 36px; }
  .code-block .copy-btn { opacity: 1; } /* revealed on hover with a mouse; a finger cannot hover */
  .badge-count { height: 18px; }
}
@media (max-width: 960px) {
  body.sidebar-open { overflow: hidden; } /* the page behind the open navigation does not scroll */
}
@media (max-width: 720px) {
  body.ari-open { overflow: hidden; }
  /* the dashboard's drop zone: phones upload through the Upload button (file picker) instead,
     and the library and latest findings come straight after the headline numbers */
  .dash-upload { display: none; }
  .toolbar-search { flex-basis: 100%; max-width: none; }
  .select.toolbar-select { flex: 1 1 140px; min-width: 0; }
}
@media (max-width: 600px) {
  /* modals: the width of the phone, aligned to the top of the *visible* viewport (above the
     on-screen keyboard: app.js sets --vvh / --vvt), title and buttons always in view */
  dialog.modal, dialog.modal.modal-lg, dialog.modal.modal-xl {
    width: calc(100vw - 16px); max-width: calc(100vw - 16px);
    max-height: calc(var(--vvh, 100dvh) - 16px);
    margin: calc(8px + var(--vvt, 0px)) auto auto;
  }
  dialog.modal > .modal-header { position: sticky; top: 0; z-index: 3; background: var(--surface); padding-bottom: 10px; }
  dialog.modal .modal-footer {
    position: sticky; bottom: 0; z-index: 3; background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap;
  }
}
@media (max-width: 480px) {
  /* card titles keep their width; actions (segmented controls, buttons) drop below them */
  .card-header { flex-wrap: wrap; }
  .card-header > div:first-child { flex: 1 1 auto; }
  /* the id under a backtest's name is in its page address; on a phone the name and period suffice */
  .table td.name-cell .cell-sub.mono { display: none; }
  /* charts: shorter, so a chart and its caption fit on the screen together */
  .chart { height: 280px; } .chart.lg { height: 340px; }
  .table tr.group-row .btn-sm { padding: 0 8px; }
  #library td.shrink > .row-nowrap { flex-direction: column; } /* rename / delete stacked: the name keeps its width */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media print {
  .sidebar, .topbar, .drawer, .toasts { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
