/**
 * Pioneer grid last-row + item alignment.
 *
 * Off: leave GreenShift's CSS Grid alone.
 * Center / Fill: CSS Grid cannot center or stretch an incomplete last row
 * when earlier rows fill every column, so those two modes use flex-wrap
 * (same as Icon Grid). Column count and gap still come from GreenShift.
 *
 * Editor: GS styles sit on the block host; cards live in
 * .block-editor-inner-blocks > .block-editor-block-list__layout.
 */

.pioneer-gs-grid {
	--pioneer-grid-cols-current: var(--pioneer-grid-cols-desktop, 1);
	--pioneer-grid-gap-current: var(--pioneer-grid-gap-desktop, 0px);
	--pioneer-grid-col-width: calc(
		(100% - (var(--pioneer-grid-cols-current, 1) - 1) * var(--pioneer-grid-gap-current, 0px)) /
			var(--pioneer-grid-cols-current, 1)
	);
}

.pioneer-gs-grid--center-last:not(.block-editor-block-list__block),
.pioneer-gs-grid--fill-last:not(.block-editor-block-list__block) {
	display: flex !important;
	flex-wrap: wrap !important;
	align-content: flex-start;
	grid-template-columns: none !important;
}

.pioneer-gs-grid--center-last:not(.block-editor-block-list__block) {
	justify-content: center !important;
}

.pioneer-gs-grid--fill-last:not(.block-editor-block-list__block) {
	justify-content: flex-start !important;
}

.pioneer-gs-grid:not(.block-editor-block-list__block) > :not(style):not(script),
.pioneer-gs-grid--nested-items .wp-block-post-template > * {
	--pioneer-grid-item-span: var(--pioneer-grid-item-span-desktop, 1);
	--pioneer-grid-item-width: calc(
		var(--pioneer-grid-item-span, 1) * var(--pioneer-grid-col-width) +
			(var(--pioneer-grid-item-span, 1) - 1) * var(--pioneer-grid-gap-current, 0px)
	);
}

.pioneer-gs-grid--center-last:not(.block-editor-block-list__block) > :not(style):not(script),
.pioneer-gs-grid--nested-items.pioneer-gs-grid--center-last .wp-block-post-template > * {
	box-sizing: border-box;
	flex: 0 0 var(--pioneer-grid-item-width) !important;
	width: var(--pioneer-grid-item-width) !important;
	max-width: 100% !important;
}

/* Fill: grow leftover items so 2 of 3 become 50/50. Full rows stay at column width. */
.pioneer-gs-grid--fill-last:not(.block-editor-block-list__block) > :not(style):not(script),
.pioneer-gs-grid--nested-items.pioneer-gs-grid--fill-last .wp-block-post-template > * {
	box-sizing: border-box;
	flex: 1 0 var(--pioneer-grid-item-width) !important;
	flex-grow: 1 !important;
	width: auto !important;
	min-width: 0;
	max-width: 100% !important;
}

.pioneer-gs-grid--nested-items.pioneer-gs-grid--center-last,
.pioneer-gs-grid--nested-items.pioneer-gs-grid--fill-last {
	display: block !important;
}

.pioneer-gs-grid--nested-items.pioneer-gs-grid--center-last .wp-block-post-template,
.pioneer-gs-grid--nested-items.pioneer-gs-grid--fill-last .wp-block-post-template {
	display: flex !important;
	flex-wrap: wrap !important;
	align-content: flex-start;
	width: 100%;
	gap: var(--pioneer-grid-gap-current, 0px);
}

.pioneer-gs-grid--nested-items.pioneer-gs-grid--center-last .wp-block-post-template {
	justify-content: center !important;
}

.pioneer-gs-grid--nested-items.pioneer-gs-grid--fill-last .wp-block-post-template {
	justify-content: flex-start !important;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > .block-editor-inner-blocks,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > .block-editor-inner-blocks,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > .block-editor-inner-blocks,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > .block-editor-inner-blocks,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > * > .block-editor-inner-blocks,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > * > .block-editor-inner-blocks {
	grid-column: 1 / -1;
	width: 100%;
	max-width: 100%;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout {
	display: flex;
	flex-wrap: wrap;
	align-content: flex-start;
	width: 100%;
	gap: var(--pioneer-grid-gap-current, 0px);
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout {
	justify-content: center;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout {
	justify-content: flex-start;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block {
	--pioneer-grid-item-span: var(--pioneer-grid-item-span-desktop, 1);
	--pioneer-grid-item-width: calc(
		var(--pioneer-grid-item-span, 1) * var(--pioneer-grid-col-width) +
			(var(--pioneer-grid-item-span, 1) - 1) * var(--pioneer-grid-gap-current, 0px)
	);
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block {
	box-sizing: border-box;
	flex: 0 0 var(--pioneer-grid-item-width) !important;
	width: var(--pioneer-grid-item-width) !important;
	max-width: 100% !important;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block {
	box-sizing: border-box;
	flex: 1 0 var(--pioneer-grid-item-width) !important;
	flex-grow: 1 !important;
	width: auto !important;
	min-width: 0;
	max-width: 100% !important;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--center-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--fill-last > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-list-appender {
	flex: 0 0 100%;
	width: 100%;
}

.pioneer-gs-grid .pioneer-gs-grid-item--full,
.pioneer-gs-grid--nested-items .wp-block-post-template > .pioneer-gs-grid-item--full,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--full,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--full,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--full {
	flex: 0 0 100% !important;
	grid-column: 1 / -1 !important;
	width: 100% !important;
	max-width: 100% !important;
}

.pioneer-gs-grid .pioneer-gs-grid-item--center,
.pioneer-gs-grid--nested-items .wp-block-post-template > .pioneer-gs-grid-item--center,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--center,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--center,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block.pioneer-gs-grid-item--center {
	flex: 0 0 100% !important;
	grid-column: 1 / -1 !important;
	justify-self: center !important;
	width: var(--pioneer-grid-item-width, var(--pioneer-grid-col-width)) !important;
	max-width: var(--pioneer-grid-item-width, var(--pioneer-grid-col-width)) !important;
	margin-left: auto !important;
	margin-right: auto !important;
}

.pioneer-gs-grid--is-flex:not(.block-editor-block-list__block):not(.pioneer-gs-grid--center-last):not(.pioneer-gs-grid--fill-last) {
	flex-wrap: wrap !important;
}

.pioneer-gs-grid--is-flex:not(.block-editor-block-list__block):not(.pioneer-gs-grid--center-last):not(.pioneer-gs-grid--fill-last) > :not(style):not(script) {
	box-sizing: border-box;
	flex: 0 0 var(--pioneer-grid-item-width) !important;
	width: var(--pioneer-grid-item-width) !important;
	max-width: 100% !important;
}

.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--is-flex:not(.pioneer-gs-grid--center-last):not(.pioneer-gs-grid--fill-last) > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--is-flex:not(.pioneer-gs-grid--center-last):not(.pioneer-gs-grid--fill-last) > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block,
.editor-styles-wrapper .block-editor-block-list__block.pioneer-gs-grid--is-flex:not(.pioneer-gs-grid--center-last):not(.pioneer-gs-grid--fill-last) > * > * > .block-editor-inner-blocks > .block-editor-block-list__layout > .block-editor-block-list__block {
	box-sizing: border-box;
	flex: 0 0 var(--pioneer-grid-item-width) !important;
	width: var(--pioneer-grid-item-width) !important;
	max-width: 100% !important;
}
