/* ================================
   MEDIA GALLERY BLOCK STYLES
   Premium masonry layout with preserved aspect ratios
   ================================ */

/* Go to Top Button */
.media-gallery-go-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3.5rem;
  height: 3.5rem;
  background: var(
    --wp--preset--color--primary,
    var(--luminate_color_primary, #242a2e)
  );
  color: var(--wp--preset--color--white, var(--luminate_color_white, #ffffff));
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(1rem) scale(0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  line-height: 1;
}

.media-gallery-go-to-top:hover,
.media-gallery-go-to-top:focus {
  background: var(
    --wp--preset--color--primary,
    var(--luminate_color_primary, #242a2e)
  );
  color: var(--wp--preset--color--white, var(--luminate_color_white, #ffffff));
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(0) scale(1);
  outline: none;
}

.media-gallery-go-to-top:focus-visible {
  outline: 2px solid
    var(--wp--preset--color--primary, var(--luminate_color_primary, #242a2e));
  outline-offset: 2px;
}

.media-gallery-go-to-top.media-gallery-go-to-top-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.media-gallery-go-to-top svg {
  width: 1.5rem;
  height: 1.5rem;
  transition: transform 0.2s ease;
}

.media-gallery-go-to-top:hover svg {
  transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
  .media-gallery-go-to-top {
    transition:
      opacity 0.2s ease,
      visibility 0.2s ease;
  }

  .media-gallery-go-to-top svg {
    transition: none;
  }
}

@media (max-width: 768px) {
  .media-gallery-go-to-top {
    bottom: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
  }

  .media-gallery-go-to-top svg {
    width: 1.25rem;
    height: 1.25rem;
  }
}

.media-gallery-go-to-top * {
  pointer-events: none;
}

.luminate-child-media-gallery {
  margin: 0;
  clear: both;
  width: 100%;
  max-width: 100%;
  padding: 0;
}

/* Override WordPress block wrapper constraints */
.luminate-child-media-gallery.wp-block,
.luminate-child-media-gallery[class*="wp-block"] {
  max-width: 100% !important;
  width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

.luminate-child-media-gallery.alignwide,
.luminate-child-media-gallery.alignfull {
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
}

.media-gallery-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  transition: opacity 0.2s ease;
}

/* Make container look clickable when link URL is set */
.luminate-child-media-gallery[data-link-url]:not([data-link-url=""])
  .media-gallery-container {
  cursor: pointer;
}

.luminate-child-media-gallery[data-link-url]:not([data-link-url=""])
  .media-gallery-container:hover {
  opacity: 0.95;
}

.luminate-child-media-gallery[data-link-url]:not([data-link-url=""])
  .media-gallery-container:focus {
  outline: 2px solid
    var(--wp--preset--color--primary, var(--luminate_color_primary, #242a2e));
  outline-offset: 2px;
}

.media-gallery-grid {
  margin: 0;
  padding: 0 0 0.2rem 0; /* Add bottom padding for spacing between rows */
  list-style: none;
  width: 100%;
}

/* Grid item - preserves aspect ratio */
.media-gallery-item {
  position: relative;
  width: 100%;
  margin-bottom: 0.2rem !important; /* Ensure bottom spacing between rows */
  opacity: 0;
  transform: translateY(1rem);
  transition:
    opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  aspect-ratio: var(--aspect-ratio, 1);
}

.media-gallery-item.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .media-gallery-item {
    transition: opacity 0.2s ease;
    transform: none;
  }
  .media-gallery-item.is-visible {
    transform: none;
  }
}

/* Link wrapper */
.media-gallery-link {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
  transition: opacity 0.3s ease;
}

.media-gallery-link:hover {
  opacity: 0.85;
}

.media-gallery-link:focus-visible {
  outline: 2px solid
    var(--wp--preset--color--primary, var(--luminate_color_primary, #242a2e));
  outline-offset: 2px;
}

/* Image wrapper */
.media-gallery-image-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(
    --wp--preset--color--background,
    var(--luminate_background_color_lite, #f6f5f2)
  );
  contain: layout;
}

/* Image */
.media-gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
  contain: layout;
}

.media-gallery-image.is-loaded {
  opacity: 1;
}

/* Overlay for captions */
.media-gallery-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(36, 42, 46, 0.8) 0%,
    transparent 100%
  );
  padding: var(--wp--custom--spacing--small, max(1.25rem, 5vw));
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.media-gallery-link:hover .media-gallery-overlay,
.media-gallery-link:focus-visible .media-gallery-overlay {
  opacity: 1;
}

.media-gallery-caption {
  color: var(--wp--preset--color--white, var(--luminate_color_white, #ffffff));
  font-family: var(
    --wp--preset--font-family--primary-font,
    var(--luminate_font_family_primary)
  );
  font-size: var(
    --wp--custom--typography--font-size--small,
    var(--luminate_font_size_small, clamp(0.75rem, 3.5vw, 0.875rem))
  );
  line-height: var(--wp--custom--typography--line-height--medium, 1.3);
  letter-spacing: var(
    --wp--custom--typography--letter-spacing--body,
    var(--luminate_letter_spacing_regular, 0.02em)
  );
}

/* Loader */
.media-gallery-loader {
  text-align: center;
  padding: var(--wp--custom--spacing--medium, clamp(2rem, 8vw, 4rem))
    var(--wp--custom--spacing--outer, 1.25rem);
  margin-top: var(--wp--style--block-gap, 1.5rem);
  clear: both;
  min-height: 100px; /* Ensure it has height for IntersectionObserver */
  display: block; /* Always visible for IntersectionObserver */
}

.media-gallery-loader[data-loading="true"] .loader-spinner,
.media-gallery-loader[data-loading="true"] .loader-text {
  display: block;
}

.media-gallery-loader[data-loading="false"] .loader-spinner,
.media-gallery-loader[data-loading="false"] .loader-text {
  display: none;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 1rem;
  border: 4px solid
    var(
      --wp--preset--color--background,
      var(--luminate_background_color_lite, #f6f5f2)
    );
  border-top: 4px solid
    var(--wp--preset--color--primary, var(--luminate_color_primary, #242a2e));
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .loader-spinner {
    animation: none;
    border-top-color: transparent;
  }
}

.loader-text {
  font-family: var(
    --wp--preset--font-family--primary-font,
    var(--luminate_font_family_primary)
  );
  color: var(
    --wp--preset--color--primary,
    var(--luminate_color_primary, #242a2e)
  );
  font-size: var(
    --wp--custom--typography--font-size--small,
    var(--luminate_font_size_small, clamp(0.75rem, 3.5vw, 0.875rem))
  );
  letter-spacing: var(
    --wp--custom--typography--letter-spacing--body,
    var(--luminate_letter_spacing_regular, 0.02em)
  );
  margin: 0;
}

/* Responsive column widths - flexible masonry layout */
/* Masonry.js will handle the layout, these are fallback widths */
/* Minimum 3 columns on all screen sizes */
/* Maximum 10px gap between images (right and bottom spacing handled by Masonry.js gutter) */
.media-gallery-item {
  width: calc(33.333% - 0.2rem); /* Always 3 columns minimum */
}

@media (min-width: 1024px) {
  .media-gallery-item {
    width: calc(25% - 0.2rem); /* 4 columns */
  }
}

@media (min-width: 1280px) {
  .media-gallery-item {
    width: calc(20% - 0.2rem); /* 5 columns */
  }
}

@media (min-width: 1600px) {
  .media-gallery-item {
    width: calc(16.666% - 0.2rem); /* 6 columns */
  }
}

@media (min-width: 1920px) {
  .media-gallery-item {
    width: calc(14.285% - 0.2rem); /* 7 columns */
  }
}

@media (min-width: 2560px) {
  .media-gallery-item {
    width: calc(12.5% - 0.2rem); /* 8 columns */
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Editor preview */
.luminate-child-media-gallery-editor {
  padding: 20px;
  border: 1px dashed #ccc;
  background: #f9f9f9;
}

.luminate-child-media-gallery-preview {
  text-align: center;
}

.luminate-child-media-gallery-preview p {
  margin: 10px 0;
}
