:root {
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    sans-serif;
  color: #20352f;
  background: #f3f5f1;
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
select {
  font: inherit;
}
button {
  cursor: pointer;
  border: 0;
  border-radius: 7px;
  padding: 11px 16px;
  background: #28654e;
  color: white;
  font-weight: 600;
}
button:hover {
  filter: brightness(0.94);
}
button.secondary {
  background: #e8eee9;
  color: #284c3c;
}
button.danger {
  background: #f8e7e3;
  color: #922f23;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
input,
select {
  width: 100%;
  padding: 11px;
  border: 1px solid #cbd6cc;
  border-radius: 6px;
  background: #fff;
  color: #20352f;
}
label {
  display: grid;
  gap: var(--field-gap, 12px);
  font-size: 13px;
  font-weight: 600;
}
h1 {
  font-size: 32px;
  letter-spacing: -1px;
  margin: 0 0 10px;
}
h2 {
  font-size: 19px;
  margin: 0 0 18px;
}
h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
p {
  line-height: 1.6;
  color: #64736a;
}
small {
  color: #68796c;
}
a {
  color: #28654e;
}
.shell {
  display: grid;
  grid-template-columns: 235px 1fr;
  min-height: 100vh;
}
aside {
  background: #153e31;
  color: #e4eee7;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
  gap: 25px;
}
aside .brand {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
  padding: 0 12px;
}
aside .brand span {
  display: block;
  font-size: 11px;
  letter-spacing: 2px;
  color: #b6d4bb;
  margin-top: 8px;
}
nav {
  display: grid;
  gap: 6px;
}
nav button {
  text-align: left;
  background: transparent;
  color: #c2d4c9;
  font-weight: 500;
}
nav button.active {
  background: #315647;
  color: #fff;
}
aside footer {
  margin-top: auto;
  font-size: 12px;
  overflow-wrap: anywhere;
  color: #b6c9bc;
}
aside footer button {
  margin-top: 12px;
  background: #315647;
}
main {
  padding: 38px 44px;
  max-width: 1500px;
  width: 100%;
}
.top {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 28px;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 1.6px;
  font-size: 11px;
  color: #687d6f;
  font-weight: 700;
  margin-bottom: 12px;
}
.badge {
  font-size: 12px;
  color: #47624c;
  border: 1px solid #d1ded0;
  padding: 7px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.notice {
  padding: 15px 18px;
  background: #fff6df;
  border: 1px solid #eadcba;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: #725e2e;
  margin: 20px 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.card {
  background: #fff;
  border: 1px solid #e0e6dc;
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}
.stat {
  font-size: 31px;
  font-weight: 600;
  letter-spacing: -1px;
  margin: 10px 0;
}
.muted {
  font-size: 13px;
  color: #6d7e71;
}
.two {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
}
.formgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
form button {
  margin-top: 20px;
}
.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0;
  border-bottom: 1px solid #edf0e9;
}
.row:last-child {
  border-bottom: 0;
}
.row p {
  margin: 4px 0;
  font-size: 13px;
}
.number {
  text-align: right;
  white-space: nowrap;
  font-size: 19px;
  font-weight: 600;
}
.empty {
  text-align: center;
  padding: 35px 15px;
  color: #758476;
}
.auth {
  max-width: 460px;
  margin: 10vh auto;
  padding: 35px;
}
.auth label {
  margin-top: 18px;
}
.auth button {
  width: 100%;
}
.chart {
  width: 100%;
  height: 230px;
  margin: 14px 0;
}
.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #718272;
}
.scenario {
  min-width: 170px;
  width: auto;
}
.loading {
  padding: 60px;
  text-align: center;
}
#toast {
  position: fixed;
  bottom: 25px;
  right: 25px;
  max-width: 440px;
  padding: 15px 22px;
  border-radius: 8px;
  background: #203f31;
  color: #fff;
  display: none;
  z-index: 10;
  box-shadow: 0 4px 20px #0002;
}
.error {
  color: #ac3528;
}
.wide {
  grid-column: 1/-1;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
td,
th {
  text-align: left;
  padding: 12px 7px;
  border-bottom: 1px solid #edf0e9;
}
th {
  color: #738071;
  font-weight: 500;
}
.scroll {
  overflow: auto;
}
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }
  aside {
    padding: 18px;
    gap: 15px;
  }
  aside .brand span,
  aside footer {
    display: none;
  }
  nav {
    display: flex;
    overflow: auto;
  }
  nav button {
    white-space: nowrap;
  }
  main {
    padding: 25px 18px;
  }
  .grid,
  .two {
    grid-template-columns: 1fr;
  }
  .top {
    align-items: flex-start;
  }
  .badge {
    display: none;
  }
}
@media (max-width: 500px) {
  .formgrid {
    grid-template-columns: 1fr;
  }
  .auth {
    margin: 5vh 15px;
    padding: 25px;
  }
  h1 {
    font-size: 27px;
  }
  .card {
    padding: 19px;
  }
}

.chart-legend-item { display: inline-block; margin: 0 16px 8px 0; }
input[type="color"] { height: 42px; padding: 4px; cursor: pointer; }

.income-chart-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: start; }
.income-chart-legend { position: static; width: auto; padding: 12px; background: transparent; color: inherit; border: 0; }
.income-key-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 13px; }
.income-swatch { flex: 0 0 16px; width: 16px; height: 16px; }
.income-breakdown-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #dde5df; }
.income-breakdown-row strong { margin-left: auto; white-space: nowrap; }
@media (max-width: 850px) { .income-chart-layout { grid-template-columns: minmax(0, 1fr); } }

.account-colour-control { display: flex; align-items: center; gap: 12px; }
.account-colour-control input[type="color"] { width: 52px; min-width: 52px; height: 38px; appearance: auto; -webkit-appearance: auto; padding: 2px; }
.account-colour-control svg { flex: 0 0 32px; }
.account-table-swatch { vertical-align: middle; margin-right: 6px; }
.archived-accounts { margin-top: 20px; padding-top: 16px; border-top: 1px solid #dce5da; }
.archived-accounts summary { font-weight: 700; cursor: pointer; }
.archived-accounts .scroll { margin-top: 14px; }

#forecast-settings .formgrid { align-items: start; gap: 18px 24px; }
#forecast-settings label { display: flex; flex-direction: column; gap: 8px; margin: 0; }
#forecast-settings input, #forecast-settings select { box-sizing: border-box; width: 100%; height: 44px; min-height: 44px; margin: 0; padding: 10px 12px; font: inherit; }
#forecast-settings .formgrid > label { display: grid; grid-template-rows: auto 44px; align-content: start; gap: 8px; }
#forecast-settings label small { font-weight: normal; }
#forecast-settings .downturn-help { margin: -4px 0 0; color: #64736a; }
.funding-preference-groups { display: grid; gap: 24px; }
.funding-preference-group h3 { margin: 0 0 14px; }
.funding-preference-grid { display: grid; align-items: start; gap: 18px 24px; }
.funding-preference-grid > label { display: grid; grid-template-rows: auto 44px; align-content: start; gap: 8px; }
.funding-general .funding-preference-grid { grid-template-columns: 1.15fr .75fr .75fr 1.8fr; }
.funding-general .downturn-help { grid-column: 1 / -1; }
.funding-pension .funding-preference-grid { grid-template-columns: 2fr 1fr; }
.funding-cash .funding-preference-grid { grid-template-columns: 1fr 1fr; max-width: 820px; }
@media (max-width: 1050px) {
  .funding-general .funding-preference-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 500px) {
  .funding-preference-grid, .funding-general .funding-preference-grid, .funding-pension .funding-preference-grid, .funding-cash .funding-preference-grid { grid-template-columns: 1fr; }
}
#forecast-settings fieldset { margin: 20px 0; padding: 18px; border: 1px solid #dce5da; border-radius: 8px; }
#forecast-settings fieldset > label { margin-bottom: 14px; }
.extra-pension-heading { text-align: center; background: #edf4ef; border-bottom: 2px solid #adc8b5; }
caption { text-align: left; padding: 10px 0; color: #64736a; }

.annual-summary-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px 20px; margin: 12px 0; }
.annual-summary-grid > span { display: flex; flex-direction: column; gap: 3px; }
.annual-summary-grid small { font-weight: normal; }
.annual-person-tax { display: grid; gap: 7px; margin: 10px 0; font-size: 13px; }
.forecast-year > summary { cursor: pointer; }
.forecast-year[open] > summary { margin-bottom: 18px; }
@media (max-width: 850px) { .annual-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.rate-plot svg { width: 100%; min-height: 240px; touch-action: none; }
.rate-plot circle { cursor: ns-resize; }
.rate-plot circle:focus { stroke: #a66b28; stroke-width: 4px; outline: none; }
.rate-value-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(110px,1fr)); gap: 12px; margin: 20px 0; }
.rate-editor [data-stats] { font-weight: 600; margin: 16px 0; }
#scenario-form fieldset label { margin-bottom: 12px; }

/* Keep rate controls aligned without stretching an input beside the fill button. */
.rate-editor .formgrid,
#scenario-form .formgrid { align-items: start; }
.rate-editor label,
#scenario-form label { align-content: start; }
.rate-editor input,
.rate-editor select,
#scenario-form input,
#scenario-form select { height: 44px; min-height: 44px; margin: 0; padding: 10px 12px; }
.rate-editor .rate-fill-controls {
  display: flex;
  flex-direction: column;
  gap: var(--field-gap, 12px);
  grid-row: span 2;
  min-width: 0;
}
.rate-editor .rate-fill-controls > label { margin: 0; }
.rate-editor .rate-fill-controls > [data-fill] { margin: 0; }
.overview-scenario { margin-bottom: 20px; }
.overview-scenario select { width: 100%; max-width: 440px; height: 44px; }

.scenario-choice { padding: 12px; border: 2px solid transparent; border-radius: 8px; cursor: pointer; margin-bottom: 8px; gap: 12px; }
.scenario-choice.is-selected { background: #e8eee9; border-color: #28654e; }
.scenario-choice:hover { background: #edf2ed; }
.scenario-choice-main { flex: 1; min-width: 0; text-align: left; background: transparent; color: inherit; padding: 8px; margin: 0; font-weight: normal; }
.scenario-choice-main:hover { filter: none; }
.scenario-choice-main:focus-visible { outline: 2px solid #28654e; outline-offset: 2px; }

/* Supporting details sit beneath the full-width overview charts. */
.overview-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.overview-main { min-width: 0; }
.overview-summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.overview-summary .card { padding: 18px; margin-bottom: 16px; }
.overview-allowances { margin-top: 16px; }
.overview-allowances .row { padding: 10px 0; }
.overview-summary #income-year-deposits { margin-bottom: 0; }
@media (max-width: 900px) { .overview-layout { grid-template-columns: minmax(0, 1fr); gap: 0; } }
@media (max-width: 600px) { .overview-summary { grid-template-columns: minmax(0, 1fr); gap: 0; } }

.overview-header { gap: 20px; flex-wrap: wrap; }
.overview-header .overview-scenario { margin-bottom: 0; width: 285px; max-width: 100%; }
.income-chart-main { min-width: 0; }

#income-bars [aria-pressed="true"] text { font-weight: 700; text-decoration: underline; }

.template-import { padding: 18px 24px; }
.template-import > p { margin-top: 0; }
.template-import-controls { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.template-import-controls label { flex: 1; min-width: 220px; margin: 0; }
.template-import-controls select, .template-import-controls button { height: 44px; margin-bottom: 0; }

.account-modal { width: min(1000px, calc(100vw - 40px)); max-height: calc(100dvh - 40px); box-sizing: border-box; overflow: auto; border: 1px solid #dce5da; border-radius: 12px; padding: 24px; color: #253e34; background: #f5f7f2; }
.account-modal::backdrop { background: rgb(0 0 0 / 45%); }
.account-modal-header { gap: 20px; }
.account-modal-header h2 { margin: 0; }
.balance-history-layout > button { margin-bottom: 16px; }
.balance-history-layout td { vertical-align: top; }
.account-modal [hidden] { display: none; }

.default-scenario { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; white-space: nowrap; }
.default-scenario input { width: auto; height: auto; margin: 0; }

#person label { display: block; margin-top: 20px; }
#person > label:first-child { margin-top: 0; }
#person label small { display: block; margin: 6px 0 8px; font-weight: normal; line-height: 1.4; }
#person fieldset { margin-top: 20px; margin-bottom: 20px; }

.account-group-heading { background: #e8eee8; color: #314c3e; font-weight: 600; padding: 12px; border-bottom: 1px solid #d5dfd5; }


@media (min-width: 901px) {
  .shell > aside { position: sticky; top: 0; height: 100dvh; box-sizing: border-box; align-self: start; overflow-y: auto; }
}

/* Only the page heading sticks; card headings remain in normal flow. */
main > .top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f3f5f1;
  padding: 18px 0;
  margin-top: -18px;
  box-shadow: 0 1px 0 #e0e6dc;
}

.scenario-list-heading, .scenario-list-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.scenario-list-heading { padding: 0 14px 8px; font-size: 13px; font-weight: 600; color: #68796c; }
.scenario-list-heading > span:first-child { text-align: center; }
.scenario-list-row .default-scenario { justify-content: center; margin: 0; }
.scenario-list-row .default-scenario input { width: 18px; height: 18px; cursor: pointer; }
@media (max-width: 500px) { .scenario-list-heading, .scenario-list-row { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 4px; } }

#spending-target { margin: 20px 0; }
#spending-target label { max-width: 420px; margin-bottom: 12px; }

.rate-group-heading { margin: 16px 0 0; font-size: 14px; }

button[form="spending-target"] { margin-top: 20px; }

/* Account identity and holding controls share a compact, consistent layout. */
.account-modal-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.account-modal-title input[type="color"] { width: 44px; min-width: 44px; height: 44px; margin: 0; padding: 3px; flex: 0 0 44px; }
.account-holding-controls { grid-column: 1 / -1; }
.account-holding-controls .formgrid { margin-bottom: 0; }
.account-holding-controls small { grid-column: 1 / -1; }
.account-modal select, .account-modal input:not([type="color"]):not([type="checkbox"]):not([type="radio"]) { box-sizing: border-box; height: 44px; min-height: 44px; font: inherit; padding: 10px 12px; }
#account label { display: flex; flex-direction: column; gap: 8px; }
#account label > input, #account label > select { margin: 0; }
#account .formgrid { align-items: start; }
#account div:not(.formgrid) > small + label, #account div:not(.formgrid) > label + label { margin-top: 12px; }

/* Hidden account labels must override the form label flex layout. */
#account [hidden] { display: none; }

.account-settings-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; flex-wrap: wrap; margin-bottom: 20px; }
.account-settings-header h2 { margin: 0; }
.account-settings-header label { margin: 0 0 0 auto; min-width: 180px; }
.account-override-row { grid-column: 1 / -1; }
.account-opening-balances label, .account-settings-header label { display: flex; flex-direction: column; gap: 8px; }
.account-opening-balances input, .account-settings-header select { margin: 0; }
.account-opening-balances .formgrid { align-items: start; }

/* Reserve enough width to keep account actions together. */
.account-row-actions { white-space: nowrap; width: 1%; }
.account-row-actions button { display: inline-block; margin: 0; }
.account-row-actions button + button { margin-left: 6px; }

.source-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.source-actions button { margin: 0; }

.selectable-source-row { cursor: pointer; }
.selectable-source-row > td:first-child { white-space: nowrap; }
.account-order-handle { touch-action: none; cursor: grab; min-width: 44px; min-height: 44px; margin-right: 8px; padding: 4px 10px; font-size: 1.35rem; vertical-align: middle; }
.account-order-handle:disabled { cursor: default; opacity: .4; }
.account-dragging { opacity: .25; }
.account-dragging .account-order-handle { cursor: grabbing; }
.account-drag-preview { position: fixed; z-index: 10000; pointer-events: none; table-layout: fixed; border-collapse: separate; border-spacing: 0; margin: 0; background: #fff; border: 0; outline: 1px solid #28654e; outline-offset: -1px; box-shadow: 0 12px 28px #173b3433; opacity: .95; }
.account-drag-preview tr { background: #e8eee9; }
.account-drag-preview td { border: 0; }
.account-drop-gap > td { box-sizing: border-box; padding: 0; text-align: center; color: #28654e; background: #e8eee980; border: 0; outline: 2px dashed #7b9c8b; outline-offset: -2px; font-size: .85rem; }
.selectable-source-row:hover, .selectable-source-row.is-selected { background: #e8eee9; }
.selectable-source-row:focus-visible { outline: 2px solid #28654e; outline-offset: -2px; }
.rate-table-choice { display: block; width: 100%; text-align: left; color: #253e34; background: transparent; border: 1px solid transparent; border-bottom-color: #dce5da; border-radius: 6px; padding: 18px 12px; margin: 0; }
.rate-table-choice:hover, .rate-table-choice.is-selected { background: #e8eee9; border-color: #28654e; }
.rate-table-choice:focus-visible { outline: 2px solid #28654e; }
.rate-table-selection {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.rate-table-selection .rate-table-choice {
  width: auto;
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}
.rate-table-checkbox { display: flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; min-height: 44px; cursor: pointer; }
.rate-table-checkbox input { width: 18px; height: 18px; margin: 0; accent-color: #28654e; }
.rate-comparison-actions { margin-top: 16px; align-items: center; }
.rate-comparison-chart svg { display: block; width: 100%; min-width: 640px; }
.rate-comparison-legend { display: grid; gap: 10px; margin: 16px 0; }
.rate-comparison-key { display: flex; align-items: center; gap: 10px; overflow-wrap: anywhere; }
.rate-comparison-key svg { flex: 0 0 32px; }
[data-editor] .source-actions { margin-top: 16px; }

/* Keep the funding plot aligned with the assets plot; the key overlays it. */
.income-key-dropdown { position: relative; flex-shrink: 0; }
.income-key-dropdown summary { cursor: pointer; color: #245d49; padding: 8px 12px; border: 1px solid #ccd9cf; border-radius: 6px; }
.income-key-dropdown .income-chart-legend { position: absolute; right: 0; top: 100%; z-index: 10; width: min(320px, 75vw); max-height: 420px; overflow-y: auto; background: #fff; border: 1px solid #ccd9cf; border-radius: 8px; box-shadow: 0 6px 20px #0002; padding: 16px; }
#income-bars { width: 100%; }
#income-bars .chart { display: block; width: 100%; }

#balance-chart, #income-bars .chart { height: auto; }

.analysis-progress { background: #edf4ef; border: 1px solid #c8dace; border-radius: 8px; padding: 18px; margin: 20px 0; display: grid; gap: 10px; }
.analysis-progress progress { display: block; width: 100%; height: 22px; accent-color: #28644e; border: 0; border-radius: 6px; overflow: hidden; background: #dce6df; }
.analysis-progress progress::-webkit-progress-bar { background: #dce6df; border-radius: 6px; }
.analysis-progress progress::-webkit-progress-value { background: #28644e; border-radius: 6px; }
.analysis-progress progress::-moz-progress-bar { background: #28644e; border-radius: 6px; }
.analysis-progress small { display: block; }

.shortfall-analysis-modal { width: min(1440px, calc(100vw - 40px)); max-width: calc(100vw - 40px); }
.shortfall-analysis-modal table { min-width: 1180px; width: 100%; }
.shortfall-analysis-modal th, .shortfall-analysis-modal td { padding: 16px 14px; vertical-align: top; }
.shortfall-analysis-modal th:first-child, .shortfall-analysis-modal td:first-child { width: 32%; min-width: 280px; }
.shortfall-analysis-modal td:not(:first-child) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.shortfall-analysis-modal .scroll { margin-top: 16px; }

.shortfall-analysis-modal td:last-child { white-space: normal; min-width: 200px; }
.shortfall-analysis-modal .analysis-comparison { display: inline; }

.examine-forecast-modal { width: min(1500px, calc(100vw - 40px)); max-width: calc(100vw - 40px); }
.examine-forecast-modal > .account-modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.examine-forecast-modal table { min-width: 1100px; }

.shortfall-analysis-modal table { min-width: 1550px; }

.shortfall-analysis-modal { width: min(1600px, calc(100vw - 40px)); }
.shortfall-analysis-modal table { min-width: 1000px; table-layout: fixed; }
.shortfall-analysis-modal th:first-child, .shortfall-analysis-modal td:first-child { width: 28%; min-width: 0; }
.shortfall-analysis-modal th:last-child, .shortfall-analysis-modal td:last-child { width: 23%; min-width: 0; }
.shortfall-analysis-modal th, .shortfall-analysis-modal td { padding: 14px 10px; }
.shortfall-analysis-modal td:not(:first-child) { white-space: normal; }
.analysis-row-details { margin-top: 8px; font-size: .9em; }
.analysis-options { display: grid; grid-template-columns: repeat(auto-fit,minmax(280px,1fr)); gap: 12px; margin: 16px 0; }
.analysis-options label { display: flex; align-items: baseline; gap: 10px; }
.analysis-options input { width: auto; flex-shrink: 0; }
[data-run-analysis] { margin: 16px 0; }

.account-modal .account-modal-header { display: flex; flex-wrap: nowrap; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.account-modal .account-modal-header > :first-child { min-width: 0; }
.account-modal .modal-close { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 40px; width: 40px; height: 40px; min-width: 40px; padding: 0; margin-left: auto; border: 1px solid #617a6d; border-radius: 50%; color: #254f3f; background: transparent; font-size: 28px; line-height: 1; }
.account-modal .modal-close:hover { background: #dfeae3; }
.account-modal .modal-close:focus-visible { outline: 3px solid #2873b5; outline-offset: 3px; }

.rate-table-modal { width: min(1250px, calc(100vw - 40px)); max-width: calc(100vw - 40px); }

.spending-stage-choice { display: flex; flex-direction: column; gap: 8px; text-align: left; width: 100%; padding: 16px; margin: 4px 0; background: transparent; color: #253e34; border: 1px solid transparent; border-bottom-color: #dce5da; border-radius: 6px; }
.spending-stage-choice:hover { background: #e8f0eb; border-color: #bdcfc3; }
.spending-stage-choice:focus-visible { outline: 2px solid #28644e; outline-offset: 2px; }
.spending-stage-choice span { font-weight: normal; }

#add-stage > small { display: block; }
#add-stage > button { display: block; margin-top: 16px; margin-bottom: 16px; }

.overview-charts #income-bars .chart { margin-bottom: 0; }
.overview-charts #balance-chart { display: block; width: 100%; height: auto; margin: 0 0 8px; }
.overview-charts .income-chart-main > .top { margin-bottom: 16px; }
.overview-funding-detail #income-breakdown { margin-top: 16px; }

.overview-chart-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.overview-chart-actions button { margin: 0; }

.heading-with-help { display: flex; align-items: center; gap: 10px; position: relative; min-width: 0; }
.context-help { flex: 0 0 auto; }
.context-help > summary { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border: 1px solid #617a6d; border-radius: 50%; color: #254f3f; background: transparent; font-weight: 700; cursor: pointer; list-style: none; }
.context-help > summary::-webkit-details-marker { display: none; }
.context-help > summary:hover { background: #e8f0eb; }
.context-help > summary:focus-visible { outline: 3px solid #2873b5; outline-offset: 3px; }
.context-help-panel { position: absolute; top: calc(100% + 8px); left: 0; z-index: 20; width: min(460px, calc(100vw - 80px)); max-height: 60vh; overflow: auto; padding: 16px; border: 1px solid #bdcfc3; border-radius: 8px; background: #fff; color: #253e34; box-shadow: 0 6px 20px #153e3126; font-size: 14px; font-weight: normal; line-height: 1.6; }
.context-help-panel p { margin: 0; }

.heading-with-help > h2 { margin: 0; }
.heading-with-help .context-help { margin: 0; }
.heading-with-help .context-help > summary { box-sizing: border-box; line-height: 1; }

/* Shared dropdowns: distinct from numeric spinner controls. */
select,
#forecast-settings select,
#scenario-form select,
.rate-editor select,
.account-modal select {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  min-height: 44px;
  padding: 10px 42px 10px 12px;
  border: 1px solid #bdcfc3;
  border-radius: 6px;
  background-color: #e8eee9;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12' viewBox='0 0 16 12'%3E%3Cpath d='M2 3l6 6 6-6' fill='none' stroke='%2328654e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  color: #253e34;
  cursor: pointer;
}
select:hover { border-color: #28654e; }
select:focus-visible { outline: 2px solid #28654e; outline-offset: 2px; }
select:disabled { opacity: .6; cursor: default; }
select option { background: #f4f7f3; color: #253e34; }
/* Browsers with customisable native pickers also style the open menu. */
@supports (appearance: base-select) {
  select, #forecast-settings select, #scenario-form select, .rate-editor select, .account-modal select, select::picker(select) { appearance: base-select; -webkit-appearance: base-select; }
  select::picker-icon { display: none; }
  select::picker(select) { border: 1px solid #bdcfc3; border-radius: 6px; background: #f4f7f3; padding: 4px; box-shadow: 0 6px 20px #153e3126; }
  select option { padding: 10px 12px; border-radius: 4px; }
  select option:hover, select option:focus, select option:checked { background: #e8eee9; color: #153e31; }
}
input[type="number"],
#forecast-settings input[type="number"],
#scenario-form input[type="number"],
.rate-editor input[type="number"],
.account-modal input[type="number"] {
  box-sizing: border-box;
  width: 16ch;
  max-width: 100%;
  min-width: 0;
  justify-self: start;
}

.select-menu { z-index: 10000; overflow-y: auto; overscroll-behavior: contain; padding: 4px; border: 1px solid #bdcfc3; border-radius: 6px; background: #f4f7f3; color: #253e34; box-shadow: 0 6px 20px #153e3126; font-size: 14px; }
.select-menu:focus { outline: 2px solid #28654e; }
.select-menu-option { padding: 10px 30px 10px 12px; position: relative; cursor: pointer; border-bottom: 1px solid #dde5df; }
.select-menu-option.is-active { background: #e8eee9; color: #153e31; }
.select-menu-option[aria-selected="true"] { font-weight: 600; }
.select-menu-option[aria-selected="true"]::after { content: "✓"; position: absolute; right: 10px; }

.account-modal .modal-close svg { display: block; flex: 0 0 16px; }

.overview-charts #chart-month {
  display: block;
  width: 78.1609%;
  margin: 0 0 8px 10.3448%;
  padding: 0;
  border: 0;
  height: 24px;
  background: transparent;
  accent-color: #28654e;
  cursor: pointer;
}
.overview-charts #chart-month:focus-visible { outline: 2px solid #28654e; outline-offset: 3px; }
.overview-charts #forecast-period-controls > span,
.overview-charts #forecast-period-controls > label {
  display: block;
  margin: 0 11.4943% 8px 10.3448%;
}
.overview-charts #forecast-period-controls > label[hidden] { display: none; }

.scenario-return-row { margin-top: 16px; }
.scenario-return-row > label, .scenario-return-row select { width: 100%; min-width: 0; }
.scenario-investment-rate-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); gap: 10px 20px; align-items: end; }
.scenario-investment-rate-row > small { grid-column: 2; color: #64736a; }
.fee-input-action { display: flex; gap: 8px; align-items: center; }
.fee-input-action input { min-width: 0; }
.fee-input-action button { flex: 0 0 auto; margin: 0; }
@media (max-width: 700px) { .scenario-investment-rate-row { grid-template-columns: 1fr; } .scenario-investment-rate-row > small { grid-column: 1; } }

.scenario-common-rates { display: grid; gap: 16px; margin-top: 16px; }

#scenario-form > fieldset { margin-top: 24px; }

[data-common-table] { margin-top: 12px; }
[data-common-table][hidden] { display: none; }

/* Form columns respond to their card, including narrow desktop side panels. */
main, .card, fieldset, label, .formgrid > *, .funding-preference-grid > * {
  min-width: 0;
}
.shell { grid-template-columns: 235px minmax(0, 1fr); }
.two { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.card { container-type: inline-size; }
.formgrid,
.funding-general .funding-preference-grid,
.funding-pension .funding-preference-grid,
.funding-cash .funding-preference-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  align-items: start;
  gap: 16px 20px;
}
.formgrid > label,
#account .formgrid > label,
#scenario-form .formgrid > label,
#forecast-settings .formgrid > label,
#forecast-settings .funding-preference-grid > label {
  display: grid;
  grid-template-rows: auto 44px;
  align-content: start;
  gap: 8px;
  margin: 0;
}
select,
#forecast-settings select,
#scenario-form select,
.rate-editor select,
.account-modal select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}
select[multiple], select[size]:not([size="1"]):not([size="0"]) {
  height: auto;
  background-image: none;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]) {
  min-height: 44px;
}
.top { flex-wrap: wrap; }
.top > select.scenario { flex: 1 1 280px; max-width: 440px; }
.template-import-controls label { flex: 1 1 280px; min-width: 0; }
.account-settings-header label { flex: 1 1 280px; min-width: 0; max-width: 440px; }
.select-menu { font-size: 16px; }
.select-menu-option { min-height: 44px; overflow-wrap: anywhere; white-space: normal; }

.rate-editor .formgrid > label:has(textarea[name="feeNotes"]) {
  grid-template-rows: auto auto;
}
.rate-editor textarea[name="feeNotes"] {
  width: 100%;
  min-width: 0;
  min-height: 130px;
  padding: 10px 12px;
  border: 1px solid #cbd6cc;
  border-radius: 6px;
  background: #fff;
  color: #20352f;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
}
.field-caption { display: flex; align-items: center; gap: 6px; }
.help-anchor { display: inline-flex; vertical-align: middle; flex: 0 0 auto; }
.help-heading > .help-anchor { margin-left: 6px; }
.help-popover > p, .help-popover > small {
  display: block;
  margin: 0;
  color: inherit;
  font: inherit;
}
.help-popover > :is(p, small) + :is(p, small) { margin-top: 12px; }
button.help-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: #254f3f;
  flex: 0 0 32px;
}
.help-trigger > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font: 700 14px/1 Georgia, serif;
}
.help-trigger:focus-visible { outline: 3px solid #2873b5; outline-offset: 2px; }
.help-popover {
  position: fixed;
  z-index: 10001;
  display: block;
  width: min(420px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  overflow: auto;
  overflow-wrap: anywhere;
  padding: 16px;
  margin: 0;
  border: 1px solid #bdcfc3;
  border-radius: 8px;
  background: #fff;
  color: #253e34;
  box-shadow: 0 6px 20px #153e3126;
  font-size: 14px;
  font-weight: normal;
  line-height: 1.6;
}
.help-popover[hidden] { display: none; }
#account .formgrid > label[hidden],
#scenario-form .formgrid > label[hidden],
#forecast-settings .formgrid > label[hidden],
#forecast-settings .funding-preference-grid > label[hidden] { display: none; }
@container (max-width: 580px) {
  .formgrid,
  .funding-general .funding-preference-grid,
  .funding-pension .funding-preference-grid,
  .funding-cash .funding-preference-grid,
  .scenario-investment-rate-row { grid-template-columns: minmax(0, 1fr); }
  .scenario-investment-rate-row > small { grid-column: 1; }
}
@media (max-width: 1100px) {
  .two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .overview-header .overview-scenario,
  .overview-scenario select,
  .top > select.scenario,
  .account-settings-header label { width: 100%; max-width: none; }
  .top > select.scenario { flex-basis: 100%; }
  .account-modal { width: calc(100vw - 24px); padding: 16px; }
  button.help-trigger { width: 44px; height: 44px; flex-basis: 44px; }
  .analysis-options { grid-template-columns: minmax(0, 1fr); }
}

#scenario-form .scenario-return-row[hidden] { display: none; }

#scenario-form .scenario-common-rates { display: block; }
#scenario-form .scenario-rate-group { margin: 28px 0; padding: 24px 20px 28px; border: 1px solid #bdcec5; border-radius: 10px; background: #f7faf8; min-width: 0; }
#scenario-form .scenario-rate-group > legend { padding: 0 8px; font-weight: 700; }
#scenario-form .scenario-rate-group > div > label { display: block; margin-bottom: 0; line-height: 1.5; }

#scenario-form .scenario-rate-group [hidden] { display: none; }

#scenario-form .scenario-rate-group select { margin-top: 10px; }
#scenario-form .scenario-rate-group .scenario-return-row { margin-top: 28px; }
#scenario-form .scenario-rate-group [data-common-table] { margin-top: 24px; }

#scenario-form .scenario-parameters {
  grid-template-columns: minmax(100px, 140px) minmax(0, 1fr);
  gap: 20px 24px;
  align-items: end;
}
#scenario-form .scenario-parameters > .scenario-name,
#scenario-form .scenario-parameters > [data-cycle-error] { grid-column: 1 / -1; }
#scenario-form .scenario-parameters > label {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  line-height: 1.5;
}
#scenario-form .scenario-parameters > label > input,
#scenario-form .scenario-parameters > label > select { margin: 0; width: 100%; }
#scenario-form .scenario-parameters > [data-cycle-error]:empty { display: none; }
@media (max-width: 480px) {
  #scenario-form .scenario-parameters { grid-template-columns: minmax(0, 1fr); }
}

/* The static dialog title receives initial focus; interactive controls retain their focus rings. */
.account-modal .modal-initial-focus:focus { outline: none; }

details[open] > #forecast-settings { margin-top: 20px; }
.account-modal form > [data-holdings] fieldset { margin: 18px 0; padding: 16px; }

/* Keep the explanation readable while making unavailable pension inputs visibly inactive. */
.account-modal [data-holdings] fieldset:disabled {
  background: #f2f4f2;
  border-color: #c8ceca;
}
.account-modal [data-holdings] fieldset:disabled :is(input, select, textarea, button) {
  background: #e2e7e3;
  color: #647169;
  -webkit-text-fill-color: #647169;
  border-color: #c4cdc6;
  box-shadow: none;
  opacity: 1;
  cursor: not-allowed;
}
.account-modal [data-holdings] fieldset:disabled button:hover { filter: none; }

/* Shared form rhythm: content-height captions, 12px gaps and 44px controls. */
:root { --field-gap: 12px; --control-height: 44px; }
:is(body, #account, #person, #scenario-form, #forecast-settings) label.form-field.form-field {
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  align-items: start;
  gap: var(--field-gap);
  line-height: 1.4;
}
:is(body, #account, #person, #scenario-form, #forecast-settings) .form-field > :is(input, select) {
  height: var(--control-height);
  min-height: var(--control-height);
  margin: 0;
}
:is(body, #account, #person, #scenario-form, #forecast-settings) .form-field > .field-caption {
  display: flex;
  align-items: flex-start;
  align-self: start;
  min-height: 0;
  line-height: 1.4;
}
.field-caption > .help-anchor {
  position: relative;
  width: 32px;
  height: 1.4em;
  flex: 0 0 32px;
}
.field-caption > .help-anchor > .help-trigger {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}
:is(body, #account, #scenario-form, #forecast-settings) :is(.formgrid, .funding-preference-grid, .rate-value-grid) {
  align-items: start;
  row-gap: var(--field-gap);
}
/* Keep visibility/disabled groups in the DOM without creating a second layout. */
.formgrid > :is([data-account-field], [data-account-fee]):not(:has(> .formgrid)) { display: contents; }
:is(body, #account, #person, #scenario-form, #forecast-settings) label.form-field[hidden],
.formgrid > :is([data-account-field], [data-account-fee])[hidden] { display: none; }
@supports (grid-template-rows: subgrid) {
  :is(body, #account, #scenario-form, #forecast-settings) :is(
    .formgrid > label.form-field,
    .formgrid > :is([data-account-field], [data-account-fee]) > label.form-field,
    .funding-preference-grid > label.form-field,
    .rate-value-grid > label.form-field
  ) {
    grid-row: span 2;
    grid-template-rows: subgrid;
    margin: 0;
  }
  /* A field-local action uses its own third row. */
  :is(body, #account, #scenario-form, #forecast-settings) .formgrid > label.form-field:has(> button) { grid-row: span 3; }
}
form > label.form-field + label.form-field { margin-top: 20px; }
#income-rate { margin-top: 20px; }
.formgrid.form-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tfc-person { margin: 16px 0; min-width: 0; }
.tfc-person > legend { font-weight: 700; }
.tfc-person:disabled { background: #f2f4f2; color: #647169; }
@container (max-width: 580px) {
  .formgrid.form-pair { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .field-caption > .help-anchor { width: 44px; flex-basis: 44px; }
  .card > .top { gap: 12px; }
  .card > .top > h2 { margin-bottom: 0; }
}
