/* ============================================================================
   PREVIEW OVERLAY (botón VISTA PREVIA sobre la imagen)
   Compat: .book-image, .product-image-container, .product-image-wrapper
============================================================================ */
.book-image,
.product-image-container,
.product-image-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease, visibility .3s ease, transform .3s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px); /* Safari */
  z-index: 2;
  pointer-events: none; /* evita captar clicks cuando está oculto */
}

.book-image:hover .preview-overlay,
.product-image-container:hover .preview-overlay,
.product-image-wrapper:hover .preview-overlay {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.preview-btn {
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transform: translateY(10px);
  outline: none;
}

.book-image:hover .preview-btn,
.product-image-container:hover .preview-btn,
.product-image-wrapper:hover .preview-btn {
  transform: translateY(0);
}

.preview-btn:hover {
  background: #ffffff;
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.preview-btn:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

.preview-btn svg {
  width: 16px;
  height: 16px;
}

/* ============================================================================
   MODAL DE VISTA PREVIA
============================================================================ */
.preview-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;               /* por defecto oculto */
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px); /* Safari */
}

.preview-modal.active {
  display: flex;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-up {
  from {
    opacity: 0;
    transform: translateY(50px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content {
  background: #ffffff;
  border-radius: 20px;
  width: 900px;
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
  overflow: hidden;
  animation: modal-slide-up .4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
             modal-fade-in .3s ease;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.modal-header {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
}

.close-modal {
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.close-modal:hover {
  background: #ffffff;
  transform: scale(1.1);
}

.close-modal:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

.modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 500px;
}

.modal-image-section {
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: relative;
}

.modal-product-image {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.modal-image-fallback {
  font-size: 120px;
  opacity: 0.3;
  color: #64748b;
  display: none; /* se muestra sólo si falla la imagen */
}


.modal-category-badge {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  align-self: flex-start;
  margin-bottom: 16px;
}

.modal-product-title {
  font-size: 28px;
  font-weight: 800;
  color: #1f2937;
  margin: 0 0 12px;
  line-height: 1.2;
}

/* Mejora principal para la descripción */
.modal-product-description {
    color: #70806b;
    line-height: 1.6;
    margin: 0 0 24px;
    font-size: 16px;
    
    /* PROPIEDAD AGREGADA: Permite mostrar viñetas y saltos de línea */
    white-space: pre-wrap;
    
    /* NUEVAS PROPIEDADES para manejar descripciones largas */
    max-height: 180px;      /* Altura máxima antes de scroll */
    overflow-y: auto;       /* Scroll vertical cuando sea necesario */
    padding-right: 8px;     /* Espacio para el scrollbar */
    
    /* Scrollbar personalizado */
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f3f4f6;
}
  
  /* NUEVAS PROPIEDADES para manejar descripciones largas */
  max-height: 180px;           /* Altura máxima antes de scroll */
  overflow-y: auto;            /* Scroll vertical cuando sea necesario */
  padding-right: 8px;          /* Espacio para el scrollbar */
  
  /* Scrollbar personalizado */
  scrollbar-width: thin;
  scrollbar-color: #d1d5db #f3f4f6;
}

/* Scrollbar personalizado para WebKit (Chrome, Safari, Edge) */
.modal-product-description::-webkit-scrollbar {
  width: 6px;
}

.modal-product-description::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 3px;
}

.modal-product-description::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.modal-product-description::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Ajustar la sección de información para mejor distribución del espacio */
.modal-info-section {
  overflow-y: auto;
  max-height: calc(90vh - 80px); /* Altura restante menos padding */
  padding: 40px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start; /* Cambio de space-between a flex-start */
  gap: 0; /* Sin gap automático, controlamos con margins */
}

.modal-info-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.modal-price-section {
  margin-bottom: 24px;
}

/* Pricing (dual/normal) */
.book-pricing {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;            /* se centra en cards; aquí alineado a la izquierda */
}

.price-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.price-sale {
  font-size: 24px;
  font-weight: 800;
  color: #059669;              /* verde oferta */
}

.price-original {
  font-size: 18px;
  color: #6b7280;
  text-decoration: line-through;
}

.price-normal {
  font-size: 24px;
  font-weight: 800;
  color: #1f2937;
}

.savings-badge {
  background: #eedcfc;
  color: #166534;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  align-self: flex-start;
}

/* Stock */
.modal-stock-info {
  margin-bottom: 24px;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
}

.stock-available { background: #dcfce7; color: #166534; }
.stock-low       { background: #fed7d7; color: #c53030; }
.stock-out       { background: #f3f4f6; color: #6b7280; }

/* Cantidad */
.quantity-selector {
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 24px;
}

.quantity-btn {
  background: transparent;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  color: #374151;
  transition: background-color .2s ease;
}

.quantity-btn:hover { background: #e5e7eb; }
.quantity-btn:disabled { cursor: not-allowed; opacity: 0.5; }

.quantity-input {
  border: none;
  background: transparent;
  text-align: center;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #374151;
  width: 60px;
}

/* Acciones */
.modal-actions {
  display: flex;
  gap: 16px;
}

.modal-add-to-cart {
  flex: 1;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.modal-add-to-cart:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.modal-add-to-cart:active { transform: translateY(0); }
.modal-add-to-cart:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Loader circular */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   RESPONSIVE
============================================================================ */
@media (max-width: 768px) {
  .modal-content {
    width: 95vw;
    max-height: 95vh;
  }
  .modal-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    min-height: auto;
  }
  .modal-image-section {
    padding: 20px;
    min-height: 250px;
  }
  .modal-info-section {
    padding: 20px;
  }
  .modal-product-title { font-size: 24px; }
  .modal-actions { flex-direction: column; }
}

/* ============================================================================
   REDUCED MOTION (accesibilidad)
============================================================================ */
@media (prefers-reduced-motion: reduce) {
  .preview-overlay,
  .preview-btn,
  .modal-content {
    transition: none !important;
    animation: none !important;
  }
}

/* ============================================================================
   EXTRA: estilos de pricing centrados para cards (opcional)
   Úsalos en la grilla si quieres igual que en libros.
============================================================================ */
.card .book-pricing { text-align: center; margin: 1rem 0; }
.card .price-container {
  display: flex; justify-content: center; align-items: baseline;
  gap: .5rem; margin: .5rem 0;
}
.card .price-sale { font-size: 1.4rem; font-weight: bold; color: #2c3e50; }
.card .price-original { font-size: 1.4rem; color: #ff3838; text-decoration: line-through; }
.card .price-normal { font-size: 1.3rem; font-weight: bold; color: #33502c; }
