/* Gallery grid and lightbox tweaks */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}
.gallery-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  transition: transform .25s ease, box-shadow .25s ease;
  cursor: zoom-in;
}
.gallery-item img:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

/* subtle scale on hover for the whole item */
.gallery-item:hover img {
  transform: scale(1.04);
}

/* Overlay sits absolutely at the bottom of the image */
.gallery-overlay {
  position: absolute;
  top: 0; /* cover the entire item */
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem;
  /* darker, semi-transparent overlay to ensure caption contrast */
  background: linear-gradient(to top, rgba(0,0,0,0.72) 0%, rgba(0,0,0,0.45) 40%, rgba(0,0,0,0.12) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* let clicks pass to the anchor */
  transform: translateY(12%);
  opacity: 0;
  transition: transform .28s cubic-bezier(.2,.9,.2,1), opacity .28s ease;
}
.gallery-overlay .text-center {
  width: 100%;
  text-align: center; /* center captions for easier reading */
  pointer-events: auto; /* allow interaction if needed inside overlay */
}
.gallery-overlay h5 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-overlay p {
  margin: 0;
  font-size: .9rem;
  color: rgba(255,255,255,0.9);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Slide-up / fade-in animation on hover */
.gallery-item:hover .gallery-overlay {
  transform: translateY(0);
  opacity: 1;
}

/* Lightbox tweaks to make controls slightly larger */
.sl-wrapper button { font-size: 2.2em; }
.sl-wrapper .sl-prev, .sl-wrapper .sl-next { padding: 8px 12px; }

/* Make overlay cover full viewport and ensure buttons remain clickable */
.sl-overlay {
  position: fixed !important;
  inset: 0 !important;
  display: block !important;
}

.sl-wrapper button {
  position: absolute !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .gallery-item img { height: 140px; }
}

/* Center the lightbox image perfectly and constrain to viewport */

/* Ensure the lightbox wrapper is a centered flex container so opened media is vertically and horizontally centered */
.sl-wrapper {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: initial !important;
}

/* Make the image container behave like a centered flex item and override default absolute positioning */
.sl-wrapper .sl-image {
  position: relative !important;
  margin: 0 !important;
  transform: none !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  max-width: 90vw !important;
  max-height: 90vh !important;
}

.sl-wrapper .sl-image img {
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: calc(100vh - 120px) !important; /* leave room for controls/captions */
  display: block;
}

/* Place the close button at the top-right and make it always visible */
.sl-wrapper .sl-close {
  display: block !important;
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  z-index: 100001 !important;
  background: rgba(0,0,0,0.45) !important;
  color: #fff !important;
  padding: 6px 10px !important;
  border-radius: 6px !important;
  font-size: 1.6rem !important;
  line-height: 1 !important;
  cursor: pointer !important;
}

/* Slightly reduce size on small screens */
@media (max-width: 480px) {
  .sl-wrapper .sl-close { font-size: 1.2rem !important; padding: 6px 8px !important; }
}
