/**
 * Listing performance helpers for category + search grids.
 *
 * Product photos already ship with loading="lazy" (Magento image.phtml /
 * theme image pipeline — verified live 2026-07-09). This sheet reduces
 * offscreen paint cost and contains layout work.
 *
 * Scoped via layout XML to catalogsearch_result_index + catalog_category_view.
 *
 * 2026-07-15: Homecenter-inspired mobile card density (title clamp, price +
 * circular cart, hide in-stock noise).
 */

/* Paint offscreen product cards more cheaply (modern Chromium/Safari). */
.catalogsearch-result-index .products.wrapper.grid .product-item,
.catalog-category-view .products.wrapper.grid .product-item {
  content-visibility: auto;
  contain-intrinsic-size: auto 420px;
}

/* Prefer predictable image scaling. */
.catalogsearch-result-index .product-image-photo,
.catalog-category-view .product-image-photo {
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

/* Limit style/layout recalculation on hover-heavy product cards. */
.catalogsearch-result-index .product-item-info,
.catalog-category-view .product-item-info {
  contain: layout style;
}

/* -------------------------------------------------------------------------- */
/* Mobile type scale + Homecenter-like card chrome (≤768px)                   */
/* -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .catalog-category-view .products.wrapper.grid .product-item-info,
  .catalogsearch-result-index .products.wrapper.grid .product-item-info {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  /* --- Title: 2-line clamp so grid rows align --- */
  .catalog-category-view .products.wrapper.grid .product-item .product-item-name a,
  .catalogsearch-result-index .products.wrapper.grid .product-item .product-item-name a {
    display: -webkit-box !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden !important;
    font-size: 13px !important;
    line-height: 1.3 !important;
    max-height: 2.6em;
    min-height: 2.6em;
    text-transform: none !important;
  }

  /* --- Stock: hide “In stock” / “En stock”; keep OOS compact --- */
  .catalog-category-view .products.wrapper.grid .stock.available,
  .catalogsearch-result-index .products.wrapper.grid .stock.available,
  .catalog-category-view .products-grid .stock.available,
  .catalogsearch-result-index .products-grid .stock.available,
  .catalog-category-view .stock-info-block .stock.available,
  .catalogsearch-result-index .stock-info-block .stock.available {
    display: none !important;
  }

  /* Collapse empty stock block when only “available” was present */
  .catalog-category-view .products.wrapper.grid .stock-info-block:has(.stock.available):not(:has(.stock.unavailable)),
  .catalogsearch-result-index .products.wrapper.grid .stock-info-block:has(.stock.available):not(:has(.stock.unavailable)),
  .catalog-category-view .stock-info-block:has(.stock.available):not(:has(.stock.unavailable)),
  .catalogsearch-result-index .stock-info-block:has(.stock.available):not(:has(.stock.unavailable)) {
    display: none !important;
  }

  .catalog-category-view .products.wrapper.grid .stock.unavailable,
  .catalogsearch-result-index .products.wrapper.grid .stock.unavailable {
    display: inline-block !important;
    margin: 4px 0 0;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px !important;
    font-weight: 600;
    line-height: 1.3;
    color: #b42318;
    background: #fef3f2;
  }

  .catalog-category-view .products.wrapper.grid .stock.unavailable span,
  .catalogsearch-result-index .products.wrapper.grid .stock.unavailable span {
    font-size: inherit !important;
  }

  /* --- Drop short description on dense mobile grid --- */
  .catalog-category-view .products.wrapper.grid .product-item-description,
  .catalogsearch-result-index .products.wrapper.grid .product-item-description {
    display: none !important;
  }

  /* --- Footer: price left + cart right (Homecenter pattern) --- */
  .catalog-category-view .products.wrapper.grid .product-item-details.-footer,
  .catalogsearch-result-index .products.wrapper.grid .product-item-details.-footer {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px;
    width: 100%;
    margin-top: auto;
    padding-top: 8px;
  }

  .catalog-category-view .products.wrapper.grid .product-item-details.-footer .price-box,
  .catalogsearch-result-index .products.wrapper.grid .product-item-details.-footer .price-box {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
  }

  .catalog-category-view .products.wrapper.grid .product-item .price-box .price-container .price,
  .catalogsearch-result-index .products.wrapper.grid .product-item .price-box .price-container .price {
    font-size: 15px !important;
    font-weight: 700 !important;
    line-height: 1.2;
    letter-spacing: -0.02em;
  }

  .catalog-category-view .products.wrapper.grid .product-item-actions,
  .catalogsearch-result-index .products.wrapper.grid .product-item-actions {
    flex: 0 0 auto;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    margin: 0 !important;
    width: auto !important;
    max-width: none !important;
  }

  /* Hide compare/wishlist on dense mobile cards (cart is primary) */
  .catalog-category-view .products.wrapper.grid .product-item-actions .actions-secondary,
  .catalogsearch-result-index .products.wrapper.grid .product-item-actions .actions-secondary {
    display: none !important;
  }

  .catalog-category-view .products.wrapper.grid .product-item-actions .actions-primary,
  .catalogsearch-result-index .products.wrapper.grid .product-item-actions .actions-primary {
    margin: 0 !important;
    width: auto !important;
  }

  /* Circular icon cart — text stays in DOM for a11y, visually clipped */
  .catalog-category-view .products.wrapper.grid .action.tocart,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart {
    position: relative !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 2px solid #e84e24 !important;
    border-radius: 50% !important;
    background: #fff !important;
    color: #e84e24 !important;
    box-shadow: none !important;
    overflow: hidden;
    flex: 0 0 44px !important;
  }

  .catalog-category-view .products.wrapper.grid .action.tocart:hover,
  .catalog-category-view .products.wrapper.grid .action.tocart:focus-visible,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart:hover,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart:focus-visible {
    background: #e84e24 !important;
    color: #fff !important;
  }

  .catalog-category-view .products.wrapper.grid .action.tocart span,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  /* Cart glyph (simple bag) via mask so hover color works */
  .catalog-category-view .products.wrapper.grid .action.tocart::before,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart::before {
    content: "" !important;
    display: block;
    width: 20px;
    height: 20px;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='21' r='1'/%3E%3Ccircle cx='20' cy='21' r='1'/%3E%3Cpath d='M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='21' r='1'/%3E%3Ccircle cx='20' cy='21' r='1'/%3E%3Cpath d='M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  /* Kill Athlete2 ::after underlines / full-width button paints on mobile grid cart */
  .catalog-category-view .products.wrapper.grid .action.tocart::after,
  .catalogsearch-result-index .products.wrapper.grid .action.tocart::after {
    display: none !important;
    content: none !important;
  }
}
