/* ==========================================================================
   KROCHET - Estilos Específicos para la Galería de Creaciones
   Optimizado para móviles (2 columnas), grid fluido, filtros y lightbox táctil
   ========================================================================== */

/* Encabezado de la página de Galería */
.gallery-hero {
  padding: calc(var(--space-2xl) + 20px) 0 var(--space-xl);
  background: linear-gradient(180deg, var(--color-surface-warm) 0%, var(--color-bg) 100%);
  text-align: center;
  border-bottom: 1px solid var(--color-border-subtle);
}

.gallery-hero-inner {
  max-width: 780px;
  margin: 0 auto;
}

.gallery-hero .section-title {
  font-size: clamp(1.85rem, 4vw, 2.75rem);
  margin: var(--space-sm) 0 var(--space-md);
  color: var(--color-text-main);
}

.gallery-hero .section-subtitle {
  font-size: 1.05rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: var(--space-lg);
}

/* Barra de Controles: Buscador y Filtros */
.gallery-controls-section {
  position: sticky;
  top: 72px; /* Altura del header fijo */
  z-index: 50;
  background-color: rgba(255, 252, 249, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-subtle);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.02);
}

.gallery-controls-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* Buscador */
.gallery-search-wrap {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.gallery-search-input {
  width: 100%;
  padding: 12px 44px 12px 42px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  background-color: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--color-text-main);
  transition: all var(--transition-fast);
  outline: none;
}

.gallery-search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 150, 0.15);
}

.gallery-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-text-subtle);
  pointer-events: none;
}

.gallery-search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-subtle);
  cursor: pointer;
  padding: 4px;
  display: none;
  border-radius: var(--radius-full);
}

.gallery-search-clear:hover {
  color: var(--color-text-main);
}

/* Pestañas de Filtros (Scroll horizontal táctil) */
.gallery-filter-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: none; /* Firefox */
  -webkit-overflow-scrolling: touch;
  justify-content: flex-start;
}

@media (min-width: 768px) {
  .gallery-filter-tabs {
    justify-content: center;
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

.gallery-filter-tabs::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.gallery-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.gallery-tab-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
  background-color: var(--color-primary-light);
}

.gallery-tab-btn.active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(0, 168, 150, 0.25);
}

.gallery-tab-count {
  font-size: 0.78rem;
  opacity: 0.85;
  background-color: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 10px;
}

.gallery-tab-btn.active .gallery-tab-count {
  background-color: rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

/* Barra de Estado / Contador */
.gallery-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) 0 var(--space-xs);
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* Cuadrícula de Galería */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 2 columnas obligadas en móvil */
  gap: 12px;
  padding: var(--space-md) 0 var(--space-2xl);
}

@media (min-width: 640px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }
}

@media (min-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 22px;
  }
}

/* Tarjeta de Producto */
.gallery-card {
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-light);
}

.gallery-card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--color-surface-soft);
  overflow: hidden;
}

.gallery-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
  display: block;
}

.gallery-card:hover .gallery-card-img {
  transform: scale(1.05);
}

/* Insignias Flotantes sobre la Imagen */
.gallery-badge-category {
  position: absolute;
  top: 8px;
  left: 8px;
  background-color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  color: var(--color-primary-dark);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

.gallery-badge-photos {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background-color: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(4px);
  color: #FFFFFF;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}

/* Cuerpo de la Tarjeta */
.gallery-card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.gallery-card-title {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text-main);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (min-width: 768px) {
  .gallery-card-title {
    font-size: 1.05rem;
  }
}

.gallery-card-actions {
  margin-top: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}

.gallery-card-wa-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: var(--color-whatsapp-light);
  color: var(--color-whatsapp-dark);
  border: 1px solid rgba(37, 211, 102, 0.3);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.gallery-card-wa-btn:hover {
  background-color: var(--color-whatsapp);
  color: #FFFFFF;
  border-color: var(--color-whatsapp);
}

.gallery-card-wa-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Estado Vacío (Sin Resultados) */
.gallery-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-md);
  background-color: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1.5px dashed var(--color-border);
  grid-column: 1 / -1;
  max-width: 600px;
  margin: 0 auto;
}

.gallery-empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
}

.gallery-empty-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--color-text-main);
  margin-bottom: var(--space-xs);
}

.gallery-empty-text {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin-bottom: var(--space-lg);
}

/* Botón "Cargar Más" */
.gallery-load-more-wrap {
  text-align: center;
  padding: var(--space-lg) 0 var(--space-3xl);
}

.gallery-load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background-color: var(--color-surface);
  color: var(--color-primary-dark);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.gallery-load-more-btn:hover {
  background-color: var(--color-primary);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(0, 168, 150, 0.25);
  transform: translateY(-2px);
}

/* ==========================================================================
   VISOR MODAL / LIGHTBOX
   Diseñado específicamente para interacción touch móvil y zoom nítido
   ========================================================================== */

.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background-color: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: var(--space-sm);
}

.lightbox-modal.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-dialog {
  background-color: var(--color-surface);
  border-radius: var(--radius-xl);
  overflow: hidden;
  width: 100%;
  max-width: 680px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  transform: scale(0.96);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.lightbox-modal.active .lightbox-dialog {
  transform: scale(1);
}

/* Botón Cerrar */
.lightbox-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--color-border);
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.lightbox-close-btn:hover {
  background-color: var(--color-surface);
  color: var(--color-accent);
  transform: scale(1.08);
}

/* Contenedor de la Imagen Principal del Lightbox */
.lightbox-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--color-surface-warm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

@media (min-height: 800px) and (min-width: 640px) {
  .lightbox-stage {
    aspect-ratio: 4 / 3.8;
  }
}

.lightbox-main-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

/* Flechas de Navegación del Lightbox */
.lightbox-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid var(--color-border);
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.lightbox-nav-btn:hover {
  background-color: #FFFFFF;
  color: var(--color-primary);
  transform: translateY(-50%) scale(1.08);
}

.lightbox-nav-prev {
  left: 12px;
}

.lightbox-nav-next {
  right: 12px;
}

/* Tiras de Miniaturas en el Lightbox (si hay > 1 foto) */
.lightbox-thumbs-strip {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background-color: var(--color-surface-soft);
  overflow-x: auto;
  border-bottom: 1px solid var(--color-border-subtle);
  scrollbar-width: thin;
}

.lightbox-thumb-item {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  opacity: 0.6;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.lightbox-thumb-item.active {
  border-color: var(--color-primary);
  opacity: 1;
  transform: scale(1.05);
}

.lightbox-thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Panel de Información del Lightbox */
.lightbox-info {
  padding: 16px 20px 20px;
  overflow-y: auto;
}

.lightbox-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.lightbox-category-tag {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  background-color: var(--color-primary-light);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

.lightbox-counter {
  font-size: 0.8rem;
  color: var(--color-text-subtle);
  font-weight: 600;
}

.lightbox-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-main);
  line-height: 1.3;
  margin-bottom: 10px;
}

.lightbox-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.lightbox-tag {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background-color: var(--color-surface-soft);
  padding: 2px 8px;
  border-radius: 4px;
}

/* Botón WhatsApp en Lightbox */
.lightbox-wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  background-color: var(--color-whatsapp);
  color: #FFFFFF;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.35);
  transition: all var(--transition-fast);
}

.lightbox-wa-btn:hover {
  background-color: var(--color-whatsapp-dark);
  box-shadow: 0 6px 18px rgba(37, 211, 102, 0.45);
  transform: translateY(-2px);
}

.lightbox-wa-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* ==========================================================================
   AJUSTES: tags visibles en tarjetas, accesibilidad y rendimiento móvil
   ========================================================================== */

/* Tags en la tarjeta (máx. 3, una sola línea, sin romper el alto de la grilla) */
.gallery-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  max-height: 2.9em; /* máx. 2 filas */
  overflow: hidden;
}

.gallery-card-tag {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--color-text-muted);
  background-color: var(--color-surface-soft);
  border: 0;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.gallery-card-tag:hover,
.gallery-card-tag:focus-visible {
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
}

/* Tags del visor: ahora son botones (filtran la galería) */
button.lightbox-tag {
  font-family: var(--font-sans);
  border: 0;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

button.lightbox-tag:hover,
button.lightbox-tag:focus-visible {
  background-color: var(--color-primary-light);
  color: var(--color-primary-dark);
}

/* Foco visible para teclado */
.gallery-card-img-wrap:focus-visible,
.lightbox-thumb-item:focus-visible,
.gallery-card-tag:focus-visible,
.lightbox-tag:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.gallery-card-img-wrap { cursor: pointer; }

/* Renderizado diferido de tarjetas fuera de pantalla (menos trabajo en móviles) */
.gallery-card {
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
}

/* Miniatura del visor con tamaño fijo para evitar saltos de layout */
.lightbox-thumb-item { background-color: var(--color-surface-soft); }

@media (prefers-reduced-motion: reduce) {
  .gallery-card,
  .gallery-card-img,
  .lightbox-modal,
  .lightbox-dialog {
    transition: none;
  }
  .gallery-card:hover { transform: none; }
  .gallery-card:hover .gallery-card-img { transform: none; }
}
