/*
 * Product card and the grid it sits in.
 * Figma "Sportlab Cosmetics UI" -> RelatedCard-0 (12754:46083).
 *
 * One component at every width: 334px under the product page, 247.5px in the
 * four-column shop grid, the full width of a small phone in a single column.
 * The card is its own container, so the narrow variant follows the card
 * rather than the window.
 */

/****************************** GRID ******************************/

.product-grid {
	display: grid;
	grid-template-columns: repeat(var(--product-grid-columns, 4), minmax(0, 1fr));
	gap: var(--product-grid-gap, 1.25rem);
	margin: 0;
	padding: 0;
}

.product-grid.columns-1 {
	--product-grid-columns: 1;
}
.product-grid.columns-2 {
	--product-grid-columns: 2;
}
.product-grid.columns-3 {
	--product-grid-columns: 3;
}
.product-grid.columns-4 {
	--product-grid-columns: 4;
}
.product-grid.columns-5 {
	--product-grid-columns: 5;
}
.product-grid.columns-6 {
	--product-grid-columns: 6;
}

@media (max-width: 1199.98px) {
	.product-grid:is(.columns-4, .columns-5, .columns-6) {
		--product-grid-columns: 3;
	}
}

@media (max-width: 991.98px) {
	.product-grid:not(.columns-1) {
		--product-grid-columns: 2;
	}
}

@media (max-width: 575.98px) {
	.product-grid:not(.columns-1) {
		--product-grid-columns: 1;
	}
}

/****************************** CARD ******************************/

.product-card {
	container: product-card / inline-size;
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
	box-sizing: border-box;
	width: auto;
	max-width: none;
	margin: 0;
	padding: 1.25rem 1.25rem 2rem;
	background: var(--sl-white);
	border: 1px solid var(--sl-grey-200);
	border-radius: var(--sl-radius-lg);
	font-family: var(--theme-font);
	text-align: center;
}

.product-card .woocommerce-LoopProduct-link {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	align-items: center;
	color: inherit;
	text-decoration: none;
}

.product-card .woocommerce-LoopProduct-link img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 1;
	margin: 0 0 1rem;
	object-fit: contain;
	background: none;
	border-radius: var(--sl-radius-md);
}

.product-card .woocommerce-loop-product__title {
	width: 100%;
	margin: 0 0 0.75rem;
	padding: 0;
	font-size: 1rem;
	font-weight: 400;
	line-height: 1.4;
	color: var(--sl-ink-warm);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/*
 * woocommerce.css colours and sizes "div.product span.price" for the product
 * page, and it outweighs a plain .product-card .price here. :is() takes the
 * weight of its heaviest branch while still matching outside .woocommerce.
 */
:is(.woocommerce .products, .products) .product-card .price {
	display: block;
	margin: 0;
	font-size: 1.375rem;
	font-weight: 600;
	line-height: 1.2;
	color: var(--sl-black);
}

:is(.woocommerce .products, .products) .product-card .price del {
	margin-right: 0.375rem;
	font-size: 0.875em;
	font-weight: 400;
	color: var(--sl-grey-500);
	opacity: 1;
}

:is(.woocommerce .products, .products) .product-card .price ins {
	display: inline;
	font-weight: inherit;
	text-decoration: none;
}

/****************************** CTA ******************************/

.product-card .product-card-cta {
	display: inline-flex;
	align-self: center;
	align-items: center;
	justify-content: center;
	max-width: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 0.9375rem 2rem;
	border: 1px solid var(--sl-black);
	border-radius: var(--sl-radius-md);
	background: var(--sl-white);
	color: var(--sl-black);
	font-family: var(--theme-font);
	font-size: 1rem;
	font-weight: 800;
	line-height: 1.5;
	white-space: nowrap;
	text-decoration: none;
	transition:
		background-color 0.2s,
		color 0.2s;
}

.product-card .product-card-cta:hover,
.product-card .product-card-cta:focus-visible {
	background: var(--sl-black);
	color: var(--sl-white);
}

.product-card .product-card-cta.loading {
	opacity: 0.5;
	pointer-events: none;
}

/* WooCommerce adds this link after an AJAX add to cart. */
.product-card .added_to_cart {
	align-self: center;
	margin-top: -1rem;
	font-size: 0.875rem;
	line-height: 1.4;
	color: var(--sl-grey-600);
	text-decoration: underline;
}

/****************************** BADGES ******************************/

/* Shared with the product page, where the same pills sit above the name. */
.product-badge,
.product-badges .themeSaleLabel {
	display: inline-block;
	padding: 0.5rem 1rem;
	border-radius: var(--sl-radius-xs);
	background: var(--sl-accent-soft);
	color: var(--sl-black);
	font-family: var(--theme-font);
	font-size: 0.75rem;
	font-weight: 800;
	line-height: 0.875rem;
	letter-spacing: 0.075rem;
	text-transform: uppercase;
}

.product-badges .themeSaleLabel {
	position: static;
	background: var(--sl-accent);
}

.product-card .product-badges {
	position: absolute;
	top: 1.25rem;
	left: 1.25rem;
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.375rem;
	max-width: calc(100% - 5rem);
	margin: 0;
	text-align: left;
}

/****************************** WISHLIST ******************************/

/*
 * TI Wishlist's heart, wherever the plugin prints it - the card here, the
 * buybox on the product page. Its <img> icons give way to one masked shape
 * coloured by currentColor: outlined, or filled once the product is saved.
 * The img rule matches the plugin's own !important one, and wins by order.
 */
.tinv-wishlist .tinvwl_add_to_wishlist_button.tinvwl-icon-custom img {
	display: none !important;
}

.tinvwl_add_to_wishlist_button.tinvwl-icon-custom::before {
	--wishlist-heart: url("../template-img/icon_heart.svg");

	content: "";
	flex: none;
	width: var(--wishlist-heart-size, 1rem);
	height: var(--wishlist-heart-size, 1rem);
	background: currentColor;
	-webkit-mask: var(--wishlist-heart) no-repeat center / contain;
	mask: var(--wishlist-heart) no-repeat center / contain;
	transition: background-color 0.2s;
}

.tinvwl_add_to_wishlist_button.tinvwl-icon-custom.tinvwl-product-in-list::before {
	--wishlist-heart: url("../template-img/icon_heart_filled.svg");
}

/* The plugin pins this top-left with .tinv-wraper.tinv-wishlist.tinvwl-above_thumb-add-to-cart. */
.product-card .tinv-wraper.tinv-wishlist {
	--wishlist-heart-size: 2rem;

	position: absolute;
	top: 1.1875rem;
	right: 1.3125rem;
	left: auto;
	z-index: 2;
	margin: 0;
	line-height: 0;
}

.product-card .tinvwl-tooltip,
.product-card .tinv-wishlist-clear {
	display: none;
}

/* As strong as the plugin's 18px box rule, which would squash the heart. */
.product-card .tinvwl_add_to_wishlist_button.tinvwl-icon-custom.no-txt {
	display: inline-flex;
	width: auto;
	height: auto;
	margin: 0;
	color: var(--sl-grey-900);
	cursor: pointer;
}

.product-card
	.tinvwl_add_to_wishlist_button.tinvwl-icon-custom:is(
		:hover,
		:focus-visible,
		.tinvwl-product-in-list
	) {
	color: var(--sl-accent);
}

/****************************** NARROW ******************************/

/*
 * Below ~200px inside the card - a tight column count on a mid-size screen -
 * the button label wraps onto two lines rather than spilling out, and
 * everything else steps down.
 */
@container product-card (max-width: 12.5rem) {
	.product-card .woocommerce-LoopProduct-link img {
		margin-bottom: 0.75rem;
	}

	.product-card .woocommerce-loop-product__title {
		margin-bottom: 0.5rem;
		font-size: 0.875rem;
	}

	:is(.woocommerce .products, .products) .product-card .price {
		font-size: 1.125rem;
	}

	.product-card .product-card-cta {
		width: 100%;
		padding: 0.625rem 0.75rem;
		font-size: 0.875rem;
		line-height: 1.3;
		white-space: normal;
	}

	.product-card .product-badges {
		max-width: calc(100% - 2.5rem);
	}

	.product-card :is(.product-badge, .themeSaleLabel) {
		padding: 0.3125rem 0.5rem;
		font-size: 0.625rem;
		letter-spacing: 0.05rem;
	}
}
