/* Desert Sage Care Club — design system.
   Warm desert, workshop-honest, high contrast for New Mexico sun (§5).
   Light theme is the default; dark theme follows the device or the user's choice.
   Every text/background pair is checked by scripts/contrast-check.mjs (WCAG 2.1 AA). */

:root {
  --juniper: #2F3E34;
  --sage: #8A9A7B;
  --sand: #F3EDE2;
  --terracotta: #A8522A;
  --charcoal: #1E1F1C;

  --bg: #F3EDE2;
  --surface: #FFFDF8;
  --surface-2: #F7F1E6;
  --surface-3: #ECE4D5;
  --text: #2F3E34;
  --text-muted: #4E584C;
  --border: #DCD3C3;
  --border-strong: #6E7C62;
  --primary: #A8522A;
  --primary-hover: #8F4421;
  --primary-text: #FFFFFF;
  --link: #8A4220;
  --focus: #1F5FA8;
  --header-bg: #2F3E34;
  --header-text: #F3EDE2;
  --accent: #6E7C62;

  --good-bg: #E2EEDD;
  --good-fg: #1D5328;
  --good-dot: #2E7D3E;
  --on-good: #FFFFFF;
  --warn-bg: #FBEACB;
  --warn-fg: #6B4300;
  --warn-dot: #B87A00;
  --bad-bg: #F7DCD6;
  --bad-fg: #8C1D14;
  --bad-dot: #C0392B;
  --info-bg: #E2EBEF;
  --info-fg: #234758;
  --neutral-bg: #ECE6DA;
  --neutral-fg: #3E463B;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30, 31, 28, 0.07), 0 3px 10px rgba(30, 31, 28, 0.06);
  --shadow-lg: 0 8px 30px rgba(30, 31, 28, 0.18);
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: "Bitter", Georgia, "Times New Roman", serif;
  --tap: 48px;
  --gutter: 16px;
  --content: 760px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E1F1C;
    --surface: #282A25;
    --surface-2: #30332D;
    --surface-3: #3A3E36;
    --text: #F3EDE2;
    --text-muted: #CFC8BA;
    --border: #44493F;
    --border-strong: #93A085;
    --primary: #E3824F;
    --primary-hover: #EE9466;
    --primary-text: #1E1F1C;
    --link: #F0A97F;
    --focus: #8DB8F2;
    --header-bg: #161714;
    --header-text: #F3EDE2;
    --accent: #A9B79A;
    --good-bg: #213A26;
    --good-fg: #B9E2BF;
    --good-dot: #5CB46D;
    --on-good: #10200F;
    --warn-bg: #43361A;
    --warn-fg: #F5D58F;
    --warn-dot: #E0A82E;
    --bad-bg: #4A2420;
    --bad-fg: #F6B9AE;
    --bad-dot: #E5675A;
    --info-bg: #213642;
    --info-fg: #B8D5E3;
    --neutral-bg: #33362F;
    --neutral-fg: #DCD6C9;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 3px 10px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1E1F1C;
  --surface: #282A25;
  --surface-2: #30332D;
  --surface-3: #3A3E36;
  --text: #F3EDE2;
  --text-muted: #CFC8BA;
  --border: #44493F;
  --border-strong: #93A085;
  --primary: #E3824F;
  --primary-hover: #EE9466;
  --primary-text: #1E1F1C;
  --link: #F0A97F;
  --focus: #8DB8F2;
  --header-bg: #161714;
  --header-text: #F3EDE2;
  --accent: #A9B79A;
  --good-bg: #213A26;
  --good-fg: #B9E2BF;
  --good-dot: #5CB46D;
  --on-good: #10200F;
  --warn-bg: #43361A;
  --warn-fg: #F5D58F;
  --warn-dot: #E0A82E;
  --bad-bg: #4A2420;
  --bad-fg: #F6B9AE;
  --bad-dot: #E5675A;
  --info-bg: #213642;
  --info-fg: #B8D5E3;
  --neutral-bg: #33362F;
  --neutral-fg: #DCD6C9;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 3px 10px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* ───────────── Base ───────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}
img, svg { max-width: 100%; }
/* Every line icon gets a sensible default size; containers (.btn, .tab, .notice…) set their own. */
svg.i { width: 1.3em; height: 1.3em; flex: none; vertical-align: -0.25em; }
.option > svg.i { width: 28px; height: 28px; color: var(--primary); }
.list-row > svg.i, .list-row > span > svg.i { width: 22px; height: 22px; }
/* Headings get focus after navigation (for screen readers); no ring for that. */
h1[tabindex="-1"]:focus { outline: none; }
h1, h2, h3, h4 { font-family: var(--font-head); line-height: 1.25; margin: 0 0 0.5em; color: var(--text); font-weight: 700; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
small, .small { font-size: 0.88rem; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, Menlo, monospace; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: 8px; top: -60px; background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 8px; }

/* ───────────── Layout ───────────── */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.page { width: 100%; max-width: var(--content); margin: 0 auto; padding: 16px var(--gutter) 120px; flex: 1; }
.page-wide { max-width: 1180px; }
.stack > * + * { margin-top: 14px; }
.stack-sm > * + * { margin-top: 8px; }
.stack-lg > * + * { margin-top: 22px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
/* In rows that wrap, the text keeps a readable width and the buttons drop to the next line. */
[style*="flex-wrap:wrap"] > .grow, .row-wrap > .grow { flex: 1 1 11rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 14px; }

.demo-banner {
  background: #F2C14E;
  color: #2B2100;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 6px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  text-align: center;
  position: relative;
  z-index: 30;
}
.demo-banner button { font: inherit; font-weight: 700; background: rgba(0, 0, 0, 0.1); color: inherit; border: 0; border-radius: 999px; padding: 4px 12px; min-height: 32px; cursor: pointer; }
.demo-banner button:hover { background: rgba(0, 0, 0, 0.18); }
/* TV Support (Addendum v1.1 §6.3): always says who is signed in. */
.support-banner { background: #DCE8F5; color: #12304F; font-size: 0.9rem; font-weight: 600; padding: 6px var(--gutter); display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; text-align: center; position: relative; z-index: 30; }
/* In the installed iPhone app the page runs under the status bar: the first banner keeps its
   text below the notch (the sticky top bar has its own safe-area padding). */
.app > .demo-banner:first-child, .app > .support-banner:first-child { padding-top: calc(6px + env(safe-area-inset-top)); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  color: var(--header-text);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px var(--gutter); min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; flex: 1; }
.brand img { width: 36px; height: 36px; flex: none; border-radius: 8px; background: var(--sand); }
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 0.78rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: var(--header-text); }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex: none;
  text-decoration: none;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn svg { width: 24px; height: 24px; }
.dot-count {
  position: absolute;
  top: 6px;
  right: 4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #F2C14E;
  color: #2B2100;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

/* Bottom tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(30, 31, 28, 0.06);
}
.tabbar-inner { max-width: var(--content); margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 62px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  border: 0;
  background: none;
  cursor: pointer;
  position: relative;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--primary); }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
.tab .dot-count { top: 4px; right: calc(50% - 26px); }

/* Admin layout with sidebar on wide screens */
.admin-shell { display: flex; flex: 1; min-height: 0; }
.sidebar { display: none; }
@media (min-width: 960px) {
  .sidebar {
    display: block;
    width: 248px;
    flex: none;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 14px 10px 40px;
    position: sticky;
    top: 58px;
    height: calc(100vh - 58px);
    overflow-y: auto;
  }
  .admin-shell .tabbar { display: none; }
  .admin-shell .page { padding-bottom: 60px; }
}
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  min-height: 46px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.side-link svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.side-link:hover { background: var(--surface-2); }
.side-link[aria-current="page"] { background: var(--surface-3); color: var(--text); }
.side-link[aria-current="page"] svg { color: var(--primary); }
.side-link .badge { margin-left: auto; }
.side-group { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 14px 12px 4px; font-weight: 700; }

/* ───────────── Cards ───────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-tight { padding: 12px 14px; }
.card-flat { box-shadow: none; }
.card h2, .card h3 { margin-bottom: 6px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { border-color: var(--border-strong); }
.card-accent { border-left: 6px solid var(--primary); }
.card-good { border-left: 6px solid var(--good-dot); }
.card-warn { border-left: 6px solid var(--warn-dot); }
.card-bad { border-left: 6px solid var(--bad-dot); }
.section-title { font-family: var(--font-head); font-size: 1.15rem; margin: 22px 0 10px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.page-title h1 { margin: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  min-height: 56px;
  color: inherit;
  text-decoration: none;
}
a.list-row:hover { background: var(--surface-2); }
.list-row .chev { color: var(--text-muted); flex: none; width: 20px; height: 20px; }

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid transparent;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--link); padding-left: 10px; padding-right: 10px; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--bad-fg); border-color: var(--bad-dot); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-good { background: var(--good-dot); color: var(--on-good); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 58px; font-size: 1.1rem; border-radius: 14px; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 0.92rem; border-radius: 10px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--primary-text) 40%, transparent);
  border-top-color: var(--primary-text);
  animation: spin 0.8s linear infinite;
}
.btn-secondary.is-busy::after, .btn-ghost.is-busy::after, .btn-danger.is-busy::after { border-color: rgba(0, 0, 0, 0.15); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
.action-bar {
  position: sticky;
  bottom: 70px;
  z-index: 5;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 14px 0 6px;
}
@media (min-width: 960px) { .admin-shell .action-bar { bottom: 0; } }

/* ───────────── Badges, lights, status ───────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--neutral-fg);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.no-dot::before { display: none; }
.badge-good { background: var(--good-bg); color: var(--good-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-sample { background: #F2C14E; color: #2B2100; }
.badge-sample::before { display: none; }

.status-line {
  border-radius: var(--radius);
  padding: 16px 18px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 1.35rem;
  line-height: 1.25;
}
.status-line small { display: block; font-family: var(--font-body); font-weight: 600; font-size: 0.95rem; margin-top: 4px; }
.tone-good { background: var(--good-bg); color: var(--good-fg); }
.tone-warn { background: var(--warn-bg); color: var(--warn-fg); }
.tone-bad { background: var(--bad-bg); color: var(--bad-fg); }
.tone-info { background: var(--info-bg); color: var(--info-fg); }
.tone-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

.light { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.light-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12); }
.light-green .light-dot { background: var(--good-dot); }
.light-amber .light-dot { background: var(--warn-dot); }
.light-red .light-dot { background: var(--bad-dot); }
.light-panel { border-radius: var(--radius-sm); padding: 12px 14px; }
.light-panel.light-green { background: var(--good-bg); color: var(--good-fg); }
.light-panel.light-amber { background: var(--warn-bg); color: var(--warn-fg); }
.light-panel.light-red { background: var(--bad-bg); color: var(--bad-fg); }
.light-panel p { margin: 4px 0 0; font-weight: 500; }

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--info-bg);
  color: var(--info-fg);
}
.notice svg { width: 24px; height: 24px; flex: none; margin-top: 1px; }
.notice p:last-child { margin-bottom: 0; }
.notice-good { background: var(--good-bg); color: var(--good-fg); }
.notice-warn { background: var(--warn-bg); color: var(--warn-fg); }
.notice-bad { background: var(--bad-bg); color: var(--bad-fg); }
.notice a { color: inherit; font-weight: 700; }
.warning-box { border: 3px solid var(--bad-dot); background: var(--bad-bg); color: var(--bad-fg); border-radius: var(--radius); padding: 14px 16px; font-weight: 600; }

/* ───────────── Forms ───────────── */
.field { display: block; }
.field + .field { margin-top: 14px; }
.label { display: block; font-weight: 700; margin-bottom: 6px; }
.hint { display: block; color: var(--text-muted); font-size: 0.9rem; margin-top: 5px; }
.error-text { display: block; color: var(--bad-fg); font-weight: 600; font-size: 0.92rem; margin-top: 6px; }
.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 2px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad-dot); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
.input-code { font-family: ui-monospace, Consolas, Menlo, monospace; font-size: 1.8rem; letter-spacing: 0.4em; text-align: center; font-weight: 700; padding: 8px; }
.input-vin { font-family: ui-monospace, Consolas, Menlo, monospace; letter-spacing: 0.12em; text-transform: uppercase; font-size: 1.15rem; }
.input-money { position: relative; }
.input-money .input { padding-left: 30px; }
.input-money::before { content: "$"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: 700; }
.inline-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 12px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  min-height: 56px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}
.check + .check { margin-top: 10px; }
.check input { width: 24px; height: 24px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
.check:has(input:checked) { border-color: var(--primary); background: var(--surface-2); }
.check:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.check .check-body { flex: 1; min-width: 0; }
.check .check-title { font-weight: 700; }
.check .check-side { text-align: right; flex: none; }
.check-plain { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; min-height: 44px; }
.check-plain input { width: 24px; height: 24px; margin: 1px 0 0; flex: none; accent-color: var(--primary); }

.segmented { display: inline-flex; background: var(--surface-3); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.segmented button, .segmented a {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 8px 14px;
  min-height: 42px;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.segmented [aria-pressed="true"], .segmented [aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
.segmented-block { display: flex; width: 100%; }
.segmented-block > * { flex: 1; justify-content: center; }

.rating { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rating button {
  min-height: 46px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rating button[aria-pressed="true"].r-green { background: var(--good-bg); color: var(--good-fg); border-color: var(--good-dot); }
.rating button[aria-pressed="true"].r-yellow { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-dot); }
.rating button[aria-pressed="true"].r-red { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-dot); }
.rating button[aria-pressed="true"].r-na { background: var(--surface-3); border-color: var(--border-strong); }

/* ───────────── Tables ───────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; }

/* ───────────── Vehicle + plan pieces ───────────── */
.vehicle-card .vehicle-title { font-family: var(--font-head); font-size: 1.25rem; font-weight: 800; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}
.chip svg { width: 16px; height: 16px; }
.chip-good { background: var(--good-bg); color: var(--good-fg); border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.chip-bad { background: var(--bad-bg); color: var(--bad-fg); border-color: transparent; }

.plan-card { display: flex; flex-direction: column; gap: 10px; position: relative; }
.plan-card.is-highlight { border: 2px solid var(--primary); }
.plan-card .plan-flag { position: absolute; top: -12px; right: 14px; background: var(--primary); color: var(--primary-text); font-size: 0.78rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; }
.plan-price { font-family: var(--font-head); font-size: 2rem; font-weight: 800; line-height: 1; }
.plan-price small { font-family: var(--font-body); font-size: 0.95rem; font-weight: 600; color: var(--text-muted); }
.plan-includes { list-style: none; padding: 0; margin: 0; }
.plan-includes li { display: flex; gap: 8px; padding: 4px 0; }
.plan-includes svg { width: 20px; height: 20px; color: var(--good-dot); flex: none; margin-top: 2px; }
.savings { font-weight: 700; color: var(--good-fg); }

.hero { text-align: center; padding: 18px 4px 6px; }
.hero-logo { width: 104px; height: 104px; margin: 0 auto 10px; display: block; }
.hero h1 { font-size: 1.9rem; margin-bottom: 4px; }
.hero .tagline { font-family: var(--font-head); font-size: 1.2rem; color: var(--text-muted); margin-bottom: 4px; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick-actions a, .quick-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 78px;
  padding: 10px 6px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
}
.quick-actions svg { width: 26px; height: 26px; color: var(--primary); }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps > li { counter-increment: step; position: relative; padding: 0 0 18px 50px; min-height: 40px; }
.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -2px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--juniper);
  color: var(--sand);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
:root[data-theme="dark"] .steps > li::before { background: var(--sage); color: var(--charcoal); }

.progress-dots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 14px; flex-wrap: wrap; }
.progress-dots span { font-size: 0.8rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-muted); }
.progress-dots span[aria-current="step"] { background: var(--juniper); color: var(--sand); }
.progress-dots span.done { background: var(--good-bg); color: var(--good-fg); }

/* Visit tracker */
.tracker { list-style: none; margin: 0; padding: 0; }
.tracker li { display: flex; gap: 14px; position: relative; padding-bottom: 18px; }
.tracker li:last-child { padding-bottom: 0; }
.tracker li::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 3px; background: var(--border); }
.tracker li:last-child::before { display: none; }
.tracker li.done::before { background: var(--good-dot); }
.tracker .t-dot { width: 33px; height: 33px; border-radius: 50%; border: 3px solid var(--border-strong); background: var(--surface); flex: none; display: flex; align-items: center; justify-content: center; z-index: 1; }
.tracker li.done .t-dot { background: var(--good-dot); border-color: var(--good-dot); color: var(--on-good); }
.tracker li.current .t-dot { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.tracker .t-dot svg { width: 18px; height: 18px; }
.tracker .t-label { font-weight: 700; padding-top: 4px; }
.tracker li.current .t-label { color: var(--primary); }

.mini-steps { display: flex; gap: 4px; }
.mini-steps span { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); }
.mini-steps span.done { background: var(--good-dot); }

/* Day picker */
.day-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-grid .dow { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-align: center; text-transform: uppercase; }
.day {
  min-height: 58px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  line-height: 1.1;
}
.day .d-num { font-weight: 800; font-size: 1.05rem; }
.day .d-note { font-size: 0.66rem; font-weight: 700; margin-top: 3px; text-transform: uppercase; letter-spacing: 0.02em; }
.day[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.day.is-full { background: var(--surface-2); border-style: dashed; }
.day.is-closed { background: transparent; border-color: transparent; color: var(--text-muted); cursor: default; }
.day.is-empty { visibility: hidden; }
.day-load { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.day-load > span { display: block; height: 100%; background: var(--sage); }
.day-load.is-hi > span { background: var(--warn-dot); }
.day-load.is-full > span { background: var(--bad-dot); }

.option-list { display: grid; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  min-height: 72px;
  border-radius: var(--radius);
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.option:hover { border-color: var(--primary); }
.option .o-main { flex: 1; }
.option .o-title { font-weight: 800; font-size: 1.1rem; }
.option[disabled] { opacity: 0.55; cursor: not-allowed; }

/* Photos */
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photo {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-3);
  cursor: zoom-in;
}
.photo-tile { position: relative; }
.photo-tile .photo-flag { position: absolute; left: 4px; bottom: 4px; font-size: 0.7rem; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.7); color: #fff; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi .k-value { font-family: var(--font-head); font-size: 1.6rem; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 0.88rem; color: var(--text-muted); margin-top: 2px; }

.meter { height: 10px; background: var(--surface-3); border-radius: 5px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--good-dot); border-radius: 5px; }
.meter.is-warn > span { background: var(--warn-dot); }
.meter.is-bad > span { background: var(--bad-dot); }

/* ───────────── Overlays ───────────── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 22, 19, 0.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease-out; }
@media (min-width: 720px) { .sheet-backdrop { align-items: center; } }
.sheet {
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px var(--gutter) calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: rise 0.18s ease-out;
}
@media (min-width: 720px) { .sheet { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0.5; } }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.9); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 10px; }

.toasts { position: fixed; left: 0; right: 0; bottom: 84px; z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 var(--gutter); }
.toast {
  pointer-events: auto;
  background: var(--juniper);
  color: var(--sand);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  animation: rise 0.18s ease-out;
}
.toast.toast-bad { background: #8C1D14; color: #fff; }

/* Loading */
.skeleton { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 28px 12px; color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; color: var(--sage); margin-bottom: 8px; }

/* Terms (≥16 px, well above New Mexico's 10-point minimum for renewal terms) */
.terms { font-size: 17px; line-height: 1.6; }
.terms h3 { font-size: 1.05rem; margin: 18px 0 4px; }
.terms p { margin: 0; }
.terms strong { font-weight: 800; }
.terms-table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 16px; }
.terms-table th, .terms-table td { border: 1px solid var(--border-strong); padding: 6px 8px; text-align: left; }
.terms-draft { background: #F2C14E; color: #2B2100; font-weight: 800; padding: 8px 12px; border-radius: 10px; }
.terms-version { color: var(--text-muted); font-size: 0.9rem; margin-top: 14px; }
.terms-box { max-height: 52vh; overflow-y: auto; border: 2px solid var(--border-strong); border-radius: var(--radius); padding: 4px 16px 16px; background: var(--surface); }
.key-facts { list-style: none; padding: 0; margin: 0; }
.key-facts li { display: flex; gap: 10px; padding: 7px 0; font-weight: 600; }
.key-facts svg { width: 22px; height: 22px; flex: none; color: var(--primary); margin-top: 1px; }

/* Help */
.help-steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.help-steps > li { counter-increment: step; margin-bottom: 18px; padding-left: 52px; position: relative; font-size: 1.08rem; }
.help-steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-weight: 800; display: flex; align-items: center; justify-content: center; }
.help-shot { margin-top: 10px; border-radius: 12px; border: 1px solid var(--border); max-width: 320px; width: 100%; height: auto; display: block; background: var(--surface-2); }
.help-page { font-size: 1.06rem; }
.help-lead { font-size: 1.15rem; margin: 0; }
.help-num { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--sand); color: var(--text); font-weight: 800; display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem; }
.help-why { background: var(--info-bg); color: var(--info-fg); border-radius: var(--radius); padding: 14px 16px; }
.help-stuck { background: var(--warn-bg); color: var(--warn-fg); border-radius: var(--radius); padding: 14px 16px; }

/* "New version — tap to refresh" (Addendum v1.1 §5.7). */
.update-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 80; max-width: calc(100% - 2 * var(--gutter)); }
.update-banner button { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 10px 18px; border: 0; border-radius: 999px; background: var(--header-bg); color: var(--header-text); font: inherit; font-weight: 700; box-shadow: var(--shadow-lg); cursor: pointer; }

/* Install guide (Addendum v1.1 §4): pictures, and an arrow at the edge of the screen next to
   where the browser's Share button is. */
.install-pic { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.install-pic svg { max-width: 100%; height: auto; }
.install-arrow { position: fixed; z-index: 90; color: var(--primary); filter: drop-shadow(0 0 2px #fff) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35)); pointer-events: none; animation: install-bob 1.1s ease-in-out infinite; }
.install-arrow-bottom { bottom: calc(4px + env(safe-area-inset-bottom)); left: calc(50% - 24px); }
.install-arrow-bottom-right { bottom: calc(4px + env(safe-area-inset-bottom)); right: 14px; }
.install-arrow-top-right { top: calc(4px + env(safe-area-inset-top)); right: 14px; transform: rotate(180deg); animation-name: install-bob-up; }
@keyframes install-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 8px; } }
@keyframes install-bob-up { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }

/* Share and QR codes (Addendum v1.1 §3). */
.seg-row { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border: 2px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; }
.seg-opt input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.seg-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.stripe-checkout { min-height: 420px; }
.qr-preview { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; display: flex; justify-content: center; }
.qr-preview svg { width: 100%; max-width: 340px; height: auto; background: #fff; box-shadow: var(--shadow); }
.qr-invite { display: flex; justify-content: center; }
.qr-invite svg { width: min(240px, 70vw); height: auto; background: #fff; border-radius: 8px; }

/* QR printables print alone, at true size (letter paper, no page margins). */
#print-area { display: none; }

/* Print: estimates and reports print cleanly. */
@page qr-letter { size: 8.5in 11in; margin: 0; }
@media print {
  html.printing body > *:not(#print-area) { display: none !important; }
  html.printing body { background: #fff; padding: 0; margin: 0; }
  html.printing #print-area { display: block; }
  .print-page { page: qr-letter; width: 8.5in; height: 11in; overflow: hidden; break-after: page; }
  .print-page:last-child { break-after: auto; }
  .print-page svg { display: block; width: 8.5in; height: 11in; }
  .topbar, .tabbar, .sidebar, .demo-banner, .support-banner, .update-banner, .install-arrow, .no-print, .action-bar, .toasts { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
}

@media (min-width: 720px) {
  h1 { font-size: 1.9rem; }
  .page { padding-top: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .install-arrow { animation: none; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
