/**
 * Masonry Gallery Styles
 *
 * Applies to Divi Gallery modules (grid layout) with the CSS class
 * "pp-masonry-gallery". Landscape photos fill 3:2 tiles; portrait
 * photos (tagged .is-portrait by masonry-gallery.js) span two rows.
 */

/* ==================================================
   Masonry Quilt Grid
   ================================================== */

.pp-masonry-gallery {
  container-type: inline-size;
}

.pp-masonry-gallery .et_pb_gallery_items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: clamp(150px, 17.8vw, 235px);
  grid-auto-flow: dense;
  gap: 12px;
}

/* Exact 3:2 tiles where container query units are supported:
   row = (container - 2 gaps) / 3 columns * 2/3 */
@supports (width: 1cqw) {
  .pp-masonry-gallery .et_pb_gallery_items {
    grid-auto-rows: calc((100cqw - 24px) * 2 / 9);
  }
}

/* ==================================================
   Neutralize Divi's Float Grid
   ================================================== */

/* Divi also sets inline width/margin on grid items via JS,
   hence the !important */
.pp-masonry-gallery .et_pb_gallery_item.et_pb_grid_item {
  float: none;
  width: auto !important;
  margin: 0 !important;
  clear: none !important;
  overflow: hidden;
}

/* ==================================================
   Tiles
   ================================================== */

.pp-masonry-gallery .et_pb_gallery_image {
  display: block;
  width: 100%;
  height: 100%;
}

.pp-masonry-gallery .et_pb_gallery_image a {
  display: block;
  width: 100%;
  height: 100%;
}

.pp-masonry-gallery .et_pb_gallery_image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Portrait photos span two rows */
.pp-masonry-gallery .et_pb_gallery_item.is-portrait {
  grid-row: span 2;
}

/* Tiles are height-locked; titles and captions don't fit */
.pp-masonry-gallery .et_pb_gallery_title,
.pp-masonry-gallery .et_pb_gallery_caption {
  display: none;
}

/* ==================================================
   Pagination
   ================================================== */

.pp-masonry-gallery .et_pb_gallery_pagination {
  clear: both;
  margin-top: 20px;
}

/* ==================================================
   Responsive
   ================================================== */

@media (max-width: 980px) {
  .pp-masonry-gallery .et_pb_gallery_items {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: clamp(140px, 26.5vw, 260px);
  }

  @supports (width: 1cqw) {
    .pp-masonry-gallery .et_pb_gallery_items {
      grid-auto-rows: calc((100cqw - 12px) / 3);
    }
  }
}

@media (max-width: 767px) {
  /* Single column: drop the quilt, show natural aspect */
  .pp-masonry-gallery .et_pb_gallery_items {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }

  .pp-masonry-gallery .et_pb_gallery_item.is-portrait {
    grid-row: auto;
  }

  .pp-masonry-gallery .et_pb_gallery_image,
  .pp-masonry-gallery .et_pb_gallery_image a,
  .pp-masonry-gallery .et_pb_gallery_image img {
    height: auto;
  }
}

/* ==================================================
   Stock Grid Galleries (site-wide)
   ================================================== */

/* The image-size filters in masonry-gallery.php serve uncropped images
   to every gallery module. Restore the stock uniform-crop look for grid
   galleries without the masonry class (they simply get sharper images). */
.et_pb_gallery_grid:not(.pp-masonry-gallery) .et_pb_gallery_image img {
  aspect-ratio: 400 / 284;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* ==================================================
   Lightbox Download Button
   ================================================== */

/* Injected into .mfp-wrap (fixed, viewport-covering) by
   masonry-gallery.js; sits left of Magnific's close button */
.pp-lightbox-download {
  position: fixed;
  top: 12px;
  right: 60px;
  z-index: 1047;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #374aae;
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.pp-lightbox-download svg {
  width: 22px;
  height: 22px;
}

.pp-lightbox-download:hover,
.pp-lightbox-download:focus-visible {
  opacity: 1;
}

.pp-lightbox-download:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.pp-lightbox-download.is-downloading {
  opacity: 0.35;
  cursor: wait;
}
