/* ════════════════════════════════════════════════════════════════════════════
   Pumo Cam — design system
   Matte, warm, precise. Five hues with one job each, plus three supports:
     sand        base / neutral: hairlines, fills, neutral data
     terracotta  the brand accent: primary actions, active states, highlights
     burgundy    alerts, danger, negatives (never on a terracotta component)
     olive       people, positive, success, live-OK
     brass       a material, not a paint: brushed hairlines, indicator edges,
                 focus glints, premium badges — never a flat fill or text
     cream       elevated insets · charcoal text / dark base / video stage
     paper       the app background (instead of white)
   Every other colour is a color-mix() of these. Both themes come from the
   same tokens. Layers keep the cascade explicit (no !important anywhere).
   ════════════════════════════════════════════════════════════════════════════ */
@layer tokens, base, layout, components, pages, pumo, utilities, motion;

/* ── tokens ───────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* palette (read by js/palette.js for canvas drawing — keep them hex) */
    --sand: #B19D7A;
    --terracotta: #B15A2F;
    --burgundy: #6B2D3A;
    --olive: #657956;
    --brass: #EABA5C;
    --cream: #F4ECDC;
    --charcoal: #2B2B29;
    --paper: #FAF6EE;

    /* type */
    --font-ui: "Geist", "IBM Plex Sans Arabic", system-ui, sans-serif;
    --font-display: "Readex Pro", "IBM Plex Sans Arabic", "Geist", system-ui, sans-serif;
    --font-num: "Geist", "IBM Plex Sans Arabic", system-ui, sans-serif;
    --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

    /* space · radius · motion */
    --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-7: 28px; --s-8: 32px;
    --r-xs: 8px; --r-sm: 10px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-2xl: 24px; --r-pill: 999px;
    /* motion tokens: four durations, three curves */
    --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms; --dur-4: 480ms;
    --ease-out: cubic-bezier(.22, 1, .36, 1);
    --ease-in-out: cubic-bezier(.65, 0, .35, 1);
    --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
    --rail-w: 252px;
    --rail-row: 42px;
    --rail-step: 44px; /* row + gap: the sliding indicator moves in these steps */

    /* brass, brushed (used as thin lines only) */
    --brass-soft: color-mix(in srgb, var(--brass) 55%, var(--cream));
    --brass-line: linear-gradient(90deg, transparent, var(--brass-soft) 22%, var(--brass) 50%, var(--brass-soft) 78%, transparent);
    --brass-edge: linear-gradient(180deg, var(--brass-soft), var(--brass) 45%, color-mix(in srgb, var(--brass) 70%, var(--terracotta)));

    /* the video stage is charcoal in both themes */
    --stage: var(--charcoal);
    --stage-deep: oklch(from var(--charcoal) calc(l * 0.86) c h);
    --on-stage: var(--cream);
    --hud: color-mix(in srgb, var(--charcoal) 78%, transparent);
    --hud-line: color-mix(in srgb, var(--cream) 14%, transparent);
  }

  /* light (default) */
  :root, [data-theme="light"] {
    color-scheme: light;
    --bg: var(--paper);
    --rail-bg: color-mix(in srgb, var(--cream) 58%, var(--paper));
    --surface: color-mix(in srgb, var(--paper) 62%, var(--cream));
    --surface-2: color-mix(in srgb, var(--cream) 94%, var(--sand));
    --surface-3: color-mix(in srgb, var(--cream) 82%, var(--sand));
    --field: var(--paper);
    --line: color-mix(in srgb, var(--sand) 30%, transparent);
    --line-strong: color-mix(in srgb, var(--sand) 58%, transparent);
    --fg: var(--charcoal);
    --fg-2: color-mix(in srgb, var(--charcoal) 58%, var(--sand));
    --fg-3: color-mix(in srgb, var(--charcoal) 38%, var(--sand));
    --dot: var(--charcoal);

    --accent: var(--terracotta);
    --accent-top: color-mix(in srgb, var(--terracotta) 90%, var(--charcoal));
    --accent-deep: color-mix(in srgb, var(--terracotta) 74%, var(--charcoal));
    --accent-ink: color-mix(in srgb, var(--terracotta) 76%, var(--charcoal));
    --accent-soft: color-mix(in srgb, var(--terracotta) 11%, transparent);
    --on-accent: var(--cream);

    --ok: var(--olive);
    --ok-ink: color-mix(in srgb, var(--olive) 76%, var(--charcoal));
    --ok-soft: color-mix(in srgb, var(--olive) 13%, transparent);
    --bad: var(--burgundy);
    --bad-ink: var(--burgundy);
    --bad-soft: color-mix(in srgb, var(--burgundy) 10%, transparent);
    --neutral-soft: color-mix(in srgb, var(--sand) 18%, transparent);

    --chart-a: var(--charcoal);
    --chart-b: color-mix(in srgb, var(--sand) 62%, transparent);
    --chart-line: var(--accent);

    --focus: color-mix(in srgb, var(--brass) 60%, var(--charcoal));
    --glint: color-mix(in srgb, var(--brass) 38%, transparent);
    --shade: var(--charcoal);
    --shadow-1: 0 1px 1px color-mix(in srgb, var(--shade) 5%, transparent), 0 2px 6px -2px color-mix(in srgb, var(--shade) 8%, transparent);
    --shadow-2: 0 1px 2px color-mix(in srgb, var(--shade) 5%, transparent), 0 14px 30px -18px color-mix(in srgb, var(--shade) 26%, transparent);
    --shadow-3: 0 2px 4px color-mix(in srgb, var(--shade) 6%, transparent), 0 30px 60px -26px color-mix(in srgb, var(--shade) 38%, transparent);
    --inner-hl: inset 0 1px 0 color-mix(in srgb, var(--paper) 80%, transparent);
    --backdrop: color-mix(in srgb, var(--charcoal) 42%, transparent);
  }

  /* dark: "espresso bar at night" — charcoal warmed with burgundy and sand,
     cream-tinted layers that lift, sand secondary text, a brighter terracotta */
  [data-theme="dark"] {
    color-scheme: dark;
    --espresso: color-mix(in srgb, color-mix(in srgb, var(--charcoal) 86%, var(--burgundy)) 93%, var(--sand));
    --bg: oklch(from var(--espresso) calc(l * 0.8) calc(c * 1.25) h);
    --rail-bg: oklch(from var(--espresso) calc(l * 0.88) calc(c * 1.15) h);
    --surface: oklch(from var(--espresso) calc(l * 1.04) calc(c * 1.25) h);
    --surface-2: oklch(from var(--espresso) calc(l * 1.17) calc(c * 1.15) h);
    --surface-3: oklch(from var(--espresso) calc(l * 1.3) c h);
    --field: oklch(from var(--espresso) calc(l * 0.86) calc(c * 1.1) h);
    --line: color-mix(in srgb, var(--sand) 15%, transparent);
    --line-strong: color-mix(in srgb, var(--sand) 32%, transparent);
    --fg: var(--cream);
    --fg-2: color-mix(in srgb, var(--sand) 72%, var(--cream));
    --fg-3: color-mix(in srgb, var(--sand) 72%, var(--espresso));
    --dot: var(--cream);

    --accent-top: color-mix(in srgb, var(--terracotta) 90%, var(--cream));
    --accent-deep: color-mix(in srgb, var(--terracotta) 84%, var(--charcoal));
    --accent-ink: color-mix(in srgb, var(--terracotta) 60%, var(--cream));
    --accent-soft: color-mix(in srgb, var(--terracotta) 24%, transparent);

    --ok: color-mix(in srgb, var(--olive) 82%, var(--cream));
    --ok-ink: color-mix(in srgb, var(--olive) 56%, var(--cream));
    --ok-soft: color-mix(in srgb, var(--olive) 30%, transparent);
    --bad: color-mix(in srgb, var(--burgundy) 84%, var(--cream));
    --bad-ink: color-mix(in srgb, var(--burgundy) 40%, var(--cream));
    --bad-soft: color-mix(in srgb, var(--burgundy) 42%, transparent);
    --neutral-soft: color-mix(in srgb, var(--sand) 18%, transparent);

    --chart-a: var(--cream);
    --chart-b: color-mix(in srgb, var(--sand) 52%, transparent);
    --chart-line: color-mix(in srgb, var(--terracotta) 72%, var(--cream));

    --focus: var(--brass);
    --glint: color-mix(in srgb, var(--brass) 30%, transparent);
    --brass-line: linear-gradient(90deg, transparent, var(--brass) 20%, var(--brass-soft) 50%, var(--brass) 80%, transparent);
    --shade: oklch(from var(--espresso) calc(l * 0.34) c h);
    --shadow-1: 0 1px 1px color-mix(in srgb, var(--shade) 30%, transparent), 0 4px 10px -4px color-mix(in srgb, var(--shade) 45%, transparent);
    --shadow-2: 0 1px 2px color-mix(in srgb, var(--shade) 35%, transparent), 0 22px 44px -22px color-mix(in srgb, var(--shade) 80%, transparent);
    --shadow-3: 0 2px 6px color-mix(in srgb, var(--shade) 40%, transparent), 0 40px 80px -30px color-mix(in srgb, var(--shade) 90%, transparent);
    --inner-hl: inset 0 1px 0 color-mix(in srgb, var(--cream) 7%, transparent);
    --backdrop: color-mix(in srgb, var(--espresso) 78%, transparent);
  }
}

/* ── base ─────────────────────────────────────────────────────────────────── */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html {
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    background: var(--bg);
  }
  html[lang="ar"] { line-height: 1.7; }
  body { margin: 0; color: var(--fg); background: var(--bg); }
  [data-theme="dark"] body {
    background:
      radial-gradient(900px 520px at 78% -8%, color-mix(in srgb, var(--burgundy) 20%, transparent), transparent 65%),
      radial-gradient(700px 420px at 10% 110%, color-mix(in srgb, var(--terracotta) 8%, transparent), transparent 70%),
      var(--bg);
  }
  h1, h2, h3, h4, p { margin: 0; }
  h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; letter-spacing: -.012em; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { -webkit-tap-highlight-color: transparent; }
  code { font-family: var(--font-mono); font-size: .92em; }
  img { max-width: 100%; }
  ::selection { background: color-mix(in srgb, var(--terracotta) 26%, transparent); }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--sand) 45%, transparent); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--sand) 70%, transparent); }
  * { scrollbar-color: color-mix(in srgb, var(--sand) 50%, transparent) transparent; scrollbar-width: thin; }
  [aria-invalid="true"] { box-shadow: 0 0 0 1.5px var(--bad); }
}

/* ── layout: shell, rail, top bar, mobile dock ───────────────────────────── */
@layer layout {
  .shell { display: flex; width: 100%; height: 100dvh; overflow: hidden; }

  /* rail */
  .rail {
    position: relative; isolation: isolate;
    width: var(--rail-w); flex: none;
    display: flex; flex-direction: column; gap: var(--s-1);
    padding: var(--s-5) var(--s-3) var(--s-4);
    overflow-y: auto; overflow-x: hidden;
    background: var(--rail-bg);
    border-inline-end: 1px solid var(--line);
  }
  .rail-brand { position: relative; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-1) var(--s-2) var(--s-5); margin-bottom: var(--s-3); min-width: 0; }
  .rail-brand::after { content: ""; position: absolute; inset-inline: var(--s-2); bottom: 0; height: 1px; background: var(--brass-line); opacity: .75; }
  .rail-brand img { width: 38px; height: 38px; border-radius: var(--r-md); object-fit: contain; flex: none; box-shadow: var(--shadow-1); }
  .rail-brand-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
  .rail-brand-txt b { font-family: var(--font-display); font-weight: 500; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rail-brand-txt small { font-size: 11.5px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .rail-nav { position: relative; isolation: isolate; }
  .rail-nav > div { display: flex; flex-direction: column; gap: calc(var(--rail-step) - var(--rail-row)); }
  /* the sliding active indicator: a terracotta pill with a brushed-brass edge */
  .rail-ind {
    position: absolute; z-index: -1; inset-inline: 0; top: 0; height: var(--rail-row);
    border-radius: var(--r-md);
    background: linear-gradient(180deg, var(--accent-top), var(--accent-deep));
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--cream) 24%, transparent), 0 8px 18px -10px color-mix(in srgb, var(--terracotta) 70%, transparent);
    opacity: 0;
    transform: translateY(0);
    transition: transform var(--dur-4) var(--ease-spring), opacity var(--dur-2) ease;
    will-change: transform;
  }
  .rail-ind::before { content: ""; position: absolute; inset-block: 9px; inset-inline-start: 0; width: 2px; border-radius: 2px; background: var(--brass-edge); }
  .rail-nav:not([data-idx="-1"]) .rail-ind { opacity: 1; }
  .rail-nav[data-idx="1"] .rail-ind { transform: translateY(calc(var(--rail-step) * 1)); }
  .rail-nav[data-idx="2"] .rail-ind { transform: translateY(calc(var(--rail-step) * 2)); }
  .rail-nav[data-idx="3"] .rail-ind { transform: translateY(calc(var(--rail-step) * 3)); }
  .rail-nav[data-idx="4"] .rail-ind { transform: translateY(calc(var(--rail-step) * 4)); }
  .rail-nav[data-idx="5"] .rail-ind { transform: translateY(calc(var(--rail-step) * 5)); }
  .rail-nav[data-idx="6"] .rail-ind { transform: translateY(calc(var(--rail-step) * 6)); }
  .rail-nav[data-idx="7"] .rail-ind { transform: translateY(calc(var(--rail-step) * 7)); }
  .rail-nav[data-idx="8"] .rail-ind { transform: translateY(calc(var(--rail-step) * 8)); }
  .rail-nav[data-idx="9"] .rail-ind { transform: translateY(calc(var(--rail-step) * 9)); }
  .rail-nav[data-idx="10"] .rail-ind { transform: translateY(calc(var(--rail-step) * 10)); }

  .rail-row {
    position: relative;
    display: flex; align-items: center; gap: var(--s-3);
    width: 100%; height: var(--rail-row); flex: none;
    padding-inline: var(--s-2) var(--s-3);
    border: 0; border-radius: var(--r-md);
    font-size: 13.5px; font-weight: 450; text-align: start;
    color: var(--fg-2); background: transparent; cursor: pointer;
    transition: color var(--dur-2) ease;
  }
  .rail-row::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: var(--surface-2); opacity: 0; transition: opacity var(--dur-1) ease; }
  .rail-row:hover { color: var(--fg); }
  .rail-row:hover::before { opacity: 1; }
  .rail-row > span:not(.rail-ic):not(.rail-count) { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rail-nav .rail-row[aria-current="page"] { color: var(--on-accent); }
  .rail-nav .rail-row[aria-current="page"]::before { opacity: 0; }
  .rail-ic { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); }
  .rail-ic svg { width: 18px; height: 18px; stroke-width: 1.7; }
  .rail-count {
    margin-inline-start: auto; flex: none;
    min-width: 22px; height: 20px; padding: 0 7px;
    display: inline-grid; place-items: center;
    font-family: var(--font-num); font-size: 11px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums;
    color: var(--fg-2); background: var(--surface); border-radius: var(--r-pill);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .rail-count.pop, .badge-dot.pop { animation: badge-pop var(--dur-4) var(--ease-spring); }
  .rail-count.bad { color: var(--cream); background: var(--bad); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cream) 18%, transparent); }
  .rail-nav .rail-row[aria-current="page"] .rail-count.bad { color: var(--charcoal); background: var(--cream); box-shadow: none; }
  .rail-row[aria-current="page"] .rail-count:not(.bad) { color: var(--cream); background: color-mix(in srgb, var(--cream) 18%, transparent); box-shadow: none; }
  .rail-spacer { flex: 1; min-height: var(--s-4); }
  #railConn { height: 36px; font-size: 12.5px; }
  #railConn .rail-ic { width: 30px; }
  .rail-row-out:hover { color: var(--bad-ink); }
  .rail-me {
    display: flex; align-items: center; gap: var(--s-3);
    margin-block: var(--s-2) var(--s-1); padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2);
    border-radius: var(--r-lg); min-width: 0;
    background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  }
  .rail-me .avatar {
    width: 34px; height: 34px; font-size: 13px;
    color: var(--cream); background: var(--charcoal);
    box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2.5px var(--brass-soft);
  }
  [data-theme="dark"] .rail-me .avatar { color: var(--charcoal); background: var(--cream); }
  .rail-me-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
  .rail-me-txt b { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail-me-txt small { font-size: 11px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: start; unicode-bidi: plaintext; }

  /* frame + top bar */
  .frame { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  .topbar {
    position: relative; z-index: 20; flex: none;
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3);
    padding: var(--s-4) var(--s-8) var(--s-2);
  }
  .topbar-title { display: flex; flex-direction: column; min-width: 0; }
  .topbar-title h1 { font-size: 19px; font-weight: 500; letter-spacing: -.015em; line-height: 1.3; }
  .topbar-sub { font-size: 12px; color: var(--fg-2); }
  .topbar-spacer { flex: 1; }

  /* branch switcher */
  .navpills {
    flex: none; display: flex; gap: var(--s-2);
    overflow-x: auto; scrollbar-width: none;
    padding: var(--s-2) var(--s-8) var(--s-3);
    border-bottom: 1px solid var(--line);
  }
  .navpills::-webkit-scrollbar { display: none; }
  .navpill {
    position: relative; isolation: isolate; overflow: hidden;
    flex: none; display: inline-flex; align-items: center; gap: var(--s-2);
    height: 36px; padding: 0 var(--s-4);
    border: 0; border-radius: var(--r-pill);
    font-size: 13px; font-weight: 450; white-space: nowrap; cursor: pointer;
    color: var(--fg-2); background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong);
    transition: color var(--dur-1) ease, background-color var(--dur-1) ease, box-shadow var(--dur-2) ease, transform var(--dur-3) var(--ease-spring);
  }
  .navpill:hover { color: var(--fg); background: var(--surface-2); transform: translateY(-1px); }
  .navpill:active { transform: scale(.97); transition-duration: var(--dur-1); }
  .navpill[aria-current="page"] {
    color: var(--accent-ink); background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--terracotta) 40%, transparent);
  }

  .main { flex: 1; min-width: 0; overflow: auto; padding: var(--s-6) var(--s-8) 56px; scroll-padding-top: var(--s-4); }

  /* mobile dock */
  .mbar-wrap {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    display: none; justify-content: center;
    padding: 0 var(--s-3) calc(env(safe-area-inset-bottom, 0px) + var(--s-3));
    pointer-events: none;
  }
  .mbar {
    pointer-events: auto;
    display: flex; align-items: center; gap: 2px;
    max-width: 100%; padding: 6px;
    overflow-x: auto; scrollbar-width: none;
    border-radius: 22px;
    background: var(--charcoal);
    box-shadow: 0 20px 40px -18px color-mix(in srgb, var(--charcoal) 70%, transparent), inset 0 1px 0 color-mix(in srgb, var(--cream) 10%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--cream) 6%, transparent);
  }
  [data-theme="dark"] .mbar { background: color-mix(in srgb, var(--espresso) 90%, var(--cream)); box-shadow: 0 20px 44px -18px var(--shade), inset 0 1px 0 color-mix(in srgb, var(--cream) 10%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--sand) 18%, transparent); }
  .mbar::-webkit-scrollbar { display: none; }
  .mbar-btn {
    position: relative; flex: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    min-width: 62px; height: 52px; padding: 0 var(--s-2);
    border: 0; border-radius: 16px;
    font-size: 10.5px; line-height: 1; white-space: nowrap;
    color: color-mix(in srgb, var(--cream) 62%, var(--charcoal)); background: transparent; cursor: pointer;
    isolation: isolate; overflow: hidden;
    transition: color var(--dur-1) ease, transform var(--dur-3) var(--ease-spring);
  }
  .mbar-btn:active { transform: scale(.94); transition-duration: var(--dur-1); }
  .mbar-btn svg { width: 20px; height: 20px; stroke-width: 1.7; }
  .mbar-btn:hover { color: var(--cream); }
  .mbar-btn[aria-current="page"] {
    color: var(--cream);
    background: linear-gradient(180deg, var(--accent-top), var(--accent-deep));
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--cream) 24%, transparent);
  }
  .mbar-btn[aria-current="page"]::after { content: ""; position: absolute; inset-inline: 16px; bottom: 0; height: 1.5px; border-radius: 2px; background: var(--brass-line); }
  .mbar-btn[aria-current="page"] .badge-dot { background: var(--cream); box-shadow: 0 0 0 2px var(--accent-deep); }
  .mbar-btn .badge-dot { position: absolute; top: 7px; inset-inline-end: 16px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--charcoal); }
}

/* ── components ───────────────────────────────────────────────────────────── */
@layer components {
  /* page scaffolding */
  .page { display: none; }
  .page.on { display: block; }
  .pg { display: flex; flex-direction: column; gap: var(--s-6); max-width: 1360px; margin-inline: auto; min-width: 0; }
  .sec { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
  .sec-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s-2) var(--s-3); padding-inline: 2px; }
  .sec-head h2, .sec-head h3 {
    display: inline-flex; align-items: center; gap: var(--s-2);
    font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-2);
  }
  .sec-head h2::before, .sec-head h3::before { content: ""; width: 18px; height: 1px; background: var(--brass-line); }
  .sec-head p, .sec-head small { font-size: 12.5px; color: var(--fg-2); display: inline-flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

  /* cards */
  .card {
    position: relative; isolation: isolate; min-width: 0;
    padding: var(--s-6);
    border-radius: var(--r-xl);
    background: var(--surface);
    box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line), var(--inner-hl);
  }
  /* hover depth: a deeper shadow that fades in (opacity only) */
  .card::after {
    content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
    box-shadow: var(--shadow-3); opacity: 0; transition: opacity var(--dur-3) var(--ease-out);
  }
  .card:hover::after { opacity: .7; }
  [data-theme="dark"] .card { background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 93%, var(--cream)), var(--surface) 46%); }
  .card-tight { padding: var(--s-4) var(--s-5); border-radius: var(--r-lg); }
  .card h3 { font-size: 15px; font-weight: 500; letter-spacing: -.008em; }
  .card h4 { font-size: 13px; font-weight: 500; }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4); }
  .card-sub { margin-top: var(--s-1); font-size: 12.5px; line-height: 1.6; color: var(--fg-2); }
  h4.card-sub { font-family: var(--font-ui); font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
  button.card { text-align: start; cursor: pointer; border: 0; font: inherit; color: inherit; }
  .sep { border: 0; height: 1px; margin: var(--s-5) 0; background: var(--line); }
  .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
  .grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: var(--s-4); }
  .card > .grid-2 { gap: var(--s-3) var(--s-4); }

  /* fields */
  .fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .fld + .fld { margin-top: var(--s-3); }
  .grid-2 > .fld + .fld { margin-top: 0; }
  .fld-l { font-size: 12px; font-weight: 500; color: var(--fg-2); }
  .fld-hint { font-size: 11.5px; color: var(--fg-2); }
  .fld-hint[role="alert"] { color: var(--bad-ink); }
  .fld-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
  .fld-row > .inp { flex: 1; min-width: 160px; }
  .fld-row > .inp-sm { flex: 0 1 auto; min-width: 0; }
  .lbl { display: block; margin-bottom: var(--s-2); }
  .check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; min-height: 32px; }
  .check .fld-l, .check .fld-hint { cursor: pointer; }
  input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--terracotta); cursor: pointer; }
  .range { width: 100%; accent-color: var(--terracotta); cursor: pointer; }
  .inp {
    width: 100%; min-height: 44px;
    padding: 9px 14px;
    border: 0; border-radius: var(--r-md); outline: none;
    font-size: 14px; color: var(--fg);
    background: var(--field);
    box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 1px 2px color-mix(in srgb, var(--shade) 5%, transparent);
    transition: box-shadow var(--dur-1) ease, background-color var(--dur-1) ease;
  }
  .inp:hover { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sand) 80%, transparent); }
  .inp:focus { box-shadow: inset 0 0 0 1.5px var(--focus), 0 0 0 4px var(--glint); }
  .inp::placeholder { color: var(--fg-3); }
  .inp:disabled { opacity: .5; cursor: not-allowed; }
  .inp[aria-invalid="true"] { box-shadow: inset 0 0 0 1.5px var(--bad), 0 0 0 3px var(--bad-soft); }
  textarea.inp { min-height: 84px; resize: vertical; line-height: 1.6; }
  select.inp {
    appearance: none; -webkit-appearance: none; cursor: pointer;
    padding-inline-end: 36px;
    background-image: linear-gradient(45deg, transparent 50%, var(--fg-2) 50%), linear-gradient(135deg, var(--fg-2) 50%, transparent 50%);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    background-position: right 18px center, right 13px center;
  }
  [dir="rtl"] select.inp { background-position: left 13px center, left 18px center; }
  select.inp[multiple] { background-image: none; padding-inline-end: 14px; }
  select.inp option { background: var(--surface); color: var(--fg); }
  input[type="file"].inp { padding: 7px 8px; font-size: 13px; }
  input[type="file"].inp::file-selector-button {
    margin-inline-end: var(--s-3); height: 28px; padding: 0 var(--s-3);
    border: 0; border-radius: var(--r-sm); cursor: pointer;
    font: inherit; font-size: 12.5px; color: var(--fg); background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line-strong);
  }
  input[type="date"].inp, input[type="time"].inp { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
  .inp-sm { min-height: 36px; padding: 5px 12px; font-size: 13px; width: auto; border-radius: var(--r-sm); }
  select.inp-sm { padding-inline-end: 32px; }
  .pw { position: relative; }
  .pw .inp { padding-inline-end: 46px; }
  .pw .ibtn { position: absolute; inset-inline-end: 4px; top: 50%; translate: 0 -50%; width: 34px; height: 34px; background: transparent; box-shadow: none; }

  /* buttons: heights 44 (default) / 36 (small). Pseudo-elements: ::before is
     the hover sheen, ::after the busy spinner or the saved tick; the press
     glow is one shared .ripple element (core.js). */
  .btn {
    position: relative; isolation: isolate; overflow: hidden;
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    height: 44px; padding: 0 20px;
    border: 0; border-radius: var(--r-md);
    font-size: 13.5px; font-weight: 500; letter-spacing: .005em; white-space: nowrap; text-decoration: none;
    cursor: pointer; user-select: none;
    color: var(--on-accent);
    background: linear-gradient(180deg, var(--accent-top), var(--accent-deep));
    --btn-shadow:
      inset 0 1px 0 color-mix(in srgb, var(--cream) 30%, transparent),
      inset 0 -1px 0 color-mix(in srgb, var(--charcoal) 24%, transparent),
      0 1px 2px color-mix(in srgb, var(--charcoal) 18%, transparent),
      0 8px 18px -10px color-mix(in srgb, var(--terracotta) 70%, transparent);
    --btn-bloom: 0 14px 28px -12px color-mix(in srgb, var(--terracotta) 75%, transparent);
    --btn-edge: 0 0 0 1px color-mix(in srgb, var(--brass) 60%, transparent);
    --sheen: color-mix(in srgb, var(--cream) 26%, transparent);
    box-shadow: var(--btn-shadow);
    transition: transform var(--dur-3) var(--ease-spring), box-shadow var(--dur-2) var(--ease-out), color var(--dur-1) ease, opacity var(--dur-2) ease;
  }
  .btn::before {
    content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
    background: linear-gradient(105deg, transparent 30%, var(--sheen) 48%, transparent 66%);
    transform: translateX(-110%);
  }
  .btn:hover { transform: translateY(-1px); box-shadow: var(--btn-shadow), var(--btn-edge), var(--btn-bloom); }
  .btn:hover::before { transform: translateX(110%); transition: transform 760ms var(--ease-out); }
  .btn:active {
    transform: scale(.97); transition-duration: var(--dur-1);
    box-shadow: inset 0 2px 4px color-mix(in srgb, var(--charcoal) 34%, transparent), 0 1px 1px color-mix(in srgb, var(--charcoal) 12%, transparent);
  }
  .btn:disabled { opacity: .42; cursor: not-allowed; transform: none; box-shadow: var(--btn-shadow); }
  .btn:disabled::before { display: none; }
  .btn svg { width: 16px; height: 16px; flex: none; }
  /* busy: the label steps back, a fine spinner and a travelling shimmer */
  .btn[aria-busy="true"] { color: transparent; pointer-events: none; }
  .btn[aria-busy="true"]::before { display: block; transform: translateX(-110%); animation: btn-shimmer 1.1s var(--ease-in-out) infinite; }
  .btn[aria-busy="true"]::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid color-mix(in srgb, var(--on-accent) 30%, transparent); border-top-color: var(--on-accent);
    animation: spin .8s linear infinite;
  }
  /* saved: the label gives way to a tick that draws itself */
  .btn.is-done { color: transparent; pointer-events: none; }
  .btn.is-done::after {
    content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 13px;
    margin: -9px 0 0 -4px;
    border-right: 2.2px solid var(--on-accent); border-bottom: 2.2px solid var(--on-accent);
    transform: rotate(45deg); transform-origin: center;
    animation: tick-in var(--dur-3) var(--ease-spring) both;
  }
  .btn-soft {
    color: var(--fg);
    background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 70%, var(--paper)), var(--surface-2));
    --btn-shadow: inset 0 0 0 1px var(--line-strong), var(--inner-hl), 0 1px 2px color-mix(in srgb, var(--shade) 8%, transparent);
    --btn-bloom: 0 12px 24px -14px color-mix(in srgb, var(--shade) 40%, transparent);
    --btn-edge: inset 0 0 0 1px color-mix(in srgb, var(--sand) 70%, transparent);
    --sheen: color-mix(in srgb, var(--paper) 70%, transparent);
  }
  [data-theme="dark"] .btn-soft { background: linear-gradient(180deg, var(--surface-3), var(--surface-2)); --sheen: color-mix(in srgb, var(--cream) 10%, transparent); }
  .btn-soft:active { box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 2px 3px color-mix(in srgb, var(--shade) 14%, transparent); }
  .btn-soft[aria-busy="true"]::after, .btn-ghost[aria-busy="true"]::after { border-color: var(--line-strong); border-top-color: var(--fg); }
  .btn-soft.is-done::after, .btn-ghost.is-done::after { border-color: var(--ok-ink); border-top-color: transparent; border-left-color: transparent; }
  .btn-ghost {
    color: var(--fg-2); background: transparent; padding-inline: var(--s-3);
    --btn-shadow: 0 0 0 0 transparent; --btn-bloom: 0 0 0 0 transparent; --btn-edge: inset 0 0 0 1px var(--line);
    --sheen: color-mix(in srgb, var(--sand) 14%, transparent);
  }
  .btn-ghost:hover { color: var(--fg); background: var(--surface-2); }
  .btn-ghost:active { box-shadow: none; }
  .btn-ghost.danger:hover { color: var(--bad-ink); }
  .btn-danger {
    color: var(--cream);
    background: linear-gradient(180deg, color-mix(in srgb, var(--burgundy) 88%, var(--cream)), var(--burgundy));
    --btn-shadow: inset 0 1px 0 color-mix(in srgb, var(--cream) 22%, transparent), 0 1px 2px color-mix(in srgb, var(--charcoal) 20%, transparent), 0 8px 18px -10px color-mix(in srgb, var(--burgundy) 80%, transparent);
    --btn-bloom: 0 14px 28px -12px color-mix(in srgb, var(--burgundy) 80%, transparent);
    --btn-edge: 0 0 0 1px color-mix(in srgb, var(--cream) 30%, transparent);
  }
  .btn-sm { height: 36px; padding: 0 14px; font-size: 12.5px; border-radius: var(--r-sm); gap: 6px; }
  .btn-sm svg { width: 14px; height: 14px; }
  .btn-ghost.btn-sm { padding-inline: 10px; }
  .btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-5); }

  .ibtn {
    position: relative; isolation: isolate; flex: none; overflow: hidden;
    width: 44px; height: 44px;
    display: inline-grid; place-items: center;
    border: 0; border-radius: var(--r-md); cursor: pointer;
    font-size: 13px; font-weight: 500;
    color: var(--fg-2);
    background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 70%, var(--surface-2)));
    box-shadow: inset 0 0 0 1px var(--line-strong), var(--inner-hl), var(--shadow-1);
    transition: color var(--dur-1) ease, box-shadow var(--dur-2) var(--ease-out), transform var(--dur-3) var(--ease-spring);
  }
  .ibtn:hover { color: var(--fg); transform: translateY(-1px); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sand) 70%, transparent), var(--inner-hl), var(--shadow-2); }
  .ibtn:active { transform: scale(.94); transition-duration: var(--dur-1); }
  .ibtn svg { width: 18px; height: 18px; stroke-width: 1.8; transition: transform var(--dur-3) var(--ease-spring); }
  .ibtn:hover svg { transform: scale(1.06); }
  .ibtn-sm { width: 36px; height: 36px; border-radius: var(--r-sm); }
  .ibtn-sm svg { width: 15px; height: 15px; }
  .ibtn[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--terracotta) 40%, transparent); }
  .card .ibtn, .zone-row .ibtn { box-shadow: none; background: transparent; }
  .card .ibtn:hover, .zone-row .ibtn:hover { background: var(--surface-3); box-shadow: none; }
  /* buttons that sit on the video: grouped in one quiet HUD pill each
     (.hud-group), so the picture — not the controls — has the attention */
  .hud-group {
    display: inline-flex; align-items: center; gap: 2px; padding: 3px;
    border-radius: var(--r-pill);
    background: var(--hud); box-shadow: inset 0 0 0 1px var(--hud-line);
    backdrop-filter: blur(8px);
  }
  .hud-group:not(:has(> :not(.hidden))) { display: none; }
  .ibtn-hud { width: 30px; height: 30px; color: color-mix(in srgb, var(--cream) 82%, transparent); background: transparent; box-shadow: none; border-radius: var(--r-pill); }
  .ibtn-hud:hover { color: var(--cream); background: color-mix(in srgb, var(--cream) 12%, transparent); box-shadow: none; transform: none; }
  .ibtn-hud[aria-pressed="true"], .ibtn-hud[aria-expanded="true"] {
    color: var(--cream);
    background: color-mix(in srgb, var(--cream) 18%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brass) 40%, transparent);
  }
  .ibtn-hud[aria-pressed="false"] { color: color-mix(in srgb, var(--cream) 55%, transparent); }

  /* press glow: one element, moved to the pressed control (core.js) */
  .ripple {
    position: absolute; z-index: -1; pointer-events: none;
    left: var(--rx, 50%); top: var(--ry, 50%);
    width: var(--rs, 120px); height: var(--rs, 120px); margin: calc(var(--rs, 120px) / -2) 0 0 calc(var(--rs, 120px) / -2);
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, currentColor 28%, transparent) 0, transparent 62%);
    opacity: 0; transform: scale(.2);
  }
  .ripple.go { animation: ripple var(--dur-4) var(--ease-out) both; }

  /* focus: a brass ring with a soft glow */
  .btn:focus-visible, .ibtn:focus-visible, .chip:focus-visible, .navpill:focus-visible, .rail-row:focus-visible,
  .mbar-btn:focus-visible, .utab:focus-visible, .mini:focus-visible, .dash-status:focus-visible, .mesh:focus-visible, .alert-thumb:focus-visible {
    outline: 2px solid var(--focus); outline-offset: 2px;
    box-shadow: 0 0 0 5px var(--glint), 0 0 18px 4px var(--glint);
  }

  /* chips, dots */
  .chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 26px; padding: 0 11px;
    border: 0; border-radius: var(--r-pill);
    font-size: 12px; font-weight: 450; line-height: 1; white-space: nowrap;
    color: var(--fg-2); background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .chip b { font-weight: 600; color: var(--fg); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
  .chip-ok { color: var(--ok-ink); background: var(--ok-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--olive) 30%, transparent); }
  .chip-warn { color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--terracotta) 30%, transparent); }
  .chip-bad { color: var(--bad-ink); background: var(--bad-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--burgundy) 30%, transparent); }
  .chip-live { color: var(--ok-ink); background: var(--ok-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--olive) 30%, transparent); }
  .chip-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
  .chip-ink { color: var(--cream); background: var(--charcoal); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brass) 30%, transparent); }
  [data-theme="dark"] .chip-ink { color: var(--charcoal); background: var(--cream); }
  .net-chip[data-state="ok"] { display: none; }
  button.chip {
    position: relative; isolation: isolate; overflow: hidden;
    height: 36px; padding: 0 14px; font-size: 13px; cursor: pointer;
    color: var(--fg); background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong);
    transition: color var(--dur-1) ease, background-color var(--dur-1) ease, box-shadow var(--dur-2) ease, transform var(--dur-3) var(--ease-spring);
  }
  button.chip:hover { background: var(--surface-2); transform: translateY(-1px); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sand) 70%, transparent), var(--shadow-1); }
  button.chip:active { transform: scale(.96); transition-duration: var(--dur-1); }
  button.chip[aria-pressed="true"] {
    color: var(--on-accent);
    background: linear-gradient(180deg, var(--accent-top), var(--accent-deep));
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--cream) 24%, transparent), 0 6px 14px -8px color-mix(in srgb, var(--terracotta) 70%, transparent);
  }
  button.chip[aria-pressed="true"] b { color: inherit; }
  button.chip.chip-ok { color: var(--ok-ink); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--olive) 40%, transparent); }
  button.chip.chip-warn { color: var(--accent-ink); }
  button.chip.chip-bad { color: var(--bad-ink); }
  .chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
  .chip svg { width: 13px; height: 13px; flex: none; stroke-width: 2.1; }
  .chip [data-icon] { display: inline-grid; place-items: center; }
  .dot { position: relative; width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; background: var(--fg-3); }
  .dot-ok { background: var(--ok); }
  .dot-warn { background: var(--accent); }
  .dot-bad { background: var(--bad); }
  .dot-accent { background: var(--accent); }
  .dot-pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; opacity: .55; animation: pulse 2.2s var(--ease-out) infinite; }

  /* underline tabs */
  .utabs { display: flex; gap: var(--s-1); overflow-x: auto; scrollbar-width: none; padding: 4px; border-radius: var(--r-lg); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
  .utabs::-webkit-scrollbar { display: none; }
  .utab {
    position: relative; isolation: isolate; overflow: hidden; flex: none;
    display: inline-flex; align-items: center; gap: var(--s-2);
    height: 36px; padding: 0 14px;
    border: 0; border-radius: var(--r-md); background: transparent;
    font-size: 13px; font-weight: 450; color: var(--fg-2); white-space: nowrap; cursor: pointer;
    transition: color var(--dur-1) ease, background-color var(--dur-2) ease, box-shadow var(--dur-2) ease, transform var(--dur-3) var(--ease-spring);
  }
  .utab:hover { color: var(--fg); background: color-mix(in srgb, var(--surface) 55%, transparent); }
  .utab:active { transform: scale(.97); transition-duration: var(--dur-1); }
  .utab[aria-selected="true"] { color: var(--fg); background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }
  .utab[aria-selected="true"]::after {
    content: ""; position: absolute; inset-inline: 14px; bottom: 5px; height: 2px; border-radius: 2px;
    background: var(--accent); transform-origin: center; animation: grow-x var(--dur-3) var(--ease-out) both;
  }
  .tabpane { display: none; }
  .tabpane.on { display: flex; flex-direction: column; gap: var(--s-4); }

  /* tables */
  .tbl-wrap { position: relative; overflow-x: auto; min-width: 0; margin-inline: calc(var(--s-2) * -1); padding-inline: var(--s-2); }
  .tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
  .tbl th {
    text-align: start; white-space: nowrap;
    padding: var(--s-2) var(--s-3) 10px;
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-2);
    border-bottom: 1px solid var(--line-strong);
  }
  .tbl td { padding: var(--s-3); vertical-align: middle; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child td { border-bottom: 0; }
  .tbl td:first-child:not(.num) { min-width: 8em; }
  .tbl td.num, .tbl th.num { text-align: end; }
  .td-bar { min-width: 120px; }
  .tbl td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
  .tbl td.bad { color: var(--bad-ink); font-weight: 500; }
  .tbl tbody tr { transition: background-color var(--dur-1) ease; }
  .tbl tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
  .tbl tbody tr:hover td:first-child { border-start-start-radius: var(--r-sm); border-end-start-radius: var(--r-sm); }
  .tbl tbody tr:hover td:last-child { border-start-end-radius: var(--r-sm); border-end-end-radius: var(--r-sm); }
  .tbl .inp-sm { min-height: 32px; }

  /* lists, rows, key-values */
  .list { display: flex; flex-direction: column; gap: var(--s-2); }
  .row {
    display: flex; align-items: center; gap: var(--s-3); min-width: 0;
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
    transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2) ease;
  }
  .list > .row:hover { transform: translateY(-1px); box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line-strong); }
  .card .row { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
  .card .list > .row:hover { box-shadow: inset 0 0 0 1px var(--line-strong); }
  .row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .row-title { font-size: 14px; font-weight: 450; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .row-sub { font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kv { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 11px 0; font-size: 13.5px; }
  .kv + .kv { border-top: 1px solid var(--line); }
  .kv > span { color: var(--fg-2); display: inline-flex; align-items: center; gap: var(--s-2); min-width: 0; }
  .kv > b { font-weight: 500; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 14.5px; text-align: end; }
  .kv > b.ok { color: var(--ok-ink); }
  .kv > b.bad { color: var(--bad-ink); }
  .strong { font-weight: 500; }

  /* split bars (js ui.splitBar → svg) */
  .bar { display: block; width: 100%; height: 8px; border-radius: var(--r-pill); overflow: hidden; background: var(--surface-3); }
  .bar rect { transition: width var(--dur-3) var(--ease-out); }
  .seg-ok { fill: var(--ok); }
  .seg-warn { fill: var(--accent); }
  .seg-bad { fill: var(--bad); }
  .seg-neutral { fill: var(--sand); }
  .seg-accent { fill: var(--accent); }

  /* legends */
  .legend { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: 11.5px; color: var(--fg-2); }
  .legend > span { display: inline-flex; gap: 6px; align-items: center; }
  .legend .dot { width: 8px; height: 8px; border-radius: 3px; }
  .sw-a { background: var(--chart-a); }
  .sw-b { background: var(--chart-b); }
  .sw-line { background: var(--chart-line); }

  /* SVG charts (ui.js barChart) */
  .chart { display: block; width: 100%; height: auto; direction: ltr; overflow: visible; }
  .chart .ch-grid { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 2 5; }
  .chart .ch-t { font-size: 9.5px; fill: var(--fg-2); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
  .chart .b-in { fill: var(--chart-a); }
  .chart .b-out { fill: var(--chart-b); }
  .chart rect { transition: opacity var(--dur-1) ease; }
  .chart rect:hover { opacity: .72; }
  .chart .ch-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
  .chart .ch-dot { fill: var(--surface); stroke: var(--chart-line); stroke-width: 2; }
  .chart-enter rect { transform-box: fill-box; transform-origin: 50% 100%; animation: bar-in var(--dur-4) var(--ease-spring) both; }
  .chart-enter rect:nth-of-type(3n+2) { animation-delay: 40ms; }
  .chart-enter rect:nth-of-type(3n) { animation-delay: 80ms; }
  .chart-enter .ch-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: line-draw 900ms var(--ease-in-out) 120ms forwards; }
  .chart-enter .ch-dot { animation: fade-in var(--dur-3) ease 700ms both; }

  /* notes, empty states */
  .note {
    position: relative;
    display: flex; align-items: flex-start; gap: 10px;
    padding: var(--s-3) var(--s-4); padding-inline-start: 18px;
    border-radius: var(--r-md);
    font-size: 13px; line-height: 1.65;
    color: var(--fg); background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .note::before { content: ""; position: absolute; inset-block: 10px; inset-inline-start: 7px; width: 3px; border-radius: 3px; background: var(--sand); }
  .note-ok { color: var(--ok-ink); background: var(--ok-soft); }
  .note-ok::before { background: var(--ok); }
  .note-warn { color: var(--accent-ink); background: var(--accent-soft); }
  .note-warn::before { background: var(--accent); }
  .empty { padding: 36px var(--s-4); text-align: center; color: var(--fg-2); font-size: 13.5px; line-height: 1.7; }
  .empty-glyph {
    width: 52px; height: 52px; margin: 0 auto var(--s-3);
    display: grid; place-items: center; border-radius: 16px;
    color: var(--fg-2); background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line), 0 0 0 5px color-mix(in srgb, var(--surface-2) 45%, transparent);
  }
  .empty-glyph svg { width: 22px; height: 22px; stroke-width: 1.6; }
  .empty .btn-row { justify-content: center; margin-top: var(--s-4); }

  /* skeleton */
  .skl { position: relative; overflow: hidden; min-height: 140px; border-radius: var(--r-lg); background: var(--surface-2); }
  .skl::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--paper) 55%, transparent), transparent);
    transform: translateX(-100%);
    animation: shimmer 1.5s var(--ease-in-out) infinite;
  }
  [data-theme="dark"] .skl::after { background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--cream) 6%, transparent), transparent); }

  /* modal + toast */
  .modal {
    width: calc(100% - 32px); max-width: 560px; max-height: 88vh; overflow: auto;
    padding: var(--s-6);
    border: 0; border-radius: var(--r-2xl);
    color: inherit; background: var(--surface);
    box-shadow: var(--shadow-3), inset 0 0 0 1px var(--line);
  }
  .modal::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
  .modal-wide { max-width: 1000px; padding: var(--s-3); }
  .modal-wide img, .modal-wide video { display: block; width: 100%; border-radius: var(--r-lg); background: var(--stage); }
  .modal-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); padding-inline: var(--s-2) 0; }
  .modal-head h3 { font-size: 16px; }
  .toast {
    position: fixed; z-index: 70; bottom: 28px; inset-inline-start: 50%;
    max-width: calc(100% - 32px);
    padding: 12px 20px;
    border-radius: var(--r-lg);
    font-size: 13.5px; font-weight: 450;
    color: var(--cream); background: var(--charcoal);
    box-shadow: 0 24px 48px -20px color-mix(in srgb, var(--charcoal) 70%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--cream) 8%, transparent);
    opacity: 0; pointer-events: none;
    translate: -50% 16px;
    transition: opacity var(--dur-2) ease, translate var(--dur-4) var(--ease-spring);
  }
  .toast::before { content: ""; position: absolute; inset-inline: 18px; top: 0; height: 1px; background: var(--brass-line); }
  [dir="rtl"] .toast { translate: 50% 16px; }
  .toast.on { opacity: 1; translate: -50% 0; }
  [dir="rtl"] .toast.on { translate: 50% 0; }
  [data-theme="dark"] .toast { background: var(--surface-3); color: var(--fg); }


  /* numbers */
  .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "lnum" 1; }
  .ltr { direction: ltr; unicode-bidi: isolate; }
  .dotnum { color: var(--dot); overflow: visible; display: block; direction: ltr; flex: none; }
  .splitnum {
    font-family: var(--font-num); font-weight: 300; letter-spacing: -.025em;
    font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; line-height: 1;
    color: var(--fg);
  }
  .splitnum-unit, .tile-v > span, .mesh-big > span:last-child {
    position: relative;
    font-size: 13px; font-weight: 450; letter-spacing: 0; color: var(--fg-2);
  }
  .splitnum-unit { font-size: .4em; margin-inline-start: .3em; }
  .splitnum-unit::after, .tile-v > span::after {
    content: ""; position: absolute; inset-inline: 0; bottom: -4px; height: 1px; background: var(--brass-line);
  }
  .big { font-size: 36px; }
  .mid { font-size: 26px; }
  .avatar { flex: none; display: grid; place-items: center; border-radius: 50%; font-weight: 500; font-family: var(--font-display); }

  /* ── video stage ─────────────────────────────────────────────────────── */
  .vid {
    position: relative; isolation: isolate;
    width: 100%; aspect-ratio: 16 / 9;
    border-radius: var(--r-xl); overflow: hidden;
    background: radial-gradient(120% 90% at 50% 40%, var(--stage), var(--stage-deep));
    box-shadow: 0 1px 2px color-mix(in srgb, var(--charcoal) 20%, transparent), 0 26px 50px -30px color-mix(in srgb, var(--charcoal) 70%, transparent);
  }
  /* inner frame hairline + a soft cinematic vignette, above the picture */
  .vid::after {
    content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; border-radius: inherit;
    background: radial-gradient(130% 100% at 50% 45%, transparent 60%, color-mix(in srgb, var(--charcoal) 55%, transparent));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cream) 9%, transparent);
  }
  .vid canvas, .vid .vid-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
  .vid .vid-img { object-fit: cover; }
  .vid.swap canvas, .vid.has-frame canvas { animation: stage-in var(--dur-4) var(--ease-out) both; }
  .vid-empty {
    position: absolute; inset: 0; z-index: 1;
    display: grid; place-items: center; align-content: center; gap: 10px;
    padding: var(--s-4);
    font-size: 13px; text-align: center;
    color: color-mix(in srgb, var(--cream) 62%, transparent);
  }
  .vid-empty svg { width: 28px; height: 28px; stroke-width: 1.5; opacity: .75; }
  .vid.has-frame .vid-empty { display: none; }
  /* stalled: the picture stopped arriving — hatch it, never show it as live */
  .vid.stalled::before {
    content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--charcoal) 42%, transparent) 0 10px, color-mix(in srgb, var(--charcoal) 22%, transparent) 10px 20px);
  }
  .vid-hud { position: absolute; inset-inline: 14px; top: 14px; z-index: 2; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; pointer-events: none; }
  .vid-hud > * { pointer-events: auto; }
  .vid-hud .spacer, .vid-foot .spacer { flex: 1; }
  .hud-chip {
    display: inline-flex; align-items: center; gap: 7px;
    height: 28px; padding: 0 12px;
    border-radius: var(--r-pill);
    font-size: 12px; font-weight: 450; white-space: nowrap;
    color: var(--cream); background: var(--hud);
    box-shadow: inset 0 0 0 1px var(--hud-line);
  }
  .hud-chip:empty { display: none; }
  .hud-chip b { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; }
  .hud-chip .dot { width: 7px; height: 7px; background: color-mix(in srgb, var(--cream) 45%, transparent); }
  .hud-chip .dot-ok { background: var(--olive); box-shadow: 0 0 0 2px color-mix(in srgb, var(--olive) 30%, transparent); }
  .hud-chip .dot-warn { background: var(--terracotta); }
  .hud-chip .dot-bad { background: color-mix(in srgb, var(--burgundy) 70%, var(--cream)); }
  .hud-in { background: color-mix(in srgb, var(--olive) 88%, var(--charcoal)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cream) 18%, transparent); }
  .vid-foot { position: absolute; inset-inline: 14px; bottom: 14px; z-index: 2; display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; pointer-events: none; }
  .vid-foot > * { pointer-events: auto; }
  .vid-title { color: var(--cream); font-size: 14px; font-weight: 500; line-height: 1.35; text-shadow: 0 1px 10px color-mix(in srgb, var(--charcoal) 80%, transparent); }
  .vid-title small { display: block; font-size: 11.5px; font-weight: 400; opacity: .78; }
  .vid:fullscreen { border-radius: 0; aspect-ratio: auto; }
  /* the overlay's box colours (palette.js stageInk: visitor olive, staff
     brass with a heavier edge and a corner tab, violation burgundy) */
  .stage-legend { gap: 6px; }
  .stage-legend > span + .lg { margin-inline-start: 6px; }
  .lg {
    position: relative; flex: none; display: inline-block;
    width: 12px; height: 10px; border-radius: 2px;
    border: 1.5px solid var(--lg-c, currentColor);
  }
  .lg-visitor { --lg-c: color-mix(in srgb, var(--olive) 70%, var(--cream)); }
  .lg-staff { --lg-c: var(--brass); border-width: 2.5px; background: linear-gradient(135deg, var(--lg-c) 0 32%, transparent 32%); }
  .lg-alert { --lg-c: color-mix(in srgb, var(--burgundy) 78%, var(--cream)); }
  .stage-legend-m { display: none; }

  /* the stage on the live page gets a thin brass bezel */
  #stage { border-radius: var(--r-2xl); box-shadow: 0 0 0 1px color-mix(in srgb, var(--brass) 22%, transparent), 0 2px 4px color-mix(in srgb, var(--charcoal) 16%, transparent), 0 40px 70px -36px color-mix(in srgb, var(--charcoal) 75%, transparent); }
  #stage canvas { cursor: default; }
  #stage.pointing canvas { cursor: pointer; }

  /* the one tooltip on the stage: who the hovered / tapped person is */
  .vid-tip {
    position: absolute; z-index: 3; pointer-events: none;
    translate: -50% calc(-100% - 8px);
    padding: 5px 11px;
    border-radius: var(--r-pill);
    font-size: 12.5px; font-weight: 500; white-space: nowrap;
    color: var(--cream); background: color-mix(in srgb, var(--charcoal) 88%, transparent);
    box-shadow: inset 0 0 0 1px var(--hud-line), 0 6px 18px -6px color-mix(in srgb, var(--charcoal) 70%, transparent);
    animation: fade-in var(--dur-1) ease both;
  }
  .vid-tip.below { translate: -50% 8px; }

  .label-menu {
    position: absolute; z-index: 5;
    display: flex; align-items: center; gap: 6px;
    padding: 6px; padding-inline-start: 14px;
    border-radius: var(--r-pill);
    font-size: 12.5px;
    color: var(--fg); background: var(--surface);
    box-shadow: var(--shadow-3), inset 0 0 0 1px var(--line);
    animation: pop-in var(--dur-2) var(--ease-out) both;
  }
  .label-menu b { font-weight: 500; margin-inline-end: 4px; }

  /* ── camera wall ─────────────────────────────────────────────────────── */
  .wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: var(--s-4); }
  .wall-tile {
    position: relative; display: block;
    padding: 0; border: 0; border-radius: var(--r-xl);
    background: none; text-align: start; cursor: pointer; color: inherit;
    transition: transform var(--dur-2) var(--ease-out);
  }
  .wall-tile .vid { border-radius: var(--r-xl); }
  .wall-tile::after {
    content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
    box-shadow: 0 30px 50px -26px color-mix(in srgb, var(--charcoal) 80%, transparent);
    opacity: 0; transition: opacity var(--dur-2) ease;
  }
  .wall-tile:hover { transform: translateY(-3px); }
  .wall-tile:hover::after { opacity: 1; }
  .wall-tile:active { transform: translateY(-1px) scale(.995); }
  .wall-tile[aria-current="true"] .vid { box-shadow: 0 0 0 2px var(--accent), 0 0 0 5px color-mix(in srgb, var(--brass) 30%, transparent), 0 20px 36px -24px color-mix(in srgb, var(--charcoal) 70%, transparent); }
  .wall-tile:focus-visible { outline: none; }
  .wall-tile:focus-visible .vid { box-shadow: 0 0 0 2px var(--focus), 0 0 0 6px var(--glint); }
  .wall-tile .vid-hud { inset-inline: 10px; top: 10px; }
  .wall-tile .vid-foot { inset-inline: 12px; bottom: 10px; }
  .wall-tile .hud-chip { height: 24px; font-size: 11px; padding: 0 9px; }
  .wall-tile .vid-title { font-size: 13px; }
  .wall-off .vid { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
  .wall-off .vid::after { display: none; }
  .wall-off .vid-empty { color: var(--fg-2); }
  .wall-off .vid-title { color: var(--fg); text-shadow: none; }
  .wall-off .hud-chip { color: var(--fg-2); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
  .card .wall .vid { box-shadow: 0 1px 2px color-mix(in srgb, var(--charcoal) 16%, transparent); }

  /* small stat insets */
  .stat-trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-2); }
  .stat-trio { align-self: start; }
  .stat-trio.one { grid-template-columns: minmax(0, 1fr); }
  .stat-trio.one .big { font-size: 56px; }
  .stat-trio.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-trio > div {
    display: flex; flex-direction: column; gap: 10px; min-width: 0;
    padding: 14px 16px;
    border-radius: var(--r-lg);
    color: var(--dot); background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .stat-trio small { font-size: 11.5px; color: var(--fg-2); }
  .tiles-group + .tiles-group { margin-top: var(--s-4); }
  .tiles-label { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); font-size: 11.5px; font-weight: 600; color: var(--fg-2); }
  .tiles-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
  .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: var(--s-2); }
  .ttile {
    display: flex; flex-direction: column; gap: 4px;
    padding: var(--s-3);
    border-radius: var(--r-md);
    font-size: 13px; font-weight: 450;
    background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  }
  .ttile small { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 400; color: var(--fg-2); }
  .ttile.occupied small { color: var(--accent-ink); }
  .ttile.occupied .dot { background: var(--accent); }
  .ttile.awaiting { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--burgundy) 35%, transparent); }
  .ttile.awaiting small { color: var(--bad-ink); }
  .ttile.awaiting .dot { background: var(--bad); }
  .ttile.free small { color: var(--ok-ink); }
  .ttile.free .dot { background: var(--ok); }

  /* ── zone editor ─────────────────────────────────────────────────────── */
  .ed-canvas {
    position: relative; overflow: hidden;
    width: 100%; aspect-ratio: 16 / 9;
    border-radius: var(--r-xl);
    background: var(--stage);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--brass) 18%, transparent), 0 26px 50px -30px color-mix(in srgb, var(--charcoal) 70%, transparent);
  }
  .ed-canvas canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
  .ed-hint {
    position: absolute; inset-inline: 14px; bottom: 14px;
    display: none; padding: 10px 14px;
    border-radius: var(--r-md);
    font-size: 12.5px; color: var(--cream); background: var(--hud);
    box-shadow: inset 0 0 0 1px var(--hud-line);
    pointer-events: none; /* clicks reach the canvas under it (zone points / colour samples at the bottom of the frame) */
  }
  .ed-hint.on { display: block; animation: rise-in var(--dur-2) var(--ease-out) both; }
  .ed-tools { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-4); }
  .zone-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px var(--s-3);
    border-radius: var(--r-md);
    font-size: 13px;
    background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  }
  .zone-row + .zone-row { margin-top: 6px; }
  .zone-row code { font-size: 11.5px; color: var(--fg-2); overflow-wrap: anywhere; }
  .zone-row .grow, .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .zone-row code.grow, code.grow { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  .zone-sw { width: 12px; height: 12px; flex: none; display: inline-block; border-radius: 4px; overflow: hidden; background: var(--surface-3); }
  .zone-sw svg { display: block; width: 100%; height: 100%; }
  .src-group { border-radius: var(--r-lg); background: var(--surface-2); padding: 2px var(--s-4); box-shadow: inset 0 0 0 1px var(--line); }
  .src-group + .src-group { margin-top: var(--s-2); }
  .src-group summary { cursor: pointer; padding: var(--s-3) 0; font-size: 13.5px; font-weight: 500; list-style: none; display: flex; align-items: center; gap: var(--s-2); }
  .src-group summary::-webkit-details-marker { display: none; }
  .src-group summary::after {
    content: ""; margin-inline-start: auto; width: 7px; height: 7px;
    border-inline-end: 1.5px solid var(--fg-2); border-bottom: 1.5px solid var(--fg-2);
    transform: rotate(45deg); transition: transform var(--dur-2) var(--ease-out);
  }
  .src-group[open] summary::after { transform: rotate(-135deg); }
  .src-group .inp { background: var(--field); }
  .src-group .fld { padding-bottom: var(--s-3); }
  .brand-prev { width: 56px; height: 56px; border-radius: var(--r-lg); object-fit: contain; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
}

/* ── pages ────────────────────────────────────────────────────────────────── */
@layer pages {
  /* overview */
  .dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s-4); flex-wrap: wrap; padding-top: var(--s-1); }
  .dash-title { font-weight: 400; font-size: clamp(28px, 3.2vw, 42px); line-height: 1.12; letter-spacing: -.025em; }
  .dash-date { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; margin-top: var(--s-2); font-size: 13px; color: var(--fg-2); }
  .dash-status {
    display: inline-flex; align-items: center; gap: 10px;
    height: 40px; padding: 0 var(--s-4) 0 14px;
    border: 0; border-radius: var(--r-pill); cursor: pointer;
    font-size: 13px; font-weight: 450; color: var(--fg);
    background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line-strong);
    transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-1) ease;
  }
  .dash-status:hover { background: var(--surface-2); }
  .dash-status:active { transform: scale(.98); }
  .dash-status-dot { position: relative; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--fg-3); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sand) 22%, transparent); }
  .dash-status[data-state="live"] .dash-status-dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
  .dash-status[data-state="live"] .dash-status-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--ok); animation: pulse 2.4s var(--ease-out) infinite; }
  .dash-status[data-state="partial"] .dash-status-dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
  .dash-status[data-state="down"] .dash-status-dot { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
  .dash-day { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }
  .dash-trend { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: var(--s-4); }

  .tile { display: flex; flex-direction: column; gap: var(--s-3); min-height: 168px; padding: var(--s-5) var(--s-6) var(--s-6); overflow: hidden; transition: transform var(--dur-3) var(--ease-spring); }
  .tile:hover { transform: translateY(-2px); }
  .tile::before { content: ""; position: absolute; inset-inline: var(--s-6); top: 0; height: 1px; background: var(--brass-line); opacity: 0; transition: opacity var(--dur-2) ease; }
  .tile:hover::before { opacity: .9; }
  .tile-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px var(--s-2); font-size: 12.5px; font-weight: 450; color: var(--fg-2); }
  .tile-v { position: relative; margin-top: auto; display: flex; align-items: flex-end; gap: 10px; min-height: 44px; color: var(--dot); }
  /* a soft glow behind a KPI whose value just changed (js dotNumTo adds .bump) */
  .tile-v::before {
    content: ""; position: absolute; inset: -30% -12% -20%; z-index: -1; pointer-events: none;
    background: radial-gradient(60% 60% at 30% 60%, color-mix(in srgb, var(--brass) 26%, transparent), transparent 70%);
    opacity: 0;
  }
  [dir="rtl"] .tile-v::before { background: radial-gradient(60% 60% at 70% 60%, color-mix(in srgb, var(--brass) 26%, transparent), transparent 70%); }
  .tile-v.bump::before { animation: glow-pulse 1.2s var(--ease-out); }
  .tile-v > span { padding-bottom: 4px; }
  .tile-v > .num { font-size: 14px; color: var(--fg-2); }
  .delta { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-family: var(--font-num); color: var(--fg-2); }
  .delta.up { color: var(--ok-ink); }
  .delta.down { color: var(--bad-ink); }

  /* the queue card: a matte gradient with film grain */
  .mesh {
    position: relative; overflow: hidden; isolation: isolate;
    border: 0; border-radius: var(--r-2xl);
    color: var(--cream); font: inherit; cursor: pointer;
    transition: transform var(--dur-2) var(--ease-out);
  }
  .mesh:hover { transform: translateY(-2px); }
  .mesh:active { transform: translateY(0) scale(.995); }
  .mesh::before { content: ""; position: absolute; inset: -20%; z-index: -3; filter: blur(28px); transition: opacity var(--dur-3) ease; }
  .mesh::after {
    content: ""; position: absolute; inset: 0; z-index: -1; opacity: .22; mix-blend-mode: overlay; pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  }
  .mesh-bloom { position: absolute; inset: 0; z-index: -2; pointer-events: none; background: radial-gradient(70% 50% at 50% 0%, color-mix(in srgb, var(--cream) 28%, transparent), transparent 70%); }
  .mesh-bloom::after { content: ""; position: absolute; inset-inline: 22px; top: 0; height: 1px; background: var(--brass-line); opacity: .8; }
  .queue-ok { box-shadow: 0 30px 50px -30px color-mix(in srgb, var(--olive) 80%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--cream) 10%, transparent); }
  .queue-ok::before {
    background:
      radial-gradient(50% 45% at 20% 80%, color-mix(in srgb, var(--olive) 70%, var(--charcoal)), transparent 70%),
      radial-gradient(55% 50% at 85% 25%, color-mix(in srgb, var(--olive) 55%, var(--sand)), transparent 70%),
      radial-gradient(60% 50% at 55% 55%, var(--olive), transparent 75%),
      color-mix(in srgb, var(--olive) 88%, var(--charcoal));
  }
  .queue-alert { box-shadow: 0 30px 50px -30px color-mix(in srgb, var(--burgundy) 85%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--cream) 10%, transparent); }
  .queue-alert::before {
    background:
      radial-gradient(50% 45% at 20% 80%, color-mix(in srgb, var(--burgundy) 70%, var(--charcoal)), transparent 70%),
      radial-gradient(55% 50% at 85% 25%, color-mix(in srgb, var(--burgundy) 62%, var(--sand)), transparent 70%),
      radial-gradient(60% 50% at 55% 55%, var(--burgundy), transparent 75%),
      color-mix(in srgb, var(--burgundy) 90%, var(--charcoal));
  }
  .mesh-card { display: flex; flex-direction: column; gap: var(--s-3); min-height: 256px; padding: var(--s-6); text-align: start; }
  .mesh-top { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); font-family: var(--font-display); font-size: 15px; font-weight: 500; }
  .mesh-big { margin-top: auto; display: flex; align-items: flex-end; gap: var(--s-3); }
  .mesh-big .dotnum { color: var(--cream); }
  .mesh-big > span:last-child { color: color-mix(in srgb, var(--cream) 82%, transparent); font-size: 14px; padding-bottom: 8px; }
  .mesh-foot { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; }
  .mesh-chip {
    display: inline-flex; align-items: center; height: 26px; padding: 0 11px;
    border-radius: var(--r-pill); font-size: 11.5px; font-weight: 450;
    color: var(--cream); background: color-mix(in srgb, var(--charcoal) 26%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cream) 22%, transparent);
  }
  .mesh-chip:empty { display: none; }

  .minis { display: flex; flex-wrap: wrap; gap: var(--s-2); }
  .minis:empty { display: none; }
  .mini {
    display: inline-flex; align-items: center; gap: var(--s-2);
    height: 38px; padding: 0 var(--s-4);
    border: 0; border-radius: var(--r-pill);
    font-size: 13px; color: var(--fg-2);
    background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  }
  button.mini { cursor: pointer; font: inherit; font-size: 13px; transition: transform var(--dur-1) var(--ease-out), box-shadow var(--dur-1) ease; }
  button.mini:hover { transform: translateY(-1px); box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line-strong); }
  .mini b { font-family: var(--font-num); font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
  .mini-bad b { color: var(--bad-ink); }
  .minis > .empty { flex: 1; }

  /* dotted hourly columns */
  .cols, .cols-x { direction: ltr; }
  .cols { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); align-items: end; gap: 4px; height: 136px; margin-top: var(--s-4); }
  .col { display: flex; flex-direction: column-reverse; align-items: center; gap: 3px; height: 100%; }
  .col i { width: 6px; height: 6px; flex: none; border-radius: 50%; background: color-mix(in srgb, var(--dot) 78%, transparent); transform-origin: bottom; }
  .col.peak i { background: var(--accent); }
  .col.now i:last-child { background: transparent; box-shadow: 0 0 0 1.5px var(--accent); }
  .cols-x {
    display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 4px;
    margin-top: 10px; padding-top: var(--s-2);
    border-top: 1px solid var(--line);
    font-size: 10px; text-align: center; color: var(--fg-3); font-family: var(--font-num);
  }

  /* live page */
  .live-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s-5) var(--s-4); align-items: start; }
  /* stage on top, the camera wall right under it, the live side panel beside both */
  #page-live .live-layout { grid-template-areas: "stage side" "wall side"; grid-template-rows: auto 1fr; }
  #page-live .live-layout > #stage { grid-area: stage; }
  #page-live .live-layout > .live-side { grid-area: side; }
  #page-live .live-layout > .live-wall { grid-area: wall; }
  #page-live .wall { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s-3); }
  #lvTables { max-height: 420px; overflow-y: auto; margin-inline: -4px; padding-inline: 4px; }
  .live-side { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }

  /* alerts */
  .alert-row {
    display: grid; grid-template-columns: 58px auto minmax(0, 1fr) auto; align-items: center; gap: var(--s-3);
    padding: 10px var(--s-4) 10px 10px;
    border-radius: var(--r-lg);
    background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
    transition: transform var(--dur-2) var(--ease-out), box-shadow var(--dur-2) ease;
  }
  .alert-row:hover { transform: translateY(-1px); box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line-strong); }
  .alert-row .at { font-family: var(--font-num); font-size: 11.5px; color: var(--fg-2); text-align: center; line-height: 1.35; direction: ltr; font-variant-numeric: tabular-nums; }
  .alert-row .at b { display: block; font-weight: 500; font-size: 15px; color: var(--fg); }
  .alert-ic { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--r-md); color: var(--fg-2); background: var(--neutral-soft); }
  .alert-ic svg { width: 18px; height: 18px; stroke-width: 1.7; }
  .alert-ic.k-uniform, .alert-ic.k-ppe_violation, .alert-ic.k-no_cap, .alert-ic.k-no_gloves, .alert-ic.k-no_apron,
  .alert-ic.k-short_wash, .alert-ic.k-no_handwash, .alert-ic.k-animal, .alert-ic.k-abandoned_bag, .alert-ic.k-after_close_people,
  .alert-ic.k-camera_offline, .alert-ic.k-camera_blocked, .alert-ic.k-occupancy_max { color: var(--bad-ink); background: var(--bad-soft); }
  .alert-ic.k-queue_long, .alert-ic.k-occupancy_warn, .alert-ic.k-bussing, .alert-ic.k-dirty_seat, .alert-ic.k-unattended,
  .alert-ic.k-phone, .alert-ic.k-task_overdue, .alert-ic.k-opened_late, .alert-ic.k-lights_after_close, .alert-ic.k-accuracy_drift,
  .alert-ic.k-satisfaction_drop, .alert-ic.k-checklist_missed, .alert-ic.k-disk_low { color: var(--accent-ink); background: var(--accent-soft); }
  .alert-msg { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .alert-msg p { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
  .alert-msg .chips { gap: 4px; }
  .alert-msg .chip { height: 22px; font-size: 11px; padding: 0 9px; }
  .alert-msg button.chip { height: 26px; }
  .alert-thumb {
    width: 88px; height: 58px; padding: 0; border: 0; overflow: hidden;
    border-radius: var(--r-md); cursor: zoom-in;
    background: var(--stage); box-shadow: inset 0 0 0 1px var(--line);
    transition: transform var(--dur-2) var(--ease-out);
  }
  .alert-thumb:hover { transform: scale(1.03); }
  .alert-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .task-row .alert-ic { width: 36px; height: 36px; }

  /* new-alert cards (alarm.js): a quiet stack at the top corner, above the
     page, under the toast. Critical = burgundy edge + a slow ring that keeps
     asking to be acknowledged; warning = terracotta edge. */
  .apops {
    position: fixed; z-index: 65; top: 76px; inset-inline-end: 24px;
    width: min(380px, calc(100% - 32px));
    display: flex; flex-direction: column; gap: var(--s-2);
    pointer-events: none;
  }
  .apops:empty { display: none; }
  .apop {
    position: relative; isolation: isolate; pointer-events: auto;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: var(--s-3);
    padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-3), inset 0 0 0 1px var(--line-strong);
    overflow: hidden;
  }
  .apop::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--accent); }
  .apop::after { content: ""; position: absolute; inset-inline: 18px; top: 0; height: 1px; background: var(--brass-line); opacity: .8; }
  .apop-critical { box-shadow: var(--shadow-3), inset 0 0 0 1px color-mix(in srgb, var(--burgundy) 45%, transparent); }
  .apop-critical::before { background: var(--bad); }
  [data-theme="dark"] .apop { background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 93%, var(--cream)), var(--surface-2) 46%); }
  .apop .alert-ic { width: 36px; height: 36px; }
  .apop-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .apop-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); flex-wrap: wrap; }
  .apop-top b { font-size: 13.5px; font-weight: 600; }
  .apop-top .chip { height: 22px; font-size: 11px; padding: 0 9px; }
  .apop .alert-msg p { font-size: 13px; line-height: 1.55; }
  .apop-meta { font-size: 11.5px; color: var(--fg-2); }
  .apop-act { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: 2px; }
  .apop-x { width: 28px; height: 28px; margin: -2px; }
  .apop-x svg { width: 14px; height: 14px; }
  .apop-more {
    pointer-events: auto; align-self: flex-end;
    padding: 4px 12px; border-radius: var(--r-pill);
    font-size: 11.5px; color: var(--fg-2); background: var(--surface-2); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  }

  /* staff accountability */
  #spTable { min-width: 0; } /* the wide table scrolls inside its card, never the page */
  .sp-tbl td { white-space: nowrap; }
  .sp-tbl tbody tr[aria-current="true"] { background: var(--accent-soft); }
  .sp-tbl .chip { height: 24px; padding: 0 10px; }
  .sp-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .sp-who > span:last-child { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
  .sp-who b { font-weight: 500; }
  .sp-who small { font-size: 11.5px; color: var(--fg-2); }
  .sp-av { width: 32px; height: 32px; font-size: 13px; color: var(--cream); background: var(--charcoal); box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2.5px var(--brass-soft); }
  [data-theme="dark"] .sp-av { color: var(--charcoal); background: var(--cream); }
  .sp-av-unk, [data-theme="dark"] .sp-av-unk { color: var(--fg-2); background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
  .sp-av svg { width: 16px; height: 16px; stroke-width: 1.8; }
  /* people directory (pages/people.js): the enrolled face crops */
  .sp-av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
  .pp-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: var(--s-3); margin-block: var(--s-3); }
  .pp-photo { position: relative; margin: 0; display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
  .pp-ph { display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; border-radius: var(--r-md); color: var(--fg-2); background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
  .pp-ph img { width: 100%; height: 100%; object-fit: cover; }
  .pp-ph svg { width: 22px; height: 22px; }
  .pp-photo figcaption { font-size: 11.5px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pp-photo .ibtn { position: absolute; inset-block-start: var(--s-1); inset-inline-end: var(--s-1); background: var(--surface); }
  .sp-trend { display: flex; align-items: center; gap: 10px; }
  .spark { display: block; flex: none; direction: ltr; overflow: visible; }
  .spark rect { fill: color-mix(in srgb, var(--sand) 75%, transparent); }
  .spark rect.nil { fill: var(--line-strong); }
  .spark rect.hi { fill: var(--bad); }
  #page-staff .tile-v > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  /* Settings → Account: alert sounds */
  .snd-levels { display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-3); }
  .snd-lvl { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
  .snd-lvl .check { align-items: flex-start; min-width: 0; }
  .snd-lvl .check input { margin-top: 3px; }
  .snd-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .snd-lvl .btn [data-icon] { display: inline-grid; place-items: center; }
  .snd-vol { flex: 1; min-width: 160px; }
  #sndVolumeOut { min-width: 3.5em; text-align: end; }

  /* analytics */
  .heat-wrap {
    position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
    border-radius: var(--r-lg); background: var(--stage);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cream) 8%, transparent);
  }
  .heat-wrap canvas { width: 100%; height: 100%; display: block; }
  .heat-scale { display: flex; align-items: center; gap: 10px; margin-top: var(--s-3); font-size: 11.5px; color: var(--fg-2); direction: ltr; }
  .heat-scale i { flex: 1; max-width: 220px; height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--cream), var(--sand), var(--terracotta)); box-shadow: inset 0 0 0 1px var(--line); }
  .emo { display: grid; grid-template-columns: 26px minmax(0, 1fr) 48px; align-items: center; gap: var(--s-3); font-size: 13px; }
  .emo + .emo { margin-top: var(--s-3); }
  .emo > span:last-child { text-align: end; font-family: var(--font-num); font-variant-numeric: tabular-nums; }

  /* editor */
  .editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--s-4); align-items: start; }
}

/* ── utilities (last: they win over components without !important) ──────── */
@layer utilities {
  .hidden { display: none; }
  .role-viewer .admin-only { display: none; }
  .muted { color: var(--fg-2); }
  button.chip[aria-pressed="true"] .muted { color: inherit; opacity: .78; }
  .mt-s { margin-top: var(--s-2); }
  .mt-m { margin-top: var(--s-3); }
  .mt-l { margin-top: var(--s-4); }
  .card.narrow-s { max-width: 580px; }
  .card.narrow-l { max-width: 760px; }
  .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; }
}

/* ── responsive ───────────────────────────────────────────────────────────── */
@layer layout {
  @media (max-width: 1279.98px) {
    /* collapsed icon rail */
    .rail { width: 76px; padding-inline: 10px; align-items: stretch; }
    .rail-brand { justify-content: center; padding-inline: 0; }
    .rail-brand-txt, .rail-me-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .rail-row { justify-content: center; padding: 0; }
    .rail-row > span:not(.rail-ic):not(.rail-count) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .rail-count { position: absolute; top: 3px; inset-inline-end: 3px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 9.5px; }
    .rail-me { justify-content: center; padding: 6px; background: transparent; box-shadow: none; }
    #railConn .rail-count { display: none; }
  }
  @media (max-width: 1023.98px) {
    .rail { display: none; }
    .mbar-wrap { display: flex; }
    .net-chip[data-state="ok"] { display: inline-flex; }
    .main { padding: var(--s-4) var(--s-5) calc(7rem + env(safe-area-inset-bottom, 0px)); }
    /* a short screen (phone on its side): the stage never runs under the dock */
    #stage:not(:fullscreen) { max-height: calc(100svh - 8.5rem - env(safe-area-inset-bottom, 0px)); }
    .topbar { padding: var(--s-3) var(--s-4) var(--s-1); }
    .navpills { padding: var(--s-2) var(--s-4) var(--s-3); }
  }
  @media (max-width: 600px) {
    .main { padding-inline: var(--s-4); }
    .topbar { gap: 6px; }
    .topbar-title { flex: 1 1 100%; }
    .topbar-spacer { display: none; }
    .topbar-title h1 { font-size: 17px; }
    .topbar .inp-sm { min-height: 36px; padding: 4px 10px; max-width: 150px; }
    .topbar .ibtn { width: 36px; height: 36px; }
  }
}
@layer components {
  @media (max-width: 600px) {
    .card { padding: var(--s-4) 18px; border-radius: var(--r-lg); }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .grid-2 > .fld + .fld { margin-top: var(--s-3); }
    .wall { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .wall-tile .vid-title small, .wall-tile .hud-chip.opt { display: none; }
    .wall-tile .vid-foot { inset-inline: 8px; bottom: 7px; }
    .wall-tile .vid-title { font-size: 11.5px; }
    .row { flex-wrap: wrap; row-gap: 10px; }
    .row .row-main { flex-basis: calc(100% - 56px); }
    .big { font-size: 30px; }
    .vid-hud { inset-inline: 10px; top: 10px; gap: 4px; }
    .vid-foot { inset-inline: 10px; bottom: 10px; gap: 4px; }
    .hud-chip { height: 26px; padding: 0 9px; font-size: 11px; }
    /* the stage runs edge to edge; the HUD keeps to two quiet groups */
    #page-live .live-layout > #stage { width: auto; margin-inline: calc(var(--s-4) * -1); border-radius: 0; box-shadow: none; }
    #stage::after { border-radius: 0; }
    #stageFps { display: none; }
    #stage .ibtn-hud { width: 32px; height: 32px; }
    #stage .hud-group { gap: 0; padding: 2px; }
    #stage .vid-hud { row-gap: 6px; }
    .stat-trio > div { padding: var(--s-3); }
    .utabs { margin-inline: calc(var(--s-4) * -1); border-radius: 0; box-shadow: none; padding-inline: var(--s-4); }
  }
}
@layer pages {
  @media (max-width: 1180px) {
    .live-layout, .editor, .dash-trend { grid-template-columns: minmax(0, 1fr); }
    #page-live .live-layout { grid-template-areas: "stage" "side" "wall"; grid-template-rows: none; }
  }
  @media (max-width: 1023.98px) {
    .dash-day { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (max-width: 600px) {
    .dash-day { gap: 10px; }
    .tile { min-height: 140px; padding: var(--s-4); }
    .tile-v { min-height: 36px; }
    .alert-row { grid-template-columns: 48px minmax(0, 1fr) auto; padding-inline-end: 10px; }
    .alert-row .alert-ic { display: none; }
    .alert-thumb { width: 72px; height: 48px; }
    .apops { top: calc(env(safe-area-inset-top, 0px) + 10px); inset-inline: 12px; width: auto; }
    .apop { grid-template-columns: minmax(0, 1fr) auto; padding-inline-start: var(--s-3); }
    .apop .alert-ic { display: none; }
    .stage-legend { display: none; }
    .stage-legend-m { display: flex; }
    .stage-legend-m .lg { background-color: var(--stage); } /* the swatch sits on the stage's charcoal, like the boxes */
    .snd-lvl { flex-wrap: wrap; }
    .cols { gap: 2px; height: 112px; }
    .col i { width: 4px; height: 4px; }
    .cols-x { gap: 2px; }
    .mesh-card { min-height: 210px; padding: 20px; }
    .dash-status { height: 36px; font-size: 12.5px; }
  }
}

/* ── motion ───────────────────────────────────────────────────────────────── */
@layer motion {
  @keyframes page-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  @keyframes rise-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes pop-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
  @keyframes stage-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  @keyframes pulse { 0% { transform: scale(1); opacity: .6; } 80%, 100% { transform: scale(3); opacity: 0; } }
  @keyframes shimmer { to { transform: translateX(100%); } }
  @keyframes btn-shimmer { from { transform: translateX(-110%); } to { transform: translateX(110%); } }
  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes dock-in { from { opacity: 0; transform: scale(.86); } to { opacity: 1; transform: none; } }
  @keyframes ripple { 0% { opacity: .9; transform: scale(.2); } 100% { opacity: 0; transform: scale(1); } }
  @keyframes tick-in { from { opacity: 0; transform: rotate(45deg) scale(.3); } to { opacity: 1; transform: rotate(45deg) scale(1); } }
  @keyframes glow-pulse { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
  @keyframes bar-in { from { transform: scaleY(0); } to { transform: scaleY(1); } }
  @keyframes line-draw { to { stroke-dashoffset: 0; } }
  @keyframes badge-pop { 0% { transform: scale(.4); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
  @keyframes tab-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
  @keyframes tab-in-rtl { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
  @keyframes alarm-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--burgundy) 45%, transparent); } 70%, 100% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--burgundy) 0%, transparent); } }

  /* page enter: the page slides up and fades in, its blocks follow in turn */
  .page.on { animation: page-in var(--dur-3) var(--ease-out) both; }
  .page.on .pg > * { animation: rise-in var(--dur-4) var(--ease-out) both; }
  .page.on .pg > :nth-child(2) { animation-delay: 50ms; }
  .page.on .pg > :nth-child(3) { animation-delay: 100ms; }
  .page.on .pg > :nth-child(4) { animation-delay: 150ms; }
  .page.on .pg > :nth-child(5) { animation-delay: 200ms; }
  .page.on .pg > :nth-child(6) { animation-delay: 250ms; }
  .page.on .pg > :nth-child(n+7) { animation-delay: 300ms; }
  .page.on .dash-day > * { animation: rise-in var(--dur-4) var(--ease-spring) both; }
  .page.on .dash-day > :nth-child(2) { animation-delay: 70ms; }
  .page.on .dash-day > :nth-child(3) { animation-delay: 140ms; }
  .page.on .dash-day > :nth-child(4) { animation-delay: 210ms; }
  .page.on .wall > * { animation: pop-in var(--dur-4) var(--ease-out) both; }
  .page.on .wall > :nth-child(2) { animation-delay: 40ms; }
  .page.on .wall > :nth-child(3) { animation-delay: 80ms; }
  .page.on .wall > :nth-child(n+4) { animation-delay: 120ms; }
  /* settings: the new tab slides in from the reading direction */
  .tabpane.on { animation: tab-in var(--dur-3) var(--ease-out) both; }
  [dir="rtl"] .tabpane.on { animation-name: tab-in-rtl; }
  .modal[open] { animation: pop-in var(--dur-3) var(--ease-spring) both; }
  .modal[open]::backdrop { animation: fade-in var(--dur-2) ease both; }
  .mbar-btn[aria-current="page"] { animation: dock-in var(--dur-3) var(--ease-spring) both; }
  /* a new alert card slides in; a critical one keeps a slow ring on its icon until acknowledged */
  .apop { animation: rise-in var(--dur-4) var(--ease-spring) both; }
  .apop-critical .alert-ic { animation: alarm-ring 2.4s var(--ease-out) infinite; }

  /* Reduced motion, tiered: movement goes (tier 1), entrances become short
     fades (tier 2), colour/opacity feedback, the busy spinner and the saved
     tick stay (tier 3). */
  @media (prefers-reduced-motion: reduce) {
    .page.on, .page.on .pg > *, .page.on .dash-day > *, .page.on .wall > *, .tabpane.on, [dir="rtl"] .tabpane.on, .modal[open], .label-menu, .ed-hint.on,
    .vid.swap canvas, .vid.has-frame canvas, .mbar-btn[aria-current="page"], .chart-enter .ch-dot, .apop {
      animation: fade-in 150ms ease both;
      animation-delay: 0ms;
    }
    .apop-critical .alert-ic { animation: none; }
    .chart-enter rect, .rail-count.pop, .badge-dot.pop, .utab[aria-selected="true"]::after, .ripple.go, .tile-v.bump::before { animation: none; }
    .chart-enter .ch-line { animation: none; stroke-dashoffset: 0; }
    .btn::before, .btn:hover::before { transform: translateX(-110%); transition: none; }
    .btn[aria-busy="true"]::before { animation: none; }
    .btn.is-done::after { animation: fade-in 150ms ease both; }
    .dot-pulse::after, .dash-status[data-state="live"] .dash-status-dot::after { animation: none; opacity: 0; }
    .skl::after { animation: none; opacity: 0; }
    .rail-ind { transition: opacity var(--dur-1) ease; }
    .btn, .ibtn, .ibtn svg, button.chip, .navpill, .utab, .mbar-btn, .tile, .row, .alert-row, .wall-tile, .mesh, .mini, .dash-status, .alert-thumb {
      transition-property: opacity, background-color, color, box-shadow;
    }
    .btn:hover, .btn:active, .ibtn:hover, .ibtn:active, .ibtn:hover svg, button.chip:hover, button.chip:active, .navpill:hover, .navpill:active,
    .utab:active, .mbar-btn:active, .tile:hover, .list > .row:hover, .alert-row:hover, .wall-tile:hover, .wall-tile:active,
    .mesh:hover, .mesh:active, button.mini:hover, .dash-status:active, .alert-thumb:hover { transform: none; }
    .toast { transition: opacity var(--dur-2) ease; }
    .bar rect { transition: none; }
    html:focus-within { scroll-behavior: auto; }
  }
}
