/* Suntyp Block — per-post page settings (front end + block editor canvas) */

/* Scope: body (front end) or .suntyp-layout-scope (editor iframe / wrapper) */
:is(
	body,
	.suntyp-layout-scope,
	.editor-styles-wrapper
)[data-suntyp-layout="full-width"],
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-layout-full-width {
	--suntyp-page-layout-mode: full-width;
}

:is(
	body,
	.suntyp-layout-scope,
	.editor-styles-wrapper
)[data-suntyp-layout="contained"],
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-layout-contained {
	--suntyp-page-layout-mode: contained;
}

/* Full width — remove constrained layout (native flow). */
:is(
	body.suntyp-layout-full-width,
	.suntyp-layout-scope.suntyp-layout-full-width,
	[data-suntyp-layout="full-width"]
) :is(
	main.is-layout-constrained,
	.wp-block-post-content.is-layout-constrained,
	.is-root-container.is-layout-constrained
) {
	max-width: none !important;
	max-inline-size: none !important;
}

:is(
	body.suntyp-layout-full-width,
	.suntyp-layout-scope.suntyp-layout-full-width,
	[data-suntyp-layout="full-width"]
) :is(
	main.is-layout-constrained,
	.wp-block-post-content.is-layout-constrained
) > :where(:not(.alignleft):not(.alignright)) {
	max-width: none !important;
	max-inline-size: none !important;
	margin-inline: 0 !important;
}

/* Wide blocks still respect global wide size on full-width pages. */
:is(
	body.suntyp-layout-full-width,
	.suntyp-layout-scope.suntyp-layout-full-width,
	[data-suntyp-layout="full-width"]
) :is(
	main,
	.wp-block-post-content
) > .alignwide {
	max-width: var(--wp--style--global--wide-size) !important;
	max-inline-size: var(--wp--style--global--wide-size) !important;
	margin-inline: auto !important;
}

/* Contained — enforce global content width. */
:is(
	body.suntyp-layout-contained,
	.suntyp-layout-scope.suntyp-layout-contained,
	[data-suntyp-layout="contained"]
) :is(
	main.is-layout-constrained,
	.wp-block-post-content.is-layout-constrained,
	.is-root-container.is-layout-constrained
) > :where(:not(.alignleft):not(.alignright):not(.alignfull)) {
	max-width: var(--wp--style--global--content-size) !important;
	max-inline-size: var(--wp--style--global--content-size) !important;
	margin-inline: auto !important;
}

/* Container width presets (override global content / wide sizes). */
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-container-narrow {
	--wp--style--global--content-size: min(36rem, 100% - 2 * var(--wp--preset--spacing--50, 1.5rem));
	--st-content: var(--wp--style--global--content-size);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-container-normal {
	--wp--style--global--content-size: min(46rem, 100% - 2 * var(--wp--preset--spacing--50, 1.5rem));
	--st-content: var(--wp--style--global--content-size);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-container-wide {
	--wp--style--global--content-size: min(56rem, 100% - 2 * var(--wp--preset--spacing--40, 1rem));
	--wp--style--global--wide-size: min(80rem, 100% - 2 * var(--wp--preset--spacing--40, 1rem));
	--st-content: var(--wp--style--global--content-size);
	--st-wide: var(--wp--style--global--wide-size);
}

/* Content spacing */
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-spacing-compact main {
	padding-block: var(--wp--preset--spacing--40, 1rem);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-spacing-comfortable main {
	padding-block: var(--wp--preset--spacing--70, 3rem);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-spacing-spacious main {
	padding-block: var(--wp--preset--spacing--80, 4rem);
}

/* Sidebar layout (front end + editor preview) */
.suntyp-page-layout {
	display: grid;
	gap: var(--wp--custom--grid--gap, 1.5rem);
	align-items: start;
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-sidebar-left .suntyp-page-layout,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-sidebar-right .suntyp-page-layout {
	grid-template-columns: minmax(0, 16rem) minmax(0, 1fr);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-sidebar-right .suntyp-page-layout {
	grid-template-columns: minmax(0, 1fr) minmax(0, 16rem);
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-sidebar-left .suntyp-page-layout__sidebar {
	order: -1;
}

@media (max-width: 781px) {
	:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-has-sidebar .suntyp-page-layout {
		grid-template-columns: 1fr;
	}

	:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-sidebar-left .suntyp-page-layout__sidebar {
		order: 0;
	}
}

.suntyp-page-layout__main,
.suntyp-page-layout__sidebar {
	min-width: 0;
}

.suntyp-page-layout__sidebar--preview {
	padding: var(--wp--preset--spacing--40, 0.75rem);
	border: 1px dashed color-mix(in srgb, currentColor 30%, transparent);
	border-radius: var(--wp--preset--border-radius--sm, 0.25rem);
	font-size: var(--wp--preset--font-size--sm, 0.875rem);
	color: color-mix(in srgb, currentColor 70%, transparent);
}

/* Title & featured image */
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-hide-title .wp-block-post-title,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-hide-title .entry-title {
	display: none !important;
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-hide-featured-image .wp-block-post-content .wp-block-post-featured-image,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-hide-featured-image .wp-block-post-featured-image {
	display: none !important;
}

/* Header & footer */
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-header-disabled .suntyp-header,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-header-disabled header.suntyp-header,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-header-disabled #suntyp-header,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-header-disabled header.wp-block-template-part,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-header-disabled .wp-block-template-part[class*="header"] {
	display: none !important;
}

:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-footer-disabled .suntyp-footer,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-footer-disabled footer.suntyp-footer,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-footer-disabled #suntyp-footer,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-footer-disabled footer.wp-block-template-part,
:is(body, .suntyp-layout-scope, .editor-styles-wrapper).suntyp-footer-disabled .wp-block-template-part[class*="footer"] {
	display: none !important;
}
