:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-2: #eef2eb;
  --surface-3: #e4eadf;
  --text: #18201b;
  --muted: #637067;
  --line: #dce4da;
  --primary: #2d6a4f;
  --primary-strong: #1f513b;
  --primary-soft: #dcefe4;
  --button-primary: #2d6a4f;
  --button-primary-hover: #1f513b;
  --accent: #d99a35;
  --danger: #b84a4a;
  --danger-soft: #f8e5e5;
  --button-danger: #a43f3f;
  --positive: #287a57;
  --negative: #c05a4b;
  --shadow: 0 14px 40px rgba(41, 63, 48, .08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --sidebar: 232px;
  --font: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101511;
  --surface: #171e19;
  --surface-2: #202922;
  --surface-3: #29342c;
  --text: #edf3ee;
  --muted: #a3afa6;
  --line: #2d3930;
  --primary: #72b991;
  --primary-strong: #9ad0af;
  --primary-soft: #213d2d;
  --button-primary: #347153;
  --button-primary-hover: #285e45;
  --accent: #e0a84e;
  --danger: #ed8b8b;
  --danger-soft: #402525;
  --button-danger: #943a3a;
  --positive: #80c9a0;
  --negative: #ef998d;
  --shadow: 0 14px 40px rgba(0, 0, 0, .25);
}

[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #10151a;
  --surface: #171e26;
  --surface-2: #202a35;
  --surface-3: #2a3644;
  --text: #eef4fa;
  --muted: #a1afbf;
  --line: #2b3949;
  --primary: #8ab8ff;
  --primary-strong: #b6d1ff;
  --primary-soft: #1d3351;
  --button-primary: #396fae;
  --button-primary-hover: #2e5d94;
  --accent: #e3ad58;
  --danger: #f19a99;
  --danger-soft: #442829;
  --button-danger: #98454a;
  --positive: #7fd2ab;
  --negative: #ef9a94;
  --shadow: 0 18px 44px rgba(0, 0, 0, .34);
}

[data-theme="sand"] {
  color-scheme: light;
  --bg: #f5efe4;
  --surface: #fffdf8;
  --surface-2: #f0e6d5;
  --surface-3: #e8dac4;
  --text: #2b241c;
  --muted: #766859;
  --line: #e5d8c4;
  --primary: #9b5f3e;
  --primary-strong: #75432b;
  --primary-soft: #f3dfd0;
  --button-primary: #9b5f3e;
  --button-primary-hover: #75432b;
  --accent: #c08839;
  --danger: #ad4c45;
  --danger-soft: #f8e3df;
  --button-danger: #a03e3d;
  --positive: #377454;
  --negative: #ae5148;
  --shadow: 0 16px 42px rgba(93, 62, 34, .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-shell { min-height: 100vh; }
.desktop-sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 20;
  width: var(--sidebar); padding: 28px 20px;
  display: flex; flex-direction: column;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--button-primary); color: #fff; }
.brand-mark svg { width: 20px; height: 20px; }
.side-nav { display: grid; gap: 7px; margin-top: 48px; }
.nav-link { min-height: 48px; padding: 0 14px; display: flex; align-items: center; gap: 13px; border-radius: 13px; color: var(--muted); font-weight: 600; transition: background .2s, color .2s; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary-strong); }
.nav-link svg { width: 20px; height: 20px; }
.sidebar-foot { margin-top: auto; padding: 14px 4px 0; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot p { margin: 0; max-width: 125px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.main-content { min-height: 100vh; margin-left: var(--sidebar); }
.page { max-width: 1240px; margin: 0 auto; padding: 42px 42px 72px; }
.mobile-header, .bottom-nav, .fab { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 13px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(28px, 3vw, 40px); line-height: 1.15; letter-spacing: -.045em; }
h2 { margin: 0; font-size: 20px; line-height: 1.3; letter-spacing: -.02em; }
h3 { margin: 0; font-size: 16px; }
.subtle { margin: 7px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.button { min-height: 44px; border: 1px solid transparent; border-radius: 12px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--button-primary); color: #fff; font-weight: 700; cursor: pointer; transition: background .2s, border-color .2s, transform .2s; }
.button:hover { background: var(--button-primary-hover); }
.button:active { transform: translateY(1px); }
.button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.button.secondary:hover { background: var(--surface-2); }
.button.danger { background: var(--button-danger); }
.button.ghost { background: transparent; color: var(--muted); }
.button.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.button svg { width: 18px; height: 18px; }
.icon-button { width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; background: var(--surface); cursor: pointer; transition: background .2s, color .2s; }
.icon-button:hover { background: var(--surface-2); color: var(--primary); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .8fr); gap: 20px; }
.hero-card { position: relative; min-height: 282px; padding: 30px; overflow: hidden; color: #f7fff9; background: #285e47; border-color: transparent; }
.hero-card::after { content: ""; position: absolute; width: 340px; height: 340px; right: -125px; top: -180px; border: 70px solid rgba(255,255,255,.07); border-radius: 50%; }
.hero-card .label { color: rgba(255,255,255,.72); }
.amount-xl { margin: 13px 0 9px; font-size: clamp(38px, 5vw, 58px); font-weight: 760; line-height: 1; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.delta-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border-radius: 999px; background: rgba(255,255,255,.14); font-size: 13px; font-weight: 700; }
.hero-meta { position: absolute; z-index: 1; left: 30px; right: 30px; bottom: 27px; display: flex; justify-content: space-between; gap: 18px; }
.hero-meta-item span { display: block; color: rgba(255,255,255,.65); font-size: 12px; }
.hero-meta-item strong { display: block; margin-top: 3px; font-size: 16px; font-variant-numeric: tabular-nums; }
.summary-stack { display: grid; gap: 14px; }
.metric-card { min-height: 126px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 14px; }
.metric-value { font-size: 25px; font-weight: 740; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.metric-note { color: var(--muted); font-size: 12px; }
.metric-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--primary-soft); color: var(--primary); }

.section-card { margin-top: 20px; padding: 25px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.segment { min-height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 650; }
.segment.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.chart-wrap { position: relative; min-height: 230px; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 3; vector-effect: non-scaling-stroke; }
.chart-area { fill: url(#areaGradient); }
.chart-dot { fill: var(--surface); stroke: var(--primary); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart-axis { fill: var(--muted); font: 11px var(--font); }
.chart-empty, .empty-state { min-height: 220px; display: grid; place-items: center; text-align: center; padding: 30px; }
.empty-inner { max-width: 380px; }
.empty-icon { width: 54px; height: 54px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 17px; background: var(--primary-soft); color: var(--primary); }
.empty-icon svg { width: 26px; height: 26px; }
.empty-state h3 { margin-bottom: 6px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

.accounts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.account-tile { padding: 17px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.account-tile-top { display: flex; align-items: center; gap: 10px; }
.account-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.account-name { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-category { color: var(--muted); font-size: 12px; }
.account-amount { margin-top: 16px; font-size: 20px; font-weight: 720; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.progress { height: 5px; margin-top: 12px; border-radius: 9px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; }

.toolbar { margin-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.select, .input, .textarea { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); transition: border-color .2s, box-shadow .2s; }
.select { width: auto; padding-right: 35px; cursor: pointer; }
.textarea { min-height: 88px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: color-mix(in srgb, var(--muted) 72%, transparent); }
.field { display: grid; gap: 7px; }
.field > label { font-size: 13px; font-weight: 700; }
.field-help { color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-prefix .input { padding-left: 32px; font-variant-numeric: tabular-nums; }
.snapshot-list { display: grid; gap: 12px; }
.snapshot-item { padding: 18px 20px; display: grid; grid-template-columns: 120px minmax(160px, 1fr) repeat(4, minmax(105px, auto)) 46px; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.snapshot-date strong, .snapshot-total strong { display: block; }
.snapshot-date span, .snapshot-total span, .snapshot-stat span { color: var(--muted); font-size: 12px; }
.snapshot-stat strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.snapshot-note { min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }

.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 13px; margin-bottom: 20px; }
.stat-card { padding: 19px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 23px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.charts-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .8fr); gap: 20px; }
.charts-grid .section-card { margin-top: 0; }
.detail-charts-grid { margin-top: 20px; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); }
.donut-layout { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 20px; }
.donut { width: 150px; height: 150px; border-radius: 50%; position: relative; }
.donut::after { content: ""; position: absolute; inset: 29px; border-radius: 50%; background: var(--surface); }
.donut-center { position: absolute; z-index: 1; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center strong { font-size: 18px; }
.donut-center span { color: var(--muted); font-size: 11px; }
.legend { display: grid; gap: 9px; }
.legend-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; font-size: 13px; }
.legend-item i { width: 9px; height: 9px; border-radius: 50%; }
.legend-item span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item strong { font-variant-numeric: tabular-nums; }
.period-list { display: grid; gap: 8px; }
.period-row { display: grid; grid-template-columns: 100px 1fr 1fr 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.period-row:last-child { border: 0; }
.period-row.header { color: var(--muted); font-size: 12px; }
.bar-track { height: 8px; border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--primary); }
.cashflow-legend { display: flex; gap: 16px; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.cashflow-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cashflow-legend i { width: 9px; height: 9px; border-radius: 3px; }
.income-dot, .cashflow-income { fill: var(--primary); background: var(--primary); }
.expense-dot, .cashflow-expense { fill: var(--negative); background: var(--negative); }
.account-change-list { display: grid; gap: 15px; }
.account-change { display: grid; grid-template-columns: 118px minmax(90px, 1fr) auto; align-items: center; gap: 12px; font-size: 13px; }
.account-change > div:first-child { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-change > div:first-child span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.change-track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.change-track i { display: block; height: 100%; border-radius: inherit; background: var(--positive); }
.change-track.down i { background: var(--negative); }
.account-change strong { font-variant-numeric: tabular-nums; white-space: nowrap; }

.manage-list { display: grid; gap: 10px; }
.manage-item { min-height: 70px; padding: 12px 14px; display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; }
.manage-item .meta { color: var(--muted); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.settings-card { padding: 24px; }
.settings-card h2 { margin-bottom: 5px; }
.settings-card > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.action-list { display: grid; gap: 10px; }
.action-row { min-height: 60px; padding: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }
.action-row:last-child { border: 0; }
.action-row strong { display: block; font-size: 14px; }
.action-row span { display: block; color: var(--muted); font-size: 12px; }
.info-box { padding: 14px; display: flex; gap: 10px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-strong); font-size: 13px; }
.info-box svg { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; }
.reminder-notice { min-height: 64px; margin: -4px 0 18px; padding: 12px 14px 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line)); border-radius: 16px; background: var(--primary-soft); color: var(--primary-strong); }
.reminder-notice > div { display: flex; align-items: center; gap: 11px; font-size: 13px; line-height: 1.45; }
.reminder-notice svg { width: 20px; height: 20px; flex: 0 0 auto; }
.reminder-notice strong { display: block; }
.budget-card { margin-top: 20px; padding: 19px 21px; }
.budget-card.over { border-color: color-mix(in srgb, var(--negative) 42%, var(--line)); }
.budget-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.budget-card .label { display: block; color: var(--muted); font-size: 13px; }
.budget-card strong { display: block; margin-top: 4px; font-size: 23px; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.budget-card strong small { color: var(--muted); font-size: 14px; font-weight: 650; letter-spacing: 0; }
.budget-card p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.budget-progress { height: 7px; margin-top: 17px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.budget-progress i { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.budget-card.over .budget-progress i { background: var(--negative); }
.budget-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.budget-list div { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.budget-list strong { margin: 0; color: var(--text); font-size: 12px; letter-spacing: 0; }
.budget-form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.budget-field { padding: 12px; display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 13px; font-size: 13px; font-weight: 700; }
.budget-field .input { min-height: 42px; }
.toggle-row { min-height: 64px; padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.toggle-row span { display: grid; gap: 3px; }
.toggle-row small { color: var(--muted); font-size: 12px; font-weight: 400; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-row i { width: 44px; height: 25px; position: relative; flex: 0 0 auto; border-radius: 99px; background: var(--line); transition: background .2s; }
.toggle-row i::after { content: ''; width: 19px; height: 19px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform .2s; }
.toggle-row input:checked + i { background: var(--primary); }
.toggle-row input:checked + i::after { transform: translateX(19px); }

.ledger-preview { padding-bottom: 12px; }
.ledger-hero { min-height: 164px; padding: 26px 28px; display: flex; align-items: center; justify-content: space-between; gap: 24px; background: linear-gradient(135deg, var(--surface) 0%, var(--primary-soft) 100%); }
.ledger-kicker { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.ledger-hero strong { display: block; margin-top: 3px; font-size: clamp(34px, 4vw, 48px); line-height: 1.1; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.ledger-hero p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.ledger-hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.transaction-list { display: grid; }
.transaction-row { min-height: 76px; padding: 12px 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto 44px; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.transaction-row:last-child { border-bottom: 0; }
.transaction-row.compact { grid-template-columns: 38px minmax(0, 1fr) auto; min-height: 64px; }
.transaction-badge { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--danger-soft); color: var(--negative); }
.transaction-badge.income { background: var(--primary-soft); color: var(--positive); }
.transaction-badge svg { width: 20px; height: 20px; }
.transaction-row.compact .transaction-badge { width: 36px; height: 36px; border-radius: 12px; }
.transaction-main { min-width: 0; display: grid; }
.transaction-main strong { font-size: 15px; }
.transaction-main span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.transaction-amount { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.transaction-edit { justify-self: end; }
.category-bars { display: grid; gap: 16px; }
.category-bar { display: grid; gap: 7px; }
.category-bar-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 13px; }
.category-bar-top span { display: inline-flex; align-items: center; gap: 8px; }
.category-bar-top i { width: 9px; height: 9px; border-radius: 50%; }
.category-bar-top strong { font-variant-numeric: tabular-nums; }

.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-card { min-height: 118px; padding: 14px; position: relative; display: grid; align-content: start; gap: 5px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); text-align: left; cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s; }
.theme-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.theme-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 22%, transparent); }
.theme-card > svg { position: absolute; top: 12px; right: 12px; width: 17px; height: 17px; color: var(--primary); }
.theme-card strong { font-size: 14px; }
.theme-card span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.theme-swatch { width: 100%; height: 30px; display: block; border-radius: 9px; background: linear-gradient(135deg, #2d6a4f 0 46%, #dcefe4 46% 100%); }
.theme-swatch.midnight { background: linear-gradient(135deg, #10151a 0 46%, #396fae 46% 100%); }
.theme-swatch.sand { background: linear-gradient(135deg, #9b5f3e 0 46%, #f3dfd0 46% 100%); }

.transaction-type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 4px; border-radius: 15px; background: var(--surface-2); }
.type-choice { min-height: 48px; border: 0; border-radius: 11px; display: flex; align-items: center; justify-content: center; gap: 8px; background: transparent; color: var(--muted); font-weight: 750; cursor: pointer; }
.type-choice.active { background: var(--surface); color: var(--text); box-shadow: 0 3px 10px rgba(0,0,0,.08); }
.type-choice.active.expense { color: var(--negative); }
.type-choice.active.income { color: var(--positive); }
.amount-entry { margin-top: 22px; }
.amount-entry label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 750; }
.amount-entry-input { min-height: 82px; padding: 0 16px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface-2); transition: border-color .2s, box-shadow .2s; }
.amount-entry-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.amount-entry-input span { color: var(--muted); font-size: 24px; font-weight: 700; }
.amount-entry-input input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 36px; font-weight: 760; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.amount-entry-input input::placeholder { color: color-mix(in srgb, var(--muted) 38%, transparent); }
.category-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.category-chip { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 650; transition: all .2s; }
.category-chip:hover { border-color: var(--primary); color: var(--primary); }
.category-chip.selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 24px; display: grid; place-items: center; background: rgba(9, 15, 11, .5); backdrop-filter: blur(5px); animation: fade-in .18s ease; }
.modal { width: min(620px, 100%); max-height: min(820px, calc(100vh - 48px)); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 28px 80px rgba(0,0,0,.25); animation: modal-in .22s ease; }
.modal.wide { width: min(760px, 100%); }
.modal-head { position: sticky; top: 0; z-index: 2; padding: 22px 24px 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 22px 24px; }
.modal-foot { position: sticky; bottom: 0; z-index: 2; padding: 16px 24px; display: flex; justify-content: flex-end; gap: 10px; background: var(--surface); border-top: 1px solid var(--line); }
.balance-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.balance-field { padding: 12px; border: 1px solid var(--line); border-radius: 13px; }
.balance-field label { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; font-weight: 650; }
.balance-field .input { min-height: 42px; }
.snapshot-preview { margin: 18px 0 0; padding: 15px; border-radius: 14px; background: var(--surface-2); display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.snapshot-preview span { display: block; color: var(--muted); font-size: 11px; }
.snapshot-preview strong { display: block; margin-top: 4px; font-size: 15px; font-variant-numeric: tabular-nums; }
.color-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.color-option { width: 34px; height: 34px; padding: 0; border: 3px solid var(--surface); border-radius: 50%; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.color-option.selected { box-shadow: 0 0 0 3px var(--text); }
.toast-root { position: fixed; z-index: 200; right: 22px; bottom: 22px; display: grid; gap: 10px; pointer-events: none; }
.toast { min-width: 250px; max-width: 360px; padding: 13px 16px; display: flex; align-items: center; gap: 10px; border-radius: 13px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); animation: toast-in .25s ease; }
.toast.error { background: var(--danger); color: #fff; }
.toast svg { flex: 0 0 auto; width: 18px; height: 18px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 1050px) {
  .accounts-grid { grid-template-columns: 1fr 1fr; }
  .snapshot-item { grid-template-columns: 105px 1fr repeat(3, 110px) 46px; }
  .snapshot-stat.adjustment { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .desktop-sidebar { display: none; }
  .main-content { margin-left: 0; }
  .mobile-header { height: 66px; padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); }
  .mobile-header .brand-mark { width: 34px; height: 34px; border-radius: 11px; }
  .page { padding: 25px 16px 30px; }
  .page-head { align-items: flex-start; margin-bottom: 22px; }
  .page-head .button.primary-action { display: none; }
  .page-actions { width: 100%; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .hero-card { min-height: 265px; padding: 25px; }
  .hero-meta { left: 25px; right: 25px; bottom: 24px; }
  .summary-stack { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 116px; padding: 17px; }
  .metric-value { font-size: 20px; }
  .metric-note { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .section-card { padding: 19px; border-radius: 20px; }
  .section-head { align-items: flex-start; }
  .section-head .segmented { flex: 0 0 auto; }
  .accounts-grid { grid-template-columns: 1fr; }
  .bottom-nav { position: fixed; z-index: 50; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); height: 64px; padding: 6px 8px; display: grid; grid-template-columns: repeat(5, 1fr); background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 12px 35px rgba(22,40,29,.18); backdrop-filter: blur(16px); }
  .bottom-nav .nav-link { min-height: 50px; padding: 5px; flex-direction: column; justify-content: center; gap: 2px; border-radius: 14px; font-size: 10px; }
  .bottom-nav .nav-link svg { width: 20px; height: 20px; }
  .fab { position: fixed; z-index: 60; right: 19px; bottom: calc(88px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border: 0; border-radius: 18px; display: grid; place-items: center; background: var(--button-primary); color: #fff; box-shadow: 0 12px 28px rgba(35, 91, 65, .28); cursor: pointer; }
  .fab svg { width: 25px; height: 25px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filter-group { display: grid; grid-template-columns: 1fr 1fr; }
  .select { width: 100%; }
  .snapshot-item { padding: 16px; grid-template-columns: 1fr auto; gap: 8px 14px; }
  .snapshot-date { grid-column: 1; }
  .snapshot-note { grid-column: 1 / -1; grid-row: 2; }
  .snapshot-total { grid-column: 2; grid-row: 1; text-align: right; }
  .snapshot-stat { padding-top: 8px; border-top: 1px solid var(--line); }
  .snapshot-stat.expense { grid-column: 1; }
  .snapshot-stat.income { grid-column: 2; text-align: right; }
  .snapshot-stat.adjustment { display: none; }
  .snapshot-item .icon-button { grid-column: 2; grid-row: 4; justify-self: end; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 16px; }
  .stat-card strong { font-size: 20px; }
  .donut-layout { grid-template-columns: 130px 1fr; gap: 14px; }
  .donut { width: 130px; height: 130px; }
  .period-row { grid-template-columns: 82px repeat(3, 1fr); gap: 8px; font-size: 12px; }
  .settings-grid { grid-template-columns: 1fr; }
  .ledger-hero { min-height: 0; padding: 21px; align-items: flex-start; flex-direction: column; }
  .ledger-hero-actions { width: 100%; }
  .ledger-hero-actions .button { flex: 1; }
  .transaction-row { grid-template-columns: 42px minmax(0, 1fr) auto; }
  .transaction-row .transaction-edit { grid-column: 3; grid-row: 2; width: 36px; height: 36px; min-height: 36px; }
  .transaction-row:not(.compact) { padding-bottom: 9px; }
  .transaction-amount { align-self: center; }
  .theme-picker { grid-template-columns: 1fr; }
  .budget-list { grid-template-columns: 1fr; }
  .budget-form-grid { grid-template-columns: 1fr; }
  .reminder-notice { align-items: flex-start; flex-direction: column; }
  .reminder-notice .button { width: 100%; }
  .account-change { grid-template-columns: 92px minmax(72px, 1fr) auto; gap: 9px; }
  .theme-card { min-height: 82px; grid-template-columns: 78px 1fr; align-items: center; column-gap: 12px; }
  .theme-card .theme-swatch { grid-row: 1 / span 2; height: 48px; }
  .theme-card strong { align-self: end; }
  .theme-card span { align-self: start; }
  .form-grid, .balance-fields { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .snapshot-preview { grid-template-columns: 1fr 1fr; }
  .snapshot-preview > div:first-child { grid-column: 1 / -1; }
  .modal-backdrop { padding: 0; place-items: end center; }
  .modal, .modal.wide { width: 100%; max-height: calc(94vh - env(safe-area-inset-bottom)); border-radius: 25px 25px 0 0; border-bottom: 0; }
  .modal-head { padding: 20px 18px 14px; }
  .modal-body { padding: 18px; }
  .modal-foot { padding: 13px 18px calc(13px + env(safe-area-inset-bottom)); }
  .toast-root { left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
}

@media (max-width: 390px) {
  .amount-xl { font-size: 36px; }
  .hero-meta { gap: 10px; }
  .hero-meta-item strong { font-size: 14px; }
  .section-head { flex-direction: column; }
  .donut-layout { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .bottom-nav .nav-link { font-size: 9px; }
  .category-chip { padding: 0 12px; }
}

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

@media print {
  .desktop-sidebar, .mobile-header, .bottom-nav, .fab, .page-actions, .toolbar { display: none !important; }
  .main-content { margin: 0; }
  .page { max-width: none; padding: 0; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
}
