/* Material Surface Visualizer – Frontend Styles */

.msv-visualizer {
	font-family: inherit;
	color: inherit;
	box-sizing: border-box;
}

.msv-visualizer *,
.msv-visualizer *::before,
.msv-visualizer *::after {
	box-sizing: inherit;
}

/* ---- Loading & Error ---- */
.msv-loading {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 24px 0;
	color: #666;
}

.msv-spinner {
	display: inline-block;
	width: 20px;
	height: 20px;
	border: 3px solid #ddd;
	border-top-color: #0073aa;
	border-radius: 50%;
	animation: msv-spin 0.7s linear infinite;
}

@keyframes msv-spin {
	to { transform: rotate(360deg); }
}

.msv-error {
	padding: 12px 16px;
	background: #fff0f0;
	border-left: 4px solid #cc1818;
	border-radius: 4px;
	color: #cc1818;
	margin: 8px 0;
}

/* ---- Layout ---- */
.msv-layout {
	display: flex;
	flex-wrap: wrap;
	gap: 20px;
	align-items: flex-start;
}

.msv-canvas-area {
	position: relative;
	flex: 1 1 360px;
	min-width: 0;
	max-width: 100%;
}

.msv-canvas {
	display: block;
	max-width: 100%;
	height: auto;
	border-radius: 6px;
	box-shadow: 0 2px 12px rgba(0,0,0,.12);
	cursor: crosshair;
}

.msv-svg-overlay {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.msv-svg-overlay polygon {
	fill: transparent;
	stroke: none;
	pointer-events: fill;
	cursor: pointer;
	transition: fill 0.2s ease;
}

.msv-svg-overlay polygon:hover {
	fill: rgba(255, 255, 255, 0.12);
}

.msv-svg-overlay polygon.msv-active {
	fill: rgba(255, 255, 255, 0.08);
}

/* ---- Panel ---- */
.msv-panel {
	flex: 0 0 280px;
	min-width: 240px;
	max-width: 100%;
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.msv-section {
	background: #fafafa;
	border: 1px solid #eee;
	border-radius: 6px;
	padding: 14px 16px;
}

.msv-label {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: #888;
	margin-bottom: 8px;
}

/* Surface select */
.msv-surface-select {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid #ddd;
	border-radius: 4px;
	font-size: 14px;
	background: #fff;
	cursor: pointer;
}

/* Group tabs */
.msv-group-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-bottom: 10px;
}

.msv-group-tab {
	padding: 4px 10px;
	border: 1px solid #ddd;
	border-radius: 20px;
	font-size: 12px;
	background: #fff;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
}

.msv-group-tab:hover,
.msv-group-tab.msv-active {
	background: #0073aa;
	color: #fff;
	border-color: #0073aa;
}

/* Material grid */
.msv-material-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
	gap: 6px;
	max-height: 240px;
	overflow-y: auto;
	padding-right: 4px;
}

.msv-material-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	cursor: pointer;
	border: 2px solid transparent;
	border-radius: 6px;
	padding: 4px;
	transition: border-color 0.15s;
	list-style: none;
}

.msv-material-item:hover {
	border-color: #0073aa;
}

.msv-material-item.msv-selected {
	border-color: #0073aa;
	background: #f0f7fb;
}

.msv-material-swatch {
	width: 48px;
	height: 48px;
	border-radius: 4px;
	object-fit: cover;
	border: 1px solid #e0e0e0;
	display: block;
}

.msv-material-name {
	font-size: 10px;
	text-align: center;
	margin-top: 3px;
	word-break: break-word;
	color: #555;
	line-height: 1.2;
}

/* Custom colour */
.msv-custom-color-wrap {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid #eee;
}

.msv-custom-color-label {
	display: flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
	font-size: 13px;
}

.msv-custom-color-input {
	width: 32px;
	height: 32px;
	padding: 0;
	border: 1px solid #ddd;
	border-radius: 4px;
	cursor: pointer;
}

/* Upload */
.msv-upload-wrap {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid #eee;
}

.msv-upload-label {
	display: inline-block;
	cursor: pointer;
	font-size: 13px;
}

/* Selected info */
.msv-selected-info {
	background: #f0f7fb;
	border: 1px solid #b8d8e8;
	border-radius: 6px;
	padding: 14px 16px;
}

.msv-selected-detail {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 10px;
}

.msv-selected-swatch {
	width: 36px;
	height: 36px;
	border-radius: 4px;
	border: 1px solid #ddd;
	flex-shrink: 0;
	display: block;
	overflow: hidden;
}

.msv-selected-swatch img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.msv-selected-text {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.msv-selected-name {
	font-size: 14px;
	font-weight: 600;
}

.msv-selected-sku {
	font-size: 11px;
	color: #888;
}

.msv-product-link {
	font-size: 12px;
	text-decoration: none;
}

/* Actions */
.msv-actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.msv-actions .button {
	flex: 1 1 auto;
	text-align: center;
	padding: 10px 16px;
	font-size: 14px;
	border-radius: 4px;
	cursor: pointer;
	text-decoration: none;
}

/* ---- Canvas loading overlay (room switch) ---- */
.msv-canvas-loading {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.42);
	border-radius: 6px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	color: #fff;
	font-size: 15px;
	font-weight: 500;
	letter-spacing: 0.02em;
	z-index: 20;
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
}

.msv-canvas-spinner {
	display: block;
	width: 44px;
	height: 44px;
	border: 4px solid rgba(255, 255, 255, 0.3);
	border-top-color: #fff;
	border-radius: 50%;
	animation: msv-spin 0.7s linear infinite;
}

/* ---- Room Selector ---- */
.msv-room-selector {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 25;
	font-family: inherit;
}

.msv-room-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 9px 14px;
	background: #fff;
	border: none;
	border-radius: 6px;
	box-shadow: 0 2px 12px rgba(0,0,0,.18);
	cursor: pointer;
	font-size: 15px;
	font-weight: 600;
	color: #1a1a1a;
	white-space: nowrap;
	transition: box-shadow 0.15s;
}

.msv-room-btn:hover {
	box-shadow: 0 4px 18px rgba(0,0,0,.22);
}

.msv-room-btn:disabled,
.msv-room-btn[aria-disabled="true"] {
	opacity: 0.6;
	cursor: not-allowed;
}

.msv-room-chevron {
	flex-shrink: 0;
	transition: transform 0.2s;
}

.msv-room-btn[aria-expanded="true"] .msv-room-chevron {
	transform: rotate(180deg);
}

.msv-room-dropdown {
	display: none;
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	min-width: 200px;
	background: #fff;
	border-radius: 8px;
	box-shadow: 0 6px 24px rgba(0,0,0,.18);
	list-style: none;
	margin: 0;
	padding: 6px 0;
	overflow: hidden;
}

.msv-room-dropdown.msv-room-open {
	display: block;
}

.msv-room-option {
	padding: 10px 16px;
	cursor: pointer;
	transition: background 0.12s;
	line-height: 1.3;
}

.msv-room-option:hover {
	background: #f5f5f5;
}

.msv-room-option.msv-room-active .msv-room-option-name {
	color: #b5451b;
	font-weight: 700;
}

.msv-room-option-name {
	display: block;
	font-size: 15px;
	font-weight: 600;
	color: #1a1a1a;
}

.msv-room-option-sub {
	display: block;
	font-size: 12px;
	color: #888;
	margin-top: 2px;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
	.msv-layout {
		flex-direction: column;
	}
	.msv-panel {
		flex: 1 1 100%;
		max-width: 100%;
	}
	.msv-material-grid {
		max-height: 160px;
	}
	/* Larger touch targets for mobile polygon clicks */
	.msv-svg-overlay polygon {
		pointer-events: fill;
	}
}
