/**
 * megacart — carrito lateral deslizante. Autor: Ecomm Sistema.
 */

/* El tema le da el tamano/icono de fondo al div .header (42x42 en escritorio, otro tamano
   en movil dentro de #_mobile_cart), pero el <a> con el evento de clic dentro no tiene
   tamano propio (sus hijos van display:none): sin esto el enlace queda a 0x0 y un clic/tap
   real no cae sobre el (un clic sintetico via JS "funciona" igual porque no depende del
   hit-testing del navegador — por eso este bug no se detecta probando por JS).
   Sin ID de #_desktop_cart/#_mobile_cart delante: el theme MUEVE el bloque entre uno y
   otro contenedor segun el ancho de pantalla, asi que la regla tiene que valer en ambos. */
.blockcart .header a.js-megacart-toggle {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

/* Insignia de unidades: se posiciona aqui mismo (no depender de la regla del theme para
   #_desktop_cart, que no aplica dentro de #_mobile_cart y dejaba la insignia sin sitio,
   con ancho/alto 0 al ir dentro de un <a> tambien colapsado). */
.blockcart .header a.js-megacart-toggle span.cart-products-count {
  display: flex !important;
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  align-items: center;
  justify-content: center;
  background: #1a2340;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
}

.blockcart.inactive .header a.js-megacart-toggle span.cart-products-count,
.blockcart .header a.js-megacart-toggle span.cart-products-count:empty {
  display: none !important;
}

/* Panel lateral (mismo patron que otros paneles deslizantes: fixed + transform por right) */
.megacart-popup {
  position: fixed;
  z-index: 1200;
  top: 0;
  right: -420px;
  width: 420px;
  max-width: 100%;
  height: 100vh;
  /* En movil 100vh incluye la zona tapada por la barra del navegador: dvh es el alto visible */
  height: 100dvh;
  background: #fff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .15);
  transition: right .3s ease-in-out;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
}

.megacart-popup.open {
  right: 0;
}

.megacart-popup::-webkit-scrollbar {
  width: 5px;
}

.megacart-popup::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 5px;
}

.overlay-lateral-popup {
  position: fixed;
  z-index: 1100;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s ease-in-out;
}

body.openMegacartPopup {
  overflow: hidden;
}

body.openMegacartPopup .overlay-lateral-popup {
  opacity: .45;
  visibility: visible;
}

/* Cabecera del panel */
.megacart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
  margin-bottom: 16px;
  padding-right: 10px;
}

.megacart-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a2340;
}

.megacart-popup .close-popup {
  cursor: pointer;
  width: 18px;
  height: 18px;
  position: relative;
}

.megacart-popup .close-popup:before,
.megacart-popup .close-popup:after {
  content: '';
  position: absolute;
  top: 8px;
  left: 0;
  width: 18px;
  border-bottom: 2px solid #1a2340;
}

.megacart-popup .close-popup:before {
  transform: rotate(45deg);
}

.megacart-popup .close-popup:after {
  transform: rotate(-45deg);
}

/* Aviso envio gratis */
.megacart-freeshipping {
  background: #fdf6e3;
  color: #7a5b00;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .85rem;
  text-align: center;
  margin-bottom: 16px;
}

.megacart-freeshipping.is-reached {
  background: #e7f6ec;
  color: #1f7a41;
}

/* Lista de productos */
.megacart-products {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 10px;
}

.megacart-product-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid #f0f0f0;
}

.megacart-product-image {
  flex: 0 0 72px;
  width: 72px;
}

.megacart-product-image img {
  width: 100%;
  border-radius: 8px;
  display: block;
}

.megacart-product-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.megacart-product-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.megacart-product-name {
  font-weight: 600;
  color: #1a2340;
  font-size: .95rem;
  text-decoration: none;
}

.megacart-product-attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.megacart-attr {
  background: #f2f2f2;
  color: #555;
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 999px;
}

/* Fotos y textos que el cliente ha personalizado (modulo megacustomization) */
.megacart-product-custom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}

.megacart-custom-img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border: 1px solid #e3e6ea;
  border-radius: 3px;
  background: #fff;
}

.megacart-custom-text {
  background: #f2f2f2;
  color: #555;
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.megacart-product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.megacart-qty-controls {
  display: flex;
  align-items: center;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
}

.megacart-qty-btn {
  border: none;
  background: #fff;
  width: 26px;
  height: 26px;
  line-height: 26px;
  cursor: pointer;
  font-size: .95rem;
  color: #1a2340;
}

.megacart-qty-btn:hover {
  background: #f2f2f2;
}

.megacart-qty-value {
  min-width: 28px;
  text-align: center;
  font-size: .85rem;
}

.megacart-product-price {
  flex: 0 0 auto;
  font-weight: 600;
  color: #1a2340;
  font-size: .95rem;
  white-space: nowrap;
}

.megacart-remove {
  color: #999;
  display: inline-flex;
  align-items: center;
  transition: color .2s ease;
}

.megacart-remove:hover {
  color: #c0392b;
}

.megacart-remove .material-icons {
  font-size: 18px;
}

/* Bloque inferior fijo: totales + botones */
.megacart-bottom {
  border-top: 1px solid #eee;
  padding-top: 16px;
  margin-top: 12px;
  padding-right: 10px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.megacart-row {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
  padding: 4px 0;
  color: #555;
}

.megacart-row.megacart-total {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a2340;
  padding-top: 8px;
  border-top: 1px solid #f0f0f0;
  margin-top: 6px;
}

.megacart-row.megacart-discount .value {
  color: #1f7a41;
}

.megacart-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.megacart-btn {
  flex: 0 0 auto;
  text-align: center;
  padding: 12px 10px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
}

.megacart-actions .megacart-btn {
  flex: 1 1 50%;
}

.megacart-btn-secondary {
  background: #fff;
  border-color: #ddd;
  color: #1a2340;
}

.megacart-btn-secondary:hover {
  border-color: #1a2340;
}

.megacart-btn-primary {
  background: var(--color3);
  color: #fff;
}

.megacart-btn-primary:hover {
  background: #101627;
  color: #fff;
}

/* Carrito vacio */
.megacart-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}

.megacart-empty-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: #1a2340;
}

.megacart-empty-sub {
  color: #777;
  font-size: .9rem;
  margin-bottom: 10px;
}

@media (max-width: 480px) {
  .megacart-popup {
    width: 100%;
    right: -100%;
    padding: 18px 4px 18px 14px

  }
}
