/* ============================================================
   LSIT — Video Surveillance Ops
   Direction: "signal room" night-ops. Deep blue-black void,
   amber phosphor signal accent, HUD reticle framing, burned-in
   DVR-style OSD overlays.
   ============================================================ */

:root {
  --void:    #0A0D13;
  --panel:   #10151F;
  --panel-2: #161C29;
  --line:    #212A3B;
  --line-hi: #2E3A50;
  --haze:    #818C9E;
  --text:    #E4E9F1;
  --signal:  #F2A93B;   /* amber phosphor — the signature */
  --signal-dim: #7a5a20;
  --online:  #4FD1A5;
  --live:    #FF4D4D;

  --r: 3px;
  --gap: 14px;
  --font-display: 'Chakra Petch', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 700px at 82% -10%, rgba(242,169,59,0.06), transparent 60%),
    radial-gradient(900px 600px at 0% 100%, rgba(79,209,165,0.04), transparent 55%),
    var(--void);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* faint CRT scanlines over the whole app */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.014) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: overlay;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(10,13,19,0.96), rgba(10,13,19,0.82));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-logo {
  height: 42px; width: auto; display: block;
  filter: drop-shadow(0 0 8px rgba(45,120,230,0.25));
}

.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--signal-dim);
  border-radius: var(--r);
  position: relative;
  background: rgba(242,169,59,0.05);
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px var(--signal), 0 0 2px #fff inset;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.brand-text h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 4px;
}
.brand-text p {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--haze);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.status-strip {
  display: flex;
  gap: 4px;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  overflow: hidden;
}
.stat {
  display: flex; flex-direction: column;
  padding: 6px 18px;
  border-right: 1px solid var(--line);
}
.stat:last-child { border-right: 0; }
.stat-k {
  font-family: var(--font-mono);
  font-size: 9px; letter-spacing: 2px;
  color: var(--haze);
}
.stat-v {
  font-family: var(--font-display);
  font-weight: 700; font-size: 18px; line-height: 1.1;
}
.stat-v.online { color: var(--online); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.grid-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.grid-toggle button {
  background: var(--panel);
  color: var(--haze);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 8px 11px;
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 1px;
  transition: all .15s;
}
.grid-toggle button:last-child { border-right: 0; }
.grid-toggle button:hover { color: var(--text); }
.grid-toggle button.active {
  background: rgba(242,169,59,0.12);
  color: var(--signal);
}

.btn-add {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 1px;
  font-size: 13px;
  color: var(--signal);
  background: transparent;
  border: 1px solid var(--signal-dim);
  border-radius: var(--r);
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: all .18s;
}
.btn-add span { font-size: 16px; line-height: 0; }
.btn-add:hover { background: rgba(242,169,59,0.1); border-color: var(--signal); }
.btn-add.solid {
  background: var(--signal);
  color: #1a1205;
  border-color: var(--signal);
}
.btn-add.solid:hover { background: #ffbe4d; box-shadow: 0 0 20px rgba(242,169,59,0.3); }

.admin-link { text-decoration: none; }

/* ---------------- Video wall ---------------- */
.wall {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: var(--gap) 22px 40px;
}
.wall[hidden] { display: none; }

/* ---- camera groups ---- */
.cam-group { display: block; }
.group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 2px 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.group-head .g-name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text);
  text-transform: uppercase;
  font-size: 15px;
}
.group-head .g-swatch {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
  align-self: center;
}
.group-head .g-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--haze);
  letter-spacing: .05em;
}
.group-head .g-count b { color: var(--online); font-weight: 600; }
.group-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: var(--gap);
}

/* ---- view + grouping bar ---- */
.viewbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--panel), transparent);
}
.view-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.view-toggle button {
  background: var(--panel);
  color: var(--haze);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .05em;
  cursor: pointer;
}
.view-toggle button:last-child { border-right: 0; }
.view-toggle button:hover { color: var(--text); }
.view-toggle button.active { background: var(--panel-2); color: var(--signal); }
.viewbar-group { display: flex; gap: 16px; margin-left: auto; flex-wrap: wrap; }
.ctl { display: flex; flex-direction: column; gap: 4px; }
.ctl > span {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--haze);
}
.ctl select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  min-width: 140px;
}
.ctl select:focus-visible { outline: 2px solid var(--signal); outline-offset: 1px; }

/* ---- map view ---- */
.map-view {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 0;
  height: calc(100vh - 128px);
  min-height: 460px;
}
.map-view[hidden] { display: none; }
.map-stage {
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.map-side {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.map-side-head .eyebrow { display: block; margin-bottom: 10px; }
.pop-legend { display: flex; flex-direction: column; gap: 8px; }
.pop-legend .leg {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text);
}
.pop-legend .leg .dot {
  width: 10px; height: 10px; border-radius: 50%;
  box-shadow: 0 0 7px currentColor; flex: none;
}
.pop-legend .leg .n { color: var(--haze); margin-left: auto; }
.unmapped-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.unmapped-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 7px 9px; font-size: 12px;
}
.unmapped-list li button {
  background: transparent; color: var(--signal);
  border: 1px solid var(--signal-dim); border-radius: var(--r);
  font-family: var(--font-mono); font-size: 11px; padding: 3px 7px; cursor: pointer;
}
.unmapped-list li button:hover { background: rgba(242,169,59,.1); border-color: var(--signal); }

/* ---- Leaflet dark skin ---- */
.leaflet-container { background: #e8eef5; font-family: var(--font-body); }
.leaflet-tile { filter: brightness(1.02); }
.map-pin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #0A0D13;
  box-shadow: 0 0 0 2px currentColor, 0 0 10px currentColor;
}
.map-pin::after {
  content: ''; position: absolute; inset: 4px;
  border-radius: 50%; background: currentColor;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line-hi); border-radius: var(--r);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.leaflet-popup-content { margin: 12px 14px; font-family: var(--font-body); }
.pop-popup .pp-name { font-family: var(--font-display); font-weight: 700; letter-spacing: .04em; }
.pop-popup .pp-meta { font-family: var(--font-mono); font-size: 11px; color: var(--haze); margin: 3px 0 9px; }
.pop-popup button {
  background: var(--signal); color: #10151F; border: 0; border-radius: var(--r);
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  padding: 5px 10px; cursor: pointer; letter-spacing: .04em;
}
.leaflet-bar a, .leaflet-control-attribution {
  background: var(--panel) !important; color: var(--haze) !important; border-color: var(--line) !important;
}
.leaflet-control-attribution a { color: var(--signal) !important; }

/* ---- drawer coord row ---- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  animation: tileIn .4s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes tileIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.tile-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background:
    repeating-linear-gradient(45deg, #0c1017 0 10px, #0a0e14 10px 20px);
  overflow: hidden;
}
.tile-frame video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

/* HUD reticle corners — the framing signature */
.reticle {
  position: absolute;
  width: 16px; height: 16px;
  z-index: 6;
  pointer-events: none;
  border-color: var(--signal);
  opacity: 0.85;
}
.reticle.tl { top: 8px; left: 8px; border-top: 1.5px solid; border-left: 1.5px solid; }
.reticle.tr { top: 8px; right: 8px; border-top: 1.5px solid; border-right: 1.5px solid; }
.reticle.bl { bottom: 8px; left: 8px; border-bottom: 1.5px solid; border-left: 1.5px solid; }
.reticle.br { bottom: 8px; right: 8px; border-bottom: 1.5px solid; border-right: 1.5px solid; }

/* Burned-in OSD overlays */
.osd {
  position: absolute;
  z-index: 5;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  display: flex; align-items: center; gap: 6px;
}
.osd-tl { top: 12px; left: 30px; }
.osd-tr { top: 14px; right: 30px; color: var(--haze); }
.osd-bl { bottom: 12px; left: 30px; flex-direction: column; align-items: flex-start; gap: 1px; }
.osd-br { bottom: 14px; right: 30px; color: #cfd6e2; font-weight: 500; }

.osd-name { font-weight: 600; color: #fff; font-size: 11px; }
.osd-loc { color: var(--haze); font-size: 9px; }

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 8px var(--live);
  animation: pulse 1.4s ease-in-out infinite;
}
.osd-live { color: var(--live); font-weight: 600; }

/* loading / offline states */
.tile-loading, .tile-offline {
  position: absolute; inset: 0;
  z-index: 4;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  color: var(--haze);
  font-size: 11px; letter-spacing: 2px;
  background: rgba(10,13,19,0.72);
}
.tile[data-state="loading"] .tile-loading { display: flex; }
.tile[data-state="offline"] .tile-offline { display: flex; }
.tile[data-state="offline"] .osd-tl,
.tile[data-state="loading"] .osd-tl { opacity: 0; }

.spinner {
  width: 26px; height: 26px;
  border: 2px solid var(--line-hi);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.off-icon { font-size: 22px; color: var(--live); }
.btn-retry {
  margin-top: 4px;
  background: transparent;
  border: 1px solid var(--line-hi);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 10px; letter-spacing: 1.5px;
  transition: all .15s;
}
.btn-retry:hover { border-color: var(--signal); color: var(--signal); }

/* tile bottom bar */
.tile-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 11px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.ch { font-size: 11px; color: var(--haze); letter-spacing: 1px; }
.tile-actions { display: flex; gap: 4px; }
.tbtn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--haze);
  width: 26px; height: 26px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.tbtn:hover { color: var(--text); border-color: var(--line-hi); }
.tbtn.danger:hover { color: var(--live); border-color: var(--live); }

/* ---------------- Empty state ---------------- */
.empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 90px 20px;
  gap: 14px;
}
.empty[hidden] { display: none; }
.empty-reticle {
  width: 84px; height: 84px;
  position: relative;
  margin-bottom: 8px;
}
.empty-reticle::before, .empty-reticle::after {
  content: ''; position: absolute; inset: 0;
  border: 1px dashed var(--line-hi);
  border-radius: 50%;
}
.empty-reticle::after {
  inset: 26px;
  border-style: solid;
  border-color: var(--signal-dim);
  animation: pulse 2.4s ease-in-out infinite;
}
.empty h2 { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: 1px; }
.empty p { color: var(--haze); font-size: 14px; max-width: 380px; line-height: 1.6; }
.empty .btn-add { margin-top: 8px; }

/* ---------------- Add drawer ---------------- */
.scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,7,11,0.72);
  backdrop-filter: blur(3px);
  display: flex; justify-content: flex-end;
}
.scrim[hidden] { display: none; }

.drawer {
  width: min(440px, 100%);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line-hi);
  display: flex; flex-direction: column;
  animation: slideIn .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 2.5px;
  color: var(--signal);
}
.drawer-head h2 {
  font-family: var(--font-display);
  font-weight: 600; font-size: 22px; letter-spacing: 0.5px;
  margin-top: 4px;
}
.drawer-close {
  background: transparent; border: 1px solid var(--line);
  color: var(--haze); width: 32px; height: 32px;
  border-radius: var(--r); cursor: pointer; font-size: 14px;
  transition: all .15s;
}
.drawer-close:hover { color: var(--text); border-color: var(--line-hi); }

.drawer-body {
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 1.5px;
  color: var(--haze);
  text-transform: uppercase;
}
.field input {
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px rgba(242,169,59,0.12);
}
.field .hint { font-size: 10px; color: var(--haze); letter-spacing: 0.3px; }

.probe-row { display: flex; align-items: center; gap: 12px; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line-hi);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--r);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 12px; letter-spacing: 1px;
  transition: all .15s;
}
.btn-ghost:hover { border-color: var(--signal); color: var(--signal); }
.probe-result { font-size: 11px; }
.probe-result.ok { color: var(--online); }
.probe-result.bad { color: var(--live); }

.drawer-foot { margin-top: 4px; }
.drawer-foot .btn-add { width: 100%; justify-content: center; padding: 12px; }
.form-error { color: var(--live); font-size: 12px; font-family: var(--font-mono); min-height: 14px; }

/* ---------------- Fullscreen viewer ---------------- */
.viewer {
  position: fixed; inset: 0; z-index: 150;
  background: #000;
  display: flex; flex-direction: column;
}
.viewer[hidden] { display: none; }
.viewer-osd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(0,0,0,0.85), transparent);
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
}
.viewer-osd #viewerName { font-size: 13px; letter-spacing: 2px; color: var(--signal); }
.viewer-close {
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--line-hi);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--r);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 1.5px;
}
.viewer-close:hover { border-color: var(--signal); color: var(--signal); }
.viewer-stage { flex: 1; display: grid; place-items: center; }
.viewer-stage video { max-width: 100%; max-height: 100%; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; gap: 12px; row-gap: 10px; }
  .status-strip { display: none; }
  .brand-text p { display: none; }
  .wall { --cols: 1 !important; padding: var(--gap) 14px 40px; }
}
@media (max-width: 560px) {
  .topbar-actions { gap: 8px; }
  .btn-add { font-size: 0; padding: 9px 12px; }
  .btn-add span { font-size: 18px; }
  .grid-toggle { display: none; }
}

/* ---------------- A11y ---------------- */
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.05s !important; }
}
