/* HDGroup AI Assistant v1 — mọi selector nằm dưới #hd-ai để không ảnh hưởng theme / plugin khác. */
#hd-ai {
	--hd-navy: #13294b;
	--hd-navy-2: #1d3a66;
	--hd-red: #d6283b;
	--hd-ink: #1f2937;
	--hd-muted: #64748b;
	--hd-line: #e3e8ef;
	--hd-soft: #f4f6fa;
	--hd-bg: #ffffff;
	--hd-focus: #2563eb;
	--hd-z: 99999998;   /* trên bong bóng đếm WPC Fly Cart (99999997), DƯỚI ngăn giỏ Fly Cart (99999999) */
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	color: var(--hd-ink);
}
#hd-ai *, #hd-ai *::before, #hd-ai *::after { box-sizing: border-box; }
#hd-ai [hidden] { display: none !important; }
#hd-ai button, #hd-ai textarea {
	font: inherit; color: inherit; letter-spacing: normal; text-transform: none;
	margin: 0; box-shadow: none; min-height: 0; width: auto; height: auto;
}
#hd-ai button { cursor: pointer; background: none; border: 0; padding: 0; border-radius: 0; line-height: 1.2; }
#hd-ai :focus { outline: none; }
#hd-ai :focus-visible { outline: 2px solid var(--hd-focus); outline-offset: 2px; }
#hd-ai p { margin: 0; padding: 0; }
#hd-ai h2 { margin: 0; padding: 0; }
#hd-ai a { text-decoration: none; }
#hd-ai svg { display: block; flex: none; }
#hd-ai .hd-ai-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }

/* ---------- Launcher ---------- */
#hd-ai .hd-ai-launcher {
	position: fixed; z-index: 99999990;
	right: 118px; bottom: 22px;              /* bên trái cụm liên hệ .hal (Gọi / Messenger / Zalo) */
	display: inline-flex; align-items: center; gap: 8px;
	height: 48px; padding: 0 18px 0 14px; border-radius: 24px;
	background: var(--hd-navy); color: #fff;
	border: 1px solid rgba(255,255,255,.14);
	box-shadow: 0 6px 18px rgba(19,41,75,.28);
	font-weight: 600; font-size: 14px; white-space: nowrap;
	transition: background-color .15s ease, transform .15s ease;
}
#hd-ai .hd-ai-launcher:hover { background: var(--hd-navy-2); }
#hd-ai .hd-ai-launcher::after {
	content: ""; position: absolute; top: 9px; left: 31px; width: 8px; height: 8px;
	border-radius: 50%; background: var(--hd-red); border: 2px solid var(--hd-navy);
}
#hd-ai.is-open .hd-ai-launcher { visibility: hidden; }

/* ---------- Panel ---------- */
#hd-ai .hd-ai-panel {
	position: fixed; z-index: var(--hd-z);
	right: 24px; bottom: 22px;
	width: 400px; max-width: calc(100vw - 32px);
	height: 640px; max-height: calc(100vh - 44px);
	display: flex; flex-direction: column;
	background: var(--hd-bg);
	border: 1px solid var(--hd-line); border-radius: 16px;
	box-shadow: 0 18px 48px rgba(15,23,42,.18), 0 2px 6px rgba(15,23,42,.06);
	overflow: hidden;
	animation: hd-ai-in .16s ease-out;
}
@keyframes hd-ai-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#hd-ai .hd-ai-head {
	display: flex; align-items: center; gap: 10px;
	padding: 12px 10px 12px 14px;
	border-bottom: 1px solid var(--hd-line);
	background: #fff;
}
#hd-ai .hd-ai-avatar { flex: none; width: 40px; height: 40px; }
#hd-ai .hd-ai-head__txt { flex: 1; min-width: 0; }
#hd-ai .hd-ai-title { font-size: 15px; font-weight: 700; line-height: 1.25; color: var(--hd-navy); }
#hd-ai .hd-ai-sub { font-size: 12.5px; color: var(--hd-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#hd-ai .hd-ai-badge {
	display: inline-block; font-size: 10.5px; font-weight: 700; line-height: 16px; padding: 0 6px;
	border-radius: 8px; background: #eef2f8; color: var(--hd-navy); letter-spacing: .02em;
}
#hd-ai .hd-ai-badge--demo { background: #fff4e5; color: #8a4b00; }
#hd-ai .hd-ai-iconbtn {
	flex: none; width: 44px; height: 44px; border-radius: 10px;
	display: inline-flex; align-items: center; justify-content: center; color: var(--hd-muted);
}
#hd-ai .hd-ai-iconbtn:hover { background: var(--hd-soft); color: var(--hd-navy); }

/* ---------- Log ---------- */
#hd-ai .hd-ai-log {
	flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
	padding: 14px 14px 6px; background: #fbfcfe;
	display: flex; flex-direction: column; gap: 10px;
	-webkit-overflow-scrolling: touch;
}
#hd-ai .hd-ai-msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-line; }
#hd-ai .hd-ai-msg--bot { align-self: flex-start; background: var(--hd-soft); border: 1px solid #e9edf3; border-top-left-radius: 4px; }
#hd-ai .hd-ai-msg--user { align-self: flex-end; background: var(--hd-navy); color: #fff; border-top-right-radius: 4px; }
#hd-ai .hd-ai-msg--error { border-color: #f3d2d6; background: #fff6f7; }
#hd-ai .hd-ai-typing { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
#hd-ai .hd-ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: #9aa6b8; animation: hd-ai-dot 1.1s infinite ease-in-out; }
#hd-ai .hd-ai-typing i:nth-child(2) { animation-delay: .15s; }
#hd-ai .hd-ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes hd-ai-dot { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }

#hd-ai .hd-ai-quick { display: flex; flex-wrap: wrap; gap: 8px; }
#hd-ai .hd-ai-chip {
	min-height: 44px; padding: 0 14px; border-radius: 22px;
	border: 1px solid #cdd6e3; background: #fff; color: var(--hd-navy);
	font-size: 13.5px; font-weight: 600;
}
#hd-ai .hd-ai-chip:hover { border-color: var(--hd-navy); background: #f3f6fb; }
#hd-ai .hd-ai-chip[disabled] { opacity: .55; cursor: default; }

/* Thẻ sản phẩm */
#hd-ai .hd-ai-cards { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
#hd-ai .hd-ai-card {
	display: grid; grid-template-columns: 72px 1fr; gap: 10px; align-items: center;
	padding: 8px; border: 1px solid var(--hd-line); border-radius: 12px; background: #fff;
}
#hd-ai .hd-ai-card__img { width: 72px; height: 72px; border-radius: 8px; object-fit: contain; background: #f6f7f9; display: block; }
#hd-ai .hd-ai-card__body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#hd-ai .hd-ai-card__brand { font-size: 11.5px; color: var(--hd-muted); text-transform: uppercase; letter-spacing: .03em; }
#hd-ai .hd-ai-card__name {
	font-size: 13.5px; font-weight: 600; color: var(--hd-ink); line-height: 1.35;
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
#hd-ai .hd-ai-card__price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
#hd-ai .hd-ai-card__now { font-weight: 700; color: var(--hd-red); font-size: 14px; }
#hd-ai .hd-ai-card__old { color: #94a3b8; text-decoration: line-through; font-size: 12px; }
#hd-ai .hd-ai-card__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
#hd-ai .hd-ai-card__stock { font-size: 12px; color: #15803d; }
#hd-ai .hd-ai-card__stock.is-out { color: #b91c1c; }
#hd-ai .hd-ai-card__stock.is-unknown { color: var(--hd-muted); }
#hd-ai .hd-ai-card__cta {
	display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 18px;
	background: var(--hd-navy); color: #fff !important; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
#hd-ai .hd-ai-card__cta:hover { background: var(--hd-navy-2); }

#hd-ai .hd-ai-sources { align-self: stretch; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
#hd-ai .hd-ai-sources__label { color: var(--hd-muted); }
#hd-ai .hd-ai-sources a { color: var(--hd-navy); text-decoration: underline; text-underline-offset: 2px; min-height: 28px; display: inline-flex; align-items: center; }
#hd-ai .hd-ai-handoff {
	align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
	min-height: 40px; padding: 0 14px; border-radius: 20px;
	border: 1px solid #0068ff; color: #0068ff !important; background: #fff; font-weight: 600; font-size: 13px;
}
#hd-ai .hd-ai-handoff:hover { background: #f0f6ff; }

/* ---------- Form ---------- */
#hd-ai .hd-ai-form {
	display: flex; align-items: flex-end; gap: 8px;
	padding: 10px 12px; border-top: 1px solid var(--hd-line); background: #fff;
}
#hd-ai .hd-ai-input {
	flex: 1; min-width: 0; resize: none; display: block;
	min-height: 44px; max-height: 120px; padding: 11px 14px;
	border: 1px solid #cdd6e3; border-radius: 22px; background: #fff;
	font-size: 16px; line-height: 20px;  /* 16px: iOS không zoom khi focus */
	overflow-y: auto;
}
#hd-ai .hd-ai-input:focus { border-color: var(--hd-navy); }
#hd-ai .hd-ai-input:focus-visible { outline: 2px solid var(--hd-focus); outline-offset: 0; }
#hd-ai .hd-ai-send {
	flex: none; width: 44px; height: 44px; border-radius: 50%;
	display: inline-flex; align-items: center; justify-content: center;
	background: var(--hd-navy); color: #fff;
}
#hd-ai .hd-ai-send:hover { background: var(--hd-navy-2); }
#hd-ai .hd-ai-send[disabled] { background: #9aa6b8; cursor: default; }

#hd-ai .hd-ai-foot {
	display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
	padding: 6px 14px 10px; background: #fff; font-size: 12px;
}
#hd-ai .hd-ai-disclaimer { color: var(--hd-muted); }
#hd-ai .hd-ai-zalo { color: #0068ff !important; font-weight: 600; min-height: 32px; display: inline-flex; align-items: center; }
#hd-ai .hd-ai-zalo:hover { text-decoration: underline; }

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
	#hd-ai .hd-ai-panel { right: 16px; bottom: 16px; width: 390px; height: 620px; max-height: calc(100vh - 32px); }
}

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
	#hd-ai .hd-ai-launcher {
		right: 12px; bottom: calc(222px + env(safe-area-inset-bottom, 0px)); /* trên cột .hal + nút lên đầu trang */
		width: 52px; height: 52px; padding: 0; border-radius: 50%; justify-content: center;
	}
	#hd-ai .hd-ai-launcher__text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
	#hd-ai .hd-ai-launcher::after { top: 11px; left: 30px; }
	#hd-ai .hd-ai-panel {
		left: 0; right: 0; width: 100%; max-width: none;
		bottom: var(--hd-ai-kb, 0px);
		height: calc(var(--hd-ai-vvh, 100vh) - 12px); max-height: none;
		border-radius: 16px 16px 0 0; border-bottom: 0;
		padding-bottom: env(safe-area-inset-bottom, 0px);
	}
	#hd-ai .hd-ai-msg { max-width: 92%; }
}
@media (max-width: 767px) and (min-height: 700px) {
	#hd-ai .hd-ai-panel { height: min(calc(var(--hd-ai-vvh, 100vh) - 12px), 92vh); }
}
/* Khóa cuộn trang nền khi mở panel trên mobile */
html.hd-ai-lock, html.hd-ai-lock body { overflow: hidden !important; }

@media (prefers-reduced-motion: reduce) {
	#hd-ai .hd-ai-panel { animation: none; }
	#hd-ai .hd-ai-typing i { animation: none; opacity: .7; }
	#hd-ai * { transition: none !important; scroll-behavior: auto !important; }
}
@media print { #hd-ai { display: none !important; } }
