/* Grafiken zum Artikel Kostenerstattung (Magazin). Wird nur auf Seiten
   geladen, die die Grafiken einbinden. Ohne JavaScript und bei reduzierter
   Bewegung stehen alle Grafiken sofort im Endzustand. */
.ke-fig {
  /* Palette wie die Grafik Beitragsentwicklung (beitragsverlauf.css):
     Schwarz hebt hervor, Grau ordnet unter. */
  --ke-accent: #1A1F1D;
  --ke-base: #A3A3A3;
  --ke-soft: #D4D4D4;
  --ke-play: 3s; /* Laufzeit der Zeitleiste, das Skript liest denselben Wert */
  --ke-ease: cubic-bezier(.2, .7, .2, 1);
  container-type: inline-size;
  margin: 2.5rem 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  font-size: 14px;
  line-height: 1.5;
  color: var(--dark);
}

/* Die Textregeln von .art-body (p, ul, ol, li) gelten in den Grafiken nicht.
   Die Klassenregeln weiter unten haben dieselbe Spezifität und stehen später. */
.art-body .ke-fig :where(p, ul, ol, li) {
  margin: 0;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}

.ke-fig .ke-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}
.ke-fig .ke-title {
  font-weight: 700;
  font-size: 17px;
  line-height: 1.35;
  color: var(--black);
}
.ke-fig .ke-sub,
.ke-fig .ke-note {
  font-size: 13px;
  color: var(--dark-grey);
}
.ke-fig .ke-note { margin-top: 14px; }

/* ── Legende ── */
.ke-fig .ke-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 12px;
  list-style: none;
  font-size: 13px;
  color: var(--dark-grey);
}
.ke-fig .ke-legend li { display: flex; align-items: center; gap: 6px; }
.ke-fig .ke-legend li::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--ke-swatch, var(--ke-base));
  box-shadow: inset 0 0 0 var(--ke-swatch-ring, 0) var(--ke-accent);
}
.ke-fig .ke-legend strong { color: var(--black); font-weight: 600; }
.ke-key--kasse  { --ke-swatch: var(--ke-base); }
.ke-key--zusatz { --ke-swatch: var(--ke-soft); }
.ke-key--own    { --ke-swatch: var(--ke-accent); }
.ke-key--switch { --ke-swatch: var(--white); --ke-swatch-ring: 2px; }

/* ══ 1. Die Lücke ══ */
.ke-fig .ke-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.ke-fig .ke-switch[hidden] { display: none; }
.ke-switch-btn {
  font: 600 13px/1 var(--sans);
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--white);
  color: var(--dark-grey);
  cursor: pointer;
}
.ke-switch-btn[aria-pressed="true"] {
  background: var(--ke-accent);
  border-color: var(--ke-accent);
  color: var(--white);
}
.ke-switch-btn:focus-visible {
  outline: 2px solid var(--ke-accent);
  outline-offset: 2px;
}
.ke-bar {
  display: flex;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}
.ke-seg {
  height: 100%;
  transition: width 900ms var(--ke-ease);
}
.ke-seg--kasse  { background: var(--ke-base); }
.ke-seg--zusatz { background: var(--ke-soft); }
.ke-seg--own    { background: var(--ke-accent); }
.ke-fig .ke-bar-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--dark-grey);
}
.ke-fig .ke-readout {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 16px;
}
.ke-readout-label { color: var(--dark-grey); }
.ke-readout-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ke-accent);
  font-variant-numeric: tabular-nums;
}

/* ══ 2. Der Weg einer Rechnung ══ */
.ke-fig .ke-flow {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  list-style: none;
  line-height: 1.4;
  counter-reset: ke-step;
}
.ke-fig .ke-step {
  position: relative;
  padding: 14px 12px;
  border-radius: 10px;
  background: var(--off-white);
  counter-increment: ke-step;
  transition: opacity 500ms var(--ke-ease), transform 500ms var(--ke-ease);
  transition-delay: calc(var(--i, 0) * 280ms);
}
.ke-step::before {
  content: counter(ke-step);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--ke-accent);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
}
.ke-step strong { display: block; margin-bottom: 2px; }
.ke-fig .ke-step--own { background: var(--ke-accent); color: var(--white); }
.ke-step--own::before { background: var(--white); color: var(--ke-accent); }
.ke-step-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ke-accent);
}

/* ══ 3. Die Reihenfolge ══ */
.ke-lane + .ke-lane { margin-top: 22px; }
.ke-fig .ke-lane-title {
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--black);
}
.ke-track {
  position: relative;
  height: 34px;
  margin: 0 8px;
}
.ke-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 16px;
  height: 2px;
  background: var(--border);
}
.ke-band {
  position: absolute;
  top: 12px;
  height: 10px;
  left: calc(var(--from) * 100%);
  width: calc((var(--to) - var(--from)) * 100%);
  border-radius: 5px;
  background: repeating-linear-gradient(135deg, var(--border) 0 6px, var(--light-grey) 6px 12px);
  border: 1px solid var(--border);
}
.ke-mark {
  position: absolute;
  top: 9px;
  left: calc(var(--at) * 100%);
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--ke-accent);
  border: 2px solid var(--white);
  box-shadow: 0 0 0 1px var(--ke-accent);
  transition: opacity 300ms ease, transform 300ms var(--ke-ease);
  transition-delay: calc(var(--at) * var(--ke-play));
}
.ke-mark--own { background: var(--ke-accent); box-shadow: 0 0 0 1px var(--ke-accent); }
.ke-mark--ok  { background: var(--ke-base); box-shadow: 0 0 0 1px var(--ke-base); }
/* Umstellung bei der Kasse: Ring statt Punkt */
.ke-mark--switch { background: var(--white); box-shadow: 0 0 0 2px var(--ke-accent); }
.ke-head-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: 2px;
  background: var(--black);
  opacity: 0;
  transform: translateX(-1px);
  transition: left var(--ke-play) linear;
}
.ke-fig .ke-months {
  display: flex;
  justify-content: space-between;
  margin: 2px 8px 0;
  font-size: 12px;
  color: var(--dark-grey);
}
.ke-fig .ke-steps {
  margin-top: 10px;
  padding-left: 20px;
}
.ke-fig .ke-steps li + li { margin-top: 2px; }
.ke-own-text { color: var(--black); font-weight: 700; }

/* ══ 4. Die schmalere Tür ══ */
.ke-cols {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 240px;
  padding: 0 4px;
  border-bottom: 1px solid var(--border);
}
.ke-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.ke-col-value {
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  color: var(--black);
  font-variant-numeric: tabular-nums;
  transition: opacity 400ms ease;
  transition-delay: calc(var(--i, 0) * 250ms + 700ms);
}
/* Betrag der Sonderanhebung über der Säule, weil das rote Teilstück schmal ist */
.ke-col-extra {
  display: block;
  font-size: 12px;
  color: var(--ke-accent);
}
.ke-col-stack {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: calc(var(--h) * 100%);
  transform-origin: bottom;
  transition: transform 800ms var(--ke-ease);
  transition-delay: calc(var(--i, 0) * 250ms);
}
.ke-col-part { width: 100%; }
.ke-col-part--base { flex: var(--base) 0 0; background: var(--ke-base); border-radius: 0 0 2px 2px; }
.ke-col-part--extra { flex: var(--extra) 0 0; background: var(--ke-accent); border-radius: 4px 4px 0 0; }
.ke-col-part--base:only-child { border-radius: 4px 4px 2px 2px; }
.ke-col--gap {
  flex: 1.3;
  justify-content: center;
  align-items: center;
  padding: 0 4px 24px;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  color: var(--dark-grey);
}
.ke-col--gap strong { display: block; color: var(--black); }
.ke-years {
  display: flex;
  gap: 14px;
  padding: 6px 4px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--dark-grey);
}
.ke-years span { flex: 1; text-align: center; }
.ke-years .ke-years-gap { flex: 1.3; }

/* ── Animation: nur wenn das Skript die Grafik scharf geschaltet hat ── */
.ke-armed .ke-seg { width: 0 !important; }
.ke-armed .ke-step { opacity: 0; transform: translateY(10px); }
.ke-armed .ke-mark { opacity: 0; transform: scale(.4); }
.ke-armed .ke-head-line { left: 0; }
.ke-armed .ke-col-stack { transform: scaleY(0); }
.ke-armed .ke-col-value { opacity: 0; }
.ke-playing .ke-head-line { opacity: 1; }

/* ── Schmale Grafik: richtet sich nach der Breite der Grafik selbst,
   nicht nach dem Fenster, weil die Artikelspalte auf dem Tablet schmal ist ── */
@container (max-width: 680px) {
  .ke-fig .ke-flow { grid-template-columns: 1fr; gap: 8px; }
  .ke-fig .ke-step { display: grid; grid-template-columns: 26px 1fr; column-gap: 12px; align-items: start; }
  .ke-step::before { grid-row: span 3; margin-bottom: 0; }
}
@container (max-width: 520px) {
  .ke-cols, .ke-years { gap: 8px; }
  .ke-cols { height: 200px; }
  .ke-col-value { font-size: 11px; }
  .ke-col-extra { font-size: 10px; }
  .ke-col--gap { font-size: 10px; padding-bottom: 16px; }
  .ke-readout-value { font-size: 24px; }
}
@media (max-width: 760px) {
  .ke-fig { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .ke-seg, .ke-step, .ke-mark, .ke-head-line, .ke-col-stack, .ke-col-value {
    transition: none !important;
  }
}

/* Hervorgehobener Schritt ist dunkel hinterlegt, das Etikett braucht dort helle Schrift */
.ke-step--own .ke-step-tag {
  padding: 2px 6px;
  border: 1px solid var(--white);
  border-radius: 4px;
  color: var(--white);
}
.ke-fig .ke-step--own strong { color: var(--white); }
