:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f9;
  --field-bg: #ffffff;
  --text: #1b1c2e;
  --muted: #52566f;
  --line: #dcdde9;
  --field-line: #6a6e8a; /* field borders: at least 3:1 against the card and the page */
  --accent: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #e7e8fb;
  --warn: #92400e;
  --warn-soft: #fef3e2;
  --error: #b91c1c;
  --radius: 12px;
  --tap: 44px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131c;
    --surface: #1a1c29;
    --surface-2: #232637;
    --field-bg: #232637;
    --text: #e8e9f5;
    --muted: #a3a7c2;
    --line: #31344a;
    --field-line: #7d82a3;
    --accent: #a5b4fc;
    --accent-ink: #14163a;
    --accent-soft: #25284d;
    --warn: #fbbf24;
    --warn-soft: #2b2416;
    --error: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: break-word;
}

h1, h2, h3 { text-wrap: balance; }

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.skip-link { position: absolute; left: 8px; top: -60px; z-index: 10; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 8px; font-weight: 700; text-decoration: none; }
.skip-link:focus { top: 8px; }
main:focus { outline: none; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header > .wrap { display: flex; align-items: center; min-height: 56px; }
.logo { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.2rem; }
.logo svg { color: var(--accent); }
.logo .glyph { stroke: var(--surface); }
.logo small { color: var(--muted); font-weight: 500; font-size: 0.8rem; margin-left: 2px; }
.site-nav { border-top: 1px solid var(--line); }
.site-nav .wrap { display: flex; gap: 4px; overflow-x: auto; padding-top: 4px; padding-bottom: 4px; scrollbar-width: none; }
.site-nav .wrap::-webkit-scrollbar { display: none; }
.site-nav a { flex: none; display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 0.9rem; white-space: nowrap; }
.site-nav a:hover { background: var(--surface-2); color: var(--text); }
.site-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* Content */
main { padding-bottom: 48px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; margin-top: 4px; font-size: 0.85rem; color: var(--muted); }
.crumbs a { display: inline-flex; align-items: center; min-height: var(--tap); min-width: var(--tap); color: var(--muted); }
h1 { font-size: 1.75rem; line-height: 1.3; margin: 20px 0 8px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 20px; }
h2 { font-size: 1.3rem; line-height: 1.4; margin: 40px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
h3 { font-size: 1.08rem; line-height: 1.4; margin: 26px 0 8px; }
p, ul, ol { margin: 0 0 14px; }
ul, ol { padding-left: 1.4em; }
li { margin-bottom: 4px; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.note { font-size: 0.88rem; color: var(--muted); }
.meta { font-size: 0.85rem; color: var(--muted); margin-top: 32px; }
.callout { background: var(--warn-soft); border-left: 4px solid var(--warn); padding: 10px 14px; border-radius: 6px; font-size: 0.95rem; margin: 16px 0; }
.formula { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 12px 0; }
.sources ul { font-size: 0.93rem; }
.contact-mail { font-size: 1.2rem; font-weight: 700; }

/* Spacing helper (no inline styles) */
.mt-s { margin-top: 8px; }

table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 0.95rem; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
thead th { background: var(--surface-2); font-weight: 600; }
tbody th { font-weight: 600; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; margin-bottom: 16px; }
.table-scroll table { margin: 0; }

/* Tool card */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 0 20px; }
.tool > h2:first-child { margin-top: 0; font-size: 1.1rem; border: 0; padding: 0; }
.table-scroll code { white-space: nowrap; }
.block { display: block; color: var(--muted); }
.tool-hint { font-size: 0.9rem; color: var(--muted); margin: -4px 0 12px; }

label { font-size: 0.92rem; color: var(--muted); }
input[type="text"] {
  font: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--field-line);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: var(--tap);
  width: 100%;
  font-variant-numeric: tabular-nums;
}
input::placeholder { color: var(--muted); opacity: 1; } /* full-strength muted text: 3.5:1 at 70% opacity was too faint */
input:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible, .table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; font-size: 0.92rem; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-bottom: 12px; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0; }
.field-error { font-size: 0.88rem; font-weight: 600; color: var(--error); margin: 0; }
.field-error::before { content: "Problem: "; font-weight: 700; }

/* Amount field with a "$" in front */
.money-input { display: flex; align-items: stretch; min-height: var(--tap); background: var(--field-bg); border: 1px solid var(--field-line); border-radius: 8px; }
.money-input > span { display: flex; align-items: center; padding-left: 12px; color: var(--muted); font-size: 1.1rem; }
.money-input input { flex: 1; min-width: 0; border: 0; box-shadow: none; background: transparent; border-radius: 8px; padding-left: 6px; }
.money-input:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.money-input input:focus-visible { outline: none; }
.money-input:has(input[aria-invalid="true"]) { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }

/* Segmented control made of radio buttons */
.seg { margin-bottom: 14px; }
.seg legend { margin-bottom: 4px; }
.seg-opts { display: flex; border: 1px solid var(--field-line); border-radius: 10px; overflow: hidden; background: var(--field-bg); }
.seg-opts label { flex: 1; position: relative; display: flex; color: var(--text); }
.seg-opts input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg-opts span { flex: 1; display: flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 6px 12px; font-size: 0.95rem; font-weight: 600; text-align: center; line-height: 1.3; }
.seg-opts label + label span { border-left: 1px solid var(--field-line); }
.seg-opts input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg-opts input:focus-visible + span { outline: 3px solid var(--text); outline-offset: -3px; }

.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); font-size: 0.95rem; color: var(--text); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }

.btn {
  font: inherit;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--field-line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  min-height: var(--tap);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.icon-btn { font: inherit; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; min-width: var(--tap); min-height: var(--tap); border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--error); }

/* Result */
.result { margin-top: 16px; background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; }
.result:empty { min-height: 96px; }
.result-main { font-size: 2.2rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; color: var(--text); overflow-wrap: anywhere; }
.result-main small { display: block; font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.result dl { display: grid; grid-template-columns: fit-content(55%) minmax(0, 1fr); gap: 4px 14px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); font-size: 0.95rem; }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.result dd small { display: block; font-weight: 400; font-size: 0.82rem; color: var(--muted); }
.result .err { color: var(--error); font-weight: 600; font-size: 1rem; }
.result-empty { margin: 0; color: var(--muted); }
.result-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.copy-btn { font-size: 0.9rem; }

/* "Next step" card after a tool: quiet, one outlined button, nothing that looks like an advert */
.next-step { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 12px 16px 14px; margin: 0 0 24px; }
.next-step p { margin: 0; }
.next-step-label { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.next-step-title { margin-top: 2px; font-weight: 700; }
.next-step-text { margin: 2px 0 10px; font-size: 0.95rem; color: var(--muted); }
.next-step .btn { display: inline-flex; align-items: center; text-decoration: none; font-weight: 600; color: var(--accent); border-color: var(--accent); }

/* Invoice items */
.inv-rows { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.inv-row { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 4px 12px 10px; }
.inv-head { display: flex; align-items: center; justify-content: space-between; }
.inv-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; }
.inv-fields .field { margin-bottom: 6px; }
.inv-flags { display: flex; flex-wrap: wrap; column-gap: 20px; }
.inv-out { margin: 2px 0 0; font-size: 0.88rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.4em; }
@media (min-width: 560px) { .inv-fields { grid-template-columns: minmax(0, 1fr) 180px; } }

/* BAS worksheet */
.bas-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 16px; }
@media (min-width: 640px) { .bas-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.group-title { font-weight: 700; font-size: 1.02rem; color: var(--text); margin-bottom: 8px; }
.tool details > summary { display: flex; align-items: center; min-height: var(--tap); color: var(--accent); font-size: 0.95rem; list-style: none; cursor: pointer; }
.tool details > summary::-webkit-details-marker { display: none; }
.tool details > summary::before { content: "▸"; margin-right: 6px; transition: transform 0.15s; }
.tool details[open] > summary::before { transform: rotate(90deg); }

/* Lists and FAQ */
.tool-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.tool-list li { margin: 0; }
.tool-list a { display: block; height: 100%; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--text); }
.tool-list a:hover { border-color: var(--accent); }
.tool-list strong { display: block; color: var(--accent); }
.tool-list span { display: block; font-size: 0.88rem; color: var(--muted); line-height: 1.5; }
.faq details { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.faq summary { cursor: pointer; padding: 10px 14px; font-weight: 600; }
.faq details > div { padding: 0 14px 4px; }

.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 20px 0 28px; font-size: 0.88rem; color: var(--muted); }
.site-footer p { margin: 0 0 8px; }
.site-footer a { color: var(--muted); }
.footer-links { display: flex; flex-wrap: wrap; gap: 0 20px; }
.footer-links a { display: inline-flex; align-items: center; min-height: var(--tap); min-width: var(--tap); }
h1 + .table-scroll { margin-top: 16px; }

@media (max-width: 480px) {
  h1 { font-size: 1.5rem; }
  .result-main { font-size: 1.9rem; }
}

/* On phones a slim total bar stays in view while items are edited (the full result is below the list) */
.inv-bar { display: none; }
@media (max-width: 600px) {
  .inv-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; position: sticky; bottom: 8px; z-index: 2; margin: 12px 0 0; padding: 10px 16px; background: var(--accent); color: var(--accent-ink); border-radius: 10px; box-shadow: 0 -2px 10px rgb(0 0 0 / 0.2); font-weight: 600; font-variant-numeric: tabular-nums; }
  .inv-bar[hidden] { display: none; }
  .inv-bar strong { font-size: 1.25rem; }
  #inv-tool input { scroll-margin-bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .site-header, .site-nav, .related, .site-footer, .btn-row, .icon-btn, .result-actions, .skip-link, .next-step { display: none !important; }
  body { background: #fff; }
}

.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; }
