/* LiveBarn network test: one design system for the public test and the admin.
   Colors are tokens on :root, redefined for dark mode. */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --surface-3: #e7ecf2;
  --text: #111827;
  --text-2: #374151;
  --muted: #5f6b7a;
  --border: #e2e7ee;
  --border-strong: #cdd5df;
  --accent: #1f6feb;
  --accent-hover: #175bd0;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;
  --ok: #157f3b;
  --ok-soft: #e5f5ea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --danger: #c62828;
  --danger-hover: #a91f1f;
  --danger-soft: #fdecec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 6px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  /* Charts and gauge. Series colors validated for color-vision deficiency and
     contrast against the surface in both modes. */
  --series-dl: #2a78d6;
  --series-ul: #eb6834;
  --chart-grid: #e6e9ee;
  --chart-axis: #c3c9d2;
  --gauge-track: #e9edf2;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c222b;
    --surface-3: #252c37;
    --text: #e8ebf0;
    --text-2: #c4cad3;
    --muted: #98a2b0;
    --border: #262e39;
    --border-strong: #36404d;
    --accent: #4d8ff7;
    --accent-hover: #6aa2f9;
    --accent-soft: rgba(77, 143, 247, 0.15);
    --accent-text: #07101f;
    --ok: #46c06a;
    --ok-soft: rgba(70, 192, 106, 0.14);
    --warn: #e3b341;
    --warn-soft: rgba(227, 179, 65, 0.14);
    --danger: #ff7b72;
    --danger-hover: #ff958e;
    --danger-soft: rgba(255, 123, 114, 0.14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 6px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
    --series-dl: #3987e5;
    --series-ul: #d95926;
    --chart-grid: #252c36;
    --chart-axis: #3b4552;
    --gauge-track: #222a34;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; }
p { margin: 0 0 12px; }
small { font-size: 0.85em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.n { text-align: right; font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; line-height: 1.2;
  padding: 9px 16px; min-height: 38px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
}
button:hover, .button:hover { background: var(--accent-hover); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.button.secondary, button.secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm);
}
.button.secondary:hover, button.secondary:hover { background: var(--surface-2); }
.button.ghost, button.ghost { background: transparent; color: var(--text-2); }
.button.ghost:hover, button.ghost:hover { background: var(--surface-2); }
button.danger, .button.danger { background: var(--danger); color: #fff; }
button.danger:hover { background: var(--danger-hover); }
button.danger-outline { background: var(--surface); color: var(--danger); border-color: var(--border-strong); }
button.danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); }
.button.lg, button.lg { padding: 12px 22px; min-height: 46px; font-size: 1rem; border-radius: var(--radius); }
.button.block, button.block { width: 100%; }
.icon-button {
  padding: 6px; min-height: 0; background: transparent; color: var(--muted); border-radius: var(--radius-sm);
}
.icon-button:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Forms ---------- */

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0 0 6px; color: var(--text); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 9px 12px; min-height: 40px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[readonly] { background: var(--surface-2); }
.field { margin-bottom: 18px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }
fieldset { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; padding: 0; }

/* Alerts */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; border-radius: var(--radius); margin: 0 0 16px;
  border: 1px solid transparent; font-size: 0.92rem;
}
.alert .icon { margin-top: 2px; }
.alert[hidden] { display: none; }
.alert.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--text); }
.alert.error .icon { color: var(--danger); }
.alert.notice { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert.notice .icon { color: var(--ok); }
.alert.warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.warning .icon { color: var(--warn); }

/* ---------- Cards, badges, tables ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head .muted { font-size: 0.85rem; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-used-up { background: var(--warn-soft); color: var(--warn); }
.badge-revoked { background: var(--danger-soft); color: var(--danger); }
.badge-plain::before { display: none; }
.badge-setup-pending { background: var(--warn-soft); color: var(--warn); }
.badge-disabled { background: var(--danger-soft); color: var(--danger); }

.table-wrap {
  overflow-x: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-size: 0.75rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em;
}
th small { text-transform: none; letter-spacing: 0; font-weight: 500; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td a { font-weight: 600; }
tr.incomplete td { color: var(--muted); }
td .sub { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }

/* Usage bar (tests used of allowed) */
progress.usage {
  appearance: none; -webkit-appearance: none;
  width: 72px; height: 6px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--surface-3); vertical-align: middle; margin-left: 8px;
}
progress.usage::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.usage::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress.usage::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
progress.usage.wide { display: block; width: 100%; height: 8px; margin: 10px 0 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; color: var(--border-strong); margin-bottom: 8px; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 420px; margin: 0 auto 16px; }

/* ---------- Public pages ---------- */

.is-public { min-height: 100vh; display: flex; flex-direction: column; }
.public-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; max-width: 880px; width: 100%; margin: 0 auto;
}
.public-main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 8px 16px 32px; }
.public-footer { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 16px 16px 28px; }
.public-footer p { margin: 0; display: inline-flex; gap: 8px; align-items: center; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 9px; background: var(--accent); color: #fff;
}
.brand-mark .icon { width: 20px; height: 20px; stroke-width: 2.4; }
.brand-text { display: flex; flex-direction: column; font-weight: 750; font-size: 1rem; line-height: 1.1; }
.brand-text small { font-weight: 500; color: var(--muted); font-size: 0.78rem; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  font-size: 0.85rem; color: var(--text-2); box-shadow: var(--shadow-sm);
}
.pill strong { font-variant-numeric: tabular-nums; }

/* Entry: access code */
.entry { max-width: 440px; margin: 6vh auto 0; }
.entry .card { padding: 28px; }
.entry h1 { margin-bottom: 6px; }
.entry .lead { color: var(--muted); margin-bottom: 22px; }
.code-input {
  font-family: var(--mono); font-size: 1.6rem; letter-spacing: 0.18em; text-align: center;
  text-transform: uppercase; padding: 12px; min-height: 58px;
}
.code-input::placeholder { color: var(--border-strong); letter-spacing: 0.18em; }
.entry .help { margin-top: 18px; font-size: 0.85rem; color: var(--muted); text-align: center; }

/* Test page */
.test-head { text-align: center; margin: 4px 0 22px; }
.test-head .eyebrow {
  display: inline-block; margin-bottom: 8px; padding: 3px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 0.82rem; font-weight: 650;
}
.test-head h1 { font-size: 1.8rem; }
.test-head p { color: var(--muted); max-width: 540px; margin: 8px auto 0; }

.test-card { padding: 24px; }
.setup { display: grid; gap: 4px; transition: opacity 0.2s; }
.setup.is-locked { opacity: 0.55; pointer-events: none; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; display: block; margin: 0; font-weight: 400; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice-body {
  display: flex; gap: 12px; align-items: flex-start; height: 100%;
  padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius);
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
}
.choice-body .icon {
  width: 34px; height: 34px; padding: 7px; border-radius: 9px;
  background: var(--surface-2); color: var(--muted); flex: none;
}
.choice-title { display: block; font-weight: 650; color: var(--text); }
.choice-desc { display: block; font-size: 0.82rem; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.choice:hover .choice-body { border-color: var(--border-strong); }
.choice input:checked + .choice-body { border-color: var(--accent); background: var(--accent-soft); }
.choice input:checked + .choice-body .icon { background: var(--accent); color: #fff; }
.choice input:focus-visible + .choice-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.wifi-tip { margin: 10px 0 0; }

/* Gauge */
.gauge-wrap { display: grid; place-items: center; margin: 14px 0 6px; }
.gauge { position: relative; width: min(300px, 80vw); }
.gauge svg { display: block; width: 100%; height: auto; overflow: visible; }
.gauge-track { fill: none; stroke: var(--gauge-track); stroke-width: 14; stroke-linecap: round; }
.gauge-value { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round; transition: stroke 0.3s; }
.gauge-value.dl { stroke: var(--series-dl); }
.gauge-value.ul { stroke: var(--series-ul); }
.gauge-tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.gauge-center { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 4%; }
.gauge-start {
  width: 124px; height: 124px; border-radius: 50%;
  font-size: 1.3rem; font-weight: 750; letter-spacing: 0.02em;
  background: var(--accent); color: #fff;
  box-shadow: 0 0 0 10px var(--accent-soft), var(--shadow-lg);
}
.gauge-start:hover { background: var(--accent-hover); transform: scale(1.03); }
.gauge-start:disabled { background: var(--surface-3); color: var(--muted); box-shadow: none; transform: none; }
.gauge-start.is-again { font-size: 1.05rem; }
.gauge-start[hidden], .gauge-readout[hidden] { display: none; }
.gauge-readout { display: flex; flex-direction: column; align-items: center; text-align: center; }
.gauge-phase {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.gauge-number { font-size: 3rem; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.gauge-unit { color: var(--muted); font-size: 0.9rem; }
.gauge-sub { color: var(--muted); font-size: 0.8rem; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Steps: progress while testing, results when done */
.steps { list-style: none; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.step {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.step-head { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 650; color: var(--muted); }
.step-dot {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); flex: none;
}
.step-dot .icon { width: 13px; height: 13px; stroke-width: 2.6; }
.step-value { font-size: 1.45rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; }
.step-value small { font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.step-sub { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.2em; }
.step.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.step.is-active .step-dot { background: var(--accent); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.step.dl.is-active { border-color: var(--series-dl); }
.step.dl.is-active .step-dot { background: var(--series-dl); }
.step.ul.is-active { border-color: var(--series-ul); }
.step.ul.is-active .step-dot { background: var(--series-ul); }
.step.is-done .step-dot { background: var(--ok); color: #fff; }
.step.is-skipped { opacity: 0.45; }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) {
  .step.is-active .step-dot { animation: none; }
  .gauge-start:hover { transform: none; }
}

.test-status { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 28px; margin: 14px 0 0; font-weight: 600; text-align: center; }
.test-status .icon { color: var(--ok); }
.test-status.is-error .icon { color: var(--danger); }
.test-status .icon[hidden] { display: none; }
.test-meta { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

.details { margin-top: 22px; display: grid; gap: 14px; }
.details[hidden] { display: none; }

/* ---------- Admin app shell ---------- */

.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar .brand { padding: 2px 6px 6px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 550;
}
.side-nav a:hover { background: var(--surface-2); text-decoration: none; }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.side-new { width: 100%; }
.side-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 6px 0; border-top: 1px solid var(--border);
}
.side-user form { margin: 0 0 0 auto; }
.side-user-link {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  margin: -6px; padding: 6px; border-radius: var(--radius-sm); color: var(--text);
}
.side-user-link:hover, .side-user-link[aria-current="page"] { background: var(--surface-2); text-decoration: none; }
.side-user-name { display: flex; flex-direction: column; min-width: 0; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-name small { font-weight: 500; color: var(--muted); font-size: 0.78rem; }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.85rem;
}
.avatar.sm { width: 26px; height: 26px; font-size: 0.78rem; }
.avatar.lg { width: 40px; height: 40px; font-size: 1.05rem; }
.app-main { min-width: 0; width: 100%; max-width: 1240px; padding: 28px 32px 48px; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; }
.back:hover { color: var(--text); text-decoration: none; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head a { font-size: 0.88rem; font-weight: 600; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat {
  display: flex; flex-direction: column; gap: 10px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); color: var(--text); transition: border-color 0.15s, box-shadow 0.15s;
}
a.stat:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.stat-icon { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-n { font-size: 2rem; font-weight: 750; line-height: 1; }
.stat-sub { color: var(--muted); font-size: 0.82rem; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }

/* Compact lists in cards */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; padding-bottom: 0; }
.list li:first-child { padding-top: 0; }
.list-main { min-width: 0; flex: 1; }
.list-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { display: block; color: var(--muted); font-size: 0.82rem; }
.list-end { text-align: right; font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.speeds { display: inline-flex; gap: 10px; }
.speeds span { display: inline-flex; align-items: center; gap: 3px; }
.speeds .dl .icon { color: var(--series-dl); }
.speeds .ul .icon { color: var(--series-ul); }

/* Filters toolbar */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 14px 16px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.filters .field { margin: 0; display: flex; flex-direction: column; min-width: 150px; }
.filters .field.grow { flex: 1 1 220px; }
.filters label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.filters .actions { flex-direction: row; gap: 8px; min-width: 0; }
.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px; }
.result-count { color: var(--muted); font-size: 0.85rem; margin: 0 0 10px; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }

/* Token page */
.facts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.fact { padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.fact-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; }
.fact-value { font-size: 1.15rem; font-weight: 700; }
.fact-sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

.manage { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.manage form { margin: 0; }
.manage .card { display: flex; flex-direction: column; gap: 10px; }
.manage h3 { display: flex; align-items: center; gap: 8px; }
.manage h3 .icon { color: var(--muted); }
.manage p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.danger-zone h3 .icon { color: var(--danger); }

/* Segmented radio choices (forms) */
.seg-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.seg { position: relative; margin: 0; font-weight: 600; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: block; text-align: center; padding: 9px 6px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font-size: 0.9rem;
}
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-card { max-width: 560px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* Admins */
.name-cell { display: inline-flex; align-items: center; gap: 10px; }
.role-tag {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-sm);
  font-size: 0.8rem; font-weight: 650; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.role-tag.role-owner { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.role-tag.role-viewer { color: var(--muted); }
table.matrix th:not(:first-child), table.matrix td:not(:first-child) { text-align: center; }
.can .icon { color: var(--ok); stroke-width: 2.6; }
.cannot { color: var(--border-strong); }
.choices.stack { grid-template-columns: minmax(0, 1fr); }
.seg-choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.manage .save { margin-top: 10px; }
.note-card p { display: flex; gap: 10px; align-items: flex-start; margin: 0; color: var(--text-2); }
.note-card .icon { color: var(--muted); margin-top: 3px; }
.form-title { margin-bottom: 16px; }

/* Activity log */
td.wrap { white-space: normal; min-width: 280px; }
.event { display: inline-flex; gap: 8px; align-items: flex-start; }
.event .icon { color: var(--muted); margin-top: 2px; }
.filter-note { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 0.9rem; margin: -4px 0 14px; }
.filter-note .icon { color: var(--muted); }

/* Token created */
.share { max-width: 600px; }
.success-head { text-align: center; margin-bottom: 20px; }
.success-icon {
  display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok); margin-bottom: 10px;
}
.success-icon .icon { width: 28px; height: 28px; }
.success-head p { color: var(--muted); margin: 6px 0 0; }
.code-display {
  font-family: var(--mono); font-size: 2rem; font-weight: 700; letter-spacing: 0.16em; text-align: center;
  padding: 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong);
  margin-bottom: 18px;
}
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 0.88rem; }
.copy button { flex: none; }
.message-preview {
  white-space: pre-wrap; font-size: 0.88rem; color: var(--text-2);
  background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 10px;
}

/* Result page */
.metric-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.metric-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.metric-label .dl { color: var(--series-dl); }
.metric-label .ul { color: var(--series-ul); }
.metric-value { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 4px; }
.metric-value small { font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 20px; color: var(--muted); font-size: 0.88rem; margin: 6px 0 0; }
.meta-row span { display: inline-flex; align-items: center; gap: 6px; }

/* Login */
.login { max-width: 400px; margin: 8vh auto 0; }
.login .card { padding: 28px; }
.login h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login .lead { color: var(--muted); margin-bottom: 20px; }

/* ---------- Charts ---------- */

.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 16px 18px 14px;
}
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 6px; }
.chart-head h2, .chart-head h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.chart-head .muted { font-size: 0.82rem; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.key.dl { background: var(--series-dl); }
.key.ul { background: var(--series-ul); }

.chart { position: relative; }
.chart-svg { display: block; overflow: visible; touch-action: pan-y; cursor: crosshair; }
.chart-svg:focus { outline: none; }
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart-gridline { stroke: var(--chart-grid); stroke-width: 1; }
.chart-base { stroke: var(--chart-axis); stroke-width: 1; }
.chart-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.dl { stroke: var(--series-dl); }
.chart-line.ul { stroke: var(--series-ul); }
.chart-area.dl { fill: var(--series-dl); fill-opacity: 0.1; }
.chart-area.ul { fill: var(--series-ul); fill-opacity: 0.1; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-dot.dl { fill: var(--series-dl); }
.chart-dot.ul { fill: var(--series-ul); }
.chart-cross { stroke: var(--muted); stroke-width: 1; }
.chart-bar { fill: var(--accent); transition: opacity 0.15s; }
.chart-bars.has-active .chart-bar { opacity: 0.45; }
.chart-bars.has-active .chart-bar.is-active { opacity: 1; }
.chart-tip {
  position: absolute; top: -6px; transform: translateX(-50%);
  pointer-events: none; white-space: nowrap; z-index: 2;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 10px; font-size: 0.82rem; box-shadow: var(--shadow);
}
.chart-tip strong { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.chart-key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 6px; }
.chart-key.dl { background: var(--series-dl); }
.chart-key.ul { background: var(--series-ul); }
.chart-key.bar { height: 8px; width: 8px; border-radius: 2px; background: var(--accent); }

.chart-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 16px; margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.chart-stats dt { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.chart-stats dd { margin: 2px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-stats small { font-weight: 400; color: var(--muted); }

details { margin-top: 10px; }
details summary { cursor: pointer; color: var(--accent); font-size: 0.88rem; font-weight: 600; }
details .table-wrap { margin-top: 10px; max-height: 320px; overflow-y: auto; box-shadow: none; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0; margin-right: auto; }
  .side-nav { flex-direction: row; order: 3; width: 100%; overflow-x: auto; }
  .side-nav a { padding: 7px 10px; }
  .side-new { width: auto; padding: 7px 12px; min-height: 34px; }
  .side-user { margin: 0; padding: 0; border: 0; }
  .side-user-name { display: none; }
  .app-main { padding: 20px 16px 40px; }
  .grid-2, .manage, .facts-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .test-head h1 { font-size: 1.45rem; }
  .test-card { padding: 16px; }
  .choices { grid-template-columns: 1fr; }
  .steps { gap: 6px; }
  .step { padding: 10px; }
  .step-head { flex-direction: column; align-items: flex-start; gap: 4px; font-size: 0.8rem; }
  .step-value { font-size: 1.1rem; }
  .gauge-number { font-size: 2.4rem; }
  .seg-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .code-display { font-size: 1.5rem; }
  .side-new span { display: none; }
}

.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge .icon { width: 0.95em; height: 0.95em; }
.metric-label .icon.dl { color: var(--series-dl); }
.metric-label .icon.ul { color: var(--series-ul); }
.field > button.block { margin-top: 8px; }
textarea { resize: vertical; font-size: 0.88rem; line-height: 1.45; }
#code-form button { margin-top: 14px; }
