/*---------------------------
    Gallery Area Styles 
-----------------------------*/

.rn-gallery-area {
  padding: 120px 0;
}

/* Masonry Layout using Masonry.js */
.gallery-masonry {
  position: relative;
  width: 100%;
  padding: 0;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  min-height: 500px;
}

.gallery-item {
  display: block;
  width: calc(25% - 15px);
  margin-bottom: 20px;
  background: var(--background-color-1);
  box-shadow: var(--shadow-1);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  visibility: visible;
  opacity: 1;
  will-change: opacity, transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
  /* Hardware acceleration */
  contain: layout style paint;
  /* Optimize rendering */
}

.gallery-item a {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  object-fit: cover;
  object-position: center;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  transition: transform 0.3s ease-in-out, filter 0.3s ease-in-out;
  transform-origin: center center;
  transform: scale(1) translateZ(0);
  /* Hardware acceleration */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, filter;
  filter: brightness(1);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.gallery-item:hover img {
  transform: scale(1.03);
  filter: brightness(1.08);
}

/* Gallery Overlay with Gradient */
.gallery-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  padding: 15px 15px 15px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0.55) 40%, rgba(0, 0, 0, 0.2) 70%, transparent 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
  pointer-events: none;
  border-radius: 0 0 8px 8px;
}

.gallery-caption {
  color: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  margin: 0;
  padding: 0;
  text-align: left;
  font-weight: 400;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 2.8em;
  white-space: normal;
  word-wrap: break-word;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  filter: blur(0);
}

/* Images should fill their containers completely */
.gallery-item img.loaded {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 10 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
}

/* Responsive Breakpoints */
/* 3 columns for 780px - 1200px */
@media only screen and (min-width: 780px) and (max-width: 1199px) {
  .gallery-item {
    width: calc(33.333% - 13.33px) !important;
  }
}

/* 2 columns for 576px - 779px */
@media only screen and (min-width: 576px) and (max-width: 779px) {
  .gallery-item {
    width: calc(50% - 10px) !important;
  }
}

/* 1 column for below 576px */
@media only screen and (max-width: 575px) {
  .gallery-item {
    width: 100% !important;
  }
}

/* Lazy Loading Styles */
.lazy-image {
  opacity: 0;
  transition: opacity 0.4s ease-in-out;
  will-change: opacity;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  z-index: 1;
  visibility: hidden;
}

.lazy-image.loaded {
  opacity: 1 !important;
  display: block !important;
  visibility: visible !important;
  z-index: 10 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

.lazy-image.error {
  background: #2a2d32;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 14px;
}

/* Skeleton Loader */
.skeleton-loader {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
      #2a2d32 0%,
      #32363b 50%,
      #2a2d32 100%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 10px;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  z-index: 0;
  transition: opacity 0.2s ease;
}

.skeleton-loader[style*="display: none"],
.skeleton-loader[style*="display:none"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  z-index: -1 !important;
  pointer-events: none !important;
}

.skeleton-loader[style*="opacity: 0"],
.skeleton-loader[data-removed="true"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  z-index: -1 !important;
  pointer-events: none !important;
}

.skeleton-loader::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.1),
      transparent);
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

@keyframes skeleton-shimmer {
  0% {
    left: -100%;
  }

  100% {
    left: 100%;
  }
}

/* Skeleton heights based on image height classes */
.skeleton-small {
  min-height: 280px;
  height: 280px;
}

.skeleton-medium {
  min-height: 380px;
  height: 380px;
}

.skeleton-large {
  min-height: 480px;
  height: 480px;
}

.skeleton-xlarge {
  min-height: 580px;
  height: 580px;
}

/* Loading Spinner */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.gallery-loading {
  width: 100%;
  text-align: center;
  padding: 40px 0;
  grid-column: 1 / -1;
}

.gallery-item-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: var(--background-color-1);
  border-radius: 10px;
}

/* Optimize image rendering */
.gallery-item img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Ensure skeleton and image are properly layered */
.gallery-item a {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

/* Set link height based on gallery item height class */
.gallery-item.height-small a {
  height: 280px;
}

.gallery-item.height-medium a {
  height: 380px;
}

.gallery-item.height-large a {
  height: 480px;
}

.gallery-item.height-xlarge a {
  height: 580px;
}

.gallery-item a .skeleton-loader {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  transition: opacity 0.4s ease-in-out;
  width: 100%;
}

.gallery-item a .lazy-image {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
}

.gallery-item a .lazy-image.loaded {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 10 !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* Reduce repaints on scroll */
.gallery-masonry {
  contain: layout style paint;
}

/* Enhanced stagger animation support */
.gallery-item.stagger-animate {
  opacity: 0;
  transform: translateY(30px) scale(0.95) translateZ(0);
  transition: none;
  will-change: opacity, transform;
}

.gallery-item.stagger-animate.active {
  transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  opacity: 1;
  transform: translateY(0) scale(1) translateZ(0);
}

/* Prevent flickering during animations */
.gallery-item img,
.gallery-item .skeleton-loader,
.gallery-item .gallery-overlay {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
}

/* Optimize image loading transitions */
.gallery-item img.loaded {
  animation: imageFadeIn 0.4s ease-out forwards;
}

@keyframes imageFadeIn {
  from {
    opacity: 0;
    transform: scale(1.02) translateZ(0);
  }

  to {
    opacity: 1;
    transform: scale(1) translateZ(0);
  }
}