* { box-sizing: border-box; }

/* ---- Theme tokens: light by default, dark via system setting or toggle ---- */
:root {
  --brand: #0b6e4f;
  --brand-2: #e3f3ec;
  --on-brand: #fff;
  --head: #0b6e4f;
  --bg: #f3f4f6;
  --card: #fff;
  --card-2: #eceef1;
  --text: #1d2329;
  --muted: #69727d;
  --line: #e1e4e8;
  --input-line: #cdd3d9;
  --track: #e3e6ea;
  --ok: #17753a;
  --ok-bg: #e1f4e6;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --bad: #c42525;
  --bad-bg: #fde7e7;
  --bad-line: #f0c2c2;
  --info: #1d5bb8;
  --info-bg: #e4edfb;
  --purple: #7e22ce;
  --purple-bg: #f3e8ff;
  --wa: #128c4a;
  --toast-bg: #1d2329;
  --toast-fg: #fff;
  --radius: 12px;
  color-scheme: light;
}
body.trip-return { --brand: #4338ca; --brand-2: #ebe9fd; --head: #4338ca; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #3cc08f;
    --brand-2: rgba(60, 192, 143, .16);
    --on-brand: #04140d;
    --head: #0e4a37;
    --bg: #0f1316;
    --card: #1a1f24;
    --card-2: #262c33;
    --text: #e6e9ec;
    --muted: #9aa4ae;
    --line: #2c333a;
    --input-line: #3d454d;
    --track: #2c333a;
    --ok: #6ad596;
    --ok-bg: rgba(106, 213, 150, .14);
    --warn: #f2c265;
    --warn-bg: rgba(242, 194, 101, .14);
    --bad: #ff8a8a;
    --bad-bg: rgba(255, 110, 110, .14);
    --bad-line: rgba(255, 110, 110, .4);
    --info: #8db8ff;
    --info-bg: rgba(141, 184, 255, .14);
    --purple: #d3a6ff;
    --purple-bg: rgba(211, 166, 255, .14);
    --wa: #4fd88a;
    --toast-bg: #e6e9ec;
    --toast-fg: #111;
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) body.trip-return { --brand: #9b94f7; --brand-2: rgba(155, 148, 247, .18); --head: #352d91; }
}
:root[data-theme="dark"] {
  --brand: #3cc08f;
  --brand-2: rgba(60, 192, 143, .16);
  --on-brand: #04140d;
  --head: #0e4a37;
  --bg: #0f1316;
  --card: #1a1f24;
  --card-2: #262c33;
  --text: #e6e9ec;
  --muted: #9aa4ae;
  --line: #2c333a;
  --input-line: #3d454d;
  --track: #2c333a;
  --ok: #6ad596;
  --ok-bg: rgba(106, 213, 150, .14);
  --warn: #f2c265;
  --warn-bg: rgba(242, 194, 101, .14);
  --bad: #ff8a8a;
  --bad-bg: rgba(255, 110, 110, .14);
  --bad-line: rgba(255, 110, 110, .4);
  --info: #8db8ff;
  --info-bg: rgba(141, 184, 255, .14);
  --purple: #d3a6ff;
  --purple-bg: rgba(211, 166, 255, .14);
  --wa: #4fd88a;
  --toast-bg: #e6e9ec;
  --toast-fg: #111;
  color-scheme: dark;
}
:root[data-theme="dark"] body.trip-return { --brand: #9b94f7; --brand-2: rgba(155, 148, 247, .18); --head: #352d91; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; }
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin-top: 14px; }
p { margin: 0 0 8px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 14px; }
.err { color: var(--bad); font-weight: 600; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Inputs */
input[type=text], input[type=tel], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--input-line); border-radius: 10px;
  background: var(--card); color: var(--text); font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-2); }
textarea { resize: vertical; }
label.field { display: block; margin-bottom: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; color: var(--text); font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form input { width: 90px; flex: none; }
.inline-form span { flex: 1; color: var(--muted); font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  font-weight: 650; text-decoration: none; color: var(--text); text-align: center;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: var(--card); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn.wa { color: var(--wa); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row > .btn { flex: 1 1 auto; }
.linkbtn { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 8px 0; }

/* Header + nav */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--head); color: #fff;
}
.brand { font-weight: 750; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { display: block; font-weight: 500; font-size: 12px; opacity: .85; overflow: hidden; text-overflow: ellipsis; }
.seg { display: inline-flex; background: rgba(255,255,255,.2); border-radius: 999px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; color: #fff; padding: 7px 14px; border-radius: 999px; font-weight: 650; font-size: 14px; }
.seg button.on { background: #fff; color: var(--head); }
.seg.light { background: var(--card-2); }
.seg.light button { color: var(--text); }
.seg.light button.on { background: var(--brand); color: var(--on-brand); }
.icon { border: 0; background: transparent; color: #fff; font-size: 22px; width: 40px; height: 40px; border-radius: 50%; flex: none; }
.offline { background: var(--bad); color: #fff; text-align: center; padding: 6px; font-weight: 600; font-size: 14px; position: sticky; top: 56px; z-index: 19; }
main { max-width: 820px; margin: 0 auto; padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a { flex: 1; text-align: center; padding: 7px 0 9px; color: var(--muted); text-decoration: none; font-weight: 650; font-size: 13px; }
nav.bottom a span { display: block; font-size: 21px; line-height: 1.2; }
nav.bottom a.on { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

/* Login */
.login { max-width: 380px; margin: 0 auto; padding: 60px 20px; }
.login h1 { font-size: 26px; }
.login input { margin: 12px 0; font-size: 20px; letter-spacing: 1px; text-align: center; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stats.four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; text-align: left; color: var(--text); }
button.stat { width: 100%; }
.stat b { display: block; font-size: 22px; line-height: 1.2; }
.stat b small { font-size: 14px; color: var(--muted); font-weight: 600; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.stat.bad b { color: var(--bad); }
.stat.good b { color: var(--ok); }
.progress { height: 10px; background: var(--track); border-radius: 99px; overflow: hidden; margin: 4px 0 12px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }

/* Search + chips */
.searchbar { position: relative; }
.searchbar input { padding-right: 44px; font-size: 17px; min-height: 50px; }
.searchbar input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.searchbar .clear { position: absolute; right: 4px; top: 4px; width: 42px; height: 42px; border: 0; background: none; font-size: 24px; color: var(--muted); }
.chips { display: flex; flex-direction: column; gap: 5px; padding: 10px 0 8px; }
.chip-group { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { flex: none; min-height: 34px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 5px 9px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.chip.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.chip em { font-style: normal; opacity: .75; margin-left: 2px; }
.chips.dim .chip { opacity: .5; }
.filter-summary { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.filter-summary b { color: var(--text); }

/* Lists */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin-bottom: 12px; }
.row {
  display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; background: var(--card); border: 0;
  border-bottom: 1px solid var(--line); padding: 11px 12px; color: var(--text); text-decoration: none;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--brand-2); }
.row .sr { flex: none; min-width: 42px; color: var(--muted); font-size: 13px; font-weight: 700; }
.row .main { flex: 1; min-width: 0; }
.row .name { display: block; font-weight: 650; }
.row .sub { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { flex: none; text-align: right; }
.empty { padding: 20px; text-align: center; color: var(--muted); }
.more { padding: 10px; text-align: center; color: var(--muted); font-size: 14px; }

.pill { display: inline-block; white-space: nowrap; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.wait { background: var(--card-2); color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.tags { display: block; margin-top: 3px; }
.tag { display: inline-block; font-size: 11px; font-weight: 750; padding: 1px 6px; border-radius: 4px; margin: 0 4px 2px 0; text-transform: uppercase; letter-spacing: .02em; }
.tag.chair { background: var(--info-bg); color: var(--info); }
.tag.senior { background: var(--warn-bg); color: var(--warn); }
.tag.vol { background: var(--ok-bg); color: var(--ok); }
.tag.walkin { background: var(--purple-bg); color: var(--purple); }
.tag.flag { background: var(--bad-bg); color: var(--bad); }

/* Phone numbers */
.phones { margin: 4px 0 10px; }
.phone { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 6px 0; }
.phone + .phone { border-top: 1px solid var(--line); }
.phone-num { flex: 1 1 auto; font-size: 18px; font-weight: 700; color: var(--text); text-decoration: none; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.phone-num.big { font-size: 24px; }
.phone-acts { display: flex; gap: 6px; }

/* Bus cards */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 14px 0 8px; }
.section-head h2 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 8px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--text); text-decoration: none; }
.card:active { background: var(--brand-2); }
.bus-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 6px; }
.bus-label { flex: none; max-width: 100%; font-size: 20px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .progress { margin: 8px 0 6px; height: 8px; }
.progress i.full { background: var(--bad); }
.bus-meta { font-size: 14px; }
.bus-meta b { font-size: 17px; }
.vols { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mybus { background: var(--card); border: 2px solid var(--brand); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.mybus-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mybus-top .main { min-width: 0; }
.mybus .bus-label { font-size: 24px; }
.mybus .progress { margin: 8px 0 4px; height: 8px; }
.mybus .btn-row { margin-top: 8px; }
.covol { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; }
.covol .who { flex: 1 1 auto; font-weight: 650; }
.bus-summary { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.bus-summary b { color: var(--text); }
body.no-nav main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
body.no-nav #toast { bottom: calc(20px + env(safe-area-inset-bottom)); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel.danger { border-color: var(--bad-line); }
.back { display: inline-block; margin-bottom: 8px; font-weight: 650; text-decoration: none; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.detail-head .bus-label { font-size: 28px; }
.contact { padding: 8px 0; border-top: 1px solid var(--line); }
.contact .who { font-weight: 650; }
.contact .phone { padding: 2px 0; border: 0; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.admin-row:first-child { border-top: 0; }
.admin-row .main { flex: 1; min-width: 0; }
.admin-row .sub { font-size: 13px; color: var(--muted); }
.admin-row select { margin-top: 6px; min-height: 40px; font-size: 14px; }
.admin-row .acts { display: flex; flex-direction: column; gap: 6px; flex: none; }
details summary { cursor: pointer; font-weight: 650; color: var(--brand); padding: 10px 0; }
.log-item { font-size: 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.log-item .sub { font-size: 12px; color: var(--muted); }

/* Bottom sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--card); color: var(--text); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
@media (min-width: 700px) { .sheet { bottom: 50%; transform: translateY(50%); border-radius: 18px; } }
.sheet-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 6px; }
.sheet-head .main { flex: 1; min-width: 0; }
.sheet-title { font-size: 20px; font-weight: 750; line-height: 1.25; }
.sheet .x { flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--card-2); color: var(--text); font-size: 22px; line-height: 1; }
.status { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 15px; }
.status.ok { background: var(--ok-bg); }
.status.wait { background: var(--card-2); }
.status.warn { background: var(--warn-bg); }
.status.bad { background: var(--bad-bg); }
.label { font-size: 14px; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.checks { display: grid; gap: 8px; }
.bigcheck { display: flex; align-items: center; gap: 12px; border: 2px solid var(--line); border-radius: 12px; padding: 12px; font-weight: 650; }
.bigcheck input { width: 26px; height: 26px; accent-color: var(--brand); flex: none; }
.bigcheck:has(input:checked) { border-color: var(--brand); background: var(--brand-2); }
.busgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.busbtn { border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); padding: 8px 4px; text-align: center; min-height: 58px; }
.busbtn b { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busbtn small { font-size: 12px; color: var(--muted); font-weight: 600; }
.busbtn.sel { border-color: var(--brand); background: var(--brand-2); box-shadow: 0 0 0 1px var(--brand); }
.busbtn.cur small { color: var(--ok); }
.busbtn:disabled { opacity: .4; }
.warnline { color: var(--warn); background: var(--warn-bg); padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; margin-top: 10px; }
.vol-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; }
.vol-chip .main { flex: 1; min-width: 0; }
.vol-chip .sub { display: block; font-size: 13px; color: var(--muted); }
.choice { display: block; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 6px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); }
.choice b { font-size: 18px; font-variant-numeric: tabular-nums; }
.choice .sub { display: block; font-size: 13px; color: var(--muted); }
.choice.sel { border-color: var(--brand); background: var(--brand-2); }
.choice:disabled { opacity: .5; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--toast-bg); color: var(--toast-fg); padding: 12px 16px; border-radius: 12px; width: max-content; max-width: calc(100% - 24px);
  box-shadow: 0 6px 24px rgba(0,0,0,.3); font-weight: 600; text-align: center;
  pointer-events: none; /* never swallow taps meant for the list underneath */
}
#toast.err { background: var(--bad); color: #fff; }
[hidden] { display: none !important; }
