/* CarPooler — mobile-first design tokens drawn from the logo */
:root {
  --navy: #022f70;
  --blue: #0072f3;
  --blue-strong: #005ccc;
  --green: #2f9e47;
  --orange: #e98a0c;
  --red: #c4302b;

  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #eef3fa;
  --text: #0d1a33;
  --muted: #56657e;
  --border: #dae2ee;
  --focus: #0072f3;

  --blue-tint: #e5f0ff;
  --green-tint: #e4f5e8;
  --orange-tint: #fff1dc;
  --red-tint: #fde8e7;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(2, 47, 112, .06), 0 4px 16px rgba(2, 47, 112, .06);
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --navy: #9cc2ff;
    --blue: #4d9bff;
    --blue-strong: #79b4ff;
    --green: #5cc977;
    --orange: #f7a93c;
    --red: #ff7b72;
    --bg: #0a1322;
    --surface: #111d31;
    --surface-2: #17263f;
    --text: #e8eef8;
    --muted: #9aabc6;
    --border: #23365a;
    --blue-tint: #13294b;
    --green-tint: #143223;
    --orange-tint: #3a2a10;
    --red-tint: #3d1a1a;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; color: var(--text); }
h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.muted { font-size: .92rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
}
.topbar-inner { max-width: 600px; margin: 0 auto; display: flex; align-items: center; gap: 12px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); flex: 1; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand-text { min-width: 0; }
.brand-team { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.brand-sub { font-size: .78rem; color: var(--muted); display: block; }

main.page {
  max-width: 600px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
main.page.no-tabs { padding-bottom: 40px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar ul { list-style: none; margin: 0 auto; padding: 0; max-width: 600px; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabbar a:hover { text-decoration: none; color: var(--text); }
.tabbar a[aria-current="page"] { color: var(--blue); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.4; }
.tabbar svg { width: 24px; height: 24px; }

/* ---------- Building blocks ---------- */
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card-tight { padding: 0; overflow: hidden; }
.card h2 { margin-bottom: 4px; }
.section-title { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 0 8px; }

.hero {
  background: linear-gradient(135deg, var(--navy), #0a4fb0);
  color: #fff; border: 0; border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(135deg, #0d2c5c, #123f86); } }
.hero h2, .hero h1 { color: #fff; }
.hero .label { font-size: .8rem; opacity: .85; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.hero .big { font-size: 1.6rem; font-weight: 800; margin: 2px 0 10px; }
.hero .faces { display: flex; flex-wrap: wrap; gap: 6px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.35rem; font-weight: 800; margin-top: 2px; }
.stat .v.pending { color: var(--muted); font-size: 1rem; font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 60px; color: var(--text); }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item .chev { color: var(--muted); }
.list-title { font-weight: 650; }
.list-sub { font-size: .86rem; color: var(--muted); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--blue-tint); color: var(--navy); font-weight: 750; font-size: .9rem;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.4rem; }
.avatar.sm { width: 30px; height: 30px; font-size: .72rem; }
.hero .avatar { background: rgba(255, 255, 255, .18); color: #fff; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.blue { background: var(--blue-tint); color: var(--blue-strong); }
.pill.green { background: var(--green-tint); color: var(--green); }
.pill.orange { background: var(--orange-tint); color: var(--orange); }
.pill.red { background: var(--red-tint); color: var(--red); }
.hero .pill { background: rgba(255, 255, 255, .18); color: #fff; }

/* ---------- Forms ---------- */
label, .label { display: block; font-weight: 650; font-size: .92rem; margin-bottom: 6px; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.field + .field { margin-top: 14px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date],
input[type=time], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-tint); }
.is-invalid { border-color: var(--red) !important; }
.error { color: var(--red); font-size: .87rem; margin-top: 4px; font-weight: 600; }
.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
.two-col .field + .field { margin-top: 0; }
input[type=file] { max-width: 100%; font-size: .9rem; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; margin: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--blue); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: var(--radius-sm); border: 1.5px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; text-align: center;
  background: var(--blue); color: #fff;
}
.btn:hover { background: var(--blue-strong); text-decoration: none; }
@media (prefers-color-scheme: dark) { .btn { color: #071426; } }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--blue); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--border); }
.btn.danger:hover { background: var(--red-tint); }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > form { display: contents; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; font-weight: 600; min-height: 44px; }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius-sm); padding: 12px 14px; font-weight: 600; font-size: .95rem; }
.alert.ok { background: var(--green-tint); color: var(--green); }
.alert.err { background: var(--red-tint); color: var(--red); }
.alert.info { background: var(--blue-tint); color: var(--blue-strong); }
.alert.warn { background: var(--orange-tint); color: var(--orange); }
#net-banner { display: none; position: sticky; top: 0; z-index: 40; text-align: center; padding: 6px 12px; font-size: .85rem; font-weight: 700; background: var(--orange-tint); color: var(--orange); }
body.offline #net-banner { display: block; }

.empty { text-align: center; padding: 28px 16px; }
.empty .icon { width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; background: var(--blue-tint); color: var(--blue); }
.empty .icon svg { width: 26px; height: 26px; }

/* ---------- Week grid ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day { border-top: 1px solid var(--border); padding: 12px 16px; }
.day:first-child { border-top: 0; }
.day.today { background: var(--blue-tint); }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.day-name { font-weight: 750; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 600; }
.chip .dot { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .65rem; font-weight: 800; background: var(--surface); color: var(--muted); }
.chip.drive .dot { background: var(--blue); color: #fff; }
.chip.ride .dot { background: var(--green-tint); color: var(--green); }
.chip.away { opacity: .55; text-decoration: line-through; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }

/* ---------- Availability toggles ---------- */
.avail { width: 100%; border-collapse: collapse; }
.avail th, .avail td { padding: 10px 8px; text-align: center; border-top: 1px solid var(--border); }
.avail th:first-child, .avail td:first-child { text-align: left; padding-left: 16px; }
.avail thead th { border-top: 0; font-size: .8rem; color: var(--muted); font-weight: 700; }
.toggle { position: relative; display: inline-flex; width: 52px; height: 32px; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle span { flex: 1; border-radius: 999px; background: var(--border); transition: background .15s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + span { background: var(--blue); }
.toggle.green input:checked + span { background: var(--green); }
.toggle input:checked + span::after { transform: translateX(20px); }
.toggle input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.toggle input:disabled + span { opacity: .4; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 420px; margin: 0 auto; }
.auth-logo { width: 200px; margin: 0 auto 20px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; letter-spacing: .04em; word-break: break-all; }
.codebox { background: var(--surface-2); border: 1.5px dashed var(--border); border-radius: var(--radius-sm); padding: 12px; }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data td, table.data th { padding: 10px 12px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-top: 0; }

details.disclosure summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; color: var(--blue); }
.install-hint { display: none; }
body.show-install-hint .install-hint { display: block; }

@media (min-width: 640px) {
  main.page { padding-top: 24px; }
  h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (prefers-color-scheme: dark) { .auth-logo { background: #fff; border-radius: 18px; padding: 14px; } }
/* utilities (no inline styles: CSP forbids them) */
.mb { margin-bottom: 16px; } .mt { margin-top: 16px; } .mt-sm { margin-top: 8px; } .mt-lg { margin-top: 28px; }
.center { text-align: center; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.p { padding: 16px; } .px { padding-left: 16px; padding-right: 16px; } .pb { padding-bottom: 16px; }
.fw { font-weight: 700; } .small-text { font-size: .86rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* ---------- Phase 2/3 components ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg.five { grid-template-columns: repeat(5, 1fr); }
.seg label { margin: 0; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 9px; font-size: .78rem; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.15; padding: 2px; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg input[value=driver]:checked + span { background: var(--blue); color: #fff; }
.seg input[value=passenger]:checked + span { background: var(--green); color: #fff; }
.seg input[value=absent]:checked + span { background: var(--red-tint); color: var(--red); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.seg input:disabled + span { opacity: .6; cursor: default; }
.person-row { padding: 12px 16px; border-top: 1px solid var(--border); }
.person-row:first-child { border-top: 0; }

.state { font-size: .72rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.state.suggested { background: var(--surface-2); color: var(--muted); }
.state.volunteered { background: var(--blue-tint); color: var(--blue-strong); }
.state.confirmed { background: var(--blue); color: #fff; }
.state.completed { background: var(--green-tint); color: var(--green); }
.state.uncovered { background: var(--red-tint); color: var(--red); }
.state.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
@media (prefers-color-scheme: dark) { .state.confirmed { color: #071426; } }

.driver-line { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.driver-line .who { font-weight: 750; }
.reason { font-size: .82rem; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.actions > form { display: contents; }

.bal { display: grid; grid-template-columns: 90px 1fr 64px; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); }
.bal:first-child { border-top: 0; }
.bal .track { position: relative; height: 10px; background: var(--surface-2); border-radius: 999px; }
.bal .track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--border); }
.bal .fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.bal .fill.pos { left: 50%; background: var(--green); }
.bal .fill.neg { right: 50%; background: var(--orange); }
.bal .num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.pos-text { color: var(--green); } .neg-text { color: var(--red); }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.big-money { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tabs a { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 650; font-size: .9rem; color: var(--text); }
.tabs a[aria-current="page"] { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (prefers-color-scheme: dark) { .tabs a[aria-current="page"] { color: #071426; } }
.split-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: center; padding: 6px 0; }
.hidden { display: none !important; }
.table-wrap { overflow-x: auto; }
.person-row legend { width: 100%; }

/* bar widths without inline styles (CSP) */
.bal .fill.w-0 { width: 0%; }
.bal .fill.w-1 { width: 1%; }
.bal .fill.w-2 { width: 2%; }
.bal .fill.w-3 { width: 3%; }
.bal .fill.w-4 { width: 4%; }
.bal .fill.w-5 { width: 5%; }
.bal .fill.w-6 { width: 6%; }
.bal .fill.w-7 { width: 7%; }
.bal .fill.w-8 { width: 8%; }
.bal .fill.w-9 { width: 9%; }
.bal .fill.w-10 { width: 10%; }
.bal .fill.w-11 { width: 11%; }
.bal .fill.w-12 { width: 12%; }
.bal .fill.w-13 { width: 13%; }
.bal .fill.w-14 { width: 14%; }
.bal .fill.w-15 { width: 15%; }
.bal .fill.w-16 { width: 16%; }
.bal .fill.w-17 { width: 17%; }
.bal .fill.w-18 { width: 18%; }
.bal .fill.w-19 { width: 19%; }
.bal .fill.w-20 { width: 20%; }
.bal .fill.w-21 { width: 21%; }
.bal .fill.w-22 { width: 22%; }
.bal .fill.w-23 { width: 23%; }
.bal .fill.w-24 { width: 24%; }
.bal .fill.w-25 { width: 25%; }
.bal .fill.w-26 { width: 26%; }
.bal .fill.w-27 { width: 27%; }
.bal .fill.w-28 { width: 28%; }
.bal .fill.w-29 { width: 29%; }
.bal .fill.w-30 { width: 30%; }
.bal .fill.w-31 { width: 31%; }
.bal .fill.w-32 { width: 32%; }
.bal .fill.w-33 { width: 33%; }
.bal .fill.w-34 { width: 34%; }
.bal .fill.w-35 { width: 35%; }
.bal .fill.w-36 { width: 36%; }
.bal .fill.w-37 { width: 37%; }
.bal .fill.w-38 { width: 38%; }
.bal .fill.w-39 { width: 39%; }
.bal .fill.w-40 { width: 40%; }
.bal .fill.w-41 { width: 41%; }
.bal .fill.w-42 { width: 42%; }
.bal .fill.w-43 { width: 43%; }
.bal .fill.w-44 { width: 44%; }
.bal .fill.w-45 { width: 45%; }
.bal .fill.w-46 { width: 46%; }
.bal .fill.w-47 { width: 47%; }
.bal .fill.w-48 { width: 48%; }
.bal .fill.w-49 { width: 49%; }
.bal .fill.w-50 { width: 50%; }
.w-amount { width: 90px !important; min-height: 40px !important; }
