/*
 * "Product comparison" style for the core Table block (is-style-pff-compare).
 * Theme-independent: inherits the theme's fonts and takes its accent from the block theme's
 * primary colour, then Astra's, then the brand pink – the same tokens as the product cards.
 *
 * Expected markup (what the Table block saves): a header row in <thead> with <th scope="col">,
 * product names as <th scope="row">, short value columns centred with the block's alignment
 * control, and affiliate links with rel="sponsored".
 */
.wp-block-table.is-style-pff-compare {
	--pff-tc-accent: var(--wp--preset--color--primary, var(--ast-global-color-0, #a15a6d));
	--pff-tc-line: color-mix(in srgb, var(--pff-tc-accent) 18%, transparent);
	--pff-tc-bg: var(--wp--preset--color--base, #fff);
	--pff-tc-stripe: color-mix(in srgb, var(--pff-tc-accent) 5%, var(--pff-tc-bg));
	position: relative;
	margin-block: 2rem;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border: 1px solid color-mix(in srgb, var(--pff-tc-accent) 35%, transparent);
	border-radius: 12px;
	/* Scroll hint: a soft shadow appears on the right while there is more table to see. */
	background:
		linear-gradient(to left, var(--pff-tc-bg) 30%, transparent) right center / 2.5rem 100% no-repeat local,
		radial-gradient(farthest-side at 100% 50%, rgb(0 0 0 / 0.12), transparent) right center / 0.9rem 100% no-repeat scroll,
		var(--pff-tc-bg);
}

.wp-block-table.is-style-pff-compare table {
	width: 100%;
	min-width: 36rem; /* Narrow screens scroll sideways rather than crushing the columns. */
	margin: 0;
	border: 0;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 0.95rem;
	line-height: 1.45;
	font-variant-numeric: tabular-nums;
	background: transparent;
}

/* Cells – selectors doubled so theme and core table borders don't win. */
.wp-block-table.is-style-pff-compare th,
.wp-block-table.is-style-pff-compare td {
	padding: 0.7rem 0.65rem;
	border: 0;
	border-top: 1px solid var(--pff-tc-line);
	text-align: left;
	vertical-align: middle;
	background-color: transparent;
	overflow-wrap: normal; /* Never split a word mid-way (themes often set break-word). */
	word-break: normal;
}

.wp-block-table.is-style-pff-compare .has-text-align-center {
	text-align: center;
}

/* Header row. */
.wp-block-table.is-style-pff-compare thead {
	border: 0;
}

.wp-block-table.is-style-pff-compare thead th {
	border-top: 0;
	background-color: color-mix(in srgb, var(--pff-tc-accent) 12%, var(--pff-tc-bg));
	color: color-mix(in srgb, var(--pff-tc-accent) 75%, #000);
	font-size: 0.78rem;
	font-weight: 700;
	letter-spacing: 0.03em;
	line-height: 1.3;
	text-transform: uppercase;
	vertical-align: bottom;
}

/* Zebra rows. */
.wp-block-table.is-style-pff-compare tbody tr:nth-child(even) > * {
	background-color: var(--pff-tc-stripe);
}

.wp-block-table.is-style-pff-compare tbody tr:hover > * {
	background-color: color-mix(in srgb, var(--pff-tc-accent) 9%, var(--pff-tc-bg));
}

/* Product name column: stays in view while the rest of the table scrolls sideways. */
.wp-block-table.is-style-pff-compare th[scope="row"],
.wp-block-table.is-style-pff-compare thead th:first-child {
	position: sticky;
	left: 0;
	z-index: 1;
	min-width: 8.5rem;
	max-width: 13rem;
	box-shadow: inset -1px 0 0 var(--pff-tc-line);
}

.wp-block-table.is-style-pff-compare th[scope="row"] {
	background-color: var(--pff-tc-bg);
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.3;
}

.wp-block-table.is-style-pff-compare th[scope="row"] a {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, var(--pff-tc-accent) 45%, transparent);
	text-underline-offset: 0.2em;
}

.wp-block-table.is-style-pff-compare th[scope="row"] a:hover,
.wp-block-table.is-style-pff-compare th[scope="row"] a:focus-visible {
	color: var(--pff-tc-accent);
}

/* Product thumbnails. */
.wp-block-table.is-style-pff-compare img {
	display: block;
	width: 64px;
	max-width: none;
	height: 64px;
	margin-inline: auto;
	object-fit: cover;
	border-radius: 8px;
	background: #e5e5e5;
}

/* Affiliate links read as small buttons. */
.wp-block-table.is-style-pff-compare td a[rel~="sponsored"] {
	display: inline-block;
	padding: 0.45em 0.85em;
	border-radius: 999px;
	background: var(--pff-tc-accent);
	color: #fff;
	font-size: 0.85rem;
	font-weight: 700;
	line-height: 1.2;
	text-decoration: none;
	white-space: nowrap;
	transition: filter 0.15s ease;
}

.wp-block-table.is-style-pff-compare td a[rel~="sponsored"]:hover,
.wp-block-table.is-style-pff-compare td a[rel~="sponsored"]:focus-visible {
	color: #fff;
	text-decoration: none;
	filter: brightness(0.9);
}

.wp-block-table.is-style-pff-compare td a[rel~="sponsored"]:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--pff-tc-accent) 45%, #fff);
	outline-offset: 2px;
}

.wp-block-table.is-style-pff-compare figcaption {
	margin: 0;
	padding: 0.75rem 1rem;
	border-top: 1px solid var(--pff-tc-line);
	font-size: 0.85rem;
	text-align: left;
}

@media (max-width: 600px) {
	.wp-block-table.is-style-pff-compare table {
		font-size: 0.9rem;
	}

	.wp-block-table.is-style-pff-compare th,
	.wp-block-table.is-style-pff-compare td {
		padding: 0.65rem 0.75rem;
	}

	.wp-block-table.is-style-pff-compare th[scope="row"],
	.wp-block-table.is-style-pff-compare thead th:first-child {
		min-width: 7.5rem;
		max-width: 9rem;
	}

	.wp-block-table.is-style-pff-compare th[scope="row"] {
		font-size: 0.92rem;
	}

	.wp-block-table.is-style-pff-compare img {
		width: 52px;
		height: 52px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-table.is-style-pff-compare td a[rel~="sponsored"] {
		transition: none;
	}
}
