/**
 * Savvy Rest comparison tables.
 *
 * Applies to the core Table block when an editor picks the "Comparison" style.
 * Self-contained: wp-block-library's table CSS is dequeued on some templates,
 * so nothing here leans on it.
 */

.wp-block-table.sr-ctable,
.wp-block-table.is-style-savvyrest-comparison {
	--sr-ctable-plum: #7e4f8a;
	--sr-ctable-green: #243017;
	--sr-ctable-ink: #4b4f58;
	--sr-ctable-rule: #e6e0d3;
	--sr-ctable-head: #f5f2ea;
	--sr-ctable-stub: #fbf8f1;
	--sr-ctable-zebra: #fdfcfa;
	--sr-ctable-hover: #fbf6fc;

	margin: 2.25rem 0;
	padding: 0;
	font-family: "Cabinet Grotesk", system-ui, -apple-system, sans-serif;
}

/* The scroll region: only scrolls when the table genuinely cannot shrink. */
.wp-block-table.is-style-savvyrest-comparison .sr-ctable__scroll {
	overflow-x: auto;
	border: 1px solid var(--sr-ctable-rule);
	border-radius: 14px;
	background: #fff;
	-webkit-overflow-scrolling: touch;
}

.wp-block-table.is-style-savvyrest-comparison .sr-ctable__scroll:focus-visible {
	outline: 2px solid var(--sr-ctable-plum);
	outline-offset: 2px;
}

.wp-block-table.is-style-savvyrest-comparison table {
	width: 100%;
	margin: 0;
	border: 0;
	border-collapse: collapse;
	border-spacing: 0;
	font-size: 1rem;
	line-height: 1.5;
	color: var(--sr-ctable-ink);
	text-align: left;
}

/* wp-block-library gives every cell `border: 1px solid` with no colour, which
   resolves to currentColor. Clear it and draw only the rules we want. */
.wp-block-table.is-style-savvyrest-comparison table th,
.wp-block-table.is-style-savvyrest-comparison table td {
	border: 0;
}

/* Same source: a 3px currentColor rule under <thead> that outranks ours. */
.wp-block-table.is-style-savvyrest-comparison table thead,
.wp-block-table.is-style-savvyrest-comparison table tfoot {
	border: 0;
}

/* Caption doubles as the table's visible label, so it sits above the grid. */
.wp-block-table.is-style-savvyrest-comparison table caption {
	caption-side: top;
	padding: 1rem 1.25rem 0.875rem;
	border-bottom: 1px solid var(--sr-ctable-rule);
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--sr-ctable-plum);
	text-align: left;
}

/* Keep the left-hand stub from collapsing or hogging the grid. */
.wp-block-table.is-style-savvyrest-comparison table thead th:first-child,
.wp-block-table.is-style-savvyrest-comparison table tbody th[scope="row"],
.wp-block-table.is-style-savvyrest-comparison table tfoot th[scope="row"] {
	width: 24%;
	min-width: 6.5rem;
}

.wp-block-table.is-style-savvyrest-comparison table thead th {
	padding: 0.875rem 1.25rem;
	background: var(--sr-ctable-head);
	border-bottom: 2px solid var(--sr-ctable-plum);
	font-size: 0.9375rem;
	font-weight: 700;
	line-height: 1.35;
	color: var(--sr-ctable-green);
	text-align: left;
	vertical-align: bottom;
}

.wp-block-table.is-style-savvyrest-comparison table tbody th,
.wp-block-table.is-style-savvyrest-comparison table tbody td,
.wp-block-table.is-style-savvyrest-comparison table tfoot th,
.wp-block-table.is-style-savvyrest-comparison table tfoot td {
	padding: 0.875rem 1.25rem;
	border-top: 1px solid var(--sr-ctable-rule);
	vertical-align: top;
}

.wp-block-table.is-style-savvyrest-comparison table tbody tr:first-child th,
.wp-block-table.is-style-savvyrest-comparison table tbody tr:first-child td {
	border-top: 0;
}

/* Row headers: the left-hand stub that names what each row compares. */
.wp-block-table.is-style-savvyrest-comparison table tbody th[scope="row"],
.wp-block-table.is-style-savvyrest-comparison table tfoot th[scope="row"] {
	position: sticky;
	left: 0;
	z-index: 1;
	background: var(--sr-ctable-stub);
	font-weight: 600;
	color: var(--sr-ctable-green);
	text-align: left;
}

.wp-block-table.is-style-savvyrest-comparison table tbody tr:nth-child(even) td {
	background: var(--sr-ctable-zebra);
}

.wp-block-table.is-style-savvyrest-comparison table tbody tr:hover td {
	background: var(--sr-ctable-hover);
}

.wp-block-table.is-style-savvyrest-comparison table tbody tr:hover th[scope="row"] {
	background: var(--sr-ctable-hover);
}

.wp-block-table.is-style-savvyrest-comparison table tbody td:empty::after {
	content: "\2014";
	color: #a49f93;
}

.wp-block-table.is-style-savvyrest-comparison table a {
	color: var(--sr-ctable-plum);
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.wp-block-table.is-style-savvyrest-comparison table strong {
	color: var(--sr-ctable-green);
}

/* A figcaption is normally converted to <caption>; style it in case one survives. */
.wp-block-table.is-style-savvyrest-comparison figcaption {
	margin-top: 0.75rem;
	font-size: 0.875rem;
	color: #6f6a61;
}

@media (max-width: 782px) {
	.wp-block-table.is-style-savvyrest-comparison table {
		font-size: 0.9375rem;
	}

	.wp-block-table.is-style-savvyrest-comparison table caption {
		padding: 0.875rem 1rem 0.75rem;
	}

	.wp-block-table.is-style-savvyrest-comparison table thead th,
	.wp-block-table.is-style-savvyrest-comparison table tbody th,
	.wp-block-table.is-style-savvyrest-comparison table tbody td,
	.wp-block-table.is-style-savvyrest-comparison table tfoot th,
	.wp-block-table.is-style-savvyrest-comparison table tfoot td {
		padding: 0.75rem 0.875rem;
	}
}

@media (max-width: 600px) {
	.wp-block-table.sr-ctable {
		margin: 1.75rem 0;
	}

	.wp-block-table.is-style-savvyrest-comparison table {
		font-size: 0.875rem;
	}

	.wp-block-table.is-style-savvyrest-comparison table thead th {
		font-size: 0.8125rem;
	}

	.wp-block-table.is-style-savvyrest-comparison table thead th,
	.wp-block-table.is-style-savvyrest-comparison table tbody th,
	.wp-block-table.is-style-savvyrest-comparison table tbody td,
	.wp-block-table.is-style-savvyrest-comparison table tfoot th,
	.wp-block-table.is-style-savvyrest-comparison table tfoot td {
		padding: 0.6875rem 0.75rem;
	}

	/* Shadow on the sticky stub, so a scrolled table reads as scrolled. */
	.wp-block-table.is-style-savvyrest-comparison table tbody th[scope="row"] {
		box-shadow: 1px 0 0 var(--sr-ctable-rule);
	}
}

@media (prefers-reduced-motion: no-preference) {
	.wp-block-table.is-style-savvyrest-comparison table tbody tr td,
	.wp-block-table.is-style-savvyrest-comparison table tbody tr th {
		transition: background-color 120ms ease;
	}
}
