/* ==========================================================================
   MotoJoy — product cell

   One owner for .mj-product-cell, the designed catalog cell. Registered as a
   shared style handle so any section rendering products consumes the same
   stylesheet rather than restyling the cell.

   Two variants, both documented in docs/design-system.md: --machine (§8.4,
   landscape media plus a specification strip) and --gear (§8.3, portrait
   media). They differ in media ratio and in which parts are present; the rest
   is identical, which is why they share a file rather than fork.
   ========================================================================== */

/* A detached card with the ink edge and hard shadow of the submenu and cart
   notice — §5.3. The cell owns it, so every grid that lays cells out (shop,
   product rail, related products, cart cross-sells) only sets a gap. */
.mj-product-cell {
  display: flex;
  flex-direction: column;
  background-color: var(--wp--preset--color--bg);
  border: 1px solid var(--wp--preset--color--ink);
  box-shadow: var(--wp--preset--shadow--hard);
}

/* Hover fills the cell — §5.3. Nothing lifts, the shadow stays. Guarded so a
   touch device does not strand a cell in the hover state after a tap. */
@media (hover: hover) and (pointer: fine) {
  .mj-product-cell:hover {
    background-color: var(--wp--preset--color--surface);
  }
}

/* Paint containment, not position: relative, anchors the stacked images and
   badge without creating a stacking context that paints over the cell edge. */
.mj-product-cell__media {
  contain: paint;
  display: block;
  overflow: hidden;
  /* White, not surface: most supplier shots sit on white, so a white plane
     makes their edges disappear under contain. */
  background-color: var(--wp--preset--color--bg);
}

/* Ratio per cell type — design-system.md §8.3 (D2). The box sets grid rhythm
   only; contain below fits every supplier shape inside it uncut. */
.mj-product-cell--machine .mj-product-cell__media {
  aspect-ratio: var(--wp--custom--ratio-machine);
}

.mj-product-cell--gear .mj-product-cell__media {
  aspect-ratio: var(--wp--custom--ratio-gear);
}

/* Absolutely positioned so the two views stack in the same box; the media's
   aspect-ratio owns the height. Contain, because supplier images arrive square,
   landscape and portrait within one category and cover would cut the product.
   The padding keeps edge-to-edge shots off the hairline. */
.mj-product-cell__image {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: var(--wp--preset--spacing--3);
  object-fit: contain;
}

/* The secondary view needs its own plane, or the primary shows through the
   letterbox of a differently shaped second image. */
.mj-product-cell__image--secondary {
  background-color: var(--wp--preset--color--bg);
}

/* Second supplier view on hover — §8.3. It sits inside the media area only, so
   it can never cover the price, stock or action. */
.mj-product-cell__image--secondary {
  opacity: 0;
}

@media (hover: hover) and (pointer: fine) {
  .mj-product-cell__image--secondary {
    transition: opacity var(--wp--custom--duration-base)
      var(--wp--custom--ease-out);
  }

  .mj-product-cell:hover .mj-product-cell__image--secondary {
    opacity: 1;
  }
}

/* §7: reduce to no transition. The swap itself is opacity-only, which the
   reduced-motion guidance permits; it is the cross-fade that goes. */
@media (prefers-reduced-motion: reduce) {
  .mj-product-cell__image--secondary {
    transition: none;
  }
}

/* Rectangular, uppercase, no radius, one per media area — §8.7. */
.mj-product-cell__badge {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  padding: var(--wp--preset--spacing--1) var(--wp--preset--spacing--2);
  color: var(--wp--preset--color--text-on-dark);
  font-size: var(--wp--preset--font-size--label);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--wp--custom--tracking-label);
}

/* Planes come from motojoy_product_badge(): brand = sale, ink = Naujiena or Populiaru. */
.mj-product-cell__badge--brand {
  background-color: var(--wp--preset--color--brand);
}

.mj-product-cell__badge--ink {
  background-color: var(--wp--preset--color--ink);
}

.mj-product-cell__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--wp--preset--spacing--2);
  padding: var(--wp--preset--spacing--4);
}

.mj-product-cell__body > * {
  margin-block: 0;
}

.mj-product-cell__cat {
  color: var(--wp--preset--color--text-muted);
  font-size: var(--wp--preset--font-size--label);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--wp--custom--tracking-label);
}

/* Supplier names run long; the cell must survive two lines without the price
   and action drifting out of alignment across a row. */
.mj-product-cell__title {
  /* §8.3: body 500, max two lines, clamped. Same technique shop.css uses for
     the catalog intro, so the project has one way of clamping text.
     -webkit-line-clamp needs display:-webkit-box; both are required. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: var(--wp--preset--font-size--body);
  font-weight: 500;
  line-height: var(--wp--custom--leading-body);
  /* Supplier titles arrive as model codes that can run 90 characters with no
     space in them. Without a break opportunity such a token lays out wider
     than its column and escapes the cell — the retired product card hid this
     behind overflow:hidden on its root rather than letting the text wrap. */
  overflow-wrap: anywhere;
}

.mj-product-cell__title a {
  color: var(--wp--preset--color--ink);
  text-decoration: none;
}

.mj-product-cell__title a:hover,
.mj-product-cell__title a:focus-visible {
  text-decoration: underline;
}

/* Specification strip: the same hairline table as the catalog grid, so the
   cell reads as part of one system — §5.3. */
.mj-product-cell__specs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-block: var(--wp--preset--spacing--2);
  font-size: var(--wp--preset--font-size--sm);
  font-weight: 500;
  border-block-start: 1px solid var(--wp--preset--color--rule);
}

.mj-product-cell__specs dt,
.mj-product-cell__specs dd {
  margin: 0;
  padding-block: var(--wp--preset--spacing--1);
  border-block-end: 1px solid var(--wp--preset--color--rule);
}

.mj-product-cell__specs dt {
  color: var(--wp--preset--color--text-muted);
}

.mj-product-cell__specs dd {
  font-variant-numeric: tabular-nums;
}

/* margin-block-start:auto pins price, stock and action to the bottom so they
   align across a row regardless of how far the title wraps. */
.mj-product-cell__price {
  margin-block-start: auto;
  font-size: var(--wp--preset--font-size--price);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* WooCommerce emits the original inside <del> on a sale item. */
.mj-product-cell__price del {
  margin-inline-end: var(--wp--preset--spacing--2);
  color: var(--wp--preset--color--text-muted);
  font-size: var(--wp--preset--font-size--sm);
  font-weight: 500;
}

.mj-product-cell__price ins {
  text-decoration: none;
}

.mj-product-cell__price-sub {
  margin-inline-start: var(--wp--preset--spacing--2);
  color: var(--wp--preset--color--text-muted);
  font-size: var(--wp--preset--font-size--sm);
  font-weight: 500;
}

/* Status pairs colour with a mark and a word, never colour alone — §3.4. */
.mj-product-cell__stock {
  display: flex;
  align-items: center;
  gap: var(--wp--preset--spacing--2);
  font-size: var(--wp--preset--font-size--sm);
  font-weight: 500;
}

.mj-product-cell__stock.is-in {
  color: var(--wp--preset--color--success);
}

.mj-product-cell__stock.is-low {
  color: var(--wp--preset--color--warning);
}

/* Out of stock is neutral, not an error: the product stays orderable. */
.mj-product-cell__stock.is-out {
  color: var(--wp--preset--color--text-muted);
}

/* Backorder keeps the is-out action treatment but reads as "attention". */
.mj-product-cell__stock.is-backorder {
  color: var(--wp--preset--color--warning);
}

.mj-product-cell__delivery {
  color: var(--wp--preset--color--text-muted);
  font-size: var(--wp--preset--font-size--sm);
  font-weight: 500;
}

.mj-product-cell__action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--wp--custom--control-h-compact);
  margin-block-start: var(--wp--preset--spacing--3);
  padding-inline: var(--wp--preset--spacing--4);
  color: var(--wp--preset--color--text-on-dark);
  font-size: var(--wp--preset--font-size--button);
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: var(--wp--custom--tracking-label);
  background-color: var(--wp--preset--color--ink);
  border: 1px solid var(--wp--preset--color--ink);
}

.mj-product-cell__action:hover,
.mj-product-cell__action:focus-visible {
  color: var(--wp--preset--color--text-on-dark);
  background-color: var(--wp--preset--color--ink-soft);
  border-color: var(--wp--preset--color--ink-soft);
}

.mj-product-cell__action:focus-visible {
  outline: var(--wp--custom--focus-ring-width) solid
    var(--wp--preset--color--focus);
  outline-offset: var(--wp--custom--focus-ring-offset);
}

/* Revealed on hover — §8.3. Opacity keeps its space so price and stock never
   move; focus-within keeps it reachable and visible from the keyboard. Touch
   devices fall outside the query and always show it. */
@media (hover: hover) and (pointer: fine) {
  .mj-product-cell__action {
    opacity: 0;
    transition: opacity var(--wp--custom--duration-base)
      var(--wp--custom--ease-out);
  }

  .mj-product-cell:hover .mj-product-cell__action,
  .mj-product-cell:focus-within .mj-product-cell__action {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mj-product-cell__action {
    transition: none;
  }
}

/* An out-of-stock product is still orderable, so its action stays available
   but drops to the secondary treatment rather than reading as the primary
   buy action — §8.1. */
.mj-product-cell__stock.is-out ~ .mj-product-cell__action {
  color: var(--wp--preset--color--ink);
  background-color: transparent;
  border-color: var(--wp--preset--color--border);
}

.mj-product-cell__stock.is-out ~ .mj-product-cell__action:hover,
.mj-product-cell__stock.is-out ~ .mj-product-cell__action:focus-visible {
  color: var(--wp--preset--color--text-on-dark);
  background-color: var(--wp--preset--color--ink);
  border-color: var(--wp--preset--color--ink);
}
