:root {
  --product-orange: var(--c-brand);
  --product-orange-dark: var(--c-brand-dark);
  --product-orange-light: var(--c-brand-light);
  --product-page-bg: var(--c-bg);
  --product-line: var(--c-line);
  --product-text: var(--c-text);
  --product-muted: var(--c-muted);
  --product-white: #ffffff;
}

/* scroll-margin: chừa chỗ cho header dính khi bấm menu "Sách" (#san-pham). */
.products {
  scroll-margin-top: 4.5rem;
  padding: 3.5rem 1rem 5rem;
  background: var(--product-page-bg);
  color: var(--product-text);
}

.products .container {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

/* Tiêu đề */

.products-head {
  margin-bottom: 2.25rem;
  text-align: center;
}

.products-title {
  position: relative;
  display: inline-block;
  margin: 0;
  padding-bottom: 0.875rem;
  color: var(--product-text);
  font-size: 2rem;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.products-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 3rem;
  height: 0.25rem;
  border-radius: 999rem;
  background: linear-gradient(90deg, var(--product-orange), var(--c-gold));
  transform: translateX(-50%);
}

.products-count {
  margin: 0.75rem 0 0;
  color: var(--product-muted);
  font-size: 0.9375rem;
}

/* Lưới sản phẩm */

.products-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.5rem;
}

.product-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  border: 0.0625rem solid var(--product-line);
  border-radius: 1.25rem;
  background: var(--product-white);
  box-shadow: 0 0.5rem 1.75rem rgba(var(--c-shadow-rgb), 0.06);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.product-card:hover {
  border-color: var(--c-brand-border);
  box-shadow: 0 1.25rem 2.5rem rgba(var(--c-brand-rgb), 0.14);
  transform: translateY(-0.375rem);
}

/* Ảnh bìa: đặt trên nền mềm, đổ bóng như cuốn sách thật */

.product-image {
  position: relative;
  display: flex;
  aspect-ratio: 4 / 5;
  /* min-height 0 + overflow hidden: ảnh lớn không làm khung cao hơn tỉ lệ 4:5. */
  min-height: 0;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1.75rem;
  background: radial-gradient(circle at 50% 35%, #fff 0%, var(--c-brand-light) 70%, var(--c-brand-border) 100%);
}

.product-image img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  border-radius: 0.25rem 0.5rem 0.5rem 0.25rem;
  box-shadow: -0.25rem 0 0 rgba(0, 0, 0, 0.08) inset,
    0 0.75rem 1.5rem rgba(var(--c-shadow-rgb), 0.25);
  object-fit: contain;
  transition: transform 0.4s ease;
}

.product-card:hover .product-image img {
  transform: scale(1.04);
}

.product-badge {
  position: absolute;
  top: 0.875rem;
  left: 0.875rem;
  display: inline-flex;
  align-items: center;
  padding: 0.3125rem 0.625rem;
  border-radius: 999rem;
  background: var(--c-error);
  box-shadow: 0 0.25rem 0.75rem rgba(var(--c-error-rgb), 0.25);
  color: var(--product-white);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.product-badge--muted {
  background: var(--c-muted);
  box-shadow: none;
}

.product-card.is-out-of-stock .product-image img {
  filter: grayscale(0.6);
  opacity: 0.75;
}

/* Thông tin */

.product-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.625rem;
  padding: 1.125rem 1.25rem 1.25rem;
}

/* Tên sách: tối đa 2 dòng, luôn chiếm đủ 2 dòng để các thẻ thẳng hàng (tên đầy đủ ở thuộc tính title). */
.product-name {
  min-height: 2.9em;
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.45;
}

.product-name a {
  display: -webkit-box;
  overflow: hidden;
  color: var(--product-text);
  text-decoration: none;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: break-word;
  transition: color 0.2s ease;
}

/* Đánh giá + đã bán */

.product-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.625rem;
  color: var(--product-muted);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.product-rating {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.product-rating strong {
  color: var(--product-text);
  font-weight: 650;
}

.product-rating-star {
  color: var(--c-gold);
  font-size: 0.9375rem;
  line-height: 1;
}

.product-rating.is-empty .product-rating-star {
  color: var(--c-line-strong);
}

.product-sold {
  position: relative;
  padding-left: 0.6875rem;
}

.product-sold::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 0.0625rem;
  height: 0.75rem;
  background: var(--c-line-strong);
  transform: translateY(-50%);
}

.product-name a:hover {
  color: var(--product-orange-dark);
}

.product-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.5rem;
  margin-top: auto;
  color: var(--product-orange);
  font-size: 1.125rem;
  font-weight: 750;
  line-height: 1.3;
}

/* Giá gốc khi đang giảm (Woo: <del> giá cũ, <ins> giá mới) */
.product-price del {
  order: 2;
  color: var(--c-placeholder);
  font-size: 0.8125rem;
  font-weight: 500;
}

.product-price ins {
  text-decoration: none;
}

.product-button {
  position: relative;
  z-index: 0;
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-top: 0.25rem;
  padding: 0 1rem;
  border: 0.0625rem solid var(--product-orange);
  border-radius: 0.75rem;
  background: var(--product-white);
  color: var(--product-orange-dark);
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  transition: color var(--t-duration) var(--t-ease), box-shadow var(--t-duration) var(--t-ease);
}

/* Gradient không transition được → đặt ở lớp dưới và chuyển opacity cho nền hiện dần. */
.product-button::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, var(--product-orange) 0%, var(--product-orange-dark) 100%);
  opacity: 0;
  transition: opacity var(--t-duration) var(--t-ease);
}

.product-card:hover .product-button,
.product-button:focus-visible {
  box-shadow: 0 0.5rem 1.25rem rgba(var(--c-brand-rgb), 0.25);
  color: var(--product-white);
}

.product-card:hover .product-button::before,
.product-button:focus-visible::before {
  opacity: 1;
}

/* Tablet */

@media (max-width: 64rem) {
  .products-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 48rem) {
  .products {
    padding: 2.5rem 1rem 4rem;
  }

  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }
}

/* Mobile: 2 cột gọn */

@media (max-width: 39.9375rem) {
  .products {
    padding: 2rem 0.75rem 3.5rem;
  }

  .products-head {
    margin-bottom: 1.5rem;
  }

  .products-title {
    font-size: 1.5rem;
  }

  .products-count {
    font-size: 0.875rem;
  }

  .products-grid {
    gap: 0.75rem;
  }

  .product-card {
    border-radius: 1rem;
  }

  .product-card:hover {
    transform: none;
  }

  .product-image {
    padding: 1rem 1.125rem;
  }

  .product-badge {
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.6875rem;
  }

  .product-body {
    gap: 0.5rem;
    padding: 0.75rem 0.75rem 0.875rem;
  }

  .product-name {
    font-size: 0.875rem;
    line-height: 1.4;
  }

  .product-price {
    font-size: 1rem;
  }

  /*
   * Thẻ hẹp: gọn 1 dòng "★ 3,5 | Đã bán 8".
   * Bỏ số lượt đánh giá; sách chưa có đánh giá chỉ hiện "Đã bán N".
   */
  .product-meta {
    flex-wrap: nowrap;
    gap: 0.5rem;
    overflow: hidden;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  .product-rating {
    gap: 0.1875rem;
  }

  .product-rating-star {
    font-size: 0.8125rem;
  }

  .product-rating-count,
  .product-rating.is-empty {
    display: none;
  }

  .product-sold {
    padding-left: 0.5rem;
  }

  .product-rating.is-empty + .product-sold {
    padding-left: 0;
  }

  .product-rating.is-empty + .product-sold::before {
    content: none;
  }

  .product-button {
    min-height: 2.375rem;
    font-size: 0.8125rem;
    border-radius: 0.625rem;
  }
}
