/**
 * GALLERY - GOMALOR
 * Sistema de galería dinámico con lightbox profesional estilo WhatsApp
 */

/* ============================================
   SECCIÓN GALERÍA
   ============================================ */

.gallery {
  background-color: var(--color-white);
  padding: var(--space-3xl) 0;
}

/* ============================================
   FILTROS
   ============================================ */

.gallery__filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-2xl);
}

.gallery-filter {
  padding: 0.625rem 1.5rem;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font-primary);
  color: var(--color-gray-dark);
  background-color: var(--color-white);
  border: 2px solid var(--color-gray-light);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing-smooth);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
  overflow: hidden;
}

.gallery-filter::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(45, 80, 22, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.4s, height 0.4s;
}

.gallery-filter:hover::before {
  width: 300px;
  height: 300px;
}

.gallery-filter:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.gallery-filter.active {
  color: var(--color-white);
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.gallery-filter:active {
  transform: translateY(0);
}

/* ============================================
   GRID DE GALERÍA
   ============================================ */

.gallery__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
  margin-top: var(--space-xl);
}

@media (min-width: 768px) {
  .gallery__grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
  }
}

@media (min-width: 1024px) {
  .gallery__grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1280px) {
  .gallery__grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ============================================
   GALLERY ITEM
   ============================================ */

.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  cursor: pointer;
  aspect-ratio: 4 / 3;
  background-color: var(--color-gray-lightest);
  transition: all var(--duration-normal) var(--easing-smooth);
}

.gallery-item:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

/* Estados de filtro */
.gallery-item.hidden {
  display: none;
}

.gallery-item.visible {
  animation: fadeInScale var(--duration-normal) var(--easing-smooth);
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================
   GALLERY ITEM INNER
   ============================================ */

.gallery-item-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ============================================
   THUMBNAIL
   ============================================ */

.gallery-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform var(--duration-slow) var(--easing-smooth);
}

/* Lazy loading effect */
.gallery-image.lazy {
  filter: blur(10px);
  transform: scale(1.1);
  background: linear-gradient(
    90deg,
    var(--color-gray-lightest) 0%,
    var(--color-gray-lighter) 50%,
    var(--color-gray-lightest) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.gallery-image.loaded {
  filter: blur(0);
  transform: scale(1);
  animation: none;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.gallery-item:hover .gallery-image {
  transform: scale(1.1);
}

/* ============================================
   OVERLAY
   ============================================ */

.gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay-dark-heavy);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--easing-smooth);
  pointer-events: none;
}

.gallery-item:hover .gallery-overlay {
  opacity: 1;
}

.gallery-zoom-icon,
.gallery-play-icon {
  font-size: var(--text-4xl);
  color: var(--color-white);
  transform: scale(0.5);
  transition: transform var(--duration-normal) var(--easing-bounce);
}

.gallery-item:hover .gallery-zoom-icon,
.gallery-item:hover .gallery-play-icon {
  transform: scale(1);
}

/* ============================================
   LIGHTBOX - ESTILO WHATSAPP
   ============================================ */

.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.97);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-normal) var(--easing-smooth);
}

.lightbox.active {
  opacity: 1;
  visibility: visible;
}

/* ============================================
   LIGHTBOX HEADER
   ============================================ */

.lightbox-header {
  position: relative;
  padding: 1rem 1.5rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.lightbox-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--color-white);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
}

.lightbox-brand svg {
  width: 24px;
  height: 24px;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lightbox-btn {
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: none;
  border-radius: 50%;
  color: var(--color-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-normal) var(--easing-smooth);
}

.lightbox-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.lightbox-btn svg {
  width: 20px;
  height: 20px;
}

.lightbox-close {
  font-size: var(--text-2xl);
  line-height: 1;
}

.lightbox-close:hover {
  transform: rotate(90deg) scale(1.1);
}

/* ============================================
   LIGHTBOX CONTENT
   ============================================ */

.lightbox-content {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow: hidden;
}

.lightbox-image-container {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: lightboxZoomIn var(--duration-normal) var(--easing-smooth);
}

@keyframes lightboxZoomIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.lightbox-image {
  max-width: 100%;
  max-height: 70vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
}

/* Loading state */
.lightbox-image.loading {
  opacity: 0.3;
}

.lightbox-content.loading::after {
  content: '';
  position: absolute;
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Video container */
.lightbox-video-container {
  position: relative;
  width: 100%;
  max-width: 1200px;
  aspect-ratio: 16 / 9;
  display: none;
}

.lightbox-video-container.active {
  display: block;
}

.lightbox-video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--radius-md);
}

/* ============================================
   NAVIGATION ARROWS
   ============================================ */

.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: var(--color-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-normal) var(--easing-smooth);
  z-index: 10;
}

.lightbox-prev {
  left: 2rem;
}

.lightbox-next {
  right: 2rem;
}

.lightbox-prev:hover,
.lightbox-next:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-50%) scale(1.1);
}

.lightbox-prev:active,
.lightbox-next:active {
  transform: translateY(-50%) scale(0.95);
}

.lightbox-prev svg,
.lightbox-next svg {
  width: 24px;
  height: 24px;
}

/* ============================================
   LIGHTBOX FOOTER - ESTILO WHATSAPP
   ============================================ */

.lightbox-footer {
  position: relative;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
  max-height: 30vh;
  overflow-y: auto;
}

.lightbox-caption {
  color: var(--color-white);
  font-size: var(--text-base);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.lightbox-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--text-sm);
}

.lightbox-meta-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lightbox-meta-item svg {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

.lightbox-counter {
  margin-left: auto;
  padding: 0.25rem 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  font-weight: var(--weight-medium);
}

/* ============================================
   RESPONSIVE - TABLET
   ============================================ */

@media (max-width: 1023px) {
  .gallery__filters {
    gap: var(--space-xs);
  }
  
  .gallery-filter {
    padding: 0.5rem 1rem;
    font-size: var(--text-xs);
  }
  
  .lightbox-prev,
  .lightbox-next {
    width: 45px;
    height: 45px;
  }
  
  .lightbox-prev {
    left: 1rem;
  }
  
  .lightbox-next {
    right: 1rem;
  }
  
  .lightbox-content {
    padding: 1rem;
  }
  
  .lightbox-image {
    max-height: 60vh;
  }
}

/* ============================================
   RESPONSIVE - MÓVIL
   ============================================ */

@media (max-width: 767px) {
  .gallery__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-xs);
  }
  
  .gallery__filters {
    gap: 0.5rem;
  }
  
  .gallery-filter {
    padding: 0.5rem 0.875rem;
    font-size: 0.625rem;
  }
  
  .gallery-zoom-icon,
  .gallery-play-icon {
    font-size: var(--text-2xl);
  }
  
  /* Lightbox móvil */
  .lightbox-header {
    padding: 0.75rem 1rem;
  }
  
  .lightbox-brand {
    font-size: var(--text-base);
  }
  
  .lightbox-btn {
    width: 36px;
    height: 36px;
  }
  
  .lightbox-content {
    padding: 0.5rem;
  }
  
  .lightbox-image {
    max-height: 50vh;
    border-radius: var(--radius-sm);
  }
  
  .lightbox-prev,
  .lightbox-next {
    width: 40px;
    height: 40px;
  }
  
  .lightbox-prev {
    left: 0.5rem;
  }
  
  .lightbox-next {
    right: 0.5rem;
  }
  
  .lightbox-prev svg,
  .lightbox-next svg {
    width: 20px;
    height: 20px;
  }
  
  .lightbox-footer {
    padding: 1rem;
    max-height: 40vh;
  }
  
  .lightbox-caption {
    font-size: var(--text-sm);
  }
  
  .lightbox-meta {
    gap: 1rem;
    font-size: 0.75rem;
  }
  
  .lightbox-counter {
    margin-left: 0;
    width: 100%;
    text-align: center;
    margin-top: 0.5rem;
  }
}

/* ============================================
   ACCESIBILIDAD
   ============================================ */

.gallery-item:focus {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.gallery-filter:focus,
.lightbox-btn:focus,
.lightbox-prev:focus,
.lightbox-next:focus {
  outline: 2px solid var(--color-white);
  outline-offset: 2px;
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .gallery-item,
  .gallery-image,
  .gallery-zoom-icon,
  .gallery-filter,
  .lightbox,
  .lightbox-image-container {
    transition: none;
    animation: none;
  }
  
  .gallery-item:hover {
    transform: none;
  }
  
  .lightbox-close:hover {
    transform: none;
  }
  
  .lightbox-prev:hover,
  .lightbox-next:hover {
    transform: translateY(-50%);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .gallery__filters,
  .gallery-overlay,
  .lightbox {
    display: none;
  }
  
  .gallery__grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
  
  .gallery-item {
    page-break-inside: avoid;
    border: 1px solid var(--color-gray-light);
  }
  
  .gallery-item:hover {
    transform: none;
  }
}