/* ==========================================================================
   AI Gallery — grid, slider thumbnail grid, and Bootstrap modal lightbox

   Rendered by AI\GallerySlider. Loaded for every [gallery] (both the default
   grid and slider="true"). Brand-agnostic: theme tokens fall back to sensible
   defaults so this works in any brand built on ai-beehive.

     - default        → .ai-gallery--grid (responsive thumbnail grid)
     - slider="true"  → .ai-gallery-slider-wrapper (Slick, see gallery-slider.css)
                        + .ai-gallery-thumbgrid below it

   Every image is a <button> trigger (never a file/attachment link) that opens
   the shared Bootstrap modal/carousel lightbox (.ai-gallery-modal).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */

.ai-gallery--grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-left: auto;
  margin-right: auto;
}

.ai-gallery-cols-1 { grid-template-columns: repeat(1, 1fr); }
.ai-gallery-cols-2 { grid-template-columns: repeat(2, 1fr); }
.ai-gallery-cols-3 { grid-template-columns: repeat(3, 1fr); }
.ai-gallery-cols-4 { grid-template-columns: repeat(4, 1fr); }
.ai-gallery-cols-5 { grid-template-columns: repeat(5, 1fr); }
.ai-gallery-cols-6 { grid-template-columns: repeat(6, 1fr); }

.ai-gallery-item {
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0;
}

/* Clickable image button — reset native button chrome. */
.ai-gallery-trigger {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
}

.ai-gallery--grid .ai-gallery-trigger {
  aspect-ratio: 3 / 2;
}

.ai-gallery--grid .ai-gallery-img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
  border: 0;
  transition: transform 0.3s ease;
}

.ai-gallery--grid .ai-gallery-trigger:hover .ai-gallery-img,
.ai-gallery--grid .ai-gallery-trigger:focus-visible .ai-gallery-img {
  transform: scale(1.04);
}

.ai-gallery-grid-caption {
  font-family: var(--font-ui, inherit);
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--color-text-muted, #6c757d);
  padding: 0.35em 0;
}

/* --------------------------------------------------------------------------
   Slider thumbnail grid (shown below slider="true")
   -------------------------------------------------------------------------- */

.ai-gallery-thumbgrid {
  display: grid;
  /* auto-fit collapses any unused trailing columns (e.g. 5 thumbs in a
     6-wide row) and redistributes that space to the real thumbnails, so
     the row always fills the container width with no leftover gap. */
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.ai-gallery-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  outline: 2px solid transparent;
  outline-offset: -2px;
}

.ai-gallery-thumb:hover {
  opacity: 0.85;
}

.ai-gallery-thumb.is-active {
  opacity: 1;
  outline-color: var(--color-action, var(--bs-primary, #0d6efd));
}

.ai-gallery-thumb-img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
  border: 0;
}

/* --------------------------------------------------------------------------
   Bootstrap modal / carousel lightbox
   -------------------------------------------------------------------------- */

/* Neutralise any inherited max-width/centering on the fixed modal so it can
   fill the viewport (e.g. article content-column rules in a child theme). */
.ai-gallery-modal {
  max-width: none !important;
  margin: 0 !important;
}

.ai-gallery-modal .modal-content {
  background: transparent;
  border: 0;
}

.ai-gallery-modal .modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-gallery-modal-img {
  width: auto;
  max-width: 100%;
  max-height: 85vh;
  margin: 0 auto;
  object-fit: contain;
}

.ai-gallery-modal-close {
  position: absolute;
  top: -0.75rem;
  right: -0.75rem;
  z-index: 10;
  padding: 0.5rem;
  border-radius: 50%;
  background-color: #fff;
  opacity: 1;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.ai-gallery-modal-caption {
  background: rgba(0, 0, 0, 0.55);
  border-radius: 0.25rem;
  padding: 0.4em 0.75em;
}

/* On phones the negative-offset close button would clip off-screen. */
@media (max-width: 575.98px) {
  .ai-gallery-modal-close {
    top: 0.25rem;
    right: 0.25rem;
  }
}

/* --------------------------------------------------------------------------
   Responsive columns
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .ai-gallery--grid,
  .ai-gallery-cols-3,
  .ai-gallery-cols-4,
  .ai-gallery-cols-5,
  .ai-gallery-cols-6 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .ai-gallery--grid,
  .ai-gallery-cols-2,
  .ai-gallery-cols-3,
  .ai-gallery-cols-4,
  .ai-gallery-cols-5,
  .ai-gallery-cols-6 {
    grid-template-columns: repeat(1, 1fr);
  }
}
