/* ─────────────────────────────────────────────────────────────
   EPD Ring Simulator — test console
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-dim: #64748b;
  --text-faint: #94a3b8;

  --accent: #0d9488;
  --accent-dark: #0f766e;
  --accent-soft: #ccfbf1;
  --blue: #2563eb;

  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* The grid the control row is built on. */
  --label-col: 96px;   /* wide enough for the scenario buttons */
  --cols: 11;   /* fallback; renderControlRow() sets this from COLUMNS.length */
}

* { box-sizing: border-box; }

/* Class-level `display` rules outrank the UA's [hidden] rule — force it. */
[hidden] { display: none !important; }

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

h1, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.mono { font-family: var(--mono); }

/* ───────────────────────── Login gate ───────────────────────── */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #0f172a 0%, #134e4a 100%);
  z-index: 100;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.gate-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.gate-brand h1 { font-size: 19px; }
.gate-brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }

.gate-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  border: 4px solid var(--accent);
  box-shadow: inset 0 0 0 2px var(--surface);
}

.gate-mark.small { width: 18px; height: 18px; border-width: 3px; }

.gate-error {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: #991b1b;
  font-size: 13px;
}

.gate-hint { margin: 16px 0 0; font-size: 12px; color: var(--text-faint); text-align: center; }

.field { display: block; margin-bottom: 11px; }
.field > span { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 500; color: var(--text-dim); }

.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
}

.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ───────────────────────── Top bar ───────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-stat { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.topbar-stat span { font-weight: 600; color: var(--text); }
.topbar-stat.error span { color: var(--danger); }
.topbar-user { font-size: 12px; color: var(--text-faint); }

.tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ───────────────────────── Layout ───────────────────────── */

main { max-width: 1440px; margin: 0 auto; padding: 12px 14px 40px; }

.console {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

/* ───────────────────────── Top control bar ───────────────────────── */

.bar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 14px; }

.stack { display: flex; flex-direction: column; gap: 3px; }
.stack > span { font-size: 11px; font-weight: 500; color: var(--text-dim); }
.stack-center { align-items: center; }

.stack select, .stack input[type="text"] {
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 12px;
  min-width: 108px;
}

.stack input[type="text"] { font-family: var(--mono); min-width: 92px; }
.stack select:focus, .stack input:focus { outline: none; border-color: var(--accent); }
.stack select:disabled { background: var(--surface-2); color: var(--text-faint); }

.transport { display: flex; align-items: center; gap: 4px; }

.tbtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--blue);
  cursor: pointer;
}

.tbtn:hover:not(:disabled) { background: var(--surface-2); }
.tbtn:disabled { opacity: .35; cursor: not-allowed; }
.tbtn.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }

/* Dark when idle, bright green for one second on each message sent. */
.led {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #14532d;
  border: 1px solid #052e16;
  color: rgba(255, 255, 255, .92);
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background .12s, box-shadow .12s;
}

.led.lit { background: #22c55e; box-shadow: 0 0 0 5px rgba(34, 197, 94, .25); }
.led.bad { background: var(--danger); box-shadow: 0 0 0 5px rgba(220, 38, 38, .25); }

/* Switch */

.switch {
  flex: none;
  width: 38px;
  height: 21px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background .15s;
}

.switch.is-on { background: var(--accent); }

.switch-thumb {
  display: block;
  width: 15px;
  height: 15px;
  margin-left: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform .15s;
}

.switch.is-on .switch-thumb { transform: translateX(17px); }

/* ───────────────────────── Command strip ───────────────────────── */

.strip { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 18px; }
.strip-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.strip-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-left: auto; }

.kv { display: flex; flex-wrap: wrap; gap: 3px 14px; margin: 0; align-items: baseline; }
.kv dt { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.kv dt::after { content: ':'; }
.kv dd { margin: 0; font-size: 12px; font-family: var(--mono); word-break: break-all; }

.inline-field, .inline-check { display: flex; align-items: center; gap: 6px; }
.inline-field > span, .inline-check > span { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

.inline-field select, .inline-field input {
  padding: 4px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 12px;
}

.inline-field input { width: 116px; font-family: var(--mono); }
.inline-field select:focus, .inline-field input:focus { outline: none; border-color: var(--accent); }

.badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 600;
}

.badge.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-dark); }
.badge.ok { background: var(--ok-soft); border-color: transparent; color: #166534; }
.badge.err { background: var(--danger-soft); border-color: transparent; color: #991b1b; }

.hint { margin: 0; font-size: 11px; color: var(--text-faint); font-family: var(--mono); }

/* ═════════════════ Aligned payload / control grid ═════════════════
   Both rows share one template, so every control sits directly under
   the value it produces. */

.crow {
  display: grid;
  grid-template-columns: var(--label-col) repeat(var(--cols), minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
  padding: 7px 0;
}

.crow + .crow { border-top: 1px solid var(--border); }

.rlabel {
  display: flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  line-height: 1.25;
}

.rlabel em { font-style: italic; font-weight: 500; }

#control-row .rlabel { flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; }

.scenarios { display: flex; flex-direction: column; gap: 4px; width: 100%; }

/* Scoped under .scenarios so these win against the generic .btn rule, which is
   declared later in this file and whose `border` shorthand would otherwise
   reset the colour back to transparent. */
.scenarios .btn-scen {
  padding: 3px 6px;
  font-size: 10.5px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  white-space: nowrap;
}

.scenarios .btn-scen:hover { background: var(--surface-2); color: var(--text); }
/* Running: amber, because the scenario is actively driving the payload. */
.scenarios .btn-scen.is-active { background: var(--warn-soft); border-color: var(--warn); color: #92400e; }

.rnote {
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--warn);
}

/* A column whose slider is not reaching the wire right now. Still editable —
   the value is kept for when the ring goes active again. */
.ccell.inert { opacity: .38; }

/* Meta strip: transmit indicator, last-message time, active device, Reset.
   Not on the .crow grid — it is a header for the control row, not a column
   of it, so it lays out on its own. */
.crow-meta {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 4px 0 9px;
  border-bottom: 1px solid var(--border);
}

.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label { font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.ts-line { display: flex; align-items: baseline; gap: 10px; }
.ts { font-size: 13px; font-variant-numeric: tabular-nums; }
.ts-et { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-dim); }

.active-id {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: .02em;
  color: var(--accent-dark);
}

.meta-reset { margin-left: auto; }

/* Control cells */

.ccell { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 2px 0; }
.ccell-key { font-size: 10px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ccell select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 11.5px;
}

.ccell select:focus { outline: none; border-color: var(--accent); }

.slider-cell { display: flex; flex-direction: column; gap: 2px; }

.slider-cell input[type="number"] {
  width: 100%;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.slider-cell input[type="number"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.slider-cell input[type="range"] { width: 100%; height: 13px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.slider-range { font-size: 9.5px; color: var(--text-faint); }

/* PPG Status: one radio per row, code and name to the right of the dot. */
.radio-list { display: flex; flex-direction: column; gap: 1px; }

.radio-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  line-height: 1.3;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.radio-row input { width: 13px; height: 13px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.radio-row span { overflow: hidden; text-overflow: ellipsis; }

/* ───────────────────────── Phone row ───────────────────────── */

.crow-phone {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.crow-phone .rlabel { width: var(--label-col); flex: none; align-items: flex-start; padding-top: 18px; }
.crow-phone .stack { min-width: 92px; }
.crow-phone #phone-batt-slot { width: 120px; display: flex; flex-direction: column; gap: 3px; }
.crow-phone #phone-batt-slot > span { font-size: 11px; font-weight: 500; color: var(--text-dim); }

/* Every label occupies the same height so the inputs beneath them share a
   baseline — the phone-battery cell is taller (box + slider + range) and
   would otherwise drag its neighbours out of line. */
.crow-phone .stack > span,
.crow-phone #phone-batt-slot > span { height: 15px; line-height: 15px; }

/* ───────────────────────── Trend graphs ───────────────────────── */

.graph-head { display: flex; align-items: center; gap: 14px; padding-bottom: 7px; }
.graph-title { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.graph-legend { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-dim); }
.graph-legend > span { margin-left: 8px; }
.graph-legend > span:first-child { margin-left: 0; }

.key-line  { display: inline-block; width: 14px; height: 2px; background: var(--accent); vertical-align: middle; }
.key-dot   { display: inline-block; width: 7px; height: 7px; border-radius: 50%; vertical-align: middle;
             background: var(--surface); border: 1.5px solid var(--accent); }
.key-limit { display: inline-block; width: 14px; height: 0; vertical-align: middle; border-top: 1.5px dashed var(--warn); }
.key-limit.crit { border-top-color: var(--danger); }

.graph-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.graph { min-width: 0; }
.graph-cap { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-bottom: 2px; }
.graph-cap span { font-size: 11px; font-weight: 600; color: var(--text-dim); }
.graph-cap b { font-family: var(--mono); font-size: 13px; color: var(--accent-dark); font-variant-numeric: tabular-nums; }
.graph-plot { width: 100%; height: 192px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; }

.g-line  { fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.g-dot   { fill: var(--accent); }
/* Hollow: a value the ring did not actually measure. */
.g-dot.rep { fill: var(--surface); stroke: var(--accent); stroke-width: 1.2; }
.g-axis  { stroke: var(--border-strong); stroke-width: 1; }
.g-grid  { stroke: var(--border); stroke-width: 1; }
.g-limit { stroke-width: 1.2; stroke-dasharray: 4 3; }
.g-limit.risk { stroke: var(--warn); }
.g-limit.crit { stroke: var(--danger); }
.g-limit-label { font-size: 8.5px; font-family: var(--mono); }
.g-limit-label.risk { fill: var(--warn); }
.g-limit-label.crit { fill: var(--danger); }
.g-tick  { font-size: 8.5px; font-family: var(--mono); fill: var(--text-faint); }
.g-empty { font-size: 11px; fill: var(--text-faint); }

@media (max-width: 900px) {
  .graph-row { grid-template-columns: 1fr; }
}

/* ───────────────────────── JSON panes / log ───────────────────────── */

.json-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 860px) { .json-grid { grid-template-columns: 1fr; } }

.pane h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
}

.pane pre {
  margin: 0;
  height: 210px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 11.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
}

.pane-log { margin-top: 10px; }

.log {
  height: 120px;
  overflow-y: auto;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11.5px;
}

.log-line { padding: 2px 0; color: var(--text-dim); }
.log-line time { color: var(--text-faint); margin-right: 9px; }
.log-line.ok { color: #166534; }
.log-line.err { color: #991b1b; }
.log-line.warn { color: #92400e; }

/* ───────────────────────── Buttons ───────────────────────── */

.btn {
  padding: 6px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 3px 9px; font-size: 11.5px; }
.btn-block { width: 100%; }

/* ───────────────────────── Narrow screens ───────────────────────── */

@media (max-width: 1100px) {
  .crow { grid-template-columns: var(--label-col) repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .crow { grid-template-columns: var(--label-col) repeat(2, minmax(0, 1fr)); }
}
