/**
 * Блок «текст + медиа» (.stomarus-text-media)
 * ≥769px: медиа в float — текст .stomarus-prose обтекает сбоку, затем продолжается снизу.
 * <769px: колонка — текст сверху, медиа снизу (DOM: медиа первым, визуальный порядок через flex order).
 */

.stomarus-text-media {
	display: flex;
	flex-direction: column;
	flex-wrap: nowrap;
	align-items: stretch;
	justify-content: flex-start;
	gap: clamp(16px, 3vw, 24px);
	/*margin-bottom: 6px;*/
	margin-bottom: 0px;
}

.stomarus-text-media:has(.stomarus-text-media__embed--vertical) {
	overflow: visible;
}

.stomarus-text-media__body {
	order: 1;
	width: 100%;
	min-width: 0;
}

.stomarus-text-media__body h2 {
	margin-top: 0;
}

/* Первый блок контента — без отступа сверху у текста рядом с медиа */
.stomarus-text-media__body > :first-child {
	margin-top: 0;
	margin-block-start: 0;
	padding-top: 0;
	padding-block-start: 0;
}

.stomarus-text-media__body > .wp-block-group:first-child > :first-child,
.stomarus-text-media__body > .wp-block-group:first-child > .wp-block-group__inner-container > :first-child {
	margin-top: 0;
	margin-block-start: 0;
	padding-top: 0;
	padding-block-start: 0;
}

.stomarus-text-media__media {
	order: 2;
	width: 100%;
	position: relative;
	overflow: hidden;
	box-sizing: border-box;
	height: auto;
	min-height: 200px;
	max-height: none;
}

/* Вертикальное YouTube: не обрезаем плеер (см. десктоп overflow у колонки). */
.stomarus-text-media__media:has(.stomarus-text-media__embed--vertical) {
	overflow: visible;
	min-height: 0;
}

.stomarus-text-media__figure {
	margin: 0;
	width: 100%;
	height: auto;
	min-height: 180px;
	max-height: 70vw;
}

.stomarus-text-media__figure img {
	width: 100%;
	height: auto;
	max-height: 70vw;
	object-fit: cover;
	display: block;
}

/* YouTube / iframe — 16:9. Вертикаль (Shorts): .stomarus-text-media__embed--vertical — 9:16. Файл: --file. */
.stomarus-text-media__embed:not(.stomarus-text-media__embed--file):not(.stomarus-text-media__embed--vertical) {
	position: relative;
	width: 100%;
	height: 0;
	padding-bottom: 56.25%;
	min-height: 0;
}

/*
 * Вертикальный YouTube (435×688): тот же приём, что для 16:9 — иначе при float высота в потоке 0
 * (aspect-ratio + height:auto ломались), iframe 688px вылезал на текст. 688/435 ≈ 158.16%.
 */
.stomarus-text-media__embed--vertical:not(.stomarus-text-media__embed--file) {
	position: relative;
	width: 100%;
	height: 0;
	min-height: 0;
	padding-bottom: 158.16%;
	/* не hidden: иначе при рассинхроне с intrinsic iframe обрезался низ плеера */
	overflow: visible;
}

.stomarus-text-media__embed:not(.stomarus-text-media__embed--file) iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	border: 0;
	box-sizing: border-box;
}

/* Видеофайл из медиатеки (MP4 и т.д.) — высота по ролику, float обтекает корректно */
.stomarus-text-media__embed--file {
	position: relative;
	width: 100%;
	height: auto;
	min-height: 0;
	padding-bottom: 0;
	overflow: hidden;
}

.stomarus-text-media__embed--file .stomarus-text-media__video {
	width: 100%;
	height: auto;
	display: block;
	max-height: min(70vw, 560px);
}

.stomarus-text-media__below {
	margin-top: clamp(12px, 2vw, 20px);
	width: 100%;
	clear: both;
}

.stomarus-text-media__below iframe {
	max-width: 100%;
	display: block;
}

/* Десктоп: float — обтекание текста */
@media (min-width: 769px) {
	.stomarus-text-media {
		display: flow-root;
		gap: 0;
		align-items: stretch;
	}

	.stomarus-text-media__media {
		float: right;
		order: 0;
		width: auto;
		max-width: min(40vw, 460px);
		margin: 0 0 clamp(16px, 3vw, 24px) clamp(16px, 3vw, 32px);
		min-height: 0;
		/*
		 * Не flex по умолчанию: float + flex + width:auto даёт shrink-to-fit ≈ 0
		 * в части браузеров. Вертикальная колонка «картинка + видео» — .stomarus-text-media__media--stack.
		 */
		display: block;
		overflow: hidden;
	}

	.stomarus-text-media__media:has(.stomarus-text-media__embed--vertical) {
		overflow: visible;
	}

	.stomarus-text-media--reverse-desktop .stomarus-text-media__media {
		float: left;
		margin: 0 clamp(16px, 3vw, 32px) 0 0;
	}

	.stomarus-text-media__body {
		order: 0;
		width: auto;
		min-width: 0;
	}

	/*
	 * В style.css у h1–h6 задано clear: both — из-за этого заголовки уходят под float медиа.
	 * Здесь обтекание должно работать как у обычного текста.
	 */
	.stomarus-text-media__body h1,
	.stomarus-text-media__body h2,
	.stomarus-text-media__body h3,
	.stomarus-text-media__body h4,
	.stomarus-text-media__body h5,
	.stomarus-text-media__body h6,
	.stomarus-text-media__body .wp-block-heading,
	.stomarus-text-media__body .wp-block-list,
	.stomarus-text-media__body ol,
	.stomarus-text-media__body ul {
		clear: none;
	}

	.stomarus-text-media__figure {
		margin: 0;
		width: auto;
		max-width: 100%;
		min-height: 0;
		max-height: 305px;
		display: block;
	}

	.stomarus-text-media__figure img {
		width: auto;
		height: auto;
		max-width: 100%;
		max-height: 305px;
		object-fit: contain;
		display: block;
	}

	.stomarus-text-media__embed:not(.stomarus-text-media__embed--file):not(.stomarus-text-media__embed--vertical) {
		position: relative;
		width: min(100%, 435px);
		height: 0;
		padding-bottom: 56.25%;
		max-width: 100%;
		min-height: 0;
	}

	.stomarus-text-media__embed--vertical:not(.stomarus-text-media__embed--file) {
		width: min(100%, 435px);
		max-width: 100%;
		height: 0;
		padding-bottom: 158.16%;
		min-height: 0;
		overflow: visible;
	}

	.stomarus-text-media__embed:not(.stomarus-text-media__embed--file) iframe {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
		border: 0;
	}

	.stomarus-text-media__embed--file {
		width: min(100%, 435px);
		max-width: 100%;
		height: auto;
		padding-bottom: 0;
	}

	/*
	 * Только YouTube/файл в колонке (без figure): float + width:auto и блок 16:9
	 * с height:0 дают ширину столбца 0 — padding-bottom:% от нуля, iframe не виден.
	 * На мобилке у колонки width:100%, там всё ок.
	 */
	.stomarus-text-media__media:has(> .stomarus-text-media__embed:only-child) {
		min-width: min(40vw, 435px);
		width: min(40vw, 435px);
	}

	/* Картинка + видео в одной колонке — весь столбец в float */
	.stomarus-text-media__media--stack {
		display: flex;
		flex-direction: column;
		height: auto;
		min-height: 0;
		gap: 12px;
		align-items: flex-start;
		width: auto;
		max-width: min(50vw, 560px);
		min-width: min(280px, 100%);
	}

	.stomarus-text-media__media--stack .stomarus-text-media__figure {
		flex-shrink: 0;
		display: flex;
		align-items: center;
		max-height: none;
		height: auto;
		min-height: 0;
		width: auto;
		max-width: 100%;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__figure img {
		max-height: 305px;
		width: auto;
		max-width: 100%;
		height: auto;
		object-fit: contain;
		display: block;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed:not(.stomarus-text-media__embed--file):not(.stomarus-text-media__embed--vertical) {
		flex-shrink: 0;
		position: relative;
		width: min(100%, 435px);
		height: 0;
		padding-bottom: 56.25%;
		max-width: 100%;
		min-height: 0;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed--vertical:not(.stomarus-text-media__embed--file) {
		flex-shrink: 0;
		width: min(100%, 435px);
		max-width: 100%;
		height: 0;
		padding-bottom: 158.16%;
		min-height: 0;
		overflow: visible;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed--file {
		flex-shrink: 0;
		width: min(100%, 435px);
		max-width: 100%;
		height: auto;
		padding-bottom: 0;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed:not(.stomarus-text-media__embed--file) iframe {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
	}

	/* Видео под float-рядом (нижний блок): явная ширина/пропорции на десктопе */
	.stomarus-text-media__below {
		position: relative;
		z-index: 1;
		overflow: visible;
	}

	.stomarus-text-media__below iframe {
		width: min(100%, 435px);
		height: auto;
		aspect-ratio: 16 / 9;
	}
}

/* Вкладки услуг: на десктопе медиа слева (как раньше row-reverse) */
.tabs_services .stomarus-text-media {
	flex-direction: column;
}

@media (min-width: 769px) {
	.tabs_services .stomarus-text-media {
		display: flow-root;
	}

	.tabs_services .stomarus-text-media__media {
		float: left;
		margin: 0 clamp(16px, 3vw, 32px) 0  0;
	}

	.tabs_services .stomarus-text-media--reverse-desktop .stomarus-text-media__media {
		float: right;
		margin: 0 0 clamp(16px, 3vw, 24px) clamp(16px, 3vw, 32px);
	}
}

@media (max-width: 768px) {
	.stomarus-text-media--reverse-desktop {
		flex-direction: column;
	}

	.tabs_services .stomarus-text-media {
		flex-direction: column;
	}

	.tabs_services .stomarus-text-media__media {
		float: none;
		margin: 0;
		width: 100%;
		max-width: none;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__figure {
		height: auto;
		min-height: 0;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed:not(.stomarus-text-media__embed--file):not(.stomarus-text-media__embed--vertical) {
		height: 0;
		padding-bottom: 56.25%;
		width: 100%;
		min-height: 0;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed--vertical:not(.stomarus-text-media__embed--file) {
		width: 100%;
		height: 0;
		padding-bottom: 158.16%;
		min-height: 0;
		overflow: visible;
	}

	.stomarus-text-media__media--stack .stomarus-text-media__embed--file {
		height: auto;
		padding-bottom: 0;
		width: 100%;
	}
}

/* Карточка специалиста: секция не режет float-колонку с вертикальным YouTube */
.single-specialists-main .spec-section:has(.stomarus-text-media__embed--vertical) {
	overflow: visible;
}
