/* ==========================================================================
   Bildansicht (Lightbox) – Homepage V2 (26.09.2026)
   Gegenstück zu /assets/js/bildansicht.js. Greift nur an Elementen, die das
   Skript selbst erzeugt (.ba, .ba-ausloeser) bzw. markiert (figure.ba-bereit).

   Farben: eigene --ba-*-Tokens je Design (klassisch / V2) und Modus (hell /
   dunkel). Der Schleier ist in BEIDEN Modi dunkel – deshalb stehen Fokusring
   und Bildunterschrift immer auf hellen Akzenten, auch im Hellmodus, wo die
   Seiten-Tokens --gold bewusst abgedunkelt sind (würden auf dem Schleier
   untergehen). Nur Leisten/Knöpfe folgen dem Modus (hell = weiße Flächen).
   ========================================================================== */

/* ---- 1. Tokens ------------------------------------------------------------ */
/* Klassisch, dunkel (Standard) */
.ba,
.ba-bereit {
  --ba-schleier: rgba(5, 9, 20, .95);
  --ba-knopf-bg: rgba(18, 24, 40, .94);
  --ba-knopf-bg-hover: #1c2438;
  --ba-knopf-text: #f5f7fb;
  --ba-knopf-linie: rgba(255, 255, 255, .16);
  --ba-knopf-linie-hover: rgba(245, 158, 11, .55);
  --ba-knopf-akzent: #fbbf24;
  --ba-text: #f5f7fb;
  --ba-text-2: #cfd6e4;
  --ba-text-3: #9aa3b5;
  --ba-akzent: #f59e0b;                 /* Fokusring, Ladekreisel – auf dunklem Schleier */
  --ba-rahmen-linie: rgba(255, 255, 255, .14);
  --ba-rahmen-bg: #0a1020;
  --ba-rahmen-schatten: 0 30px 80px -24px rgba(0, 0, 0, .8);
  --ba-plakette-bg: rgba(5, 9, 20, .82);
  --ba-plakette-text: #f5f7fb;
  --ba-plakette-linie: rgba(245, 158, 11, .5);
  --ba-plakette-icon: #fbbf24;
  --ba-plakette-schatten: 0 8px 22px -10px rgba(0, 0, 0, .6);
  --ba-radius: 14px;
  --ba-radius-klein: 10px;
  --ba-schrift: var(--sans, 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif);
  --ba-dauer: .18s;
}

/* Klassisch, hell */
html[data-theme="light"] .ba,
html[data-theme="light"] .ba-bereit {
  --ba-schleier: rgba(9, 13, 26, .93);
  --ba-knopf-bg: #ffffff;
  --ba-knopf-bg-hover: #f4f6fb;
  --ba-knopf-text: #0b1020;
  --ba-knopf-linie: rgba(11, 16, 32, .14);
  --ba-knopf-linie-hover: #d97f06;
  --ba-knopf-akzent: #b45309;
  --ba-rahmen-linie: rgba(255, 255, 255, .22);
  --ba-plakette-bg: rgba(255, 255, 255, .95);
  --ba-plakette-text: #0b1020;
  --ba-plakette-linie: rgba(11, 16, 32, .14);
  --ba-plakette-icon: #b45309;
  --ba-plakette-schatten: 0 8px 22px -10px rgba(11, 16, 32, .45);
}

/* V2, dunkel: Navy, Haarlinien, Champagnergold, Radius 10/8 */
html[data-design="v2"] .ba,
html[data-design="v2"] .ba-bereit {
  --ba-schleier: rgba(5, 9, 20, .96);
  --ba-knopf-bg: #121b2e;
  --ba-knopf-bg-hover: #18233a;
  --ba-knopf-text: #e8ecf3;
  --ba-knopf-linie: rgba(148, 163, 184, .24);
  --ba-knopf-linie-hover: rgba(207, 178, 122, .55);
  --ba-knopf-akzent: #dcc394;
  --ba-text: #e8ecf3;
  --ba-text-2: #b4bdcb;
  --ba-text-3: #8d98aa;
  --ba-akzent: #cfb27a;
  --ba-rahmen-linie: rgba(148, 163, 184, .24);
  --ba-rahmen-bg: #0a101c;
  --ba-rahmen-schatten: 0 24px 64px -28px rgba(0, 0, 0, .8);
  --ba-plakette-bg: rgba(13, 20, 36, .86);
  --ba-plakette-text: #e8ecf3;
  --ba-plakette-linie: rgba(207, 178, 122, .45);
  --ba-plakette-icon: #cfb27a;
  --ba-plakette-schatten: 0 1px 2px rgba(0, 0, 0, .3);
  --ba-radius: 10px;
  --ba-radius-klein: 8px;
}

/* V2, hell: Flächen weiß, Text Navy, Gold für Text abgedunkelt */
html[data-design="v2"][data-theme="light"] .ba,
html[data-design="v2"][data-theme="light"] .ba-bereit {
  --ba-schleier: rgba(10, 15, 28, .93);
  --ba-knopf-bg: #ffffff;
  --ba-knopf-bg-hover: #f2f4f7;
  --ba-knopf-text: #0d1424;
  --ba-knopf-linie: rgba(15, 23, 42, .14);
  --ba-knopf-linie-hover: rgba(122, 95, 43, .6);
  --ba-knopf-akzent: #7a5f2b;
  --ba-rahmen-linie: rgba(255, 255, 255, .2);
  --ba-plakette-bg: rgba(255, 255, 255, .95);
  --ba-plakette-text: #0d1424;
  --ba-plakette-linie: rgba(15, 23, 42, .14);
  --ba-plakette-icon: #7a5f2b;
  --ba-plakette-schatten: 0 1px 3px rgba(15, 23, 42, .18);
}

/* ---- 2. Auslöser auf der Seite ---------------------------------------------- */
figure.ba-bereit { cursor: zoom-in; }
figure.ba-pos { position: relative; }

.ba-ausloeser {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: zoom-in;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.ba-plakette {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 36px;
  padding: .45rem .8rem .45rem .65rem;
  border: 1px solid var(--ba-plakette-linie);
  border-radius: var(--ba-radius-klein);
  background: var(--ba-plakette-bg);
  color: var(--ba-plakette-text);
  font: 600 .8rem/1.1 var(--ba-schrift);
  letter-spacing: .01em;
  white-space: nowrap;
  box-shadow: var(--ba-plakette-schatten);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--ba-dauer) ease, transform var(--ba-dauer) ease;
}
.ba-plakette svg { display: block; width: 16px; height: 16px; flex: none; color: var(--ba-plakette-icon); }

.ba-ausloeser:hover .ba-plakette,
.ba-ausloeser:focus-visible .ba-plakette { opacity: 1; transform: none; }

/* Fokus: Ring innen (die figure schneidet mit overflow:hidden) plus Ring außen an der figure.
   Höhere Spezifität als die globalen :focus-visible-Regeln der Seiten (setzen border-radius). */
figure.ba-bereit > .ba-ausloeser:focus { outline: none; }
figure.ba-bereit > .ba-ausloeser:focus-visible {
  outline: 3px solid var(--ba-akzent);
  outline-offset: -3px;
  border-radius: inherit;
  box-shadow: inset 0 0 0 6px rgba(5, 9, 20, .55);
}
figure.ba-bereit:has(> .ba-ausloeser:focus-visible) {
  outline: 2px solid var(--ba-akzent);
  outline-offset: 3px;
}

/* Rahmen der figure beim Überfahren dezent betonen */
figure.ba-bereit:hover,
html[data-design="v2"] figure.ba-bereit.funktion-bild:hover { border-color: var(--ba-plakette-linie); }

/* Touchgeräte: kein Hover – Plakette dauerhaft, aber zurückhaltend */
@media (hover: none) {
  .ba-ausloeser { padding: 8px; }
  .ba-plakette {
    opacity: .9;
    transform: none;
    gap: .35rem;
    min-height: 28px;
    padding: .3rem .55rem .3rem .45rem;
    font-size: .72rem;
    font-weight: 500;
  }
  .ba-plakette svg { width: 14px; height: 14px; }
}
@media (max-width: 380px) {
  .ba-plakette span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .ba-plakette { padding: .4rem; }
}

/* ---- 3. Dialog ---------------------------------------------------------------- */
.ba[hidden] { display: none !important; }

.ba {
  position: fixed;
  inset: 0;
  z-index: 10050;                       /* über Kopfleiste, Mobilleiste (9000) und Cookie-Banner (10000/10001) */
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-sizing: border-box;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: var(--ba-schleier);
  color: var(--ba-text);
  font-family: var(--ba-schrift);
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: normal;
  text-align: left;
  cursor: default;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transition: opacity var(--ba-dauer) ease;
}
.ba *, .ba *::before, .ba *::after { box-sizing: border-box; }
.ba.ba--offen { opacity: 1; }
.ba.ba--schliesst { pointer-events: none; }
.ba:focus { outline: none; }

/* Kopf: Zoomleiste links, Schließen rechts */
.ba-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
}
.ba-leiste {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--ba-knopf-linie);
  border-radius: var(--ba-radius);
  background: var(--ba-knopf-bg);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .6);
}
.ba-stufe {
  min-width: 3.6em;
  padding: 0 .2rem;
  color: var(--ba-knopf-text);
  font: 600 .82rem/1 var(--ba-schrift);
  font-variant-numeric: tabular-nums;
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
}

.ba .ba-knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 .6rem;
  border: 1px solid transparent;
  border-radius: var(--ba-radius-klein);
  background: transparent;
  color: var(--ba-knopf-text);
  font: 600 .88rem/1 var(--ba-schrift);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color var(--ba-dauer) ease, border-color var(--ba-dauer) ease, color var(--ba-dauer) ease;
}
.ba .ba-knopf svg { display: block; width: 20px; height: 20px; flex: none; }
.ba .ba-knopf:hover { background: var(--ba-knopf-bg-hover); border-color: var(--ba-knopf-linie-hover); }
/* Nur das Symbol dimmen – opacity am Knopf würde auch den Fokusring verblassen lassen */
.ba .ba-knopf[aria-disabled="true"] { cursor: default; }
.ba .ba-knopf[aria-disabled="true"] svg { opacity: .38; }
.ba .ba-knopf[aria-disabled="true"]:hover { background: transparent; border-color: transparent; }

/* Schließen: eigene, deutlich abgesetzte Fläche oben rechts */
.ba .ba-schliessen {
  padding: 0 1rem 0 .8rem;
  border-color: var(--ba-knopf-linie);
  background: var(--ba-knopf-bg);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, .6);
}
.ba .ba-schliessen svg { width: 22px; height: 22px; }
.ba .ba-schliessen:hover { background: var(--ba-knopf-bg-hover); border-color: var(--ba-knopf-linie-hover); }

/* Fokusring: helles Gold auf dem (immer dunklen) Schleier, dazu goldene Kante am Knopf selbst.
   Spezifität über den globalen :focus-visible-Regeln der Seiten. */
.ba .ba-knopf:focus { outline: none; }
.ba .ba-knopf:focus-visible {
  outline: 2px solid var(--ba-akzent);
  outline-offset: 2px;
  border-radius: var(--ba-radius-klein);
  border-color: var(--ba-knopf-linie-hover);
  box-shadow: none;
}

/* Mitte: Bildrahmen + Unterschrift, gemeinsam zentriert */
.ba-mitte {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.ba-rahmen {
  position: relative;
  flex: none;
  overflow: hidden;
  border-radius: var(--ba-radius);
  background: var(--ba-rahmen-bg);
  box-shadow: 0 0 0 1px var(--ba-rahmen-linie), var(--ba-rahmen-schatten);
  cursor: zoom-in;
  touch-action: none;                   /* nur der Bildbereich – Gesten gehören hier dem Skript */
  -webkit-user-select: none;
  user-select: none;
  transform: scale(.985);
  transition: transform var(--ba-dauer) ease;
}
.ba--offen .ba-rahmen { transform: none; }
.ba-rahmen.ba-rahmen--zoom { cursor: grab; }
.ba-rahmen.ba-rahmen--zieht { cursor: grabbing; }

/* max-width:none ist Pflicht – die Seiten setzen img{max-width:100%}, das den Zoom kappen würde */
.ba .ba-bild {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  max-width: none;
  max-height: none;
  margin: 0;
  object-fit: contain;
  transform-origin: 0 0;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;                 /* Zeigerereignisse gehen an den Rahmen (Pointer-Capture) */
}
.ba .ba-bild.ba-bild--gleitend {
  transition: width .2s ease, height .2s ease, transform .2s ease;
}

/* Ladeanzeige: erscheint verzögert, damit sie bei schnellem Laden nicht aufblitzt */
.ba-laden {
  position: absolute;
  left: 50%;
  bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  max-width: calc(100% - 24px);
  padding: .5rem .9rem .5rem .6rem;
  border: 1px solid var(--ba-knopf-linie);
  border-radius: 999px;
  background: rgba(5, 9, 20, .82);
  color: #f5f7fb;
  font: 500 .82rem/1.2 var(--ba-schrift);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%);
  transition: opacity .2s ease .15s, visibility 0s linear .35s;
}
.ba--laedt .ba-laden { opacity: 1; visibility: visible; transition: opacity .2s ease .15s, visibility 0s; }
.ba-laden-text { overflow: hidden; text-overflow: ellipsis; }
.ba-kreisel {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid rgba(255, 255, 255, .22);
  border-top-color: var(--ba-akzent);
  border-radius: 50%;
  animation: ba-drehen .8s linear infinite;
}
@keyframes ba-drehen { to { transform: rotate(360deg); } }

/* Unterschrift unter dem Bild – immer helle Schrift auf dem dunklen Schleier */
.ba-unterschrift {
  flex: none;
  width: 100%;
  max-width: min(100%, 72ch);
  text-align: center;
}
.ba-unterschrift p { margin: 0; }
.ba-unterschrift p[hidden] { display: none; }
.ba-titel {
  color: var(--ba-text);
  font: 600 1.02rem/1.3 var(--ba-schrift);
  letter-spacing: -.005em;
}
.ba-text {
  margin-top: .25rem !important;
  color: var(--ba-text-2);
  font-size: .92rem;
  line-height: 1.45;
}
.ba-hinweis {
  margin-top: .45rem !important;
  color: var(--ba-text-3);
  font-size: .76rem;
  letter-spacing: .01em;
}

/* Nur für Screenreader: Zoomstufe ansagen */
.ba-ansage {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Kleine Bildschirme: Beschriftung am Schließen-Knopf nur als Symbol */
@media (max-width: 560px) {
  .ba { gap: 10px; }
  .ba .ba-schliessen { padding: 0; width: 44px; }
  .ba-schliessen-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .ba-titel { font-size: .95rem; }
  .ba-text { font-size: .86rem; }
}
/* Wenig Höhe (Handy quer): Hinweiszeile weg, Text auf eine Zeile */
@media (max-height: 520px) {
  .ba { gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .ba-mitte { gap: 8px; }
  .ba-hinweis { display: none; }
  .ba-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---- 4. Zusammenspiel mit dem Gold-Cursor der Seite (custom-cursor.js) --------------
   Im Dialog gelten die nativen Zeiger (Lupe, Hand), der Gold-Cursor liegt ohnehin darunter. */
html.ba-offen .cc,
html.ba-offen .cursor-light { visibility: hidden !important; }
html.cc-on .ba { cursor: default; }
html.cc-on .ba .ba-knopf { cursor: pointer; }
html.cc-on .ba .ba-knopf[aria-disabled="true"] { cursor: default; }
html.cc-on .ba .ba-rahmen { cursor: zoom-in; }
html.cc-on .ba .ba-rahmen.ba-rahmen--zoom { cursor: grab; }
html.cc-on .ba .ba-rahmen.ba-rahmen--zieht { cursor: grabbing; }

/* ---- 5. Reduzierte Bewegung: keine Übergänge ------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ba,
  .ba-rahmen,
  .ba .ba-bild.ba-bild--gleitend,
  .ba .ba-knopf,
  .ba-laden,
  .ba--laedt .ba-laden,
  .ba-plakette { transition: none !important; }
  .ba-rahmen { transform: none; }
  .ba-plakette { transform: none; }
  .ba-kreisel { animation-duration: 2.4s; }
}

/* ---- 6. Hoher Kontrast (Windows) und Druck ----------------------------------------- */
@media (forced-colors: active) {
  .ba { background: Canvas; }
  .ba-plakette, .ba-leiste, .ba .ba-schliessen { border-color: ButtonText; }
  .ba .ba-knopf:focus-visible,
  figure.ba-bereit > .ba-ausloeser:focus-visible { outline-color: Highlight; }
}
@media print {
  .ba-ausloeser, .ba { display: none !important; }
}
