:root {
  --bg-panel: rgba(7, 11, 16, 0.86);
  --text: #d7e6ec;
  --text-dim: #7d94a3;
  --accent: #22d3ee;
  --accent-soft: rgba(34, 211, 238, 0.14);
  --accent-glow: rgba(34, 211, 238, 0.35);
  --border: rgba(34, 211, 238, 0.22);
  --danger: #ff5f6d;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Aircraft sit on the tiles rather than on the panel, so they need a colour
     that contrasts with the basemap. Default to the light-tile treatment:
     magenta with a dark halo, which also reads well on satellite imagery. Any
     future light basemap then gets a sensible colour without further changes. */
  --aircraft-color: #ff2d95;
  --aircraft-glow: rgba(0, 0, 0, 0.55);
}

:root[data-basemap="dark"] {
  --aircraft-color: #a3e635;
  --aircraft-glow: rgba(163, 230, 53, 0.7);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--mono);
  background: #05070a;
}

#map {
  height: 100%;
  width: 100%;
  background: #05070a;
}

.leaflet-tile-pane {
  filter: saturate(0.9);
}

/* Leaflet chrome re-themed to match the panel */
.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--accent) !important;
  border: 1px solid var(--border) !important;
  backdrop-filter: blur(8px);
}
.leaflet-control-zoom a:hover {
  background: var(--accent-soft) !important;
}
.leaflet-control-attribution {
  background: rgba(5, 7, 10, 0.7) !important;
  color: var(--text-dim) !important;
  font-family: var(--mono);
  font-size: 0.68rem !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }

/* Control panel */
#control-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 250px;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 24px rgba(34, 211, 238, 0.06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  /* Keeps the panel (header + collapse controls) reachable even when the
     content below is taller than the viewport. */
  max-height: calc(100vh - 32px);
}

.corner {
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: var(--accent);
  opacity: 0.75;
  pointer-events: none;
}
.corner-tl { top: -1px; left: -1px; border-top: 2px solid; border-left: 2px solid; }
.corner-tr { top: -1px; right: -1px; border-top: 2px solid; border-right: 2px solid; }
.corner-bl { bottom: -1px; left: -1px; border-bottom: 2px solid; border-left: 2px solid; }
.corner-br { bottom: -1px; right: -1px; border-bottom: 2px solid; border-right: 2px solid; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-mark {
  color: var(--accent);
  filter: drop-shadow(0 0 5px var(--accent-glow));
  flex-shrink: 0;
}
.logo-pulse {
  animation: logo-pulse 2.4s ease-in-out infinite;
  transform-origin: 20px 20px;
}
@keyframes logo-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(1.7); }
}

.panel-title-block {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  margin-right: auto;
}
.panel-title {
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  color: var(--text);
}
.panel-subtitle {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 6px #2ecc71;
  animation: live-blink 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes live-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--border);
  background: var(--accent-soft);
}
.icon-btn svg { transition: transform 0.2s ease; }
#control-panel.collapsed #collapse-btn svg { transform: rotate(-90deg); }

.panel-body {
  overflow-y: auto;
  overflow-x: hidden;
  /* Flex items default to min-height:auto, which would prevent this from
     ever shrinking below its content size and defeat the scrolling above. */
  min-height: 0;
  /* The actual cap is #control-panel's max-height (flex item shrinks to
     fit); this just needs to be tall enough to never clip real content. */
  max-height: 2000px;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
  opacity: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.panel-body::-webkit-scrollbar-thumb:hover { background: var(--accent); }

#control-panel.collapsed .panel-body {
  max-height: 0;
  opacity: 0;
}

/* Collapsible panel groups */
.panel-group {
  margin-top: 12px;
}
.panel-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.panel-group-header:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}
.group-count {
  color: var(--accent);
  opacity: 0.8;
  font-size: 0.64rem;
  text-transform: none;
  letter-spacing: normal;
}
.panel-group-header .chevron {
  margin-left: auto;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.panel-group.collapsed .panel-group-header .chevron {
  transform: rotate(-90deg);
}
.panel-group.collapsed .panel-group-header {
  margin-bottom: 0;
}

.panel-group-content {
  overflow: hidden;
  max-height: 800px;
  opacity: 1;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}
.panel-group.collapsed .panel-group-content {
  max-height: 0;
  opacity: 0;
}

/* Search */
.search-box {
  position: relative;
  margin-top: 12px;
}
.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
#search-input {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 26px 7px 28px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search-input::placeholder { color: var(--text-dim); }
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.search-clear:hover { color: var(--accent); }

.search-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: rgba(7, 11, 16, 0.97);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.search-results li {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.search-results li:hover { background: var(--accent-soft); }
.result-name {
  font-size: 0.78rem;
  color: var(--text);
}
.result-detail {
  font-size: 0.64rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-empty {
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: default;
}
.search-empty:hover { background: transparent; }

.search-header {
  font-size: 0.64rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  cursor: default;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.search-header:hover { background: transparent; }

#search-input.is-loading {
  border-color: var(--accent);
  animation: search-loading 1.1s ease-in-out infinite;
}
@keyframes search-loading {
  0%, 100% { box-shadow: 0 0 4px var(--accent-glow); }
  50% { box-shadow: 0 0 14px var(--accent-glow); }
}

.search-hit {
  animation: search-pulse 1.6s ease-out infinite;
}
@keyframes search-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Location list */
.location-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.location-btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  padding: 5px 7px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.location-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.location-btn--district {
  border-left-color: var(--text-dim);
  opacity: 0.85;
}
.location-btn--all {
  grid-column: 1 / -1;
  border-left-color: var(--text-dim);
  color: var(--text-dim);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}

/* Basemap segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.segmented--three {
  grid-template-columns: 1fr 1fr 1fr;
}
.segmented button {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.segmented button:hover {
  color: var(--text);
  border-color: var(--accent);
}
.segmented button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}
.layer-toggle input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.layer-toggle--disabled {
  cursor: default;
  color: var(--text-dim);
}
.layer-toggle--disabled input { cursor: default; }

.count-badge {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--accent);
  opacity: 0.8;
}
.layer-note {
  font-size: 0.62rem;
  line-height: 1.4;
  color: var(--text-dim);
  padding: 2px 0 0 22px;
}

/* Map markers: aircraft */
.aircraft-divicon { background: none; border: none; }
.aircraft-badge {
  color: var(--aircraft-color);
  filter: drop-shadow(0 0 5px var(--aircraft-glow));
  transform-origin: center;
  line-height: 0;
}
.aircraft-badge--ground {
  color: var(--text-dim);
  filter: none;
  opacity: 0.7;
}

/* Map markers: traffic control reports */
.blitzer-divicon { background: none; border: none; }
.blitzer-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px 2px 4px;
  background: rgba(7, 11, 16, 0.9);
  border: 1px solid #f59e0b;
  border-radius: 4px;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
  white-space: nowrap;
  width: fit-content;
}
.blitzer-glyph { font-size: 0.72rem; line-height: 1; }
.blitzer-vmax {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: #f59e0b;
}

/* Installed cameras are permanent and far more numerous, so they sit back
   visually against the amber of the live mobile reports. */
.blitzer-badge--fixed {
  border-color: #64748b;
  box-shadow: none;
  opacity: 0.82;
}
.blitzer-badge--fixed .blitzer-vmax { color: #94a3b8; }

/* Map markers: rail stations */
.station-divicon { background: none; border: none; }
.station-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 16, 0.9);
  border: 1px solid #f87171;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.35);
}
.station-badge--large { width: 26px; height: 26px; }
.station-badge--large .station-glyph { font-size: 0.9rem; }
.station-badge--small { width: 19px; height: 19px; opacity: 0.85; }
.station-badge--small .station-glyph { font-size: 0.65rem; }
.station-badge--alert {
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
}
.station-glyph { line-height: 1; }

/* Departure board inside the station popup */
.dep-table {
  border-collapse: collapse;
  margin-top: 6px;
  font-size: 0.74rem;
  width: 100%;
}
.dep-table td { padding: 2px 6px 2px 0; white-space: nowrap; }
.dep-table td:first-child { color: var(--accent); }
.dep-table td:nth-child(3) {
  white-space: normal;
  max-width: 130px;
}
.dep-table td:last-child { color: var(--text-dim); text-align: right; }
.dep-delay { color: #fbbf24; margin-left: 3px; }
.dep-cancelled td { text-decoration: line-through; opacity: 0.5; }
.dep-empty {
  margin-top: 6px;
  font-size: 0.74rem;
  color: var(--text-dim);
}

/* Map markers: Sperrmüll */
.sperrmuell-divicon { background: none; border: none; }
.sperrmuell-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px 2px 5px;
  background: rgba(7, 11, 16, 0.9);
  border: 1px solid #c084fc;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.35);
  white-space: nowrap;
  width: fit-content;
}
.sperrmuell-badge--past { opacity: 0.4; }
.sperrmuell-glyph { font-size: 0.72rem; line-height: 1; }
.sperrmuell-day {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: #c084fc;
}

.soon-badge {
  margin-left: auto;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.legend-caption {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.75;
  margin: 8px 0 4px;
}
.legend-caption:first-child { margin-top: 0; }

.aq-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.aq-legend > span { white-space: nowrap; }
.aq-legend > span > span {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.panel-footer {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.6rem;
  line-height: 1.5;
  color: var(--text-dim);
}
.panel-footer a { color: var(--text-dim); }
.panel-footer a:hover { color: var(--accent); }

/* Map markers: weather badge */
.weather-divicon { background: none; border: none; }
.weather-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 5px;
  background: rgba(7, 11, 16, 0.88);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.2);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  width: fit-content;
}
.weather-glyph { font-size: 1.05rem; line-height: 1; }
.weather-temp {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

/* Map markers: fuel price badge */
.fuel-divicon { background: none; border: none; }
.fuel-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px 2px 4px;
  background: rgba(7, 11, 16, 0.9);
  border: 1px solid var(--fuel-color, var(--border));
  border-radius: 4px;
  box-shadow: 0 0 8px color-mix(in srgb, var(--fuel-color, #22d3ee) 35%, transparent);
  white-space: nowrap;
  width: fit-content;
}
.fuel-badge--closed { opacity: 0.45; }
.fuel-pin { font-size: 0.72rem; line-height: 1; }
.fuel-price {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--fuel-color, var(--text));
}

.fuel-table {
  border-collapse: collapse;
  margin: 5px 0;
  font-size: 0.78rem;
}
.fuel-table td { padding: 1px 10px 1px 0; }
.fuel-table td:last-child { color: var(--accent); text-align: right; }

/* Leaflet popup theming (always dark/HUD, regardless of basemap) */
.kaleidoscope-popup .leaflet-popup-content-wrapper {
  background: #0d1219;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 16px rgba(34, 211, 238, 0.08);
  font-family: var(--mono);
}
.kaleidoscope-popup .leaflet-popup-tip {
  background: #0d1219;
  border: 1px solid var(--border);
}
.kaleidoscope-popup .leaflet-popup-close-button {
  color: var(--text-dim) !important;
}
.fr24-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
}
.fr24-link:hover { text-decoration-color: currentColor; }

.popup-body { font-size: 0.85rem; line-height: 1.5; }
.popup-body strong { font-size: 1rem; color: var(--accent); }
.popup-body small { opacity: 0.6; }
