:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --border: #2d3a4f;
  --text: #e8eef6;
  --muted: #8b9bb4;
  --accent: #3d9cf0;
  --accent-2: #f0a03d;
  --er-yes: #2ecc71;
  --er-partial: #f39c12;
  --er-no: #95a5a6;
  --air: #5dade2;
  --road: #58d68d;
  --ferry: #a569bd;
  --walk: #f5b041;
  --charter: #ec7063;
  --stay: #85929e;
  --taxi: #48c9b0;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }

.app {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: .02em;
}

header .sub {
  color: var(--muted);
  font-size: .8rem;
  flex: 1;
  min-width: 180px;
}

header .actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: .8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #041018; font-weight: 600; }

.list-pane {
  overflow: auto;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 10px;
}

.map-pane {
  position: relative;
  background: #0a1018;
  min-height: 280px;
}

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

.map-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: linear-gradient(160deg, #152033, #0d1520);
  z-index: 2;
}
.map-fallback.visible { display: flex; }
.map-fallback .card {
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.map-fallback h2 { margin: 0 0 8px; font-size: 1.1rem; }
.map-fallback p { margin: 0 0 10px; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.map-fallback code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; font-size: .8rem; }

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 3;
  background: rgba(26,35,50,.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .72rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  max-width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i {
  width: 18px; height: 0;
  border-top: 3px solid;
  display: inline-block;
}
.legend i.dashed { border-top-style: dashed; }
.legend i.dotted { border-top-style: dotted; border-top-width: 3px; }

.leg {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.leg:hover { border-color: #3d5270; }
.leg.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.leg-summary {
  display: grid;
  grid-template-columns: 28px 64px 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
}
.leg-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.seq {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: .75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.leg.active .seq { background: var(--accent); color: #041018; }

.date {
  font-size: .72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.mode-icon {
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.route {
  font-size: .84rem;
  font-weight: 560;
  line-height: 1.25;
  min-width: 0;
}
.route .codes {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
  margin-top: 2px;
}

.meta-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: .7rem;
  color: var(--muted);
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge.yes { background: rgba(46,204,113,.18); color: var(--er-yes); }
.badge.partial { background: rgba(243,156,18,.18); color: var(--er-partial); }
.badge.no { background: rgba(149,165,166,.15); color: var(--er-no); }

.leg-details {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  line-height: 1.45;
  color: #c5d0e0;
}
.leg.open .leg-details { display: block; }

.leg-details dl {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 10px;
  margin: 12px 0 0;
}
.leg-details dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.leg-details dd { margin: 0; }
.leg-details .notes {
  margin-top: 10px;
  padding: 10px;
  background: var(--panel-2);
  border-radius: 8px;
  white-space: pre-wrap;
}
.leg-details .source {
  margin-top: 8px;
  font-size: .72rem;
  color: var(--muted);
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 0 2px;
}
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .7rem;
  cursor: pointer;
}
.chip.on { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

.status {
  font-size: .72rem;
  color: var(--muted);
  padding: 4px 2px 10px;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(40vh, 45vh) 1fr;
    height: auto;
    min-height: 100vh;
  }
  .map-pane {
    grid-row: 2;
    min-height: 40vh;
    height: 45vh;
  }
  .list-pane {
    grid-row: 3;
    border-right: none;
    border-top: 1px solid var(--border);
    max-height: none;
  }
  header { position: sticky; top: 0; }
}

.badge.phase-pre { background: rgba(93,173,226,.18); color: #5dade2; }
.badge.phase-earth-river { background: rgba(46,204,113,.18); color: #2ecc71; }
.badge.phase-post { background: rgba(240,160,61,.18); color: #f0a03d; }
#copy-link.copied { border-color: var(--er-yes); color: var(--er-yes); }

/* Map popup contrast: dark text on white popup (Mapbox + Google) */
.mapboxgl-popup-content, .gm-style .gm-style-iw-c, .gm-style .gm-style-iw-d {
  color: #111 !important;
}
.mapboxgl-popup-content *, .gm-style .gm-style-iw-d * {
  color: #111 !important;
  opacity: 1 !important;
}
.mapboxgl-popup-content strong, .gm-style .gm-style-iw-d strong { font-weight: 700; }
.mapboxgl-popup-close-button { color: #333 !important; font-size: 18px; }
