/*
 * Comm Centre theme: shop listing (the shop, product category and tag archives, and shop search results).
 *
 * Loads after base.css on every page, so every rule is scoped by .cc-shop (the main element of the listing templates)
 * and .cc-shop-grid or .cc-shop-toolbar. It also has to win over assets/css/shop.css, which loads later and has the
 * earlier card rules, so the selectors here carry one more class than the ones they replace.
 *
 * The card, top to bottom: the product photo on a light neutral tile (square, padded, never cropped), the name in
 * normal case (at most three lines), the price WooCommerce prints, and a compact add to cart button pinned to the
 * bottom so a row of cards lines up. The whole card is one link (the name's link is stretched over the card); the
 * button sits above it. Reads only the variables in tokens.css. No glow, no shadow, 2px corners.
 */

/* ------------------------------------------------------------------ toolbar */

.cc-shop .cc-shop-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--cc-space-s) var(--cc-space-m);
	margin: 0 0 var(--cc-space-l);
	padding-bottom: var(--cc-space-m);
	border-bottom: 1px solid var(--cc-color-line);
}

.cc-shop .cc-shop-toolbar > * {
	margin: 0;
}

/* With no results WooCommerce prints neither the count nor the sort, so the bar would be a bare line and a gap. */
.cc-shop .cc-shop-toolbar:not(:has(.woocommerce-result-count, .woocommerce-ordering)) {
	display: none;
}

.cc-shop .cc-shop-toolbar .woocommerce-result-count {
	color: var(--cc-color-secondary);
	font-size: var(--cc-font-size-s);
	line-height: 1.4;
}

.cc-shop .cc-shop-toolbar .woocommerce-ordering {
	margin: 0;
}

.cc-shop .cc-shop-toolbar select {
	font-weight: 500;
}

/* ------------------------------------------------------------------ grid */

.cc-shop .cc-shop-grid {
	--cc-shop-tile: var(--cc-color-panel);
	margin: 0;
}

.cc-shop .cc-shop-grid ul.wc-block-product-template {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--cc-space-s);
	margin: 0;
	padding: 0;
	list-style: none;
}

.cc-shop .cc-shop-grid ul.wc-block-product-template > li.wc-block-product {
	width: auto;
	min-width: 0;
	max-width: none;
	margin: 0;
	padding: 0;
}

@media (min-width: 30em) {
	.cc-shop .cc-shop-grid ul.wc-block-product-template {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: var(--cc-space-m);
	}
}

@media (min-width: 48em) {
	.cc-shop .cc-shop-grid ul.wc-block-product-template {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: var(--cc-space-m);
	}
}

@media (min-width: 80em) {
	.cc-shop .cc-shop-grid ul.wc-block-product-template {
		grid-template-columns: repeat(4, minmax(0, 1fr));
		gap: var(--cc-space-l);
	}
}

/* ------------------------------------------------------------------ card */

.cc-shop .cc-shop-grid .cc-shop-card {
	position: relative;
	isolation: isolate;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	height: 100%;
	background: var(--cc-color-raised);
	border: 1px solid var(--cc-color-line);
	border-radius: var(--cc-radius-m);
	overflow: hidden;
}

.cc-shop .cc-shop-grid .cc-shop-card:hover {
	border-color: var(--cc-color-line-strong);
}

.cc-shop .cc-shop-grid .cc-shop-card > * {
	margin: 0;
	padding: 0;
}

/* The photo tile. Photos are transparent or white-background, so a light neutral tile suits both. */
.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__media {
	display: block;
	box-sizing: border-box;
	width: 100%;
	aspect-ratio: 1 / 1;
	padding: var(--cc-space-l);
	background: var(--cc-shop-tile);
}

.cc-shop .cc-shop-grid .cc-shop-card__media > a,
.cc-shop .cc-shop-grid .cc-shop-card__media > .cc-placeholder {
	display: block;
	width: 100%;
	height: 100%;
}

.cc-shop .cc-shop-grid .cc-shop-card__media img {
	display: block;
	width: 100%;
	height: 100%;
	max-height: none;
	/* WooCommerce writes object-fit:cover into the image's own style attribute, so this has to be important. */
	object-fit: contain !important;
	/* White photo backgrounds melt into the tile instead of showing as a white box. Transparent photos are unaffected. */
	mix-blend-mode: multiply;
}

/* No product photo: the labelled illustration, dark on the same tile, with room under it for the label. */
.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__media:has(.cc-placeholder) {
	padding-bottom: var(--cc-space-xl);
}

.cc-shop .cc-shop-grid .cc-placeholder {
	position: relative;
	display: block;
}

.cc-shop .cc-shop-grid .cc-placeholder img {
	width: 100%;
	height: 100%;
}

.cc-shop .cc-shop-grid .cc-placeholder__label {
	left: 0;
	bottom: calc(-1 * var(--cc-space-l));
}

/* ------------------------------------------------------------------ name */

.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	overflow: hidden;
	margin: 0;
	padding: var(--cc-space-m) var(--cc-space-m) 0;
	font-family: var(--cc-font-body);
	font-size: var(--cc-font-size-m);
	font-weight: 600;
	letter-spacing: 0;
	line-height: 1.35;
	text-transform: none;
}

.cc-shop .cc-shop-grid .cc-shop-card__title a {
	display: inline;
	min-height: 0;
	color: var(--cc-color-white);
	text-decoration: none;
}

/* Wi-Fi stays in one piece (inc/shop-listing.php wraps it). */
.cc-shop .cc-shop-grid .cc-shop-card__title .cc-nobreak {
	white-space: nowrap;
}

/* One link per card: the name's link covers the whole card. The button below sits above it. */
.cc-shop .cc-shop-grid .cc-shop-card__title a::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
}

.cc-shop .cc-shop-grid .cc-shop-card:hover .cc-shop-card__title a {
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

/* The focus ring goes round the whole card when the browser can tell (:has), and stays on the link when it cannot. */
@supports selector(:has(*)) {
	.cc-shop .cc-shop-grid .cc-shop-card__title a:focus-visible {
		outline: none;
	}

	.cc-shop .cc-shop-grid .cc-shop-card:has(.cc-shop-card__title a:focus-visible) {
		outline: var(--cc-focus-width) solid var(--cc-color-focus);
		outline-offset: var(--cc-focus-offset);
	}
}

/* ------------------------------------------------------------------ price */

.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__price {
	margin-top: auto;
	padding: var(--cc-space-s) var(--cc-space-m) 0;
	color: var(--cc-color-white);
	font-size: var(--cc-font-size-s);
	line-height: 1.3;
}

.cc-shop .cc-shop-grid .cc-shop-card__price .wc-block-components-product-price {
	margin: 0;
	color: var(--cc-color-white);
	font-size: var(--cc-font-size-l);
	font-weight: 700;
	line-height: 1.25;
}

.cc-shop .cc-shop-grid .cc-shop-card__price del {
	margin-inline-end: var(--cc-space-xs);
	color: var(--cc-color-secondary);
	font-size: var(--cc-font-size-s);
	font-weight: 400;
}

.cc-shop .cc-shop-grid .cc-shop-card__price ins {
	text-decoration: none;
}

/* The theme's own price output (inc. and ex. GST, From, Discuss pricing). The amount leads, the rest is quiet. */
.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price {
	display: flex;
	flex-direction: column;
	gap: var(--cc-space-xxs);
}

.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price__main {
	font-size: var(--cc-font-size-l);
	font-weight: 700;
}

.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price__from,
.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price__tax,
.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price__ex {
	color: var(--cc-color-secondary);
	font-size: var(--cc-font-size-xs);
	font-weight: 400;
}

.cc-shop .cc-shop-grid .cc-shop-card__price .cc-price--discuss {
	font-size: var(--cc-font-size-m);
	font-weight: 600;
}

/* ------------------------------------------------------------------ button */

.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__button {
	position: relative;
	z-index: 2;
	align-items: flex-start;
	gap: var(--cc-space-xs);
	margin: 0;
	padding: var(--cc-space-m);
}

.cc-shop .cc-shop-grid .cc-shop-card__button .wp-block-button__link,
.cc-shop .cc-shop-grid .cc-shop-card__button .wc-block-components-product-button__button {
	width: auto;
	min-height: var(--cc-target-min);
	margin: 0;
	padding: 0.5rem 1.1rem;
	background-color: transparent;
	border: 2px solid var(--cc-color-secondary);
	color: var(--cc-color-white);
	font-size: var(--cc-font-size-xs);
	letter-spacing: 0.12em;
}

.cc-shop .cc-shop-grid .cc-shop-card__button .wp-block-button__link:hover {
	background-color: var(--cc-color-action);
	border-color: var(--cc-color-action);
	color: var(--cc-color-action-ink);
}

/* After a product is added, WooCommerce adds a View cart link under the button. */
.cc-shop .cc-shop-grid .cc-shop-card__button .added_to_cart {
	display: inline-flex;
	align-items: center;
	min-height: var(--cc-target-min);
	color: var(--cc-color-white);
	font-size: var(--cc-font-size-s);
}

/* ------------------------------------------------------------------ phones: a list, the photo beside the details */

@media (max-width: 29.99em) {
	.cc-shop .cc-shop-grid .cc-shop-card {
		display: grid;
		grid-template-columns: 7.5rem minmax(0, 1fr);
		grid-template-rows: auto 1fr auto;
		align-items: start;
	}

	.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__media {
		grid-column: 1;
		grid-row: 1 / span 3;
		align-self: stretch;
		height: 100%;
		min-height: 7.5rem;
		aspect-ratio: auto;
		padding: var(--cc-space-s);
	}

	.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__media:has(.cc-placeholder) {
		padding-bottom: var(--cc-space-xl);
	}

	.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__title {
		grid-column: 2;
		grid-row: 1;
	}

	.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__price {
		grid-column: 2;
		grid-row: 2;
		align-self: end;
		margin-top: 0;
	}

	.cc-shop .cc-shop-grid .cc-shop-card .cc-shop-card__button {
		grid-column: 2;
		grid-row: 3;
		padding-top: var(--cc-space-s);
	}
}

/* ------------------------------------------------------------------ pagination */

.cc-shop .cc-shop-grid .wp-block-query-pagination {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: var(--cc-space-xs);
	margin-top: var(--cc-space-xl);
}

.cc-shop .cc-shop-grid .wp-block-query-pagination-numbers {
	display: flex;
	flex-wrap: wrap;
	gap: var(--cc-space-xs);
}

.cc-shop .cc-shop-grid .wp-block-query-pagination a,
.cc-shop .cc-shop-grid .wp-block-query-pagination .page-numbers {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	min-width: var(--cc-target-min);
	min-height: var(--cc-target-min);
	padding: 0 var(--cc-space-s);
	border: 1px solid var(--cc-color-line-strong);
	border-radius: var(--cc-radius-s);
	color: var(--cc-color-white);
	font-size: var(--cc-font-size-s);
	text-decoration: none;
}

.cc-shop .cc-shop-grid .wp-block-query-pagination a:hover {
	border-color: var(--cc-color-white);
}

.cc-shop .cc-shop-grid .wp-block-query-pagination .page-numbers.current {
	background-color: var(--cc-color-white);
	border-color: var(--cc-color-white);
	color: var(--cc-color-canvas);
	font-weight: 600;
}

.cc-shop .cc-shop-grid .wp-block-query-pagination .page-numbers.dots {
	border-color: transparent;
}

@media (prefers-reduced-motion: no-preference) {
	.cc-shop .cc-shop-grid .cc-shop-card,
	.cc-shop .cc-shop-grid .cc-shop-card__button .wp-block-button__link,
	.cc-shop .cc-shop-grid .wp-block-query-pagination a {
		transition: background-color var(--cc-transition-fast) ease, border-color var(--cc-transition-fast) ease, color var(--cc-transition-fast) ease;
	}
}
