/* ---------- App shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; padding: 0 var(--s4);
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: var(--fs-lg); }

.main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--s4) var(--s4) calc(80px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px;
  color: var(--text-2); text-decoration: none; font-size: var(--fs-xs);
}
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabbar .icon { width: 22px; height: 22px; }

.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand-mark .icon { width: 18px; height: 18px; }

@media (min-width: 768px) {
  .app { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: auto 1fr; }
  .sidebar { grid-row: 1 / span 2; }
  .topbar { grid-column: 2; }
  .main { grid-column: 2; padding-bottom: var(--s6); }
  .tabbar { display: none; }
}

.sidebar { display: none; }
@media (min-width: 768px) {
  .sidebar {
    display: flex; flex-direction: column; gap: var(--s1);
    position: sticky; top: 0; height: 100dvh;
    padding: var(--s4) var(--s3);
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: var(--s2) var(--s2) var(--s4); }
  .sidebar a.nav {
    display: flex; align-items: center; gap: var(--s3);
    min-height: 40px; padding: 0 var(--s3);
    border-radius: var(--r-input);
    color: var(--text-2); text-decoration: none; font-size: var(--fs-sm);
  }
  .sidebar a.nav:hover { background: var(--surface-2); color: var(--text); }
  .sidebar a.nav[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .sidebar .nav-group { margin-top: var(--s4); padding: 0 var(--s3); font-size: var(--fs-xs); color: var(--text-2); }
  .sidebar .spacer { flex: 1; }
}

.icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- Cards & lists ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s4);
  box-shadow: var(--shadow);
}
.card h2 { font-size: var(--fs-md); }
.section-title { font-size: var(--fs-sm); color: var(--text-2); font-weight: 600; margin: var(--s5) 0 var(--s2); }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--border); }
.list-item {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 56px; padding: var(--s3) var(--s4);
  color: var(--text); text-decoration: none;
}
a.list-item:hover { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .icon { color: var(--text-2); }

.kv { display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; gap: var(--s3); grid-template-columns: 1fr; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Alerts & badges ---------- */
.alert { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-card); font-size: var(--fs-sm); }
.alert .icon { margin-top: 1px; }
.alert-warning { background: var(--warning-soft); color: var(--text); }
.alert-warning .icon { color: var(--warning); }
.alert-danger { background: var(--negative-soft); }
.alert-danger .icon { color: var(--negative); }
.alert .grow { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: var(--fs-sm); font-weight: 600; }
.field-hint { font-size: var(--fs-xs); color: var(--text-2); min-height: 1em; }
.field-hint.error { color: var(--negative); }
.field-hint.ok { color: var(--positive); }

.input, select.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; }

.check { display: flex; gap: var(--s3); align-items: flex-start; font-size: var(--fs-sm); }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s4);
  font: inherit; font-weight: 600; font-size: var(--fs-sm);
  border: 1px solid transparent; border-radius: var(--r-input);
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms, opacity 120ms;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--negative); color: #fff; }
.btn-text { background: none; color: var(--accent); padding: 0 var(--s2); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ---------- Lock / setup ---------- */
.lock {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--s5) var(--s4);
}
.lock-card { width: 100%; max-width: 420px; }
.lock-head { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; margin-bottom: var(--s5); }
.lock-head .brand-mark { width: 52px; height: 52px; border-radius: 14px; }
.lock-head .brand-mark .icon { width: 30px; height: 30px; }
.steps { font-size: var(--fs-xs); color: var(--text-2); text-align: center; }

.recovery-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem; letter-spacing: 0.06em; line-height: 1.8;
  text-align: center; word-spacing: 0.3em;
  padding: var(--s4);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--r-input);
  user-select: all;
}

/* ---------- Placeholder ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; padding: var(--s7) var(--s4); color: var(--text-2); }
.empty .icon { width: 40px; height: 40px; color: var(--border); }
.empty h2 { color: var(--text); }

/* ---------- Toasts & modal ---------- */
#toasts {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--s2);
  width: min(92vw, 420px);
}
@media (min-width: 768px) { #toasts { bottom: var(--s5); } }
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--text); color: var(--bg);
  border-radius: var(--r-input);
  font-size: var(--fs-sm);
  box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.toast-error { background: var(--negative); color: #fff; }
.toast .btn-text { color: inherit; text-decoration: underline; min-height: 32px; }

.modal {
  width: min(92vw, 440px);
  padding: var(--s5);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
.modal::backdrop { background: rgb(0 0 0 / 45%); }
.modal h2 { margin-bottom: var(--s4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s2); }

.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--s2) 0; text-align: left; border-bottom: 1px solid var(--border); }
.table td.num, .table th.num { text-align: right; }

/* ---------- Phase 03 ---------- */
.topbar-actions { gap: var(--s2); }
.btn-sm { min-height: 36px; padding: 0 var(--s3); }
.btn-sm .icon { width: 18px; height: 18px; }
.btn-danger-text { color: var(--negative); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap);
  background: none; border: 0; border-radius: var(--r-input);
  color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-lg { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.01em; }
.amount-xl { font-size: var(--fs-hero); font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }

.month-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s2); }
.month-label { text-align: center; font-size: var(--fs-lg); }

.summary-bar {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 0;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden;
}
.summary-bar > div { background: var(--surface); padding: var(--s3) var(--s4); }
.summary-bar dt { font-size: var(--fs-xs); color: var(--text-2); }
.summary-bar dd { margin: 2px 0 0; font-weight: 650; font-size: var(--fs-md); }
@media (max-width: 380px) { .summary-bar > div { padding: var(--s3); } .summary-bar dd { font-size: var(--fs-sm); } }

.filters { display: grid; grid-template-columns: 1fr; gap: var(--s2); }
@media (min-width: 640px) { .filters { grid-template-columns: 2fr 1fr 1fr; } }

.day-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: 600; margin: var(--s3) 0 var(--s2); }
.tx-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: var(--fs-xs); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.tx { min-height: 60px; }
.is-void .tx-title, .is-void .amount { text-decoration: line-through; color: var(--text-2); }

.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin: var(--s4) 0 var(--s2); }
.group-head h2 { font-size: var(--fs-md); }
.stack > section:first-child .group-head, .stack > .group-head:first-child { margin-top: 0; }

/* Entry form */
.tx-form { display: flex; flex-direction: column; gap: var(--s5); max-width: 560px; margin: 0 auto; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: 10px; }
.segmented button {
  min-height: 38px; border: 0; border-radius: 8px; background: none;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(16 24 32 / 12%); }

.amount-field {
  display: flex; align-items: baseline; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
}
.amount-field:focus-within { outline: 2px solid var(--focus); border-color: transparent; }
.amount-currency { font-weight: 600; color: var(--text-2); }
.amount-input {
  flex: 1; min-width: 0; border: 0; outline: 0; padding: 0; background: none;
  font: inherit; font-size: 2.25rem; font-weight: 650; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.amount-input::placeholder { color: var(--border); }
.amount-input:focus-visible { outline: none; } /* the wrapper shows focus */

.label { font-size: var(--fs-sm); font-weight: 600; }
.chip-grid { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 36px; padding: 0 var(--s3);
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font: inherit; font-size: var(--fs-sm); color: var(--text); cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.date-row { flex-wrap: wrap; }
.date-row .input { flex: 1 1 160px; width: auto; }

.split-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.split-line { display: grid; grid-template-columns: 1fr 110px auto; gap: var(--s2); align-items: center; }
.split-line > input:nth-of-type(2) { grid-column: 1 / span 2; }
.split-amount { text-align: right; font-variant-numeric: tabular-nums; }

details.more > summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); list-style: none; display: flex; align-items: center; gap: var(--s2); min-height: var(--tap); }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: auto; transition: transform 150ms; }
details.more[open] > summary::after { transform: rotate(225deg); }
details.more[open] > summary { margin-bottom: var(--s2); }
details.card { padding-top: 0; padding-bottom: 0; }
details.card[open] { padding-bottom: var(--s4); }

.form-error:empty { display: none; }
.form-error { color: var(--negative); font-size: var(--fs-sm); }
.form-actions { display: flex; flex-direction: column; gap: var(--s3); }
.secondary-actions { justify-content: center; }
@media (max-width: 767px) {
  .form-actions {
    position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 2;
    padding: var(--s3) 0; background: var(--bg);
    box-shadow: 0 -1px 0 var(--border);
  }
}

/* Accounts */
.account-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); }
.home-cash { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; }

/* Budget */
.budget-row { display: grid; gap: var(--s2); padding: var(--s3) var(--s4); }
.budget-main { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.budget-input { width: 120px; text-align: right; font-variant-numeric: tabular-nums; min-height: 38px; }
.budget-meta { display: flex; justify-content: space-between; gap: var(--s3); }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 200ms ease-out; }
.progress-near > span { background: var(--warning); }
.progress-over > span { background: var(--negative); }

/* Categories / reference */
.indent { padding-left: var(--s4); }
.edit-row, .add-row { padding: var(--s3) var(--s4); }
.add-row { display: grid; grid-template-columns: 1fr; gap: var(--s2); }
@media (min-width: 640px) { .add-row { grid-template-columns: 2fr 1fr auto; align-items: center; } }

.onboard h2 { font-size: var(--fs-lg); }
.steps-list { margin: 0; padding-left: 1.25rem; display: grid; gap: var(--s2); color: var(--text-2); }
.footnote { display: flex; align-items: center; gap: var(--s1); justify-content: center; padding-top: var(--s3); }
.footnote .icon { width: 14px; height: 14px; }

/* ---------- Phase 04 ---------- */
.nw-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.nw-bar span { flex-basis: 0; min-width: 0; }
.nw-assets { background: var(--accent); }
.nw-liab { background: var(--warning); }
.loan-box legend, fieldset.card legend { font-size: var(--fs-sm); font-weight: 600; padding: 0 var(--s1); }
fieldset.card { margin: 0; }
.list-item.holding { min-height: 64px; }
[hidden] { display: none !important; }

/* ---------- Phase 05 ---------- */
.lock { padding-top: calc(var(--s5) + env(safe-area-inset-top)); }
.runway { display: block; text-decoration: none; color: inherit; }
.runway .amount-xl { font-variant-numeric: normal; }
a.runway-link:hover { border-color: var(--accent); }
.summary-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .summary-4 { grid-template-columns: repeat(4, 1fr); } }
.contract-top { gap: var(--s2); }
.list-item.contract { align-items: flex-start; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--s4); border-left: 1px solid var(--border); display: grid; gap: var(--s3); }
.timeline li { display: grid; gap: 2px; }

.chart { margin: 0; position: relative; }
.chart-box { width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg .grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-svg .grid.zero { stroke: var(--text-2); stroke-opacity: 0.5; }
.chart-svg .tick { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .series.muted { stroke-opacity: 0.35; }
.chart-svg .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .ref { stroke: var(--text-2); stroke-width: 1; stroke-opacity: 0.6; }
.chart-svg .crosshair { stroke: var(--text-2); stroke-width: 1; }
.chart-svg rect:focus { outline: none; }
.chart-svg rect:focus-visible { outline: 2px solid var(--focus); }
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s3); margin: 0 0 var(--s2); padding: 0; font-size: var(--fs-xs); color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.key-line { display: inline-block; width: 14px; height: 2px; border-radius: 2px; }
.chart-tip {
  position: absolute; top: 28px; z-index: 3; min-width: 160px; pointer-events: none;
  padding: var(--s2) var(--s3); border-radius: var(--r-input);
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgb(0 0 0 / 15%);
  font-size: var(--fs-xs);
}
.tip-title { color: var(--text-2); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row strong { font-variant-numeric: tabular-nums; }

.fc-head, .fc-month > summary { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1.3fr; gap: var(--s2); align-items: center; }
.fc-head { font-size: var(--fs-xs); color: var(--text-2); padding: 0 var(--s4); }
.fc-head span:not(:first-child) { text-align: right; }
.forecast-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.fc-month + .fc-month { border-top: 1px solid var(--border); }
.fc-month > summary { list-style: none; cursor: pointer; min-height: 48px; padding: var(--s2) var(--s4); font-size: var(--fs-sm); }
.fc-month > summary::-webkit-details-marker { display: none; }
.fc-month > summary .amount { text-align: right; }
.fc-month.is-short > summary { background: var(--negative-soft); }
.fc-in, .fc-out { font-size: var(--fs-xs); }
.fc-close { font-weight: 600; }
.fc-detail { padding: var(--s2) var(--s4) var(--s4); display: grid; gap: var(--s3); background: var(--surface-2); }
.fc-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: var(--fs-xs); }
.fc-lines li { display: flex; justify-content: space-between; gap: var(--s3); }
@media (max-width: 400px) { .fc-month > summary { grid-template-columns: 1.2fr 0.9fr 0.9fr 1.2fr; font-size: var(--fs-xs); } }

/* ---------- Phase 06 ---------- */
.list-item.goal { align-items: flex-start; }
.list-item.goal > .icon { margin-top: 2px; color: var(--accent); }

/* ---------- Phase 07 ---------- */
.report-tabs { display: flex; gap: var(--s1); overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.report-tabs a { flex: none; padding: var(--s2) var(--s3); min-height: var(--tap); display: inline-flex; align-items: center; color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.report-tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.filters-2 { grid-template-columns: 1fr auto; align-items: center; }
.key-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.chart-svg .bar-group:focus { outline: none; }
.chart-svg .bar-group:focus-visible rect { stroke: var(--focus); stroke-width: 2; }
.chart-svg .bar-group.hover .bar { filter: brightness(1.1); }
.ranked ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.ranked li { display: grid; grid-template-columns: minmax(84px, 34%) 1fr auto; grid-template-areas: "label track value" ". note note"; align-items: center; gap: 2px var(--s3); font-size: var(--fs-sm); }
.rlabel { grid-area: label; overflow-wrap: anywhere; }
.rtrack { grid-area: track; height: 12px; display: flex; }
.rbar { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.rvalue { grid-area: value; font-weight: 600; }
.rnote { grid-area: note; font-size: var(--fs-xs); color: var(--text-2); }
.stack-bar { display: flex; height: 16px; gap: 2px; border-radius: 4px; overflow: hidden; }
.stack-bar span { min-width: 2px; }
.stack-bar span:last-child { border-radius: 0 4px 4px 0; }
.stack-legend { margin-top: var(--s3); gap: var(--s2) var(--s4); font-size: var(--fs-sm); color: var(--text); }
.stack-legend strong { color: var(--text-2); font-weight: 600; }
.bridge dd { font-variant-numeric: tabular-nums; }
.table { margin-top: var(--s2); }
.nw-line { border: 1px solid var(--border); }
.list-item.goal-mini { align-items: flex-start; }

/* ---------- Monthly commitments ---------- */
.commit-group > summary { justify-content: space-between; color: var(--text); font-weight: 500; }
.commit-group > summary .amount { font-weight: 600; margin-right: var(--s2); }
.commit-items { list-style: none; margin: 0; padding: 0 0 var(--s2) var(--s3); display: grid; gap: 2px; font-size: var(--fs-sm); }
.commit-items a, .commit-items .commit-row { display: flex; gap: var(--s3); justify-content: space-between; min-height: 36px; align-items: center; color: var(--text); text-decoration: none; }
.commit-items a:hover { color: var(--accent); }
.commit-group > summary .grow { flex: 1; }
.commit-group > summary::after { margin-left: var(--s2); }

/* ---------- Personalisation (v1.1) ---------- */
.status-line { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-2); text-decoration: none; }
.status-line .icon { color: var(--accent); }
.alert.reserve { text-decoration: none; color: var(--text); }
.alert-ok { background: var(--accent-soft); }
.alert-ok .icon { color: var(--accent); }
.runway .kv { margin-top: var(--s3); }
.nw-card { display: grid; gap: var(--s2); color: var(--text); text-decoration: none; }
.tier-bar { display: flex; gap: 2px; height: 10px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.tier-bar span { min-width: 0; }
.tier-1 { background: var(--series-1); }
.tier-2 { background: var(--series-3); }
.tier-3 { background: var(--series-4); }
.key-swatch.tier-1, .key-swatch.tier-2, .key-swatch.tier-3 { display: inline-block; }
.plan-line { grid-template-columns: 1fr 120px auto; }
.plan-line > input:nth-of-type(2) { grid-column: auto; }
.plan-item { display: flex; flex-direction: column; gap: var(--s1); padding-bottom: var(--s2); border-bottom: 1px solid var(--border); }
.plan-sub { display: grid; grid-template-columns: 1fr 120px; gap: var(--s2); padding-right: calc(var(--tap) + var(--s2)); }
.plan-sub label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* ---------- Commitments page ---------- */
.commit-hero { display: grid; gap: var(--s3); }
.commit-group-card { display: grid; gap: var(--s2); }
.commit-group-card h2 { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-md); }
.commit-list { list-style: none; margin: 0; padding: 0; display: grid; }
.commit-row-item { padding: var(--s2) 0; border-top: 1px solid var(--border); display: grid; gap: var(--s1); }
.commit-row-item:first-child { border-top: 0; }
/* Name and status stacked on the left, amount box on the right: fits a phone without wrapping. */
.commit-main { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: var(--s2); row-gap: 4px; align-items: center; }
.commit-name { grid-column: 1; font-size: var(--fs-sm); font-weight: 550; overflow-wrap: anywhere; }
.commit-status { grid-column: 1; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-width: 0; }
.commit-status:empty { display: none; }
.commit-status .btn-text { min-height: 32px; padding: 0 var(--s1); }
.commit-main > .commit-amount, .commit-main > .amount { grid-column: 2; grid-row: 1 / span 2; }
.commit-main > .icon-btn { grid-column: 3; grid-row: 1 / span 2; }
.commit-left { font-size: var(--fs-sm); color: var(--text-2); }
.commit-hero, .commit-group-card { min-width: 0; grid-template-columns: minmax(0, 1fr); }
.commit-hero .tx-sub { white-space: normal; }
.commit-amount { width: 104px; min-height: 36px; text-align: right; font-variant-numeric: tabular-nums; padding: 6px 10px; }
.chip-state { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--text-2); padding: 2px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.chip-state .icon { width: 12px; height: 12px; }
.chip-state.ok { background: var(--accent-soft); color: var(--accent); }
.chip-state.bad { background: var(--negative-soft); color: var(--negative); }
.state-paid .commit-name { color: var(--text-2); }
.pay-all { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); align-items: center; padding-top: var(--s2); }
.pay-all select { min-width: 0; width: 100%; }
.pay-group { justify-self: stretch; }
.commit-progress { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--s2); }
.commit-add-budget { display: grid; grid-template-columns: 1fr 110px; gap: var(--s2); padding-top: var(--s2); }

/* ---------- Dashboard (v1.2): visual tiles ---------- */
.dash { display: grid; gap: var(--s3); grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .dash { grid-template-columns: repeat(6, 1fr); }
  .t-runway, .t-reserve, .t-networth, .t-baby { grid-column: span 3; }
  .t-status, .t-timeline, .t-month, .t-goals { grid-column: span 6; }
  .t-curve { grid-column: span 4; }
  .t-commit { grid-column: span 2; }
}
.tile {
  display: flex; flex-direction: column; gap: var(--s3); min-width: 0;
  padding: var(--s4); border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-decoration: none;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 4%);
  transition: border-color 150ms ease-out, transform 150ms ease-out;
}
a.tile:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
a.tile:active { transform: scale(0.995); }
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.tile-head .icon { width: 14px; height: 14px; opacity: 0.6; }
.tile-big { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.tile-big-row { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.tile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: var(--s2) var(--s3); }
.stat { display: grid; gap: 2px; }
.stat-label { font-size: var(--fs-xs); color: var(--text-2); }
.stat-value { font-size: var(--fs-sm); font-weight: 600; }
.stat-value.muted { color: var(--text-2); }
.stat-value.neg, .neg { color: var(--negative); }
.delta { font-size: var(--fs-xs); font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.delta.up { color: var(--positive); background: color-mix(in srgb, var(--positive) 14%, transparent); }
.delta.down { color: var(--negative); background: var(--negative-soft); }

/* Gauge */
.gauge { width: 100%; max-width: 280px; height: auto; margin: 0 auto; display: block; overflow: visible; }
.gz { fill: none; stroke-width: 14; stroke-linecap: butt; opacity: 0.22; }
.gz-bad { stroke: var(--negative); }
.gz-warn { stroke: var(--warning); }
.gz-good { stroke: var(--positive); }
.gv { fill: none; stroke-width: 14; stroke-linecap: round; }
.gv-bad { stroke: var(--negative); fill: var(--negative); }
.gv-warn { stroke: var(--warning); fill: var(--warning); }
.gv-good { stroke: var(--accent); fill: var(--accent); }
path.gv-bad, path.gv-warn, path.gv-good { fill: none; }
.g-dot { stroke: var(--surface); stroke-width: 3; }
.g-tick { stroke: var(--text-2); stroke-width: 1.5; }
.g-tick-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.g-value { fill: var(--text); font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.g-unit { fill: var(--text-2); font-size: 12px; }

/* Reserve meter */
.rs-word { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.02em; }
.rs-word.rs-short { color: var(--negative); }
.rs-word.rs-minimum { color: var(--warning); }
.rs-word.rs-comfortable { color: var(--accent); }
.rmeter { padding: 18px 0 2px; }
.rm-track { position: relative; height: 14px; border-radius: 7px; background: var(--surface-2); }
.rm-fill { position: absolute; inset: 0 auto 0 0; border-radius: 7px; transition: width 300ms ease-out; }
.rm-bad { background: var(--negative); }
.rm-warn { background: var(--warning); }
.rm-good { background: var(--accent); }
.rm-mark { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; }
.rm-mark-label { position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 600; color: var(--text-2); white-space: nowrap; }

/* Cash curve */
.curve { width: 100%; height: 110px; display: block; overflow: visible; }
.cv-area { fill: color-mix(in srgb, var(--accent) 16%, transparent); }
.cv-area.neg { fill: color-mix(in srgb, var(--warning) 14%, transparent); }
.cv-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.cv-zero { stroke: var(--negative); stroke-width: 1; vector-effect: non-scaling-stroke; opacity: 0.7; }
.cv-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.cv-dot.neg { fill: var(--negative); }
.cv-label, .cv-low { fill: var(--text-2); font-size: 10px; }
.cv-low { font-weight: 600; text-anchor: middle; }

/* Work timeline */
.timeline { width: 100%; height: auto; display: block; }
.tl-grid { stroke: var(--chart-grid); stroke-width: 1; }
.tl-month { fill: var(--text-2); font-size: 11px; }
.tl-work { fill: var(--accent); }
.tl-work.expected { fill: var(--accent); opacity: 0.35; }
.tl-work-label { fill: var(--accent-ink); font-size: 10px; font-weight: 600; }
.tl-pay { fill: var(--series-3); stroke: var(--surface); stroke-width: 2; }
.tl-pay.overdue { fill: var(--warning); }
.tl-pay-label { fill: var(--text); font-size: 10px; font-weight: 600; text-anchor: middle; }
.tl-baby { stroke: var(--series-5); stroke-width: 2; }
.tl-baby-label { fill: var(--series-5); font-size: 10px; font-weight: 700; }
.tl-today { stroke: var(--text); stroke-width: 1.5; opacity: 0.6; }
.tl-k-work { background: var(--accent); }
.key-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.tl-k-pay { background: var(--series-3); }
.tl-k-baby { background: var(--series-5); }
.tl-k-today { background: var(--text); opacity: 0.6; }

/* This month bars */
.mbars { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s2) var(--s3); align-items: center; font-size: var(--fs-sm); }
.mlabel { color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; }
.mtrack { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.mbar { display: block; height: 100%; border-radius: 5px; }
.mbar.in { background: var(--series-3); }
.mbar.out { background: var(--series-2); }

.tile p.tx-sub { white-space: normal; overflow: visible; }
.t-commit .tile-big { font-size: var(--fs-lg); }
@media (min-width: 720px) and (max-width: 1100px) { .t-curve, .t-commit { grid-column: span 3; } }
.stat-value { overflow-wrap: anywhere; }

@media (min-width: 720px) { .t-due { grid-column: span 6; } }
.due-list { list-style: none; margin: 0; padding: 0; display: grid; }
.due-list a { display: flex; align-items: center; gap: var(--s2); min-height: 44px; color: var(--text); text-decoration: none; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.due-list li:first-child a { border-top: 0; }

/* Goals tile: one bar per goal, two columns when there's room */
.goal-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3) var(--s4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.goal-bars li { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.goal-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sign-off simulator */
.sim-verdict { border-radius: 12px; padding: var(--s3) var(--s4); background: var(--surface-2); border-left: 4px solid var(--text-2); }
.sim-verdict p { margin: var(--s1) 0 0; }
.sv-safe { border-left-color: var(--accent); background: var(--accent-soft); }
.sv-safe strong { color: var(--accent); }
.sv-attention { border-left-color: var(--warning); background: var(--warning-soft); }
.sv-attention strong { color: var(--warning); }
.sv-action { border-left-color: var(--negative); background: var(--negative-soft); }
.sv-action strong { color: var(--negative); }
.sim-row { display: flex; flex-direction: column; gap: var(--s1); }
.sim-track { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); }
.sim-fill { display: block; height: 100%; border-radius: 999px; background: var(--series-1); }
.sim-fill.neg { background: var(--negative); }
.sim-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); border-radius: 1px; }

/* Home headline: safe / attention / action */
.t-status { gap: var(--s2); border-left: 4px solid var(--text-2); }
.st-head { display: flex; align-items: center; gap: var(--s2); }
.st-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-2); flex: none; }
.st-title { font-size: var(--fs-lg); letter-spacing: -0.01em; }
.st-body { margin: 0; color: var(--text-2); max-width: 70ch; }
.st-safe { border-left-color: var(--accent); } .st-safe .st-dot { background: var(--accent); } .st-safe .st-title { color: var(--accent); }
.st-attention { border-left-color: var(--warning); } .st-attention .st-dot { background: var(--warning); }
.st-action { border-left-color: var(--negative); } .st-action .st-dot { background: var(--negative); } .st-action .st-title { color: var(--negative); }

/* What-if comparison */
.wi-table { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-card); background: var(--surface); }
.wi-row { display: grid; grid-template-columns: 1fr auto 16px auto; gap: var(--s2); align-items: baseline; padding: var(--s3) var(--s4); border-top: 1px solid var(--border); }
.wi-row:first-child { border-top: 0; }
.wi-label { color: var(--text-2); font-size: var(--fs-sm); }
.wi-before { color: var(--text-2); font-size: var(--fs-sm); }
.wi-arrow { color: var(--text-2); text-align: center; }
.wi-row.worse .wi-after { color: var(--warning); }
@media (max-width: 420px) { .wi-row { grid-template-columns: 1fr auto; } .wi-before, .wi-arrow { display: none; } }

/* Contract history: income per year */
.year-bars { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: auto 1fr auto; gap: var(--s1) var(--s3); align-items: center; }
.year-bars li { display: contents; }
.year-bars .yb-sub { grid-column: 2 / -1; margin-bottom: var(--s2); }
