:root {
  --ink: #1a1d1f;
  --paper: #f7f6f3;
  --panel: #ffffff;
  --line: #e2ded5;
  --b1: #D92B26;
  --b2: #F1B80E;
  --rail: #0072CE;
  --accent: #1d4ed8;
  --origin: #2f6f4f;
  --dest: #b3392c;
  --muted: #6b6a65;
  --ride: #ff8200;
  --non-ride: #333434;
  --exist-bus: #ff8200;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--ink);
  color: var(--paper);
  border-bottom: 3px solid var(--accent);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-size: 26px;
  color: var(--accent);
}

.brand h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: #b9b7ae;
  font-family: var(--mono);
}

.legend {
  display: flex;
  gap: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: #d8d6cd;
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.swatch {
  width: 16px;
  height: 3px;
  display: inline-block;
  border-radius: 2px;
}
.swatch.b1 { background: var(--b1); }
.swatch.b2 { background: var(--b2); }
.swatch.rail { background: var(--rail); }

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1;
  background: #e9e7e0;
}

#panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  order: -1; /* sidebar sits left of the map on desktop; see mobile override below */
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

#panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
  cursor: pointer;
}
#panel-title:hover {
  text-decoration: underline;
}

#tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.toggle-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-row + .toggle-row {
  margin-top: 10px;
}

.tab-btn {
  flex: 1;
  padding: 13px 10px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.tab-panel.hidden { display: none; }

.panel-block {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-block.hidden { display: none; }

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  color: var(--ink);
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 10px;
  border-radius: 3px;
  vertical-align: middle;
  background-color: var(--paper);
}
.swatch-20 { background-color: rgba(29, 78, 216, 0.55); }
.swatch-40 { background-color: rgba(29, 78, 216, 0.32); }
.swatch-60 { background-color: rgba(29, 78, 216, 0.16); }

.search-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-field {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--accent); }

.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  max-height: 220px;
  overflow-y: auto;
}

.suggestion-item {
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover,
.suggestion-item.highlighted {
  background: var(--paper);
}

.suggestion-empty {
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
}

.instruction-banner {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.instruction-banner p {
  margin: 0;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--ink);
}

.instruction-banner .button-row {
  margin-top: 10px;
}

.button-row {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
}
.btn-secondary:hover { border-color: var(--ink); color: var(--ink); }

.combo-row {
  display: flex;
  gap: 6px;
}

.combo-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--sans);
}
.combo-btn:hover { border-color: var(--muted); }

.combo-btn.active {
  background: var(--ink);
  border-color: var(--ink);
}
.combo-btn.active .combo-label,
.combo-btn.active .combo-time {
  color: var(--paper);
}

.combo-btn.unavailable {
  opacity: 0.45;
  cursor: default;
}
.combo-btn.unavailable:hover { border-color: var(--line); }
.combo-btn.unavailable.active { opacity: 0.7; }

.combo-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}

.combo-time {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

#summary { text-align: left; }

.summary-total {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
}
.summary-unit {
  font-size: 15px;
  color: var(--muted);
  margin-left: 3px;
}

.time-bar {
  display: flex;
  width: 100%;
  height: 8px;
  margin-top: 12px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--non-ride);
}

.time-bar-seg {
  height: 100%;
}
.time-bar-seg.is-other { background: var(--non-ride); }
.time-bar-seg.is-ride { background: var(--ride); border-radius: 4px; }

#itinerary h2,
#iso-legend h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}

#itinerary-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#itinerary-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  font-size: 13px;
  line-height: 1.4;
}

#itinerary-list li.type-ride {
  align-items: stretch;
  padding-bottom: 18px;
}

.leg-marker {
  flex: 0 0 18px;
  width: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.marker-icon {
  color: var(--non-ride);
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-bar {
  width: 8px;
  min-height: 32px;
  border-radius: 4px;
  background: var(--ride);
  align-self: stretch;
}

.leg-content {
  flex: 1;
  min-width: 0;
}

.leg-main {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
}

.leg-route-name {
  display: block;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.leg-sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

#empty-state p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 8px;
}
#empty-state .hint {
  font-size: 11.5px;
  font-family: var(--mono);
}

.leaflet-popup-content { font-family: var(--sans); font-size: 12px; }

/* ---------------------------------------------------------------------
   Mobile layout — below this width the side-by-side map/sidebar becomes
   a stacked layout: map on top, panel below. The panel is capped to a
   small slice of the screen so the map always stays mostly visible (no
   full-screen "bottom sheet" takeover) — the panel itself scrolls for
   any content that doesn't fit. Desktop layout above this width is
   completely unchanged.
   ------------------------------------------------------------------- */
@media (max-width: 700px) {
  #layout {
    flex-direction: column;
  }

  #panel {
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--line);
    flex: 0 0 auto;
    max-height: 42.5vh; /* 70% more than the original 25vh */
    order: 1; /* undo the desktop left-sidebar order — map stays on top on mobile */
  }

  /* Isochrone tab: lay the legend out horizontally instead of stacked, so
     it takes up far less of the panel's height and leaves more room for
     the map. */
  #iso-legend {
    padding: 14px 20px;
  }

  #iso-legend h2 {
    margin: 0 0 8px;
  }

  .legend-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px 16px;
  }
}

/* ---------------------------------------------------------------------
   Preview mode (?preview=1) — used when the map is embedded read-only
   (a blog post, a shared screenshot, etc.). The map stays pannable and
   zoomable, but the full sidebar chrome (title, reset/share, click
   instructions, summary, itinerary) is stripped down to just the
   up-to-four network combo tabs, plus the travel-time legend on the
   Isochrone tab — shown as a slim strip across the full width of the
   bottom of the screen rather than a side/bottom panel. The title/
   Reset/Share bar stays, just shrunk down (see reset-btn/share-btn/
   panel-title's preview-mode behavior in app.js — they act differently
   in preview: Reset restores the view, Share shares the plain non-
   preview URL, and the title opens the non-preview URL in a new tab).
   This layout applies at every viewport size (mobile portrait *and* a
   half-width laptop-screen embed), so it's written unconditionally
   rather than inside the max-width: 700px block above, and !important
   is used where needed to win over that block's own #panel/#layout
   rules.
   ------------------------------------------------------------------- */
body.preview-mode #layout {
  flex-direction: column;
}

body.preview-mode #map {
  cursor: default;
}

body.preview-mode #panel {
  width: 100% !important;
  flex: 0 0 auto !important;
  min-height: 15vh;
  max-height: none !important;
  border-right: none;
  border-top: 1px solid var(--line);
  overflow: visible;
  order: 1 !important; /* map stays on top in preview embeds too */
}

/* Hide the tab switcher and the journey-detail blocks; the title/Reset/
   Share bar and the combo tabs (+ legend on the Isochrone tab) stay. */
body.preview-mode #tabs,
body.preview-mode .instruction-banner,
body.preview-mode #summary,
body.preview-mode #itinerary,
body.preview-mode #empty-state,
body.preview-mode .search-block {
  display: none !important;
}

body.preview-mode #panel-header {
  padding: 8px 14px;
}

body.preview-mode #combo-selector,
body.preview-mode #iso-combo-selector {
  display: block !important;
}

body.preview-mode .panel-block {
  padding: 8px 14px;
  border-bottom: none;
}

/* Isochrone tab's legend: lay it out horizontally like the mobile view
   above, so it, the combo row, and the header all fit inside 15vh. */
body.preview-mode #iso-legend {
  padding: 4px 14px 8px;
}

body.preview-mode #iso-legend h2 {
  display: none;
}

body.preview-mode .legend-list {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px 14px;
}

body.preview-mode .combo-btn {
  padding: 5px 4px;
}