/* =========================================================================
   Personal Financial Planning Scenario Planner — styles
   Plain CSS, no frameworks. Organized top-to-bottom:
   1. Design tokens (colors, spacing)   2. Base / resets
   3. Layout    4. Components    5. Responsive    6. Print
   ========================================================================= */

/* ---------- 1. Design tokens ---------- */
:root {
  --bg:            #f4f6fb;
  --surface:       #ffffff;
  --ink:           #1c2333;   /* main text */
  --ink-soft:      #4a5568;   /* secondary text */
  --line:          #d7deea;   /* borders */
  --brand:         #1e5eff;   /* primary blue */
  --brand-dark:    #1546c0;
  --brand-tint:    #eaf0ff;
  --good:          #0f8a4d;   /* on track / surplus */
  --good-tint:     #e4f6ec;
  --warn:          #b45309;   /* borderline */
  --warn-tint:     #fdf0dc;
  --bad:           #c0322b;   /* off track / shortfall */
  --bad-tint:      #fbe9e8;
  --focus:         #ffb020;   /* high-contrast focus ring */
  --radius:        12px;
  --shadow:        0 2px 10px rgba(28, 35, 51, 0.08);
  --maxw:          1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- 2. Base / resets ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 16px;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 0.6em; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* Visible focus outline everywhere for keyboard users */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Screen-reader-only helper */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Skip link appears on keyboard focus */
.skip-link {
  position: absolute;
  left: 12px; top: -60px;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 100;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- 3. Layout ---------- */
.site-header {
  background: linear-gradient(135deg, #12306e, #1e5eff);
  color: #fff;
  padding: 34px 0 30px;
}
.site-header h1 { color: #fff; margin-bottom: 6px; }
.subtitle {
  color: #cfe0ff;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 12px;
}
.tagline { color: #dbe6ff; max-width: 60ch; margin: 0; font-size: 1.05rem; }

.disclaimer {
  background: var(--warn-tint);
  border-top: 3px solid var(--warn);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  font-size: 0.95rem;
  color: #5a3a0a;
}

main { padding: 26px 0 40px; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* Keep results visible on scroll for wide screens */
@media (min-width: 981px) {
  .results { position: sticky; top: 16px; }
}

/* ---------- 4. Components ---------- */

/* Fieldsets & fields */
fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 4px;
  margin: 0 0 18px;
}
legend {
  font-weight: 700;
  padding: 0 8px;
  font-size: 0.98rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.input-wrap:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.input-wrap input {
  flex: 1 1 auto;
  border: 0;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  min-width: 0;
  background: transparent;
  color: var(--ink);
}
.input-wrap input:focus { outline: none; }
.unit {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #f1f4fa;
  color: var(--ink-soft);
  font-size: 0.9rem;
  white-space: nowrap;
}
.unit.prefix { border-right: 1px solid var(--line); }
.unit:not(.prefix) { border-left: 1px solid var(--line); }

/* Field with an error */
.field.has-error .input-wrap { border-color: var(--bad); }
.field.has-error .input-wrap:focus-within { box-shadow: 0 0 0 3px var(--bad-tint); }
.error {
  color: var(--bad);
  font-size: 0.82rem;
  margin: 5px 0 0;
  font-weight: 600;
  min-height: 0;
}

/* Info "i" buttons + tooltip */
.info {
  border: 0;
  background: var(--brand-tint);
  color: var(--brand-dark);
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  cursor: pointer;
  line-height: 18px;
  padding: 0;
  flex: 0 0 auto;
}
.info:hover { background: #d8e2ff; }
.tooltip {
  position: absolute;
  max-width: 260px;
  background: var(--ink);
  color: #fff;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 0.83rem;
  line-height: 1.4;
  z-index: 90;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  pointer-events: none;
}

/* Scenario picker */
.scenario-picker legend { margin-bottom: 4px; }
.scenario-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.scenario-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}
.scenario-btn:hover { border-color: var(--brand); }
.scenario-btn.is-active {
  border-color: var(--brand);
  background: var(--brand-tint);
}
.scenario-name { font-weight: 700; font-size: 0.95rem; }
.scenario-sub { font-size: 0.75rem; color: var(--ink-soft); }
.scenario-hint { font-size: 0.82rem; color: var(--ink-soft); margin: 0; }

/* Buttons */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  flex: 1 1 auto;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--brand-dark); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--brand); background: var(--brand-tint); }

/* Verdict banner */
.verdict {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: #f7f9fd;
}
.verdict-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff;
  flex: 0 0 auto;
}
.verdict-title { font-weight: 700; font-size: 1.1rem; margin: 0; }
.verdict-detail { margin: 2px 0 0; color: var(--ink-soft); font-size: 0.9rem; }
.verdict.good  { background: var(--good-tint); border-color: var(--good); }
.verdict.good  .verdict-icon { background: var(--good); }
.verdict.warn  { background: var(--warn-tint); border-color: var(--warn); }
.verdict.warn  .verdict-icon { background: var(--warn); }
.verdict.bad   { background: var(--bad-tint);  border-color: var(--bad); }
.verdict.bad   .verdict-icon { background: var(--bad); }

/* Result cards */
.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fbfcfe;
}
.card-label {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin: 0 0 6px;
  font-weight: 600;
  display: flex; align-items: center; gap: 5px;
}
.card-value { font-size: 1.5rem; font-weight: 700; margin: 0; }
.card-value.pos { color: var(--good); }
.card-value.neg { color: var(--bad); }

/* Chart */
.chart-block, .compare-block { margin-bottom: 24px; }
.chart-sub { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 10px; }
.chart-wrap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}
#projectionChart { width: 100%; height: auto; display: block; }
.chart-note { font-size: 0.82rem; color: var(--ink-soft); margin-top: 8px; }

/* Comparison table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
caption { text-align: left; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { background: #f1f4fa; font-size: 0.82rem; }
tbody tr.active-row { background: var(--brand-tint); font-weight: 600; }
td .pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.pill.yes { background: var(--good-tint); color: var(--good); }
.pill.no  { background: var(--bad-tint);  color: var(--bad); }

/* Assumptions disclosure */
.assumptions {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 16px;
  background: #fbfcfe;
}
.assumptions summary {
  cursor: pointer;
  font-weight: 700;
  padding: 10px 0;
}
.assumptions ul { margin: 0 0 12px; padding-left: 20px; }
.assumptions li { margin-bottom: 8px; font-size: 0.9rem; }

/* Footer */
.site-footer {
  background: #12203f;
  color: #cdd7ec;
  padding: 24px 0;
  margin-top: 20px;
  font-size: 0.88rem;
}
.footer-disclaimer { color: #9fb0d0; margin: 6px 0 0; }

/* ---------- 5. Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.4rem; }
  .cards { grid-template-columns: 1fr; }
  .scenario-buttons { grid-template-columns: 1fr; }
  .btn { flex-basis: 100%; }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ---------- 6. Print (used by "Save as PDF") ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .site-header { background: none; color: #000; border-bottom: 2px solid #000; }
  .site-header h1 { color: #000; }
  .tagline, .skip-link, .button-row, .info, .scenario-hint,
  .site-footer, .tooltip { display: none !important; }
  .disclaimer { background: #fff; color: #000; border-color: #000; }
  .layout { display: block; }
  .panel { box-shadow: none; border: 1px solid #999; page-break-inside: avoid; margin-bottom: 12px; }
  .results { position: static !important; }
  .card, .verdict, table { page-break-inside: avoid; }
  .assumptions[open] summary ~ * { display: block; }
  .inputs fieldset { page-break-inside: avoid; }
}
