:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-subtle: #eef3f0;
  --surface-raised: #ffffff;
  --text: #14211c;
  --text-secondary: #53625b;
  --text-tertiary: #6b7972;
  --border: #d6dfda;
  --border-strong: #a9b9b1;
  --primary: #14634d;
  --primary-hover: #0f4f3e;
  --primary-soft: #dcefe7;
  --on-primary: #ffffff;
  --danger: #b42336;
  --danger-soft: #fff0f2;
  --focus: #0a66c2;
  --shadow-sm: 0 1px 2px rgba(18, 38, 30, .06);
  --shadow-md: 0 14px 36px rgba(18, 38, 30, .12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --content: 1040px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1512;
  --surface: #16201c;
  --surface-subtle: #202c27;
  --surface-raised: #1a2520;
  --text: #f3f7f5;
  --text-secondary: #bdc9c3;
  --text-tertiary: #9caaa3;
  --border: #34443d;
  --border-strong: #51635b;
  --primary: #74d3ad;
  --primary-hover: #91dfbf;
  --primary-soft: #163d30;
  --on-primary: #092119;
  --danger: #ff8b9a;
  --danger-soft: #3c1c22;
  --focus: #80bfff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-md: 0 18px 40px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); font: 16px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
button, select, summary { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .62; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 21px; height: 21px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 5vw, 3rem); line-height: 1.08; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.22rem; line-height: 1.25; letter-spacing: -.015em; }
.eyebrow { margin: 0 0 .28rem; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .095em; text-transform: uppercase; }
.lede { max-width: 38ch; color: var(--text-secondary); font-size: 1.05rem; }

.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: 10px max(20px, calc((100vw - var(--content)) / 2)); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(18px); }
.brand-lockup { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.brand-copy { display: grid; min-width: 0; }
.brand-icon, .brand-mark { display: block; object-fit: cover; }
.brand-icon { width: 38px; height: 38px; border-radius: 9px; }
.brand-mark { width: 52px; height: 52px; margin-bottom: 1.4rem; border-radius: 12px; }
.product-name { display: block; color: var(--text); font-size: 1rem; font-weight: 820; line-height: 1.2; }
.household-context { display: flex; align-items: baseline; gap: .35rem; min-width: 0; color: var(--text-secondary); font-size: .72rem; line-height: 1.35; }
.household-context > span { flex: 0 0 auto; }
.household-context > strong { overflow: hidden; color: var(--text-secondary); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.household-context > strong::before { content: "· "; }
.household-picker { position: relative; display: inline-flex; align-items: center; min-width: 0; max-width: min(42vw, 250px); }
.household-picker select { width: 100%; height: 24px; min-height: 24px; min-width: 0; padding: 0 22px 0 0; border: 0; background: transparent; color: var(--text-secondary); font-size: 1rem; font-weight: 700; appearance: none; text-overflow: ellipsis; }
.household-picker .icon { position: absolute; right: 0; width: 17px; height: 17px; pointer-events: none; }
.account-area { position: relative; }
.avatar-button { display: flex; align-items: center; gap: .38rem; min-width: 54px; height: 44px; padding: 4px 8px 4px 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
#avatar-initials { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: .75rem; font-weight: 850; letter-spacing: .025em; }
.avatar-button .chevron { width: 16px; height: 16px; transition: transform .16s ease; }
.avatar-button[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.account-menu { position: absolute; top: calc(100% + 9px); right: 0; width: 232px; padding: 7px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-md); }
.account-summary { padding: .65rem .7rem .72rem; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.account-summary span { display: block; color: var(--text-secondary); font-size: .76rem; }
.account-summary strong { display: block; overflow: hidden; text-overflow: ellipsis; }
.account-menu button { display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 44px; padding: .55rem .7rem; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; }
.account-menu button:hover { background: var(--surface-subtle); }
.account-menu .menu-danger { color: var(--danger); }

.content { width: min(100% - 32px, var(--content)); margin: 0 auto; padding: 44px 0 calc(110px + env(safe-area-inset-bottom)); }
.page { display: none; }
.page.active { display: block; animation: page-in .18s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 28px; }
.page-heading .button { flex: 0 0 auto; }

label { display: grid; min-width: 0; gap: .43rem; color: var(--text-secondary); font-size: .86rem; font-weight: 720; }
input, select, textarea { width: 100%; min-width: 0; max-width: 100%; font-size: 1rem; }
input, select { height: 48px; min-height: 48px; padding: .72rem .82rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
input::placeholder { color: var(--text-tertiary); opacity: 1; }
input:hover, select:hover { border-color: var(--primary); }
.select-control { position: relative; display: block; color: var(--text); }
.select-control select { appearance: none; padding-right: 44px; }
.select-control .icon { position: absolute; top: 50%; right: 13px; width: 18px; height: 18px; transform: translateY(-50%); pointer-events: none; }
.date-control { display: flex; align-items: center; width: 100%; min-width: 0; height: 48px; min-height: 48px; padding: 0 .82rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.date-control:hover { border-color: var(--primary); }
.date-control:focus-within { outline: 3px solid var(--focus); outline-offset: 3px; }
.date-control input[type="date"], .date-control input[type="month"] { display: block; width: 100%; min-width: 0; max-width: 100%; height: auto; min-height: 0; padding: 0; border: 0; border-radius: 0; outline: 0; background: transparent; color: inherit; }
.stack { display: grid; gap: 1rem; }
.stack.compact { gap: .85rem; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.optional { color: var(--text-tertiary); font-weight: 550; }
.field-help { color: var(--text-tertiary); font-size: .75rem; font-weight: 560; line-height: 1.35; }

.entry-panel { width: min(100%, 680px); padding: clamp(22px, 5vw, 38px); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.amount-label { margin-bottom: .45rem; }
.amount-field { display: flex; align-items: center; margin-bottom: 1.35rem; border-bottom: 2px solid var(--border-strong); color: var(--text); }
.amount-field:focus-within { border-color: var(--primary); box-shadow: 0 2px 0 var(--primary); }
.amount-field > span { color: var(--primary); font-size: clamp(2rem, 7vw, 3.3rem); font-weight: 750; }
.amount-field input { height: auto; min-height: 74px; padding: .2rem .5rem; border: 0; border-radius: 0; background: transparent; font-size: clamp(2.5rem, 10vw, 4.8rem); font-weight: 760; line-height: 1; letter-spacing: -.055em; }
.amount-field input:focus { outline: none; }
.date-shortcuts { display: flex; gap: .55rem; margin: .75rem 0 1rem; }
.date-shortcuts button { min-height: 36px; padding: .35rem .75rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-subtle); color: var(--text-secondary); font-size: .82rem; font-weight: 750; }
.date-shortcuts button.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.button { display: inline-flex; align-items: center; justify-content: center; justify-self: start; flex: 0 0 auto; gap: .55rem; height: 48px; min-height: 48px; padding: 0 1rem; border: 1px solid transparent; border-radius: var(--radius-sm); font-weight: 780; line-height: 1; white-space: nowrap; }
.button.full { width: 100%; justify-self: stretch; }
.button.primary { background: var(--primary); color: var(--on-primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button.secondary:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.button.danger { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); background: var(--danger-soft); color: var(--danger); }
.submit-expense { height: 52px; min-height: 52px; margin-top: 1.25rem; font-size: 1rem; }
.text-button { min-height: 44px; padding: 0 .2rem; border: 0; background: transparent; color: var(--primary); font-weight: 790; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.button-row { display: flex; flex-wrap: wrap; gap: .7rem; }
.button-row.split { justify-content: space-between; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin: 38px 0 14px; }
.section-heading .eyebrow { margin-bottom: .18rem; }
.expense-list, .history-list { display: grid; gap: 8px; }
.expense-row { display: grid; grid-template-columns: 5px minmax(0, 1fr) auto; align-items: center; gap: .9rem; width: 100%; min-height: 72px; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); text-align: left; box-shadow: var(--shadow-sm); }
.expense-row:hover { border-color: var(--border-strong); background: var(--surface-raised); }
.expense-dot { width: 5px; height: 40px; border-radius: 99px; background: var(--category); }
.expense-copy, .expense-amount { display: grid; min-width: 0; }
.expense-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .98rem; }
.expense-copy span, .expense-amount small { overflow: hidden; color: var(--text-secondary); font-size: .78rem; font-weight: 560; text-overflow: ellipsis; white-space: nowrap; }
.expense-amount { justify-items: end; font-size: 1.02rem; font-weight: 820; font-variant-numeric: tabular-nums; }
.empty-state { display: grid; place-items: center; min-height: 128px; padding: 1.5rem; border: 1px dashed var(--border-strong); border-radius: var(--radius-md); color: var(--text-secondary); text-align: center; }

.month-toolbar { display: grid; grid-template-columns: 44px minmax(170px, 240px) 44px; justify-content: center; gap: .55rem; margin-bottom: 16px; }
.month-toolbar input { text-align: center; font-weight: 750; }
.history-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 20px; padding: 15px 18px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-subtle); color: var(--text-secondary); }
.history-summary strong { color: var(--text); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.history-day { margin: 24px 0 8px; color: var(--text-secondary); font-size: .82rem; font-weight: 800; letter-spacing: .03em; }
.history-day:first-child { margin-top: 0; }

.filter-panel { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.report-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: .8rem; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.stat { min-height: 120px; padding: 19px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.stat span { display: block; color: var(--text-secondary); font-size: .82rem; font-weight: 720; }
.stat strong { display: block; margin-top: .35rem; font-size: clamp(1.4rem, 3vw, 2rem); line-height: 1.2; font-variant-numeric: tabular-nums; }
.panel { padding: clamp(18px, 4vw, 28px); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.panel + .panel { margin-top: 14px; }
.panel > .section-heading { margin: 0 0 24px; }
.bar-chart { display: grid; gap: 18px; }
.bar-row { display: grid; grid-template-columns: 150px minmax(120px, 1fr) 105px; align-items: center; gap: 16px; min-height: 28px; }
.bar-row > span:first-child { font-size: .9rem; font-weight: 680; white-space: nowrap; }
.bar-track { height: 10px; overflow: hidden; border-radius: 99px; background: var(--surface-subtle); }
.bar-fill { height: 100%; min-width: 6px; border-radius: inherit; background: var(--category); }
.bar-value { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.line-chart svg { display: block; width: 100%; min-height: 220px; }
.chart-grid { stroke: var(--border-strong); stroke-width: 1; }
.chart-area { fill: var(--primary-soft); opacity: .75; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: var(--surface); stroke: var(--primary); stroke-width: 3; }
.chart-label { fill: var(--text-secondary); font-size: 12px; }
.month-row { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid var(--border); }
.month-row:last-child { border-bottom: 0; }
.month-row small { color: var(--text-tertiary); }
.month-row strong { font-variant-numeric: tabular-nums; }

.settings-heading { align-items: center; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-grid .panel + .panel { margin-top: 0; }
.settings-section-heading { display: flex; align-items: flex-start; gap: .8rem; margin-bottom: 1.25rem; }
.settings-section-heading p { margin: .2rem 0 0; color: var(--text-secondary); font-size: .86rem; }
.section-icon { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto; border-radius: 10px; background: var(--primary-soft); color: var(--primary); }
.member-list { display: grid; gap: 7px; }
.member { display: flex; align-items: center; justify-content: space-between; min-height: 46px; padding: .5rem .7rem; border-radius: var(--radius-sm); background: var(--surface-subtle); }
.member strong { font-size: .9rem; }
.member span:last-child { color: var(--text-secondary); font-size: .74rem; font-weight: 780; text-transform: capitalize; }
.disclosure { margin-top: .8rem; border-top: 1px solid var(--border); }
.disclosure summary { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 52px; margin-top: 6px; padding: .45rem .6rem; border-radius: var(--radius-sm); color: var(--primary); font-weight: 780; list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary:hover { background: var(--primary-soft); }
.disclosure summary .icon { width: 18px; height: 18px; transition: transform .16s ease; }
.disclosure[open] summary .icon { transform: rotate(180deg); }
.disclosure form { padding: .8rem .6rem .25rem; border-top: 1px solid var(--border); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: .8rem; min-width: 0; min-height: 48px; }
.form-status { min-width: 0; flex: 1 1 auto; color: var(--primary); font-size: .82rem; font-weight: 700; line-height: 1.35; }
.inset-form { margin-top: 1rem; padding: 1rem; border-radius: var(--radius-sm); background: var(--surface-subtle); }

.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 430px); padding: clamp(26px, 7vw, 44px); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-md); }
.auth-card h1 { margin-bottom: .7rem; }
.notice { padding: .8rem; border-left: 4px solid var(--primary); background: var(--primary-soft); color: var(--text); font-size: .88rem; }
.form-error { min-height: 1.35em; margin: .2rem 0 0; color: var(--danger); font-size: .86rem; font-weight: 650; }

.bottom-nav { position: fixed; z-index: 15; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, minmax(72px, 1fr)); width: min(calc(100% - 24px), 520px); padding: 6px; transform: translateX(-50%); border: 1px solid var(--border); border-radius: 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow-md); backdrop-filter: blur(18px); }
.bottom-nav button { display: grid; place-items: center; gap: 2px; min-height: 54px; padding: 5px 8px; border: 0; border-radius: 11px; background: transparent; color: var(--text-secondary); font-size: .7rem; font-weight: 760; }
.bottom-nav button.active { background: var(--primary-soft); color: var(--primary); }
.bottom-nav .icon { width: 22px; height: 22px; }

dialog { width: min(calc(100% - 28px), 500px); max-height: calc(100vh - 40px); overflow: auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-md); }
dialog::backdrop { background: rgba(4, 12, 9, .58); backdrop-filter: blur(3px); }
dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-copy { color: var(--text-secondary); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: .72rem 1rem; transform: translate(-50%, 12px); border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 760; opacity: 0; pointer-events: none; transition: .18s ease; box-shadow: var(--shadow-md); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 720px) {
  .topbar { min-height: 68px; padding: 9px 16px; }
  .brand-icon { display: none; }
  .content { width: min(100% - 24px, var(--content)); padding-top: 28px; }
  .page-heading { margin-bottom: 22px; }
  .field-grid, .settings-grid { grid-template-columns: 1fr; }
  .settings-heading { align-items: end; }
  .settings-heading .button { padding-inline: .75rem; }
  .report-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-toolbar .button { grid-column: 1 / -1; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat:first-child { grid-column: 1 / -1; }
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 440px) {
  h1 { font-size: 2rem; }
  .household-picker { max-width: 45vw; }
  .report-toolbar { grid-template-columns: 1fr; }
  .account-menu { position: fixed; top: 68px; right: 12px; }
  .entry-panel { padding: 20px 16px; }
  .amount-field input { min-width: 0; }
  .settings-heading { display: grid; }
  .settings-heading .button { width: 100%; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .form-status:not(:empty) { flex-basis: 100%; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat:first-child { grid-column: auto; }
  .bottom-nav { bottom: 0; width: 100%; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 16px 16px 0 0; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }
}

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