/*
 * ═══════════════════════════════════════════════════════════════════
 * cards.css — Polish para las grillas de productos
 * ═══════════════════════════════════════════════════════════════════
 *
 * Tailwind CDN cubre el 95% del styling, pero algunos refinamientos
 * (animaciones complejas, gradientes especificos, micro-interacciones)
 * son mas claros en CSS plano que en clases utility largas.
 *
 * Solo afecta a contenedores .product-grid (#recientesGrid y
 * #productsGrid). Las clases existentes en las cards de app.js NO
 * necesitan cambios — esto las potencia desde afuera.
 *
 * Cambios principales:
 *   - Fade-up con stagger al cargar la grilla
 *   - Imagen del producto: zoom suave en hover de la card
 *   - Card hover: shadow lift mas dramatico + borde rojo soft
 *   - Skeleton loader animado para estado intermedio
 *   - "Stock bajo" pulsa sutil para llamar atencion
 */

/* ─────────────────────────────────────────────────────────────
   GRID CONTAINER
   ─────────────────────────────────────────────────────────── */

/* Aire entre cards: mas en desktop, menos en mobile (para
   maximizar el numero de productos por pantalla en mobile). */
.product-grid {
  --card-gap: 1.25rem;
}

@media (min-width: 1024px) {
  .product-grid {
    --card-gap: 1.5rem;
  }
}

/* ─────────────────────────────────────────────────────────────
   STAGGER FADE-UP AL APARECER LAS CARDS
   ─────────────────────────────────────────────────────────── */

/* Las cards se inyectan via innerHTML, asi que animamos con CSS
   puro (sin JS). Damos delays escalonados a los primeros ~12 items
   para que entren onda cascada. Despues del 12 todas iguales —
   no queremos delays acumulativos de 2s+ en pantallas largas. */

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.product-grid > article {
  animation: cardEnter 350ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.product-grid > article:nth-child(1)  { animation-delay: 0ms; }
.product-grid > article:nth-child(2)  { animation-delay: 40ms; }
.product-grid > article:nth-child(3)  { animation-delay: 80ms; }
.product-grid > article:nth-child(4)  { animation-delay: 120ms; }
.product-grid > article:nth-child(5)  { animation-delay: 160ms; }
.product-grid > article:nth-child(6)  { animation-delay: 200ms; }
.product-grid > article:nth-child(7)  { animation-delay: 240ms; }
.product-grid > article:nth-child(8)  { animation-delay: 280ms; }
.product-grid > article:nth-child(9)  { animation-delay: 320ms; }
.product-grid > article:nth-child(10) { animation-delay: 360ms; }
.product-grid > article:nth-child(11) { animation-delay: 400ms; }
.product-grid > article:nth-child(12) { animation-delay: 440ms; }

/* ─────────────────────────────────────────────────────────────
   CARD HOVER — sombra mas dramatica + borde rojo soft
   ─────────────────────────────────────────────────────────── */

/* Tailwind ya tiene hover:shadow-xl hover:-translate-y-1 en las
   cards. Lo potenciamos aqui sin pelear con esas clases. */
.product-grid > article {
  transition:
    transform 280ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 280ms ease-out,
    border-color 280ms ease-out;
}

.product-grid > article:hover {
  /* Borde rojo soft + sombra con tinte rojo */
  border-color: #fca5a5 !important;
  box-shadow:
    0 12px 32px -8px rgba(147, 0, 11, 0.18),
    0 4px 16px -4px rgba(147, 0, 11, 0.08);
}

/* ─────────────────────────────────────────────────────────────
   IMAGEN — zoom mas suave que el de Tailwind default
   ─────────────────────────────────────────────────────────── */

.product-grid > article img {
  transition: transform 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

.product-grid > article:hover img {
  transform: scale(1.07);
}

/* ─────────────────────────────────────────────────────────────
   BADGE "STOCK BAJO" — pulse sutil para atraer atencion
   ─────────────────────────────────────────────────────────── */

@keyframes stockBajoPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.0); }
  50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.18); }
}

.product-grid > article span.bg-amber-100 {
  animation: stockBajoPulse 2s ease-in-out infinite;
}

/* ─────────────────────────────────────────────────────────────
   CARD AGOTADO — saturacion reducida + opacidad
   ─────────────────────────────────────────────────────────── */

.product-grid > article:has(button:disabled) {
  opacity: 0.75;
  filter: saturate(0.6);
}

.product-grid > article:has(button:disabled):hover {
  opacity: 1;
  filter: saturate(1);
}

/* ─────────────────────────────────────────────────────────────
   SKELETON LOADER (Fase D — mostrado mientras se cargan productos)
   ─────────────────────────────────────────────────────────── */

/* Card-shaped skeleton: imagen, titulo, precio, boton — todos
   con gradient shimmer animado. Por estructura, en lugar de un
   block monolitico mostramos los placeholders parciales para
   que la transicion a card real sea visualmente continua. */

.skeleton-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 1.5rem;
  overflow: hidden;
  padding: 0;
  height: 360px;
  display: flex;
  flex-direction: column;
}

.skeleton-card .skeleton-img,
.skeleton-card .skeleton-line {
  background: linear-gradient(
    90deg,
    #f1f5f9 0%,
    #e2e8f0 50%,
    #f1f5f9 100%
  );
  background-size: 200% 100%;
  animation: skeletonShine 1.4s ease-in-out infinite;
}

.skeleton-card .skeleton-img {
  height: 14rem;          /* matches h-56 de la card real */
  border-bottom: 1px solid #f1f5f9;
}

.skeleton-card .skeleton-body {
  padding: 1.25rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.skeleton-card .skeleton-line {
  height: 0.75rem;
  border-radius: 999px;
}

.skeleton-card .skeleton-line.long  { width: 90%; }
.skeleton-card .skeleton-line.mid   { width: 60%; }
.skeleton-card .skeleton-line.short { width: 40%; }

.skeleton-card .skeleton-button {
  margin-top: auto;
  height: 2.75rem;
  border-radius: 1rem;
  background: linear-gradient(
    90deg,
    #fee2e2 0%,
    #fecaca 50%,
    #fee2e2 100%
  );
  background-size: 200% 100%;
  animation: skeletonShine 1.4s ease-in-out infinite;
}

@keyframes skeletonShine {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Las skeleton cards NO necesitan el fade-up stagger ni el hover lift */
.product-grid > .skeleton-card {
  animation: none;
  transition: none;
}

.product-grid > .skeleton-card:hover {
  transform: none;
  border-color: #e2e8f0 !important;
  box-shadow: none;
}

/* ─────────────────────────────────────────────────────────────
   BADGES NUEVOS (Fase C — diseno enriquecido de cards)
   ─────────────────────────────────────────────────────────── */

/* Badge "OFERTA" / "NUEVO" con gradient + glow rojo Mega */
.badge-oferta {
  background: linear-gradient(135deg, #93000b 0%, #b91c1c 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(147, 0, 11, 0.25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
  letter-spacing: 0.04em;
  position: relative;
  overflow: hidden;
}

/* Brillo diagonal sutil que se mueve cada 3s */
.badge-oferta::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(255, 255, 255, 0.35) 50%,
    transparent 70%
  );
  transform: translateX(-100%);
  animation: badgeShine 3s ease-in-out infinite;
}

@keyframes badgeShine {
  0%, 60%, 100% { transform: translateX(-100%); }
  80%           { transform: translateX(100%); }
}

/* Badge "MÁS VENDIDO" con dorado */
.badge-bestseller {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
  letter-spacing: 0.04em;
}

/* Badge "AGOTADO" con gris oscuro */
.badge-agotado {
  background: #1f2937;
  color: #fff;
  letter-spacing: 0.04em;
}

/* ─────────────────────────────────────────────────────────────
   PRECIO CON DESCUENTO (precio tachado + nuevo precio resaltado)
   ─────────────────────────────────────────────────────────── */

.price-old {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(147, 0, 11, 0.6);
  color: #9ca3af;
  font-size: 0.875rem;
}

.price-new {
  color: #93000b;
  font-weight: 900;
  font-size: 1.25rem;
}

/* Pill que muestra el % de descuento */
.discount-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.625rem;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: 4px;
  border: 1px solid #fde68a;
}

/* ─────────────────────────────────────────────────────────────
   ESTADO "SIN RESULTADOS" — animacion sutil
   ─────────────────────────────────────────────────────────── */

.no-results-empty {
  animation: noResultsBob 2s ease-in-out infinite;
}

@keyframes noResultsBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ─────────────────────────────────────────────────────────────
   HIGHLIGHT DE COINCIDENCIA EN BUSQUEDA (Fase F)
   ─────────────────────────────────────────────────────────── */

/* La funcion searchHighlight() en ui/catalogo.js envuelve los matches
   en <mark class="search-match"> para visualizar que parte del texto
   matcheo la query del usuario. */
.search-match {
  background: linear-gradient(180deg, transparent 60%, #fef08a 60%);
  color: inherit;
  padding: 0;
  font-weight: inherit;
  border-radius: 2px;
}

/* ─────────────────────────────────────────────────────────────
   RESPETAR PREFERENCIAS DE MOVIMIENTO REDUCIDO
   ─────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .product-grid > article,
  .product-grid > article img,
  .product-grid > article span.bg-amber-100,
  .skeleton-card .skeleton-img,
  .skeleton-card .skeleton-line,
  .skeleton-card .skeleton-button,
  .badge-oferta::after,
  .no-results-empty {
    animation: none !important;
    transition: none !important;
  }
}
