/* Deadhead Chemist — product card normalisation.
 * Loaded last so it wins over WooCommerce core + theme layers.
 * Goal: tight cards with the button sitting directly under the price,
 * no forced equal-height dead space.
 */

body ul.products {
  align-items: start !important;
}

body ul.products li.product {
  display: flex !important;
  flex-direction: column !important;
  height: auto !important;
  padding: 0 !important;
  margin-bottom: 0 !important;
  text-align: left !important;
  overflow: hidden;
}

/* Image block: always square, never grows */
body ul.products li.product > a:first-child,
body ul.products li.product .woocommerce-loop-product__link {
  flex: 0 0 auto !important;
  display: block !important;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  margin: 0 !important;
}

body ul.products li.product > a:first-child img,
body ul.products li.product .woocommerce-loop-product__link img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  margin: 0 !important;
  display: block !important;
}

/* Title: clamp to two lines so every card matches */
body ul.products li.product .woocommerce-loop-product__title,
body ul.products li.product h2,
body ul.products li.product h3,
body ul.products li.product .product-title {
  display: -webkit-box !important;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
  margin: 0 !important;
  padding: 14px 14px 0 !important;
  font-size: 1rem !important;
  line-height: 1.2 !important;
}

body ul.products li.product .star-rating {
  margin: 8px 14px 0 !important;
  font-size: 0.8em !important;
}

body ul.products li.product .woocommerce-loop-product__title + .price,
body ul.products li.product .price {
  margin: 6px 0 0 !important;
  padding: 0 14px !important;
  font-size: 1.05rem !important;
  line-height: 1.3 !important;
}

body ul.products li.product .product-excerpt {
  margin: 6px 0 0 !important;
  padding: 0 14px !important;
}

/* Button sits directly under the price with normal spacing */
body ul.products li.product .button,
body ul.products li.product .add_to_cart_button {
  margin: 12px 14px 14px !important;
  width: calc(100% - 28px) !important;
  padding: 0.7rem 1rem !important;
  align-self: stretch;
}

/* Sale flash sits tight to the corner */
body ul.products li.product .onsale {
  top: 10px !important;
  left: 10px !important;
  right: auto !important;
  margin: 0 !important;
}

/* Homepage / shortcode grids: consistent columns and gap */
body .product-tabs ul.products,
body .sbc-section ul.products {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 20px !important;
  margin: 0 !important;
}

body .product-tabs ul.products::before,
body .product-tabs ul.products::after,
body .sbc-section ul.products::before,
body .sbc-section ul.products::after {
  display: none !important;
}

body .product-tabs ul.products li.product,
body .sbc-section ul.products li.product {
  width: 100% !important;
  float: none !important;
  margin: 0 !important;
  clear: none !important;
}

/* Rebuilt homepage cards. These do not use the WooCommerce loop DOM, so no
 * plugin or legacy `.sbc-card-body` flex rule can push the button downward. */
.dhc-product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  gap: 20px;
  margin: 0;
}

.dhc-product-card,
body ul.products li.product.dhc-product-card {
  display: block;
  height: auto !important;
  min-width: 0;
  align-self: start !important;
  overflow: hidden;
  padding: 0 !important;
  background: var(--sbc-surface);
  border: 1px solid var(--sbc-line);
  border-radius: var(--sbc-radius-lg);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.dhc-product-card:hover {
  border-color: var(--sbc-primary);
  box-shadow: var(--sbc-shadow-lg);
  transform: translateY(-2px);
}

.dhc-product-card__image {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--sbc-bg-alt);
}

.dhc-product-card__image img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  object-fit: cover;
}

.dhc-product-card__content,
body ul.products li.product.dhc-product-card .dhc-product-card__content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  grid-auto-rows: max-content;
  height: auto !important;
  min-height: 0 !important;
  flex: none !important;
  gap: 8px;
  padding: 14px;
}

.dhc-product-card__title {
  display: -webkit-box;
  min-height: 2.5em;
  overflow: hidden;
  color: var(--sbc-ink);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.dhc-product-card__rating,
.dhc-product-card__rating .star-rating {
  margin: 0;
}

.dhc-product-card__price {
  min-height: 1.4em;
  margin: 0;
  color: var(--sbc-ink);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
}

.dhc-product-card__price del {
  color: var(--sbc-ink-soft);
  font-size: 0.85em;
  font-weight: 500;
}

.dhc-product-card__price ins {
  color: var(--sbc-danger);
  text-decoration: none;
}

body .dhc-product-card__button,
body .woocommerce .dhc-product-card__button {
  display: inline-flex;
  width: 100%;
  min-height: 42px;
  margin: 4px 0 0 !important;
  padding: 0.7rem 0.8rem !important;
  align-items: center;
  justify-content: center;
  align-self: start;
  text-align: center;
}

body ul.products li.product.dhc-product-card .dhc-product-card__price + .dhc-product-card__button {
  margin-top: 4px !important;
}

@media (max-width: 1024px) {
  body .product-tabs ul.products,
  body .sbc-section ul.products {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  .dhc-product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 782px) {
  body .product-tabs ul.products,
  body .sbc-section ul.products {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }
  .dhc-product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .dhc-product-card__content {
    gap: 6px;
    padding: 10px;
  }
  .dhc-product-card__title {
    font-size: 0.82rem;
  }
  .dhc-product-card__price {
    font-size: 0.9rem;
  }
  body .dhc-product-card__button,
  body .woocommerce .dhc-product-card__button {
    min-height: 38px;
    font-size: 0.7rem !important;
    padding: 0.6rem 0.4rem !important;
  }
  body ul.products li.product .woocommerce-loop-product__title {
    font-size: 0.9rem !important;
    padding: 10px 10px 0 !important;
  }
  body ul.products li.product .price {
    padding: 0 10px !important;
    font-size: 0.95rem !important;
  }
  body ul.products li.product .button,
  body ul.products li.product .add_to_cart_button {
    margin: 10px !important;
    width: calc(100% - 20px) !important;
    font-size: 0.78rem !important;
    padding: 0.6rem 0.5rem !important;
  }
}

/* Why Deadhead Chemist grid */
.sbc-why-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 1.75rem;
}

.sbc-why-card {
  background: var(--sbc-card, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--sbc-border, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  padding: 20px;
}

.sbc-why-card__title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 8px;
}

.sbc-why-card p {
  margin: 0;
  line-height: 1.6;
  opacity: 0.9;
}
