:root {
  --bg: #0d0f12;
  --panel: #14181d;
  --panel2: #1c2127;
  --fg: #e6e6e6;
  --muted: #8a939f;
  --accent: #6cf;
  --warn: #f7a500;
  --bad: #e85a5a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 -apple-system, system-ui, sans-serif; height: 100%; overflow: hidden; }

#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid #222;
  height: 44px;
}
.brand { font-weight: 600; color: var(--accent); }
nav a { color: var(--muted); text-decoration: none; margin-right: 12px; }
nav a.active { color: var(--fg); border-bottom: 2px solid var(--accent); padding-bottom: 2px; }
#status { margin-left: auto; color: var(--muted); font-size: 12px; }

.view { position: absolute; inset: 44px 0 0 0; display: grid; }
.view[hidden] { display: none; }

/* REVIEW VIEW LAYOUT: grid + transport + sidebar */
#view-review {
  grid-template-columns: 1fr 320px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "grid     sidebar"
    "transport sidebar";
}

#grid {
  grid-area: grid;
  display: grid;
  gap: 4px;
  padding: 4px;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "doorbell doorbell"
    "porch    east";
  min-height: 0;
  background: #000;
}
#grid .pane[data-id="doorbell"] { grid-area: doorbell; }
#grid .pane[data-id="porchcam"] { grid-area: porch; }
#grid .pane[data-id="eastcam"]  { grid-area: east; }

.pane {
  position: relative;
  background: #000;
  overflow: hidden;
  border: 1px solid #222;
}
.pane.hover { border-color: var(--accent); }
.pane .vp {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transform-origin: 0 0;
  cursor: grab;
}
.pane .vp.dragging { cursor: grabbing; }
.pane video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.pane .label {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(0,0,0,0.55);
  padding: 4px 8px;
  font-size: 12px;
  letter-spacing: 0.5px;
  border-radius: 3px;
  pointer-events: none;
}
.pane .clock {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.55);
  padding: 4px 8px;
  font: 12px ui-monospace, monospace;
  border-radius: 3px;
  pointer-events: none;
}
.pane .tools {
  position: absolute;
  bottom: 8px; right: 8px;
  display: flex; gap: 6px;
}
.pane .tools button {
  background: rgba(0,0,0,0.6);
  color: var(--fg);
  border: 1px solid #333;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
}
.pane .tools button:hover { background: rgba(0,0,0,0.85); border-color: var(--accent); }
.pane .tools button.audio-on { background: rgba(108,204,255,0.25); border-color: var(--accent); }
.pane .nofootage {
  position: absolute; inset: 0;
  background: #111;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 14px;
  z-index: 2;
}
.pane .nofootage[hidden] { display: none; }

#transport {
  grid-area: transport;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid #222;
  flex-wrap: wrap;
}
#transport button {
  background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36;
  padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
#transport button:hover { border-color: var(--accent); }
#transport label { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 12px; }
#transport select, #transport input[type="number"] {
  background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36; padding: 4px 6px; border-radius: 3px;
}
.scrub-wrap {
  flex: 1; min-width: 200px; position: relative;
  height: 28px; padding: 0;
  cursor: pointer;
  user-select: none;
}
#scrub-track {
  position: absolute; left: 0; right: 0; bottom: 6px;
  height: 6px; background: #2a2f36; border-radius: 3px;
  pointer-events: none;
}
#markers {
  position: absolute; top: 0; left: 0; right: 0; height: 14px;
  pointer-events: none;
}
#playhead {
  position: absolute; top: 0; bottom: 0;
  width: 0; pointer-events: none; z-index: 5;
}
#playhead::before {
  content: ''; position: absolute;
  top: 0; left: -0.5px;
  width: 1px; height: 14px;
  background: #fff;
}
#playhead::after {
  content: ''; position: absolute;
  top: 14px; left: -1.5px;
  width: 3px; bottom: 0;
  background: #fff;
  border-radius: 1.5px;
  box-shadow: 0 0 4px rgba(255,255,255,0.4);
}
#markers .marker {
  position: absolute; top: 0; transform: translateX(-50%);
  width: 2px; height: 14px;
  background: var(--warn);
  pointer-events: auto; cursor: pointer;
  z-index: 4;
}
#markers .marker::before {
  content: ''; position: absolute; top: -2px; left: -3px;
  width: 8px; height: 4px; background: var(--warn); border-radius: 2px;
}
#markers .marker:hover { background: var(--accent); }
#markers .marker:hover::before { background: var(--accent); }
#markers .marker.bang { background: var(--bad); }
#markers .marker.bang::before { background: var(--bad); }
#markers .marker .tip {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #000; color: var(--fg); border: 1px solid var(--accent);
  padding: 4px 8px; border-radius: 3px; font-size: 11px;
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.1s;
  z-index: 10;
}
#markers .marker:hover .tip { opacity: 1; }

#range-region {
  position: absolute; top: 14px; bottom: 6px;
  background: rgba(108, 204, 255, 0.18);
  pointer-events: none;
  z-index: 2;
}
.range-handle {
  position: absolute; top: 0; bottom: 0;
  width: 12px;
  transform: translateX(-50%);
  cursor: ew-resize;
  z-index: 6;
  user-select: none;
}
.range-handle .grip {
  position: absolute; top: 14px; bottom: 0;
  left: 50%; transform: translateX(-50%);
  width: 3px; background: var(--accent);
  border-radius: 1.5px;
}
.range-handle .tag {
  position: absolute; top: 0;
  left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #001;
  font-size: 9px; font-weight: 700;
  padding: 1px 4px; border-radius: 2px;
  pointer-events: none;
  line-height: 12px;
}
.range-handle:hover .grip { background: #fff; box-shadow: 0 0 4px var(--accent); }
#time-readout { display: flex; flex-direction: column; align-items: flex-end; font: 12px ui-monospace, monospace; min-width: 160px; }
#t-bang { color: var(--fg); }
#t-wall { color: var(--muted); }

#sidebar {
  grid-area: sidebar;
  background: var(--panel);
  border-left: 1px solid #222;
  padding: 12px;
  overflow-y: auto;
}
#sidebar h3 { font-size: 13px; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.5px; }
#sidebar h3:first-child { margin-top: 0; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.row input[type="text"], .row input:not([type]) {
  flex: 1;
  background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36; padding: 6px; border-radius: 3px;
}
.row input[type="number"] {
  width: 70px; background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36; padding: 6px; border-radius: 3px;
}
#sidebar button {
  background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36;
  padding: 8px 10px; border-radius: 4px; cursor: pointer; font-size: 12px;
  display: block; width: 100%; margin-top: 6px; text-align: left;
}
#sidebar .row > button { display: inline-block; width: auto; margin-top: 0; }
#sidebar button:hover { border-color: var(--accent); }
#sidebar button.primary { background: #1e3247; border-color: #2d4f72; color: var(--fg); }
#sidebar button.primary:hover { background: #244064; border-color: var(--accent); }
.export-block .hint { color: var(--muted); font-size: 11px; margin: 4px 0; }
#ann-list, #export-list { list-style: none; padding: 0; margin: 0; }
#ann-list li, #export-list li {
  padding: 6px 8px;
  background: var(--panel2);
  border: 1px solid #222;
  border-radius: 3px;
  margin-bottom: 4px;
  font-size: 12px;
  cursor: pointer;
}
#ann-list li .t { color: var(--accent); font: 12px ui-monospace, monospace; margin-right: 6px; }
#ann-list li .del { float: right; color: var(--bad); }
#ann-list li .num {
  display: inline-block; width: 16px; height: 16px; line-height: 16px;
  text-align: center; background: var(--warn); color: #000;
  border-radius: 3px; font-weight: 600; font-size: 11px; margin-right: 4px;
}
#ann-list li.glass-break {
  border-color: var(--bad);
}
#ann-list li.glass-break .t { color: var(--bad); }
#adjustments {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #222;
}
#adjustments > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 4px 0;
  list-style: none;
}
#adjustments > summary::before { content: '▸ '; display: inline-block; transition: transform 0.1s; }
#adjustments[open] > summary::before { content: '▾ '; }
#adjustments > summary:hover { color: var(--fg); }
#adjustments h3:first-of-type { margin-top: 12px; }
#export-list a { color: var(--accent); text-decoration: none; }
#export-list a:hover { text-decoration: underline; }
.export-block label { color: var(--muted); font-size: 12px; display: block; margin: 4px 0; }

/* SYNC VIEW */
#view-sync { grid-template-rows: auto 1fr; padding: 12px; }
.sync-help { color: var(--muted); margin: 0 0 12px; max-width: 900px; }
#sync-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  min-height: 0;
}
.sync-pane { background: var(--panel); border: 1px solid #222; padding: 8px; display: flex; flex-direction: column; }
.sync-pane h4 { margin: 0 0 6px; font-size: 13px; color: var(--accent); }
.sync-pane video { width: 100%; height: 50vh; background: #000; object-fit: contain; }
.sync-pane .marks { margin-top: 8px; font: 12px ui-monospace, monospace; color: var(--muted); }
.sync-pane .marks.set { color: var(--accent); }
.sync-pane .controls { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.sync-pane .controls button { background: var(--panel2); color: var(--fg); border: 1px solid #2a2f36; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.sync-pane .controls button.mark { background: #2a4a2a; border-color: #3c6c3c; }
.sync-pane .controls button.mark.set { background: #1a3a1a; }
kbd { background: #222; padding: 1px 6px; border-radius: 3px; font-size: 11px; }

/* CAR ID VIEW */
#view-car-id:not([hidden]) { display: block; overflow-y: auto; padding: 24px; }
.car-id-page { max-width: 1100px; margin: 0 auto; padding-bottom: 64px; }
.car-id-head h1 { margin: 0 0 8px; color: var(--accent); font-size: 22px; }
.car-id-head .lede { color: var(--fg); font-size: 14px; line-height: 1.55; margin: 0 0 24px; max-width: 800px; }
.car-id-block { margin-bottom: 28px; }
.car-id-block h2 {
  font-size: 13px; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid #222; padding-bottom: 6px; margin: 0 0 12px;
}
.evidence-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 12px; }
.evidence-row.three { grid-template-columns: repeat(3, 1fr); }
.evidence-row.single { grid-template-columns: 1fr; }
.evidence-row figure img { display: block; width: 100%; background: #000; }
.evidence-row figure, .reference-figure { margin: 0; background: var(--panel); border: 1px solid #222; border-radius: 4px; overflow: hidden; }
.evidence-row video, .reference-figure img { display: block; width: 100%; background: #000; }
.evidence-row figcaption, .reference-figure figcaption {
  padding: 8px 12px; color: var(--muted); font-size: 12px; line-height: 1.45;
}
.reference-figure img { max-height: 60vh; object-fit: contain; }
.match-list { margin: 0; padding-left: 22px; line-height: 1.55; }
.match-list li { margin-bottom: 8px; }
.match-list li strong { color: var(--accent); }
.callout {
  background: var(--panel); border: 1px solid var(--accent);
  padding: 14px 18px; border-radius: 4px; line-height: 1.55;
  color: var(--fg);
}
.callout strong { color: var(--accent); }
.candidate {
  background: var(--panel); border: 1px solid #222; border-radius: 4px;
  padding: 16px; margin-bottom: 16px;
}
.candidate-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.candidate-head h3 { margin: 0; font-size: 16px; color: var(--fg); }
.candidate-head h3 .years { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 4px; }
.candidate-head .confidence {
  font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--accent); border: 1px solid var(--accent); padding: 2px 8px; border-radius: 3px;
}
.candidate .reference-figure { margin-bottom: 0; }
.ref-gallery {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.candidate-points h4 {
  margin: 12px 0 4px; font-size: 12px; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--muted);
}
.candidate-points h4:first-child { margin-top: 0; }

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid #2a2f36;
  border-radius: 6px;
  padding: 24px 28px;
  max-width: 520px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.modal-card h2 { margin: 0 0 12px; color: var(--accent); font-size: 18px; }
.modal-card p { margin: 0 0 10px; line-height: 1.5; }
.modal-card .hint { color: var(--muted); font-size: 12px; }
.modal-card button {
  margin-top: 14px;
  background: #1e3247; border: 1px solid #2d4f72; color: var(--fg);
  padding: 8px 18px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.modal-card button:hover { border-color: var(--accent); }
