/**
 * Card layer (Plan 3 catalog UI, split out in Plan 4 Task 1): the ToolCard / PackCard and the product grid, with the
 * row layout below 600 px. Loaded on every page (inc/enqueue.php), right after components.css, because the mega menu's
 * spotlight and the homepage rails print cards outside the catalog views. The catalog page shell (filters, toolbar,
 * headers, pagination, empty state, hub rows, limits table) stays in catalog.css, which loads only where it is used.
 * Colours come from tokens.css only.
 *
 * WooCommerce and Astra style every ul.products and li.product (up to 0,3,3 specificity, e.g.
 * `.woocommerce ul.products:not(.elementor-grid)` sets four fixed columns, `.woocommerce-js ul.products li.product a img`
 * a margin). The grid and card rules that must win over them repeat a class (`.dv-grid.dv-grid.dv-grid`,
 * `.dv-card.dv-card`) to reach 0,4,0, as components.css does against Astra's button rules.
 */

/* Grid -------------------------------------------------------------------------- */

.products.dv-grid.dv-grid.dv-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
	gap: var(--dv-space-4);
	margin: 0;
	padding: 0;
	list-style: none;
}

.products.dv-grid.dv-grid.dv-grid::before,
.products.dv-grid.dv-grid.dv-grid::after {
	content: none;
	display: none;
}

@media (min-width: 1024px) {
	.products.dv-grid.dv-grid.dv-grid {
		gap: var(--dv-space-5);
	}
}

/* ToolCard ---------------------------------------------------------------------- */

/*
 * A console surface wherever the grid sits: the card re-points the semantic tokens as .dv-console does, so the badges
 * and text inside it read for a dark surface even outside a console panel.
 */
.products.dv-grid > .product.dv-card.dv-card {
	--dv-bg-canvas: var(--dv-console);
	--dv-bg-subtle: var(--dv-console-2);
	--dv-bg-surface: var(--dv-console-2);
	--dv-border: var(--dv-console-border);
	--dv-ink: var(--dv-console-ink);
	--dv-ink-2: var(--dv-console-ink-2);
	--dv-ink-3: var(--dv-console-ink-2);
	--dv-link: var(--dv-console-ink);
	position: relative;
	display: flex;
	flex-direction: column;
	float: none;
	clear: none;
	width: auto;
	margin: 0;
	padding: 0;
	color-scheme: dark;
	list-style: none;
	text-align: left;
}

.dv-card .dv-card__link {
	display: flex;
	flex: 1;
	flex-direction: column;
	padding: var(--dv-space-3);
	border: 1px solid var(--dv-console-border);
	border-radius: var(--dv-radius-lg);
	background-color: var(--dv-console);
	color: var(--dv-console-ink);
	text-decoration: none;
	transition: background-color var(--dv-dur-fast) var(--dv-ease), border-color var(--dv-dur-fast) var(--dv-ease), transform var(--dv-dur-fast) var(--dv-ease);
}

.dv-card .dv-card__link:hover,
.dv-card .dv-card__link:focus {
	background-color: var(--dv-console-2);
	color: var(--dv-console-ink);
	text-decoration: none;
}

.dv-card .dv-card__link:hover {
	border-color: var(--dv-console-ink-2);
	transform: translateY(-2px);
}

/* The brief's card ring is brand red (theme.css draws every other ring in the link colour). */
.dv-card .dv-card__link:focus-visible {
	outline-color: var(--dv-brand) !important;
}

.dv-card__art {
	position: relative;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	aspect-ratio: 1;
	padding: var(--dv-space-4);
	border-radius: var(--dv-radius-md);
	background-color: var(--dv-console-2);
	overflow: hidden;
	transition: background-color var(--dv-dur-fast) var(--dv-ease);
}

.dv-card__frame {
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	transition: background-color var(--dv-dur-fast) var(--dv-ease);
}

.dv-card .dv-card__link:hover .dv-card__art {
	background-color: var(--dv-console-3);
}

.dv-card.dv-card .dv-card__img.dv-card__img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	border-radius: var(--dv-radius-sm);
	box-shadow: none;
	object-fit: contain;
}

.dv-card__initial {
	color: var(--dv-console-ink-2);
	font-family: var(--dv-font-display);
	font-size: 48px;
	font-weight: 700;
	line-height: 1;
}

/* Personal or Pack top left, one badge top right. Outlined badges get a solid ground over the artwork. */
.dv-card__chips {
	position: absolute;
	top: var(--dv-space-2);
	right: var(--dv-space-2);
	left: var(--dv-space-2);
	display: flex;
	gap: var(--dv-space-2);
	pointer-events: none;
}

.dv-card__chips .dv-badge:is(.dv-badge--personal, .dv-badge--shared, .dv-badge--best) {
	background-color: var(--dv-console);
}

.dv-card__chips .dv-card__badge {
	margin-left: auto;
}

.dv-card .dv-card__vendor {
	overflow: hidden;
	margin: var(--dv-space-3) var(--dv-space-1) 0;
	color: var(--dv-console-ink-2);
	font-family: var(--dv-font-mono);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.dv-card.dv-card .dv-card__name.dv-card__name {
	display: -webkit-box;
	overflow: hidden;
	margin: var(--dv-space-1) var(--dv-space-1) 0;
	padding: 0;
	color: var(--dv-console-ink);
	font-family: var(--dv-font-display);
	font-size: var(--dv-text-h3);
	font-weight: 600;
	line-height: 1.25;
	letter-spacing: -0.01em;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
}

/* A card without a vendor line: the name takes its place under the artwork. */
.dv-card.dv-card .dv-card__art + .dv-card__name {
	margin-top: var(--dv-space-3);
}

.dv-card .dv-card__tagline {
	overflow: hidden;
	margin: var(--dv-space-1) var(--dv-space-1) 0;
	color: var(--dv-console-ink-2);
	font-size: var(--dv-text-body-s);
	line-height: 1.45;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/*
 * The focal point: the price, at the foot of every card whatever the name's length. Always two lines, the amount
 * (with the arrow on its right) over the cadence, so price rows line up across a grid row whatever the offer.
 */
.dv-card__price {
	display: grid;
	grid-template-areas:
		"amount arrow"
		"cadence cadence";
	grid-template-columns: minmax(0, 1fr) auto;
	grid-template-rows: auto calc(.8125rem * 1.3);
	align-items: center;
	row-gap: 2px;
	margin: auto var(--dv-space-1) var(--dv-space-1);
	padding-top: var(--dv-space-4);
}

.dv-card__amount {
	grid-area: amount;
	color: var(--dv-console-ink);
	font-size: var(--dv-text-h3);
	font-weight: 500;
	line-height: 1.2;
}

.dv-card__cadence {
	grid-area: cadence;
	overflow: hidden;
	color: var(--dv-console-ink-2);
	font-size: .8125rem;
	line-height: 1.3;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.dv-card__arrow {
	grid-area: arrow;
	margin-left: var(--dv-space-3);
	color: var(--dv-console-ink-2);
	font-size: var(--dv-text-body);
	line-height: 1;
	transition: color var(--dv-dur-fast) var(--dv-ease), transform var(--dv-dur-fast) var(--dv-ease);
}

.dv-card .dv-card__link:hover .dv-card__arrow {
	color: var(--dv-console-ink);
	transform: translateX(4px);
}

@media (min-width: 1024px) {
	.products.dv-grid.dv-grid.dv-grid--3 {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

/*
 * PackCard: the art tile lists the first three included items of the pack's description (Inter 14) and "+ n more" in
 * mono, instead of an image. The item count is for the mobile row only, where the tile is 88 px.
 */
.dv-card__count {
	display: none;
}

@media (min-width: 600px) {
	/* Not a square: the list sets the height (a square is mostly empty on a wide card). */
	.dv-card .dv-card__art.dv-card__art--list {
		flex: 1 1 auto; /* the tiles of a row share its height */
		aspect-ratio: auto;
		min-height: 216px;
	}

	.dv-card__art--list .dv-card__frame {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: flex-start;
		padding-top: var(--dv-space-6);
	}

	.dv-card__list {
		display: grid;
		gap: var(--dv-space-2);
		width: 100%;
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.dv-card__list > li {
		display: -webkit-box;
		overflow: hidden;
		margin: 0;
		padding: 0 0 0 var(--dv-space-4);
		position: relative;
		color: var(--dv-console-ink);
		font-size: var(--dv-text-body-s);
		line-height: 1.4;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		line-clamp: 2;
	}

	.dv-card__list > li::before {
		content: "";
		position: absolute;
		top: .55em;
		left: 0;
		width: 6px;
		height: 6px;
		border-radius: 50%;
		background-color: var(--dv-console-ink-2);
	}

	.dv-card__more {
		margin-top: var(--dv-space-2);
		color: var(--dv-console-ink-2);
		font-size: var(--dv-text-label);
		line-height: 1.4;
	}
}

/*
 * Below 600 px the card is a row: an 88 px art tile, then the chip and vendor line, the name, the tagline and the
 * two-line price, with the arrow at the far right, centred on the row. The art wrapper and the price block give up
 * their boxes (display: contents) so their children sit in the card's grid.
 */
@media (max-width: 599px) {
	.products.dv-grid.dv-grid.dv-grid {
		gap: var(--dv-space-3);
	}

	.dv-card .dv-card__link {
		display: grid;
		grid-template-areas:
			"art chips vendor arrow"
			"art name name arrow"
			"art tag tag arrow"
			"art amount amount arrow"
			"art cadence cadence arrow";
		grid-template-columns: 88px auto minmax(0, 1fr) auto;
		align-content: center;
		box-sizing: border-box;
		min-height: 120px;
		padding: var(--dv-space-3);
	}

	.dv-card.dv-card--no-vendor .dv-card__link {
		grid-template-areas:
			"art chips name arrow"
			"art tag tag arrow"
			"art amount amount arrow"
			"art cadence cadence arrow";
	}

	.dv-card .dv-card__art,
	.dv-card .dv-card__price {
		display: contents;
	}

	.dv-card__frame {
		grid-area: art;
		align-self: center;
		width: 88px;
		height: 88px;
		margin-right: var(--dv-space-3);
		padding: var(--dv-space-2);
		border-radius: var(--dv-radius-md);
		background-color: var(--dv-console-2);
	}

	.dv-card .dv-card__link:hover .dv-card__frame {
		background-color: var(--dv-console-3);
	}

	.dv-card__initial {
		font-size: 32px;
	}

	.dv-card__chips {
		position: static;
		grid-area: chips;
		align-self: center;
		margin-right: var(--dv-space-2);
	}

	.dv-card__chips .dv-card__badge {
		margin-left: 0;
	}

	.dv-card .dv-card__vendor {
		grid-area: vendor;
		align-self: center;
		margin: 0;
	}

	.dv-card.dv-card .dv-card__name.dv-card__name,
	.dv-card.dv-card .dv-card__art + .dv-card__name {
		grid-area: name;
		align-self: center;
		margin: var(--dv-space-1) 0 0;
		font-size: var(--dv-text-body);
	}

	.dv-card.dv-card--no-vendor .dv-card__name.dv-card__name {
		margin-top: 0;
	}

	.dv-card .dv-card__tagline {
		grid-area: tag;
		margin: 2px 0 0;
		font-size: .8125rem;
	}

	.dv-card__amount {
		margin-top: var(--dv-space-2);
	}

	.dv-card__arrow {
		grid-row: 1 / -1;
		align-self: center;
	}

	/* The kind of pack ("Build your own") is too wide to share the chip's line: it takes the line below. */
	.dv-card.dv-card--pack .dv-card__link {
		grid-template-areas:
			"art chips chips arrow"
			"art vendor vendor arrow"
			"art name name arrow"
			"art tag tag arrow"
			"art amount amount arrow"
			"art cadence cadence arrow";
	}

	.dv-card.dv-card--pack .dv-card__vendor {
		margin-top: var(--dv-space-1);
	}

	/* A pack's list tile is the 88 px square with only the item count. */
	.dv-card__list,
	.dv-card__more {
		display: none;
	}

	.dv-card__count {
		display: block;
		color: var(--dv-console-ink-2);
		font-size: var(--dv-text-label);
		line-height: 1.3;
		text-align: center;
	}
}

/* Reduced motion: no translation (theme.css shortens the transitions themselves). ------- */

@media (prefers-reduced-motion: reduce) {
	.dv-card .dv-card__link:hover,
	.dv-card .dv-card__link:hover .dv-card__arrow {
		transform: none;
	}
}

html[data-motion="reduce"] .dv-card .dv-card__link:hover,
html[data-motion="reduce"] .dv-card .dv-card__link:hover .dv-card__arrow {
	transform: none;
}
