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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

#sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #0f3460;
  color: #00ccff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.access-badge {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  color: #fff;
}
.badge-anon    { background: #334; }
.badge-friends { background: #2a5a3a; }
.badge-owner   { background: #3a2a5a; }

.connection-status {
  padding: 5px 14px;
  font-size: 11px;
  color: #555;
  border-bottom: 1px solid #0f3460;
}
.status-ok   { color: #00ff88; }
.status-warn { color: #ffaa00; }
.status-err  { color: #ff4444; }
.data-spinner {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1.5px solid rgba(0,255,136,0.25);
  border-top-color: #00ff88;
  border-radius: 50%;
  animation: data-spin 0.75s linear infinite;
  margin-left: 7px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.data-spinner.hidden { display: none; }
@keyframes data-spin { to { transform: rotate(360deg); } }
.mqtt-leds {
  display: inline-flex;
  gap: 4px;
  margin-left: 8px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.mqtt-led {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  opacity: 0.15;
  transition: opacity 0.25s ease-out;
}
.mqtt-rx { background: #00ccff; }
.mqtt-tx { background: #ffcc00; }
.mqtt-led.blink { opacity: 1; transition: none; }

/* ── Toggle panel ─────────────────────────────────────────────────────────── */

#toggle-panel {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

#toggle-panel::-webkit-scrollbar { width: 4px; }
#toggle-panel::-webkit-scrollbar-track { background: #0f1c30; }
#toggle-panel::-webkit-scrollbar-thumb { background: #0f3460; }

.agent-row { border-bottom: 1px solid #0d1b30; }

.agent-header {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  gap: 7px;
  cursor: default;
  user-select: none;
}

.agent-header:hover { background: #1a2a4a; }

.agent-check {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #00ccff;
  flex-shrink: 0;
}

.agent-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.agent-name {
  flex: 1;
  color: #c8d8e8;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-row.disabled .agent-name { color: #556; }

/* NWS alert sub-list */
.alert-list {
  padding: 2px 6px 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 220px;
  overflow-y: auto;
}
.alert-list::-webkit-scrollbar { width: 4px; }
.alert-list::-webkit-scrollbar-track { background: transparent; }
.alert-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
.alert-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.4;
}
.alert-item:hover { background: rgba(255,255,255,0.07); }
.alert-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}
.alert-name {
  font-weight: 600;
  color: #ccd;
  white-space: nowrap;
  flex-shrink: 0;
}
.alert-area {
  color: #778;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-indicator.online   { background: #00ff88; box-shadow: 0 0 4px #00ff8866; }
.status-indicator.degraded { background: #ffaa00; box-shadow: 0 0 4px #ffaa0066; }
.status-indicator.offline  { background: #445; }

.expand-btn {
  color: #445;
  cursor: pointer;
  font-size: 10px;
  padding: 0 2px;
  flex-shrink: 0;
  line-height: 1;
}
.expand-btn:hover { color: #aaa; }

.type-list {
  padding: 0 10px 6px 40px;
}
.type-list.hidden { display: none; }

.type-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: default;
}

.type-check {
  width: 12px;
  height: 12px;
  cursor: pointer;
  accent-color: #00aacc;
  flex-shrink: 0;
}

.type-name {
  color: #778;
  font-size: 11px;
}

/* ── Map ──────────────────────────────────────────────────────────────────── */

#map {
  position: absolute;
  top: 0;
  left: 260px;
  right: 0;
  bottom: 0;
}

/* ── Leaflet marker overrides ─────────────────────────────────────────────── */

.globe-marker {
  background: none !important;
  border: none !important;
}

.marker-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.marker-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.65);
  flex-shrink: 0;
}

/* Active-event pulse ring — expands outward from the marker centre */
@keyframes marker-pulse {
  0%   { transform: translate(-50%, -50%) scale(1);   opacity: 0.75; }
  100% { transform: translate(-50%, -50%) scale(3.2); opacity: 0; }
}
.marker-pulse {
  position: absolute;
  top: 7px;   /* vertically centres on a 14px dot (half of 14) */
  left: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  pointer-events: none;
  animation: marker-pulse 1.4s ease-out infinite;
  z-index: -1;
}

/* Directional arrow: a triangle pointing up, rotated by heading */
.marker-arrow {
  width: 0;
  height: 0;
  border-left:   5px solid transparent;
  border-right:  5px solid transparent;
  border-bottom: 13px solid currentColor;
  transform-origin: 50% 100%;
  flex-shrink: 0;
}

/* Aircraft silhouette marker: SVG drawn in currentColor, rotated by heading */
.marker-aircraft {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 50% 50%;
  flex-shrink: 0;
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.65));
}

/* APRS symbol sprite crop — real APRS icon set, shown upright (not rotated) */
.marker-aprs {
  background-repeat: no-repeat;
  flex-shrink: 0;
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.65));
}

/* Face photo marker */
.marker-face {
  width:  32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  position: relative;
}

/* Small triangle that rotates around the face circle to show heading.
   Apex-up at rest (0deg) so it matches the same compass convention as
   .marker-arrow / .marker-aircraft — 0deg = north = up, rotating clockwise. */
.marker-face-dir {
  position: absolute;
  top: -9px;
  left: 50%;
  transform-origin: 50% 25px;  /* pivot at circle centre (16px below this element's top) */
  width: 0;
  height: 0;
  border-left:   4px solid transparent;
  border-right:  4px solid transparent;
  border-bottom: 7px solid currentColor;
  margin-left: -4px;
  opacity: 0.85;
}

/* Small count badge for a marker representing multiple merged features
   (e.g. co-located APRS stations within a few meters of each other) */
.marker-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: #e53935;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.marker-label {
  position: absolute;
  /* top is set inline per marker type */
  top: 17px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
}

/* ── Leaflet popup overrides ──────────────────────────────────────────────── */

.feature-popup { min-width: 160px; max-width: 280px; }

.popup-agent {
  font-size: 10px;
  color: #999;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.popup-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: #222;
}

/* Generic popup image (e.g. aircraft photo) with attribution line */
.popup-image-wrap { margin-bottom: 6px; }

.popup-image {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 4px;
}

.popup-image-credit {
  font-size: 9px;
  color: #999;
  margin-top: 2px;
}

.feature-popup table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.feature-popup td {
  padding: 2px 4px;
  vertical-align: top;
}

.feature-popup td:first-child {
  color: #777;
  white-space: nowrap;
  padding-right: 8px;
}

.feature-popup tr:nth-child(even) td { background: #f7f7f7; }

.popup-stale {
  margin-top: 6px;
  padding: 4px 6px;
  background: #fff8e6;
  border: 1px solid #f0c060;
  border-radius: 3px;
  color: #a06000;
  font-size: 11px;
}

/* ── Entity section ──────────────────────────────────────────────────────── */

#entity-section {
  border-top: 1px solid #0f3460;
  flex-shrink: 0;
}
#entity-section.hidden { display: none; }

.entities-header {
  padding: 6px 14px 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #446;
}

.entity-row {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  gap: 8px;
  cursor: pointer;
  border-bottom: 1px solid #0d1b30;
  user-select: none;
}
.entity-row:hover  { background: #1a2a4a; }
.entity-row.active { background: #1e2f50; }

.entity-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.entity-name { flex: 1; color: #c8d8e8; font-size: 12px; }
.entity-row.active .entity-name { color: #fff; font-weight: 600; }
.entity-type { font-size: 11px; color: #446; }

.entity-follow-check {
  flex-shrink: 0;
  margin: 0;
  accent-color: #4fc3f7;
  cursor: pointer;
}

/* Entity badge inside popups */
.popup-entity-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  margin-bottom: 6px;
  border-left: 3px solid;
  background: rgba(0,0,0,0.04);
  border-radius: 0 3px 3px 0;
  font-size: 12px;
  font-weight: 600;
  color: #333;
}
.popup-entity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Config button (owner only, in sidebar header) ───────────────────────── */

.config-btn {
  background: none;
  border: none;
  color: #557;
  font-size: 15px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  margin-left: 4px;
}
.config-btn:hover { color: #00ccff; }
.config-btn.hidden { display: none; }

/* ── Config panel ─────────────────────────────────────────────────────────── */

#config-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
#config-panel.hidden { display: none; }

.config-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: #0f3460;
  color: #aac;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex-shrink: 0;
}
.config-close-btn {
  background: none;
  border: none;
  color: #557;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  line-height: 1;
}
.config-close-btn:hover { color: #fff; }

#config-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.config-section { margin-bottom: 12px; }

.config-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #446;
}

.config-entity-list { padding: 0 8px; }

.config-entity-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  background: #1a2540;
}
.config-entity-row:hover { background: #1e2f50; }

.config-entity-name { flex: 1; color: #c8d8e8; font-size: 12px; }
.config-entity-type { font-size: 10px; color: #446; }

.config-empty {
  padding: 16px 12px;
  color: #446;
  font-size: 11px;
  line-height: 1.5;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn-sm {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 3px;
  border: none;
  cursor: pointer;
  line-height: 1.4;
}
.btn-primary { background: #0f3460; color: #00ccff; }
.btn-primary:hover { background: #1a4a80; }
.btn-ghost   { background: transparent; color: #779; border: 1px solid #334; }
.btn-ghost:hover { color: #aac; border-color: #557; }
.btn-icon    { background: none; border: none; cursor: pointer; color: #446; font-size: 13px; padding: 0 3px; line-height: 1; }
.btn-icon:hover         { color: #aac; }
.btn-icon.btn-danger    { color: #633; }
.btn-icon.btn-danger:hover { color: #f66; }

/* ── Modal ────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  width: 360px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #0f3460;
  color: #c8d8e8;
  font-size: 13px;
  font-weight: 600;
  border-radius: 5px 5px 0 0;
  flex-shrink: 0;
}
.modal-x-btn {
  background: none;
  border: none;
  color: #557;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}
.modal-x-btn:hover { color: #fff; }

.modal-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #0f3460;
  flex-shrink: 0;
}

/* ── Form elements ────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 10px; }

.form-label {
  display: block;
  font-size: 11px;
  color: #779;
  margin-bottom: 4px;
}

.form-hint { color: #446; font-weight: 400; }

.form-input {
  width: 100%;
  background: #0d1b30;
  border: 1px solid #1a2f50;
  border-radius: 3px;
  color: #c8d8e8;
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
}
.form-input:focus { border-color: #00ccff; }
select.form-input { cursor: pointer; }

.form-color {
  width: 100%;
  height: 32px;
  padding: 2px 4px;
  background: #0d1b30;
  border: 1px solid #1a2f50;
  border-radius: 3px;
  cursor: pointer;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.source-row {
  display: flex;
  gap: 5px;
  margin-bottom: 5px;
  align-items: center;
}
.source-row .form-input { flex: 1; }
.source-row .source-type { max-width: 110px; flex: none; }

/* ── Camera placement banner ──────────────────────────────────────────────── */

#placement-banner {
  position: absolute;
  top: 12px;
  left: 272px;
  right: 12px;
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  background: rgba(0, 204, 255, 0.92);
  color: #000;
  font-size: 13px;
  font-weight: 600;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
}
#placement-banner.hidden { display: none; }
#placement-msg { flex: 1; }
#placement-cancel {
  background: rgba(0,0,0,0.15);
  border: none;
  color: #000;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
}
#placement-cancel:hover { background: rgba(0,0,0,0.3); }

/* Crosshair cursor during placement */
body.placing .leaflet-container,
body.placing .leaflet-grab,
body.placing .leaflet-dragging .leaflet-grab { cursor: crosshair !important; }

/* ── Camera popup ─────────────────────────────────────────────────────────── */

/* Multi-camera group layout */
.camera-group { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.cam-channel { display: flex; flex-direction: column; gap: 3px; }
.cam-channel-label {
  font-size: 10px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Camera group section in config panel */
.config-cam-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 4px 3px;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid #333;
  margin-top: 8px;
}
.config-cam-group-header:first-child { margin-top: 0; }
.config-cam-member {
  padding-left: 18px;
  font-size: 11px;
  opacity: 0.88;
}

.camera-snap-wrap {
  margin: 6px 0;
  border-radius: 4px;
  overflow: hidden;
  background: #111;
  line-height: 0;
}

.camera-snap {
  width: 100%;
  max-width: 280px;
  display: block;
  min-height: 60px;
}

.camera-view-link {
  margin: 5px 0 6px;
  font-size: 11px;
}

.camera-view-link a {
  color: #0077cc;
  text-decoration: none;
}

.camera-view-link a:hover { text-decoration: underline; }

/* Unplaced camera indicator in config list */
.cam-unplaced {
  font-size: 10px;
  color: #664;
  background: #221a00;
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.toggle-empty {
  padding: 20px 14px;
  color: #445;
  font-size: 11px;
  text-align: center;
  line-height: 1.6;
}

/* ── Dark mode (follows browser preference) ───────────────────────────────────
   The sidebar/modals are dark in both themes; this block darkens the parts
   Leaflet renders light: basemap tiles, map background, popups, and the
   zoom/attribution controls. */

@media (prefers-color-scheme: dark) {
  .leaflet-container { background: #0d1420; }

  /* Darken standard OSM tiles: invert lightness, then hue-rotate 180° so
     colors land back near their originals (water stays blue-ish). Only the
     tile pane is filtered — vector overlays and markers keep true colors. */
  .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.7) contrast(0.9) saturate(0.5);
  }

  /* Popups */
  .leaflet-popup-content-wrapper,
  .leaflet-popup-tip {
    background: #1c2438;
    color: #c8d8e8;
    box-shadow: 0 3px 14px rgba(0,0,0,0.7);
  }
  .leaflet-popup-close-button { color: #778 !important; }
  .leaflet-popup-close-button:hover { color: #fff !important; }

  .popup-title { color: #e8eef4; }
  .popup-agent { color: #8899aa; }
  .feature-popup td:first-child { color: #8899aa; }
  .feature-popup tr:nth-child(even) td { background: rgba(255,255,255,0.05); }

  .popup-entity-badge {
    background: rgba(255,255,255,0.06);
    color: #dde6ee;
  }

  .popup-stale {
    background: #33280e;
    border-color: #8a6d2a;
    color: #e0b050;
  }

  .camera-view-link a { color: #4fc3f7; }

  /* Zoom + attribution controls */
  .leaflet-control-zoom a {
    background: #1c2438;
    color: #c8d8e8;
    border-color: #0f3460;
  }
  .leaflet-control-zoom a:hover {
    background: #263356;
    color: #fff;
  }
  .leaflet-bar { border-color: #0f3460; }
  .leaflet-control-attribution {
    background: rgba(13, 20, 32, 0.8);
    color: #667;
  }
  .leaflet-control-attribution a { color: #4a7fa8; }
}
