/* ============================================================
 * AI Sales Chatbot — Frontend widget
 * Sạch, hiện đại, màu nhấn tuỳ biến qua --asc-primary
 * ============================================================ */

#asc-chat-root,
#asc-chat-root * {
	box-sizing: border-box;
}

/* ------------------------------------------------------------
 * Reset chống xung đột với theme của site.
 * Theme thường style đè <button>/<textarea>, khiến chip gợi ý,
 * ô nhập và nút gửi hiển thị sai so với preview. Trung hoà về 0
 * để widget tự quyết định giao diện. Các quy tắc thành phần bên
 * dưới được prefix #asc-chat-root nên luôn thắng reset này.
 * ------------------------------------------------------------ */
#asc-chat-root button,
#asc-chat-root input,
#asc-chat-root textarea {
	margin: 0;
	font: inherit;
	letter-spacing: inherit;
	text-align: inherit;
	text-transform: none;
	color: inherit;
	background: none;
	border: none;
	border-radius: 0;
	box-shadow: none;
	outline: none;
	text-shadow: none;
	min-width: 0;
	min-height: 0;
	width: auto;
	-webkit-appearance: none;
	appearance: none;
}

#asc-chat-root {
	--asc-primary: #4f46e5;
	--asc-primary-dark: color-mix(in srgb, var(--asc-primary) 82%, #000);
	--asc-on-primary: #ffffff;
	--asc-bg: #ffffff;
	--asc-bot-bubble: #f1f3f8;
	--asc-text: #1f2330;
	--asc-muted: #8a90a2;
	--asc-border: #e7e9f0;
	--asc-radius: 20px;
	--asc-shadow: 0 18px 50px rgba(20, 23, 40, 0.18);
	position: fixed;
	bottom: 22px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
}

#asc-chat-root.asc-pos-right { right: 22px; }
#asc-chat-root.asc-pos-left { left: 22px; }

/* -------- Launcher button -------- */
#asc-chat-root .asc-launcher {
	position: relative;
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	cursor: pointer;
	background: var(--asc-primary);
	color: var(--asc-on-primary);
	box-shadow: 0 10px 26px color-mix(in srgb, var(--asc-primary) 45%, transparent);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	margin-left: auto;
}

#asc-chat-root .asc-launcher:hover {
	transform: translateY(-3px) scale(1.04);
	box-shadow: 0 16px 34px color-mix(in srgb, var(--asc-primary) 55%, transparent);
}

.asc-launcher:active { transform: scale(0.97); }

.asc-launcher svg {
	width: 28px;
	height: 28px;
	position: absolute;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.asc-icon-close { opacity: 0; transform: rotate(-90deg) scale(0.5); }

#asc-chat-root.asc-open .asc-icon-chat { opacity: 0; transform: rotate(90deg) scale(0.5); }
#asc-chat-root.asc-open .asc-icon-close { opacity: 1; transform: rotate(0) scale(1); }

/* Pulse ring when idle */
.asc-launcher::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	border: 2px solid var(--asc-primary);
	opacity: 0;
	animation: ascPulse 2.6s ease-out infinite;
}

#asc-chat-root.asc-open .asc-launcher::after { animation: none; }

@keyframes ascPulse {
	0% { transform: scale(1); opacity: 0.5; }
	70% { transform: scale(1.55); opacity: 0; }
	100% { opacity: 0; }
}

.asc-launcher-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid #fff;
}

/* -------- Chat window -------- */
.asc-window {
	position: absolute;
	bottom: 76px;
	width: 384px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 120px);
	background: var(--asc-bg);
	border-radius: var(--asc-radius);
	box-shadow: var(--asc-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(16px) scale(0.97);
	transform-origin: bottom right;
	transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
	pointer-events: none;
}

#asc-chat-root.asc-pos-right .asc-window { right: 0; }
#asc-chat-root.asc-pos-left .asc-window { left: 0; transform-origin: bottom left; }

#asc-chat-root.asc-open .asc-window {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* -------- Header -------- */
.asc-head {
	background: linear-gradient(135deg, var(--asc-primary), var(--asc-primary-dark));
	color: var(--asc-on-primary);
	padding: 16px 18px;
	display: flex;
	align-items: center;
	gap: 12px;
	flex-shrink: 0;
}

.asc-head-avatar {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.22);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	flex-shrink: 0;
	font-weight: 700;
	font-size: 18px;
}

.asc-head-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.asc-head-info { flex: 1; min-width: 0; }

.asc-head-name {
	font-weight: 700;
	font-size: 16px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.asc-head-status {
	font-size: 12.5px;
	opacity: 0.9;
	display: flex;
	align-items: center;
	gap: 6px;
}

.asc-status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
	animation: ascDot 2s infinite;
}

@keyframes ascDot {
	0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
	70% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
	100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

#asc-chat-root .asc-head-min {
	background: rgba(255, 255, 255, 0.18);
	border: none;
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease;
}

#asc-chat-root .asc-head-min:hover { background: rgba(255, 255, 255, 0.3); }
.asc-head-min svg { width: 18px; height: 18px; }

/* -------- Messages area -------- */
.asc-messages {
	flex: 1;
	overflow-y: auto;
	padding: 18px 16px 8px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: linear-gradient(180deg, #fafbff 0%, #ffffff 100%);
	scroll-behavior: smooth;
}

.asc-messages::-webkit-scrollbar { width: 6px; }
.asc-messages::-webkit-scrollbar-thumb { background: #d6d9e4; border-radius: 3px; }

.asc-msg {
	max-width: 82%;
	display: flex;
	flex-direction: column;
	animation: ascMsgIn 0.25s ease;
}

@keyframes ascMsgIn {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.asc-msg-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	word-wrap: break-word;
	white-space: pre-wrap;
}

.asc-msg.bot { align-self: flex-start; }
.asc-msg.bot .asc-msg-bubble {
	background: var(--asc-bot-bubble);
	color: var(--asc-text);
	border-bottom-left-radius: 5px;
}

.asc-msg.user { align-self: flex-end; }
.asc-msg.user .asc-msg-bubble {
	background: var(--asc-primary);
	color: var(--asc-on-primary);
	border-bottom-right-radius: 5px;
}

.asc-msg-bubble a { color: inherit; text-decoration: underline; }

.asc-msg-time {
	font-size: 11px;
	color: var(--asc-muted);
	margin-top: 3px;
	padding: 0 4px;
}

.asc-msg.user .asc-msg-time { text-align: right; }

/* -------- Typing indicator -------- */
.asc-typing {
	align-self: flex-start;
	background: var(--asc-bot-bubble);
	padding: 13px 16px;
	border-radius: 16px;
	border-bottom-left-radius: 5px;
	display: inline-flex;
	gap: 4px;
}

.asc-typing span {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--asc-muted);
	animation: ascTyping 1.3s infinite ease-in-out;
}

.asc-typing span:nth-child(2) { animation-delay: 0.18s; }
.asc-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes ascTyping {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* -------- Product cards -------- */
.asc-products {
	display: flex;
	gap: 10px;
	overflow-x: auto;
	padding: 4px 2px 10px;
	margin: 2px 0;
	scroll-snap-type: x mandatory;
	align-self: stretch;
}

.asc-products::-webkit-scrollbar { height: 5px; }
.asc-products::-webkit-scrollbar-thumb { background: #d6d9e4; border-radius: 3px; }

.asc-product {
	flex: 0 0 168px;
	scroll-snap-align: start;
	border: 1px solid var(--asc-border);
	border-radius: 14px;
	overflow: hidden;
	background: #fff;
	display: flex;
	flex-direction: column;
	transition: box-shadow 0.16s ease, transform 0.16s ease;
}

.asc-product:hover {
	box-shadow: 0 8px 22px rgba(20, 23, 40, 0.12);
	transform: translateY(-2px);
}

.asc-product-img {
	width: 100%;
	height: 120px;
	object-fit: cover;
	background: #f3f4f8;
}

.asc-product-body {
	padding: 10px 11px 12px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	flex: 1;
}

.asc-product-name {
	font-size: 13.5px;
	font-weight: 600;
	color: var(--asc-text);
	line-height: 1.3;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.asc-product-price {
	font-size: 14.5px;
	font-weight: 700;
	color: var(--asc-primary);
	margin-top: auto;
}

.asc-product-actions {
	display: flex;
	gap: 6px;
	margin-top: 4px;
}

.asc-btn {
	flex: 1;
	border: none;
	border-radius: 9px;
	padding: 8px 6px;
	font-size: 12.5px;
	font-weight: 600;
	cursor: pointer;
	transition: filter 0.15s ease, background 0.15s ease;
	text-align: center;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.asc-btn-primary { background: var(--asc-primary); color: var(--asc-on-primary); }
.asc-btn-primary:hover { filter: brightness(1.08); }

.asc-btn-ghost {
	background: #f1f3f8;
	color: var(--asc-text);
}

.asc-btn-ghost:hover { background: #e7e9f0; }

/* -------- Order confirmation card -------- */
.asc-order {
	align-self: stretch;
	border: 1px solid var(--asc-border);
	border-left: 4px solid #22c55e;
	border-radius: 12px;
	padding: 14px;
	background: #f6fef9;
}

.asc-order-head {
	font-weight: 700;
	color: #15803d;
	display: flex;
	align-items: center;
	gap: 6px;
	margin-bottom: 8px;
}

.asc-order-row {
	display: flex;
	justify-content: space-between;
	font-size: 13.5px;
	padding: 3px 0;
	color: var(--asc-text);
}

.asc-order-row span:last-child { font-weight: 600; }

/* -------- Quick replies -------- */
.asc-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
	padding: 8px 16px 4px;
	flex-shrink: 0;
}

#asc-chat-root .asc-chip {
	background: #fff;
	border: 1.5px solid var(--asc-border);
	color: var(--asc-primary);
	padding: 7px 13px;
	border-radius: 18px;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.15s ease;
	white-space: nowrap;
}

#asc-chat-root .asc-chip:hover {
	background: var(--asc-primary);
	color: var(--asc-on-primary);
	border-color: var(--asc-primary);
}

/* -------- Input bar -------- */
.asc-input-bar {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 14px 14px;
	border-top: 1px solid var(--asc-border);
	background: #fff;
	flex-shrink: 0;
}

#asc-chat-root .asc-input {
	flex: 1;
	border: 1.5px solid var(--asc-border);
	border-radius: 22px;
	padding: 10px 16px;
	font-size: 14.5px;
	font-family: inherit;
	resize: none;
	max-height: 110px;
	line-height: 1.4;
	outline: none;
	transition: border-color 0.15s ease;
	color: var(--asc-text);
	background: #fff;
}

#asc-chat-root .asc-input:focus { border-color: var(--asc-primary); }

#asc-chat-root .asc-send {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: none;
	background: var(--asc-primary);
	color: var(--asc-on-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: filter 0.15s ease, transform 0.12s ease;
}

.asc-send:hover { filter: brightness(1.08); }
.asc-send:active { transform: scale(0.92); }
.asc-send:disabled { opacity: 0.45; cursor: default; }
.asc-send svg { width: 20px; height: 20px; }

/* -------- Footer credit -------- */
.asc-foot {
	text-align: center;
	font-size: 11px;
	color: var(--asc-muted);
	padding: 0 0 8px;
	background: #fff;
}

/* -------- Mobile -------- */
@media (max-width: 480px) {
	#asc-chat-root { bottom: 16px; }
	#asc-chat-root.asc-pos-right { right: 16px; }
	#asc-chat-root.asc-pos-left { left: 16px; }

	.asc-window {
		width: 100vw;
		height: 100vh;
		max-width: 100vw;
		max-height: 100vh;
		bottom: 0;
		border-radius: 0;
		position: fixed;
		left: 0;
		right: 0;
	}

	#asc-chat-root.asc-open .asc-launcher { opacity: 0; pointer-events: none; }
}

/* -------- Reduced motion -------- */
@media (prefers-reduced-motion: reduce) {
	.asc-launcher::after,
	.asc-status-dot,
	.asc-msg,
	.asc-window { animation: none !important; transition: opacity 0.1s linear; }
}
