/* ============================================================
   CALCULATOR PAGES  (shared by every tool under /calculators/)
   Currently used by: compound-interest.html (Zinseszinsrechner)
============================================================ */

/* ============================================================
   LAYOUT  — input card (form + results) and chart card
============================================================ */
.calc-card {
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.calc-card + .calc-card { margin-top: 1.5rem; }
.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 340px) 1fr;
  gap: 2rem;
  align-items: start;
}
@media (max-width: 880px) {
  .calc-layout { grid-template-columns: 1fr; gap: 1.75rem; }
}
@media (max-width: 560px) {
  .calc-card { padding: 1.5rem 1.25rem; }
}

/* ============================================================
   FORM
============================================================ */
.calc-form { display: flex; flex-direction: column; gap: 1.1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field__label {
  font-family: "Sora", sans-serif;
  font-size: .8rem; font-weight: 600; color: var(--clr-text);
}
.field__hint { font-size: .72rem; color: var(--clr-muted); line-height: 1.4; }

/* text / number inputs with a trailing unit (€, %, Jahre) */
.field__control { position: relative; display: flex; align-items: center; }
.field__control input,
.field__control select {
  width: 100%;
  font-family: "Nunito Sans", sans-serif;
  font-size: .95rem; font-weight: 600; color: var(--clr-text);
  background: var(--clr-card);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .7rem .85rem;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.field__control input { padding-right: 2.6rem; }
.field__control input:focus,
.field__control select:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-light);
}
.field__unit {
  position: absolute; right: .9rem;
  font-size: .85rem; font-weight: 700; color: var(--clr-muted);
  pointer-events: none;
}
/* select: custom chevron */
.field__control--select::after {
  content: ""; position: absolute; right: 1rem; pointer-events: none;
  width: 9px; height: 9px;
  border-right: 2px solid var(--clr-muted);
  border-bottom: 2px solid var(--clr-muted);
  transform: rotate(45deg) translateY(-2px);
}
.field__control--select select { padding-right: 2.4rem; cursor: pointer; }

/* hide native number spinners (we parse German input ourselves) */
.field__control input[type="number"]::-webkit-outer-spin-button,
.field__control input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field__control input[type="number"] { -moz-appearance: textfield; }

/* segmented control — Ausschüttungsintervall */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--clr-bg);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 3px; gap: 3px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-family: "Sora", sans-serif; font-size: .82rem; font-weight: 600;
  color: var(--clr-muted);
  padding: .5rem .4rem; border-radius: 6px;
  cursor: pointer; transition: all .15s; user-select: none;
}
.seg input:checked + label {
  background: var(--clr-card);
  color: var(--clr-primary-dark);
  box-shadow: var(--shadow-sm);
}
.seg input:focus-visible + label { box-shadow: 0 0 0 3px var(--clr-primary-light); }

/* 3-option variant (Inflationsrechner-Modusumschalter) — die Labels
   sind länger als bei der 2er-Variante, deshalb hier ein knapperes
   Layout und auf schmalen Schirmen vertikales Stapeln, damit nichts
   abgeschnitten wird. */
.seg--3 label { font-size: .78rem; padding: .5rem .3rem; line-height: 1.25; }
@media (max-width: 560px) {
  .seg--3 { grid-auto-flow: row; grid-template-columns: 1fr; }
}

/* hide [hidden] elements even though .field sets a display value
   (the UA rule [hidden]{display:none} is otherwise overridden) */
.field[hidden] { display: none; }

/* out-of-range warning */
.field__warn { font-size: .72rem; font-weight: 600; color: #c0392b; line-height: 1.4; }
.field__control input.is-error,
input.is-error {
  border-color: #c0392b;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, .12);
}

/* ----- custom select (Kapitalertragssteuer with country flags) -----
   A native <select> can't render images, so this is a button + listbox. */
.ci-select { position: relative; }
.ci-select__button {
  width: 100%;
  display: flex; align-items: center; gap: .5rem;
  min-height: 2.85rem;
  font-family: "Nunito Sans", sans-serif;
  font-size: .92rem; font-weight: 600; color: var(--clr-text);
  background: var(--clr-card);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .55rem 2.4rem .55rem .85rem;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.ci-select__button:focus-visible {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-light);
}
.ci-select__button::after {
  content: ""; position: absolute; right: 1rem; top: 50%;
  width: 9px; height: 9px;
  border-right: 2px solid var(--clr-muted);
  border-bottom: 2px solid var(--clr-muted);
  transform: translateY(-65%) rotate(45deg);
  transition: transform .15s;
}
.ci-select__button[aria-expanded="true"]::after { transform: translateY(-35%) rotate(225deg); }
.ci-select__current { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.ci-select__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ci-select__list {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
  list-style: none; margin: 0; padding: .3rem;
  background: var(--clr-card);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 17rem; overflow-y: auto;
}
.ci-select__option {
  display: flex; align-items: center; gap: .55rem;
  padding: .5rem .6rem; border-radius: var(--radius-xs);
  font-size: .88rem; font-weight: 600; color: var(--clr-text);
  cursor: pointer;
}
.ci-select__option:hover,
.ci-select__option:focus { background: var(--clr-primary-tint); outline: none; }
.ci-select__option[aria-selected="true"] { background: var(--clr-primary-light); }
.ci-flag {
  width: 1.2em; height: 1.2em; flex-shrink: 0;
  border-radius: 2px; object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .06);
}

/* ============================================================
   RESULTS
============================================================ */
.calc-output { display: flex; flex-direction: column; gap: 1.25rem; }
.result-hero {
  background: linear-gradient(140deg, var(--clr-primary-deep), #115c44);
  border-radius: var(--radius);
  padding: 1.6rem 1.75rem; color: #fff;
  position: relative; overflow: hidden;
}
.result-hero::after {
  content: ""; position: absolute; bottom: -50px; right: -40px;
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(94,228,180,.22) 0%, transparent 70%);
  pointer-events: none;
}
.result-hero__label {
  font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(255,255,255,.6);
}
.result-hero__value {
  font-family: "Sora", sans-serif; font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 800; line-height: 1.1; margin: .3rem 0 .25rem; color: #fff;
}
.result-hero__sub { font-size: .85rem; color: rgba(255,255,255,.7); position: relative; z-index: 1; }
.result-hero__sub strong { color: #5ee4b4; font-weight: 700; }

.result-list { list-style: none; display: flex; flex-direction: column; }
.result-list li {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; padding: .7rem 0;
  border-bottom: 1px solid var(--clr-border);
  font-size: .9rem;
}
.result-list li:last-child { border-bottom: none; }
/* min-width:0 lets a long label wrap and give up space instead of
   pushing the (no-wrap) value past the card edge on narrow or
   large-font phones */
.result-list__key { color: var(--clr-muted); font-weight: 600; min-width: 0; }
.result-list__val { font-family: "Sora", sans-serif; font-weight: 700; color: var(--clr-text); white-space: nowrap; }
.result-list__sub { display: block; font-size: .72rem; color: var(--clr-muted); font-weight: 500; margin-top: .3rem; }
.result-list__val--pos { color: var(--clr-primary-dark); }
.result-list__val--neg { color: #c0392b; }
.result-list li.is-sum {
  border-top: 1px solid var(--clr-border); border-bottom: none;
  margin-top: .15rem;
}
.result-list li.is-total {
  margin-top: .3rem; padding-top: .9rem;
  border-top: 2px solid var(--clr-primary-light); border-bottom: none;
}
.result-list li.is-total .result-list__key { color: var(--clr-text); font-weight: 700; }
.result-list li.is-total .result-list__val { font-size: 1.15rem; color: var(--clr-primary-dark); }

/* ============================================================
   CHART
============================================================ */
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem;
}
.chart-head h3 {
  font-family: "Sora", sans-serif; font-size: 1rem; font-weight: 700; color: var(--clr-text);
}
.chart-legend { display: flex; flex-wrap: wrap; gap: 1rem; }
.chart-legend__item {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 600; color: var(--clr-muted);
}
.chart-legend__swatch { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.chart-legend__swatch--dep   { background: var(--clr-primary); }
.chart-legend__swatch--gain  { background: var(--clr-accent); }
.chart-legend__swatch--total { width: 18px; height: 0; border-radius: 0; border-top: 3px solid var(--clr-primary-deep); }

.chart-wrap { position: relative; }
.ci-svg {
  display: block; width: 100%; height: auto;
  font-family: "Nunito Sans", sans-serif;
  overflow: visible;
  /* horizontal finger drags scrub the chart; vertical still scrolls the
     page — stops the tooltip drag from janking the page sideways */
  touch-action: pan-y;
}

/* areas */
.ci-area-dep  { fill: rgba(22,165,124,.16); stroke: none; }
.ci-area-gain { fill: rgba(255,107,53,.15); stroke: none; }
/* lines */
.ci-line-dep   { fill: none; stroke: var(--clr-primary); stroke-width: 2; stroke-linejoin: round; }
.ci-line-total { fill: none; stroke: var(--clr-primary-deep); stroke-width: 2.5; stroke-linejoin: round; }
/* axes + grid */
.ci-grid { stroke: var(--clr-border); stroke-width: 1; }
.ci-axis-line { stroke: var(--clr-muted); stroke-width: 1.25; }
/* axis font-size is set on the <svg> per render (user units, see
   chartGeom) so on-screen text stays ~constant across widths */
.ci-axis-y { fill: var(--clr-muted); text-anchor: end; }
.ci-axis-x { fill: var(--clr-muted); text-anchor: middle; }
.ci-axis-x--unit { font-weight: 700; }
.ci-axis-title { fill: var(--clr-muted); font-weight: 700; }
/* hover guide + markers */
.ci-guide { stroke: var(--clr-primary-dark); stroke-width: 1; stroke-dasharray: 4 4; transition: opacity .12s; }
.ci-dot { stroke: #fff; stroke-width: 2; transition: opacity .12s; }
.ci-dot--total { fill: var(--clr-primary-deep); }
.ci-dot--dep   { fill: var(--clr-primary); }

/* tooltip */
.ci-tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  /* left is the tooltip CENTRE (JS clamps it); translate keeps the box
     within the chart so it never spills past the frame on touch */
  transform: translateX(-50%);
  background: #1c1c2e; color: #fff;
  border-radius: var(--radius-sm); padding: .55rem .7rem;
  font-size: .74rem; line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  min-width: 150px; max-width: calc(100% - 8px);
}
.ci-tooltip__yr { font-weight: 700; margin-bottom: .25rem; font-family: "Sora", sans-serif; }
.ci-tooltip__row { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.ci-tooltip__row b { margin-left: auto; font-weight: 700; }
.ci-sw { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.ci-sw--total { background: #5ee4b4; }
.ci-sw--dep   { background: var(--clr-primary); }
.ci-sw--gain  { background: var(--clr-accent); }

/* ============================================================
   INFO / ASSUMPTIONS NOTE
============================================================ */
.calc-note {
  margin-top: 1.5rem;
  background: var(--clr-primary-tint);
  border: 1px solid var(--clr-primary-light);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-size: .82rem; color: var(--clr-primary-deep); line-height: 1.6;
}
.calc-note strong { font-weight: 700; }
.calc-note ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.calc-note li { margin-bottom: .2rem; }

.calc-disclaimer {
  margin-top: 1rem;
  background: var(--clr-accent-light);
  border: 1px solid rgba(229, 87, 31, .22);
  border-left: 3px solid var(--clr-accent);
  border-radius: var(--radius-sm);
  padding: .8rem 1.25rem;
  font-size: .8rem; color: var(--clr-disclaimer-text); line-height: 1.55;
}
.calc-disclaimer strong { font-weight: 700; }

/* ============================================================
   DARK MODE  – chart + note colours (palette flips in base.css)
   ------------------------------------------------------------
   --clr-primary-deep stays a dark brand green (it backs the hero
   etc.), so the chart's "total" foreground is lifted to the mint
   accent and the note/error text to readable light tones.
============================================================ */
:root[data-theme="dark"] .calc-note                   { color:#cdeadf; }
:root[data-theme="dark"] .ci-line-total               { stroke:#5ee4b4; }
:root[data-theme="dark"] .ci-dot--total               { fill:#5ee4b4; }
:root[data-theme="dark"] .chart-legend__swatch--total { border-top-color:#5ee4b4; }
:root[data-theme="dark"] .field__warn,
:root[data-theme="dark"] .result-list__val--neg       { color:#ff9d9d; }
:root[data-theme="dark"] .field__control input.is-error,
:root[data-theme="dark"] input.is-error {
  border-color:#ff7676; box-shadow:0 0 0 3px rgba(255,118,118,.18);
}
