/* =============================================================
   Product cards — Happy-Beds-style treatment for Woodmart loop
   cards (shop archive, category pages, product grids).

   STRUCTURE NOTE
   Variable-product cards contain a hidden quick-shop variations
   form (a table of Size / Color / Base / ... rows). The colour
   circles ARE that form's Color row. Everything here works with
   that: the form is filtered down to just the colour swatches,
   and the container that holds the form is what gets placed in
   the card grid.
   ============================================================= */

:root {
	--bbs-card-ink: #1a1a2e;
	--bbs-card-border: #e6e6ec;
	--bbs-card-radius: 10px;
	--bbs-card-muted: #6b6b7c;
	--bbs-card-sale: #e4032e;
	--bbs-swatch-size: 26px;
}

/* -------------------------------------------------------------
   1. Swatch circles (never stretched)
   ------------------------------------------------------------- */
/* -------------------------------------------------------------
   1. Swatch circles on LOOP CARDS ONLY.
   Scoped to .wd-product deliberately: the single product page
   uses the same classes at a much larger size, and must not be
   squashed into 26px circles.
   ------------------------------------------------------------- */
.wd-product .wd-swatch {
	width: var(--bbs-swatch-size) !important;
	height: var(--bbs-swatch-size) !important;
	min-width: var(--bbs-swatch-size) !important;
	max-width: var(--bbs-swatch-size) !important;
	aspect-ratio: 1 / 1 !important;
	flex: 0 0 auto !important;
	border-radius: 50% !important;
	overflow: hidden;
	box-sizing: border-box;
	border: 1px solid rgba(0, 0, 0, .12);
	padding: 0 !important;
}

.wd-product .wd-swatch .wd-swatch-bg,
.wd-product .wd-swatch img {
	width: 100% !important;
	height: 100% !important;
	border-radius: 50% !important;
	object-fit: cover;
	display: block;
}

.wd-product .wd-swatch .wd-swatch-text {
	display: none !important;
}

.wd-product .wd-swatches-product {
	display: flex !important;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-start !important;
	gap: 6px;
}

/* Square product images, everywhere */
.wd-product .wd-loop-prod-thumb img {
	aspect-ratio: 1 / 1;
	width: 100%;
	object-fit: cover;
}

/* "+N" counter added by product-cards.js when > 3 colours */
.bbs-swatch-more {
	width: var(--bbs-swatch-size);
	height: var(--bbs-swatch-size);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: #f1f1f4;
	color: var(--bbs-card-ink);
	font-size: 11px;
	font-weight: 600;
	flex: 0 0 auto;
}

.wd-swatch.bbs-swatch-hidden {
	display: none !important;
}

/* Cap at 3 dots in CSS as well, so the limit holds even before
   the script runs. The script appends the exact "+N" bubble. */
.wd-product .wd-swatches-product .wd-swatch:nth-child(n+4) {
	display: none !important;
}

/* -------------------------------------------------------------
   2. Quick-shop form, filtered: colour row only
   ------------------------------------------------------------- */
.wd-product .variations_form .variations .label,
.wd-product .variations_form select,
.wd-product .variations_form .quantity,
.wd-product .variations_form .single_add_to_cart_button,
.wd-product .variations_form .woocommerce-variation,
.wd-product .variations_form .reset_variations {
	display: none !important;
}

/* Hide every attribute row... */
.wd-product .variations_form .variations tr {
	display: none !important;
}

/* ...except one containing colour swatches (inline bg colour) */
.wd-product .variations_form .variations tr:has(.wd-swatch-bg[style*="background-color"]) {
	display: block !important;
}

.wd-product .variations_form .variations,
.wd-product .variations_form .variations tbody,
.wd-product .variations_form .variations tr:has(.wd-swatch-bg[style*="background-color"]) td {
	display: block !important;
	border: 0 !important;
	padding: 0 !important;
	margin: 0 !important;
}

/* -------------------------------------------------------------
   3. Card shell
   ------------------------------------------------------------- */
.wd-product .wd-product-wrapper {
	display: flex;
	flex-direction: column;
	height: 100%;
	position: relative;
	background: #fff;
	border: 1px solid var(--bbs-card-border);
	border-radius: var(--bbs-card-radius);
	overflow: hidden;
	box-shadow: 0 2px 12px rgba(20, 20, 40, .06);
	transition: box-shadow .2s ease, transform .2s ease;
}

.wd-product:hover .wd-product-wrapper {
	box-shadow: 0 8px 22px rgba(20, 20, 40, .1);
	transform: translateY(-2px);
}

.wd-product .wd-loop-prod-thumb {
	margin: 0;
	order: 1;
}

.wd-product .wd-loop-prod-title {
	order: 2;
	margin-top: 14px;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.35;
	text-align: left;
	padding-left: 16px;
	padding-right: 16px;
}

.wd-product .wd-loop-prod-title a {
	color: var(--bbs-card-ink);
}

/* Quick-shop container (the colour dots) after the title */
.wd-product .wd-product-wrapper > div:has(.variations_form) {
	order: 3;
	padding: 12px 16px 0;
	position: relative;
}

/* "Colour options" caption over the dots */
.wd-product .wd-product-wrapper > div:has(.variations_form)::before {
	content: "Colour options";
	display: block;
	margin-bottom: 6px;
	font-size: 12px;
	color: var(--bbs-card-muted);
}

/* Price under the dots, left-aligned, "Now from" caption */
.wd-product .wd-loop-prod-price {
	order: 4;
	margin-top: auto;
	padding: 12px 16px 16px;
	text-align: left;
	font-weight: 700;
	color: var(--bbs-card-ink);
}

.wd-product .wd-loop-prod-price::before {
	content: "Now from";
	display: block;
	margin-bottom: 2px;
	font-size: 12px;
	font-weight: 400;
	color: var(--bbs-card-muted);
}

.wd-product .wd-loop-prod-price ins {
	text-decoration: none;
	font-size: 20px;
}

.wd-product .wd-loop-prod-price del {
	font-size: 13px;
	font-weight: 400;
	color: var(--bbs-card-muted);
	margin-right: 6px;
}

/* Delivery bar pinned to the card foot (rendered from
   functions.php). Woodmart wraps hook output in .wd-el-hook,
   so the wrapper is what the card layout positions. */
.wd-product .wd-product-wrapper > .wd-el-hook:has(.bbs-card-delivery) {
	order: 5;
}

.wd-product .bbs-card-delivery {
	order: 5;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	border-top: 1px solid var(--bbs-card-border);
	font-size: 13px;
	color: var(--bbs-card-ink);
}

.wd-product .bbs-card-delivery svg {
	width: 22px;
	height: 22px;
	flex: 0 0 auto;
}

.wd-product .bbs-card-delivery strong {
	font-weight: 700;
}

/* No add-to-cart / select-options button on cards */
.wd-product .wd-add-btn-wrapp {
	display: none !important;
}

/* -------------------------------------------------------------
   4. Sale badge — red pill, top left
   ------------------------------------------------------------- */
.wd-product .product-labels {
	left: 10px;
	top: 10px;
	right: auto;
}

.wd-product .product-label.onsale {
	background: var(--bbs-card-sale) !important;
	color: #fff !important;
	border-radius: 6px !important;
	width: auto !important;
	height: auto !important;
	min-width: 0 !important;
	min-height: 0 !important;
	line-height: 1 !important;
	padding: 7px 10px !important;
	font-size: 12px;
	font-weight: 700;
}

/* -------------------------------------------------------------
   5. Desktop: image on top, then title, then a split meta row —
      colour options left | price right, divided — and the
      delivery bar full width beneath. Matches the reference.
   ------------------------------------------------------------- */
@media (min-width: 769px) {
	/* Equal-height cards: stretch every card to the tallest in
	   the row, then give the title a fixed 2-line box so the
	   meta row and delivery bar line up across the whole grid. */
	.wd-products .wd-product,
	.products .wd-product {
		display: flex;
	}

	.wd-product .wd-product-wrapper {
		display: grid !important;
		grid-template-columns: 1fr 1fr !important;
		grid-template-rows: auto auto 1fr auto !important;
		align-content: start;
		width: 100%;
		height: 100%;
	}

	.wd-product .wd-loop-prod-thumb {
		grid-column: 1 / -1 !important;
		grid-row: 1 !important;
	}

	.wd-product .wd-loop-prod-title {
		grid-column: 1 / -1 !important;
		grid-row: 2 !important;
		text-align: left !important;
		/* Exactly two lines, ellipsis beyond — height never varies */
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		line-clamp: 2;
		overflow: hidden;
		min-height: calc(2 * 1.35em);
	}

	.wd-product .wd-loop-prod-title a {
		display: block;
	}

	/* Colour options — left cell, bottom aligned */
	.wd-product .wd-product-wrapper > div:has(.variations_form) {
		grid-column: 1 !important;
		grid-row: 3 !important;
		align-self: end;
		text-align: left !important;
		padding-bottom: 14px;
	}

	/* Price — right cell, divided from the colours */
	.wd-product .wd-loop-prod-price {
		grid-column: 2 !important;
		grid-row: 3 !important;
		align-self: end;
		text-align: left !important;
		border-left: 1px solid var(--bbs-card-border);
		margin-top: 0;
		padding-top: 12px;
	}

	/* Delivery bar — full width foot */
	.wd-product .wd-product-wrapper > .wd-el-hook:has(.bbs-card-delivery) {
		grid-column: 1 / -1 !important;
		grid-row: 4 !important;
	}
}

/* -------------------------------------------------------------
   6. Mobile: one card per row, image left / content right,
      delivery bar full width underneath — the reference layout.
   ------------------------------------------------------------- */
@media (max-width: 768px) {
	.wd-products,
	.products {
		--wd-col-sm: 1 !important;
		--wd-col-md: 1 !important;
		grid-template-columns: 1fr !important;
	}

	.wd-product .wd-wishlist-btn {
		display: none !important;
	}

	.wd-product .wd-product-wrapper {
		display: grid !important;
		grid-template-columns: 44% 1fr !important;
		grid-template-rows: auto auto auto auto !important;
		align-items: start;
		align-content: start;
		height: auto !important;
	}

	.wd-product .wd-loop-prod-thumb {
		grid-column: 1 !important;
		grid-row: 1 / 4 !important;
		height: auto;
		align-self: start;
	}

	.wd-product .wd-loop-prod-thumb img {
		aspect-ratio: 1 / 1 !important;
		height: auto !important;
		object-fit: cover;
	}

	.wd-product .wd-loop-prod-title {
		grid-column: 2 !important;
		grid-row: 1 !important;
		margin-top: 12px;
		font-size: 15px;
		padding-right: 12px;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		line-clamp: 3;
		overflow: hidden;
	}

	.wd-product .wd-product-wrapper > div:has(.variations_form) {
		grid-column: 2 !important;
		grid-row: 2 !important;
		padding-top: 10px;
	}

	/* Dots only on mobile, no caption */
	.wd-product .wd-product-wrapper > div:has(.variations_form)::before {
		display: none;
	}

	.wd-product .wd-loop-prod-price {
		grid-column: 2 !important;
		grid-row: 3 !important;
		align-self: start;
		margin-top: 0;
		padding-top: 8px;
		padding-bottom: 14px;
	}

	.wd-product .wd-loop-prod-price ins {
		font-size: 21px;
	}

	/* Delivery bar spans the whole card under the image */
	.wd-product .wd-product-wrapper > .wd-el-hook:has(.bbs-card-delivery),
	.wd-product .bbs-card-delivery {
		grid-column: 1 / -1 !important;
		grid-row: 4 !important;
	}

	/* Compare / quick view cluster gone on mobile */
	.wd-product .wd-product-wrapper > .wp-block-wd-container:has(.wd-compare-btn) {
		display: none !important;
	}
}
