/* ============================================================
   Product card and product scroller

   One product card for the whole storefront: the homepage
   catalogue, shop.php, the search results grid and the related
   products on a product page. It used to be four different
   cards — see app/helpers/product.php.

   The card is deliberately understated. The product photograph
   is the only saturated thing in it; everything else is black,
   white, a hairline and one gold rule that appears on hover.
   ============================================================ */

/* --- Scroller ------------------------------------------------ */
.product-scroller {
  position: relative;
}

.product-track {
  display: flex;
  gap: var(--space-5);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: var(--space-2) 2px var(--space-4);
  -webkit-overflow-scrolling: touch;
}

.product-track::-webkit-scrollbar {
  display: none;
}

.product-track > .product-tile {
  flex: 0 0 calc((100% - 3 * var(--space-5)) / 4);
  scroll-snap-align: start;
}

@media (max-width: 1199px) {
  .product-track > .product-tile { flex: 0 0 calc((100% - 2 * var(--space-5)) / 3); }
}

@media (max-width: 900px) {
  .product-track > .product-tile { flex: 0 0 calc((100% - var(--space-5)) / 2); }
}

@media (max-width: 600px) {
  .product-track { gap: var(--space-3); }
  .product-track > .product-tile { flex: 0 0 76%; }
}

/* Arrows sit on the card edge, vertically centred on the image */
.product-scroller .scroll-arrow {
  position: absolute;
  top: calc(var(--space-2) + 50%);
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--brand-black);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  opacity: 1;
  z-index: 2;
}

.product-scroller .scroll-arrow.left-arrow { left: -14px; }
.product-scroller .scroll-arrow.right-arrow { right: -14px; }

/* Inside a banded section the arrow would otherwise sit on the band's
   rounded corner. Pull the track in and the arrows land on the padding
   instead of the edge. */
.section--band .product-scroller {
  padding-inline: var(--space-4);
}

.section--band .product-scroller .scroll-arrow.left-arrow { left: -8px; }
.section--band .product-scroller .scroll-arrow.right-arrow { right: -8px; }

.product-scroller .scroll-arrow:hover:not(:disabled),
.product-scroller .scroll-arrow:focus-visible {
  background: var(--brand-black);
  color: var(--brand-gold);
  border-color: var(--brand-black);
}

.product-scroller .scroll-arrow:disabled {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 900px) {
  /* Touch scrolling is the interaction on a phone; the arrows
     would only cover the first and last card. */
  .product-scroller .scroll-arrow { display: none; }
}

/* --- Grid ---------------------------------------------------- */
.product-grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
}

@media (max-width: 600px) {
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }
}

.product-grid__empty {
  grid-column: 1 / -1;
  width: 100%;
  padding: var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

/* --- The card ------------------------------------------------ */
.product-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--brand-black);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

/* The gold rule that appears along the top on hover — the whole
   of the card's "interaction colour", and nothing else moves. */
.product-tile::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--brand-gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-slow);
  z-index: 3;
}

.product-tile:hover,
.product-tile:focus-visible,
.product-tile:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 10px 30px rgba(35, 31, 32, 0.10);
  transform: translateY(-2px);
  color: var(--brand-black);
}

.product-tile:hover::before,
.product-tile:focus-within::before {
  transform: scaleX(1);
}

.product-tile__media {
  position: relative;
  aspect-ratio: 1 / 1;
  /* A hair of warmth behind the cut-out product photos, so white
     packshots do not float on a white card. */
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  overflow: hidden;
}

.product-tile__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: var(--space-5);
  transition: transform var(--transition-slow);
}

.product-tile:hover .product-tile__media img {
  transform: scale(1.04);
}

/* --- Badges -------------------------------------------------- */
.product-tile__tags {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  right: var(--space-3);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  pointer-events: none;
}

.product-tile__badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  line-height: 1;
}

.product-tile__badge--save {
  background: var(--brand-black);
  color: var(--brand-gold);
}

.product-tile__badge--new {
  background: var(--surface);
  color: var(--brand-black);
  border: 1px solid var(--brand-black);
}

.product-tile__stock {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  background: var(--warning-bg);
  color: #8a4b00;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
}

/* The old card slid a black "view details" bar over the image on
   hover. The whole card is the link; the bar was decoration that
   covered the product. */
.product-tile__cta {
  display: none;
}

/* --- Body ---------------------------------------------------- */
.product-tile__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  border-top: 1px solid var(--border-color);
  flex: 1;
}

.product-tile__brand {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.product-tile__title {
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
}

.product-tile__prices {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-3);
}

.product-tile__price {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--brand-black);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.product-tile--sale .product-tile__price {
  /* Sale prices stay gold, in the readable gold — the bright brand gold
     measured 2.2:1 against the card. */
  color: var(--gold-text);
}

.product-tile__price-was {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
  .product-tile__media img { padding: var(--space-3); }
  .product-tile__body { padding: var(--space-3); }
  .product-tile__title { font-size: var(--fs-sm); }
  .product-tile__price { font-size: var(--fs-base); }
}

@media (prefers-reduced-motion: reduce) {
  .product-tile,
  .product-tile:hover,
  .product-tile__media img,
  .product-tile:hover .product-tile__media img {
    transform: none;
    transition: none;
  }
}
