:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #191b20;
  --panel-2: #22252b;
  --line: #30343c;
  --text: #eceef1;
  --muted: #a0a6b0;
  --amber: #f2b134;
  --red: #ef4444;
  --green: #4ade80;
  --warn: #fbbf24;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
h2 { margin: 0; font-size: 15px; font-weight: 600; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.brand svg { width: 22px; height: 22px; fill: var(--amber); }
.clock { display: flex; align-items: baseline; gap: 8px; }
.tc { font: 600 22px/1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock-meta { color: var(--muted); font-size: 12px; }
.summary { color: var(--muted); font-size: 13px; flex: 1 1 140px; min-width: 0; }
.summary strong { color: var(--text); font-weight: 600; }
.summary .rec { color: var(--red); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: #565c68; }
.btn:focus-visible, .mini:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.btn[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }
.btn-primary { background: var(--amber); border-color: var(--amber); color: #1b1404; }
.btn-record { background: #4a1616; border-color: #7f2323; }
.btn-record:hover { border-color: var(--red); }
.btn-stop.armed { background: var(--red); border-color: var(--red); color: #fff; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); }
.square { width: 11px; height: 11px; background: currentColor; border-radius: 2px; }

.banner { padding: 8px 16px; background: #5a3b05; color: #ffe2a8; font-weight: 600; }
.banner[hidden] { display: none; }

.layout { flex: 1; min-height: 0; display: flex; }
.tiles {
  flex: 1; min-width: 0; overflow-y: auto; padding: 12px;
  display: grid; gap: 12px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  /* Tiles clip their overflow, so without this the rows squash to fit the panel. */
  grid-auto-rows: max-content;
}
.empty {
  grid-column: 1 / -1; padding: 64px 16px; text-align: center; color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 6px; }

.side {
  width: 360px; flex: none; display: flex; flex-direction: column;
  border-left: 1px solid var(--line); background: var(--panel);
}
.side[hidden] { display: none; }
.map { flex: 1 1 60%; min-height: 220px; background: #1d2026; }
.log-wrap { flex: 1 1 40%; min-height: 120px; display: flex; flex-direction: column; border-top: 1px solid var(--line); padding: 10px 12px 0; }
.log { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; font-size: 12px; color: var(--muted); }
.log li { padding: 3px 0; display: flex; gap: 8px; }
.log time { font-family: var(--mono); flex: none; }
.log .warn { color: var(--warn); }
.log .error { color: #fca5a5; }

.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; display: flex; flex-direction: column; min-width: 0;
}
.tile.recording { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.tile.offline { opacity: .72; }
.view { position: relative; aspect-ratio: 16 / 9; background: #000; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.no-signal {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .06em;
}
.badge-row { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; justify-content: space-between; gap: 6px; pointer-events: none; }
.badge {
  padding: 2px 7px; border-radius: 5px; background: rgba(0,0,0,.72); color: #fff;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.name { overflow: hidden; text-overflow: ellipsis; }
.badge.rec { background: var(--red); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.meter { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.5); }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width .1s linear; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.stat { background: var(--panel); padding: 4px 8px; min-width: 0; }
.stat.wide { grid-column: span 2; }
.stat dt { color: var(--muted); font-size: 11px; }
.stat dd { margin: 0; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat dd.warn { color: var(--warn); }
.stat dd.bad { color: #fca5a5; }
.stats { margin: 0; }

.applied { padding: 5px 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; min-height: 28px; }
.applied.pending { color: var(--warn); }
.zoom-row { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.zoom-row input { flex: 1; min-width: 0; height: 28px; accent-color: var(--amber); touch-action: none; }
.zoom-row output { width: 40px; text-align: right; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.mini {
  min-height: 38px; padding: 0 6px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.mini:hover:not(:disabled) { border-color: #565c68; }
.mini:disabled { opacity: .45; cursor: not-allowed; }
.mini.on { background: #143d24; border-color: var(--green); color: #bbf7d0; }
.mini.recording { background: var(--red); border-color: var(--red); color: #fff; }

.map-pin {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--amber); color: #1b1404; font-weight: 700; font-size: 12px; border: 2px solid #1b1404;
}
.map-pin.recording { background: var(--red); color: #fff; }
.map-pin.offline { background: #6b7280; color: #fff; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 12px; border-radius: 8px; background: #3a1d1d; border: 1px solid #7f2323; color: #fecaca; font-weight: 600; }
.toast.warn { background: #3b2c0c; border-color: #7a5a10; color: #fde68a; }

.dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
.dialog-wide { width: min(640px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.65); }
.dialog h2 { font-size: 17px; margin-bottom: 8px; }
.dialog label { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.dialog input:not([type="checkbox"]), .dialog select {
  min-height: 40px; padding: 0 10px; width: 100%;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 16px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.note { color: var(--muted); margin: 0 0 8px; font-size: 13px; }
.note code { color: var(--text); word-break: break-all; }
.note.warn-note { color: var(--warn); }
.error { color: #fca5a5; margin: 8px 0 0; }
.error[hidden] { display: none; }
.form-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0; padding: 4px 12px 12px; min-width: 0; }
legend { padding: 0 6px; color: var(--amber); font-weight: 600; font-size: 13px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog input:disabled, .dialog select:disabled { opacity: .45; }
.checks { margin-top: 10px; }
.dialog .checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; font-weight: 400; min-height: 32px; margin: 0; }
.checks input { width: 18px; height: 18px; accent-color: var(--amber); }
.qr { display: flex; justify-content: center; background: #fff; padding: 12px; border-radius: 8px; margin: 8px 0; }
.qr img, .qr svg { width: 100%; max-width: 280px; height: auto; display: block; }

@media (max-width: 900px) {
  .layout { flex-direction: column; overflow-y: auto; }
  .tiles { overflow: visible; flex: none; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
  .side { width: 100%; border-left: 0; border-top: 1px solid var(--line); flex: none; }
  .map { flex: none; height: 300px; }
  .log-wrap { flex: none; height: 180px; }
}
@media (max-width: 560px) {
  .form-columns { grid-template-columns: 1fr; }
  .summary { order: 3; flex-basis: 100%; }
}
