/* =========================================================================
   AAIS live system — "Signal Discipline"

   One rule governs this stylesheet: colour always means clinical state.
   Chrome is graphite and bone; red/orange/yellow/green/blue appear only on
   patients, beds and people, so a glance at any screen reads as triage.
   The simulators keep their own styles.css and never load this file.
   ========================================================================= */

:root {
  color-scheme: dark;

  /* Ground and ink */
  --bg: #0c0e0f;
  --surface: #141719;
  --surface-2: #1b1f22;
  --surface-3: #252a2e;
  --line: #2b3034;
  --line-strong: #3d4448;
  --ink: #eceae4;
  --ink-2: #a9adad;
  --ink-3: #737a7c;
  --on-primary: #0c0e0f;

  /* Clinical state — the only saturated colours in the system */
  --red: #ff5a4a;
  --orange: #ff9d2e;
  --yellow: #f4d23c;
  --green: #3ddc84;
  --blue: #5eb0ff;
  --grey: #7f8789;
  --red-wash: rgba(255, 90, 74, 0.12);
  --orange-wash: rgba(255, 157, 46, 0.12);
  --yellow-wash: rgba(244, 210, 60, 0.12);
  --green-wash: rgba(61, 220, 132, 0.12);
  --blue-wash: rgba(94, 176, 255, 0.12);

  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* 4px rhythm */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 6px;
  --rail: 6px;
  --touch: 52px; /* gloved hands, moving vehicle */
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f1ec;
    --surface: #fbfaf7;
    --surface-2: #ecebe6;
    --surface-3: #e0ded8;
    --line: #d6d3cc;
    --line-strong: #b9b5ad;
    --ink: #121415;
    --ink-2: #4c5254;
    --ink-3: #6f7577;
    --on-primary: #fbfaf7;
    --red: #d42a1c;
    --orange: #c86400;
    --yellow: #9c7c00;
    --green: #16874a;
    --blue: #1f6fd1;
    --grey: #6a7274;
    --red-wash: rgba(212, 42, 28, 0.09);
    --orange-wash: rgba(200, 100, 0, 0.09);
    --yellow-wash: rgba(156, 124, 0, 0.1);
    --green-wash: rgba(22, 135, 74, 0.09);
    --blue-wash: rgba(31, 111, 209, 0.09);
    --shadow: 0 18px 40px rgba(18, 20, 21, 0.14);
  }
}

/* Tone tokens: set data-tone on any element and use var(--tone). */
[data-tone="red"] { --tone: var(--red); --tone-wash: var(--red-wash); }
[data-tone="orange"] { --tone: var(--orange); --tone-wash: var(--orange-wash); }
[data-tone="yellow"] { --tone: var(--yellow); --tone-wash: var(--yellow-wash); }
[data-tone="green"] { --tone: var(--green); --tone-wash: var(--green-wash); }
[data-tone="blue"] { --tone: var(--blue); --tone-wash: var(--blue-wash); }
[data-tone="grey"] { --tone: var(--grey); --tone-wash: transparent; }

/* ---------- Base ---------- */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 0.95;
  text-transform: uppercase;
}
.num {
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 0.9;
}
.mono { font-family: var(--font-mono); font-size: 0.86em; letter-spacing: 0.02em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Shell ---------- */

.shell {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--s5) var(--s5) var(--s7);
}
.shell--narrow { max-width: 620px; padding-inline: var(--s4); }
.shell--wall { max-width: none; padding: var(--s5) var(--s6); }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 60px;
  padding: var(--s2) var(--s5);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.06em;
}
/* The mark: the status rail itself, in the four triage colours. */
.brand-mark {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  width: 6px;
  height: 22px;
  border-radius: 1px;
  overflow: hidden;
}
.brand-mark i:nth-child(1) { background: var(--red); }
.brand-mark i:nth-child(2) { background: var(--orange); }
.brand-mark i:nth-child(3) { background: var(--yellow); }
.brand-mark i:nth-child(4) { background: var(--green); }
.app-role {
  padding-left: var(--s4);
  border-left: 1px solid var(--line);
  min-width: 0;
}
.app-role-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1;
}
.app-role-context {
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-bar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.app-bar-link {
  font-size: 13px;
  color: var(--ink-2);
  text-decoration: none;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius);
}
.app-bar-link:hover { color: var(--ink); background: var(--surface-2); }

@media (max-width: 640px) {
  .app-bar { padding-inline: var(--s4); gap: var(--s3); }
  .brand-word { display: none; }
  .app-role { padding-left: var(--s3); }
  .app-role-name { font-size: 18px; }
  .shell { padding: var(--s4) var(--s4) var(--s7); }
}

/* Connection state: a stale board must never look like a live one. */
.live {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}
.live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--grey);
}
.live.is-live { color: var(--green); }
.live.is-live::before { background: var(--green); box-shadow: 0 0 0 4px var(--green-wash); }
.live.is-down { color: var(--red); }
.live.is-down::before { background: var(--red); animation: blink 1s steps(2) infinite; }

/* ---------- Surfaces ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s5);
}
.panel + .panel { margin-top: var(--s4); }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.panel-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin: var(--s6) 0 var(--s3);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
}
.section-head h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* The status rail — the system's signature. Any card with data-tone gets it. */
.railed {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: var(--rail) solid var(--tone, var(--grey));
  border-radius: var(--radius);
}
.railed.is-washed { background: linear-gradient(90deg, var(--tone-wash), transparent 55%), var(--surface); }

.tone-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tone, var(--ink-2));
}
.tone-label::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--tone, var(--grey));
}

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

/* ---------- Controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-primary);
}
.btn--primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 86%, var(--bg)); }
.btn--ghost { background: transparent; }
.btn--tone {
  background: var(--tone);
  border-color: var(--tone);
  color: #0c0e0f;
}
.btn--tone:hover:not(:disabled) { background: color-mix(in srgb, var(--tone) 85%, #000); }
.btn--lg {
  min-height: var(--touch);
  padding: 0 var(--s5);
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn--block { width: 100%; }
.btn--quiet {
  min-height: 36px;
  border: 0;
  background: none;
  padding: 0 var(--s2);
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn--quiet:hover:not(:disabled) { background: none; color: var(--ink); }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-color: var(--on-primary) transparent var(--on-primary) transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.field { display: grid; gap: 6px; min-width: 0; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.field-hint { font-size: 12px; color: var(--ink-3); }
.input,
.select,
.textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px var(--s3);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 16px; /* keeps iOS from zooming on focus */
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus,
.select:focus,
.textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 18%, transparent); }
.input--code {
  font-family: var(--font-mono);
  font-size: 28px;
  letter-spacing: 0.5em;
  text-align: center;
}
.input[aria-invalid="true"] { border-color: var(--red); }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-primary); }

/* Resource switch (bed-board) */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left: var(--rail) solid var(--tone, var(--grey));
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}
.switch:hover { background: var(--surface-2); }
.switch-name { font-weight: 600; }
.switch-state {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tone, var(--ink-2));
}

/* ---------- Feedback ---------- */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: var(--s5);
  z-index: 100;
  display: grid;
  gap: var(--s2);
  width: min(92vw, 460px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: var(--s3) var(--s4);
  background: var(--ink);
  color: var(--on-primary);
  border-left: var(--rail) solid var(--tone, var(--ink-3));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 500;
  animation: toast-in 180ms ease-out;
}

.empty {
  display: grid;
  place-items: center;
  gap: var(--s2);
  padding: var(--s7) var(--s5);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-2);
}
.empty-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--ink);
}

.notice {
  display: flex;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left: var(--rail) solid var(--tone, var(--grey));
  border-radius: var(--radius);
  background: var(--tone-wash, var(--surface));
  font-size: 14px;
}

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: var(--s4);
  background: rgba(0, 0, 0, 0.62);
}
.dialog {
  width: min(100%, 420px);
  padding: var(--s5);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dialog h2 {
  font-family: var(--font-display);
  font-size: 28px;
  text-transform: uppercase;
  margin-bottom: var(--s2);
}
.form-error { min-height: 20px; margin: var(--s2) 0; color: var(--red); font-size: 14px; font-weight: 500; }

/* ---------- Motion ---------- */

@keyframes blink { 50% { opacity: 0.2; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
/* The one expressive motion in the system: a new inbound patient's rail
   flares three times so the wall board catches the eye across a room. */
@keyframes rail-flare {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  50% { box-shadow: -10px 0 28px -6px var(--tone); }
}
.is-new { animation: rail-flare 900ms ease-in-out 3; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
