/*
 * Related products — single product page only.
 *
 * Markup: single-product.php wraps WooCommerce's standard related template
 *   .related-section > section.related.products > h2 + .shop-grid > article.product
 * Cards come from woocommerce/content-product.php (shared with shop/search),
 * so every rule here is scoped to .related-section and loads after style.css.
 *
 * Enqueued from functions.php only when is_product(); its version is the
 * file's modification time, so uploading this file alone busts caches.
 */

/* ── Section ── */
.related-section {
  margin-top: 48px;
  padding: 40px 0 64px;
  border-top: 1px solid var(--line);
}

/* WC's <section> carries the global .products class, whose grid put the
   heading beside the cards. Reset it to a plain block. */
.related-section .related.products {
  display: block;
  width: auto;
  margin: 0;
}

.related-section .related.products > h2 {
  margin: 0 0 24px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--navy-900);
  text-align: right;
  letter-spacing: -0.01em;
}

/* ── Grid: 4 columns (≥768px) → 2 columns; fixed tracks keep card size constant
   whether there are 1 or 4 related products ── */
.related-section .shop-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

/* ── Card ── */
.related-section .shop-grid > .product {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.related-section .shop-grid > .product:hover {
  transform: translateY(-3px);
  box-shadow: var(--sh-2);
  border-color: var(--blue-100);
}

/* Image: square frame, 500×500 source shown whole and centred */
.related-section .shop-grid .product .media {
  aspect-ratio: 1 / 1;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.related-section .shop-grid .product .media > a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 14px;
  box-sizing: border-box;
}
.related-section .shop-grid .product .media img,
.related-section .shop-grid .product .media .product-thumb {
  width: 100%;
  height: 100%;
  max-width: 500px;
  max-height: 500px;
  object-fit: contain;
}
.related-section .shop-grid .product .media .ph {
  position: static;
  border-radius: var(--r-md);
}

/* Body: name, price, then the button pinned to the bottom */
.related-section .shop-grid .product .body {
  flex: 1;
  gap: 6px;
  padding: 14px 14px 16px;
}
.related-section .shop-grid .product .name {
  min-height: 3em;               /* always reserve two lines */
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.related-section .shop-grid .product .name a:hover {
  color: var(--blue-600);
}
.related-section .shop-grid .product .price-row {
  flex-wrap: wrap;
  row-gap: 2px;
  margin-top: auto;              /* price + button align across a row */
  padding-top: 4px;
}
.related-section .shop-grid .product .price {
  font-size: 18px;
  line-height: 1.3;
}

.related-section .shop-grid .product .add {
  min-height: 42px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  font-size: 14px;
  line-height: 1.2;
}
.related-section .shop-grid .product .add.out-of-stock {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-400);
}
.related-section .shop-grid .product .add.out-of-stock:hover {
  background: var(--bg-soft);
}
.related-section .shop-grid .product .add:focus-visible,
.related-section .shop-grid .product .fav:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

/* "View cart" link WooCommerce appends after an AJAX add */
.related-section .shop-grid .product .added_to_cart {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-600);
  text-align: center;
}

/* ── Tablet: stays at 4 columns — WooCommerce shows 4 related products,
   and 3 columns would leave the fourth alone on a second row ── */
@media (max-width: 1023px) {
  .related-section .shop-grid {
    gap: 16px;
  }
  .related-section .shop-grid .product .body {
    padding: 12px 12px 14px;
  }
  .related-section .shop-grid .product .add {
    font-size: 13px;
  }
}

/* ── Mobile ── */
@media (max-width: 767px) {
  .related-section {
    margin-top: 32px;
    padding: 28px 0 40px;
  }
  .related-section .related.products > h2 {
    margin-bottom: 16px;
    font-size: 20px;
  }
  .related-section .shop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .related-section .shop-grid .product .media > a {
    padding: 10px;
  }
  .related-section .shop-grid .product .badges {
    top: 8px;
    right: 8px;
  }
  .related-section .shop-grid .product .fav {
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
  }
  .related-section .shop-grid .product .body {
    padding: 10px 10px 12px;
  }
  .related-section .shop-grid .product .name {
    font-size: 13px;
  }
  .related-section .shop-grid .product .price {
    font-size: 16px;
  }
  .related-section .shop-grid .product .add {
    min-height: 40px;
    padding: 8px;
    gap: 6px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .related-section .shop-grid > .product,
  .related-section .shop-grid > .product:hover {
    transition: none;
    transform: none;
  }
}
