/* Custom Image Gallery Styles */
.custom-gallery-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  overflow: hidden;
}


.custom-gallery-overlay.show {
  opacity: 1;
}

.gallery-container {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  transform: scale(0.8);
  transition: transform 0.3s ease;
  overflow: visible;
}

.custom-gallery-overlay.show .gallery-container {
  transform: scale(1);
}

.gallery-image-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
  overflow: hidden;
  width: 100%;
  height: 80vh;
  min-height: 300px;
  isolation: isolate;
  background: rgba(0, 0, 0, 0.3);
}

.gallery-main-image {
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  will-change: transform, opacity;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: pan-y pinch-zoom;
  transition: opacity 0.2s ease;
  z-index: 3;
}

.gallery-main-image:not([src]),
.gallery-main-image[src=""] {
  opacity: 0;
  visibility: hidden;
}

.gallery-next-image {
  z-index: 1;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0s;
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  position: absolute;
}

.gallery-next-image:not([src]),
.gallery-next-image[src=""] {
  opacity: 0;
  visibility: hidden;
}

/* Error placeholder for failed image loads */
.gallery-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: 600px;
  max-height: 70vh;
  background: rgba(255, 255, 255, 0.1);
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.2rem;
  text-align: center;
  padding: 2rem;
  z-index: 3;
}

.gallery-image-placeholder svg {
  width: 80px;
  height: 80px;
  opacity: 0.5;
  margin-bottom: 1rem;
}

/* Ensure counter and close button stay in position */
.gallery-counter,
.gallery-close {
  position: absolute !important;
}

.gallery-main-image.error-state {
  display: none;
}

.gallery-next-image.error-state {
  display: none;
}

.gallery-counter {
  position: absolute;
  top: -2.5rem;
  left: 0rem;
  color: black;
  font-size: 1rem;
  font-weight: bold;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.25rem 1rem;
  border-radius: 25px;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.gallery-close {
  position: absolute;
  top: -2.5rem;
  right: 0.25rem;
  background: rgba(255, 255, 255, 0.9);
  color: black;
  border: none;
  font-size: 1.5rem;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  max-width: 2rem;
  max-height: 2rem;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.gallery-close:focus {
  outline: none;
}

.gallery-close:active {
  background: rgba(255, 255, 255, 0.9);
  -webkit-tap-highlight-color: transparent;
}

.gallery-close:hover {
  background: rgba(255, 0, 0, 0.8);
  color: white;
  transform: scale(1.1);
}

.gallery-prev, .gallery-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: white;
  border: none;
  font-size: 3rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.gallery-prev:focus,
.gallery-next:focus {
  outline: none;
}

.gallery-prev:active,
.gallery-next:active {
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.gallery-prev {
  left: -3rem;
}

.gallery-next {
  right: -3rem;
}

.gallery-prev:hover, .gallery-next:hover {
  background: transparent;
  transform: translateY(-50%) scale(1.1);
}

.gallery-prev:disabled, .gallery-next:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.gallery-prev:disabled:hover, .gallery-next:disabled:hover {
  transform: translateY(-50%) scale(1);
  background: rgba(0, 0, 0, 0.7);
}

/* Loading animation */
.gallery-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid white;
  border-radius: 50%;
  animation: gallery-spin 1s linear infinite;
}

@keyframes gallery-spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .gallery-container {
    max-width: 95%;
    max-height: 95%;
  }
  
  .gallery-image-container {
    height: 70vh;
    min-height: 250px;
  }
  
  .gallery-main-image {
    max-height: 70vh;
  }
  
  .gallery-next-image {
    max-height: 70vh !important;
    max-width: 100% !important;
  }
  
  .gallery-main-image,
  .gallery-next-image {
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
  }
  
  .gallery-close {
    width: 2rem !important;
    height: 2rem !important;
    min-width: 2rem !important;
    min-height: 2rem !important;
    max-width: 2rem !important;
    max-height: 2rem !important;
    padding: 0 !important;
    aspect-ratio: 1 / 1;
  }
  
  .gallery-prev {
    left: 0rem !important;
  }
  
  .gallery-next {
    right: 0rem !important;
  }
  
  .gallery-prev:hover,
  .gallery-next:hover,
  .gallery-prev:active,
  .gallery-next:active {
    background: transparent !important;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .gallery-prev:hover,
  .gallery-next:hover {
    transform: translateY(-50%) scale(1);
    background: transparent;
  }
  
  .gallery-prev:active,
  .gallery-next:active {
    background: transparent !important;
  }
  
  .gallery-close:hover {
    transform: scale(1);
    background: rgba(255, 255, 255, 0.9);
  }
  
  .gallery-close:active {
    background: rgba(255, 255, 255, 0.9) !important;
  }
}
