/* Comparison table (docs/widgets/comparison.md), in the design language (spec §3.7): the table on a
   raised card with its own colours, a tinted column for the highlighted plan, pill buttons and badge,
   and ticks in tinted circles. The tokens (--hafe-surface, --hafe-accent…) come from design.css.

   The widget's Show control sets the custom properties per breakpoint: every plan, or one at a time.
   Which one is a radio button's state, so no script is involved. Without those properties (no
   generated CSS yet), every plan shows. */
.hafe-comparison {
	--hafe-comparison-wash: color-mix(in srgb, var(--hafe-accent) 6%, var(--hafe-surface));
	--hafe-comparison-band: color-mix(in srgb, var(--hafe-ink) 4%, var(--hafe-surface));
}

.hafe-scheme-dark .hafe-comparison {
	--hafe-comparison-wash: color-mix(in srgb, var(--hafe-accent) 14%, var(--hafe-surface));
}

.hafe-comparison__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* The card. It scrolls sideways when the plans don't fit. Positioned, so text kept for screen
   readers scrolls with its cell and can't widen the page. */
.hafe-comparison__scroll {
	position: relative;
	overflow-x: auto;
	border: 1px solid var(--hafe-comparison-border, var(--hafe-line));
	border-radius: var(--hafe-comparison-radius, var(--hafe-radius));
	background: var(--hafe-comparison-bg, var(--hafe-surface));
	box-shadow: var(--hafe-shadow);
}

.hafe-comparison__table {
	width: 100%;
	margin: 0;
	border: 0;
	border-collapse: separate;
	border-spacing: 0;
	background: none;
	font-size: inherit;
	overflow-wrap: break-word;
}

/* Specific enough to undo the table styles of themes: lines, stripes and capitals. */
.hafe-comparison .hafe-comparison__table > * > tr > * {
	padding: var(--hafe-comparison-padding, 0.85em 1em);
	border: 0;
	border-block-end: 1px solid var(--hafe-comparison-line, var(--hafe-line));
	background: none;
	color: var(--hafe-comparison-color, var(--hafe-ink));
	font-weight: inherit;
	text-align: center;
	text-transform: none;
	vertical-align: middle;
}

.hafe-comparison__table > tbody:last-child > tr:last-child > * {
	border-block-end: 0;
}

/* Words stay whole in every cell (the table scrolls first), and only a word too long for any
   column breaks. In the one-plan view (the Show control), a very long feature name may break
   anywhere, so it can't widen a phone. The minimum width keeps ordinary words whole when every
   plan shows: the plans' own minimum would otherwise squeeze it. */
.hafe-comparison__table > * > tr > :first-child {
	overflow-wrap: var(--hafe-comparison-wrap, break-word);
	width: var(--hafe-comparison-feature-width, auto);
	min-width: var(--hafe-comparison-feature-width, var(--hafe-comparison-min, 6.5em));
	text-align: start;
}

/* Rows, and every other row in its own colour when one is set. The count skips group headings and
   starts again in each group. Hover comes last, so it shows on either kind of row. */
.hafe-comparison__table > tbody > tr {
	background: var(--hafe-comparison-row-bg, none);
}

.hafe-comparison__table > tbody > tr:nth-child(even of :not(.hafe-comparison__group)) {
	background: var(--hafe-comparison-row-alt-bg, var(--hafe-comparison-row-bg, none));
}

.hafe-comparison__table > tbody > tr:not(.hafe-comparison__group):hover {
	background: var(--hafe-comparison-hover-bg, var(--hafe-comparison-row-bg, none));
}

.hafe-comparison__table > tbody > tr:nth-child(even of :not(.hafe-comparison__group)):hover {
	background: var(--hafe-comparison-hover-bg, var(--hafe-comparison-row-alt-bg, var(--hafe-comparison-row-bg, none)));
}

/* Plans */
.hafe-comparison .hafe-comparison__table > thead > tr > * {
	padding: var(--hafe-comparison-padding, 1.5em 0.75em 1.25em);
	background: var(--hafe-comparison-head-bg, none);
	vertical-align: bottom;
}

/* Hello Elementor lines the top of a table's first header row, with a rule more specific than the
   ones above. */
.hafe-comparison .hafe-comparison__table > thead:first-child > tr:first-child > * {
	border-block-start: 0;
}

.hafe-comparison__plan {
	min-width: var(--hafe-comparison-min, 6.5em);
}

.hafe-comparison__badge,
.hafe-comparison__name,
.hafe-comparison__price {
	display: block;
}

.hafe-comparison__badge {
	width: fit-content;
	max-width: 100%;
	box-sizing: border-box;
	margin-block-end: 0.75em;
	margin-inline: auto;
	padding: 0.35em 0.9em;
	border-radius: var(--hafe-pill);
	background: var(--hafe-accent);
	color: var(--hafe-comparison-badge-color, var(--hafe-on-accent));
	font-size: 0.7em;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.hafe-comparison__name {
	color: var(--hafe-comparison-name-color, inherit);
	font-size: 1.15em;
	font-weight: 600;
}

.hafe-comparison__price {
	margin-block-start: 0.2em;
	color: var(--hafe-comparison-price-color, var(--hafe-ink-soft));
	font-size: 0.95em;
	font-weight: 400;
}

.hafe-comparison .hafe-comparison__button {
	display: inline-block;
	margin-block-start: 1em;
	padding: 0.55em 1em;
	border: 0;
	border-radius: var(--hafe-pill);
	background: var(--hafe-comparison-button-bg, var(--hafe-tint));
	color: var(--hafe-comparison-button-color, var(--hafe-accent-ink));
	font-size: 0.9em;
	font-weight: 600;
	line-height: 1.25;
	text-decoration: none;
	text-transform: none;
	transition: background-color 0.2s, color 0.2s;
}

.hafe-comparison .hafe-comparison__button:hover {
	background: var(--hafe-comparison-button-hover-bg, var(--hafe-tint-strong));
	color: var(--hafe-comparison-button-hover-color, var(--hafe-comparison-button-color, var(--hafe-accent-ink)));
}

/* The highlighted plan: its column in a wash of the accent, and a solid button. */
.hafe-comparison .hafe-comparison__table > * > tr > .is-highlighted {
	background: var(--hafe-comparison-highlight-bg, var(--hafe-comparison-wash));
}

.hafe-comparison .is-highlighted .hafe-comparison__button {
	background: var(--hafe-comparison-button-bg, var(--hafe-accent));
	color: var(--hafe-comparison-button-color, var(--hafe-on-accent));
}

.hafe-comparison .is-highlighted .hafe-comparison__button:hover {
	background: var(--hafe-comparison-button-hover-bg, color-mix(in srgb, var(--hafe-accent) 85%, #000));
	color: var(--hafe-comparison-button-hover-color, var(--hafe-comparison-button-color, var(--hafe-on-accent)));
}

/* Group headings: a quiet band across the table. */
.hafe-comparison__table > tbody > .hafe-comparison__group > th {
	padding-block: 0.7em;
	background: var(--hafe-comparison-group-bg, var(--hafe-comparison-band));
	color: var(--hafe-comparison-group-color, var(--hafe-ink-soft));
	font-size: 0.8em;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

/* Checks in a tinted circle; crosses and dashes are quieter. */
.hafe-comparison__mark {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: var(--hafe-comparison-mark-size, 1.5em);
	block-size: var(--hafe-comparison-mark-size, 1.5em);
	border-radius: 50%;
	background: var(--hafe-tint);
	color: var(--hafe-comparison-check, var(--hafe-accent-ink));
	line-height: 1;
	vertical-align: middle;
}

.hafe-comparison__mark svg {
	width: 50%;
	height: 50%;
	fill: currentColor;
}

.hafe-comparison__mark i {
	font-size: calc(var(--hafe-comparison-mark-size, 1.5em) / 2);
}

.hafe-comparison__mark--cross,
.hafe-comparison__mark--dash {
	background: none;
	color: var(--hafe-comparison-cross, var(--hafe-ink-soft));
}

/* Without a circle, the glyph takes more of the mark. */
.hafe-comparison__mark--cross svg,
.hafe-comparison__mark--dash svg {
	width: 65%;
	height: 65%;
}

.hafe-comparison__mark--dash {
	color: var(--hafe-comparison-dash, var(--hafe-ink-soft));
}

.hafe-comparison__note {
	display: block;
	margin-block-start: 0.25em;
	color: var(--hafe-ink-soft);
	font-size: 0.8em;
}

/* The choice of a plan, when one shows at a time: a pill of its own, on our surface. */
.hafe-comparison__switch {
	display: none;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.25em;
	width: fit-content;
	max-width: 100%;
	box-sizing: border-box;
	min-width: 0;
	margin: 0 auto 1.25em;
	padding: 0.3em;
	border: 1px solid var(--hafe-line);
	border-radius: 1.75em;
	background: var(--hafe-surface);
}

.hafe-comparison__option {
	position: relative;
}

.hafe-comparison__choice {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	pointer-events: none;
}

/* Two classes: spec §4. */
.hafe-comparison .hafe-comparison__option label {
	cursor: pointer;
	display: block;
	margin: 0;
	/* Narrower sides on a phone, so four plans' names fit on one line. */
	padding: 0.5em clamp(0.6em, 3.2vw, 1.1em);
	border-radius: var(--hafe-pill);
	color: var(--hafe-ink-soft);
	font-weight: 600;
	text-align: center;
	transition: background-color 0.2s, color 0.2s;
}

.hafe-comparison__choice:checked + label {
	background: var(--hafe-accent);
	color: var(--hafe-comparison-badge-color, var(--hafe-on-accent));
}

.hafe-comparison__choice:focus-visible + label {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 2px;
}

@supports selector(:has(a)) {
	.hafe-comparison__switch {
		display: var(--hafe-comparison-switch, none);
	}

	.hafe-comparison__table > * > tr > :nth-child(n + 2) {
		display: var(--hafe-comparison-others, table-cell);
	}

	.hafe-comparison:has([data-plan="1"]:checked) .hafe-comparison__table > * > tr > :nth-child(2),
	.hafe-comparison:has([data-plan="2"]:checked) .hafe-comparison__table > * > tr > :nth-child(3),
	.hafe-comparison:has([data-plan="3"]:checked) .hafe-comparison__table > * > tr > :nth-child(4),
	.hafe-comparison:has([data-plan="4"]:checked) .hafe-comparison__table > * > tr > :nth-child(5),
	.hafe-comparison:has([data-plan="5"]:checked) .hafe-comparison__table > * > tr > :nth-child(6),
	.hafe-comparison:has([data-plan="6"]:checked) .hafe-comparison__table > * > tr > :nth-child(7) {
		display: table-cell;
	}
}

@media print {
	.hafe-comparison__switch {
		display: none;
	}

	.hafe-comparison__table > * > tr > :nth-child(n + 2) {
		display: table-cell !important;
	}

	.hafe-comparison__scroll {
		overflow: visible;
	}
}
