/* --------------------------------------------------------------------------
   YSF DASHBOARD — project layer.

   Loaded AFTER assets/brand.css (vendored, never edited) and BEFORE the page
   markup. Drives three things:

     1. The slot override.  The pack's GUIDE §2 documents `--brand-accent` as
        the single point of variation, but the vendored brand.css does not
        alias every accent role to it (the shadow tokens are literal).  This
        file performs the aliasing so changing `--brand-accent` cascades to
        every accent role.  Currently set to phosphor cyan to match the morse
        trainer at 4e9kkz-morse.duckdns.org — same callsign, same operator,
        same family.

     2. Density override.  The pack's spacing scale (2/4/8/12/16/24/32/40/48/64)
        is ~50% too loose for a single 1080p ham-shack monitor.  Re-scaled to
        75% for cards, sections, and headers, but the typography, radius,
        shadow, and motion scales are unchanged.

     3. Project-level components the pack does not ship.  Specifically:
          - .data-table     molecule (Last Heard, Connected Gateways, System Info)
          - .stat           molecule (4 numeric-prefix tiles)
          - .connect-bar    strip below the header
          - .tx-alert       active-transmission callout
          - .tag--ok/warn/err/info  status variants
          - [data-fresh]    row-level "new since last refresh" affordance
          - .icon           inline-SVG sizing + currentColor stroke contract
        All of these resolve only through pack tokens — no raw hex, no
        arbitrary px outside the pack's scale, no border-radius > 0 except
        2px (inputs) and 9999px (pills).

   a11y: respects prefers-reduced-motion and forced-colors throughout.
   -------------------------------------------------------------------------- */

/* ----- fonts (self-hosted, no Google Fonts CSP widening) ----------------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/inter-latin-var.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin-var.woff2") format("woff2");
}

/* ----- slot override: cyan, 11.4:1 on canvas (AAA) ----------------------- */

:root {
  color-scheme: dark;
  --brand-accent: #00d9e8;       /* override the accent (slot §2 of the pack) */
  --accent: var(--brand-accent); /* the pack's own --accent literal */
  --accent-hover: var(--brand-accent);
  --shadow-hard: 4px 4px 0 var(--brand-accent);
  --shadow-hard-hover: 8px 8px 0 var(--brand-accent);
  --shadow-pressed: 2px 2px 0 var(--brand-accent);
}

/* ----- density override (75% of pack defaults) --------------------------- *
 * Only the spacing scale is shrunk. Typography, color, radius, shadow, and
 * motion stay at the pack's defaults so visual rhythm is preserved.
 * -------------------------------------------------------------------------- */

:root {
  --space-1: 3px;
  --space-2: 6px;
  --space-3: 9px;
  --space-4: 12px;
  --space-6: 18px;
  --space-8: 24px;
  --space-10: 28px;
  --space-12: 32px;
  --space-16: 48px;
}

/* The pack's components declare `display`, which beats the UA's [hidden]
   rule. We toggle [hidden] on nodes that carry pack classes (loading state,
   TX alert), so restore hiding once, here, instead of per element. */
[hidden] {
  display: none !important;
}

/* ----- body + layout shell ---------------------------------------------- */

body {
  margin: 0;
  background: var(--canvas-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: var(--leading-normal);
}

.app {
  display: grid;
  /* minmax(0, 1fr) instead of 1fr: 1fr would let the column expand to
     fit oversized children (e.g. a flex item with min-width: auto that
     holds a long wordmark), which on phones pushed the page past the
     375 px viewport.  minmax(0, 1fr) tells the grid: the column may
     shrink to 0, and children are responsible for wrapping inside it. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "header"
    "connect"
    "tx"
    "stats"
    "lists"
    "lastheard"
    "footer";
  gap: var(--space-4);
  padding: var(--space-4);
  max-inline-size: 1280px;
  margin: 0 auto;
  min-block-size: 100dvh;
}

@media (min-width: 768px) {
  .app {
    gap: var(--space-6);
    padding: var(--space-6);
  }
  .app__stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-3);
  }
  .app__lists {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
  }
}

.app__header    { grid-area: header;    }
.app__connect   { grid-area: connect;   }
.app__tx        { grid-area: tx;        }
.app__stats     { grid-area: stats;     }
.app__lists     { grid-area: lists;     }
.app__lastheard { grid-area: lastheard; }
.app__footer    { grid-area: footer;    }

/* ----- skip link -------------------------------------------------------- */

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-2);
  inset-block-start: calc(-1 * var(--space-16));
  z-index: var(--z-nav);
  padding-block: var(--space-3);
  padding-inline: var(--space-4);
  border-radius: var(--radius-none);
  background: var(--accent);
  color: var(--text-inverse);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  text-decoration: none;
}

.skip-link:focus {
  inset-block-start: var(--space-2);
}

/* ----- site header (callsign + tagline + LIVE) --------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border-hairline);
  background: var(--canvas-raised);
  flex-wrap: wrap;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin: 0;
  /* allow the wordmark to shrink below its content width on narrow
     viewports.  Default min-width: auto on a flex item pins the
     intrinsic content width, which on a 375 px phone was wider than
     the available column and forced the whole grid wider. */
  min-width: 0;
}

.app-header__brand > svg.brand-mark {
  /* the brand mark stays at 24 px; only the wordmark span shrinks/wraps */
  flex-shrink: 0;
}

.app-header__tagline {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.app-header__status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.app-header__refresh {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* brand mark — a 24x24 tile + a "Y" stroke + accent underline.
   Uses pack's --accent token, mirrors the morse mark. */
.brand-mark {
  display: block;
  inline-size: var(--mark-size);
  block-size: var(--mark-size);
  flex: 0 0 var(--mark-size);
}

.brand-mark .mark-tile {
  fill: var(--canvas-base);
  stroke: var(--accent);
}

.brand-mark .mark-letter {
  fill: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: var(--weight-bold);
  text-anchor: middle;
  dominant-baseline: central;
}

.brand-mark .mark-underline {
  fill: var(--accent);
}

/* ----- tag variants (status semantics the pack defines but doesn't expose) */

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-block: 2px;
  padding-inline: var(--space-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: var(--leading-none);
  white-space: nowrap;
}

.tag--ok {
  color: var(--status-ok-fg);
  background: var(--status-ok-bg);
  border-color: var(--status-ok-fg);
}

.tag--warn {
  color: var(--status-warn-fg);
  background: var(--status-warn-bg);
  border-color: var(--status-warn-fg);
}

.tag--err {
  color: var(--status-err-fg);
  background: var(--status-err-bg);
  border-color: var(--status-err-fg);
}

.tag--info {
  color: var(--status-info-fg);
  background: var(--status-info-bg);
  border-color: var(--status-info-fg);
}

.tag--accent {
  color: var(--text-inverse);
  background: var(--accent);
  border-color: var(--accent);
}

/* Forced-colors mode: status colors collapse to one Highlight fill, so the
   tag variants become visually identical.  Add a left-border bar (a
   non-color cue) so OK / WARN / ERR / INFO remain distinguishable in
   Windows High Contrast.  The :before marker is hidden by default to keep
   sighted users unaffected. */
@media (forced-colors: active) {
  .tag { forced-color-adjust: none; }
  .tag--ok,
  .tag--warn,
  .tag--err,
  .tag--info {
    border-inline-start-width: 4px;
  }
}

/* ----- spinner (polling-alive) ------------------------------------------- */

.spinner {
  display: inline-block;
  inline-size: 12px;
  block-size: 12px;
  border: 1.5px solid var(--border-strong);
  border-block-start-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  vertical-align: middle;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* ----- connect bar (the "how do I connect" strip) ----------------------- */

.connect-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--canvas-raised);
  border-block-end: 2px solid var(--accent);
  flex-wrap: wrap;
}

.connect-bar__group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  /* defensive wrap + shrink: a single long value (e.g. the 35-char
     connect URL) shouldn't push the connect bar wider than the
     viewport on very narrow phones.  Not currently an issue at 375 px
     (the value fits) but brittleness insurance. */
  min-width: 0;
  flex-wrap: wrap;
}

.connect-bar__label {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-subtle);
}

.connect-bar__value {
  font-family: var(--font-mono);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.connect-bar__divider {
  inline-size: 1px;
  block-size: var(--space-6);
  background: var(--border-hairline);
}

@media (max-width: 640px) {
  .connect-bar__divider { display: none; }
}

/* ----- stat tile (4-up grid, numeric prefix) ---------------------------- */

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--canvas-raised);
  border: 1px solid var(--border-hairline);
}

.stat__head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.stat__icon {
  inline-size: 20px;
  block-size: 20px;
  color: var(--text-muted);
  flex: 0 0 20px;
}

.stat__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: var(--leading-none);
}

.stat__value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-none);
}

.stat__sub {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* Mobile: the vertical layout wastes ~150 px per tile when 4 of them
   stack on a 375 px phone (600 px just for stats).  Switch to a compact
   horizontal layout: label + value + icon on one row, sub on its own
   row.  The value drops from --text-2xl (48 px) to --text-xl (32 px)
   so it doesn't dominate the row.  Result: ~70 px per tile instead
   of ~150 px, 50-60% vertical recovery.  Desktop (>= 768 px) keeps
   the original vertical layout. */
@media (max-width: 767px) {
  .stat {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    column-gap: var(--space-3);
    row-gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
  }
  .stat__label {
    order: 1;
    flex: 1 1 0;
    min-inline-size: 0;
  }
  .stat__value {
    order: 2;
    flex: 0 0 auto;
    font-size: var(--text-xl);
  }
  .stat__head {
    order: 3;
    flex: 0 0 auto;
  }
  .stat__sub {
    order: 4;
    flex: 0 1 100%;
  }
}

/* status states on the value, not the tile */
.stat--alert .stat__value { color: var(--status-err-fg); }
.stat--alert .stat__icon  { color: var(--status-err-fg); }

.stat--warn .stat__value  { color: var(--status-warn-fg); }
.stat--warn .stat__icon   { color: var(--status-warn-fg); }

/* value-change tick: when the polling JS sets data-fresh on a stat, the
   background flashes --canvas-sunken for one frame (240ms then auto-clear
   via the JS, but the CSS is here for the visual) */
.stat__value--tick {
  transition: background-color var(--motion-base) var(--motion-easing);
  background-color: var(--canvas-sunken);
}

/* ----- card chrome (panels) ---------------------------------------------- */

.card {
  background: var(--canvas-raised);
  border: 1px solid var(--border-hairline);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card__icon {
  inline-size: 20px;
  block-size: 20px;
  color: var(--text-muted);
  flex: 0 0 20px;
}

.card__title {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin: 0;
  color: var(--text-primary);
}

.card__meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  margin-inline-start: auto;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

/* ----- data table (project molecule — pack has no table component) ------- */

.data-table {
  inline-size: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  text-align: start;
  padding-block: var(--space-2);
  padding-inline: var(--space-3);
  border-block-end: 1px solid var(--border-hairline);
  vertical-align: middle;
}

.data-table th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  border-block-end-color: var(--border-strong);
  white-space: nowrap;
}

.data-table td {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.data-table td:first-child {
  color: var(--text-subtle);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-block-end: none;
}

.data-table a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--border-hairline);
  text-underline-offset: 2px;
}

.data-table a:hover,
.data-table a:focus-visible {
  text-decoration-color: var(--accent);
  color: var(--accent);
}

/* new-since-last-refresh row: accent left border for one refresh cycle, then
   the JS removes the data-fresh attribute */
.data-table tbody tr[data-fresh="true"] td:first-child {
  border-inline-start: 2px solid var(--accent);
  padding-inline-start: calc(var(--space-3) - 2px);
}

@media (prefers-reduced-motion: no-preference) {
  .data-table tbody tr[data-fresh="true"] {
    animation: row-flash var(--motion-slow) var(--motion-easing) 1;
  }
}

@keyframes row-flash {
  from { background-color: var(--canvas-sunken); }
  to   { background-color: transparent; }
}

/* empty cell (one row, full span) */
.data-table__empty {
  text-align: center !important;
  color: var(--text-subtle);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  padding-block: var(--space-6) !important;
}

/* ----- system info table (definition list, mono, no header row) -------- */

.info-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  row-gap: var(--space-1);
  column-gap: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.info-list dt {
  color: var(--text-muted);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  padding-block: var(--space-1);
  border-block-end: 1px solid var(--border-hairline);
}

.info-list dd {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin: 0;
  padding-block: var(--space-1);
  text-align: end;
  border-block-end: 1px solid var(--border-hairline);
}

.info-list .info-list__row:last-child dt,
.info-list .info-list__row:last-child dd {
  border-block-end: none;
}

/* The 6 row wrappers were being auto-flowed into the parent's 2 columns
   as 6 grid items (alternating left / right), so the rendered output
   had labels and values split across columns.  Subgrid aligns each row
   to the parent's column tracks so every label shares col 1 and every
   value shares col 2.  grid-column: 1 / -1 makes each row span both
   parent tracks; subgrid inherits them.  Replaces a broken auto-flow
   without changing the markup (the wrapper divs stay so the
   :last-child border rule still works). */
.info-list__row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
}

/* ----- TX alert (only renders when a station is actively transmitting) --- */

.tx-alert {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--status-err-bg);
  border: 1px solid var(--status-err-fg);
  border-inline-start-width: 4px;
}

.tx-alert__icon {
  inline-size: 24px;
  block-size: 24px;
  color: var(--status-err-fg);
  flex: 0 0 24px;
}

.tx-alert__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
  min-inline-size: 0;
}

.tx-alert__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--status-err-fg);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin: 0;
}

.tx-alert__dot {
  display: inline-block;
  inline-size: 8px;
  block-size: 8px;
  background: var(--status-err-fg);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .tx-alert__dot { animation: none; }
}

.tx-alert__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

@media (min-width: 640px) {
  .tx-alert__grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
  }
}

.tx-alert__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tx-alert__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.tx-alert__value {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.tx-alert__value a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--border-hairline);
}

.tx-alert__value a:hover,
.tx-alert__value a:focus-visible {
  text-decoration-color: var(--accent);
  color: var(--accent);
}

/* ----- empty state (no last-heard, no gateways) ------------------------- */

.empty {
  text-align: center;
  padding-block: var(--space-8);
  padding-inline: var(--space-4);
  border: 1px dashed var(--border-hairline);
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

/* ----- footer ------------------------------------------------------------ */

.site-footer {
  /* override the brand pack's space-between (which left-aligns a single
     child) — centre the line, like the morse site's footer */
  justify-content: center;
  /* allow wrap so a long single line doesn't push the page wider than
     the viewport on narrow phones (the previous version with 3 inline
     links + separators overflowed the 375 px viewport by ~120 px) */
  flex-wrap: wrap;
  text-align: center;
  padding: var(--space-3) var(--space-4);
  border-block-start: 1px solid var(--border-hairline);
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-color: var(--border-hairline);
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

/* ----- live regions (sr-only) ------------------------------------------- */

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ----- icon sizing (24x24 default, 16x16 in chrome) --------------------- */

.icon {
  display: inline-block;
  inline-size: 24px;
  block-size: 24px;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
  flex: 0 0 auto;
}

.icon--sm {
  inline-size: 16px;
  block-size: 16px;
}

.icon--xs {
  inline-size: 12px;
  block-size: 12px;
}

/* ----- boot loading state ----------------------------------------------- *
 * The dashboard is server-rendered, so by the time the HTML parses the
 * data is already in place.  A body.booting fade-in delayed perceived
 * load on every refresh (5 s on the first poll due to setInterval
 * timing), so the state was removed.  The "(Ns ago)" counter on the
 * refresh label is the honest indicator of data freshness.
 * -------------------------------------------------------------------------- */

/* ----- mobile touch targets (a11y: WCAG 2.5.5, 44x44 minimum) -------- *
 * Phones at 375-414 px have a tighter tap-precision budget than desktop
 * and the brand pack's defaults leave several interactive elements well
 * under 44 px tall (callsign links in data tables: 18 px; footer links:
 * 36 px; skip link: 39 px).  This block bumps the tap area without
 * changing the visual size — the text stays at 14 px, the link just
 * gets a larger invisible hit box via min-block-size + display swap.
 * Scoped to mobile so desktop tap targets aren't affected.
 * -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .skip-link {
    min-block-size: 44px;
  }

  .data-table a {
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
  }

  .site-footer a {
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
  }
}
