/* The desktop testbench's look (pbtest/theme.py): a chart recorder, not a
   dashboard. Graph paper with a blue grid and pens on it — current black,
   cell voltage blue, control voltage green, power violet — in a light grey
   chassis with engraved, condensed labels. Light on purpose: a lab in
   daylight, and the printed characteristic everyone already reads. */

:root {
  --screen: #FCFCF9;
  --graticule: #9FB7D1;
  --bg: #E9ECEF;
  --card: #F6F7F8;
  --card-border: #CBD2DA;
  --well: #FFFFFF;
  --text: #15191E;
  --muted: #66707C;

  --current: #15191E;
  --ucell: #1D5BD1;
  --uctrl: #22876A;
  --power: #7A3DBF;
  --setpoint: #7C8792;
  --breakthrough: #D18A16;

  --idle: #66707C;
  --approach: #D18A16;
  --regulate: #1E8E4E;
  --accent: #1E8E4E;
  --danger: #C3262E;
  --pending: #D18A16;

  --mono: "SF Mono", "Menlo", "DejaVu Sans Mono", "Consolas", monospace;
  --sans: "Avenir Next", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --condensed: "Avenir Next Condensed", "Avenir Next", "Helvetica Neue",
    "Arial Narrow", system-ui, sans-serif;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 var(--sans);
}

button, input, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }
.spacer { flex: 1; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* -- controls ------------------------------------------------------------- */

button, a.button {
  background: var(--well);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
a.button { display: inline-block; color: var(--text); text-decoration: none; font-size: inherit; line-height: inherit; }
button:hover:not(:disabled), a.button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--ucell);
  outline-offset: 1px;
}
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
button.accent:hover:not(:disabled), button.danger:hover:not(:disabled) { filter: brightness(1.08); }
button.link { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline; }
button.seg { min-width: 44px; }
button.seg[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }
button.small, a.button.small { padding: 3px 8px; font-size: 12px; }

input[type=text], input:not([type]), select {
  background: var(--well);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  padding: 5px 8px;
  min-width: 0;
}
input.num { font-family: var(--mono); text-align: right; width: 84px; }

label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* -- login ---------------------------------------------------------------- */

body.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background-color: var(--screen);
  background-image:
    repeating-linear-gradient(0deg, rgba(159, 183, 209, .35) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(159, 183, 209, .35) 0 1px, transparent 1px 24px);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  padding: 24px;
}
.login-card h1 {
  font: 600 28px/1.1 var(--condensed);
  margin: 0 0 8px;
}
.login-card form { display: grid; gap: 6px; margin-top: 16px; }
.login-card label { font-weight: 600; margin-top: 6px; }
.login-card input { padding: 9px 10px; font-size: 16px; }
.login-card input#code { font-family: var(--mono); letter-spacing: .06em; }
.login-card button[type=submit] { margin-top: 12px; padding: 10px; font-size: 16px; }
.login-card .error { color: var(--danger); margin: 6px 0 0; font-weight: 600; }
.known { margin-top: 22px; border-top: 1px solid var(--card-border); padding-top: 12px; }
.known h2 { font: 600 13px var(--condensed); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.known ul { list-style: none; margin: 0 0 8px; padding: 0; }
.known li a { display: flex; align-items: center; gap: 8px; padding: 6px 0; color: var(--text); text-decoration: none; font-weight: 600; }
.known li a:hover { text-decoration: underline; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--regulate); }
.dot.connecting { background: var(--pending); }
.dot.offline { background: var(--danger); }

/* -- plant page frame ------------------------------------------------------- */

body.plant { min-height: 100vh; display: flex; flex-direction: column; }

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
}
header.top h1 {
  font: 600 20px/1.1 var(--condensed);
  margin: 0;
}
header.top .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 2px; font-weight: 600; font-size: 13px;
  color: #fff; background: var(--muted); border: 1px solid transparent;
}
.pill.online { background: var(--regulate); }
.pill.connecting { background: var(--pending); }
.pill.offline { background: var(--danger); }
.pill.resting { background: var(--muted); }
.viewers { position: relative; }
.viewers button { display: inline-flex; gap: 6px; align-items: center; }
.viewers .count { font-family: var(--mono); font-weight: 600; }
.viewers ul {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
  list-style: none; margin: 0; padding: 6px 0; min-width: 180px;
  background: var(--well); border: 1px solid var(--card-border); border-radius: 2px;
  box-shadow: 0 4px 14px rgba(21, 25, 30, .12);
}
.viewers li { padding: 4px 12px; white-space: nowrap; }
.viewers li.me { font-weight: 600; }

/* The newest event, one line; the log behind it. */
.notice {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 12px 0; padding: 6px 10px;
  background: var(--card); border: 1px solid var(--card-border);
  border-left: 4px solid var(--muted); border-radius: 2px;
  min-height: 34px; cursor: pointer;
}
.notice.warn { border-left-color: var(--pending); }
.notice.fault { border-left-color: var(--danger); background: #fbeeee; }
.notice .when { font-family: var(--mono); color: var(--muted); font-size: 12px; flex: none; }
.notice .text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice .more { color: var(--muted); font-size: 12px; flex: none; }

.offline-banner {
  margin: 8px 12px 0; padding: 8px 12px; border-radius: 2px;
  background: var(--danger); color: #fff; font-weight: 600;
}
.replay-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 10px; background: #fff7e8; border: 1px solid var(--pending);
  border-radius: 2px;
}

main.body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(220px, 270px) minmax(0, 1fr) minmax(320px, 370px);
  grid-template-areas: "left center right";
  gap: 10px;
  padding: 10px 12px;
  min-height: 0;
}
.col-left { grid-area: left; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.col-center { grid-area: center; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.col-right { grid-area: right; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

@media (max-width: 1180px) {
  main.body {
    grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
    grid-template-areas: "center center" "left right";
  }
}
/* A phone reads top to bottom: what the board does, the curves, the
   controls, then the characteristic and the runs. The columns dissolve so
   their cards can take that order. */
@media (max-width: 760px) {
  main.body {
    display: flex;
    flex-direction: column;
    padding: 8px;
  }
  .col-left, .col-center, .col-right { display: contents; }
  #state-card { order: 1; }
  #replay { order: 2; }
  .paper { order: 3; }
  .foot { order: 4; }
  .col-right > .card { order: 5; }
  #plane-card { order: 6; }
  #runs-card { order: 7; }
  header.top { padding: 8px; }
  .notice, .offline-banner { margin: 8px 8px 0; }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  padding: 10px 12px;
}
.card > h2 {
  font: 600 13px var(--condensed);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 8px;
}
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

/* -- state banner ------------------------------------------------------------ */

.state-word {
  font: 600 34px/1.05 var(--condensed);
  color: var(--muted);
  overflow-wrap: anywhere;
}
.state-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; min-height: 1.3em; }
.lamps { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 10px; }
.lamp {
  font-size: 12px; font-weight: 600; text-align: center;
  padding: 3px 4px; border-radius: 2px;
  border: 1px solid var(--card-border); color: var(--card-border); background: var(--card);
}
.lamp.on.regulate { background: var(--regulate); border-color: var(--regulate); color: #fff; }
.lamp.on.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.lamp.on.pending { background: var(--pending); border-color: var(--pending); color: #fff; }

/* -- paper -------------------------------------------------------------------- */

.paper {
  flex: 1;
  min-height: 360px;
  background: var(--screen);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  padding: 4px 0 2px 0;
  overflow: hidden;
}
.trace {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 156px;
}
.trace .chart { min-width: 0; min-height: 0; position: relative; }
.reading {
  display: flex; flex-direction: column; justify-content: center;
  padding: 0 10px; border-left: 1px solid rgba(159, 183, 209, .45);
}
.reading .name { font: 600 12px var(--condensed); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.reading .value { font: 600 30px/1.05 var(--mono); white-space: nowrap; }
.reading .value small { font-size: 15px; font-weight: 500; margin-left: 3px; }
.reading .sub { font: 12px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading.current .value { color: var(--current); }
.reading.ucell .value { color: var(--ucell); }
.reading.uctrl .value { color: var(--uctrl); }
.reading.power .value { color: var(--power); }
.cursor-time { font: 12px var(--mono); color: var(--muted); text-align: right; padding: 0 8px; min-height: 1.3em; }

@media (max-width: 760px) {
  .paper { min-height: 0; flex: none; }
  .trace { flex: none; height: 190px; grid-template-columns: minmax(0, 1fr) 96px; }
  .reading .value { font-size: 22px; }
  .reading .value small { font-size: 12px; }
  .reading .sub { white-space: normal; }
}

.foot { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.foot .spacer { flex: 1; }

.plane-wrap { position: relative; aspect-ratio: 1 / 1; background: var(--screen); border: 1px solid var(--card-border); border-radius: 2px; }
.plane-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* uPlot sits on the paper: no frame of its own. */
.uplot { font-family: var(--mono); }
.u-select { background: rgba(29, 91, 209, .10); }

/* -- control panel -------------------------------------------------------------- */

.sp-row { display: flex; align-items: center; gap: 8px; }
.sp-row input[type=range] { flex: 1; min-width: 80px; accent-color: var(--text); }
.sp-amps { font-family: var(--mono); white-space: nowrap; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row > button { flex: 1; padding: 9px; }
.inline-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.fields { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 10px; align-items: center; }
.fields label { cursor: help; }
.field { display: flex; align-items: center; gap: 6px; }
.field input { flex: 1; min-width: 60px; width: 0; }
.field .unit { color: var(--muted); font-size: 12px; min-width: 42px; }
.field .mark { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.field.pending .mark { background: var(--pending); }
.field.failed .mark { background: var(--danger); }
.field.failed input { border-color: var(--danger); }

/* -- runs ------------------------------------------------------------------------- */

.runs { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; }
.runs li { padding: 7px 0; border-top: 1px solid var(--card-border); }
.runs li.shown { background: #fff7e8; }
.runs .run-name { font-weight: 600; overflow-wrap: anywhere; }
.runs .run-meta { color: var(--muted); font-size: 12px; }
.runs .run-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.capture-live { display: flex; flex-direction: column; gap: 6px; }
.capture-live .rec { color: var(--danger); font-weight: 600; }
.capture-live .rec::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); margin-right: 6px; animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .capture-live .rec::before { animation: none; } }

/* -- footer status line --------------------------------------------------------------- */

footer.status {
  padding: 4px 12px 6px; color: var(--muted); font: 12px var(--mono);
  display: flex; flex-wrap: wrap; gap: 4px 18px;
}

/* -- dialogs & log ---------------------------------------------------------------------- */

dialog {
  border: 1px solid var(--card-border);
  border-radius: 2px;
  padding: 18px 20px;
  max-width: min(560px, calc(100vw - 32px));
  background: var(--card);
  color: var(--text);
}
dialog::backdrop { background: rgba(21, 25, 30, .35); }
dialog h3 { font: 600 20px var(--condensed); margin: 0 0 8px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog dl { display: grid; grid-template-columns: auto auto; gap: 4px 16px; margin: 8px 0; }
dialog dt { color: var(--muted); }
dialog dd { margin: 0; font-weight: 600; font-family: var(--mono); }
dialog .headline { font: 600 19px var(--mono); color: var(--accent); margin: 10px 0; }
dialog ul.notes { color: var(--muted); padding-left: 18px; }
dialog input { width: 100%; }

dialog.log { width: min(760px, calc(100vw - 32px)); max-width: none; }
.log-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.log-list li { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 10px; padding: 5px 0 5px 8px; border-top: 1px solid var(--card-border); border-left: 3px solid transparent; }
.log-list li.warn { border-left-color: var(--pending); }
.log-list li.fault { border-left-color: var(--danger); }
.log-list li.local { font-style: italic; }
.log-list .when { font: 12px var(--mono); color: var(--muted); }

/* Simple mode hides what only an expert touches (pbtest: set_expert). */
body:not(.expert) .x { display: none !important; }
body.expert .s { display: none !important; }
