/* Household Finance design system. Palette carried over from the Retirement
   Simulator: terracotta / orange / cream, with green, red and blue reserved for
   data meaning (money in, money out, information). See /style. */
:root {
  --bg: #fdf6ec;
  --surface: #fffdf9;
  --surface-2: #f5efe6;
  --border: #e8ddd0;
  --text: #3a2f28;
  --text-2: #5a4433;
  --muted: #8a7766;
  --brand: #b8502f;
  --brand-2: #e5793a;
  --brand-ink: #fffdf9;
  --gold: #a97f2e;
  --pos: #2f8f4e;
  --neg: #b3261e;
  --info: #2f6fb0;
  --pos-bg: #e6f3ea;
  --neg-bg: #fbe9e7;
  --info-bg: #e7f0f9;
  --warn-bg: #f6e3b0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(58, 47, 40, .08), 0 2px 8px rgba(58, 47, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --step--1: .875rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1915;
    --surface: #2a221d;
    --surface-2: #332a24;
    --border: #4a3b31;
    --text: #f3e8da;
    --text-2: #e8ddd0;
    --muted: #b5a291;
    --brand: #e5793a;
    --brand-2: #f09a5f;
    --brand-ink: #1f1915;
    --gold: #d6a84a;
    --pos: #5cc27f;
    --neg: #ff8a80;
    --info: #5cb3e6;
    --pos-bg: #1f3526;
    --neg-bg: #3d2320;
    --info-bg: #1d2e3d;
    --warn-bg: #4a3b1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
a { color: var(--brand); }
a:hover { color: var(--brand-2); }
h1 { font-size: var(--step-3); line-height: 1.2; margin: .2em 0 .6em; }
h2 { font-size: var(--step-2); margin: 1.4em 0 .5em; }
h3 { font-size: var(--step-1); margin: 1.2em 0 .4em; }
p { margin: .5em 0 1em; }
small, .muted { color: var(--muted); }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }

/* layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--brand); text-decoration: none; font-size: var(--step-1); }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.nav a { text-decoration: none; color: var(--text-2); padding: .35rem .6rem; border-radius: 6px; font-size: var(--step--1); }
.nav a[aria-current="page"], .nav a:hover { background: var(--surface-2); color: var(--brand); }
.userbox { display: flex; gap: .5rem; align-items: center; font-size: var(--step--1); color: var(--muted); }
main { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.narrow { max-width: 460px; margin: 2rem auto; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.row > * { flex: 1 1 260px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.kpi { font-size: var(--step-2); font-weight: 700; font-variant-numeric: tabular-nums; }
.btn { display: inline-block; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: .55rem 1rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: var(--brand-2); border-color: var(--brand-2); color: var(--brand-ink); }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.secondary:hover { background: var(--surface-2); color: var(--brand); }
.btn.danger { background: transparent; color: var(--neg); border-color: var(--neg); }
.btn.small { padding: .25rem .6rem; min-height: 32px; font-size: var(--step--1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

form.stack label { display: block; font-weight: 600; margin: .8rem 0 .25rem; }
form.stack .hint { font-weight: 400; color: var(--muted); font-size: var(--step--1); display: block; }
input[type=text], input[type=password], input[type=date], input[type=search], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; min-height: 44px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 1px; }
input.code { font-size: var(--step-2); letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters > div { flex: 1 1 150px; }
.filters label { font-size: var(--step--1); font-weight: 600; display: block; }

.alert { border-radius: 8px; padding: .8rem 1rem; margin: 0 0 1rem; border: 1px solid transparent; }
.alert.ok { background: var(--pos-bg); border-color: var(--pos); }
.alert.bad { background: var(--neg-bg); border-color: var(--neg); }
.alert.info { background: var(--info-bg); border-color: var(--info); }
.alert.warn { background: var(--warn-bg); border-color: var(--gold); }
.alert ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--pos-bg); color: var(--pos); }
.badge.bad { background: var(--neg-bg); color: var(--neg); }
.badge.info { background: var(--info-bg); color: var(--info); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num.pos, .pos { color: var(--pos); }
.num.neg, .neg { color: var(--neg); }
tr.dup td { opacity: .55; }
tfoot td { font-weight: 700; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--text-2); }
.empty .btn { margin-top: .6rem; }

/* "What does this do?" expander and the "?" help drawer */
details.explain { background: var(--info-bg); border-radius: 8px; padding: .5rem .8rem; margin: 0 0 1rem; }
details.explain summary { cursor: pointer; font-weight: 600; color: var(--info); }
details.help-drawer { position: relative; }
details.help-drawer > summary { list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--brand); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
details.help-drawer > summary::-webkit-details-marker { display: none; }
details.help-drawer[open] > .drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -4px 0 20px rgba(0,0,0,.15); padding: 1rem 1.2rem 3rem; overflow-y: auto; z-index: 50; }
.drawer-close { float: right; }
.help-body h1 { font-size: var(--step-2); }
.help-body table { margin: .5rem 0 1rem; }

.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; padding-left: 2.2rem; position: relative; margin-bottom: .8rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.qr { background: #fff; padding: .6rem; border-radius: 8px; width: 220px; max-width: 100%; }
.qr svg { width: 100%; height: auto; display: block; }
.swatches { display: flex; flex-wrap: wrap; gap: .6rem; }
.swatch { width: 110px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: .75rem; }
.swatch div { height: 48px; }
.swatch span { display: block; padding: .3rem .4rem; }
.sw-brand { background: var(--brand); } .sw-brand2 { background: var(--brand-2); } .sw-bg { background: var(--bg); }
.sw-surface { background: var(--surface); } .sw-text { background: var(--text); } .sw-gold { background: var(--gold); }
.sw-pos { background: var(--pos); } .sw-neg { background: var(--neg); } .sw-info { background: var(--info); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; background: var(--surface-2); }
.dropzone input[type=file] { width: 100%; font: inherit; padding: 1rem 0; }

@media (max-width: 640px) {
  h1 { font-size: var(--step-2); }
  .topbar-inner { gap: .4rem; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .hide-sm { display: none; }
  main { padding-top: .8rem; }
}
.narrow.wide { max-width: 560px; }
.form-card { max-width: 640px; }

/* Phase 2 */
.subnav { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .6rem; }
.subnav a { text-decoration: none; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: var(--step--1); }
.subnav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
form.inline { display: inline-flex; gap: .3rem; align-items: center; margin: .2rem .4rem .2rem 0; flex-wrap: wrap; }
form.inline input[type=text], form.inline select { width: auto; min-width: 160px; min-height: 36px; padding: .3rem .5rem; }
svg.bar { width: 100%; min-width: 80px; height: 10px; display: block; }
.bar-bg { fill: var(--surface-2); }
.bar-fill.ok { fill: var(--pos); } .bar-fill.warn { fill: var(--gold); } .bar-fill.over { fill: var(--neg); }
.bar-col { width: 22%; }
table.budget tr.sub td, tr.sub td { color: var(--text-2); font-size: .82rem; }
input.amount { max-width: 130px; text-align: right; font-variant-numeric: tabular-nums; min-height: 36px; }
svg.trend { width: 100%; height: auto; max-height: 260px; }
.trend-bar { fill: var(--brand-2); } .trend-bar.over { fill: var(--neg); }
.trend-target { stroke: var(--text); stroke-width: 2; stroke-dasharray: 3 2; }
.trend-label { font-size: 10px; fill: var(--muted); }
.split-row { border-top: 1px dashed var(--border); padding-top: .4rem; }

/* Phase 3 */
a.kpi-link { text-decoration: none; color: inherit; display: block; }
a.kpi-link:hover { border-color: var(--brand); }
.nw-line { stroke: var(--brand); stroke-width: 2.5; }
.nw-dot { fill: var(--brand); } .nw-dot.stale { fill: var(--gold); }
.stack-traditional { fill: var(--brand); background: var(--brand); }
.stack-roth { fill: var(--pos); background: var(--pos); }
.stack-taxable { fill: var(--info); background: var(--info); }
.stack-hsa { fill: var(--gold); background: var(--gold); }
.stack-na { fill: var(--muted); background: var(--muted); }
.legend { font-size: var(--step--1); color: var(--text-2); }
.legend .key { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; vertical-align: middle; margin-left: .6rem; }
