/* CPF LIFE calculator: light, off-white, deep navy text, lots of white space.
   System font stack only. No external fonts, no CDNs, no trackers. */

:root {
  --bg: #FAFAF7;
  --panel-bg: #FFFFFF;
  --text: #16232E;
  --text-quiet: #64707B;
  --border: #E6E2D8;
  --badge-bg: #EFEDE5;
  --badge-text: #6B6558;
  --hint: #9A6B00;
  --error: #B3261E;
  --std: #1F4E79;
  --bas: #2E8B57;
  --esc: #C9852A;
  --footnote: #7A8590;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- Header ---------- */

.hero {
  text-align: center;
  margin-bottom: 32px;
}

.hero h1 {
  font-size: 32px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

.hero .subline {
  font-size: 16px;
  color: var(--text-quiet);
  margin: 0;
}

/* ---------- Print summary (hidden on screen) ---------- */

.print-summary {
  display: none;
}

/* ---------- Inputs panel ---------- */

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 40px;
}

.inputs-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.inputs-row.inputs-estimator,
.inputs-row.inputs-prepared {
  grid-template-columns: repeat(3, 1fr);
}

.inputs-row.inputs-oa {
  grid-template-columns: repeat(2, 1fr);
}

.field {
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* inputs line up even when one label wraps to two lines */
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-quiet);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input,
.field select {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--std);
  outline-offset: 1px;
}

.hint {
  color: var(--hint);
  font-size: 13px;
  margin: 12px 0 0;
}

.error {
  color: var(--error);
  font-size: 13px;
  margin: 12px 0 0;
  font-weight: 600;
}

.error-box {
  background: #FFF8E8;
  border: 1px solid #E8D6A8;
  color: #5C4700;
  border-radius: 12px;
  padding: 18px 20px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 40px;
}

.prepared-by-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-quiet);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 12px;
}

.toggle-block {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.toggle-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-quiet);
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}

.toggle-mark::before {
  content: "+"; /* plus sign, closed state */
}

.toggle-btn[aria-expanded="true"] .toggle-mark {
  background: var(--std);
  border-color: var(--std);
  color: #fff;
}

.toggle-btn[aria-expanded="true"] .toggle-mark::before {
  content: "\2212"; /* minus sign, open state */
}

.toggle-body {
  margin-top: 16px;
}

.helper-line {
  font-size: 12px;
  color: var(--text-quiet);
  margin: 0 0 12px;
}

.actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.btn-print {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
}

.btn-print:hover {
  border-color: var(--std);
}

/* ---------- Prepared by / basis lines ---------- */

.prepared-by-line {
  font-size: 13px;
  color: var(--text-quiet);
  margin: 0 0 4px;
}

.basis-line {
  font-size: 13px;
  color: var(--text-quiet);
  margin: 0 0 16px;
  line-height: 1.5;
}

.basis-line:empty {
  display: none;
}

/* ---------- Sections ---------- */

.section {
  margin-bottom: 44px;
}

.section h2 {
  font-size: 20px;
  font-weight: 650;
  margin: 0 0 16px;
}

/* ---------- Cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  position: relative;
  overflow: hidden;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 23px 20px 20px;
}

/* plan colour as a straight bar clipped by the rounded corners (a thick border-top curved into the radius) */
.card::before,
.oa-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--card-accent, var(--std));
}

.card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--card-accent, var(--std));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
}

.card-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.card-value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-unit {
  font-size: 14px;
  color: var(--text-quiet);
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--badge-text);
  background: var(--badge-bg);
  border-radius: 999px;
  padding: 3px 9px;
  margin-left: 4px;
}

.card-note {
  font-size: 13.5px;
  color: var(--text-quiet);
  margin: 10px 0 0;
  line-height: 1.5;
}

/* ---------- Chart ---------- */

.chart-wrap {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-quiet);
  margin: 0 0 8px;
}

#chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-gridline {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--text-quiet);
  font-size: 11px;
  font-family: inherit;
}

.chart-end-label {
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
}

.chart-end-label--narrow {
  font-size: 11px;
}

.chart-may-fall-label {
  font-size: 10.5px;
  font-weight: 600;
  font-family: inherit;
  fill: var(--bas);
}

table td.total-star {
  font-weight: 700;
}

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-bg);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
  font-size: 14px;
}

table th,
table td {
  padding: 12px 16px;
  text-align: right;
  white-space: nowrap;
}

table th:first-child,
table td:first-child {
  text-align: left;
}

table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-quiet);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

table tbody tr + tr td {
  border-top: 1px solid var(--border);
}

table td.col-std { color: var(--std); font-weight: 600; }
table td.col-bas { color: var(--bas); font-weight: 600; }
table td.col-esc { color: var(--esc); font-weight: 600; }

#family-lines p,
.footnote {
  font-size: 13px;
  color: var(--footnote);
  margin: 12px 0 0;
  line-height: 1.5;
}

/* ---------- OA section (kept visually separate: neutral grey, no plan colours) ---------- */

.oa-panel {
  --card-accent: #8A94A0;
  position: relative;
  overflow: hidden;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 27px 24px 24px;
}

.oa-panel .table-scroll {
  border-color: var(--border);
}

.oa-box {
  margin-top: 16px;
  background: var(--badge-bg);
  border-radius: 12px;
  padding: 16px 18px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.55;
}

.oa-box p {
  margin: 0 0 10px;
}

.oa-box p:last-child {
  margin-bottom: 0;
}

/* ---------- Footer ---------- */

.footer {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 8px;
}

.footer p {
  font-size: 13px;
  color: var(--text-quiet);
  line-height: 1.6;
  margin: 0 0 10px;
}

.footer p:last-child {
  margin-bottom: 0;
}

.footer p.footer-bold {
  color: var(--text);
  font-size: 13px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .inputs-row.inputs-main {
    grid-template-columns: repeat(2, 1fr);
  }
  .inputs-row.inputs-estimator,
  .inputs-row.inputs-oa,
  .inputs-row.inputs-prepared {
    grid-template-columns: repeat(2, 1fr);
  }
  .cards {
    grid-template-columns: 1fr;
  }
  .hero h1 {
    font-size: 26px;
  }
  .card-value {
    font-size: 30px;
  }
  .page {
    padding: 24px 16px 48px;
  }
  /* all three plan columns stay on screen on a phone: no sideways scroll to find Escalating */
  table {
    min-width: 0;
    font-size: 13px;
  }
  table th,
  table td {
    padding: 10px 8px;
  }
  table thead th {
    font-size: 10px;
    letter-spacing: 0.01em;
  }
  .chart-wrap {
    padding: 14px 10px;
  }
}

/* ---------- Print ---------- */

@media print {
  .no-print,
  .panel .actions,
  .toggle-block,
  .hint,
  .error,
  #chart-wrap {
    display: none !important;
  }

  #inputs-panel .inputs-main {
    display: none !important;
  }

  #inputs-panel {
    border: none;
    padding: 0;
    margin-bottom: 12px;
  }

  .print-summary {
    display: block !important;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }

  html, body, .page {
    background: #fff !important; /* off-white ground printed as a grey block on the last page */
  }

  /* A4 width sits under the 720px phone breakpoint: force the desktop layout back so it fits 2 pages */
  .cards {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px;
    margin-bottom: 16px;
  }

  .card {
    padding: 12px;
  }

  .card-value {
    font-size: 24px !important;
  }

  table {
    min-width: 0;
    font-size: 12px;
  }

  table th,
  table td {
    padding: 7px 10px;
  }

  .page {
    max-width: 100%;
    padding: 12px 18px;
  }

  .hero {
    margin-bottom: 12px;
  }

  .section {
    margin-bottom: 20px;
  }

  .card,
  .oa-panel,
  .oa-box,
  .footer p {
    break-inside: avoid; /* the OA risk text must never land on a different page from the OA figures */
  }

  .table-scroll {
    overflow-x: visible;
  }

  a[href]::after {
    content: "";
  }
}
