/* ==========================================================================
   TRÌNH GIẢ LẬP 3D & AR STUDIO (3D AR SIMULATOR)
   Tối ưu hóa hiển thị 100% không bị cắt xén trên điện thoại và mọi màn hình
   ========================================================================== */

/* 1. KHUNG CHỨA TOÀN BỘ MODAL GIẢ LẬP */
.ar-sim-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	z-index: 2147483646;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 20px;
	box-sizing: border-box;
	user-select: none;
	-webkit-user-select: none;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Đảm bảo luôn nổi trên cùng khi bật Fullscreen */
:fullscreen .ar-sim-modal,
:-webkit-full-screen .ar-sim-modal,
:-moz-full-screen .ar-sim-modal,
:-ms-fullscreen .ar-sim-modal {
	position: fixed !important;
	top: 0 !important;
	left: 0 !important;
	width: 100vw !important;
	height: 100vh !important;
	z-index: 2147483647 !important;
	display: flex !important;
}

.ar-sim-modal.active {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

.ar-sim-backdrop {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(8, 14, 26, 0.85);
	backdrop-filter: blur(16px);
	-webkit-backdrop-filter: blur(16px);
}

/* 2. CỬA SỔ GIẢ LẬP 3D (3D STUDIO WINDOW) */
.ar-sim-window {
	position: relative;
	width: 90vw;
	max-width: 90vw;
	height: 90vh;
	height: 90dvh;
	max-height: 90vh;
	max-height: 90dvh;
	min-height: 480px;
	background: linear-gradient(155deg, rgba(26, 36, 56, 0.97), rgba(12, 19, 34, 0.99));
	border: 1px solid rgba(255, 255, 255, 0.18);
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8), 0 0 40px rgba(14, 165, 233, 0.25);
	border-radius: 22px;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform: scale(0.92) translateY(16px);
	transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
	z-index: 2;
}

.ar-sim-modal.active .ar-sim-window {
	transform: scale(1) translateY(0);
}

/* 3. THANH TIÊU ĐỀ (HEADER) */
.ar-sim-header {
	padding: 14px 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid rgba(255, 255, 255, 0.1);
	background: rgba(15, 23, 42, 0.45);
	flex-shrink: 0;
}

.ar-sim-title-box {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.ar-sim-badge {
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.8px;
	color: #38bdf8;
	background: rgba(14, 165, 233, 0.18);
	border: 1px solid rgba(56, 189, 248, 0.4);
	padding: 3px 8px;
	border-radius: 20px;
	flex-shrink: 0;
}

.ar-sim-title {
	margin: 0;
	font-size: 15.5px;
	font-weight: 600;
	color: #f8fafc;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ar-sim-header-actions {
	display: flex;
	gap: 8px;
	flex-shrink: 0;
}

.ar-sim-icon-btn {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: #cbd5e1;
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
	transition: all 0.25s ease;
	outline: none;
}

.ar-sim-icon-btn:hover {
	background: rgba(56, 189, 248, 0.25);
	color: #38bdf8;
	border-color: #38bdf8;
}

.ar-sim-close-btn:hover {
	background: #ef4444;
	color: #ffffff;
	border-color: #ef4444;
	transform: rotate(90deg);
}

/* 4. KHUNG XEM 3D (VIEWPORT) */
.ar-sim-viewport {
	position: relative;
	flex: 1;
	min-height: 0; /* Cực kỳ quan trọng để flex item không bị tràn ra ngoài màn hình */
	width: 100%;
	height: 100%;
	background: radial-gradient(circle at 50% 40%, rgba(30, 41, 59, 0.75) 0%, rgba(10, 15, 29, 0.98) 100%);
	overflow: hidden;
	display: flex;
	justify-content: center;
	align-items: center;
}

#ar-sim-model-viewer {
	width: 100% !important;
	height: 100% !important;
	min-height: 100% !important;
	background: transparent;
	--poster-color: transparent;
	outline: none;
	display: block;
}

/* Poster loading */
.ar-sim-poster {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	width: 100%;
	height: 100%;
}

.ar-sim-spinner {
	width: 38px;
	height: 38px;
	border: 3.5px solid rgba(56, 189, 248, 0.2);
	border-top-color: #38bdf8;
	border-radius: 50%;
	animation: arSimSpin 0.8s linear infinite;
}

@keyframes arSimSpin {
	to { transform: rotate(360deg); }
}

/* Gợi ý tương tác (Hint) */
.ar-sim-hint {
	position: absolute;
	top: 14px;
	left: 50%;
	transform: translateX(-50%);
	background: rgba(15, 23, 42, 0.8);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: #cbd5e1;
	font-size: 11.5px;
	padding: 4px 12px;
	border-radius: 20px;
	pointer-events: none;
	box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
	white-space: nowrap;
	z-index: 5;
}

/* 5. LỚP PHỦ MÃ QR (QR OVERLAY) */
.ar-sim-qr-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(10, 15, 29, 0.94);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	display: none;
	justify-content: center;
	align-items: center;
	padding: 16px;
	box-sizing: border-box;
	z-index: 10;
}

.ar-sim-qr-overlay.active {
	display: flex;
}

.ar-sim-qr-card {
	text-align: center;
	max-width: 340px;
	width: 100%;
}

.ar-sim-qr-back-btn {
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(255, 255, 255, 0.15);
	color: #cbd5e1;
	font-size: 12px;
	padding: 5px 14px;
	border-radius: 16px;
	cursor: pointer;
	margin-bottom: 10px;
	transition: all 0.2s ease;
	outline: none;
}

.ar-sim-qr-back-btn:hover {
	background: rgba(56, 189, 248, 0.2);
	color: #38bdf8;
	border-color: #38bdf8;
}

.ar-sim-qr-img-box {
	position: relative;
	display: inline-block;
	background: #ffffff;
	padding: 8px;
	border-radius: 14px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 25px rgba(56, 189, 248, 0.3);
	margin: 8px 0;
	overflow: hidden;
}

.ar-sim-qr-img-box img {
	width: 160px;
	height: 160px;
	display: block;
	border-radius: 6px;
}

.ar-sim-qr-laser {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 3px;
	background: linear-gradient(90deg, transparent, #38bdf8, #0284c7, transparent);
	box-shadow: 0 0 10px #38bdf8;
	animation: arQrLaser 2.4s ease-in-out infinite;
}

@keyframes arQrLaser {
	0%, 100% { top: 6px; opacity: 0.3; }
	50% { top: calc(100% - 6px); opacity: 1; }
}

.ar-sim-qr-note {
	font-size: 11.5px;
	color: #38bdf8;
	margin-top: 4px;
}

/* 6. THANH CÔNG CỤ DƯỚI CÙNG (TOOLBAR) */
.ar-sim-toolbar {
	padding: 10px 16px;
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 8px;
	background: rgba(15, 23, 42, 0.65);
	border-top: 1px solid rgba(255, 255, 255, 0.1);
	flex-wrap: wrap;
	flex-shrink: 0;
}

.ar-sim-tool-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: #cbd5e1;
	font-size: 12px;
	font-weight: 500;
	padding: 7px 12px;
	border-radius: 10px;
	cursor: pointer;
	transition: all 0.2s ease;
	outline: none;
	white-space: nowrap;
}

.ar-sim-tool-btn:hover {
	background: rgba(255, 255, 255, 0.12);
	border-color: rgba(255, 255, 255, 0.25);
	color: #ffffff;
	transform: translateY(-2px);
}

.ar-sim-tool-btn.is-active {
	background: rgba(14, 165, 233, 0.25);
	border-color: #38bdf8;
	color: #38bdf8;
	box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
}

.ar-sim-tool-highlight {
	background: linear-gradient(135deg, #0284c7, #0369a1) !important;
	border-color: rgba(56, 189, 248, 0.6) !important;
	color: #ffffff !important;
	box-shadow: 0 4px 15px rgba(2, 132, 199, 0.45), 0 0 20px rgba(56, 189, 248, 0.3) !important;
	font-weight: 600;
}

.ar-sim-tool-highlight:hover {
	background: linear-gradient(135deg, #0ea5e9, #0284c7) !important;
	box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6), 0 0 25px rgba(56, 189, 248, 0.5) !important;
	transform: translateY(-2px);
}

/* ==========================================================================
   7. RESPONSIVE TOÀN DIỆN CHO ĐIỆN THOẠI & TABLET (KHÔNG CẮT XÉN)
   ========================================================================== */

/* Tablet & Màn hình vừa (<= 1024px) */
@media screen and (max-width: 1024px) {
	.ar-sim-window {
		width: 94vw;
		max-width: 94vw;
		height: 86vh;
		height: 86dvh;
	}
}

/* Smartphone Portrait (Điện thoại màn hình đứng <= 768px) */
@media screen and (max-width: 768px) {
	.ar-sim-modal {
		padding: 10px;
	}

	.ar-sim-window {
		width: 80vw !important;
		max-width: 80vw !important;
		height: 80vh !important;
		height: 80dvh !important;
		max-height: 80dvh !important;
		min-height: 0 !important;
		border-radius: 18px;
		margin: auto;
	}

	.ar-sim-header {
		padding: 10px 14px;
	}

	.ar-sim-badge {
		font-size: 9px;
		padding: 2px 6px;
	}

	.ar-sim-title {
		font-size: 13.5px;
	}

	.ar-sim-icon-btn {
		width: 30px;
		height: 30px;
	}

	.ar-sim-hint {
		top: 8px;
		font-size: 10px;
		padding: 3px 8px;
		max-width: 85%;
	}

	.ar-sim-toolbar {
		padding: 8px 10px;
		gap: 6px;
		justify-content: center;
	}

	.ar-sim-tool-btn {
		font-size: 11px;
		padding: 6px 9px;
		gap: 4px;
		border-radius: 8px;
	}

	.ar-sim-tool-btn svg {
		width: 14px;
		height: 14px;
	}

	.ar-sim-qr-img-box img {
		width: 130px;
		height: 130px;
	}
}

/* Smartphone Nhỏ (<= 480px) */
@media screen and (max-width: 480px) {
	.ar-sim-modal {
		padding: 8px;
	}

	.ar-sim-window {
		width: 80vw !important;
		max-width: 80vw !important;
		height: 80vh !important;
		height: 80dvh !important;
		max-height: 80dvh !important;
	}

	.ar-sim-badge {
		display: none; /* Ẩn badge để nhường chỗ cho tiêu đề */
	}

	.ar-sim-title {
		font-size: 13px;
	}

	.ar-sim-toolbar {
		padding: 6px 8px;
		gap: 4px;
	}

	.ar-sim-tool-btn {
		font-size: 10px;
		padding: 5px 7px;
	}

	.ar-sim-tool-btn svg {
		width: 13px;
		height: 13px;
	}
}

/* Smartphone Xoay Ngang (Mobile Landscape - max-height: 500px) */
@media screen and (max-height: 500px) and (orientation: landscape) {
	.ar-sim-modal {
		padding: 6px;
	}

	.ar-sim-window {
		width: 96vw !important;
		max-width: 96vw !important;
		height: 96vh !important;
		height: 96dvh !important;
		max-height: 96dvh !important;
		min-height: 0 !important;
		border-radius: 14px;
	}

	.ar-sim-header {
		padding: 6px 12px;
	}

	.ar-sim-title {
		font-size: 12px;
	}

	.ar-sim-badge {
		display: none;
	}

	.ar-sim-icon-btn {
		width: 26px;
		height: 26px;
	}

	.ar-sim-hint {
		display: none; /* Ẩn hint ở màn hình ngang để nhìn rõ mô hình */
	}

	.ar-sim-toolbar {
		padding: 4px 8px;
		gap: 4px;
	}

	.ar-sim-tool-btn {
		font-size: 10px;
		padding: 4px 7px;
		gap: 3px;
	}

	.ar-sim-tool-btn svg {
		width: 12px;
		height: 12px;
	}

	.ar-sim-qr-img-box img {
		width: 100px;
		height: 100px;
	}

	.ar-sim-qr-card h4 {
		font-size: 14px;
		margin: 4px 0;
	}

	.ar-sim-qr-card p {
		display: none;
	}
}
