/*
 * Komponenty stron kalkulatorów (docs/visual-language.md): układ, formularz, suwak, wynik, wykresy, tabele, teksty.
 * Wymaga tokens.css. Bez zewnętrznych czcionek: systemowy stos fontów.
 */

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p, ul, figure, fieldset { margin: 0; }
h1, h2, h3 { text-wrap: balance; line-height: 1.15; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Układ */
.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.crumbs { font-size: 14px; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.intro { display: grid; gap: 8px; }
.eyebrow { font: 500 12px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
h1 { font-size: clamp(30px, 5vw, 42px); font-weight: 750; letter-spacing: -.015em; }
.lede { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  display: grid;
  gap: 14px;
  min-width: 0;
}
.card h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }

.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
@media (max-width: 720px) { .columns { grid-template-columns: minmax(0, 1fr); } }

/* Formularz */
/* Fieldset z legendą jako zwykły blok: legenda pływa, więc nie siada na linii oddzielającej. */
.calc { display: block; }
.step { border: 0; margin: 0; padding: 0; min-width: 0; display: block; }
.step + .step { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.step > * + * { margin-top: 10px; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-size: 19px; font-weight: 600; }
legend + * { clear: both; margin-top: 0; }
.step > legend + * + * { margin-top: 10px; }
.n { font: 500 12px var(--mono); color: var(--accent); border: 1px solid currentColor; border-radius: 99px; padding: 1px 8px; }

.row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.hint { font-size: 13px; color: var(--muted); }
.hint.at-limit { color: var(--warn); font-weight: 600; }

.money {
  display: flex; align-items: center; gap: 6px;
  width: 200px; max-width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--sunken);
  color: var(--muted); font-size: 14px;
}
.money:focus-within { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.money input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; color: var(--ink);
  font: 500 22px var(--mono); font-variant-numeric: tabular-nums;
  padding: 10px 0;
}
.money input:focus { outline: none; }

.toggle { display: inline-flex; gap: 6px; }
.toggle label { position: relative; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle span {
  display: block; padding: 5px 12px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--line); border-radius: 99px; background: var(--sunken); cursor: pointer;
}
.toggle input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

select {
  font: inherit; font-size: 14px; color: var(--ink); max-width: 100%; min-width: 0; flex: 0 1 380px;
  background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Suwak: wypełnienie niebieskie do progu, pomarańczowe za progiem */
.slider { --p: 50%; --t: 50%; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 36px; margin: 0; background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 10px; border-radius: 99px;
  background: linear-gradient(to right,
    var(--low) 0 min(var(--p), var(--t)),
    var(--high) min(var(--p), var(--t)) var(--p),
    var(--line) var(--p));
}
input[type="range"]::-moz-range-track {
  height: 10px; border-radius: 99px;
  background: linear-gradient(to right,
    var(--low) 0 min(var(--p), var(--t)),
    var(--high) min(var(--p), var(--t)) var(--p),
    var(--line) var(--p));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; margin-top: -10px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--ink);
  box-shadow: 0 1px 4px rgb(0 0 0 / .2); cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--ink);
  box-shadow: 0 1px 4px rgb(0 0 0 / .2); cursor: grab;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }

.ticks { position: relative; height: 18px; font: 500 12px var(--mono); color: var(--muted); }
.ticks span { position: absolute; white-space: nowrap; transform: translateX(-50%); }
.ticks .start { transform: none; }
.ticks .end { transform: translateX(-100%); }
.ticks .threshold { color: var(--high); }

/* Wynik */
.result > * + * { margin-top: 16px; }
.headline { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; }
.label { font-size: 13px; color: var(--muted); }
.big { font-size: clamp(40px, 8vw, 56px); font-weight: 750; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big small { font-size: .42em; font-weight: 500; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px;
  font-size: 13px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* Wykres i podział wpłaty jako jeden element */
.combo { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--sunken); min-width: 0; }
.chart { display: block; width: calc(100% - 24px); height: 270px; margin: 12px 12px 4px; overflow: visible; }
.combo figcaption { display: grid; gap: 10px; padding: 12px 14px 14px; border-top: 1px solid var(--line); background: var(--surface); }

.chart text { font: 11px var(--mono); fill: var(--muted); }
.chart .grid { stroke: var(--line); }
.chart .area-low { fill: var(--low-soft); }
.chart .area-high { fill: var(--high-soft); }
.chart .line-low { fill: none; stroke: var(--low); stroke-width: 2; stroke-linejoin: round; }
.chart .line-high { fill: none; stroke: var(--high); stroke-width: 2.5; stroke-linejoin: round; }
.chart .threshold { stroke: var(--high); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart text.threshold-label { fill: var(--high); font-weight: 500; }
.chart .guide { stroke: var(--ink); stroke-dasharray: 3 3; opacity: .55; }
.chart .dot { fill: var(--ink); stroke: var(--surface); stroke-width: 2.5; }
.chart text.value { font: 600 13px var(--font); fill: var(--ink); }
.chart text.layer { font: 600 12px var(--font); }
.chart text.layer-low { fill: var(--low); }
.chart text.layer-high { fill: var(--high); }

.bar { display: flex; gap: 2px; height: 24px; border-radius: 6px; overflow: hidden; background: var(--line); }
.bar i { display: block; min-width: 3px; transition: flex-grow .2s; }

.high { --swatch: var(--high); }
.low { --swatch: var(--low); }
.zero { --swatch: var(--zero); }
.over { --swatch: repeating-linear-gradient(45deg, var(--zero) 0 4px, var(--zero-soft) 4px 8px); }
.bar i { background: var(--swatch); }

.parts { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 20px; }
.parts li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 4px 10px; }
.parts li::before { content: ""; width: 12px; height: 12px; margin-top: 5px; border-radius: 3px; background: var(--swatch); }
.parts b { font-size: 14px; }
.parts .nums, .parts .what { grid-column: 2; }
.parts .nums { font: 500 14px var(--mono); font-variant-numeric: tabular-nums; }
.parts .what { font-size: 13px; color: var(--muted); }
.parts .off { opacity: .5; }

.explain { display: grid; gap: 10px; }
.explain p { max-width: 65ch; }
.explain .note { font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); border-left: 3px solid var(--warn); }
.explain .meta { font-size: 13px; color: var(--muted); }

.num { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Tabela rozliczenia */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 8px 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; vertical-align: top; }
td:last-child { text-align: right; padding-left: 12px; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot th, tfoot td { border-bottom: 0; padding-top: 12px; font-weight: 600; }
tfoot td { color: var(--accent); font-size: 16px; }

/* Tabela wyników przy różnych zarobkach */
.table-scroll { overflow-x: auto; }
.data-table th, .data-table td { padding: 8px 10px; text-align: right; white-space: nowrap; font-family: var(--font); font-variant-numeric: tabular-nums; }
.data-table th:first-child, .data-table td:first-child { padding-left: 0; text-align: left; }
.data-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); vertical-align: bottom; white-space: normal; }
.data-table tbody th { font-weight: 600; }
.data-table td:last-child { font-weight: 400; color: inherit; }
.data-table td.relief { font-weight: 600; color: var(--accent); }
@media (max-width: 600px) {
  .data-table .extra { display: none; }
  .data-table th, .data-table td { padding-inline: 6px; }
}

/* Teksty */
.prose p, .prose li { max-width: 68ch; }
.prose ul { padding-left: 18px; display: grid; gap: 6px; }
.prose pre { margin: 0; padding: 12px; overflow-x: auto; white-space: pre-wrap; font: 13px var(--mono); background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; }
.faq { gap: 10px; }
.faq h3 { font-size: 17px; font-weight: 600; margin-top: 10px; }
.foot { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
.foot a { color: var(--accent); }
.foot code { font: 12px var(--mono); overflow-wrap: anywhere; }


/* Kilka liczb obok siebie zamiast jednej (np. najwięcej / najmniej / różnica) */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stats .wide { grid-column: 1 / -1; }
.stat { display: grid; gap: 2px; }
.stat .v { font-size: clamp(26px, 5vw, 38px); font-weight: 750; letter-spacing: -.015em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .v small { font-size: .45em; font-weight: 500; color: var(--muted); }
.stat .d { font-size: 13px; color: var(--muted); }
.stat .d b { color: var(--ink); }
@media (max-width: 560px) { .stats { grid-template-columns: minmax(0, 1fr); } }

/* Legenda wykresu: kwadrat w kolorze (--sw), nazwa i opcjonalna kwota */
.legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 2px 8px; font-size: 13px; }
.legend li::before { content: ""; width: 12px; height: 12px; margin-top: 4px; border-radius: 3px; background: var(--sw); }
.legend b { font-size: 14px; }
.legend span { grid-column: 2; font: 500 13px var(--mono); color: var(--muted); }
.legend .low { --sw: var(--low); }
.legend .high { --sw: var(--high); }
.legend .hatch { --sw: repeating-linear-gradient(45deg, var(--ink) 0 1.5px, transparent 1.5px 5px); }
.legend .net { --sw: var(--part-net); }
.legend .pit { --sw: var(--part-pit); }
.legend .zus { --sw: var(--part-zus); }
.legend .health { --sw: var(--part-health); }

/* Kreskowanie na wykresie (wzór <pattern id="hatch"> rysuje JS) */
.chart .hatch { fill: url(#hatch); }
.chart .hatch-line { stroke: var(--ink); stroke-width: 1.5; opacity: .35; }

/* Dymek nad wykresem */
.tip { position: fixed; pointer-events: none; z-index: 5; min-width: 190px; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 4px 16px rgb(0 0 0 / .15); font-size: 13px; }
.tip[hidden] { display: none; }
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 12px; font: 12px var(--mono); }
.tip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

/* Powiązany kalkulator (docs/visual-language.md, sekcja 9) */
.related { display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--accent-soft); background: var(--accent-soft); }
.related p { max-width: 65ch; }
.related a { color: var(--accent); font-weight: 600; }
.related .label { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
