/* Haus — self-hosted styling only: system fonts, no remote assets. */

:root {
  --bg: #F4F6F3;
  --surface: #FFFFFF;
  --surface-2: #EDF1EC;
  --surface-3: #E3EAE2;
  --ink: #1B2620;
  --muted: #5C6A63;
  --faint: #8A968F;
  --line: #E0E6DF;
  --line-strong: #C9D2C8;
  --need: #0B8462;
  --need-soft: #E2F1EB;
  --want: #B07C2C;
  --want-soft: #F5ECDC;
  --bad: #B4392B;
  --bad-soft: #F8E7E4;
  --accent-ink: #0A6B50;
  --chart-recurring: #A3D2BF;
  --chart-bills: #0B8462;
  --chart-spends: #B07C2C;
  --tile-ring: rgba(11, 132, 98, 0.25);
  --shadow: 0 1px 2px rgba(27, 38, 32, 0.06), 0 4px 14px rgba(27, 38, 32, 0.05);
  --overlay: rgba(24, 32, 28, 0.94);
  --overlay-ink: #F2F6F3;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

/* Dark mode is its own set of steps chosen against the dark surface, not a flip
   of the light ones. Two identical blocks: follow the OS, or an explicit choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151A;
    --surface: #1B2027;
    --surface-2: #232A32;
    --surface-3: #2B333C;
    --ink: #E8ECE9;
    --muted: #99A5A0;
    --faint: #6E7A75;
    --line: #2A313A;
    --line-strong: #3A434D;
    --need: #2BA787;
    --need-soft: #1B2E2A;
    --want: #BC8130;
    --want-soft: #2F2717;
    --bad: #E0705C;
    --bad-soft: #33211E;
    --accent-ink: #4CC0A0;
    --chart-recurring: #2E6355;
    --chart-bills: #2BA787;
    --chart-spends: #BC8130;
    --tile-ring: rgba(43, 167, 135, 0.35);
    --shadow: none;
    --overlay: rgba(8, 11, 14, 0.95);
    --overlay-ink: #E8ECE9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151A;
  --surface: #1B2027;
  --surface-2: #232A32;
  --surface-3: #2B333C;
  --ink: #E8ECE9;
  --muted: #99A5A0;
  --faint: #6E7A75;
  --line: #2A313A;
  --line-strong: #3A434D;
  --need: #2BA787;
  --need-soft: #1B2E2A;
  --want: #BC8130;
  --want-soft: #2F2717;
  --bad: #E0705C;
  --bad-soft: #33211E;
  --accent-ink: #4CC0A0;
  --chart-recurring: #2E6355;
  --chart-bills: #2BA787;
  --chart-spends: #BC8130;
  --tile-ring: rgba(43, 167, 135, 0.35);
  --shadow: none;
  --overlay: rgba(8, 11, 14, 0.95);
  --overlay-ink: #E8ECE9;
  color-scheme: dark;
}

/* Flowery: pastel and colourful — blush ground, plum ink, mint for needs,
   rose for wants, coral for trouble. Contrast is kept at AA for body text. */
:root[data-theme="flowery"] {
  --bg: #FFF5F9;
  --surface: #FFFFFF;
  --surface-2: #FDEDF4;
  --surface-3: #F9E0EC;
  --ink: #3D2A36;
  --muted: #7E6273;
  --faint: #AD93A3;
  --line: #F1D8E4;
  --line-strong: #E3BBD0;
  --need: #2F8A5E;
  --need-soft: #DDF3E6;
  --want: #B85C93;
  --want-soft: #F9E2EE;
  --bad: #D3465F;
  --bad-soft: #FBE1E7;
  --accent-ink: #27754F;
  --chart-recurring: #C5E9D6;
  --chart-bills: #2F8A5E;
  --chart-spends: #B85C93;
  --tile-ring: rgba(184, 92, 147, 0.3);
  --shadow: 0 1px 2px rgba(61, 42, 54, 0.06), 0 6px 18px rgba(184, 92, 147, 0.10);
  --overlay: rgba(61, 42, 54, 0.94);
  --overlay-ink: #FFF5F9;
  color-scheme: light;
}
:root[data-theme="flowery"] body {
  background:
    radial-gradient(520px 320px at 8% -4%, rgba(255, 196, 221, 0.55), transparent 70%),
    radial-gradient(460px 300px at 96% 4%, rgba(200, 224, 255, 0.5), transparent 70%),
    radial-gradient(420px 260px at 60% 110%, rgba(255, 228, 190, 0.5), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
:root[data-theme="flowery"] .card,
:root[data-theme="flowery"] .tile { border-radius: 14px; }
:root[data-theme="flowery"] .tile.lead { background: linear-gradient(135deg, #FFFFFF, #FDEDF4); }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  padding: 28px 20px 72px;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1080px; margin: 0 auto; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

h1, h2, h3 { font-family: var(--sans); text-wrap: balance; margin: 0; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.005em; }
h3 { font-size: 13px; font-weight: 650; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

header.page { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 6px; }
header.page .spacer { flex: 1; }
.subtitle { color: var(--muted); margin: 0 0 20px; max-width: 68ch; }

/* connection chip */
.v1-chip {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 2px 10px 3px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.v1-chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint);
}
.v1-chip[data-state="live"] { color: var(--accent-ink); border-color: var(--tile-ring); }
.v1-chip[data-state="live"]::before { background: var(--need); animation: pulse 2.4s ease-in-out infinite; }
.v1-chip[data-state="offline"] { color: var(--bad); border-color: var(--bad); }
.v1-chip[data-state="offline"]::before { background: var(--bad); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .v1-chip::before { animation: none !important; } }

/* buttons */
button { font-family: var(--sans); cursor: pointer; }
button.ghost, button.primary {
  appearance: none; border-radius: 7px; font-size: 13px; font-weight: 600;
  padding: 6px 13px; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); transition: background 0.15s, border-color 0.15s;
}
button.ghost:hover { background: var(--surface-2); }
select.ghost {
  appearance: none; -webkit-appearance: none; border-radius: 7px; font: 600 13px var(--sans);
  padding: 6px 28px 6px 12px; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
select.ghost:hover { background-color: var(--surface-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button.primary { background: var(--need); border-color: var(--need); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.ghost.danger { color: var(--bad); border-color: transparent; margin-left: auto; }
button.ghost.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
:focus-visible { outline: 2px solid var(--need); outline-offset: 2px; border-radius: 5px; }

.tabs { display: flex; gap: 4px; margin-bottom: 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button {
  appearance: none; background: none; border: none; border-bottom: 2px solid transparent;
  font: 600 14px var(--sans); color: var(--muted); padding: 8px 14px 10px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--need); }
.tabs button:hover { color: var(--ink); }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px 12px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.tile .label {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); display: block; margin-bottom: 6px;
}
/* Proportional figures: a big standalone number reads loose with tabular-nums. */
.tile .big { font-size: 25px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.tile .big.negative { color: var(--bad); }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.tile.lead { border-color: var(--tile-ring); }
.tile.lead .big { color: var(--accent-ink); }
.tile.lead .big.negative { color: var(--bad); }
.spark-host { margin-top: 8px; height: 34px; }
.spark { width: 100%; height: 34px; display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--need); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark.is-negative .spark-line { stroke: var(--want); }
.spark-zero { stroke: var(--line-strong); stroke-width: 1; }

/* ---------- layout ---------- */
.grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; align-items: start; margin-top: 14px; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: 14px; }
.view-note { margin: -4px 0 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.card > header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 16px 0; }
.card .hint { font-size: 12px; color: var(--faint); text-align: right; }
.card .body { padding: 10px 16px 16px; }
.chart-card { margin-top: 14px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.scroll-x { overflow-x: auto; }
th {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; text-align: left; padding: 8px 8px 6px; border-bottom: 1px solid var(--line);
}
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: var(--mono); font-size: 13px; }
td.date { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
tr.cat-row td {
  font-weight: 650; font-size: 13px; background: var(--surface-2);
  padding-top: 6px; padding-bottom: 6px;
}
tr.cat-row td.num { font-family: var(--mono); font-weight: 650; }
tfoot td { border-top: 1px solid var(--line-strong); border-bottom: none; font-weight: 650; padding-top: 9px; }
tfoot td.num { font-family: var(--mono); }
td.act { width: 1%; text-align: right; padding-right: 0; }

.basis-note { display: block; font-size: 11.5px; color: var(--faint); font-family: var(--mono); }
.who { font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px 1px; margin-left: 4px; white-space: nowrap; }
.who-head { color: var(--muted); margin-bottom: 6px; }

.row-edit {
  appearance: none; background: none; border: none; color: var(--muted);
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  opacity: 0; transition: opacity 0.12s;
}
tr:hover .row-edit, .row-edit:focus-visible { opacity: 1; }
.row-edit:hover { background: var(--surface-2); color: var(--ink); }
@media (hover: none) { .row-edit { opacity: 1; } }

.chip {
  display: inline-block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em;
  text-transform: uppercase; border-radius: 999px; padding: 1px 8px 2px;
}
.chip.need { color: var(--need); background: var(--need-soft); }
.chip.want { color: var(--want); background: var(--want-soft); }

/* ---------- income list ---------- */
.income-block { display: grid; gap: 2px; }
.income-block + .income-block { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.kv-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px;
  padding: 4px 6px; border-radius: 6px; font-size: 14px; align-items: baseline;
}
.kv-row .k { color: var(--muted); overflow-wrap: anywhere; }
.kv-row .v { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.kv-row.editable { cursor: pointer; }
.kv-row.editable:hover { background: var(--surface-2); }
.kv-row.total .k, .kv-row.total .v { font-weight: 650; color: var(--ink); }
.rule { border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- editor ---------- */
.editor-row td { background: var(--surface-2); padding: 4px 8px 10px; }
.add-open, .kv-editor { margin-top: 8px; }
.editor {
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 9px; padding: 12px; display: grid; gap: 10px;
}
.editor-row .editor { border: none; background: none; padding: 6px 0 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.field { display: grid; gap: 3px; min-width: 0; }
.field-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.field input, .field select, .basis select {
  font: 400 13.5px var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px;
  width: 100%; min-width: 0;
}
.field input[type="number"] { font-family: var(--mono); text-align: right; }
.basis { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; }
.basis select { width: auto; padding: 6px 4px; font-size: 12px; color: var(--muted); }
.editor-actions { display: flex; gap: 8px; align-items: center; }

.add {
  appearance: none; margin-top: 10px; width: 100%; background: none;
  border: 1px dashed var(--line-strong); border-radius: 8px;
  color: var(--muted); font-size: 13px; font-weight: 600; padding: 8px 12px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.add:hover { border-color: var(--need); color: var(--accent-ink); background: var(--need-soft); }
.add span { font-size: 15px; line-height: 1; margin-right: 2px; }
.add.slim { margin-top: 4px; padding: 5px 10px; font-size: 12px; }

select {
  font: 500 12.5px var(--sans); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 3px 6px; cursor: pointer;
}

/* ---------- charts ---------- */
.chart-host { margin-top: 4px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.gridline { stroke: var(--line); stroke-width: 1; }
.zeroline { stroke: var(--line-strong); stroke-width: 1; }
.tick, .axis-label { fill: var(--muted); font: 10px var(--mono); font-variant-numeric: tabular-nums; }
.cap-label { fill: var(--muted); font: 600 10px var(--mono); transition: opacity 0.25s; }

.ylc .seg.recurring { fill: var(--chart-recurring); }
.ylc .seg.bills { fill: var(--chart-bills); }
.ylc .seg.spends { fill: var(--chart-spends); }
.ylc .hit { fill: transparent; }
.ylc .col .seg { transition: opacity 0.15s; }
.ylc .col.hover .seg { opacity: 0.82; }
.ylc .col.hover .cap-label { fill: var(--ink); }

.line { fill: none; stroke: var(--need); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { fill: var(--need); opacity: 0.1; stroke: none; }
.end-dot { fill: var(--need); stroke: var(--surface); stroke-width: 2; }
.end-label { fill: var(--muted); font: 600 11px var(--mono); }
.crosshair { stroke: var(--line-strong); stroke-width: 1; transition: opacity 0.12s; }
.marker { fill: var(--need); stroke: var(--surface); stroke-width: 2; transition: opacity 0.12s; }
.chart.is-negative .line, .chart.is-negative .end-dot, .chart.is-negative .marker { stroke-linecap: round; }
.chart .hit { fill: transparent; }

.legend { display: flex; gap: 14px; align-items: center; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; margin-bottom: 10px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.swatch.need { background: var(--need); }
.swatch.want { background: var(--want); }
.swatch.recurring { background: var(--chart-recurring); }
.swatch.bills { background: var(--chart-bills); }
.swatch.spends { background: var(--chart-spends); }

.barlist { display: flex; flex-direction: column; gap: 9px; }
.barrow { display: grid; grid-template-columns: 118px minmax(0, 1fr) 78px; gap: 10px; align-items: center; font-size: 13px; }
.barrow .name { color: var(--ink); overflow-wrap: anywhere; }
.barrow .track { display: flex; gap: 2px; height: 14px; }
.barrow .seg { border-radius: 0 4px 4px 0; transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1); }
.barrow .seg:first-child { border-radius: 4px 0 0 4px; }
.barrow .seg.zero { width: 0 !important; }
.barrow .seg.need { background: var(--need); }
.barrow .seg.want { background: var(--want); }
.barrow .val { text-align: right; font-family: var(--mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.barrow:hover .name { font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .barrow .seg { transition: none; } }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; top: 0; left: 0; z-index: 40; pointer-events: none;
  background: var(--overlay); color: var(--overlay-ink);
  border-radius: 8px; padding: 9px 11px; font-size: 12.5px; min-width: 168px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22); will-change: transform;
}
.tooltip[hidden] { display: none; }
.tt-title { font-weight: 650; margin-bottom: 5px; font-size: 12.5px; }
.tt-row { display: flex; justify-content: space-between; gap: 18px; line-height: 1.6; opacity: 0.9; }
.tt-row b { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.tt-row i { font-style: normal; opacity: 0.55; font-size: 11px; }
.tt-total { margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255, 255, 255, 0.18); opacity: 1; font-weight: 600; }

/* ---------- sign in ---------- */

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 30px 24px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card input[type="email"], .auth-card input[type="password"] {
  width: 100%; font: 500 15px var(--sans); padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.auth-card input:focus-visible { outline: 2px solid var(--need); outline-offset: 1px; }
.auth-submit { width: 100%; padding: 10px; font-size: 14px; margin-top: 6px; }
.auth-submit:disabled { opacity: 0.6; cursor: progress; }
.auth-error {
  margin: 4px 0 0; padding: 9px 11px; border-radius: 8px; font-size: 13px;
  background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad);
}
.auth-error[hidden] { display: none; }
.auth-links { margin: 18px 0 0; font-size: 13px; color: var(--muted); display: flex; gap: 8px; justify-content: center; }
.auth-links a { color: var(--accent-ink); }
.auth-note { margin: 16px 0 0; font-size: 11.5px; color: var(--faint); text-align: center; }
.auth-note.warn { color: var(--bad); font-weight: 600; }
.auth-placeholder {
  border: 1px dashed var(--line-strong); border-radius: 10px; padding: 14px 16px;
  font-size: 13px; color: var(--muted); line-height: 1.6; background: var(--surface-2);
}
.auth-placeholder code { font-size: 11.5px; word-break: break-all; }

/* who is signed in, in the header */
.whoami {
  appearance: none; display: inline-flex; align-items: center; gap: 9px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 999px; padding: 3px 12px 3px 3px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.whoami:hover { background: var(--surface-2); }
.whoami .avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--need); color: #fff; font: 700 11px var(--sans);
}
.whoami.anonymous .avatar { background: var(--surface-3); color: var(--faint); }
.whoami-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.whoami-text b { font: 600 12.5px var(--sans); color: var(--ink); }
.whoami-text i { font-style: normal; font-size: 10.5px; color: var(--faint); }

/* the Haus, in settings */
.haus-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.haus-name { font-size: 15px; font-weight: 650; margin-right: 8px; }
.role-chip {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  border-radius: 999px; padding: 2px 8px 3px; border: 1px solid var(--line-strong); color: var(--muted);
}
.role-chip.role-owner { color: var(--accent-ink); border-color: var(--tile-ring); }
.set-select { padding: 7px 28px 7px 11px; }
.set-signout {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface-2);
  font-size: 13.5px;
}
.set-signout .exp-meta { display: block; }
button.ghost.danger-outline { color: var(--bad); border-color: var(--line-strong); }
button.ghost.danger-outline:hover { background: var(--bad-soft); border-color: var(--bad); }
.invite-link {
  margin-top: 12px; border: 1px solid var(--tile-ring); border-radius: 10px;
  padding: 12px 14px; background: var(--need-soft); font-size: 13px;
}
.invite-link p { margin: 0 0 8px; }
.invite-link input {
  width: 100%; font: 500 12px var(--mono); padding: 7px 9px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  margin-bottom: 8px;
}

/* ---------- settings ---------- */

.cog {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  cursor: pointer; transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.cog:hover { color: var(--ink); background: var(--surface-2); }
.cog svg { display: block; }

dialog.settings { max-width: 560px; }
#settings-body { padding: 22px 24px 24px; overflow-y: auto; max-height: min(80vh, 720px); }
#settings-body:focus { outline: none; }
#settings-body h2 { font-size: 17px; margin-bottom: 6px; }
#settings-body h3 {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 24px 0 6px; padding-top: 16px; border-top: 1px solid var(--line);
}
.set-note { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.set-rows { display: flex; flex-direction: column; gap: 8px; }
.set-row { display: flex; gap: 8px; align-items: center; }
.set-row input {
  flex: 1; font: 500 14px var(--sans); padding: 7px 10px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.set-add { margin-top: 10px; }
.set-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.set-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 999px; padding: 4px 4px 4px 11px; font-size: 13px;
}
.set-chip i {
  font-style: normal; font-family: var(--mono); font-size: 10.5px; color: var(--faint);
}
.set-remove {
  appearance: none; border: none; background: none; cursor: pointer; color: var(--muted);
  width: 19px; height: 19px; border-radius: 50%; font-size: 15px; line-height: 1; padding: 0;
}
.set-remove:hover:not(:disabled) { background: var(--bad-soft); color: var(--bad); }
.set-remove:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---------- savings, pensions and the calculators ---------- */

.holdings td { vertical-align: top; }
.row-name { font-weight: 600; }
.row-meta { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.goal { display: inline-block; min-width: 92px; }
.goal-bar { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.goal-bar i { display: block; height: 100%; background: var(--need); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.toggle input { width: 15px; height: 15px; }
.field-hint { font-size: 11px; color: var(--faint); margin-top: 3px; display: block; }

.calc-source { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.calc-source select {
  font: 500 13px var(--sans); padding: 5px 10px; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.calc-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0 4px; }
.calc-field { display: flex; flex-direction: column; gap: 4px; }
.calc-field > span {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.calc-input { display: flex; align-items: center; gap: 6px; }
.calc-input input {
  width: 100%; font: 600 15px var(--sans); font-variant-numeric: tabular-nums;
  padding: 7px 9px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
}
.calc-input i { font-style: normal; font-size: 12px; color: var(--faint); white-space: nowrap; }
.calc-head {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 22px 0 2px; padding-top: 14px; border-top: 1px solid var(--line);
}
.calc-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; margin: 10px 0 4px; }
.calc-out > div { display: flex; flex-direction: column; gap: 2px; }
.calc-out .label { font-size: 12px; color: var(--muted); }
.calc-out b { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.calc-out b.good { color: var(--accent-ink); }
.cover-bar { display: flex; gap: 5px; margin: 10px 0 2px; }
.cover-bar i { flex: 1; height: 9px; border-radius: 3px; background: var(--surface-3); }
.cover-bar i.on { background: var(--need); }
.legend .swatch.total { background: var(--need); }
.legend .swatch.invested { background: var(--line-strong); }
.growth-total { fill: none; stroke: var(--need); stroke-width: 2.2; stroke-linejoin: round; }
.growth-invested { fill: none; stroke: var(--line-strong); stroke-width: 1.6; stroke-dasharray: 4 4; }

/* ---------- explanations ---------- */

/* The control stays out of the way until you go looking: hidden by default,
   revealed when the tile is hovered, and always revealed when it has focus so
   a keyboard never loses it. */
.why {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--muted); font: 600 9.5px/1 var(--sans);
  width: 15px; height: 15px; border-radius: 50%; padding: 0; margin-left: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: -2px; cursor: pointer; opacity: 0; transition: opacity 0.14s, color 0.14s, border-color 0.14s;
}
.tile:hover .why, .card:hover .why, .why:focus-visible { opacity: 1; }
.why:hover { color: var(--accent-ink); border-color: var(--tile-ring); }
.why:focus-visible { opacity: 1; }
@media (hover: none) { .why { opacity: 1; } }  /* touch has no hover to reveal it */

.tt-formula { font-family: var(--mono); font-size: 12px; line-height: 1.5; }
.tt-hint { margin-top: 6px; font-size: 11px; opacity: 0.6; }

dialog.explain {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--ink);
  max-width: 520px; width: calc(100% - 32px); max-height: min(80vh, 720px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}
dialog.explain::backdrop { background: rgba(12, 16, 14, 0.42); backdrop-filter: blur(2px); }
#explain-body { padding: 22px 24px 24px; overflow-y: auto; max-height: min(80vh, 720px); }
#explain-body:focus { outline: none; }  /* focused for screen readers, not to be drawn */
.explain-close {
  position: absolute; top: 10px; right: 12px; appearance: none; border: none; background: none;
  color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.explain-close:hover { background: var(--surface-2); color: var(--ink); }
#explain-body h2 { font-size: 17px; margin-bottom: 2px; }
#explain-body h3 {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 20px 0 8px;
}
.exp-value { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 10px; }
.exp-formula {
  margin: 0 0 12px; padding: 9px 11px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.6;
}
.exp-long { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.exp-rows { border-top: 1px solid var(--line); }
.exp-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px;
}
.exp-row-value { font-variant-numeric: tabular-nums; }
.exp-meta { display: block; font-size: 11.5px; color: var(--faint); }
.exp-total { font-weight: 650; border-bottom: none; }
.link-why {
  appearance: none; border: none; background: none; padding: 0 0 0 4px; cursor: pointer;
  color: var(--accent-ink); font: 500 12px var(--sans); text-decoration: underline; text-underline-offset: 2px;
}
.exp-assumptions { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.exp-assumptions li { margin-bottom: 4px; }
.exp-terms { margin: 0; font-size: 13px; }
.exp-terms dt { font-weight: 650; margin-top: 10px; }
.exp-terms dd { margin: 2px 0 0; color: var(--muted); line-height: 1.55; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50; background: var(--overlay); color: var(--overlay-ink);
  border-radius: 999px; padding: 9px 18px; font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  animation: rise 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast[hidden] { display: none; }
.toast[data-tone="error"] { background: var(--bad); color: #fff; border-radius: 10px; max-width: min(520px, 90vw); text-align: center; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- asset page ---------- */
.asset .band { fill: var(--need); opacity: 0.12; stroke: none; }
.asset .equity-fill { fill: var(--accent-ink); opacity: 0.1; stroke: none; }
.asset .line.value { stroke: var(--need); }
.asset .line.balance { stroke: var(--want); }
.asset .marker.value { fill: var(--need); stroke: var(--surface); stroke-width: 2; }
.asset .marker.balance { fill: var(--want); stroke: var(--surface); stroke-width: 2; }
.asset .end-label.value { fill: var(--accent-ink); }
.asset .end-label.balance { fill: var(--want); }
.asset .nowline { stroke: var(--line-strong); stroke-width: 1; }
.asset .now-label { fill: var(--faint); font: 600 9.5px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }

.swatch.value { background: var(--need); }
.swatch.balance { background: var(--want); }
.swatch.band { background: var(--need); opacity: 0.28; }
.swatch.equity { background: var(--accent-ink); opacity: 0.28; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.mini-stats > div {
  background: var(--surface-2); border-radius: 8px; padding: 9px 11px 10px; display: grid; gap: 1px;
}
.mini-stats .label {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.mini-stats b { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.mini-stats .sub { font-size: 11.5px; color: var(--faint); }

.status {
  display: inline-block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em;
  text-transform: uppercase; border-radius: 999px; padding: 1px 8px 2px; white-space: nowrap;
}
.status.done { color: var(--need); background: var(--need-soft); }
.status.quoted { color: var(--want); background: var(--want-soft); }
.status.planned { color: var(--muted); background: var(--surface-3); }

.property-form { background: none; border: none; padding: 0; }
.property-form .editor-actions { flex-wrap: wrap; }
.suffixed { position: relative; display: flex; align-items: center; }
.suffixed input { padding-right: 34px; }
.suffixed .suffix {
  position: absolute; right: 9px; font-size: 11.5px; color: var(--faint);
  font-family: var(--mono); pointer-events: none;
}

/* ---------- payment speed ---------- */
.speed { display: grid; gap: 14px; }
.speed-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.speed-head .label {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); display: block;
}
.speed-head .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.speed-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  appearance: none; background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 600; color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.preset:hover { background: var(--need-soft); color: var(--accent-ink); border-color: var(--tile-ring); }

input[type="range"] {
  appearance: none; -webkit-appearance: none; width: 100%; background: none; margin: 2px 0 0; padding: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px; background: var(--surface-3);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px;
  border-radius: 50%; background: var(--need); border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25); cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--need);
  border: 2px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,0.25); cursor: grab;
}
input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }
.speed-scale {
  display: flex; justify-content: space-between; font-family: var(--mono);
  font-size: 10.5px; color: var(--faint); margin-top: -2px;
}

.speed-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.speed-out > div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px 11px; display: grid; gap: 1px; }
.speed-out .label {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.speed-out b { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.speed-out .sub { font-size: 11.5px; color: var(--faint); }
.speed-out .good { background: var(--need-soft); }
.speed-out .good b { color: var(--accent-ink); }
.speed-out .good.is-zero { background: var(--surface-2); }
.speed-out .good.is-zero b { color: var(--ink); }
.speed-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.speed-actions button[disabled] { opacity: 0.45; cursor: default; filter: none; }

.payoff .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.payoff .line.contractual { stroke: var(--faint); stroke-width: 1.5; }
.payoff .line.actual { stroke: var(--chart-recurring); }
.payoff .line.slider { stroke: var(--need); stroke-width: 2.5; }
.payoff .payoff-dot { stroke: var(--surface); stroke-width: 2; }
.payoff .payoff-dot.contractual { fill: var(--faint); }
.payoff .payoff-dot.actual { fill: var(--chart-recurring); }
.payoff .payoff-dot.slider { fill: var(--need); }
.payoff .end-label.slider { fill: var(--accent-ink); font: 600 11px var(--mono); }

.swatch.contractual { background: var(--faint); }
.swatch.actual { background: var(--chart-recurring); }
.swatch.slider { background: var(--need); }

.field-group-label {
  grid-column: 1 / -1; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--faint); padding-top: 6px;
  border-top: 1px solid var(--line); margin-top: 2px;
}
.over { color: var(--accent-ink); font-weight: 600; font-size: 11.5px; }

.kv-list { display: grid; gap: 3px; margin: 0; }
.kv-list > div { display: flex; justify-content: space-between; gap: 14px; align-items: baseline; padding: 3px 0; }
.kv-list dt { color: var(--muted); font-size: 13.5px; margin: 0; }
.kv-list dd { margin: 0; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- outgoings page ---------- */
.tabs button.tab-tool { color: var(--faint); }
.tabs button.tab-tool[aria-selected="true"] { color: var(--ink); }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end;
  padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.filter { display: grid; gap: 3px; min-width: 0; }
.filter > span {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--faint);
}
.filter.grow { flex: 1; min-width: 160px; }
.filter input[type="search"] {
  font: 400 13px var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 4px 9px; width: 100%;
}
.filters button.ghost { padding: 4px 11px; }

.add-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 0 4px; }
.add-row-label { font-size: 12.5px; color: var(--muted); }
.add-row .add { width: auto; margin-top: 0; }

table.dense td { padding: 5px 8px; }
table.dense th { padding: 7px 8px 5px; }
.who-cell { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.faint { color: var(--faint); }
td.num .faint { font-family: var(--sans); }

.type-chip {
  display: inline-block; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.05em;
  text-transform: uppercase; border-radius: 4px; padding: 1px 6px 2px;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.type-chip.monthly { background: var(--need-soft); color: var(--need); }
.type-chip.yearly { background: var(--want-soft); color: var(--want); }
.type-chip.improvements { background: var(--surface-3); color: var(--ink); }

.row-del {
  appearance: none; background: none; border: none; color: var(--faint);
  font-size: 17px; line-height: 1; padding: 1px 7px 3px; border-radius: 6px;
  opacity: 0; transition: opacity 0.12s, background 0.12s, color 0.12s;
}
tr:hover .row-del, .row-del:focus-visible { opacity: 1; }
.row-del:hover { background: var(--bad-soft); color: var(--bad); }
@media (hover: none) { .row-del { opacity: 1; } }
td.act { white-space: nowrap; }

.empty {
  border: 1px dashed var(--line-strong); border-radius: 8px; padding: 18px 16px;
  color: var(--muted); font-size: 13.5px; text-align: center;
}
.empty.slim { padding: 8px 12px; font-size: 12.5px; }
.footnote { font-size: 12px; color: var(--faint); margin: 10px 0 0; max-width: 70ch; }
.hint { font-size: 12px; color: var(--faint); }
