:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #1a2230;
  --muted: #6b7684;
  --border: #e2e7ee;
  --accent: #0b5cab;
  --accent-ink: #ffffff;
  --ok: #157347;
  --ok-bg: #e6f4ec;
  --warn: #b7791f;
  --danger: #c62828;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1d2630;
    --text: #e7ecf2;
    --muted: #93a0ae;
    --border: #2a3542;
    --accent: #4a9be8;
    --accent-ink: #0b141d;
    --ok: #4cc88a;
    --ok-bg: #16311f;
    --warn: #e0b057;
    --danger: #ef9a9a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

.view { min-height: 100dvh; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Buttons / fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 16px; font-weight: 600;
  padding: 12px 16px; border-radius: 12px; cursor: pointer;
  min-height: 48px; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text); min-height: 48px;
}
.error { color: var(--danger); font-size: 14px; margin: 4px 0 12px; }

/* ---------- Login ---------- */
.login-view { display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}

/* ---------- App shell ---------- */
.app-view { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--accent); color: var(--accent-ink);
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar-title strong { font-size: 18px; }
.zone-pill { font-size: 12px; opacity: .9; }
.icon-btn {
  border: none; background: rgba(255,255,255,.18); color: var(--accent-ink);
  width: 40px; height: 40px; border-radius: 10px; font-size: 20px; cursor: pointer;
}
.icon-btn:active { transform: rotate(90deg); }

.zone-bar {
  display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: calc(56px + var(--safe-top)); z-index: 9;
}
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.content {
  flex: 1; padding: 12px 12px calc(84px + var(--safe-bottom));
}

/* ---------- Collection cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card.collected { opacity: .72; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-cust { font-size: 17px; font-weight: 700; margin: 0; }
.card-loc { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.card-rows { margin: 10px 0 0; display: grid; gap: 6px; }
.row { display: flex; gap: 8px; font-size: 14px; }
.row .k { color: var(--muted); flex: none; width: 92px; }
.row .v { color: var(--text); word-break: break-word; }
.row a { color: var(--accent); text-decoration: none; }
.card-actions { margin-top: 12px; }

.badge-status {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); flex: none;
}
.badge-status.ok { background: var(--ok-bg); color: var(--ok); }

.meta-id { font-size: 12px; color: var(--muted); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.nav-btn {
  position: relative; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px;
}
.nav-btn.active { color: var(--accent); }
.nav-ico { font-size: 20px; line-height: 1; }
.badge {
  position: absolute; top: 2px; left: 56%; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- Profile ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.readout { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.readout:last-child { border-bottom: none; }
.readout .k { color: var(--muted); }

/* ---------- States ---------- */
.state { text-align: center; color: var(--muted); padding: 48px 16px; }
.state .big { font-size: 40px; display: block; margin-bottom: 8px; }
.skeleton { height: 120px; border-radius: 16px; margin-bottom: 12px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%); z-index: 50;
  background: #222c38; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; max-width: 90%; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.err { background: var(--danger); }

/* ---------- Grouped collection list ---------- */
.grp { margin-bottom: 14px; }
.grp-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); cursor: pointer; user-select: none;
}
.grp-caret { font-size: 12px; color: var(--muted); transition: transform .15s; width: 14px; text-align: center; }
.grp.collapsed .grp-caret { transform: rotate(-90deg); }
.grp-loc { font-weight: 700; font-size: 15px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-count { font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--surface-2); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.grp.grp-done .grp-count { color: var(--ok); }
.grp-check { display: inline-flex; align-items: center; padding: 4px; }
.grp-check input, .card-check input { width: 22px; height: 22px; accent-color: var(--accent); }
.grp-body { padding-top: 10px; display: grid; gap: 10px; }
.grp.collapsed .grp-body { display: none; }

.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-head-main { flex: 1; min-width: 0; }
.card-check { flex: none; display: inline-flex; align-items: center; padding-top: 2px; }
.card.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.coll-time { font-weight: 700; color: var(--accent); white-space: nowrap; }

/* ---------- Sticky multi-select action bar ---------- */
.select-bar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-bottom)); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.14);
}
.sel-count { font-weight: 700; font-size: 15px; }
.sel-actions { display: flex; align-items: center; gap: 10px; }
.sel-clear { border: none; background: none; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; padding: 10px; }
.sel-mark { width: auto; min-height: 44px; padding: 10px 18px; }
body.has-selbar .content { padding-bottom: calc(150px + var(--safe-bottom)); }

/* ---------- Topbar left (back + title) ---------- */
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.topbar-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Location list (main page) ---------- */
.loc-list { display: grid; gap: 10px; }
.loc-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; cursor: pointer; min-height: 60px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow); color: var(--text);
}
.loc-row:active { transform: translateY(1px); }
.loc-name { font-size: 16px; font-weight: 700; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc-meta { display: flex; align-items: center; gap: 8px; flex: none; }
.loc-count { font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--surface-2); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.loc-row.loc-done .loc-count { color: var(--ok); }
.loc-chevron { color: var(--muted); font-size: 22px; line-height: 1; }

/* ---------- Detail page ---------- */
.detail-head { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; padding: 0 2px; }
.detail-count { font-size: 13px; font-weight: 700; color: var(--muted); }
.detail-cards { display: grid; gap: 10px; }
.grp-check span { font-size: 14px; font-weight: 600; }

/* Location row: name + overall collection time stacked on the left */
.loc-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.loc-time { font-size: 12.5px; font-weight: 600; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Urgency / temperature flags */
.card-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.flag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.flag-urgent { background: rgba(198, 40, 40, 0.15); color: var(--danger); }
.flag-temp { background: rgba(11, 92, 171, 0.16); color: var(--accent); }

/* Hero ID on the order card — the number the driver matches to the sample tube */
.card-id { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-id-label { font-size: 10px; font-weight: 800; letter-spacing: 1px; color: var(--muted); }
.card-id-num { font-size: 25px; font-weight: 800; letter-spacing: .5px; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1.1; }
/* name is now secondary under the hero ID */
.card-cust { font-size: 14px; font-weight: 600; color: var(--muted); margin: 3px 0 0; }

/* neutral (non-error) status message, e.g. "Waking the server…" */
.error.info { color: var(--muted); }
