/* ============================================================
   Custodia lightbox — shared by admin and public portal
   The portal script supplies the accessible dialog lifecycle;
   legacy admin lightboxes retain the same core class names.
   ============================================================ */

body.custodia-lightbox-active {
  overflow: hidden;
}

#custodia-lightbox {
  position: fixed;
  z-index: 99999;
  inset: 0;
  display: none;
  box-sizing: border-box;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  color: #ffffff;
}

#custodia-lightbox.custodia-lightbox-open {
  display: grid;
  place-items: center;
}

.custodia-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 12, 12, 0.92);
  cursor: pointer;
}

.custodia-lightbox-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 1440px);
  height: min(100%, 960px);
  min-width: 0;
  min-height: 0;
}

.custodia-lightbox-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 52px;
  padding-bottom: 0.55rem;
}

.custodia-lightbox-title {
  overflow: hidden;
  margin: 0;
  color: #ffffff;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custodia-lightbox-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.custodia-lightbox-close,
.custodia-lightbox-zoom,
.custodia-lightbox-prev,
.custodia-lightbox-next {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.custodia-lightbox-close {
  font-size: 1.65rem;
  line-height: 1;
}

.custodia-lightbox-zoom {
  gap: 0.45rem;
  width: auto;
  padding: 0 0.85rem;
  font-size: 0.78rem;
}

.custodia-lightbox-zoom > span[aria-hidden="true"] {
  font-size: 1.25rem;
  line-height: 1;
}

.custodia-lightbox-prev,
.custodia-lightbox-next {
  font-size: 2.1rem;
  line-height: 1;
}

.custodia-lightbox-close:hover,
.custodia-lightbox-zoom:hover,
.custodia-lightbox-prev:hover,
.custodia-lightbox-next:hover {
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.24);
}

.custodia-lightbox-close:focus-visible,
.custodia-lightbox-zoom:focus-visible,
.custodia-lightbox-prev:focus-visible,
.custodia-lightbox-next:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 3px;
}

.custodia-lightbox-nav {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  min-height: 0;
}

.custodia-lightbox-media {
  grid-column: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
}

.custodia-lightbox-prev {
  grid-column: 1;
}

.custodia-lightbox-next {
  grid-column: 3;
}

.custodia-lightbox-img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(80vw, 1200px);
  max-height: 76vh;
  border-radius: 4px;
  background: #1a1a1a;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.6);
  cursor: zoom-in;
}

.custodia-lightbox-img.custodia-lightbox-zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

/* Admin inline previews place the image directly in the middle grid column. */
.custodia-lightbox-nav > .custodia-lightbox-img {
  grid-column: 2;
  justify-self: safe center;
}

.custodia-lightbox-nav > .custodia-lightbox-img:not(.custodia-lightbox-zoomed) {
  max-width: 100%;
}

#custodia-lightbox.custodia-lightbox-zoomed .custodia-lightbox-media {
  display: block;
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#custodia-lightbox.custodia-lightbox-zoomed .custodia-lightbox-media::-webkit-scrollbar {
  display: none;
}

/* Compatibility for the older admin lightbox, where the image is a direct
   child of the navigation row rather than the scrollable media wrapper. */
#custodia-lightbox.custodia-lightbox-zoomed .custodia-lightbox-nav:not(:has(.custodia-lightbox-media)) {
  overflow: auto;
}

.custodia-lightbox-footer {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 48px;
  padding-top: 0.65rem;
}

.custodia-lightbox-description,
.custodia-lightbox-counter {
  margin: 0;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.82rem;
  line-height: 1.45;
}

.custodia-lightbox-description {
  overflow: hidden;
  max-width: 72ch;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custodia-lightbox-counter {
  flex-shrink: 0;
  white-space: nowrap;
}

.custodia-lightbox-prev[hidden],
.custodia-lightbox-next[hidden] {
  display: none;
}

/* Bootstrap carousel zoom (legacy _carousel_modal.html templates) */
.carousel-item img {
  cursor: zoom-in;
}

.carousel-item img.custodia-carousel-zoomed {
  width: auto !important;
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.modal.custodia-zoomed .modal-dialog {
  max-width: 95vw;
}

.modal.custodia-zoomed .modal-body {
  overflow: auto;
  max-height: 90vh;
}

@media (max-width: 640px) {
  #custodia-lightbox {
    padding:
      max(0.65rem, env(safe-area-inset-top))
      max(0.5rem, env(safe-area-inset-right))
      max(0.65rem, env(safe-area-inset-bottom))
      max(0.5rem, env(safe-area-inset-left));
  }

  .custodia-lightbox-dialog {
    width: 100%;
    height: 100%;
  }

  .custodia-lightbox-topbar {
    min-height: 48px;
  }

  .custodia-lightbox-nav {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 0.25rem;
  }

  .custodia-lightbox-control-label {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .custodia-lightbox-zoom {
    width: 44px;
    padding: 0;
  }

  .custodia-lightbox-footer {
    min-height: 56px;
  }

  .custodia-lightbox-description {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .custodia-lightbox-close,
  .custodia-lightbox-zoom,
  .custodia-lightbox-prev,
  .custodia-lightbox-next {
    transition: none;
  }
}
