/* Gallery Styles for consistent image and video layout */

/* Base styles for all media items */
.gallery-container,
.section-image {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin: 20px 0;
}

.gallery-item,
.section-image > img,
.section-image > video,
.section-image > .video-container,
.section-image > figure {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease;
  background: #f0f0f0;
  margin-bottom: 20px;
  width: 100%;
}

/* Single media item - full width, fixed height */
.gallery-item:only-child,
.section-image > img:only-child,
.section-image > video:only-child,
.section-image > .video-container:only-child,
.section-image > figure:only-child {
  height: 500px;
  max-width: 100%;
  margin-bottom: 20px;
}

/* Multiple media items - square aspect ratio */
.gallery-item:not(:only-child),
.section-image > img:not(:only-child),
.section-image > video:not(:only-child),
.section-image > .video-container:not(:only-child),
.section-image > figure:not(:only-child) {
  width: calc(50% - 10px); /* Default for mobile: 2 items per row */
  aspect-ratio: 1/1;
}

/* Ensure media fills container and maintains aspect ratio */
.gallery-item img,
.gallery-item video,
.section-image > img,
.section-image > video,
.section-image > .video-container,
.section-image > figure,
.section-image .video-container > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  aspect-ratio: 1/1;
}

/* Override for single item */
.gallery-item:only-child img,
.gallery-item:only-child video,
.section-image > img:only-child,
.section-image > video:only-child,
.section-image > .video-container:only-child,
.section-image > figure:only-child {
  aspect-ratio: auto;
  height: 500px;
}

/* Gallery overlay styles */
.gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.gallery-item:hover .gallery-overlay {
  opacity: 1;
}

.gallery-overlay i {
  color: white;
  font-size: 2rem;
}

/* Responsive grid layout */
/* 3 items per row on larger screens */
@media (min-width: 768px) {
  .gallery-item:not(:only-child),
  .section-image > img:not(:only-child),
  .section-image > video:not(:only-child),
  .section-image > .video-container:not(:only-child),
  .section-image > figure:not(:only-child) {
    width: calc(33.333% - 14px);
  }
}

/* 4 items per row on even larger screens */
@media (min-width: 992px) {
  .gallery-item:not(:only-child),
  .section-image > img:not(:only-child),
  .section-image > video:not(:only-child),
  .section-image > .video-container:not(:only-child),
  .section-image > figure:not(:only-child) {
    width: calc(25% - 15px);
  }
}

/* Adjust for exact counts */
/* 2 items */
.gallery-item:first-child:nth-last-child(2),
.gallery-item:first-child:nth-last-child(2) ~ .gallery-item,
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(2),
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(2) ~ :is(img, video, .video-container, figure) {
  width: calc(50% - 10px);
}

/* 3 items */
.gallery-item:first-child:nth-last-child(3),
.gallery-item:first-child:nth-last-child(3) ~ .gallery-item,
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(3),
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(3) ~ :is(img, video, .video-container, figure) {
  width: calc(33.333% - 14px);
}

/* 4 items */
.gallery-item:first-child:nth-last-child(4),
.gallery-item:first-child:nth-last-child(4) ~ .gallery-item,
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(4),
.section-image > :is(img, video, .video-container, figure):first-child:nth-last-child(4) ~ :is(img, video, .video-container, figure) {
  width: calc(25% - 15px);
}

/* Mobile view adjustments */
@media (max-width: 576px) {
  .gallery-container,
  .section-image {
    gap: 10px;
    margin: 10px 0;
  }
  
  /* Single media item on mobile */
  .gallery-item:only-child,
  .section-image > img:only-child,
  .section-image > video:only-child,
  .section-image > .video-container:only-child,
  .section-image > figure:only-child {
    height: 300px;
    margin-bottom: 15px;
  }
  
  /* Multiple items on mobile */
  .gallery-item:not(:only-child),
  .section-image > img:not(:only-child),
  .section-image > video:not(:only-child),
  .section-image > .video-container:not(:only-child),
  .section-image > figure:not(:only-child) {
    width: calc(50% - 5px);
    margin-bottom: 10px;
  }
  
  /* Single column on very small screens */
  @media (max-width: 400px) {
    .gallery-item:not(:only-child),
    .section-image > img:not(:only-child),
    .section-image > video:not(:only-child),
    .section-image > .video-container:not(:only-child),
    .section-image > figure:not(:only-child) {
      width: 100%;
    }
  }
}

/* Image Popup */
.image-popup {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-popup.show {
  display: flex;
  opacity: 1;
}

.popup-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.popup-content img {
  max-width: 100%;
  max-height: 80vh;
  display: block;
  margin: 0 auto;
}

.close-popup {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 30px;
  color: white;
  background: rgba(0, 0, 0, 0.5);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
}

.close-popup:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Video play button */
.video-play-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: all 0.3s ease;
}

.video-play-button:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: translate(-50%, -50%) scale(1.1);
}

.video-play-button::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-left: 25px solid #fff;
  margin-left: 5px;
}
