/* CORSnet application stylesheet (ux-design section 2).
 *
 * Load order: butterpaper-tokens.css defines --bp-* per theme first; this file maps those to
 * the semantic --a-* roles and styles every component. Components never read --bp-*
 * directly, so a theme is a palette swap and nothing else.
 *
 * Design intent (UniFi-class): calm neutral surfaces, hairline borders instead of shadows,
 * and colour reserved for state. Status is "quiet when fine, loud when not": healthy things
 * are a small dot and a word; only warn/bad earn a coloured edge. Every status carries a
 * text label as well as colour, so nothing depends on hue alone.
 *
 * Contrast is audited, not assumed: tools/contrast_audit.py computes every text/background
 * pair in all themes (WCAG AA: 4.5:1 text, 3:1 UI glyphs and control boundaries) and the
 * dev gallery (wireframes/gallery.html) prints the results.
 *
 * Sections: 1 tokens, 2 base, 3 shell, 4 auth layout, 5 status primitives, 6 content
 * components, 7 forms and buttons, 8 overlays, 9 responsive, 10 motion and forced colours. */

/* ================================================================ 1. tokens (2.2-2.4) */

/* `.a-scope` repeats the token layer on any element so the dev gallery can show several
 * themes on one page. Real pages never use it; they theme <html data-theme>. */
:root,
.a-scope {
  /* surfaces */
  --a-bg:            var(--bp-bg);
  --a-side:          var(--bp-side);
  --a-panel:         var(--bp-panel);
  --a-raised:        var(--bp-raised);
  --a-selected:      var(--bp-selected);
  --a-border:        var(--bp-border);
  --a-border-strong: var(--bp-control-border, var(--bp-border));

  /* text */
  --a-text:   var(--bp-text);
  --a-text-2: var(--bp-secondary);
  /* The muted ink of the canonical palettes misses AA by a hair on the sidebar grounds
   * (e.g. Light's #6A6E79 on #E0E1E9); a 15% pull toward the body ink fixes that and only
   * raises contrast everywhere else. */
  --a-text-3: color-mix(in srgb, var(--bp-muted) 85%, var(--bp-text));

  /* action */
  --a-accent:       var(--bp-accent);
  --a-accent-hover: var(--bp-accent-hover);
  --a-accent-tint:  var(--bp-accent-tint);
  --a-accent-ink:   var(--bp-accent-tint-ink, var(--bp-text));
  --a-on-accent:    var(--bp-on-accent);
  /* links: the palette's link colour is distinct from the button/primary accent
   * (docs.igage.com: #045d99 on light grounds, #019aeb on dark ones) */
  --a-link:       var(--bp-link, var(--a-accent));
  --a-link-hover: var(--bp-link-hover, var(--a-accent-hover));
  /* the top bar carries the brand navy in every colourway */
  --a-header:      var(--bp-header, #1E3A5F);
  --a-header-text: var(--bp-header-text, #FFFFFF);

  /* status - five roles, each with an ink and a tint */
  --a-ok:      var(--bp-success);
  --a-warn:    var(--bp-warning);
  --a-bad:     var(--bp-danger);
  --a-info:    var(--a-info-theme);
  --a-neutral: var(--bp-muted);
  --a-ok-tint:      color-mix(in srgb, var(--a-ok) 14%, var(--a-panel));
  --a-warn-tint:    color-mix(in srgb, var(--a-warn) 16%, var(--a-panel));
  --a-bad-tint:     color-mix(in srgb, var(--a-bad) 14%, var(--a-panel));
  --a-info-tint:    color-mix(in srgb, var(--a-info) 14%, var(--a-panel));
  --a-neutral-tint: color-mix(in srgb, var(--a-neutral) 12%, var(--a-panel));

  /* data visualisation: four constellation colours, theme-aware */
  --a-gps: var(--a-accent);
  --a-glo: var(--bp-chart);
  --a-gal: var(--a-ok);
  --a-bds: var(--a-info);

  --a-focus: var(--a-accent);

  /* typography (2.3) */
  --a-font:      system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --a-font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --a-fs-11: 11px; --a-fs-12: 12px; --a-fs-13: 13px; --a-fs-14: 14px;
  --a-fs-16: 16px; --a-fs-20: 20px; --a-fs-24: 24px; --a-fs-32: 32px;
  --a-lh: 1.45;

  /* spacing, radius, elevation, motion (2.4) */
  --a-s-1: 4px;  --a-s-2: 8px;  --a-s-3: 12px; --a-s-4: 16px;
  --a-s-5: 20px; --a-s-6: 24px; --a-s-8: 32px; --a-s-10: 40px;
  --a-r-1: 6px; --a-r-2: 10px; --a-r-pill: 999px;
  --a-shadow-2: 0 4px 16px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --a-dur: 160ms; --a-ease: cubic-bezier(.2,.7,.2,1);

  /* shell metrics (2.7) */
  --a-side-w: 240px; --a-rail-w: 64px; --a-topbar-h: 56px;

  /* control heights; the coarse-pointer block below raises them to 44px */
  --a-ctl-h: 36px;
  --a-ctl-h-sm: 28px;
}

/* Per-theme additions the shared ButterPaper palette does not carry.
 *   --a-info-theme  info is a hue distinct from the accent AND from ok. Light themes use
 *                   the palette's chapter blue (#1273B1); the dark themes its night
 *                   counterpart (#7DA4C0). Neither sits near the success green, so ok and
 *                   info (and the Galileo and BeiDou constellation colours) stay distinct.
 *   --a-on-bad      ink on a SOLID --a-bad fill (confirm dialog). Light themes use white;
 *                   dark themes have a light --bp-danger so they need dark ink (the
 *                   upstream palette says: do not use white text on the red). */
:root                      { --a-info-theme: #1273B1; --a-on-bad: #FFFFFF; --a-bad-ink: #AB1F26; }
[data-theme="light"]       { --a-info-theme: #1273B1; --a-on-bad: #FFFFFF; --a-bad-ink: #AB1F26; }
[data-theme="paper"]       { --a-info-theme: #1273B1; --a-on-bad: #FFFFFF; --a-bad-ink: #AB1F26; }
/* Dark themes: the palette's red is tuned to 4.5:1 on the card ground; error text and
 * the danger button also sit on the lighter raised/selected grounds, so their ink takes
 * an 80% white mix of the same red (analogous to the palette's own red lightening). */
[data-theme="desert"]      { --a-info-theme: #7DA4C0; --a-on-bad: #260E15; --a-bad-ink: #F18685; }
[data-theme="nordic"]      { --a-info-theme: #7DA4C0; --a-on-bad: #260E15; --a-bad-ink: #F18685; }

/* Frame colours. NAD83(2011) is the theme's accent, solid; ITRF2020 is one violet per ground,
 * away from the accent and every status hue; NATRF2022 has no colour of its own. A frame is a
 * choice, not a verdict. Registered as colours so a read of the token gives the colour it
 * resolves to, which is what the contrast checks compare against the fill. */
@property --a-frame-nad83 { syntax: '<color>'; inherits: true; initial-value: transparent; }
@property --a-frame-itrf-tint { syntax: '<color>'; inherits: true; initial-value: transparent; }
:root,
[data-theme="light"],
[data-theme="paper"] {
  --a-frame-nad83: var(--a-accent);
  --a-frame-nad83-ink: var(--a-on-accent);
  --a-frame-nad83-edge: var(--a-frame-nad83);
  --a-frame-itrf: #5B3FA3;
  --a-frame-itrf-ink: #5B3FA3;
  --a-frame-itrf-edge: #9176DC; /* 3.2:1 against the NAD83 edge, 3.5:1 or more against the panel */
  --a-frame-itrf-tint: color-mix(in srgb, var(--a-frame-itrf) 12%, var(--a-panel));
}
/* On a dark panel no violet is 3:1 from the bright accent and from the panel, so the two block
 * edges part in both directions: NAD83 steps toward the panel, ITRF up to its ink. The 75% is the
 * band that holds 3:1 against the panel and against that ink on both dark panels. */
[data-theme="desert"],
[data-theme="nordic"] {
  --a-frame-nad83: var(--a-accent);
  --a-frame-nad83-ink: var(--a-on-accent);
  --a-frame-nad83-edge: color-mix(in srgb, var(--a-frame-nad83) 75%, var(--a-panel));
  --a-frame-itrf: #B79CF2;
  --a-frame-itrf-ink: #E3D8FB;
  --a-frame-itrf-edge: var(--a-frame-itrf-ink);
  --a-frame-itrf-tint: color-mix(in srgb, var(--a-frame-itrf) 12%, var(--a-panel));
}
/* The USGS topo recedes so the markers stand out; slippymap.css applies this to the tile layer
 * alone. The light themes pale it, the dark themes settle it toward the page. A filter, because
 * opacity would blend the tile into the map's ocean tone. */
[data-theme="light"], [data-theme="paper"]   { --slippy-tile-fade: saturate(.55) contrast(.78) brightness(1.06); }
[data-theme="desert"], [data-theme="nordic"] { --slippy-tile-fade: saturate(.5) contrast(.8) brightness(.84); }

/* ======================================================= 1a. canonical colourways
 *
 * The four CORSnet colourways, mapped token-for-token from the canonical docs.igage.com
 * palette (docs_colorways.json v3, Modus-derived, iGage header navy #1E3A5F kept as the
 * brand anchor). These blocks come AFTER the imported ButterPaper palettes and override
 * them for real pages, so the app - not the vendored upstream file - owns what ships.
 *
 * The palette JSON key -> token mapping, identical for every colourway:
 *   surfaces.page_bg   -> --bp-bg          (the page background)
 *   surfaces.panel     -> --bp-side        (the sidebar/secondary chrome ground)
 *   surfaces.card      -> --bp-panel       (cards; --a-panel)
 *   surfaces.raised    -> --bp-raised
 *   surfaces.selected  -> --bp-selected
 *   surfaces.header    -> --bp-header      (the top bar; --a-header)
 *   surfaces.header_text -> --bp-header-text (--a-header-text)
 *   surfaces.text      -> --bp-text
 *   surfaces.secondary -> --bp-secondary
 *   surfaces.muted     -> --bp-muted
 *   surfaces.border    -> --bp-border and --bp-control-border
 *   accents.button     -> --bp-accent      (== primary; --a-accent)
 *   accents.button_hover -> --bp-accent-hover
 *   accents.on_button  -> --bp-on-accent
 *   accents.primary_tint -> --bp-accent-tint
 *   accents.primary_ink  -> --bp-accent-tint-ink
 *   accents.link       -> --bp-link        (--a-link)
 *   accents.link_hover -> --bp-link-hover
 *   accents.chapter    -> --bp-chart       (the second data-viz hue)
 *   accents.positive   -> --bp-success     (--a-ok; the GREEN status bucket)
 *   accents.warning    -> --bp-warning     (--a-warn; the YELLOW status bucket)
 *   accents.negative   -> --bp-danger      (--a-bad; the RED status bucket)
 *
 * The Gray colourway is retired: it was CORSnet's invented monochrome review mode, and
 * `light` (the docs' first colourway) takes its place in the cycle. */

html[data-theme="light"], .a-scope[data-theme="light"] {
  --bp-bg: #F1F1F6;
  --bp-side: #E0E1E9;
  --bp-panel: #FFFFFF;
  --bp-raised: #FFFFFF;
  --bp-selected: #E9EAF0;
  --bp-border: #CBCDD6;
  /* Hairline borders stay the palette's border colour; control boundaries (inputs,
   * choice cards) need 3:1, so they take the palette's muted step. */
  --bp-control-border: #6A6E79;
  --bp-header: #1E3A5F;
  --bp-header-text: #FFFFFF;
  --bp-text: #252A2E;
  --bp-secondary: #585C65;
  --bp-muted: #6A6E79;
  --bp-accent: #1E3A5F;
  --bp-accent-hover: #0E416C;
  --bp-accent-tint: #DCEDF9;
  --bp-accent-tint-ink: #0E416C;
  --bp-on-accent: #FFFFFF;
  --bp-link: #045D99;
  --bp-link-hover: #0E416C;
  --bp-chart: #1273B1;
  --bp-success: #006638;
  --bp-warning: #9A5B00;
  --bp-danger: #AB1F26;
  color-scheme: light;
}

html[data-theme="paper"], .a-scope[data-theme="paper"] {
  --bp-bg: #FFF7E0;
  --bp-side: #FAF3D9;
  --bp-panel: #FFFBEB;
  --bp-raised: #FFFFFF;
  --bp-selected: #FFF4C9;
  --bp-border: #D7CEB5;
  --bp-control-border: #6B6250;
  --bp-header: #1E3A5F;
  --bp-header-text: #FFFFFF;
  --bp-text: #2B2417;
  --bp-secondary: #5F5747;
  --bp-muted: #6B6250;
  --bp-accent: #1E3A5F;
  --bp-accent-hover: #0E416C;
  --bp-accent-tint: #DCEDF9;
  --bp-accent-tint-ink: #0E416C;
  --bp-on-accent: #FFFFFF;
  --bp-link: #045D99;
  --bp-link-hover: #0E416C;
  --bp-chart: #1273B1;
  --bp-success: #006638;
  --bp-warning: #9A5B00;
  --bp-danger: #AB1F26;
  color-scheme: light;
}

html[data-theme="desert"], .a-scope[data-theme="desert"] {
  --bp-bg: #181716;
  --bp-side: #262523;
  --bp-panel: #201F1D;
  --bp-raised: #2D2B29;
  --bp-selected: #35332F;
  --bp-border: #3A3834;
  --bp-control-border: #A39D94;
  --bp-header: #1E3A5F;
  --bp-header-text: #ECE9E4;
  --bp-text: #ECE9E4;
  --bp-secondary: #C0BAB2;
  --bp-muted: #A39D94;
  --bp-accent: #019AEB;
  --bp-accent-hover: #4DB8F0;
  --bp-accent-tint: #0F2537;
  --bp-accent-tint-ink: #DCEDF9;
  --bp-on-accent: #171C1E;
  --bp-link: #019AEB;
  --bp-link-hover: #4DB8F0;
  --bp-chart: #7DA4C0;
  --bp-success: #70A971;
  --bp-warning: #FEC157;
  --bp-danger: #EE6867;
  color-scheme: dark;
}

html[data-theme="nordic"], .a-scope[data-theme="nordic"] {
  --bp-bg: #171C1E;
  --bp-side: #252A2E;
  --bp-panel: #252A2E;
  --bp-raised: #2B3034;
  --bp-selected: #353A40;
  --bp-border: #353A40;
  --bp-control-border: #A3A6B1;
  --bp-header: #1E3A5F;
  --bp-header-text: #F1F1F6;
  --bp-text: #F1F1F6;
  --bp-secondary: #B7B9C3;
  --bp-muted: #A3A6B1;
  --bp-accent: #019AEB;
  --bp-accent-hover: #4DB8F0;
  --bp-accent-tint: #0F2537;
  --bp-accent-tint-ink: #DCEDF9;
  --bp-on-accent: #171C1E;
  --bp-link: #019AEB;
  --bp-link-hover: #4DB8F0;
  --bp-chart: #7DA4C0;
  --bp-success: #70A971;
  --bp-warning: #FEC157;
  --bp-danger: #EE6867;
  color-scheme: dark;
}

/* Shared status icon (section 5): the green/yellow/red buckets of core::status. Elements
 * with data-bucket paint any .status-ic inside them; the map markers carry the class
 * directly and are coloured by pages/network.css with the same tokens. */
.status-ic { color: var(--a-neutral); }
[data-bucket="green"] .status-ic  { color: var(--a-ok); }
[data-bucket="yellow"] .status-ic { color: var(--a-warn); }
[data-bucket="red"] .status-ic    { color: var(--a-bad); }

/* System theme (2.2): the server renders data-theme="paper" plus data-theme-mode="system";
 * under a dark OS preference the Nordic palette is re-declared here. No script involved.
 * Keep these values identical to the Nordic block in vendor/butterpaper (the contrast audit
 * reads this block and checks it as the "system (dark)" theme). */
@media (prefers-color-scheme: dark) {
  html[data-theme-mode="system"][data-theme="paper"],
  .a-scope[data-theme-mode="system"][data-theme="paper"] {
    --bp-bg: #171C1E;
    --bp-side: #252A2E;
    --bp-panel: #252A2E;
    --bp-raised: #2B3034;
    --bp-selected: #353A40;
    --bp-border: #353A40;
    --bp-control-border: #A3A6B1;
    --bp-header: #1E3A5F;
    --bp-header-text: #F1F1F6;
    --bp-text: #F1F1F6;
    --bp-secondary: #B7B9C3;
    --bp-muted: #A3A6B1;
    --bp-accent: #019AEB;
    --bp-accent-hover: #4DB8F0;
    --bp-accent-tint: #0F2537;
    --bp-accent-tint-ink: #DCEDF9;
    --bp-success: #70A971;
    --bp-warning: #FEC157;
    --bp-danger: #EE6867;
    --bp-chart: #7DA4C0;
    --bp-on-accent: #171C1E;
    --a-info-theme: #7DA4C0;
    --a-on-bad: #260E15;
    --a-bad-ink: #F18685;
    --a-frame-nad83-edge: color-mix(in srgb, var(--a-frame-nad83) 75%, var(--a-panel));
    --a-frame-itrf: #B79CF2;
    --a-frame-itrf-ink: #E3D8FB;
    --a-frame-itrf-edge: var(--a-frame-itrf-ink);
    --slippy-tile-fade: saturate(.5) contrast(.8) brightness(.84);
    color-scheme: dark;
  }
}

/* ================================================================ 2. base */

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--a-bg);
  /* an anchor or focused element must not land under the sticky top bar */
  scroll-padding-top: calc(var(--a-topbar-h) + var(--a-s-4));
}

body {
  margin: 0;
  font-family: var(--a-font);
  font-size: var(--a-fs-14);
  line-height: var(--a-lh);
  color: var(--a-text);
  background: var(--a-bg);
  -webkit-font-smoothing: antialiased;
}

.a-scope { background: var(--a-bg); color: var(--a-text); }

[hidden] { display: none !important; }

a { color: var(--a-link); text-decoration: none; }
a:hover { color: var(--a-link-hover); text-decoration: underline; }
/* links inside running copy are always underlined (2.3) */
p a, dd a, .hint a, .error a, .banner a { text-decoration: underline; text-underline-offset: 2px; }
/* inside a banner the link takes the body ink: accent on a warn tint misses AA in dark themes */
.banner a { color: var(--a-text); font-weight: 600; }

:focus-visible { outline: 2px solid var(--a-focus); outline-offset: 2px; }

h1 { font-size: var(--a-fs-20); font-weight: 600; margin: 0; line-height: 1.3; }
h2 { font-size: var(--a-fs-16); font-weight: 600; margin: 0; line-height: 1.35; }
h3 { font-size: var(--a-fs-12); font-weight: 600; color: var(--a-text-2); letter-spacing: .02em; margin: 0; }

code, .mono { font-family: var(--a-font-mono); font-size: var(--a-fs-13); }
[data-live], .num { font-variant-numeric: tabular-nums; }
/* a live value the page has stopped trusting (4.4) */
[data-frozen] { color: var(--a-text-3); }

.skip-link {
  position: absolute;
  left: -999px;
  top: var(--a-s-2);
  padding: var(--a-s-2) var(--a-s-3);
  /* The colourway's text token, not the inherited link colour: Nordic's accent on its raised
   * surface measured 4.33:1 (U-11). */
  color: var(--a-text);
  background: var(--a-raised);
  border: 1px solid var(--a-border-strong);
  border-radius: var(--a-r-1);
  z-index: 50;
}
.skip-link:focus { left: var(--a-s-2); }

/* The sprite icon: stroke-only, currentColor, 20 x 20 viewBox (2.5). Stroke lives here, not
 * in the sprite, so one rule restyles every icon. */
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon.lg { width: 32px; height: 32px; stroke-width: 1.25; }

/* ================================================================ 3. shell (2.7, 2.9) */

/* The top bar is sticky inside a grid area that spans the whole column, so it really sticks
 * (a sticky box cannot leave its own grid area). It overlays the first --a-topbar-h of the
 * content area, which reserves that space with padding-top. */
body.app {
  display: grid;
  grid-template-columns: var(--a-side-w) minmax(0, 1fr);
  grid-template-rows: var(--a-topbar-h) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.side {
  grid-column: 1; grid-row: 1 / -1;
  position: sticky; top: 0; align-self: start;
  height: 100vh; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--a-s-3);
  padding: 0 var(--a-s-3) var(--a-s-3);
  background: var(--a-side);
  border-right: 1px solid var(--a-border);
  z-index: 6;
}
.side-brand {
  display: flex; align-items: center; gap: var(--a-s-2);
  flex: none; height: var(--a-topbar-h);
  margin: 0 calc(-1 * var(--a-s-3)); padding: 0 var(--a-s-5);
  border-bottom: 1px solid var(--a-border);
}
.side-mark { width: 24px; height: 24px; border-radius: 6px; }
.side-brand-name { font-size: var(--a-fs-16); font-weight: 600; letter-spacing: -.005em; }

.side-account {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--a-s-2);
  padding: var(--a-s-1) var(--a-s-3) var(--a-s-3);
  border-bottom: 1px solid var(--a-border);
}
.side-account-name { font-size: var(--a-fs-13); font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.side-person-name { flex-basis: 100%; font-size: var(--a-fs-12); color: var(--a-text-3); overflow-wrap: anywhere; }
.side-footer {
  margin-top: auto; display: flex; gap: var(--a-s-3);
  padding: var(--a-s-2) var(--a-s-3) 0;
  font-size: var(--a-fs-12); color: var(--a-text-3);
}

.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--a-s-1); }
.nav-group-label {
  margin: var(--a-s-2) 0 calc(-1 * var(--a-s-2)); padding: 0 var(--a-s-3);
  font-size: var(--a-fs-12); font-weight: 600; color: var(--a-text-3); letter-spacing: .02em;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: var(--a-ctl-h); padding: 0 var(--a-s-3);
  border-radius: var(--a-r-2);
  font-size: var(--a-fs-13); font-weight: 500;
  color: var(--a-text-2); text-decoration: none;
  position: relative;
  transition: background var(--a-dur) var(--a-ease), color var(--a-dur) var(--a-ease);
}
.nav-item:hover { background: var(--a-selected); color: var(--a-text); text-decoration: none; }
.nav-item.active { background: var(--a-selected); color: var(--a-text); }
.nav-item.active .icon { color: var(--a-accent); }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 7px; bottom: 7px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--a-accent);
}

.topbar {
  grid-column: 2; grid-row: 1 / -1;
  position: sticky; top: 0; align-self: start; z-index: 5;
  height: var(--a-topbar-h); min-width: 0;
  display: flex; align-items: center; gap: var(--a-s-4);
  padding: 0 var(--a-s-6);
  /* The brand surface: the docs palette's header/header_text in every colourway. */
  background: var(--a-header);
  color: var(--a-header-text);
  border-bottom: 1px solid var(--a-border);
}
/* Everything floating out of the top bar (the user menu panel) returns to the body ink;
 * only the bar's own chrome carries the header ink. */
.topbar .menu-panel { color: var(--a-text); }
.topbar .menu-panel .menu-item { color: var(--a-text); }
.topbar .live-indicator { color: var(--a-header-text); }
/* Hover/open affordances on the navy bar: a translucent ink wash instead of the light
 * --a-selected, which would swallow the white header ink. */
.topbar .theme-cycle-btn { color: var(--a-header-text); }
.topbar .theme-cycle-btn:focus-visible { outline-color: var(--a-header-text); }
.topbar .theme-cycle-btn:hover, .topbar .theme-cycle-btn:focus-visible {
  background: color-mix(in srgb, var(--a-header-text) 16%, transparent);
}
.topbar .user-menu > summary { color: var(--a-header-text); }
.topbar .user-menu > summary:hover, .topbar .menu[open] > summary {
  background: color-mix(in srgb, var(--a-header-text) 16%, transparent);
}
.topbar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-indicator { display: inline-flex; align-items: center; gap: var(--a-s-2); font-size: var(--a-fs-12); color: var(--a-text-2); white-space: nowrap; }

.content {
  grid-column: 2; grid-row: 1 / -1;
  min-width: 0; width: 100%; max-width: 1440px; margin-inline: auto;
  padding: calc(var(--a-topbar-h) + var(--a-s-6)) var(--a-s-6) var(--a-s-8);
  display: flex; flex-direction: column; gap: var(--a-s-4);
}
.content:focus { outline: none; }

/* user menu and the generic <details> menu (2.6 Menu) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary {
  display: inline-flex; align-items: center; gap: var(--a-s-2);
  min-height: var(--a-ctl-h); padding: var(--a-s-1) var(--a-s-2);
  border-radius: var(--a-r-1);
  transition: background var(--a-dur) var(--a-ease);
}
.user-menu > summary:hover, .menu[open] > summary { background: var(--a-selected); }
.user-menu-name { font-size: var(--a-fs-13); font-weight: 500; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: var(--a-r-pill);
  background: var(--a-accent-tint); color: var(--a-accent-ink);
  font-size: var(--a-fs-11); font-weight: 600;
}
/* Appearance quick-cycle (top bar, left of the user menu): an icon-only form button
   styled like the menu summary beside it. The icon inherits the button colour, which is
   the top-bar text ink on both the resting and the hover background, so it keeps AA
   contrast in light and dark themes alike. */
.theme-cycle { display: inline-flex; }
.theme-cycle-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--a-ctl-h); height: var(--a-ctl-h); padding: 0;
  border: 0; border-radius: var(--a-r-1);
  background: none; color: var(--a-text); cursor: pointer;
  transition: background var(--a-dur) var(--a-ease);
}
.theme-cycle-btn:hover, .theme-cycle-btn:focus-visible { background: var(--a-selected); }
.theme-cycle-btn:focus-visible { outline: 2px solid var(--a-focus); outline-offset: 2px; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + var(--a-s-1)); z-index: 20;
  min-width: 190px; padding: var(--a-s-1);
  background: var(--a-raised); border: 1px solid var(--a-border-strong);
  border-radius: var(--a-r-2); box-shadow: var(--a-shadow-2);
  display: flex; flex-direction: column;
}
.menu-item {
  display: flex; align-items: center; gap: var(--a-s-2);
  min-height: var(--a-ctl-h); padding: 0 var(--a-s-3); margin: 0;
  border-radius: var(--a-r-1);
  font-size: var(--a-fs-13); font-weight: 500; color: var(--a-text); text-decoration: none;
}
a.menu-item:hover { background: var(--a-selected); text-decoration: none; }
form.menu-item { padding: 0; }
.menu-item .btn {
  width: 100%; justify-content: flex-start; height: auto; min-height: var(--a-ctl-h);
  padding: 0 var(--a-s-3); color: var(--a-text); font-weight: 500;
}

/* mobile tab bar (2.9); hidden until the phone breakpoint */
.tabbar { display: none; }
.tab-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  flex: 1; min-width: 0; font-size: var(--a-fs-11); font-weight: 500;
  color: var(--a-text-2); text-decoration: none;
}
.tab-item:hover { text-decoration: none; color: var(--a-text); }
.tab-item.active { color: var(--a-accent); }
.tab-item:focus-visible { outline-offset: -4px; border-radius: var(--a-r-2); }

/* ================================================================ 4. auth layout (2.8) */

body.auth { margin: 0; background: var(--a-bg); }
.auth-split { display: grid; grid-template-columns: 44% 56%; min-height: 100vh; min-height: 100dvh; }
.auth-brand {
  display: flex; flex-direction: column; gap: var(--a-s-4);
  padding: var(--a-s-10); background: var(--a-side); border-right: 1px solid var(--a-border);
}
.auth-brand-top { display: flex; align-items: center; gap: var(--a-s-3); }
.auth-mark { width: 40px; height: 40px; border-radius: 10px; }
.auth-brand-name { font-size: var(--a-fs-32); font-weight: 600; letter-spacing: -.01em; line-height: 1.15; }
.auth-brand-value { margin: 0; font-size: var(--a-fs-16); color: var(--a-text-2); max-width: 28ch; }
.auth-brand-fact { margin: auto 0 0; font-size: var(--a-fs-13); color: var(--a-text-3); }
.auth-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--a-s-4); padding: var(--a-s-6); min-width: 0; }
.auth-trouble { margin: 0; max-width: 400px; width: 100%; text-align: center; color: var(--a-text-2); font-size: var(--a-fs-13); }
.auth-panel:focus { outline: none; }
.auth-card { max-width: 400px; width: 100%; padding: var(--a-s-8); display: flex; flex-direction: column; gap: var(--a-s-4); }
.auth-title { margin: 0; font-size: var(--a-fs-20); }
#sign-in-form { display: flex; flex-direction: column; gap: var(--a-s-3); }
.auth-submit, .auth-sso { width: 100%; justify-content: center; gap: var(--a-s-2); }
.auth-forgot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--a-s-2);
  margin: 0; color: var(--a-text-2); font-size: var(--a-fs-13);
}
.auth-or { display: flex; align-items: center; gap: var(--a-s-3); margin: 0; color: var(--a-text-3); font-size: var(--a-fs-13); }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid var(--a-border); }

/* ================================================================ 5. status primitives (2.6) */

/* One tone vocabulary for everything: ok | warn | bad | info | neutral, via data-tone. */

/* status dot: always sits next to a text label */
.dot {
  --dot-c: var(--a-neutral);
  display: inline-block; flex: none; width: 8px; height: 8px;
  border-radius: var(--a-r-pill); background: var(--dot-c);
}
.dot[data-tone="ok"]      { --dot-c: var(--a-ok); }
.dot[data-tone="warn"]    { --dot-c: var(--a-warn); }
.dot[data-tone="bad"]     { --dot-c: var(--a-bad); }
.dot[data-tone="info"]    { --dot-c: var(--a-info); }
.dot[data-tone="neutral"] { --dot-c: var(--a-neutral); }
.dot[data-live] { animation: a-pulse 2s var(--a-ease) infinite; }
@keyframes a-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--dot-c) 45%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* status pill. A pill's tone also tones its dot, so markup cannot disagree with itself. */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; min-width: 84px; padding: 0 9px 0 7px;
  border: 1px solid transparent; border-radius: var(--a-r-pill);
  font-size: var(--a-fs-12); font-weight: 600; line-height: 1; white-space: nowrap;
  color: var(--a-text); background: var(--a-neutral-tint);
}
.pill[data-tone="ok"]      { background: var(--a-ok-tint); }
.pill[data-tone="warn"]    { background: var(--a-warn-tint); }
.pill[data-tone="bad"]     { background: var(--a-bad-tint); }
.pill[data-tone="info"]    { background: var(--a-info-tint); }
.pill[data-tone="neutral"] { background: transparent; border-color: var(--a-border); }
.pill[data-tone="ok"]   .dot { --dot-c: var(--a-ok); }
.pill[data-tone="warn"] .dot { --dot-c: var(--a-warn); }
.pill[data-tone="bad"]  .dot { --dot-c: var(--a-bad); }
.pill[data-tone="info"] .dot { --dot-c: var(--a-info); }

/* badge: pill without the dot, for TEST, message-set chips and counts */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px; border-radius: var(--a-r-1);
  font-size: var(--a-fs-11); font-weight: 600; line-height: 1; white-space: nowrap;
  color: var(--a-text); background: var(--a-neutral-tint);
  font-variant-numeric: tabular-nums;
}
.badge[data-tone="ok"]      { background: var(--a-ok-tint); }
.badge[data-tone="warn"]    { background: var(--a-warn-tint); }
.badge[data-tone="bad"]     { background: var(--a-bad-tint); }
.badge[data-tone="info"]    { background: var(--a-info-tint); }
.badge[data-tone="neutral"] { background: var(--a-neutral-tint); }

/* beta: the one indicator for a feature being tested (templates/_beta.html). Badge-sized, an
 * info outline on the info tint, the word in body text so it reads in every colourway. */
.beta {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: middle;
  height: 20px; padding: 0 6px;
  border: 1px solid var(--a-info); border-radius: var(--a-r-1);
  font-size: var(--a-fs-11); font-weight: 600; line-height: 1; white-space: nowrap;
  letter-spacing: normal; text-transform: none;
  color: var(--a-text); background: var(--a-info-tint);
}
.beta .icon { width: 12px; height: 12px; stroke-width: 1.75; color: var(--a-info); }

/* status tile: the dashboard unit. Quiet when fine; only warn/bad get an edge. */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--a-s-3); }
.tile {
  display: flex; flex-direction: column; gap: var(--a-s-1); min-width: 0;
  min-height: 96px; padding: var(--a-s-4) var(--a-s-5);
  background: var(--a-panel); border: 1px solid var(--a-border); border-radius: var(--a-r-2);
  color: inherit; text-decoration: none;
  transition: background var(--a-dur) var(--a-ease);
}
a.tile:hover { background: var(--a-selected); text-decoration: none; }
/* the 3px edge replaces 2px of padding so the content does not shift when a tile degrades */
.tile[data-tone="warn"] { border-left: 3px solid var(--a-warn); padding-left: calc(var(--a-s-5) - 2px); }
.tile[data-tone="bad"]  { border-left: 3px solid var(--a-bad);  padding-left: calc(var(--a-s-5) - 2px); }
.tile-label { font-size: var(--a-fs-12); color: var(--a-text-2); }
.tile-value { font-size: var(--a-fs-24); font-weight: 600; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-sub { margin-top: auto; font-size: var(--a-fs-12); color: var(--a-text-3); display: flex; align-items: center; gap: 6px; }

/* ================================================================ 5b. frame language */

/* A frame is a choice, not a verdict: no status hue. Each badge and block carries colour, an icon
   and the frame's name together. Keyed on data-frame-key: nad83 solid, itrf tinted, natrf dashed. */
.frame-badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px 0 6px; border-radius: var(--a-r-1);
  font-size: var(--a-fs-12); font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; color: var(--a-text); background: var(--a-neutral-tint);
}
.frame-badge .icon { width: 14px; height: 14px; flex: none; }
.frame-badge[data-frame-key="nad83"] { background: var(--a-frame-nad83); color: var(--a-frame-nad83-ink); }
.frame-badge[data-frame-key="itrf"]  { background: var(--a-frame-itrf-tint); color: var(--a-frame-itrf-ink); border-color: var(--a-frame-itrf); }
.frame-badge[data-frame-key="natrf"] { background: var(--a-panel); color: var(--a-text-2); border: 1px dashed var(--a-border-strong); }

.frame-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--a-s-4); }
.frame-grid > * { min-width: 0; }
.frame-grid > .frame-block[data-frame-key="natrf"] { grid-column: 1 / -1; }
@media (max-width: 767px) { .frame-grid { grid-template-columns: minmax(0, 1fr); } }

.frame-block {
  --frame-c: var(--a-border-strong);
  display: flex; flex-direction: column; gap: var(--a-s-3); min-width: 0;
  padding: var(--a-s-3) var(--a-s-4);
  background: var(--a-panel); border: 1px solid var(--a-border); border-left: 3px solid var(--frame-c);
  border-radius: var(--a-r-2);
}
.frame-block[data-frame-key="nad83"] { --frame-c: var(--a-frame-nad83-edge); }
.frame-block[data-frame-key="itrf"]  { --frame-c: var(--a-frame-itrf-edge); }
.frame-block[data-frame-key="natrf"] { border: 1px dashed var(--a-border-strong); }
.frame-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--a-s-2) var(--a-s-3); }
.frame-epoch { font-size: var(--a-fs-12); color: var(--a-text-2); font-variant-numeric: tabular-nums; }
.frame-head .frame-copy { margin-left: auto; }
.frame-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.frame-kv { grid-template-columns: 96px minmax(0, 1fr); }
.frame-kv dd { flex-wrap: wrap; overflow-wrap: anywhere; }
/* The bare name is what pastes into a collector's Mountpoint field: one tap selects exactly it. */
.frame-mount { font-family: var(--a-font-mono); font-size: var(--a-fs-14); font-weight: 600; user-select: all; -webkit-user-select: all; }
.frame-ecef summary { cursor: pointer; font-size: var(--a-fs-13); color: var(--a-accent); min-height: 32px; display: flex; align-items: center; }
.frame-note { margin: 0; font-size: var(--a-fs-13); color: var(--a-text-2); }
.frame-explain { margin: 0 0 var(--a-s-3); font-size: var(--a-fs-13); color: var(--a-text-2); max-width: 72ch; }
/* The Rovers row in a narrow card: the frame on its own line, then the name with its copy button. */
.kv dd[data-frame] { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--a-s-1) var(--a-s-2); }
.kv dd[data-frame] .frame-badge { grid-column: 1 / -1; justify-self: start; }
.help-frames { list-style: none; margin: 0 0 var(--a-s-3); padding: 0; display: flex; flex-direction: column; gap: var(--a-s-2); }

/* Copy: the space is reserved before any script runs, so enabling the button shifts nothing.
   The script marks [data-ready]; [data-copied] is the 1.5 s confirmation (shared contract). */
.frame-copy:not([data-ready]) { visibility: hidden; }
.frame-copy:focus { outline: 2px solid var(--a-focus); outline-offset: 2px; }
.frame-copy[data-copied] { color: var(--a-ok); border-color: var(--a-ok); }
@media (pointer: coarse) { .frame-copy { height: var(--a-ctl-h); } }

@media (forced-colors: active) {
  .frame-badge { border: 1px solid CanvasText; }
  .frame-block { border-left-width: 3px; }
}

/* ================================================================ 6. content components (2.6) */

/* placeholder copy on not-yet-built screens (templates/stub.html); removed when the last
 * stub page is replaced by its real screen */

/* card */
.card { background: var(--a-panel); border: 1px solid var(--a-border); border-radius: var(--a-r-2); padding: var(--a-s-5); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--a-s-3); margin-bottom: var(--a-s-3); }
.card-meta { font-size: var(--a-fs-12); color: var(--a-text-3); display: flex; align-items: center; gap: var(--a-s-2); }
.card-body { display: flex; flex-direction: column; gap: var(--a-s-3); }
.card-body > p { margin: 0; }
.card-body:has(> .field) { gap: var(--a-s-4); }
/* a table card draws its own padding; `clip` rounds the row hover without making the card a
 * scroll container (which would break the sticky header). */
.card-table { padding: 0; overflow: clip; }
.card-table > .card-head { margin: 0; padding: var(--a-s-4) var(--a-s-5) var(--a-s-3); }

/* table */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table thead th {
  height: 36px; padding: 0 var(--a-s-4); text-align: left; white-space: nowrap;
  font-size: var(--a-fs-12); font-weight: 500; color: var(--a-text-2);
  border-bottom: 1px solid var(--a-border);
  position: sticky; top: var(--a-topbar-h); z-index: 1; background: var(--a-panel);
}
.table tbody td { height: 44px; padding: 0 var(--a-s-4); border-bottom: 1px solid var(--a-border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--a-dur) var(--a-ease); }
.table tbody tr.row-link { position: relative; cursor: pointer; }
.table tbody tr.row-link:hover { background: var(--a-selected); }
.col-status { width: 120px; }
.table th.col-num, .table td.col-num, .col-num { text-align: right; font-variant-numeric: tabular-nums; }
/* the first cell's link covers the row: one real link for keyboard and screen readers */
.row-link a::after { content: ""; position: absolute; inset: 0; }
.row-link a:hover { text-decoration: none; }
.row-link a:focus-visible { outline: 2px solid var(--a-focus); outline-offset: 2px; border-radius: 2px; }
.row-link td:has(> a) a { color: var(--a-text); font-weight: 500; }

/* gate rail: Receiving -> Reference position -> Corrections. The connector takes the tone of
 * the gate upstream of it, so a broken gate turns the link after it red. */
.gates { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--a-s-4); }
.gate {
  --gate-c: var(--a-neutral);
  position: relative; min-width: 0;
  display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; row-gap: 2px; align-items: center;
  padding: var(--a-s-4); background: var(--a-panel);
  border: 1px solid var(--a-border); border-radius: var(--a-r-2);
}
.gate[data-tone="ok"]   { --gate-c: var(--a-ok); }
.gate[data-tone="warn"] { --gate-c: var(--a-warn); }
.gate[data-tone="bad"]  { --gate-c: var(--a-bad); }
.gate[data-tone="info"] { --gate-c: var(--a-info); }
.gate[data-tone="warn"], .gate[data-tone="bad"] { border-color: var(--gate-c); }
.gate-dot {
  width: 10px; height: 10px; border-radius: var(--a-r-pill); background: var(--gate-c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gate-c) 22%, transparent);
}
.gate-title { font-size: var(--a-fs-13); font-weight: 600; }
.gate-state { grid-column: 2; font-size: var(--a-fs-13); color: var(--a-text-2); overflow-wrap: anywhere; }
.gate:not(:last-child)::after {
  content: ""; position: absolute; left: 100%; top: 50%;
  width: var(--a-s-4); height: 2px; margin-top: -1px; background: var(--gate-c);
}

/* constellation bar */
.sats { display: flex; flex-direction: column; gap: var(--a-s-2); }
.sats-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--a-selected); }
.sats-bar > span { flex: var(--n, 0); min-width: 0; box-shadow: inset -1px 0 0 var(--a-panel); }
.sats-bar > span:last-child { box-shadow: none; }
.sats-bar > span[data-sys="gps"] { background: var(--a-gps); }
.sats-bar > span[data-sys="glo"] { background: var(--a-glo); }
.sats-bar > span[data-sys="gal"] { background: var(--a-gal); }
.sats-bar > span[data-sys="bds"] { background: var(--a-bds); }
.sats-bar > span[data-sys="qzs"] { background: var(--a-neutral); }
.sats-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--a-s-1) var(--a-s-4); font-size: var(--a-fs-12); color: var(--a-text-2); }
.sats-legend li { display: inline-flex; align-items: center; gap: 6px; }
.sats-legend li::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--a-neutral); flex: none; }
.sats-legend li[data-sys="gps"]::before { background: var(--a-gps); }
.sats-legend li[data-sys="glo"]::before { background: var(--a-glo); }
.sats-legend li[data-sys="gal"]::before { background: var(--a-gal); }
.sats-legend li[data-sys="bds"]::before { background: var(--a-bds); }
.sats-legend b { font-weight: 600; color: var(--a-text); font-variant-numeric: tabular-nums; }
/* a system with zero satellites keeps its legend entry, muted (add .zero or data-zero) */
.sats-legend li.zero, .sats-legend li[data-zero] { opacity: .55; }
.sats-legend li.zero b, .sats-legend li[data-zero] b { color: inherit; }

/* key-value list */
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); margin: 0; }
.kv dt, .kv dd { min-height: 32px; padding: 3px 0; border-bottom: 1px solid color-mix(in srgb, var(--a-border) 55%, transparent); }
.kv dt:nth-last-of-type(1), .kv dd:last-of-type { border-bottom: 0; }
.kv dt { font-size: var(--a-fs-12); color: var(--a-text-2); display: flex; align-items: center; }
.kv dd { margin: 0; font-size: var(--a-fs-14); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: var(--a-s-2); min-width: 0; overflow-wrap: anywhere; }
.kv-mono dd, .kv dd.kv-mono { font-family: var(--a-font-mono); font-size: var(--a-fs-13); }
/* Copy button: hidden until the script that wires it marks it [data-ready] (no JS, no
 * dead button). The script sets [data-copied] for 1.5 s after a successful copy. */
.kv [data-copy]:not([data-ready]):not(.frame-copy) { display: none; }
.kv [data-copy] { margin-left: auto; }
[data-copy][data-copied] { color: var(--a-ok); }

/* banner: in-content notice; the tone is the border and tint, the icon repeats it */
.banner {
  --banner-c: var(--a-border-strong);
  display: flex; align-items: flex-start; gap: var(--a-s-3);
  padding: var(--a-s-3) var(--a-s-4);
  border: 1px solid var(--banner-c); border-radius: var(--a-r-2);
  background: var(--a-neutral-tint); font-size: var(--a-fs-14); color: var(--a-text);
}
p.banner { margin: 0; }
.banner[data-tone="neutral"] { --banner-c: var(--a-neutral); background: var(--a-neutral-tint); }
.banner[data-tone="info"] { --banner-c: var(--a-info); background: var(--a-info-tint); }
.banner[data-tone="warn"] { --banner-c: var(--a-warn); background: var(--a-warn-tint); }
.banner[data-tone="bad"]  { --banner-c: var(--a-bad);  background: var(--a-bad-tint); }
.banner[data-tone="ok"]   { --banner-c: var(--a-ok);   background: var(--a-ok-tint); }
.banner > .icon { margin-top: 1px; color: var(--banner-c); }
.banner[data-tone="neutral"] > .icon, .banner:not([data-tone]) > .icon { color: var(--a-text-2); }
.banner-text { flex: 1; min-width: 0; margin: 0; }
.banner-action { flex: none; margin-left: auto; font-weight: 600; white-space: nowrap; }

/* empty state: one per page */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--a-s-3); padding: var(--a-s-10) var(--a-s-5); text-align: center; }
.empty > .icon { color: var(--a-text-3); }
.empty-title { margin: 0; font-size: var(--a-fs-16); font-weight: 600; }
.empty p { margin: 0; max-width: 46ch; color: var(--a-text-2); }
.empty .btn { margin-top: var(--a-s-1); }

/* skeleton: a quiet block the exact size of the value it replaces; no shimmer on purpose */
.skel { background: var(--a-selected); border-radius: var(--a-r-1); min-height: 1em; }
.skel[data-stale] { color: transparent; }

/* ================================================================ 7. buttons and forms (2.6) */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--a-s-2);
  height: var(--a-ctl-h); padding: 0 14px; border-radius: var(--a-r-1);
  font: inherit; font-size: var(--a-fs-13); font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid var(--a-border-strong); background: var(--a-raised); color: var(--a-text);
  cursor: pointer; text-decoration: none;
  transition: background var(--a-dur) var(--a-ease), border-color var(--a-dur) var(--a-ease);
}
.btn:hover { background: var(--a-selected); text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
/* .btn.secondary is the default look; the class is accepted but needs no rule */
.btn.primary { background: var(--a-accent); color: var(--a-on-accent); border-color: transparent; }
.btn.primary:hover { background: var(--a-accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--a-text-2); }
.btn.ghost:hover { background: var(--a-selected); color: var(--a-text); }
.btn.danger { color: var(--a-bad-ink); }
/* danger turns solid only where the user is confirming the destructive act */
dialog .btn.danger { background: var(--a-bad); color: var(--a-on-bad); border-color: transparent; }
dialog .btn.danger:hover { background: color-mix(in srgb, var(--a-bad) 86%, var(--a-text)); }
.btn.sm { height: var(--a-ctl-h-sm); padding: 0 10px; font-size: var(--a-fs-12); }
.btn.icon-only { width: var(--a-ctl-h); padding: 0; }
.btn.icon-only .icon { width: 20px; height: 20px; }
.btn.icon-only.sm { width: var(--a-ctl-h-sm); }
.btn.icon-only.sm .icon { width: 16px; height: 16px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; pointer-events: none; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > label, .field > legend { font-size: var(--a-fs-13); font-weight: 500; padding: 0; }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), .field select, .field textarea {
  width: 100%; height: var(--a-ctl-h); padding: 0 10px;
  font: inherit; font-size: var(--a-fs-14); color: var(--a-text);
  background: var(--a-raised); border: 1px solid var(--a-border-strong); border-radius: var(--a-r-1);
  transition: border-color var(--a-dur) var(--a-ease);
}
.field textarea { height: auto; min-height: 88px; padding: 8px 10px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--a-text-3); opacity: 1; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { border-color: var(--a-accent); }
.field input:disabled, .field select:disabled, .field textarea:disabled { opacity: .6; cursor: not-allowed; background: var(--a-selected); }
.field [aria-invalid="true"] { border-color: var(--a-bad); }
.field input.mono, .field input[data-mono] { font-family: var(--a-font-mono); font-size: var(--a-fs-13); }
.hint { font-size: var(--a-fs-12); color: var(--a-text-3); margin: 0; }
.error { display: flex; align-items: flex-start; gap: 6px; font-size: var(--a-fs-12); color: var(--a-bad-ink); margin: 0; }
.error::before {
  content: ""; flex: none; width: 14px; height: 14px; margin-top: 1px; background: currentColor;
  -webkit-mask: var(--a-warning-glyph) center / contain no-repeat;
          mask: var(--a-warning-glyph) center / contain no-repeat;
}
.error { --a-warning-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 3.5 17.25 16H2.75ZM10 8.5v3.5M10 14.25h.01'/%3E%3C/svg%3E"); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; }
input, select, textarea { accent-color: var(--a-accent); }

/* choice card: a labelled radio shown as a selectable card (theme, participation) */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--a-s-3); }
.choice {
  display: flex; align-items: flex-start; gap: var(--a-s-3);
  padding: var(--a-s-3) var(--a-s-4); min-width: 0;
  background: var(--a-panel); border: 1px solid var(--a-border-strong); border-radius: var(--a-r-2);
  cursor: pointer;
  transition: background var(--a-dur) var(--a-ease), border-color var(--a-dur) var(--a-ease);
}
.choice:hover { background: var(--a-selected); }
.choice input { margin-top: 2px; }
.choice:has(:checked) { border-color: var(--a-accent); background: var(--a-accent-tint); color: var(--a-accent-ink); }
.choice:has(:focus-visible) { outline: 2px solid var(--a-focus); outline-offset: 2px; }
.choice-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice-title { font-size: var(--a-fs-14); font-weight: 600; }
.choice-desc { font-size: var(--a-fs-12); color: var(--a-text-2); }
.choice:has(:checked) .choice-desc { color: inherit; }

/* ================================================================ 8. overlays (2.6) */

dialog {
  width: calc(100% - 2 * var(--a-s-4)); max-width: 440px;
  padding: var(--a-s-5); color: var(--a-text);
  background: var(--a-raised); border: 1px solid var(--a-border-strong);
  border-radius: var(--a-r-2); box-shadow: var(--a-shadow-2);
}
dialog[open] { animation: a-pop var(--a-dur) var(--a-ease); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog > h2 { margin-bottom: var(--a-s-2); }
dialog > p { margin: 0 0 var(--a-s-4); color: var(--a-text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--a-s-2); margin-top: var(--a-s-5); }
@keyframes a-pop { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }

/* ================================================================ 9. responsive (2.9) */

/* tiles: 4 across, 2 under 1024, 1 under 480 */
@media (max-width: 1023px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* icon rail 768-1199 px: the sidebar collapses to icons; tooltips come from title="" */
@media (max-width: 1199px) {
  body.app { grid-template-columns: var(--a-rail-w) minmax(0, 1fr); }
  .side { padding: 0 var(--a-s-2) var(--a-s-3); align-items: stretch; }
  .side-brand { margin: 0 calc(-1 * var(--a-s-2)); padding: 0; justify-content: center; }
  .nav-label, .side-brand-name, .side-account, .side-footer {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .nav-item { justify-content: center; padding: 0; }
  /* the Admin group heading becomes a hairline divider */
  .nav-group-label { height: 1px; margin: var(--a-s-1) var(--a-s-2); padding: 0; font-size: 0; background: var(--a-border); overflow: hidden; }
  .col-opt { display: none; }
}

/* phone < 768 px: hide the sidebar, pin the tab bar, stack tables into cards */
@media (max-width: 767px) {
  body.app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
  .side { display: none; }
  .topbar, .content { grid-column: 1; }
  .topbar { padding: 0 var(--a-s-4); gap: var(--a-s-3); }
  .live-indicator:not([data-example]):not([data-ended]), .user-menu-name { display: none; }
  /* "You have been signed out" needs the width; the page title would be a sliver beside it. */
  .topbar:has(.live-indicator[data-ended]) .topbar-title { display: none; }
  .content {
    padding: calc(var(--a-topbar-h) + var(--a-s-4)) var(--a-s-4)
             calc(var(--a-topbar-h) + var(--a-s-6) + env(safe-area-inset-bottom));
  }
  .tabbar {
    display: flex; align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
    height: calc(var(--a-topbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--a-side); border-top: 1px solid var(--a-border);
  }
  .card:not(.card-table) { padding: var(--a-s-4); }
  .card-table > .card-head { padding: var(--a-s-4) var(--a-s-4) var(--a-s-3); }

  /* stacked table: each row is a card, the status cell leads, data-label names each field */
  .card-table:has(> .table) { background: transparent; border: 0; overflow: visible; }
  .card-table > .card-head { padding-inline: 0; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table tbody { display: flex; flex-direction: column; gap: var(--a-s-3); }
  .table tbody tr {
    display: flex; flex-direction: column;
    padding: var(--a-s-2) var(--a-s-4);
    background: var(--a-panel); border: 1px solid var(--a-border); border-radius: var(--a-r-2);
  }
  .table tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--a-s-4);
    height: auto; min-height: 36px; padding: 6px 0; border-bottom: 0; text-align: right;
  }
  .table tbody td + td { border-top: 1px solid color-mix(in srgb, var(--a-border) 55%, transparent); }
  .table td[data-label]::before { content: attr(data-label); flex: none; font-size: var(--a-fs-12); color: var(--a-text-2); text-align: left; }
  .table td.col-status { order: -1; justify-content: flex-start; width: auto; }
  /* the status cell and the row's link cell are self-describing: no label, left-aligned */
  .table tr.row-link td:has(> a), .table td.col-status { text-align: left; justify-content: flex-start; }
  .table tr.row-link td:has(> a)::before, .table td.col-status::before { display: none; }
  .row-link td:has(> a) a { font-size: var(--a-fs-16); font-weight: 600; }
  .table td.col-status { border-top: 0; }
  .col-num { text-align: right; }
  .table tbody tr:last-child td { border-bottom: 0; }

  /* gate rail: vertical, connector on the left */
  .gates { grid-template-columns: minmax(0, 1fr); }
  .gate:not(:last-child)::after {
    left: calc(var(--a-s-4) + 4px); top: 100%; width: 2px; height: var(--a-s-4); margin: 0;
  }
}

/* The smallest phones: the title and the Example badge need the room, and the theme button is
   a shortcut; Account keeps the full chooser. */
@media (max-width: 359px) {
  .theme-cycle { display: none; }
  .topbar { gap: var(--a-s-2); }
}

@media (max-width: 899px) {
  .auth-split { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { flex-direction: row; align-items: center; padding: var(--a-s-4); border-right: 0; border-bottom: 1px solid var(--a-border); }
  .auth-brand-name { font-size: var(--a-fs-20); }
  .auth-mark { width: 28px; height: 28px; border-radius: 7px; }
  .auth-brand-value, .auth-brand-fact { display: none; }
  .auth-panel { justify-content: flex-start; padding: var(--a-s-4); }
  .auth-card { padding: var(--a-s-5); }
}

@media (max-width: 479px) {
  .tiles { grid-template-columns: minmax(0, 1fr); }
  form .btn.primary { width: 100%; }
  .kv { grid-template-columns: 104px minmax(0, 1fr); }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; }
  .banner { flex-wrap: wrap; }
  .banner-action { margin-left: calc(20px + var(--a-s-3)); }
}

/* coarse pointers (touch): 44px targets (2.3) */
@media (pointer: coarse) {
  :root, .a-scope { --a-ctl-h: 44px; --a-ctl-h-sm: 44px; }
  .nav-item, .menu-item { min-height: 44px; }
  .field input:not([type="checkbox"]):not([type="radio"]), .field select { height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
  .table tbody td { min-height: 44px; }
}

/* ================================================================ 9b. trends (lane G)
 * The partial in templates/_trend.html. Sparklines and the 96-cell strip are drawn on the server
 * and complete with scripts off; trend.js adds only a readout. Colour is never the only cue:
 * cell height also says up (full), partial (mid), down (low) and unknown (a hollow stub). */

.trend { padding: var(--a-s-2) var(--a-s-5) var(--a-s-3); display: grid; gap: 2px; min-width: 0; }
.trend-spark { display: block; width: 100%; height: 28px; overflow: visible; color: var(--a-text-2); }
.trend-spark path { fill: none; stroke: currentColor; stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.trend-spark .trend-track { stroke: var(--a-border-strong); stroke-width: 1; }
.trend-spark:focus-visible, .trend-strip:focus-visible { outline: 2px solid var(--a-focus); outline-offset: 2px; border-radius: 2px; }
.trend-delta { margin: 0; font-size: var(--a-fs-12); color: var(--a-text-2); font-variant-numeric: tabular-nums; }
.trend-hint, .trend-read { color: var(--a-text-3); }
.trend-read { margin: 0; font-size: var(--a-fs-12); min-height: 1.3em; overflow-wrap: anywhere; }
.trend-more { font-size: var(--a-fs-12); color: var(--a-text-3); }
.trend-more summary { cursor: pointer; width: fit-content; min-height: 24px; line-height: 24px; }
.trend-more p { margin: 2px 0 0; overflow-wrap: anywhere; }

.trend-avail { display: flex; align-items: center; gap: var(--a-s-2); min-width: 0; position: relative; z-index: 1; margin-top: 2px; }
/* No gap: 96 cells share a narrow column, and a fixed gap would set the strip's width for it. */
.trend-strip { display: grid; grid-template-columns: repeat(96, minmax(0, 1fr)); height: 12px; align-items: end; flex: 1 1 64px; min-width: 64px; }
.trend-strip i { display: block; background: var(--a-ok); height: 100%; }
.trend-strip i[data-s="partial"] { background: var(--a-warn); height: 62%; }
.trend-strip i[data-s="down"] { background: var(--a-bad); height: 28%; }
.trend-strip i[data-s="unknown"] { background: transparent; box-shadow: inset 0 0 0 1px var(--a-border-strong); height: 14%; }
.trend-note { margin: 0; flex: none; font-size: var(--a-fs-12); font-variant-numeric: tabular-nums; }
.trend-pct { font-weight: 600; }
/* The strip's readout floats above it and ignores the pointer, so showing it never moves the
   strip or the cell under the pointer. Empty means nothing to show. */
.trend-tip { position: absolute; left: 0; bottom: calc(100% + 2px); z-index: 5; width: max-content; max-width: min(28rem, 90vw); padding: 2px var(--a-s-2); border: 1px solid var(--a-border-strong); border-radius: var(--a-radius, 6px); background: var(--a-panel); color: var(--a-text); font-size: var(--a-fs-12); font-variant-numeric: tabular-nums; pointer-events: none; overflow-wrap: anywhere; }
.trend-tip:empty { display: none; }
.trend-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.trend-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--a-s-3); margin-top: var(--a-s-3); }
.trend-tile { border: 1px solid var(--a-border); border-radius: var(--a-radius, 6px); background: var(--a-panel); min-width: 0; padding-top: var(--a-s-3); }
.trend-tile .trend { padding-top: 0; }
.trend-tile-label { margin: 0; padding: 0 var(--a-s-5); font-size: var(--a-fs-12); color: var(--a-text-2); }
.trend-tile-basis { margin: 0; padding: 0 var(--a-s-5); font-size: var(--a-fs-12); color: var(--a-text-3); }
.trend-tile-value { margin: 0; padding: 0 var(--a-s-5); font-size: var(--a-fs-18, 18px); font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 1023px) { .trend-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 479px) { .trend-tiles { grid-template-columns: minmax(0, 1fr); } }

@media (forced-colors: active) {
  .trend-spark path { stroke: CanvasText; }
  .trend-spark .trend-track { stroke: GrayText; }
  .trend-strip i { background: CanvasText; forced-color-adjust: none; }
  .trend-strip i[data-s="unknown"] { background: Canvas; box-shadow: inset 0 0 0 1px CanvasText; }
}

/* ================================================================ 10. motion and forced colours */

/* The report and the confidence tab: a figure that is a sentence reads as one, not as a number. */
.reason { color: var(--a-text-2); font-weight: 400; }
.grade-bar {
  display: flex; height: 6px; min-width: 96px; max-width: 200px; margin-block: var(--a-s-1);
  border-radius: 3px; overflow: hidden; background: var(--a-neutral-tint);
}
.grade-part { flex: 0 0 0; }
.grade-part[data-tone="ok"]   { background: var(--a-ok); }
.grade-part[data-tone="warn"] { background: var(--a-warn); }
.grade-part[data-tone="bad"]  { background: var(--a-bad); }
.strip { display: flex; align-items: flex-end; gap: 1px; height: 48px; margin-top: var(--a-s-3); }
.strip-day { flex: 1 1 0; min-height: 1px; border-radius: 1px; background: var(--a-info); }
.strip-table { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (forced-colors: active) {
  .pill, .badge, .beta { border: 1px solid CanvasText; }
  .dot, .gate-dot, .grade-part, .strip-day { forced-color-adjust: none; }
  .nav-item.active { outline: 2px solid Highlight; outline-offset: -2px; }
  .choice:has(:checked) { outline: 2px solid Highlight; }
}
