/* =====================================================================
   FAI-Tagebuch (content/fai): Zeitleiste, OP-Vergleich, Vorher-Nachher-
   Regler und Ausbau des Seitenstils "medizin".
   Einbinden in layout.php nach site.css:
     <link rel="stylesheet" href="<?= View::asset('fai.css') ?>">
   Teil 1-3: nur Selektoren mit .fai-  (wirkt nirgends sonst)
   Teil 4:   article.page.style-medizin (Front Matter "style: medizin",
             derzeit nur im FAI-Bereich verwendet)
   Farben nur über vorhandene Variablen: --fg --muted --accent --line
   --card (dazu --med aus dem Medizin-Stil, --err/--ok als Signalfarben).
   ===================================================================== */

/* ---------- gemeinsame Farbrollen ---------- */
.fai-ops, .fai-legend, .fai-vergleich, .fai-compare {
  --fai-med: var(--med, var(--accent));
  --fai-alert: var(--err, var(--accent));
  --fai-ok: var(--ok, var(--accent));
}
/* Punktfarbe je Eintragsart (Zeitleiste und Legende) */
.fai-step, .fai-key { --fai-dot: var(--muted); }
.fai-step--vorbereitung, .fai-key--vorbereitung { --fai-dot: var(--muted); }
.fai-step--op,           .fai-key--op           { --fai-dot: var(--fai-med); }
.fai-step--klinik,       .fai-key--klinik       { --fai-dot: var(--fai-med); }
.fai-step--zuhause,      .fai-key--zuhause      { --fai-dot: var(--accent); }
.fai-step--meilenstein,  .fai-key--meilenstein  { --fai-dot: var(--fai-ok); }
.fai-step--kontrolle,    .fai-key--kontrolle    { --fai-dot: var(--fai-med); }
.fai-step--resuemee,     .fai-key--resuemee     { --fai-dot: var(--muted); }
.fai-step--komplikation, .fai-key--komplikation { --fai-dot: var(--fai-alert); } /* zuletzt: gewinnt bei "OP + Komplikation" */

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

/* ---------- 1. Legende ---------- */
.fai-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin: 0.4rem 0 1rem; font-size: 0.8rem; color: var(--muted); }
.fai-key { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.fai-key::before { content: ''; flex: none; width: 0.72rem; height: 0.72rem; box-sizing: border-box; border-radius: 50%;
  border: 2px solid var(--fai-dot); background: var(--card); }
.fai-key--op::before, .fai-key--komplikation::before, .fai-key--meilenstein::before,
.fai-key--kontrolle::before, .fai-key--resuemee::before { background: var(--fai-dot); }
.fai-key--kontrolle::before { border-radius: 2px; transform: rotate(45deg) scale(0.85); }
.fai-key--resuemee::before { transform: scale(0.75); }

/* ---------- 2. Zeitleiste ---------- */
.fai-ops { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.2rem; margin: 0.6rem 0 0.4rem; }
@media (min-width: 780px) { .fai-ops { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.fai-op { position: relative; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 0.95rem 1rem 0.35rem; box-shadow: 0 1px 0 color-mix(in srgb, var(--fg) 4%, transparent); }
.fai-op::before { /* farbiger Kopfstreifen wie auf einer Patientenkurve */
  content: ''; position: absolute; left: -1px; right: -1px; top: -1px; height: 4px; border-radius: 12px 12px 0 0; background: var(--fai-med); }
.fai-op--2017::before { background: repeating-linear-gradient(90deg, var(--fai-med) 0 14px, color-mix(in srgb, var(--fai-med) 45%, var(--card)) 14px 20px); }

.fai-op-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.1rem 0.8rem;
  margin: 0 0 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--line); }
.fai-op .fai-op-title { margin: 0; padding: 0; border: 0; font-size: 1.05rem; line-height: 1.3; color: var(--fg); }
.fai-op .fai-op-title::before { content: none; }
.fai-op .fai-op-meta { margin: 0; font-size: 0.8rem; color: var(--muted); }

.fai-ops .fai-timeline { list-style: none; position: relative; margin: 0; padding: 0 0 0 1.75rem; }
.fai-ops .fai-timeline::before { /* die senkrechte Linie */
  content: ''; position: absolute; left: 0.6rem; top: 0.45rem; bottom: 1.1rem; width: 2px; border-radius: 2px;
  background: var(--line); }
.fai-ops .fai-step { position: relative; margin: 0; padding: 0 0 0.95rem 0.3rem; }
.fai-ops .fai-step::before { /* der Punkt */
  content: ''; position: absolute; left: calc(-1.75rem + 0.6rem + 1px); top: 0.3rem; width: 0.85rem; height: 0.85rem;
  box-sizing: border-box; transform: translateX(-50%); border-radius: 50%;
  border: 2px solid var(--fai-dot); background: var(--card);
  box-shadow: 0 0 0 3px var(--card); transition: box-shadow 0.15s ease; }
.fai-ops .fai-step--meilenstein::before, .fai-ops .fai-step--komplikation::before,
.fai-ops .fai-step--resuemee::before, .fai-ops .fai-step--kontrolle::before { background: var(--fai-dot); }
.fai-ops .fai-step--resuemee::before { width: 0.65rem; height: 0.65rem; top: 0.4rem; }
.fai-ops .fai-step--kontrolle::before { border-radius: 2px; transform: translateX(-50%) rotate(45deg); }
/* OP-Tag: größerer, gefüllter Punkt mit Kreuz */
.fai-ops .fai-step--op::before { width: 1.15rem; height: 1.15rem; top: 0.15rem; background: var(--fai-dot); }
.fai-ops .fai-step--op::after { content: '+'; position: absolute; left: calc(-1.75rem + 0.6rem + 1px); top: 0.15rem; width: 1.15rem;
  transform: translateX(-50%); text-align: center; font: 700 0.95rem/1.15rem system-ui, sans-serif; color: var(--card); pointer-events: none; }
.fai-ops .fai-step:hover::before, .fai-ops .fai-step:focus-within::before {
  box-shadow: 0 0 0 3px var(--card), 0 0 0 6px color-mix(in srgb, var(--fai-dot) 25%, transparent); }

.fai-ops .fai-when { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.5rem; font-size: 0.76rem; line-height: 1.5; color: var(--muted); }
.fai-ops .fai-date { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.fai-ops .fai-day { font-weight: 600; color: var(--fai-dot); padding: 0 0.45rem; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--fai-dot) 40%, transparent); background: color-mix(in srgb, var(--fai-dot) 9%, transparent); }
.fai-ops .fai-step--op .fai-day { color: var(--card); background: var(--fai-dot); border-color: var(--fai-dot); }

/* Titel ist der Link; die ganze Zeile ist anklickbar */
.fai-ops .fai-timeline a.fai-step-title { display: inline-block; margin-top: 0.1rem; font-weight: 650; line-height: 1.35;
  color: var(--fg); text-decoration: none; border-bottom: 0; }
.fai-ops .fai-timeline a.fai-step-title::after { content: ''; position: absolute; inset: 0; border-radius: 8px; }
.fai-ops .fai-timeline a.fai-step-title:hover { color: var(--fai-med); text-decoration: underline; text-underline-offset: 3px; }
.fai-ops .fai-timeline a.fai-step-title:focus-visible { outline: none; }
.fai-ops .fai-timeline a.fai-step-title:focus-visible::after { outline: 2px solid var(--fai-med); outline-offset: 2px; }
.fai-ops .fai-step--komplikation a.fai-step-title:hover { color: var(--fai-alert); }
.fai-ops .fai-step-text { margin: 0.12rem 0 0; font-size: 0.86rem; line-height: 1.45; color: var(--muted); }
.fai-ops .fai-step-more { position: relative; z-index: 1; margin: 0.25rem 0 0; font-size: 0.78rem; color: var(--muted); }
.fai-ops .fai-step-more a { color: var(--fai-med); }

/* ---------- 2b. Vergleichstabelle der beiden OPs ---------- */
.fai-vergleich { font-size: 0.9rem; margin: 0.6rem 0 0.4rem; }
.fai-vergleich .fai-vergleich-caption { caption-side: top; text-align: left; font-size: 0.78rem; color: var(--muted); padding: 0 0 0.35rem; }
.fai-vergleich thead th { color: var(--fg); }
.fai-vergleich thead .fai-col-2016, .fai-vergleich thead .fai-col-2017 { color: var(--fai-med); }
.fai-vergleich tbody th { width: 30%; text-transform: none; letter-spacing: 0; font-size: 0.84rem; font-weight: 600;
  color: var(--muted); background: transparent; }
.fai-vergleich tbody tr:nth-child(even) td, .fai-vergleich tbody tr:nth-child(even) th { background: color-mix(in srgb, var(--fg) 3%, transparent); }
.fai-vergleich td, .fai-vergleich th { font-variant-numeric: tabular-nums; }
.fai-vergleich tbody tr > :last-child, .fai-vergleich thead tr > :last-child { border-left: 1px dashed var(--line); }
.fai-vergleich .fai-cell-alert { box-shadow: inset 3px 0 0 var(--fai-alert); background: color-mix(in srgb, var(--fai-alert) 7%, transparent); }
@media (max-width: 520px) {
  .fai-vergleich { font-size: 0.82rem; }
  .fai-vergleich th, .fai-vergleich td { padding: 0.4rem 0.45rem; }
  .fai-vergleich tbody th { width: 34%; font-size: 0.76rem; }
}

/* ---------- 3. Vorher-Nachher-Regler (Aufbau durch fai.js) ---------- */
/* ohne JavaScript: beide Bilder nebeneinander */
.fai-compare { margin: 1.2rem 0; }
.fai-compare:not(.fai-compare--ready) { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 0.6rem; }
.fai-compare:not(.fai-compare--ready) > figcaption { grid-column: 1 / -1; }
/* Spezifität höher als "article.page.style-medizin img" aus site.css */
figure.fai-compare:not(.fai-compare--ready) > img { display: block; width: 100%; height: auto; margin: 0; box-shadow: none; }
.fai-compare > figcaption { margin-top: 0.45rem; font-size: 0.82rem; color: var(--muted); }

.fai-compare-stage { position: relative; overflow: hidden; margin: 0 auto; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: ew-resize; line-height: 0; }
.fai-compare .fai-compare-stage img.fai-compare-img { display: block; width: 100%; height: auto; max-height: none; margin: 0; padding: 0;
  border: 0; border-radius: 0; box-shadow: none; pointer-events: none; -webkit-user-drag: none; }
.fai-compare .fai-compare-stage img.fai-compare-before { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--card); will-change: clip-path; }
.fai-compare-line { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--card);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--fg) 25%, transparent); pointer-events: none; }
.fai-compare .fai-compare-handle { position: absolute; top: 50%; width: 2.5rem; height: 2.5rem; margin: -1.25rem 0 0 -1.25rem; padding: 0;
  display: flex; align-items: center; justify-content: center; gap: 0.15rem;
  border-radius: 50%; border: 2px solid var(--fai-med); background: var(--card); color: var(--fai-med);
  font: 700 0.85rem/1 system-ui, sans-serif; cursor: ew-resize; box-shadow: 0 2px 10px -2px color-mix(in srgb, var(--fg) 45%, transparent); }
.fai-compare .fai-compare-handle:hover { filter: none; background: var(--card); }
.fai-compare .fai-compare-handle:focus-visible { outline: 3px solid color-mix(in srgb, var(--fai-med) 45%, transparent); outline-offset: 2px; }
.fai-compare .fai-compare-handle::before { content: '\2039'; } /* ‹ */
.fai-compare .fai-compare-handle::after { content: '\203A'; }  /* › */
.fai-compare-label { position: absolute; top: 0.6rem; padding: 0.15rem 0.55rem; border-radius: 999px; font: 600 0.72rem/1.5 system-ui, sans-serif;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg); background: color-mix(in srgb, var(--card) 82%, transparent);
  border: 1px solid var(--line); pointer-events: none; transition: opacity 0.15s ease; }
.fai-compare-label--before { left: 0.6rem; }
.fai-compare-label--after { right: 0.6rem; }
.fai-compare-label.fai-hidden { opacity: 0; }
.fai-compare--dragging .fai-compare-stage { cursor: grabbing; }

/* ---------- 4. Ausbau Seitenstil "medizin" ---------- */
/* bessere Lesbarkeit der Akzentfarbe auf dunklem/blauem Hintergrund */
html[data-bg="dark"] article.page.style-medizin, html[data-bg="blue"] article.page.style-medizin { --med: #4fb6c2; }

/* Datums-/Schlagwort-Zeile unter dem Titel als "Krankenblatt-Kopf" */
article.page.style-medizin h1 + p:has(> em:only-child) { display: inline-block; margin: -0.2rem 0 1rem; padding: 0.15rem 0.7rem;
  font-size: 0.8rem; line-height: 1.6; color: var(--muted); border: 1px solid var(--line); border-left: 3px solid var(--med, var(--accent));
  border-radius: 6px; background: color-mix(in srgb, var(--med, var(--accent)) 6%, var(--card)); }
article.page.style-medizin h1 + p:has(> em:only-child) em { font-style: normal; font-variant-numeric: tabular-nums; }

/* Fotos: ruhiger Rahmen, zentriert, nicht höher als der Bildschirm */
article.page.style-medizin p > img, article.page.style-medizin p > a > img {
  display: block; margin: 0.6rem auto; max-height: 78vh; width: auto; max-width: 100%; object-fit: contain;
  padding: 0.35rem; background: var(--card); border: 1px solid var(--line); }
article.page.style-medizin p:has(> img:only-child), article.page.style-medizin p:has(> a:only-child > img) { text-align: center; margin: 0.4rem 0; }
article.page.style-medizin a.ext:has(> img)::after { content: none; } /* kein ↗ unter Bildern */
article.page.style-medizin a:has(> img) { border-bottom: 0; text-decoration: none; }

/* Zitate (z. B. Wikipedia-Erklärung) als Infokasten */
article.page.style-medizin blockquote { color: var(--fg); border-left: 3px solid var(--med, var(--accent)); border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--med, var(--accent)) 6%, var(--card)); padding: 0.6rem 1rem; font-size: 0.95em; }
article.page.style-medizin blockquote p { margin: 0.3rem 0; }

/* Abschnittstrenner */
article.page.style-medizin hr { border: 0; height: 1px; margin: 1.8rem 0;
  background: linear-gradient(90deg, transparent, var(--line) 15%, var(--line) 85%, transparent); }

/* Kommentare unter den Beiträgen als Karten */
article.page.style-medizin h2#kommentare ~ p:not(:has(> em:only-child)) { margin: 0 0 0.55rem; padding: 0.5rem 0.8rem; font-size: 0.92rem; line-height: 1.55;
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid color-mix(in srgb, var(--med, var(--accent)) 55%, var(--line)); border-radius: 0 8px 8px 0; }
article.page.style-medizin h2#kommentare ~ p > strong:first-child { color: var(--fg); }

/* Herkunftsvermerk "Ursprünglich veröffentlicht auf Blogger" als Fußnote */
article.page.style-medizin p:has(> em:only-child > a[href*="blogspot."]) { margin-top: 2rem; padding-top: 0.6rem; font-size: 0.8rem;
  color: var(--muted); border-top: 1px dashed var(--line); }

/* Tagebuch-Liste: Zebrastreifen wie auf einer Pflegekurve */
article.page.style-medizin .children.as-list .card:nth-child(even) { background: color-mix(in srgb, var(--med, var(--accent)) 4%, var(--card)); }
article.page.style-medizin .children.as-list .card .desc { font-variant-numeric: tabular-nums; }

/* Druck: sauberes Krankenblatt ohne Schatten und Farbflächen */
@media print {
  article.page.style-medizin { border: 0; box-shadow: none; padding: 0; }
  article.page.style-medizin img { box-shadow: none; max-height: 12cm; break-inside: avoid; }
  .fai-ops { grid-template-columns: 1fr 1fr; }
  .fai-op, .fai-step { break-inside: avoid; }
  .fai-ops .fai-timeline a.fai-step-title::after { content: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fai-ops .fai-step::before, .fai-compare-label { transition: none; }
}
