/*
 * Section and container (cis/section, cis/container). Loaded with the blocks, front end and editor canvas.
 *
 * Moved here from the Etch styles of the Section and Container components:
 *   - .section (ga928ua): size container, relative, hidden overflow, the padding and gutter attributes
 *   - .section__watermark (3h2cso5)
 *   - .container (40mxdk6): the size container that every 800px rule inside it measures against
 *   - the two readonly Etch rules that were keyed on `data-etch-element` (`:where([data-etch-element="section"])`
 *     and `...="container"`). The blocks do not print that attribute (it is only for the Etch builder), so the same
 *     declarations are keyed on the classes the elements already carry: `:where(.section)` and `:where(.container)`.
 *     They keep zero specificity, as before, so every page class still overrides them.
 *
 * The block registers the same Etch styles Etch would (see bw_section_register_class_styles()), so Etch prints its own copy of
 * these rules, in its own order, together with the page classes that tweak them (for example
 * `.bw-how-to-vendor__section.section { padding-block-end: 0 }`, which ties with `.section[data-section-padding]` and wins only
 * because Etch prints it later). This stylesheet is the fallback for when Etch's copy is not there, so every rule is written
 * with zero specificity (`:where()`): it can never override Etch's copy or a page class, whatever the load order.
 * Earlier versions of this file were wrong twice: a cascade layer lost to ACSS's unlayered gap rule, and plain class
 * selectors loaded after Etch's inline styles and beat the page classes.
 *
 * Plain stylesheet, not compiled by Etch, so the Etch @custom-media token is written out:
 *   --container-query-large = inline-size >= 800px  (50rem)
 * Left out on purpose: the Etch Section component's own `.section__background-image` property (never used; the block has its own
 * background image setting, see `.section__background` below) and one invalid Etch rule inside the column flex layout (`&[data-vertical-alignment='start'] > { ... }` has no
 * selector after the `>`, so browsers never applied it; start is the default `justify-content` anyway).
 *
 * The container queries need an ancestor with container-type: inline-size: for the container that is the section
 * (`.section` is a size container), and for everything inside the container it is the container itself.
 */

:where(.section) {
	inline-size: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}

:where(.section) {
	container-type: inline-size;
	position: relative;
	overflow: hidden;

	&[data-section-padding='m'] {
		padding-block: var(--section-space-m);
	}

	&[data-section-padding='s'] {
		padding-block: var(--section-space-s);
	}

	&[data-section-padding='l'] {
		padding-block: var(--section-space-l);
	}

	&[data-section-padding='xs'] {
		padding-block: var(--section-space-xs);
	}

	&[data-section-padding='xl'] {
		padding-block: var(--section-space-xl);
	}

	&[data-section-padding='None'] {
		padding: 0;
	}

	&[data-section-gutter='none'] {
		padding-inline: 0;
	}

	&:has(.section__watermark) {
		.section__watermark + .heading-component {
			z-index: 1;
		}
	}
}

/*
 * Background image (the "Background image" setting): a decorative layer behind the content. The layer holds the overlay colour, the
 * image sits on top of it with its own opacity, so the overlay shows through where the image is see-through (a dark overlay and a
 * 35% image give a darkened photo). Everything else in the section sits above the layer. Written before the watermark rule so the
 * watermark (absolute) keeps its own position. All zero specificity.
 */
:where(.section--has-background > *:not(.section__background)) {
	position: relative;
	z-index: 1;
}

:where(.section__background) {
	position: absolute;
	inset: 0;
	z-index: 0;
	background-color: var(--section-bg-overlay, transparent);
	pointer-events: none;
}

:where(.section__background-image) {
	position: absolute;
	inset: 0;
	inline-size: 100%;
	block-size: 100%;
	max-inline-size: none;
	object-fit: cover;
	border-radius: 0;
	opacity: var(--section-bg-opacity, 1);

	/* --media-query-large of the site: width > 992px */
	@media (width > 992px) {
		opacity: var(--section-bg-opacity-large, var(--section-bg-opacity, 1));
	}
}

:where(.section__watermark) {
	position: absolute;
	inset: 0;
	margin: auto;
	inline-size: 120%;
	max-inline-size: 120%;
	z-index: 0;
	opacity: var(--watermark-opacity);
	color: var(--watermark-color);
	pointer-events: none;
	inset-block-start: var(--watermark-vertical-inset);
	inset-inline-start: var(--watermark-horizontal-inset);

	path {
		fill: currentColor;
	}
}

:where(.container) {
	inline-size: 100%;
	display: flex;
	flex-direction: column;
	max-inline-size: var(--content-width, 1366px);
	align-self: center;
	margin-inline: auto;
}

:where(.container) {
	container-type: inline-size;
	container-name: container;
	position: relative;
	gap: var(--container-gap-size);
	align-items: var(--container-vertical-alignment);

	&[data-layout='flex'] {
		display: var(--container-layout-type);
		flex-direction: column;

		@container (inline-size >= 50rem) {
			flex-direction: var(--container-flex-layout);
		}

		&[data-flex-layout='column'] {
			&[data-vertical-alignment='center'] {
				justify-content: center;
			}

			&[data-vertical-alignment='end'] {
				justify-content: end;
			}

			&[data-horizontal-alignment='start'] {
				text-align: left;
				align-items: start;
			}

			&[data-horizontal-alignment='center'] {
				text-align: center;
				align-items: center;
			}

			&[data-horizontal-alignment='end'] {
				text-align: right;
				align-items: end;
			}

			&[data-horizontal-alignment='stretch'] {
				align-items: stretch;
			}
		}

		&[data-flex-layout='row'] {
			&[data-vertical-alignment='start'] {
				align-items: start;
			}

			&[data-vertical-alignment='center'] {
				align-items: center;
			}

			&[data-vertical-alignment='end'] {
				align-items: end;
			}

			&[data-vertical-alignment='stretch'] {
				align-items: stretch;
			}

			&[data-horizontal-alignment='start'] {
				text-align: left;
				justify-content: start;
			}

			&[data-horizontal-alignment='center'] {
				text-align: center;
				justify-content: center;
			}

			&[data-horizontal-alignment='end'] {
				text-align: right;
				justify-content: end;
			}
		}
	}

	&[data-layout='grid'] {
		display: var(--container-layout-type);
		grid-template-columns: var(--grid-1);

		@container (inline-size >= 50rem) {
			grid-template-columns: var(--container-grid-layout);
		}

		&[data-vertical-alignment='start'] {
			align-items: start;
		}

		&[data-vertical-alignment='center'] {
			align-items: center;
		}

		&[data-vertical-alignment='end'] {
			align-items: end;
		}

		&[data-vertical-alignment='stretch'] {
			align-items: stretch;
		}

		&[data-horizontal-alignment='start'] {
			text-align: left;
			justify-items: start;
		}

		&[data-horizontal-alignment='center'] {
			text-align: center;
			justify-items: center;
		}

		&[data-horizontal-alignment='end'] {
			text-align: right;
			justify-items: end;
		}

		&[data-horizontal-alignment='stretch'] {
			justify-items: stretch;
		}
	}

	&[data-fullwidth='true'] {
		max-inline-size: 100%;
	}
}

/*
 * Container watermark (the container's "Watermark" setting): a decorative SVG centred behind the content, as the loose SVG blocks
 * (.bw-stats__watermark) used to be. `isolation: isolate` keeps its z-index of -1 inside the container, so it is never lost behind the
 * section background. Zero specificity: a page class can still tweak it.
 */
:where(.container--has-watermark) {
	position: relative;
	isolation: isolate;
}

:where(.container__watermark) {
	position: absolute;
	inset: 0;
	margin: auto;
	inline-size: var(--watermark-size, 112%);
	max-inline-size: var(--watermark-size, 112%);
	z-index: -1;
	opacity: var(--watermark-opacity, 0.06);
	color: var(--watermark-color, var(--tertiary));
	pointer-events: none;
	transform: translate(var(--watermark-x, 0), var(--watermark-y, 0)) rotate(var(--watermark-rotate, -32deg));

	path {
		fill: currentColor;
	}
}

/* ---- Editor canvas only ---------------------------------------------------------------------------
 * The block wrappers are the section and container elements themselves. The editor adds its own margins and a
 * content width to every block; the section and container lay their children out, so those are removed, and the
 * container keeps the maximum width it has on the page. */
.section.wp-block {
	margin-block: 0;
	max-inline-size: none;
}

.container.wp-block {
	margin-block: 0;
	max-inline-size: var(--content-width, 1366px);

	&[data-fullwidth='true'] {
		max-inline-size: 100%;
	}
}

.section > .wp-block:not(.container),
.container > .wp-block {
	max-inline-size: none;
	margin-block: 0;
}
