/**
 * Mecha Product Islands — Layout CSS v2.0
 * Plugin: mecha-product-islands
 *
 * ARQUITECTURA FLATSOME (DOM real):
 * ─────────────────────────────────────────────────────────────────────
 *  .product-container
 *  └── .product-main
 *      └── .row.content-row          ← grid nativo de Flatsome (row UX)
 *          ├── .product-gallery.col  ← Isla 1: galería
 *          └── .product-info.col     ← Isla 2: resumen de compra
 *  └── .product-footer
 *      └── .container                ← Isla 3: pestañas de detalles
 * ─────────────────────────────────────────────────────────────────────
 *
 * Estrategia: scope con .mpi-islands-active (clase inyectada al body)
 * para evitar afectar otras páginas y ganar especificidad sobre Flatsome.
 *
 * Tabla de contenidos:
 *   1.  Variables CSS
 *   2.  Fondo gris global (canvas)
 *   3.  Grid / row — separación entre islas
 *   4.  Isla base compartida
 *   5.  Isla 1: Galería (.product-gallery)
 *   6.  Isla 2: Resumen de compra (.product-info / .entry-summary)
 *   7.  Isla 3: Pestañas (.product-footer)
 *   8.  Limpieza de estilos nativos Flatsome / WooCommerce
 *   9.  Responsive — tablet (≤ 1024px)
 *  10.  Responsive — móvil (≤ 767px)
 */


/* =========================================================
   1. VARIABLES CSS
   ========================================================= */
body.mpi-islands-active {
  --ag-bg:          #f4f4f5;
  --ag-island-bg:   #ffffff;
  --ag-gap:         20px;
  --ag-radius:      8px;
  --ag-padding:     40px;
  --ag-padding-gallery: 32px;
  --ag-shadow:      0 2px 12px rgba(0, 0, 0, 0.06);
  --ag-container-width: 1250px; /* Ancho máximo para dejar espacio a los lados */
}


/* =========================================================
   2. FONDO GRIS GLOBAL (CANVAS)
   ========================================================= */

body.mpi-islands-active .product-main {
  background-color: var(--ag-bg) !important;
  padding: var(--ag-gap) !important;
  box-sizing: border-box !important;
}

body.mpi-islands-active .product-footer {
  background-color: var(--ag-bg) !important;
  padding: 0 var(--ag-gap) var(--ag-gap) !important;
  box-sizing: border-box !important;
}

body.mpi-islands-active .product-footer > .container {
  padding: var(--ag-padding) !important;
  width: 100% !important;
  max-width: var(--ag-container-width) !important; /* Restringe el ancho */
  margin: 0 auto !important; /* Centra el contenedor en la pantalla */
}

/* =========================================================
   3. GRID / ROW — SEPARACIÓN ENTRE ISLAS
   ========================================================= */

body.mpi-islands-active .product-main .row.content-row {
  display: grid !important;
  grid-template-columns: 55% 1fr !important;
  grid-template-rows: auto !important;
  gap: var(--ag-gap) !important;
  align-items: stretch !important; /* Estira ambas columnas a la misma altura */
  width: 100% !important;
  max-width: var(--ag-container-width) !important; /* Restringe el ancho */
  margin: 0 auto !important; /* Centra el contenedor en la pantalla */
  padding: 0 !important;
  float: none !important;
}

body.mpi-islands-active .product-main .row.content-row > [class*="col"] {
  float: none !important;
  width: 100% !important; /* Fuerza a respetar la columna del grid */
  min-width: 0 !important; /* Previene grid blowout con imágenes grandes */
  max-width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

body.mpi-islands-active .product-main .row.content-row > #product-sidebar {
  display: none !important;
}

/* =========================================================
   4. ISLA BASE COMPARTIDA
   ========================================================= */
body.mpi-islands-active .product-main .product-gallery,
body.mpi-islands-active .product-main .product-info.entry-summary,
body.mpi-islands-active .product-footer > .container {
  background-color: var(--ag-island-bg) !important;
  border-radius: var(--ag-radius) !important;
  box-shadow: var(--ag-shadow) !important;
  box-sizing: border-box !important;
  position: relative;
  overflow: visible !important;
}

/* =========================================================
   5. ISLA 1: GALERÍA (.product-gallery)
   ========================================================= */
body.mpi-islands-active .product-main .row.content-row .product-gallery.col,
body.mpi-islands-active .product-main .product-gallery {
  padding: var(--ag-padding-gallery) !important;
}

body.mpi-islands-active .product-gallery .mecha-gallery,
body.mpi-islands-active .product-gallery .woocommerce-product-gallery {
  width: 100% !important;
  max-width: 100% !important;
}

body.mpi-islands-active .product-gallery .mecha-gallery__viewport {
  box-shadow: none !important;
}

body.mpi-islands-active .product-gallery .woocommerce-badge,
body.mpi-islands-active .product-gallery .onsale {
  top: var(--ag-padding-gallery) !important;
  left: var(--ag-padding-gallery) !important;
}

body.mpi-islands-active .product-gallery .is-sticky-column {
  top: calc(var(--ag-gap) + 16px) !important;
}

/* =========================================================
   6. ISLA 2: RESUMEN DE COMPRA (.product-info / .entry-summary)
   ========================================================= */
body.mpi-islands-active .product-main .row.content-row .product-info.entry-summary {
  padding: var(--ag-padding) !important;
  flex: unset !important;
  width: auto !important;
  min-width: 0 !important;
}

body.mpi-islands-active .product-info.entry-summary > * {
  /* Aseguramos que los hijos no tengan margen negativo que los saque del contenedor */
  margin-left: 0 !important;
  margin-right: 0 !important;
}

body.mpi-islands-active .product-info .product_title,
body.mpi-islands-active .product-info h1.product_title {
  margin-top: 0 !important;
  padding-top: 0 !important;
  color: #6017b1 !important;
  font-size: 1.5em !important;
  margin-bottom: 0.5em !important;
}

body.mpi-islands-active .product-info .woocommerce-breadcrumb {
  margin-bottom: 0.5em !important;
  padding: 0 !important;
  text-transform: uppercase !important;
  font-size: 11px !important;
  color: #999 !important;
}

/* Si Flatsome y WooCommerce generan dos migas de pan, ocultamos la duplicada */
body.mpi-islands-active .product-info .woocommerce-breadcrumb ~ .woocommerce-breadcrumb {
  display: none !important;
}

body.mpi-islands-active .product-info .single_add_to_cart_button {
  width: 100% !important;
  box-sizing: border-box !important;
}

body.mpi-islands-active .product-info form.cart {
  display: flex !important;
  gap: 10px !important;
  align-items: stretch !important;
  flex-wrap: wrap !important;
}

body.mpi-islands-active .product-info form.cart .quantity {
  flex-shrink: 0 !important;
}

body.mpi-islands-active .product-info form.cart .single_add_to_cart_button {
  flex: 1 !important;
  width: auto !important;
}


/* =========================================================
   7. ISLA 3: PESTAÑAS (.product-footer > .container)
   ========================================================= */

/* Sección de pestañas (Contenedor general) */
body.mpi-islands-active .product-footer .woocommerce-tabs {
  margin: 0 !important;
  padding: 0 !important;
  display: flex !important;
  gap: 40px !important;
  align-items: flex-start !important;
}

/* La columna izquierda unificada (Tabs + Rating Box) una vez creada por JS */
body.mpi-islands-active .product-footer .woocommerce-tabs .mpi-sticky-sidebar {
  flex: 0 0 210px !important;
  position: sticky !important;
  top: 40px !important;
  z-index: 10 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 30px !important; /* Espacio entre pestañas y rating box */
}

/* El selector de pestañas (aplica inmediatamente antes y después del JS) */
body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs {
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  width: 210px !important; /* Mismo ancho que el sidebar para evitar saltos */
  flex: 0 0 210px !important; 
  display: flex !important;
  flex-direction: column !important;
  gap: 6px !important;
}

/* Una vez dentro del sidebar por JS, que ocupe el 100% de ese sidebar */
body.mpi-islands-active .product-footer .woocommerce-tabs .mpi-sticky-sidebar ul.tabs {
  width: 100% !important;
  flex: none !important;
}

/* Ítem de pestaña */
body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li {
  background: transparent !important;
  border: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li a {
  padding: 8px 14px !important;
  color: #555 !important;
  font-weight: 500 !important;
  font-size: 14px !important;
  border: none !important;
  background: #f7f7f9 !important; /* Fondo sutil para inactivos */
  border-radius: 8px !important;
  display: block !important;
  transition: all 0.2s ease !important;
  text-transform: none !important;
}

body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li a:hover {
  background: #f0ecf8 !important;
  color: #6017b1 !important;
}

/* Pestaña activa */
body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li.active a {
  background: #f0ecf8 !important; /* Fondo morado clarito */
  color: #6017b1 !important;
  font-weight: 600 !important;
  border-left: 4px solid #6017b1 !important; /* Indicador claro */
  border-right: none !important; /* Quitar borde derecho nativo de Flatsome */
  padding-left: 10px !important; /* Compensar el borde (14 - 4) */
}

/* Estilos para el cuadro de valoraciones reubicado (efecto Smooth) */
.mpi-left-rating-box {
  width: 100% !important;
  transition: opacity 0.4s ease-out, transform 0.4s ease-out, max-height 0.4s ease-out !important;
  opacity: 0;
  transform: translateY(15px);
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
}

.mpi-left-rating-box.show-rating {
  opacity: 1;
  transform: translateY(0);
  max-height: 1000px; /* Suficiente para que el contenido se expanda */
  pointer-events: auto;
  margin-top: 10px;
}

.mpi-left-rating-box > div {
  margin: 0 !important;
  width: 100% !important;
}

/* Paneles de contenido (columna derecha) */
body.mpi-islands-active .product-footer .woocommerce-tabs .tab-panels {
  flex: 1 !important;
  min-width: 0 !important;
}

/* Hacer visibles TODOS los paneles para ScrollSpy */
body.mpi-islands-active .product-footer .woocommerce-tabs .panel,
body.mpi-islands-active .product-footer .woocommerce-tabs .panel:not(.active) {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
  height: auto !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 0 60px 0 !important;
  margin: 0 0 60px 0 !important;
  pointer-events: auto !important;
  overflow: visible !important;
}

body.mpi-islands-active .product-footer .woocommerce-tabs .panel:last-child {
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
}

/* Videos e IFrames en la Descripción Larga agradables y responsivos */
body.mpi-islands-active .product-footer .woocommerce-tabs .panel iframe,
body.mpi-islands-active .product-footer .woocommerce-tabs .panel video {
  max-width: 800px !important; /* Tamaño fijo máximo agradable */
  width: 100% !important; /* Adaptable en pantallas pequeñas */
  aspect-ratio: 16 / 9 !important; /* Mantiene la proporción */
  height: auto !important;
  display: block !important;
  margin: 30px auto !important; /* Centrado automático */
  border-radius: 8px !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
}

/* Títulos de cada sección inyectados por JS */
body.mpi-islands-active .product-footer .woocommerce-tabs .panel .mpi-panel-title,
body.mpi-islands-active .product-footer .woocommerce-tabs .panel > h2:first-child {
  text-align: center !important;
  margin-top: 0 !important;
  margin-bottom: 30px !important;
  color: #6017b1 !important;
  font-size: 24px !important; /* Reducido según petición */
  text-transform: uppercase !important;
  font-weight: bold !important;
  letter-spacing: 0.05em !important;
  border: none !important; /* Quitar cualquier borde superior o inferior */
  padding: 0 !important;
}

/* Ajuste específico para Mechatronic Reviews Enhancer */
/* Evitar salto visual (FOUC) ocultando el panel de métricas en su lugar original antes de ser movido por JS */
body.mpi-islands-active .mre-reviews-layout .mre-metrics-panel {
  display: none !important;
}

/* Como sacamos el panel izquierdo (mre-metrics-panel), convertimos el layout original a una sola columna (1fr) */
body.mpi-islands-active .mre-reviews-layout {
  display: block !important;
  grid-template-columns: 1fr !important;
}

/* Reducir tamaño de productos relacionados / up-sells */
body.mpi-islands-active .related.products,
body.mpi-islands-active .up-sells.products {
  transform: scale(0.85); /* Reduce todo el bloque de relacionados en un 15% */
  transform-origin: top center;
  margin-bottom: -5% !important; /* Compensa el espacio inferior que deja el scale */
}

/* Tabla de atributos/especificaciones */
.mpi-islands-active .product-footer .shop_attributes,
.mpi-islands-active .product-footer table.shop_attributes {
  border: none !important;
  width: 100% !important;
}

.mpi-islands-active .product-footer .shop_attributes th,
.mpi-islands-active .product-footer .shop_attributes td {
  border: none !important;
  border-bottom: 1px solid #f0ecf8 !important;
  background: transparent !important;
}

.mpi-islands-active .product-footer .shop_attributes tr:last-child th,
.mpi-islands-active .product-footer .shop_attributes tr:last-child td {
  border-bottom: none !important;
}

.mpi-islands-active .product-footer .shop_attributes tr:nth-child(even) td,
.mpi-islands-active .product-footer .shop_attributes tr:nth-child(even) th {
  background: #faf9ff !important;
}


/* =========================================================
   8. LIMPIEZA DE ESTILOS NATIVOS FLATSOME / WOOCOMMERCE
   ========================================================= */

/* Eliminar el container envolvente externo de WooCommerce que aparece sobre product-main */
.mpi-islands-active #product-container,
.mpi-islands-active .product-container {
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Quitar fondo y bordes del ID de producto de Flatsome */
.mpi-islands-active #product-content,
.mpi-islands-active .type-product {
  background: transparent !important;
}

/* El div.container de WooCommerce antes del product-main (notices) */
.mpi-islands-active .single-product > .container:first-child {
  background: transparent !important;
}

/* Flatsome añade padding al row de producto: eliminar */
.mpi-islands-active .row.content-row.mb-0 {
  margin-bottom: 0 !important;
}

/* Separador entre galería y summary que Flatsome puede añadir */
.mpi-islands-active .product-main::after,
.mpi-islands-active .product-main::before {
  display: none !important;
}

/* Quitar bordes grises nativos de WooCommerce tabs */
.mpi-islands-active .woocommerce-tabs ul.tabs::before {
  border: none !important;
  display: none !important;
}

/* Related products y upsells — fondo transparente */
.mpi-islands-active .product-footer .related.products,
.mpi-islands-active .product-footer .upsells.products {
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
}


/* =========================================================
   9. RESPONSIVE — TABLET (769px – 1024px)
   ========================================================= */
@media (max-width: 1024px) {
  body.mpi-islands-active {
    --ag-gap:     16px;
    --ag-padding: 30px;
    --ag-padding-gallery: 24px;
  }

  body.mpi-islands-active .product-main .row.content-row {
    grid-template-columns: 55% 1fr !important;
  }
}


/* =========================================================
   10. RESPONSIVE — MÓVIL (≤ 767px)
   ========================================================= */
@media (max-width: 767px) {
  body.mpi-islands-active {
    --ag-gap:     10px; /* Reducido para maximizar pantalla */
    --ag-padding: 16px; /* Reducido drásticamente para aprovechar ancho */
    --ag-padding-gallery: 12px; /* Galería casi al borde */
  }

  /* Colapsar a una columna */
  body.mpi-islands-active .product-main .row.content-row {
    grid-template-columns: 1fr !important;
  }

  /* Padding lateral del canvas más compacto en móvil */
  body.mpi-islands-active .product-main {
    padding: var(--ag-gap) !important;
  }

  body.mpi-islands-active .product-footer {
    padding: 0 var(--ag-gap) var(--ag-gap) !important;
  }

  /* Botones en móvil: columna */
  body.mpi-islands-active .product-info form.cart {
    flex-direction: column !important;
  }

  body.mpi-islands-active .product-info form.cart .quantity,
  body.mpi-islands-active .product-info form.cart .single_add_to_cart_button {
    width: 100% !important;
    flex: none !important;
  }

  /* Selector de pestañas en móvil: scroll horizontal estilo píldoras */
  body.mpi-islands-active .product-footer .woocommerce-tabs {
    flex-direction: column !important;
    gap: 16px !important; /* Reducido de 24px */
  }

  /* La barra lateral unificada se vuelve fluida en móvil */
  body.mpi-islands-active .product-footer .woocommerce-tabs .mpi-sticky-sidebar {
    position: relative !important;
    top: 0 !important;
    width: 100% !important;
    flex: none !important;
    gap: 16px !important; /* Reducido de 24px */
  }
  
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs {
    flex: none !important;
    width: 100% !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    gap: 8px !important; /* Píldoras más juntas */
    padding-bottom: 4px !important;
  }
  
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs::-webkit-scrollbar {
    display: none !important;
  }

  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li {
    flex: 0 0 auto !important;
    width: max-content !important;
    border: none !important;
  }

  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li::after,
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li::before,
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li a::after,
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li a::before {
    display: none !important;
  }

  /* Formato de píldoras en móvil más compactas */
  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li a {
    border-radius: 99px !important;
    padding: 8px 16px !important; /* Reducido para ahorrar altura */
    border: none !important; /* Quita el borde vertical de flatsome */
    background: #f7f7f9 !important;
    color: #555 !important;
    font-size: 13px !important; /* Reducido para que quepan más opciones */
    white-space: nowrap !important;
    display: inline-block !important;
    width: max-content !important;
    text-align: center !important;
  }

  body.mpi-islands-active .product-footer .woocommerce-tabs ul.tabs li.active a {
    background: #6017b1 !important;
    color: #ffffff !important;
    padding-left: 16px !important;
  }

  /* Optimizar espaciado de secciones (paneles) en móvil */
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel,
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel:not(.active) {
    padding: 0 0 30px 0 !important; /* Ahorramos 30px de espacio vertical muerto */
    margin: 0 0 30px 0 !important;
  }

  /* Títulos de las secciones más proporcionados en móvil */
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel .mpi-panel-title,
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel > h2:first-child {
    font-size: 18px !important; /* Reduce de 24px a 18px */
    margin-bottom: 20px !important;
  }

  /* Ajuste de videos en móvil para que el margen superior/inferior no sea excesivo */
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel iframe,
  body.mpi-islands-active .product-footer .woocommerce-tabs .panel video {
    margin: 15px auto !important;
  }
}
