/* ── Design tokens ─────────────────────────────────── */
:root {
  --bg-map:          #f0ede8;
  --bg-ui:           #ffffff;
  --border:          #e2deda;
  --text:            #1a1917;
  --text-muted:      #6b6762;

  --bus:             #1a4d6e;
  --rail:            #c07010;
  --ferry:           #2a7fc2;
  --underground:     #5a3a8a;

  --on-time:         #1a7a4a;
  --late-warn:       #d98020;
  --late-urgent:     #d94040;
  --early:           #2a7fc2;
  --cancelled:       #999999;

  --dep-due:         #d94040;   /* < 2 min */
  --dep-soon:        #d98020;   /* 2–10 min */
  --dep-later:       #1a7a4a;   /* > 10 min */

  --bottom-bar-h:    104px;     /* search row + tabs */
  --sidebar-w:       270px;
  --radius:          12px;
  --radius-sm:       8px;
  --shadow:          0 2px 12px rgba(0,0,0,.12);
}

/* ── Reset & base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-map);
}

/* ── Map ───────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  bottom: var(--bottom-bar-h);  /* leave room for bottom bar on mobile */
}

.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
  bottom: calc(var(--bottom-bar-h) + 8px);
}

/* ── Panel utility ─────────────────────────────────── */
.panel {
  background: var(--bg-ui);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.panel.hidden { display: none; }

/* ── Desktop: layer toggles (top left) ─────────────── */
#layer-toggles {
  display: none;  /* hidden on mobile */
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-btn {
  display: none;  /* shown by desktop media query */
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-ui);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color .15s, border-color .15s;
}

.layer-btn.active[data-mode="bus"]        { color: var(--bus);         border-color: var(--bus); }
.layer-btn.active[data-mode="rail"]       { color: var(--rail);        border-color: var(--rail); }
.layer-btn.active[data-mode="ferry"]      { color: var(--ferry);       border-color: var(--ferry); }
.layer-btn.active[data-mode="underground"]{ color: var(--underground); border-color: var(--underground); }

/* ── Desktop: search bar (top centre) ──────────────── */
#desktop-search {
  display: none;  /* shown by desktop media query */
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  flex-direction: row;
  align-items: center;
  gap: 0;
  width: min(420px, calc(100vw - 300px));
  background: var(--bg-ui);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#desktop-search input {
  flex: 1;
  border: none;
  outline: none;
  padding: 11px 14px;
  font-size: 15px;
  background: transparent;
  color: var(--text);
}

/* ── Desktop: sidebar (right) ───────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  border-left: 1px solid var(--border);
  border-right: none;
  border-top: none;
  border-bottom: none;
  border-radius: 0;
  z-index: 25;
  overflow-y: auto;
  display: none;  /* overridden when not .hidden on desktop */
}

#sidebar:not(.hidden) { display: flex; flex-direction: column; }

#sidebar-close {
  position: sticky;
  top: 0;
  align-self: flex-end;
  margin: 12px 12px 0 0;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  z-index: 1;
}

#sidebar-content { padding: 8px 16px 24px; }

/* ── Mobile: bottom bar ─────────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-bar-h);
  background: var(--bg-ui);
  border-top: 1px solid var(--border);
  z-index: 30;
  display: flex;
  flex-direction: column;
}

#search-row {
  display: flex;
  align-items: center;
  padding: 10px 12px 6px;
  gap: 8px;
}

#search-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 15px;
  outline: none;
  background: #f7f5f3;
  color: var(--text);
}

#search-row input:focus { border-color: var(--bus); background: var(--bg-ui); }

.locate-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-ui);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color .15s, border-color .15s;
}

.locate-btn:hover { color: var(--bus); border-color: var(--bus); }
.locate-btn svg { width: 18px; height: 18px; }

/* Nav tabs */
#nav-tabs {
  display: flex;
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: .01em;
  transition: color .15s;
}

.tab.active { color: var(--bus); }

/* ── Bottom sheet (mobile / shared) ────────────────── */
#bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--bottom-bar-h);
  max-height: 70vh;
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
  z-index: 29;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .3s ease;
}

#bottom-sheet:not(.hidden) {
  display: block;
  transform: translateY(0);
}

#sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
}

#sheet-content { padding: 8px 16px 24px; }

/* ── Departure rows (used inside sheets/sidebar) ────── */
.stop-name {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 4px;
}

.stop-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.mode-chips {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.mode-chip {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
}

.mode-chip[data-mode="bus"]        { background: #e8f0f6; color: var(--bus);         border-color: var(--bus); }
.mode-chip[data-mode="rail"]       { background: #faf3e6; color: var(--rail);        border-color: var(--rail); }
.mode-chip[data-mode="ferry"]      { background: #e8f3fb; color: var(--ferry);       border-color: var(--ferry); }
.mode-chip[data-mode="underground"]{ background: #f0eaf7; color: var(--underground); border-color: var(--underground); }

.departure {
  display: grid;
  grid-template-columns: auto 1fr 32px;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.departure:last-child { border-bottom: none; }

.route-pill {
  flex-shrink: 0;
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: var(--bus);
  cursor: pointer;
  user-select: none;
}

.route-pill:hover { opacity: 0.85; }
.route-pill.rail        { background: var(--rail); }
.route-pill.ferry       { background: var(--ferry); }
.route-pill.underground { background: var(--underground); }

.dep-info { min-width: 0; }

.dep-dest {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dep-time-group { margin-top: 2px; }

.dep-countdown {
  font-size: 14px;
  font-weight: 700;
}

.dep-countdown.due   { color: var(--dep-due); }
.dep-countdown.soon  { color: var(--dep-soon); }
.dep-countdown.later { color: var(--dep-later); }
.dep-countdown.late  { color: var(--late-warn); }
.dep-countdown.early { color: var(--early); }

.dep-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

.dep-badge.late   { background: #fef0e6; color: var(--late-urgent); }
.dep-badge.early  { background: #e8f3fb; color: var(--early); }
.dep-badge.cancel { background: #f0f0f0; color: var(--cancelled); text-decoration: line-through; }
.dep-badge.on-time { background: #e6f6eb; color: var(--success); }
.dep-badge.live    { background: #e6f6eb; color: var(--success); }

.dep-locate {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-ui);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  opacity: 0.4;
  padding: 5px;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, opacity .15s;
}
.dep-locate.live         { opacity: 1; color: var(--bus); border-color: var(--bus); }
.dep-locate:hover        { opacity: 1; color: var(--bus); border-color: var(--bus); }
.dep-locate svg          { width: 100%; height: 100%; }

.dep-scheduled {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.dep-location {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.disruption-banner {
  background: #fff3cd;
  color: #7a5800;
  border-left: 3px solid #f0a800;
  font-size: 12px;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 0 4px 4px 0;
}

/* ── Desktop overrides ──────────────────────────────── */
@media (min-width: 768px) {
  #map {
    bottom: 0;   /* map fills full height on desktop */
    right: 0;
    transition: right .3s ease;
  }

  /* Shrink map when sidebar is open */
  body.sidebar-open #map { right: var(--sidebar-w); }
  body.sidebar-open .maplibregl-ctrl-bottom-right { right: calc(var(--sidebar-w) + 8px); }

  #layer-toggles { display: flex; }
  .layer-btn { display: flex; }

  #desktop-search { display: flex; }

  #sidebar { display: none; }
  #sidebar:not(.hidden) { display: flex; }

  /* Hide mobile-only controls */
  #bottom-bar    { display: none; }
  #bottom-sheet  {
    bottom: 0;
    max-height: 100vh;
    left: auto;
    right: 0;
    width: var(--sidebar-w);
    border-radius: 0;
    border-left: 1px solid var(--border);
  }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right { bottom: 8px; }
}

/* ── Journey planner button (desktop search bar) ───────────────── */
.plan-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color .15s, background .15s;
}
.plan-btn:hover, .plan-btn.active { color: var(--bus); background: #f0f6fb; }
.plan-btn svg { width: 18px; height: 18px; }

/* ── Journey planner panel ──────────────────────────────────────── */
#journey-panel {
  position: fixed;
  z-index: 28;
  background: var(--bg-ui);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-direction: column;
  /* Mobile: bottom sheet style */
  left: 0; right: 0;
  bottom: var(--bottom-bar-h);
  max-height: 80vh;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-y: auto;
}
#journey-panel:not(.hidden) { display: flex; }

#journey-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#journey-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

#journey-minimise {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 4px;
  line-height: 1;
}
#journey-minimise svg { width: 18px; height: 18px; display: block; }
#journey-panel.minimised #journey-minimise svg polyline { points: "4 7 10 13 16 7"; }

/* Mobile only: show minimise button and support collapsed state */
@media (max-width: 767px) {
  #journey-minimise { display: block; }
  #journey-panel.minimised {
    max-height: 49px;
    overflow: hidden;
  }
  #journey-panel.minimised #journey-minimise svg {
    transform: rotate(180deg);
  }
}

#journey-form {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.jp-place-row {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.jp-place-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.jp-autocomplete-wrap {
  flex: 1;
  position: relative;
}

.jp-autocomplete-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  background: #f7f5f3;
  color: var(--text);
}

.jp-autocomplete-wrap input:focus { border-color: var(--bus); background: var(--bg-ui); }

.jp-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-ui);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  list-style: none;
  z-index: 50;
  max-height: 180px;
  overflow-y: auto;
}

.jp-suggestions:empty { display: none; }

.jp-suggestions li {
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jp-suggestions li:last-child { border-bottom: none; }
.jp-suggestions li:hover, .jp-suggestions li.selected { background: #f0f6fb; color: var(--bus); }

#jp-swap {
  align-self: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 5px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 20px;
  transition: color .15s, border-color .15s;
}

#jp-swap:hover { color: var(--bus); border-color: var(--bus); }
#jp-swap svg { width: 100%; height: 100%; }

#jp-modes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.jp-mode-btn {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-ui);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}

.jp-mode-btn.active[data-mode="bus"]        { background: #e8f0f6; color: var(--bus);         border-color: var(--bus); }
.jp-mode-btn.active[data-mode="rail"]       { background: #faf3e6; color: var(--rail);        border-color: var(--rail); }
.jp-mode-btn.active[data-mode="underground"]{ background: #f0eaf7; color: var(--underground); border-color: var(--underground); }
.jp-mode-btn.active[data-mode="ferry"]      { background: #e8f3fb; color: var(--ferry);       border-color: var(--ferry); }

#jp-submit {
  padding: 11px;
  background: var(--bus);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity .15s;
}

#jp-submit:hover { opacity: 0.88; }
#jp-submit:disabled { opacity: 0.5; cursor: default; }

#jp-results { padding: 0 16px 24px; }

.jp-itinerary {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}

.jp-itinerary:hover { border-color: var(--bus); }

.jp-itin-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.jp-itin-duration { font-weight: 700; font-size: 15px; }
.jp-itin-times { color: var(--text-muted); }
.jp-itin-changes { font-size: 12px; color: var(--text-muted); }

.jp-legs {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 4px;
  flex-wrap: wrap;
}

.jp-leg-pill {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--text-muted);
}

.jp-leg-pill.BUS, .jp-leg-pill.bus { background: var(--bus); }
.jp-leg-pill.RAIL, .jp-leg-pill.LONG_DISTANCE { background: var(--rail); }
.jp-leg-pill.SUBWAY, .jp-leg-pill.TRAM { background: var(--underground); }
.jp-leg-pill.FERRY { background: var(--ferry); }
.jp-leg-pill.WALK { background: #999; font-weight: 400; }

.jp-leg-arrow { color: var(--text-muted); font-size: 11px; }

.jp-leg-detail {
  padding: 0 12px 10px;
  font-size: 13px;
  color: var(--text-muted);
  display: none;
}

.jp-itinerary.expanded .jp-leg-detail { display: block; }

.jp-step {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 6px 8px;
  align-items: start;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.jp-step:last-child { border-bottom: none; }
.jp-step-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 3px; justify-self: center; }
.jp-step-time { color: var(--text-muted); white-space: nowrap; }

/* ── Desktop overrides for journey panel ────────────────────────── */
@media (min-width: 768px) {
  #journey-panel {
    top: 0; bottom: 0;
    left: auto; right: 0;
    width: var(--sidebar-w);
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-top: none; border-bottom: none; border-right: none;
  }
}

/* ── Toast notification ─────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-ui);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 9999;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── User location dot (pink override of MapLibre default blue) ── */
.maplibregl-user-location-dot {
  background-color: #e91e63;
  box-shadow: 0 0 0 2px #fff, 0 0 4px rgba(0,0,0,.3);
}
.maplibregl-user-location-dot::before {
  background-color: rgba(233, 30, 99, 0.25);
}

/* ── Clear-route floating button ─────────────────────── */
#clear-overlay-btn {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-bar-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.96);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 200;
  white-space: nowrap;
}
#clear-overlay-btn.visible { display: block; }
@media (min-width: 640px) {
  #clear-overlay-btn { bottom: 20px; }
}

/* ── Arrivals/Departures board tabs ──────────────────── */
.board-tab {
  flex: 1;
  padding: 6px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.board-tab.active {
  background: var(--rail, #c8860a);
  color: #fff;
  border-color: var(--rail, #c8860a);
}
