/* ==========================================================================
   The WooCommerce loop card — ONE card design, everywhere.

   This sheet is enqueued at priority 20 on wp_enqueue_scripts, i.e. AFTER
   woocommerce.css, so equal-specificity rules win by source order and no
   !important is needed. The two exceptions are marked and explained.

   The old cards were: 4px radius, no border, no hover, no transition, title
   17px/500 (identical to body copy), price 14.57px/400 — SMALLER and lighter
   than the title — and `object-fit: fill`, which stretched a 4:3 hamper photo
   and a 1:1 jar photo into different shapes side by side.
   ========================================================================== */

/* --------------------------------------------------------------------------
   GOTCHA 1 — the clearfix that eats the first cell.

   WooCommerce core ships `.woocommerce ul.products::before/::after
   { content:" "; display:table }`. In a CSS grid those pseudo-elements become
   grid ITEMS and shift every card right by one, leaving cell 1 empty. This is
   the one place !important is correct: we need to beat core at equal
   specificity from a sheet that may load before it in some contexts.
   -------------------------------------------------------------------------- */

.woocommerce ul.products::before,
.woocommerce ul.products::after,
ul.products::before,
ul.products::after {
  content: none !important;
  display: none !important;
}

/* --------------------------------------------------------------------------
   GOTCHA 2 — one card on the shop AND on the homepage.

   Woo's own loop styles are scoped `.woocommerce ul.products li.product`,
   which match on shop/archive/search but NOT inside a homepage block, whose
   <body> carries no `.woocommerce` class. Every selector below is therefore
   written unscoped, and the `.woocommerce`-scoped re-assertion at the foot of
   this file repeats the same declarations so the two can never diverge.
   -------------------------------------------------------------------------- */

ul.products {
  display: grid;
  grid-template-columns: repeat(var(--wop-cols, 4), minmax(0, 1fr));
  gap: var(--wop-grid-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

ul.products.columns-3 { --wop-cols: 3; }
ul.products.columns-4 { --wop-cols: 4; }

/* The breakpoints have to repeat the `.columns-N` selectors.
   WooCommerce puts `columns-4` on every archive's <ul>, so the rule above is
   0,2,1 while a plain `ul.products` inside a media query is 0,1,1 — and A MEDIA
   QUERY ADDS NO SPECIFICITY. The desktop rule therefore won at every width, and
   category archives stayed FOUR columns on a phone: measured 66.75px columns
   and 38px-wide cards at 390px.

   Only columns-3 and above are stepped down at each breakpoint, so a shop
   deliberately set to one or two columns is never widened by this. */

@media (max-width: 1024px) {
  ul.products,
  ul.products.columns-4,
  ul.products.columns-5,
  ul.products.columns-6 { --wop-cols: 3; }
}
@media (max-width: 780px) {
  ul.products,
  ul.products.columns-3,
  ul.products.columns-4,
  ul.products.columns-5,
  ul.products.columns-6 { --wop-cols: 2; }
}
@media (max-width: 420px) {
  ul.products,
  ul.products.columns-2,
  ul.products.columns-3,
  ul.products.columns-4,
  ul.products.columns-5,
  ul.products.columns-6 { --wop-cols: 1; }
}

ul.products li.product {
  position: relative;
  display: flex;
  flex-direction: column;
  width: auto;          /* Woo hands out percentage widths for its float grid */
  margin: 0;
  /* 18px, not 14px: a 16px corner radius needs more inset than that or the
     content reads as if it is falling out of the card, and the pill button
     ends up almost touching the sides. */
  padding: 18px;
  float: none;
  background: var(--wop-card-bg);
  border: 1px solid var(--wop-border);
  border-radius: var(--wop-radius-lg);
  box-shadow: var(--wop-shadow-sm);
  transition: transform var(--wop-dur) var(--wop-ease),
              box-shadow var(--wop-dur) var(--wop-ease);
}

ul.products li.product:hover {
  transform: translateY(-4px);
  box-shadow: var(--wop-shadow-lg);
}

/* ---- Image ---- */

ul.products li.product a img {
  width: 100%;
  height: auto;
  margin: 0 0 16px;
  aspect-ratio: var(--wop-aspect-product);
  object-fit: cover;          /* was `fill` — which stretched every photo */
  border-radius: var(--wop-radius);
  filter: var(--wop-img-filter);
}

/* Product photos: show the whole product (ticket 181). These are cut-outs on
   white, most of them wide, so `cover` in a 4:5 box cut the ends off every
   rack and barrier. A square box with `contain` fits them all, and the white
   the image sits on is the card's own white. Category tiles keep the 4:5
   crop above: those are designed tiles, not product shots. */
ul.products li.product:not(.product-category) a img {
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

/* ---- Title ---- */

ul.products li.product .woocommerce-loop-product__title {
  margin: 0 0 10px;
  padding: 0;
  color: var(--wop-heading);
  font-size: var(--wop-text-lg);
  font-weight: 600;
  line-height: var(--wop-lh-normal);

  /* Product titles here are SEO strings — one runs to 110 characters. Two
     lines, then ellipsis, so a card cannot become mostly text. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Category eyebrow (added by content-product.php) ---- */

ul.products li.product .wop-loop__cat {
  display: block;
  margin-bottom: 8px;
  color: var(--wop-text-muted);
  font-size: var(--wop-text-xs);
  font-weight: 600;
  letter-spacing: var(--wop-ls-caps);
  text-transform: uppercase;
}

/* ---- Price ---- */

ul.products li.product .price {
  display: block;
  margin: 0;
  color: var(--wop-heading);
  font-size: var(--wop-text-xl);
  font-weight: 700;
  line-height: 1.2;

  /* GOTCHA 3 — `margin-top:auto` on the button pins it to the card bottom, but
     when a two-line title fills the card that auto gap collapses and the price
     jams against the button. A fixed bottom margin guarantees a minimum gap. */
  margin-bottom: 14px;
}

ul.products li.product .price del {
  margin-right: 6px;
  color: var(--wop-text-muted);
  font-size: var(--wop-text-base);
  font-weight: 400;
}
ul.products li.product .price ins {
  text-decoration: none;
  background: transparent;
}

/* Variable products render "£4.00 – £6.00"; keep that on one line. */
ul.products li.product .price .woocommerce-Price-amount { white-space: nowrap; }

/* ---- Button ---- */

ul.products li.product .button,
ul.products li.product .added_to_cart {
  margin-top: auto;         /* pin to the card bottom — see GOTCHA 3 above */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--wop-tap-min);
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--wop-btn-radius);

  /* Donor leftover: this card came from a theme whose button was GOLD
     (#f7cc4d), where dark ink on it was 12.1:1. Retokening the background to
     navy left the ink behind, giving #052646 on #073769 — 1.28:1, which is
     invisible, not merely low contrast. White on the button navy is 14.96:1
     and matches every other button on the site. */
  background: var(--wop-btn-bg);
  color: var(--wop-text-invert);
  font-family: inherit;
  font-size: var(--wop-text-sm);
  font-weight: 600;
  letter-spacing: var(--wop-ls-caps);
  text-align: center;
  text-transform: uppercase;
  text-decoration: none;
  transition: background var(--wop-dur) var(--wop-ease),
              box-shadow var(--wop-dur) var(--wop-ease);
}

ul.products li.product .button:hover,
ul.products li.product .added_to_cart:hover {
  background: var(--wop-brand);
  color: var(--wop-text-invert);
  box-shadow: none;
}

ul.products li.product .button.loading { opacity: .7; }

ul.products li.product .added_to_cart {
  margin-top: 8px;
  background: transparent;
  border-color: var(--wop-brand-dark);
  color: var(--wop-heading);
}
ul.products li.product .added_to_cart:hover {
  background: var(--wop-brand-dark);
  color: var(--wop-text-invert);
  box-shadow: none;
}

/* The "multiple variants" note Woo prints under Select Options. */
ul.products li.product .wop-loop__variants,
ul.products li.product small.woocommerce-loop-product__variants {
  margin-top: 8px;
  color: var(--wop-text-muted);
  font-size: var(--wop-text-xs);
  line-height: 1.4;
}

/* ---- Sale flash ---- */

ul.products li.product .onsale {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 2;
  min-height: 0;
  min-width: 0;
  margin: 0;
  padding: 5px 12px;
  border-radius: var(--wop-radius-pill);
  background: var(--wop-brand-dark);
  color: var(--wop-text-invert);
  font-size: var(--wop-text-xs);
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: var(--wop-ls-caps);
}

/* ---- Star rating ---- */

ul.products li.product .star-rating {
  margin: 0 0 8px;
  color: var(--wop-brand-deep);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   GOTCHA 2, second half — re-assert the SAME design under `.woocommerce`.

   Identical declarations, higher specificity. This is what stops the shop
   archive and the homepage grid drifting apart. If you change a value above,
   change it here too — or better, move it to a token.
   -------------------------------------------------------------------------- */

.woocommerce ul.products {
  display: grid;
  grid-template-columns: repeat(var(--wop-cols, 4), minmax(0, 1fr));
  gap: var(--wop-grid-gap);
  margin: 0;
  padding: 0;
}

.woocommerce ul.products li.product {
  width: auto;
  margin: 0;
  padding: 18px;
  float: none;
  display: flex;
  flex-direction: column;
  background: var(--wop-card-bg);
  border: 1px solid var(--wop-border);
  border-radius: var(--wop-radius-lg);
  box-shadow: var(--wop-shadow-sm);
}

.woocommerce ul.products li.product a img {
  margin: 0 0 16px;
  aspect-ratio: var(--wop-aspect-product);
  object-fit: cover;
  border-radius: var(--wop-radius);
}

.woocommerce ul.products li.product:not(.product-category) a img {
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

.woocommerce ul.products li.product .woocommerce-loop-product__title {
  padding: 0;
  margin: 0 0 10px;
  font-size: var(--wop-text-lg);
  font-weight: 600;
}

.woocommerce ul.products li.product .price {
  color: var(--wop-heading);
  font-size: var(--wop-text-xl);
  font-weight: 700;
  margin-bottom: 14px;
}

/* Same rule again at WooCommerce's own specificity, so `.woocommerce` on the
   body cannot reintroduce the plugin's purple. Keep the two in step. */
.woocommerce ul.products li.product .button {
  margin-top: auto;
  padding: 12px 20px;
  border-radius: var(--wop-btn-radius);
  background: var(--wop-btn-bg);
  color: var(--wop-text-invert);
  font-size: var(--wop-text-sm);
  font-weight: 600;
  letter-spacing: var(--wop-ls-caps);
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   GOTCHA 4 — woocommerce-smallscreen.css re-floats the cards below 768px.

   The same specificity trap as the `.alt` basket button and the product tabs,
   and the one the `.columns-N` breakpoints above do NOT cover. WooCommerce
   enqueues `woocommerce-smallscreen.css` with media="only screen and
   (max-width: 768px)", and it carries:

     .woocommerce ul.products[class*="columns-"] li.product            0,4,1
       { width: 48%; float: left; clear: both; margin: 0 0 2.992em }
     .woocommerce ul.products[class*="columns-"] li.product:nth-child(2n)   0,5,1
       { float: right; clear: none !important }

   The re-assertion above is `.woocommerce ul.products li.product`, 0,3,1, so
   it LOST outright — an attribute selector counts as a class. The grid laid
   its tracks out correctly and Woo then forced every card to 48% of its own
   track: measured 157px cards in a 327px single column at 390px, and 164px
   cards in 341px tracks at 768px. Each card sat in the left half of its cell
   with the other half empty, plus a 2.992em margin the grid gap already
   provides.

   Desktop was unaffected, which is why it survived every check: above 768px
   the sheet does not apply at all. The homepage grid was unaffected too — its
   <ul> carries no `columns-` class, so the attribute selector never matched.

   Matching each selector exactly ties the specificity, and this file is
   enqueued after all three Woo stylesheets, so the tie breaks our way.
   `clear` is set to the same value Woo marks !important, so the !important
   is harmless rather than something to fight.
   -------------------------------------------------------------------------- */

.woocommerce ul.products[class*="columns-"] li.product,
.woocommerce ul.products[class*="columns-"] li.product:nth-child(2n) {
  width: auto;
  float: none;
  clear: none;
  margin: 0;
}
