/* ==========================================================================
   SG Image Lightbox – v1.2.0
   Zwei Modi: Einzelbild (isoliert) + Galerie (Masonry + Prev/Next).
   Prefix: .sg-lb-*, .sg-gallery-*, #sg-lightbox
   ========================================================================== */


/* ── Trigger-Button für Einzelbilder (unsichtbarer Wrapper um <img>) ──── */

.sg-lb-trigger {
  display: block;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  line-height: 0;
  width: 100%;
}

.sg-lb-trigger:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* img im Single-Trigger: gleich rendern wie ohne Wrapper */
.sg-lb-trigger img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}


/* ── Masonry Grid ──────────────────────────────────────────────────────── */

.sg-gallery-wrap {
  /* Kein eigenes Padding – das übernimmt das Theme */
}

.sg-gallery-grid {
  columns: 3;
  column-gap: 3px;
}

/*
 * Gallery-Item: Button-Reset + Shimmer-Ladeindikator.
 * Der Shimmer-Background scheint durch das transparente img solange es
 * noch nicht geladen ist. JS setzt .sg-loaded (img onload) → Shimmer weg.
 */
.sg-gallery-item {
  display: block;
  break-inside: avoid;
  margin-bottom: 3px;
  position: relative;
  overflow: hidden;
  cursor: zoom-in;
  border: none;
  padding: 0;
  width: 100%;
  text-align: left;
  background: linear-gradient(
    90deg,
    #e8e8e8 25%,
    #f2f2f2 50%,
    #e8e8e8 75%
  );
  background-size: 400% 100%;
  animation: sg-shimmer 1.6s ease-in-out infinite;
}

.sg-gallery-item.sg-loaded {
  background: #000;
  animation: none;
}

@keyframes sg-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.sg-gallery-item img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.65s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.sg-gallery-item:hover img,
.sg-gallery-item:focus-visible img {
  transform: scale(1.03);
}

.sg-gallery-item:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Caption – erscheint beim Hover */
.sg-gallery-item-caption {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, transparent 50%);
  color: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: flex-end;
  padding: 1.25rem 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  line-height: 1.45;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.sg-gallery-item:hover .sg-gallery-item-caption,
.sg-gallery-item:focus-visible .sg-gallery-item-caption {
  opacity: 1;
}


/* ── Lightbox ──────────────────────────────────────────────────────────── */

#sg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  align-items: center;
  justify-content: center;
}

#sg-lightbox.sg-lb-open {
  display: flex !important;
}

.sg-lb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  cursor: zoom-out;
}

.sg-lb-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 92vh;
}

.sg-lb-img {
  display: block;
  max-width: 88vw;
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.sg-lb-caption {
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  line-height: 1.5;
  text-align: center;
  padding: 0.75rem 2rem 0;
  max-width: 60ch;
  margin: 0;
}

/* Gemeinsame Button-Basis */
.sg-lb-btn {
  position: fixed;
  z-index: 2;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
  font-family: system-ui, sans-serif;
}

.sg-lb-btn:hover,
.sg-lb-btn:focus-visible {
  color: #fff;
  outline: none;
}

.sg-lb-close {
  top: 1.25rem;
  right: 1.5rem;
  font-size: 1.75rem;
  padding: 0.5rem;
}

/* Prev/Next + Counter: standardmäßig versteckt (Single-Modus) */
.sg-lb-counter,
.sg-lb-prev,
.sg-lb-next {
  display: none;
}

/* Im Gallery-Modus eingeblendet */
#sg-lightbox.sg-lb-gallery-mode .sg-lb-prev,
#sg-lightbox.sg-lb-gallery-mode .sg-lb-next {
  display: block;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.5rem;
  padding: 1rem;
}

#sg-lightbox.sg-lb-gallery-mode .sg-lb-prev { left:  0.5rem; }
#sg-lightbox.sg-lb-gallery-mode .sg-lb-next { right: 0.5rem; }

#sg-lightbox.sg-lb-gallery-mode .sg-lb-counter {
  display: block;
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
}

/* Lade-Spinner */
.sg-lb-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: sg-spin 0.7s linear infinite;
}

@keyframes sg-spin {
  to { transform: rotate(360deg); }
}


/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .sg-gallery-grid { columns: 2; }

  #sg-lightbox.sg-lb-gallery-mode .sg-lb-prev { left:  0; }
  #sg-lightbox.sg-lb-gallery-mode .sg-lb-next { right: 0; }
}

@media (max-width: 600px) {
  .sg-gallery-grid { columns: 2; }

  .sg-lb-img {
    max-width: 100vw;
    max-height: 90vh;
  }

  #sg-lightbox.sg-lb-gallery-mode .sg-lb-prev,
  #sg-lightbox.sg-lb-gallery-mode .sg-lb-next {
    font-size: 2rem;
  }
}
