:root {
  --bg: #0b0f10;
  --panel: #12181a;
  --panel-border: #23302f;
  --text: #dfe8e6;
  --text-dim: #8aa19c;
  --accent: #3ddc84;
  --danger: #ff4d4f;
  --warn: #ffb020;
  /* All aerial-threat types in the red family on purpose — a green Shahed
     marker on a green-tinted map camouflaged against the terrain. Shape
     (see TYPE_SHAPES in app.js) still carries the type distinction; color
     now uniformly says "threat, look here" instead of blending in. */
  --raketa: #ff2d55;
  --shahed: #ff4444;
  --shahed-jet: #ff8a3d;
  --fpv: #ff3d81;
  --ballistic: #ff0033;
  --mlrs: #ffb020;
  --lost: #6b7a78;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Flex column top-to-bottom: header (banner + topbar) sized by its own
   content, main area (map + sidebar) takes whatever's left. Nothing here
   depends on any element's exact pixel height — a banner wrapping to two
   lines just pushes the map down instead of getting overlapped. */
#app { display: flex; flex-direction: column; height: 100%; }
#app-header { flex: 0 0 auto; position: relative; z-index: 2000; }
#app-main { flex: 1 1 auto; position: relative; overflow: hidden; z-index: 1; }

#demo-banner, #live-banner {
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  padding: 4px 8px;
}

#demo-banner {
  background: repeating-linear-gradient(45deg, #3a0000, #3a0000 12px, #1a0000 12px, #1a0000 24px);
  color: #ffb3b3;
  border-bottom: 1px solid #5a0000;
}

#live-banner {
  background: #2a1f00;
  color: #ffcf6b;
  border-bottom: 1px solid #5a4400;
}

/* Desktop: one row (brand | search | status) — topbar-row1 is unwrapped via
   display:contents so brand/status-wrap become direct flex children of
   #topbar alongside search-wrap, ordered to match the old visual layout.
   Mobile media query below turns topbar-row1 back into a real row and
   pushes search onto its own full-width line. */
#topbar {
  background: rgba(11, 15, 16, 0.92);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
}
#topbar-row1 { display: contents; }

#brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 90px; order: 1; }
#brand-name { font-weight: 800; letter-spacing: 2px; color: var(--accent); font-size: 16px; }
#brand-sub { font-size: 10px; color: var(--text-dim); white-space: nowrap; }

#search-wrap { position: relative; flex: 1 1 auto; max-width: 420px; order: 2; min-width: 120px; }
#search-input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
#search-results {
  position: absolute;
  top: 38px; left: 0; right: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
  display: none;
}
#search-results.open { display: block; }
.search-item {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--panel-border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #1b2426; }

#status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  order: 3;
}
#status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--lost);
  box-shadow: 0 0 6px var(--lost);
}
#status-dot.live { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
#status-dot.error { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
#clock { font-variant-numeric: tabular-nums; color: var(--text); }

#sidebar-toggle {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: none;
}

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

#sidebar {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 320px;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  z-index: 1400;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s ease;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-border);
}
#sidebar-header h2 { font-size: 14px; margin: 0; color: var(--text); }
#sidebar-close { display: none; background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; }

#track-list { flex: 1; overflow-y: auto; padding: 8px; }

.track-card {
  background: #0e1516;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.track-card:hover { border-color: var(--accent); }
.track-card.status-lost { opacity: 0.55; }
.track-card-head { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.track-type-dot { width: 9px; height: 9px; border-radius: 50%; }
.track-type-dot.shahed { background: var(--shahed); }
.track-type-dot.shahed_jet { background: var(--shahed-jet); }
.track-type-dot.fpv { background: var(--fpv); }
.track-type-dot.raketa { background: var(--raketa); }
.track-type-dot.ballistic { background: var(--ballistic); }
.track-type-dot.mlrs { background: var(--mlrs); }
.track-type-dot.lost { background: var(--lost); }
.track-card-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }
.track-card-src { font-size: 11px; color: #9fb3ae; margin-top: 6px; font-style: italic; border-top: 1px dashed var(--panel-border); padding-top: 6px; }
.track-card-id { font-size: 10px; color: #6f8480; margin-top: 3px; }

#legend {
  border-top: 1px solid var(--panel-border);
  padding: 10px 14px 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.legend-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-dot.shahed { background: var(--shahed); }
.legend-dot.shahed_jet { background: var(--shahed-jet); }
.legend-dot.fpv { background: var(--fpv); }
.legend-dot.raketa { background: var(--raketa); }
.legend-dot.ballistic { background: var(--ballistic); }
.legend-dot.mlrs { background: var(--mlrs); }
.legend-dot.lost { background: var(--lost); }
.legend-note { margin-top: 8px; font-size: 10.5px; line-height: 1.4; color: #6f8480; }

/* Escalating altitude-drop highlight (user request) — a pulsing ring
   around a descending target's marker, bigger/faster/redder plus an
   exclamation badge once it's actually falling, not just descending. */
.alt-ring {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.alt-ring-descending {
  width: 34px;
  height: 34px;
  border: 2px solid var(--warn);
  animation: altPulse 1.6s ease-out infinite;
}
.alt-ring-falling {
  width: 40px;
  height: 40px;
  border: 3px solid var(--danger);
  animation: altPulse 0.85s ease-out infinite;
}
@keyframes altPulse {
  0% { transform: scale(0.75); opacity: 1; }
  100% { transform: scale(1.45); opacity: 0; }
}
.alt-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 15px;
  text-align: center;
  border: 1.5px solid #0b0f10;
  z-index: 10;
}

/* User request: number active drones over Kyiv/Bucha in order of
   appearance (1, 2, 3...) — opposite corner from .alt-badge so the two
   never overlap on the same marker. */
.seq-badge {
  position: absolute;
  top: -3px;
  left: -3px;
  min-width: 16px;
  height: 16px;
  padding: 0 2px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  border: 1.5px solid #0b0f10;
  z-index: 10;
}

.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 8px; }
.leaflet-popup-tip { background: var(--panel); }
.leaflet-container { background: #0a0d0e; }

/* Fake a dark basemap on top of standard (light) OSM raster tiles — paled
   down further (lower saturation/contrast) so red threat markers and our
   own green contours read as the loudest things on screen, not the terrain. */
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(200deg) brightness(1.05) contrast(0.72) saturate(0.32);
}
.oblast-tip {
  background: rgba(11,15,16,0.9) !important;
  color: #dfe8e6 !important;
  border: 1px solid #23302f !important;
  font-size: 11px !important;
}

@media (max-width: 720px) {
  #brand-sub { display: none; }
  #brand-name { font-size: 15px; }

  /* topbar-row1 becomes a real row again (brand + status), full width, so
     search-wrap — no longer squeezed between them — wraps onto its own
     full-width line below instead of being crushed to ~80px. */
  #topbar { padding: 6px 10px; gap: 6px; }
  #topbar-row1 { display: flex; align-items: center; justify-content: space-between; flex: 1 1 100%; order: 0; }
  #search-wrap { order: 1; flex: 1 1 100%; max-width: none; }
  /* 16px, not 13px — anything smaller makes iOS Safari zoom the whole page
     in on focus, which then has to be manually zoomed back out. */
  #search-input { font-size: 16px; padding: 9px 10px; }
  #search-results { font-size: 15px; }
  .search-item { padding: 10px; }

  #status-wrap { gap: 6px; }
  #clock { display: none; }

  /* Real touch targets (~40px+), not the mouse-sized ones from desktop. */
  #sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    padding: 0;
    font-size: 18px;
  }

  #sidebar {
    width: 88vw;
    transform: translateX(100%);
    box-shadow: -8px 0 24px rgba(0,0,0,0.5);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    font-size: 20px;
  }
  #sidebar-header { padding: 10px 12px; }
  .track-card { padding: 12px; }

  .leaflet-control-zoom a { width: 40px !important; height: 40px !important; line-height: 40px !important; font-size: 20px !important; }
}
