/* Lloyds Metals brand: black #231F20, red #E82329 */
:root {
  --chrome: #231F20;
  --accent: #E82329;
  --brand: #231F20;
  --brand-ink: #ffffff;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #17202b;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --ok: #1f8a4c; --ok-bg: #e3f4ea;
  --warn: #9a6400; --warn-bg: #fff3d6;
  --danger: #c0352b; --danger-bg: #fde7e5;
  --info: #0b5cad; --info-bg: #e3effc;
  --violet: #6a3fb5; --violet-bg: #efe8fb;
  --grey-bg: #eceff3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #ececec; --brand-ink: #1a1718; --accent: #ff4a4f;
    --bg: #121011; --surface: #1c1a1b; --ink: #ecebeb; --muted: #a7a2a3; --line: #353132;
    --ok: #4cc27f; --ok-bg: #143323;
    --warn: #f0b44c; --warn-bg: #3a2d10;
    --danger: #f07167; --danger-bg: #3d1b18;
    --info: #79b4f0; --info-bg: #142a42;
    --violet: #b79af0; --violet-bg: #2a1f40;
    --grey-bg: #2a2728;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 4px 0 12px; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.container { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--chrome); color: #fff; border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { height: 26px; width: auto; flex: none; display: block; }
.brand-text { padding-left: 12px; border-left: 1px solid rgba(255,255,255,.25); min-width: 0; }
.brand strong { display: block; font-size: .95rem; white-space: nowrap; }
.brand small { opacity: .75; white-space: nowrap; font-size: .75rem; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.who { font-size: .85rem; opacity: .85; }
@media (max-width: 760px) { .who { display: none; } }
@media (max-width: 420px) { .brand-text small { display: none; } .brand-logo { height: 20px; } }

/* ---------- navigation: bottom bar on phones, tabs on wide screens */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; position: relative;
}
.nav a svg { width: 24px; height: 24px; }
.nav a span.lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 2px; }
.nav a.active { color: var(--accent); }
.nav .count:not(:empty) { position: absolute; top: 6px; left: calc(50% + 6px); }
@media (min-width: 900px) {
  .nav { position: sticky; top: calc(54px + env(safe-area-inset-top)); bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); padding: 0 12px; gap: 4px; justify-content: center; }
  .nav a { flex: none; flex-direction: row; height: 48px; padding: 0 14px; font-size: .9rem; border-bottom: 3px solid transparent; }
  .nav a svg { width: 18px; height: 18px; }
  .nav a.active { color: var(--ink); border-color: var(--accent); }
  .nav .count:not(:empty) { position: static; }
  .container { padding-bottom: 32px; }
}
.count:not(:empty) {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

/* ---------- banners & toast */
.banner { padding: 8px 16px; font-size: .88rem; text-align: center; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--info-bg); color: var(--info); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 0); opacity: 0; pointer-events: none;
  width: max-content; max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 10px;
  background: #1d2733; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.25);
  transition: opacity .2s ease; z-index: 100; font-weight: 500;
}
.toast.show { opacity: 1; }
.toast.ok { background: var(--ok); }
.toast.error { background: #c0352b; }

/* ---------- buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.outline-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.35); color: inherit; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn.lg { min-height: 52px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn.icon { padding: 6px 9px; }

label { display: block; font-size: .86rem; font-weight: 600; color: var(--muted); }
label .opt { font-weight: 400; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 16px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.hint-text { font-weight: 400; font-size: .8rem; color: var(--muted); margin-top: 3px; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 500; }
label.check input { width: 22px; height: 22px; margin: 0; flex: none; }

/* ---------- cards & forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.form { display: grid; gap: 14px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .grid2.stack { grid-template-columns: 1fr; } }
.route-pick { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.route-pick .fields { display: grid; gap: 10px; }
.swap-btn { width: 44px; height: 44px; border-radius: 50%; padding: 0; }
.stepper { display: flex; align-items: center; gap: 0; margin-top: 4px; }
.stepper button { width: 48px; height: 46px; font-size: 1.3rem; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper input { margin: 0; text-align: center; border-radius: 0; border-left: 0; border-right: 0; width: 70px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
.login-card { width: min(100%, 400px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px 22px; box-shadow: var(--shadow); overflow: hidden; }
.login-brand { background: var(--chrome); border-bottom: 3px solid var(--accent); margin: -24px -22px 18px; padding: 22px 24px 16px; text-align: center; color: #fff; }
.login-brand img { display: block; width: 100%; height: auto; }
.login-brand div { margin-top: 10px; font-weight: 700; letter-spacing: .5px; }
.login-card form { display: grid; gap: 14px; }
.lang-pills { display: flex; gap: 6px; justify-content: center; margin-bottom: 4px; }
.lang-pills button { flex: 1; }
.lang-pills button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- stats & lists */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); line-height: 1.2; display: block; }
.stat.alert b { color: var(--accent); }
.list { display: grid; gap: 10px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 20px 0 10px; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.section-title:first-child { margin-top: 0; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .5; margin-bottom: 6px; }

.trip-card { cursor: pointer; display: block; color: inherit; text-decoration: none; }
.trip-card:active { transform: scale(.995); }
.trip-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.route { display: grid; grid-template-columns: 14px 1fr; column-gap: 10px; row-gap: 2px; align-items: center; font-weight: 600; }
.route .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); justify-self: center; }
.route .dot.end { background: var(--accent); border-color: var(--accent); }
.route .line { width: 2px; height: 10px; background: var(--line); justify-self: center; }
.trip-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: .86rem; color: var(--muted); }
.trip-meta span { display: inline-flex; align-items: center; gap: 4px; }
.trip-meta svg { width: 15px; height: 15px; }
.ref { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; color: var(--muted); }
.note { margin-top: 10px; padding: 8px 10px; background: var(--grey-bg); border-radius: 8px; font-size: .88rem; overflow-wrap: anywhere; }
.note.info { background: var(--info-bg); color: var(--info); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.actions .btn { flex: 1; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.s-pending { background: var(--warn-bg); color: var(--warn); }
.s-approved { background: var(--info-bg); color: var(--info); }
.s-assigned { background: var(--violet-bg); color: var(--violet); }
.s-in_progress { background: var(--ok); color: #fff; }
.s-completed { background: var(--ok-bg); color: var(--ok); }
.s-rejected { background: var(--danger-bg); color: var(--danger); }
.s-cancelled { background: var(--grey-bg); color: var(--muted); }

/* ---------- filters */
.filters { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-bottom: 12px; }
.filters .full { grid-column: 1 / -1; }
.filters input, .filters select { margin-top: 2px; padding: 9px 10px; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr; } .filters .full { grid-column: auto; } }

/* ---------- tables (admin) */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .4px; background: var(--grey-bg); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.user-row:last-child { border-bottom: 0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--grey-bg); color: var(--muted); flex: none; font-size: .9rem; }
.avatar.driver { background: var(--violet-bg); color: var(--violet); }
.avatar.admin { background: var(--danger-bg); color: var(--danger); }
.seg { display: flex; background: var(--grey-bg); padding: 4px; border-radius: 12px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- duty switch (driver) */
.duty { display: flex; align-items: center; gap: 12px; }
.duty .dotlive { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.duty.on .dotlive { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px transparent; } }

/* ---------- sheet (detail / dialogs) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 94vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 0 0 calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.sheet.full { height: 100vh; max-height: 100vh; border-radius: 0; max-width: none; }
@media (min-width: 900px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; max-height: 88vh; } .sheet.full { max-width: 900px; height: 88vh; border-radius: 18px; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet:not(.full) .sheet-head { padding-top: 14px; }
.sheet-head h2 { margin: 0; font-size: 1.05rem; flex: 1; min-width: 0; }
.sheet-body { padding: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.person { display: flex; align-items: center; gap: 12px; }
.person .grow b { display: block; }

/* ---------- maps */
.map { height: 300px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: var(--grey-bg); z-index: 1; }
.map.tall { height: calc(100vh - 260px); min-height: 360px; }
.map-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.pin { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.pin svg { width: 16px; height: 16px; }
.pin.driver { background: #6a3fb5; }
.pin.me { background: #0b5cad; }
.pin.traveller { background: #1f8a4c; }
.pin.plant { background: #231F20; border-radius: 8px; width: 26px; height: 26px; }
.pin.plant.dest { background: #E82329; }
.leaflet-container { font: inherit; }
.leaflet-tooltip { font-weight: 600; }

.live-pill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--ok); font-weight: 600; }
.live-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buses */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.bus-from { margin-top: 10px; }
.bus-time { font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; line-height: 1.1; min-width: 64px; }
.bus-time small { display: block; font-size: .72rem; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.bus-card.dim { opacity: .55; }
.seatbar { height: 8px; border-radius: 4px; background: var(--grey-bg); overflow: hidden; }
.seatbar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.seatbar.warn i { background: #e0a100; }
.seatbar.full i { background: var(--danger); }
.day-picks { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -8px; }
.day-picks .day { position: relative; }
.day-picks .day input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.day-picks .day span { display: inline-block; min-width: 46px; text-align: center; padding: 9px 8px; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; color: var(--ink); background: var(--surface); text-transform: capitalize; }
.day-picks .day input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.seg button { font-size: .88rem; padding: 9px 4px; }

/* assign: pick a scheduled bus */
.bus-pick { display: block; position: relative; cursor: pointer; padding-left: 44px; }
.bus-pick input { position: absolute; left: 14px; top: 18px; width: 20px; height: 20px; accent-color: var(--accent); }
.bus-pick.sel { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-bg); }
.bus-pick.dim { opacity: .55; cursor: not-allowed; }
.pick-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font-size: .8rem; }
