/**
 * WooSpatial — public viewer page styles.
 *
 * Color schemes:
 *   .scheme-dark  → dark background, white text, green accent (#00ff88)
 *   .scheme-light → light background, dark text, blue accent (#0066ff)
 *   .scheme-auto  → follows the device via prefers-color-scheme
 *
 * @package WooSpatial
 */

/* -------------------------------------------------------------------------- */
/* Theme variables                                                            */
/* -------------------------------------------------------------------------- */

:root {
	--ar-bg: #0a0a0a;
	--ar-surface: #161616;
	--ar-text: #ffffff;
	--ar-text-muted: rgba(255, 255, 255, 0.65);
	--ar-accent: #00ff88;
	--ar-accent-text: #00120a;
	--ar-border: rgba(255, 255, 255, 0.12);
	--ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Explicit dark scheme */
.scheme-dark {
	--ar-bg: #0a0a0a;
	--ar-surface: #161616;
	--ar-text: #ffffff;
	--ar-text-muted: rgba(255, 255, 255, 0.65);
	--ar-accent: #00ff88;
	--ar-accent-text: #00120a;
	--ar-border: rgba(255, 255, 255, 0.12);
	--ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Explicit light scheme */
.scheme-light {
	--ar-bg: #f5f5f5;
	--ar-surface: #ffffff;
	--ar-text: #111111;
	--ar-text-muted: rgba(17, 17, 17, 0.6);
	--ar-accent: #0066ff;
	--ar-accent-text: #ffffff;
	--ar-border: rgba(0, 0, 0, 0.1);
	--ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* Auto scheme: light by default, dark when the device prefers it */
.scheme-auto {
	--ar-bg: #f5f5f5;
	--ar-surface: #ffffff;
	--ar-text: #111111;
	--ar-text-muted: rgba(17, 17, 17, 0.6);
	--ar-accent: #0066ff;
	--ar-accent-text: #ffffff;
	--ar-border: rgba(0, 0, 0, 0.1);
	--ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
	.scheme-auto {
		--ar-bg: #0a0a0a;
		--ar-surface: #161616;
		--ar-text: #ffffff;
		--ar-text-muted: rgba(255, 255, 255, 0.65);
		--ar-accent: #00ff88;
		--ar-accent-text: #00120a;
		--ar-border: rgba(255, 255, 255, 0.12);
		--ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
	}
}

/* -------------------------------------------------------------------------- */
/* Layout                                                                     */
/* -------------------------------------------------------------------------- */

* {
	box-sizing: border-box;
}

html,
body.ar-viewer-body {
	margin: 0;
	padding: 0;
	min-height: 100%;
}

body.ar-viewer-body {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
	background: var(--ar-bg);
	color: var(--ar-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

.ar-header {
	padding: 20px 20px 8px;
	text-align: center;
}

.ar-title {
	margin: 0;
	font-size: clamp(20px, 5vw, 28px);
	font-weight: 700;
	line-height: 1.2;
}

.ar-description {
	margin: 8px auto 0;
	max-width: 640px;
	font-size: 15px;
	line-height: 1.5;
	color: var(--ar-text-muted);
}

.ar-stage {
	position: relative;
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	padding: 12px 16px 0;
	min-height: 0;
}

#ar-model-viewer {
	width: 100%;
	flex: 1 1 auto;
	min-height: 60vh;
	height: 70vh;
	background: var(--ar-surface);
	border: 1px solid var(--ar-border);
	border-radius: 16px;
	box-shadow: var(--ar-shadow);
	--poster-color: transparent;
	--progress-bar-color: var(--ar-accent);
	--progress-bar-height: 0px;
}

/* -------------------------------------------------------------------------- */
/* AR button                                                                  */
/* -------------------------------------------------------------------------- */

.ar-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 52px;
	padding: 0 26px;
	border: none;
	border-radius: 999px;
	background: var(--ar-accent);
	color: var(--ar-accent-text);
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
	transition: transform 0.12s ease, filter 0.12s ease;
	-webkit-tap-highlight-color: transparent;
}

.ar-button:hover,
.ar-button:focus-visible {
	filter: brightness(1.05);
	outline: none;
}

.ar-button:active {
	transform: scale(0.97);
}

/* The AR CTA floats over the model-viewer, centered near the bottom. */
.ar-cta {
	position: absolute;
	left: 50%;
	bottom: 22px;
	transform: translateX(-50%);
	z-index: 5;
}

.ar-cta:active {
	transform: translateX(-50%) scale(0.97);
}

.ar-button-icon {
	font-size: 18px;
}

/* Hide the AR button when the device can't do AR (set by JS). */
.ar-viewer-body.ar-unsupported .ar-cta {
	display: none;
}

/* -------------------------------------------------------------------------- */
/* Loading / progress                                                         */
/* -------------------------------------------------------------------------- */

.ar-progress {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	background: var(--ar-surface);
	border-radius: 16px;
	transition: opacity 0.3s ease;
}

/* model-viewer hides the progress-bar slot automatically when finished. */
.ar-progress-track {
	width: min(60%, 240px);
	height: 6px;
	border-radius: 999px;
	background: var(--ar-border);
	overflow: hidden;
}

.ar-progress-fill {
	width: 0%;
	height: 100%;
	border-radius: 999px;
	background: var(--ar-accent);
	transition: width 0.2s ease;
}

.ar-progress-label {
	font-size: 13px;
	color: var(--ar-text-muted);
	letter-spacing: 0.02em;
}

/* -------------------------------------------------------------------------- */
/* Load error state                                                           */
/* -------------------------------------------------------------------------- */

.ar-load-error {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	text-align: center;
	background: var(--ar-surface);
	border-radius: 16px;
	color: var(--ar-text);
}

.ar-load-error[hidden] {
	display: none;
}

/* -------------------------------------------------------------------------- */
/* Hints + footer                                                             */
/* -------------------------------------------------------------------------- */

.ar-hint {
	margin: 12px 0 0;
	text-align: center;
	font-size: 13px;
	color: var(--ar-text-muted);
}

.ar-hint-mobile {
	display: none;
}

@media (hover: none) and (pointer: coarse) {
	.ar-hint-desktop {
		display: none;
	}
	.ar-hint-mobile {
		display: inline;
	}
}

.ar-footer {
	padding: 16px;
	text-align: center;
}

.ar-footer-link {
	font-size: 13px;
	color: var(--ar-text-muted);
	text-decoration: none;
}

.ar-footer-link:hover {
	color: var(--ar-text);
}

/* -------------------------------------------------------------------------- */
/* Standalone error page                                                      */
/* -------------------------------------------------------------------------- */

.ar-viewer-error-body {
	align-items: center;
	justify-content: center;
}

.ar-error-state {
	text-align: center;
	padding: 32px 24px;
	max-width: 420px;
}

.ar-error-icon {
	font-size: 56px;
	margin-bottom: 12px;
}

.ar-error-state h1 {
	font-size: 20px;
	font-weight: 600;
	margin: 0 0 20px;
	line-height: 1.4;
}

/* -------------------------------------------------------------------------- */
/* Small screens                                                              */
/* -------------------------------------------------------------------------- */

@media (max-width: 480px) {
	#ar-model-viewer {
		height: 64vh;
		border-radius: 14px;
	}
	.ar-header {
		padding: 16px 16px 4px;
	}
}

/* -------------------------------------------------------------------------- */
/* WooCommerce product-page AR section                                        */
/* -------------------------------------------------------------------------- */
/*
 * This block styles the customer-facing section injected on WooCommerce single
 * product pages. It is theme-agnostic: it inherits the theme's font/colors and
 * only adds a light card. The "View in AR" button reuses WooCommerce's own
 * button variables (with sensible fallbacks) so it matches the store theme.
 */

.ar-viewer-product-section {
	margin: 2em 0;
	padding: 24px 20px;
	text-align: center;
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 12px;
	background: rgba(0, 0, 0, 0.02);
	box-sizing: border-box;
}

.ar-viewer-product-heading {
	margin: 0 0 14px;
	font-size: 1.15em;
	font-weight: 600;
	line-height: 1.3;
}

.ar-viewer-product-qr {
	margin: 0 auto 12px;
	line-height: 0;
}

.ar-viewer-product-qr img {
	display: inline-block;
	width: 200px;
	height: 200px;
	max-width: 100%;
	height: auto;
	border-radius: 8px;
	background: #fff;
	padding: 8px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.ar-viewer-product-caption {
	margin: 0 0 16px;
	font-size: 0.9em;
	opacity: 0.75;
	line-height: 1.5;
}

/* CTA — reuses WooCommerce button vars with neutral fallbacks. */
.ar-viewer-product-button.button,
.ar-viewer-product-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 48px;
	padding: 0 24px;
	border: none;
	border-radius: 6px;
	font-size: 1em;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	background: var(--wc-form-border-color, #2271b1);
	background: var(--wc-primary, #2271b1);
	color: var(--wc-primary-text, #ffffff);
	-webkit-tap-highlight-color: transparent;
	transition: filter 0.12s ease, transform 0.12s ease;
}

.ar-viewer-product-button:hover,
.ar-viewer-product-button:focus {
	filter: brightness(1.06);
	color: var(--wc-primary-text, #ffffff);
}

.ar-viewer-product-button:active {
	transform: scale(0.98);
}

/* Coming-soon variant. */
.ar-viewer-product-coming-soon {
	background: rgba(0, 0, 0, 0.03);
}

.ar-viewer-product-coming-soon p {
	margin: 0;
	font-size: 0.95em;
	opacity: 0.8;
}

@media (max-width: 480px) {
	.ar-viewer-product-section {
		padding: 20px 16px;
	}
	.ar-viewer-product-button {
		width: 100%;
	}
}

/* -------------------------------------------------------------------------- */
/* Product-page buttons (3D View / AR View)                                   */
/* -------------------------------------------------------------------------- */
/*
 * Colors come from the admin settings via inline CSS variables on the wrapper:
 *   --ar-btn-color, --ar-btn-text-color (with neutral fallbacks here).
 */

.ar-viewer-buttons {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin: 1.5em 0;
}

.ar-viewer-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 48px;
	padding: 0 22px;
	border: none;
	border-radius: 6px;
	font-size: 1em;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	background: var(--ar-btn-color, #111111);
	color: var(--ar-btn-text-color, #ffffff);
	-webkit-tap-highlight-color: transparent;
	transition: filter 0.12s ease, transform 0.12s ease;
}

.ar-viewer-btn:hover,
.ar-viewer-btn:focus {
	filter: brightness(1.1);
	color: var(--ar-btn-text-color, #ffffff);
}

.ar-viewer-btn:active {
	transform: scale(0.98);
}

.ar-btn-icon {
	font-size: 1.1em;
	line-height: 1;
}

/* -------------------------------------------------------------------------- */
/* Modals (3D modal + QR popup)                                               */
/* -------------------------------------------------------------------------- */

body.ar-modal-open {
	overflow: hidden;
}

.ar-viewer-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

.ar-viewer-modal.is-open {
	display: flex;
}

.ar-modal-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.7);
	-webkit-backdrop-filter: blur(2px);
	backdrop-filter: blur(2px);
	animation: ar-fade-in 0.2s ease;
}

.ar-modal-content {
	position: relative;
	z-index: 1;
	width: 100%;
	max-width: 880px;
	max-height: 92vh;
	overflow: auto;
	background: #ffffff;
	color: #111111;
	border-radius: 14px;
	padding: 20px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
	animation: ar-pop-in 0.22s ease;
}

@media (prefers-color-scheme: dark) {
	.ar-modal-content {
		background: #1b1b1b;
		color: #f2f2f2;
	}

	/* Keep the QR heading visible on the dark modal background (themes often
	   force a fixed dark colour on h3, so override with specificity + !important). */
	.ar-viewer-modal .ar-qr-content h3 {
		color:  #f2f2f2 !important;
	}
}

/* Full-screen 3D modal (scoped so the QR popup stays a small centered card). */
.ar-viewer-modal--full {
	padding: 0;
}

.ar-viewer-modal--full .ar-modal-content {
	width: 100vw;
	height: 100vh;
	height: 100dvh; /* fills around mobile browser chrome where supported */
	max-width: none;
	max-height: none;
	border-radius: 0;
	padding: 0;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.ar-viewer-modal--full .ar-modal-title {
	flex: 0 0 auto;
	margin: 0;
	padding: 16px 56px 12px 20px;
}

/* The stage holds the model-viewer and the loader overlay, filling the modal. */
.ar-modal-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
}

.ar-modal-close {
	position: absolute;
	top: 10px;
	right: 12px;
	width: 36px;
	height: 36px;
	border: none;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.06);
	color: inherit;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	transition: background 0.12s ease;
}

.ar-modal-close:hover,
.ar-modal-close:focus {
	background: rgba(0, 0, 0, 0.14);
	outline: none;
}

.ar-modal-title {
	margin: 4px 40px 14px 4px;
	font-size: 1.2em;
	font-weight: 700;
	line-height: 1.3;
}

#ar-modal-model-viewer {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	background: #f3f3f3;
	border-radius: 0;
	--poster-color: transparent;
	--progress-bar-color: var(--ar-btn-color, #111111);
}

@media (prefers-color-scheme: dark) {
	#ar-modal-model-viewer {
		background: #242424;
	}
}

/* In-modal AR button (model-viewer ar-button slot). */
.ar-inline-btn {
	position: absolute;
	left: 50%;
	bottom: 18px;
	transform: translateX(-50%);
	min-height: 46px;
	padding: 0 22px;
	border: none;
	border-radius: 999px;
	font-size: 0.95em;
	font-weight: 700;
	cursor: pointer;
	background: var(--ar-btn-color, #111111);
	color: var(--ar-btn-text-color, #ffffff);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

/* Loading overlay sitting above the model-viewer while it loads. */
.ar-modal-loader {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	background: #f3f3f3;
	opacity: 1;
	visibility: visible;
	transition: opacity 0.35s ease, visibility 0.35s ease;
}

/* Hidden state — fades out smoothly, then stops intercepting interaction. */
.ar-modal-loader.is-hidden {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.ar-modal-loading-text {
	margin: 0;
	font-size: 13px;
	letter-spacing: 0.02em;
	color: #50575e;
}

@media (prefers-color-scheme: dark) {
	.ar-modal-loader {
		background: #242424;
	}
	.ar-modal-loading-text {
		color: rgba(255, 255, 255, 0.7);
	}
}

.ar-modal-spinner {
	width: 42px;
	height: 42px;
	border: 4px solid rgba(0, 0, 0, 0.15);
	border-top-color: var(--ar-btn-color, #111111);
	border-radius: 50%;
	animation: ar-spin 0.8s linear infinite;
}

@media (prefers-color-scheme: dark) {
	.ar-modal-spinner {
		border-color: rgba(255, 255, 255, 0.2);
		border-top-color: var(--ar-btn-text-color, #ffffff);
	}
}

/* -------------------------------------------------------------------------- */
/* QR popup                                                                   */
/* -------------------------------------------------------------------------- */

.ar-qr-content {
	max-width: 360px;
	text-align: center;
}

.ar-viewer-modal .ar-qr-content h3 {
	margin: 4px 24px 16px;
	font-size: 1.15em;
	/* Higher specificity + !important so a theme's global h3 colour (often set
	   with high specificity or !important) can't override it and leave the
	   heading invisible against the modal background. Flips with dark mode below. */
	color: #111111 ;
}

.ar-qr-desktop img {
	display: block;
	width: 220px;
	height: 220px;
	max-width: 100%;
	margin: 0 auto 12px;
	padding: 8px;
	background: #ffffff;
	border-radius: 10px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.ar-qr-desktop p,
.ar-qr-mobile p {
	margin: 0 0 12px;
	font-size: 0.92em;
	opacity: 0.8;
}

.ar-qr-mobile .ar-viewer-btn {
	width: 100%;
}

/* -------------------------------------------------------------------------- */
/* Animations                                                                 */
/* -------------------------------------------------------------------------- */

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

@keyframes ar-fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes ar-pop-in {
	from { opacity: 0; transform: translateY(12px) scale(0.98); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 600px) {
	/* The QR popup card only — the 3D modal is full-screen on all sizes. */
	.ar-viewer-modal:not(.ar-viewer-modal--full) .ar-modal-content {
		padding: 16px;
		border-radius: 12px;
	}
	.ar-viewer-btn {
		flex: 1 1 auto;
	}
}
