/* TrailPool — shared styles. Light/dark via prefers-color-scheme. */
:root {
  --bg: #f4f3ee;
  --surface: #fcfcfb;
  --surface2: #efeee8;
  --ink: #22261f;
  --ink2: #5c6357;
  --ink3: #8a9184;
  --line: #ddddd2;
  --accent: #2f5d3a;
  --accent-ink: #fff;
  --driver: #2b8a3e;
  --rider: #e03131;
  --maybe: #e8590c;
  --self: #1971c2;
  --ok-bg: #e6f4ea;
  --warn-bg: #fdf0e5;
  --danger: #c92a2a;
  --shadow: 0 1px 3px rgba(20, 30, 15, .1), 0 4px 16px rgba(20, 30, 15, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141613;
    --surface: #1d201b;
    --surface2: #262a23;
    --ink: #e8eae4;
    --ink2: #a8b0a0;
    --ink3: #767e6f;
    --line: #34382f;
    --accent: #5c9c6c;
    --accent-ink: #10130e;
    --ok-bg: #1d2e22;
    --warn-bg: #33261a;
    --danger: #ff6b6b;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
a { color: var(--accent); }
p { margin: .3em 0; }

.wrap { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 900px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--ink2); text-transform: uppercase; letter-spacing: .08em;
  font-size: 12px; font-weight: 600; margin-bottom: 4px;
}
.muted { color: var(--ink2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--ink3); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 4px; }
label .opt { font-weight: 400; color: var(--ink3); }
input[type=text], input[type=tel], input[type=email], input[type=password],
input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; font: inherit;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent;
}
textarea { min-height: 70px; resize: vertical; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }

.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  flex: 1 1 40%; margin: 0; text-align: center; padding: 10px 4px; cursor: pointer;
  border: 1.5px solid var(--line); border-radius: 8px; font-weight: 600; font-size: 14px;
  color: var(--ink2); background: var(--surface);
}
.seg input:checked + label { border-color: var(--accent); color: var(--accent); background: var(--ok-bg); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); }

button, .btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 8px; padding: 10px 18px; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
.btn-secondary { background: var(--surface2); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn-block { width: 100%; padding: 13px; font-size: 17px; margin-top: 18px; }

.field-error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 1.2em; }

/* ---------- badges / chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px;
  color: #fff;
}
.chip.driver { background: var(--driver); }
.chip.rider { background: var(--rider); }
.chip.maybe { background: var(--maybe); }
.chip.self { background: var(--self); }
.chip.plain { background: var(--surface2); color: var(--ink2); border: 1px solid var(--line); }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12px; color: var(--ink2); font-weight: 600; }
.stat-click { cursor: pointer; }
.stat-click:hover { border-color: var(--accent); }

/* ---------- leader layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1100;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .spacer { flex: 1; }
.dash {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 0;
  height: calc(100dvh - 57px);
}
#map { height: 100%; min-height: 320px; background: var(--surface2); }
.side { overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg); padding: 12px; }
@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; height: auto; }
  #map { height: 52dvh; }
  .side { border-left: none; }

  /* topbar buttons scroll sideways instead of wrapping to 2 rows */
  .topbar { flex-wrap: nowrap; overflow-x: auto; }
  .topbar h1, .topbar button, .topbar .btn, .topbar .tiny { white-space: nowrap; flex-shrink: 0; }

  /* bottom nav swaps which pane is visible full-height */
  body { padding-bottom: 62px; }
  #toast { bottom: 76px; }
  #mobileNav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1500;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 6px;
  }
  body[data-mpane="map"] .side { display: none; }
  body[data-mpane="map"] #map { height: calc(100dvh - 57px - 62px); }
  body[data-mpane="people"] #map, body[data-mpane="cars"] #map { display: none; }
  body[data-mpane="people"] .side, body[data-mpane="cars"] .side { min-height: calc(100dvh - 57px - 62px); }
  body[data-mpane="people"] .tabs, body[data-mpane="cars"] .tabs { display: none; }
}

/* ---------- mobile bottom nav (hidden on desktop) ---------- */
#mobileNav { display: none; }
#mobileNav button {
  flex: 1; background: var(--surface2); color: var(--ink2); border: 1px solid var(--line);
  padding: 9px 4px; font-size: 14px; font-weight: 600; border-radius: 8px;
}
#mobileNav button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button {
  flex: 1; background: var(--surface2); color: var(--ink2); border: 1px solid var(--line);
  padding: 8px; font-size: 14px;
}
.tabs button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- filter chips ---------- */
.fchips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.fchip {
  background: var(--surface); color: var(--ink2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
}
.fchip span { color: var(--ink3); }
.fchip:hover { border-color: var(--accent); filter: none; }
.fchip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.fchip.active span { color: var(--accent-ink); opacity: .75; }

/* ---------- duplicate banner ---------- */
.dupe-banner {
  background: var(--warn-bg); border: 1px solid var(--maybe); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 9px;
}
.dupe-toggle {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--ink); padding: 2px; font-size: 13px; font-weight: 700;
}
.dupe-toggle:hover { filter: none; text-decoration: underline; }
.dupe-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.dupe-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 0; }
.dupe-card .nm { font-weight: 700; font-size: 13px; }
.dupe-card .tiny { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dupe-card button { margin-top: 6px; width: 100%; }

.person-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 7px;
  cursor: pointer;
}
.person-row:hover { border-color: var(--accent); }
.person-row .info { flex: 1; min-width: 0; }
.person-row .nm { font-weight: 600; font-size: 14px; }
.person-row .sub { font-size: 12px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.dot.driver { background: var(--driver); }
.dot.rider { background: var(--rider); }
.dot.maybe { background: var(--maybe); }
.dot.self { background: var(--self); }
.dot.hollow { background: transparent; border: 2.5px dashed var(--ink3); }

.car-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.car-card header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.car-card header .nm { font-weight: 700; }
.car-card .seatbar { font-size: 13px; color: var(--ink2); }
.car-rider { display: flex; align-items: center; gap: 8px; padding: 5px 0 5px 8px; font-size: 14px; border-top: 1px dashed var(--line); }
.car-rider .x { margin-left: auto; }
.car-actions { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.car-badges { display: flex; gap: 5px; flex-wrap: wrap; margin: 6px 0 4px; }
.badge {
  font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 8px;
  background: var(--surface2); color: var(--ink2); border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-bg); color: var(--driver); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--maybe); border-color: transparent; }
.badge.bad { background: transparent; color: var(--rider); border-color: var(--rider); }
.badge.dim { color: var(--ink3); }
select.addrider { margin-top: 8px; padding: 6px 8px; font-size: 13px; }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10, 14, 8, .55); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto; padding: 20px;
}
.modal h2 { font-size: 18px; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.hidden { display: none !important; }

/* ---------- map pins ---------- */
.pin { filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.pin svg { display: block; }
.leaflet-popup-content { font: 14px/1.45 system-ui, sans-serif; margin: 12px 14px; }
.leaflet-popup-content .nm { font-weight: 700; font-size: 15px; }
.pop-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* legend on map */
.legend {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; box-shadow: var(--shadow); font-size: 13px; line-height: 1.9;
}
.legend .dot { display: inline-block; vertical-align: -1px; margin-right: 6px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; z-index: 3000; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.actionable { display: flex; align-items: center; gap: 14px; }
#toast.show.actionable { pointer-events: auto; }
.toast-btn {
  background: transparent; color: var(--bg); border: 1.5px solid var(--bg);
  border-radius: 7px; padding: 4px 12px; font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.toast-btn:hover { filter: none; background: rgba(255, 255, 255, .15); }

/* ---------- driver / roster page bits ---------- */
.hero-num { font-size: 40px; font-weight: 800; letter-spacing: -.03em; }
.stop { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.stop:first-of-type { border-top: none; }
.stop .idx {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  margin-top: 2px;
}
.stop .who { flex: 1; }
.stop .who .nm { font-weight: 700; }
.stop .who .links { display: flex; gap: 14px; margin-top: 3px; font-size: 14px; flex-wrap: wrap; }
