/* Instrument Panel
   Tokens + a small framework-free component layer.

   Sections:
     1. tokens (dark default, light variant)
     2. base   (body, focus, scrollbars, selects)
     3. layer  (.hs-* classes: plate, led, panel, readout, meter, badge, button, table)
     4. motion (the only two allowed keyframes)

   In a React app the tokens are written onto <html> by ThemeProvider and this :root block
   is the first-paint fallback. In plain HTML this file is the whole system. */

/* ── 1. tokens ─────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  --bg-page: #16181d;
  --bg-surface: #1d2026;
  --bg-surface-muted: #14161a;         /* the well: inputs, meter tracks, insets */
  --bg-surface-raised: #24282f;
  --bg-overlay: rgba(20, 22, 26, 0.92);

  --border-default: #2f333b;           /* the hairline — does the structural work */
  --border-muted: rgba(255, 255, 255, 0.04);
  --border-emphasis: #ffb454;

  --fg-default: #e9e7e2;
  --fg-muted: #a09d94;
  --fg-subtle: #6f6c64;
  --fg-on-accent: #201607;

  --accent: #ffb454;                   /* amber — interactive + attention. Reserved. */
  --accent-muted: rgba(255, 180, 84, 0.6);
  --accent-bg: rgba(255, 180, 84, 0.1);

  --ok: #58a066;        --ok-bg: rgba(88, 160, 102, 0.12);
  --warn: #ffb454;      --warn-bg: rgba(255, 180, 84, 0.12);   /* == accent, on purpose */
  --critical: #e5484d;  --critical-bg: rgba(229, 72, 77, 0.12);
  --info: #6b8bb0;      --info-bg: rgba(107, 139, 176, 0.12);  /* neutral status only */

  --shadow-soft: 0 1px 0 rgba(0, 0, 0, 0.2);
  --shadow-strong: 0 8px 24px rgba(0, 0, 0, 0.45);

  --ambient-layer1: none;              /* stays none */
  --ambient-layer2: none;

  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-sans);    /* display IS the sans — no serif */
  --font-body: var(--font-sans);
  --font-ui: var(--font-sans);

  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 360ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 9999px;
}

/* Light — "Daylight". Same language, ground flipped. Amber deepens to ochre for AA. */
:root[data-theme="light"] {
  color-scheme: light;

  --bg-page: #f3f1ec;
  --bg-surface: #ffffff;
  --bg-surface-muted: #eae7df;
  --bg-surface-raised: #ffffff;
  --bg-overlay: rgba(243, 241, 236, 0.9);

  --border-default: #dcd8ce;
  --border-muted: rgba(0, 0, 0, 0.06);
  --border-emphasis: #a05a00;

  --fg-default: #22252b;
  --fg-muted: #585d68;
  --fg-subtle: #6b707a;
  --fg-on-accent: #fff8ec;

  --accent: #a05a00;
  --accent-muted: rgba(160, 90, 0, 0.55);
  --accent-bg: rgba(160, 90, 0, 0.1);

  --ok: #2e7d48;        --ok-bg: rgba(46, 125, 72, 0.12);
  --warn: #a05a00;      --warn-bg: rgba(160, 90, 0, 0.12);
  --critical: #c23934;  --critical-bg: rgba(194, 57, 52, 0.12);
  --info: #3a6ea3;      --info-bg: rgba(58, 110, 163, 0.12);

  --shadow-soft: 0 1px 2px rgba(20, 22, 30, 0.06);
  --shadow-strong: 0 10px 30px rgba(20, 22, 30, 0.14);
}

/* Follow the OS unless the page has explicitly chosen a ground. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="atmospheric"]) {
    color-scheme: light;
    --bg-page: #f3f1ec;
    --bg-surface: #ffffff;
    --bg-surface-muted: #eae7df;
    --bg-surface-raised: #ffffff;
    --bg-overlay: rgba(243, 241, 236, 0.9);
    --border-default: #dcd8ce;
    --border-muted: rgba(0, 0, 0, 0.06);
    --border-emphasis: #a05a00;
    --fg-default: #22252b;
    --fg-muted: #585d68;
    --fg-subtle: #6b707a;
    --fg-on-accent: #fff8ec;
    --accent: #a05a00;
    --accent-muted: rgba(160, 90, 0, 0.55);
    --accent-bg: rgba(160, 90, 0, 0.1);
    --ok: #2e7d48;        --ok-bg: rgba(46, 125, 72, 0.12);
    --warn: #a05a00;      --warn-bg: rgba(160, 90, 0, 0.12);
    --critical: #c23934;  --critical-bg: rgba(194, 57, 52, 0.12);
    --info: #3a6ea3;      --info-bg: rgba(58, 110, 163, 0.12);
    --shadow-soft: 0 1px 2px rgba(20, 22, 30, 0.06);
    --shadow-strong: 0 10px 30px rgba(20, 22, 30, 0.14);
  }
}

/* ── 2. base ───────────────────────────────────────────────────────────── */

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--fg-default);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

em {                        /* emphasis is weight + accent, never a serif italic */
  font-style: normal;
  font-weight: 600;
  color: var(--accent);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid var(--accent);     /* crisp ring, never a glow */
  outline-offset: 2px;
}

a, button, input, select, textarea, [role="button"], [tabindex] {
  transition-property: color, background-color, border-color, opacity, box-shadow;
  transition-duration: var(--dur-base);
  transition-timing-function: var(--ease);
}

::selection { background: var(--accent-bg); color: var(--fg-default); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-muted); }

select {
  background-color: var(--bg-surface-raised);
  color: var(--fg-default);
  font-family: var(--font-ui);
}
select option { background-color: var(--bg-surface-raised); color: var(--fg-default); }
select option:checked, select option:hover {
  background-color: var(--accent-bg);
  color: var(--accent);
}
select:not([multiple]) {                /* accent chevron, themed across browsers */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='currentColor' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px 14px;
  padding-right: 28px;
}

/* ── 3. layer ──────────────────────────────────────────────────────────── */

/* The plate: mono, caps, tracked. If text NAMES something, it is a plate. */
.hs-plate {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.hs-plate--subtle { color: var(--fg-subtle); font-size: 10px; }

/* Numerics never jitter. */
.hs-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* LED — always accompanied by a word. */
.hs-led {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  background: var(--fg-subtle);
}
.hs-led[data-status="ok"]   { background: var(--ok); }
.hs-led[data-status="warn"] { background: var(--warn); }
.hs-led[data-status="crit"] { background: var(--critical); }
.hs-led[data-status="info"] { background: var(--info); }
.hs-led[data-status="off"]  { background: var(--fg-subtle); }

.hs-status { display: inline-flex; align-items: center; gap: 6px; }
.hs-status[data-status="ok"]   .hs-plate { color: var(--ok); }
.hs-status[data-status="warn"] .hs-plate { color: var(--warn); }
.hs-status[data-status="crit"] .hs-plate { color: var(--critical); }
.hs-status[data-status="info"] .hs-plate { color: var(--info); }

/* Panel + power rail. The rail is neutral unless a real status is reported. */
.hs-panel {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}
.hs-panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--card-edge-color, var(--border-default));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  pointer-events: none;
}
.hs-panel[data-rail="ok"]     { --card-edge-color: var(--ok); }
.hs-panel[data-rail="warn"]   { --card-edge-color: var(--warn); }
.hs-panel[data-rail="crit"]   { --card-edge-color: var(--critical); }
.hs-panel[data-rail="info"]   { --card-edge-color: var(--info); }
.hs-panel[data-rail="accent"] { --card-edge-color: var(--accent); }

.hs-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border-default);
}
.hs-panel-body { padding: 12px 16px 14px; }

/* Readout — the KPI tile. */
.hs-readout { display: flex; flex-direction: column; gap: 8px; padding: 13px 16px 14px; }
.hs-readout__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  line-height: 1;
  font-weight: 500;
  color: var(--fg-default);
}

/* Segmented LED bargraph — discrete cells, never a smooth bar. */
.hs-seg { display: flex; gap: 2px; flex: 1 1 auto; min-width: 48px; }
.hs-seg span { flex: 1; height: 8px; border-radius: 1px; background: var(--bg-surface-muted); }
.hs-seg[data-level="ok"]   span.lit { background: var(--ok); }
.hs-seg[data-level="warn"] span.lit { background: var(--warn); }
.hs-seg[data-level="crit"] span.lit { background: var(--critical); }
.hs-meter { display: flex; align-items: center; gap: 8px; }
.hs-meter .hs-num { font-size: 11px; width: 36px; text-align: right; color: var(--fg-muted); }
/* The readout takes the level colour once it leaves nominal — the number warns too. */
.hs-seg[data-level="warn"] ~ .hs-num { color: var(--warn); }
.hs-seg[data-level="crit"] ~ .hs-num { color: var(--critical); }

/* Badge — LED + plate in a tinted pill. */
.hs-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  background: var(--bg-surface-muted);
}
.hs-badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.hs-badge[data-status="ok"]   { color: var(--ok);       background: var(--ok-bg); }
.hs-badge[data-status="warn"] { color: var(--warn);     background: var(--warn-bg); }
.hs-badge[data-status="crit"] { color: var(--critical); background: var(--critical-bg); }
.hs-badge[data-status="info"] { color: var(--info);     background: var(--info-bg); }

/* Buttons — the primary is a mono-caps amber slab. */
.hs-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-surface-muted);
  color: var(--fg-muted);
  cursor: pointer;
}
.hs-btn:hover { color: var(--fg-default); border-color: var(--accent-muted); }
.hs-btn--primary {
  font-weight: 700;
  letter-spacing: 0.22em;
  border: 0;
  background: var(--accent);
  color: var(--fg-on-accent);
}
.hs-btn--primary:hover { background: var(--accent); filter: brightness(1.08); color: var(--fg-on-accent); }
.hs-btn:active { transform: translateY(1px); }

/* Field — a well with an amber focus. */
.hs-field {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-surface-muted);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--fg-default);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 12px;
}
.hs-field::placeholder { color: var(--fg-subtle); }
.hs-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

/* Instrument table — the default for repeated records. */
.hs-table { width: 100%; border-collapse: collapse; }
.hs-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  text-align: left;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-default);
}
.hs-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}
.hs-table tbody tr:last-child td { border-bottom: 0; }
.hs-table tbody tr:hover { background: var(--bg-surface-raised); }
.hs-table td.hs-num { text-align: right; }

/* Page header — eyebrow, verdict title, meta. */
.hs-eyebrow { display: block; margin-bottom: 6px; }
.hs-title { font-size: 22px; font-weight: 600; line-height: 1.15; margin: 0; color: var(--fg-default); text-wrap: balance; }
.hs-lede  { font-size: 15px; font-weight: 400; line-height: 1.5; color: var(--fg-muted); margin: 8px 0 0; max-width: 66ch; text-wrap: pretty; }
.hs-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-muted); margin-top: 6px; }
.hs-lede + .hs-meta { color: var(--fg-subtle); margin-top: 10px; }

/* ── 4. motion ─────────────────────────────────────────────────────────── */

/* The only ambient motion in the system: a live-poll heartbeat. */
@keyframes hs-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.hs-live { animation: hs-blink 2s ease-in-out infinite; }

@keyframes hs-shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.hs-skeleton {
  background: linear-gradient(90deg, transparent 0%, var(--bg-surface-raised) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: hs-shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@media (prefers-reduced-motion: reduce) {
  .hs-live, .hs-skeleton { animation: none; }
}
