/*
 * GnomonSystem L0 admin console
 * Brand sources
 *   dark   : official site  tianshu/website/style.css   (Night #06040b, Signal #ad7aff, panels, pills, Space Grotesk / IBM Plex Mono)
 *   light  : brand kit      branding/gnomonsystem-v1/tokens.css + colors.json  (Paper #f7f5fa, Ink #211c2b, Deep #6d3dc4, Muted #71677e)
 *   rule   : "dark entrance, light content" -> sidebar / top bar / login brand panel stay dark in both themes.
 *   marks  : the logo SVGs are used untouched (no glow, shadow, gradient, tile or recolouring).
 * Chart palette is validated (dataviz validate_palette) in both modes against the card surfaces below.
 */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: dark;
  --font: "Space Grotesk", "Avenir Next", "PingFang SC", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  /* brand constants (brand kit tokens.css) */
  --night: #06040b; --signal: #ad7aff; --deep: #6d3dc4; --chalk: #f3edff; --ink: #211c2b; --paper: #f7f5fa; --muted: #71677e; --tile: #1b1225;

  /* always-dark chrome: sidebar, top bar, login brand panel */
  --side-bg: rgba(8, 5, 15, 0.96);
  --side-line: rgba(173, 122, 255, 0.16);
  --side-text: #f3edff;
  --side-dim: #b8accf;
  --side-soft: #9c8fb6;
  --side-hover: rgba(173, 122, 255, 0.10);
  --side-active: rgba(173, 122, 255, 0.18);
  --side-active-line: rgba(173, 122, 255, 0.36);

  /* theme: dark */
  --bg: #06040b;
  --card: #110a1d;
  --card-2: #171028;
  --card-3: #211538;
  --input-bg: #0d0918;
  --line: rgba(173, 122, 255, 0.18);
  --line-strong: rgba(173, 122, 255, 0.34);
  --hair: rgba(173, 122, 255, 0.10);
  --th-bg: rgba(173, 122, 255, 0.07);
  --row-hover: rgba(173, 122, 255, 0.06);
  --text: #f5f1ff;
  --text-dim: #b8accf;
  --text-soft: #9c8fb6;
  --accent: #ad7aff;
  --accent-hover: #d8bbff;
  --accent-bg: rgba(173, 122, 255, 0.14);
  --accent-line: rgba(173, 122, 255, 0.32);
  --ok: #71e2b8;   --ok-bg: rgba(113, 226, 184, 0.12);  --ok-line: rgba(113, 226, 184, 0.30);
  --warn: #ffc97b; --warn-bg: rgba(255, 201, 123, 0.12); --warn-line: rgba(255, 201, 123, 0.30);
  --bad: #ff7e9c;  --bad-bg: rgba(255, 126, 156, 0.12);  --bad-line: rgba(255, 126, 156, 0.32);
  --info: #8ed4ff; --info-bg: rgba(142, 212, 255, 0.11); --info-line: rgba(142, 212, 255, 0.28);
  --focus: #ad7aff;
  --focus-ring: rgba(173, 122, 255, 0.30);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  --scrim: rgba(6, 4, 11, 0.66);
  --btn-bg: rgba(255, 255, 255, 0.04);
  --btn-line: rgba(173, 122, 255, 0.28);
  --btn-hover: rgba(173, 122, 255, 0.13);
  --primary-bg: linear-gradient(135deg, rgba(173, 122, 255, 0.34), rgba(255, 142, 216, 0.22));
  --primary-hover: linear-gradient(135deg, rgba(173, 122, 255, 0.46), rgba(255, 142, 216, 0.30));
  --primary-line: rgba(173, 122, 255, 0.52);
  --primary-text: #ffffff;
  --meter-track: rgba(173, 122, 255, 0.16);
  --code-bg: rgba(5, 3, 10, 0.55);

  /* chart chrome + validated categorical palette (dark) */
  --chart-surface: #110a1d;
  --chart-grid: #251a38;
  --chart-axis: #3d2e57;
  --spark: #6f6286;
  --c-extract: #ad7aff;  --c-generate: #e76624; --c-query: #00a888;   --c-rejected: #d28e05;
  --c-proof: #0aac23;    --c-notify: #e24d8b;   --c-terminate: #338ced; --c-fault: #eb6263;

  --sidebar-w: 264px;
  --radius: 12px;
  --radius-lg: 18px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f5fa;
  --card: #ffffff;
  --card-2: #f3f0f8;
  --card-3: #ebe6f3;
  --input-bg: #ffffff;
  --line: #e0dae9;
  --line-strong: #c4b9d6;
  --hair: #ece8f2;
  --th-bg: #f4f1f9;
  --row-hover: rgba(109, 61, 196, 0.045);
  --text: #211c2b;
  --text-dim: #4a4357;
  --text-soft: #71677e;
  --accent: #6d3dc4;
  --accent-hover: #55309f;
  --accent-bg: rgba(109, 61, 196, 0.08);
  --accent-line: rgba(109, 61, 196, 0.28);
  --ok: #096b49;   --ok-bg: rgba(9, 107, 73, 0.10);    --ok-line: rgba(9, 107, 73, 0.28);
  --warn: #8a5a00; --warn-bg: rgba(138, 90, 0, 0.10);  --warn-line: rgba(138, 90, 0, 0.30);
  --bad: #bf2142;  --bad-bg: rgba(191, 33, 66, 0.08);  --bad-line: rgba(191, 33, 66, 0.28);
  --info: #1a64a0; --info-bg: rgba(26, 100, 160, 0.08); --info-line: rgba(26, 100, 160, 0.26);
  --focus: #6d3dc4;
  --focus-ring: rgba(109, 61, 196, 0.22);
  --shadow: 0 1px 2px rgba(33, 28, 43, 0.05), 0 10px 28px rgba(33, 28, 43, 0.06);
  --scrim: rgba(33, 28, 43, 0.5);
  --btn-bg: #ffffff;
  --btn-line: #cfc6de;
  --btn-hover: #f3effa;
  --primary-bg: #6d3dc4;
  --primary-hover: #5a31a6;
  --primary-line: #6d3dc4;
  --primary-text: #ffffff;
  --meter-track: #e6dff2;
  --code-bg: #f6f3fa;

  --chart-surface: #ffffff;
  --chart-grid: #ece8f2;
  --chart-axis: #cdc4db;
  --spark: #a79db8;
  --c-extract: #6d3dc4;  --c-generate: #f47230; --c-query: #00b894;   --c-rejected: #f2a600;
  --c-proof: #008a17;    --c-notify: #ee7fac;   --c-terminate: #257de0; --c-fault: #ec4647;
}

/* -------------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 16px; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root:not([data-theme="light"]) body {
  background:
    radial-gradient(circle at top, rgba(66, 32, 108, 0.5), transparent 32%),
    linear-gradient(180deg, #05030a 0%, #090512 44%, #06040b 100%);
  background-color: var(--bg);
}
/* the official site's faint star field (dark theme only) */
:root:not([data-theme="light"]) body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.8) 0 1px, transparent 1.4px),
    radial-gradient(circle at 82% 12%, rgba(255,255,255,0.55) 0 1px, transparent 1.4px),
    radial-gradient(circle at 65% 72%, rgba(255,255,255,0.45) 0 1px, transparent 1.6px),
    radial-gradient(circle at 28% 78%, rgba(255,255,255,0.35) 0 1px, transparent 1.5px);
  background-size: 420px 420px, 520px 520px, 480px 480px, 560px 560px;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: 0; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
code, pre, kbd, samp { font-family: var(--font-mono); }
code { font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
[hidden] { display: none !important; }
/* read-only viewer session: every control that would write is removed from view (the server refuses it anyway) */
.role-viewer [data-write] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--accent-line); }
.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;
}
.muted { color: var(--text-soft); }
.warn-text { color: var(--warn); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.icon { flex: none; vertical-align: middle; }
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 200; padding: 8px 14px; border-radius: 10px;
  background: var(--card); color: var(--text); border: 1px solid var(--line-strong); transition: top 0.15s;
}
.skip-link:focus { top: 12px; }

/* ------------------------------------------------------------------ layout */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.content { min-width: 0; display: flex; flex-direction: column; }
.main { padding: 28px clamp(16px, 3vw, 40px) 72px; width: 100%; max-width: 1360px; margin: 0 auto; outline: none; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px 16px; background: var(--side-bg); color: var(--side-text); border-right: 1px solid var(--side-line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); scrollbar-width: thin; scrollbar-color: var(--side-active-line) transparent;
}
.sidebar a { color: inherit; }
.sidebar a:hover { text-decoration: none; }
.sidebar :focus-visible { outline-color: var(--signal); }
.side-brand { display: block; padding: 6px 4px 2px; border-radius: 10px; }
.side-brand img { display: block; height: 44px; width: auto; max-width: 100%; }
.side-sub { padding: 0 6px 14px; margin-bottom: 4px; font-size: 12px; letter-spacing: 0.06em; color: var(--side-soft); border-bottom: 1px solid var(--side-line); }
.side-nav { flex: 1 0 auto; display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.nav-skeleton { display: grid; gap: 10px; padding: 8px 6px; }
.nav-skeleton span { height: 34px; border-radius: 10px; background: var(--side-hover); animation: pulse 1.4s ease-in-out infinite; }
.nav-label { padding: 0 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: var(--side-soft); }
.nav-group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: 12px; font-size: 14px;
  color: var(--side-dim); border: 1px solid transparent; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-link:hover { background: var(--side-hover); color: var(--side-text); }
.nav-link.active { background: var(--side-active); border-color: var(--side-active-line); color: var(--side-text); font-weight: 700; }
.nav-link.active::before { content: ""; position: absolute; left: -15px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--signal); }
.nav-link .icon { color: var(--side-soft); }
.nav-link.active .icon { color: var(--signal); }
.side-foot { margin-top: auto; display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--side-line); }
.node-chip { padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--side-line); }
.node-chip-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.node-chip-name strong { flex: 1 1 auto; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-chip-name .badge { flex: none; }
.node-dot { width: 8px; height: 8px; border-radius: 50%; background: #71e2b8; flex: none; }
.node-chip-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.side-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.demo-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 12px; background: rgba(255, 201, 123, 0.10); border: 1px dashed rgba(255, 201, 123, 0.5); }
.demo-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: #ffc97b; }
.demo-exit { font-size: 12px; color: var(--side-dim); text-decoration: underline; text-underline-offset: 3px; }
.sidebar .badge, .sidebar .chip { --b: var(--side-dim); }
.sidebar .chip { color: var(--side-dim); border-color: var(--side-line); background: rgba(255, 255, 255, 0.03); }
.sidebar .btn { color: var(--side-dim); }
.sidebar .btn:hover { color: var(--side-text); background: var(--side-hover); }
.sidebar .badge.ok { color: #71e2b8; background: rgba(113, 226, 184, 0.12); border-color: rgba(113, 226, 184, 0.3); }
.sidebar .badge.warn { color: #ffc97b; background: rgba(255, 201, 123, 0.12); border-color: rgba(255, 201, 123, 0.3); }

.topbar { display: none; }
.scrim { position: fixed; inset: 0; z-index: 55; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity 0.2s; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; margin-bottom: 24px; }
.page-head-text { min-width: 0; flex: 1 1 420px; }
.page-head h1 { font-size: clamp(25px, 2.8vw, 34px); line-height: 1.15; margin: 14px 0 8px; }
.page-desc { max-width: 780px; margin: 0; color: var(--text-dim); font-size: 14px; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.page-body { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.eyebrow {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; border-radius: 999px; background: var(--accent-bg);
  border: 1px solid var(--accent-line); color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em;
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); }
.stack-y { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }

/* ------------------------------------------------------------------- cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; padding: 18px 20px 0; }
.card-headings { min-width: 0; flex: 1 1 240px; }
.card-title { font-size: 16px; line-height: 1.35; }
.card-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--text-soft); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 8px 0 0; }
.card-body.flush .table-wrap { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.stat { position: relative; padding: 16px 18px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); min-width: 0; display: grid; align-content: start; gap: 2px; }
.stat-label { font-size: 12.5px; color: var(--text-soft); font-weight: 500; }
.stat-value { font-size: clamp(25px, 2.3vw, 31px); line-height: 1.2; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.stat-value small { font-size: 0.5em; font-weight: 500; color: var(--text-soft); margin-left: 4px; }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.stat-sub span { white-space: nowrap; }
.stat .spark { position: absolute; right: 14px; top: 14px; opacity: 0.95; }
.spark { display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--spark); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark-now { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.spark-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }

/* ------------------------------------------------------ badges, chips, keys */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6;
  white-space: nowrap; border: 1px solid var(--line); background: var(--card-2); color: var(--text-dim);
}
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.badge.bad { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }
.badge.info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.badge.accent { color: var(--accent); background: var(--accent-bg); border-color: var(--accent-line); }
.badge.muted { color: var(--text-soft); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 5px; vertical-align: middle; }
.chip {
  display: inline-flex; align-items: center; padding: 0 8px; border-radius: 7px; font-size: 12px; line-height: 1.7; color: var(--text-dim);
  border: 1px solid var(--line); background: var(--card-2); white-space: nowrap;
}
.chip.warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-bg); }
.chip.accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-bg); }
.chip.mono { font-family: var(--font-mono); font-size: 11.5px; }
.kind {
  display: inline-block; padding: 0 7px; border-radius: 6px; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.7;
  background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-line); white-space: nowrap;
}
.hex { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; vertical-align: middle; }
.hex code { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.hex.full code { white-space: normal; word-break: break-all; }
.copy-btn {
  display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px; background: transparent;
  color: var(--text-soft); cursor: pointer; flex: none;
}
.copy-btn:hover { color: var(--accent); background: var(--accent-bg); }
.plain-mono { font-size: 12px; color: var(--text-dim); }
.time-rel { display: inline-flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }
.time-rel .rel { font-size: 12px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--btn-line); background: var(--btn-bg); color: var(--text); font-size: 13.5px; font-weight: 600; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background 0.15s, border-color 0.15s, transform 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--btn-hover); color: var(--text); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary-bg); border-color: var(--primary-line); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); color: var(--primary-text); }
.btn.danger { color: var(--bad); border-color: var(--bad-line); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--btn-hover); }
.btn.sm { min-height: 30px; padding: 0 12px; font-size: 12.5px; gap: 6px; }
.btn.icon { width: 34px; min-height: 34px; padding: 0; }
.btn.sm.icon { width: 30px; min-height: 30px; }
.btn.current { background: var(--accent-bg); border-color: var(--accent-line); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.is-busy { opacity: 0.7; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------------- forms */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; grid-template-columns: minmax(0, 1fr); }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.req { color: var(--bad); }
.field-hint { margin: 0; font-size: 12px; color: var(--text-soft); line-height: 1.5; }
.field-error { margin: 0; font-size: 12.5px; color: var(--bad); font-weight: 600; }
input[type="text"], input[type="search"], input[type="password"], input[type="number"], input[type="datetime-local"], input[type="email"], input[type="url"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--input-bg); color: var(--text); font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { min-height: 64px; resize: vertical; line-height: 1.5; }
textarea.mono, input.mono { font-family: var(--font-mono); font-size: 12.5px; }
select { appearance: auto; padding-right: 10px; }
input::placeholder, textarea::placeholder { color: var(--text-soft); opacity: 0.8; }
input:hover, select:hover, textarea:hover { border-color: var(--accent-line); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
.field.invalid input, .field.invalid select, .field.invalid textarea, input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
input[type="number"] { font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix input { padding-right: 76px; }
.input-affix .affix { position: absolute; right: 12px; font-size: 12px; color: var(--text-soft); pointer-events: none; }
.input-affix .affix-btn { position: absolute; right: 4px; }
.form-grid { display: grid; gap: 16px 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.check-row { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--input-bg); cursor: pointer; font-size: 13.5px; user-select: none; }
.check:hover { border-color: var(--accent-line); }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); }
.check:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.check small { color: var(--text-soft); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; position: relative; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--meter-track); border: 1px solid var(--line-strong); transition: background 0.15s, border-color 0.15s; flex: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-soft); transition: transform 0.15s, background 0.15s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch-text { font-size: 13px; font-weight: 600; min-width: 2.2em; color: var(--text-dim); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--input-bg); max-width: 100%; overflow-x: auto; }
.seg { border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-dim); cursor: pointer; white-space: nowrap; }
.seg:hover { color: var(--text); }
.seg[aria-checked="true"] { background: var(--accent-bg); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 10px 16px; margin-bottom: -1px; font-size: 14px; font-weight: 600; color: var(--text-soft); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.toolbar .field { min-width: 160px; }
.toolbar .field.grow { flex: 1 1 220px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; }
.inline-form .field { min-width: 160px; }
.inline-form .field.grow { flex: 1 1 220px; }
.toolbar-label { font-size: 12.5px; font-weight: 600; color: var(--text-soft); align-self: center; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-soft); pointer-events: none; }
.search-box input { padding-left: 36px; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { padding: 10px 12px; text-align: left; white-space: nowrap; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; color: var(--text-soft); background: var(--th-bg); border-bottom: 1px solid var(--line); }
table.data td { padding: 12px; vertical-align: top; border-bottom: 1px solid var(--hair); overflow-wrap: break-word; }
table.data td time, table.data td .mono, table.data td .plain-mono, table.data td .chip, table.data td .badge { white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover > td { background: var(--row-hover); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .nowrap { white-space: nowrap; }
table.data .empty-row td { text-align: center; padding: 34px 14px; color: var(--text-soft); }
table.data .col-toggle { width: 34px; padding-right: 0; }
.row-toggle { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 8px; background: transparent; color: var(--text-soft); cursor: pointer; }
.row-toggle:hover { background: var(--accent-bg); color: var(--accent); }
.row-toggle .icon { transition: transform 0.15s; }
.row-toggle[aria-expanded="true"] .icon { transform: rotate(90deg); }
tr.expanded > td { background: var(--row-hover); }
tr.detail-row > td { padding: 0 18px 18px 48px; background: var(--row-hover); }
.cell-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@media (min-width: 641px) { table.data td .cell-actions { flex-wrap: nowrap; } }
.danger-zone { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 14px; border-radius: 14px; border: 1px dashed var(--bad-line); background: var(--bad-bg); }
.danger-zone p { margin: 0; font-size: 12.5px; color: var(--text-dim); max-width: 560px; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-soft); }
.stack-cell { display: grid; gap: 3px; justify-items: start; min-width: 0; }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--hair); }
.pager-info { font-size: 12.5px; color: var(--text-soft); }
.pager-btns { display: inline-flex; gap: 4px; align-items: center; }
.pager-gap { padding: 0 4px; color: var(--text-soft); }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 24px; margin: 0; }
.kv-row { display: grid; gap: 3px; min-width: 0; align-content: start; }
.kv dt { font-size: 12px; font-weight: 500; color: var(--text-soft); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-size: 13.5px; }
.kv.compact { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 20px; }
.kv-proof { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.hexblock { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.hexblock-pre { margin: 0; padding: 12px 14px; max-height: 190px; overflow: auto; border-radius: 12px; background: var(--code-bg); border: 1px solid var(--line); font-size: 12px; line-height: 1.7; color: var(--text-dim); white-space: normal; overflow-wrap: anywhere; word-spacing: 4px; }
.hexblock-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.hexblock-meta { font-size: 12px; color: var(--text-soft); }
.hexblock-actions { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.json { margin: 0; padding: 12px 14px; max-height: 360px; overflow: auto; border-radius: 12px; background: var(--code-bg); border: 1px solid var(--line); font-size: 12px; line-height: 1.65; color: var(--text-dim); white-space: pre-wrap; overflow-wrap: anywhere; }
.jk { color: var(--accent); }
.js { color: var(--ok); }
.jn { color: var(--warn); }
.jb { color: var(--info); }

.callout { display: flex; gap: 12px; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--info-line); background: var(--info-bg); font-size: 13.5px; line-height: 1.6; }
.callout .callout-icon { margin-top: 3px; color: var(--info); }
.callout.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.callout.warn .callout-icon { color: var(--warn); }
.callout.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.callout.bad .callout-icon { color: var(--bad); }
.callout.ok { border-color: var(--ok-line); background: var(--ok-bg); }
.callout.ok .callout-icon { color: var(--ok); }
.callout-body { min-width: 0; display: grid; gap: 4px; color: var(--text); grid-template-columns: minmax(0, 1fr); }
.callout-title { font-size: 14px; }
.callout-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.empty { display: grid; justify-items: center; gap: 6px; padding: 38px 16px; text-align: center; }
.empty-title { font-size: 15px; font-weight: 600; }
.empty-hint { margin: 0; max-width: 520px; color: var(--text-soft); font-size: 13px; }
.meter { height: 8px; border-radius: 999px; background: var(--meter-track); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }
.meter.ok .meter-fill { background: var(--ok); }
.meter.warn .meter-fill { background: var(--warn); }
.meter.bad .meter-fill { background: var(--bad); }
.is-loading { opacity: 0.55; transition: opacity 0.2s; }
.loading-line { height: 12px; border-radius: 6px; background: var(--card-2); animation: pulse 1.4s ease-in-out infinite; }

/* ----------------------------------------------------------- toasts, modals */
.toasts { position: fixed; z-index: 300; right: 18px; bottom: 18px; display: grid; gap: 10px; width: min(420px, calc(100vw - 36px)); pointer-events: none; }
/* A toast never intercepts the pointer: whatever it covers (the bottom-right corner, or the full width on a phone) stays
   clickable while it is on screen; only its close button takes clicks. */
.toast {
  pointer-events: none; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--card-2); color: var(--text);
  border: 1px solid var(--line-strong); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32); animation: toast-in 0.2s ease; font-size: 13.5px;
}
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.18s, transform 0.18s; }
.toast .icon { margin-top: 1px; }
.toast.ok { border-color: var(--ok-line); } .toast.ok > .icon { color: var(--ok); }
.toast.err { border-color: var(--bad-line); } .toast.err > .icon { color: var(--bad); }
.toast.warn { border-color: var(--warn-line); } .toast.warn > .icon { color: var(--warn); }
.toast.info { border-color: var(--info-line); } .toast.info > .icon { color: var(--info); }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-x { border: 0; background: transparent; color: var(--text-soft); cursor: pointer; padding: 2px; border-radius: 6px; pointer-events: auto; }
.toast-x:hover { color: var(--text); background: var(--btn-hover); }

dialog.modal {
  padding: 0; border: 1px solid var(--line-strong); border-radius: 20px; background: var(--card); color: var(--text); width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); overflow: hidden;
}
dialog.modal.sm { width: min(440px, calc(100vw - 24px)); }
dialog.modal.wide { width: min(880px, calc(100vw - 24px)); }
dialog.modal[open] { display: flex; flex-direction: column; animation: modal-in 0.18s ease; }
dialog.modal::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
.modal-inner { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 6px 22px; }
.modal-title { font-size: 17px; }
.modal-body { padding: 8px 22px 18px; overflow: auto; min-height: 0; display: grid; gap: 14px; align-content: start; grid-template-columns: minmax(0, 1fr); }
.modal-text { margin: 0; color: var(--text-dim); }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 12px 22px 18px; border-top: 1px solid var(--hair); }

.refresh-ctl { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); }
.refresh-ctl.loading .refresh-status::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--accent); animation: pulse 0.9s ease-in-out infinite; }
.refresh-status { font-size: 12.5px; color: var(--text-dim); }

/* ------------------------------------------------------------------- charts */
.chart { margin: 0; display: grid; gap: 10px; min-width: 0; }
.chart-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px 3px 8px; border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--text-dim); font-size: 12.5px; cursor: pointer; }
.legend-item:hover { background: var(--btn-hover); }
.legend-item.off { opacity: 0.5; }
.legend-item.off .legend-name { text-decoration: line-through; }
.key { display: inline-block; flex: none; --sc: var(--c-extract); }
.key-line { width: 16px; height: 0; border-top: 2px solid var(--sc); border-radius: 2px; }
.key-box { width: 12px; height: 12px; border-radius: 3px; background: var(--sc); }
.chart.textured .key-box { background: repeating-linear-gradient(45deg, var(--sc) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--sc); }
.texture-btn { font-size: 12px; }
.texture-btn[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent); }
.chart-stage { position: relative; min-width: 0; outline: none; border-radius: 12px; }
.chart-stage:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.chart-svg { overflow: visible; touch-action: pan-y; }
.chart-svg text { font-family: var(--font); font-variant-numeric: tabular-nums; }
.c-gridline { stroke: var(--chart-grid); stroke-width: 1; }
.c-base { stroke: var(--chart-axis); stroke-width: 1; }
.c-tick { fill: var(--text-soft); font-size: 11px; }
.c-direct, .c-peak { fill: var(--text-dim); font-size: 11.5px; font-weight: 600; }
.c-line { fill: none; stroke: var(--sc); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-area { fill: var(--sc); fill-opacity: 0.10; stroke: none; }
.c-dot { fill: var(--sc); stroke: var(--chart-surface); stroke-width: 2; }
.c-seg { fill: var(--sc); transition: filter 0.1s; }
.c-col.hot .c-seg { filter: brightness(1.22); }
.chart-stage.has-hot .c-col:not(.hot) .c-seg { opacity: 0.6; }
.c-crossline { stroke: var(--chart-axis); stroke-width: 1; }
.c-hit { cursor: crosshair; touch-action: pan-y; }
.chart-empty { display: grid; place-items: center; color: var(--text-soft); border: 1px dashed var(--line); border-radius: 12px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px; max-width: 260px; padding: 9px 12px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line-strong); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28); font-size: 12.5px;
}
.tip-title { font-weight: 700; color: var(--text); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.tip-row { display: grid; grid-template-columns: 16px auto 1fr; align-items: center; gap: 4px 8px; padding: 1px 0; }
.tip-val { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.tip-name { color: var(--text-soft); }
.tip-total { margin-top: 3px; padding-top: 4px; border-top: 1px solid var(--hair); }
.tip-key-gap { display: block; }
.pat-bg { fill: var(--sc); fill-opacity: 0.28; }
.pat-ink { stroke: var(--sc); stroke-width: 2.2; }
.table-view summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text-soft); padding: 4px 2px; width: max-content; border-radius: 6px; }
.table-view summary:hover { color: var(--accent); }
.table-view-body { max-height: 300px; overflow: auto; margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; }
.table-view-body table.data { font-size: 12.5px; }
.table-view-body table.data th { position: sticky; top: 0; }

/* validated categorical series (dataviz): colour follows the entity */
.s-extract { --sc: var(--c-extract); } .s-generate { --sc: var(--c-generate); } .s-query { --sc: var(--c-query); } .s-rejected { --sc: var(--c-rejected); }
.s-proof { --sc: var(--c-proof); } .s-notify { --sc: var(--c-notify); } .s-terminate { --sc: var(--c-terminate); } .s-fault { --sc: var(--c-fault); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--sc); margin-right: 6px; vertical-align: -1px; }

/* ----------------------------------------------------------------- dashboard */
.node-card { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 20px 32px; padding: 20px 22px; align-items: center; }
.node-name { font-size: clamp(21px, 2.2vw, 26px); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.node-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.rtsaa-top { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 28px; align-items: end; margin-bottom: 14px; }
.countdown { font-size: clamp(30px, 3.4vw, 42px); line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.countdown.warn { color: var(--warn); } .countdown.bad { color: var(--bad); }
.rtsaa-meter { display: grid; gap: 6px; align-self: center; }
.meter-legend { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-soft); flex-wrap: wrap; }
.slot-list { display: grid; gap: 12px; }
.slot { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card-2); display: grid; gap: 8px; }
.slot-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; justify-content: space-between; }
.upstream { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; padding: 12px 0; border-top: 1px solid var(--hair); }
.upstream:first-child { border-top: 0; padding-top: 0; }
.upstream .err { grid-column: 1 / -1; font-size: 12.5px; color: var(--text-dim); }
.events-list { display: grid; }
.event { display: grid; grid-template-columns: 78px 150px minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; padding: 9px 20px; border-top: 1px solid var(--hair); font-size: 13px; }
.event:first-child { border-top: 0; }
.event:hover { background: var(--row-hover); }
.event-time { color: var(--text-soft); font-variant-numeric: tabular-nums; }
.event-text { min-width: 0; overflow-wrap: anywhere; color: var(--text-dim); }

/* ----------------------------------------------------------------- pages */
.ok-text { color: var(--ok) !important; font-weight: 600; }
.usage-col { min-width: 176px; }
.usage-cell { min-width: 0; }
.usage-bar { display: flex; width: 100%; min-width: 96px; height: 8px; padding: 0; border-radius: 999px; overflow: hidden; gap: 2px; background: transparent; }
.usage-bar.is-zero { background: var(--meter-track); }   /* no usage yet: an empty track, same height as the filled rows */
.usage-bar span { display: block; height: 100%; background: var(--sc); min-width: 2px; border-radius: 2px; }
.usage-nums { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; margin-top: 4px; }
.scope-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }

.timeline { width: 100%; }
.tl-svg { display: block; overflow: visible; }
.tl-svg text { font-family: var(--font); font-size: 11px; fill: var(--text-soft); font-variant-numeric: tabular-nums; }
.tl-axis { stroke: var(--chart-axis); stroke-width: 1; }
.tl-grid { stroke: var(--chart-grid); stroke-width: 1; }
.tl-bar { fill: var(--accent); fill-opacity: 0.85; stroke: none; cursor: pointer; transition: fill-opacity 0.1s; }
.tl-bar.past { fill: var(--text-soft); fill-opacity: 0.5; }
.tl-bar.cur { fill: var(--c-proof); fill-opacity: 0.95; }
.tl-bar.alt { fill-opacity: 0.7; }
.tl-bar:hover, .tl-bar.sel { fill-opacity: 1; }
.tl-bar.sel { stroke: var(--text); stroke-width: 2; }
.tl-now { stroke: var(--bad); stroke-width: 2; }
.tl-now-label { fill: var(--bad) !important; font-weight: 700; }
.tl-lane-label { fill: var(--text-dim) !important; }
.tl-svg .tl-bar-label { fill: #fff; stroke: rgba(6, 4, 11, 0.6); stroke-width: 2.6px; paint-order: stroke; stroke-linejoin: round; font-size: 10.5px; font-weight: 600; pointer-events: none; }
.tl-key { --k: var(--c-proof); background: var(--k); }
.tl-key.past { --k: var(--text-soft); opacity: 0.55; }
.tl-key.now { --k: var(--bad); width: 3px; height: 14px; border-radius: 2px; margin-right: 8px; vertical-align: -3px; }
.tip-kv { display: grid; grid-template-columns: 44px 1fr; gap: 2px 8px; padding: 1px 0; }
tr.sel > td { background: var(--accent-bg) !important; }
.mini-meter { display: block; width: 90px; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-dim); align-items: center; }
.legend-inline .sw-bar { display: inline-block; width: 22px; height: 8px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 16px; display: grid; gap: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.settings-nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 10px; color: var(--text-dim); font-size: 13.5px; }
.settings-nav a:hover { background: var(--btn-hover); color: var(--text); text-decoration: none; }
.settings-nav a.active { background: var(--accent-bg); color: var(--accent); font-weight: 700; }
.settings-nav .count { font-size: 11.5px; color: var(--text-soft); }
.setting-group { scroll-margin-top: 16px; }
.setting-group.inactive { opacity: 0.85; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 340px); gap: 10px 28px; padding: 16px 20px; border-top: 1px solid var(--hair); position: relative; }
.setting:first-child { border-top: 0; }
.setting.dirty { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.setting.invalid { box-shadow: inset 3px 0 0 var(--bad); }
.setting-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 600; font-size: 14px; }
.setting-desc { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }
.setting-key { margin-top: 6px; font-size: 11.5px; color: var(--text-soft); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.setting-ctl { display: grid; gap: 6px; align-content: start; }
.setting-default { font-size: 12px; color: var(--text-soft); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.setting-default code { color: var(--text-dim); }
.setting-range { font-size: 11.5px; color: var(--text-soft); }
.savebar {
  position: sticky; bottom: 16px; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 16px;
  border-radius: 18px; background: var(--card-2); border: 1px solid var(--accent-line); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.diff-table td, .diff-table th { vertical-align: middle; }
.diff-from { color: var(--text-soft); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff-to { color: var(--text); font-weight: 700; }

.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.key-card { display: grid; gap: 14px; align-content: start; }
.key-card .kv { grid-template-columns: minmax(0, 1fr); }
.selftest-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
@media (max-width: 960px) { .selftest-list { grid-template-columns: minmax(0, 1fr); } }
.selftest-list li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 10px; padding: 9px 20px; border-top: 1px solid var(--hair); }
.selftest-list li:nth-child(-n+2) { border-top: 0; }
@media (max-width: 960px) { .selftest-list li:nth-child(2) { border-top: 1px solid var(--hair); } }
.selftest-list li.fail { background: var(--bad-bg); }
.selftest-list .icon.pass { color: var(--ok); } .selftest-list .icon.failed { color: var(--bad); }
/* the self-test verdict is the <summary> of a <details>: one row that keeps its height while the run is in flight (nothing
   below it moves) and opens the 27+ item list on demand */
.selftest-details > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-height: 30px; list-style: none; cursor: pointer; border-radius: 10px; }
.selftest-details > summary::-webkit-details-marker { display: none; }
.selftest-summary { min-height: 28px; }
.selftest-toggle { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.selftest-toggle::before { content: "\25B8\00a0"; }
.selftest-details[open] .selftest-toggle::before { content: "\25BE\00a0"; }
.selftest-details > summary:hover .selftest-toggle { color: var(--accent); }
.selftest-details[open] > summary { margin-bottom: 8px; }
.selftest-name { font-weight: 600; font-size: 13.5px; }
.selftest-detail { grid-column: 2; font-size: 12.5px; color: var(--text-soft); }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.result-box { margin-top: 14px; display: grid; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card-2); }
.byte-count { font-size: 12px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.byte-count.ok { color: var(--ok); } .byte-count.bad { color: var(--bad); }

/* -------------------------------------------------------------------- login */
.login { position: relative; z-index: 1; min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); }
.login-brand { position: relative; overflow: hidden; display: flex; align-items: center; padding: clamp(28px, 5vw, 72px); color: var(--chalk); background: #06040b; isolation: isolate; }
.login-brand::before {
  content: ""; position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(circle at 20% 20%, rgba(173, 122, 255, 0.26), transparent 26%),
    radial-gradient(circle at 76% 18%, rgba(125, 92, 255, 0.2), transparent 24%),
    radial-gradient(circle at 52% 70%, rgba(255, 142, 216, 0.14), transparent 30%);
}
.login-brand::after {
  content: ""; position: absolute; inset: 0; z-index: -2; pointer-events: none; opacity: 0.6;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.8) 0 1px, transparent 1.4px),
    radial-gradient(circle at 82% 12%, rgba(255,255,255,0.55) 0 1px, transparent 1.4px),
    radial-gradient(circle at 65% 72%, rgba(255,255,255,0.45) 0 1px, transparent 1.6px),
    radial-gradient(circle at 28% 78%, rgba(255,255,255,0.35) 0 1px, transparent 1.5px);
  background-size: 420px 420px, 520px 520px, 480px 480px, 560px 560px;
}
.ring { position: absolute; z-index: -1; border-radius: 50%; border: 1px solid rgba(173, 122, 255, 0.14); pointer-events: none; }
.ring.r1 { width: 520px; height: 520px; right: -170px; bottom: -190px; }
.ring.r2 { width: 800px; height: 800px; right: -320px; bottom: -330px; border-color: rgba(173, 122, 255, 0.09); }
.ring.r3 { width: 1100px; height: 1100px; right: -470px; bottom: -480px; border-color: rgba(173, 122, 255, 0.06); }
.login-brand-inner { width: min(560px, 100%); display: grid; gap: 26px; }
.login-lockup { display: block; width: min(520px, 100%); height: auto; margin-left: -14px; }
.login-headline { font-size: clamp(28px, 3.4vw, 44px); line-height: 1.12; font-weight: 700; }
.login-headline .accent-text { background: linear-gradient(135deg, #ad7aff 0%, #7d5cff 40%, #d05bff 72%, #ff8ed8 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-lede { margin: 0; max-width: 520px; color: #b8accf; font-size: 15px; line-height: 1.75; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; margin-top: 4px; }
.chain-node { padding: 7px 14px; border-radius: 999px; border: 1px solid rgba(173, 122, 255, 0.34); background: rgba(173, 122, 255, 0.10); font-size: 13px; font-weight: 700; color: #f3edff; }
.chain-node small { display: block; font-size: 10.5px; font-weight: 500; color: #b8accf; letter-spacing: 0.04em; }
.chain-edge { display: inline-flex; flex-direction: column; align-items: center; font-size: 10.5px; letter-spacing: 0.05em; color: #9c8fb6; font-family: var(--font-mono); }
.chain-edge::after { content: "→"; font-family: var(--font); font-size: 16px; line-height: 1; color: #ad7aff; }
.login-panel { display: grid; place-items: center; padding: clamp(24px, 4vw, 56px); background: var(--bg); position: relative; }
.login-card { width: min(420px, 100%); display: grid; gap: 18px; }
.login-card h2 { font-size: 24px; margin-top: 10px; }
.login-corner { position: absolute; top: 16px; right: 16px; display: flex; gap: 8px; align-items: center; }
.login-node { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 10px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 13px; }
.login-foot { font-size: 12.5px; color: var(--text-soft); display: grid; gap: 4px; }


/* ---- small page helpers ---- */
.field.dim { opacity: 0.55; }
.share { display: grid; gap: 4px; min-width: 110px; }
.setting-range.over { color: var(--warn); font-weight: 600; }
.setting-range:empty { display: none; }
.setting-group.inactive .card-head { align-items: center; }

/* --------------------------------------------------------------- animations */
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .charts-grid, .tool-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .app { display: block; }
  /* the sticky top bar (56 px + border) must not cover what scrollIntoView / #anchors / focus bring to the top edge */
  html { scroll-padding-top: 72px; }
  .setting-group { scroll-margin-top: 72px; }
  .topbar {
    position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 56px;
    background: rgba(8, 5, 15, 0.96); border-bottom: 1px solid var(--side-line); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); color: var(--side-text);
  }
  .topbar .btn { color: var(--side-dim); }
  .topbar .btn:hover { color: var(--side-text); background: var(--side-hover); }
  .topbar :focus-visible { outline-color: var(--signal); }
  .top-brand { display: inline-flex; padding: 2px; border-radius: 8px; }
  .top-brand img { display: block; width: 32px; height: 32px; }
  .top-title { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .demo-badge { padding: 2px 8px; border-radius: 999px; background: rgba(255, 201, 123, 0.12); border: 1px dashed rgba(255, 201, 123, 0.5); }
  .sidebar {
    background: #08050f; padding: 12px 12px 12px; gap: 4px;
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: min(86vw, 300px); height: auto; transform: translateX(-104%); visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s; box-shadow: 20px 0 60px rgba(0, 0, 0, 0.5);
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition-delay: 0s; }
  .nav-open .scrim { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }
  .nav-link.active::before { left: -14px; }
  .nav-link { padding: 7px 12px; }
  .side-nav { gap: 8px; padding-top: 4px; }
  .side-sub { padding-bottom: 8px; }
  .side-foot { gap: 8px; padding-top: 10px; }
  .main { padding-top: 20px; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; display: flex; overflow-x: auto; padding: 6px; }
  .settings-nav a { white-space: nowrap; }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-brand { padding: 28px 22px 30px; }
  .login-brand-inner { gap: 16px; }
  .login-lede, .chain { display: none; }
  .login-headline { font-size: 26px; }
  .login-panel { place-items: start center; padding-top: 30px; }
  .login-corner { top: 12px; right: 12px; }
  .ring.r1 { width: 320px; height: 320px; right: -120px; bottom: -150px; }
  .ring.r2, .ring.r3 { display: none; }
  .node-card { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .grid.cols-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .setting { grid-template-columns: minmax(0, 1fr); }
  .event { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; padding: 10px 16px; }
  .event .event-time { grid-column: 1; grid-row: 1; }
  .event .kind-cell { grid-column: 2; grid-row: 1; min-width: 0; }
  .event .outcome-cell { grid-column: 3; grid-row: 1; }
  .event .event-text { grid-column: 1 / -1; grid-row: 2; }
  .key-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .main { padding: 16px 14px 64px; }
  .page-head { margin-bottom: 18px; }
  .card-head { padding: 16px 16px 0; }
  .card-body { padding: 14px 16px 16px; }
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 13px 14px 12px; }
  .stat .spark { display: none; }
  .rtsaa-top { grid-template-columns: minmax(0, 1fr); }
  .toolbar { padding: 12px; }
  .refresh-ctl { border-radius: 18px; padding: 8px 10px; width: 100%; }
  .refresh-status { flex: 1 1 100%; }
  .kv.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
  .toolbar .field { min-width: 0; flex: 1 1 100%; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .setting { padding: 14px 16px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; width: auto; }
  dialog.modal { width: calc(100vw - 16px); }
  .modal-foot .btn { flex: 1 1 auto; }
  .pager { justify-content: center; }
  .chart-legend { gap: 2px 4px; }
  tr.detail-row > td { padding: 0 14px 14px; }

  /* tables become cards */
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  table.data.stack tbody tr { padding: 8px 0; border-bottom: 1px solid var(--line); position: relative; }
  table.data.stack tbody tr:last-child { border-bottom: 0; }
  table.data.stack td { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 4px 16px; border: 0; text-align: right; }
  table.data.stack td::before { content: attr(data-label); flex: 0 0 34%; max-width: 40%; text-align: left; font-size: 12px; color: var(--text-soft); }
  table.data.stack td.num { text-align: right; }
  table.data.stack td > * { min-width: 0; }
  table.data.stack td.col-toggle { display: flex; justify-content: flex-end; padding: 0 12px 2px; }
  table.data.stack td.col-toggle::before { content: none; }
  table.data.stack td .cell-actions { justify-content: flex-end; }
  table.data.stack td .stack-cell { justify-items: end; text-align: right; }
  table.data.stack tr.empty-row td { display: block; text-align: center; }
  table.data.stack tr.empty-row td::before { content: none; }
  table.data.stack tr.detail-row td { display: block; text-align: left; padding: 0 14px 12px; }
  table.data.stack tr.detail-row td::before { content: none; }
  .table-view-body table.data.stack { display: table; }
}
@media (max-width: 420px) {
  .grid.stats { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 24px; }
  .btn { padding: 0 14px; }
}
@media print {
  .sidebar, .topbar, .scrim, .toasts, .page-actions, .savebar, .refresh-ctl { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
  .card, .stat { box-shadow: none; }
}
@media (forced-colors: active) {
  .badge, .chip, .btn, .card, .stat { border: 1px solid CanvasText; }
  .meter { border: 1px solid CanvasText; }
  .meter-fill { background: Highlight; }
  .tl-bar { fill: Highlight; }
}
