/**
 * checkout-integral.css
 * LOTE 8 — CSS scoped del Checkout Integral CanaimaShop.
 *
 * Reglas:
 *  - Prefijo .cs-integral- en todos los selectores.
 *  - No selectores globales (body, form, input, button, .woocommerce { }).
 *  - No !important salvo necesidad justificada con comentario.
 *  - Diseño mínimo de estructura y legibilidad — sin rediseño final.
 *  - Cargado solo en la página de checkout bajo feature flag.
 */

/* =========================================================
   Checkout header
   ========================================================= */

.cs-integral-checkout__header {
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
  background: #fff;
}

.cs-integral-checkout__title {
  margin: 0 0 6px;
  font-size: 1.3em;
  line-height: 1.3;
}

.cs-integral-checkout__intro {
  margin: 0;
  color: #555;
  font-size: 0.95em;
}

/* =========================================================
   Summary block (LOTE 7)
   ========================================================= */

.cs-integral-summary {
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  background: #fff;
}

.cs-integral-summary__title {
  margin: 0 0 4px;
  font-size: 1.1em;
}

.cs-integral-summary__intro {
  margin: 0 0 12px;
  color: #555;
  font-size: 0.9em;
}

/* =========================================================
   Summary sections
   ========================================================= */

.cs-integral-summary__section {
  border-top: 1px solid #eee;
  padding: 10px 0;
}

.cs-integral-summary__section:first-of-type {
  border-top: 0;
  padding-top: 4px;
}

.cs-integral-summary__section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.cs-integral-summary__section-title {
  margin: 0;
  font-size: 0.95em;
  font-weight: 600;
}

.cs-integral-summary__edit-link {
  font-size: 0.82em;
  text-decoration: underline;
  white-space: nowrap;
  flex-shrink: 0;
}

/* =========================================================
   Summary items (dl/dt/dd)
   ========================================================= */

.cs-integral-summary__items {
  margin: 0;
  padding: 0;
}

.cs-integral-summary__item {
  display: flex;
  gap: 8px;
  margin: 3px 0;
  font-size: 0.88em;
}

.cs-integral-summary__item-label {
  color: #777;
  flex-shrink: 0;
  min-width: 90px;
}

.cs-integral-summary__item-value {
  color: #222;
  margin: 0;
}

/* LOTE 9C.6 — Modificadores: Total destacado y línea informativa de tokens ganados */
.cs-integral-summary__item--total {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e0e0e0;
  font-size: 1.05em;
  font-weight: 700;
}
.cs-integral-summary__item--total .cs-integral-summary__item-label,
.cs-integral-summary__item--total .cs-integral-summary__item-value {
  color: #111;
  font-weight: 700;
}

.cs-integral-summary__item--earn {
  margin-top: 6px;
  padding: 8px 10px;
  background: #fff8e1;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  font-size: 0.9em;
}
.cs-integral-summary__item--earn .cs-integral-summary__item-label {
  color: #92400e;
  font-weight: 600;
}
.cs-integral-summary__item--earn .cs-integral-summary__item-value {
  color: #92400e;
  font-weight: 700;
}

/* =========================================================
   Section status modifiers
   ========================================================= */

.cs-integral-summary__section--complete .cs-integral-summary__section-title::after {
  content: " ✓";
  color: #4caf50;
  font-weight: normal;
  font-size: 0.9em;
}

.cs-integral-summary__section--incomplete .cs-integral-summary__section-title {
  color: #b36200;
}

/* =========================================================
   Responsive
   ========================================================= */

@media (max-width: 600px) {
  .cs-integral-checkout__header,
  .cs-integral-summary {
    padding: 12px 14px;
  }

  .cs-integral-summary__item-label {
    min-width: 72px;
  }
}

/* =========================================================
   LOTE 9B.1 — Flujo único integral: anular step legacy
   Selectores scoped bajo body.cs-checkout-integral-enabled.
   Estos overrides son una red de seguridad por si las body
   classes de step legacy llegaran a coexistir con el modo
   integral (no debería ocurrir con los guards de PHP/JS).
   ========================================================= */

/* Garantizar visibilidad de todas las secciones críticas */
body.cs-checkout-integral-enabled.page-checkout #order_review,
body.cs-checkout-integral-enabled.page-checkout #order_review_heading,
body.cs-checkout-integral-enabled.page-checkout .woocommerce-checkout-review-order,
body.cs-checkout-integral-enabled.page-checkout .woocommerce-checkout-payment,
body.cs-checkout-integral-enabled.page-checkout #payment,
body.cs-checkout-integral-enabled.page-checkout .woocommerce-shipping-fields,
body.cs-checkout-integral-enabled.page-checkout .woocommerce-shipping-methods,
body.cs-checkout-integral-enabled.page-checkout .woocommerce-terms-and-conditions-wrapper,
body.cs-checkout-integral-enabled.page-checkout #place_order {
  display: block !important;
}

/* Ocultar stepper legacy y botón intermedio */
body.cs-checkout-integral-enabled .cs-checkout-progress,
body.cs-checkout-integral-enabled .cs-step-next {
  display: none !important;
}

/* =========================================================
   LOTE 9B.4 — Navegación desde el resumen (acciones Cambiar)
   ========================================================= */

/* Pulso visual en el bloque objetivo al hacer clic en Cambiar */
body.cs-checkout-integral-enabled .cs-integral-focus-pulse {
  outline: 2px solid #f4b000;
  outline-offset: 3px;
  transition: outline-color 0.2s ease, outline-offset 0.2s ease;
}

/* Scroll margin para que el bloque no quede debajo de headers fijos */
body.cs-checkout-integral-enabled .woocommerce-billing-fields,
body.cs-checkout-integral-enabled .woocommerce-shipping-fields,
body.cs-checkout-integral-enabled .woocommerce-shipping-totals,
body.cs-checkout-integral-enabled #shipping_method,
body.cs-checkout-integral-enabled #payment,
body.cs-checkout-integral-enabled .woocommerce-checkout-payment,
body.cs-checkout-integral-enabled [data-cs-integral-tokens],
body.cs-checkout-integral-enabled .cs-integral-tokens {
  scroll-margin-top: 96px;
}

/* =========================================================
   LOTE 9B.5 — Productos enriquecidos en el resumen integral
   ========================================================= */

body.cs-checkout-integral-enabled .cs-integral-products {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

body.cs-checkout-integral-enabled .cs-integral-product {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

body.cs-checkout-integral-enabled .cs-integral-product__image {
  flex-shrink: 0;
  width: 56px;
}

body.cs-checkout-integral-enabled .cs-integral-product__image img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #eee;
  display: block;
}

body.cs-checkout-integral-enabled .cs-integral-product__body {
  flex: 1;
  min-width: 0;
}

body.cs-checkout-integral-enabled .cs-integral-product__name {
  display: block;
  font-weight: 600;
  font-size: 0.92em;
  color: #222;
  text-decoration: none;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.cs-checkout-integral-enabled a.cs-integral-product__name:hover {
  text-decoration: underline;
  color: #111;
}

body.cs-checkout-integral-enabled .cs-integral-product__meta {
  font-size: 0.82em;
  color: #555;
  margin: 2px 0;
}

body.cs-checkout-integral-enabled .cs-integral-product__meta--variation {
  color: #777;
}

body.cs-checkout-integral-enabled .cs-integral-product__delivery {
  font-size: 0.82em;
  color: #666;
  margin-top: 3px;
}

/* Responsive: en pantallas muy pequeñas apilar imagen y cuerpo */
@media (max-width: 360px) {
  body.cs-checkout-integral-enabled .cs-integral-product {
    flex-direction: column;
  }
  body.cs-checkout-integral-enabled .cs-integral-product__image {
    width: 100%;
  }
  body.cs-checkout-integral-enabled .cs-integral-product__image img {
    width: 48px;
    height: 48px;
  }
}

/* =========================================================
   LOTE 9C.1 — Consolidar layout: cs-integral-summary como
   contenedor operativo principal (ancho completo).

   Objetivos:
    1. Anular el layout de 2 columnas de WooCommerce.
    2. Que .cs-integral-summary ocupe el ancho disponible.
    3. Ocultar los contenedores WooCommerce tras vaciarlos por JS.
    4. Estilos de slot para recibir nodos reales del checkout.

   Nota sobre !important: necesario para superar los
   display:block!important de LOTE 9B.1 y los floats de WC.
   Selectores de alta especificidad donde aplica.
   ========================================================= */

/* 1. form.checkout: anular flex/grid del tema */
body.cs-checkout-integral-enabled form.checkout {
  display: block !important;
  flex-direction: unset;
  gap: unset;
}

/* 2. Summary a ancho completo */
body.cs-checkout-integral-enabled .cs-integral-summary {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* 3. Neutralizar layout de 2 columnas de WooCommerce */
body.cs-checkout-integral-enabled #customer_details,
body.cs-checkout-integral-enabled .col2-set,
body.cs-checkout-integral-enabled .col2-set .col-1,
body.cs-checkout-integral-enabled .col2-set .col-2 {
  float: none !important;
  width: 100% !important;
  max-width: 100% !important;
}

body.cs-checkout-integral-enabled #order_review {
  float: none !important;
  width: 100% !important;
}

/* 4. Ocultar contenedores WooCommerce una vez vaciados por JS.
   Alta especificidad para superar display:block!important (LOTE 9B.1). */
body.cs-checkout-integral-enabled.page-checkout #customer_details.cs-integral-layout-hidden,
body.cs-checkout-integral-enabled.page-checkout #order_review.cs-integral-layout-hidden {
  display: none !important;
}

body.cs-checkout-integral-enabled #order_review_heading.cs-integral-layout-hidden,
body.cs-checkout-integral-enabled .cs-integral-layout-hidden {
  display: none !important;
}

/* 5. Slots: contenedores para los nodos reales movidos por JS */
body.cs-checkout-integral-enabled .cs-integral-summary__slot {
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
  scroll-margin-top: 96px;
}

/* 6. Nodos movidos al slot: adaptarse al ancho completo del contenedor */
body.cs-checkout-integral-enabled [data-cs-integral-moved="1"] {
  width: 100% !important;
  float: none !important;
  box-sizing: border-box;
}

/* 7. Responsive: ajustes adicionales en móvil para layout integral */
@media (max-width: 768px) {
  body.cs-checkout-integral-enabled .cs-integral-summary {
    padding: 12px 14px;
  }
  body.cs-checkout-integral-enabled .cs-integral-summary__slot {
    margin-top: 6px;
  }
}

/* =========================================================
   LOTE 9C.2 — Secciones colapsables dentro de cs-integral-summary

   Reglas:
    - Secciones colapsables [data-cs-integral-expanded="0"]: panel oculto.
    - Atributo HTML `hidden` en el panel: fuerza display:none con alta esp.
    - Preview siempre visible.
    - Confirm section: sin toggle, panel siempre abierto.
    - CSS scoped bajo body.cs-checkout-integral-enabled.
   ========================================================= */

/* ─── Panel colapsable ──────────────────────────────────── */

/* Panel con atributo hidden: ocultar con alta especificidad
   para superar display:block!important de LOTE 9B.1. */
body.cs-checkout-integral-enabled.page-checkout .cs-integral-summary__panel[hidden] {
  display: none !important;
}

/* Panel en sección colapsada: doble guardia por si se quitó el atributo hidden por error */
body.cs-checkout-integral-enabled [data-cs-integral-expanded="0"] .cs-integral-summary__panel {
  display: none !important;
}

/* Panel en sección abierta */
body.cs-checkout-integral-enabled [data-cs-integral-expanded="1"] .cs-integral-summary__panel {
  display: block;
}

/* ─── Preview ───────────────────────────────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__preview {
  display: block;
  padding: 4px 0 6px;
}

/* ─── Header de sección ─────────────────────────────────── */

/* Anular .cs-integral-summary__section-header del LOTE 7
   para incorporar el nuevo title-wrap y el botón toggle. */
body.cs-checkout-integral-enabled .cs-integral-summary__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

body.cs-checkout-integral-enabled .cs-integral-summary__section-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

body.cs-checkout-integral-enabled .cs-integral-summary__section-title {
  margin: 0;
  font-size: 0.95em;
  font-weight: 600;
}

/* ─── Indicador de estado completo (✓) ─────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__status {
  color: #4caf50;
  font-size: 0.85em;
  flex-shrink: 0;
  line-height: 1;
}

/* ─── Botón toggle "Cambiar" ────────────────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__toggle {
  font-size: 0.82em;
  color: #555;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}

body.cs-checkout-integral-enabled .cs-integral-summary__toggle:hover,
body.cs-checkout-integral-enabled .cs-integral-summary__toggle:focus {
  color: #111;
  outline: 1px dotted #888;
  outline-offset: 2px;
}

/* ─── Panel ─────────────────────────────────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__panel {
  width: 100%;
  box-sizing: border-box;
  padding-top: 6px;
}

/* ─── Acciones del panel (Guardar datos) ────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__panel-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid #eee;
}

/* ─── Botón Guardar datos ───────────────────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__save {
  background: #222;
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 4px;
  font-size: 0.9em;
  cursor: pointer;
  line-height: 1.4;
}

body.cs-checkout-integral-enabled .cs-integral-summary__save:hover,
body.cs-checkout-integral-enabled .cs-integral-summary__save:focus {
  background: #444;
  outline: none;
}

/* ─── Sección confirm ───────────────────────────────────── */

body.cs-checkout-integral-enabled .cs-integral-summary__section--confirm {
  border-top: 2px solid #e0e0e0;
  margin-top: 8px;
  padding-top: 16px;
}

/* ─── Tokens row extraída de tabla: renderizar como bloque ─ */
/* La TR se mueve al slot de tokens (un div). Sin tabla,
   el navegador la renderiza como table-row sin contexto.
   Forzar display:block para que sea legible. */
body.cs-checkout-integral-enabled [data-cs-integral-slot="tokens"] tr.cs-integral-tokens-row {
  display: block;
  width: 100%;
}

body.cs-checkout-integral-enabled [data-cs-integral-slot="tokens"] tr.cs-integral-tokens-row th,
body.cs-checkout-integral-enabled [data-cs-integral-slot="tokens"] tr.cs-integral-tokens-row td {
  display: block;
  width: 100%;
  padding: 4px 0;
  text-align: left;
}

/* ─── Hidden attribute (genérico dentro del summary) ───── */
/* Asegura que setAttribute('hidden','') oculte correctamente
   cualquier elemento dentro del summary, incluso si WC aplica
   display:block!important a esos elementos. */
body.cs-checkout-integral-enabled .cs-integral-summary [hidden] {
  display: none !important;
}

/* ─── Responsive 9C.2 ───────────────────────────────────── */

@media (max-width: 600px) {
  body.cs-checkout-integral-enabled .cs-integral-summary__toggle {
    font-size: 0.78em;
  }
  body.cs-checkout-integral-enabled .cs-integral-summary__save {
    width: 100%;
    text-align: center;
  }
  body.cs-checkout-integral-enabled .cs-integral-summary__panel-actions {
    justify-content: stretch;
  }
}

/* =========================================================
   LOTE 9C.2A — Corrección de slots: Envío y Total

   - Suprimir sección delivery (guardia CSS por si persiste en caché).
   - Wrapper table para la fila <tr> de envío extraída de la review table.
   - Slot totals full width para la shop_table completa.
   ========================================================= */

/* ─── Suprimir sección delivery ─────────────────────────── */

body.cs-checkout-integral-enabled [data-cs-integral-section="delivery"] {
  display: none !important;
}

/* ─── Wrapper table de la fila de envío ─────────────────── */

body.cs-checkout-integral-enabled .cs-integral-shipping-table {
  width: 100%;
  border-collapse: collapse;
  border: none;
}

body.cs-checkout-integral-enabled .cs-integral-shipping-table th,
body.cs-checkout-integral-enabled .cs-integral-shipping-table td {
  padding: 4px 0;
  text-align: left;
  vertical-align: top;
  border: none;
}

/* ─── Slot totals: ancho completo para la shop_table ────── */

body.cs-checkout-integral-enabled [data-cs-integral-slot="totals"] {
  width: 100%;
  overflow-x: auto;
}

body.cs-checkout-integral-enabled [data-cs-integral-slot="totals"] .woocommerce-checkout-review-order-table {
  width: 100%;
}

/* ─── Slot shipping: ancho completo ─────────────────────── */

body.cs-checkout-integral-enabled [data-cs-integral-slot="shipping"] {
  width: 100%;
}

/* =========================================================
   LOTE 9C.3 — Carrito Integral
   Scoped: body.cs-cart-integral-enabled
   Solo se aplica en la página de carrito cuando la feature
   flag del Checkout Integral está activa.
   No afecta la página de checkout ni ningún otro contexto.
   ========================================================= */

/* ─── Suprimir barra de progreso del checkout en el carrito ─ */
body.cs-cart-integral-enabled .cs-checkout-progress {
  display: none !important;
}

/* ─── Suprimir cálculo de envío y destino en cart_totals ─── */
body.cs-cart-integral-enabled .cart_totals .shipping,
body.cs-cart-integral-enabled .cart_totals .calculated_shipping,
body.cs-cart-integral-enabled .cart_totals .woocommerce-shipping-destination,
body.cs-cart-integral-enabled .cart_totals .woocommerce-shipping-calculator,
body.cs-cart-integral-enabled .cart_totals .shipping-calculator-button,
body.cs-cart-integral-enabled .cart_totals .shipping-calculator-form {
  display: none !important;
}

/* ─── Suprimir botón Actualizar Carrito (JS mantiene funcionalidad) ─ */
body.cs-cart-integral-enabled button[name="update_cart"],
body.cs-cart-integral-enabled input[name="update_cart"] {
  display: none !important;
}

/* =========================================================
   LOTE 9C.4 — Correcciones operativas finales
   Scoped: body.cs-checkout-integral-enabled (checkout)
   ========================================================= */

/* ─── B: Payment card — estado activo visual ────────────── */
body.cs-checkout-integral-enabled #payment ul.wc_payment_methods li.payment_method {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

body.cs-checkout-integral-enabled #payment ul.wc_payment_methods li.payment_method.is-selected {
  border-color: var(--cs-primary, #0066cc);
  background: rgba(0, 102, 204, 0.04);
}

/* ─── E: Controles de cantidad inline en productos del checkout ─ */
.cs-integral-product__qty-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 6px 0;
}

.cs-integral-product__qty-btn {
  background: var(--cs-surface, #f5f5f5);
  border: 1px solid var(--cs-border, #ddd);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  min-width: 28px;
  height: 28px;
  padding: 0;
}

.cs-integral-product__qty-btn:hover {
  background: var(--cs-border, #ddd);
}

.cs-integral-product__qty-input {
  max-width: 52px;
  height: 28px;
  text-align: center;
  border: 1px solid var(--cs-border, #ddd);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 0.875rem;
}

.cs-integral-product__remove-btn {
  background: transparent;
  border: 1px solid #e55;
  border-radius: 4px;
  color: #e55;
  cursor: pointer;
  font-size: 1rem;
  height: 28px;
  min-width: 28px;
  padding: 0;
}

.cs-integral-product__remove-btn:hover {
  background: #ffe5e5;
}

/* ─── F: Ocultar toggle "Es la misma dirección" ─────────── */
body.cs-checkout-integral-enabled .cs-checkout-same-address-toggle p.form-row,
body.cs-checkout-integral-enabled .cs-checkout-same-address-toggle .cs-checkout-same-address,
body.cs-checkout-integral-enabled .cs-checkout-same-address-toggle label {
  display: none !important;
}

/* ─── F: Nombre y Apellido en la misma fila ─────────────── */
body.cs-checkout-integral-enabled .woocommerce-billing-fields .form-row-first,
body.cs-checkout-integral-enabled .woocommerce-billing-fields .form-row-last {
  display: inline-block;
  width: 48%;
  clear: none;
  vertical-align: top;
}

body.cs-checkout-integral-enabled .woocommerce-billing-fields .form-row-first {
  float: left;
  margin-right: 2%;
}

body.cs-checkout-integral-enabled .woocommerce-billing-fields .form-row-last {
  float: right;
}

/* ─── FIX 8 / LOTE 9C.5: Ocultar toggle cupón en /finalizar-compra ─ */
/* El cupón se aplica desde /carrito; no se necesita el toggle aquí.  */
body.cs-checkout-integral-enabled .woocommerce-form-coupon-toggle,
body.cs-checkout-integral-enabled .woocommerce-form-coupon-toggle + .woocommerce-form-coupon {
  display: none !important;
}

@media (max-width: 768px) {
  .cs-integral-product__qty-input {
    max-width: 50%;
  }
}

