/**
 * Catalog Hub — scoped chrome (reuses Product Grid filter / Card Core visuals).
 *
 * Active direction pill owns chrome; «Подробнее →» only on the active pill
 * (no reserved empty second line on inactive pills).
 * Desktop sticky under Header. Optional one-row densify via JS class.
 *
 * Radius token: --ital-pg-filter-r (shared with Product Grid / catalog tab preset).
 * BIO/АНТЕЙ reference on autonomous page: filter-radius-small → 6px.
 */

.ital-catalog-hub {
	margin-top: 0.85rem;
	overflow-anchor: none;
	/* Base label size (unstuck). Sticky applies max(11px, base - 2px) once — not stacked. */
	--ital-hub-tab-fs-base: 0.875rem; /* 14px */
	--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
	--ital-hub-tab-pad-x: var(--ital-pg-filter-pad-x, 0.9rem);
	--ital-hub-tab-pad-y: var(--ital-pg-filter-pad-y, 0.45rem);
	--ital-hub-tab-gap: 0.5rem;
	--ital-hub-tab-r: var(--ital-pg-filter-r, 6px);
}

/*
 * First paint (desktop): optimistic mid densify (12px) until JS measures.
 * Avoids visible 14px → 11/12px jump when one orphan would densify.
 * Mobile media query below resets densify tokens; booting is harmless there.
 * If JS fails, booting class stays — tabs remain visible and usable.
 */
@media (min-width: 700px) {
	.ital-catalog-hub.is-tabs-booting {
		--ital-hub-tab-pad-x: 0.48rem;
		--ital-hub-tab-pad-y: 0.34rem;
		--ital-hub-tab-gap: 0.26rem;
		--ital-hub-tab-fs-base: 0.75rem; /* 12px */
		--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
	}
}

.ital-catalog-hub__sticky-sentinel {
	height: 1px;
	margin: 0;
	padding: 0;
	pointer-events: none;
	visibility: hidden;
}

.ital-catalog-hub__sticky {
	position: relative;
	z-index: 30;
	background: var(--ital-catalog-hub-sticky-bg, var(--ital-surface, #ffffff));
}

.ital-catalog-hub .ital-product-grid__filters {
	flex-wrap: wrap;
	align-items: flex-start;
	gap: var(--ital-hub-tab-gap);
	/* Spacing to products lives on the list — keeps sticky panel height = content. */
	margin: 0;
	padding: 0.2rem 0 0.15rem;
}

.ital-catalog-hub [data-ital-hub-list] {
	margin-top: 1rem;
	overflow-anchor: none;
}

.ital-catalog-hub__pill {
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.1rem;
	max-width: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	border: var(--ital-pg-filter-border-w, 1px) solid var(--ital-pg-filter-border, var(--ital-pg-line, rgba(0, 0, 0, 0.12)));
	border-radius: var(--ital-hub-tab-r);
	background: var(--ital-pg-filter-bg, #ffffff);
	color: var(--ital-pg-filter-text, var(--ital-pg-ink, #1a1a1a));
	transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
	overflow: hidden; /* active + «Подробнее» read as one rounded shape */
}

.ital-catalog-hub__pill:hover {
	border-color: var(--ital-pg-filter-hover-border, rgba(42, 74, 58, 0.35));
	background: var(--ital-pg-filter-hover-bg, var(--ital-pg-filter-bg, #ffffff));
	color: var(--ital-pg-filter-hover-text, var(--ital-pg-filter-text, var(--ital-pg-ink, #1a1a1a)));
}

.ital-catalog-hub__pill .ital-product-grid__filter {
	margin: 0;
	padding: var(--ital-hub-tab-pad-y) var(--ital-hub-tab-pad-x);
	border: 0 !important;
	border-radius: 0;
	background: transparent !important;
	box-shadow: none !important;
	color: inherit;
	font-size: var(--ital-hub-tab-fs);
	font-weight: 550;
	line-height: 1.2;
	transform: none !important;
	text-align: center;
	width: 100%;
	justify-content: center;
	white-space: nowrap;
	outline: none;
}

.ital-catalog-hub__pill .ital-product-grid__filter:hover,
.ital-catalog-hub__pill .ital-product-grid__filter:focus,
.ital-catalog-hub__pill .ital-product-grid__filter:focus-visible,
.ital-catalog-hub__pill .ital-product-grid__filter:active {
	background: transparent !important;
	border-color: transparent !important;
	color: inherit;
	transform: none !important;
	outline: none;
	box-shadow: none !important;
}

/* Keyboard focus on the rounded pill shell (not a rectangular inner button outline). */
.ital-catalog-hub__pill:focus-within:has(.ital-product-grid__filter:focus-visible) {
	outline: 2px solid var(--ital-pg-accent, #2a4a3a);
	outline-offset: 2px;
}

.ital-catalog-hub__pill.is-active {
	background: var(--ital-pg-filter-active-bg, var(--ital-pg-accent, #2a4a3a));
	border-color: var(--ital-pg-filter-active-border, var(--ital-pg-filter-active-bg, var(--ital-pg-accent, #2a4a3a)));
	color: var(--ital-pg-filter-active-text, #ffffff);
}

.ital-catalog-hub__pill.is-active.ital-catalog-hub__pill--has-more {
	padding-bottom: 0.18rem;
}

/* Inactive: no second-line reservation. Active only reveals the link. */
.ital-catalog-hub__pill-more {
	display: none;
	align-items: center;
	justify-content: center;
	align-self: center;
	font-size: 11px;
	font-weight: 500;
	line-height: 1.15;
	color: rgba(255, 255, 255, 0.82);
	text-decoration: none;
	padding: 0 0.65rem 0.02rem;
	white-space: nowrap;
	text-align: center;
	border-radius: 0;
}

.ital-catalog-hub__pill.is-active.ital-catalog-hub__pill--has-more .ital-catalog-hub__pill-more {
	display: inline-flex;
}

.ital-catalog-hub__pill-more:hover {
	color: #ffffff;
	text-decoration: underline;
	text-underline-offset: 0.12em;
}

.ital-catalog-hub__pill-more:focus {
	outline: none;
}

.ital-catalog-hub__pill-more:focus-visible {
	color: #ffffff;
	outline: 2px solid currentColor;
	outline-offset: 2px;
	border-radius: 4px;
}

/* Measure natural geometry without tearing down dense paint mid-frame. */
.ital-catalog-hub.is-measuring-natural {
	--ital-hub-tab-pad-x: var(--ital-pg-filter-pad-x, 0.9rem);
	--ital-hub-tab-pad-y: var(--ital-pg-filter-pad-y, 0.45rem);
	--ital-hub-tab-gap: 0.5rem;
	--ital-hub-tab-fs-base: 0.875rem;
	--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
}

/*
 * One orphan wrap → densify steps (JS picks largest that fits):
 * level 1: pad/gap @14px; level 2: labels 12px; level 3: labels 11px floor.
 */
.ital-catalog-hub.is-tab-dense {
	--ital-hub-tab-pad-x: 0.55rem;
	--ital-hub-tab-pad-y: 0.34rem;
	--ital-hub-tab-gap: 0.3rem;
	--ital-hub-tab-fs-base: 0.875rem; /* 14px */
	--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
}

.ital-catalog-hub.is-tab-dense.is-tab-dense--12 {
	--ital-hub-tab-pad-x: 0.48rem;
	--ital-hub-tab-gap: 0.26rem;
	--ital-hub-tab-fs-base: 0.75rem; /* 12px */
	--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
}

.ital-catalog-hub.is-tab-dense.is-tab-dense--11 {
	--ital-hub-tab-pad-x: 0.42rem;
	--ital-hub-tab-gap: 0.22rem;
	--ital-hub-tab-fs-base: 0.6875rem; /* 11px densify floor */
	--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
}

@media (min-width: 700px) {
	.ital-catalog-hub__sticky--desktop-on {
		position: sticky;
		top: var(--sp-header-h, 70px);
		z-index: 10050;
		background: var(--ital-catalog-hub-sticky-bg, var(--ital-surface, #ffffff));
		box-shadow: none;
		border-bottom: 1px solid transparent;
		margin-left: -0.25rem;
		margin-right: -0.25rem;
		padding: 0.1rem 0.25rem 0.05rem;
	}

	.admin-bar .ital-catalog-hub__sticky--desktop-on {
		top: calc(var(--sp-header-h, 70px) + var(--sp-admin-bar-visible, 32px));
	}

	/*
	 * Sticky label −2px from current densify/base size.
	 * Floor 11px (aligned with densify minimum). «Подробнее →» stays 11px.
	 * Does not change densify class / pad / gap (avoids wrap flip loops).
	 */
	.ital-catalog-hub__sticky--desktop-on.is-stuck .ital-catalog-hub__pill .ital-product-grid__filter {
		font-size: max(11px, calc(var(--ital-hub-tab-fs-base) - 2px));
	}

	.ital-catalog-hub__sticky--desktop-on.is-stuck {
		box-shadow: 0 8px 18px rgba(0, 0, 0, 0.06);
		border-bottom-color: rgba(0, 0, 0, 0.06);
		padding-top: 0.08rem;
		padding-bottom: 0.02rem;
	}

	.ital-catalog-hub__sticky--desktop-on.is-stuck .ital-product-grid__filters {
		padding-top: 0.12rem;
		padding-bottom: 0.08rem;
	}

	.ital-catalog-hub__sticky--desktop-off,
	.ital-catalog-hub__sticky--disabled {
		position: relative;
		box-shadow: none !important;
		border-bottom: 0 !important;
	}
}

@media screen and (max-width: 782px) {
	/* Fallback before JS measures visible admin-bar height; variable drives sticky top. */
	body.admin-bar {
		--sp-admin-bar-visible: 46px;
	}
}

@media (max-width: 699px) {
	.ital-catalog-hub__sticky--mobile-on {
		position: sticky;
		top: var(--sp-header-h, 56px);
		z-index: 10050;
		background: var(--ital-catalog-hub-sticky-bg, var(--ital-surface, #ffffff));
		padding: 0.18rem 0 0.1rem;
	}

	.admin-bar .ital-catalog-hub__sticky--mobile-on {
		top: calc(var(--sp-header-h, 56px) + var(--sp-admin-bar-visible, 46px));
	}

	.ital-catalog-hub__sticky--mobile-on.is-stuck {
		box-shadow: 0 6px 14px rgba(0, 0, 0, 0.07);
		border-bottom: 1px solid rgba(0, 0, 0, 0.06);
	}

	.ital-catalog-hub__sticky--mobile-off,
	.ital-catalog-hub__sticky--disabled {
		position: relative;
		box-shadow: none !important;
		border-bottom: 0 !important;
	}

	.ital-catalog-hub.is-tab-dense,
	.ital-catalog-hub.is-tab-dense--12,
	.ital-catalog-hub.is-tab-dense--11,
	.ital-catalog-hub.is-measuring-natural {
		--ital-hub-tab-pad-x: 0.72rem;
		--ital-hub-tab-pad-y: 0.32rem;
		--ital-hub-tab-gap: 0.35rem;
		--ital-hub-tab-fs-base: 0.8125rem;
		--ital-hub-tab-fs: var(--ital-hub-tab-fs-base);
	}

	.ital-catalog-hub .ital-product-grid__filters,
	.ital-catalog-hub__filters {
		flex-wrap: nowrap;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: thin;
		padding-bottom: 0.15rem;
		max-width: 100%;
		gap: 0.35rem;
	}

	.ital-catalog-hub__inner,
	.ital-catalog-hub__sticky {
		max-width: 100%;
		min-width: 0;
	}

	.ital-catalog-hub__pill {
		flex: 0 0 auto;
	}

	.ital-catalog-hub .ital-product-grid__filter,
	.ital-catalog-hub__pill .ital-product-grid__filter {
		flex: 0 0 auto;
		white-space: nowrap;
		padding: 0.32rem 0.72rem;
		font-size: 0.8125rem;
		font-weight: 500;
		letter-spacing: 0;
		line-height: 1.2;
		min-height: 2.25rem;
	}

	.ital-catalog-hub__pill.is-active .ital-product-grid__filter {
		font-weight: 600;
	}
}

/* Fallback when :has() is unavailable — soft focus ring via box-shadow on pill. */
@supports not selector(:has(*)) {
	.ital-catalog-hub__pill .ital-product-grid__filter:focus-visible {
		box-shadow: inset 0 0 0 2px var(--ital-pg-accent, #2a4a3a) !important;
	}
}
