.aitv-root,
.aitv-root * { box-sizing: border-box; }

.aitv-root {
	--aitv-ink: #1d2433;
	--aitv-muted: #6b7385;
	--aitv-line: #e2e6ee;
	--aitv-surface: #f6f7fa;
	--aitv-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	position: fixed;
	bottom: 20px;
	z-index: 99990;
	font: 15px/1.5 var(--aitv-font);
	color: var(--aitv-ink);
}
.aitv-right { right: 20px; }
.aitv-left { left: 20px; }
.aitv-root [hidden] { display: none !important; }

/* Chống theme ghi đè style nút/ô nhập */
.aitv-root button,
.aitv-root textarea {
	font-family: var(--aitv-font);
	margin: 0;
	text-transform: none;
	letter-spacing: normal;
	text-shadow: none;
	box-shadow: none;
}
.aitv-root button:focus-visible,
.aitv-inline-btn:focus-visible { outline: 2px solid var(--aitv-color, #0b6bcb); outline-offset: 2px; }

/* Nút nổi */
.aitv-root .aitv-fab {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 52px;
	padding: 0 20px 0 16px;
	border: 0;
	border-radius: 26px;
	background: var(--aitv-color, #0b6bcb);
	color: var(--aitv-on-color, #fff);
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(11, 30, 66, .28);
	transition: transform .15s ease, box-shadow .15s ease;
}
.aitv-root .aitv-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(11, 30, 66, .32); }
.aitv-ico { width: 22px; height: 22px; fill: currentColor; }
.aitv-no-fab .aitv-fab { display: none; }

/* Một nhịp thu hút sự chú ý khi vừa tải trang, sau đó đứng yên */
.aitv-fab::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	border: 2px solid var(--aitv-color, #0b6bcb);
	opacity: 0;
	animation: aitv-ping 1.6s ease-out 2s 2;
	pointer-events: none;
}
@keyframes aitv-ping {
	0% { opacity: .55; transform: scale(1); }
	100% { opacity: 0; transform: scale(1.25, 1.5); }
}

/* Khung chat */
.aitv-panel {
	position: absolute;
	bottom: 66px;
	width: 380px;
	height: min(620px, calc(100vh - 110px));
	display: flex;
	flex-direction: column;
	background: #fff;
	border: 1px solid var(--aitv-line);
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 18px 48px rgba(11, 30, 66, .24);
	animation: aitv-in .18s ease-out;
}
.aitv-right .aitv-panel { right: 0; }
.aitv-left .aitv-panel { left: 0; }
.aitv-no-fab .aitv-panel { bottom: 0; }
@keyframes aitv-in {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: none; }
}

.aitv-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: var(--aitv-color, #0b6bcb);
	color: var(--aitv-on-color, #fff);
}
.aitv-head strong { display: block; font-size: 16px; line-height: 1.3; }
.aitv-head span { display: block; font-size: 12.5px; opacity: .85; }
.aitv-root .aitv-close {
	width: 32px;
	height: 32px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}
.aitv-root .aitv-close:hover { background: rgba(255, 255, 255, .18); }
.aitv-head button:focus-visible { outline-color: var(--aitv-on-color, #fff); }

.aitv-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	background: var(--aitv-surface);
	overscroll-behavior: contain;
}

.aitv-msg {
	max-width: 88%;
	padding: 10px 13px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.aitv-m-bot {
	align-self: flex-start;
	background: #fff;
	border: 1px solid var(--aitv-line);
	border-bottom-left-radius: 4px;
}
.aitv-m-user {
	align-self: flex-end;
	background: var(--aitv-color, #0b6bcb);
	color: var(--aitv-on-color, #fff);
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}
.aitv-m-bot p { margin: 0 0 .55em; }
.aitv-m-bot p:last-child,
.aitv-m-bot ul:last-child { margin-bottom: 0; }
.aitv-m-bot ul { margin: 0 0 .55em; padding-left: 20px; }
.aitv-m-bot li { margin: 0 0 .2em; }
.aitv-m-bot a { color: inherit; text-decoration: underline; }
.aitv-err { background: #fff4f2; border-color: #f1c4bc; color: #7a271a; }

.aitv-typing { display: flex; gap: 5px; align-items: center; padding: 14px 15px; }
.aitv-typing i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aitv-muted);
	animation: aitv-dot 1s infinite ease-in-out;
}
.aitv-typing i:nth-child(2) { animation-delay: .15s; }
.aitv-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aitv-dot {
	0%, 80%, 100% { opacity: .3; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}

/* Câu hỏi gợi ý */
.aitv-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 12px;
	background: var(--aitv-surface);
}
.aitv-root .aitv-chip {
	padding: 7px 12px;
	border: 1px solid var(--aitv-line);
	border-radius: 16px;
	background: #fff;
	color: var(--aitv-ink);
	font-size: 13.5px;
	line-height: 1.3;
	text-align: left;
	cursor: pointer;
	transition: border-color .12s ease;
}
.aitv-root .aitv-chip:hover { border-color: var(--aitv-color, #0b6bcb); }

/* Ô nhập */
.aitv-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--aitv-line);
	background: #fff;
}
.aitv-root textarea {
	flex: 1;
	min-height: 40px;
	max-height: 110px;
	padding: 9px 12px;
	border: 1px solid var(--aitv-line);
	border-radius: 12px;
	background: #fff;
	color: var(--aitv-ink);
	font-size: 16px;
	line-height: 1.4;
	resize: none;
}
.aitv-root textarea:focus-visible { outline: 2px solid var(--aitv-color, #0b6bcb); outline-offset: 0; border-color: transparent; }
.aitv-root .aitv-send {
	flex: none;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--aitv-color, #0b6bcb);
	cursor: pointer;
}
.aitv-send svg { width: 20px; height: 20px; fill: var(--aitv-on-color, #fff); }
.aitv-root .aitv-send:disabled { opacity: .45; cursor: default; }

.aitv-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 4px 12px;
	padding: 0 14px 10px;
	background: #fff;
	font-size: 12px;
	color: var(--aitv-muted);
}
.aitv-contact { color: var(--aitv-ink); font-weight: 600; text-decoration: underline; }

/* Nút đặt bằng shortcode [ai_tu_van_button] */
.aitv-inline-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 12px 22px;
	border: 0;
	border-radius: 999px;
	background: var(--aitv-color, #0b6bcb);
	color: var(--aitv-on-color, #fff);
	font: 600 16px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	cursor: pointer;
	transition: transform .15s ease;
}
.aitv-inline-btn:hover { transform: translateY(-1px); }

/* Điện thoại: khung chat mở dạng tấm trượt gần toàn màn hình */
@media (max-width: 480px) {
	.aitv-root { bottom: 12px; }
	.aitv-right { right: 12px; }
	.aitv-left { left: 12px; }
	.aitv-panel {
		position: fixed;
		left: 8px;
		right: 8px;
		bottom: 8px;
		width: auto;
		height: calc(100vh - 16px);
		height: calc(100dvh - 16px);
		max-height: 680px;
	}
	.aitv-is-open .aitv-fab { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.aitv-fab::after { animation: none; }
	.aitv-panel,
	.aitv-typing i { animation: none; }
	.aitv-root .aitv-fab,
	.aitv-inline-btn { transition: none; }
}
