/* =========================================================
   Gallery.css
   Filtered portfolio gallery + smooth lightbox
   ========================================================= */

.portfolio-gallery {
  padding: 70px 0;
}

.gallery-filters {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 52px;
  margin-bottom: 38px;
}

.gallery-filter {
  appearance: none;
  border: 1px solid #d9dee7;
  background: #fff;
  color: #1a2b4b;
  border-radius: 999px;
  padding: 11px 22px;
  min-width: 112px;
  min-height: 44px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color 0.45s ease,
    color 0.45s ease,
    border-color 0.45s ease,
    box-shadow 0.45s ease,
    transform 0.45s ease;
  transform: translateZ(0);
  white-space: nowrap;
}

.gallery-filter:hover {
  border-color: #3e5c9a;
  box-shadow: 0 5px 18px rgba(26, 43, 75, 0.08);
  transform: translateY(-1px);
}

.gallery-filter.active {
  background: #1a2b4b;
  border-color: #1a2b4b;
  color: #fff;
  box-shadow: 0 7px 20px rgba(26, 43, 75, 0.16);
}

.gallery-filter:focus-visible,
.gallery-item:focus-visible,
.gallery-close:focus-visible,
.gallery-nav:focus-visible {
  outline: 3px solid rgba(62, 92, 154, 0.35);
  outline-offset: 3px;
}

/* Masonry: JavaScript builds the columns and drops each image into the
   shortest one, so the grid keeps growing evenly while scrolling. */
.gallery-grid {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.gallery-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 0;
  gap: inherit;
}

.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3; /* fallback; JS sets the real ratio per image */
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #eef1f5;
  cursor: pointer;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.65s ease,
    transform 0.65s ease,
    box-shadow 0.45s ease;
  box-shadow: 0 5px 18px rgba(26, 43, 75, 0.08);
}

.gallery-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s ease;
}

.gallery-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(26, 43, 75, 0.14);
}

.gallery-item:hover img {
  transform: scale(1.035);
}

/* JavaScript adds these during filtering to keep transitions smooth. */
.gallery-item.is-filtering-out {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
}

.gallery-item.is-filtering-in {
  animation: galleryFadeIn 0.8s ease both;
	
}

@keyframes galleryFadeIn {
   from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Lightbox */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 80px;
  background: rgba(8, 14, 25, 0.94);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.65s ease, visibility 0.65s ease;
}

.gallery-lightbox.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.gallery-lightbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(1100px, 88vw);
  height: min(82vh, 800px);
}

.gallery-lightbox-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.gallery-lightbox-stage img.is-visible {
  opacity: 1;
  transform: scale(1);
}

.gallery-close,
.gallery-nav {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: background-color 0.4s ease, transform 0.4s ease;
}

.gallery-close:hover,
.gallery-nav:hover {
  background: rgba(255, 255, 255, 0.20);
}

.gallery-close {
  top: 24px;
  right: 28px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 18px;
}

.gallery-close:hover {
  transform: rotate(4deg) scale(1.04);
}

.gallery-nav {
  top: 50%;
  width: 54px;
  height: 70px;
  margin-top: -35px;
  border-radius: 12px;
  font-size: 25px;
}

.gallery-prev {
  left: 25px;
}

.gallery-next {
  right: 25px;
}

.gallery-nav:hover {
  transform: scale(1.04);
}

body.gallery-lock {
  overflow: hidden;
}

/* Tablet */
@media (max-width: 1199.98px) {
  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Small tablet */
@media (max-width: 991.98px) {
  .portfolio-gallery {
    padding: 10px 0;
  }

  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 15px;
  }

  .gallery-lightbox {
    padding: 55px 65px;
  }

  .gallery-nav {
    width: 48px;
    height: 60px;
  }

  .gallery-prev {
    left: 12px;
  }

  .gallery-next {
    right: 12px;
  }
}

/* Mobile */
@media (max-width: 767.98px) {
  .portfolio-gallery {
    padding: 45px 0;
  }

  .gallery-filters {
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 25px;
  }

  .gallery-filter {
    min-width: 0;
    padding: 10px 16px;
    font-size: 13px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .gallery-lightbox {
    padding: 60px 15px;
  }

  .gallery-lightbox-stage {
    width: 100%;
    height: 75vh;
  }

  .gallery-close {
    top: 14px;
    right: 14px;
    width: 42px;
    height: 42px;
  }

  .gallery-nav {
    width: 44px;
    height: 54px;
    margin-top: -27px;
  }

  .gallery-prev {
    left: 8px;
  }

  .gallery-next {
    right: 8px;
  }
}

/* Very small mobile */
@media (max-width: 430px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .gallery-filter,
  .gallery-item,
  .gallery-item img,
  .gallery-lightbox,
  .gallery-lightbox-stage img,
  .gallery-close,
  .gallery-nav {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
