:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #16a34a;
  --accent-text: #ffffff;
  --red: #dc2626;
  --yellow: #eab308;
  --green: #22c55e;
  --warn-bg: #fef9c3;
  --warn-text: #713f12;
  --error-bg: #fee2e2;
  --error-text: #7f1d1d;
  --topbar: #0f172a;
  --topbar-text: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 4px 16px rgb(15 23 42 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #111a2e; --surface-2: #17223a; --text: #e2e8f0; --muted: #94a3b8;
    --border: #233150; --warn-bg: #3a2f0b; --warn-text: #fde68a; --error-bg: #3b1212; --error-text: #fecaca;
    --topbar: #060b16; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2e; --surface-2: #17223a; --text: #e2e8f0; --muted: #94a3b8;
  --border: #233150; --warn-bg: #3a2f0b; --warn-text: #fde68a; --error-bg: #3b1212; --error-text: #fecaca;
  --topbar: #060b16; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--topbar); color: var(--topbar-text);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; white-space: nowrap; }
.data-status { font-size: 12.5px; text-align: right; color: #cbd5e1; display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: flex-end; }
.data-status b { color: #fff; font-weight: 600; }
.data-status .pill { background: #a16207; color: #fff; padding: 1px 7px; border-radius: 99px; font-weight: 600; }
.data-status .pill.bad { background: var(--red); }

.layout { flex: 1; display: grid; grid-template-columns: 390px 1fr; min-height: 0; }
.panel { overflow-y: auto; padding: 16px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.map { min-height: 300px; }

.field { display: flex; flex-direction: column; gap: 5px; border: 0; padding: 0; margin: 0; position: relative; }
.field-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0; }
input[type="text"], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; min-height: 42px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; min-width: 0; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 9px 12px; min-height: 42px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.whatsapp { background: #25d366; color: #052e16; border-color: #25d366; }
.btn.block { width: 100%; }
.plan-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 13.5px; }

.results { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); max-height: 220px; overflow-y: auto; }
.results li button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.results li button:hover, .results li button:focus { background: var(--surface-2); }
.place-title { display: block; font-weight: 600; }
.place-area { display: block; font-size: 12.5px; color: var(--muted); }
.input-row { position: relative; }
.input-row > .results { position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 1500; }
.chosen { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chosen::before { content: "✓"; color: var(--accent); font-weight: 700; }

.help { font-size: 13.5px; color: var(--muted); }
.help summary { cursor: pointer; color: var(--text); font-weight: 500; }
.help ol { padding-left: 20px; margin: 8px 0; }
.help p { margin: 6px 0 0; }
.hint { margin: -4px 0 0; font-size: 13px; color: var(--muted); }

.night-toggle { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; font-size: 14px; cursor: pointer; }
.night-toggle input { margin-top: 3px; accent-color: var(--accent); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 9px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-weight: 500; min-height: 42px; }
.segmented input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.r, .sq.r { background: #ef4444; } .dot.y, .sq.y { background: #facc15; } .sq.g { background: #4ade80; }
.sq.m { background: #a3e635; }
/* FADE's colours from app.js, one quarter per level; red deepens to the worst */
.fade-key { flex-basis: 100%; display: grid; grid-template-columns: repeat(4, 1fr); row-gap: 3px;
  font-size: 11.5px; color: var(--muted); }
.fade-bar { grid-column: 1 / -1; height: 12px; border-radius: 3px;
  background: linear-gradient(90deg, #86efac, #bef264 25%, #fde047 50%, #fb923c 75%, #ef4444 83%, #b91c1c 92%, #7f1d1d); }
.fade-key span { border-left: 1px solid var(--muted); padding-left: 3px; white-space: nowrap; }
.sq.out { background: #0f172a; opacity: 0.45; }
.stations-toggle { display: flex; align-items: center; gap: 6px; flex-basis: 100%; cursor: pointer; }
.station-dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #0f172a; background: #fff; display: inline-block; }
.coverage { flex-basis: 100%; font-size: 12.5px; }
.coverage summary { cursor: pointer; color: var(--text); }
.coverage p { margin: 6px 0 0; color: var(--muted); }
.contact { flex-basis: 100%; padding-top: 8px; border-top: 1px solid var(--border); font-size: 12.5px; }
.contact h3 { margin: 0 0 2px; font-size: 13px; }
.contact p { margin: 0 0 2px; color: var(--muted); }
.contact a { color: var(--accent); font-weight: 600; overflow-wrap: anywhere; }
.station-popup { min-width: 220px; font-size: 13px; }
.station-popup p { margin: 6px 0; }
.station-popup table { border-collapse: collapse; width: 100%; }
.station-popup td { padding: 2px 0; border-top: 1px solid #e2e8f0; }
.station-popup td:last-child { text-align: right; font-weight: 600; padding-left: 10px; }

.banner { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.error { background: var(--error-bg); color: var(--error-text); }

.result { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.result h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.result p { margin: 0; }
.warnings { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.warnings li { background: var(--warn-bg); color: var(--warn-text); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.parts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.part { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.part.unclear { border-color: var(--yellow); }
.part-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.part-num { font-weight: 700; }
.part-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.part-route { font-size: 14px; margin: 2px 0 8px; overflow-wrap: anywhere; }
.part-links { display: flex; gap: 6px; }
.part-links .btn { flex: 1; }
.stops-box h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.stops { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.stops li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.stops .num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.stops .name { flex: 1; min-width: 0; }
.btn.remove { min-height: 30px; padding: 3px 10px; font-size: 13px; color: var(--error-text); background: var(--error-bg); border-color: transparent; }
.red-passages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.red-passages button { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  padding: 6px 8px 6px 10px; border: 1px solid var(--border); border-left: 4px solid var(--red); border-radius: 8px;
  background: var(--surface); font-size: 13px; }
.red-passages button:hover { background: var(--surface-2); }
.red-passages .where { display: block; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.share { display: flex; flex-direction: column; gap: 6px; }
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.legend { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.legend p { flex-basis: 100%; margin: 0; }
.sq { width: 12px; height: 12px; display: inline-block; border-radius: 3px; margin-right: 5px; vertical-align: -1px; opacity: .8; }

.pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 35%); }
.pin span { transform: rotate(45deg); color: #fff; font: 700 12px/1 system-ui, sans-serif; }
.pin.start { background: #2563eb; } .pin.end { background: #0f172a; } .pin.stop { background: var(--accent); }
.pin.via { background: #7c3aed; }
.stops .num.via { background: #7c3aed; }
.vias { display: flex; flex-direction: column; gap: 12px; }
.vias:empty { display: none; }
.add-via { align-self: flex-start; margin-top: -4px; }
.via-field .field-label { color: #7c3aed; }
/* Zones blend into the map ("multiply") so labels stay readable, and fade in. */
.zones-heat, .zones-crisp { mix-blend-mode: multiply; transition: opacity 0.4s ease; }
.zones-heat { filter: blur(2px); }
.zones-crisp { image-rendering: auto; }
.style-toggle { display: inline-flex; margin-left: auto; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.style-toggle button { font: inherit; font-size: 12.5px; padding: 4px 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.style-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.map-popup { display: flex; flex-direction: column; gap: 6px; }
.route-popup { gap: 3px; font-size: 13px; }
.route-popup .where { font-weight: 700; font-size: 14px; }
.route-popup .zone { display: flex; align-items: center; gap: 6px; }
.route-popup .zone i { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgb(0 0 0 / 15%); }
.route-popup .why { margin-top: 4px; padding: 4px 0 4px 8px; border-left: 4px solid #dc2626; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 2000; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

.sheet-handle { display: none; }
.place-note { display: block; font-size: 12px; color: var(--warn-text); margin-top: 2px; }
.results .searching { padding: 8px; font-size: 13px; color: var(--muted); }
.chosen { flex-wrap: wrap; }
.chosen .chosen-note { flex-basis: 100%; color: var(--warn-text); font-size: 12px; }
.locate-control a { font-size: 17px; line-height: 30px; text-align: center; text-decoration: none; }
.locate-control a.busy { opacity: .5; }
.leaflet-marker-draggable .pin { cursor: grab; }

/* Phones: the map fills the screen and the planner is a sheet over it,
   dragged up and down by its handle (peek, half, full). */
@media (max-width: 820px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  .topbar { padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); gap: 8px; }
  .brand { font-size: 15px; }
  .brand img { width: 22px; height: 22px; }
  .data-status { font-size: 11px; gap: 0 8px; }
  .data-status .st-next { display: none; }
  .layout { display: block; position: relative; }
  .map { position: absolute; inset: 0; z-index: 0; min-height: 0; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; height: 50%; max-height: 100%;
    border-right: 0; border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgb(15 23 42 / 22%);
    padding: 0 16px calc(16px + env(safe-area-inset-bottom)); overscroll-behavior: contain;
    transition: height .25s ease;
  }
  .panel.dragging { transition: none; }
  .panel[data-sheet="peek"] { overflow: hidden; }
  .sheet-handle {
    display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none;
    position: sticky; top: 0; z-index: 5; margin: 0 -16px; padding: 8px 16px 10px;
    background: var(--surface); border-radius: 16px 16px 0 0; cursor: grab; touch-action: none; user-select: none;
  }
  .sheet-handle i { width: 40px; height: 5px; border-radius: 3px; background: var(--border); }
  .sheet-handle span { font-weight: 600; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .panel[data-sheet="full"] .sheet-handle { border-bottom: 1px solid var(--border); }
  /* 16px stops iOS zooming in on the box you tap */
  input[type="text"], select, .areas-list input, .via-name { font-size: 16px; }
  .field, .result, .banner { scroll-margin-top: 64px; }
  .results { max-height: 40vh; }
  .results li button { padding: 10px 8px; }
  /* Plan stays in reach at the bottom of the sheet */
  .plan-row { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); z-index: 4; background: var(--surface);
    margin: 0 -16px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
  .panel[data-sheet="peek"] .plan-row, .panel.has-trip .plan-row { position: static; margin: 0; padding: 0; border: 0; }
  .toast { bottom: calc(var(--sheet-h, 0px) + 12px); }
  .leaflet-touch .leaflet-bar a { width: 36px; height: 36px; line-height: 36px; }
  .leaflet-popup-content { margin: 12px 14px; }
  /* a popup is nearly as wide as the screen: the map buttons step aside */
  .map.popup-open .leaflet-top.leaflet-left { opacity: 0; pointer-events: none; transition: opacity .2s; }
}

/* areas to avoid (drawn on the map) */
.areas-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.areas-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.areas-list li { display: flex; align-items: center; gap: 6px; }
.areas-list input { flex: 1; min-width: 0; padding: 6px 8px; font-size: 14px; }
.area-swatch { width: 14px; height: 14px; flex: none; border: 2px dashed #7c3aed; background: rgb(124 58 237 / 0.15); border-radius: 3px; }
.areas-status { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.areas-status.error { color: #f87171; }
.map.drawing, .map.drawing .leaflet-interactive { cursor: crosshair !important; touch-action: none !important; }
.draw-control a { font-size: 16px; line-height: 30px; text-align: center; text-decoration: none; }
.draw-control a.active { background: #ede9fe; }
.draw-banner { display: flex; align-items: center; gap: 8px; background: #fff; color: #0f172a; padding: 6px 8px 6px 12px;
  border-radius: 8px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.25); font-size: 13px; font-weight: 600; }
.via-name { width: 100%; margin-top: 6px; padding: 6px 8px; font-size: 14px; }
.btn.rename { padding: 4px 8px; }
.stops-box h3 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* How people find an area, in the map and station popups */
.area-box { margin-top: 8px; padding-top: 8px; border-top: 1px solid #e2e8f0; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.area-box p { margin: 0; }
.area-box .btn { align-self: flex-start; }
.area-head { font-size: 13px; }
.area-police { margin-top: 4px !important; }
.area-error { color: #b91c1c; }
.rate-form { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
.rate-feelings { display: flex; gap: 4px; flex-wrap: wrap; }
.rate-feelings .btn[aria-pressed="true"] { color: #fff; }
.rate-feelings .feeling-fine[aria-pressed="true"] { background: #16a34a; border-color: #16a34a; }
.rate-feelings .feeling-uneasy[aria-pressed="true"] { background: #ca8a04; border-color: #ca8a04; }
.rate-feelings .feeling-avoid[aria-pressed="true"] { background: #dc2626; border-color: #dc2626; }
.rate-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.rate-tags .tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 1px solid #e2e8f0; border-radius: 999px; font-size: 12px; cursor: pointer; }
.rate-tags .tag:has(input:checked) { background: #dcfce7; border-color: #16a34a; }
.rate-tags input { margin: 0; accent-color: #16a34a; }
.rate-tags .tag:has(input:disabled) { opacity: .45; cursor: default; }
