/*
 * Colloquy app-page shared theme (/shared/app-theme.css)
 *
 * ONE stylesheet for the plain app-page family (/transmitter, /sensor-demo,
 * and — when its next revision adopts it — /sensor). It extracts the display
 * client's look (display/index.html palette + panel/button idioms, the same
 * scheme the sensor page already uses inline) so every page reads as one
 * product. Page-specific CSS stays minimal on top of this file.
 *
 * The display client itself keeps its own inline styles — do NOT link this
 * file from display/index.html.
 *
 * Served at /shared/app-theme.css (prepare-public copies shared/ into
 * public/; the local dev servers serve the repo root directly).
 */

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

:root {
  --bg: #05070a;
  --panel: rgba(16, 21, 29, 0.88);
  --panel-solid: #10151d;
  --line: rgba(151, 163, 184, 0.26);
  --line-faint: rgba(151, 163, 184, 0.18);
  --text: #edf2f7;
  --muted: #9aa8ba;
  --blue: #5aa8ff;
  --green: #4ade80;
  --amber: #f5c451;
  --red: #fb7185;
  --field: rgba(7, 10, 16, 0.72);
  --field-deep: rgba(5, 7, 10, 0.42);
  --radius: 6px;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

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

/* ── Header idiom (brand mark + title + subtitle) ────────────────────────── */

header.app-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark { width: 32px; height: 32px; flex: 0 0 auto; }
.app-header h1 { margin: 0; font-size: 14px; font-weight: 650; }
.subtitle { color: var(--muted); font-size: 11px; }
.header-spacer { flex: 1; }

.back-btn {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(27, 34, 45, 0.94);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.back-btn:hover { border-color: rgba(90, 168, 255, 0.72); color: var(--blue); text-decoration: none; }

/* ── Panel idiom ─────────────────────────────────────────────────────────── */

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.panel-title {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Readout tiles (fixed sets — values render "-" when empty) ───────────── */

.readouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 7px;
}

.readout {
  border: 1px solid var(--line-faint);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--field-deep);
  min-width: 0;
}

.readout span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 2px; }
.readout strong { display: block; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ── Stable status rows (never hidden, never resized — "-" when empty) ───── */

.stream-rows { display: grid; gap: 6px; }
.stream-row {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line-faint);
  border-radius: var(--radius);
  background: var(--field-deep);
  padding: 6px 7px;
  min-height: 40px;
}
.stream-row span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.stream-row strong {
  font-size: 12px;
  font-weight: 650;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

/* ── Labeled slider/select rows ──────────────────────────────────────────── */

label.control-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

label.control-row .value {
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Fields + buttons ────────────────────────────────────────────────────── */

input, select, button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font: inherit;
  height: 28px;
  min-width: 0;
}

input[type="range"] { padding: 0; border: none; background: transparent; accent-color: #5b8cff; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: #5b8cff; cursor: pointer; }
input[type="number"], input[type="text"], input[type="email"], input[type="password"], select { padding: 0 6px; }
button { padding: 0 12px; cursor: pointer; background: rgba(27, 34, 45, 0.94); }
button:hover { border-color: rgba(90, 168, 255, 0.72); }
button:disabled { opacity: 0.48; cursor: default; }
.primary { background: #16324f; border-color: rgba(90, 168, 255, 0.72); }
.danger { border-color: rgba(251, 113, 133, 0.6); }

/* ── Misc idioms ─────────────────────────────────────────────────────────── */

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.4; margin: 0; }

/* ── Control-panel app shell (ADDITIVE — opt-in via classes) ─────────────────
   Desktop control-panel layout for /sensor + /actuator: a toolbar header, a
   tab bar, a slim always-visible status strip, and a viewport-filling tabbed
   body with NO page scroll. Pages opt in with class="app-noscroll" on <html>
   and class="app-shell" on <body>; nothing here touches the existing idioms
   used by /transmitter and /sensor-demo. */

html.app-noscroll, html.app-noscroll body { height: 100%; overflow: hidden; }
body.app-shell { display: flex; flex-direction: column; height: 100dvh; }
body.app-shell main.tab-content { flex: 1; min-height: 0; padding: 12px; }

@media (max-width: 760px) {
  /* Small screens fall back to normal page scroll — no-scroll is a desktop
     control-panel contract, not a phone one. */
  html.app-noscroll, html.app-noscroll body { height: auto; overflow: auto; }
  body.app-shell { height: auto; min-height: 100dvh; }
}

/* ── Toolbar header (brand + tool groups; display-client idiom) ──────────── */

header.app-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.app-toolbar .brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.app-toolbar h1 { margin: 0; font-size: 13px; font-weight: 650; white-space: nowrap; }
.app-toolbar .subtitle { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-spacer { flex: 1; }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--line-faint);
  border-radius: var(--radius);
  background: var(--field-deep);
}
.toolbar-group > label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.toolbar-group > label[hidden], .toolbar-group > [hidden] { display: none; }
.toolbar-group input, .toolbar-group select, .toolbar-group button { height: 26px; }
.toolbar-group strong { font-size: 11px; font-weight: 650; white-space: nowrap; }

/* ── Status chip (connection state at a glance) ──────────────────────────── */

.status-chip {
  /* block + line-height (not flex) so long text can ellipsize */
  display: block;
  height: 22px;
  line-height: 20px;
  max-width: 320px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field-deep);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-chip[data-state="ok"] { border-color: rgba(74, 222, 128, 0.6); color: var(--green); }
.status-chip[data-state="pending"] { border-color: rgba(245, 196, 81, 0.6); color: var(--amber); }
.status-chip[data-state="error"] { border-color: rgba(251, 113, 133, 0.6); color: var(--red); }

/* ── Torque state (color-coded readout + toggle; /actuator servo cards) ──────
   Mirrors the status-chip data-state idiom: torque ON = active/green, OFF =
   attention/amber, unsupported or disconnected = neutral/muted. Not color-only —
   callers keep the ON/off/- text and the toggle's word label. Additive: opt-in
   via the .torque-state / .torque-toggle classes; nothing else references them. */
.torque-state[data-state="on"] { color: var(--green); }
.torque-state[data-state="off"] { color: var(--amber); }
.torque-state[data-state="muted"] { color: var(--muted); }
button.torque-toggle[data-state="on"] { border-color: rgba(74, 222, 128, 0.6); color: var(--green); }
button.torque-toggle[data-state="off"] { border-color: rgba(245, 196, 81, 0.6); color: var(--amber); }
button.torque-toggle[data-state="muted"] { color: var(--muted); }

/* ── Modal dialog + backdrop (display-client admin-modal idiom, generic) ─── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 14, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(380px, calc(100vw - 32px));
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(16, 21, 29, 0.98);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title { margin: 0; font-size: 15px; font-weight: 650; }
.modal-sub { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal input { height: 32px; padding: 0 8px; }
.modal-note { margin: 0; min-height: 16px; font-size: 12px; color: var(--amber); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 4px;
  padding: 6px 12px 0;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.tab-btn {
  height: 30px;
  padding: 0 16px;
  border: 1px solid var(--line-faint);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--field-deep);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.tab-btn:hover { color: var(--text); }
.tab-btn[aria-selected="true"] {
  background: rgba(22, 50, 79, 0.7);
  border-color: rgba(90, 168, 255, 0.5);
  color: var(--text);
}
.tab-panel[hidden] { display: none; }
.tab-panel { height: 100%; min-height: 0; }

/* ── Status strip (slim fixed single row under the tab bar) ──────────────── */

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  overflow: hidden;
}
.strip-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--line-faint);
  border-radius: var(--radius);
  background: var(--field-deep);
  min-width: 0;
}
.strip-cell > span {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.strip-cell > strong {
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.strip-cell select { height: 24px; }
.strip-grow { flex: 1; }
