/* plugin.css
   ------------------------------------------------------------
   - Schlanke Basis + Fokus-/A11y-Verbesserungen
   - Basis-Thumbnailbreite für EINZELBILDER (außerhalb Grid)
   - Einheitliche Kacheln per Cropping NUR in .gallery-grid
   - Close-Button steht GENERELL leicht außerhalb (oben rechts)
   ------------------------------------------------------------ */

* { box-sizing: border-box; }

/* ------------------------------------------------------------
   Globale Variablen
   ------------------------------------------------------------ */
:root {
  /* Standardbreite der Einzelbild-Vorschau (kann seiten-/themenspezifisch überschrieben werden) */
  --lb-thumb-width: 250px;
  --lb-xbutton-top: -0.5rem;     /* leicht oberhalb */
  --lb-xbutton-right: -0.5rem;   /* leicht außerhalb */
}

/* ------------------------------------------------------------
   THUMBNAIL / TRIGGER (Standard – außerhalb von .gallery-grid)
   ------------------------------------------------------------ */
.lightbox-item {
  display: inline-block;          /* nötig, damit :focus sichtbar ist */
  cursor: pointer;
}

/* Rahmen/Optik der Thumbnail-Hülle (direktes <img> ODER <figure>) */
.lightbox-item > figure,
.lightbox-item > img {
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 10px;
  max-width: 100%;
}

/* Basis-Thumbnailgröße für EINZELBILDER */
.lightbox-item img {
  width: var(--lb-thumb-width);
  height: auto;
  display: block;
}
.lightbox-item > figure { width: var(--lb-thumb-width); }

/* Tastaturfokus sichtbar */
.lightbox-item:focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Captions (unter Thumbnail & im Modal) */
.lightbox-item figcaption,
.lightbox-modal figcaption {
  text-align: center;
  font-size: 12px;
  margin-top: .5rem;
  /* Farbe Untertitel */
  color: #000;
}

/* ------------------------------------------------------------
   MODAL / OVERLAY
   ------------------------------------------------------------ */
.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;

  display: flex;
  align-items: center;           /* zentriert Bild vertikal */
  justify-content: center;       /* zentriert Bild horizontal */

  padding: 1rem;
  background: rgba(0,0,0,0.9);   /* Overlay-Farbe */
  /* Optionaler Blur:
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  */

  overflow: hidden;
  color: #fff;
  outline: none;                 /* Fokus-Rahmen gezielt auf interaktive Elemente */

  /* unsichtbar im Ruhezustand */
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease;
}

/* Sichtbarer Zustand */
.lightbox-modal.show {
  opacity: 1;
  pointer-events: all;
}

/* Inhalt im Modal kapseln.
   HINWEIS: overflow = visible, damit der Close-Button außerhalb sichtbar ist */
.lightbox-content {
  position: relative;
  max-height: 90vh;
  max-width: 90vw;
  border-radius: 8px;            /* weiche Ecken für Bild+Caption */
  overflow: visible;             /* X-Button nicht abschneiden */
}

/* Bildgrößen im Modal – immer vollständig zeigen (robust gegen Theme-Styles) */
.lightbox-modal img {
  display: block;
  max-width: 90vw !important;
  max-height: 90vh !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain;
}

/* Close-Button: IMMER leicht außerhalb der rechten oberen Ecke */
.lightbox-modal .close {
  position: absolute;            /* relativ zu .lightbox-content */
  top: var(--lb-xbutton-top);
  right: var(--lb-xbutton-right);

  border: 1px solid #fff;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;

  font-size: 1rem;
  line-height: 1;
  padding: .5rem;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
  z-index: 10000;
}
.lightbox-modal .close:focus {
  outline: 1px solid #fff;
  outline-offset: 2px;
}

/* Optional: Body-Zustand – zusätzlich zum JS-Fix mit position:fixed */
body.lightbox-open { overflow: hidden; }

/* ------------------------------------------------------------
   OPTIONALES GALERIE-GRID (mehrere Thumbnails nebeneinander)
   - Einheitliche Kacheln mit Cropping
   - Scoping NUR auf .gallery-grid (Einzelbilder bleiben klein)
   ------------------------------------------------------------ */
.gallery-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

/* Rahmen im Grid reduzieren/entfernen und Maße vom Basis-Thumb aufheben */
.gallery-grid .lightbox-item > figure,
.gallery-grid .lightbox-item > img {
  width: auto;                   /* überschreibt var(--lb-thumb-width) */
  border-radius: 8px;
  padding: 0;
  border: none;
}

/* Bild füllt die Kachel – Cropping für ruhiges Raster */
.gallery-grid .lightbox-item img {
  width: 100%;
  height: 100%;
  aspect-ratio: 4 / 3;           /* Alternative: 1 / 1, 3 / 2, 16 / 9 */
  object-fit: cover;
  display: block;
  border-radius: 8px;
}

/* Figure im Grid bekommt ebenfalls die Kachelbreite */
.gallery-grid .lightbox-item > figure { width: auto; }

/* Gleichmäßige Caption-Höhe (optional) */
.gallery-grid .lightbox-item figcaption { min-height: 1.5em; }

/* ------------------------------------------------------------
   BEWEGUNGSPRÄFERENZ
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .lightbox-modal { transition: none; }
}

/* ------------------------------------------------------------
   FLOAT-FIX (Text soll am Thumbnail umlaufen)
   -> Nicht das <img>, sondern Wrapper (<.lightbox-item> / <figure>) floatet
   ------------------------------------------------------------ */

/* 1) Bild im Wrapper selbst NICHT floaten (verhindert doppelte Margins/Breiten) */
.lightbox-item img.leftcontentimage,
.lightbox-item img.rightcontentimage {
  float: none !important;
  max-width: 100%;
}

/* 2) Den WRAPPER floaten, sobald er ein links-/rechts-Bild enthält */
.lightbox-item:has(img.leftcontentimage),
.lightbox-item:has(span.leftcontentimage) {
  float: left;
  margin: .35em .9em .75em 0;
}
.lightbox-item:has(img.rightcontentimage),
.lightbox-item:has(span.rightcontentimage) {
  float: right;
  margin: .35em 0 .75em .9em;
}

/* 2b) Fallback ohne Wrapper-Erkennung: <figure> floatet, wenn das Kind-Bild die Klasse hat */
.lightbox-item > figure:has(> img.leftcontentimage) {
  float: left;
  margin: .35em .9em .75em 0;
}
.lightbox-item > figure:has(> img.rightcontentimage) {
  float: right;
  margin: .35em 0 .75em .9em;
}

/* 3) Auto-Clear: Übliche Inhalts-Wrapper werden flow-root,
      sobald sie ein "floated lightbox"-Kind enthalten */
:where(main, article, section, .content, .contenttext, .wrapper,
       .content-box, .card, .card-content, .content-grid, .grid, .grid-content, .clearfix)
:has(> .lightbox-item:where(:has(img.leftcontentimage), :has(img.rightcontentimage))) {
  display: flow-root;
}

/* 4) Mobile: Floats + feste Breite aufheben, Trigger blockig darstellen */
@media (max-width: 599px){
  .lightbox-item { display: block; }

  .lightbox-item > figure {
    display: block;
    width: 100% !important;      /* überschreibt var(--lb-thumb-width) */
  }

  .lightbox-item img {
    width: 100% !important;
    height: auto !important;
  }

  .lightbox-item:has(img.leftcontentimage),
  .lightbox-item:has(img.rightcontentimage),
  .lightbox-item > figure:has(> img.leftcontentimage),
  .lightbox-item > figure:has(> img.rightcontentimage){
    float: none;
    margin: 0 0 1rem 0;
  }
}
/* ===== Captions getrennt für Thumbnail vs. Modal ===== */
:root{
  --lb-caption-thumb-size: 12px;
  --lb-caption-modal-size: 13px;

  /* Farbe Untertitel THUMB */
  --lb-caption-thumb-color: #6b7280; /* dunkleres Grau auf weißem Hintergrund */

  /* Farbe Untertitel MODAL */
  --lb-caption-modal-color: #e5e7eb; /* helles Grau/Weiß auf dunklem Overlay */
}

/* Gemeinsame Basis (Reset & Typo) */
.lightbox-item figcaption,
.lightbox-modal figcaption,
.lightbox-item .imagesubtitle,
.lightbox-modal .imagesubtitle{
  text-align: center;
  line-height: 1.35;
  margin-top: .5rem;
  /* keine Farbe hier, damit die Scopes unten greifen */
}

/* Thumbnail-Caption (unter dem Thumb) */
.lightbox-item figcaption,
.lightbox-item .imagesubtitle{
  font-size: var(--lb-caption-thumb-size);
  color: var(--lb-caption-thumb-color); /* Farbe Untertitel THUMB */
}

/* Modal-Caption (unter dem großen Bild im Overlay) */
.lightbox-modal figcaption,
.lightbox-modal .imagesubtitle{
  font-size: var(--lb-caption-modal-size);
  color: var(--lb-caption-modal-color); /* Farbe Untertitel MODAL */
}
