/* Base reset */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: payslip-style ledger. Inputs on the left (sticky on desktop), results ledger on the right; stacks on phones. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --ink: #18221f;
  --muted: #5c6a65;
  --rule: #d8dfdc;
  --accent: #1d6b52;      /* take-home / what you keep */
  --accent-soft: #dcefe7;
  --tax: #b5432b;         /* deductions */
  --tax-soft: #f6e2dc;
  --lost: #a86d0c;        /* benefits lost */
  --lost-soft: #f5ead3;
  --ni: #7d4a9e;
  --loan: #2f6aa6;
  --pension: #5f8f84;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111715; --surface: #18201e; --ink: #e6ece9; --muted: #98a6a1; --rule: #2b3532;
    --accent: #5cc49d; --accent-soft: #183229; --tax: #ef8a70; --tax-soft: #3a2420;
    --lost: #e2ad4f; --lost-soft: #352a15; --ni: #b98ddb; --loan: #7fb1e6; --pension: #8bbcb0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111715; --surface: #18201e; --ink: #e6ece9; --muted: #98a6a1; --rule: #2b3532;
  --accent: #5cc49d; --accent-soft: #183229; --tax: #ef8a70; --tax-soft: #3a2420;
  --lost: #e2ad4f; --lost-soft: #352a15; --ni: #b98ddb; --loan: #7fb1e6; --pension: #8bbcb0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
}
.wrap {
  max-width: 1180px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 56px;
}
header { display: grid; gap: 6px; margin-bottom: 24px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(28px, 4vw, 40px); line-height: 1.1; margin: 0; text-wrap: balance; }
header p { margin: 0; color: var(--muted); max-width: 64ch; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 19px; margin: 0; text-wrap: balance; }
.grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* Inputs */
form.panel { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); }
@media (max-width: 860px) { form.panel { position: static; } }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 20px; display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field label, .legend { font-weight: 700; font-size: 13px; }
.hint { font-size: 12.5px; color: var(--muted); }
.salary-box { display: flex; align-items: center; border: 2px solid var(--ink); border-radius: 8px; background: var(--bg); }
.salary-box span { font-family: var(--font-mono); font-size: 22px; padding-left: 12px; color: var(--muted); }
#salary { font-family: var(--font-mono); font-size: 24px; font-weight: 600; border: 0; background: transparent; color: var(--ink); padding: 10px 12px 10px 6px; width: 100%; min-width: 0; }
#salary:focus { outline: none; }
.salary-box:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font-family: var(--font-mono); font-size: 12px; border: 1px solid var(--rule); background: transparent; color: var(--ink); padding: 4px 9px; border-radius: 99px; cursor: pointer; }
.chips button:hover { border-color: var(--accent); color: var(--accent); }
select, input[type="number"]:not(#salary) {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 9px; width: 100%;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > * { min-width: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 4px; accent-color: var(--accent); }
fieldset { border: 0; border-top: 1px solid var(--rule); padding: 16px 0 0; margin: 0; display: grid; gap: 12px; }
fieldset legend { padding: 0 0 4px; font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.example-tag { font-size: 12px; color: var(--lost); background: var(--lost-soft); border-radius: 6px; padding: 6px 9px; }

/* Results */
.results { display: grid; gap: 20px; min-width: 0; }
.headline { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
@media (max-width: 1040px) { .headline { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); padding: 16px; display: grid; gap: 2px; align-content: start; }
.stat .k { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stat .v { font-family: var(--font-mono); font-size: clamp(22px, 2.6vw, 28px); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .s { font-size: 13px; color: var(--muted); }
.stat.keep .v { color: var(--accent); }
.stat.taxrate .v { color: var(--tax); }
.stat.loss .v { color: var(--lost); }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 20px; display: grid; gap: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-head .hint { margin: 0; }

.bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: var(--bg); }
.bar div { height: 100%; transition: width .25s ease; }
@media (prefers-reduced-motion: reduce) { .bar div { transition: none; } }
.legend-row { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.legend-row span { display: inline-flex; align-items: center; gap: 6px; }
.legend-row i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
td.n, th.n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; }
tr.muted td { color: var(--muted); }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }
.sub { display: block; font-size: 12.5px; color: var(--muted); }
.pill { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; white-space: nowrap; }
.pill.tax { background: var(--tax-soft); color: var(--tax); }
.pill.lost { background: var(--lost-soft); color: var(--lost); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.info { background: var(--bg); color: var(--muted); border: 1px solid var(--rule); }

.losses { display: grid; gap: 10px; }
.loss-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 8px; }
.loss-item.hit { border-color: var(--lost); background: var(--lost-soft); }
.loss-item .t { font-weight: 700; }
.loss-item .d { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); }
.loss-item.hit .d { color: var(--ink); }
.loss-item .n { font-family: var(--font-mono); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.tips { display: grid; gap: 10px; }
.tip { padding: 12px 14px; border-radius: 8px; background: var(--accent-soft); font-size: 14px; }
.tip strong { font-family: var(--font-mono); }
.notes { font-size: 12.5px; color: var(--muted); display: grid; gap: 6px; }
.notes p { margin: 0; max-width: 90ch; }
