/* Dark, high-contrast, big touch targets — this gets used on a phone mount
   in daylight, at speed, with one hand. */

:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1f2732;
  --line: #2b3542;
  --text: #e8edf4;
  --muted: #93a1b3;
  --accent: #4ea1ff;
  --ok: #35c47a;
  --warn: #ffb020;
  --danger: #ff5c5c;
  /* Map palette: zones green, sticker outlets violet, section tolls amber.
     Kept distinct from the blue "you are here" dot. */
  --zone: #35c47a;
  --poi: #b57cff;
  --toll: #ffb020;
  --route: #4ea1ff;
  --acc: #ff8fd0;
  --border-c: #ffd24a;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only a UA-stylesheet `display: none`, so any author
   rule that sets `display` beats it. Several components below set display for
   layout, so hiding must be made to win explicitly. */
[hidden] { display: none !important; }


html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { display: flex; flex-direction: column; }

/* ── Status bar ────────────────────────────────────────────────────────── */
#statusbar {
  flex: none; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
}
.status-row { display: flex; gap: 8px; align-items: center; }

.gps-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; white-space: nowrap;
}
.gps-btn.on { border-color: var(--ok); color: var(--ok); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.gps-btn.on .dot { background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.chip {
  flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip-muted { color: var(--muted); font-weight: 500; }
.chip-ok { background: rgba(53,196,122,.15); color: var(--ok); }
.chip-warn { background: rgba(255,176,32,.15); color: var(--warn); }
.chip-danger { background: rgba(255,92,92,.15); color: var(--danger); }
.chip { border: 0; font-family: inherit; text-align: left; }
button.chip { cursor: pointer; }
.chip-next {
  flex: 0 1 auto; background: var(--surface-2); color: var(--text);
  display: flex; align-items: baseline; gap: 7px; white-space: nowrap;
}
.chip-next b { font-size: 15px; color: var(--accent); }
.chip-next span { font-size: 12px; color: var(--muted); }

/* Alerts sit over the map, top right, so they never push the map around or
   swallow the full width. Older ones scroll rather than vanishing. */
.alert-dock {
  position: absolute; top: 10px; right: 10px; z-index: 800;
  width: min(310px, calc(100% - 84px));
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.alert-dock > * { pointer-events: auto; }
.alert-strip { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.alert-more {
  align-self: flex-end; background: rgba(22,27,35,.92); border: 1px solid var(--line);
  color: var(--muted); border-radius: 8px; padding: 5px 9px; font-size: 11.5px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.alert {
  padding: 9px 30px 9px 11px; border-radius: 10px; font-size: 13px; font-weight: 600;
  border-left: 4px solid; line-height: 1.35; position: relative;
  background: rgba(22,27,35,.95); box-shadow: 0 2px 10px rgba(0,0,0,.45);
}
.alert-x {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px;
  background: none; border: 0; color: inherit; opacity: .65;
  font-size: 15px; line-height: 1; cursor: pointer;
}
.alert-x:active { opacity: 1; }
.alert-clear {
  align-self: flex-end; background: none; border: 0; color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; padding: 2px 4px;
  text-decoration: underline;
}
.alert-danger { background: rgba(255,92,92,.14); border-color: var(--danger); color: #ffc9c9; }
.alert-warn { background: rgba(255,176,32,.14); border-color: var(--warn); color: #ffe3b0; }
.alert-info { background: rgba(78,161,255,.14); border-color: var(--accent); color: #cfe4ff; }
.alert small { display: block; font-weight: 400; opacity: .85; margin-top: 2px; }

/* ── Views ─────────────────────────────────────────────────────────────── */
main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }
#view-map.active { display: block; overflow: hidden; }
#map { position: absolute; inset: 0; background: #202b36; }
.pad { padding: 14px 14px calc(24px + var(--safe-b)); }

/* ── Map overlays ──────────────────────────────────────────────────────── */
.map-controls { position: absolute; right: 12px; bottom: 74px; z-index: 500; display: flex; flex-direction: column; gap: 10px; }
.fab {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(22,27,35,.94); color: var(--text); font-size: 20px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.fab:active { background: var(--surface-2); }
/* The legend doubles as the layer switcher — one control instead of two. */
.legend {
  position: absolute; left: 12px; bottom: 12px; right: 74px; z-index: 500;
  background: rgba(22,27,35,.92); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; font-size: 12px; color: var(--muted);
  display: flex; gap: 4px; flex-wrap: wrap;
}
.legend button {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 7px;
  color: var(--muted); font-size: 11.5px; font-weight: 600;
  padding: 5px 8px; min-height: 32px; font-family: inherit;
}
.legend button.on { color: var(--text); border-color: var(--line); background: var(--surface-2); }
.legend button.off { opacity: .4; }
.legend button .mode { font-size: 9.5px; opacity: .8; text-transform: uppercase; letter-spacing: .04em; }

/* ── Collapsible stop strip ────────────────────────────────────────────── */
/* The simulation bar owns the top of the map, so the strip drops below it. */
body.simulating .trip-strip { top: 104px; }

.trip-strip {
  position: absolute; left: 12px; top: 12px; z-index: 550;
  transition: top .2s;
  max-width: min(300px, calc(100% - 24px));
  background: rgba(22,27,35,.95); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.5); overflow: hidden;
}
.trip-strip > summary {
  list-style: none; cursor: pointer; padding: 9px 12px;
  font-size: 12.5px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 8px; min-height: 38px;
}
.trip-strip > summary::-webkit-details-marker { display: none; }
.trip-strip > summary::after { content: '▾'; margin-left: auto; color: var(--muted); }
.trip-strip[open] > summary::after { content: '▴'; }
.strip-list { max-height: 46vh; overflow-y: auto; border-top: 1px solid var(--line); }
.strip-row {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 12px; background: none; border: 0; border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 13px; text-align: left; cursor: pointer; font-family: inherit;
}
.strip-row:last-child { border-bottom: 0; }
.strip-row:active { background: var(--surface-2); }
.strip-row.next { background: rgba(78,161,255,.14); }
.strip-row.done .strip-name { color: var(--muted); text-decoration: line-through; }
.strip-row.done .strip-n { background: var(--ok); }
.strip-empty { padding: 12px; color: var(--muted); font-size: 12.5px; }

/* Same vertical connector in the compact map strip: the arrow sits under the
   stop number, so the column of stops reads as one continuous thread. */
.strip-leg {
  display: grid; grid-template-columns: 21px 1fr auto; align-items: center;
  gap: 9px; padding: 2px 12px; font-size: 11px; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.strip-leg .leg-arrow { width: 21px; height: 24px; position: relative; }
.strip-leg .leg-arrow::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 6px;
  width: 2px; margin-left: -1px; background: var(--line);
}
.strip-leg .leg-arrow::after {
  content: ''; position: absolute; left: 50%; bottom: 0; margin-left: -4px;
  border-top: 7px solid var(--line);
  border-left: 4px solid transparent; border-right: 4px solid transparent;
}
.strip-leg .leg-t { color: var(--accent); font-weight: 700; }
.strip-leg .leg-d { font-weight: 600; }
.strip-leg.est { font-style: italic; opacity: .75; }
.strip-n {
  flex: none; width: 21px; height: 21px; border-radius: 50%;
  background: var(--route); color: #06121f; font-size: 11px; font-weight: 800;
  line-height: 21px; text-align: center;
}
.strip-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip-d { color: var(--muted); font-size: 11.5px; flex: none; }
.strip-go {
  flex: none; padding: 4px 8px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--accent); font-size: 11px; font-weight: 700;
  text-decoration: none;
}

/* ── Drive mode ────────────────────────────────────────────────────────── */
.drive-panel {
  position: absolute; left: 0; right: 0; top: 0; z-index: 700;
  background: linear-gradient(180deg, rgba(14,17,22,.97) 72%, rgba(14,17,22,0));
  padding: 12px 14px 26px; pointer-events: none;
}
.drive-next { display: flex; align-items: center; gap: 14px; }
.drive-meta { flex: 1; min-width: 0; }
.drive-dist { font-size: 40px; font-weight: 800; color: var(--accent); line-height: 1; }
.drive-to { font-size: 19px; font-weight: 700; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The arrival time is the second thing you look for, so it gets real size. */
.drive-eta { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.1; }
.drive-eta small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.drive-facts { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.drive-fact {
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); color: var(--text); border-left: 3px solid var(--muted);
}
.drive-fact.ok { border-color: var(--ok); color: #bff0d5; background: rgba(53,196,122,.12); }
.drive-fact.warn { border-color: var(--warn); color: #ffe3b0; background: rgba(255,176,32,.12); }
.drive-fact.danger { border-color: var(--danger); color: #ffc9c9; background: rgba(255,92,92,.14); }
.drive-fact small { display: block; font-weight: 500; opacity: .8; font-size: 11px; }

body.driving #statusbar,
body.driving #tabs,
body.driving .legend,
body.driving .trip-strip { display: none; }

/* The whole map is oversized and rotated so the direction of travel points up;
   the surplus keeps the corners covered as it turns. */
body.driving #map {
  inset: -50%; width: 200%; height: 200%;
  transform: rotate(var(--map-rot, 0deg));
  transition: transform .45s ease-out;
}
/* Pins would tilt with the map, so they are turned back the other way. */
body.driving .pin,
body.driving .me-dot { transform: rotate(calc(-1 * var(--map-rot, 0deg))); }
body.driving .map-controls { bottom: 22px; }
.me-dot.heading {
  border-radius: 50% 50% 50% 0; transform-origin: center;
}

/* ── Simulation bar ────────────────────────────────────────────────────── */
.sim-bar {
  position: absolute; left: 12px; top: 12px; z-index: 600;
  max-width: min(420px, calc(100% - 24px));
  background: rgba(22,27,35,.95); border: 1px solid var(--poi); border-radius: 10px;
  padding: 9px 11px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.sim-bar b { color: var(--poi); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.sim-bar .sim-hint { color: var(--muted); font-size: 11.5px; flex: 1 1 100%; }
.sim-bar button {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 11px; font-size: 13px; font-weight: 600; cursor: pointer;
  min-height: 36px;
}
.sim-bar button.on { border-color: var(--poi); color: var(--poi); }
.sim-bar select {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 13px; min-height: 36px;
}
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-zone { background: rgba(53,196,122,.45); border: 1px solid var(--zone); }
.sw-poi { background: var(--poi); border-radius: 50%; }
.sw-toll { background: var(--toll); border-radius: 50%; }
.sw-route { background: var(--route); border-radius: 2px; height: 4px; }
.sw-border { background: var(--border-c); border-radius: 50%; }
.sw-acc { background: var(--acc); border-radius: 50%; }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
/* Auto-columns rather than a fixed count — adding a tab must never wrap the bar
   onto a second row, which is what a hardcoded repeat(4) did when Trip arrived. */
#tabs {
  flex: none; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  height: var(--tab-h); font-size: 10.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 0 2px; min-width: 0; overflow: hidden; white-space: nowrap;
}
.tab span { font-size: 18px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ── Lists & cards ─────────────────────────────────────────────────────── */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.section-head:first-child { margin-top: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }

.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 13px;
}
.card.clickable { cursor: pointer; }
.card.clickable:active { background: var(--surface-2); }
.card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-body { margin-top: 9px; font-size: 14px; }
.card.accent-ok { border-left: 4px solid var(--ok); }
.card.accent-warn { border-left: 4px solid var(--warn); }
.card.accent-danger { border-left: 4px solid var(--danger); }
.card.accent-info { border-left: 4px solid var(--accent); }

.badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.badge-ok { background: rgba(53,196,122,.18); color: var(--ok); }
.badge-warn { background: rgba(255,176,32,.18); color: var(--warn); }
.badge-danger { background: rgba(255,92,92,.18); color: var(--danger); }

/* The hop between two stops, drawn as a vertical arrow running down from the
   previous stop to the next, with the time and distance either side of it. */
.leg-card {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; padding: 4px 14px; font-size: 12.5px; color: var(--muted);
}
.leg-card .leg-t { text-align: right; color: var(--accent); font-weight: 700; }
.leg-card .leg-d { text-align: left; font-weight: 600; }
.leg-card .leg-arrow {
  width: 12px; height: 34px; position: relative; justify-self: center;
}
.leg-card .leg-arrow::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 7px;
  width: 2px; margin-left: -1px; background: var(--line);
}
.leg-card .leg-arrow::after {
  content: ''; position: absolute; left: 50%; bottom: 0; margin-left: -5px;
  border-top: 8px solid var(--line);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
}
.leg-card.est { font-style: italic; opacity: .75; }

/* One selectable route option inside a variant group. */
.variant-row {
  display: flex; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; border-top: 1px solid var(--line);
  padding: 11px 2px; color: var(--text); font-family: inherit; font-size: 14px;
}
.variant-row:first-of-type { border-top: 0; }
.variant-row:active { background: var(--surface-2); }
.variant-radio { flex: none; color: var(--muted); font-size: 15px; line-height: 1.4; }
.variant-row.on .variant-radio { color: var(--accent); }
.variant-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.variant-label { font-weight: 700; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.variant-stats { color: var(--muted); font-size: 12.5px; }
.variant-note { color: var(--muted); font-size: 12.5px; }

.tick {
  flex: none; width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  font-size: 12px; font-weight: 800; line-height: 1; font-family: inherit;
}
.tick.on { background: var(--ok); border-color: var(--ok); color: #06121f; }

.progress { height: 5px; border-radius: 3px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); transition: width .3s; }

ul.bullets { margin: 8px 0 0; padding-left: 18px; }
ul.bullets li { margin-bottom: 5px; font-size: 13.5px; color: #c9d4e2; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 600; color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.prose { font-size: 14px; color: #c9d4e2; }
.prose p { margin: 0 0 10px; }
.prose strong { color: var(--text); }

/* ── Buttons & fields ──────────────────────────────────────────────────── */
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 15px; font-size: 14px; font-weight: 600;
  cursor: pointer; min-height: 44px; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; text-decoration: none;
}
.btn:active { filter: brightness(1.25); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06121f; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 36px; padding: 7px 11px; font-size: 13px; }
.row-buttons { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 12px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 6px 10px; }

.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input[type=text], .field input[type=date], .field select, .field textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 16px; font-family: inherit; min-height: 46px;
}
.field textarea { min-height: 60px; resize: vertical; }
.field.checkbox { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.field.checkbox input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.field.checkbox span { margin: 0; font-size: 14px; color: var(--text); font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Sheet ─────────────────────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.sheet-panel {
  width: 100%; max-height: 92vh; overflow-y: auto; background: var(--surface);
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 3000;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 17px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 18px rgba(0,0,0,.5); max-width: 90vw; text-align: center;
}

/* Leaflet popups follow the app's palette rather than the default white. */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; min-width: 210px; }
.leaflet-popup-content b { font-size: 15px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-control-attribution { background: rgba(14,17,22,.8) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--line) !important; }

/* Numbered trip pins, and the ⚑ / 🛏 markers that share their shape. */
.pin {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--pin, #4ea1ff); color: #06121f;
  border: 2px solid #0e1116; box-shadow: 0 1px 6px rgba(0,0,0,.6);
  font-size: 12px; font-weight: 800; line-height: 22px; text-align: center;
}

.me-dot {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(78,161,255,.5), 0 0 14px rgba(78,161,255,.8);
}

@media (min-width: 760px) {
  .pad { max-width: 720px; margin: 0 auto; }
}
