:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #0e141c;
  --line: #1e2733;
  --text: #d8e0ea;
  --muted: #6b7886;
  --accent: #00e676;
  --crit: #ff4d4f;
  --warn: #faad14;
  --info: #4aa3ff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 15px; letter-spacing: .3px; }
.brand strong { color: var(--accent); }
.dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); margin-right: 8px; vertical-align: middle;
  transition: background .3s, box-shadow .3s;
}
.dot.online { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.offline { background: var(--crit); box-shadow: 0 0 8px var(--crit); }
.stats { display: flex; gap: 22px; }
.stat { display: flex; flex-direction: column; line-height: 1.25; }
.stat label { font-size: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .6px; }
.stat b { font-size: 14px; font-variant-numeric: tabular-nums; }

.grid {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px;
  grid-template-rows: minmax(0, 1fr); gap: 14px; padding: 14px; overflow: hidden;
}
.video-pane { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; }

/* live count dashboard (KPI strip) */
.kpi-strip { display: flex; gap: 12px; flex: none; }
.kpi {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; display: flex; flex-direction: column; gap: 1px; position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--muted); }
.kpi.people::before { background: var(--accent); }
.kpi.vehicles::before { background: var(--info); }
.kpi.trucks::before { background: var(--warn); }
.kpi.animals::before { background: #34d27f; }
.kpi.total::before { background: #fff; }
.kpi .num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi.people .num { color: var(--accent); }
.kpi.vehicles .num { color: var(--info); }
.kpi.trucks .num { color: var(--warn); }
.kpi.animals .num { color: #34d27f; }
.kpi.total .num { color: #fff; }
.kpi .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.kpi .num.bump { animation: numbump .3s ease; }
@keyframes numbump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
.video-wrap {
  position: relative; flex: 1; min-height: 0; background: #000; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: contain; }
.video-wrap:fullscreen { border: none; border-radius: 0; }
.video-wrap:fullscreen #video { width: 100vw; height: 100vh; }
.video-badge {
  position: absolute; top: 12px; left: 12px; padding: 5px 10px; border-radius: 6px;
  background: rgba(0,0,0,.6); font-size: 11px; letter-spacing: 1px; color: var(--warn);
}

/* video hover controls (fullscreen / snapshot) */
.vid-controls {
  position: absolute; top: 10px; right: 10px; display: flex; gap: 6px;
  opacity: 0; transition: opacity .2s;
}
.video-wrap:hover .vid-controls, .video-wrap:fullscreen .vid-controls { opacity: 1; }
.vid-btn {
  width: 34px; height: 34px; border-radius: 7px; cursor: pointer; font-size: 16px; line-height: 1;
  background: rgba(0,0,0,.55); color: #fff; border: 1px solid rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
}
.vid-btn:hover { background: rgba(0,0,0,.8); border-color: var(--accent); color: var(--accent); }

.tracks, .events-pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.tracks { flex: none; height: 210px; display: flex; flex-direction: column; }
.tracks-scroll { flex: 1; overflow-y: auto; }
.tracks h3, .events-pane h3 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.count {
  font-size: 11px; color: var(--accent); background: rgba(0,230,118,.12);
  border-radius: 10px; padding: 1px 8px; letter-spacing: 0; font-variant-numeric: tabular-nums;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 4px 6px;
  position: sticky; top: 0; background: var(--panel); }
td { padding: 5px 6px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.events-pane { overflow: hidden; display: flex; flex-direction: column; }
.events { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.events li {
  padding: 9px 11px; margin-bottom: 7px; border-radius: 7px; font-size: 13px;
  background: var(--panel-2); border-left: 3px solid var(--info);
  animation: slidein .25s ease;
}
.events li.critical { border-left-color: var(--crit); }
.events li.warning { border-left-color: var(--warn); }
.events li.info { border-left-color: var(--info); }
.events li .row { display: flex; justify-content: space-between; gap: 8px; }
.events li .msg { font-weight: 500; }
.events li time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.badge {
  display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  padding: 1px 6px; border-radius: 4px; margin-top: 4px;
}
.badge.critical { background: rgba(255,77,79,.15); color: var(--crit); }
.badge.warning { background: rgba(250,173,20,.15); color: var(--warn); }
.badge.info { background: rgba(74,163,255,.15); color: var(--info); }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* --- admin / settings panel --- */
.gear {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 12px; cursor: pointer; font-size: 13px;
  align-self: center;
}
.gear:hover { border-color: var(--accent); color: var(--accent); }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 50; padding: 24px; overflow-y: auto;
}
.overlay.hidden { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 620px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.x:hover { color: var(--text); }
.modal-body { padding: 16px 20px; }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 14px 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--accent); letter-spacing: .3px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 6px 0; }
.hint.warn { color: var(--warn); }
.hint b { color: var(--text); }

.rtmp { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.rtmp code {
  flex: 1; background: #000; border: 1px solid var(--line); border-radius: 6px;
  padding: 9px 11px; font-size: 13px; color: var(--accent); overflow-x: auto;
}
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.radio { display: flex; gap: 9px; align-items: flex-start; padding: 7px 0; font-size: 13px; cursor: pointer; }
.radio input { margin-top: 2px; }
.radio b { color: var(--text); }
.text {
  width: 100%; margin-top: 8px; background: #000; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; font-size: 13px;
}
.text:disabled { opacity: .4; }

.field { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.field label { width: 130px; font-size: 13px; color: var(--muted); }
.field label b { color: var(--accent); }
.field select, .field input[type="range"] { flex: 1; }
.field select {
  background: #000; color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
}

.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.btn {
  background: var(--accent); color: #062; font-weight: 700; border: none;
  border-radius: 7px; padding: 10px 18px; cursor: pointer; font-size: 13px;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 9px 12px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.btn-sm:hover { border-color: var(--accent); }

/* --- "Start drone demo" wizard --- */
.cta {
  background: var(--accent); color: #062; font-weight: 700; border: none;
  border-radius: 7px; padding: 8px 14px; cursor: pointer; font-size: 13px;
  align-self: center; box-shadow: 0 0 0 0 rgba(0,230,118,.5); animation: pulse 2.4s infinite;
}
.cta:hover { filter: brightness(1.1); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(0,230,118,.45); }
  70% { box-shadow: 0 0 0 10px rgba(0,230,118,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,230,118,0); }
}
.modal.wizard { max-width: 640px; }
.hidden { display: none; }

.stepper {
  display: flex; gap: 8px; list-style: none; margin: 0; padding: 14px 20px 0;
  font-size: 12px; color: var(--muted);
}
.stepper li { display: flex; align-items: center; gap: 7px; flex: 1; }
.stepper li span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 700; font-size: 12px; flex: none;
}
.stepper li.active { color: var(--text); }
.stepper li.active span { background: var(--accent); color: #062; border-color: var(--accent); }
.stepper li.done span { background: rgba(0,230,118,.15); color: var(--accent); border-color: var(--accent); }

.opt { color: var(--muted); font-weight: 400; }
.wz-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.btn-sm.ghost { background: transparent; }

.handoff {
  background: #000; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; margin: 6px 0 10px; max-height: 280px; overflow: auto;
}
.handoff pre {
  margin: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px; line-height: 1.55; color: var(--text); white-space: pre-wrap; word-break: break-word;
}
.handoff pre .url { color: var(--accent); font-weight: 700; }

.checklist {
  margin-top: 14px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 12px 14px;
}
.checklist h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.checklist label { display: flex; gap: 9px; align-items: flex-start; padding: 5px 0; font-size: 13px; cursor: pointer; }
.checklist input { margin-top: 2px; }
.checklist b { color: var(--text); }

.waiting, .live-ok { text-align: center; padding: 26px 10px 14px; }
.waiting h3, .live-ok h3 { margin: 14px 0 6px; font-size: 16px; }
.spinner {
  width: 46px; height: 46px; margin: 0 auto; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.big-check {
  width: 56px; height: 56px; margin: 0 auto; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 800;
  background: rgba(0,230,118,.15); color: var(--accent); border: 2px solid var(--accent);
  animation: pop .3s ease;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 900px) {
  /* Let the page scroll vertically instead of clipping to viewport height. */
  html, body { height: auto; overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .stats { gap: 12px; flex-wrap: wrap; width: 100%; }
  .grid {
    grid-template-columns: 1fr; grid-template-rows: none;
    overflow: visible; height: auto; padding: 12px;
  }
  .video-pane, .events-pane { min-height: 0; }
  /* KPI tiles wrap to a 2-up grid so the numbers stay readable on phones. */
  .kpi-strip { flex-wrap: wrap; }
  .kpi { flex: 1 1 calc(50% - 6px); min-width: 120px; }
  .video-wrap { aspect-ratio: 16 / 9; height: auto; min-height: 220px; }
  #video { height: 100%; }
  .events-pane { max-height: 320px; }
  .modal { width: 96vw; max-width: 96vw; margin: 0 auto; max-height: 92vh; overflow: auto; }
  .stepper li { font-size: 0; gap: 0; }   /* compact: numbers only on small screens */
  .stepper li span { font-size: 12px; }
}

@media (max-width: 480px) {
  .kpi { flex: 1 1 100%; }
  .stat { flex: 1 1 auto; }
  .brand { font-size: 13px; }
}
