/* ============================================
   QUINTA P.L. - GALLERY SECTION
   Galería con lightbox responsive
   ============================================ */

.gallery {
  background-color: var(--color-white);
}

/* === FILTROS DE CATEGORÍA === */

.gallery-filters {
  margin-top: var(--spacing-xl);
  position: sticky;
  top: 60px;
  z-index: 100;
  background: var(--color-white);
  padding: var(--spacing-md) 0;
  margin-bottom: var(--spacing-2xl);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.gallery-filters-desktop {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--spacing-xs);
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--color-gray-50);
  border-radius: var(--radius-md);
}

.gallery-filters-mobile {
  display: none;
}

.gallery-filter {
  padding: 0.6rem 1rem;
  background: var(--color-white);
  border: 2px solid var(--color-gray-300);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-gray-600);
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  text-align: center;
}

.gallery-filter:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  /* Optimizar animaciones con GPU */
  will-change: transform;
}

.gallery-filter.active {
  background: var(--color-white);
  color: var(--color-dark);
  font-weight: var(--font-weight-bold);
  border-color: var(--color-primary);
  border-width: 3px;
  box-shadow: 0 2px 6px rgba(45, 122, 62, 0.2);
}

/* Dropdown móvil */
.gallery-filter-dropdown {
  width: 100%;
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-dark);
  background: var(--color-white);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232D7A3E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--spacing-md) center;
  padding-right: 3rem;
}

.gallery-filter-dropdown:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-lg);
}

/* === BOTÓN VER MÁS === */

.gallery-load-more {
  display: flex;
  justify-content: center;
  margin-top: var(--spacing-2xl);
  padding: var(--spacing-lg) 0;
}

.gallery-load-more .btn {
  min-width: 250px;
  font-weight: var(--font-weight-semibold);
  transition: all var(--transition-base);
}

.gallery-load-more .btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.load-more-count {
  opacity: 0.8;
  font-weight: var(--font-weight-normal);
  font-size: 0.9em;
}

/* === CONTADOR DE IMÁGENES === */

.gallery-counter {
  text-align: center;
  margin-top: var(--spacing-xl);
  padding: var(--spacing-md);
  font-size: var(--font-size-base);
  color: var(--color-gray-600);
  font-weight: var(--font-weight-medium);
}

#imageCountCurrent {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
}

#imageCountTotal {
  font-weight: var(--font-weight-semibold);
  color: var(--color-gray-700);
}

/* === GRID DE GALERÍA === */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--spacing-lg);
  margin-top: var(--spacing-lg);
}

.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  aspect-ratio: 4/3;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  /* Optimización de rendering */
  contain: layout style paint;
  content-visibility: auto;
  opacity: 1;
}

.gallery-item.hidden {
  display: none;
}

.gallery-item:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-xl);
  /* Optimizar transforms con GPU */
  will-change: transform;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
  /* Forzar aceleración por GPU */
  transform: translateZ(0);
  backface-visibility: hidden;
}

.gallery-item:hover img {
  transform: scale(1.1) translateZ(0);
}

/* Overlay al hacer hover */
.gallery-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(45, 122, 62, 0.7),
    rgba(200, 16, 46, 0.7)
  );
  opacity: 0;
  transition: opacity var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item:hover::after {
  opacity: 1;
}

/* Indicador de zoom */
.gallery-item::before {
  content: '+';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-white);
  z-index: 2;
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.gallery-item:hover::before {
  opacity: 1;
}

/* === MODAL LIGHTBOX === */

.gallery-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl);
}

.gallery-modal.active {
  display: flex;
  animation: fadeIn 0.3s ease-out;
}

.gallery-modal-image {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2xl);
  animation: scaleIn 0.3s ease-out;
}

/* Botón cerrar */
.gallery-modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border: 2px solid var(--color-white);
  color: var(--color-white);
  font-size: var(--font-size-3xl);
  line-height: 1 !important;
  font-family: Arial, sans-serif;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all var(--transition-base);
  z-index: var(--z-modal + 1);
  padding: 0 !important;
  margin: 0;
}

.gallery-modal-close:hover {
  background: var(--color-white);
  color: var(--color-dark);
  transform: rotate(90deg);
}

/* Botones de navegación */
.gallery-modal-prev,
.gallery-modal-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border: 2px solid var(--color-white);
  color: var(--color-white);
  font-size: var(--font-size-4xl);
  line-height: 1 !important;
  font-family: Arial, sans-serif;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  cursor: pointer;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center;
  transition: all var(--transition-base);
  z-index: var(--z-modal + 1);
  padding: 0 !important;
  margin: 0;
}

/* SVG inside arrows - scale with font size and center */
.gallery-modal-prev svg,
.gallery-modal-next svg {
  width: 1em;
  height: 1em;
  display: block;
  /* Ensure stroke uses current text color */
  stroke: currentColor;
}

.gallery-modal-prev {
  left: 20px;
}

.gallery-modal-next {
  right: 20px;
}

.gallery-modal-prev:hover,
.gallery-modal-next:hover {
  background: var(--color-white);
  color: var(--color-dark);
  transform: translateY(-50%) scale(1.1);
}

/* Caption del modal - OCULTO */
.gallery-modal-caption {
  display: none;
}

/* === RESPONSIVE === */

@media (max-width: 1024px) {
  .gallery-filters-desktop {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .gallery-filter {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--spacing-md);
  }
}

@media (max-width: 768px) {
  /* Cambiar a dropdown en móvil */
  .gallery-filters {
    top: 60px;
    padding: var(--spacing-md) var(--spacing-lg);
  }

  .gallery-filters-desktop {
    display: none;
  }

  .gallery-filters-mobile {
    display: block;
  }

  .gallery-load-more .btn {
    min-width: 200px;
    font-size: var(--font-size-sm);
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-sm);
  }

  .gallery-modal {
    padding: var(--spacing-md);
  }

  .gallery-modal-image {
    max-width: 95%;
    max-height: 85%;
  }

  .gallery-modal-close {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    font-size: var(--font-size-2xl);
  }

  .gallery-modal-prev,
  .gallery-modal-next {
    width: 50px;
    height: 50px;
    font-size: var(--font-size-3xl);
  }

  .gallery-modal-prev {
    left: 10px;
  }

  .gallery-modal-next {
    right: 10px;
  }

  .gallery-modal-caption {
    font-size: 0.75rem;
    padding: var(--spacing-sm) var(--spacing-md);
    bottom: 20px;
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .gallery-modal-prev,
  .gallery-modal-next {
    bottom: 20px;
    top: auto;
    transform: none;
  }

  .gallery-modal-prev {
    left: 50%;
    margin-left: -60px;
  }

  .gallery-modal-next {
    right: 50%;
    margin-right: -60px;
  }

  .gallery-modal-prev:hover,
  .gallery-modal-next:hover {
    transform: scale(1.1);
  }
}

/* Lazy loading placeholder */
.gallery-item img[data-src] {
  filter: blur(10px);
  transition: filter var(--transition-slow);
}

.gallery-item img.loaded {
  filter: blur(0);
}

/* Loading spinner para imágenes */
.gallery-item.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-gray-300);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
