/* Premium builder skeleton — matches simple/advanced UI layout */

@keyframes cpbpwc-builder-skeleton-shimmer {
	0% {
		background-position: 200% 0;
	}

	100% {
		background-position: -200% 0;
	}
}

.cpbpwc-main-designer-container,
.cpbpwc-designer-shell {
	position: relative;
	width: 100%;
	overflow: hidden;
}

.cpbpwc-main-designer-container.cpbpwc-designer-ready,
.cpbpwc-designer-shell.cpbpwc-designer-ready {
	overflow: visible;
}

.cpbpwc-main-designer-container.cpbpwc-is-loading:not(.cpbpwc-shell-ready),
.cpbpwc-designer-shell.cpbpwc-is-loading:not(.cpbpwc-shell-ready) {
	min-height: 0;
	height: 0;
	opacity: 0;
	visibility: hidden;
	overflow: hidden;
}

.cpbpwc-main-designer-container.cpbpwc-shell-ready,
.cpbpwc-designer-shell.cpbpwc-shell-ready {
	height: auto;
	min-height: 0;
	opacity: 1;
	visibility: visible;
	transition:
		opacity 0.22s ease,
		visibility 0.22s ease;
}

.cpbpwc-main-designer-container.cpbpwc-shell-ready:not(.cpbpwc-designer-ready),
.cpbpwc-designer-shell.cpbpwc-shell-ready:not(.cpbpwc-designer-ready) {
	min-height: 640px;
}

.cpbpwc-designer-skeleton {
	position: absolute;
	inset: 0;
	z-index: 20;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	max-height: 100%;
	background: #fff;
	border: 1px solid #e2e8f0;
	border-radius: 12px;
	padding: 8px;
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity 0.25s ease,
		visibility 0.25s ease;
}

.cpbpwc-designer-skeleton.cpbpwc-skeleton-active {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

.cpbpwc-designer-skeleton.cpbpwc-skeleton-hiding {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.cpbpwc-main-designer-container.cpbpwc-designer-ready .cpbpwc-designer-skeleton,
.cpbpwc-designer-shell.cpbpwc-designer-ready .cpbpwc-designer-skeleton {
	display: none;
}

.cpbpwc-builder-skeleton__block {
	display: block;
	flex-shrink: 0;
	background-color: #f1f5f9;
	background-image: linear-gradient(
		90deg,
		rgba(136, 124, 253, 0.06) 0%,
		rgba(136, 124, 253, 0.16) 45%,
		rgba(136, 124, 253, 0.06) 90%
	);
	background-size: 200% 100%;
	animation: cpbpwc-builder-skeleton-shimmer 1.5s ease-in-out infinite;
	border: 1px solid #e8edf3;
	border-radius: 10px;
}

/* Shell grid — mirrors .wrapper-memes-main */
.cpbpwc-builder-skeleton__shell {
	display: grid;
	width: 100%;
	height: 100%;
	max-height: 100%;
	grid-template-areas:
		"ops ops"
		"sidebar preview"
		"assets assets";
	grid-template-columns: minmax(72px, 100px) minmax(0, 1fr);
	grid-template-rows: auto minmax(0, 1fr) auto;
	gap: 8px 10px;
	box-sizing: border-box;
	overflow: hidden;
	align-content: stretch;
}

/* Top toolbar rows */
.cpbpwc-builder-skeleton__ops {
	grid-area: ops;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding-bottom: 8px;
	border-bottom: 1px solid #f1f7fe;
	min-width: 0;
}

.cpbpwc-builder-skeleton__icon-row {
	display: flex;
	flex-wrap: nowrap;
	justify-content: center;
	align-items: center;
	gap: 8px;
	width: 100%;
	max-width: 100%;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__icon {
	width: 40px;
	height: 40px;
	border-radius: 8px;
	flex: 0 0 auto;
}

.cpbpwc-builder-skeleton__canvas-bar {
	display: flex;
	justify-content: center;
	width: 100%;
	padding: 2px 0;
	min-width: 0;
}

.cpbpwc-builder-skeleton__canvas-pill {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 6px 10px;
	background: #f1f5f9;
	border: 1px solid #e2e8f0;
	border-radius: 14px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
	max-width: 100%;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__tool {
	width: 34px;
	height: 34px;
	border-radius: 10px;
	background-color: #fff;
	flex: 0 0 auto;
}

.cpbpwc-builder-skeleton__dropdown {
	width: 72px;
	height: 34px;
	border-radius: 10px;
	background-color: #fff;
	flex: 0 0 auto;
}

/* Sidebar thumbnails */
.cpbpwc-builder-skeleton__sidebar {
	grid-area: sidebar;
	display: flex;
	flex-direction: column;
	gap: 10px;
	border-right: 1px solid #f1f7fe;
	padding-right: 8px;
	min-height: 0;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__thumb {
	width: 100%;
	max-width: 72px;
	aspect-ratio: 1 / 1;
	height: auto;
	border-radius: 10px;
}

/* Canvas preview */
.cpbpwc-builder-skeleton__preview-wrap {
	grid-area: preview;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	min-width: 0;
	padding: 0 4px;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__preview {
	width: 100%;
	max-width: 100%;
	height: 100%;
	min-height: 180px;
	max-height: 100%;
	aspect-ratio: 1 / 1;
	border-radius: 12px;
	background-color: #f8fafc;
}

.cpbpwc-builder-skeleton__expand {
	position: absolute;
	top: 12px;
	right: 12px;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background-color: #fff;
}

/* Bottom assets — fit container width, no overflow */
.cpbpwc-builder-skeleton__assets {
	grid-area: assets;
	display: grid;
	grid-template-columns: repeat(5, minmax(0, 1fr));
	justify-content: center;
	gap: 8px;
	padding-top: 8px;
	border-top: 1px solid #f1f7fe;
	min-width: 0;
	max-width: 100%;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__asset {
	width: 100%;
	max-width: 64px;
	margin: 0 auto;
	aspect-ratio: 1 / 1;
	height: auto;
	border-radius: 10px;
	background-color: #fff;
}

/* Advanced builder page shell */
body.cpbpwc-advance-builder-page .cpbpwc-designer-shell,
body.cpbpwc-advance-builder-page .cpbpwc-designer-shell.cpbpwc-shell-ready,
body.cpbpwc-advance-builder-page .cpbpwc-designer-shell.cpbpwc-designer-ready {
	margin: 0;
	min-height: calc(100vh - 90px);
	height: calc(100vh - 90px);
	overflow: hidden;
}

body.cpbpwc-advance-builder-page.admin-bar .cpbpwc-designer-shell,
body.cpbpwc-advance-builder-page.admin-bar .cpbpwc-designer-shell.cpbpwc-shell-ready,
body.cpbpwc-advance-builder-page.admin-bar .cpbpwc-designer-shell.cpbpwc-designer-ready {
	min-height: calc(100vh - 122px);
	height: calc(100vh - 122px);
}

body.cpbpwc-advance-builder-page .cpbpwc-designer-shell > #product-designer {
	height: 100%;
}

body.cpbpwc-advance-builder-page .cpbpwc-designer-shell > #product-designer > .cpbpwc-advance-container {
	height: 100%;
}

body.cpbpwc-advance-builder-page .cpbpwc-designer-shell.cpbpwc-is-loading:not(.cpbpwc-shell-ready) {
	/* Advance renders shell-ready + active skeleton in PHP — keep visible on first paint. */
	min-height: calc(100vh - 90px);
	height: calc(100vh - 90px);
	opacity: 1;
	visibility: visible;
}

body.cpbpwc-advance-builder-page .cpbpwc-designer-skeleton--advance {
	border: 0;
	border-radius: 0;
	padding: 0;
	background: #f8fafc;
}

.cpbpwc-builder-skeleton__shell--advance {
	display: grid;
	grid-template-columns: 100px minmax(220px, 280px) minmax(0, 1fr);
	grid-template-areas: "rail panel stage";
	gap: 0;
	width: 100%;
	height: 100%;
	min-height: calc(100vh - 90px);
	box-sizing: border-box;
}

.cpbpwc-builder-skeleton__rail {
	grid-area: rail;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	padding: 20px 10px;
	background: #ffffff;
	border-right: 1px solid #e2e8f0;
	box-sizing: border-box;
}

.cpbpwc-builder-skeleton__rail-item {
	width: 64px;
	height: 56px;
	border-radius: 12px;
}

.cpbpwc-builder-skeleton__panel {
	grid-area: panel;
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-content: start;
	gap: 12px;
	padding: 20px;
	background: #ffffff;
	border-right: 1px solid #e2e8f0;
	box-sizing: border-box;
	overflow: hidden;
}

.cpbpwc-builder-skeleton__panel-card {
	width: 100%;
	height: 110px;
	border-radius: 12px;
}

.cpbpwc-builder-skeleton__stage {
	grid-area: stage;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: 12px;
	padding: 24px 40px 40px;
	background: #f1f5f9;
	box-sizing: border-box;
	min-width: 0;
	overflow: hidden;
}

.cpbpwc-designer-skeleton--advance .cpbpwc-builder-skeleton__canvas-bar {
	justify-content: center;
	padding: 0 0 4px;
}

.cpbpwc-designer-skeleton--advance .cpbpwc-builder-skeleton__preview-wrap {
	flex: 1 1 auto;
	width: 100%;
	max-width: 560px;
	min-height: 0;
	padding: 0;
}

.cpbpwc-designer-skeleton--advance .cpbpwc-builder-skeleton__preview {
	width: 100%;
	min-height: 320px;
	max-height: none;
	height: min(58vh, 520px);
	aspect-ratio: auto;
	border-radius: 16px;
	background-color: #ffffff;
	box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.08);
}

/* Hide legacy canvas loading while skeleton is active */
.cpbpwc-designer-skeleton.cpbpwc-skeleton-active ~ #product-designer .canvas_loading,
.cpbpwc-main-designer-container:has(.cpbpwc-designer-skeleton.cpbpwc-skeleton-active) .canvas_loading,
.cpbpwc-designer-shell:has(.cpbpwc-designer-skeleton.cpbpwc-skeleton-active) .canvas_loading {
	display: none;
}

#product-designer .canvas_loading {
	background: #f8fafc;
	color: transparent;
}

@media (max-width: 782px) {
	.cpbpwc-builder-skeleton__shell {
		grid-template-columns: 64px minmax(0, 1fr);
		grid-template-rows: auto minmax(0, 1fr) auto;
	}

	.cpbpwc-builder-skeleton__thumb,
	.cpbpwc-builder-skeleton__asset {
		max-width: 52px;
	}

	.cpbpwc-builder-skeleton__assets {
		grid-template-columns: repeat(4, minmax(0, 1fr));
		gap: 6px;
	}

	.cpbpwc-builder-skeleton__icon {
		width: 36px;
		height: 36px;
	}

	.cpbpwc-builder-skeleton__preview {
		min-height: 160px;
	}

	.cpbpwc-main-designer-container.cpbpwc-shell-ready:not(.cpbpwc-designer-ready),
	.cpbpwc-designer-shell.cpbpwc-shell-ready:not(.cpbpwc-designer-ready) {
		min-height: 520px;
	}

	.cpbpwc-builder-skeleton__shell--advance {
		grid-template-columns: 72px minmax(0, 1fr);
		grid-template-areas:
			"rail stage"
			"panel panel";
		min-height: calc(100vh - 90px);
	}

	.cpbpwc-builder-skeleton__rail-item {
		width: 52px;
		height: 48px;
	}

	.cpbpwc-builder-skeleton__panel {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		padding: 12px;
		max-height: 160px;
	}

	.cpbpwc-builder-skeleton__panel-card {
		height: 72px;
	}

	.cpbpwc-builder-skeleton__stage {
		padding: 16px;
	}

	.cpbpwc-designer-skeleton--advance .cpbpwc-builder-skeleton__preview {
		height: min(42vh, 280px);
		min-height: 180px;
	}
}
