/* WHY: липкое якорное меню (.page-anchors) нового шаблона с подсветкой пункта текущего блока — ассет шаблона
 * вне сборки Astro (dist), как css/mobile-cta.css. Поведение (подсветка, клики, .is-stuck, .is-passed, края
 * подложки, затухание строки, стрелки) — js/page-anchors.js. Липнет обёртка меню: её родитель — содержимое
 * страницы (услуги, «О нас», акция, анализы). На клинике, «клинике ?get=», у врача и в корне анализов обёртка
 * лежит в отдельном .container прямо в body, той же высоты, что и меню, — липкой обёртке там некуда ехать,
 * поэтому липнет контейнер.
 * Прилипшее меню — белая панель-вкладки на всю ширину окна, на мобильном одна поверхность с шапкой: текущий
 * пункт — тёмный текст и полоса снизу (не только цвет: фиолетовый 14px на белом — 4,4:1, ниже нормы 4,5:1).
 * TODO(frontend, при следующей пересборке dist): перенести в SCSS medcenter (PageAnchors.scss).
 */
.page-anchors-wrapper,
body > .container:has(> .page-anchors-wrapper) {
	position: sticky;
	top: 0;
	transition: opacity 0.2s ease, visibility 0s linear 0s;
}

/* WHY 200: выше активной вкладки [data-tabs] и кнопки «Разделы» (100) и нижней плашки (101),
 * ниже шапки (500), бургера (510), поиска (600), cookie-баннера (700) и попапов. Только у прилипшего:
 * в обычном положении меню лежит в потоке, и слой 200 закрывал всё, что раскрывается над ним из блоков
 * выше: выпадающие списки шапки на десктопе («Услуги», z-index 12), подсказки поиска (10), тултип цен
 * в карточке врача (20, открывается вниз). */
.page-anchors-wrapper.is-stuck,
body > .container.is-stuck {
	z-index: 200;
}

/* WHY relative: контейнер стрелок, когда липнет контейнер; top от правила выше здесь сдвинул бы меню */
body > .container > .page-anchors-wrapper {
	position: relative;
	top: auto;
}

.page-anchors-wrapper:not(:has(li)) {
	display: none;
}

/* WHY: подложка прилипшей панели — псевдоэлемент от края до края окна. Края считает скрипт по clientWidth:
 * 100vw включает полосу прокрутки и дал бы горизонтальный скролл страницы. */
.page-anchors-wrapper::before,
body > .container:has(> .page-anchors-wrapper)::before {
	content: "";
	position: absolute;
	top: 0;
	right: calc(-1 * var(--page-anchors-bleed-right, 0px));
	bottom: 0;
	left: calc(-1 * var(--page-anchors-bleed-left, 0px));
	z-index: -1;
	background: #fff;
	box-shadow: 0 1px 0 rgba(18, 6, 30, 0.08), 0 10px 18px -6px rgba(55, 38, 72, 0.1);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

body > .container > .page-anchors-wrapper::before {
	content: none;
}

.page-anchors-wrapper.is-stuck::before,
body > .container.is-stuck::before {
	opacity: 1;
}

.page-anchors-wrapper .page-anchors {
	transition: background-color 0.2s ease;
}

/* WHY: прилипшее меню — одна строка с прокруткой (на десктопе многострочное заняло бы пол-экрана); разницу
 * высот js/page-anchors.js возвращает нижним отступом. Поля ссылок (4px) и строки (12px) с интервалом 16px
 * держат текст пунктов там же, где в карточке (поле 16px, интервал 24px), а высота ссылки — 48px, как у
 * карточки: при прилипании меняется только фон, ничего не сдвигается. */
.is-stuck .page-anchors {
	flex-wrap: nowrap;
	align-items: stretch;
	gap: 16px;
	padding: 0 12px;
	border-radius: 0;
	background-color: transparent;
	overflow-x: auto;
	scrollbar-width: none;
}

.is-stuck .page-anchors li {
	display: flex;
}

.is-stuck .page-anchors li a {
	position: relative;
	display: flex;
	align-items: center;
	min-height: 48px;
	padding: 0 4px;
}

/* WHY outline внутрь: строка с overflow-x обрезает внешнюю рамку фокуса */
.is-stuck .page-anchors li a:focus-visible {
	outline: 2px solid #7765e3;
	outline-offset: -2px;
	border-radius: 6px;
}

.page-anchors li a.is-active {
	color: #7765e3;
}

.is-stuck .page-anchors li a.is-active {
	color: #372648;
}

.is-stuck .page-anchors li a.is-active::after {
	content: "";
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	height: 3px;
	border-radius: 3px 3px 0 0;
	background: #7765e3;
}

/* WHY: затухание края — подсказка, что строку можно прокрутить; классы ставит скрипт по положению прокрутки */
.is-stuck .page-anchors.is-fade-start {
	-webkit-mask-image: linear-gradient(90deg, transparent, #000 48px);
	mask-image: linear-gradient(90deg, transparent, #000 48px);
}

.is-stuck .page-anchors.is-fade-end {
	-webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent);
	mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent);
}

.is-stuck .page-anchors.is-fade-start.is-fade-end {
	-webkit-mask-image: linear-gradient(90deg, transparent, #000 48px, #000 calc(100% - 48px), transparent);
	mask-image: linear-gradient(90deg, transparent, #000 48px, #000 calc(100% - 48px), transparent);
}

/* WHY: стрелки листают длинную строку мышью; кнопки создаёт скрипт, у края строки ставит им hidden */
.page-anchors-wrapper__arrow {
	display: none;
}

.page-anchors-wrapper.is-passed,
body > .container.is-passed {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

@media screen and (max-width: 1023px) {
	/* WHY 70px: под фиксированной .header__top (12 + 46 + 12), которую строит BuildHeader на этой ширине */
	.page-anchors-wrapper,
	body > .container:has(> .page-anchors-wrapper) {
		top: 70px;
	}

	/* WHY: строка до краёв окна — пункты уходят за край экрана, как у прокручиваемых вкладок; поля
	 * компенсируют отступы обёртки, текст остаётся на месте */
	.is-stuck .page-anchors {
		margin: 0 calc(-1 * var(--page-anchors-edge-right, 16px)) 0 calc(-1 * var(--page-anchors-edge-left, 16px));
		padding: 0 calc(var(--page-anchors-edge-right, 16px) + 12px) 0 calc(var(--page-anchors-edge-left, 16px) + 12px);
	}

	/* WHY: шапка и прилипшее меню — одна панель, тень остаётся только под меню (у шапки она от .scrolling-*) */
	body:has(.page-anchors-wrapper.is-stuck:not(.is-passed)) .header__top,
	body:has(> .container.is-stuck:not(.is-passed)) .header__top {
		border-bottom-color: transparent;
		box-shadow: none;
	}
}

@media screen and (min-width: 1024px) {
	.is-stuck .page-anchors-wrapper__arrow:not([hidden]) {
		position: absolute;
		top: 50%;
		z-index: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 32px;
		height: 32px;
		padding: 0;
		border: 1px solid rgba(18, 6, 30, 0.1);
		border-radius: 8px;
		background: #fff;
		color: #372648;
		box-shadow: 0 2px 8px rgba(55, 38, 72, 0.08);
		cursor: pointer;
		transform: translateY(-50%);
		transition: border-color 0.2s ease, color 0.2s ease;
	}

	.is-stuck .page-anchors-wrapper__arrow:hover {
		border-color: #7765e3;
		color: #7765e3;
	}

	.is-stuck .page-anchors-wrapper__arrow:focus-visible {
		outline: 2px solid #7765e3;
		outline-offset: 2px;
	}

	.is-stuck .page-anchors-wrapper__arrow--prev {
		left: 0;
	}

	.is-stuck .page-anchors-wrapper__arrow--next {
		right: 0;
	}

	.page-anchors-wrapper__arrow svg {
		width: 16px;
		height: 16px;
	}

	/* WHY 80px: боковое меню разделов липнет на 32px — под прилипшей панелью (48px) его верх был бы закрыт */
	body:has(.page-anchors-wrapper li) .stream-wrapper__aside {
		top: 80px;
		max-height: calc(100vh - 116px);
	}
}
