:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --text: #182825;
  --muted: #536761;
  --border: #dbe5e1;
  --primary: #076a59;
  --primary-dark: #084d42;
  --primary-soft: #e3f3ee;
  --green: #117452;
  --green-soft: #e5f4ed;
  --amber: #865911;
  --amber-soft: #fbf0d9;
  --red: #a2323a;
  --red-soft: #fcecee;
  --radius: 12px;
  --shadow: 0 1px 2px #142b2310;
  --rail-bg: #152724;
  --rail-text: #e7f3ef;
  --rail-muted: #a6c1b8;
  --rail-active: #28453e;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101b19;
  --surface: #172724;
  --text: #ecf5f2;
  --muted: #abc1bb;
  --border: #304641;
  --primary: #7ed6bd;
  --primary-dark: #a4e9d4;
  --primary-soft: #203b34;
  --green: #87dbad;
  --green-soft: #244538;
  --amber: #ecc276;
  --amber-soft: #3f3422;
  --red: #ff9a9e;
  --red-soft: #472b2f;
  --shadow: none;
  --rail-bg: #0d1716;
  --rail-active: #203a34;
}

body {
  font-family: Aptos, "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: .96rem;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  flex: 1;
}

.workspace-rail {
  display: flex;
  flex-direction: column;
  gap: 2.1rem;
  min-height: 100svh;
  max-height: 100svh;
  position: sticky;
  top: 0;
  padding: 1.3rem 1rem;
  overflow: auto;
  background: var(--rail-bg);
  color: var(--rail-text);
}

.workspace-rail .brand {
  padding: .35rem .45rem;
  gap: .7rem;
  color: var(--rail-text);
}

.workspace-rail .brand-text { font-weight: 680; }
.workspace-rail .brand-text small { color: var(--rail-muted); margin-top: .22rem; }

.brand-mark {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 3px;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding-bottom: 8px;
  border-radius: 8px;
  background: #b4eedb;
}

.brand-mark i { width: 4px; height: 8px; background: #193a31; border-radius: 1px; }
.brand-mark i:nth-child(2) { height: 13px; }
.brand-mark i:nth-child(3) { height: 18px; }

.workspace-rail .main-nav { flex-direction: column; gap: .25rem; }
.workspace-rail .main-nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 42px;
  padding: .5rem .7rem;
  border-radius: 8px;
  color: var(--rail-text);
  font-weight: 550;
}

.workspace-rail .main-nav a:hover,
.workspace-rail .main-nav a.active,
.rail-tools a:hover,
.rail-tools a[aria-current] { background: var(--rail-active); color: #d9fff2; text-decoration: none; }

.workspace-rail .main-nav a.active { box-shadow: inset 3px 0 #91dfc6; }
.workspace-rail :focus-visible { outline-color: #b4eedb; }
.nav-mark { flex: 0 0 19px; font-size: 1.1rem; line-height: 1; text-align: center; color: #9ccebf; }

.rail-tools {
  display: flex;
  flex-direction: column;
  margin-top: auto;
  border-top: 1px solid var(--rail-active);
  padding-top: .6rem;
  font-size: .85rem;
}

.rail-tools a { color: var(--rail-muted); padding: .6rem .7rem; border-radius: 7px; }
.workspace-body { min-width: 0; display: flex; flex-direction: column; }
.workspace-body .container { width: min(1420px, 100% - clamp(2rem, 5vw, 5rem)); }
.workspace-body main.container { padding-block: clamp(1.2rem, 3vw, 2.25rem) 2.6rem; }
.workspace-toolbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.toolbar-inner { display: flex; min-height: 61px; align-items: center; justify-content: space-between; gap: .6rem; }
.toolbar-context { font-size: .86rem; color: var(--muted); }
.toolbar-context span { padding-inline: .35rem; }
.toolbar-context strong { color: var(--text); font-weight: 650; }
.toolbar-inner .header-actions { width: auto; gap: .45rem; margin: 0; }

.theme-toggle {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1.12rem;
  color: var(--primary);
  border-radius: 7px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
}

.btn { border-radius: 8px; min-height: 38px; justify-content: center; }
.btn--sm { min-height: 34px; }
[data-theme="dark"] .btn--primary { color: #10201b; }
[data-theme="dark"] .btn--ghost:hover,
[data-theme="dark"] .table tbody tr:hover { background: var(--primary-soft); }
.btn:focus-visible, .theme-toggle:focus-visible, a:focus-visible { outline-offset: 3px; }

h1, .hero h1 { font-size: clamp(1.7rem, 3vw, 2.45rem); letter-spacing: -.035em; line-height: 1.1; }
h2 { font-size: 1.1rem; font-weight: 680; }
.page-head { align-items: start; margin-bottom: 1.35rem; }
.page-head p { max-width: 65ch; }
.panel, .two-col .panel { margin-bottom: 1rem; }
.panel { padding: clamp(.9rem, 2vw, 1.25rem); }
.panel--table { padding: 0; }
.panel-head { margin-bottom: .8rem; }
.stat-card { min-width: 0; border-top: 1px solid var(--border); padding: 1rem; gap: .27rem; }
.stat-card--green { background: var(--green-soft); }
.stat-card--amber { background: var(--amber-soft); }
.stat-card--indigo { background: var(--primary-soft); }
.stat-card--red, [data-theme="dark"] .stat-card--red { background: var(--red-soft); }
.stat-label { font-size: .85rem; color: var(--muted); font-weight: 580; }
.stat-value { font-size: clamp(1.18rem, 2.15vw, 1.85rem); line-height: 1.18; overflow-wrap: anywhere; }
.stat-hint { font-size: .81rem; }
.cards-grid, .two-col { gap: .85rem; }
.table th { font-weight: 650; }
.table thead { background: var(--bg); }
.table-wrap { scrollbar-color: var(--border) transparent; }
.progress { border: 0; background: var(--border); }
.progress-fill, .progress-fill--done { background: var(--primary); }
.progress-label {
  inset: 1px auto 1px 50%;
  transform: translateX(-50%);
  padding-inline: .38rem;
  border-radius: 20px;
  background: var(--surface);
  mix-blend-mode: normal;
}
.chart { border-radius: 7px; }
[data-theme="dark"] .chart { filter: invert(1) hue-rotate(155deg) contrast(.82); }
.money-plus, [data-theme="dark"] .money-plus { color: var(--green); }
.deadline--soon, [data-theme="dark"] .deadline--soon { color: var(--amber); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .85rem; }
.overview-grid > * { min-width: 0; }
.overview-flow .panel-head { align-items: baseline; }
.overview-flow dl, .goal-affordability-values { display: grid; gap: .75rem; margin: .9rem 0 0; }
.overview-flow dl > div, .goal-affordability-values > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .55rem;
}
.overview-flow dt, .goal-affordability-values dt { color: var(--muted); }
.overview-flow dd, .goal-affordability-values dd { margin: 0; font-weight: 670; text-align: right; }
.overview-flow dl > div:last-child, .goal-affordability-values > div:last-child { border-bottom: 0; padding-bottom: 0; }
.overview-flow dl > div:last-child dd { font-size: 1.25rem; }
.overview-goals { grid-template-columns: minmax(0, .95fr) minmax(0, 1.25fr); }
.overall-panel .progress { height: 10px; }
.goal-list { gap: .8rem; }
.goal-item { border-bottom-style: solid; }
.goal-top .goal-name { min-width: 0; }

.ledger-filter-panel { background: var(--surface); }
.ledger-filters { gap: .65rem; align-items: end; margin: 0; padding: 0; border: 0; }
.ledger-filters .filter-field { display: grid; gap: .25rem; align-content: end; }
.ledger-filters select, .ledger-filters input { min-height: 38px; min-width: 0; color: var(--text); }
.ledger-filters input[type="search"] { padding-block: .35rem; width: min(100%, 15rem); }
.ledger-filter-dates { display: flex; gap: .65rem; flex-wrap: wrap; }
.ledger-filter-dates[hidden] { display: none; }
.ledger-export-actions { flex-wrap: wrap; }
.bulk-controls { margin-bottom: .75rem; }
.bulk-controls > summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.bulk-controls[open] > summary { margin-bottom: .7rem; color: var(--text); }
.ledger-operations .table-wrap { max-height: 610px; }
.ledger-operations thead th { position: sticky; top: 0; background: var(--bg); }
.ledger-row-actions { align-items: baseline; gap: .55rem; font-size: .8rem; white-space: nowrap; }
.ledger-row-actions button { padding: 0; border: 0; background: none; color: var(--red); font: inherit; cursor: pointer; }
.calendar-panel { scroll-margin-top: 1rem; }
.site-footer { background: var(--bg); border-color: var(--border); font-size: .82rem; }
.site-footer .container, .footer-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .7rem 1rem; }
.site-footer p { margin: 0; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 190px minmax(0, 1fr); }
  .workspace-rail { padding-inline: .7rem; }
  .workspace-body .container { width: calc(100% - 2rem); }
  .stat-card { padding: .8rem; }
}

@media (max-width: 820px) {
  .workspace { display: block; }
  .workspace-rail { max-height: none; min-height: 0; position: static; padding: .65rem 1rem; gap: .65rem; }
  .workspace-rail .brand { padding: .15rem 0; }
  .workspace-rail .main-nav { flex-direction: row; flex-wrap: wrap; gap: .25rem; }
  .workspace-rail .main-nav a { min-height: 32px; padding: .36rem .52rem; gap: .35rem; }
  .workspace-rail .main-nav a.active { box-shadow: inset 0 -2px #91dfc6; }
  .rail-tools { display: none; }
  .rail-tools:has(a[href$="/logout"]) { display: flex; flex-direction: row; padding-top: 0; border: 0; }
  .rail-tools a { padding: .25rem .5rem; }
  .toolbar-inner { min-height: 53px; }
  .overview-goals { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .workspace-body .container { width: calc(100% - 1.5rem); }
  .workspace-rail { padding-inline: .75rem; }
  .toolbar-context { font-size: 0; }
  .toolbar-context span { padding: 0; }
  .toolbar-context strong { font-size: .82rem; }
  .overview-grid { grid-template-columns: 1fr; gap: 0; }
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-grid--three > :last-child { grid-column: 1 / -1; }
  .page-head .head-actions { flex-wrap: wrap; }
  .ledger-filter-dates { width: 100%; }
  .ledger-operations .panel-head { align-items: start; flex-direction: column; gap: .5rem; }
  .ledger-operations .table-wrap { max-height: none; }
}

@media print {
  .workspace { display: block; }
  .workspace-rail, .workspace-toolbar { display: none; }
  .workspace-body .container { width: 100%; }
}
