/* White and airy, light grey hairlines, no shadows. Colour always means something:
   blue = income, actions and progress; raspberry = shortfalls; green = cash, wealth, on track;
   violet = what a choice costs (spending on a choice is not a problem, so not the shortfall red). */

@font-face { font-family: Inter; font-weight: 400; font-display: swap; src: url("/static/fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: Inter; font-weight: 500; font-display: swap; src: url("/static/fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: Inter; font-weight: 600; font-display: swap; src: url("/static/fonts/inter-latin-600-normal.woff2") format("woff2"); }

:root {
  --blue: #2F5BC4; --blue-tint: #EEF2FB;
  --raspberry: #B83A63; --raspberry-tint: #FBEFF3;
  --green: #3F7F2A; --green-tint: #EEF6EA;
  --violet: #6E56CF;
  --ink: #111111; --muted: #5F5F5F; --line: #E6E6E6; --field-line: #DADADA;
  --panel: #F7F8FA; --page: #FFFFFF;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.45; }
a { color: var(--blue); }
a:hover { color: var(--ink); }
input, button, select { font: inherit; }
h1 { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Header */
.site-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 40px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.link-button { border: 0; background: none; padding: 0; color: var(--blue); cursor: pointer; font-size: 13px; }

/* Buttons */
.button { display: inline-flex; align-items: center; justify-content: center; height: 44px; padding: 0 24px; border: 0; border-radius: 4px; background: var(--blue); color: #fff; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; }
.button:hover { color: #fff; background: #244AA3; }
.button.small { height: 38px; padding: 0 18px; font-size: 13px; }
.button.quiet { background: #fff; color: var(--ink); border: 1px solid var(--field-line); }
.add-button { height: 40px; padding: 0; border: 0; background: none; color: var(--blue); font-size: 13px; cursor: pointer; text-align: left; }
.add-button.money-in { color: var(--green); }
.add-button, .remove-button { align-self: flex-start; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }
.remove-button { border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 4px 0; }
.remove-button:hover { color: var(--raspberry); }

/* Fields */
.field { display: flex; flex-direction: column; gap: 8px; font-size: 13px; font-weight: 500; min-width: 0; }
.field input, .field select { height: 48px; padding: 0 14px; border: 1px solid var(--field-line); border-radius: 4px; font-size: 15px; font-weight: 400; color: var(--ink); background: #fff; width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
.field .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
.field.filled input { background: var(--blue-tint); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 16px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid .wide { grid-column: 1 / -1; }
.inline-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }

/* Segmented toggles: radio inputs styled as buttons, so they work without JavaScript. */
.segmented { display: flex; border: 1px solid var(--field-line); border-radius: 4px; overflow: hidden; min-height: 46px; }
.segmented label { flex: 1; position: relative; display: flex; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { flex: 1; display: flex; align-items: center; justify-content: center; white-space: nowrap; padding: 0 16px; color: var(--muted); font-size: 14px; font-weight: 400; background: #fff; }
.segmented label + label span { border-left: 1px solid var(--field-line); }
.segmented input:checked + span { background: var(--blue-tint); color: var(--blue); font-weight: 500; }
.segmented input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: -2px; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 500; }

/* Wizard */
.steps { max-width: 760px; margin: 0 auto; padding: 32px 40px 0; }
.steps ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; font-size: 12px; }
.steps li { padding-top: 10px; border-top: 2px solid var(--line); color: var(--muted); }
.steps li.done { border-top-color: var(--blue); color: var(--ink); }
.steps li[aria-current="step"] { border-top-color: var(--blue); color: var(--blue); font-weight: 600; }
.steps a { color: inherit; text-decoration: none; }
.wizard { max-width: 640px; margin: 0 auto; padding: 44px 40px 72px; }
.wizard .intro { margin-top: 10px; font-size: 15px; color: var(--muted); }
.wizard-body { margin-top: 36px; display: flex; flex-direction: column; gap: 40px; }
/* One spacing rule for every section, so headings, cards and buttons sit evenly. */
.input-section { display: flex; flex-direction: column; gap: 24px; }
/* Contents sit in a body element: inside <details> the browser does not apply the section's own
   flex gap, which left some cards touching and others spaced. */
.section-body { display: flex; flex-direction: column; gap: 24px; }
.filled-tag { white-space: nowrap; margin-left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--blue-tint); color: var(--blue); font-size: 11px; font-weight: 500; }
.input-section h2, .input-section h3 { margin: 0; }
.input-section > .row-list { gap: 16px; }
.wizard-nav { margin-top: 44px; padding-top: 24px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.wizard-nav .back { border: 0; background: none; color: var(--ink); font-size: 14px; cursor: pointer; height: 44px; padding: 0; text-decoration: underline; }
.card { border: 1px solid var(--line); border-radius: 6px; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.card-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.row-list { display: flex; flex-direction: column; gap: 12px; }
.card h3, .row-list h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); }
.sub-card { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.row-line { display: grid; gap: 8px; align-items: end; }

/* Conditional sections, shown or hidden with :has() so no script is needed. */
.when-buying, .when-owning, .when-renting, .when-home, .when-couple, .when-retiring, .when-override, .when-recurring, .when-taxable-in { display: contents; }
/* Home: renting shows rent; buying later shows rent, the purchase and the shared home fields;
   owning shows today's value and loan and the shared home fields. */
.home-section:has(input[name="home.status"][value="rent"]:checked) :is(.when-home, .when-buying, .when-owning) { display: none; }
.home-section:has(input[name="home.status"][value="buy"]:checked) .when-owning { display: none; }
.home-section:has(input[name="home.status"][value="own"]:checked) :is(.when-renting, .when-buying) { display: none; }
.you-section:has(input[name="you.household"][value="single"]:checked) .when-couple { display: none; }
.person-card:has(input[name$=".retirement.on"][value="no"]:checked) .when-retiring { display: none; }
.dependant-row:has(input[name$=".override"]:not(:checked)) .when-override { display: none; }
.item-card:has(input[name$=".recurring"][value="no"]:checked) .when-recurring { display: none; }

/* Problems */
.problems { padding: 16px 20px; border-radius: 6px; background: var(--raspberry-tint); color: #8E2A4B; font-size: 14px; }
.problems ul { margin: 6px 0 0; padding-left: 18px; }

/* Landing */
.landing { max-width: 920px; margin: 0 auto; padding: 72px 40px; display: flex; flex-direction: column; gap: 40px; }
.landing .lead { font-size: 17px; color: var(--muted); max-width: 560px; margin-top: 14px; }
.start-form { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; }
.plan-note { margin: 4px 0 12px; font-size: 14px; max-width: 640px; }
.plan-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.plan-list li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }

/* Results screen */
/* Two fixed columns that never wrap: a sticky sidebar that wraps under the results would sit on
   top of them while scrolling. Only narrow screens stack, and there the sidebar is not sticky. */
.workspace { max-width: 1320px; margin: 0 auto; padding: 32px 40px; display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 32px; align-items: start; }
/* The inputs panel scrolls on its own beside the results, so the page ends with the results
   instead of trailing a long panel past them. */
.inputs-panel { min-width: 0; padding: 24px; background: var(--panel); border-radius: 6px; align-self: flex-start; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.inputs-panel .field input, .inputs-panel .field select { height: 38px; padding: 0 10px; font-size: 14px; }
.inputs-panel .field { font-size: 12px; color: var(--muted); font-weight: 400; gap: 6px; }
.inputs-panel .segmented { min-height: 36px; }
.inputs-panel .segmented span { font-size: 13px; padding: 0 8px; }
.inputs-panel .field-grid { gap: 12px; align-items: end; }
/* The panel is narrow: hints would wrap unevenly and push inputs out of line, so only
   "Pre-filled" hints are shown there. The wizard shows every hint. */
.inputs-panel .hint { display: none; }
.inputs-panel .field-grid.three { gap: 8px; }
.inputs-panel .inline-pair { align-items: end; }
.inputs-panel .card { padding: 14px; gap: 12px; background: #fff; }
.inputs-panel h1 { font-size: 13px; font-weight: 600; letter-spacing: 0; }
.panel-section { border-top: 1px solid var(--line); padding-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.panel-section:first-of-type { border-top: 0; padding-top: 14px; }
.panel-section > h2 { margin: 0; font-size: 13px; }
.inputs-panel .input-section { gap: 0; }
.inputs-panel .section-body { gap: 14px; padding-top: 14px; }
.inputs-panel .tabs { margin-bottom: 4px; }
.inputs-panel legend { font-size: 12px; font-weight: 400; color: var(--muted); margin-bottom: 6px; }
.inputs-panel .card h2, .inputs-panel .card h3 { font-size: 13px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); gap: 20px; }
.tabs label { padding: 0 0 10px; font-size: 13px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs input { position: absolute; opacity: 0; pointer-events: none; }
.inputs-panel:has(#tab-plan:checked) label[for="tab-plan"],
.inputs-panel:has(#tab-assumptions:checked) label[for="tab-assumptions"] { color: var(--blue); border-bottom-color: var(--blue); font-weight: 500; }
.inputs-panel:has(#tab-plan:checked) .assumptions-tab { display: none; }
.inputs-panel:has(#tab-assumptions:checked) .plan-tab { display: none; }
.collapsible > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary h2 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.collapsible > summary h2::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s; }
.collapsible[open] > summary h2::before { transform: rotate(45deg); }
.section-summary { font-size: 12px; color: var(--muted); text-align: right; }
.explain { font-size: 12px; color: var(--muted); margin: 0; }
.pay-change { display: flex; flex-direction: column; gap: 6px; }
.plan-tab, .assumptions-tab { display: flex; flex-direction: column; gap: 18px; }
.source { font-size: 11px; color: var(--muted); }

.results { min-width: 0; display: flex; flex-direction: column; gap: 32px; }
.verdict { padding: 24px 28px; background: var(--blue-tint); border-radius: 6px; }
.verdict .meta { margin: 0 0 12px; display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.tag { padding: 3px 8px; border-radius: 4px; font-weight: 500; }
.tag.on-track { background: var(--green-tint); color: #2D5E1E; }
.tag.short { background: var(--raspberry-tint); color: #8E2A4B; }
.verdict h1 { font-size: 32px; }
.verdict .line { margin-top: 10px; font-size: 15px; color: #3F3F3F; }
.key-numbers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.key-number { padding: 14px 16px 16px; border-top: 2px solid var(--green); }
.key-number + .key-number { border-left: 1px solid var(--line); }
.key-number:first-child { padding-left: 0; }
.key-number.cost { border-top-color: var(--raspberry); }
.key-number.income { border-top-color: var(--blue); }
.key-number .label { font-size: 12px; color: var(--muted); }
.key-number .value { margin-top: 6px; font-size: 22px; font-weight: 600; }
.key-number .note { margin-top: 2px; font-size: 12px; color: var(--muted); }
figure { margin: 0; }
figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
/* position: relative is set here, not left to the chart library's inline style, because htmx's
   morph can strip inline styles; without it the chart is positioned against the page. */
.chart { position: relative; width: 100%; height: 280px; overflow: hidden; }
.chart.small { height: 240px; }
.chart-note { margin-top: 10px; font-size: 13px; color: var(--muted); }
.cost-bars { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr) 96px; align-items: center; gap: 10px 16px; font-size: 14px; }
.bar-track { height: 10px; background: var(--panel); border-radius: 2px; }
.bar-track svg { display: block; width: 100%; height: 10px; }
/* What a choice costs is a choice, not a problem: violet, not the shortfall red. */
.bar-cost { fill: var(--violet); }
.bar-gain { fill: var(--green); }
.cost-amount { text-align: right; font-weight: 500; }
.moments { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; font-size: 14px; }
.moments > div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.moments .year { color: var(--blue); font-weight: 500; }
.moments .amount { text-align: right; color: var(--raspberry); }
.moments .amount.good { color: var(--green); }
.empty { color: var(--muted); font-size: 13px; }
.htmx-request .results { opacity: 0.7; }
.choice-costs-body.is-stale { opacity: 0.45; transition: opacity 0.2s; }

[data-just-added], .just-added-flash { scroll-margin-top: 16px; }

@media (max-width: 1000px) {
  .workspace { padding-left: 20px; padding-right: 20px; gap: 20px; grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .site-header, .workspace, .wizard, .steps, .landing { padding-left: 20px; padding-right: 20px; }
  .field-grid, .field-grid.three { grid-template-columns: minmax(0, 1fr); }
  .key-numbers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .inputs-panel { position: static; max-height: none; overflow: visible; }
  /* On a phone the prompt to start comes before the inputs it points to. */
  .workspace:has([data-empty-plan]) .results { order: -1; }
  .steps ol { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* "Add" pop-ups: centred over a dimmed page. */
.add-dialog { border: 0; border-radius: 8px; padding: 28px; width: min(560px, 92vw); max-height: 88vh; overflow: auto; color: var(--ink); }
.add-dialog::backdrop { background: rgba(17, 17, 17, 0.35); }
.add-dialog h2 { margin: 0 0 20px; font-size: 18px; font-weight: 600; }
.add-dialog .dialog-body { display: flex; flex-direction: column; gap: 16px; }
.add-dialog .hint { display: block; }
.add-dialog .dialog-actions { margin-top: 28px; display: flex; justify-content: flex-end; gap: 12px; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px 24px; }
/* A newly added entry is scrolled to and briefly highlighted. */
.just-added-flash { animation: added-flash 1.6s ease-out; }
@keyframes added-flash { from { background: var(--blue-tint); } to { background: transparent; } }

/* Long setup steps come in parts: finish one, press Next, and it folds to its heading. */
.part-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.part-edit { display: none; }
.wizard-part-folded > :not(.part-header) { display: none !important; }
.wizard-part-folded .part-edit { display: inline; }
.wizard-part-folded { cursor: pointer; padding-top: 16px; padding-bottom: 16px; }
.wizard-part-folded h2 { color: var(--muted); }
.part-footer { display: flex; justify-content: flex-end; }
.wizard-part-folded .part-header .remove-button { display: none; }
.part-next[hidden] { display: none; }

/* A new, empty plan: point at the sidebar instead of showing flat charts. */
.empty-state { padding: 32px 28px; background: var(--blue-tint); border-radius: 6px; display: flex; flex-direction: column; gap: 10px; }
.empty-state h1 { font-size: 26px; }
.empty-state p { font-size: 15px; color: #3F3F3F; max-width: 560px; }
.guided-link { margin: 0; font-size: 12px; color: var(--muted); }

/* Start page: the live example. */
.preview { display: flex; flex-direction: column; gap: 24px; padding: 28px; background: var(--panel); border-radius: 6px; }
.preview-intro h2 { margin: 0 0 6px; font-size: 20px; }
.preview-toggles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.preview-toggles .segmented span { font-size: 13px; padding: 0 10px; }
.preview-results { display: flex; flex-direction: column; gap: 24px; background: #fff; border-radius: 6px; padding: 24px; }
.preview-results .verdict h2.preview-verdict { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.preview-chart { width: 100%; height: 150px; display: block; }
.preview-chart polyline { fill: none; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.preview-wealth { stroke: var(--green); stroke-width: 3; }
.preview-cash { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.preview-zero { stroke: var(--field-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.legend-wealth { color: var(--green); font-weight: 500; }
.legend-cash { color: var(--muted); }
.preview-cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; font-size: 15px; }
@media (max-width: 760px) { .preview-toggles { grid-template-columns: minmax(0, 1fr); } }
