:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1a2027;
  --muted: #6b7684;
  --line: #e2e6ea;
  --brand: #0e7c86;
  --brand-ink: #ffffff;
  --ok: #1a7f37;
  --warn: #b7791f;
  --bad: #c0392b;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .05);
  --r: 12px;
  --tab-h: 56px;
  --top-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }

/* buttons */
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: .6rem .9rem; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.ghost { background: transparent; }
.danger { color: var(--bad); border-color: #eecfca; }
.link { background: none; border: none; color: var(--brand); text-decoration: underline; }
.icon-btn { border: none; background: none; font-size: 1.4rem; padding: .3rem .5rem; line-height: 1; }
.big-btn { width: 100%; padding: 1.4rem; font-size: 1.15rem; border: 2px dashed var(--brand);
  color: var(--brand); background: #eef7f8; border-radius: var(--r); }

/* overlay / cards */
.overlay { position: fixed; inset: 0; background: rgba(20, 28, 36, .55); display: grid; place-items: center;
  z-index: 1000; padding: 1rem; }
.overlay[hidden] { display: none; }   /* the `hidden` attribute must beat display:grid */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 1.4rem;
  width: min(440px, 100%); display: flex; flex-direction: column; gap: .8rem; }
.card h1, .card h2 { margin: 0 0 .2rem; }
.logo { font-size: 2rem; text-align: center; color: var(--brand); margin: 0; }
.card input, .card label { display: block; width: 100%; }
.card label { font-weight: 600; font-size: .9rem; display: flex; flex-direction: column; gap: .3rem; }
.card input { padding: .7rem; border: 1px solid var(--line); border-radius: 10px; font-weight: 400; }

/* app shell */
#app { min-height: 100%; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
#topbar { position: sticky; top: 0; z-index: 10; height: var(--top-h); background: var(--card);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .5rem; padding: 0 .6rem; }
.title-wrap { flex: 1; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.logo-sm { font-weight: 700; color: var(--brand); }
#batch-select { flex: 1; min-width: 0; padding: .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

main { padding: 1rem; max-width: 960px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: .9rem; }

/* capture */
.thumbs { display: flex; gap: .5rem; flex-wrap: wrap; }
.thumb { position: relative; width: 84px; height: 108px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: #ddd; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; inset-inline-start: 2px; top: 2px; background: rgba(0,0,0,.6); color: #fff;
  border: none; border-radius: 50%; width: 22px; height: 22px; padding: 0; font-size: .8rem; }

/* status / progress */
.status { min-height: 1.2em; font-size: .9rem; color: var(--muted); }
.status.err { color: var(--bad); }
.status.ok { color: var(--ok); }
.progress { height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: .3rem; }
.progress > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }

/* toolbar */
.toolbar { display: flex; gap: .5rem; align-items: center; }
.toolbar.wrap { flex-wrap: wrap; }
.toolbar > * { flex: 0 0 auto; }

/* review table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.stops { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 620px; }
table.stops th, table.stops td { border-bottom: 1px solid var(--line); padding: .4rem .5rem; text-align: start; vertical-align: middle; }
table.stops th { position: sticky; top: 0; background: var(--bg); font-size: .78rem; color: var(--muted); }
table.stops td input { width: 100%; border: 1px solid transparent; border-radius: 6px; padding: .35rem; background: transparent; }
table.stops td input:focus { border-color: var(--brand); background: #fff; outline: none; }
table.stops tr.low td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.stops tr.nogeo { background: #fff7ed; }
.num-badge { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: .8rem; font-weight: 700; }
.badge { font-size: .72rem; padding: .1rem .4rem; border-radius: 999px; white-space: nowrap; }
.badge.high { background: #e6f4ea; color: var(--ok); }
.badge.low { background: #fdf0e3; color: var(--warn); }
.badge.none { background: #fbe6e2; color: var(--bad); }
.row-actions { display: flex; gap: .25rem; }
.row-actions button { padding: .3rem .45rem; font-size: .85rem; }

/* map + route */
#view-map { gap: 0; }
#map { height: 55vh; min-height: 300px; border-radius: var(--r); border: 1px solid var(--line); direction: ltr; }
#route-panel { margin-top: .8rem; display: flex; flex-direction: column; gap: .7rem; }
.day-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.day-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem .8rem; background: #eef7f8; font-weight: 600; }
.stop-row { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; border-top: 1px solid var(--line); }
.stop-row.done { opacity: .55; }
.stop-row .addr { flex: 1; min-width: 0; }
.stop-row .addr .street { font-weight: 600; }
.stop-row .addr .sub { font-size: .82rem; color: var(--muted); }
.nav-btns { display: flex; gap: .35rem; }
.nav-btns a { text-decoration: none; display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 1.1rem; }
.nav-btns a.waze { background: #33ccff20; }
.nav-btns a.gmaps { background: #34a85320; }
bdi, .ltr { direction: ltr; unicode-bidi: isolate; }

/* tabbar */
#tabbar { position: fixed; inset-inline: 0; bottom: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  display: flex; z-index: 20; }
#tabbar button { flex: 1; border: none; background: none; color: var(--muted); font-size: .85rem; border-radius: 0; }
#tabbar button.active { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }

/* toast */
#toast { position: fixed; inset-inline: 0; bottom: calc(var(--tab-h) + 12px); display: flex; flex-direction: column;
  align-items: center; gap: .4rem; z-index: 2000; pointer-events: none; }
.toast { background: #1f2933; color: #fff; padding: .6rem 1rem; border-radius: 999px; box-shadow: var(--shadow);
  font-size: .9rem; max-width: 90vw; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

@media (min-width: 760px) {
  #view-map { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; align-items: start; }
  #map { height: calc(100vh - var(--top-h) - var(--tab-h) - 2rem); }
  #route-panel { margin-top: 0; max-height: calc(100vh - var(--top-h) - var(--tab-h) - 2rem); overflow-y: auto; }
}
