/* ═══════════════════════════════════════════════════════════════════════
   Tracker admin — global stylesheet (single source of truth for the theme).
   Implements design-system/MASTER.md: Data-Dense Dashboard, light + dark
   (WCAG AA), self-hosted Fira fonts, reusable base components.

   OWNED BY THE GLOBAL THEME AGENT. Page agents reuse the classes below and
   must NOT edit this file. Class/token reference is documented at the bottom.

   Served at /app.css (cache-busted ?v= by the layout) by tracker-admin.
   Used by the shared layout (src/templates/layout.js) on EVERY cabinet page:
   qr (via delegation in qr/templates.js, + /css/qr.css on top),
   campaigns/analytics, landings, domains, users, barcodes, proofread,
   inventory, auth. Page CSS files layer on top; admin-misc.css is inlined
   into <head> right after this file.
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Self-hosted fonts ───────────────────────────────────────────────
   woff2 live flat in public/ (served by the existing /public/:file route)
   AND mirrored in public/fonts/. font-display:swap so text paints instantly. */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/public/fira-sans-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/public/fira-sans-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/public/fira-sans-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/public/fira-sans-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Code';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/public/fira-code-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Code';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/public/fira-code-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Fira Code';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/public/fira-code-600.woff2') format('woff2');
}

/* ─── Design tokens (light) ───────────────────────────────────────────
   MASTER §2. Only semantic tokens — pages must never hardcode hex.
   Surface/border/fg variants are derived so every component reads tokens. */
:root {
  /* Brand / data */
  --color-primary:        #1E40AF; /* data, links, active nav */
  --color-primary-hover:  #1B3A9C;
  --color-on-primary:     #FFFFFF;
  --color-secondary:      #3B82F6;
  --color-accent:         #D97706; /* primary CTA, main action */
  --color-accent-hover:   #B45309;
  --color-on-accent:      #FFFFFF;

  /* Neutrals / surfaces */
  --color-bg:             #F8FAFC;
  --color-surface:        #FFFFFF;
  --color-surface-2:      #F1F5FD; /* zebra / hover rows */
  --color-fg:             #1E293B; /* body text (≥ 7:1 on bg) */
  --color-fg-muted:       #64748B; /* secondary text (≥ 4.5:1 on bg) */
  --color-muted:          #E9EEF6; /* field/row fills, neutral chips */
  --color-border:         #DBEAFE;
  --color-border-strong:  #C3D6F5;

  /* Functional (always paired with icon/text, never colour-only) */
  --color-success:        #16A34A;
  --color-success-bg:     #DCFCE7;
  --color-success-fg:     #166534;
  --color-warning:        #D97706;
  --color-warning-bg:     #FEF3C7;
  --color-warning-fg:     #92400E;
  --color-destructive:    #DC2626;
  --color-destructive-bg: #FEE2E2;
  --color-destructive-fg: #991B1B;
  --color-on-destructive: #FFFFFF; /* text on a solid danger button (light) */

  --color-ring:           #1E40AF; /* focus ring */
  --color-overlay:        rgba(15, 23, 42, .45);

  /* Typography */
  --font-sans: 'Fira Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-12: 12px;  --fs-14: 14px;  --fs-16: 16px;
  --fs-18: 18px;  --fs-24: 24px;  --fs-32: 32px;

  /* Spacing scale 4/8 (MASTER §4) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  /* Radii / elevation / shape */
  --radius:    8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, .10);

  /* z-index scale (MASTER §4). Drawer layers sit between dropdowns and
     modals: topbar < overlay < drawer < modal < toast. */
  --z-nav: 10; --z-dropdown: 40; --z-topbar: 50; --z-overlay: 80; --z-drawer: 90;
  --z-modal: 100; --z-toast: 1000;

  /* Shell dimensions */
  --sidebar-w: 244px;
  --topbar-h: 56px;

  /* Motion */
  --t-fast: 150ms; --t-mid: 220ms; --ease: cubic-bezier(.2, .6, .2, 1);

  /* Legacy alias kept so any old reference to --space still resolves */
  --space: 8px;
}

/* ─── Design tokens (dark) — desaturated, NOT a raw inversion (MASTER §2) ── */
[data-theme="dark"] {
  --color-primary:        #60A5FA;
  --color-primary-hover:  #93C5FD;
  --color-on-primary:     #0B1220;
  --color-secondary:      #3B82F6;
  --color-accent:         #F59E0B;
  --color-accent-hover:   #FBBF24;
  --color-on-accent:      #1A1206;

  --color-bg:             #0B1220;
  --color-surface:        #111A2E;
  --color-surface-2:      #16213A;
  --color-fg:             #E5EDF8;
  --color-fg-muted:       #94A8C6;
  --color-muted:          #16213A;
  --color-border:         #243049;
  --color-border-strong:  #324264;

  --color-success:        #34D399;
  --color-success-bg:     #0E2A1E;
  --color-success-fg:     #6EE7B7;
  --color-warning:        #FBBF24;
  --color-warning-bg:     #2A1F08;
  --color-warning-fg:     #FCD34D;
  --color-destructive:    #F87171;
  --color-destructive-bg: #2A1414;
  --color-destructive-fg: #FCA5A5;
  --color-on-destructive: #2A0E0E; /* dark text on the light-red danger button (dark theme, AA) */

  --color-ring:           #60A5FA;
  --color-overlay:        rgba(0, 0, 0, .6);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, .5);
}

/* ─── Reset / base ───────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-fg);
  font-size: var(--fs-16);          /* ≥16px so iOS never zooms inputs */
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  font-family: var(--font-sans);    /* MASTER §3 (2026-07): headings in Fira Sans;
                                       Fira Code stays for data/numbers only */
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 var(--sp-2);
  letter-spacing: -.015em;
}
h1 { font-size: var(--fs-24); font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: var(--fs-18); }
h3 { font-size: var(--fs-16); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }
small { font-size: var(--fs-12); }
hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--sp-4) 0; }
.mono, code, kbd, samp, .tnum {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
code { font-size: .9em; }
.muted { color: var(--color-fg-muted); }
.tnum { font-variant-numeric: tabular-nums; }
.text-success { color: var(--color-success-fg); }
.text-danger  { color: var(--color-destructive-fg); }
.text-warning { color: var(--color-warning-fg); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ─── Focus ring (MASTER §9 — visible 2–4px, keyboard only) ───────────── */
:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Don't show the ring on plain mouse clicks of inputs (they get their own). */
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible { outline-offset: 1px; }

/* ═══ APP SHELL ═══════════════════════════════════════════════════════
   Desktop (≥769px): fixed-width sticky sidebar with grouped nav.
   Mobile (≤768px): sticky 56px topbar (burger + section title + theme) and
   the SAME sidebar markup as an off-canvas drawer over an overlay. */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

/* Keyboard a11y: first tab stop jumps past the nav. */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: calc(var(--z-toast) + 1);
  background: var(--color-surface); color: var(--color-primary);
  padding: 10px var(--sp-4); border-radius: 0 0 var(--radius) 0;
  font-weight: 600; box-shadow: var(--shadow-2);
}
.skip-link:focus { left: 0; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; height: 100dvh; z-index: var(--z-nav);
}
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4); min-height: 64px;
  border-bottom: 1px solid var(--color-border);
}
.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono);
  font-weight: 700; letter-spacing: .12em; font-size: var(--fs-14);
  color: var(--color-fg);
}
.brand svg { color: var(--color-primary); }
.drawer-close { display: none; }          /* mobile-only, see media block */

.nav {
  display: flex; flex-direction: column;
  padding: var(--sp-3) var(--sp-2); flex: 1; overflow-y: auto;
}
.nav-group { margin-bottom: var(--sp-4); display: flex; flex-direction: column; gap: 2px; }
.nav-group:last-child { margin-bottom: 0; }
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--color-fg-muted); padding: 0 var(--sp-3); margin-bottom: var(--sp-1);
  user-select: none;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); min-height: 40px;
  border-radius: var(--radius);
  color: var(--color-fg); font-weight: 500; font-size: var(--fs-14);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--color-fg-muted);
  transition: color var(--t-fast) var(--ease); }
.nav-item:hover { background: var(--color-muted); text-decoration: none; }
.nav-item:hover svg { color: var(--color-fg); }
/* Active = tinted pill + accent bar in the nav gutter (modern SaaS pattern,
   replaces the old solid-blue pill). Colour + weight + bar — not colour alone. */
.nav-item.nav-active {
  background: color-mix(in srgb, var(--color-primary) 11%, transparent);
  color: var(--color-primary); font-weight: 600;
}
.nav-item.nav-active svg { color: var(--color-primary); }
.nav-item.nav-active::before {
  content: ""; position: absolute; left: calc(-1 * var(--sp-2)); top: 8px; bottom: 8px;
  width: 3px; border-radius: var(--radius-pill); background: var(--color-primary);
}

.sidebar-foot {
  padding: var(--sp-3); border-top: 1px solid var(--color-border);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.who { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.who-avatar {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--color-primary) 14%, transparent);
  color: var(--color-primary);
  font-weight: 700; font-size: var(--fs-14); text-transform: uppercase;
}
.who-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who-meta strong, .who strong { font-size: var(--fs-14); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--color-fg-muted); font-weight: 600;
}
.foot-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.logout-form { margin: 0; }
.btn-link {
  background: none; border: none; color: var(--color-primary);
  cursor: pointer; padding: 0; font: inherit; font-weight: 600;
}
.btn-link:hover { text-decoration: underline; }

/* Mobile topbar + drawer chrome (hidden on desktop). */
.topbar { display: none; }
.burger { display: none; }
.drawer-overlay {
  position: fixed; inset: 0; background: var(--color-overlay);
  z-index: var(--z-overlay);
}
.drawer-overlay[hidden] { display: none; }
/* Desktop can never show the overlay, even if a rotation strands the
   drawer-open state (the script also closes it via matchMedia). */
@media (min-width: 769px) {
  .drawer-overlay { display: none !important; }
}

.content {
  flex: 1; min-width: 0;
  padding: var(--sp-5) var(--sp-6);
  max-width: 1440px; width: 100%; margin: 0 auto;
  overflow-x: hidden;               /* a wide child must scroll itself, not the page */
}

/* ─── Page header ─────────────────────────────────────────────────────── */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin-bottom: var(--sp-5); flex-wrap: wrap;
}
.page-head h1 { margin: 0; }

/* ═══ THEME TOGGLE ════════════════════════════════════════════════════ */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-fg-muted);
  cursor: pointer; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.theme-toggle:hover { background: var(--color-muted); color: var(--color-fg); }
.theme-toggle svg { width: 18px; height: 18px; }
/* Show sun in dark mode, moon in light mode (the other is hidden). */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ═══ BUTTONS (MASTER §6) ═════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px var(--sp-4); min-height: 40px;
  border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer; text-decoration: none; user-select: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(0.5px); }   /* pressed cue, no layout shift */

/* primary = brand blue */
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); }

/* accent = the single main CTA per screen (MASTER §6) */
.btn-accent, .btn.accent { background: var(--color-accent); color: var(--color-on-accent); }
.btn-accent:hover, .btn.accent:hover { background: var(--color-accent-hover); }

/* secondary = muted outline */
.btn-secondary, .btn.secondary {
  background: var(--color-surface); color: var(--color-fg);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover, .btn.secondary:hover { background: var(--color-muted); }

/* ghost = quiet text-button */
.btn-ghost, .btn.ghost {
  background: transparent; color: var(--color-fg); border-color: var(--color-border);
}
.btn-ghost:hover, .btn.ghost:hover { background: var(--color-muted); }

/* danger / destructive */
.btn-danger, .btn.danger { background: var(--color-destructive); color: var(--color-on-destructive); }
.btn-danger:hover, .btn.danger:hover { filter: brightness(.94); }

.btn-sm { padding: 6px 10px; min-height: 32px; font-size: var(--fs-14); }
.btn-block { width: 100%; }

.btn[disabled], .btn[aria-disabled="true"], .btn:disabled {
  opacity: .55; cursor: not-allowed; pointer-events: none;
}
/* Async loading: .btn.is-loading shows a spinner and dims the label. */
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  color: var(--color-on-primary);
  animation: spin .6s linear infinite;
}
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after,
.btn.secondary.is-loading::after, .btn.ghost.is-loading::after { color: var(--color-fg); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ CARDS / SURFACES ════════════════════════════════════════════════ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--sp-5); margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.card.empty { box-shadow: none; }

/* ═══ KPI STAT CARDS (MASTER §6) ══════════════════════════════════════ */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-3); margin: var(--sp-4) 0;
}
.kpi {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: var(--sp-4); box-shadow: var(--shadow-1);
}
.kpi .k-label {
  font-size: var(--fs-12); color: var(--color-fg-muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
}
.kpi .k-value {
  font-family: var(--font-mono);
  font-size: var(--fs-32); font-weight: 700; font-variant-numeric: tabular-nums;
  margin-top: var(--sp-1); line-height: 1.1; color: var(--color-fg);
}
/* Delta with direction (icon + colour, never colour alone) */
.kpi .k-delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-12);
  font-weight: 600; margin-top: var(--sp-1); }
.kpi .k-delta.up   { color: var(--color-success-fg); }
.kpi .k-delta.down { color: var(--color-destructive-fg); }

/* ═══ FORMS (MASTER §6) ═══════════════════════════════════════════════ */
.field { margin-bottom: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-1); max-width: 480px; }
.field label { font-weight: 600; font-size: var(--fs-14); }
.field input, .field select, .field textarea,
input[type="text"], input[type="url"], input[type="email"],
input[type="tel"], input[type="number"], input[type="password"],
input[type="search"], input[type="date"], select, textarea {
  padding: 10px var(--sp-3); min-height: 40px;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius);
  font: inherit; font-size: var(--fs-16);
  background: var(--color-surface); color: var(--color-fg);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.field textarea, textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.field input::placeholder, textarea::placeholder, input::placeholder { color: var(--color-fg-muted); opacity: 1; }
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-ring) 28%, transparent);
}
input[type="color"] { padding: 2px; min-height: 40px; height: 40px; width: 56px; cursor: pointer; }
input[type="file"] { min-height: auto; padding: var(--sp-2); }
/* Disabled controls read clearly non-interactive (impeccable §Forms). */
.field input:disabled, .field select:disabled, .field textarea:disabled,
input:disabled, select:disabled, textarea:disabled {
  opacity: .5; cursor: not-allowed; background: var(--color-muted);
}
.field .help, .help { font-size: var(--fs-12); color: var(--color-fg-muted); }
.field-required > label::after { content: " *"; color: var(--color-destructive); }

/* Inline field error: red border + message under field, announced to SR */
.field .error, .field-error .error { color: var(--color-destructive-fg); font-size: var(--fs-12); font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea {
  border-color: var(--color-destructive);
}
.field.has-error input:focus, .field.has-error select:focus, .field.has-error textarea:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-destructive) 28%, transparent);
}

.form-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-2); flex-wrap: wrap; }

/* Password reveal (login) */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 56px; }
.pw-toggle {
  position: absolute; right: var(--sp-2); top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--color-fg-muted); font-size: var(--fs-12); font-weight: 600; padding: 4px 6px;
}
.pw-toggle:hover { color: var(--color-fg); }

/* Repeatable variant builder rows (campaigns/new) */
.variant-row {
  display: grid; grid-template-columns: 1fr 2fr 80px auto;
  gap: var(--sp-2); margin-bottom: var(--sp-2); align-items: center;
}

/* ═══ DATA TABLES (MASTER §6) ═════════════════════════════════════════
   Two selectors styled identically: `table.data` (current templates) and
   `.table` (MASTER name, for new page agents). Sticky header, zebra,
   hover row, tabular numerics. */
.table-wrap {
  overflow-x: auto;                 /* mobile: scroll the table, not the page */
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface); box-shadow: var(--shadow-1);
}
table.data, .table {
  width: 100%; border-collapse: collapse;
  font-variant-numeric: tabular-nums; font-size: var(--fs-14);
}
table.data th, table.data td, .table th, .table td {
  padding: 10px var(--sp-3); text-align: left;
  border-bottom: 1px solid var(--color-border);
}
table.data thead th, .table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--color-muted); color: var(--color-fg);
  font-weight: 600; white-space: nowrap;
  border-bottom: 1px solid var(--color-border-strong);
}
/* Sortable header affordance (aria-sort drives the indicator) */
.table th[aria-sort] { cursor: pointer; }
.table th[aria-sort="ascending"]::after  { content: " ▲"; font-size: 10px; color: var(--color-primary); }
.table th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; color: var(--color-primary); }
table.data td.num, table.data th.num, .table td.num, .table th.num {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.data tbody tr:nth-child(even), .table tbody tr:nth-child(even) { background: var(--color-surface-2); }
table.data tbody tr:hover, .table tbody tr:hover { background: var(--color-muted); }
table.data tfoot td, .table tfoot td {
  font-weight: 700; background: var(--color-muted);
  border-top: 1px solid var(--color-border-strong);
}
table.data .mono, .table .mono { font-family: var(--font-mono); font-size: var(--fs-14); }

/* ═══ BADGES / STATUS (icon/text + colour, MASTER §9) ═════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-12); font-weight: 600; line-height: 1.4;
  background: var(--color-muted); color: var(--color-fg);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-on, .badge.pass    { background: var(--color-success-bg);     color: var(--color-success-fg); }
.badge-on .dot, .badge.pass .dot { background: var(--color-success); }
.badge-off, .badge.reject { background: var(--color-destructive-bg); color: var(--color-destructive-fg); }
.badge-off .dot, .badge.reject .dot { background: var(--color-destructive); }
.badge.warn               { background: var(--color-warning-bg);     color: var(--color-warning-fg); }
.badge.warn .dot          { background: var(--color-warning); }
.badge-neutral, .badge.scans { background: var(--color-muted); color: var(--color-fg-muted); }

/* ═══ ALERTS / BANNERS (role="alert" in markup; aria-live for dynamic) ═ */
.alert {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  margin-bottom: var(--sp-4); font-weight: 500; border: 1px solid transparent;
}
.alert svg { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; }
.alert-error   { background: var(--color-destructive-bg); color: var(--color-destructive-fg);
                 border-color: color-mix(in srgb, var(--color-destructive) 35%, transparent); }
.alert-success { background: var(--color-success-bg); color: var(--color-success-fg);
                 border-color: color-mix(in srgb, var(--color-success) 35%, transparent); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning-fg);
                 border-color: color-mix(in srgb, var(--color-warning) 35%, transparent); }
.alert-info    { background: var(--color-muted); color: var(--color-fg);
                 border-color: var(--color-border-strong); }

/* ═══ SEGMENTED CONTROL (date range — MASTER §6) ══════════════════════ */
.segmented {
  display: inline-flex; border: 1px solid var(--color-border-strong);
  border-radius: var(--radius); overflow: hidden; background: var(--color-surface);
}
.segmented a, .segmented button {
  padding: 8px var(--sp-4); min-height: 40px; display: inline-flex; align-items: center;
  color: var(--color-fg); font-weight: 500; font: inherit;
  background: none; border: none; border-right: 1px solid var(--color-border);
  cursor: pointer; transition: background var(--t-fast) var(--ease);
}
.segmented a:last-child, .segmented button:last-child { border-right: none; }
.segmented a:hover, .segmented button:hover { background: var(--color-muted); text-decoration: none; }
.segmented a.seg-active, .segmented button.seg-active,
.segmented a[aria-current="true"] {
  background: var(--color-primary); color: var(--color-on-primary); font-weight: 600;
}

/* ═══ EMPTY STATE ═════════════════════════════════════════════════════ */
.empty {
  text-align: center; padding: var(--sp-7) var(--sp-5);
  color: var(--color-fg-muted);
}
.empty .btn { margin-top: var(--sp-3); }

/* ═══ TOAST (MASTER §6 — aria-live, auto-dismiss, top z) ══════════════ */
.toast-region {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: var(--z-toast); pointer-events: none; max-width: min(92vw, 380px);
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  background: var(--color-surface); color: var(--color-fg);
  border: 1px solid var(--color-border-strong); border-left-width: 4px;
  border-radius: var(--radius); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-2); pointer-events: auto;
  animation: toast-in var(--t-mid) var(--ease);
}
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-error   { border-left-color: var(--color-destructive); }
.toast.toast-warning { border-left-color: var(--color-warning); }
.toast svg { width: 18px; height: 18px; flex: 0 0 18px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ═══ SKELETON / SHIMMER (MASTER §6 — loading >300ms) ════════════════ */
.skeleton {
  display: block; border-radius: var(--radius-sm);
  background: linear-gradient(100deg,
    var(--color-muted) 30%,
    color-mix(in srgb, var(--color-muted) 60%, var(--color-surface)) 50%,
    var(--color-muted) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skeleton-text { height: 12px; margin: 6px 0; }
.skeleton-title { height: 20px; width: 40%; margin: 8px 0 14px; }
.skeleton-row { height: 40px; margin: 6px 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ═══ BARE / AUTH PAGES (login, 403) ══════════════════════════════════ */
body.bare {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--color-bg); padding: var(--sp-4);
}
.bare-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--sp-6); width: 380px; max-width: 92vw;
  box-shadow: var(--shadow-2);
}
.bare-card h1 { margin: 0 0 var(--sp-5); font-size: var(--fs-24); text-align: center; }
.bare-card .btn-primary, .bare-card .btn[type="submit"] { width: 100%; }
.bare-card .field { max-width: none; }

/* ═══ RESPONSIVE (MASTER §4 — 375 / 768 / 1024 / 1440) ════════════════ */
@media (max-width: 1024px) {
  .content { padding: var(--sp-4) var(--sp-5); }
}

/* Mobile: sticky topbar + off-canvas drawer. The sidebar markup is reused as
   the drawer panel; html.drawer-open (set by the layout's inline script)
   slides it in and locks page scroll. */
@media (max-width: 768px) {
  .topbar {
    display: flex; align-items: center; gap: var(--sp-2);
    position: sticky; top: 0; z-index: var(--z-topbar);
    min-height: var(--topbar-h);
    padding: 0 var(--sp-3);
    padding-left: max(var(--sp-3), env(safe-area-inset-left));
    padding-right: max(var(--sp-3), env(safe-area-inset-right));
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
  }
  .topbar-title {
    flex: 1; min-width: 0;
    font-weight: 600; font-size: var(--fs-16);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .burger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-left: -8px; flex: 0 0 44px;
    border: none; background: none; color: var(--color-fg);
    border-radius: var(--radius); cursor: pointer;
  }
  .burger:hover, .burger:active { background: var(--color-muted); }
  .topbar .theme-toggle { border: none; background: none; width: 44px; height: 44px; }

  .app { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    /* visibility gate: a transform alone leaves the closed drawer's links in
       the tab order / a11y tree (focus vanishes off-screen). Delay hiding
       until the slide-out finishes so the animation still plays. */
    visibility: hidden;
    transition: transform var(--t-mid) var(--ease), visibility 0s linear var(--t-mid);
    z-index: var(--z-drawer);
    border-right: 1px solid var(--color-border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  html.drawer-open .sidebar {
    transform: translateX(0); box-shadow: var(--shadow-2);
    visibility: visible;
    transition: transform var(--t-mid) var(--ease), visibility 0s;
  }
  /* Scroll lock: html alone is not enough on iOS Safari — lock body too and
     kill touch scrolling through the overlay; contain drawer-nav overscroll. */
  html.drawer-open, html.drawer-open body { overflow: hidden; }
  html.drawer-open .drawer-overlay { touch-action: none; }
  .sidebar .nav { overscroll-behavior: contain; }
  .drawer-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-right: -8px;
    border: none; background: none; color: var(--color-fg-muted);
    border-radius: var(--radius); cursor: pointer;
  }
  .drawer-close:hover { background: var(--color-muted); color: var(--color-fg); }
  .nav-item { min-height: 44px; }               /* ≥44px touch targets in the drawer */
  .sidebar .theme-toggle { width: 44px; height: 44px; }
  .foot-actions .btn-link {
    min-height: 44px; display: inline-flex; align-items: center; padding: 0 var(--sp-2);
  }

  .content {
    padding: var(--sp-4) var(--sp-3);
    padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  }
  .page-head { gap: var(--sp-2); }
  .variant-row { grid-template-columns: 1fr; }
  .toast-region { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); max-width: none; }
  /* Date-range control wraps instead of pushing the page wider than the viewport */
  .segmented { flex-wrap: wrap; max-width: 100%; }
  .segmented a, .segmented button { flex: 1 1 auto; justify-content: center; }
}

/* ═══ MOTION PREFERENCE (MASTER §8/§9) ════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── Reference (for page agents) ──────────────────────────────────────
   TOKENS  : --color-{primary,accent,secondary,bg,surface,surface-2,fg,
             fg-muted,muted,border,border-strong,success,warning,destructive,
             ring} (+ -bg/-fg/-hover variants); --font-sans, --font-mono;
             --fs-12..32; --sp-1..7 (4/8 scale); --radius(-sm/-lg/-pill);
             --shadow-1/-2; --z-nav/-dropdown/-modal/-toast; --t-fast/-mid; --ease.
   THEME   : add  data-theme="dark"  to <html> for dark mode.
   SHELL   : .app .sidebar .brand .nav .nav-item(.nav-active) .sidebar-foot
             .who .role-badge .btn-link .topbar .content .page-head .theme-toggle.
   BUTTONS : .btn + .btn-primary/.btn-accent/.btn-secondary/.btn-ghost/.btn-danger
             (legacy aliases .btn.secondary/.ghost/.accent/.danger), .btn-sm,
             .btn-block, [disabled], .btn.is-loading (spinner).
   FORMS   : .field (label/input/select/textarea) .help .error .field.has-error
             .field-required .form-actions .pw-wrap .pw-toggle .variant-row.
   TABLES  : .table-wrap + (table.data | .table); td/th + .num; thead sticky;
             zebra+hover; tfoot totals; th[aria-sort].
   CARDS   : .card .card.empty; KPI: .kpis .kpi .k-label .k-value .k-delta(.up/.down).
   STATUS  : .badge(.dot) .badge-on/-off/-neutral (aliases .pass/.reject/.warn/.scans).
   FEEDBACK: .alert .alert-error/-success/-warning/-info (role="alert");
             .toast-region .toast .toast-success/-error/-warning (aria-live).
   RANGE   : .segmented a/button (.seg-active | aria-current="true").
   LOADING : .skeleton .skeleton-text/-title/-row (shimmer).
   AUTH    : body.bare .bare-card.
   A11Y    : :focus-visible ring, prefers-reduced-motion, .visually-hidden,
             tabular-nums on .tnum/.mono/numbers, contrast ≥4.5:1 both themes. */
