:root {
  --bg: #070b11;
  --bg-2: #0b1119;
  --text: #e8edf3;
  --muted: #8794a3;
  --accent: #4da3ff;
  --accent-dim: rgba(77, 163, 255, 0.15);
  --ok: #4ade80;
  --bad: #ff5c5c;
  --rec: #ff4d4d;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-border: rgba(255, 255, 255, 0.08);
  --radius: 18px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 20% -10%, #11203a 0%, transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, #15233b 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

.hidden { display: none !important; }

/* ── Glass primitive ─────────────────────────────────────────── */
.glass {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Top bar ─────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 24px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent-dim); color: var(--accent); font-size: 1.1rem;
}
.brand-name { font-weight: 650; font-size: 1.05rem; }

.topnav { display: flex; gap: 6px; margin: 0 auto; }
.topnav-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 9px 18px; border-radius: 12px; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 8px; transition: all 0.15s;
}
.topnav-btn:hover { color: var(--text); }
.topnav-btn.active {
  color: var(--accent); background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(77, 163, 255, 0.25);
}

.conn-pill {
  border: 1px solid var(--glass-border); background: var(--glass);
  color: var(--bad); padding: 8px 16px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; min-width: 120px;
}
.conn-pill.ok { color: var(--ok); }

.banner {
  margin: 0 24px 8px; padding: 12px 16px; border-radius: 12px;
  background: rgba(255, 196, 0, 0.1); border: 1px solid rgba(255, 196, 0, 0.2);
  color: #ffd479; font-size: 0.88rem;
}

/* ── Layout ──────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 250px 1fr 330px;
  gap: 18px;
  padding: 6px 24px 24px;
  align-items: start;
}
.col-cameras { padding: 14px; position: sticky; top: 10px; }
.col-main { min-width: 0; }
.col-right { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 10px; }

/* ── Camera sidebar ──────────────────────────────────────────── */
.camera-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.camera-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 14px; cursor: pointer; transition: background 0.15s;
}
.camera-item:hover { background: rgba(255, 255, 255, 0.04); }
.camera-item.active {
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(77, 163, 255, 0.3), 0 0 24px rgba(77, 163, 255, 0.12);
}
.camera-thumb {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06); display: grid; place-items: center; color: var(--muted);
}
.camera-item.active .camera-thumb { background: var(--accent); color: #06121f; }
.camera-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.camera-name { font-size: 0.92rem; font-weight: 550; }
.camera-status { font-size: 0.74rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.bad { background: var(--bad); }
.add-camera {
  width: 100%; padding: 13px; border-radius: 14px; cursor: pointer;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--glass-border);
  color: var(--text); font-size: 0.9rem;
}

/* ── Feed card ───────────────────────────────────────────────── */
.feed-card { padding: 18px; }
.feed-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.feed-head h1 { font-size: 1.5rem; margin: 0; }
.live-badge {
  font-size: 0.78rem; color: var(--ok); background: rgba(74, 222, 128, 0.12);
  padding: 4px 12px; border-radius: 999px; font-weight: 600;
}
.live-badge.bad { color: var(--bad); background: rgba(255, 92, 92, 0.12); }
.feed-head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.res-select {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--glass-border);
  padding: 8px 14px; border-radius: 12px; font-size: 0.85rem; color: var(--text);
}
.icon-btn {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--glass-border);
  width: 38px; height: 38px; border-radius: 12px; color: var(--text);
  cursor: pointer; font-size: 1rem;
}

.video-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: 14px; overflow: hidden;
}
#live-video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transform-origin: 0 0; transition: transform 0.08s ease-out;
}
#live-video.no-anim { transition: none; }
#live-video.zoomed { cursor: grab; }
#live-video.panning { cursor: grabbing; }

.zoom-controls {
  position: absolute; top: 12px; left: 12px; z-index: 2;
  display: flex; align-items: center; gap: 2px; padding: 4px;
  background: rgba(10, 14, 20, 0.7); backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); border-radius: 999px;
}
.zoom-btn {
  width: 30px; height: 30px; border: none; background: transparent;
  color: var(--text); border-radius: 50%; cursor: pointer; font-size: 1.05rem; line-height: 1;
}
.zoom-btn:hover { background: rgba(255, 255, 255, 0.12); }
.zoom-level { font-size: 0.74rem; color: var(--muted); min-width: 36px; text-align: center; }
.live-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 0.9rem; text-align: center; padding: 20px;
}
.floating-controls {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 8px 10px;
  background: rgba(10, 14, 20, 0.7); backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); border-radius: 999px;
  transition: opacity 0.35s ease;
}
/* Fade controls away when idle; moving over the video brings them back. */
.video-wrap.controls-idle .floating-controls,
.video-wrap.controls-idle .zoom-controls { opacity: 0; pointer-events: none; }
.zoom-controls { transition: opacity 0.35s ease; }
.fc-btn {
  background: transparent; border: none; color: var(--text);
  width: 44px; height: 44px; border-radius: 999px; cursor: pointer; font-size: 1.05rem;
  transition: background 0.15s;
}
.fc-btn:hover { background: rgba(255, 255, 255, 0.1); }
.fc-btn.recording { color: var(--rec); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ── Timeline ────────────────────────────────────────────────── */
.timeline-card { margin-top: 16px; }
.timeline-head { display: flex; align-items: center; margin-bottom: 12px; }
.timeline-day { font-size: 1rem; font-weight: 550; }
.timeline-filter { margin-left: auto; }
.chip {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--glass-border);
  padding: 6px 14px; border-radius: 12px; font-size: 0.82rem; color: var(--muted);
}
.timeline {
  position: relative; height: 26px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.03); overflow: hidden;
}
.timeline-rec {
  position: absolute; top: 50%; transform: translateY(-50%);
  height: 6px; background: rgba(77, 163, 255, 0.25); border-radius: 3px;
}
.timeline-event {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 8px; height: 16px; border-radius: 3px; background: var(--accent);
  cursor: pointer; box-shadow: 0 0 10px rgba(77, 163, 255, 0.5);
}
.timeline-event:hover { height: 22px; }
.timeline-axis {
  display: flex; justify-content: space-between;
  margin-top: 8px; color: var(--muted); font-size: 0.72rem;
}

/* ── Right cards ─────────────────────────────────────────────── */
.card { padding: 18px; }
.card h2 { font-size: 1rem; margin: 0 0 14px; }
.card-head { display: flex; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.link-btn { margin-left: auto; background: none; border: none; color: var(--accent); cursor: pointer; font-size: 0.82rem; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qa-btn {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--glass-border);
  color: var(--text); padding: 14px 10px; border-radius: 14px; cursor: pointer;
  font-size: 0.88rem; transition: all 0.15s;
}
.qa-btn:hover { background: rgba(255, 255, 255, 0.09); }
.qa-btn.active { color: var(--rec); box-shadow: inset 0 0 0 1px rgba(255, 77, 77, 0.4); }

.activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.activity-item { display: flex; align-items: center; gap: 12px; cursor: default; }
.activity-item.playable { cursor: pointer; }
.activity-thumb {
  width: 58px; height: 38px; border-radius: 8px; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06) center/cover; display: grid; place-items: center; font-size: 1rem;
}
.activity-meta { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.activity-title { font-size: 0.88rem; }
.activity-sub { font-size: 0.74rem; color: var(--muted); }
.activity-time { font-size: 0.74rem; color: var(--muted); white-space: nowrap; }
.activity-list .empty { color: var(--muted); font-size: 0.84rem; text-align: center; padding: 16px; }

.zones-preview {
  width: 100%; aspect-ratio: 16 / 9; border-radius: 12px;
  background: rgba(255, 255, 255, 0.04) center/cover; position: relative; overflow: hidden;
}
.zones-preview .zone {
  position: absolute; border: 1.5px solid var(--accent); background: rgba(77, 163, 255, 0.12); border-radius: 4px;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(6px); padding: 20px;
}
.modal-card { width: min(720px, 100%); max-height: 85vh; display: flex; flex-direction: column; padding: 20px; }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { overflow-y: auto; }
.modal-body .row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 12px; background: rgba(255, 255, 255, 0.03); margin-bottom: 8px; cursor: pointer;
}
.modal-body .row.dim { opacity: 0.6; cursor: default; }
.modal-body .meta { margin-left: auto; color: var(--muted); font-size: 0.8rem; }
.modal .button {
  display: block; width: 100%; padding: 13px; margin-bottom: 10px; border: none;
  border-radius: 12px; background: var(--accent); color: #06121f; font-weight: 600; cursor: pointer;
}
.modal .button.secondary { background: rgba(255, 255, 255, 0.08); color: var(--text); }
#modal-body input[type="date"] {
  width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04); color: var(--text); margin-bottom: 12px;
}

/* Login overlay */
.login-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 50% 0%, #122036 0%, var(--bg) 70%); }
.login-card { width: 100%; max-width: 380px; padding: 30px 24px; text-align: center; }
.login-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.login-card input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--glass-border); background: rgba(255,255,255,.06); color: var(--text); font-size: 1rem; margin: 8px 0 12px; }
.login-err { color: var(--bad); font-size: 0.82rem; min-height: 18px; }

/* Playback video shown inside the modal */
.playback-hidden { display: none; }
#modal-body video { width: 100%; border-radius: 12px; background: #000; }

/* ── Fullscreen ──────────────────────────────────────────────── */
.video-wrap:fullscreen { aspect-ratio: auto; }
.video-wrap:fullscreen #live-video { object-fit: contain; }

/* ── Responsive (phone) ──────────────────────────────────────── */
@media (max-width: 1024px) {
  .topnav { order: 3; width: 100%; margin: 8px 0 0; justify-content: center; flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; }
  .brand { min-width: 0; }
  .layout { grid-template-columns: 1fr; }
  .col-cameras, .col-right { position: static; }
  .col-main { order: -1; }
}
@media (max-width: 540px) {
  .topnav-btn { padding: 8px 12px; font-size: 0.82rem; }
  .feed-head h1 { font-size: 1.2rem; }
  .quick-actions { grid-template-columns: 1fr 1fr; }
}
