:root {
  --toolbar-bg: #1a2332;
  --toolbar-elev: #243044;
  --toolbar-border: #334155;
  --text: #e8eef7;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --danger: #f87171;
  --toolbar-h: 52px;
  --font: "Source Sans 3", "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: #0f172a;
}

.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  min-height: var(--toolbar-h);
  height: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.4rem 0.75rem;
  background: linear-gradient(180deg, var(--toolbar-bg), var(--toolbar-elev));
  border-bottom: 1px solid var(--toolbar-border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.search {
  display: flex;
  gap: 0.35rem;
  min-width: 12rem;
  flex: 1 1 14rem;
  max-width: 22rem;
}

.search input,
.field select,
.mode button {
  font: inherit;
  color: var(--text);
  background: #0f172a;
  border: 1px solid var(--toolbar-border);
  border-radius: 4px;
  padding: 0.35rem 0.55rem;
}

.search input {
  flex: 1;
  min-width: 0;
}

.search button,
.mode button {
  cursor: pointer;
  background: var(--accent);
  border-color: transparent;
  white-space: nowrap;
}

.search button:hover {
  background: var(--accent-hover);
}

.side-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--toolbar-border);
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.35);
}

.side-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.overlay-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.overlay-toggle {
  user-select: none;
  cursor: pointer;
}

.overlay-toggle input {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

.overlay-source-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--toolbar-border);
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.55);
  font-size: 0.8rem;
  color: var(--muted);
}

.overlay-source-menu label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  white-space: nowrap;
}

.overlay-source-menu label.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.overlay-source-menu input {
  accent-color: var(--accent);
}

.overlay-marker-filter {
  font: inherit;
  color: var(--text);
  background: #0f172a;
  border: 1px solid var(--toolbar-border);
  border-radius: 4px;
  padding: 0.35rem 0.55rem;
  min-width: 8rem;
  max-width: 14rem;
}

.layers-open,
.layers-close {
  font: inherit;
  color: var(--text);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  white-space: nowrap;
}

.layers-open {
  display: none;
}

.layers-panel-head {
  display: none;
}

.layers-scrim {
  display: none;
}

/* Flex wrapper (not display:contents) so <select> dropdowns stay usable */
.layers-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.field select {
  max-width: 14rem;
  background: #0f172a;
}

.mode {
  display: flex;
  gap: 0;
}

.mode button {
  background: #0f172a;
  border-radius: 0;
}

.mode button:first-child {
  border-radius: 4px 0 0 4px;
}

.mode button:last-child {
  border-radius: 0 4px 4px 0;
}

.mode button.active {
  background: var(--accent);
  border-color: transparent;
}

#map-root {
  position: fixed;
  /* top set in JS from measured .toolbar height so wrapped rows never cover zoom */
  top: var(--toolbar-h);
  left: 0;
  right: 0;
  bottom: 0;
}

.map-pane {
  position: absolute;
  inset: 0;
}

.map-pane.hidden {
  display: none;
}

.sbs {
  display: flex;
}

.sbs-half {
  flex: 1;
  height: 100%;
  position: relative;
}

.sbs-half + .sbs-half {
  border-left: 1px solid var(--toolbar-border);
}

.date-badge {
  position: absolute;
  z-index: 500;
  top: 10px;
  padding: 0.35rem 0.6rem;
  background: rgba(26, 35, 50, 0.88);
  border: 1px solid var(--toolbar-border);
  border-radius: 4px;
  font-size: 0.8rem;
  pointer-events: none;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-badge.before {
  left: 10px;
}

.date-badge.after {
  right: 10px;
}

.toast {
  position: fixed;
  z-index: 2000;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #7f1d1d;
  color: #fecaca;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.toast[hidden] {
  display: none;
}

.leaflet-container {
  background: #0b1220;
  font: inherit;
}

.swipe-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 44px;
  margin-left: -22px;
  z-index: 500;
  cursor: ew-resize;
  touch-action: none;
  display: flex;
  justify-content: center;
}

.swipe-divider::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.55);
}

.swipe-handle {
  position: absolute;
  top: 50%;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #cbd5e1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.swipe-handle::before,
.swipe-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -5px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.swipe-handle::before {
  left: 10px;
  border-right: 7px solid #334155;
}

.swipe-handle::after {
  right: 10px;
  border-left: 7px solid #334155;
}

@media (max-width: 700px) {
  .layers-open {
    display: inline-flex;
  }

  .layers-panel {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, var(--toolbar-elev), var(--toolbar-bg));
    border-top: 1px solid var(--toolbar-border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
    /* No overflow:auto — it dismisses/clips native <select> pickers on mobile */
    max-height: min(85vh, 32rem);
  }

  .layers-panel.is-open {
    display: flex;
  }

  .layers-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
  }

  .layers-close {
    background: #0f172a;
    border-color: var(--toolbar-border);
  }

  .layers-scrim {
    display: none;
    position: fixed;
    inset: 0;
    /* Below .toolbar (1000): panel lives inside the toolbar stacking context.
       A higher scrim was intercepting taps on the version <select> and closing the sheet. */
    z-index: 950;
    background: rgba(15, 23, 42, 0.55);
  }

  .layers-scrim.is-open {
    display: block;
  }

  .layers-panel .side-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .layers-panel .field {
    justify-content: space-between;
  }

  .layers-panel .field select {
    max-width: none;
    flex: 1;
  }

  .overlay-marker-filter {
    max-width: none;
    width: 100%;
    min-width: 0;
  }

  .overlay-controls {
    flex-wrap: wrap;
    flex: 1 1 100%;
  }

  .overlay-source-menu {
    flex: 1 1 100%;
  }
}

@media (max-width: 900px) {
  .toolbar {
    padding: 0.5rem 0.75rem;
  }
}
