/**
 * Layout Div — frontend styles.
 * Layout is scoped per block via data-bb-id + inline CSS from render.php.
 */

.wp-block-bb-layout-div.bb-layout-div {
	box-sizing: border-box;
}

.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--theme,
.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--wide,
.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--custom {
	box-sizing: border-box;
	width: 100%;
	margin-left: auto;
	margin-right: auto;
}

.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--theme {
	max-width: var(--wp--style--global--content-size, 1200px);
}

.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--wide {
	max-width: var(--wp--style--global--wide-size, 1400px);
}

.wp-block-bb-layout-div.bb-layout-div .bb-layout-div__inner--full {
	width: 100%;
	max-width: none;
}

.bb-layout-div.is-linked {
	position: relative;
}

.bb-layout-div__link {
	position: absolute;
	inset: 0;
	z-index: 1;
	display: block;
	text-decoration: none;
}

.bb-layout-div.is-linked > .bb-layout-div__inner {
	position: relative;
	z-index: 0;
}

/*
 * Position: Sticky on the section itself, in Flow, Flex row, Flex column, and Grid.
 * Beats the link overlay's position:relative. A sticky inner section used as a
 * column stays content-sized so it can stick beside a taller sibling.
 */
.wp-block-bb-layout-div.bb-layout-div.is-position-sticky {
	position: sticky;
	top: calc(0px + var(--wp-admin--admin-bar--position-offset, 0px));
	z-index: 2;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner > .bb-layout-div.is-position-sticky {
	align-self: start !important;
	height: auto !important;
}

.bb-layout-div.is-linked a:not(.bb-layout-div__link),
.bb-layout-div.is-linked button,
.bb-layout-div.is-linked input,
.bb-layout-div.is-linked select,
.bb-layout-div.is-linked textarea,
.bb-layout-div.is-linked [tabindex]:not([tabindex="-1"]),
.bb-layout-div.is-linked .wp-block-button__link {
	position: relative;
	z-index: 2;
}

@media (min-width: 783px) {
	.wp-block-bb-layout-div.bb-layout-div.bb-layout-div--hide-desktop {
		display: none !important;
	}
}

@media (min-width: 481px) and (max-width: 782px) {
	.wp-block-bb-layout-div.bb-layout-div.bb-layout-div--hide-tablet {
		display: none !important;
	}
}

@media (max-width: 480px) {
	.wp-block-bb-layout-div.bb-layout-div.bb-layout-div--hide-mobile {
		display: none !important;
	}
}

/* Flow — flex column; gap comes from scoped CSS (row-gap / gap). */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flow {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	flex-wrap: nowrap;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flow > * {
	margin-top: 0;
	margin-bottom: 0;
	margin-block-start: 0;
	margin-block-end: 0;
}

/*
 * A direct child with its own width keeps that width. Children without a width
 * still stretch. Flow only opts out of stretch; flex row/column also refuse to
 * grow or shrink that width away.
 */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flow > [style*="width:"] {
	align-self: flex-start;
	max-width: 100%;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row > [style*="width:"],
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column > [style*="width:"] {
	align-self: flex-start;
	flex: 0 0 auto;
	max-width: 100%;
}

/* Core % button: the class width wins. The buttons group stays the column width. */
.bb-layout-div .wp-block-buttons > .wp-block-button[class*="wp-block-button__width"] {
	align-self: flex-start;
	max-width: 100%;
}

/* Flex row */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row {
	display: flex;
	flex-direction: row;
	flex-wrap: nowrap;
	align-items: flex-start;
}

/* Buttons group fills the flex row, so a core % button is that share of the row. */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row > .wp-block-buttons {
	flex: 1 0 auto;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	box-sizing: border-box;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row.bb-layout-div--wrap {
	flex-wrap: wrap;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row.bb-layout-div--justify-center {
	justify-content: center;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row.bb-layout-div--justify-flex-end {
	justify-content: flex-end;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row.bb-layout-div--justify-space-between {
	justify-content: space-between;
}

/* Flex column */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column {
	display: flex;
	flex-direction: column;
	flex-wrap: nowrap;
	align-items: flex-start;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column > * {
	margin-top: 0;
	margin-bottom: 0;
	margin-block-start: 0;
	margin-block-end: 0;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column.bb-layout-div--justify-center {
	justify-content: center;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column.bb-layout-div--justify-flex-end {
	justify-content: flex-end;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column.bb-layout-div--justify-space-between {
	justify-content: space-between;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column.bb-layout-div--justify-last-to-bottom {
	min-height: 100%;
	flex: 1 1 auto;
	height: 100%;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column.bb-layout-div--justify-last-to-bottom > *:last-child {
	margin-top: auto !important;
	margin-block-start: auto !important;
}

/* Grid */
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-grid {
	display: grid;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-grid.bb-layout-div--grid-push-last-in-cells > .bb-layout-div {
	display: flex;
	flex-direction: column;
	min-height: 100%;
	height: 100%;
	box-sizing: border-box;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-grid.bb-layout-div--grid-push-last-in-cells > .bb-layout-div > .bb-layout-div__inner {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	min-height: 100%;
	height: 100%;
	box-sizing: border-box;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-grid.bb-layout-div--grid-push-last-in-cells > .bb-layout-div > .bb-layout-div__inner > *:last-child {
	margin-top: auto !important;
	margin-block-start: auto !important;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row > *,
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column > *,
.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-grid > * {
	min-width: 0;
	max-width: 100%;
	overflow-wrap: break-word;
	word-break: break-word;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-row > .bb-layout-div {
	box-sizing: border-box;
	min-width: 0;
	max-width: 100%;
}

.bb-layout-div[data-bb-id] > .bb-layout-div__inner.bb-layout-div--layout-flex-column > .bb-layout-div {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
}

/*
 * Content column contract (top-level only):
 * Inner theme/wide/custom max-width is owned by the plugin and centered against a
 * consistent containing block. Outer align (wide vs full) controls the background
 * shell; content: wide must match whether the outer is alignwide or alignfull.
 * Nested sections keep normal % / flex / grid behaviour (resets below).
 *
 * Root-padding compensation (--bb-layout-div-root-pad*): horizontal inset for
 * top-level alignfull shells when .bb-layout-div--compensate-root-pad is present
 * (block toggle + constrained content). Not written into Spacing attributes.
 * Alignwide shells use wide-size only (no compensation expansion).
 * Auto padding with a background adds Default padding on L/R when outer align
 * is not full, or when align is full and Compensate root padding is off.
 * Align full + Compensate on keeps Spacing L/R at 0 so compensation is
 * root-pad only (avoids double padding with Default).
 */
:root {
	--bb-layout-div-root-pad-desktop: 0px;
	--bb-layout-div-root-pad-tablet: 0px;
	--bb-layout-div-root-pad-mobile: 0px;
	--bb-layout-div-root-pad: var(--bb-layout-div-root-pad-desktop, 0px);
}

.wp-block-bb-layout-div.bb-layout-div.alignfull.bb-layout-div--compensate-root-pad:not(
		.bb-layout-div .bb-layout-div
	) {
	/* Fallback only — per-block scoped CSS (!important) owns real L/R values. */
	padding-left: var(--bb-layout-div-root-pad, 0px);
	padding-right: var(--bb-layout-div-root-pad, 0px);
}

/*
 * Full-width outer sections — hybrid breakout:
 * - Classic (Kadence, etc.): viewport breakout. Root padding vars are often
 *   0/unset there, so negative root-pad margins do nothing and the shell stays
 *   trapped in the theme content column (background not edge-to-edge).
 * - FSE with .has-global-padding: root-padding negative margins (overflow-safe
 *   on TT5 / Ollie; avoids 100vw clip when root padding / scrollbars exist).
 * Nested sections reset below (must beat the has-global-padding rule).
 */
.wp-block-bb-layout-div.bb-layout-div.alignfull {
	box-sizing: border-box;
	width: var(--global-vw, 100vw);
	max-width: 100vw;
	margin-left: calc(50% - var(--global-vw, 100vw) / 2);
	margin-right: calc(50% - var(--global-vw, 100vw) / 2);
}

.has-global-padding .wp-block-bb-layout-div.bb-layout-div.alignfull {
	width: auto;
	max-width: none;
	margin-left: calc(-1 * var(--wp--style--root--padding-left, 0px));
	margin-right: calc(-1 * var(--wp--style--root--padding-right, 0px));
}

/* Nested sections stay within the parent inner column. */
.bb-layout-div .bb-layout-div.alignfull,
.has-global-padding .bb-layout-div .bb-layout-div.alignfull {
	width: 100%;
	max-width: none;
	margin-left: 0;
	margin-right: 0;
}

/*
 * Top-level alignwide: fill the available canvas (max 100%), cap at wide-size.
 * No viewport units — avoids right-edge clip on small screens.
 * Nested sections unchanged below.
 */
.wp-block-bb-layout-div.bb-layout-div.alignwide {
	box-sizing: border-box;
	width: 100%;
	max-width: var(--wp--style--global--wide-size, 1400px);
	margin-left: auto;
	margin-right: auto;
}

/* Nested alignwide: fill the parent inner column; do not break out. */
.bb-layout-div .bb-layout-div.alignwide {
	width: 100%;
	max-width: none;
	margin-left: 0;
	margin-right: 0;
}

/*
 * Top-level constrained inners: center on the same reference whether the outer is
 * alignwide or alignfull. Nested inners keep width:100% of their parent slot.
 */
.wp-block-bb-layout-div.bb-layout-div:not(.bb-layout-div .bb-layout-div) > .bb-layout-div__inner--theme,
.wp-block-bb-layout-div.bb-layout-div:not(.bb-layout-div .bb-layout-div) > .bb-layout-div__inner--wide,
.wp-block-bb-layout-div.bb-layout-div:not(.bb-layout-div .bb-layout-div) > .bb-layout-div__inner--custom {
	box-sizing: border-box;
	width: 100%;
	margin-left: auto;
	margin-right: auto;
}

.bb-layout-div[class*="has-"][class*="-background-color"],
.bb-layout-div[class*="has-background"] {
	background-size: cover;
	background-position: center;
}
