/* cams — spy terminal aesthetic
   dark ops console with cyan/amber accents, monospace display type */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Oswald:wght@300;400;500;700&display=swap');

:root {
  --bg: #0a0e14;
  --bg-elev: #111820;
  --bg-chrome: #0d131a;
  --border: #1e2a36;
  --border-bright: #2a3b4d;
  --text: #d6e3f0;
  --text-dim: #7a8b9c;
  --text-faint: #455565;
  --accent: #00d4ff;
  --accent-warm: #ff6b35;
  --accent-amber: #ffb547;
  --danger: #ff3860;
  --scan: rgba(0, 212, 255, 0.04);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

/* ───────── LAYOUT ───────── */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  width: 100vw;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  gap: 24px;
  position: relative;
  z-index: 1000;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
  opacity: 0.3;
}

.brand {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent-warm);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-warm);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.brand small {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 2px;
}

.topbar-meta {
  margin-left: auto;
  display: flex;
  gap: 20px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.topbar-meta strong {
  color: var(--accent);
  font-weight: 500;
}

/* ───────── SIDEBAR ───────── */

.sidebar {
  grid-row: 2;
  background: var(--bg-chrome);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section.sidebar-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar h2 {
  font-family: 'Oswald', sans-serif;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 500;
  margin-bottom: 10px;
}

.search-box {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  transition: border-color 0.15s;
}

.search-box:focus {
  outline: none;
  border-color: var(--accent);
}

.search-box::placeholder {
  color: var(--text-faint);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.filter-chip .icon {
  font-size: 11px;
  line-height: 1;
}

.filter-chip:hover {
  border-color: var(--border-bright);
  color: var(--text);
}

.filter-chip.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.cam-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -18px -16px;
  padding: 0 18px 16px;
}

.cam-list-empty {
  text-align: center;
  padding: 24px 0;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.cam-row {
  padding: 9px 10px;
  border-left: 2px solid transparent;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cam-row:hover {
  background: var(--bg);
  border-left-color: var(--border-bright);
}

.cam-row.active {
  background: var(--bg);
  border-left-color: var(--accent);
}

.cam-row-name {
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cam-row-meta {
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

/* ───────── MAP ───────── */

.map-wrap {
  grid-row: 2;
  position: relative;
  background: #050a10;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
}

/* invert the light tiles for dark-ops feel */
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(190deg) brightness(0.95) contrast(0.85);
}

/* but DO NOT invert markers, popups, controls */
.leaflet-marker-pane,
.leaflet-popup-pane,
.leaflet-tooltip-pane,
.leaflet-shadow-pane,
.leaflet-overlay-pane {
  filter: none;
}

.leaflet-control-attribution {
  background: rgba(13, 19, 26, 0.85) !important;
  color: var(--text-dim) !important;
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 9px !important;
  border: 1px solid var(--border) !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
}

.leaflet-control-zoom a {
  background: var(--bg-chrome) !important;
  color: var(--accent) !important;
  border-color: var(--border) !important;
  font-family: 'JetBrains Mono', monospace !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-elev) !important;
}

/* Cluster markers */
.marker-cluster {
  background: rgba(0, 212, 255, 0.15) !important;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 11px;
}

.marker-cluster div {
  background: rgba(0, 212, 255, 0.25) !important;
  color: var(--text) !important;
}

/* Custom diamond markers */
.cam-marker {
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  background: var(--accent);
  border: 1px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent), 0 0 8px rgba(0, 212, 255, 0.5);
  transition: all 0.15s;
}

.cam-marker.active {
  background: var(--accent-warm);
  box-shadow: 0 0 0 1px var(--accent-warm), 0 0 12px rgba(255, 107, 53, 0.7);
  transform: rotate(45deg) scale(1.3);
}

.cam-marker.cat-traffic   { background: #ff6b35; box-shadow: 0 0 0 1px #ff6b35, 0 0 6px rgba(255, 107, 53, 0.5); }
.cam-marker.cat-landmark  { background: #00d4ff; box-shadow: 0 0 0 1px #00d4ff, 0 0 6px rgba(0, 212, 255, 0.5); }
.cam-marker.cat-wildlife  { background: #8ae234; box-shadow: 0 0 0 1px #8ae234, 0 0 6px rgba(138, 226, 52, 0.5); }
.cam-marker.cat-harbour   { background: #4fc3f7; box-shadow: 0 0 0 1px #4fc3f7, 0 0 6px rgba(79, 195, 247, 0.5); }
.cam-marker.cat-transport { background: #ffd54f; box-shadow: 0 0 0 1px #ffd54f, 0 0 6px rgba(255, 213, 79, 0.5); }
.cam-marker.cat-tourism   { background: #ce93d8; box-shadow: 0 0 0 1px #ce93d8, 0 0 6px rgba(206, 147, 216, 0.5); }

/* ───────── LOADING ───────── */

.loading {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-chrome);
  border: 1px solid var(--accent);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
  z-index: 500;
  transition: opacity 0.3s;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── VIEWER ───────── */

.viewer {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 460px;
  max-width: calc(100vw - 32px);
  background: var(--bg-chrome);
  border: 1px solid var(--accent);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(0, 212, 255, 0.05);
  z-index: 600;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 90px);
  opacity: 0;
  pointer-events: none;
  transform: translateX(20px);
  transition: opacity 0.2s, transform 0.2s;
}

.viewer.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.viewer-header {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.viewer-title {
  font-family: 'Oswald', sans-serif;
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 500;
}

.viewer-subtitle {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-top: 3px;
  text-transform: uppercase;
}

.viewer-close {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.viewer-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.viewer-feed {
  position: relative;
  background: #000;
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
}

.viewer-feed.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 1px solid var(--accent);
  box-shadow: inset 0 0 24px rgba(0, 212, 255, 0.45);
  animation: cctvFlash 0.6s ease-out forwards;
}

@keyframes cctvFlash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

.viewer-feed iframe,
.viewer-feed video,
.viewer-feed img {
  width: 100%;
  height: 100%;
  display: block;
  border: none;
  object-fit: cover;
}

.viewer-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
  gap: 16px;
  color: var(--text-dim);
  background: var(--bg);
}

.viewer-fallback .icon {
  width: 40px;
  height: 40px;
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 20px;
}

.viewer-fallback p {
  font-size: 12px;
  line-height: 1.6;
  max-width: 360px;
}

.viewer-fallback a.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--accent);
  color: var(--bg);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 11px;
  border: 1px solid var(--accent);
  transition: all 0.15s;
}

.viewer-fallback a.btn:hover {
  background: transparent;
  color: var(--accent);
}

.viewer-meta {
  padding: 14px 18px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 11px;
}

.viewer-meta dt {
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 10px;
}

.viewer-meta dd { color: var(--text); }

.viewer-meta dd.coords {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.viewer-status {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-chrome);
  border-top: 1px solid var(--border);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  gap: 8px;
}

.viewer-status .dot {
  width: 6px;
  height: 6px;
  background: var(--accent-warm);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-warm);
  animation: pulse 2s ease-in-out infinite;
}

.viewer-status-spacer { flex: 1; }

/* Corner crosshair decoration */
.viewer::before, .viewer::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid var(--accent);
  pointer-events: none;
}

.viewer::before {
  top: -1px; left: -1px;
  border-right: none;
  border-bottom: none;
}

.viewer::after {
  bottom: -1px; right: -1px;
  border-left: none;
  border-top: none;
}

/* ───────── MOBILE MENU CONTROLS (hidden on desktop) ───────── */

.topbar-menu,
.sidebar-close {
  display: none;
}

.topbar-menu {
  background: transparent;
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  cursor: pointer;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}

.topbar-menu span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--accent);
}

.sidebar-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 14px;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 800;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ───────── SCROLLBARS ───────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* ───────── MOBILE LAYOUT ───────── */

@media (max-width: 900px) {

  /* Map fills the entire view below the topbar */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr;
  }

  .topbar {
    padding: 0 12px;
    gap: 12px;
  }

  .topbar-menu {
    display: flex;
  }

  .brand {
    font-size: 16px;
    letter-spacing: 0.2em;
  }

  .brand small {
    display: none;
  }

  .topbar-meta {
    gap: 10px;
    font-size: 10px;
  }

  .topbar-secure {
    display: none;
  }

  /* Sidebar becomes a slide-up sheet, hidden by default */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: 75vh;
    border-right: none;
    border-top: 1px solid var(--accent);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.6);
    z-index: 900;
    transform: translateY(100%);
    transition: transform 0.25s ease-out;
  }

  .sidebar.open {
    transform: translateY(0);
  }

  .sidebar-close {
    display: block;
  }

  /* Viewer panel — full-width sheet from top */
  .viewer {
    width: calc(100vw - 16px);
    right: 8px;
    left: 8px;
    top: 8px;
    max-width: none;
    max-height: calc(100vh - 70px);
  }

  /* Larger touch targets in lists */
  .cam-row {
    padding: 12px 10px;
    font-size: 12px;
  }

  .cam-row-name {
    font-size: 12px;
  }

  .filter-chip {
    padding: 6px 12px;
    font-size: 11px;
  }
}

/* Phones in portrait — viewer takes priority over map */
@media (max-width: 600px) {
  .viewer-feed {
    aspect-ratio: 16/10;
  }
}
