:root {
  --bg: #f3f4f7; --card: #fff; --ink: #141a2b; --muted: #5b6375; --line: #d9dde5;
  --head: #1f2a44; --head-ink: #fff; --accent: #2457d6; --accent-ink: #fff;
  --done: #1d7a46; --done-bg: #e6f4ec; --warn: #9a5b00; --warn-bg: #fff4dc; --error: #b42318;
  --note-bg: #fff8e1; --note-line: #f0d48a;
  --radius: 10px; --tap: 48px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141e; --card: #1a2030; --ink: #eef1f7; --muted: #a3abbd; --line: #2e3647;
    --head: #0b0f18; --accent: #5b8cff; --accent-ink: #0b0f18;
    --done: #5fd394; --done-bg: #16301f; --warn: #ffc25c; --warn-bg: #3a2c10; --error: #ff8a80;
    --note-bg: #2f2814; --note-line: #6b5a24;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; }
h2 { font-size: 1.25rem; margin: 0 0 .6rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.center { text-align: center; }
.error { color: var(--error); font-weight: 600; }
.plain { list-style: none; padding: 0; margin: .3rem 0 .8rem; max-height: 40vh; overflow: auto; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); background: var(--head); color: var(--head-ink); }
.brand { font-weight: 700; flex: 1; }
.tag { font-size: .7rem; background: #f5b400; color: #000; padding: .1rem .4rem; border-radius: 4px; vertical-align: middle; }
.status { font-size: .85rem; padding: .25rem .6rem; border-radius: 99px; background: rgba(255, 255, 255, .15); white-space: nowrap; }
.status.offline { background: #f5b400; color: #000; }
.status.error { background: #ff6b5e; color: #000; }
.top .linkbtn { color: var(--head-ink); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: 6rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.narrow { max-width: 420px; margin: 2rem auto; }
label { display: block; font-weight: 600; margin: .6rem 0; }
input, textarea { font: inherit; color: inherit; background: var(--card); border: 1.5px solid var(--line); border-radius: 8px; padding: .6rem .7rem; width: 100%; min-height: var(--tap); }
input:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.btn { font: inherit; font-weight: 600; min-height: var(--tap); padding: .55rem 1.1rem; border-radius: 8px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.wide { width: 100%; margin-top: .5rem; }
.btn:disabled { opacity: .5; }
.linkbtn { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: .5rem 0; text-decoration: underline; min-height: 40px; }
.row { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }

.tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { font: inherit; font-weight: 600; min-height: 42px; padding: .4rem 1rem; border-radius: 99px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.tabs button[aria-current="true"] { background: var(--head); color: var(--head-ink); border-color: var(--head); }
.tabs .badge { font-size: .75rem; margin-left: .35rem; color: var(--done); }

.route-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.progress-wrap { min-width: 220px; flex: 0 1 320px; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--done); transition: width .3s; }
#progress-text { margin: .3rem 0 0; font-size: .95rem; text-align: right; }

.office-note { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 8px; padding: .35rem .6rem; font-size: .92rem; margin-top: .35rem; }
.office-note.big { font-size: 1rem; padding: .7rem .9rem; margin: 0 0 .8rem; }
.office-note.big p { margin: .15rem 0; }
.banner { background: var(--done-bg); color: var(--ink); border: 1px solid var(--done); border-radius: 8px; padding: .7rem .9rem; margin-bottom: .8rem; }

.tools { display: flex; gap: .8rem; align-items: center; margin-bottom: .6rem; }
.tools input[type=search] { flex: 1; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0; white-space: nowrap; }
.check input { width: 22px; height: 22px; min-height: 0; }

.stops { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.stops-head { display: none; }
.stop { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: .75rem; display: grid; gap: .4rem .75rem;
  grid-template-columns: 2.2rem 1fr 6.2rem; grid-template-areas: "num main ret" "num draw ret" "note note note"; }
.stop.done { border-color: color-mix(in srgb, var(--done) 55%, var(--line)); }
.stop.done .num { background: var(--done); color: #fff; }
.stop .num { grid-area: num; align-self: start; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.stop .main { grid-area: main; min-width: 0; }
.stop .biz { font-weight: 700; }
.stop .addr { color: var(--muted); font-size: .92rem; }
.stop .draw { grid-area: draw; font-size: .92rem; color: var(--muted); }
.stop .draw b { color: var(--ink); }
.stop .ret { grid-area: ret; margin: 0; font-weight: 600; font-size: .8rem; color: var(--muted); }
.stop .ret input { font-size: 1.35rem; font-weight: 700; text-align: center; padding: .4rem; margin-top: .15rem; }
.stop .ret input.bad { border-color: var(--error); }
.stop .note-area { grid-area: note; }
.stop .note-area textarea { min-height: 44px; resize: vertical; font-size: .98rem; }
.stop .note-toggle { padding: .3rem 0; min-height: 36px; }
.stop .warn { grid-column: 1 / -1; color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: .25rem .5rem; font-size: .88rem; }
.stop .has-note { color: var(--accent); font-weight: 600; }

.finish-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; padding: .7rem 1rem; padding-bottom: max(.7rem, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-top: 1px solid var(--line); display: flex; justify-content: center; }
.finish-bar .btn { width: min(100%, 420px); font-size: 1.05rem; }

dialog { border: 0; border-radius: 14px; padding: 1.25rem; width: min(92vw, 480px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog li button { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: .3rem 0; text-align: left; }

.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); z-index: 10; background: var(--head); color: var(--head-ink); padding: .7rem 1rem; border-radius: 8px; max-width: 90vw; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }

/* Laptops: one row per stop, like the paper sheet, with the note box always open. */
@media (min-width: 820px) {
  .stops { gap: 0; border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
  .stops-head, .stop { grid-template-columns: 2.6rem minmax(0, 1.4fr) 4.5rem 6.5rem minmax(0, 1.6fr); grid-template-areas: "num main draw ret note"; align-items: center; }
  .stops-head { display: grid; gap: .75rem; padding: .4rem .75rem; font-size: .82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  .stop { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: .45rem .75rem; }
  .stop.done { background: color-mix(in srgb, var(--done-bg) 55%, var(--card)); }
  .stop .draw { text-align: right; font-size: 1rem; }
  .stop .draw .lbl, .stop .ret .lbl { display: none; }
  .stop .ret input { margin: 0; font-size: 1.15rem; min-height: 42px; }
  .stop .note-toggle { display: none; }
  .stop .note-area textarea { display: block !important; min-height: 42px; height: 42px; }
  .stop .warn { grid-column: 2 / -1; }
}

/* Office page */
.office-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.office-table th, .office-table td { text-align: left; padding: .55rem .7rem; border-top: 1px solid var(--line); vertical-align: top; }
.office-table th { font-size: .82rem; text-transform: uppercase; color: var(--muted); border-top: 0; }
.office-table td.n { text-align: right; font-variant-numeric: tabular-nums; }
.office-table tr.route-row { cursor: pointer; }
.office-table tr.route-row:hover { background: var(--bg); }
.pill { display: inline-block; font-size: .8rem; font-weight: 700; border-radius: 99px; padding: .1rem .55rem; }
.pill.ok { background: var(--done-bg); color: var(--done); }
.pill.part { background: var(--warn-bg); color: var(--warn); }
.pill.none { background: var(--bg); color: var(--muted); }
.stat-row { display: flex; gap: .8rem; flex-wrap: wrap; margin: .8rem 0 1rem; }
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; min-width: 150px; flex: 1; }
.stat b { display: block; font-size: 1.5rem; }
.detail td { background: var(--bg); }
.notes-list { display: grid; gap: .5rem; margin: .5rem 0 1.5rem; padding: 0; list-style: none; }
.notes-list li { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: .6rem .8rem; }
.scroll-x { overflow-x: auto; }
