/* Off Grid Ops — the design system. One shared stylesheet, mobile-first, no build step.
   The CSP forbids inline styles and scripts, so everything visual lives here or in
   static/pages/<page>.css (namespaced .pg-<page>). Documented in docs/dashboard/UI.md;
   the class names follow the shared UI contract.

   Sections: 1 tokens · 2 base · 3 shell · 4 page layout · 5 components
             (card, stat, table, pill, badge, chips, buttons, forms, notices, empty,
             freshness, disclosure, list, split, kv) · 6 utilities · 7 legacy classes
             kept for pages not yet converted · 8 print */

/* ── 1. tokens ───────────────────────────────────────────────────────────── */
:root {
  /* colour — re-theme here; nothing below hard-codes a brand colour */
  --bg: #f6f5f1;             /* warm off-white canvas */
  --surface: #ffffff;        /* cards, sidebar, inputs */
  --surface-2: #f0eee8;      /* subtle fill: hover rows, active nav, wells */
  --surface-3: #e6e3db;      /* stronger fill */
  --border: #e5e2da;         /* hairlines */
  --border-strong: #d2cec4;  /* inputs, secondary buttons */
  --text: #1b1b18;           /* near-black */
  --text-muted: #6b675f;
  --text-faint: #767269;
  --accent: #f2cf1d;         /* the one accent: primary actions, active markers (sun yellow) */
  --accent-hover: #e6c20c;
  --accent-text: #1b1b18;    /* text on --accent */
  --accent-soft: #fbf1c2;
  --focus: #1b1b18;
  --success: #1e7a45;  --success-soft: #e1f2e6;
  --warning: #8a5a00;  --warning-soft: #fcefd2;
  --danger:  #b3261e;  --danger-soft:  #fbe5e2;
  --info:    #1f5aa6;  --info-soft:    #e3ecfa;
  --trial: #c2410c;          /* trial banner — deliberately loud */
  --trial-text: #ffffff;

  /* type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;     /* 12 */
  --text-sm: 0.8125rem;   /* 13 */
  --text-base: 0.9375rem; /* 15 */
  --text-md: 1rem;        /* 16 */
  --text-lg: 1.125rem;    /* 18 */
  --text-xl: 1.5rem;      /* 24 */
  --text-2xl: 1.875rem;   /* 30 */

  /* space, shape, depth */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 48px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(27, 27, 24, 0.05);
  --shadow-md: 0 10px 30px rgba(27, 27, 24, 0.12), 0 1px 3px rgba(27, 27, 24, 0.08);
  --gutter: 16px;
  --sidebar-w: 240px;
  --tabbar-h: 60px;
  --tap: 44px;

  /* legacy aliases for older markup; do not use in new CSS */
  --card: var(--surface);
  --ink: var(--text);
  --muted: var(--text-muted);
  --line: var(--border);
  --accent-ink: var(--accent-text);
  --ok-bg: var(--success-soft); --ok-ink: var(--success);
  --warn-bg: var(--warning-soft); --warn-ink: var(--warning);
  --err-bg: var(--danger-soft); --err-ink: var(--danger);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --surface: #1e1e1b;
    --surface-2: #272723;
    --surface-3: #31312c;
    --border: #2f2f2a;
    --border-strong: #45443d;
    --text: #efede6;
    --text-muted: #a7a398;
    --text-faint: #8d897f;
    --accent-hover: #ffe04a;
    --accent-soft: #3a3313;
    --focus: #f2cf1d;
    --success: #7bd39c;  --success-soft: #16301f;
    --warning: #f1c46b;  --warning-soft: #362810;
    --danger:  #ff9b90;  --danger-soft:  #3a1a17;
    --info:    #9cc0f5;  --info-soft:    #17263c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

/* ── 2. 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: 400 var(--text-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: var(--text-xl); font-weight: 650; }
h2 { font-size: var(--text-lg); font-weight: 600; }
h3 { font-size: var(--text-md); font-weight: 600; }
h4 { font-size: var(--text-base); font-weight: 600; }
p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }
a { color: var(--text); text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
code { font-family: var(--font-mono); font-size: 0.875em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
.icon { width: 20px; height: 20px; flex: none; }

.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: var(--space-2); top: var(--space-2); z-index: 100; background: var(--surface); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); }

/* ── 3. shell ────────────────────────────────────────────────────────────── */
/* phone: .topbar + content + fixed .tabbar; ≥900px: fixed .sidebar + content */
.app-main { min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; }
body.app:not(.anon) .app-main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 650; font-size: var(--text-md); letter-spacing: -0.01em; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text); }
.brand-mark .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.brand-name span { color: var(--text-muted); font-weight: 500; }

.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 var(--gutter); background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar-me { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); margin-right: -10px; color: var(--text); border-radius: var(--radius-pill); }
.topbar-me:hover { background: var(--surface-2); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar > a, .tab-more > summary {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-muted); text-decoration: none; font-size: 11px; font-weight: 500; min-width: 0; position: relative;
  list-style: none; cursor: pointer; height: var(--tabbar-h);
}
.tab-more > summary::-webkit-details-marker { display: none; }
.tabbar > a span, .tab-more > summary span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tabbar > a.current, .tab-more > summary.current { color: var(--text); font-weight: 650; }
.tabbar > a.current::before, .tab-more > summary.current::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}
.tab-more { position: relative; min-width: 0; }
.tab-more[open] > summary { color: var(--text); }
.tab-more[open] > summary::after { content: ""; position: fixed; inset: 0 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom)); background: rgba(20, 20, 18, 0.25); z-index: -1; }
.tab-sheet {
  position: fixed; left: var(--space-2); right: var(--space-2); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-2));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: var(--space-2); display: flex; flex-direction: column;
}
.tab-sheet a, .tab-sheet button {
  display: flex; align-items: center; justify-content: flex-start; gap: var(--space-3); min-height: 48px; padding: 0 var(--space-3);
  color: var(--text); text-decoration: none; border-radius: var(--radius-sm); font: inherit; font-size: var(--text-md); font-weight: 500;
  background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
}
.tab-sheet a:hover, .tab-sheet button:hover, .tab-sheet a.current { background: var(--surface-2); }
.tab-sheet form { display: block; border-top: 1px solid var(--border); margin-top: var(--space-1); padding-top: var(--space-1); }
.tab-sheet-who { margin: 0; padding: var(--space-2) var(--space-3); color: var(--text-muted); font-size: var(--text-sm); display: flex; gap: var(--space-2); align-items: center; }

.who { display: flex; flex-direction: column; gap: var(--space-1); }
.me { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); padding: var(--space-2); border-radius: var(--radius-sm); min-width: 0; }
.me:hover { background: var(--surface-2); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex: none; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--text); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.02em; }
.me-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.25; }
.me-name { font-weight: 600; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.me-text .role { margin-top: 2px; }
.role { font-size: 11px; text-transform: capitalize; color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-pill); padding: 0 7px; line-height: 18px; display: inline-block; font-weight: 500; }
.who form.inline { display: block; }
.who .signout { justify-content: flex-start; width: 100%; color: var(--text-muted); font-weight: 500; padding: 0 var(--space-2); }

@media (min-width: 900px) {
  body.app:not(.anon) .app-main { margin-left: var(--sidebar-w); padding-bottom: 0; }
  /* paint the sidebar column on the body too, so it reads as one column past the fold (print, full-page captures) */
  body.app:not(.anon) { background: linear-gradient(to right, var(--surface) calc(var(--sidebar-w) - 1px), var(--border) calc(var(--sidebar-w) - 1px) var(--sidebar-w), var(--bg) var(--sidebar-w)); }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: var(--space-6); position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    padding: var(--space-5) var(--space-3) var(--space-4); background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; z-index: 20;
  }
  .sidebar .brand { padding: 0 var(--space-2); }
  .nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .nav a {
    display: flex; align-items: center; gap: var(--space-3); min-height: 38px; padding: 0 var(--space-3);
    color: var(--text-muted); text-decoration: none; border-radius: var(--radius-sm); font-size: var(--text-base); font-weight: 500; position: relative;
  }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a.current { background: var(--surface-2); color: var(--text); font-weight: 600; }
  .nav a.current::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
  .who { border-top: 1px solid var(--border); padding-top: var(--space-3); }
}

/* signed-out pages (login): no chrome, centred column */
.anon-brand { display: flex; justify-content: center; padding: var(--space-8) var(--gutter) 0; }
.anon-brand .brand { font-size: var(--text-lg); }
.anon-brand .brand-mark { width: 36px; height: 36px; border-radius: 10px; }
body.anon .page { max-width: 440px; }
body.anon .page-header { text-align: center; justify-content: center; margin-top: var(--space-2); }

/* trial banner: on every page, unmissable, never dismissible */
.banner-trial {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 9px var(--gutter); background-color: var(--trial); color: var(--trial-text); font-size: var(--text-sm); line-height: 1.35;
  background-image: repeating-linear-gradient(-45deg, transparent 0 14px, rgba(255, 255, 255, 0.08) 14px 28px);
}
.banner-trial .icon { width: 18px; height: 18px; }
body.anon .banner-trial { border-radius: var(--radius-sm); margin: var(--space-4) var(--gutter) 0; }
@media (min-width: 900px) { body.app:not(.anon) .banner-trial { position: sticky; top: 0; z-index: 15; } }

.foot {
  display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: auto;
  padding: var(--space-4) var(--gutter) var(--space-5); color: var(--text-faint); font-size: var(--text-xs);
}
.env { text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.env-live { color: var(--success); }
.env-dev { color: var(--text-muted); }
.ver { font-family: var(--font-mono); }
.trial-pill { background: var(--trial); color: var(--trial-text); border-radius: var(--radius-pill); padding: 0 8px; font-weight: 600; }

/* ── 4. page layout ──────────────────────────────────────────────────────── */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: var(--space-5) var(--gutter) var(--space-7); flex: 1 0 auto; min-width: 0; }
@media (min-width: 900px) { .page { padding: var(--space-7) var(--space-7) var(--space-8); } }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3) var(--space-5); margin: 0 0 var(--space-6); }
.page-heading { min-width: 0; flex: 1 1 260px; }
.page-header h1, .page-title { font-size: var(--text-xl); font-weight: 650; letter-spacing: -0.02em; overflow-wrap: anywhere; }
@media (min-width: 900px) { .page-header h1, .page-title { font-size: var(--text-2xl); } }
.page-subtitle { margin: var(--space-1) 0 0; color: var(--text-muted); font-size: var(--text-base); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; width: 100%; }
.page-actions > .btn { flex: 1 1 auto; }
@media (min-width: 600px) { .page-actions { width: auto; } .page-actions > .btn { flex: 0 0 auto; } }
.page-back { display: inline-flex; align-items: center; gap: 6px; flex-basis: 100%; color: var(--text-muted); text-decoration: none; font-size: var(--text-sm); font-weight: 500; margin-bottom: calc(-1 * var(--space-2)); min-height: 32px; }
.page-back:hover { color: var(--text); }
.page-back .icon { width: 16px; height: 16px; }

.section { margin: 0 0 var(--space-7); }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-3); }
.section-title { font-size: var(--text-lg); font-weight: 600; margin: 0 0 var(--space-3); }
.section-head .section-title { margin: 0; }
.section-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack > .chips { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; }
.grid-2, .grid-3 { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
@media (min-width: 720px) { .grid-2, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.grid-2 > .card, .grid-3 > .card { margin: 0; }

/* ── 5. components ───────────────────────────────────────────────────────── */

/* card */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: var(--space-5); margin: 0 0 var(--space-4); min-width: 0;
}
.card:has(> .card-header), .card:has(> .card-body), .card.flush { padding: 0; }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.card-header h2, .card-header h3 { font-size: var(--text-md); font-weight: 600; margin: 0; }
.card-header p { margin: 0; color: var(--text-muted); font-size: var(--text-sm); flex-basis: 100%; }
.card-body { padding: var(--space-5); }
.card-body.flush { padding: 0; }
.card-footer { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: flex-end; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.card > h2 { font-size: var(--text-md); font-weight: 600; margin: 0 0 var(--space-3); }
.card.narrow { max-width: 440px; }
@media (max-width: 599px) {
  .card { padding: var(--space-4); }
  .card-header, .card-body, .card-footer { padding-left: var(--space-4); padding-right: var(--space-4); }
}

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin: 0 0 var(--space-6); }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); } }
.stat {
  display: flex; flex-direction: column; gap: var(--space-1); margin: 0; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: var(--space-4); color: var(--text); text-decoration: none;
}
.stat-label { color: var(--text-muted); font-size: var(--text-sm); font-weight: 500; order: -1; }
.stat-value { font-size: 1.625rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-value.money { font-size: 1.375rem; }
@media (min-width: 900px) { .stat-value { font-size: 2rem; } .stat-value.money { font-size: 1.75rem; } }
.stat-delta { font-size: var(--text-sm); color: var(--text-muted); }
a.stat:hover, .stat-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }
.stat-success .stat-value { color: var(--success); }

/* tables — quiet: hairline rows, muted header, tabular numbers */
.table-wrap, .scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: var(--text-base); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { color: var(--text-muted); font-weight: 500; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; padding-top: 8px; padding-bottom: 8px; }
tbody tr:last-child > * { border-bottom: 0; }
table.table tbody tr:hover > * { background: var(--surface-2); }
th:first-child, td:first-child { padding-left: var(--space-4); }
th:last-child, td:last-child { padding-right: var(--space-4); }
td.num, th.num, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.row-link { position: relative; cursor: pointer; }
tr.row-link .row-cover { color: inherit; text-decoration: none; font-weight: 600; }
tr.row-link .row-cover::after { content: ""; position: absolute; inset: 0; }
/* other links and controls in a clickable row stay clickable above the cover */
tr.row-link a:not(.row-cover), tr.row-link button, tr.row-link input, tr.row-link select { position: relative; z-index: 1; }
.table-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); }
td.detail { font-family: var(--font-mono); font-size: var(--text-xs); word-break: break-word; }

/* pills — soft tints with a status dot */
.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: var(--radius-pill); padding: 1px 9px 1px 8px;
  font-size: var(--text-xs); font-weight: 600; line-height: 20px; white-space: nowrap; border: 0;
  background: var(--surface-2); color: var(--text-muted); vertical-align: middle;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill-neutral { background: var(--surface-2); color: var(--text-muted); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill.no-dot::before { display: none; }
.pill.no-dot { padding-left: 9px; }

/* DR / SI dealer-tier badge */
.badge-tier, .tier-badge {
  display: inline-flex; align-items: center; border-radius: 5px; padding: 0 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em; line-height: 18px; white-space: nowrap; background: var(--surface-2); color: var(--text-muted); border: 1px solid transparent; vertical-align: middle;
}
.badge-tier.tier-dr, .tier-badge.tier-dr { background: var(--success-soft); color: var(--success); }
.badge-tier.tier-si, .tier-badge.tier-si { background: var(--info-soft); color: var(--info); }
.badge-tier.tier-single { background: var(--surface-2); color: var(--text-muted); }
.badge-tier.tier-fallback, .tier-badge.tier-fallback { background: var(--warning-soft); color: var(--warning); border-color: currentColor; }

/* chips — filters as links (or label.chip around a radio) */
.chips { display: flex; gap: var(--space-2); overflow-x: auto; margin: 0 0 var(--space-4); padding: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
@media (min-width: 720px) { .chips { flex-wrap: wrap; overflow: visible; } }
.chip {
  display: inline-flex; flex-direction: row; align-items: center; gap: 6px; flex: none; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface);
  color: var(--text); text-decoration: none; font-size: var(--text-sm); font-weight: 500; white-space: nowrap; cursor: pointer; position: relative;
}
.chip:hover { background: var(--surface-2); }
.chip.is-active, label.chip:has(input:checked) { background: var(--text); border-color: var(--text); color: var(--bg); }
label.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip-count { font-size: var(--text-xs); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-muted); background: var(--surface-2); border-radius: var(--radius-pill); padding: 0 6px; line-height: 18px; }
.chip.is-active .chip-count, label.chip:has(input:checked) .chip-count { background: color-mix(in srgb, var(--bg) 20%, transparent); color: inherit; }
@media (max-width: 899px) { .chip { min-height: 40px; } }

/* buttons — .btn + kind; bare <button> and legacy .button look like secondary */
.btn, button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: 0 var(--space-4); border-radius: var(--radius-sm);
  font: inherit; font-size: var(--text-base); font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer;
  transition: background-color .12s, border-color .12s, box-shadow .12s;
}
.btn:hover, button:hover, .button:hover { background: var(--surface-2); }
.btn .icon { width: 18px; height: 18px; }
.btn-primary, button.primary, .button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-primary:hover, button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger, button.danger:not(.link) { background: var(--surface); border-color: color-mix(in srgb, var(--danger) 40%, var(--border-strong)); color: var(--danger); }
.btn-danger:hover, button.danger:not(.link):hover { background: var(--danger-soft); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-block { width: 100%; }
.btn[disabled], button:disabled { opacity: 0.45; cursor: not-allowed; }
button.link { background: none; border: 0; color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; padding: 0 var(--space-1); font-weight: 500; min-height: var(--tap); }
@media (max-width: 899px) { .btn, button, .button { min-height: var(--tap); } .btn-sm { min-height: 36px; } }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: var(--text-sm); font-weight: 600; }
.field > label { display: flex; flex-direction: column; gap: 6px; }
.field-hint, .hint { font-size: var(--text-sm); font-weight: 400; color: var(--text-muted); }
.field-error { font-size: var(--text-sm); color: var(--danger); font-weight: 500; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: var(--text-sm); }
input:not([type]), input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=search], input[type=tel], input[type=url], select, textarea {
  font: inherit; font-size: var(--text-md); font-weight: 400; color: var(--text); width: 100%; min-height: var(--tap);
  padding: 9px 12px; background-color: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 36px; background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%238f8b82' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
  text-overflow: ellipsis;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 60%, transparent); }
input[type=checkbox], input[type=radio] { accent-color: var(--text); width: 18px; height: 18px; margin: 0; }
input[type=file] { font: inherit; font-size: var(--text-sm); width: 100%; max-width: 100%; padding: var(--space-2) 0; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; margin-right: var(--space-3); padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
.form-actions {
  display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: flex-end;
  padding-top: var(--space-4); border-top: 1px solid var(--border);
}
.form-actions.sticky {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--surface); padding: var(--space-3) 0;
}
@media (min-width: 900px) { .form-actions.sticky { bottom: 0; } }
@media (max-width: 599px) { .form-actions > .btn, .form-actions > button { flex: 1 1 auto; } }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: var(--text-md); padding: 0; margin-bottom: var(--space-3); }
label.check, .check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; font-size: var(--text-base); }
label.check input { flex: none; margin-top: 2px; }

/* notices */
.notice {
  display: block; margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  font-size: var(--text-base); background: var(--info-soft); color: var(--info); border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
}
.notice a { color: inherit; font-weight: 600; }
.notice-ok, .notice.ok { background: var(--success-soft); color: var(--success); }
.notice-warn, .notice.warn { background: var(--warning-soft); color: var(--warning); }
.notice-error, .notice.error { background: var(--danger-soft); color: var(--danger); }
.notice-info { background: var(--info-soft); color: var(--info); }

/* empty state */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-8) var(--space-4); }
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text-muted); margin-bottom: var(--space-2); }
.empty-icon .icon { width: 22px; height: 22px; }
.empty-title { font-size: var(--text-md); font-weight: 600; margin: 0; }
.empty-text { color: var(--text-muted); max-width: 42ch; margin: 0 0 var(--space-3); font-size: var(--text-base); }

/* freshness line */
.freshness {
  display: flex; gap: var(--space-2); align-items: flex-start; width: 100%; max-width: 1180px; margin: 0 auto;
  padding: 0 var(--gutter) var(--space-2); color: var(--text-faint); font-size: var(--text-xs);
}
@media (min-width: 900px) { .freshness { padding: 0 var(--space-7) var(--space-2); } }
.freshness .icon { width: 14px; height: 14px; margin-top: 2px; }
.fresh { white-space: nowrap; }
.fresh.stale { color: var(--warning); background: var(--warning-soft); padding: 0 6px; border-radius: 4px; font-weight: 600; }

/* disclosure */
details.disclosure { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin: 0 0 var(--space-4); box-shadow: var(--shadow-sm); }
details.disclosure > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 52px; padding: 0 var(--space-5);
  cursor: pointer; font-weight: 600; list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after {
  content: ""; width: 8px; height: 8px; border-right: 1.8px solid var(--text-muted); border-bottom: 1.8px solid var(--text-muted);
  transform: rotate(45deg); margin-top: -4px; flex: none;
}
details.disclosure[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }
details.disclosure > :not(summary) { margin: 0 var(--space-5) var(--space-5); }
details.disclosure[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); }
@media (max-width: 599px) { details.disclosure > summary { padding: 0 var(--space-4); } details.disclosure > :not(summary) { margin: 0 var(--space-4) var(--space-4); } }
details > summary { cursor: pointer; }

/* list — inbox / activity rows */
ul.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); position: relative; min-height: 64px; }
.list-item:last-child { border-bottom: 0; }
.list-item:has(a.list-title):hover { background: var(--surface-2); }
.card > ul.list:first-child > .list-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card > ul.list:last-child > .list-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.list-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--surface-2); color: var(--text); }
.list-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-title { font-weight: 600; font-size: var(--text-base); color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.list-title::after { content: ""; position: absolute; inset: 0; }
.list-meta { color: var(--text-muted); font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-1); flex: none; text-align: right; }
.list-side .money { font-weight: 600; font-size: var(--text-base); color: var(--text); }
.list-extra { position: relative; z-index: 1; }

/* split view — media left / panel right; stacks on phone */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.split-media { min-width: 0; }
.split-panel { min-width: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.split-panel > .card, .split-panel > details.disclosure { margin: 0; }
.split-footer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-2)); z-index: 12;
  display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: flex-end;
  padding: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md);
}
@media (min-width: 1024px) {
  .split { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: var(--space-6); }
  .split-media { position: sticky; top: 56px; max-height: calc(100dvh - 72px); overflow: auto; }
  .split-footer { bottom: var(--space-4); }
  /* a footer placed right after .split lines up under the panel column */
  .split + .split-footer { margin-left: calc((100% - var(--space-6)) * 5 / 11 + var(--space-6)); }
}
.split + .split-footer { margin-top: var(--space-4); }

/* key/value */
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--space-2) var(--space-5); margin: 0; }
dl.kv dt { color: var(--text-muted); font-size: var(--text-sm); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  dl.kv dt { margin-top: var(--space-3); font-size: var(--text-xs); }
  dl.kv dt:first-child { margin-top: 0; }
}

/* money */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── 6. utilities ────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.pre { white-space: pre-wrap; margin: 0; }
.tabular { font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
form.inline { display: inline; margin: 0; }
.error-msg { font-size: var(--text-lg); }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
code.secret { font-size: 1.05rem; letter-spacing: 0.06em; word-break: normal; overflow-wrap: break-word; line-height: 1.8; }

/* ── 7. legacy classes (pages not yet converted — delete as pages move to the contract) ── */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); } }
.grid > .card { margin: 0; }
.stat .n { font-size: 1.625rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.stat .l { color: var(--text-muted); font-size: var(--text-sm); }
.inline-form { display: flex; gap: var(--space-2); align-items: end; flex-wrap: wrap; margin-bottom: var(--space-3); }
.inline-form label { flex: 1; min-width: 200px; }

.sev { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 8px; border-radius: var(--radius-pill); white-space: nowrap; background: var(--surface-2); color: var(--text-muted); }
.sev-high { background: var(--danger-soft); color: var(--danger); }
.sev-medium { background: var(--warning-soft); color: var(--warning); }
.sev-low { background: var(--success-soft); color: var(--success); }
.suggestion-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.suggestion-list li { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.suggestion-list li:first-child { padding-top: 0; }
.suggestion-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.suggestion-owner { color: var(--text-muted); font-weight: 600; }
.due-groups { display: flex; flex-direction: column; gap: 14px; }
.due-group h3 { margin: 0 0 6px; font-size: var(--text-base); }
.due-group ul { margin: 0; padding-left: 18px; }
.banking-field { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); display: flex; flex-direction: column; gap: 10px; }

.report-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.report-list li { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.report-list li:last-child { border-bottom: 0; }
.report-list a { font-weight: 600; text-decoration: none; }
.report-list p { margin: 4px 0 0; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--text); text-decoration: underline; }
.pager { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chart-card h2 { margin-top: 0; font-size: var(--text-md); }
.report-chart { display: block; width: 100%; height: auto; min-width: 560px; }
.chart-card { overflow-x: auto; }
.chart-label { font-size: 10px; fill: var(--text-muted); }
.chart-value { font-size: 10px; fill: var(--text); }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; color: var(--text-muted); margin: 6px 0 0; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.bar-primary { fill: var(--text); }
.bar-secondary { fill: var(--surface-3); }
.bar-negative { fill: var(--danger); }
.legend-swatch.bar-primary { background: var(--text); }
.legend-swatch.bar-secondary { background: var(--surface-3); }
.line-primary { stroke: var(--text); stroke-width: 2; }
.line-primary-dot { fill: var(--text); }
.line-secondary { stroke: var(--text-faint); stroke-width: 2; stroke-dasharray: 4 3; }
.line-secondary-dot { fill: var(--text-faint); }
.legend-swatch.line-primary { background: var(--text); }
.legend-swatch.line-secondary { background: var(--text-faint); }
.tl-live { fill: var(--success); }
.tl-upcoming { fill: var(--info); }
.tl-openended { fill: #8a6d3b; }
.tl-ended { fill: var(--surface-3); }
.tl-withdrawn { fill: var(--danger); }
.tl-unknown { fill: var(--text-faint); }
.tl-deadline { stroke: var(--danger); stroke-width: 2; }
.tl-today { stroke: var(--text); stroke-width: 1; stroke-dasharray: 2 2; }
.legend-swatch.tl-live { background: var(--success); }
.legend-swatch.tl-upcoming { background: var(--info); }
.legend-swatch.tl-openended { background: #8a6d3b; }
.legend-swatch.tl-ended { background: var(--surface-3); }
.legend-swatch.tl-withdrawn { background: var(--danger); }
.legend-swatch.tl-unknown { background: var(--text-faint); }
.legend-swatch.tl-deadline-swatch { background: var(--danger); width: 3px; }
.tier-card p { margin: 6px 0 0; }
.tier-toggle { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tier-toggle-label { font-weight: 600; margin-right: 4px; }
.tier-toggle a {
  display: inline-flex; align-items: center; min-height: 36px; justify-content: center; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); text-decoration: none; font-weight: 500; font-size: var(--text-sm);
}
.tier-toggle a.current, .tier-toggle a[aria-current="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
@media (max-width: 899px) { .tier-toggle a { min-height: var(--tap); } }
tr.tier-fallback-row td { background: var(--warning-soft); }
h3.tier-heading { font-size: var(--text-base); margin: 16px 0 6px; }

.banner.interim { background: var(--warning-soft); color: var(--warning); text-align: center; padding: var(--space-2) var(--gutter); font-weight: 600; border-radius: var(--radius-sm); margin-bottom: var(--space-4); }
.flag-warn { display: inline-block; font-size: var(--text-xs); font-weight: 600; color: var(--warning); background: var(--warning-soft); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.pill-status { font-size: var(--text-xs); font-weight: 600; border-radius: var(--radius-pill); padding: 1px 8px; background: var(--surface-2); color: var(--text-muted); }
.pill-status.submitted { background: var(--warning-soft); color: var(--warning); }
.pill-status.approved { background: var(--success-soft); color: var(--success); }
.pill-status.rejected { background: var(--danger-soft); color: var(--danger); }
details:not(.disclosure):not(.tab-more) > summary:not(.btn) { font-weight: 600; min-height: 36px; display: list-item; padding: 6px 0; }

/* ── 8. print ────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .tabbar, .split-footer, .skip-link { display: none !important; }
  body.app:not(.anon) .app-main { margin: 0; padding: 0; }
  .card { box-shadow: none; }
}

/* auth + account pages (pages/account.py — foundation, not a page agent's) */
.auth-card { padding: var(--space-6); }
.auth-note { text-align: center; margin: var(--space-4) auto 0; max-width: 36ch; }
.card .auth-note { text-align: left; margin-left: 0; }
.account-card { max-width: 560px; }
.account-card .card-footer { justify-content: flex-start; }
.account-signout { margin-top: var(--space-2); }
@media (max-width: 599px) {
  /* phones: let list titles and meta wrap to two lines instead of truncating to a word */
  .list-title, .list-meta { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
}

/* ── release polish (cross-page) ───────────────────────────────────────────── */
/* Sub-navigation between a section's views (Calendar · Claims · Net cost; On hand · Past sales):
   underline tabs, so it is never mistaken for the filter chips that often sit right under it. */
.chips.tabs { gap: var(--space-5); border-bottom: 1px solid var(--border); padding: 0; margin: 0 0 var(--space-5); }
.chips.tabs .chip { border: 0; border-radius: 0; background: transparent; padding: 0 2px; min-height: 42px; color: var(--text-muted); font-weight: 500; box-shadow: inset 0 -2px 0 transparent; }
.chips.tabs .chip:hover { color: var(--text); background: transparent; }
.chips.tabs .chip.is-active { color: var(--text); background: transparent; border: 0; box-shadow: inset 0 -2px 0 var(--text); font-weight: 600; }
@media (max-width: 719px) { .chips.tabs { gap: var(--space-4); } }
/* A list inside a padded card body lines up with the body text, not indented twice. */
.card-body > ul.list > .list-item, .card-body > .stack > ul.list > .list-item { padding-left: 0; padding-right: 0; }
/* Empty states inside cards need less air than a full-page empty state. */
.card > .empty, .card-body > .empty { padding: var(--space-6) var(--space-4); }
.card > .empty .empty-text:last-child, .card-body > .empty .empty-text:last-child { margin-bottom: 0; }
/* A disclosure nested in a card is secondary: smaller summary, no second shadow. */
.card details.disclosure { box-shadow: none; }
.card details.disclosure > summary { font-size: var(--text-base); min-height: 48px; }
/* key/value values read at body size (long notes were larger than their neighbours). */
dl.kv dd { font-size: var(--text-base); }
.empty .error-msg { color: var(--text-muted); margin: 0 0 var(--space-3); }
