.wp-block-wlc-algolia-search-page-v2-editor {
	border: 1px solid #ddd;
	border-radius: 8px;
	background: #fff;
	overflow: hidden;
}

.wp-block-wlc-algolia-search-page-v2__editor-wrapper {
	padding: 20px;
}

.wp-block-wlc-algolia-search-page-v2__editor-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 16px;
	margin-bottom: 20px;
	padding-bottom: 16px;
	border-bottom: 1px solid #e0e0e0;
}

.wp-block-wlc-algolia-search-page-v2__editor-title {
	margin: 0 0 8px 0;
	font-size: 16px;
	font-weight: 600;
	color: #1e1e1e;
}

.wp-block-wlc-algolia-search-page-v2__editor-description {
	margin: 0;
	font-size: 13px;
	color: #757575;
	line-height: 1.5;
}

.wp-block-wlc-algolia-search-page-v2__editor-post-type {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: #757575;
	white-space: nowrap;

	strong {
		color: #1e1e1e;
		font-weight: 600;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-layout {
	display: grid;
	grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
	gap: 20px;
	min-width: 0;

	// When filters sidebar is enabled, always reserve the first column.
	// Keep a structural :has() fallback so existing compiled assets without the class still align.
	&.has-filters-sidebar,
	&:has(> .wp-block-wlc-algolia-search-page-v2__editor-panel:nth-child(3)) {
		grid-template-columns: minmax(0, 280px) minmax(0, 340px) minmax(0, 1fr);
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-panel {
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	background: #fafafa;
	padding: 16px;
	min-width: 0;
	overflow: hidden;
}

.wp-block-wlc-algolia-search-page-v2__editor-panel-title {
	margin: 0 0 12px 0;
	font-size: 14px;
	font-weight: 600;
	color: #1e1e1e;
}

.wp-block-wlc-algolia-search-page-v2__editor-search {
	margin-bottom: 12px;
}

.wp-block-wlc-algolia-search-page-v2__editor-search-input {
	width: 100%;
	padding: 8px 12px;
	border: 1px solid #ddd;
	border-radius: 4px;
	font-size: 13px;
	background: #fff;
	transition: border-color 0.15s ease;

	&:focus {
		outline: none;
		border-color: #0073aa;
		box-shadow: 0 0 0 1px #0073aa;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-hint {
	font-size: 12px;
	color: #757575;
	margin-bottom: 12px;
	line-height: 1.5;
}

.wp-block-wlc-algolia-search-page-v2__editor-field-list {
	max-height: 400px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding-right: 4px;

	&::-webkit-scrollbar {
		width: 6px;
	}

	&::-webkit-scrollbar-track {
		background: transparent;
	}

	&::-webkit-scrollbar-thumb {
		background: #ccc;
		border-radius: 3px;

		&:hover {
			background: #999;
		}
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-field-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 12px;
	border: 1px solid #e0e0e0;
	border-radius: 6px;
	background: #fff;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;

	&:hover {
		border-color: #0073aa;
		box-shadow: 0 1px 3px rgba(0, 115, 170, 0.1);
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-field-info {
	flex: 1;
	min-width: 0;
	overflow: hidden;
}

.wp-block-wlc-algolia-search-page-v2__editor-field-path {
	font-size: 12px;
	font-weight: 600;
	color: #1e1e1e;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	margin-bottom: 4px;
	font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}

.wp-block-wlc-algolia-search-page-v2__editor-field-sample {
	font-size: 11px;
	color: #757575;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}

.wp-block-wlc-algolia-search-page-v2__editor-template {
	border-radius: 8px;
	background: #fafafa;
	padding: 16px;

	// Ensure InnerBlocks container is visible
	.block-editor-inner-blocks {
		width: 100%;
		min-height: 100px;
	}

	.block-editor-block-list__layout {
		display: flex;
		flex-direction: column;
		gap: 8px;
		min-height: 50px;
		padding-bottom: 8px; // Add padding to prevent overlap
	}

	// Hide rendered inner blocks in this panel (we manage them via the custom template list UI).
	// Keep only the inserter/appender visible.
	.block-editor-block-list__layout > *:not(.block-list-appender) {
		display: none !important;
	}

	.block-editor-block-list__layout > .block-list-appender {
		display: block;
	}

	// Block appender button - make it very visible and ensure it doesn't overlap
	.block-list-appender {
		width: 100%;
		margin-top: 16px !important; // Increased margin to prevent overlap
		position: relative;
		z-index: 0; // Ensure it's below blocks
		
		.block-editor-button-block-appender {
			width: 100% !important;
			display: flex !important;
			justify-content: center !important;
			align-items: center !important;
			border: 2px dashed #0073aa !important;
			border-radius: 4px !important;
			padding: 16px !important;
			background: #fff !important;
			color: #0073aa !important;
			font-size: 14px !important;
			font-weight: 500 !important;
			cursor: pointer !important;
			transition: all 0.15s ease !important;
			min-height: 48px !important;
			position: relative !important; // Ensure proper positioning
			margin: 0 !important; // Remove any default margins

			&:hover,
			&:focus {
				background: #f0f6fc !important;
				border-color: #005177 !important;
				color: #005177 !important;
				outline: none !important;
				box-shadow: 0 0 0 1px #005177 !important;
			}
		}
	}

	// When empty, make appender more prominent
	.block-editor-block-list__layout:empty + .block-list-appender,
	.block-list-appender:first-child {
		margin-top: 0 !important;
	}

	// Prevent inline block inserter from overlapping
	.block-editor-block-list__layout .wp-block {
		.block-editor-block-list__insertion-point {
			display: none; // Hide inline insertion points to avoid confusion
		}
	}
}

// Force V3 template panel cosmetics even when V2 stylesheets are loaded later.
.wp-block-wlc-algolia-search-page .wp-block-wlc-algolia-search-page-v2__editor-template {
	border: none !important;
	min-height: 0 !important;
}

.wp-block-wlc-algolia-search-page-v2__editor-template-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: 12px;
}

.wp-block-wlc-algolia-search-page-v2__editor-template-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 8px 10px;
	border: 1px solid #e0e0e0;
	border-radius: 6px;
	background: #fff;
	cursor: pointer;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;

	&:hover {
		border-color: #0073aa;
	}

	&:focus {
		outline: none;
		border-color: #0073aa;
		box-shadow: 0 0 0 1px #0073aa;
	}

	&.is-selected {
		border-color: #0073aa;
		background: #f0f6fc;
		box-shadow: 0 0 0 1px #0073aa;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-template-item-info {
	flex: 1;
	min-width: 0;
}

.wp-block-wlc-algolia-search-page-v2__editor-template-item-title {
	font-size: 12px;
	font-weight: 600;
	color: #1e1e1e;
}

.wp-block-wlc-algolia-search-page-v2__editor-template-item-meta {
	font-size: 11px;
	color: #757575;
	font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.wp-block-wlc-algolia-search-page-v2__editor-template-item-actions {
	display: flex;
	align-items: center;
	gap: 6px;
}

// Filters sidebar editor styles
.wp-block-wlc-algolia-search-page-v2__editor-facets-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	min-height: 60px;
	padding: 8px;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	background: #fff;

	&.is-dragging-over {
		background: #f0f6fc;
		border-color: #0073aa;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-facet-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border: 1px solid #e0e0e0;
	border-radius: 6px;
	background: #fff;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;

	&.is-dragging {
		opacity: 0.8;
		box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
		border-color: #0073aa;
	}

	&:hover {
		border-color: #0073aa;
		box-shadow: 0 1px 3px rgba(0, 115, 170, 0.1);
	}

	// Keep remove icon button visible even when not hovered.
	.components-button.is-tertiary.is-destructive.has-icon {
		opacity: 1 !important;
		visibility: visible !important;
		color: #b32d2e !important;
		padding: 0 8px !important;
		min-width: auto !important;
		height: 24px !important;
		gap: 0 !important;

		&:hover,
		&:focus {
			color: #8a2424 !important;
		}

		&::before {
			content: 'Remove';
			font-size: 11px;
			line-height: 1;
			font-weight: 400;
		}
	}

	.components-button.is-tertiary.is-destructive.has-icon .dashicon,
	.components-button.is-tertiary.is-destructive.has-icon .dashicons {
		display: none !important;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-facet-handle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	color: #757575;
	cursor: grab;
	flex-shrink: 0;

	&:active {
		cursor: grabbing;
	}

	svg {
		width: 18px;
		height: 18px;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-facet-content {
	flex: 1;
	min-width: 0;

	.components-text-control__input {
		font-size: 13px;
		font-weight: 500;
		margin-bottom: 4px;
	}
}

.wp-block-wlc-algolia-search-page-v2__editor-facet-attribute {
	font-size: 11px;
	color: #757575;
	font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.wp-block-wlc-algolia-search-page-v2__editor-empty-state {
	padding: 20px;
	text-align: center;
	color: #757575;
	font-size: 13px;
	border: 1px dashed #ddd;
	border-radius: 4px;
	background: #fafafa;
}

// Preview styles
.wp-block-wlc-algolia-search-page__preview-wrapper {
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	background: #fff;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	height: 800px;
	max-height: 80vh;
}

.wp-block-wlc-algolia-search-page__preview-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px 20px;
	border-bottom: 1px solid #e0e0e0;
	background: #f9f9f9;

	h3 {
		margin: 0;
		font-size: 16px;
		font-weight: 600;
		color: #1e1e1e;
	}
}

.wp-block-wlc-algolia-search-page__preview-iframe {
	width: 100%;
	height: 100%;
	border: none;
	flex: 1;
	background: #fff;
}
