/*
 * Page-layout styles for bsm-main layouts.
 *
 * Three variants:
 *   .bsm-main--wide    : full-width (home, /test-wide/, service maps)
 *   .bsm-main--section : grid 280px sidebar + 1fr content
 *   .bsm-main--detail  : grid 280px sidebar + 1fr content + sticky subnav
 *
 * Page templates use the matching <main> wrapper class; inside they
 * use .bsm-section-layout / .bsm-detail-layout for the grid container.
 *
 * Source: ../files/10_Projects/bsm_company/05_Brand/wp-page-templates.md
 *         sections 4.2-4.4
 */

.bsm-main {
	padding-bottom: 64px;
}

.bsm-main--wide {
	padding: 0 32px 32px;
}

/* Контент wide-страницы ограничен по ширине контейнера (1320px) и
 * центрирован. Без этого блоки растягиваются до границ окна на больших
 * мониторах. Раздел/detail уже имеют max-width в .bsm-section-layout
 * и .bsm-detail-layout — wide был без него.
 *
 * Если блок хочет быть full-width (например, hero с фоном), используй
 * align="full" в Inspector — блок вылезет за max-width через
 * .alignfull (см. ниже). */
.bsm-main--wide > .bsm-page > .bsm-page-content {
	max-width: var(--container-max);
	margin-left: auto;
	margin-right: auto;
}

/* Full-width блоки внутри wide-страницы — выходят за max-width контейнера. */
.bsm-main--wide > .bsm-page > .bsm-page-content > .alignfull,
.bsm-main--wide > .bsm-page > .bsm-page-content > [data-align="full"] {
	max-width: none;
	margin-left: calc(50% - 50vw);
	margin-right: calc(50% - 50vw);
}

/* Wide-aligned блоки (1320px+) — растягиваются на контейнер + 50px с каждой стороны. */
.bsm-main--wide > .bsm-page > .bsm-page-content > .alignwide,
.bsm-main--wide > .bsm-page > .bsm-page-content > [data-align="wide"] {
	max-width: var(--container-max);
	margin-left: calc(50% - min(50vw, var(--container-max) / 2));
	margin-right: calc(50% - min(50vw, var(--container-max) / 2));
}

/* ---- Block spacing: типовое расстояние между блоками ----
 *
 * Любой следующий блок внутри .bsm-page-content получает margin-top.
 * Это покрывает:
 *   - bsm-* блоки (cards, feature-list, page-hero, cta, и т.д.)
 *   - стандартные WP-блоки (paragraph, heading, image, list, table, ...)
 *   - любые будущие блоки
 *
 * Источник: files/10_Projects/bsm_company/05_Brand/design/04-library.html
 *   .content-block h2 margin-top: 56px (~ var(--space-12) + чуть-чуть)
 *   и явная «воздушность» между секциями в 04-library.
 *
 * Первый блок — без верхнего отступа (иначе лишний пробел перед первым).
 *
 * Override: любой блок может переопределить margin-top в Inspector
 * (supports.spacing.margin уже включён в каждом bsm-блоке).
 */
.bsm-page-content > * + * {
	margin-top: var(--space-12);   /* 48px */
}

.bsm-page-content > *:first-child {
	margin-top: 0;
}

.bsm-main--section > .bsm-section-layout,
.bsm-main--detail > .bsm-detail-layout {
	max-width: var(--container-max);
	margin: 0 auto;
	padding: 16px 32px 0;
	display: grid;
	grid-template-columns: 280px 1fr;
	gap: 32px;
	align-items: start;
}

/* Если в layout нет <aside class="bsm-sidebar"> (явный override через
 * метабокс «Боковое меню — Не показывать»), grid схлопывается в одну колонку.
 * Поддержка :has() — Chrome 105+, Firefox 121+, Safari 15.4+. */
.bsm-main--section > .bsm-section-layout:not(:has(> .bsm-sidebar)),
.bsm-main--detail > .bsm-detail-layout:not(:has(> .bsm-sidebar)) {
	grid-template-columns: 1fr;
}

/* Sidebar column — НЕ стики: в макете (01-detail.html) sidebar скроллится
 * вместе с контентом. Стики только subnav под topnav — чтобы не было
 * конфликта позиций. */
.bsm-main--section > .bsm-section-layout > .bsm-sidebar,
.bsm-main--detail > .bsm-detail-layout > .bsm-sidebar {
	align-self: start;
	margin-top: 12px;
}

/* Content column */
.bsm-main--section > .bsm-section-layout > .bsm-page,
.bsm-main--detail > .bsm-detail-layout > .bsm-page {
	min-width: 0;
	padding-top: 12px;
}

/* ---- Page-hero slot (when bsm/page-hero is the first block) ---- */

/*
 * Если на странице section/detail первый блок — bsm/page-hero, шаблон
 * выводит его в <div class="bsm-page-hero-slot"> ДО .bsm-section-layout.
 * Внешние отступы не нужны — page-hero сам имеет padding-bottom: 20px
 * (см. blocks/page-hero/style.css), а layout-grid имеет padding-top: 20px.
 * Это даёт симметричный минимальный промежуток вокруг subnav.
 */
.bsm-page-hero-slot {
	margin-bottom: 0;
}

/* ---- Responsive: stack sidebar above content ---- */

@media (max-width: 900px) {
	.bsm-main {
		padding-top: 24px;
		padding-bottom: 48px;
	}

	.bsm-main--wide {
		padding-left: 16px;
		padding-right: 16px;
	}

	.bsm-main--section > .bsm-section-layout,
	.bsm-main--detail > .bsm-detail-layout {
		grid-template-columns: 1fr;
		gap: 16px;
		padding: 0 16px;
	}

	.bsm-main--section > .bsm-section-layout > .bsm-sidebar,
	.bsm-main--detail > .bsm-detail-layout > .bsm-sidebar {
		position: static;
		top: auto;
	}
}
