/* Fairfinanz — Ratenrechner.
   Nur Token-Farben aus css/tokens.css. Kein Verlauf, kein Schatten, kein zweites Rot.
   Rost erscheint hier nur im Fokusring (aus tokens.css) — nirgends als Fläche. */

.rechner-karte {
  background: var(--flaeche2);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  padding: 40px;
}

.rechner-raster {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

/* ---------- Eingaben ---------- */

.r-eingaben { margin: 0; padding: 0; border: 0; min-width: 0; }
.r-eingaben legend { padding: 0; }

.r-feld + .r-feld { margin-top: 30px; }

.r-feld-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.r-feld-kopf label {
  font-weight: 600;
  color: var(--tinte);
  line-height: 1.3;
}

/* Zahlenfeld + Einheit — die Einheit steht neben dem Feld, nicht im Feldwert. */
.r-eingabe {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.r-einheit {
  flex: 0 0 auto;
  width: 16px;
  font-weight: 600;
  color: var(--sekundaer);
}

.r-zahl {
  width: 160px;
  flex: 0 0 auto;
  min-height: 52px;
  padding: 0 14px;
  text-align: right;
  font-family: inherit;
  font-size: var(--t-body);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--tinte);
  background: var(--papier);
  /* --sekundaer statt --linie: gegen die Kartenfläche (--flaeche2) ergibt --linie
     nur 1,22:1 — das Feld war als Eingabe nicht erkennbar (WCAG 1.4.11 verlangt 3:1).
     --sekundaer bringt 7,18:1, genau wie das Kontaktformular. */
  border: 1.5px solid var(--sekundaer);
  border-radius: var(--radius);
}
.r-zahl:hover { border-color: var(--tinte); }
.r-zahl:focus { border-color: var(--tinte); outline: none; }
.r-zahl:focus-visible { outline: 2px solid var(--tinte); outline-offset: 2px; }

/* Schieberegler — Bahn: Sekundär · Griff: Tinte.
   Die Bahn trug früher --linie und war gegen die Karte praktisch unsichtbar (1,22:1);
   --sekundaer bringt 7,18:1 — eine feine, aber sichtbare Linie. */
.r-regler {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 28px;
  margin: 14px 0 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
/* Der zurückgelegte Teil der Schiene ist golden — die Breite kommt als --fortschritt
   aus js/rechner.js. Gold ist hier eine Linie, kein Text: erlaubt. Fällt das Skript
   aus, ist --fortschritt leer, der Verlauf 0 breit und die Schiene schlicht grau. */
.r-regler::-webkit-slider-runnable-track {
  height: 4px;
  background:
    linear-gradient(var(--akzent), var(--akzent)) left center / var(--fortschritt, 0%) 4px no-repeat,
    var(--sekundaer);
  border-radius: 2px;
}
.r-regler::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -12px;
  border: none;
  border-radius: 50%;
  background: var(--tinte);
}
.r-regler::-moz-range-track {
  height: 4px;
  background:
    linear-gradient(var(--akzent), var(--akzent)) left center / var(--fortschritt, 0%) 4px no-repeat,
    var(--sekundaer);
  border-radius: 2px;
}
.r-regler::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--tinte);
}
.r-regler:focus { outline: none; }
.r-regler:focus-visible {
  outline: 2px solid var(--tinte);
  outline-offset: 4px;
  border-radius: 4px;
}

.r-skala {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: var(--t-klein);
  color: var(--sekundaer);
}

/* Makler-Schalter */
.r-schalter {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--linie);
  cursor: pointer;
  font-weight: 600;
}
.r-haken {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin: 0;
  background: var(--papier);
  border: 2px solid var(--tinte);
  border-radius: 3px;
  cursor: pointer;
}
.r-haken:checked { background: var(--tinte); }
.r-haken:checked::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 3px;
  width: 6px;
  height: 13px;
  border: solid var(--papier);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

/* ---------- Ergebnis ---------- */

.r-ergebnis {
  min-width: 0;
  padding: 32px;
  background: var(--papier);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
}

.r-rate {
  display: block;
  margin-top: 14px;
  font-family: "Archivo", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(44px, 5.4vw, 68px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  color: var(--tinte);
  font-variant-numeric: tabular-nums;
}
/* Sonderfall „Kein Darlehen nötig" — Text statt Zahl, darf nicht umbrechen wie eine Summe */
.r-rate--text {
  font-size: clamp(26px, 2.8vw, 34px);
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.r-rate-fuss {
  margin-top: 10px;
  font-size: var(--t-klein);
  color: var(--sekundaer);
}

.r-liste { margin: 26px 0 0; }
.r-zeile {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 0;
  border-top: 1px solid var(--linie);
}
.r-zeile dt { color: var(--sekundaer); }
.r-zeile dd {
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Die Zinsbindungs-Tabelle — der Teil, an dem sich eine Baufinanzierung entscheidet.
   Kurz gebunden ist billiger, lässt aber mehr Restschuld stehen. Genau diese Abwägung
   zeigte der alte Rechner nicht: Er kannte nur EINE Rate zu einem Zins, den der Besucher
   selbst geraten hatte. */
.r-tabelle-huelle {
  margin-top: 26px;
  overflow-x: auto; /* auf mittleren Breiten scrollt die Tabelle, nicht die Seite */
}
.r-tabelle-huelle[hidden] { display: none; }
.r-tabelle-huelle:focus-visible {
  outline: 2px solid var(--tinte);
  outline-offset: 3px;
}
.r-tabelle {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: var(--t-klein);
}
.r-tabelle th,
.r-tabelle td {
  text-align: right;
  padding: 12px 0 12px 16px;
  white-space: nowrap;
  border-top: 1px solid var(--linie);
}
.r-tabelle thead th {
  border-top: 0;
  border-bottom: 2px solid var(--akzent);
  padding-top: 0;
  font-weight: 600;
  color: var(--sekundaer);
  font-size: 14px;
}
.r-tabelle th[scope="row"],
.r-tabelle thead th:first-child {
  text-align: left;
  padding-left: 0;
  font-weight: 600;
}
.r-tabelle tbody th[scope="row"] { color: var(--tinte); }
.r-t-rate { font-weight: 700; }
.r-t-laufzeit { color: var(--sekundaer); }

/* Die Leitbindung (10 Jahre) trägt die große Zahl oben — hier wird sie wiedererkennbar
   markiert, damit klar ist, welche Zeile gemeint ist. */
.r-tabelle tbody tr.ist-leit { background: var(--flaeche2); }
.r-tabelle tbody tr.ist-leit th[scope="row"],
.r-tabelle tbody tr.ist-leit td:first-of-type { padding-left: 10px; }
.r-tabelle tbody tr.ist-leit td:last-child { padding-right: 10px; }

/* "Restschuld danach 231.018 €" ist die erschreckendste Zahl der Seite. Sie braucht einen
   Satz, keine Fußnote — deshalb steht die Erklärung sichtbar unter der Tabelle. */
.r-erklaerung {
  margin-top: 18px;
  font-size: var(--t-klein);
  line-height: 1.6;
  color: var(--sekundaer);
  max-width: 56ch;
}
.r-erklaerung[hidden] { display: none; }

/* MOBIL WIRD DIE TABELLE ZU BLÖCKEN.
   Bei 390 px Fensterbreite liefen "Restschuld danach" und "Schuldenfrei nach" rechts aus der
   Hülle heraus — ohne Verlauf, ohne Wischhinweis, und die Overlay-Scrollbalken von iOS und
   Android erscheinen erst, WENN man schon scrollt. Genau die zwei Spalten, wegen derer der
   Zinsregler in Runde 5 gestrichen wurde, sah auf dem Handy niemand.
   Also kein Scrollen mehr, sondern ein Block je Zinsbindung. Die Spaltennamen kommen aus
   data-spalte (gesetzt in js/rechner.js) — der Tabellenkopf wird ausgeblendet, die
   Semantik der Tabelle bleibt für Screenreader erhalten. */
@media (max-width: 699px) {
  .r-tabelle-huelle { overflow-x: visible; }
  .r-tabelle thead { display: none; }
  .r-tabelle,
  .r-tabelle tbody,
  .r-tabelle tr,
  .r-tabelle th,
  .r-tabelle td { display: block; }

  .r-tabelle tbody tr {
    border-top: 1px solid var(--linie);
    padding: 14px 0;
  }
  .r-tabelle tbody tr.ist-leit {
    padding: 14px 12px;
  }
  .r-tabelle th[scope="row"] {
    border-top: 0;
    padding: 0 0 8px;
    font-size: 19px;
    font-weight: 700;
  }
  .r-tabelle td {
    border-top: 0;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    text-align: right;
  }
  .r-tabelle td::before {
    content: attr(data-spalte);
    color: var(--sekundaer);
    font-weight: 400;
    text-align: left;
  }
  .r-tabelle tbody tr.ist-leit th[scope="row"],
  .r-tabelle tbody tr.ist-leit td:first-of-type,
  .r-tabelle tbody tr.ist-leit td:last-child { padding-left: 0; padding-right: 0; }
}

/* Der Zins ist eine Angabe der Seite, keine Frage an den Besucher — also steht hier,
   woher er kommt und wie alt er ist. Ohne Datum wäre eine Zinsangabe irreführend. */
.r-annahme {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--linie);
  font-size: var(--t-klein);
  color: var(--sekundaer);
  line-height: 1.5;
}
.r-annahme b { color: var(--tinte); white-space: nowrap; }
.r-annahme-quelle { display: block; margin-top: 2px; }

.r-beispiel {
  font-size: 14px;
  line-height: 1.6;
  color: var(--sekundaer);
  padding-bottom: 18px;
}

/* Aufklappbare Herkunft der Kaufnebenkosten */
.r-details {
  margin-top: 0;
  border-top: 1px solid var(--linie);
}
.r-details > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 8px 0;
  list-style: none;
  cursor: pointer;
  font-size: var(--t-klein);
  font-weight: 600;
  color: var(--sekundaer);
}
.r-details > summary::-webkit-details-marker { display: none; }
.r-details > summary::after {
  content: "";
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--sekundaer);
  border-bottom: 2px solid var(--sekundaer);
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.18s ease;
}
.r-details[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.r-details > summary:hover { color: var(--tinte); }

.r-nk-liste {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: var(--t-klein);
}
.r-nk-liste li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  color: var(--sekundaer);
}
.r-nk-liste li + li { border-top: 1px solid var(--linie); }
/* Ohne diese Zeile schlägt display:flex das [hidden] des Browsers. */
.r-nk-liste li[hidden] { display: none; }
.r-nk-liste b {
  font-weight: 600;
  color: var(--tinte);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.r-nk-liste .r-nk-summe {
  color: var(--tinte);
  font-weight: 600;
  border-top: 1px solid var(--tinte);
}

/* Fällt der Haken weg, verschwindet die Maklerzeile auch ohne JavaScript. */
.rechner-karte:has(#r-makler:not(:checked)) [data-nk-makler] { display: none; }

.r-ehrlich {
  margin-top: 24px;
  max-width: 62ch;
  font-size: var(--t-klein);
  line-height: 1.55;
  color: var(--sekundaer);
}

/* Warnhinweise im Ergebnis. Rot, nicht Gold — Gold ist auf Papier nur 2,8:1 und
   ist in diesem System ohnehin nie eine Bedeutungsfarbe (--fehler ist die für Fehler). */
.r-warnung {
  margin-top: 22px;
  max-width: 62ch;
  padding: 12px 14px;
  border-left: 3px solid var(--fehler);
  background: rgba(138, 29, 29, 0.05);
  font-size: var(--t-klein);
  line-height: 1.55;
  color: var(--fehler);
}
/* Der Ohne-JavaScript-Hinweis verschwindet, sobald der Rechner wirklich läuft. */
html.rechner-bereit .r-ohne-js { display: none; }

.r-weiter { margin-top: 20px; }
.r-weiter a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--tinte);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
}
/* Hover ändert die STÄRKE, nicht die Farbe. Der Link ist bereits Indigo, und der Akzent
   ist auf hellem Grund ebenfalls Indigo — ein Farbwechsel wäre kein Wechsel. */
.r-weiter a:hover { text-decoration-thickness: 3px; }

/* ---------- Mobile Ergebniszeile ---------- */

#r-sticky {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--tinte);
  color: var(--papier);
}
#r-sticky .r-sticky-label {
  font-size: var(--t-klein);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--flaeche2);
}
#r-sticky .r-sticky-wert {
  font-family: "Archivo", system-ui, sans-serif;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Mobil ---------- */

@media (max-width: 699px) {
  .rechner-karte {
    padding: 24px 20px;
    margin-bottom: 84px;   /* Platz, damit die Ergebniszeile nichts verdeckt */
  }
  .rechner-raster {
    grid-template-columns: 1fr;
    gap: 34px;
  }
  .r-feld-kopf {
    display: block;
  }
  .r-eingabe {
    display: flex;
    width: 100%;
    margin-top: 8px;
  }
  .r-zahl {
    /* volle Restbreite, ohne die Einheit aus der Karte zu drücken */
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    min-height: 56px;
  }
  .r-schalter { min-height: 56px; }

  /* Trefferfläche des Reglers auf die mobile Mindestgröße (52px) bringen.
     Bahn (4px) und Griff (28px) bleiben optisch gleich — nur der Finger
     bekommt mehr Platz; Chrome zentriert die Bahn in der Feldhöhe. */
  .r-regler { height: 52px; margin-top: 2px; }

  .r-ergebnis { padding: 24px 20px; }
  .r-details > summary { min-height: 56px; }
  .r-weiter a { min-height: 52px; }

  #r-sticky {
    display: flex;
    opacity: 0;
    visibility: hidden;         /* sonst bliebe die Zeile tastaturfokussierbar */
    pointer-events: none;
    transform: translateY(100%);
    /* visibility bewusst OHNE Transition: sonst bliebe die Zeile für die Dauer der
       Animation tastaturfokussierbar — und ohne gezeichnete Frames sogar dauerhaft. */
    transition: transform 0.22s ease, opacity 0.22s ease;
  }
  #r-sticky.ist-sichtbar {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }
}
