/* ========== GALLERY STYLES ========== */

.cms-gallery {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 0 15px;
  box-sizing: border-box;
}

.cms-gallery > a {
  flex: 0 0 auto;
  position: relative;
  width: calc(33.33% - 15px);
  margin: 15px 0;
  text-decoration: none;
  box-sizing: border-box;
}

/* Medium screen adjustments */
@media screen and (max-width: 991px) {
  .cms-gallery > a {
    width: calc(50% - 15px);
  }
}

/* Mobile screen adjustments */
@media screen and (max-width: 767px) {
  body {
    overflow-x: hidden;
  }

  .cms-gallery {
    padding: 0;
  }

  .cms-gallery > a {
    width: 100%;
    padding: 0;
  }
}

/* Decorative inner frame */
.cms-gallery > a:before {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  left: 6px;
  pointer-events: none;
}

/* Caption overlay on hover (updated with overflow fix) */
.cms-gallery > a:after {
  content: attr(data-caption);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  text-align: center;
  font-size: 15px;
  letter-spacing: 0.5px;
  font-weight: 500;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.5s;
  pointer-events: none;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
}

/* Smaller caption in Surreal CMS editor */
.cms-editable .cms-gallery > a:after {
  font-size: 11px;
}

/* Show caption only on hover outside CMS */
:not(.is-cms) .cms-gallery > a:hover:after {
  opacity: 1;
}

/* Responsive caption font/padding tweaks */
@media screen and (max-width: 600px) {
  .cms-gallery > a:after {
    padding: 0 12px;
    font-size: 13px;
  }
}

/* Responsive images */
.cms-gallery > a img {
  display: block;
  width: 100%;
  height: auto;
  border: none;
}

/* ========== FANCYBOX LIGHTBOX CAPTIONS ========== */

.fancybox__caption {
  padding-left: 20px;
  padding-right: 20px;
  text-align: center;
  box-sizing: border-box;
}

@media screen and (max-width: 600px) {
  .fancybox__caption {
    padding-left: 15px;
    padding-right: 15px;
  }
}
