:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.975 0.004 75);
  --surface-raised: oklch(0.995 0.001 75);
  --ink: oklch(0.245 0.025 48);
  --muted: oklch(0.49 0.024 48);
  --line: oklch(0.88 0.012 70);
  --primary: oklch(0.57 0.14 58);
  --primary-hover: oklch(0.49 0.14 58);
  --accent: oklch(0.42 0.09 165);
  --success: oklch(0.48 0.12 151);
  --warning: oklch(0.66 0.15 75);
  --danger: oklch(0.52 0.18 26);
  --danger-bg: oklch(0.97 0.02 25);
  --focus: oklch(0.57 0.14 58 / 0.32);
  --shadow: 0 10px 30px oklch(0.24 0.025 48 / 0.08);
  --radius: 8px;
  --sidebar-width: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; }
button:disabled, input:disabled, select:disabled { cursor: not-allowed; opacity: 0.6; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, p { margin: 0; }
h1, h2 { letter-spacing: 0; text-wrap: balance; }
h1 { max-width: 18ch; font-size: 30px; line-height: 1.16; font-weight: 720; }
h2 { font-size: 18px; line-height: 1.28; font-weight: 700; }
small { display: block; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { display: grid; min-height: 100vh; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; display: flex; width: var(--sidebar-width); flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); padding: 22px 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 18px; font-weight: 760; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 8px; background: var(--primary); color: var(--bg); font-size: 16px; font-weight: 850; }
.workspace-menu { margin: 30px 0 18px; }
.workspace-label, .section-label { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.workspace-menu details { margin-top: 5px; }
.workspace-menu summary { display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; font-weight: 700; }
.workspace-menu summary::-webkit-details-marker { display: none; }
.workspace-menu summary::after { content: "+"; color: var(--muted); font-size: 18px; font-weight: 400; }
.workspace-menu details[open] summary::after { content: "-"; }
.workspace-list { display: grid; gap: 4px; margin-top: 10px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); box-shadow: var(--shadow); }
.workspace-list a { padding: 7px 8px; border-radius: 5px; color: var(--ink); font-weight: 600; }
.workspace-list a[aria-current="true"] { background: oklch(0.93 0.035 64); color: var(--primary-hover); }
.side-nav { display: grid; gap: 3px; }
.side-nav a, .side-bottom > a, .quiet-button { display: flex; min-height: 40px; align-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 0 10px; font-weight: 650; text-align: left; text-decoration: none; }
.side-nav a:hover, .side-bottom > a:hover, .quiet-button:hover { background: oklch(0.93 0.009 70); color: var(--ink); text-decoration: none; }
.side-nav a.active { background: oklch(0.93 0.035 64); color: var(--primary-hover); }
.side-bottom { display: grid; gap: 3px; margin-top: auto; }
.side-bottom form { margin: 0; }
.quiet-button { width: 100%; }
.main-content { grid-column: 2; width: min(1280px, 100%); padding: 44px 48px 64px; }

.messages { position: fixed; z-index: 30; top: 16px; right: 16px; display: grid; gap: 8px; width: min(390px, calc(100vw - 32px)); }
.message { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); padding: 12px 14px; box-shadow: var(--shadow); font-weight: 600; }
.message.success { border-color: oklch(0.78 0.08 151); color: oklch(0.32 0.08 151); }
.message.error { border-color: oklch(0.78 0.1 26); color: var(--danger); }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-header .section-label { margin-bottom: 8px; color: var(--primary-hover); }
.intro { max-width: 65ch; margin-top: 9px; color: var(--muted); font-size: 15px; text-wrap: pretty; }
.header-total { display: grid; gap: 3px; padding-bottom: 4px; text-align: right; }
.header-total span { color: var(--muted); font-size: 12px; }
.header-total strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 7px; padding: 0 14px; font-weight: 720; text-decoration: none; transition: background 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out, transform 180ms ease-out; }
.button:hover { text-decoration: none; }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--primary); color: var(--bg); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border-color: var(--line); background: var(--surface-raised); color: var(--ink); }
.button.secondary:hover { border-color: var(--muted); }

.net-worth-band { display: flex; align-items: center; justify-content: space-between; gap: 32px; margin-bottom: 24px; border: 1px solid oklch(0.84 0.06 60); border-radius: var(--radius); background: oklch(0.965 0.02 66); padding: 24px; }
.net-worth-band p { color: oklch(0.42 0.09 54); font-size: 13px; font-weight: 700; }
.net-worth-band strong { display: block; margin: 5px 0 2px; font-size: 30px; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.net-worth-band span { color: var(--muted); }
.net-worth-breakdown { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)); gap: 20px; margin: 0; }
.net-worth-breakdown div { display: grid; gap: 3px; }
.net-worth-breakdown dt { color: var(--muted); font-size: 12px; }
.net-worth-breakdown dd { margin: 0; font-weight: 720; font-variant-numeric: tabular-nums; }
.support-note { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 16px 0; }
.support-mark { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: var(--accent); color: var(--bg); font-weight: 800; }
.support-note p { color: var(--muted); }
.support-note strong { display: block; margin-top: 2px; }
.support-note > a { margin-left: auto; font-weight: 700; white-space: nowrap; }

.dashboard-grid, .split-grid, .settings-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr); gap: 20px; }
.lower-grid { margin-top: 20px; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr); }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); padding: 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading .section-label { margin-bottom: 5px; }
.panel-heading > a { font-weight: 700; white-space: nowrap; }
.chart-key { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 12px; }
.chart-key span::before { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; content: ""; }
.income-key::before { background: var(--success); }
.expense-key::before { background: var(--primary); }
.bar-chart { display: grid; height: 190px; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; align-items: end; padding: 12px 4px 0; border-bottom: 1px solid var(--line); }
.chart-day { display: grid; min-width: 0; gap: 6px; text-align: center; color: var(--muted); font-size: 11px; }
.bar-set { display: flex; height: 154px; align-items: end; justify-content: center; gap: 3px; }
.bar { width: min(13px, 34%); min-height: 0; border-radius: 4px 4px 0 0; transition: height 180ms ease-out; }
.income-bar { background: var(--success); }
.expense-bar { background: var(--primary); }
.chart-summary { display: flex; flex-wrap: wrap; gap: 12px 20px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.chart-summary strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.progress-list, .goal-list { display: grid; gap: 16px; }
.progress-row { display: grid; gap: 7px; }
.progress-row > div:first-child, .budget-title, .budget-foot, .goal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress-row strong, .budget-title b { font-variant-numeric: tabular-nums; }
.progress-row small { font-size: 12px; }
.progress-track, .goal-progress, .large-progress { height: 7px; overflow: hidden; border-radius: 999px; background: oklch(0.92 0.01 70); }
.progress-fill, .goal-progress span, .large-progress span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.progress-fill.over { background: var(--danger); }
.empty-inline, .empty-state { color: var(--muted); }
.empty-inline { display: grid; gap: 12px; padding: 16px 0 2px; }
.empty-state { display: grid; min-height: 150px; place-content: center; gap: 7px; text-align: center; }
.goal-row { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(70px, 1.1fr) auto; }
.goal-row > div:first-child { display: grid; gap: 3px; }
.goal-row span { color: var(--muted); font-size: 12px; }
.goal-row b { color: var(--primary-hover); font-size: 12px; }
.account-list, .resource-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.account-list li, .resource-list li { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); padding: 10px 0; }
.account-list li:first-child, .resource-list li:first-child { border-top: 0; padding-top: 0; }
.account-list li span, .resource-list li > div:first-child { display: grid; gap: 2px; }
.account-list small, .resource-list span { font-size: 12px; }
.account-list strong, .resource-actions b { font-variant-numeric: tabular-nums; }

.entry-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(240px, 0.55fr); gap: 24px; align-items: start; }
.entry-aside, .guidance { display: grid; gap: 10px; padding: 22px 8px; color: var(--muted); }
.entry-aside h2, .guidance h2 { color: var(--ink); }
.entry-aside .section-label, .guidance .section-label { color: var(--primary-hover); }
.transaction-form { display: grid; gap: 16px; }
.stack-form { display: grid; gap: 8px; }
.stack-form label, .transaction-form label { font-size: 13px; font-weight: 680; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.two > div { display: grid; gap: 8px; }
input, select { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); padding: 9px 10px; }
input::placeholder { color: oklch(0.44 0.02 48); }
input:hover, select:hover { border-color: oklch(0.67 0.025 60); }
input:focus, select:focus { border-color: var(--primary); outline: 3px solid var(--focus); outline-offset: 0; }
.money-entry { display: grid; gap: 8px; }
.money-entry input { min-height: 56px; font-size: 24px; font-weight: 720; font-variant-numeric: tabular-nums; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.keypad button { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-weight: 700; }
.keypad button:hover { background: oklch(0.93 0.014 70); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; }
.field-error, .errorlist { margin: 0; padding: 0; color: var(--danger); font-size: 12px; list-style: none; }
.form-errors { border: 1px solid oklch(0.8 0.1 26); border-radius: 6px; background: var(--danger-bg); padding: 10px; color: var(--danger); }
.checkbox-label { display: flex; min-height: 42px; align-items: center; gap: 9px; }
.checkbox-label input { width: 18px; min-height: 18px; }
.list-panel { margin-top: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 660px; }
th { border-bottom: 1px solid var(--line); padding: 0 8px 9px; color: var(--muted); font-size: 12px; font-weight: 650; text-align: left; }
td { border-bottom: 1px solid var(--line); padding: 12px 8px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td small { margin-top: 2px; }
.type-badge { display: inline-flex; border-radius: 999px; padding: 3px 7px; font-size: 11px; font-weight: 700; }
.type-badge.income { background: oklch(0.94 0.04 151); color: oklch(0.32 0.08 151); }
.type-badge.expense { background: oklch(0.95 0.035 26); color: var(--danger); }
.type-badge.transfer { background: oklch(0.93 0.018 220); color: oklch(0.36 0.04 220); }
.transfer-to { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.money { font-weight: 720; font-variant-numeric: tabular-nums; white-space: nowrap; }
.negative { color: var(--danger); }
.row-actions, .resource-actions, .goal-card-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.row-actions form, .resource-actions form, .goal-card-actions form { margin: 0; }
.row-actions a, .resource-actions a, .goal-card-actions a, .danger-link { border: 0; background: transparent; padding: 0; color: var(--accent); font-size: 12px; font-weight: 700; }
.danger-link { color: var(--danger); }
.danger-link:hover { text-decoration: underline; }

.budget-table { display: grid; gap: 18px; }
.budget-row { display: grid; gap: 9px; border-top: 1px solid var(--line); padding-top: 17px; }
.budget-row:first-child { border-top: 0; padding-top: 0; }
.budget-title > div { display: grid; gap: 2px; }
.budget-title span, .budget-foot span { color: var(--muted); font-size: 12px; }
.budget-foot { align-items: flex-start; }

.goal-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 18px; }
.goal-card { display: grid; gap: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); padding: 20px; }
.goal-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.goal-card-top .section-label { margin-bottom: 4px; }
.goal-card-top > strong { color: var(--primary-hover); font-size: 22px; font-variant-numeric: tabular-nums; }
.large-progress { height: 9px; }
.goal-numbers { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.goal-numbers b { color: var(--ink); font-variant-numeric: tabular-nums; }
.contribution { border-top: 1px solid var(--line); padding-top: 12px; }
.contribution summary { cursor: pointer; color: var(--accent); font-weight: 720; }
.contribution-form { display: grid; gap: 8px; margin-top: 14px; }
.contribution-form label { font-size: 12px; font-weight: 650; }
.goal-card-actions { justify-content: flex-start; }
.full-width { grid-column: 1 / -1; }

.help-text { color: var(--muted); font-size: 12px; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.integration-panel { grid-column: 1 / -1; max-width: 680px; }
.integration-status { display: grid; gap: 6px; margin-bottom: 16px; }
.integration-status span { width: fit-content; border-radius: 999px; background: oklch(0.94 0.02 76); padding: 3px 8px; color: oklch(0.42 0.06 64); font-size: 11px; font-weight: 700; }

.auth-body { display: grid; min-height: 100vh; place-items: center; background: var(--surface); padding: 24px; }
.auth-shell { width: min(440px, 100%); }
.auth-brand { margin-bottom: 22px; }
.auth-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-raised); padding: 28px; box-shadow: var(--shadow); }
.auth-panel .intro { margin-bottom: 24px; }
.auth-panel .secondary-copy { margin-top: 20px; color: var(--muted); }
.auth-footnote { margin-top: 18px; color: var(--muted); text-align: center; }
.auth-panel .errorlist { margin-top: -4px; }

.mobile-nav { display: none; }

@media (max-width: 1020px) {
  .main-content { padding: 36px 30px 56px; }
  .net-worth-band { align-items: flex-start; flex-direction: column; }
  .net-worth-breakdown { width: 100%; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-content { width: 100%; padding: 28px 18px 88px; }
  .mobile-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); background: var(--surface-raised); box-shadow: 0 -8px 20px oklch(0.24 0.025 48 / 0.06); padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { display: grid; min-height: 46px; place-items: center; border-radius: 6px; color: var(--muted); font-size: 11px; font-weight: 700; text-align: center; text-decoration: none; }
  .mobile-nav a.active { background: oklch(0.93 0.035 64); color: var(--primary-hover); }
  .dashboard-grid, .split-grid, .settings-grid, .entry-layout { grid-template-columns: 1fr; }
  .entry-aside, .guidance { order: -1; padding: 0; }
  .lower-grid { grid-template-columns: 1fr; }
  .settings-grid .integration-panel { grid-column: auto; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 15px; }
  .header-total { padding: 0; text-align: left; }
  .add-transaction { width: 100%; }
  .goal-cards { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  body { font-size: 13px; }
  .main-content { padding: 24px 14px 82px; }
  h1 { font-size: 26px; }
  h2 { font-size: 17px; }
  .panel, .goal-card { padding: 16px; }
  .net-worth-band { margin-right: -2px; margin-left: -2px; padding: 18px; }
  .net-worth-band strong { font-size: 26px; }
  .net-worth-breakdown { grid-template-columns: 1fr; gap: 11px; }
  .net-worth-breakdown div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .support-note { align-items: flex-start; }
  .support-note > a { display: none; }
  .panel-heading { margin-bottom: 14px; }
  .form-grid.two { grid-template-columns: 1fr; }
  .goal-row { grid-template-columns: 1fr auto; }
  .goal-row .goal-progress { grid-column: 1 / -1; grid-row: 2; }
  .budget-foot { align-items: flex-start; flex-direction: column; }
  .resource-list li { align-items: flex-start; flex-direction: column; }
  .resource-actions { justify-content: flex-start; }
  .row-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
