/* =========================================================================
   AMWS — base.css  (Calm instrument design system)
   Tokens source of truth: :root here + DESIGN.md
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

:root {
  /* ---- Colour ---- */
  --bg: #07090D;
  --surface-1: #0D1117;
  --surface-2: #151B24;
  --border: #232C39;           /* decorative only */
  --border-strong: #6B7A90;    /* input/button/segmented edges, >=3:1 */
  --text: #E8EDF4;
  --text-muted: #9AA7B8;
  --text-faint: #7A8798;
  --white: var(--text);

  --primary: #5B9BFF;
  --primary-hover: #7DB1FF;
  --on-primary: #07090D;

  --nominal: #3DDC97;
  --warning: #FFB020;
  --critical: #FF6B6F;
  --emergency: #E5484D; /* EMER key fill only */

  /* ---- Compatibility aliases (legacy names used in files) ---- */
  --black: var(--bg);
  --ink: var(--surface-1);
  --blue: var(--primary);
  --blue-text: var(--primary);
  --white-08: color-mix(in srgb, var(--text) 8%, transparent);
  --white-12: color-mix(in srgb, var(--text) 12%, transparent);
  --white-20: color-mix(in srgb, var(--text) 20%, transparent);
  --white-40: var(--text-muted);
  --white-60: var(--text-muted);
  --blue-06: color-mix(in srgb, var(--primary) 6%, var(--surface-1));
  --blue-12: color-mix(in srgb, var(--primary) 12%, var(--surface-1));
  --blue-15: color-mix(in srgb, var(--primary) 15%, var(--surface-1));
  --blue-25: color-mix(in srgb, var(--primary) 25%, var(--surface-1));
  --blue-40: color-mix(in srgb, var(--primary) 40%, var(--surface-1));
  --blue-60: color-mix(in srgb, var(--primary) 60%, transparent);

  /* ---- Spacing (4px base) ---- */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  /* legacy */
  --s8: 32px;
  --s10: 40px;

  /* ---- Shape ---- */
  --r-sm: 3px;   /* badges, chips */
  --r-md: 8px;   /* buttons, inputs, tiles */
  --r-lg: 16px;  /* drawer, watch glass */
  --r-case: 24px; /* physical watch case only */

  /* ---- Typography ---- */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --fs-xs: 11px;
  --lh-xs: 16px;
  --fs-sm: 13px;
  --lh-sm: 20px;
  --fs-base: 16px;
  --lh-base: 24px;
  --fs-md: 18px;
  --lh-md: 26px;
  --fs-lg: 24px;
  --lh-lg: 32px;
  --fs-xl: 36px;
  --lh-xl: 40px;
  --fs-2xl: 56px;
  --lh-2xl: 56px;

  /* legacy type aliases */
  --text-xs: 11px;
  --text-sm: 13px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 36px;
  --text-3xl: 56px;
}

/* ---- Base ---- */
body {
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

/* Subtle neutral backdrop (no external assets) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--primary) 6%, transparent) 0%, transparent 60%);
}

#app { position: relative; z-index: 1; display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh; }

/* ---- Typography ---- */
.lbl {
  display: block;
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* =========================================================================
   SEVERITY SYSTEM (classes preserved for JS: sev-nominal/advisory/caution/warning/emergency)
   Status is never colour alone: colour + icon (✓ ⚠ ✕) + word.
   ========================================================================= */
.sev-nominal   { --sev-color: var(--nominal); --sev-text: var(--nominal); --sev-border: var(--nominal); --sev-bg: color-mix(in srgb, var(--nominal) 14%, var(--surface-1)); --sev-bold: var(--nominal); }
.sev-advisory  { --sev-color: var(--warning); --sev-text: var(--warning); --sev-border: var(--warning); --sev-bg: color-mix(in srgb, var(--warning) 14%, var(--surface-1)); --sev-bold: var(--warning); }
.sev-caution   { --sev-color: var(--warning); --sev-text: var(--warning); --sev-border: var(--warning); --sev-bg: color-mix(in srgb, var(--warning) 14%, var(--surface-1)); --sev-bold: var(--warning); }
.sev-warning   { --sev-color: var(--critical); --sev-text: var(--critical); --sev-border: var(--critical); --sev-bg: color-mix(in srgb, var(--critical) 14%, var(--surface-1)); --sev-bold: var(--critical); }
.sev-emergency { --sev-color: var(--emergency); --sev-text: var(--text); --sev-border: var(--emergency); --sev-bg: color-mix(in srgb, var(--emergency) 20%, var(--surface-1)); --sev-bold: var(--text); }
.sev-cannot-reach { --sev-color: var(--critical); --sev-text: var(--critical); --sev-border: var(--critical); --sev-bg: color-mix(in srgb, var(--critical) 14%, var(--surface-1)); --sev-bold: var(--critical); }

/* ---- Status chip (data-chip) ---- */
.chip, [data-chip] {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  font-family: var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--sev-border, var(--border-strong));
  color: var(--sev-text, var(--text-muted));
  background: var(--sev-bg, transparent);
  white-space: nowrap;
  font-weight: 600;
}
.chip.sev-emergency { font-weight: 600; border-width: 1px; animation: border-pulse 1.4s ease-in-out infinite; }

/* ---- Provenance badges (neutral, never warning/amber) ---- */
.badge-assumed, .badge-provenance {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  line-height: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  padding: 1px 4px;
  vertical-align: middle;
  margin-left: var(--s1);
  background: transparent;
}

/* ---- Bar ---- */
.bar-track { height: 6px; background: var(--surface-2); border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: var(--primary); border-radius: var(--r-sm); transition: width 0.3s ease; }
.sev-warning .bar-fill, .sev-caution .bar-fill, .sev-advisory .bar-fill { background: var(--warning); }
.sev-emergency .bar-fill, .sev-critical .bar-fill { background: var(--critical); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 40px;
  padding: var(--s2) var(--s4);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: 600 var(--fs-xs)/1.2 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--primary); color: var(--text); background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger  { border-color: var(--critical); color: var(--critical); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--critical) 14%, var(--surface-1)); }
.btn.wide    { width: 100%; }
.btn.quiet { border: none; color: var(--text-muted); background: transparent; }
.btn.quiet:hover { color: var(--text); background: transparent; }

/* ---- Hold-to-confirm ---- */
.btn-hold {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: var(--s3) var(--s4);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: 600 var(--fs-xs)/1.2 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-hold .fill {
  position: absolute; inset: 0; width: 0;
  background: color-mix(in srgb, var(--primary) 20%, transparent);
  transition: none;
}
.btn-hold.holding .fill { transition: width linear; }
.btn-hold .hold-label { font-size: 10px; color: var(--text-muted); }
.btn-hold.red  { border-color: var(--critical); color: var(--critical); }
.btn-hold.red .fill { background: color-mix(in srgb, var(--critical) 20%, transparent); }
.btn-hold.blue { border-color: var(--primary); color: var(--primary); }

/* ---- Focus ---- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button:not(:focus-visible) { outline: none; }

/* ---- KV pair ---- */
.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
}
.kv:last-child { border-bottom: none; }
.kv .v { font-family: var(--font-mono); color: var(--text); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s5);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: var(--s3); flex: none; }
.brand-mark { width: 28px; height: 28px; fill: none; stroke: var(--primary); stroke-width: 1.5; }
.brand-name { font-size: var(--fs-base); font-weight: 600; color: var(--text); letter-spacing: 0.04em; }
.brand-desc { font-size: var(--fs-xs); color: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase; }

.topbar-meta { display: flex; gap: var(--s5); align-items: center; flex: 1; min-width: 0; }
.topbar-meta .item { display: flex; flex-direction: column; gap: 1px; }
.topbar-meta .item .v { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text); font-variant-numeric: tabular-nums; }

/* SIMULATED DATA pill - provenance (neutral dashed) */
.sim-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  padding: 3px 8px;
  white-space: nowrap;
  background: transparent;
}
.sim-pill::before { content: none; }

.topbar-actions { display: flex; align-items: center; gap: var(--s3); flex: none; }

/* ---- View toggle / Segmented controls ---- */
.view-toggle, .seg {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: transparent;
}
.view-toggle button, .seg button {
  padding: var(--s2) var(--s3);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font: 600 var(--fs-xs)/1 var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-height: 40px;
}
.view-toggle button[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ---- Main stage ---- */
.main-stage {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: var(--s5);
  padding: var(--s6) var(--s5);
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}
@media (max-width: 1099px) {
  .main-stage { grid-template-columns: 1fr; }
  .watch-stage { justify-self: center; }
}
@media (max-width: 699px) {
  .main-stage { padding: var(--s4); gap: var(--s4); }
  .topbar { padding: var(--s2) var(--s4); gap: var(--s2); }
  .topbar-meta { display: none; }
}

body.view-wrist .main-stage  { grid-template-columns: 1fr; }
body.view-wrist .ground-view { display: none; }
body.view-wrist .watch-stage { justify-self: center; }
body.view-ground .watch-stage { display: none; }

/* ---- Drawer ---- */
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: 360px;
  max-width: 100vw;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  border-radius: var(--r-lg) 0 0 var(--r-lg);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.18s ease-out;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 0 0 1px var(--border), 0 16px 48px rgb(0 0 0 / .6);
}
body.drawer-open .drawer { transform: none; }
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / .55);
  z-index: 199;
}
body.drawer-open .drawer-backdrop { display: block; }

.drawer-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4) var(--s5);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.presenter-banner {
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  display: inline-block;
  margin-bottom: var(--s2);
  background: transparent;
}
.drawer-body { padding: var(--s4) var(--s5) var(--s7); }
.ctl-group { margin-bottom: var(--s5); }
.ctl-group h4 {
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--s2);
  font-weight: 600;
}
.rng { margin-bottom: var(--s3); }
.rng label { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s1); }
.rng output { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text); font-variant-numeric: tabular-nums; }
.rng input[type="range"] { width: 100%; accent-color: var(--primary); }
.rng input[type="number"] {
  width: 100%; min-height: 40px; padding: var(--s2) var(--s3);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  color: var(--text); font: 400 var(--fs-sm)/var(--lh-sm) var(--font-mono);
}
.tgl { display: flex; align-items: center; gap: var(--s3); font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s3); cursor: pointer; min-height: 40px; }
.tgl input { accent-color: var(--primary); }

/* ---- Demo panel ---- */
.demo-text { font-size: var(--fs-xs); color: var(--text-muted); min-height: 2.5em; margin: var(--s3) 0; }
.demo-step { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.demo-bar  { height: 4px; background: var(--surface-2); border-radius: var(--r-sm); overflow: hidden; margin: var(--s2) 0; border: 1px solid var(--border); }
.demo-prog { display: block; height: 100%; background: var(--primary); border-radius: var(--r-sm); width: 0; transition: width 0.2s linear; }
.demo-btns { display: flex; gap: var(--s2); }
.demo-cta { margin-top: 4px; min-height: 44px; padding: 10px 18px; font-weight: 600; letter-spacing: .06em; }

/* ---- Footer ---- */
.foot {
  padding: var(--s5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  color: var(--text-muted);
  text-align: center;
}
.foot a { color: var(--primary); text-decoration: underline; }
.foot p + p { margin-top: var(--s2); }
.foot .legend { display: flex; gap: var(--s5); justify-content: center; margin-top: var(--s3); flex-wrap: wrap; }
.foot .legend-item { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xs); }

/* ---- Emergency body state ---- */
body.is-emergency .topbar { border-bottom-color: var(--critical); }

/* ---- Animations ---- */
@keyframes border-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50%       { box-shadow: 0 0 0 2px color-mix(in srgb, var(--critical) 30%, transparent); }
}
@keyframes pulse-em {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
.em-pulse { animation: pulse-em 1.4s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  .em-pulse { animation: none; }
  .chip.sev-emergency { animation: none; }
  .btn-hold.holding .fill { transition: none; }
  .bar-fill { transition: none; }
  .drawer { transition: opacity 0.15s ease; transform: none; opacity: 0; pointer-events: none; }
  body.drawer-open .drawer { opacity: 1; pointer-events: auto; }
  body::before { display: none; }
  .demo-prog { transition: none; }
}
