/**
 * Visimex 2026 — AI Chatbot widget
 * Màu theo token theme (chrome.css): nâu --vx-brown, cam --vx-orange, kem --vx-cream.
 * Không dùng icon/emoji trong nội dung chat. Ngoại lệ duy nhất: nút mở chat là vòng tròn có biểu tượng khung chat,
 * đặt cùng cột với nút WhatsApp "Contact Us" (.vx-fab trong chrome.css) và có thẻ chữ bên cạnh giống hệt.
 * Ảnh đại diện bot là biểu tượng trang web (Site Icon).
 */

.vx-chatbot {
	--cb-brown: var(--vx-brown, #8b4f2d);
	--cb-brown-dark: var(--vx-brown-heading, #6b3a2a);
	--cb-brown-deep: var(--vx-brown-d, #4a2418);
	--cb-orange: var(--vx-orange, #e8782a);
	--cb-orange-dark: #c45c1c;
	--cb-cream: var(--vx-cream, #f5ede8);
	--cb-paper: #fbf7f3;
	--cb-bubble: #fffdfa;
	--cb-line: #e8dcd1;
	--cb-muted: #8a7466;
	font-family: var(--vx-font-base, 'Roboto', sans-serif);
	color: var(--cb-brown-deep);
}

.vx-chatbot button {
	font-family: inherit;
	cursor: pointer;
}

.vx-chatbot button:focus-visible,
.vx-chatbot__input:focus-visible {
	outline: 2px solid var(--cb-orange);
	outline-offset: 2px;
}

/* ---------- Nút mở: cùng cột với nút WhatsApp .vx-fab ---------- */
/* .vx-fab: right 1rem, top 50%, translateY(-20%), cao 3.25 + 0.65 + 3.25 = 7.15rem -> mép trên = 50vh - 1.43rem.
   Nút chat nằm ngay trên, cách 0.65rem (bằng khoảng cách giữa các nút của .vx-fab). */
.vx-chatbot__launcher {
	position: fixed;
	right: 1rem;
	bottom: calc(50vh + 2.08rem);
	z-index: 50;
	display: flex;
	align-items: center;
	gap: 0.7rem;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
}

/* Thẻ chữ: giống .vx-fab__label */
.vx-chatbot__launcher-label {
	position: relative;
	padding: 0.5rem 0.9rem;
	border-radius: 999px;
	background: #fff;
	color: #1b1b1b;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
	animation: vx-chatbot-in 0.45s ease 0.35s both;
}

.vx-chatbot__launcher-label::after {
	content: "";
	position: absolute;
	top: 50%;
	right: -6px;
	margin-top: -6px;
	border: 6px solid transparent;
	border-right: 0;
	border-left-color: #fff;
}

/* Vòng tròn biểu tượng chat: cùng cỡ .vx-fab__bubble */
.vx-chatbot__launcher-bubble {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: 3.25rem;
	height: 3.25rem;
	min-width: 44px;
	min-height: 44px;
	border-radius: 50%;
	background: var(--cb-brown);
	color: #fff;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
	transition: background-color 0.2s ease, transform 0.2s ease;
}

.vx-chatbot__launcher-bubble svg {
	display: block;
	width: 1.65rem;
	height: 1.65rem;
}

.vx-chatbot__launcher-bubble .vx-chatbot__dot {
	fill: var(--cb-brown);
	transition: fill 0.2s ease;
}

.vx-chatbot__launcher:hover .vx-chatbot__launcher-bubble {
	background: var(--cb-brown-dark);
	transform: translateY(-2px);
}

.vx-chatbot__launcher:hover .vx-chatbot__dot {
	fill: var(--cb-brown-dark);
}

@keyframes vx-chatbot-in {
	from {
		opacity: 0;
		transform: translateX(12px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.vx-chatbot__avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	border-radius: 50%;
}

.vx-chatbot__avatar img {
	display: block;
	width: 72%;
	height: 72%;
	object-fit: contain;
}

.vx-chatbot.is-open .vx-chatbot__launcher,
.vx-chatbot.is-fab-closed .vx-chatbot__launcher {
	display: none;
}

/* Popup báo giá / catalogue đang mở: ẩn nút như .vx-fab */
body.is-modal-open .vx-chatbot__launcher,
body:has(.vx-modal:not([hidden])) .vx-chatbot__launcher {
	visibility: hidden;
	pointer-events: none;
}

/* ---------- Khung chat ---------- */
.vx-chatbot__window {
	position: fixed;
	right: 24px;
	bottom: 96px; /* chừa chỗ cho huy hiệu reCAPTCHA của theme (bắt buộc phải hiển thị) */
	z-index: 55; /* trên nút WhatsApp (50), dưới popup báo giá .vx-modal (60) */
	display: flex;
	flex-direction: column;
	width: 400px;
	height: min(640px, calc(100vh - 120px));
	overflow: hidden;
	border: 1px solid var(--cb-line);
	border-radius: 16px;
	background: var(--cb-paper);
	box-shadow: 0 16px 40px rgba(74, 36, 24, 0.22);
}

.vx-chatbot__window[hidden] {
	display: none;
}

.vx-chatbot__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.1rem 1.25rem 0.9rem;
	border-bottom: 1px solid var(--cb-line);
	background: var(--cb-cream);
}

.vx-chatbot__title {
	margin: 0;
	font-size: 1.9rem;
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.02em;
	color: var(--cb-brown);
}

.vx-chatbot__logo {
	display: block;
	width: auto;
	height: 2.6rem;
}

.vx-chatbot__status {
	margin: 0.35rem 0 0;
	font-size: 0.9rem;
	color: var(--cb-brown-dark);
}

/* Nút đóng: dấu X vẽ bằng 2 nét mảnh */
.vx-chatbot__close {
	position: relative;
	flex: 0 0 auto;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--cb-brown);
}

.vx-chatbot__close::before,
.vx-chatbot__close::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 1.4rem;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
}

.vx-chatbot__close::before {
	transform: translate(-50%, -50%) rotate(45deg);
}

.vx-chatbot__close::after {
	transform: translate(-50%, -50%) rotate(-45deg);
}

.vx-chatbot__close:hover {
	color: var(--cb-orange-dark);
}

/* ---------- Tin nhắn ---------- */
.vx-chatbot__messages {
	flex: 1;
	overflow-y: auto;
	padding: 1.1rem 1.1rem 0.5rem;
	scroll-behavior: smooth;
}

.vx-chatbot__row {
	display: flex;
	gap: 0.6rem;
	margin-bottom: 1rem;
}

.vx-chatbot__row--user {
	justify-content: flex-end;
}

.vx-chatbot__avatar {
	width: 2rem;
	height: 2rem;
	margin-top: 0.1rem;
	border: 1px solid var(--cb-line);
	background: #fff;
}

.vx-chatbot__stack {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	min-width: 0;
	max-width: 85%;
}

.vx-chatbot__bubble {
	padding: 0.75rem 1rem;
	border-radius: 16px;
	font-size: 0.925rem;
	line-height: 1.55;
	overflow-wrap: anywhere;
}

.vx-chatbot__row--bot .vx-chatbot__bubble {
	border: 1px solid var(--cb-line);
	background: var(--cb-bubble);
	color: var(--cb-brown-deep);
}

.vx-chatbot__row--user .vx-chatbot__bubble {
	max-width: 85%;
	background: var(--cb-brown);
	color: #fff;
}

.vx-chatbot__bubble p {
	margin: 0;
}

.vx-chatbot__bubble ul {
	margin: 0;
	padding-left: 1.1rem;
}

.vx-chatbot__bubble p + ul,
.vx-chatbot__bubble ul + p {
	margin-top: 0.4rem;
}

.vx-chatbot__bubble li + li {
	margin-top: 0.25rem;
}

.vx-chatbot__bubble a {
	color: var(--cb-orange-dark);
	text-decoration: underline;
	word-break: break-all;
}

.vx-chatbot__row.is-error .vx-chatbot__bubble {
	border-color: #eec3bc;
	background: #fdf2f0;
}

.vx-chatbot__typing .vx-chatbot__bubble {
	color: var(--cb-muted);
	font-style: italic;
}

/* Nút hành động dưới câu trả lời (form + trang sản phẩm) */
.vx-chatbot__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.vx-chatbot__cta {
	align-self: flex-start;
	padding: 0.55rem 1rem;
	border: 1px solid var(--cb-brown);
	border-radius: 999px;
	background: #fff;
	color: var(--cb-brown);
	font-size: 0.85rem;
	font-weight: 600;
	text-decoration: none;
}

.vx-chatbot__cta:hover {
	background: var(--cb-cream);
}

.vx-chatbot__cta--quote {
	border-color: var(--cb-orange);
	background: var(--cb-orange);
	color: #fff;
}

.vx-chatbot__cta--quote:hover {
	border-color: var(--cb-orange-dark);
	background: var(--cb-orange-dark);
}

/* ---------- Câu gợi ý: hàng ngang kéo được, chữ gạch chân, không khung bọc ---------- */
.vx-chatbot__suggest {
	display: flex;
	gap: 1.25rem;
	overflow-x: auto;
	padding: 0.35rem 1.25rem 0.6rem;
	scrollbar-width: thin;
	-webkit-overflow-scrolling: touch;
}

.vx-chatbot__suggest[hidden] {
	display: none;
}

.vx-chatbot__suggest-item {
	flex: 0 0 auto;
	padding: 0.3rem 0;
	white-space: nowrap;
	border: 0;
	background: none;
	color: var(--cb-brown);
	font-size: 0.9rem;
	font-weight: 600;
	text-align: left;
	text-decoration: underline;
	text-decoration-color: rgba(139, 79, 45, 0.3);
	text-underline-offset: 4px;
}

.vx-chatbot__suggest-item:hover {
	color: var(--cb-orange-dark);
	text-decoration-color: currentColor;
}

/* ---------- Ô nhập: dải nâu, viền trên là đường cam thẳng ---------- */
.vx-chatbot__form {
	display: flex;
	align-items: flex-end;
	gap: 0.9rem;
	padding: 1rem 1.25rem 1.2rem;
	border-top: 3px solid var(--cb-orange);
	background: var(--cb-brown-deep);
}

.vx-chatbot__input {
	flex: 1;
	min-width: 0;
	padding: 0.55rem 0 0.5rem;
	border: 0;
	border-bottom: 1px solid rgba(255, 255, 255, 0.55);
	border-radius: 0;
	background: transparent;
	color: #fff;
	font-family: inherit;
	font-size: 0.95rem;
}

.vx-chatbot__input::placeholder {
	color: rgba(245, 237, 232, 0.65);
}

.vx-chatbot__input:focus {
	border-bottom-color: var(--cb-orange);
	outline: none;
}

.vx-chatbot__send {
	padding: 0.5rem 1rem;
	border: 0;
	border-radius: 999px;
	background: var(--cb-orange);
	color: #fff;
	font-size: 0.9rem;
	font-weight: 600;
}

.vx-chatbot__send:hover {
	background: var(--cb-orange-dark);
}

.vx-chatbot__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ---------- Mobile: đặt trên thanh liên hệ cố định (.vx-sticky cao 3.5rem) ---------- */
@media (max-width: 767px) {
	/* Mobile không có .vx-fab (dùng thanh .vx-sticky) -> nút chat đứng riêng, trên huy hiệu reCAPTCHA (đáy 64px, cao 60px) */
	.vx-chatbot__launcher {
		right: 12px;
		bottom: calc(132px + env(safe-area-inset-bottom, 0px));
	}

	.vx-chatbot__window {
		left: 8px;
		right: 8px;
		bottom: calc(3.5rem + 12px + env(safe-area-inset-bottom, 0px));
		width: auto;
		height: calc(100vh - 3.5rem - 32px - env(safe-area-inset-bottom, 0px));
	}

	.vx-chatbot__title {
		font-size: 1.6rem;
	}

	/* iOS tự phóng to trang nếu ô nhập nhỏ hơn 16px */
	.vx-chatbot__input {
		font-size: 16px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.vx-chatbot__launcher-label {
		animation: none;
	}

	.vx-chatbot__launcher-bubble {
		transition: none;
	}

	.vx-chatbot__messages {
		scroll-behavior: auto;
	}
}
