/**
 * Shared product card (template-parts/product-card.php).
 *
 * Used by the homepage grids and every classic product loop (shop, categories,
 * search, upsells, cross-sells). Loaded site-wide by inc/ms-shop-product-card.php.
 *
 * Selectors start with `:is(.ms-shop-home, ul.products li.product) .ms-shop-card`
 * so they beat Storefront's loop rules and style.css's archive link colours
 * (`body.woocommerce.archive .site-main a`). The older `.product-wrapper`
 * card rules in style.css no longer match anything.
 *
 * Fonts: the card uses the homepage font variables when present (Inter / Plus
 * Jakarta Sans on the front page) and inherits the site font (Montserrat) elsewhere.
 */

/* ---------------------------------------------------------------------
 * Loop grid: 3 → 2 → 1 columns (replaces Storefront's float columns).
 * #page raises specificity above Storefront's `.storefront-full-width-content
 * .site-main ul.products.columns-3 li.product` width rules.
 * ------------------------------------------------------------------- */
#page ul.products.ms-shop-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 24px;
  margin: 0 0 32px;
  padding: 0;
  list-style: none;
}

/* Archive pages (shop, categories, tags, product search): always 3 per row on desktop. */
.archive #page ul.products.ms-shop-card-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 900px) {
  .archive #page ul.products.ms-shop-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .archive #page ul.products.ms-shop-card-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

#page ul.products.ms-shop-card-grid::before,
#page ul.products.ms-shop-card-grid::after {
  content: none;
  display: none;
}

#page ul.products.ms-shop-card-grid > li.product {
  display: flex;
  width: auto;
  min-width: 0;
  float: none;
  clear: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

/* style.css has `.product.type-product { margin-right: 30px !important; }` (≥768px),
   which also styles the single-product wrapper, so cancel it only inside the card grid. */
#page ul.products.ms-shop-card-grid > li.product.type-product {
  margin-right: 0 !important;
}

/* ---------------------------------------------------------------------
 * Card
 * ------------------------------------------------------------------- */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card {
  --ms-shop-card-tint: #eaf6fc;
  --ms-shop-card-ink: #0f172a;
  --ms-shop-card-muted: #5b6676;
  --ms-shop-card-text: #334155; /* body copy: darker than muted for readability */
  --ms-shop-card-line: #e6e8ec;
  --ms-shop-card-line-strong: #c9cfd8;
  --ms-shop-card-navy: #00324c;
  --ms-shop-card-navy-hover: #00243a;
  --ms-shop-card-blue: #1475b0;
  --ms-shop-card-amber: #f5a623;
  --ms-shop-card-sale: #0f6b4f;

  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  overflow: clip; /* clips the sale ribbon without making the card scrollable */
  background: #fff;
  border: 1px solid var(--ms-shop-card-line);
  border-radius: 24px;
  color: var(--ms-shop-card-ink);
  font-family: var(--ms-shop-home-sans, inherit);
  text-align: left;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card *,
:is(.ms-shop-home, ul.products li.product) .ms-shop-card *::before,
:is(.ms-shop-home, ul.products li.product) .ms-shop-card *::after {
  box-sizing: border-box;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card a:focus-visible {
  outline: 2px solid var(--ms-shop-card-blue);
  outline-offset: 2px;
}

/* Image area */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.ms-shop-card__media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 5 / 5; /* portrait frame */
  background: #fff;
  border-bottom: 1px solid var(--ms-shop-card-line);
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__media
  img {
  /* Fill the frame (minus 24px padding) so every frame stays exactly 4:5. */
  position: absolute;
  inset: 24px;
  display: block;
  width: calc(100% - 48px);
  height: calc(100% - 48px);
  max-width: none;
  margin: 0;
  border-radius: 0;
  object-fit: contain;
  box-shadow: none;
}

/* Tags ("New"; on-sale cards use the ribbon instead) */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__tag {
  position: absolute;
  top: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  font-weight: 700;
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__tag--new {
  background: var(--ms-shop-card-amber);
  color: var(--ms-shop-card-navy);
}

/* Sale ribbon: diagonal band across the top-right corner (same look as the
   product page ribbon). The card's overflow: hidden + radius clips its ends. */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__ribbon {
  position: absolute;
  top: 36px;
  right: -53px;
  z-index: 2;
  width: 210px;
  padding: 9px 0;
  background: var(--ms-shop-card-sale);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  color: #fff;
  font-size: 10px;
  line-height: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  transform: rotate(45deg);
  pointer-events: none;
}

/* Body */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__title {
  margin: 0;
  padding: 0;
  font-family: var(--ms-shop-home-display, inherit);
  font-size: 20px;
  line-height: 26px;
  font-weight: 600;
  letter-spacing: normal;
  color: var(--ms-shop-card-ink);
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__title
  a {
  color: var(--ms-shop-card-ink);
  text-decoration: none;
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__title
  a:hover,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__title
  a:focus {
  color: var(--ms-shop-card-blue);
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__desc {
  margin: 0;
  font-size: 15px;
  line-height: 22px;
  color: var(--ms-shop-card-text);
  /* Full excerpt; keep the line breaks typed in the Listing excerpt field. */
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* Price */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__price {
  display: flex;
  flex-direction: column;
  margin-top: auto;
  padding-top: 12px;
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__price-label {
  font-size: 12px;
  color: var(--ms-shop-card-muted);
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__price-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__amount {
  font-family: var(--ms-shop-home-display, inherit);
  font-size: 22px;
  line-height: 28px;
  font-weight: 600;
  color: var(--ms-shop-card-ink);
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card .ms-shop-card__was {
  font-size: 14px;
  color: var(--ms-shop-card-muted);
  text-decoration: line-through;
  opacity: 1;
}

/* Buttons: the theme's Buy Now (primary, navy) first, then Add to Cart.
   Without a Buy Now (homepage cards, variable products) Add to Cart / Select options is navy. */
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.ms-shop-card__btn,
:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 12px;
  box-shadow: none;
  font-family: var(--ms-shop-home-sans, inherit);
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  text-shadow: none;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.ms-shop-card__btn,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn:visited {
  background: var(--ms-shop-card-navy);
  border-color: var(--ms-shop-card-navy);
  color: #fff;
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn:hover,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn:focus {
  background: var(--ms-shop-card-navy-hover);
  border-color: var(--ms-shop-card-navy-hover);
  color: #fff;
}

/* Buy Now: primary. */
:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now,
:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now:visited {
  background: var(--ms-shop-card-navy);
  border-color: var(--ms-shop-card-navy);
  color: #fff;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now:hover,
:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now:focus {
  background: var(--ms-shop-card-navy-hover);
  border-color: var(--ms-shop-card-navy-hover);
  color: #fff;
}

/* Add to Cart next to a Buy Now: secondary (white). */
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__actions:has(a.buy-now)
  a.ms-shop-card__btn,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__actions:has(a.buy-now)
  a.ms-shop-card__btn:visited {
  background: #fff;
  border-color: var(--ms-shop-card-line-strong);
  color: var(--ms-shop-card-ink);
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__actions:has(a.buy-now)
  a.ms-shop-card__btn:hover,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  .ms-shop-card__actions:has(a.buy-now)
  a.ms-shop-card__btn:focus {
  background: #fff;
  border-color: var(--ms-shop-card-muted);
  color: var(--ms-shop-card-ink);
}

/* AJAX add-to-cart states (WooCommerce adds .loading / .added and a "View cart" link). */
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn.loading {
  opacity: 0.7;
}

:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn.loading::after,
:is(.ms-shop-home, ul.products li.product)
  .ms-shop-card
  a.ms-shop-card__btn.added::after {
  position: static;
  margin: 0 0 0 4px;
}

:is(.ms-shop-home, ul.products li.product) .ms-shop-card a.added_to_cart {
  display: block;
  margin: 0;
  padding: 2px 0;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--ms-shop-card-blue);
}

@media (prefers-reduced-motion: reduce) {
  :is(.ms-shop-home, ul.products li.product) .ms-shop-card a.ms-shop-card__btn,
  :is(.ms-shop-home, ul.products li.product) .ms-shop-card a.buy-now {
    transition: none;
  }
}
