/* Bus Ministry — iPad app. Design system ported from the Claude Design
   prototype (styles.css), adapted for a full-viewport production app:
   the device-bezel ".stage/.ipad" mockup chrome is dropped in favor of
   ".app" filling the viewport. Tokens, palettes, and components match 1:1. */

:root {
  --bg: #f7f4ec;
  --surface: #ffffff;
  --surface-2: #fbf8f0;
  --ink: #1a1715;
  --ink-2: #4a4640;
  --muted: #8a8780;
  --line: rgba(26, 23, 21, 0.08);
  --line-strong: rgba(26, 23, 21, 0.14);
  --accent: #2f5d3a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 93, 58, 0.1);
  --gold: #c89c4a;
  --yes: #2f7a4a;        --yes-bg: rgba(47, 122, 74, 0.1);
  --maybe: #b07a18;      --maybe-bg: rgba(176, 122, 24, 0.12);
  --no: #b03a2e;         --no-bg: rgba(176, 58, 46, 0.1);
  --unknown: #7a7670;    --unknown-bg: rgba(122, 118, 112, 0.12);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 0 rgba(255,255,255,0.6) inset;
  --shadow-md: 0 4px 18px rgba(0,0,0,0.06), 0 1px 0 rgba(255,255,255,0.6) inset;

  --font-sans: "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", "Inter Tight", Georgia, serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;

  --pad: 16px; --pad-lg: 22px; --card-pad: 18px; --row-pad: 14px; --gap: 14px;
}

[data-density="compact"] {
  --pad: 12px; --pad-lg: 16px; --card-pad: 14px; --row-pad: 10px; --gap: 10px;
}

/* Palettes (default = navy, set on <html data-palette> in ipad.html) */
[data-palette="sage"] {
  --bg:#f3efe4; --surface:#fbf8f0; --surface-2:#efe9d9; --ink:#1c1f1a; --ink-2:#3a3f37;
  --muted:#847f72; --line:rgba(28,31,26,.08); --line-strong:rgba(28,31,26,.16);
  --accent:#2f5d3a; --accent-soft:rgba(47,93,58,.10); --gold:#b8862c;
}
[data-palette="navy"] {
  --bg:#efeadd; --surface:#fbf6e9; --surface-2:#e7e1d0; --ink:#131822; --ink-2:#2f3645;
  --muted:#7a7c84; --line:rgba(19,24,34,.08); --line-strong:rgba(19,24,34,.16);
  --accent:#1f3a5f; --accent-soft:rgba(31,58,95,.10); --gold:#d9a23a;
}
[data-palette="minimal"] {
  --bg:#f7f5f0; --surface:#ffffff; --surface-2:#f0ece3; --ink:#1a1715; --ink-2:#3a3631;
  --muted:#8a857c; --line:rgba(26,23,21,.07); --line-strong:rgba(26,23,21,.14);
  --accent:#c25a3a; --accent-soft:rgba(194,90,58,.10); --gold:#6b4f3b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
  letter-spacing: -0.005em;
  overscroll-behavior: none;
}

/* App shell — fills the viewport (replaces the prototype's device bezel) */
.app { position: fixed; inset: 0; display: flex; background: var(--bg); }
.app.top { flex-direction: column; }

/* Sidebar */
.sidebar {
  width: 224px; flex: 0 0 224px;
  border-right: 1px solid var(--line); background: var(--surface-2);
  padding: 14px 12px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 14px; }
.sidebar .brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 16px; box-shadow: var(--shadow-sm);
}
.sidebar .brand .title { font-family: var(--font-display); font-size: 17px; font-weight: 600; line-height: 1.1; color: var(--ink); }
.sidebar .brand .sub { font-size: 10.5px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

.nav-section-label { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--ink-2); font-size: 13.5px; font-weight: 500; user-select: none; cursor: pointer;
  transition: background .12s ease, color .12s ease; border: 0; background: transparent; width: 100%; text-align: left;
}
.nav-item .ico { width: 22px; height: 22px; display: grid; place-items: center; color: var(--muted); }
.nav-item:hover { background: rgba(0,0,0,.04); }
.nav-item.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.nav-item.active .ico { color: var(--accent); }
.nav-item .badge { margin-left: auto; font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.sidebar .me .av { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg,#e8c89c,#b8862c); color: #29261b; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.sidebar .me .name { font-size: 13px; font-weight: 600; line-height: 1.1; }
.sidebar .me .role { font-size: 11px; color: var(--muted); }

/* Top bar (alternative nav) */
.topbar { height: 56px; flex: 0 0 56px; border-bottom: 1px solid var(--line); background: var(--surface-2); display: flex; align-items: center; gap: 6px; padding: 0 16px; }
.topbar .brand-row { display: flex; align-items: center; gap: 10px; margin-right: 14px; }
.topbar .brand-row .mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 14px; }
.topbar .brand-row .title { font-family: var(--font-display); font-weight: 600; font-size: 15px; white-space: nowrap; }
.topbar .nav-item { width: auto; padding: 7px 11px; font-size: 13px; }
.topbar .nav-item .ico { display: none; }
.topbar .nav-item.active { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.topbar .nav-item .badge { display: none; }
.topbar .prefs { padding: 0; flex-wrap: nowrap; }

/* Preference cluster (palette / density / layout) — used in both navs */
.prefs { display: flex; gap: 4px; }
.prefs button { appearance: none; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 7px; padding: 5px 8px; font: inherit; font-size: 10.5px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.prefs button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.sidebar .prefs { flex-wrap: wrap; padding: 8px 4px 2px; }
.sidebar .prefs button { flex: 1 1 28%; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: var(--pad-lg) var(--pad-lg) 14px; gap: 18px;
  border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: nowrap;
}
.header > div:first-child { min-width: 0; flex: 0 1 auto; }
.header .eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header h1 { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.05; white-space: nowrap; }
.header .header-actions { display: flex; gap: 8px; align-items: center; }
.body { flex: 1; min-height: 0; overflow: auto; padding: var(--pad-lg); -webkit-overflow-scrolling: touch; }

/* Buttons */
.btn {
  appearance: none; font: inherit; font-weight: 500; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 9px;
  color: var(--ink); cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface);
  transition: background .12s ease, border-color .12s ease; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 1px 2px rgba(0,0,0,.08); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: rgba(0,0,0,.04); }
.btn .ico { width: 16px; height: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--unknown-bg); color: var(--unknown); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.yes { background: var(--yes-bg); color: var(--yes); }
.pill.maybe { background: var(--maybe-bg); color: var(--maybe); }
.pill.no { background: var(--no-bg); color: var(--no); }
.pill.unknown { background: var(--unknown-bg); color: var(--unknown); }

/* Y/M/N segmented control */
.status-seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line); }
.status-seg button { appearance: none; border: 0; background: transparent; font: inherit; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 7px; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.status-seg button:hover { color: var(--ink); }
.status-seg button.active[data-v="yes"] { background: var(--yes); color: #fff; }
.status-seg button.active[data-v="maybe"] { background: var(--maybe); color: #fff; }
.status-seg button.active[data-v="no"] { background: var(--no); color: #fff; }

/* Family row */
.family-row {
  display: grid; grid-template-columns: 36px minmax(0,1fr) auto auto; align-items: center; gap: 14px;
  padding: var(--row-pad) 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: relative; user-select: none; transition: background .14s ease;
}
.family-row:last-child { border-bottom: none; }
.family-row:hover { background: var(--surface-2); }
.family-row.selected { background: var(--accent-soft); }
.family-row.selected::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent); }
.family-row .ord { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: 13px; color: var(--ink-2); border: 1px solid var(--line); }
.family-row .who { min-width: 0; }
.family-row .who .name { font-weight: 600; font-size: 14.5px; line-height: 1.15; }
.family-row .who .meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.family-row .who .meta .dot-sep { opacity: .5; }
.family-row .who .meta .addr { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kids { font-size: 12px; color: var(--ink-2); display: inline-flex; gap: 4px; flex-shrink: 0; flex-wrap: wrap; }
.kid-tag { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); font-size: 11px; white-space: nowrap; }
.kid-tag .kdot { width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; }

/* Progress ring */
.ring-wrap { position: relative; display: inline-grid; place-items: center; }
.ring-wrap .ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1; }
.ring-wrap .ring-label .pct { font-family: var(--font-display); font-weight: 600; font-size: 22px; }
.ring-wrap .ring-label .sub { font-size: 9px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-top: 4px; font-weight: 600; }

/* Stats */
.stats-strip { display: grid; grid-template-columns: repeat(4,1fr); gap: var(--gap); }
.stat { padding: var(--card-pad); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-sm); }
.stat .label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--font-display); font-size: 28px; font-weight: 600; line-height: 1; }
.stat .delta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Two-col + detail */
.two-col { display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: var(--gap); align-items: start; }
.detail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--card-pad); box-shadow: var(--shadow-sm); position: sticky; top: 0; display: flex; flex-direction: column; gap: 14px; }
.detail h3 { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.row-kv { display: flex; gap: 10px; align-items: baseline; font-size: 12.5px; }
.row-kv .k { color: var(--muted); width: 64px; flex: 0 0 64px; font-size: 11.5px; letter-spacing: .02em; }
.row-kv .v { color: var(--ink); min-width: 0; word-break: break-word; }
.eyebrow-sm { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* Filter chips + search */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 999px; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-strong); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer; }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.search { display: flex; align-items: center; gap: 8px; padding: 7px 11px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; width: 220px; min-width: 0; }
.search input { appearance: none; background: transparent; border: 0; outline: none; font: inherit; font-size: 13px; color: var(--ink); width: 100%; }
.search input::placeholder { color: var(--muted); }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yes); box-shadow: 0 0 0 3px var(--yes-bg); }
.sync.err .dot { background: var(--no); box-shadow: 0 0 0 3px var(--no-bg); }

/* Section card */
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.section > .section-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.section > .section-h h3 { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.section > .section-h .sub { font-size: 12px; color: var(--muted); }
.list-head { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--surface-2); }

/* Captain route row */
.route-row { display: grid; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); transition: background .14s, opacity .18s; }
.route-row:last-child { border-bottom: none; }
.route-row.boarded { opacity: .55; }
.route-row.boarded .who .name { text-decoration: line-through; }
.route-row .pickup { font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); }
.route-row .who .name { font-weight: 600; font-size: 14px; }
.route-row .who .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.board-btn { appearance: none; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; padding: 8px 14px; border-radius: 9px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line-strong); display: inline-flex; align-items: center; gap: 6px; }
.board-btn:hover { background: var(--surface); }
.route-row.boarded .board-btn { background: var(--yes); color: #fff; border-color: transparent; }
.kid-chip { appearance: none; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 5px 12px 5px 8px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: background .12s, color .12s; }
.kid-chip .kbox { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-strong); display: inline-grid; place-items: center; }
.kid-chip.on { background: var(--yes); color: #fff; border-color: transparent; }
.kid-chip.on .kbox { background: rgba(255,255,255,.22); border: 0; }

/* Report bars */
.bars { display: flex; align-items: flex-end; gap: 22px; height: 200px; padding-top: 10px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.bars .bar { background: var(--accent-soft); border-radius: 8px 8px 4px 4px; position: relative; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.bars .bar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); border-radius: 8px 8px 4px 4px; }
.bars .bar-col .lbl { text-align: center; font-size: 11px; color: var(--muted); }
.bars .bar-col .val { text-align: center; font-family: var(--font-display); font-size: 14px; font-weight: 600; }

/* Utility */
.muted { color: var(--muted); }
.row-flex { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.note-box { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; padding: 10px 12px; background: var(--surface-2); border-radius: 9px; border-left: 2px solid var(--gold); }
.loading, .empty { text-align: center; padding: 50px 20px; color: var(--muted); font-size: 14px; }

/* Skeleton loaders (shimmer) */
.sk { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line-strong) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk-shimmer 1.4s ease infinite; border-radius: 6px; }
@keyframes sk-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.placeholder { display: grid; place-items: center; gap: 14px; padding: 60px 20px; text-align: center; color: var(--muted); }

/* Modal / overlay (driver sheet, add family) */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20,18,16,.45); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); color: var(--ink); border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.35); display: flex; flex-direction: column; overflow: hidden; max-height: 90vh; }
.modal .m-head { padding: 14px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.modal .m-body { padding: 20px 22px; overflow: auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 11px; color: var(--muted); font-weight: 600; }
.field input { appearance: none; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 9px 11px; font: inherit; font-size: 14px; color: var(--ink); outline: none; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 100; animation: toast-in .18s ease; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Driver sheet — paper preview that prints clean */
.sheet { width: 760px; max-width: 92vw; background: #fff; color: #111; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet thead tr { border-bottom: 1.5px solid #111; }
.sheet th { text-align: left; padding: 8px 6px; }
.sheet tbody tr { border-bottom: 1px dashed #ccc; vertical-align: top; }
.sheet td { padding: 10px 6px; }
.sheet .box { display: inline-block; width: 24px; height: 24px; border: 1.5px solid #111; border-radius: 4px; }

@media print {
  body { background: #fff; }
  .app, .toast, .overlay > .modal > .m-head { display: none !important; }
  .overlay { position: static; inset: auto; background: none; backdrop-filter: none; padding: 0; display: block; }
  .modal { box-shadow: none; max-height: none; border-radius: 0; }
  .sheet { width: 100%; max-width: 100%; }
}

/* Narrow / portrait fallback */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .stats-strip { grid-template-columns: repeat(2,1fr); }
}
