/**
 * Core block layout — theme.json blockGap (32px) inside nested layout containers.
 *
 * Top-level post content (adjacent groups, covers, etc.) has no automatic gap.
 * Wrap longform copy in a Group (layout: default/constrained) so gap applies within.
 *
 * Custom blocks (wp-block-acf-*, wp-block-westeck-*) are excluded.
 */

:root {
	--westeck-layout-block-gap: var(--wp--style--block-gap, 32px);
	--westeck-layout-block-gap-small: var(--wp--preset--spacing--30, 20px);
	--westeck-layout-heading-gap: calc(var(--westeck-layout-block-gap) * 1.618);
	--westeck-layout-block-gap-double: calc(var(--westeck-layout-block-gap) * 2);
}

/* Cancel blockGap on the post content root (WP theme.json may still output it). */
.wp-block-post-content:is(.is-layout-flow, .is-layout-constrained):not(.single-post-body)
	> * + *:not(figure):not(div.wp-caption) {
	margin-block-start: 0;
	margin-block-end: 0;
}

/*
 * Nested flow/constrained layouts only (e.g. Group block wrapping article body).
 * Not .wp-block-post-content itself — so top-level sections stay flush.
 */
.wp-block-post-content
	:is(.is-layout-flow, .is-layout-constrained)
	> * + *:not([class*='wp-block-acf']):not([class*='wp-block-westeck']) {
	margin-block-start: var(--westeck-layout-block-gap);
	margin-block-end: 0;
}

.wp-block-post-content
	:is(.is-layout-flow, .is-layout-constrained)
	> :is(ul.wp-block-list, ol.wp-block-list, .wp-block-list):not(:first-child) {
	margin-block-start: var(--westeck-layout-block-gap);
	margin-block-end: 0;
}

/* Headings — extra top whitespace (block gap × 1.618) */
.wp-block-post-content
	:is(.is-layout-flow, .is-layout-constrained)
	> * + :is(h1, h2, h3, h4, h5, h6):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
.wp-block-post-content
	:is(.is-layout-flow, .is-layout-constrained)
	> * + .wp-block-heading:not([class*='wp-block-acf']):not([class*='wp-block-westeck']) {
	margin-block-start: var(--westeck-layout-heading-gap);
}

/* Editor — nested group/column inner layouts only (not the root canvas). */
.editor-styles-wrapper
	.block-editor-block-list__layout.is-layout-flow:not(.is-root-container)
	> .wp-block:not(:first-child):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
.editor-styles-wrapper
	.wp-block-post-content
	.block-editor-block-list__layout:is(.is-layout-flow, .is-layout-constrained)
	> .wp-block:not(:first-child):not([class*='wp-block-acf']):not([class*='wp-block-westeck']) {
	margin-block-start: var(--westeck-layout-block-gap);
	margin-block-end: 0;
}

.editor-styles-wrapper
	.block-editor-block-list__layout.is-layout-flow:not(.is-root-container)
	> .wp-block-heading:not(:first-child):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
.editor-styles-wrapper
	.wp-block-post-content
	.block-editor-block-list__layout:is(.is-layout-flow, .is-layout-constrained)
	> .wp-block-heading:not(:first-child):not([class*='wp-block-acf']):not([class*='wp-block-westeck']) {
	margin-block-start: var(--westeck-layout-heading-gap);
}

/* Editor root canvas — no automatic gap between top-level sections. */
.editor-styles-wrapper
	.block-editor-block-list__layout.is-root-container:is(.is-layout-flow, .is-layout-constrained)
	> .wp-block {
	margin-block-start: 0;
	margin-block-end: 0;
}

/*
 * Cover inner layouts — h1 headings sit flush (heroes, CTAs, overlays).
 * Overrides blockGap on .wp-block-cover__inner-container under post content.
 */
:is(.wp-block-cover, .wp-block-cover-image)
	.wp-block-cover__inner-container:is(.is-layout-flow, .is-layout-constrained)
	> :is(h1, h1.wp-block-heading, h1.wp-block-post-title),
:is(.wp-block-cover, .wp-block-cover-image)
	:is(.is-layout-flow, .is-layout-constrained)
	> :is(h1, h1.wp-block-heading, h1.wp-block-post-title) {
	margin-block-start: 0 !important;
	margin-top: 0 !important;
	padding-block-start: 0 !important;
	padding-top: 0 !important;
}

.editor-styles-wrapper
	:is(.wp-block-cover, .wp-block-cover-image)
	:is(h1, h1.wp-block-heading, h1.wp-block-post-title) {
	margin-block-start: 0 !important;
	margin-top: 0 !important;
	padding-block-start: 0 !important;
	padding-top: 0 !important;
}

/*
 * Feature Tabs — tab WYSIWYG body (headings, paragraphs, lists).
 * Same blockGap as nested post content; block is excluded from rules above.
 */
.feature-tabs__content > * + * {
	margin-block-start: var(--westeck-layout-block-gap);
	margin-block-end: 0;
}

.feature-tabs__content > * + :is(h1, h2, h3, h4, h5, h6) {
	margin-block-start: var(--westeck-layout-heading-gap);
}

.editor-styles-wrapper .feature-tabs__content > * + * {
	margin-block-start: var(--westeck-layout-block-gap);
	margin-block-end: 0;
}

.editor-styles-wrapper .feature-tabs__content > * + :is(h1, h2, h3, h4, h5, h6) {
	margin-block-start: var(--westeck-layout-heading-gap);
}

/*
 * Single post body — direct block siblings (classic converted to blocks, legacy inline HTML).
 * Same gaps as .wp-block-freeform; excluded from post-content root margin reset above.
 */
body.single-post .wp-block-post-content.single-post-body > * + *:not(figure):not(div.wp-caption):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
body.single-post .entry-content.single-post-body > * + *:not(figure):not(div.wp-caption):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
body.single-post .wp-block-post-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-paragraph, .wp-block-heading)
	+ :is(p, div, ul, ol, blockquote, table, hr, pre, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-paragraph, .wp-block-heading),
body.single-post .entry-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-paragraph, .wp-block-heading)
	+ :is(p, div, ul, ol, blockquote, table, hr, pre, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-paragraph, .wp-block-heading) {
	margin-block-start: var(--westeck-layout-block-gap) !important;
	margin-top: var(--westeck-layout-block-gap) !important;
	margin-block-end: 0 !important;
	margin-bottom: 0 !important;
}

body.single-post .wp-block-post-content.single-post-body > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading),
body.single-post .entry-content.single-post-body > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading),
body.single-post .wp-block-post-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6, .wp-block-paragraph)
	+ :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading),
body.single-post .wp-block-post-content.single-post-body :is(h4, .h4, .wp-block-heading) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading),
body.single-post .entry-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6, .wp-block-paragraph)
	+ :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading),
body.single-post .entry-content.single-post-body :is(h4, .h4, .wp-block-heading) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .wp-block-heading) {
	margin-block-start: var(--westeck-layout-heading-gap) !important;
	margin-top: var(--westeck-layout-heading-gap) !important;
}

body.single-post .wp-block-post-content.single-post-body > :is(h4, .h4, .wp-block-heading),
body.single-post .entry-content.single-post-body > :is(h4, .h4, .wp-block-heading),
body.single-post .wp-block-post-content.single-post-body :is(h4, .h4).wp-block-heading,
body.single-post .entry-content.single-post-body :is(h4, .h4).wp-block-heading {
	margin-block-end: 30px !important;
	margin-bottom: 30px !important;
}

.editor-styles-wrapper .wp-block-post-content.single-post-body > * + *:not(figure):not(div.wp-caption):not([class*='wp-block-acf']):not([class*='wp-block-westeck']),
.editor-styles-wrapper .wp-block-post-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h4, h5, h6, .wp-block-paragraph, .wp-block-heading)
	+ :is(p, div, ul, ol, blockquote, table, hr, pre, h1, h2, h3, h4, h5, h6, .wp-block-paragraph, .wp-block-heading) {
	margin-block-start: var(--westeck-layout-block-gap) !important;
	margin-top: var(--westeck-layout-block-gap) !important;
	margin-block-end: 0 !important;
	margin-bottom: 0 !important;
}

.editor-styles-wrapper .wp-block-post-content.single-post-body > * + :is(h1, h2, h3, h4, h5, h6, .wp-block-heading),
.editor-styles-wrapper .wp-block-post-content.single-post-body
	:is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .wp-block-paragraph)
	+ :is(h1, h2, h3, h4, h5, h6, .wp-block-heading),
.editor-styles-wrapper .wp-block-post-content.single-post-body :is(h4, .h4, .wp-block-heading) + :is(h1, h2, h3, h4, h5, h6, .wp-block-heading) {
	margin-block-start: var(--westeck-layout-heading-gap) !important;
	margin-top: var(--westeck-layout-heading-gap) !important;
}

/*
 * Classic block (core/freeform) — raw HTML in one block, not separate .wp-block siblings.
 * !important beats theme flat margin resets (style.css, editor-content.css).
 * Includes generic div wrappers (legacy TinyMCE) and .h1–.h6 class headings.
 */
.wp-block-freeform > * + *,
.wp-block-post-content .wp-block-freeform > * + *,
.wp-block-freeform.block-library-classic__content > * + *,
.editor-styles-wrapper .wp-block-freeform > * + *,
.editor-styles-wrapper .wp-block-freeform-block > * + *,
body.mce-content-body > * + *,
body#tinymce > * + *,
.wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
.wp-block-post-content .wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
.editor-styles-wrapper .wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
body.mce-content-body :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
body#tinymce :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre) {
	margin-block-start: var(--westeck-layout-block-gap) !important;
	margin-top: var(--westeck-layout-block-gap) !important;
}

.wp-block-freeform > * + *:not(figure):not(div.wp-caption),
.wp-block-post-content .wp-block-freeform > * + *:not(figure):not(div.wp-caption),
.wp-block-freeform.block-library-classic__content > * + *:not(figure):not(div.wp-caption),
.editor-styles-wrapper .wp-block-freeform > * + *:not(figure):not(div.wp-caption),
.editor-styles-wrapper .wp-block-freeform-block > * + *:not(figure):not(div.wp-caption),
body.mce-content-body > * + *:not(figure):not(div.wp-caption),
body#tinymce > * + *:not(figure):not(div.wp-caption),
.wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
.wp-block-post-content .wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
.editor-styles-wrapper .wp-block-freeform :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
body.mce-content-body :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre),
body#tinymce :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption) + :is(p, div, h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, ul, ol, blockquote, table, hr, pre) {
	margin-block-end: 0 !important;
	margin-bottom: 0 !important;
}

.wp-block-freeform > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-post-content .wp-block-freeform > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-freeform.block-library-classic__content > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.editor-styles-wrapper .wp-block-freeform > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.editor-styles-wrapper .wp-block-freeform-block > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body.mce-content-body > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body#tinymce > * + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-freeform :is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-post-content .wp-block-freeform :is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-freeform :is(h4, .h4) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.wp-block-post-content .wp-block-freeform :is(h4, .h4) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.editor-styles-wrapper .wp-block-freeform :is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
.editor-styles-wrapper .wp-block-freeform :is(h4, .h4) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body.mce-content-body :is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body.mce-content-body :is(h4, .h4) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body#tinymce :is(p, div, ul, ol, blockquote, figure, table, hr, pre, div.wp-caption, h1, h2, h3, h5, h6, .h1, .h2, .h3, .h5, .h6) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6),
body#tinymce :is(h4, .h4) + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
	margin-block-start: var(--westeck-layout-heading-gap) !important;
	margin-top: var(--westeck-layout-heading-gap) !important;
}

/* Classic block — h4 space below (matches single-post paragraph bottom margin) */
.wp-block-freeform :is(h4, .h4),
.wp-block-post-content .wp-block-freeform :is(h4, .h4),
.editor-styles-wrapper .wp-block-freeform :is(h4, .h4),
body.mce-content-body :is(h4, .h4),
body#tinymce :is(h4, .h4) {
	margin-block-end: 30px !important;
	margin-bottom: 30px !important;
}

/*
 * Figures / image captions (2× default block gap above and below).
 * Classic block (.wp-block-freeform) OR legacy inline HTML as direct post-content children
 * (migrated classic posts — no freeform wrapper).
 */
.wp-block-post-content:is(.is-layout-flow, .is-layout-constrained) > :is(figure.wp-caption, div.wp-caption),
.wp-block-post-content .wp-block-freeform :is(figure, figure.wp-caption, div.wp-caption),
.wp-block-freeform :is(figure, figure.wp-caption, div.wp-caption),
.editor-styles-wrapper .wp-block-post-content > :is(figure.wp-caption, div.wp-caption),
.editor-styles-wrapper .wp-block-freeform :is(figure, figure.wp-caption, div.wp-caption),
body.mce-content-body :is(figure, figure.wp-caption, div.wp-caption),
body#tinymce :is(figure, figure.wp-caption, div.wp-caption) {
	margin-block-start: var(--westeck-layout-block-gap-double) !important;
	margin-block-end: var(--westeck-layout-block-gap-double) !important;
	margin-top: var(--westeck-layout-block-gap-double) !important;
	margin-bottom: var(--westeck-layout-block-gap-double) !important;
}

/*
 * Group utility — DOM order: heading then video; visual order reversed.
 * Add class "reverse-order" in the Group block → Advanced → Additional CSS class(es).
 */
.wp-block-group.reverse-order {
	display: flex;
	flex-direction: column-reverse;
}

/*
 * Benefits section — tighter paragraph top spacing (small block gap, not default).
 * Set HTML anchor id="benefits" on the Group block.
 */
#benefits p,
.editor-styles-wrapper #benefits p {
	margin-block-start: var(--westeck-layout-block-gap-small) !important;
	margin-top: var(--westeck-layout-block-gap-small) !important;
	padding-block-start: 0 !important;
	padding-top: 0 !important;
}
