/* Kalkulator oszczędzania — Business Insider Polska */

:root {
  --blue: #086ef7;
  --blue-hover: #0862da;
  --blue-soft: #eaf2fe;

  /* serie wykresu (zwalidowane: dataviz validate_palette.js) */
  --c-paid: #7fb0ff;
  --c-gain: #086ef7;
  --c-loss: #db3832;

  --ink: #1e1e1e;
  --ink-2: #444444;
  --muted: #6b6b6b;
  --faint: #9e9e9e;
  --line: #e0e0e0;
  --grid: #ececec;
  --page: #f9f9f9;
  --panel: #f5f5f5;

  --font: "Poppins", system-ui, sans-serif;
  --font-head: "Poppins", system-ui, sans-serif;
  --radius: 12px;
  --thumb: 22px;
}

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

html, body { margin: 0; padding: 0; background: var(--page); }

/* iOS nie powiększa samowolnie tekstu (np. w poziomie) — wysokość zostaje przewidywalna */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* łamanie tekstu wyważone wszędzie, gdzie to możliwe */
h1, p, label, small, .field-label, .res-label, .check-text, .tip {
  text-wrap: balance;
}

/* scrollbar */
::-webkit-scrollbar { width: 9px; height: 9px; display: block; }
::-webkit-scrollbar-track { background-color: #f1f1f1; border-radius: 5px; }
::-webkit-scrollbar-thumb { background-color: var(--blue); border-radius: 5px; }
html { scrollbar-width: thin; scrollbar-color: var(--blue) #f1f1f1; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- wrapper ---------- */

.embed-wrap {
  position: relative;
  width: 100%;
  height: 840px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 24px 20px;
  overflow: hidden;
  background: var(--page);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- nagłówek ---------- */

.calc-head {
  flex: none;
  text-align: center;
}

.calc-brand {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.calc-logo {
  display: block;
  height: 11px;
  width: auto;
}

.calc-kicker {
  display: inline-block;
  padding: 4px 8px 3px;
  border-radius: 4px;
  background: var(--blue);
  color: #ffffff;
  font-size: 11px;
  line-height: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.calc-title {
  margin: 0 auto;
  max-width: 640px;
  font: 700 26px/1.25 var(--font-head);
  letter-spacing: -.01em;
  color: var(--ink);
}

/* ---------- siatka ---------- */

.calc-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "controls result"
    "controls chart"
    "controls million";
  column-gap: 16px;
}

.card {
  padding: 20px;
  background: #ffffff;
  border: 1px solid var(--line);
}

.controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: var(--radius);
}

/* prawa kolumna na desktopie: jedna karta z separatorami */
.result  { grid-area: result;  border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.chart   { grid-area: chart;   border-top-color: var(--grid); border-bottom: 0; }
.million { grid-area: million; border-top-color: var(--grid); border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- pola ---------- */

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.field-label, .res-label {
  margin: 0;
  font-size: 12px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.field-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
}

/* ---------- pole liczbowe ---------- */

.num {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 10px 3px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
}

.num:hover { border-color: #a9c9fb; }

.num:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(8, 110, 247, .18);
}

.num-input {
  width: 4ch; /* dopasowywane w JS do długości liczby */
  min-width: 2ch;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  text-align: right;
  font: 600 18px/1.3 var(--font-head);
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}


.num-unit {
  font: 600 15px/1.3 var(--font-head);
  color: var(--blue);
}

/* ---------- suwak ---------- */

input[type="range"] {
  --f: 0;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right,
    var(--blue) 0,
    var(--blue) calc(var(--f) * (100% - var(--thumb)) + var(--thumb) / 2),
    var(--line) calc(var(--f) * (100% - var(--thumb)) + var(--thumb) / 2),
    var(--line) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((6px - var(--thumb)) / 2);
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--blue);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
  transition: transform .12s;
}

input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(8, 110, 247, .25); }

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
}

input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--blue);
}

input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  box-sizing: border-box;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--blue);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(8, 110, 247, .25); }

/* ---------- instrumenty (pigułki) ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  margin: 0;
  padding: 6px 12px;
  font: 500 13px/1.2 var(--font);
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 100px;
  cursor: pointer;
  transition: border-color .15s, background-color .15s, color .15s;
  user-select: none;
  -webkit-user-select: none;
}

.chip-rate { font-weight: 400; color: var(--muted); }

.chip:hover { border-color: #a9c9fb; }
.chip:focus { outline: none; }
.chip:focus-visible { box-shadow: 0 0 0 3px rgba(8, 110, 247, .25); }

.chip[aria-pressed="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.chip[aria-pressed="true"] .chip-rate { color: rgba(255, 255, 255, .85); }

.field-own {
  padding-top: 14px;
  border-top: 1px solid var(--grid);
}

.field-own .field-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

/* ---------- inflacja ---------- */

.check {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.check input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.check-box {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border: 2px solid var(--faint);
  border-radius: 5px;
  background: #ffffff;
  transition: background-color .15s, border-color .15s;
}

.check:hover .check-box { border-color: var(--blue); }

.check input:checked + .check-box {
  background: var(--blue);
  border-color: var(--blue);
}

.check input:checked + .check-box::after {
  content: "";
  width: 5px;
  height: 10px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}

.check input:focus-visible + .check-box { box-shadow: 0 0 0 3px rgba(8, 110, 247, .25); }

.check-text {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 500;
}

.check-note { font-weight: 400; color: var(--muted); }

.check-text small {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

/* ---------- wynik ---------- */

.result { padding-bottom: 18px; }

.res-total {
  margin: 6px 0 2px;
  font: 700 clamp(32px, 5.2vw, 46px)/1.1 var(--font-head);
  letter-spacing: -.02em;
  white-space: nowrap;
}

.res-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  /* zawsze 2 linie (druga przy inflacji), żeby wykres nie skakał */
  min-height: 2.8em;
  color: var(--muted);
}

.res-sub-line { display: block; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.tile {
  padding: 9px 12px 10px;
  background: var(--panel);
  border-radius: 10px;
}

.tile-label {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.tile-val {
  display: block;
  margin-top: 3px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

.sw {
  flex: none;
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.sw[hidden] { display: none; }
.sw-paid { background: var(--c-paid); }
.sw-gain { background: var(--c-gain); }
.sw-loss { background: var(--c-loss); }

/* ---------- wykres ---------- */

.chart {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 20px 12px;
}

.chart-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 6px;
}

.legend {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-box {
  position: relative;
  flex: 1;
  min-height: 170px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 6px;
}

.chart-box:focus { outline: none; }
.chart-box:focus-visible { box-shadow: 0 0 0 2px var(--blue); }

.chart-box svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-box .grid { stroke: var(--grid); stroke-width: 1; }
.chart-box .axis { stroke: #cecece; stroke-width: 1; }

.chart-box .ytick,
.chart-box .xtick {
  font-family: var(--font);
  font-size: 11px;
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-box .xtick.last { font-weight: 600; fill: var(--ink); }

.chart-box .end-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  fill: var(--ink);
}

.chart-box .bar { transition: opacity .12s; }
.chart-box .is-hover .bar:not(.on) { opacity: .4; }
.chart-box .seg-paid { fill: var(--c-paid); }
.chart-box .seg-gain { fill: var(--c-gain); }
.chart-box .seg-loss { fill: var(--c-loss); }

.tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  min-width: 170px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}

.tip.show { opacity: 1; }

.tip-title { display: block; margin-bottom: 2px; font-weight: 600; }

.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}

.tip-row > span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.tip-row.total { margin-top: 2px; padding-top: 3px; border-top: 1px solid var(--grid); font-weight: 600; }
.tip-row.total > span:first-child { color: var(--ink); }

.chart-note {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.touch-hint { display: none; }

@media (hover: none) {
  .hover-hint { display: none; }
  .touch-hint { display: inline; }
}

/* ---------- droga do miliona ---------- */

.million { padding-top: 16px; }

.mil-val {
  margin: 6px 0 4px;
  font: 700 26px/1.2 var(--font-head);
  color: var(--blue);
}

.mil-val small {
  font: 500 14px var(--font);
  color: var(--muted);
}

.mil-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}

.mil-text strong { color: var(--ink); font-weight: 600; }

.mil-stack { display: grid; }
.mil-stack > * { grid-area: 1 / 1; }
.mil-sizer { visibility: hidden; pointer-events: none; }

/* ---------- stopka ---------- */

.calc-foot {
  flex: none;
  margin: 0 auto;
  max-width: 820px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- desktop: nieco mniejsza skala, lewa kolumna węższa ---------- */

@media (min-width: 641px) {
  .embed-wrap { font-size: 14px; gap: 16px; padding: 22px 22px 18px; }
  .calc-title { font-size: 24px; }
  .calc-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); column-gap: 14px; }
  .card { padding: 18px; }
  .chart { padding: 14px 18px 10px; }
  .controls { gap: 14px; }
  .field-label, .res-label { font-size: 11px; }
  .field-own .field-label { font-size: 13px; }
  .num-input { font-size: 16px; }
  .num-unit { font-size: 13px; }
  .chip { font-size: 12px; padding: 5px 11px; }
  .check-text { font-size: 13px; }
  .check-text small { font-size: 11px; }
  .res-total { font-size: clamp(30px, 4.6vw, 42px); }
  .res-sub { font-size: 12px; }
  .tile-val { font-size: 15px; }
  .tile-label, .legend, .chart-note { font-size: 11px; }
  .mil-val { font-size: 23px; }
  .mil-val small { font-size: 13px; }
  .mil-text { font-size: 13px; }
  .calc-foot { font-size: 11px; }
}

/* ---------- wąski desktop ---------- */

@media (min-width: 641px) and (max-width: 800px) {
  .embed-wrap { padding: 20px 16px 16px; gap: 14px; }
  .calc-title { font-size: 22px; }
  .calc-grid { column-gap: 12px; }
  .card { padding: 16px; }
  .chart { padding: 14px 16px 10px; }
  .controls { gap: 13px; }
  .field-own { padding-top: 11px; }
  .res-total { font-size: 32px; }
  .tiles { margin-top: 10px; }
  .mil-val { font-size: 22px; }
  .mil-text { font-size: 13px; }
  .field-label, .res-label { font-size: 11px; }
  .calc-foot { font-size: 11px; }
}

/* ---------- mobile ---------- */

@media (max-width: 640px) {
  :root { --thumb: 26px; }

  .embed-wrap {
    height: 1620px;
    gap: 14px;
    padding: 16px 16px 14px;
    /* awaryjnie (np. powiększony tekst systemowy): przewijanie zamiast ucięcia */
    overflow-y: auto;
  }

  .calc-title { font-size: 21px; }

  /* logo nad etykietą */
  .calc-brand { flex-direction: column; gap: 8px; }

  /* na wąskich ekranach druga linia może się złamać — rezerwa na 3 linie */
  .res-sub { min-height: 4.2em; }

  /* wykres wypełnia wolne miejsce — bez pustego pasa na dole */
  .chart-box { min-height: 170px; max-height: 300px; }

  /* wynik pod suwakami */
  .calc-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    align-content: start;
    grid-template-areas:
      "controls"
      "result"
      "chart"
      "million";
    row-gap: 12px;
  }

  .card { padding: 16px; }
  .chart { padding: 14px 16px 12px; }

  .result, .chart, .million {
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  .res-total { font-size: 38px; }

  input[type="range"] { height: 30px; }

  .num-input { font-size: 17px; }
}

/* ---------- bardzo wąskie telefony (np. iPhone SE 1. gen.) ---------- */

@media (max-width: 359px) {
  .embed-wrap { padding: 14px 12px 12px; gap: 12px; }
  .calc-title { font-size: 19px; }
  .card { padding: 14px; }
  .chart { padding: 12px 14px 10px; }
  .controls { gap: 13px; }
  .field-label, .res-label { font-size: 11px; }
  .field-own .field-label { font-size: 13px; }
  .chip { font-size: 12px; padding: 5px 9px; }
  .chips { gap: 5px; }
  .check-text small { font-size: 11px; }
  .res-total { font-size: 34px; }
  .chart-box { min-height: 150px; }
  .mil-text { font-size: 13px; }
  .calc-foot { font-size: 10.5px; }
}

/* legenda zawsze pod tytułem wykresu — dłuższe opisy (strata) nie zmieniają wysokości */
@media (max-width: 800px) {
  .chart-head { flex-direction: column; align-items: flex-start; }
}
