/*
 * Shared by every apps/toolkit tool: form controls, the calculator layout
 * (form + results), stat tiles, notices, charts and tables. Site chrome (nav,
 * footer, buttons, hero, cards) comes from common/css/site.css, loaded before
 * this file. Only styles unique to one tool live next to that tool.
 */

/* ── Form controls ───────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  font-size: 0.8125rem; font-weight: 600; color: var(--text);
}
.field-hint { font-size: 0.75rem; color: var(--muted); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-affix {
  position: absolute; font-size: 0.9375rem; color: var(--muted);
  pointer-events: none;
}
.input-affix--pre { left: 14px; }
.input-affix--post { right: 14px; }
.input, .select {
  width: 100%;
  font: inherit; font-size: 0.9375rem; color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none; appearance: none;
}
.input--pre { padding-left: 30px; }
.input--post { padding-right: 44px; }
.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input[type=number] { -moz-appearance: textfield; }
.input:hover, .select:hover { border-color: var(--primary); }
.input:focus, .select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.input[aria-invalid="true"] { border-color: var(--warning); }
html[data-theme="dark"] .input,
html[data-theme="dark"] .select { background: var(--bg); color-scheme: dark; }
.select {
  padding-right: 36px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* Segmented control (pill radio group) */
.segmented {
  position: relative;
  display: inline-flex; padding: 4px; gap: 4px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 999px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 7px 16px; border-radius: 999px; cursor: pointer;
  font-size: 0.8125rem; font-weight: 600; color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.segmented input:checked + label {
  background: var(--primary); color: #fff;
}
.segmented input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── Disclaimer ──────────────────────────────────────────── */
.disclaimer {
  font-size: 0.8125rem; color: var(--muted); line-height: 1.6;
}

/* ══ Calculator layout ═══════════════════════════════════════
   Form on the left (sticky on desktop), results on the right. */
.calc-section { padding: 32px 0 96px; }
.calc-grid {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .calc-grid { grid-template-columns: 1fr; }
}

/* ── Form ────────────────────────────────────────────────── */
.calc-form { padding: 8px 28px 28px; min-width: 0; }
@media (max-width: 480px) { .calc-form { padding: 4px 20px 24px; } }
@media (min-width: 901px) {
  .calc-form { position: sticky; top: 88px; max-height: calc(100vh - 112px); overflow-y: auto; }
}
.form-group {
  border: none;
  padding: 20px 0 24px;
  display: flex; flex-direction: column; gap: 16px;
  border-bottom: 1px solid var(--border);
  min-width: 0; /* fieldsets default to min-content, which overflows on mobile */
}
.form-group:last-of-type { border-bottom: none; padding-bottom: 0; }
.form-group-title {
  float: left; width: 100%;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--primary);
  padding-top: 4px;
}
.form-group-title + * { clear: both; }
.form-group-hint { margin-top: -8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-row--amount { grid-template-columns: 1fr auto; align-items: center; }
.input--post-wide { padding-right: 68px; }
.segmented--full { display: flex; }
.segmented--full label { flex: 1; text-align: center; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--border); background: transparent;
  color: var(--muted); font-size: 1.125rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); transform: scale(1.05); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
#addOneOff { align-self: flex-start; }

.form-error {
  margin-top: 16px;
  font-size: 0.8125rem; font-weight: 600; color: var(--warning);
}

/* ── Results ─────────────────────────────────────────────── */
.calc-results { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

/* ── Share row ───────────────────────────────────────────── */
.share-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px 16px; flex-wrap: wrap;
}
.share-hint { font-size: 0.8125rem; color: var(--muted); flex: 1 1 260px; }
.share-row .btn { flex-shrink: 0; }

.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px;
}
@media (max-width: 760px) { .stat-grid { gap: 12px; } }
@media (max-width: 380px) { .stat-grid { grid-template-columns: 1fr; } }
.stat {
  padding: 20px 22px;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.stat-label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.stat-value {
  font-size: clamp(1.375rem, 2.2vw, 1.75rem); font-weight: 900;
  letter-spacing: -0.03em; line-height: 1.15;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-value--good { color: var(--success); }
.stat-note { font-size: 0.8125rem; color: var(--muted); line-height: 1.45; }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface);
  border-left: 4px solid var(--warning);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  font-size: 0.875rem; line-height: 1.6;
}
.notice-icon {
  flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--warning); color: #fff;
  font-size: 0.8125rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
html[data-theme="dark"] .notice-icon { color: var(--bg); }


/* ── Chart series tones ──────────────────────────────────────
   primary: the headline series. alt: the thing it's compared with.
   muted (dashed): a baseline. Indigo + orange pass the dataviz
   colour-blindness and contrast checks in both themes. */
:root { --series-alt: #eb6834; }
/* ── Chart ───────────────────────────────────────────────── */
.chart-card, .table-card { padding: 24px 24px 20px; }
.chart-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.chart-title { font-size: 1.0625rem; font-weight: 700; color: var(--text); }
.chart-sub { font-size: 0.8125rem; color: var(--muted); }
.legend {
  list-style: none; display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 0.8125rem; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 18px; height: 0; border-top: 2px solid; }
.legend-swatch--primary { border-color: var(--primary); }
.legend-swatch--alt { border-color: var(--series-alt); }
.legend-swatch--muted { border-color: var(--muted); border-top-style: dashed; }

.chart { position: relative; width: 100%; height: 300px; }
@media (max-width: 600px) { .chart { height: 240px; } }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line--primary { stroke: var(--primary); }
.chart .line--alt { stroke: var(--series-alt); }
.chart .line--muted { stroke: var(--muted); stroke-dasharray: 5 4; }
.chart .area { opacity: 0.08; }
.chart .area--primary { fill: var(--primary); }
.chart .area--alt { fill: var(--series-alt); }
.chart .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot--primary { fill: var(--primary); }
.chart .dot--alt { fill: var(--series-alt); }
.chart .dot--muted { fill: var(--muted); }
.chart .end-label {
  fill: var(--text); font-size: 11px; font-weight: 600;
  stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; paint-order: stroke;
}
.chart .crosshair { stroke: var(--muted); stroke-width: 1; opacity: 0.6; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }

.chart-tooltip {
  position: absolute; top: 0; left: 0; z-index: 2;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 10px 12px;
  font-size: 0.8125rem; line-height: 1.5;
  min-width: 180px;
  font-variant-numeric: tabular-nums;
}
.chart-tooltip strong { display: block; color: var(--text); margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.tt-row span:last-child { margin-left: auto; color: var(--text); font-weight: 600; }
.tt-key { width: 12px; height: 0; border-top: 2px solid; }
.tt-key--primary { border-color: var(--primary); }
.tt-key--alt { border-color: var(--series-alt); }
.tt-key--muted { border-color: var(--muted); border-top-style: dashed; }

/* ── Schedule table ──────────────────────────────────────── */
.table-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.table-scroll { overflow-x: auto; max-height: 480px; overflow-y: auto; }
.table-scroll:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.schedule {
  width: 100%; border-collapse: collapse;
  font-size: 0.875rem; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.schedule th {
  position: sticky; top: 0;
  background: var(--surface);
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
  text-align: right; padding: 10px 10px;
  border-bottom: 1px solid var(--border);
}
.schedule td {
  text-align: right; padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.schedule th:first-child, .schedule td:first-child { text-align: left; padding-left: 0; }
.schedule th:last-child, .schedule td:last-child { padding-right: 0; }
.schedule td:first-child { font-weight: 600; }
.schedule tr:last-child td { border-bottom: none; }
.schedule .zero { color: var(--muted); }
.schedule tbody tr:hover td { background: var(--primary-light); }

/* Year rows expand into their months. */
.year-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 600; color: var(--text);
  background: none; border: none; padding: 0; cursor: pointer;
}
.year-toggle::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 ease;
}
.year-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
.year-toggle:hover { color: var(--primary); }
.year-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.schedule tr.month-row td {
  font-size: 0.8125rem; color: var(--muted);
  padding-top: 6px; padding-bottom: 6px;
  background: var(--bg);
}
.schedule tr.month-row td:first-child { font-weight: 500; padding-left: 22px; }

@media (max-width: 480px) {
  .segmented--full label { padding: 7px 4px; }
}

/* ══ Shared result pieces ═══════════════════════════════════
   Checkboxes, tax summary, verdict, option cards, notices and the
   'worth knowing' list, used by more than one tool. */

/* ── Checkboxes and grouped inputs ─────────────────────── */
.check {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 0.875rem; color: var(--text); line-height: 1.45;
  cursor: pointer;
}
.check input {
  flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px;
  accent-color: var(--primary); cursor: pointer;
}
.field-optional { font-weight: 400; color: var(--muted); }
.tax-summary {
  font-size: 0.8125rem; line-height: 1.5; color: var(--text);
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--primary-light);
}
.tax-summary:empty { display: none; }

.option-inputs { display: flex; flex-direction: column; gap: 12px; }
.option-input {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: var(--radius-sm);
  background: var(--bg);
}
html[data-theme="dark"] .option-input .input,
html[data-theme="dark"] .option-input .select { background: var(--surface); }
.option-name { font-size: 0.875rem; font-weight: 700; color: var(--text); }

/* ── Verdict ─────────────────────────────────────────────── */
.verdict { padding: 24px; display: flex; flex-direction: column; gap: 8px; }
.verdict-text {
  font-size: clamp(1.25rem, 2vw, 1.5rem); font-weight: 800;
  letter-spacing: -0.02em; line-height: 1.3; color: var(--text);
}
.verdict-text em { font-style: normal; color: var(--primary); }
.verdict-sub { font-size: 0.9375rem; color: var(--muted); line-height: 1.6; }

/* ── Option cards ────────────────────────────────────────── */
.option-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
@media (max-width: 760px) { .option-grid { gap: 12px; } }
@media (max-width: 520px) { .option-grid { grid-template-columns: 1fr; } }
.option-card {
  padding: 20px 22px;
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
  border: 1.5px solid transparent;
}
.option-card.is-best { border-color: var(--success); }
.option-card.is-best .stat-label::after {
  content: 'Best'; margin-left: 8px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--success); color: var(--surface);
  font-size: 0.6875rem; letter-spacing: 0.05em;
}
.option-diff { font-size: 0.875rem; font-weight: 700; }
.option-diff--ahead { color: var(--success); }
.option-diff--behind { color: var(--muted); }
.option-facts {
  margin-top: 8px; padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.8125rem;
}
.option-facts div { display: flex; justify-content: space-between; gap: 12px; }
.option-facts dt { color: var(--muted); }
.option-facts dd { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

#notices { display: flex; flex-direction: column; gap: 12px; }
#notices:empty { display: none; }

/* ── Worth knowing ───────────────────────────────────────── */
.worth-knowing { padding: 24px; }
.worth-knowing ul {
  margin-top: 12px; padding-left: 18px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 0.9375rem; color: var(--muted); line-height: 1.6;
}
.worth-knowing strong { color: var(--text); font-weight: 600; }

.schedule td.best { color: var(--success); font-weight: 700; }

/* ── Stacked bars (Toolkit.stackedBars) ─────────────────────
   One tone per kind of money, the same in every tool. Take-home keeps
   --primary. Checked with the dataviz palette validator against --surface
   in both themes, in this order: every adjacent pair clears the CVD and
   normal-vision checks and every hue clears 3:1 contrast. Segments are
   split by a 2px surface gap, each bar is labelled with its total, and
   every tool shows the same figures in a table. */
:root {
  --bar-home: var(--primary);
  --bar-pension: #009490;
  --bar-tax: var(--series-alt);
  --bar-ni: #c026d3;
}
html[data-theme="dark"] { --bar-pension: #14a3a3; --bar-ni: #d946ef; }

.bars-legend { margin-bottom: 16px; }
.bar-key { width: 12px; height: 12px; border-radius: 3px; }
.bars { position: relative; display: flex; flex-direction: column; gap: 18px; }
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-label {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 0.8125rem; color: var(--muted);
}
.bar-label strong { color: var(--text); font-weight: 600; }
.bar-label span:last-child { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.bar-track { display: flex; gap: 2px; height: 24px; }
.bar-seg { height: 100%; min-width: 2px; flex: 0 1 auto; transition: opacity 0.15s ease; }
.bar-seg:first-child { border-radius: 4px 0 0 4px; }
.bar-seg:last-child { border-radius: 0 4px 4px 0; }
.bar-seg:only-child { border-radius: 4px; }
.bars:hover .bar-seg { opacity: 0.55; }
.bars .bar-seg:hover { opacity: 1; }
.tt-key--home, .tt-key--pension, .tt-key--tax, .tt-key--ni { height: 10px; width: 10px; border: 0; border-radius: 2px; }
.bar-key--home, .bar-seg--home, .tt-key--home { background: var(--bar-home); }
.bar-key--pension, .bar-seg--pension, .tt-key--pension { background: var(--bar-pension); }
.bar-key--tax, .bar-seg--tax, .tt-key--tax { background: var(--bar-tax); }
.bar-key--ni, .bar-seg--ni, .tt-key--ni { background: var(--bar-ni); }

/* ── Small shared pieces ─────────────────────────────────── */
/* Side-by-side fields whose labels may wrap: line the inputs up. */
.field-row--end { align-items: end; }
/* Table cells for money gained or lost, and totals rows. */
.schedule td.gain { color: var(--success); font-weight: 600; }
.schedule td.loss { color: var(--warning); font-weight: 600; }
.schedule tr.total td { font-weight: 800; }
/* Tables short enough to show in full, without their own scroll. */
.table-scroll--full { max-height: none; }

/* ── Where to go from here: the end-of-results links block ── */
.next-steps { padding: 24px; }
.next-steps-list {
  list-style: none; margin-top: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.next-steps-list li { display: flex; flex-direction: column; gap: 2px; font-size: 0.875rem; color: var(--muted); line-height: 1.5; }
.next-steps-list a { font-size: 0.9375rem; font-weight: 700; color: var(--primary); text-decoration: none; }
.next-steps-list a:hover { text-decoration: underline; }
.next-steps-list a::after { content: ' →'; }
