/* Layout: full-screen map, top bar, bottom sheet with tabs; log sheet covers the screen. */
:root {
  --bg: #f3f6f5;
  --panel: #ffffff;
  --ink: #10221f;
  --muted: #5b6e6a;
  --line: #d6e0dd;
  --accent: #14627a;
  --accent-ink: #ffffff;
  --sig-green: #1c9a4a;
  --sig-flash: #6fcf5a;
  --sig-yellow: #e9b10b;
  --sig-red: #d23b2f;
  --ok: #1c9a4a;
  --tight: #e08a00;
  --bad: #d23b2f;
  --noscooter: #6e1a45;
  --track: #7b3fe4;
  --track-old: #7b3fe4;
  --todo: #6a7d8a;
  --plain: #b9c4c9;
  --shadow: 0 -6px 24px rgba(16, 34, 31, .14);
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1615; --panel: #13201f; --ink: #e6efec; --muted: #93a7a2; --line: #26403c;
    --accent: #4cb3cf; --accent-ink: #062027; --todo: #8fa3b0; --plain: #4b5a5f; --noscooter: #e0559d; --track: #b48cff; --track-old: #9a7ad8;
    --shadow: 0 -6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.4 var(--f-body);
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.brand {
  pointer-events: auto; background: var(--panel); border-radius: 12px; padding: 6px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); display: flex; flex-direction: column; line-height: 1.2;
}
.brand strong { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.iconbtn {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.15); font-size: 22px; line-height: 1;
}

.topbtns { display: flex; gap: 8px; }
.iconbtn.on { background: var(--accent); color: var(--accent-ink); }
.editbanner {
  position: fixed; z-index: 600; left: max(10px, env(safe-area-inset-left, 0px)); right: max(10px, env(safe-area-inset-right, 0px));
  top: calc(64px + env(safe-area-inset-top, 0px)); background: var(--ink); color: var(--panel); border-radius: 14px; padding: 10px 12px;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 14px;
}
.editbanner > div { display: grid; gap: 2px; min-width: 0; }
.editbanner .btn { flex: none; }
@media (min-width: 760px) { .editbanner { right: auto; width: 440px; } }
.edit-handle { width: 26px; height: 26px; border-radius: 50%; border: 2px dashed var(--ink); background: rgba(255,255,255,.15); cursor: grab; }
.edit-handle.gone { border-color: var(--bad); }
.toast { display: flex; align-items: center; gap: 10px; }
.toast-undo { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 8px; padding: 8px 14px; min-height: 40px; flex: none; }
.nolights { margin-top: 12px; display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.nolights .btn { flex: 1; font-size: 14px; }
.addsheet {
  position: fixed; z-index: 880; left: max(10px, env(safe-area-inset-left, 0px)); right: max(10px, env(safe-area-inset-right, 0px));
  top: calc(64px + env(safe-area-inset-top, 0px)); background: var(--panel); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0,0,0,.3); display: grid; gap: 10px;
}
.addsheet h2 { margin: 0; }
.editsheet { z-index: 950; max-height: calc(100vh - 80px); overflow-y: auto; }
@media (min-width: 760px) { .addsheet { right: auto; width: 420px; } }
.custom-pin { width: 18px; height: 18px; border-radius: 4px; transform: rotate(45deg); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }

/* ride banner */
.ride {
  position: fixed; z-index: 600; left: max(10px, env(safe-area-inset-left, 0px)); right: max(10px, env(safe-area-inset-right, 0px));
  top: calc(64px + env(safe-area-inset-top, 0px));
  background: var(--accent); color: var(--accent-ink); border-radius: 16px; padding: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); display: grid; gap: 10px;
}
.ride-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ride-arrow { font-size: 38px; width: 48px; text-align: center; transition: transform .3s; flex: none; }
.ride-text { min-width: 0; }
.ride-label { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ride-sub { font-family: var(--f-mono); font-size: 14px; opacity: .9; }
.ride-turn { margin-top: 4px; font-weight: 700; font-size: 16px; background: rgba(0,0,0,.18); border-radius: 8px; padding: 3px 8px; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ride-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ride .btn { background: rgba(255,255,255,.18); color: inherit; border-color: transparent; }
.ride .btn.primary { background: var(--accent-ink); color: var(--accent); }

/* tabs + sheet */
.tabs {
  position: fixed; z-index: 700; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 0 max(0px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(0px, env(safe-area-inset-left, 0px));
}
.tab { flex: 1; border: 0; background: none; padding: 12px 4px; font-weight: 700; color: var(--muted); border-top: 3px solid transparent; }
.tab.active { color: var(--accent); border-top-color: var(--accent); }

.sheet {
  position: fixed; z-index: 650; left: 0; right: 0;
  bottom: calc(50px + env(safe-area-inset-bottom, 0px));
  max-height: 46vh; overflow-y: auto; background: var(--panel); box-shadow: var(--shadow);
  border-radius: 18px 18px 0 0; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px));
  transition: max-height .25s ease;
}
.sheet.tall { max-height: 78vh; }
.sheet.mini { max-height: 44px; overflow: hidden; }
.sheet-grip { position: sticky; top: 0; display: block; width: 100%; border: 0; background: var(--panel); padding: 12px 0 12px; z-index: 1; touch-action: none; cursor: grab; }
.sheet.mini { max-height: 40px; }
.sheet-grip span { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
h2 { font-size: 20px; margin: 4px 0 10px; text-wrap: balance; }
h3 { font-size: 16px; margin: 18px 0 8px; }
.pane { display: grid; gap: 10px; }
.pane > h2 { margin-bottom: 0; }

.btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 14px;
  font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.callout.danger .btn.danger { background: var(--bad); color: #fff; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .btn { flex: 1; }

.callout { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.callout.danger { border-color: var(--bad); display: grid; gap: 8px; }
.callout b { font-variant-numeric: tabular-nums; }

.field { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.field input, .field select, .field textarea {
  font-weight: 400; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); width: 100%; min-width: 0;
}
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.check input { width: 22px; height: 22px; flex: none; margin: 0; accent-color: var(--accent); }

.seg { border: 0; padding: 0; margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.seg legend { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.seg label { flex: 1; min-width: 96px; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line); font-weight: 700; font-size: 14px; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.pt { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.pt span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.pin.a { background: var(--accent); } .pin.b { background: var(--ink); color: var(--panel); }

/* loop list */
.loops { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.loop {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.loop .name { font-weight: 700; }
.loop .facts { grid-column: 1; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.loop .go { grid-row: 1 / span 2; grid-column: 2; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--tight) 20%, transparent); color: var(--tight); }
.badge.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.badge.done { background: var(--bg); color: var(--muted); }

/* results */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.dot.noscooter { background: var(--noscooter); }
.chips.pick.unsuit button[data-v="trailer"].on { background: var(--bad); border-color: var(--bad); color: #fff; }
.chips.pick.unsuit button[data-v="scooter"].on { background: var(--noscooter); border-color: var(--noscooter); color: #fff; }
.dot.ok { background: var(--ok); } .dot.tight { background: var(--tight); } .dot.bad { background: var(--bad); }
.dot.todo { background: var(--todo); } .dot.plain { background: var(--plain); width: 8px; height: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.stat b { display: block; font-size: 22px; font-family: var(--f-mono); }
.stat span { font-size: 12px; color: var(--muted); }
.loglist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.loglist li { border-bottom: 1px solid var(--line); padding: 6px 0; display: flex; gap: 10px; align-items: center; }
.loglist li button { border: 0; background: none; text-align: left; padding: 0; flex: 1; min-width: 0; }
.loglist .t { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loglist .d { font-size: 13px; color: var(--muted); }

/* log sheet */
.logsheet {
  position: fixed; inset: 0; z-index: 900; background: var(--panel); display: grid; grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.log-head { display: flex; gap: 10px; align-items: flex-start; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); }
.log-head .iconbtn { box-shadow: none; background: var(--bg); flex: none; }
.log-head h2 { margin: 2px 0 6px; font-size: 18px; }
.log-body { overflow-y: auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px)); }
.log-foot { display: flex; gap: 8px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); }
.log-foot .btn { flex: 1; }
.block { display: grid; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.chip.warn { border-color: var(--tight); color: var(--tight); }
.chips.pick button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: 14px; min-height: 40px;
}
.chips.pick button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.phase-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.phase { border: 0; border-radius: 14px; min-height: 64px; font-weight: 700; font-size: 18px; color: #fff; }
.phase:active { transform: scale(.97); }
.phase.green { background: var(--sig-green); }
.phase.flash { background: repeating-linear-gradient(135deg, var(--sig-green) 0 14px, var(--sig-flash) 14px 28px); }
.phase.yellow { background: var(--sig-yellow); color: #241a00; }
.phase.red { background: var(--sig-red); }
.phase.press { background: var(--ink); color: var(--panel); grid-column: 1 / -1; min-height: 52px; font-size: 16px; }
.both-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.both-col { display: grid; gap: 8px; }
.both-col b { text-align: center; font-size: 14px; }
.both-grid .phase { min-height: 56px; font-size: 16px; }
.both-grid .phase.press { grid-column: 1 / -1; }
.overlap { border-radius: 10px; padding: 8px 10px; font-weight: 700; font-size: 15px; background: var(--bg); }
.overlap.yes { color: var(--ok); } .overlap.some { color: var(--tight); } .overlap.no { color: var(--bad); }
.clock { font-family: var(--f-mono); font-size: 34px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.evlist { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-family: var(--f-mono); font-size: 14px; }
.evlist li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border-radius: 8px; background: var(--bg); }
.evlist li i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.summary div { background: var(--bg); border-radius: 10px; padding: 6px 8px; font-size: 12px; color: var(--muted); }
.summary b { display: block; color: var(--ink); font-family: var(--f-mono); font-size: 18px; }
.saved { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 14px; }
.saved li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.saved li span { min-width: 0; }
.saved button { border: 0; background: none; color: var(--bad); font-weight: 700; }
.fit { font-weight: 700; font-size: 15px; min-height: 1.4em; }
.fit.ok { color: var(--ok); } .fit.tight { color: var(--tight); } .fit.bad { color: var(--bad); }

.toast {
  position: fixed; z-index: 1000; left: 50%; transform: translateX(-50%);
  bottom: calc(70px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--panel);
  padding: 10px 16px; border-radius: 12px; font-weight: 700; max-width: calc(100% - 32px);
}

/* map markers */
.leaflet-container { font: 14px/1.3 var(--f-body); }
.stopnum {
  background: var(--accent); color: var(--accent-ink); border-radius: 12px; font: 700 12px/22px var(--f-mono);
  min-width: 22px; height: 22px; text-align: center; padding: 0 5px; box-shadow: 0 0 0 2px #fff;
}
.stopnum.next { background: var(--sig-yellow); color: #241a00; transform: scale(1.25); }
.stopnum.done { background: var(--ok); }
.stopnum.skipped { background: var(--todo); }
.me { width: 18px; height: 18px; border-radius: 50%; background: #2a7cf7; box-shadow: 0 0 0 3px #fff, 0 0 0 8px rgba(42,124,247,.25); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 760px) {
  .sheet { left: auto; right: 12px; width: 420px; bottom: 62px; border-radius: 18px; max-height: 70vh; }
  .sheet.tall { max-height: 85vh; }
  .tabs { left: auto; right: 12px; width: 420px; bottom: 8px; border-radius: 14px; border: 1px solid var(--line); }
  .ride { right: auto; width: 420px; }
}
