/* Ported from dev custom-css-js snippet 178958 "Catalog Density" on 2026-11-25 (Trello: Slim down Catalog Product Pages). */
/**
 * Catalog Density - tighten vertical spacing in catalog product cards,
 * bottom-align the lower block, and move the wishlist control onto the image.
 * Scoped to catalog/archive/search listings only; single product pages,
 * related products and cart cross-sells are untouched.
 * Trello: "Slim down Catalog Product Pages"
 */

/* ---- Card container ---------------------------------------------------- */

/* Pack content to the top; the lower block is bottom-pinned separately. */
body.archive ul.products li.product,
body.post-type-archive-product ul.products li.product,
body.search-results ul.products li.product {
    justify-content: flex-start;
}

/* Gap between product rows: 53.86px -> 24px.
   The .woocommerce on the body is load-bearing, not decoration. WooCommerce
   ships woocommerce-smallscreen.css, which sets this margin through
   .woocommerce ul.products[class*="columns-"] li.product and scores (0,4,2).
   Without the extra class this rule is (0,3,3) and loses below ~768px, so the
   row gap silently stayed at 53.86px on phones and tablets. This is (0,4,3). */
body.archive.woocommerce ul.products li.product,
body.post-type-archive-product.woocommerce ul.products li.product,
body.search-results.woocommerce ul.products li.product {
    margin-bottom: 24px;
}

/* ---- Image, title, reviews, price -------------------------------------- */

/* Image: 1em -> 0.5em */
body.archive ul.products li.product a img,
body.post-type-archive-product ul.products li.product a img,
body.search-results ul.products li.product a img {
    margin-bottom: 0.5em;
}

/* Title: 16px -> 14px with a tighter line box. !important is required to beat
   snippet 155527 ("Backorder, Cart, and Catalog Styling"), which forces 16px.
   Scoped to catalog listings, so 155527 still governs everywhere else. */
body.archive ul.products li.product .woocommerce-loop-product__title,
body.post-type-archive-product ul.products li.product .woocommerce-loop-product__title,
body.search-results ul.products li.product .woocommerce-loop-product__title {
    font-size: 14px !important;
    line-height: 1.35;
    padding: 0.25em 0;
}

/* Reviews (Yotpo star row): strip the margins above and below. */
body.archive ul.products li.product .yotpo-widget-instance,
body.post-type-archive-product ul.products li.product .yotpo-widget-instance,
body.search-results ul.products li.product .yotpo-widget-instance {
    margin-top: 0;
    margin-bottom: 0;
}

body.archive ul.products li.product .yotpo-widget-instance .yotpo-reviews-star-ratings-widget,
body.post-type-archive-product ul.products li.product .yotpo-widget-instance .yotpo-reviews-star-ratings-widget,
body.search-results ul.products li.product .yotpo-widget-instance .yotpo-reviews-star-ratings-widget {
    margin-top: 0 !important;
    margin-bottom: 2px !important;
}

/* Price: 0.5em -> 0.25em */
body.archive ul.products li.product .price,
body.post-type-archive-product ul.products li.product .price,
body.search-results ul.products li.product .price {
    margin-bottom: 0.25em;
}

/* ---- Bottom-justified lower block -------------------------------------- */

/* The image/title/price link is always present, always visible, and always the
   first flex child, so parking the free space directly after it bottom-pins
   everything below as one group. Do NOT move this onto the colour label or the
   swatch row: snippet 155527 ("Simple Swatches Jumping Fix") sets display:none
   on those for some products, and a display:none element is not a flex item, so
   the auto margin silently does nothing and the button rides up. */
body.archive ul.products li.product > a.woocommerce-LoopProduct-link,
body.post-type-archive-product ul.products li.product > a.woocommerce-LoopProduct-link,
body.search-results ul.products li.product > a.woocommerce-LoopProduct-link {
    margin-bottom: auto;
}

/* Swatch row: 5px above, 10px below (the gap up to Add to cart). */
body.archive ul.products li.product .simple_swatches-options-archive,
body.post-type-archive-product ul.products li.product .simple_swatches-options-archive,
body.search-results ul.products li.product .simple_swatches-options-archive {
    margin-top: 5px;
    margin-bottom: 10px;
}

/* Add to cart / Read more: slimmer, and no extra margin since the swatch row
   below-margin already sets the gap. */
body.archive ul.products li.product .button,
body.post-type-archive-product ul.products li.product .button,
body.search-results ul.products li.product .button {
    margin-top: 0;
    padding-top: 10px;
    padding-bottom: 10px;
}

/* ---- Wishlist as a heart over the image -------------------------------- */

/* li.product is already position:relative, so this anchors to the card, whose
   top edge is the product image. */
body.archive ul.products li.product .yith-add-to-wishlist-button-block,
body.post-type-archive-product ul.products li.product .yith-add-to-wishlist-button-block,
body.search-results ul.products li.product .yith-add-to-wishlist-button-block {
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
    margin: 0;
    z-index: 5;
}

body.archive ul.products li.product .yith-add-to-wishlist-button-block a,
body.post-type-archive-product ul.products li.product .yith-add-to-wishlist-button-block a,
body.search-results ul.products li.product .yith-add-to-wishlist-button-block a {
    position: relative;
    /* Icon colour is left to YITH (--add-to-wishlist-icon-color, the site red).
       Setting colour here would be dead CSS: YITH colours the SVG directly
       rather than letting it inherit. The shadow keeps the outline readable
       against both light and dark product photos. */
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.75));
}

body.archive ul.products li.product .yith-add-to-wishlist-button-block .yith-wcwl-icon,
body.post-type-archive-product ul.products li.product .yith-add-to-wishlist-button-block .yith-wcwl-icon,
body.search-results ul.products li.product .yith-add-to-wishlist-button-block .yith-wcwl-icon {
    width: 22px;
    height: 22px;
}

/* The "Add to Wishlist" text becomes a hover/focus tooltip. Using opacity
   rather than display:none keeps it readable by screen readers. */
body.archive ul.products li.product .yith-wcwl-add-to-wishlist-button__label,
body.post-type-archive-product ul.products li.product .yith-wcwl-add-to-wishlist-button__label,
body.search-results ul.products li.product .yith-wcwl-add-to-wishlist-button__label {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    padding: 3px 6px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 11px;
    line-height: 1.4;
    white-space: nowrap;
    border-radius: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-in-out;
}

body.archive ul.products li.product .yith-add-to-wishlist-button-block a:hover .yith-wcwl-add-to-wishlist-button__label,
body.archive ul.products li.product .yith-add-to-wishlist-button-block a:focus .yith-wcwl-add-to-wishlist-button__label,
body.post-type-archive-product ul.products li.product .yith-add-to-wishlist-button-block a:hover .yith-wcwl-add-to-wishlist-button__label,
body.post-type-archive-product ul.products li.product .yith-add-to-wishlist-button-block a:focus .yith-wcwl-add-to-wishlist-button__label,
body.search-results ul.products li.product .yith-add-to-wishlist-button-block a:hover .yith-wcwl-add-to-wishlist-button__label,
body.search-results ul.products li.product .yith-add-to-wishlist-button-block a:focus .yith-wcwl-add-to-wishlist-button__label {
    opacity: 1;
}

/* ---- Partial last row: keep products in line ----
 *
 * genesis-sample-woocommerce.css lays the product list out as
 *   .woocommerce ul.products { display:flex; flex-wrap:wrap; justify-content:space-between }
 * which spreads each row across the full width. A FULL row of four looks
 * right, so this has gone unnoticed - but a row with two left over gets them
 * shoved to opposite edges, with a hole in the middle. Measured at 1440px: the
 * last two cards sat at x=173 and x=693 instead of 173 and 355.
 *
 * Pre-existing, and it affects every archive whose product count is not a
 * multiple of the column count - not only filtered searches.
 *
 * Fixed by packing rows from the left and using WooCommerce's own 3.8% gutter
 * as the gap instead of the per-item right margin. 3.8% is the gutter all of
 * WooCommerce's column widths are designed around (22.05% x4, 30.75% x3,
 * 48% x2 ...), so this holds at every column count rather than only at four.
 *
 * Verified full rows do not move: 1440px columns go 173/355/537/720 ->
 * 173/354/535/717, and at 420px (two columns) the layout is identical.
 */
.woocommerce ul.products {
    justify-content: flex-start;
    column-gap: 3.8%;
}

.woocommerce ul.products li.product {
    /* replaced by the column-gap above; !important because WooCommerce's own
       layout stylesheet sets the margin on several selectors. */
    margin-right: 0 !important;
}
