/* AlphaMiner dashboard styles — no build step, CSS custom properties only.
 * Palette: data-viz reference instance (chart surface, ink, hairlines, categorical slots 1-3,
 * ordinal blue ramp, fixed status colours). Dark values are selected steps, not an inversion. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --surface-3: #ebeae4;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.20);
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --on-accent: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --info: #2a78d6;
  --neutral: #898781;
  --good-ink: #006300;
  --critical-ink: #b3261e;
  --critical-soft: rgba(208, 59, 59, 0.08);
  --warning-soft: rgba(250, 178, 25, 0.14);
  /* chart roles */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --ord-1: #86b6ef;
  --ord-2: #5598e7;
  --ord-3: #2a78d6;
  --ord-4: #1c5cab;
  --ord-5: #0d366b;
  --context-line: #b5b3ab;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sidebar-w: 224px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: rgba(57, 135, 229, 0.18);
    --good-ink: #0ca30c;
    --critical-ink: #f08a85;
    --critical-soft: rgba(208, 59, 59, 0.16);
    --warning-soft: rgba(250, 178, 25, 0.14);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --ord-1: #184f95;
    --ord-2: #256abf;
    --ord-3: #3987e5;
    --ord-4: #6da7ec;
    --ord-5: #b7d3f6;
    --context-line: #57564f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-soft: rgba(57, 135, 229, 0.18);
  --good-ink: #0ca30c;
  --critical-ink: #f08a85;
  --critical-soft: rgba(208, 59, 59, 0.16);
  --warning-soft: rgba(250, 178, 25, 0.14);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --ord-1: #184f95;
  --ord-2: #256abf;
  --ord-3: #3987e5;
  --ord-4: #6da7ec;
  --ord-5: #b7d3f6;
  --context-line: #57564f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* ---------- 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.55 var(--font);
  overflow-x: hidden;
  overflow-x: clip;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }
p { margin: 0; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--text-muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.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; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 16px; font-weight: 600; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .nav-toggle { display: none; }
.data-chip, .job-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface);
  font-size: 12.5px; color: var(--text-2);
  white-space: nowrap; min-width: 0; overflow: hidden;
}
.data-chip .sep { color: var(--text-muted); }
.data-chip strong { color: var(--text); font-weight: 600; }
.job-pill { gap: 8px; padding-right: 4px; }
.job-pill a { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--neutral); display: inline-block; }
.dot[data-tone="good"] { background: var(--good); }
.dot[data-tone="critical"] { background: var(--critical); }
.dot[data-tone="warning"] { background: var(--warning); }
.dot[data-tone="info"] { background: var(--info); }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.view { padding: 20px; min-width: 0; outline: none; }
.view > * + * { margin-top: 16px; }
.backdrop, .drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.36); z-index: 35;
}
.drawer-backdrop { z-index: 49; }

/* ---------- generic components ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card > * + * { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h3 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); margin-top: 4px; font-size: 13px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; min-width: 0; box-shadow: var(--shadow);
}
.tile-label { font-size: 12.5px; color: var(--text-2); }
.tile-value { font-size: 22px; font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meter { margin-top: 8px; }

.meter { height: 6px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s; }
.meter[data-tone="warning"] > span { background: var(--warning); }
.meter[data-tone="critical"] > span { background: var(--critical); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--critical-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 12px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); cursor: pointer; padding: 0; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.span-all { grid-column: 1 / -1; }
.field label, .field .label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%; min-width: 0;
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.5; }
textarea.code { font-family: var(--mono); font-size: 13px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.input-inline, select.input.input-inline { width: auto; min-width: 90px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* chips */
.chip {
  --chip: var(--neutral);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 12px; line-height: 20px; font-weight: 500; white-space: nowrap;
  color: var(--text);
  background: color-mix(in srgb, var(--chip) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 38%, transparent);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--chip); flex: none; }
.chip.has-icon::before { display: none; }
.chip .chip-ic {
  display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%;
  background: var(--chip); color: #fff; font-size: 9.5px; font-weight: 700; line-height: 1;
}
.chip[data-tone="warning"] .chip-ic { color: #0b0b0b; }
.chip.pulse::before { animation: pulse 1.6s ease-in-out infinite; }
.chip[data-tone="good"] { --chip: var(--good); }
.chip[data-tone="info"] { --chip: var(--info); }
.chip[data-tone="warning"] { --chip: var(--warning); }
.chip[data-tone="serious"] { --chip: var(--serious); }
.chip[data-tone="critical"] { --chip: var(--critical); }
.chip[data-tone="neutral"] { --chip: var(--neutral); }
.tag {
  display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; line-height: 18px;
  background: var(--surface-3); color: var(--text-2); vertical-align: middle; font-weight: 500;
}

/* segmented filter */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  border-radius: 999px; height: 28px; padding: 0 10px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.seg .count { color: var(--text-muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: transparent; font: inherit; color: var(--text-2); cursor: pointer;
  padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { color: var(--text-muted); margin-left: 4px; font-weight: 400; }
.tabpanel > * + * { margin-top: 12px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.data th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
table.data th.num, table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover td { background: var(--surface-2); }
table.data tbody tr.selected td { background: var(--accent-soft); }
table.data tr.expand-row > td { background: var(--surface-2); padding: 12px; }
.expand-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.th-sort {
  border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.th-sort .arrow { font-size: 10px; color: var(--text-muted); width: 8px; }
th[aria-sort="ascending"] .arrow, th[aria-sort="descending"] .arrow { color: var(--accent); }
.expr {
  display: block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono); font-size: 12.5px; color: var(--text);
}
.cell-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; font-weight: 500; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; border-top: 1px solid var(--border); }
.empty { padding: 28px 12px; text-align: center; color: var(--text-muted); font-size: 13px; }
.metrics-wrap table.data td, .metrics-wrap table.data th { padding: 6px 10px; }
table.metrics td:first-child, table.metrics th:first-child { color: var(--text-2); white-space: nowrap; }

/* callouts */
.callout { border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; border: 1px solid; }
.callout-error { background: var(--critical-soft); border-color: color-mix(in srgb, var(--critical) 40%, transparent); color: var(--critical-ink); }
.callout-error ul { margin: 4px 0 0; padding-left: 18px; }
.callout-warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 50%, transparent); color: var(--text); }
.callout-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--text); }
.callout pre { margin-top: 6px; font-size: 12px; color: inherit; }

/* code blocks */
.code-block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0;
}
.expr-box { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.expr-box .code-block { flex: 1 1 260px; min-width: 0; max-height: none; }
.prose { font-size: 13.5px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }

/* event log */
.log {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  height: 280px; overflow: auto; padding: 8px 10px;
}
.log-line { display: grid; grid-template-columns: max-content max-content minmax(0, 1fr); gap: 8px; padding: 1px 0; }
.log-line .t { color: var(--text-muted); }
.log-line .k { color: var(--text-2); font-weight: 600; }
.log-line .m { overflow-wrap: anywhere; }
.log-line.is-error .m, .log-line.is-error .k { color: var(--critical-ink); }
.log-line.is-accept .k { color: var(--good-ink); }
.live { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }

.round-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.round-chip {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  padding: 6px 10px; font-size: 12.5px; line-height: 1.45; min-width: 124px;
}
.round-chip b { display: block; font-size: 12.5px; }
.round-chip span { color: var(--text-2); font-variant-numeric: tabular-nums; }

.lessons { margin: 0; padding-left: 20px; font-size: 13px; }
.lessons li + li { margin-top: 4px; }

/* lab */
.lab-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
.history { display: flex; flex-direction: column; gap: 4px; }
.history button {
  text-align: left; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 5px 8px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history button:hover { border-color: var(--accent); }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "\25B8"; color: var(--text-muted); transition: transform 0.15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.inline > summary { cursor: pointer; color: var(--text-2); font-size: 13px; }
.ops-pre { max-height: 560px; }

/* charts */
.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.chart-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.chart-card h4 { font-size: 13.5px; }
.chart-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.chart-box { position: relative; height: 250px; }
.chart-fallback { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: 13px; text-align: center; padding: 12px; }
.chart-table { margin-top: 10px; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.chart-table table.data th { position: sticky; top: 0; }

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(980px, 100vw);
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.22s ease, visibility 0.22s; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.drawer-head h3 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; }
.drawer-body > * + * { margin-top: 16px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0, 0, 0, 0.45); padding: 16px; }
.modal-card {
  width: min(420px, 100%); background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 20px;
}
.modal-card > * + * { margin-top: 12px; }
.modal-card p { color: var(--text-2); font-size: 13px; }
.modal-card .form-actions { justify-content: flex-end; }

/* toasts */
.toasts {
  position: fixed; top: 12px; right: 12px; z-index: 70;
  display: flex; flex-direction: column; gap: 8px;
  width: min(380px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; gap: 10px; align-items: start;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--info); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 10px 10px 10px 12px; font-size: 13px; animation: toast-in 0.18s ease;
}
.toast .ic { font-weight: 700; width: 16px; text-align: center; }
.toast .msg { overflow-wrap: anywhere; }
.toast[data-type="error"] { border-left-color: var(--critical); }
.toast[data-type="error"] .ic { color: var(--critical-ink); }
.toast[data-type="success"] { border-left-color: var(--good); }
.toast[data-type="success"] .ic { color: var(--good-ink); }
.toast[data-type="warn"] { border-left-color: var(--warning); }
.toast button { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

.loading { display: flex; align-items: center; gap: 8px; color: var(--text-muted); padding: 24px 4px; }
.is-stale { opacity: 0.6; transition: opacity 0.2s; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .hide-md { display: none !important; }
  .lab-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 260px; height: auto;
    transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .topbar .nav-toggle { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .view { padding: 16px; }
}
@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .page-title { font-size: 15px; }
  .data-chip { padding: 0 8px; }
  .job-pill a { max-width: 96px; }
  .tile-value { font-size: 19px; }
  .chart-box { height: 220px; }
  .expr { max-width: 200px; }
  .drawer-body { padding: 12px; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .chip, .tile, .card, .chart-card { border: 1px solid CanvasText; }
}
