/* Shared in-app photo lightbox (public/assets/js/utils/photo-lightbox.js).
   A dark full-viewport overlay used to view photos without navigating away —
   the PWA-safe replacement for the old `<a target="_blank">` raw-image links.
   The scrim is intentionally dark in both colour themes. Sits above app modals
   (`.modal` is z-index 2130) but below toasts (9999). */

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vw, 40px);
}

.photo-lightbox[hidden] {
  display: none;
}

.photo-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.photo-lightbox__stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: min(1100px, 100%);
  max-height: 100%;
}

.photo-lightbox__image {
  display: block;
  max-width: 100%;
  /* Leave room for the close button and caption row. */
  max-height: calc(100dvh - clamp(24px, 8vw, 80px) - 64px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.04);
}

.photo-lightbox__image[hidden] {
  display: none;
}

.photo-lightbox__close {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.photo-lightbox__close:hover {
  background: rgba(40, 40, 40, 0.92);
}

.photo-lightbox__close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.photo-lightbox__close svg {
  display: block;
}

.photo-lightbox__spinner {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  animation: photo-lightbox-spin 0.7s linear infinite;
}

.photo-lightbox__spinner[hidden] {
  display: none;
}

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

.photo-lightbox__error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  padding: 24px;
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
}

.photo-lightbox__error[hidden] {
  display: none;
}

.photo-lightbox__error p {
  margin: 0;
  font-size: 0.95rem;
}

.photo-lightbox__fallback {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.photo-lightbox__fallback:hover {
  background: rgba(255, 255, 255, 0.24);
}

.photo-lightbox__fallback:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.photo-lightbox__caption {
  margin: 0;
  max-width: 100%;
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.9rem;
  text-align: center;
  text-wrap: balance;
}

.photo-lightbox__caption[hidden] {
  display: none;
}

/* Lock background scroll while the viewer is open. Distinct from `modal-open`
   so dismissing the lightbox doesn't unlock a modal that is still open. */
body.photo-lightbox-open {
  overflow: hidden;
}

@media (max-width: 900px) {
  .photo-lightbox {
    padding: 0;
  }

  .photo-lightbox__stage {
    width: 100%;
    height: 100%;
    gap: 10px;
    padding: 16px;
  }

  .photo-lightbox__image {
    max-height: calc(100dvh - 96px);
    border-radius: var(--radius-sm);
  }

  .photo-lightbox__close {
    top: 10px;
    right: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .photo-lightbox__spinner {
    animation-duration: 1.6s;
  }

  .photo-lightbox__close {
    transition: none;
  }
}
