:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --text: #221F26;
  --muted: #6E6A75;
  --border: #E9E3DA;
  /* Damson-ink brand primary, deliberately decoupled from the family accent
     palette (src/colors.js) - they used to be the same hex, which meant a
     brand button and a family badge were visually identical. */
  --brand: #423E7A;
  --brand-ink: #ffffff;
  --carpool-accent: var(--brand); /* overridden inline (JS) per active carpool */
  --danger: #ef476f;
  --cover-bg: #FFF4E5;
  --cover-text: #8A5200;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  /* Both elevation tiers are tinted from --text rather than neutral black. */
  --shadow: 0 2px 12px rgba(34, 31, 38, 0.08);
  --shadow-raised: 0 -8px 30px rgba(34, 31, 38, 0.22);
  --tap-min: 44px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Karla", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

h1, h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }

.safe-top { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- Icons ---------- */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
}
.icon-sm { width: 16px; height: 16px; }
.icon-brand { width: 40px; height: 40px; color: var(--brand); }
.nav-icon { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap-min);
  border-radius: var(--radius-md);
  border: none;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
  padding: 12px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-full { width: 100%; display: flex; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:active { opacity: 0.85; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: 14px; border-radius: var(--radius-sm); }

.muted { color: var(--muted); }
.error-text { color: var(--danger); font-weight: 600; }

.app-footer { text-align: center; padding: 12px 0 4px; }
.app-footer p { margin: 0; font-size: 12px; color: var(--muted); }
.app-footer .app-version { font-size: 11px; margin-top: 2px; }

/* ---------- Login / Whoami ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card, .whoami-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 8px; }
.brand h1 { font-size: 24px; }
.whoami-card h1 { margin-bottom: 4px; font-size: 22px; }
#login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.text-input, #passcode-input {
  min-height: var(--tap-min);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  padding: 10px 14px;
  font-size: 16px;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
}
.color-input { width: 100%; height: 44px; border-radius: var(--radius-md); border: 1.5px solid var(--border); padding: 4px; }

/* ---------- Onboarding (welcome / start-crew / join / confirm) ----------
   Cream full-canvas, no white box. A single "route" line draws itself
   behind the content on load. Content leads at top, the primary action
   pins to the thumb zone at the bottom. */
.onboard { position: relative; overflow: hidden; align-items: stretch; }
.onboard-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  min-height: min(660px, 86dvh);
  display: flex;
  flex-direction: column;
  text-align: start;
}
.onboard-top { margin-top: 7dvh; animation: onboard-rise 560ms cubic-bezier(.2,.7,.2,1) both; }
.onboard-mark {
  width: 52px; height: 52px; border-radius: 15px;
  background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 30%, transparent);
}
.onboard-mark .icon { width: 28px; height: 28px; }
.onboard-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 8vw, 34px);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--text);
  margin: 20px 0 0;
}
.onboard-sub {
  font-size: 16px;
  line-height: 1.5;
  color: var(--muted);
  margin: 10px 0 0;
  max-width: 32ch;
}
.onboard-field { margin-top: 30px; animation: onboard-rise 560ms 120ms cubic-bezier(.2,.7,.2,1) both; }
.onboard-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding: 12px 2px;
  font-family: var(--font-body);
  font-size: 22px;
  color: var(--text);
  transition: border-color 0.15s ease;
}
.onboard-input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.onboard-input:focus { outline: none; border-bottom-color: var(--brand); }
.onboard-icons { margin-top: 22px; gap: 10px; }
.onboard-icons .icon-picker-btn {
  width: 50px; height: 50px; border-radius: 50%;
  border-width: 1.5px;
}
.onboard-icons .icon-picker-btn.selected {
  background: var(--brand); border-color: var(--brand); color: var(--brand-ink);
  transform: scale(1.06);
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}
.onboard-actions {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: onboard-rise 560ms 220ms cubic-bezier(.2,.7,.2,1) both;
}
.onboard-actions .btn { width: 100%; }
.btn-lg { min-height: 54px; font-size: 16px; border-radius: 16px; }
.onboard-textlink {
  background: none; border: none;
  color: var(--muted); font-family: var(--font-body); font-weight: 600; font-size: 14px;
  min-height: 44px; padding: 0 12px; cursor: pointer;
}
.onboard-textlink:active { color: var(--brand); }
.onboard .crew-preview { margin: 18px 0 0; }

/* The self-drawing route motif, shared behind all onboarding screens. */
.onboard-route { display: none; position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
body.onboarding .onboard-route { display: block; }
.onboard-route-line {
  fill: none; stroke: var(--brand); stroke-width: 3; stroke-linecap: round;
  opacity: 0.10;
  stroke-dasharray: 2000; stroke-dashoffset: 2000;
  animation: route-draw 1200ms 120ms ease-out forwards;
}
.onboard-route-stop {
  fill: var(--brand); opacity: 0;
  transform-box: fill-box; transform-origin: center;
  animation: route-stop 420ms ease-out forwards;
  animation-delay: calc(var(--d) * 1100ms + 200ms);
}
@keyframes route-draw { to { stroke-dashoffset: 0; } }
@keyframes route-stop { from { opacity: 0; transform: scale(0.3); } to { opacity: 0.14; transform: scale(1); } }
@keyframes onboard-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .onboard-route-line { animation: none; stroke-dashoffset: 0; }
  .onboard-route-stop { animation: none; opacity: 0.14; }
  .onboard-top, .onboard-field, .onboard-actions { animation: none; }
}

/* ---------- First-run setup checklist (admin, top of Week tab) ---------- */
.setup-checklist {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 14px 14px 8px;
  margin-bottom: 4px;
}
.setup-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.setup-tour-link { display: block; width: 100%; margin-top: 4px; padding: 8px; background: none; border: none;
  font-family: var(--font-body); font-weight: 600; font-size: 13px; color: var(--brand); cursor: pointer; text-align: center; }
.setup-tour-link:active { opacity: .7; }
.setup-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: var(--text); }
.setup-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.setup-dismiss {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  border: none; background: var(--bg); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.setup-dismiss .icon { width: 15px; height: 15px; }
.setup-step {
  width: 100%; text-align: start;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 6px; margin-top: 6px;
  background: none; border: none; border-top: 1px solid var(--border);
  min-height: var(--tap-min);
}
.setup-step:first-of-type { border-top: none; }
.setup-check {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.setup-step.done .setup-check { background: var(--brand); border-color: var(--brand); }
.setup-check .icon { width: 14px; height: 14px; }
.setup-step-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.setup-step-title { font-size: 14.5px; font-weight: 700; color: var(--text); }
.setup-step.done .setup-step-title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.setup-step-desc { font-size: 12.5px; color: var(--muted); }
.setup-step.primary:not(.done) .setup-step-title { color: var(--brand); }
.setup-optional { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--bg); padding: 1px 6px; border-radius: 5px; }
.setup-step-chevron { color: var(--muted); flex-shrink: 0; }

/* ---------- Group chat row (Crew tab) ---------- */
.group-chat-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px; text-decoration: none; color: inherit;
}
.group-chat-icon {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%;
  background: var(--teal-soft); color: var(--teal);
  display: flex; align-items: center; justify-content: center;
}
.group-chat-icon .icon { width: 19px; height: 19px; }
.group-chat-text { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.group-chat-title { font-weight: 700; font-size: 14.5px; color: var(--text); }
.group-chat-sub { font-size: 12px; color: var(--muted); }
.group-chat-row .icon-sm { color: var(--muted); }

/* ---------- Slot action sheet (tap your own grid slot) ---------- */
.slot-action-hint { font-size: 12.5px; color: var(--muted); text-align: center; margin: 2px 0 0; }

.family-pick-list { display: flex; flex-direction: column; gap: 10px; margin: 20px 0; }
.family-pick-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap-min);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 16px;
  font-weight: 600;
  text-align: start;
}
.family-pick-btn:active { background: var(--bg); }

/* ---------- Your Carpools screen ---------- */
.carpools-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.carpools-card h1 { font-size: 22px; margin-bottom: 4px; }
.carpools-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.carpool-card {
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.carpool-card-active { border-color: var(--brand); border-width: 2px; }
.carpool-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 16px;
  width: 100%;
  text-align: start;
  background: none;
  border: none;
}
.carpool-card-header:active { background: var(--bg); }
.carpool-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.carpool-card-icon .icon { width: 20px; height: 20px; }
.carpool-card-info { flex: 1; min-width: 0; }
.carpool-card-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.carpool-card-next { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.carpool-card-fields { padding: 2px 16px 14px; border-top: 1px solid var(--border); text-align: start; }
.carpools-join-row { display: flex; gap: 8px; margin-bottom: 10px; }
.carpools-join-row .text-input { flex: 1; }
#screen-carpools #carpools-logout-btn { margin-top: 16px; }

/* ---------- Icon picker ---------- */
.icon-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.icon-picker-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.icon-picker-btn.selected { border-color: var(--brand); color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, var(--surface)); }

.field-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 10px;
}
.field-checkbox-row input { width: 18px; height: 18px; }

/* ---------- Avatars ---------- */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-xs { width: 26px; height: 26px; font-size: 10px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
/* Everywhere a family color is decorative rather than load-bearing (roster
   cards, next-up riders, family pickers) uses a lighter ring treatment;
   solid fills stay reserved for the schedule grid and driver strip, where
   the color IS the information. Border/text color is set inline per family. */
.avatar-ring {
  background: var(--surface);
  border-width: 2.5px;
  border-style: solid;
  font-weight: 800;
}

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  /* Chrome-only tint from the active carpool's accent color - never used
     inside the grid/avatars, where family colors are the sole signal. */
  background: color-mix(in srgb, var(--carpool-accent, var(--brand)) 7%, var(--surface));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  gap: 8px;
}
.carpool-chip {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--carpool-accent, var(--brand));
  background: none;
  border: none;
  padding: 4px 2px;
  cursor: default;
  max-width: 62%;
  min-height: 36px;
}
.carpool-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.carpool-chip .icon { flex-shrink: 0; }
.carpool-chip .icon-sm { opacity: 0.7; }
.carpool-chip-interactive { cursor: pointer; }
.whoami-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  min-height: 36px;
  color: var(--text);
  cursor: default;
}
.whoami-chip-interactive { cursor: pointer; border-color: var(--brand); }
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.week-nav-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.week-label-wrap { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 8px; min-width: 0; }
.week-label { font-family: var(--font-display); font-weight: 600; font-size: 15px; text-align: center; white-space: nowrap; }
.week-today-btn {
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  background: none;
  border: none;
  padding: 0;
  white-space: nowrap;
  text-decoration: underline;
}
.week-copy-btn {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  border: none;
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
  min-height: 32px;
}
.grid-view-toggle {
  display: flex;
  padding: 4px 10px 0;
}
.grid-view-btn {
  flex: 1;
  text-align: center;
  padding: 4px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-right-width: 0;
}
.grid-view-btn:first-child { border-radius: 8px 0 0 8px; }
.grid-view-btn:last-child { border-radius: 0 8px 8px 0; border-right-width: 1px; }
.grid-view-btn.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.main {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 70px;
}

.tab-panel { display: flex; flex-direction: column; gap: 6px; }

.section-title { font-size: 17px; margin: 6px 2px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  min-height: var(--tap-min);
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  position: relative;
}
.nav-btn.active { color: var(--brand); }
.badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 26px);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- Cards / list ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; gap: 10px; }
.empty-state { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- Week sub-view toggle (Next Up | Full Week) ----------
   A top segmented control, not a 5th bottom-nav tab or a swipe gesture -
   swipe conflicts with Android/iOS edge-back gestures, and this is one
   nav-level concept ("my week"), not two peer destinations. Bigger and
   more prominent than the in-card .grid-view-toggle (Mon-Fri/Sat-Sun)
   below, since this is the primary navigation for the whole tab. */
.weekview-toggle {
  display: flex;
  gap: 8px;
  padding: 2px 2px 4px;
}
.weekview-toggle-btn {
  flex: 1;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.weekview-toggle-btn.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.weekview-toggle-btn .badge { position: static; margin: 0; }

.weekview-panel { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Next up (default landing view) ---------- */
.next-up-full-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.next-up-full-empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.next-up-eyebrow { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); margin-bottom: 4px; }
.next-up-likely-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}
.next-up-divider { height: 1px; background: var(--border); margin: 6px 0; }
.next-up-leg-line {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.next-up-leg-line .direction-icons { color: var(--brand); margin-top: 2px; flex-shrink: 0; }
.next-up-leg-line .direction-icons .icon { width: 15px; height: 15px; }
.next-up-open { color: var(--muted); font-style: italic; }
.next-up-avatar-faded { opacity: 0.4; border-style: dashed; }

.next-up-detail-leg { margin-bottom: 2px; }
.next-up-detail-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 10px 0 4px; }
.next-up-detail-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; min-height: var(--tap-min); }
.next-up-detail-name { flex: 1; font-weight: 600; }
.next-up-detail-status { flex-shrink: 0; }
.next-up-detail-status-riding { color: var(--brand); }
.next-up-detail-status-skip { color: var(--muted); }

.plan-next-week-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  min-height: var(--tap-min);
}
.plan-next-week-link .icon { width: 14px; height: 14px; }

/* ---------- Optout panel ---------- */
/* Always expanded now - it lives inside the deliberately denser "Full
   Week" view, not collapsed on the main screen. */
.optout-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding-bottom: 14px;
}
.optout-panel-title {
  padding: 14px 16px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.optout-panel-title strong { color: var(--brand); }
.optout-grid {
  display: grid;
  gap: 6px;
  margin: 0 16px;
}
.optout-toggle-btn {
  min-height: var(--tap-min);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.optout-toggle-btn.needed {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  border-color: var(--brand);
  color: var(--brand);
}
.optout-help { font-size: 12px; color: var(--muted); margin: 10px 16px 0; }

/* ---------- Schedule grid ---------- */
.schedule-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.schedule-grid {
  display: grid;
  gap: 6px;
  padding: 8px;
}
/* Stays visible while scrolling through a tall grid (many rows) - sticks
   within .schedule-card's own box (its overflow:hidden clips the sticky
   range to "while this card is in view," which is exactly the wanted
   behavior, not a bug). Solid background so rows don't show through. */
.grid-corner { position: sticky; top: 0; z-index: 2; background: var(--surface); }
.grid-day-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  text-align: center;
  padding: 4px 0 8px;
  color: var(--text);
}
.grid-leg-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding-inline-end: 4px;
}
.direction-icons { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.direction-icons .icon { width: 14px; height: 14px; flex-shrink: 0; }
.grid-leg-text {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}
.grid-cell {
  position: relative;
  min-height: 56px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  text-align: center;
}
.grid-cell-filled {
  background: var(--cell-color, var(--brand));
  color: #fff;
  animation: cell-pop 0.18s ease-out;
}
@keyframes cell-pop {
  from { transform: scale(0.92); opacity: 0.6; }
  to { transform: scale(1); opacity: 1; }
}
.grid-cell-mine {
  box-shadow: 0 0 0 2.5px var(--surface), 0 0 0 4.5px var(--cell-color, var(--brand));
}
.grid-cell-filled[data-action] {
  cursor: pointer;
}
.grid-cell-filled[data-action]:active {
  filter: brightness(0.94);
}
.grid-cell-open {
  background: color-mix(in srgb, var(--brand) 4%, transparent);
  border: 1.5px dashed color-mix(in srgb, var(--brand) 30%, var(--border));
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  gap: 2px;
}
.grid-cell-open .icon { width: 14px; height: 14px; color: color-mix(in srgb, var(--brand) 55%, var(--muted)); }
.grid-cell-open:active {
  background: color-mix(in srgb, var(--brand) 10%, transparent);
}
.grid-cell-name {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.grid-cell-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.grid-cell-remove .icon { width: 12px; height: 12px; }
.grid-cell-note {
  font-size: 9px;
  font-weight: 700;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 1px 6px;
}
.grid-cell-cover {
  position: absolute;
  bottom: 3px;
  left: 3px;
  right: 3px;
  background: var(--cover-bg);
  color: var(--cover-text);
  border-radius: 999px;
  font-size: 8px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 4px;
  text-align: center;
}

/* ---------- Requests ---------- */
.request-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.request-top { display: flex; align-items: center; justify-content: space-between; }
.request-title { font-weight: 700; font-size: 15px; }
.request-sub { font-size: 13px; color: var(--muted); }
.request-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.request-card-new { border: 2px solid var(--brand); animation: request-card-pulse 1.6s ease-out 1; }
.request-nudge { font-size: 12px; font-weight: 600; color: var(--brand); margin: 0; }
@keyframes request-card-pulse {
  0% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 25%, transparent); }
  100% { box-shadow: var(--shadow); }
}

/* ---------- Stats ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-name { width: 84px; font-size: 13px; font-weight: 600; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: var(--border); border-radius: 999px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; min-width: 4px; }
.bar-count { width: 26px; text-align: end; font-size: 13px; font-weight: 700; }

/* ---------- Families ---------- */
.family-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap-min);
}
.family-card-info { flex: 1; min-width: 0; }
.family-card-name { font-weight: 700; font-size: 15px; }
.family-card-kid { font-size: 12px; color: var(--muted); }
.family-links { display: flex; gap: 10px; }
.family-links a { color: var(--muted); display: flex; }

/* ---------- Sheets (modals) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(34, 31, 38, 0.45); z-index: 40;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-raised);
}
.sheet:not(.hidden) { animation: sheet-in 0.22s cubic-bezier(0.25, 0.8, 0.4, 1); }
@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 4px auto 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.direction-preview { font-size: 12px; margin: 2px 0 0; }
.day-picker { display: flex; gap: 6px; }
.day-chip {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.day-chip.selected { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.link-row { display: flex; gap: 8px; align-items: center; }
.link-row .text-input { flex: 1; font-size: 13px; }

/* In-app tour overlay - full-screen host for the story iframe. */
.app-tour-overlay { position: fixed; inset: 0; z-index: 130; background: var(--bg); }
.app-tour-overlay iframe { border: 0; width: 100%; height: 100%; display: block; }

/* Welcome card - first open on a new device (once per family). A centered
   modal over a dim backdrop, warmer than the utility bottom-sheets. */
.welcome-overlay {
  position: fixed; inset: 0;
  background: rgba(34, 31, 38, 0.55);
  z-index: 110;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.welcome-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: 22px;
  padding: 28px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-raised);
  display: flex; flex-direction: column; gap: 10px;
  text-align: center;
  animation: sheet-in 0.24s cubic-bezier(0.25, 0.8, 0.4, 1);
}
.welcome-badge {
  width: 56px; height: 56px; margin: 0 auto 4px;
  border-radius: 50%;
  background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; justify-content: center;
}
.welcome-badge .icon { width: 28px; height: 28px; }
.welcome-body { font-size: 15px; line-height: 1.45; margin: 0; }
.welcome-keep { font-size: 12px; margin: 2px 0 8px; }
.welcome-card .field-label { text-align: start; }
#welcome-nickname-block { text-align: start; }
.admin-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  border-radius: 999px;
  padding: 2px 8px;
  margin-inline-start: 6px;
}
/* ---------- Settings sheet: header + overflow ---------- */
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-header h2 { margin: 0; }
.overflow-menu { position: relative; }
.overflow-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.overflow-btn:hover, .overflow-btn[aria-expanded="true"] { background: var(--bg); color: var(--text); }
.overflow-menu-list {
  position: absolute; top: 40px; right: 0; z-index: 5;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-raised);
  padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.overflow-menu-item {
  text-align: start; border: none; background: transparent;
  color: var(--text); font-size: 14px; font-weight: 600;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.overflow-menu-item:hover { background: var(--bg); }

/* ---------- Settings sheet: collapsible sections ---------- */
.settings-section {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}
.settings-section[open] { background: color-mix(in srgb, var(--brand) 4%, var(--surface)); }
.settings-section-summary {
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  padding: 13px 14px; cursor: pointer;
  user-select: none;
}
.settings-section-summary::-webkit-details-marker { display: none; }
.settings-section-title { font-size: 15px; font-weight: 700; color: var(--text); }
.settings-section-hint { font-size: 12px; color: var(--muted); margin-inline-start: auto; }
.settings-chevron { color: var(--muted); transition: transform 0.18s ease; flex-shrink: 0; }
.settings-section[open] > .settings-section-summary .settings-chevron,
.settings-subrow[open] > .settings-subrow-summary .settings-chevron { transform: rotate(90deg); }
.settings-section-body {
  display: flex; flex-direction: column; gap: 8px;
  padding: 2px 14px 14px;
}
.settings-section-body .field-label:first-child { margin-top: 0; }
.settings-microcopy { font-size: 12px; margin: 0; }

/* ---------- Settings sheet: Crew Plus sub-row ---------- */
.settings-subrow { border-top: 1px solid var(--border); margin-top: 4px; }
.settings-subrow-summary {
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 2px 4px; cursor: pointer; user-select: none;
  font-size: 14px; font-weight: 600; color: var(--text);
}
.settings-subrow-summary::-webkit-details-marker { display: none; }
.settings-subrow-summary .settings-chevron { margin-inline-start: auto; }
.settings-subrow-body { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 2px; }
.plus-pill {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  border-radius: 999px; padding: 2px 8px;
}

.photo-picker { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 6px; }
.photo-preview {
  width: 88px; height: 88px; border-radius: 50%; object-fit: cover;
  background: var(--bg); border: 1.5px solid var(--border);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 60;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast button { background: none; border: none; color: #9fc2ff; font-weight: 700; }

/* ---------- Banners ---------- */
.offline-banner, .wake-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px calc(8px + env(safe-area-inset-top));
  padding-top: calc(8px + env(safe-area-inset-top));
}
.offline-banner { background: #ffe8e8; color: #b3261e; }
.wake-banner { background: var(--cover-bg); color: var(--cover-text); }
.stale-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 101;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  background: #b3261e;
  color: #fff;
  padding: 10px 16px calc(10px + env(safe-area-inset-top));
  padding-top: calc(10px + env(safe-area-inset-top));
}
.stale-banner code { background: rgba(255,255,255,0.2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

@media (min-width: 640px) {
  .main { max-width: 560px; margin: 0 auto; width: 100%; }
  .topbar-row { max-width: 560px; margin: 0 auto; width: 100%; }
  .bottom-nav { max-width: 640px; margin: 0 auto; left: 0; right: 0; border-radius: 18px 18px 0 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .sheet { max-width: 560px; margin: 0 auto; }
}

/* ---------- Onboarding: crew preview, plan badge, upgrade prompt ---------- */
.crew-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 14px 0;
  font-size: 14px;
  text-align: start;
}
.crew-preview-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--brand);
  color: var(--brand-ink);
}
.crew-preview-icon .icon { width: 18px; height: 18px; }

.plan-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  border-radius: var(--radius-sm);
  padding: 3px 9px;
  margin: 4px 0 14px;
}

.upgrade-prompt {
  background: var(--cover-bg);
  color: var(--cover-text);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  margin: 10px 0;
}
.upgrade-prompt p { margin: 0; }

.invite-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
}
.invite-list-item-meta { color: var(--muted); font-size: 12px; }

.btn[disabled] { opacity: 0.6; pointer-events: none; }

/* ---------- PWA install (account sheet) ---------- */
.install-hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 0;
}
.install-hint strong { color: var(--text); }

/* Larger Android phones (412-430px wide) get more breathing room, not
   stretched content - the design already caps width at 640px+ via .main's
   max-width rule below; this fills the gap for phone-only widths. */
@media (min-width: 400px) and (max-width: 639px) {
  .main { padding-left: 20px; padding-right: 20px; }
}

@media (max-width: 360px) {
  .grid-day-header { font-size: 11px; }
  .grid-cell-name { font-size: 10px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #17151C;
    --surface: #211E29;
    --text: #F3F0FA;
    --muted: #9C96A8;
    --border: #322D3C;
    --shadow: 0 2px 16px rgba(0,0,0,0.4);
    --shadow-raised: 0 -8px 30px rgba(0,0,0,0.5);
    --cover-bg: #3A2C12;
    --cover-text: #FFCB7A;
  }
  .optout-toggle-btn { background: #2A2632; }
}

/* ==========================================================================
   i18n — per-language fonts, RTL (Hebrew), and the language picker
   ========================================================================== */

/* Fraunces + Karla cover Latin only. Give Hebrew a Hebrew stack and Russian a
   Cyrillic-capable one (Fraunces has no Cyrillic, so its display face falls
   back for ru). Overriding the CSS vars re-themes every component at once. */
:root[lang="he"] {
  --font-display: "Heebo", "Arial Hebrew", system-ui, sans-serif;
  --font-body: "Heebo", "Arial Hebrew", system-ui, sans-serif;
}
:root[lang="ru"] {
  --font-display: Georgia, "PT Serif", "Times New Roman", serif;
  --font-body: "Karla", system-ui, "Segoe UI", sans-serif;
}

/* Route/direction glyphs are a spatial sequence (origin → destination), like a
   time or phone number — keep them left-to-right even in an RTL UI. */
.direction-icons { direction: ltr; display: inline-flex; }

/* Keep LTR data readable inside RTL: phone numbers, invite links, and mixed
   Latin/Hebrew names shouldn't get reordered by the bidi algorithm. */
.grid-cell-name, .family-card-kid, .family-card-name,
.next-up-detail-name, .invite-list-item-meta, .bar-name { unicode-bidi: plaintext; }
input[type="tel"], #carpool-invite-input, #family-link-input,
#join-token-input, #carpool-groupchat-input,
a[href^="tel:"] { direction: ltr; unicode-bidi: plaintext; }

/* Mirror only direction-encoding chevrons under RTL (disclosure / "forward");
   never mirror neutral icons (check, bell, avatars, the brand mark). The open
   settings chevron keeps its rotate(90deg) — down means open in any direction. */
[dir="rtl"] .settings-section:not([open]) > .settings-section-summary > .settings-chevron,
[dir="rtl"] .settings-subrow:not([open]) > .settings-subrow-summary > .settings-chevron,
[dir="rtl"] .plan-next-week-link > .icon,
[dir="rtl"] .group-chat-row > svg.icon-sm,
[dir="rtl"] .setup-step-chevron,
[dir="rtl"] .settings-row-value > .icon { transform: scaleX(-1); }

/* Absolutely-positioned bits pinned to a physical edge need flipping in RTL. */
[dir="rtl"] .overflow-menu-list { left: 0; right: auto; }
[dir="rtl"] #weekview-optout-badge { left: calc(50% - 26px); right: auto; }

/* Account-sheet "Language" row + the picker itself */
.settings-row-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--tap-min);
  padding: 12px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text); font-weight: 600; font-size: 15px;
}
.settings-row-btn:active { background: var(--bg); }
.settings-row-value { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.lang-pick-btn { justify-content: space-between; }
.lang-pick-btn.lang-active { border-color: var(--brand); color: var(--brand); font-weight: 700; }
.lang-pick-btn .icon { color: var(--brand); }

/* ---------- Crew Plus upgrade sheet ---------- */
.plan-toggle { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px; margin: 10px 0 4px; }
.plan-opt { flex: 1; border: none; background: transparent; padding: 9px 8px; border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13.5px; font-weight: 700; color: var(--muted); cursor: pointer; }
.plan-opt.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }
.plus-price { font-size: 16px; font-weight: 700; color: var(--text); margin: 2px 0 12px; }
.plus-benefits { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 14px; }
.plus-b { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; color: var(--text); }
.plus-b .icon { color: var(--brand); margin-top: 1px; flex: 0 0 auto; }
.plus-reassure { font-size: 12.5px; text-align: center; margin: 8px 0 2px; }
.crew-plus-active { color: var(--brand); font-weight: 700; }
