:root {
  --bg: #0b1117;
  --panel-bg: rgba(17, 24, 33, 0.92);
  --panel-border: #263241;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #2dd4bf;
  --accent-2: #3b82f6;
  --danger: #ef4444;
  --warn: #f59e0b;
  --fire: #ff5722;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

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

/* ---------- Top bar ---------- */

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  /* Higher than #layers-panel (1000) so the basemap dropdown — nested
     inside #topbar and thus confined to its stacking context — can
     actually render above the sidebar instead of behind it. */
  z-index: 1010;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(11,17,23,0.95), rgba(11,17,23,0.0));
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

/* Push Leaflet's top-left controls (the drawing toolbar) below our own
   fixed header, which would otherwise sit on top of it. */
.leaflet-top.leaflet-left {
  margin-top: 62px;
}

#brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

#brand-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

#statusline {
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#statusline .sep { margin: 0 6px; opacity: 0.5; }
#auth-badge { padding: 1px 6px; border-radius: 4px; background: #1c2734; }

#topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#btn-settings, #btn-basemap, #btn-zoom-in, #btn-zoom-out, #btn-measure {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
}
#btn-settings:hover, #btn-basemap:hover, #btn-zoom-in:hover, #btn-zoom-out:hover, #btn-measure:hover {
  border-color: var(--accent);
}
#btn-measure.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

#zoom-control { display: flex; gap: 8px; }

#basemap-control { position: relative; }

#basemap-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1001;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
#basemap-menu.hidden { display: none; }
#basemap-menu label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}
#basemap-menu label:hover { background: rgba(255, 255, 255, 0.06); }
#basemap-menu input { accent-color: var(--accent); }

/* ---------- Error banner ---------- */

#error-banner {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: #3a1414;
  border: 1px solid var(--danger);
  color: #fecaca;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 90vw;
}
#error-banner.hidden { display: none; }

/* ---------- Side panel ---------- */

#layers-panel {
  position: absolute;
  top: 60px;
  right: 12px;
  z-index: 1000;
  width: 260px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px;
  backdrop-filter: blur(6px);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
#layers-panel.hidden {
  transform: translateX(300px);
  opacity: 0;
  pointer-events: none;
}

.panel-tabs {
  display: flex;
  gap: 4px;
  margin: -4px -4px 14px;
  border-bottom: 1px solid var(--panel-border);
}
.panel-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-dim);
  padding: 8px 4px;
  font-size: 13px;
  cursor: pointer;
}
.panel-tab:hover { color: var(--text); }
.panel-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.panel-tab-content.hidden { display: none; }

.panel-section { margin-bottom: 16px; }
.panel-section:last-child { margin-bottom: 0; }
.panel-section h3 {
  margin: 0 0 8px 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}
.panel-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-section-head h3 { margin: 0; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 13.5px;
}
.layer-row input { accent-color: var(--accent); }

#btn-new-layer, #btn-clear-filter {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--accent);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 12px;
}
#btn-new-layer:hover, #btn-clear-filter:hover { border-color: var(--accent); }

#layers-panel .panel-section .field { margin-bottom: 8px; }
#layers-panel .panel-section .field:last-child { margin-bottom: 0; }


#custom-layers-list { margin-top: 6px; }

.custom-layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.custom-layer-row:hover { background: rgba(255,255,255,0.04); }
.custom-layer-row.active { border-color: var(--accent); background: rgba(45,212,191,0.08); }

.custom-layer-row .swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.custom-layer-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  font-size: 13px;
}
.custom-layer-row button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
.custom-layer-row button:hover { color: var(--text); }

.hint {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
  margin: 8px 0 0 0;
}

#panel-toggle {
  position: absolute;
  top: 60px;
  right: 12px;
  z-index: 999;
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  display: none;
}
#panel-toggle.show { display: block; }

/* ---------- Selected-aircraft panel ---------- */

#aircraft-panel {
  position: absolute;
  left: 12px;
  /* Shifted up to leave room for the scale bar, which now also lives in
     this corner (see L.control.scale in app.js). */
  bottom: 52px;
  z-index: 1000;
  width: 300px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}
#aircraft-panel.hidden { display: none; }

#btn-close-aircraft-panel {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  z-index: 1;
}
#btn-close-aircraft-panel:hover { color: var(--text); }

#aircraft-panel-photo-wrap {
  position: relative;
  width: 100%;
  height: 150px;
  background: #0b1117;
  border-radius: 10px 10px 0 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#aircraft-panel-photo-link {
  display: none;
  width: 100%;
  height: 100%;
}
#aircraft-panel-photo-wrap.has-photo #aircraft-panel-photo-link { display: block; }
#aircraft-panel-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#aircraft-panel-photo-placeholder {
  font-size: 40px;
  color: var(--panel-border);
}
#aircraft-panel-photo-wrap.has-photo #aircraft-panel-photo-placeholder { display: none; }

#aircraft-panel-body { padding: 12px 14px 14px; }

#aircraft-panel-stale {
  color: var(--warn);
  font-size: 12px;
  margin-bottom: 6px;
}
#aircraft-panel-stale.hidden { display: none; }

#aircraft-panel-list {
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
  margin-bottom: 10px;
}
#aircraft-panel-list .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--panel-border);
}
#aircraft-panel-list .row:last-child { border-bottom: none; }
#aircraft-panel-list .row span:first-child { color: var(--text-dim); }
#aircraft-panel-list .row span:last-child { text-align: right; }
#aircraft-panel-list .row.lead span:last-child { font-size: 15px; font-weight: 700; color: var(--text); }

#aircraft-panel-credit {
  display: block;
  margin-top: 8px;
  color: var(--text-dim);
  text-decoration: none;
}
#aircraft-panel-credit:hover { color: var(--accent); }
#aircraft-panel-credit.hidden { display: none; }

@media (max-width: 640px) {
  #aircraft-panel { left: 8px; right: 8px; width: auto; bottom: 8px; }
}

/* ---------- Modals ---------- */

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

.modal-box {
  background: #131c26;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 20px;
  width: 320px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 14px 0; }
#settings-modal .modal-box { width: 380px; }
.modal-section-title {
  margin-top: 18px !important;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  font-size: 12px !important;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.data-sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12.5px;
  color: var(--text-dim);
}
.data-sources-list li {
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.data-sources-list li:last-child { border-bottom: none; }
.data-sources-list a {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}
.data-sources-list a:hover { text-decoration: underline; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.field input[type="text"], .field input[type="color"] {
  background: #0b1117;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 13.5px;
}
.field input[type="color"] { padding: 2px; height: 34px; cursor: pointer; }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
}
.modal-actions button {
  background: var(--accent-2);
  border: none;
  color: white;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.modal-actions button:hover { filter: brightness(1.1); }
.modal-actions button.danger { background: var(--danger); margin-right: auto; }
.modal-actions button:not(.danger):not(:first-child):last-child {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text);
}

/* ---------- Aircraft markers ---------- */

.ac-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
}
.ac-icon svg { display: block; overflow: visible; }
.ac-icon .plane-shape {
  fill: var(--accent-2);
  stroke: #0b1117;
  stroke-width: 0.5;
}
.ac-icon.ground .plane-shape { fill: #6b7280; }
.ac-icon.military .plane-shape { fill: var(--warn); }
.ac-icon.wildfire .plane-shape { fill: var(--fire); }
/* Altitude-coloring mode ("Höhenfarbe") wins over the ground/military/
   wildfire fill above when enabled — same selector specificity, so source
   order decides. --ac-color is set inline per marker in planeIconHtml(). */
.ac-icon.alt-color .plane-shape { fill: var(--ac-color, var(--accent-2)); }
.ac-icon.selected .plane-shape {
  stroke: var(--accent);
  stroke-width: 1.6;
}
.ac-icon.selected svg { filter: drop-shadow(0 0 4px var(--accent)); }

/* Line-art icons (helicopters) — strokes carry the color, no fill. */
.ac-icon .rotor-line {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 2;
  stroke-linecap: round;
}
.ac-icon.ground .rotor-line { stroke: #6b7280; }
.ac-icon.military .rotor-line { stroke: var(--warn); }
.ac-icon.wildfire .rotor-line { stroke: var(--fire); }
.ac-icon.alt-color .rotor-line { stroke: var(--ac-color, var(--accent-2)); }
.ac-icon.selected .rotor-line { stroke: var(--accent); stroke-width: 2.6; }

.leaflet-tooltip.ac-label {
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000;
  white-space: nowrap;
  transform: translate(10px, -5px);
  pointer-events: none;
}
.leaflet-tooltip.ac-label::before {
  display: none;
}

/* ---------- Altitude-color legend ---------- */

#altitude-legend {
  position: absolute;
  /* Top-left rather than bottom-left: that corner already holds the
     aircraft-detail panel (much taller, higher z-index) and the scale bar
     — sharing it made the legend get hidden behind the aircraft panel
     whenever both were visible at once. */
  top: 60px;
  left: 12px;
  z-index: 900;
  width: 230px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 12px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
#altitude-legend.hidden { display: none; }
.altitude-legend-title {
  font-weight: 600;
  letter-spacing: .04em;
  margin-bottom: 6px;
  color: var(--text);
}
.altitude-legend-bar {
  height: 8px;
  border-radius: 4px;
  /* Same hue sweep (0deg red -> 300deg magenta over 0-40000ft) as
     altitudeColorHsl() in app.js — keep both in sync. */
  background: linear-gradient(to right,
    hsl(0, 85%, 55%), hsl(60, 85%, 55%), hsl(120, 85%, 55%),
    hsl(180, 85%, 55%), hsl(240, 85%, 55%), hsl(300, 85%, 55%));
}
.altitude-legend-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

/* ---------- Airport markers ---------- */

.airport-icon {
  border-radius: 50%;
  background: #94a3b8;
  border: 1px solid #0b1117;
}
.airport-icon.large { background: #f59e0b; }

.airport-popup .name { font-weight: 700; margin-bottom: 2px; }
.airport-popup .row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.airport-popup .row span:first-child { color: var(--text-dim); }

/* ---------- Wildfire & tanker-base markers ---------- */

.wildfire-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  filter: drop-shadow(0 0 2px #0b1117);
}
.wildfire-icon.large { font-size: 20px; }

.tanker-base-icon {
  width: 10px; height: 10px;
  background: var(--accent-2);
  border: 1.5px solid #0b1117;
  transform: rotate(45deg);
}

.calfire-station-icon {
  width: 9px; height: 9px;
  background: var(--danger);
  border: 1.5px solid #0b1117;
  border-radius: 2px;
}

.wildfire-popup .name, .tanker-base-popup .name, .fire-hotspot-popup .name, .smoke-popup .name,
.calfire-station-popup .name { font-weight: 700; margin-bottom: 2px; }
.wildfire-popup .row, .tanker-base-popup .row, .fire-hotspot-popup .row, .smoke-popup .row,
.calfire-station-popup .row {
  display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px;
}
.wildfire-popup .row span:first-child, .tanker-base-popup .row span:first-child,
.fire-hotspot-popup .row span:first-child, .smoke-popup .row span:first-child,
.calfire-station-popup .row span:first-child { color: var(--text-dim); }

.wildfire-search-link {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent-2);
  text-decoration: none;
}
.wildfire-search-link:hover { text-decoration: underline; }

/* ---------- Sidebar wildfire-aircraft list ---------- */

.hint-inline { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-dim); }
#wildfire-tab-count { margin-left: 4px; color: var(--text-dim); font-weight: 400; }
.panel-tab.active #wildfire-tab-count { color: var(--text); }

#wildfire-ac-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.wildfire-ac-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 87, 34, 0.08);
  border: 1px solid rgba(255, 87, 34, 0.25);
  cursor: pointer;
  font-size: 12.5px;
}
.wildfire-ac-row:hover { background: rgba(255, 87, 34, 0.18); }
.wildfire-ac-row .callsign { font-weight: 600; }
.wildfire-ac-row .meta { color: var(--text-dim); text-align: right; }
#wildfire-ac-hint.hidden { display: none; }

/* ---------- Leaflet overrides ---------- */

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: #131c26;
  color: var(--text);
}
.leaflet-container a.leaflet-popup-close-button { color: var(--text-dim); }
.leaflet-control-attribution {
  background: rgba(11,17,23,0.7) !important;
  color: var(--text-dim) !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }

.leaflet-control-scale-line {
  background: var(--panel-bg) !important;
  border: 1px solid var(--panel-border) !important;
  border-top: 1px solid var(--panel-border) !important;
  color: var(--text) !important;
  box-shadow: none !important;
  backdrop-filter: blur(4px);
}

/* ---------- Distance measurement tool ---------- */

#map.measuring { cursor: crosshair; }

.measure-label {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.measure-hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
}

@media (max-width: 640px) {
  #layers-panel { width: calc(100vw - 24px); }
  #brand-name { display: none; }
}

#clocks {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#clocks b { color: var(--text); font-weight: 600; }
#clocks small { opacity: 0.7; }
@media (max-width: 900px) {
  #clocks small { display: none; }
}
@media (max-width: 700px) {
  #clocks { display: none; }
}
