:root {
  --ink: #202124;
  --muted: #5f6368;
  --line: #e4e7ec;
  --field: #f1f3f4;
  --accent: #137a4f;
  --accent-dark: #0e6342;
  --ok: #1aa251;
  --bad: #e5484d;
  --shadow: 0 2px 8px rgba(0,0,0,.14), 0 8px 28px rgba(0,0,0,.12);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

#map { position: absolute; inset: 0; z-index: 0; background: #e9eef2; }
.leaflet-control-attribution { font-size: 9px; }
.leaflet-control-zoom { display: none; }

.hidden { display: none !important; }

/* ---------- Search card ---------- */
.search-card {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 10px; right: 10px;
  max-width: 480px; margin: 0 auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  z-index: 900;
}
.brand-row { font-size: 12.5px; color: var(--muted); margin: 0 2px 8px; display: flex; align-items: center; gap: 6px; }
.brand-row b { color: var(--ink); }
.brand-row .logo { flex: none; }
.warn-badge {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; color: var(--bad); font-weight: 800; font-size: 14px;
  display: grid; place-items: center;
}
.nav-icon svg { display: block; }
.icon-btn.round { display: grid; place-items: center; }
.fab svg, .swap svg { display: block; margin: 0 auto; }
.fields { position: relative; display: flex; flex-direction: column; gap: 7px; padding-right: 38px; }
.field {
  display: flex; align-items: center; gap: 9px;
  background: var(--field);
  border: 1.5px solid transparent;
  border-radius: 11px;
  padding: 0 10px;
  transition: border-color .12s, box-shadow .12s;
}
.field.target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(19,122,79,.13); }
.field input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 15px; padding: 12px 0; color: var(--ink); min-width: 0;
}
.pin { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.pin-a { background: #1a73e8; box-shadow: 0 0 0 3px rgba(26,115,232,.18); }
.pin-b { background: var(--bad); box-shadow: 0 0 0 3px rgba(229,72,77,.18); }
.field-clear { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 6px; }
.swap {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: 32px; height: 56px;
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  font-size: 15px; color: var(--muted);
}
.click-hint { margin: 8px 2px 0; font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.click-hint::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex: none;
}

/* Autocomplete */
.ac { margin-top: 8px; border-top: 1px solid var(--line); max-height: 38vh; overflow-y: auto; }
.ac .opt { padding: 11px 6px; display: flex; gap: 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ac .opt:last-child { border-bottom: 0; }
.ac .opt:active { background: var(--field); }
.ac .o-pin { font-size: 14px; margin-top: 1px; }
.ac .o-name { font-size: 14.5px; font-weight: 500; }
.ac .o-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.ac .opt.mutedopt { color: var(--muted); justify-content: center; cursor: default; }

/* ---------- FABs ---------- */
.fab {
  position: absolute; right: 12px; z-index: 800;
  width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: #fff; box-shadow: var(--shadow);
  font-size: 20px; display: grid; place-items: center;
}
.fab:active { transform: scale(.94); }
.fab-locate { bottom: calc(var(--safe-bot) + 24px); }
.fab-recenter { bottom: calc(var(--safe-bot) + 140px); }

/* ---------- Legend ---------- */
.legend {
  position: absolute; left: 12px; bottom: calc(var(--safe-bot) + 24px); z-index: 700;
  background: rgba(255,255,255,.94); border-radius: 10px; box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 11.5px; color: var(--muted);
  display: flex; gap: 10px; align-items: center;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 13px; height: 4px; border-radius: 2px; display: inline-block; }
.sw-ok { background: var(--ok); }
.sw-bad { background: var(--bad); }

/* ---------- Bottom sheet ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 950;
  max-width: 560px; margin: 0 auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,.18);
  padding: 6px 16px calc(var(--safe-bot) + 14px);
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; }
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.icon-btn { border: 0; background: transparent; font-size: 16px; color: var(--muted); padding: 6px; }
.icon-btn.round { background: var(--field); border-radius: 50%; width: 42px; height: 42px; font-size: 17px; }

.route-cards { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; max-height: 34vh; overflow-y: auto; }
.route-card {
  display: flex; align-items: center; gap: 11px;
  border: 1.5px solid var(--line); border-radius: 13px;
  padding: 11px 13px; background: #fff;
}
.route-card.active { border-color: var(--accent); background: #eef7f1; }
.rc-badge { font-size: 10px; font-weight: 700; letter-spacing: .05em; color: var(--muted); background: var(--field); border-radius: 999px; padding: 4px 8px; }
.route-card.active .rc-badge { background: var(--accent); color: #fff; }
.rc-main { flex: 1; }
.rc-time { font-size: 17px; font-weight: 700; }
.rc-dist { font-size: 12.5px; color: var(--muted); }
.rc-flag { font-size: 12px; font-weight: 600; text-align: right; }
.rc-flag.good { color: var(--ok); }
.rc-flag.warn { color: var(--bad); }

.big-btn {
  width: 100%; border: 0; border-radius: 13px;
  background: var(--accent); color: #fff;
  font-size: 16.5px; font-weight: 700; padding: 15px;
}
.big-btn:active { background: var(--accent-dark); }

/* ---------- Navigation ---------- */
.nav-banner {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 10px; right: 10px;
  max-width: 480px; margin: 0 auto;
  z-index: 960;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.nav-icon { font-size: 34px; line-height: 1; min-width: 40px; text-align: center; }
.nav-dist { font-size: 23px; font-weight: 800; }
.nav-street { font-size: 14px; opacity: .95; margin-top: 1px; }

.nav-warn {
  position: absolute;
  top: calc(var(--safe-top) + 96px);
  left: 10px; right: 10px;
  max-width: 480px; margin: 0 auto;
  z-index: 955;
  background: var(--bad); color: #fff;
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13.5px; font-weight: 600;
  display: flex; gap: 8px; align-items: center;
  animation: pulse 1.1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .8; } }

.nav-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 960;
  max-width: 560px; margin: 0 auto;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,.18);
  padding: 12px 16px calc(var(--safe-bot) + 12px);
  display: flex; align-items: center; gap: 12px;
}
.nav-stat { flex: 1; text-align: center; }
.nav-stat b { display: block; font-size: 18px; font-weight: 800; }
.nav-stat span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.end-btn { border: 0; background: var(--bad); color: #fff; border-radius: 12px; padding: 13px 20px; font-size: 15px; font-weight: 700; }

/* ---------- Modal ---------- */
.modal { position: absolute; inset: 0; z-index: 1000; background: rgba(10,14,20,.5); display: grid; place-items: center; padding: 20px; }
.modal-card { width: 100%; max-width: 360px; background: #fff; border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
.modal-card h2 { margin: 0 0 14px; font-size: 19px; }
.sum-grid { display: flex; gap: 10px; margin-bottom: 18px; }
.sum-grid > div { flex: 1; background: var(--field); border-radius: 12px; padding: 14px; text-align: center; }
.sum-grid b { display: block; font-size: 20px; color: var(--accent); }
.sum-grid span { font-size: 11.5px; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bot) + 86px);
  z-index: 1100;
  background: rgba(28,32,38,.92); color: #fff;
  border-radius: 11px; padding: 11px 16px; font-size: 13.5px;
  max-width: 86%; text-align: center; box-shadow: var(--shadow);
}

/* ---------- Markers ---------- */
.mk { width: 15px; height: 15px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.mk-a { background: #1a73e8; }
.mk-b { background: var(--bad); }
.me { width: 46px; height: 46px; display: grid; place-items: center; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 7px rgba(26,115,232,.22); }

/* Navigation puck: one persistent element so position + rotation both glide. */
.leaflet-marker-icon.me-mk { transition: transform .75s linear; will-change: transform; }
.leaflet-zoom-anim .leaflet-marker-icon.me-mk { transition: none; }
.me-wrap { width: 46px; height: 46px; display: grid; place-items: center; }
.puck {
  width: 46px; height: 46px;
  filter: drop-shadow(0 3px 8px rgba(26,115,232,.5));
  transition: transform .6s ease;
  will-change: transform;
}
.puck svg { display: block; }
.poi { background: transparent; }
.poi-dot { width: 9px; height: 9px; border-radius: 50%; background: #c77700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.leaflet-tooltip.poi-label { background: rgba(255,255,255,.92); border: 0; box-shadow: none; color: #4a3a12; font-size: 11px; font-weight: 600; padding: 0 3px; }
.leaflet-tooltip.poi-label::before { display: none; }

.gw-pop h4 { margin: 0 0 2px; font-size: 15px; }
.gw-pop .pop-type { font-size: 12px; color: var(--muted); }
.gw-pop .pop-addr { font-size: 12.5px; margin-top: 4px; }
.gw-pop .pop-set { font-size: 12px; color: var(--accent); font-weight: 600; margin-top: 6px; }
