:root {
  --green: #0b6e4f; --green-dark: #08523b;
  --amber: #b45309; --blue: #1d4ed8; --slate: #374151;
  --ink: #111827; --muted: #5b6472; --bg: #f4f6f8; --panel: #ffffff; --line: #dfe3e8; --chip: #eef2f5;
  --red: #dc2626;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #f2f4f7; --muted: #a3acb9; --bg: #0b0f14; --panel: #161c24; --line: #2a3441; --chip: #1f2833; color-scheme: dark; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  height: 100%; margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Georgian", "Noto Sans", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; background: var(--bg); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--sb) + 112px); }

/* ---------------------------------------------------------------- driving view */
.top {
  position: fixed; z-index: 10; top: calc(var(--st) + 8px); left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px);
  display: flex; flex-direction: column; align-items: flex-start; pointer-events: none;
}
.banner {
  width: 100%; display: flex; gap: 14px; align-items: center; padding: 12px 16px 12px 12px;
  border-radius: 18px; background: var(--green); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
  pointer-events: auto; transition: background-color .25s;
}
.banner.back { background: var(--amber); }
.banner.start { background: var(--blue); }
.banner.wait { background: var(--slate); }
.b-icon { width: 78px; height: 78px; flex: none; color: #fff; }
.b-icon svg { width: 100%; height: 100%; display: block; }
.b-text { min-width: 0; flex: 1; }
.b-dist { font-size: 40px; font-weight: 800; letter-spacing: -.5px; line-height: 1.02; font-variant-numeric: tabular-nums; }
.b-instr { font-size: 21px; font-weight: 650; margin-top: 3px; line-height: 1.2; }
.b-street { font-size: 18px; opacity: .93; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.then {
  margin-top: -6px; padding: 12px 14px 8px; border-radius: 0 0 14px 14px; background: var(--green-dark); color: #fff;
  display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; box-shadow: 0 6px 14px rgba(0, 0, 0, .2);
}
.banner.back + .then { background: #8a3f06; }
.then-icon { width: 30px; height: 30px; display: inline-block; }
.then-icon svg { width: 100%; height: 100%; display: block; }

.bottom {
  position: fixed; z-index: 10; left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); bottom: calc(var(--sb) + 8px);
  background: var(--panel); border-radius: 18px; box-shadow: 0 8px 24px rgba(0, 0, 0, .22); padding: 10px 12px 12px;
}
.bar { position: relative; height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
#barFill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--green); }
#barMissed { position: absolute; inset: 0; pointer-events: none; }
#barMissed i { position: absolute; top: 0; bottom: 0; background: var(--red); min-width: 2px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; }
.stat { min-width: 0; }
.big { font-size: 18px; white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.small { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btns { display: flex; gap: 8px; flex: none; }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--chip); color: var(--ink);
  display: inline-grid; place-items: center; padding: 0;
}
.round svg { width: 26px; height: 26px; }
.round.on { background: var(--green); color: #fff; border-color: var(--green); }

.pill {
  position: fixed; z-index: 11; left: calc(var(--sl) + 12px); bottom: calc(var(--sb) + 112px);
  padding: 12px 18px; border-radius: 999px; border: 0; background: var(--panel); color: var(--ink);
  font-weight: 650; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
.toast {
  position: fixed; z-index: 12; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 116px);
  width: min(560px, calc(100% - 24px)); display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 12px 14px; border-radius: 14px; background: #111827; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  font-weight: 600;
}
.toast button { flex: none; padding: 10px 14px; border-radius: 10px; border: 0; background: #fff; color: #111827; font-weight: 700; }
.simbar { display: flex; gap: 6px; margin-bottom: 10px; }
.simbar button { flex: 1 1 auto; padding: 9px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--chip); font-weight: 650; font-size: 14px; white-space: nowrap; }
.simbar button.on { background: var(--blue); color: #fff; border-color: var(--blue); }

.car { width: 48px; height: 48px; }
.car svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .4)); }
.car.off svg circle { fill: #f59e0b; }

.gpshelp {
  margin-top: 8px; width: 100%; background: var(--panel); color: var(--ink); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); pointer-events: auto; border-left: 6px solid var(--amber);
}
.gh-title { font-size: 18px; font-weight: 750; }
.gh-text { font-size: 15px; margin-top: 6px; line-height: 1.4; }
.gh-btns { display: flex; gap: 8px; }
.gh-btns .btn { flex: 1; padding: 12px 10px; font-size: 16px; }
.gpschip { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; }
.gpschip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.gpschip.good { color: #15803d; } .gpschip.fair { color: #b45309; } .gpschip.poor { color: var(--red); }
.gpschip.none { color: var(--muted); } .gpschip.sim { color: var(--blue); }

/* ---------------------------------------------------------------- menu sheet */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border-radius: 20px 20px 0 0; padding: 10px 16px calc(var(--sb) + 16px);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .3);
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.sheet h3 { margin: 18px 2px 8px; font-size: 13px; text-transform: none; letter-spacing: .02em; color: var(--muted); font-weight: 650; }
.sheet .item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 14px 14px; margin: 6px 0;
  border-radius: 14px; border: 1px solid var(--line); background: var(--chip); font-size: 17px; font-weight: 600;
}
.sheet .item.danger { color: var(--red); }
.sheet .item:disabled { opacity: .45; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--chip); font-weight: 600; font-size: 15px; }
.seg button.on { background: var(--green); border-color: var(--green); color: #fff; }
.missed-list { list-style: none; margin: 0; padding: 0; }
.missed-list li { padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.missed-list li b { font-weight: 650; }

/* ---------------------------------------------------------------- preview */
.preview-card {
  position: fixed; z-index: 10; left: calc(var(--sl) + 8px); right: calc(var(--sr) + 8px); bottom: calc(var(--sb) + 8px);
  background: var(--panel); border-radius: 18px; padding: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.p-head { display: flex; gap: 12px; align-items: center; }
.p-icon { width: 64px; height: 64px; flex: none; color: #fff; background: var(--green); border-radius: 14px; padding: 6px; }
.p-icon svg { width: 100%; height: 100%; display: block; }
.p-instr { font-size: 20px; font-weight: 700; }
.p-street { font-size: 16px; color: var(--muted); }
.p-meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.p-btns { display: flex; gap: 8px; margin-top: 10px; }
.p-btns .btn { flex: 1; }

/* ---------------------------------------------------------------- start screen */
.home {
  position: fixed; inset: 0; z-index: 30; overflow: auto; -webkit-overflow-scrolling: touch; background: var(--bg);
  padding: calc(var(--st) + 18px) calc(var(--sr) + 16px) calc(var(--sb) + 24px) calc(var(--sl) + 16px);
}
.wrap { max-width: 560px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand img { width: 46px; height: 46px; border-radius: 12px; }
.brand h1 { font-size: 24px; margin: 0; letter-spacing: -.2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 19px; margin: 0 0 4px; line-height: 1.25; }
.card .meta { color: var(--muted); font-size: 15px; margin: 2px 0; }
.card .warn { color: var(--amber); font-size: 15px; margin-top: 6px; }
.mini-map { display: block; width: 100%; height: 190px; border-radius: 12px; overflow: hidden; margin: 12px 0 6px; background: var(--chip); }
.prog { margin-top: 10px; }
.btn {
  display: block; width: 100%; padding: 15px 16px; margin-top: 10px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); font-size: 17px; font-weight: 650; text-align: center;
}
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); font-size: 19px; padding: 17px 16px; }
.btn.quiet { background: transparent; }
.btn:disabled { opacity: .5; }
.how { margin: 6px 0 0; padding-left: 20px; color: var(--ink); }
.how li { margin: 6px 0; }
.note { color: var(--muted); font-size: 14px; margin-top: 10px; }
.err { color: var(--red); font-weight: 600; margin-top: 8px; }
.label { font-size: 13px; color: var(--muted); font-weight: 650; margin: 14px 0 6px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- landscape (phone across the dashboard) */
@media (orientation: landscape) and (max-height: 560px) {
  .top { right: auto; width: min(430px, 48vw); }
  .b-icon { width: 62px; height: 62px; }
  .b-dist { font-size: 32px; }
  .b-instr { font-size: 18px; }
  .b-street { font-size: 16px; }
  .bottom { right: auto; width: min(430px, 48vw); }
  .toast { left: calc(var(--sl) + 8px); transform: none; width: min(430px, 48vw); bottom: calc(var(--sb) + 120px); }
  .pill { left: auto; right: calc(var(--sr) + 12px); bottom: calc(var(--sb) + 16px); }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--sb) + 4px); }
}

/* Bundled survey days: keep large touch targets on narrow phone screens. */
.day-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.day-picker .day-option { min-height: 54px; margin: 0; font-weight: 650; }
.day-option:focus-visible, #hChooseDay:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
