/* Home plan — one stylesheet, light and dark. */

:root {
  --paper: #edf1f4;
  --card: #ffffff;
  --ink: #18232f;
  --muted: #5b6875;
  --rule: #d6dee3;
  --brand: #283a73;
  --brand-ink: #ffffff;
  --porch: #f0a92e;
  --ok: #1f7149;
  --warn: #a8402a;
  --focus: #c7820a;
  --field: #f6f8f9;
  --chip: #e5eaf4;
  --series-savings: #c7820a;
  --series-cash: #4a63b5;
  --shadow: 0 1px 0 rgba(24, 35, 47, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10161d;
    --card: #18212b;
    --ink: #e6ecf1;
    --muted: #95a3af;
    --rule: #2a3642;
    --brand: #93a8ee;
    --brand-ink: #10161d;
    --porch: #f0a92e;
    --ok: #5cc28c;
    --warn: #f07d62;
    --focus: #f0a92e;
    --field: #121a22;
    --chip: #233046;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #10161d;
  --card: #18212b;
  --ink: #e6ecf1;
  --muted: #95a3af;
  --rule: #2a3642;
  --brand: #93a8ee;
  --brand-ink: #10161d;
  --ok: #5cc28c;
  --warn: #f07d62;
  --focus: #f0a92e;
  --field: #121a22;
  --chip: #233046;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
a { color: var(--brand); }

/* Top bar */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.top-in { max-width: 640px; margin: 0 auto; display: flex; align-items: baseline; gap: 12px; }
.brand { font: 700 19px/1.2 var(--round); margin: 0; letter-spacing: -0.01em; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 32px; }

/* Bottom tabs */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  background: var(--card);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-in { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 9px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--brand); }

/* Headings and text */
h1 { font: 700 24px/1.2 var(--round); margin: 4px 0 4px; letter-spacing: -0.01em; }
h2 { font: 700 18px/1.25 var(--round); margin: 28px 0 10px; }
h3 { font: 600 16px/1.3 var(--sans); margin: 0; }
p { margin: 0 0 10px; }
.lede { color: var(--muted); margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* Surfaces */
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.banner {
  border-left: 4px solid var(--porch);
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 15px;
}
.banner.bad { border-left-color: var(--warn); }

/* Snapshot strip on Home */
.snapshot { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 18px; }
.snap { min-width: 0; }
.snap span { display: block; font-size: 13px; color: var(--muted); }
.snap .n, .snap b { font: 700 20px/1.2 var(--round); }

/* The goal card: the house glyph carries the identity of the app */
.goal {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.house { width: 64px; height: 64px; display: block; }
.house .outline { fill: none; stroke: var(--brand); stroke-width: 2.4; stroke-linejoin: round; }
.house .lit { fill: var(--porch); }
.house .door { fill: var(--card); stroke: var(--brand); stroke-width: 2; }
.goal-name { font: 700 20px/1.25 var(--round); margin: 0; }
.goal-where { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.goal-when { font: 700 22px/1.2 var(--round); margin-bottom: 6px; letter-spacing: -0.01em; }
.goal-when.later { color: var(--muted); font-size: 18px; }
.facts { display: grid; gap: 4px; font-size: 14px; }
.fact { display: flex; justify-content: space-between; gap: 10px; }
.fact > span:first-child { color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin-top: 2px; }
.meter > i { display: block; height: 100%; background: var(--porch); border-radius: 3px; }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--chip); }
.tag.ok { color: var(--ok); }
.tag.bad { color: var(--warn); }

/* Explainable numbers */
.n {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--muted);
  text-underline-offset: 3px;
  cursor: help;
}
.n:hover { text-decoration-color: var(--brand); }

/* Ledger tables */
.ledger { width: 100%; border-collapse: collapse; font-size: 15px; }
.ledger th { text-align: left; font-weight: 400; color: var(--muted); padding: 6px 0; }
.ledger td { text-align: right; padding: 6px 0; white-space: nowrap; }
.ledger tr + tr th, .ledger tr + tr td { border-top: 1px solid var(--rule); }
.ledger tr.total th, .ledger tr.total td { font-weight: 700; color: var(--ink); }
.ledger.cols td, .ledger.cols th.col { text-align: right; padding-left: 10px; }
.ledger thead th { font-size: 13px; }

/* Forms */
form { margin: 0; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; margin-bottom: 14px; min-width: 0; }
.field label, .field .label { font-weight: 600; font-size: 15px; }
.help { font-size: 13px; color: var(--muted); }
.err { font-size: 13px; color: var(--warn); font-weight: 600; }
.input {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  min-height: 44px;
}
.input:focus-within { border-color: var(--brand); }
.input input, .input select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 10px 0;
  font-size: 16px;
  outline: none;
  width: 100%;
}
.input select { padding-right: 4px; appearance: auto; }
.input .unit { color: var(--muted); font-size: 14px; white-space: nowrap; }
.field.has-err .input { border-color: var(--warn); }
.btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 8px 16px;
  font-weight: 600;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: 0.55; cursor: default; }

/* Collapsible setup sections */
details.sec {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
details.sec > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: "+"; color: var(--muted); font-weight: 400; }
details.sec[open] > summary::after { content: "−"; }
details.sec > .sec-body { padding: 0 16px 16px; }

/* Charts */
.chart-wrap { position: relative; margin: 6px 0 4px; }
.chart { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .savings { stroke: var(--series-savings); }
.chart .cash { stroke: var(--series-cash); stroke-dasharray: 5 4; }
.chart .ref { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart .ref-label { fill: var(--muted); font-size: 11px; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.chart .dot { fill: var(--series-savings); stroke: var(--card); stroke-width: 2; }
.chart .marker { stroke: var(--ok); stroke-width: 1.5; }
.chart .marker-label { fill: var(--ok); font-size: 11px; font-weight: 700; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.chart .end-label { font-size: 11px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key i { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--series-savings); }
.key.cash i { border-top: 2px dashed var(--series-cash); }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  z-index: 2;
}
.tip .row-t { display: flex; align-items: center; gap: 6px; }
.tip b { font-weight: 700; }
.tip i { display: inline-block; width: 12px; border-top: 2px solid var(--series-savings); }
.tip i.cash { border-top: 2px dashed var(--series-cash); }
.tip .t { color: var(--muted); }

/* Explain sheet */
dialog.sheet {
  border: 0;
  padding: 0;
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  margin: auto auto 0;
  border-radius: 18px 18px 0 0;
  background: var(--card);
  color: var(--ink);
}
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 18px; }
}
dialog.sheet::backdrop { background: rgba(10, 16, 22, 0.45); }
.sheet-in { padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 86vh; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet-head button { appearance: none; border: 0; background: none; color: var(--brand); font-weight: 600; padding: 8px 0; min-height: 40px; }
.sheet h2 { margin: 2px 0 2px; }
.sheet .value { font: 700 30px/1.15 var(--round); margin-bottom: 12px; }
.formula {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 2.1;
  margin-bottom: 12px;
  font-size: 15px;
}
.chip {
  appearance: none;
  border: 0;
  background: var(--chip);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 14px;
  line-height: 1.5;
}
.chip b { font-weight: 700; margin-left: 2px; }
span.chip { display: inline; }
.sheet .note { border-left: 3px solid var(--porch); padding-left: 10px; }
.sheet .src { font-size: 13px; color: var(--muted); }
.inputs { list-style: none; padding: 0; margin: 0 0 12px; }
.inputs li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 15px; }
.inputs li button { appearance: none; border: 0; background: none; padding: 0; color: var(--brand); text-align: left; font-weight: 600; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  z-index: 30;
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .house { margin: 0 auto 10px; width: 72px; height: 72px; }

@media (prefers-reduced-motion: no-preference) {
  .house .lit { transition: y 0.5s ease, height 0.5s ease; }
}

.table-toggle { margin: 8px 0 16px; font-size: 14px; }
.table-toggle summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.table-toggle .ledger { margin-top: 6px; font-size: 14px; }

a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
