:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1d2125;
  --muted: #5d656e;
  --line: #d8dcd9;
  --accent: #d2541b;
  --ok: #17803c;
  --warn: #a16207;
  --bad: #b42318;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181b;
    --surface: #1d2226;
    --ink: #e7e9eb;
    --muted: #9aa2ab;
    --line: #30363c;
    --accent: #f08a55;
    --ok: #4ade80;
    --warn: #facc15;
    --bad: #f87171;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font);
  padding-inline: 16px;
  padding-block: 24px 48px;
}
main { max-width: 1100px; margin: 0 auto; display: grid; gap: 20px; }
header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
h1 { margin: 0; font-size: 1.4rem; }
nav { display: flex; gap: 14px; }
a { color: var(--accent); }
form.panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
input, select {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}
button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: 9px 16px;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.status { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: grid; }
.tile .videos { display: grid; gap: 2px; background: var(--line); }
.tile video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; object-fit: contain; }
.tile .bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; }
.tile .name { font-family: var(--mono); font-size: 0.9rem; overflow-wrap: anywhere; }
.chip { font-family: var(--mono); font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.chip.live { color: var(--ok); }
.chip.waking { color: var(--warn); }
.chip.sleeping { color: var(--muted); }
.chip.offline { color: var(--bad); }
.chip.ready, .chip.control { color: var(--ok); }
.chip.negotiating { color: var(--warn); }
.chip.joined { color: var(--muted); }
.chip.away { color: var(--bad); }
.empty { color: var(--muted); }
pre.log {
  margin: 0;
  font: 0.8rem/1.5 var(--mono);
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.preview video { width: 100%; max-width: 480px; aspect-ratio: 16 / 9; background: #000; border-radius: 6px; }
@media (prefers-reduced-motion: no-preference) { button { transition: opacity 0.15s; } }

/* Collapsible panels: log and server state */
details.panel > summary, .debug summary { cursor: pointer; font-weight: 600; }
details.panel[open] > summary { margin-bottom: 12px; }
.debug > div { display: grid; gap: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.table-wrap table { border-collapse: collapse; width: 100%; font: 0.78rem/1.45 var(--mono); }
.table-wrap th, .table-wrap td { text-align: left; vertical-align: top; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: pre-line; }
.table-wrap th { color: var(--muted); font-weight: 600; background: var(--bg); white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: 0; }

[hidden] { display: none !important; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 0.95rem; padding-block: 9px; }
label.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
button.small { padding: 4px 12px; font-size: 0.82rem; }

/* IPC: a window per device on the viewer, one panel on the device simulator */
.ipc { display: grid; gap: 8px; }
.tile .ipc { border-top: 1px solid var(--line); padding: 10px 12px 12px; }
.ipc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.ipc-head h2 { margin: 0; font-size: 1rem; }
.ipc-head .control { flex: 1 1 12rem; min-width: 0; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.ipc-head .control.mine { color: var(--ok); font-weight: 600; }
.ipc-send { display: flex; gap: 6px; }
.ipc-send input { flex: 1; }
.ipc-send select { flex: none; padding-inline: 6px; }
.ipc-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 160px; overflow: auto; font: 0.78rem/1.45 var(--mono); }
.ipc-log:empty { display: none; }
.ipc-log li { overflow-wrap: anywhere; }
.ipc-log .out { color: var(--accent); }
.ipc-log .note { color: var(--muted); }

/* Dashboard */
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.total { display: grid; gap: 2px; }
.total .label { font-size: 0.85rem; color: var(--muted); }
.total .value { font-size: 2rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.rooms { display: grid; gap: 12px; }
.rooms-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.rooms-head h2 { margin: 0; font-size: 1.05rem; }
.refresh { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.refresh label { display: flex; align-items: center; gap: 6px; }
.refresh select { padding: 4px 8px; }
tr.room { cursor: pointer; }
tr.room:hover td, tr.room:focus-visible td { background: var(--bg); }
tr.room-details > td { background: var(--bg); padding: 12px; }
.debug-body { display: grid; gap: 12px; }
.chip.unwatched { color: var(--muted); border-style: dashed; }
