/*
 * Tarjetas de producto y cantidades.
 *
 * Esta capa se limita a los grids reales de Productos/Busqueda y a los
 * controles de cantidad del detalle. No modifica las tarjetas editoriales de
 * Inicio, las categorias ni los badges HOT/NEW/PROMO.
 */

/* El titulo dispone de dos lineas estables. Si necesita mas, se recorta sin
 * puntos suspensivos para evitar finales distintos entre navegadores. */
:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton) {
  height: auto !important;
}

:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  > .normal,
:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .product-item-bot,
:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .text-bar {
  flex: 0 0 auto !important;
  min-width: 0 !important;
}

:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .text {
  box-sizing: border-box;
  height: 32px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  overflow: hidden !important;
}

:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .name {
  display: block !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: 32px !important;
  overflow: hidden !important;
  text-overflow: clip !important;
  white-space: normal !important;
  -webkit-box-orient: initial !important;
  -webkit-line-clamp: initial !important;
}

:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  :is(
    .price-line,
    .packet-actions,
    .spec-inline,
    .action-buttons,
    .quantity-bar
  ) {
  min-width: 0;
}

/* En catalogo la linea de precio esta vacia. Pack y favorito comparten una
 * unica fila tactil de 44 px en vez de reservar dos filas separadas. */
html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .text-bar {
  display: grid !important;
  grid-template-areas:
    "gf-title gf-title"
    "gf-pack gf-wishlist";
  grid-template-columns: minmax(0, 1fr) 44px;
  grid-template-rows: 32px 44px;
  column-gap: 2px;
  width: 100%;
}

html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .text {
  grid-area: gf-title;
}

html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .price-line {
  grid-area: gf-wishlist;
  align-self: stretch;
  justify-self: stretch;
  width: 44px !important;
  height: 44px !important;
  margin: 0 !important;
}

html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .price-line
  > .price-inline {
  flex: 0 0 44px !important;
  align-self: stretch;
  justify-content: center;
  box-sizing: border-box;
  width: 44px !important;
  min-width: 44px !important;
  height: 44px !important;
  min-height: 44px !important;
  margin: 0 !important;
}

html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .wishlist-btn {
  width: 44px !important;
  height: 44px !important;
  margin: 0 !important;
}

html.storefront-public-route:is(
    .storefront-catalog,
    .gf-b2b-access-pending,
    .gf-b2b-visitor-catalog
  )
  :is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .packet-actions {
  grid-area: gf-pack;
  align-self: stretch;
  width: 100%;
  height: 44px;
  margin: 0 !important;
  padding: 0 !important;
}

/* Identidad comun del badge de cantidad en listados. */
:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  > .quantity {
  position: absolute !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 36px !important;
  min-height: 28px;
  max-width: calc(100% - 20px);
  margin: 0 !important;
  padding: 5px 8px !important;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.94) !important;
  border-radius: 8px !important;
  background: var(--b2b-brand, #d91f26) !important;
  box-shadow: 0 2px 6px rgba(123, 15, 21, 0.24) !important;
  color: #fff !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 16px !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
  top: 10px !important;
  left: 10px !important;
  z-index: 20 !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* El detalle conserva un badge deliberadamente mayor tambien en movil. */
ion-modal.product-modal-shell
  .product-modal
  .media
  > .quantity-chip {
  position: absolute !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 42px !important;
  min-height: 30px;
  margin: 0 !important;
  padding: 5px 9px !important;
  border: 1px solid rgba(255, 255, 255, 0.94) !important;
  border-radius: 9px !important;
  background: var(--b2b-brand, #d91f26) !important;
  box-shadow: 0 2px 7px rgba(123, 15, 21, 0.26) !important;
  color: #fff !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 18px !important;
  white-space: nowrap !important;
  top: 10px !important;
  left: 10px !important;
  z-index: 3 !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

ion-modal.product-modal-shell .product-modal .media > .badge-stack {
  max-width: calc(100% - 78px) !important;
}

/* Los controles de cantidad de los listados se agrupan sin heredar los
 * 12 px del componente. El detalle mantiene su separacion propia. */
:is(app-products, app-search)
  .product-grid
  .product-item:not(.skeleton)
  .packet-actions
  .quantity-bar {
  gap: 2px !important;
}

/* El valor y el estado MAX utilizan exactamente el mismo ancho. */
:is(app-products, app-search, app-product-detail-modal)
  .quantity-bar
  .qty-input-wrap,
:is(app-products, app-search, app-product-detail-modal)
  .quantity-bar
  .qty-input,
:is(app-products, app-search, app-product-detail-modal)
  .quantity-bar
  .qty-input-wrap.is-max
  .qty-input {
  flex: 0 0 52px !important;
  box-sizing: border-box !important;
  width: 52px !important;
  min-width: 52px !important;
  max-width: 52px !important;
}

@media (max-width: 767px) {
  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .product-item-bot {
    padding: 3px 4px 2px !important;
  }

  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .packet-actions {
    gap: 2px;
  }

  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .spec-inline {
    flex: 1 1 auto !important;
    overflow: hidden;
    font-size: 12.5px;
  }

  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .packet-actions
    .action-buttons {
    flex: 0 0 auto;
    margin: 0 !important;
  }

  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .packet-actions
    .quantity-bar {
    gap: 2px !important;
  }

  /* Dos controles de 40 px y 2 px de separacion caben en una tarjeta de
   * 158 px a 320 px de viewport sin sacrificar el objetivo tactil. */
  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .packet-actions
    .qty-btn {
    display: inline-flex !important;
    flex: 0 0 40px !important;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
    margin: 0 !important;
  }

  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    .packet-actions
    .qty-btn::part(native) {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 40px !important;
  }

  /* En las tarjetas moviles se conserva una escala algo menor que en
   * escritorio; el detalle queda excluido y mantiene como minimo 42 x 30 px. */
  :is(app-products, app-search)
    .product-grid
    .product-item:not(.skeleton)
    > .quantity {
    min-width: 32px !important;
    min-height: 26px;
    max-width: calc(100% - 14px);
    padding: 4px 7px !important;
    font-size: 13px !important;
    line-height: 16px !important;
    top: 7px !important;
    left: 7px !important;
  }
}
