:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 12px;
  --tabs-h: 64px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px; background: var(--panel); }
.topbar h1 { font-size: 16px; margin: 0; }
.status { font-size: 12px; color: var(--muted); text-align: right; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

main { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; padding: 12px 16px calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); }
.view.active { display: block; }
#view-record { display: none; padding: 0 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
#view-record.active { display: flex; flex-direction: column; }
#view-map { padding: 0 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)); }

.stage { position: relative; flex: 1; min-height: 200px; background: #000; overflow: hidden; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.horizon { position: absolute; left: 0; right: 0; top: 0; height: 35%;
  background: rgba(15, 23, 42, .45); border-bottom: 1px dashed rgba(245, 158, 11, .7);
  pointer-events: none; display: none; }
.horizon span { position: absolute; bottom: 4px; right: 8px; font-size: 11px; color: var(--accent); }
.stage.live .horizon { display: block; }
.hud { position: absolute; top: 8px; left: 8px; display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.hud > div { background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 6px; }
.hud b { color: var(--accent); }
.flash { position: absolute; inset: 0; border: 6px solid var(--accent); opacity: 0; pointer-events: none; transition: opacity .4s; }
.flash.on { opacity: 1; transition: none; }
.placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; }
.stage.live .placeholder { display: none; }

.controls { display: flex; gap: 8px; padding: 10px 16px; flex-wrap: wrap; background: var(--panel); }
.controls .big { flex: 1 1 200px; }
.lastdet { padding: 0 16px 8px; font-size: 13px; color: var(--muted); background: var(--panel); min-height: 8px; }

.btn { appearance: none; border: 0; border-radius: var(--radius); background: var(--panel2); color: var(--text);
  padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer; text-align: center; display: inline-block; }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: #111; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--panel2); }
.btn.big { font-size: 17px; padding: 14px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--panel);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--panel2); z-index: 1000; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font-size: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: 11px; }
.tabs button.active { color: var(--accent); }

.toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.toolbar select, .field select { flex: 1; min-width: 0; background: var(--panel2); color: var(--text); border: 0;
  border-radius: 8px; padding: 10px; font-size: 14px; }
.summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); }
.chip i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.events li { display: flex; gap: 10px; background: var(--panel); border-radius: var(--radius); padding: 8px; align-items: center; }
.events img { width: 96px; height: 54px; object-fit: cover; border-radius: 8px; flex-shrink: 0; cursor: pointer; background: #000; }
.events .meta { flex: 1; min-width: 0; font-size: 13px; }
.events .meta b { font-size: 14px; }
.events .meta a { color: var(--accent); }
.events .del { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

#map { height: 100%; width: 100%; }
.leaflet-popup-content img { width: 220px; border-radius: 6px; display: block; margin-bottom: 4px; }

h2 { font-size: 15px; margin: 20px 0 10px; color: var(--accent); }
h2:first-child { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; border: 0; padding: 0; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field legend { margin-bottom: 6px; }
#set-classes label { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

dialog { background: var(--panel); color: var(--text); border: 0; border-radius: var(--radius);
  padding: 12px; max-width: min(96vw, 1000px); }
dialog::backdrop { background: rgba(0,0,0,.8); }
dialog img { width: 100%; border-radius: 8px; display: block; }
dialog form { margin-top: 8px; text-align: right; }
