/* Gallery Improvements */
.image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  width: 100%;
  height: auto;
  overflow: hidden;
  background: #f3f4f6;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Gallery item container */
.gallery-item {
  flex: 1 1 calc(33.333% - 6px);
  max-width: calc(33.333% - 6px);
  min-height: 250px;
  display: flex;
  flex-direction: column;
  position: relative;
  border: 3px solid white;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.gallery-image-link {
  flex: 1 1 calc(33.333% - 6px);
  max-width: calc(33.333% - 6px);
  min-height: 250px;
  display: flex;
  align-items: stretch;
  position: relative;
  text-decoration: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  border: 3px solid white;
  border-radius: var(--radius-md);
}

/* When gallery-image-link is inside a gallery-item, it should fill the container */
.gallery-item .gallery-image-link {
  flex: 1 1 100%;
  max-width: 100%;
  width: 100%;
  min-height: 200px;
  border: none;
  border-radius: 0;
}

/* When 3 or fewer images, let them expand to fill space */
.image-gallery .gallery-item:first-child:nth-last-child(1),
.image-gallery .gallery-item:first-child:nth-last-child(2),
.image-gallery .gallery-item:first-child:nth-last-child(2) ~ .gallery-item,
.image-gallery .gallery-item:first-child:nth-last-child(3),
.image-gallery .gallery-item:first-child:nth-last-child(3) ~ .gallery-item,
.image-gallery .gallery-image-link:first-child:nth-last-child(1),
.image-gallery .gallery-image-link:first-child:nth-last-child(2),
.image-gallery .gallery-image-link:first-child:nth-last-child(2) ~ .gallery-image-link,
.image-gallery .gallery-image-link:first-child:nth-last-child(3),
.image-gallery .gallery-image-link:first-child:nth-last-child(3) ~ .gallery-image-link {
  max-width: none;
}

/* When exactly 4 images, show 2x2 grid (for modals/site detail pages) */
.image-gallery .gallery-item:first-child:nth-last-child(4),
.image-gallery .gallery-item:first-child:nth-last-child(4) ~ .gallery-item,
.image-gallery .gallery-image-link:first-child:nth-last-child(4),
.image-gallery .gallery-image-link:first-child:nth-last-child(4) ~ .gallery-image-link {
  flex: 1 1 calc(50% - 5px);
  max-width: calc(50% - 5px);
}

/* Info page header galleries - show 4 images in a single row */
.info-page-content .image-gallery .gallery-item:first-child:nth-last-child(4),
.info-page-content .image-gallery .gallery-item:first-child:nth-last-child(4) ~ .gallery-item {
  flex: 1 1 calc(25% - 6px);
  max-width: calc(25% - 6px);
}

/* Map header gallery - show 6 images in a single row */
.map-header-gallery .image-gallery .gallery-item:first-child:nth-last-child(6),
.map-header-gallery .image-gallery .gallery-item:first-child:nth-last-child(6) ~ .gallery-item {
  flex: 1 1 calc(16.666% - 6px);
  max-width: calc(16.666% - 6px);
  min-height: 180px;
}

.gallery-image-link:hover {
  transform: scale(1.03);
  z-index: 10;
  box-shadow: var(--shadow-lg);
}

/* Enhanced hover indicator with icon */
.gallery-image-link::after {
  content: "\f002"; /* FontAwesome magnifying glass */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: rgba(0, 0, 0, 0.75);
  color: white;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: scale(0.8);
  box-shadow: var(--shadow-md);
}

.gallery-image-link:hover::after {
  opacity: 1;
  transform: scale(1);
}

/* Image overlay on hover */
.gallery-image-link::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.3) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.gallery-image-link:hover::before {
  opacity: 1;
}

.gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.gallery-image-link:hover .gallery-image {
  transform: scale(1.05);
}

/* Enhanced "View on Map" link */
.site-map-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--site-primary-b);
  background: var(--site-highlight-background);
  border: 1px solid var(--site-primary-a);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s ease;
}

.site-map-link:hover {
  background: var(--site-primary-b);
  color: white;
  border-color: var(--site-primary-b);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.site-map-link::before {
  content: "\f3c5"; /* FontAwesome map-marker-alt */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .image-gallery {
    gap: 4px;
  }

  .gallery-item {
    flex: 0 0 calc(50% - 5px);
    min-height: 180px;
  }

  .gallery-image-link {
    flex: 0 0 calc(50% - 5px);
    min-height: 180px;
  }

  .gallery-image-link::after {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
  }
}