:root {
  --ink: #1c2b27;
  --muted: #5c6f68;
  --bg: #f3f6f4;
  --card: #ffffff;
  --green: #194e43;
  --green-2: #2f6f5e;
  --mint: #e7f3ee;
  --line: #d7e3de;
  --gold: #8d6b2f;
  --danger: #8d3b3b;
  --shadow: 0 12px 40px rgba(25, 78, 67, 0.08);
  --radius: 18px;
  color-scheme: light;
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #2f6f5e; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.skip { position: absolute; left: 12px; top: -40px; background: var(--green); color: white; padding: 8px 12px; z-index: 5; }
.skip:focus { top: 12px; }

#app {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}
.update-banner {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  background: var(--green);
  color: white;
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.update-banner button { background: white; color: var(--green); }
.fab {
  position: fixed;
  z-index: 3;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 48px;
  padding: 12px 18px;
  box-shadow: 0 10px 28px rgba(25, 78, 67, 0.28);
}
.page-actions { display: flex; gap: 8px; flex: 0 0 auto; align-items: center; }
.add-asset, .add-receivable { flex: 0 0 auto; }
.lock { min-height: calc(100vh - 48px); display: grid; align-items: center; }
.lock-card { width: min(460px, 100%); margin: 0 auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 22px; display: grid; gap: 14px; }
.lock-card h1 { font-size: 1.8rem; }
.lock-card form { display: grid; gap: 12px; }
.lock-card details { color: var(--muted); }
.lock-card ol { margin: 8px 0 0; padding-left: 1.2rem; }
.pin-dots { letter-spacing: 0.35em; font-size: 1.3rem; text-align: center; margin: 0; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-pad button { border-radius: 14px; padding: 14px 0; font-size: 1.25rem; }
header, .sectionhead, .pagehead, .header-actions, .actions, .formfooter, .toolbar, .legend, .sourceline, footer {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
header { justify-content: space-between; }
.brand { color: inherit; text-decoration: none; font-size: 1.35rem; letter-spacing: -0.03em; }
.brandmark { display: inline-grid; place-items: center; width: 1.7em; height: 1.7em; margin-right: 8px; border-radius: 8px; background: var(--green); color: white; font-weight: 650; }
.brandthin { font-weight: 450; color: var(--green-2); }
.lede, .muted, .small, .footnote { color: var(--muted); }
.lede { margin-top: 8px; }
.eyebrow { letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.72rem; color: var(--green-2); margin: 0 0 4px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -0.04em; margin-bottom: 6px; }
h2 { font-size: 1.25rem; letter-spacing: -0.03em; }
.money { font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.pagehead { justify-content: space-between; align-items: end; margin: 22px 0; }
.nav { display: flex; gap: 8px; margin: 18px 0; position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--bg) 92%, transparent); padding: 6px 0; }
.nav a, button, .group-buttons button {
  border: 1px solid var(--line); background: white; border-radius: 999px; padding: 8px 14px; text-decoration: none; color: var(--ink); cursor: pointer;
}
.nav a.active, button.primary, .group-buttons button[aria-selected="true"] { background: var(--green); color: white; border-color: var(--green); }
button.danger { background: var(--danger); color: white; border-color: var(--danger); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.header-actions select, .toolbar select, label select, .currency-label select {
  border: 1px solid var(--line); background: white; border-radius: 10px; padding: 8px 10px;
}

.summary, .split, .visuals, .insights, .steps, .phone-grid, .plangrid { display: grid; gap: 14px; }
.summary { grid-template-columns: 1.4fr 1fr; }
.balance, .stat, .panel, .plan, .dialog {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.balance { background: linear-gradient(160deg, #194e43, #2f6f5e); color: white; }
.balance .balancefoot, .balance .balancebottom { color: #d7ebe4; }
.balance h2 { font-size: clamp(2rem, 5vw, 3rem); margin: 8px 0; }
.stat h2 { font-size: 1.6rem; margin: 8px 0; }
.stat h2 span, .balancebottom { font-size: 0.95rem; font-weight: 500; }
.panel { margin-top: 14px; }
.sectionhead, .pagehead { justify-content: space-between; }
.switch { display: inline-flex; align-items: center; gap: 8px; }
.insights { grid-template-columns: repeat(3, 1fr); }
.insights div, .plan { border: 1px solid var(--line); border-radius: 14px; }
.insights div { padding: 12px; display: grid; }
.insights strong { font-size: 1.3rem; }
.visuals { grid-template-columns: 220px 1fr; align-items: center; }
.donut { width: 100%; height: auto; }
.donut path { cursor: pointer; }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr; gap: 8px; width: 100%; text-align: left; border-radius: 12px; }
.bar.selected { border-color: var(--green); background: var(--mint); }
.bar-track { background: #edf3f0; border-radius: 999px; height: 12px; align-self: center; }
.bar-fill { display: block; height: 100%; width: var(--width); background: var(--bar); border-radius: inherit; }
.inside ul, .allocation { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.inside li, .allocation li, .listrow { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding: 8px 0; }
.inside small { width: 100%; color: var(--muted); }
.alloc-track { flex: 1; background: #edf3f0; border-radius: 999px; height: 10px; align-self: center; min-width: 80px; }
.alloc-track span { display: block; height: 100%; background: var(--green-2); border-radius: inherit; }
.split { grid-template-columns: 1.4fr 1fr; align-items: start; }
.wealth { width: 100%; height: auto; }
.gridline { stroke: #edf1f2; }
.tick { fill: var(--muted); font-size: 11px; }
.wealth-area { fill: #8fbd84; opacity: 0.35; }
.wealth-line, .swatch.wealth { stroke: #326b53; }
.contrib-line, .swatch.contrib { stroke: #488eab; }
.withdraw-line, .swatch.withdraw { stroke: #aa7a27; }
.wealth-line, .contrib-line, .withdraw-line { fill: none; stroke-width: 2.5; }
.wealth-dot { fill: #326b53; }
.swatch { width: 18px; height: 4px; display: inline-block; background: currentColor; border-radius: 99px; }
.swatch.wealth { background: #326b53; }
.swatch.contrib { background: #488eab; }
.swatch.withdraw { background: #aa7a27; }
.legend { list-style: none; padding: 0; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
td small { display: block; color: var(--muted); }
td.actions { white-space: nowrap; }
.plangrid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.plan .money { font-size: 1.5rem; margin: 8px 0; }
.notice { background: var(--mint); border-radius: 12px; padding: 12px 14px; }
.notice.error { background: #f8e8e8; color: var(--danger); }
.empty, .empty-hero { color: var(--muted); }
.empty-hero h2 { color: var(--ink); }
.steps, .phone-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.steps article, .phone-grid section { border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.sourceline { margin-top: 28px; }
.sourceline a { color: var(--green); }
footer { justify-content: space-between; color: var(--muted); font-size: 0.85rem; padding-bottom: 12px; }

.backdrop { position: fixed; inset: 0; background: rgba(22, 36, 32, 0.46); display: grid; place-items: end center; z-index: 4; padding: 12px; }
.dialog {
  width: min(680px, 100%);
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.dialog form { display: flex; flex-direction: column; min-height: 0; flex: 1; margin-bottom: 0; overflow: hidden; }
.dialog-body { overflow: auto; min-height: 0; flex: 1; }
.dialog h2:focus { outline: none; }
form, .dialog label { display: grid; gap: 6px; margin-bottom: 12px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: white; }
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.formfooter { justify-content: flex-end; position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
.symbol-hits { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
tr.click-row, li.click-row { cursor: pointer; }
tr.click-row:hover, li.click-row:hover, tr.click-row:focus-visible { background: var(--mint); }
button.rowlink, button.account-link {
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-weight: 650;
  text-align: left;
  color: inherit;
}
button.account-link { display: inline; font-weight: 550; color: var(--green); text-decoration: underline; }
.inside .rowlink { display: flex; justify-content: space-between; gap: 12px; width: 100%; }
a.navlink { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 8px 14px; text-decoration: none; color: var(--ink); }
.delete-confirm { color: var(--danger); margin-right: auto; }
.amount-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.amount-preview div { background: var(--mint); border-radius: 12px; padding: 10px 12px; }
.amount-preview span { display: block; color: var(--muted); font-size: 0.85rem; }
.amount-preview strong { font-size: 1.15rem; }
#rename-account { display: grid; gap: 12px; }
.symbol-hits button { text-align: left; }
.status-paid { color: var(--muted); }
.status-part { color: var(--gold); }

@media (min-width: 801px) {
  .fab { display: none; }
}

@media (max-width: 800px) {
  .summary, .split, .visuals, .insights { grid-template-columns: 1fr; }
  .nav { position: sticky; top: 0; margin: 8px 0 0; padding: 8px; background: color-mix(in srgb, var(--bg) 92%, white); justify-content: space-between; }
  .nav a { flex: 1; text-align: center; padding: 8px 2px; font-size: 0.72rem; line-height: 1.15; }
  #app { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .backdrop { padding: 0; place-items: stretch; }
  .dialog {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  }
  .dialog form { display: flex; flex-direction: column; min-height: 0; flex: 1; margin: 0; overflow: hidden; }
  .dialog-body { overflow: auto; min-height: 0; flex: 1; }
  .formfooter { flex: 0 0 auto; padding-bottom: 4px; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; padding: 8px; }
  td { border: 0; display: flex; justify-content: space-between; gap: 12px; }
  td::before { content: attr(data-label); color: var(--muted); }
  .formgrid, .amount-preview { grid-template-columns: 1fr; }
  .header-actions { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
