/**
 * CSS FORZADO PARA CARDS UNIFORMES
 * Desktop: 321px x 492px
 * Tablet: Cards flexibles
 * Mobile: 2 columnas con cards fluidas
 *
 * IMPORTANTE: Este CSS NO se aplica en modo moderno (data-modern="true")
 */

/* -------------------------
 * RESET PARA MODO MODERNO
 * ------------------------- */
.waeg-shop-wrapper[data-modern="true"] .waeg-grid ul.products,
.waeg-shop-wrapper[data-modern="true"] .waeg-grid li.product {
  all: revert !important;
}

/* -------------------------
 * REGLA GLOBAL PARA BOTONES
 * Ocultar botones de WC por defecto y mostrar solo los personalizados en móvil.
 * ------------------------- */
.waeg-grid li.product .button,
.waeg-grid li.product .add_to_cart_button {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  position: absolute !important;
  left: -9999px !important;
}

.waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart,
.waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: all !important;
  position: relative !important;
  left: auto !important;
  width: 100%;
  height: auto;
}

/* ===========================
   DESKTOP (> 1024px)
   Grid con cards de 321px fijas y 4 columnas con cards de 267px.
   =========================== */
@media (min-width: 1025px) {
  /* Ocultar botones móviles y mostrar los de WooCommerce */
  .waeg-grid li.product .waeg-mobile-button-row {
    display: none;
  }

  .waeg-grid li.product .button,
  .waeg-grid li.product .add_to_cart_button,
  .waeg-grid li.product a.button,
  .waeg-grid li.product button.button {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: all !important;
    position: relative !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* --- Layout principal (auto-fill) --- */
  .waeg-grid ul.products {
    display: grid;
    grid-template-columns: repeat(auto-fill, 321px);
    gap: 12px;
    align-items: stretch;
    justify-content: center;
  }

  .waeg-grid li.product {
    display: grid;
    grid-template-rows: 280px 40px 24px 1fr 48px;
    gap: 0;
    width: 321px;
    height: 517px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    padding: 0;
    margin: 0;
  }

  .waeg-grid li.product img {
    grid-row: 1;
    width: 100%;
    height: 323px;
    object-fit: contain;
    padding: 8px;
    background: #fafafa;
    margin: 0;
    border-radius: 8px 8px 0 0;
  }

  .waeg-grid li.product .woocommerce-loop-product__title {
    grid-row: 2;
    height: 40px;
    margin: 4px 16px 0;
    padding: 0;
    font-size: 15px;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .waeg-grid li.product .price {
    grid-row: 3;
    height: 24px;
    margin: 4px 16px;
    padding: 0;
    font-size: 11.6px;
    font-weight: 600;
  }

  .waeg-grid li.product::before {
    content: '';
    grid-row: 4;
    min-height: 4px;
  }

  .waeg-grid li.product .button,
  .waeg-grid li.product .add_to_cart_button {
    grid-row: 5;
    margin: 0 12px 16px;
    width: calc(100% - 24px);
  }

  /* --- Layout 4 columnas (.waeg-columns-4) --- */
  .waeg-columns-4 .waeg-grid ul.products {
    grid-template-columns: repeat(4, 267px);
  }

  .waeg-columns-4 .waeg-grid li.product {
    grid-template-rows: 210px 36px 24px 1fr 44px;
    width: 267px;
    height: 390px;
  }
  
  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row {
    display: flex;
    flex-direction: row;
    gap: 6px;
    grid-row: 5;
    margin: 0 8px 12px;
    align-items: stretch;
    justify-content: center;
    width: calc(100% - 16px);
    box-sizing: border-box;
  }
  
  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    padding: 10px 4px;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp svg {
    width: 14px;
    height: 14px;
    fill: white;
    flex-shrink: 0;
  }

  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp:hover {
    background: #1eae57;
  }

  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 10px 4px;
    background: #7B0303;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
  }
  
  .waeg-columns-4 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart:hover {
    background: var(--waeg-primary-darker);
    transform: translateY(-2px);
  }

  .waeg-columns-4 .waeg-grid li.product img {
    height: 210px;
    padding: 14px;
  }

  .waeg-columns-4 .waeg-grid li.product .woocommerce-loop-product__title {
    height: 36px;
    margin: 6px 12px 0;
    font-size: 13px;
  }

  .waeg-columns-4 .waeg-grid li.product .price {
    height: 24px;
    margin: 4px 12px;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    color: var(--waeg-gray-700);
  }
  
  /* --- Comportamiento de enlaces e insignia 'onsale' --- */
  .waeg-grid li.product a.woocommerce-loop-product__link {
    display: contents;
    pointer-events: none;
  }
  
  .waeg-grid li.product a.woocommerce-loop-product__link img,
  .waeg-grid li.product .woocommerce-loop-product__title {
    pointer-events: all;
    cursor: pointer;
  }

  .waeg-grid li.product .onsale {
    display: none !important;
  }

  /* Botón WC estándar "Ver" — estilo igual al waeg-btn-cart para 3-col */
  .waeg-grid li.product .ver-producto-btn {
    grid-row: 5;
    margin: 0 12px 16px;
    width: calc(100% - 24px);
    display: inline-flex !important;
    justify-content: center;
    align-items: center;
    background: #7B0303;
    color: white !important;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.3s ease;
  }

  .waeg-grid li.product .ver-producto-btn:hover {
    background: #5a0202;
    transform: translateY(-2px);
  }

  /* Ocultar botón "Ver" WC estándar en 4-col y 5-col (reemplazado por waeg-mobile-button-row) */
  .waeg-columns-4 .waeg-grid li.product .button,
  .waeg-columns-4 .waeg-grid li.product .add_to_cart_button,
  .waeg-columns-4 .waeg-grid li.product .ver-producto-btn,
  .waeg-columns-5 .waeg-grid li.product .button,
  .waeg-columns-5 .waeg-grid li.product .add_to_cart_button,
  .waeg-columns-5 .waeg-grid li.product .ver-producto-btn {
    display: none !important;
  }

  /* --- Layout 5 columnas (.waeg-columns-5) — 15% más pequeño que 4 col --- */
  /* 4-col: 267×390px → 5-col: 227×332px */
  .waeg-columns-5 .waeg-grid ul.products {
    grid-template-columns: repeat(5, 227px);
  }

  .waeg-columns-5 .waeg-grid li.product {
    grid-template-rows: 179px 31px 20px 1fr 38px;
    width: 227px;
    height: 332px;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row {
    display: flex;
    flex-direction: row;
    gap: 5px;
    grid-row: 5;
    margin: 0 6px 10px;
    align-items: stretch;
    justify-content: center;
    width: calc(100% - 12px);
    box-sizing: border-box;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 3px;
    flex: 1;
    min-width: 0;
    padding: 6px 3px;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 7px;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp svg {
    width: 12px;
    height: 12px;
    fill: white;
    flex-shrink: 0;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp:hover {
    background: #1eae57;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 6px 3px;
    background: #7B0303;
    color: white;
    border: none;
    border-radius: 7px;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    transition: all 0.3s ease;
  }

  .waeg-columns-5 .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart:hover {
    background: var(--waeg-primary-darker);
    transform: translateY(-2px);
  }

  .waeg-columns-5 .waeg-grid li.product img {
    height: 179px;
    padding: 12px;
  }

  .waeg-columns-5 .waeg-grid li.product .woocommerce-loop-product__title {
    height: 31px;
    margin: 5px 10px 0;
    font-size: 11px;
  }

  .waeg-columns-5 .waeg-grid li.product .price {
    height: 20px;
    margin: 3px 10px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    color: var(--waeg-gray-700);
  }
}

/* ===========================
   TABLET (721px - 1024px)
   Grid fluido con 2-3 columnas
   =========================== */
@media (min-width: 721px) and (max-width: 1024px) {
  .waeg-grid ul.products {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    padding: 0 12px;
  }

  .waeg-grid li.product {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: auto;
    min-height: 420px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    overflow: hidden;
    padding: 0;
    margin: 0;
  }

  .waeg-grid li.product img {
    height: 215px;
    object-fit: contain;
    padding: 8px;
    background: #fafafa;
    flex-shrink: 0;
    border-radius: 8px 8px 0 0;
  }

  .waeg-grid li.product .woocommerce-loop-product__title {
    min-height: 40px;
    max-height: 50px; /* Permitir algo de flexibilidad */
    margin: 4px 12px 0;
    font-size: 14px;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex-shrink: 0;
  }

  .waeg-grid li.product .price {
    margin: 8px 12px;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
  }

  .waeg-grid li.product .waeg-mobile-button-row {
    display: flex;
    flex-direction: row;
    gap: 6px;
    margin: auto 12px 12px;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    padding: 10px 6px;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp svg {
    width: 14px;
    height: 14px;
    fill: white;
    flex-shrink: 0;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp:hover {
    background: #1eae57;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    padding: 10px 6px;
    background: #7B0303;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    transition: all 0.3s ease;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart:hover {
    background: var(--waeg-primary-darker);
  }
  
  .waeg-grid li.product a.woocommerce-loop-product__link {
    display: contents;
  }
}

/* ===========================
   MOBILE (<= 720px)
   2 columnas fluidas
   =========================== */
@media (max-width: 720px) {
  .waeg-grid ul.products {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 0 8px;
    align-items: stretch;
  }

  .waeg-grid li.product {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 280px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    overflow: hidden;
  }

  .waeg-grid li.product img {
    height: 175px;
    object-fit: contain;
    padding: 0;
    background: #fafafa;
    flex-shrink: 0;
    border-radius: 8px 8px 0 0;
  }

  .waeg-grid li.product .woocommerce-loop-product__title {
    min-height: 32px;
    max-height: 44px;
    margin: 2px 8px 0;
    font-size: 12px;
    line-height: 1.25;
    text-align: center;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex-shrink: 0;
  }

  .waeg-grid li.product .price {
    margin: 4px 8px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    flex-shrink: 0;
  }
  
  .waeg-grid li.product::before {
    display: none;
  }

  .waeg-grid li.product .waeg-mobile-button-row {
    display: flex;
    flex-direction: row;
    gap: 4px;
    margin: auto 6px 6px;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 6px 4px;
    background: #25D366;
    color: white;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp svg {
    width: 14px;
    height: 14px;
    fill: white;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 6px 4px;
    background: var(--waeg-gray-700);
    color: white;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
  }

  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart:hover {
    background: #1a1a1a;
  }

  .waeg-grid li.product a.woocommerce-loop-product__link {
    display: contents;
  }
}

/* ===========================
   MOBILE PEQUEÑO (<= 480px)
   =========================== */
@media (max-width: 480px) {
  .waeg-grid ul.products {
    gap: 6px;
    padding: 0 6px;
  }
  
  .waeg-grid li.product {
    min-height: 250px;
    border-radius: 8px;
  }
  
  .waeg-grid li.product img {
    min-height: 110px;
    max-height: 140px;
    padding: 6px;
  }
  
  .waeg-grid li.product .woocommerce-loop-product__title {
    font-size: 11px;
    margin: 4px 6px 0;
    min-height: 28px;
    max-height: 38px;
  }
  
  .waeg-grid li.product .price {
    font-size: 13px;
    margin: 3px 6px;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row {
    gap: 3px;
    margin: auto 4px 4px;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp,
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    height: 28px;
    padding: 5px 3px;
    font-size: 9px;
    border-radius: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp svg {
    width: 12px;
    height: 12px;
  }
}

/* ===========================
   MOBILE MUY PEQUEÑO (<= 360px)
   =========================== */
@media (max-width: 360px) {
  .waeg-grid ul.products {
    gap: 4px;
    padding: 0 4px;
  }
  
  .waeg-grid li.product {
    min-height: 230px;
  }
  
  .waeg-grid li.product img {
    height: 135px;
    padding: 0;
    object-fit: contain;
    border-radius: 8px 8px 0 0;
  }
  
  .waeg-grid li.product .woocommerce-loop-product__title {
    font-size: 10px;
    margin: 3px 4px 0;
    min-height: 24px;
    max-height: 32px;
    line-height: 1.2;
  }
  
  .waeg-grid li.product .price {
    font-size: 12px;
    margin: 2px 4px;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row {
    gap: 2px;
    margin: auto 3px 3px;
  }
  
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-whatsapp,
  .waeg-grid li.product .waeg-mobile-button-row .waeg-btn-cart {
    height: 26px;
    padding: 4px 2px;
    font-size: 8px;
    border-radius: 4px;
  }
}
