:root {
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Layout: a tax form on the left, the settlement it produces on the right, workings below. */
:root {
  --paper: #eef4f1; --sheet: #fbfdfc; --ink: #12302b; --muted: #557069; --rule: #cbdad4;
  --accent: #0b6e5b; --on-accent: #ffffff;
  --seg-net: #0b6e5b; --seg-cuota: #c58a12; --seg-state: #3a6db0; --seg-cat: #b5433c;
  --warn-bg: #fbf0d9; --warn-ink: #6d4b05;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1a18; --sheet: #142421; --ink: #e3efeb; --muted: #94aea7; --rule: #2a403b;
    --accent: #52d3b2; --on-accent: #06211b;
    --seg-net: #52d3b2; --seg-cuota: #e2ad45; --seg-state: #7ba8e6; --seg-cat: #e8817a;
    --warn-bg: #33280f; --warn-ink: #f0d08e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1a18; --sheet: #142421; --ink: #e3efeb; --muted: #94aea7; --rule: #2a403b;
  --accent: #52d3b2; --on-accent: #06211b;
  --seg-net: #52d3b2; --seg-cuota: #e2ad45; --seg-state: #7ba8e6; --seg-cat: #e8817a;
  --warn-bg: #33280f; --warn-ink: #f0d08e; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.5; }
.page {
  max-width: 1120px; margin-inline: auto;
  padding-block: 32px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 28px;
}
header { display: grid; gap: 4px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.title-row h1 { min-width: 0; }
#lang { flex: none; font-family: var(--font-data); font-size: 0.85rem; padding: 6px 8px; background: var(--sheet); color: var(--ink); border: 1px solid var(--rule); border-radius: 4px; cursor: pointer; }
#lang:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.75rem, 4vw, 2.5rem); line-height: 1.1; margin: 0; text-wrap: balance; }
.lede { margin: 0; color: var(--muted); max-width: 65ch; }
h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; margin: 0; text-wrap: balance; }
h3 { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0; }
.tool { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 24px; align-items: start; }
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 20px; min-width: 0; }

form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
label, .label { font-weight: 600; font-size: 0.92rem; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 0; }
input[type="number"] {
  width: 100%; font-family: var(--font-data); font-size: 1.1rem; padding: 10px 12px;
  background: var(--paper); color: var(--ink); border: 1px solid var(--rule); border-radius: 4px;
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.switch { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch label { text-align: center; padding: 8px; cursor: pointer; font-family: var(--font-data); font-weight: 500; }
.switch input:checked + label { background: var(--accent); color: var(--on-accent); }
.switch input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -4px; }
.profile { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chip { font: inherit; font-size: 0.8rem; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 3px; color: var(--ink); background: transparent; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip:focus-visible, .pop-done:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.profile-wrap { position: relative; }
.pop { position: absolute; left: 0; right: 0; z-index: 5; display: grid; gap: 12px; padding: 14px; background: var(--sheet); border: 1px solid var(--accent); border-radius: 6px; box-shadow: 0 8px 24px rgba(10, 40, 34, 0.18); }
.pop select { width: 100%; font-family: var(--font-body); font-size: 0.95rem; padding: 9px 10px; background: var(--paper); color: var(--ink); border: 1px solid var(--rule); border-radius: 4px; }
.pop select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pop-done { justify-self: end; font: inherit; font-size: 0.85rem; font-weight: 600; padding: 4px 12px; border: 1px solid var(--accent); border-radius: 3px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.edited { font-size: 0.72rem; font-weight: 600; color: var(--accent); margin-left: 6px; }

.results { display: grid; gap: 20px; }
.headline { display: grid; gap: 2px; }
.net { font-family: var(--font-display); font-weight: 700; font-size: clamp(2.6rem, 8vw, 4.25rem); line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.net-sub { color: var(--muted); }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 12px; border-radius: 4px; font-size: 0.9rem; margin: 0; }
.bar { display: flex; height: 26px; border-radius: 3px; overflow: hidden; gap: 2px; background: var(--rule); }
.bar span { display: block; min-width: 0; }
.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 20px; margin: 0; padding: 0; list-style: none; font-size: 0.88rem; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 2px; }
.pct { font-family: var(--font-data); font-size: 0.82rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; border-top: 1px solid var(--rule); padding-top: 16px; }
.stat { display: grid; gap: 2px; align-content: start; }
.stat b { font-family: var(--font-data); font-weight: 500; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.side { display: grid; gap: 24px; min-width: 0; }
.savings { display: grid; gap: 14px; }
.savings .stats { border-top: 0; padding-top: 0; }
.fold { min-width: 0; }
.fold summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }
.fold summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.fold[open] summary { margin-bottom: 8px; }
#fold-profile summary { position: relative; padding-right: 72px; }
.link-btn { position: absolute; top: 0; right: 0; font: inherit; font-size: 0.85rem; font-weight: 500; padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
form hr { border: 0; border-top: 1px solid var(--rule); margin: 0; width: 100%; }

.workings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.workings .sheet { display: grid; gap: 14px; }
.lines { display: grid; margin: 0; }
.lines > div { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; border-bottom: 1px solid var(--rule); }
.lines > div:last-child { border-bottom: 0; }
.lines dt { min-width: 0; font-size: 0.92rem; }
.lines dt small { display: block; color: var(--muted); font-size: 0.8rem; }
.lines dd { margin: 0; font-family: var(--font-data); font-size: 0.92rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines .total dt, .lines .total dd { font-weight: 600; }
.wide { grid-column: 1 / -1; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 460px; }
th { text-align: right; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--rule); }
td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--rule); font-family: var(--font-data); font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
.notes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; font-size: 0.9rem; }
.notes ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 6px; }
.notes a { color: var(--accent); }
.foot { color: var(--muted); font-size: 0.85rem; margin: 0; max-width: 75ch; }
@media (max-width: 860px) {
  .tool, .workings, .notes { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .legend { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
