/* ============================================================
   Modal - Estilo Neutro Premium
   Compatible con producto.html cargado vía modal
============================================================ */

/* Global safety: avoid horizontal overflow on mobile */
*,
*::before,
*::after{
  box-sizing: border-box;
}
html, body{
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
img, svg, video, canvas{
  max-width: 100%;
}



/* --- OVERLAY --- */
#overlay {
  position: fixed;
  inset: 0;
  backdrop-filter: blur(6px);
  background: rgba(15, 23, 42, 0.48);

  /* Centramos el modal en pantalla */
  display: flex;
  justify-content: center;
  align-items: center;

  /* Importante: NO permitimos scroll en el overlay,
     para que el modal no “se mueva” arriba/abajo.
     El scroll quedará en la página de fondo. */
  overflow: hidden;

  padding: 24px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  z-index: 9999;
}

#overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Contenedor para posicionar botón flotante relativo al modal */
.modal-wrapper {
  position: relative;
  /* +10% vs 900px (≈990px) */
  max-width: 1140px;
  width: 100%;
}

/* --- MODAL BOX --- */
#modal {
  background: #ffffff;
  /* +10% vs 900px (≈990px) */
  max-width: 1140px;
  width: 100%;
  /* Tarjeta totalmente redondeada (sin “cortes” tipo chip) */
  border-radius: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  padding: 24px;
  position: relative;
  animation: modalFade .25s ease forwards;

  /* Altura un poco más compacta (-5% aprox vs la versión anterior)
     y control de overflow: la tarjeta NO se mueve, solo hace scroll el hemisferio derecho */
  height: min(90vh, calc(100vh - 48px));
  max-height: min(90vh, calc(100vh - 48px));
  overflow: hidden;
  display: flex;
}

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

/* =========================
   “Tarjeta en dos hemisferios” (solo para vista modal)
   - Izquierda: imagen principal + miniaturas (sin scroll)
   - Derecha: info con scroll vertical
   ========================= */

#modal .product-full {
  width: 100%;
  height: 100%;
}

#modal .product-grid {
  height: 100%;
  flex-wrap: nowrap;
  align-items: stretch;
}

#modal .gallery {
  display: flex;
  flex-direction: column;
  min-height: 0; /* permite que el lado derecho haga scroll sin empujar */
}

#modal .info {
  overflow-y: auto;
  min-height: 0;
  padding-right: 6px;
}

/* Ajuste fino de altura de imagen dentro del modal para mantener proporciones */
#modal .main-img img {
  height: 390px; /* -5% aprox vs 360 */
}

/* --- CLOSE BUTTON --- */
.cerrar-modal {
  display: none !important;
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f3f4f6;
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 1.2rem;
  transition: background .15s;
}

.cerrar-modal:hover {
  background: #e5e7eb;
}

/* --- GALERÍA PRINCIPAL --- */
.modal-gallery {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
}

.modal-main-img {
  flex: 1 1 380px;
  /* Fondo blanco (sin gris) detrás del producto */
  background: #ffffff;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-main-img img {
  width: 100%;
  /* Reducimos ~15% la altura para una tarjeta más compacta */
  height: 360px;
  object-fit: contain;
  background: #ffffff;
}

/* --- MINIATURAS --- */
.modal-thumbs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-thumb {
  width: 80px;
  height: 80px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform .12s;
}

.modal-thumb:hover {
  transform: translateY(-4px);
}

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

/* --- INFO DEL PRODUCTO --- */
.modal-info {
  margin-top: 20px;
}

.modal-title {
  font-size: 1.35rem;
  color: #0f172a;
  font-weight: 700;
  margin: 0;
}

.modal-sku {
  background: #000;
  color:#fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-top: 8px;
  display: inline-block;
  font-weight: 600;
}

.modal-desc {
  margin-top: 14px;
  color: #6b7280;
  line-height: 1.45;
}

/* --- COLORES --- */
.modal-colors {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-color {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.08);
}

/* --- BADGE AGOTADO --- */
.badge-agotado {
  background: #e11d48;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-block;
  margin-top: 10px;
}

/* --- BOTÓN FLOTANTE DE CIERRE (EXTERNO) --- */
.modal-close-fab {
  position: absolute;
  /* valores negativos para que quede fuera del recuadro del modal */
  top: -22px;
  right: -22px;

  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: none;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 22px;
  line-height: 1;
  color: #0f172a;

  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  z-index: 10000; /* por encima del modal */
}

.modal-close-fab i {
  pointer-events: none; /* para que el click lo reciba el botón, no el <i> */
}

.modal-close-fab:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.3);
}

.modal-close-fab:active {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
}

.modal-close-fab:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 2px;
}

@media (max-width: 680px) {
  /* Botón de cierre: más grande y accesible, debajo del modal (fijo) */
  .modal-close-fab{
    position: fixed;
    top: auto;
    right: auto;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    width: 58px;
    height: 58px;
    font-size: 26px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35);
  }
}

/* --- RESPONSIVE --- */
@media (max-width: 680px){
  .modal-wrapper{ width: calc(100% - 24px); }

  #modal{
    padding: 16px;
    /* dejamos espacio para el botón de cierre fijo */
    height: min(92vh, calc(100vh - 108px));
    max-height: min(92vh, calc(100vh - 108px));
    overflow: auto;
    display: block;
  }

  /* En móvil, apilamos hemisferios: imágenes arriba, info abajo */
  #modal .product-grid{
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 10px; /* menos espacio entre miniaturas y el bloque de info */
    height: auto;
  }
  #modal .gallery,
  #modal .info{
    min-width: 0;
  }
  #modal .info{
    overflow: visible;
    padding-right: 0;
  }

  #modal .main-img img { height: 247px; }

  /* Un poco de aire extra bajo botones (para que no queden “pegados” al FAB de cerrar) */
  #modal .actions{ margin-bottom: 10px; padding-bottom: 14px; }

  /* Aire al final del contenido dentro de la tarjeta */
  #modal .info{ padding-bottom: 22px; }
}
