/**
 * Búho compare (T-89): the compare bar and the compare page (the Compare button is the theme's .buho-action).
 *
 * Mobile first; breakpoints 600, 782 and 1024 px, like the theme. Colours are the theme's tokens
 * (CLAUDE.md §5.2, T-55 roles) read through local --bc-* variables, so light, dark and the studio
 * skin follow; this sheet's dark block only restates what the tokens do not cover. Amber is never
 * text on a light background and focus rings are the theme's (navy + amber).
 *
 * Rules for this file:
 * - The dark block exists twice, identically (explicit + system), between the @buho-dark markers;
 *   the theme's tests/js/color-scheme-css.test.js checks it.
 * - A fill under white text reads --bc-fill (--buho-navy-surface), never --brand-navy.
 * - Every element this sheet gives a display value also gets a [hidden] rule.
 */

.buho-compare,
.buho-compare-bar {
	--bc-ink: var(--color-text, #1c1f24);
	--bc-text: var(--color-text-muted, #3a414b);
	--bc-muted: var(--brand-muted, #5b6470);
	--bc-line: var(--color-line, #c3c8cf);
	--bc-line-soft: var(--color-line-soft, #edeef0);
	--bc-field: var(--color-field-border, #858c96); /* Control borders: 3:1 (WCAG 1.4.11). */
	--bc-surface: var(--brand-surface, #fff);
	--bc-raise: var(--buho-paper, #f6f6f4);
	--bc-navy: var(--brand-navy, #093c71); /* Text, links and borders (light blue in dark mode). */
	--bc-fill: var(--buho-navy-surface, #093c71); /* Fills under white text. */
	--bc-fill-hover: var(--buho-navy-surface-hover, #062a50);
	--bc-on-fill: #fff;
	--bc-photo: var(--buho-photo-panel, #fff);
	--bc-photo-filter: var(--buho-photo-filter, none);
	--bc-shadow: 0 -6px 18px rgba(9, 60, 113, 0.1);
	--bc-code: var(--font-code, ui-monospace, Menlo, Consolas, monospace);
	--bc-brand: var(--font-brand, "League Spartan", system-ui, sans-serif);
}

.buho-compare *,
.buho-compare-bar *,
.buho-compare *::before,
.buho-compare-bar *::before {
	box-sizing: border-box;
}

/* The Compare button uses the theme's product action slot (.buho-action, theme.css section
   "product actions (T-88)", studio-catalogue.css, studio-product.css): no rules of its own. Its icon
   is one path (two columns), so the slot's pressed fill works for it as for the heart. */

/* After "Clear all" in the bar, the script focuses the main content when the page has no Compare
   button: no ring round the whole page. */
[data-buho-compare-focus]:focus {
	outline: none;
	box-shadow: none;
}

/* ------------------------------------------------------------ compare bar */

/* Space for the bar at the end of every page while it shows (assets/js/compare.js measures it). */
html.buho-has-compare-bar {
	scroll-padding-bottom: var(--buho-compare-bar-h, 0px);
}

html.buho-has-compare-bar body {
	padding-bottom: var(--buho-compare-bar-h, 0px);
}

.buho-compare-bar {
	position: fixed;
	right: 0;
	bottom: var(--buho-compare-bottom, 0px); /* Above buho-product's sticky bar on phones. */
	left: 0;
	z-index: 45; /* Over page content and the product sticky bar (40), under the header drawer. */
	padding: 8px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
	border-top: 1px solid var(--bc-line);
	background: var(--bc-surface);
	box-shadow: var(--bc-shadow);
	color: var(--bc-ink);
	font-family: var(--bc-brand);
	line-height: 1.3;
	animation: buho-compare-in 0.2s ease-out;
}

.buho-compare-bar[hidden] {
	display: none;
}

@keyframes buho-compare-in {
	from {
		transform: translateY(100%);
	}
}

.buho-compare-bar__inner {
	display: grid;
	grid-template-areas:
		"head actions"
		"body body";
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: center;
	gap: 6px 12px;
	max-width: var(--buho-max, 1184px);
	margin-inline: auto;
}

.buho-compare-bar__head {
	display: flex;
	grid-area: head;
	align-items: center;
	gap: 4px;
	min-width: 0;
}

.buho-compare-bar__title {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0 8px;
	margin: 0;
	color: var(--bc-ink);
	font-family: inherit;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.2;
}

.buho-compare-bar__count {
	color: var(--bc-muted);
	font-family: var(--bc-code);
	font-size: 13px;
	font-weight: 400;
}

.buho-compare-bar__expand {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--bc-navy);
	cursor: pointer;
}

.buho-compare-bar__expand svg {
	transition: transform 0.15s ease;
}

/* Open: the chevron points down (fold); folded: up (open). */
.buho-compare-bar__expand[aria-expanded="true"] svg {
	transform: rotate(180deg);
}

.buho-compare-bar__body {
	grid-area: body;
	min-width: 0;
}

.buho-compare-bar__body[hidden] {
	display: none;
}

.buho-compare-bar__items {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr)); /* Phones: two a row, half the height. */
	gap: 6px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.buho-compare-bar__item {
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
	min-height: 44px;
	margin: 0;
	padding: 4px;
	border: 1px solid var(--bc-line);
	background: var(--bc-surface);
}

/* Empty places (up to four): only on wide screens. */
.buho-compare-bar__item--empty {
	display: none;
	justify-content: center;
	border-style: dashed;
	color: var(--bc-muted);
	font-size: 13px;
}

.buho-compare-bar__thumb {
	display: grid;
	flex: none;
	place-items: center;
	width: 32px;
	height: 32px;
	overflow: hidden;
	background: var(--bc-photo);
}

.buho-compare-bar__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	filter: var(--bc-photo-filter);
}

/* Phones: up to two lines (half-width chips); one line from 600 px. */
.buho-compare-bar__name {
	display: -webkit-box;
	flex: 1;
	min-width: 0;
	overflow: hidden;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.2;
	overflow-wrap: anywhere;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.buho-compare-bar__remove {
	display: inline-flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--bc-text);
	cursor: pointer;
}

.buho-compare-bar__remove:hover {
	color: var(--bc-navy);
}

.buho-compare-bar__note {
	margin: 6px 0 0;
	color: var(--bc-text);
	font-size: 13px;
}

.buho-compare-bar__note[hidden] {
	display: none;
}

.buho-compare-bar__actions {
	display: flex;
	grid-area: actions;
	align-items: center;
	gap: 4px 12px;
}

.buho-compare-bar__clear {
	min-height: 44px;
	padding: 0 6px;
	border: 0;
	background: transparent;
	color: var(--bc-navy);
	font-family: inherit;
	font-size: 14px;
	text-decoration: underline;
	text-underline-offset: 3px;
	cursor: pointer;
}

/* Folded on a phone: one line (title, count, unfold, Compare). */
.buho-compare-bar.is-collapsed .buho-compare-bar__clear {
	display: none;
}

.buho-compare-bar__go {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 18px;
	border: 1px solid var(--bc-fill);
	background: var(--bc-fill);
	color: var(--bc-on-fill);
	font-size: 15px;
	font-weight: 600;
	text-decoration: none;
	white-space: nowrap;
}

.buho-compare-bar__go:hover {
	border-color: var(--bc-fill-hover);
	background: var(--bc-fill-hover);
	color: var(--bc-on-fill);
}

/* Fewer than two: not a link yet (no href; the note says why). */
.buho-compare-bar__go[aria-disabled="true"] {
	border-color: var(--bc-field);
	background: transparent;
	color: var(--bc-muted);
	cursor: not-allowed;
}

@media (min-width: 600px) {
	.buho-compare-bar {
		padding-top: 10px;
		padding-bottom: calc(10px + env(safe-area-inset-bottom));
	}

	.buho-compare-bar__inner {
		grid-template-areas: "head body actions";
		grid-template-columns: auto minmax(0, 1fr) auto;
		gap: 8px 20px;
	}

	.buho-compare-bar__title {
		flex-direction: column;
		gap: 2px;
	}

	/* Always open from 600 px. */
	.buho-compare-bar__expand {
		display: none;
	}

	.buho-compare-bar__body[hidden] {
		display: block;
	}

	.buho-compare-bar.is-collapsed .buho-compare-bar__clear {
		display: inline;
	}

	.buho-compare-bar__items {
		grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	}

	.buho-compare-bar__item {
		gap: 10px;
		min-height: 50px;
	}

	.buho-compare-bar__thumb {
		width: 40px;
		height: 40px;
	}

	.buho-compare-bar__name {
		display: block;
		font-size: 14px;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.buho-compare-bar__remove {
		width: 36px;
		height: 36px;
	}

	.buho-compare-bar__note {
		margin-top: 4px;
	}
}

@media (min-width: 1024px) {
	.buho-compare-bar__items {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.buho-compare-bar__item--empty {
		display: flex;
	}
}

/* ------------------------------------------------------------ compare page */

.buho-compare {
	--bc-label: 104px; /* Row labels (sticky first column). */
	--bc-pad: 8px 10px; /* Cell padding. */
	--bc-visible: 1; /* Product columns visible at once; the rest scroll. */
	--bc-n: 1;
	color: var(--bc-ink);
	font-family: var(--bc-brand);
	line-height: 1.45;
}

.buho-compare--n2 {
	--bc-n: 2;
	--bc-visible: 2;
}

.buho-compare--n3 {
	--bc-n: 3;
	--bc-visible: 2;
}

.buho-compare--n4 {
	--bc-n: 4;
	--bc-visible: 2;
}

.buho-compare [hidden] {
	display: none !important;
}

.buho-compare__head {
	max-width: 47.5rem;
	margin-bottom: 20px;
}

.buho-compare__title {
	margin: 0 0 12px;
	color: var(--bc-navy);
	font-size: clamp(2.125rem, 1.5rem + 2.6vw, 3.5rem);
	font-weight: 600;
	line-height: 1.05;
	text-wrap: balance;
}

.buho-compare__lead {
	margin: 0;
	color: var(--bc-text);
	font-size: 1.0625rem;
}

.buho-compare__notice {
	margin: 0 0 16px;
	padding: 10px 14px;
	border-left: 3px solid var(--bc-navy);
	background: var(--bc-raise);
	color: var(--bc-ink);
	font-size: 15px;
}

.buho-compare__empty {
	max-width: 47.5rem;
	padding: 28px 24px;
	border: 1px solid var(--bc-line);
	background: var(--bc-surface);
}

.buho-compare__empty p {
	margin: 0 0 12px;
	color: var(--bc-text);
}

.buho-compare__empty p:last-child {
	margin: 20px 0 0;
}

.buho-compare__empty-title {
	color: var(--bc-ink) !important;
	font-size: 1.25rem;
	font-weight: 600;
}

.buho-compare__tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 24px;
	margin: 0 0 12px;
}

.buho-compare__hint {
	margin: 0;
	color: var(--bc-text);
}

.buho-compare__links {
	display: flex;
	flex-wrap: wrap;
	gap: 0 20px;
	margin: 0;
}

.buho-compare__links a {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	color: var(--bc-navy);
}

/* "Show differences only": a square switch (the native checkbox, role="switch"). */
.buho-compare__switch {
	display: inline-flex;
	align-items: center;
	gap: 12px;
	min-height: 44px;
	cursor: pointer;
}

.buho-compare__switch-input {
	position: relative;
	flex: none;
	width: 44px;
	height: 24px;
	margin: 0;
	border: 1px solid var(--bc-field);
	border-radius: 0;
	background: var(--bc-surface);
	cursor: pointer;
	appearance: none;
	-webkit-appearance: none;
}

.buho-compare__switch-input::before {
	position: absolute;
	top: 3px;
	left: 3px;
	width: 16px;
	height: 16px;
	background: var(--bc-field);
	content: "";
	transition: transform 0.15s ease;
}

.buho-compare__switch-input:checked {
	border-color: var(--bc-fill);
	background: var(--bc-fill);
}

.buho-compare__switch-input:checked::before {
	background: var(--bc-on-fill);
	transform: translateX(20px);
}

.buho-compare__same {
	margin: 0 0 12px;
	color: var(--bc-text);
}

/* The table scrolls inside its own box (both sticky edges work there); from 1024 px every column
   fits, the box no longer scrolls and the header row sticks to the window instead. */
.buho-compare__scroll {
	/* Positioned, so absolutely placed descendants (screen-reader text) stay inside the scrolled
	   box instead of widening the page. */
	position: relative;
	max-height: calc(100vh - 16px);
	max-height: calc(100svh - 16px);
	overflow: auto;
	overscroll-behavior-x: contain;
	border: 1px solid var(--bc-line);
	background: var(--bc-surface);
	container-type: inline-size;
}

.buho-compare__table {
	/* A product column: what is left beside the labels, shared by the visible columns. */
	--bc-col: calc((100vw - 2 * var(--buho-gutter, 20px) - 2px - var(--bc-label)) / var(--bc-visible));
	width: calc(var(--bc-label) + var(--bc-n) * var(--bc-col));
	margin: 0;
	border-collapse: separate;
	border-spacing: 0;
	table-layout: fixed;
	font-size: 14px;
}

/* The scroll box's own width where container units exist (a custom property is never invalid at
   parse time, so the fallback above cannot be a second declaration in the same rule). */
@supports (width: 1cqi) {
	.buho-compare__table {
		--bc-col: calc((100cqi - var(--bc-label)) / var(--bc-visible));
	}
}

.buho-compare__table th,
.buho-compare__table td {
	width: var(--bc-col);
	padding: var(--bc-pad);
	border-bottom: 1px solid var(--bc-line-soft);
	background: var(--bc-surface);
	font-weight: 400;
	text-align: left;
	vertical-align: top;
	overflow-wrap: anywhere;
}

.buho-compare__table td + td,
.buho-compare__table th + td,
.buho-compare__table thead th + th,
.buho-compare__table thead td + th {
	border-left: 1px solid var(--bc-line-soft);
}

/* Row labels: the sticky first column. */
.buho-compare__table th[scope="row"],
.buho-compare__table .buho-compare__corner {
	position: sticky;
	left: 0;
	z-index: 1;
	width: var(--bc-label);
	border-right: 1px solid var(--bc-line);
	color: var(--bc-text);
	font-size: 13px;
}

/* Product names: the sticky header row. */
.buho-compare__table thead th,
.buho-compare__table thead td {
	position: sticky;
	top: 0;
	z-index: 2;
	border-bottom: 1px solid var(--bc-line);
	vertical-align: bottom;
}

.buho-compare__table thead .buho-compare__corner {
	z-index: 3;
	color: var(--bc-muted);
	font-family: var(--bc-code);
	font-size: 12px;
}

.buho-compare__name {
	display: block;
	color: var(--bc-navy);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
}

.buho-compare__name:hover {
	text-decoration: underline;
}

.buho-compare__remove {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	min-height: 28px;
	margin-top: 4px;
	color: var(--bc-text);
	font-size: 13px;
	text-decoration: none;
}

.buho-compare__remove:hover {
	color: var(--bc-navy);
	text-decoration: underline;
}

/* Photos: the card's rules (whole datasheet photos on the photo panel, never upscaled). */
.buho-compare__photo-row td {
	padding: 8px;
}

.buho-compare__media {
	display: grid;
	grid-template: minmax(0, 1fr) / minmax(0, 1fr);
	place-items: center;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	border: 1px solid var(--bc-line-soft);
	background: var(--bc-photo);
}

.buho-compare__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	filter: var(--bc-photo-filter);
}

.buho-compare__img.buho-photo {
	max-width: min(100%, var(--buho-photo-w, 100%));
	max-height: min(100%, var(--buho-photo-h, 100%));
	margin: auto;
	object-fit: contain;
}

.buho-compare__media .buho-placeholder-media {
	width: 100%;
	height: 100%;
	border: 0;
}

/* Section headings: a full-width band, its words held at the left while the table scrolls. */
.buho-compare__group th {
	padding-top: 18px;
	padding-bottom: 8px;
	border-bottom-color: var(--bc-line);
	background: var(--bc-raise);
}

.buho-compare__group-label {
	position: sticky;
	left: 12px;
	color: var(--bc-muted);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

/* Technical values (codes, units, IP…): the code font. */
.buho-compare__value--tech {
	font-family: var(--bc-code);
	font-size: 14px;
}

.buho-compare__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.buho-compare__list li + li {
	margin-top: 2px;
}

.buho-compare__none,
.buho-compare__muted {
	color: var(--bc-muted);
}

.buho-compare__datasheet,
.buho-compare__choose {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 44px;
	color: var(--bc-navy);
	font-size: 14px;
}

.buho-compare__quote-row td {
	font-size: 14px;
}

/* buho-quote-list's "Add to quote" (families without codes): compact; the optional note can be
   added on the quote list page. */
.buho-compare__quote .buho-field:has(> textarea) {
	display: none;
}

.buho-compare__quote .buho-add-to-quote {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 8px;
}

.buho-compare__quote .buho-add-to-quote__hint {
	margin: 0;
	color: var(--bc-text);
	font-size: 13px;
}

.buho-compare__quote .buho-field {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0;
	font-size: 13px;
	font-weight: 600;
}

.buho-compare__quote .buho-field select,
.buho-compare__quote .buho-field input {
	width: 100%;
	max-width: 12rem;
	min-height: 44px;
	padding: 0 10px;
	border: 1px solid var(--bc-field);
	border-radius: 0;
	background: var(--bc-surface);
	color: var(--bc-ink);
	font: inherit;
	font-size: 15px;
	font-weight: 400;
}

.buho-compare__quote .buho-field input {
	max-width: 7rem;
	font-family: var(--bc-code);
}

.buho-compare__quote .buho-add-to-quote__button {
	justify-self: start;
	min-height: 44px;
	padding: 0 18px;
	border: 1px solid var(--bc-fill);
	border-radius: 0;
	background: var(--bc-fill);
	color: var(--bc-on-fill);
	font: inherit;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
}

.buho-compare__quote .buho-add-to-quote__button:hover {
	border-color: var(--bc-fill-hover);
	background: var(--bc-fill-hover);
}

.buho-compare__quote .buho-add-to-quote__status {
	margin: 0;
	font-size: 14px;
}

.buho-compare__quote .buho-add-to-quote__status:empty {
	display: none;
}

/* "Show differences only": rows (and whole sections) where every family has the same value. */
.buho-compare.is-diff [data-same] {
	display: none;
}

@media (min-width: 600px) {
	.buho-compare {
		--bc-label: 150px;
		--bc-pad: 10px 12px;
	}

	.buho-compare--n1,
	.buho-compare--n2 {
		--bc-visible: 2;
	}

	.buho-compare--n3,
	.buho-compare--n4 {
		--bc-visible: 3;
	}

	.buho-compare__table {
		font-size: 15px;
	}

	.buho-compare__table th[scope="row"] {
		font-size: 14px;
	}

	.buho-compare__name {
		font-size: 17px;
	}
}

@media (min-width: 1024px) {
	.buho-compare {
		--bc-label: 190px;
	}

	.buho-compare--n1 {
		--bc-visible: 2;
	}

	.buho-compare--n4 {
		--bc-visible: 4;
	}

	.buho-compare__scroll {
		max-height: none;
		overflow: visible;
	}
}

@media (prefers-reduced-motion: reduce) {
	.buho-compare-bar {
		animation: none;
	}

	.buho-compare-bar__expand svg,
	.buho-compare__switch-input::before {
		transition: none;
	}
}

/* @buho-dark:explicit:start (buho-compare) — dark chosen in the switch. Keep identical to the system block. */
:where(:root[data-theme="dark"]) .buho-compare,
:where(:root[data-theme="dark"]) .buho-compare-bar {
	--bc-shadow: 0 -6px 18px rgba(0, 0, 0, 0.45);
}
/* @buho-dark:explicit:end */

/* @buho-dark:system:start (buho-compare) — "System" with a dark system setting (also without JavaScript). */
@media (prefers-color-scheme: dark) {
	:where(:root:not([data-theme="light"])) .buho-compare,
	:where(:root:not([data-theme="light"])) .buho-compare-bar {
		--bc-shadow: 0 -6px 18px rgba(0, 0, 0, 0.45);
	}
}
/* @buho-dark:system:end */
