/* Mobile-first styles. Light and dark themes via prefers-color-scheme. */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #1c1d21;
  --muted: #6b6f76;
  --border: #e4e2dc;
  --accent: #2a9d8f;
  --accent-text: #ffffff;
  --accent-soft: #d8efec;
  --good: #2f9e44;
  --warn: #e08e0b;
  --bad: #d63c3c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 16px;
  --nav-h: 64px;
  --rail-w: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2126;
    --surface-2: #272b31;
    --text: #eceef1;
    --muted: #9aa0a8;
    --border: #2f343b;
    --accent: #3cbcac;
    --accent-text: #08201d;
    --accent-soft: #173a36;
    --good: #51cf66;
    --warn: #fcc419;
    --bad: #ff6b6b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
/* The scrollbar's room is kept on wide screens, so the page doesn't shift sideways when it grows. */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Equal-width digits: amounts and counts keep their width as they update. */
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }
p { margin: 8px 0; }
code.block {
  display: block; padding: 8px 10px; border-radius: 8px; background: var(--surface-2);
  font-size: 0.8rem; word-break: break-all; user-select: all;
}
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; word-break: break-word; }
.grow { flex: 1; min-width: 0; }
.block { display: block; }
.left { align-self: flex-start; text-align: left; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; flex-wrap: wrap; }
.negative { color: var(--bad) !important; }
.positive { color: var(--good) !important; }
.strong { font-weight: 600; }
.right { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.danger-text { color: var(--bad) !important; }

/* Layout */
.app { min-height: 100vh; min-height: 100dvh; }
.page {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  display: flex; flex-direction: column; gap: 14px;
}
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 10px 2px 8px; }
.section-head a { font-size: 0.9rem; }
section { display: flex; flex-direction: column; gap: 10px; }
section > .section-head { margin-bottom: 0; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 16px;
}
.card.list { padding: 0; overflow: hidden; }
.card.form { display: flex; flex-direction: column; gap: 12px; }

/* Main navigation: a bottom tab bar on phones, a side rail on wide screens (see the end). */
.main-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.main-nav a, .main-nav .nav-more {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 0.7rem; font-weight: 500;
  border: 0; background: none; padding: 0; cursor: pointer;
}
.main-nav svg, .list-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.main-nav [aria-current="page"] { color: var(--accent); }
.main-nav .nav-overflow { display: none; }
.list-icon { display: inline-flex; color: var(--muted); }

/* An area's sub-navigation: a sticky tab strip above its pages. */
.subnav {
  position: sticky; top: 0; z-index: 15;
  padding: calc(var(--safe-top) + 10px) 0 0;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.subnav-title { max-width: 640px; margin: 0 auto; padding: 0 16px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.subnav-tabs {
  display: flex; gap: 4px; max-width: 640px; margin: 0 auto; padding: 4px 10px 0;
  overflow-x: auto; scrollbar-width: none;
}
.subnav-tabs::-webkit-scrollbar { display: none; }
.subnav-tab {
  flex: none; padding: 8px 8px 10px; color: var(--muted); font-size: 0.92rem; font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.subnav-tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.subnav + .page { padding-top: 16px; }

/* Buttons & inputs */
button { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--bad); }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.88rem; border-radius: 10px; }
.icon-btn {
  min-width: 40px; min-height: 40px; border: 0; background: transparent; border-radius: 10px;
  color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
.icon-btn:disabled { opacity: 0.3; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 500; font-size: 0.95rem; min-height: 40px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; /* prevents iOS zoom */
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.inline-input { border-color: transparent !important; padding: 4px 0 !important; min-height: 32px !important; font-weight: 600; background: transparent !important; }
.inline-input:focus { border-color: var(--border) !important; padding: 4px 8px !important; }
.money-input { position: relative; }
.money-input input { padding-left: 30px; font-variant-numeric: tabular-nums; }
.money-prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 500; }
.form-error { color: var(--bad); font-size: 0.88rem; font-weight: 500; }
.notice { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; }
.notice-warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); }
.notice-bad { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.notice .link { padding: 0; font-size: inherit; font-weight: 600; }
details summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; padding: 8px 0; }
details .form { display: flex; flex-direction: column; gap: 10px; }
.form { display: flex; flex-direction: column; gap: 10px; }

.search input { border-radius: 999px; padding-left: 16px; }

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 0.88rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
select.chip-select { width: auto; min-height: 36px; padding: 0 12px; border-radius: 999px; font-size: 0.88rem; }
.chip-toggle { flex-direction: row; color: var(--text); font-weight: 500; }
.chip-toggle input { width: 16px; height: 16px; }

/* Tags & pills */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.tag-good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.tag-warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.tag-bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill {
  --pill: #888;
  display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--pill) 16%, transparent);
  color: color-mix(in srgb, var(--pill) 75%, var(--text));
}
.pill-none { background: var(--surface-2); color: var(--muted); }
.pill-auto { font-size: 0.65rem; margin-left: 2px; opacity: 0.8; }

/* Transactions */
.tx-group { gap: 6px; }
.tx-day { display: flex; justify-content: space-between; padding: 6px 4px 0; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.tx-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; min-height: 64px;
  border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; cursor: pointer;
}
.tx-row:last-child, .list > :last-child { border-bottom: 0; }
.tx-row:active, .list-row:active, .budget-row:active, .rule-main:active { background: var(--surface-2); }
.tx-row.declined { opacity: 0.55; }
.tx-row.declined .tx-amount { text-decoration: line-through; }
.tx-icon { width: 40px; height: 40px; border-radius: 12px; flex: none; object-fit: cover; background: var(--surface-2); }
.tx-icon-text { display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem; font-weight: 700; color: var(--muted); }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.tx-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.tx-amount.in, .detail-amount.in { color: var(--good); }
.tx-local { font-size: 0.75rem; font-weight: 400; color: var(--muted); }

.detail-head { display: flex; gap: 12px; align-items: center; }
.detail-head .tx-icon { width: 52px; height: 52px; }
.detail-title { font-size: 1.15rem; font-weight: 700; }
.detail-amount { font-size: 2.2rem; font-weight: 700; text-align: center; margin: 16px 0 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 16px 0 0; font-size: 0.9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cat-choice {
  --pill: #888;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px; padding: 8px 4px; border-radius: 12px; cursor: pointer;
  border: 2px solid transparent; background: color-mix(in srgb, var(--pill) 12%, var(--surface));
}
.cat-choice.selected { border-color: var(--pill); background: color-mix(in srgb, var(--pill) 24%, var(--surface)); }
.cat-emoji { font-size: 1.4rem; }
.cat-name { font-size: 0.75rem; font-weight: 600; text-align: center; line-height: 1.15; }

/* Home */
.banner {
  display: block; padding: 12px 14px; border-radius: 12px; font-weight: 600; font-size: 0.9rem;
  background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--text);
}
.hero { display: flex; flex-direction: column; gap: 6px; }
.hero-amount { font-size: 2.6rem; font-weight: 750; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 4px; }
.hero-foot { display: flex; justify-content: space-between; }
.hero .btn { align-self: flex-start; margin-top: 8px; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.live-dot.on { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 20%, transparent); }
.accounts { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; scroll-snap-type: x mandatory; }
.accounts::-webkit-scrollbar { display: none; }
.account-card {
  flex: none; min-width: 160px; padding: 14px 16px; border-radius: var(--radius); scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text);
}
.account-name { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.account-balance { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* Progress bars */
.bar { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: visible; margin: 6px 0 2px; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s ease; }
.bar.warn .bar-fill { background: var(--warn); }
.bar.over .bar-fill { background: var(--bad); }
.bar-marker { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: 0.35; border-radius: 1px; }

/* Budgets */
.period-nav { display: flex; align-items: center; justify-content: space-between; }
.period-nav .icon-btn { font-size: 1.6rem; color: var(--text); }
.period-label { display: flex; flex-direction: column; align-items: center; font-weight: 700; }
.totals-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.total { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.budget-row {
  --pill: #888;
  display: block; width: 100%; padding: 14px 16px 14px 20px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left; cursor: pointer; position: relative;
}
.budget-row::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--pill); }
.budget-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.budget-left { font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 16px;
  border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; cursor: pointer; color: var(--text);
}
.list-row.static { cursor: default; }
.list-row.static:active { background: transparent; }
.cat-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.cat-badge { width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex: none; font-size: 1.1rem; }

.trend-bars { display: flex; align-items: flex-end; gap: 8px; height: 160px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; }
.trend-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.trend-bar { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-bar.spent { background: var(--accent); }
.trend-bar.income { background: color-mix(in srgb, var(--good) 45%, var(--surface-2)); }
.trend-label { font-size: 0.75rem; font-weight: 600; }
.trend-value { font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; justify-content: center; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.spent { background: var(--accent); }
.sw.income { background: color-mix(in srgb, var(--good) 45%, var(--surface-2)); }

/* Rules */
.rule-row { display: flex; align-items: center; gap: 4px; padding: 6px 12px 6px 4px; border-bottom: 1px solid var(--border); }
.rule-row.disabled .rule-main { opacity: 0.5; }
.rule-order { display: flex; flex-direction: column; }
.rule-order .icon-btn { min-height: 30px; font-size: 0.75rem; }
.rule-main { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 8px 4px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.rule-name { font-weight: 600; }
.rule-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.85rem; }
.conditions { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.condition { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.condition-top { display: flex; gap: 6px; align-items: center; }
.condition-top select { flex: 1; min-width: 0; }
.conditions > .btn { align-self: flex-start; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; font-weight: 600; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.preview { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); }
.preview-list { max-height: 320px; overflow-y: auto; }
.preview-list .tx-row { pointer-events: none; }

/* Switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background 0.2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Settings */
.members { display: flex; flex-direction: column; gap: 8px; }
.member { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.avatar-child { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); color: color-mix(in srgb, var(--warn) 70%, var(--text)); }
.person-row .avatar { width: 40px; height: 40px; font-size: 1.05rem; }

/* Family and home */
.family-card { display: flex; flex-direction: column; gap: 14px; }
.family-name { font-size: 1.3rem; letter-spacing: -0.01em; }
.people-strip { display: flex; gap: 14px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.people-strip::-webkit-scrollbar { display: none; }
.person-chip { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; max-width: 72px; text-align: center; }
.person-chip .avatar { width: 48px; height: 48px; font-size: 1.2rem; }
.person-chip span:last-child { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Placeholders for screens still to come */
.placeholder { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.placeholder p { margin: 0; }
.plans { margin: 4px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; display: flex; flex-direction: column; gap: 4px; }
.about { display: flex; align-items: center; justify-content: center; gap: 2px; }
.about .live-dot { width: 8px; height: 8px; margin-right: 4px; }
.invite { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--accent-soft); }
.invite-code { font-size: 1.8rem; font-weight: 800; letter-spacing: 0.15em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; user-select: all; }
.connection { display: flex; flex-direction: column; gap: 10px; }
.account-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.account-row.disabled .grow { opacity: 0.55; }
.emoji-field { width: 76px; flex: none; }
.emoji-field input { text-align: center; font-size: 1.3rem; }
.palette { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 12px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.selected { border-color: var(--text); }

/* Tax */
.segmented.tabs { display: flex; }
.segmented.tabs button { flex: 1; padding: 8px 4px; }
.page-header .segmented button { padding: 6px 10px; }
.center-row { justify-content: center; }
.tax-notes { display: flex; flex-direction: column; gap: 8px; }
.tax-note { padding: 10px 12px; border-radius: 10px; font-size: 0.88rem; background: var(--surface-2); }
.tax-note.tip { background: var(--accent-soft); }
.tax-note.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); }
.ledger { display: flex; flex-direction: column; gap: 6px; }
.ledger h3 { margin: 12px 0 2px; }
.ledger h3:first-child { margin-top: 0; }
.ledger-row { display: flex; justify-content: space-between; gap: 12px; font-size: 0.92rem; }
.ledger-row > :last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger-row.strong { font-weight: 700; border-top: 1px solid var(--border); padding-top: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid > label { min-width: 0; }
.hint { font-weight: 400; font-size: 0.8rem; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.items { display: flex; flex-direction: column; gap: 8px; }
.items > .btn { align-self: flex-start; }
.item-row { display: flex; flex-direction: column; gap: 6px; }
.item-top { display: flex; gap: 6px; align-items: center; }
.item-top select { flex: 1; min-width: 0; }
.item-amount { width: 130px; flex: none; }
.list-row.selected { background: var(--accent-soft); }
.list-row .check { width: 16px; flex: none; color: var(--accent); font-weight: 700; }

/* Auth */
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 48px) 16px 32px; display: flex; flex-direction: column; gap: 20px; }
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.auth-brand img { border-radius: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-switch { text-align: center; font-size: 0.9rem; color: var(--muted); margin-top: 16px; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; text-align: center; }

/* Sheets */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.4); animation: fade 0.2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; max-height: 92dvh;
  max-width: 640px; margin: 0 auto; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 32px rgb(0 0 0 / 0.2);
  animation: slide-up 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 0; flex: none; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 6px 20px; flex: none; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 4px 20px calc(var(--safe-bottom) + 20px); display: flex; flex-direction: column; gap: 10px;
}
.sheet-body > h3 { margin-bottom: 0; }
.sheet-actions { margin-top: 12px; }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; font-weight: 500; max-width: 480px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); animation: fade 0.2s ease; }
.toast-error { background: var(--bad); color: #fff; }

/* States */
/* Fades in after a moment, so quick loads don't flash it. */
.spinner-wrap { display: flex; justify-content: center; padding: 40px 0; animation: fade 0.2s ease 0.4s both; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty-title { font-weight: 600; color: var(--text); }
.error-card { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.error-card p { color: var(--muted); }

@media (min-width: 700px) {
  .page { padding-top: calc(var(--safe-top) + 28px); }
  .subnav + .page { padding-top: 24px; }
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 20px; animation: fade 0.2s ease; }
  .sheet-handle { display: none; }
}

/* Wide screens: the tab bar becomes a side rail showing every area. */
@media (min-width: 900px) {
  :root { --rail-w: 220px; }
  .main-nav {
    top: 0; right: auto; width: var(--rail-w); height: auto;
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: calc(var(--safe-top) + 24px) 12px 24px;
    border-top: 0; border-right: 1px solid var(--border);
  }
  .main-nav a {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 10px 12px; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
  }
  .main-nav [aria-current="page"] { background: var(--accent-soft); }
  .main-nav .nav-overflow { display: flex; }
  .main-nav .nav-more { display: none; }
  .app-main { margin-left: var(--rail-w); }
  .page { padding-bottom: 48px; }
  .toasts { bottom: 24px; left: var(--rail-w); }
}

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