/* SelfTrackr — shared design system. Source of truth: rules/ui.md, every
   component is shown in packages/shared/preview.html.
   Mobile first: the base rules are the phone layout; wider screens are
   enhancements (min-width: 721px tablet/desktop shell, 1081px wide grids). */

/* ── Tokens ──────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  --color-bg: #FFFFFF;              /* page */
  --color-card: #FFFFFF;            /* cards, lists, inputs */
  --color-surface: #F5F5F7;         /* sidebar, icon wells, segmented track */
  --color-surface-elevated: #E8E8ED;/* hover on surface */
  --color-border: #D2D2D7;          /* inputs */
  --color-border-light: #E8E8ED;    /* cards, dividers */
  --color-text-primary: #1D1D1F;
  --color-text-secondary: #6E6E73;
  --color-text-placeholder: #AEAEB2;
  --color-accent: #0071E3;          /* identity, links, active, primary action */
  --color-accent-hover: #0058B0;
  --color-accent-subtle: color-mix(in srgb, var(--color-accent) 10%, transparent);
  --color-on-accent: #FFFFFF;
  --color-success: #34C759;
  --color-success-text: #1F8A3D;
  --color-warning: #FF9500;
  --color-warning-text: #B25E00;
  --color-error: #FF3B30;
  --color-error-text: #C0392B;

  /* Chart / category palette, in this order */
  --chart-1: #0071E3; --chart-2: #34C759; --chart-3: #FF9500; --chart-4: #AF52DE;
  --chart-5: #5856D6; --chart-6: #5AC8FA; --chart-7: #FF3B30; --chart-8: #FFCC00;

  /* Chess board squares (same in both modes: a board is a board) */
  --board-light: #F0D9B5; --board-dark: #B58863; --board-ink-light: #6B4F2E; --board-ink-dark: #FFF8EE;

  --font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont,
    "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-size-xs: 12px;  --line-height-xs: 16px;
  --font-size-sm: 14px;  --line-height-sm: 20px;
  --font-size-base: 16px;--line-height-base: 24px;
  --font-size-lg: 20px;  --line-height-lg: 28px;
  --font-size-xl: 24px;  --line-height-xl: 32px;
  --font-size-2xl: 32px; --line-height-2xl: 40px;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px; --space-12: 48px; --space-16: 64px;

  --max-width: 1200px;
  --sidebar-width: 220px;
  --content-padding: 20px;
  --tabbar-height: 64px;
  --topbar-height: 52px;
  --touch: 44px;                    /* minimum tap target */

  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-elevated: 0 8px 24px rgba(0,0,0,0.10);
  --glass: rgba(255,255,255,0.92);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #000000;
    --color-card: #1C1C1E;
    --color-surface: #1C1C1E;
    --color-surface-elevated: #2C2C2E;
    --color-border: #48484A;
    --color-border-light: #2C2C2E;
    --color-text-primary: #F5F5F7;
    --color-text-secondary: #98989D;
    --color-text-placeholder: #636366;
    --color-accent: #0A84FF;
    --color-accent-hover: #409CFF;
    --color-accent-subtle: color-mix(in srgb, var(--color-accent) 18%, transparent);
    --color-success: #30D158; --color-success-text: #30D158;
    --color-warning: #FF9F0A; --color-warning-text: #FF9F0A;
    --color-error: #FF453A;   --color-error-text: #FF6961;
    --chart-1: #0A84FF; --chart-2: #30D158; --chart-3: #FF9F0A; --chart-4: #BF5AF2;
    --chart-5: #5E5CE6; --chart-6: #64D2FF; --chart-7: #FF453A; --chart-8: #FFD60A;
    --shadow-card: 0 0 0 transparent;
    --shadow-hover: 0 0 0 transparent;
    --shadow-elevated: 0 8px 24px rgba(0,0,0,0.5);
    --glass: rgba(28,28,30,0.92);
  }
}

/* ── Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
svg { flex-shrink: 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--color-accent) 45%, transparent); outline-offset: 2px; }
.text-secondary { color: var(--color-text-secondary); }
.num, .tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── App shell (ST.mountShell) ───────────────────────────────────────── */
/* Phone: top bar + page + bottom tab bar. ≥721px: sidebar + page. */
.app { min-height: 100vh; min-height: 100dvh; background: var(--color-bg); }
.main { min-width: 0; }

.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 600; letter-spacing: -0.01em; color: var(--color-text-primary); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: var(--radius-md);
  background: var(--color-accent); color: var(--color-on-accent);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; letter-spacing: -0.02em;
}
.local-pill {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: var(--radius-sm);
  color: var(--color-warning-text); background: color-mix(in srgb, var(--color-warning) 14%, transparent);
}

/* Phone top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--content-padding) 0;
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--color-border-light);
}
.topbar__module { font-size: var(--font-size-base); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.topbar__user { width: var(--touch); height: var(--touch); display: grid; place-items: center; margin-right: -6px; }

/* Account menu (opened from the top-bar avatar) */
.menu {
  position: fixed; z-index: 60;
  top: calc(var(--topbar-height) + env(safe-area-inset-top) + 6px);
  right: max(12px, env(safe-area-inset-right));
  width: min(300px, calc(100vw - 24px));
  background: var(--color-card); border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-elevated);
  padding: var(--space-2);
}
.menu[hidden] { display: none; }
.menu__head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.menu__name { font-weight: 600; font-size: var(--font-size-sm); line-height: 1.3; }
.menu__email, .menu__meta { font-size: var(--font-size-xs); color: var(--color-text-secondary); line-height: 1.3; word-break: break-all; }
.menu__meta { padding: 0 var(--space-3) var(--space-2); }
.menu__item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: var(--touch); padding: 0 var(--space-3); border-radius: var(--radius-md);
  font-size: var(--font-size-sm); font-weight: 500; color: var(--color-text-primary);
}
.menu__item:hover { background: var(--color-surface); text-decoration: none; }
.menu__item svg { width: 18px; height: 18px; color: var(--color-text-secondary); }

/* Sidebar (≥721px) */
.sidebar { display: none; }
.sidebar__brand { padding: 0 var(--space-3); font-size: var(--font-size-lg); }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 40px; padding: 8px var(--space-3); border-radius: var(--radius-md);
  font-size: var(--font-size-sm); font-weight: 500; color: var(--color-text-primary);
  transition: background 120ms ease;
}
.nav-item:hover { background: var(--color-surface-elevated); text-decoration: none; }
.nav-item--active, .nav-item--active:hover { background: var(--color-accent-subtle); color: var(--color-accent); }
.nav-item--soon { color: var(--color-text-placeholder); pointer-events: none; }
.nav-item--soon::after { content: "soon"; margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.nav-item__icon { width: 20px; height: 20px; }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 6px 32px; }
.nav-sub a {
  display: block; padding: 6px var(--space-3); border-radius: var(--radius-sm);
  font-size: var(--font-size-sm); color: var(--color-text-secondary);
}
.nav-sub a:hover { background: var(--color-surface-elevated); text-decoration: none; }
.nav-sub a.is-active { color: var(--color-accent); font-weight: 600; }
.nav-sub a.is-open { color: var(--color-text-primary); font-weight: 600; }
.nav-sub--deep { margin: 0 0 4px 12px; border-left: 1px solid var(--color-border-light); padding-left: 4px; }
.nav-sub--deep a { font-size: var(--font-size-xs); padding: 5px var(--space-3); }
.sidebar__footer { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-2); }
.sidebar__user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); min-width: 0; }
.sidebar__user-name { font-size: var(--font-size-sm); font-weight: 500; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-email { font-size: var(--font-size-xs); color: var(--color-text-secondary); line-height: 1.2; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__meta { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-3); font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.sidebar__meta button { font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); padding: 6px 0; }
.sidebar__meta button:hover { color: var(--color-error); }

/* Bottom tab bar (phone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px max(4px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--color-border-light);
}
.tabbar__btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 48px; padding: 4px 2px; border-radius: var(--radius-md);
  font-size: 10px; font-weight: 500; line-height: 1.2; color: var(--color-text-secondary);
}
.tabbar__btn:hover { text-decoration: none; }
.tabbar__btn svg { width: 22px; height: 22px; }
.tabbar__btn--active { color: var(--color-accent); }
.tabbar__btn--soon { opacity: 0.4; pointer-events: none; }

/* In-module views on the phone: a scrolling segmented bar under the top bar */
.viewbar { display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none; padding: var(--space-3) var(--content-padding) 0; }
.viewbar::-webkit-scrollbar { display: none; }
.viewbar a {
  flex-shrink: 0; min-height: var(--touch); display: inline-flex; align-items: center;
  padding: 0 14px; border-radius: 999px; font-size: var(--font-size-sm); font-weight: 500;
  background: var(--color-surface); color: var(--color-text-primary);
}
.viewbar a:hover { text-decoration: none; }
.viewbar a.is-active, .viewbar a.is-open { background: var(--color-accent); color: var(--color-on-accent); }
.viewbar--deep { padding-top: var(--space-2); }
.viewbar--deep a { font-size: var(--font-size-xs); background: none; border: 1px solid var(--color-border-light); }
.viewbar--deep a.is-active { background: var(--color-accent-subtle); color: var(--color-accent); border-color: transparent; }

/* ── Page ────────────────────────────────────────────────────────────── */
.page {
  max-width: var(--max-width); margin: 0 auto;
  padding: var(--space-6) var(--content-padding) calc(var(--tabbar-height) + var(--space-8) + env(safe-area-inset-bottom));
  padding-left: max(var(--content-padding), env(safe-area-inset-left));
  padding-right: max(var(--content-padding), env(safe-area-inset-right));
}
.page__header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: var(--space-4); margin-bottom: var(--space-6); }
.page__header > :first-child { min-width: 0; }
.page__eyebrow { font-size: var(--font-size-sm); color: var(--color-text-secondary); margin-bottom: var(--space-1); }
.page__title { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.page__subtitle { font-size: var(--font-size-base); color: var(--color-text-secondary); margin-top: var(--space-2); }
.page__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: var(--touch); font-size: var(--font-size-sm); font-weight: 500; margin-bottom: var(--space-1); }
.back-link svg { width: 16px; height: 16px; }
.section-title { font-size: var(--font-size-lg); line-height: var(--line-height-lg); font-weight: 600; letter-spacing: -0.01em; margin: var(--space-8) 0 var(--space-4); }
.stack { display: grid; gap: var(--space-4); }

/* ── Card ────────────────────────────────────────────────────────────── */
.card { background: var(--color-card); border: 1px solid var(--color-border-light); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); min-width: 0; }
.card__header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-4) 0; }
.card__title { font-size: var(--font-size-lg); line-height: var(--line-height-lg); font-weight: 600; letter-spacing: -0.01em; }
.card__subtitle { font-size: var(--font-size-sm); color: var(--color-text-secondary); }
.card__body { padding: var(--space-4); }
.card__footer { padding: 0 var(--space-4) var(--space-4); display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ── Summary cards (overview tiles) ──────────────────────────────────── */
.summary-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); margin-bottom: var(--space-8); }
.summary-card {
  display: block; width: 100%; padding: var(--space-4); text-align: left; color: inherit;
  background: var(--color-card); border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
a.summary-card:hover, button.summary-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-hover); text-decoration: none; }
.summary-card__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); gap: var(--space-2); }
.summary-card__label { font-size: var(--font-size-sm); color: var(--color-text-secondary); font-weight: 500; }
.summary-card__icon {
  width: 28px; height: 28px; border-radius: var(--radius-md); display: grid; place-items: center;
  color: var(--tint, var(--color-accent)); background: color-mix(in srgb, var(--tint, var(--color-accent)) 10%, transparent);
}
.summary-card__icon svg { width: 16px; height: 16px; }
.summary-card__value { font-size: var(--font-size-xl); line-height: var(--line-height-xl); font-weight: 600; letter-spacing: -0.02em; margin-bottom: var(--space-1); font-variant-numeric: tabular-nums; }
.summary-card__delta { font-size: var(--font-size-xs); color: var(--color-text-secondary); display: flex; align-items: center; gap: 4px; margin-bottom: var(--space-4); }
.summary-card__delta:last-child { margin-bottom: 0; }
.sparkline { width: 100%; height: 36px; display: block; color: var(--tint, var(--color-accent)); }

.delta--up { color: var(--color-success-text); }
.delta--down { color: var(--color-error-text); }
.delta--warn { color: var(--color-warning-text); }
.delta-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-sm); font-size: var(--font-size-xs); font-weight: 600; white-space: nowrap; }
.delta-pill svg { width: 10px; height: 10px; }
.delta-pill--up { background: color-mix(in srgb, var(--color-success) 12%, transparent); color: var(--color-success-text); }
.delta-pill--down { background: color-mix(in srgb, var(--color-error) 10%, transparent); color: var(--color-error-text); }

/* ── Stats ───────────────────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-bottom: var(--space-8); }
.stat-row > .card { display: flex; flex-direction: column; }
.stat-row > .card > .card__body { flex: 1; display: flex; flex-direction: column; justify-content: space-between; }
.stat-row__hero { grid-column: 1 / -1; }
.hero-stat__label, .stat-mini__label { font-size: var(--font-size-sm); color: var(--color-text-secondary); margin-bottom: var(--space-2); }
.hero-stat__value { font-size: 40px; line-height: 1.05; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-stat__value .currency, .hero-stat__value .cents { font-size: 22px; font-weight: 600; color: var(--color-text-secondary); letter-spacing: 0; }
.hero-stat__value .currency { vertical-align: top; margin-right: 4px; }
.hero-stat__sub { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--font-size-sm); color: var(--color-text-secondary); margin-top: var(--space-2); }
.stat-mini__value { font-size: var(--font-size-lg); line-height: var(--line-height-lg); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-mini__sub { font-size: var(--font-size-xs); color: var(--color-text-secondary); margin-top: var(--space-1); }

.split-2 { display: grid; grid-template-columns: 1fr; gap: var(--space-4); margin-bottom: var(--space-8); }

/* ── Segmented control (filters, periods) ────────────────────────────── */
.segmented { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; background: var(--color-surface); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
.segmented::-webkit-scrollbar { display: none; }
.segmented__btn {
  flex-shrink: 0; min-height: 32px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 14px; border-radius: var(--radius-sm); font-size: var(--font-size-sm); font-weight: 500;
  color: var(--color-text-secondary); white-space: nowrap; transition: background 120ms ease, color 120ms ease;
}
.segmented__btn:hover { color: var(--color-text-primary); text-decoration: none; }
.segmented__btn--active { background: var(--color-card); color: var(--color-text-primary); box-shadow: var(--shadow-card); }

/* ── Lists (rows with an icon, a title, a trailing value) ────────────── */
.list-group { margin-bottom: var(--space-6); }
.list-group__header { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); padding: 0 var(--space-2); margin-bottom: var(--space-2); font-size: var(--font-size-xs); color: var(--color-text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.list { background: var(--color-card); border: 1px solid var(--color-border-light); border-radius: var(--radius-lg); overflow: hidden; }
.list-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3);
  min-height: 56px; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-light); color: inherit;
}
.list-row:last-child { border-bottom: none; }
.list-row--no-icon { grid-template-columns: minmax(0, 1fr) auto; }
a.list-row:hover, button.list-row:hover { background: var(--color-surface); text-decoration: none; }
button.list-row { width: 100%; text-align: left; }
.list-row__icon {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--tint, var(--color-text-primary)); background: color-mix(in srgb, var(--tint, var(--color-text-secondary)) 12%, transparent);
}
.list-row__icon svg { width: 18px; height: 18px; }
.list-row__title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row__sub { font-size: var(--font-size-xs); color: var(--color-text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row__trail { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-end; }
.amount { font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount--income { color: var(--color-success-text); }
.amount--expense { color: var(--color-text-primary); }

/* ── Breakdown (share of a total, with bars) ─────────────────────────── */
.breakdown { display: flex; flex-direction: column; gap: var(--space-4); }
.breakdown__row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); font-size: var(--font-size-sm); }
.breakdown__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tint, var(--color-accent)); }
.breakdown__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown__amount { color: var(--color-text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.breakdown__bar { grid-column: 1 / -1; height: 4px; background: var(--color-surface); border-radius: 2px; overflow: hidden; margin-top: -4px; }
.breakdown__bar > span { display: block; height: 100%; border-radius: 2px; background: var(--tint, var(--color-accent)); }
.breakdown__bar--over > span { background: var(--color-error); }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-sm);
  font-size: var(--font-size-xs); font-weight: 600; white-space: nowrap;
  background: var(--color-surface); color: var(--color-text-secondary);
}
.badge--accent { background: var(--color-accent-subtle); color: var(--color-accent); }
.badge--success { background: color-mix(in srgb, var(--color-success) 12%, transparent); color: var(--color-success-text); }
.badge--warning { background: color-mix(in srgb, var(--color-warning) 14%, transparent); color: var(--color-warning-text); }
.badge--error { background: color-mix(in srgb, var(--color-error) 10%, transparent); color: var(--color-error-text); }

/* ── Avatar ──────────────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #FFB199 0%, #FF6A88 100%);
  display: grid; place-items: center; color: #FFFFFF; font-weight: 600; font-size: 13px;
}
.avatar--lg { width: 56px; height: 56px; font-size: 20px; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form { display: grid; gap: var(--space-4); }
.form__row { display: grid; gap: var(--space-4); }
.form__actions { display: flex; flex-direction: column; gap: var(--space-2); }
.field { display: grid; gap: 6px; min-width: 0; }
.field__label { font-size: var(--font-size-sm); font-weight: 500; }
.field__hint { font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.input, .select, .textarea {
  width: 100%; min-height: var(--touch); padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px keeps iOS from zooming */ color: var(--color-text-primary);
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  transition: border-color 120ms ease, box-shadow 120ms ease; appearance: none;
}
.textarea { min-height: 96px; resize: vertical; }
.select { background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%), linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.input::placeholder, .textarea::placeholder { color: var(--color-text-placeholder); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-subtle); }
.input[aria-invalid="true"] { border-color: var(--color-error); }
.input:disabled { background: var(--color-surface); color: var(--color-text-secondary); }
.checkbox { display: flex; align-items: center; gap: var(--space-2); min-height: var(--touch); font-size: var(--font-size-sm); }
.checkbox input { width: 20px; height: 20px; accent-color: var(--color-accent); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--touch); padding: 0 18px; border-radius: var(--radius-md);
  font-size: var(--font-size-sm); font-weight: 600; white-space: nowrap; text-decoration: none;
  background: var(--color-surface); color: var(--color-text-primary);
  transition: background 120ms ease, opacity 120ms ease;
}
.btn:hover { background: var(--color-surface-elevated); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn--primary { background: var(--color-accent); color: var(--color-on-accent); }
.btn--primary:hover { background: var(--color-accent-hover); }
.btn--danger { background: color-mix(in srgb, var(--color-error) 10%, transparent); color: var(--color-error-text); }
.btn--danger:hover { background: color-mix(in srgb, var(--color-error) 16%, transparent); }
.btn--plain { background: none; color: var(--color-accent); padding: 0 var(--space-2); }
.btn--plain:hover { background: var(--color-accent-subtle); }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 0 12px; }
.btn--icon { width: var(--touch); padding: 0; }

/* ── Notices ─────────────────────────────────────────────────────────── */
.notice { display: flex; gap: var(--space-2); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--font-size-sm); background: var(--color-surface); }
.notice[hidden] { display: none; }
.notice--error { background: color-mix(in srgb, var(--color-error) 10%, transparent); color: var(--color-error-text); }
.notice--success { background: color-mix(in srgb, var(--color-success) 12%, transparent); color: var(--color-success-text); }
.notice--info { background: var(--color-accent-subtle); color: var(--color-accent); }

/* ── Empty state ─────────────────────────────────────────────────────── */
.empty { text-align: center; padding: var(--space-12) var(--space-6); color: var(--color-text-secondary); }
.empty__icon { width: 48px; height: 48px; margin: 0 auto var(--space-3); border-radius: 50%; display: grid; place-items: center; background: var(--color-surface); }
.empty__icon svg { width: 22px; height: 22px; }
.empty__title { display: block; color: var(--color-text-primary); font-weight: 600; margin-bottom: var(--space-1); }
.empty .btn { margin-top: var(--space-4); }

/* ── Tables (wide data; always inside .table-scroll) ─────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
.table th { text-align: left; font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.04em; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-light); white-space: nowrap; }
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-light); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }

/* ── Charts (ST.sparkline, ST.lineChart) ─────────────────────────────── */
.chart-wrap { position: relative; width: 100%; touch-action: pan-y; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; color: var(--color-accent); }
.chart-svg .grid { stroke: var(--color-border-light); }
.chart-svg .label { fill: var(--color-text-secondary); font-size: 11px; }
.chart-tooltip {
  position: absolute; pointer-events: none; white-space: nowrap; transform: translate(-50%, -100%);
  background: var(--color-card); border: 1px solid var(--color-border-light); border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated); padding: var(--space-2) var(--space-3); font-size: var(--font-size-sm);
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip__date { font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.chart-tooltip__value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Sign-in screens (no shell) ──────────────────────────────────────── */
.auth-screen {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  padding: max(var(--space-12), env(safe-area-inset-top)) var(--content-padding) max(var(--space-8), env(safe-area-inset-bottom));
  background: var(--color-surface);
}
.auth-screen__inner { width: 100%; max-width: 400px; }
.auth-screen__brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); margin-bottom: var(--space-6); text-align: center; }
.auth-screen__brand .brand-mark { width: 48px; height: 48px; border-radius: 12px; font-size: 22px; }
.auth-screen__title { font-size: var(--font-size-xl); line-height: var(--line-height-xl); font-weight: 700; letter-spacing: -0.02em; }
.auth-screen__subtitle { color: var(--color-text-secondary); font-size: var(--font-size-sm); margin-top: var(--space-1); }
.auth-screen .card__body { padding: var(--space-6) var(--space-4); }
.auth-screen__foot { text-align: center; font-size: var(--font-size-xs); color: var(--color-text-secondary); margin-top: var(--space-6); }
.divider { display: flex; align-items: center; gap: var(--space-3); color: var(--color-text-secondary); font-size: var(--font-size-xs); margin: var(--space-4) 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--color-border-light); }

/* ── ≥ 461px: small tablets / large phones in landscape ──────────────── */
@media (min-width: 461px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .form__actions { flex-direction: row; }
  .form__actions .btn { width: auto; }
  .auth-screen { justify-content: center; }
  .auth-screen .card__body { padding: var(--space-8); }
}

/* ── ≥ 721px: sidebar shell ──────────────────────────────────────────── */
@media (min-width: 721px) {
  :root { --content-padding: 48px; }
  .app { display: flex; }
  .main { flex: 1; }
  .topbar, .tabbar, .viewbar, .menu { display: none !important; }
  .sidebar {
    display: flex; flex-direction: column; gap: var(--space-8);
    width: var(--sidebar-width); flex-shrink: 0; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
    padding: var(--space-6) var(--space-3); background: var(--color-surface); border-right: 1px solid var(--color-border-light);
  }
  .page { padding-top: var(--space-12); padding-bottom: var(--space-16); }
  .page__header { margin-bottom: var(--space-8); }
  .page__title { font-size: var(--font-size-2xl); line-height: var(--line-height-2xl); }
  .card__header { padding: var(--space-6) var(--space-6) 0; }
  .card__body { padding: var(--space-6); }
  .card__footer { padding: 0 var(--space-6) var(--space-6); }
  .summary-card { padding: var(--space-6); }
  .list-row { padding: var(--space-4) var(--space-6); }
  .stat-row { gap: var(--space-4); }
  .hero-stat__value { font-size: 56px; }
  .hero-stat__value .currency, .hero-stat__value .cents { font-size: 32px; }
  .stat-mini__value { font-size: var(--font-size-xl); line-height: var(--line-height-xl); }
  .form__row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .split-2 { gap: var(--space-6); }
}

/* ── ≥ 1081px: wide grids ────────────────────────────────────────────── */
@media (min-width: 1081px) {
  .summary-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .stat-row { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .stat-row__hero { grid-column: auto; }
  .split-2 { grid-template-columns: 2fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
