/* ==========================================================================
   Chatbot Container & Positioning
   ========================================================================== */
#tkalu-chatbot-container {
	position: fixed;
	bottom: var(--tkalu-cb-bottom, 20px);
	z-index: 2147483647; /* Đảm bảo nằm trên Zalo Chat và các widget khác */
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
}

#tkalu-chatbot-container.is-right {
	right: var(--tkalu-cb-side, 20px);
}

#tkalu-chatbot-container.is-left {
	left: var(--tkalu-cb-side, 20px);
}

#tkalu-chatbot-container.tkalu-chatbot-hidden .tkalu-chatbot-box {
	display: none;
}

/* ==========================================================================
   Toggle Button & Greeting Message
   ========================================================================== */
.tkalu-toggle-wrapper {
	position: absolute;
	bottom: 0;
	display: flex;
	align-items: center;
	gap: 12px;
}

/* Side Pos - Right */
#tkalu-chatbot-container.is-right .tkalu-toggle-wrapper.tkalu-greeting-pos-side {
	right: 0;
	flex-direction: row;
}

/* Side Pos - Left */
#tkalu-chatbot-container.is-left .tkalu-toggle-wrapper.tkalu-greeting-pos-side {
	left: 0;
	flex-direction: row-reverse;
}

/* Top Pos - Common */
.tkalu-toggle-wrapper.tkalu-greeting-pos-top {
	flex-direction: column;
}
.tkalu-toggle-wrapper.tkalu-greeting-pos-top .tkalu-greeting-message {
	/* Override slide animation depending on position */
	animation: tkalu-slideUp 0.5s ease-out forwards; 
}

/* Top Pos - Right */
#tkalu-chatbot-container.is-right .tkalu-toggle-wrapper.tkalu-greeting-pos-top {
	right: 0;
	align-items: flex-end;
}
/* Top Pos - Left */
#tkalu-chatbot-container.is-left .tkalu-toggle-wrapper.tkalu-greeting-pos-top {
	left: 0;
	align-items: flex-start;
}


/* Greeting Bubble */
.tkalu-greeting-message {
	background: #ffffff;
	border-radius: 12px;
	width: 220px;
	box-shadow: 0 4px 12px rgba(0,0,0,0.1);
	pointer-events: auto;
	animation: tkalu-slideInRight 0.5s ease-out;
	border: 1px solid rgba(0,0,0,0.05);
	padding: 10px 12px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	cursor: pointer;
}

#tkalu-chatbot-container.is-left .tkalu-greeting-message {
	animation: tkalu-slideInLeft 0.5s ease-out;
}

.tkalu-greeting-header {
	display: flex;
	align-items: center;
	gap: 8px;
}

.tkalu-greeting-avatar {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	overflow: hidden;
	flex-shrink: 0;
	background: #f0f0f0;
	display: flex;
	align-items: center;
	justify-content: center;
}

.tkalu-greeting-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tkalu-greeting-avatar .tkalu-chat-icon {
	font-size: 14px;
}

.tkalu-greeting-name {
	font-size: 13px;
	font-weight: 600;
	color: var(--tkalu-primary-color, #0068ff);
	line-height: 1.2;
	flex: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tkalu-greeting-close {
	font-size: 18px;
	color: #999;
	line-height: 1;
	cursor: pointer;
	transition: color 0.2s;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 24px;
	width: 24px;
}

.tkalu-greeting-close:hover {
	color: #333;
}

.tkalu-greeting-body {
	height: 40px;
	overflow: hidden;
	position: relative;
}

.tkalu-greeting-slider {
	display: flex;
	flex-direction: column;
	transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.tkalu-greeting-line {
	height: 40px;
	display: flex;
	align-items: center;
	font-size: 13px;
	color: #444;
	line-height: 1.3;
	opacity: 0.1;
	transition: opacity 0.5s ease-in-out;
}

.tkalu-greeting-line.active {
	opacity: 1;
}

/* Hide greeting entirely on mobile */
@media (max-width: 768px) {
	.tkalu-greeting-message {
		display: none !important;
	}
}

/* Toggle Circle Button */
.tkalu-chatbot-toggle-btn {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--tkalu-primary-color, #0068ff);
	border: none;
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s, box-shadow 0.2s;
	flex-shrink: 0;
	overflow: hidden;
    padding: 0;
}

.tkalu-chatbot-toggle-btn:hover {
	transform: scale(1.05);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.tkalu-chatbot-toggle-btn img.tkalu-custom-avatar {
	width: 100%;
	height: 100%;
	object-fit: cover;
	-webkit-backface-visibility: hidden;
	backface-visibility: hidden;
	-webkit-transform: translateZ(0) scale(1.0);
	transform: translateZ(0) scale(1.0);
	image-rendering: -webkit-optimize-contrast;
}

.tkalu-chatbot-toggle-btn .tkalu-chat-icon {
	font-size: 28px;
    line-height: 1;
}

/* Hide toggle wrapper completely when chatbox is open */
#tkalu-chatbot-container:not(.tkalu-chatbot-hidden) .tkalu-toggle-wrapper {
	display: none;
}

/* ==========================================================================
   Main Chat Box
   ========================================================================== */
.tkalu-chatbot-box {
	width: var(--tkalu-cb-width, 360px);
	height: var(--tkalu-cb-height, 600px);
	max-height: calc(100vh - var(--tkalu-cb-bottom, 20px) - 60px);
	max-height: calc(100dvh - var(--tkalu-cb-bottom, 20px) - 60px);
	border-radius: 12px;
	box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
	background: #ffffff;
	display: flex;
	flex-direction: column;
	border: 1px solid rgba(0,0,0,0.1);
	position: absolute;
	bottom: 40px;
	overflow: hidden;
	animation: tkalu-slideUp 0.3s ease-out forwards;
}

#tkalu-chatbot-container.is-right .tkalu-chatbot-box { right: 0; }
#tkalu-chatbot-container.is-left .tkalu-chatbot-box { left: 0; }

/* Header */
.tkalu-chatbot-header {
	background: var(--tkalu-primary-color, #0068ff);
	color: #ffffff;
	padding: 12px 16px;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.tkalu-header-info {
	display: flex;
	align-items: center;
	gap: 12px;
}

.tkalu-header-avatar {
	width: 36px;
	height: 36px;
	background: #ffffff;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.tkalu-header-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tkalu-header-avatar .tkalu-chat-icon {
	font-size: 20px;
}

.tkalu-header-text h4 {
	margin: 0 0 2px 0;
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
}

.tkalu-header-status {
	font-size: 12px;
	opacity: 0.9;
	display: flex;
	align-items: center;
	gap: 4px;
}

.tkalu-header-status::before {
	content: '';
	display: inline-block;
	width: 8px;
	height: 8px;
	background: #28c76f;
	border-radius: 50%;
	border: 1px solid #fff;
}

.tkalu-chatbot-header-buttons {
	display: flex;
	gap: 8px;
}

.tkalu-chatbot-header-btn {
	background: transparent;
	border: none;
	color: #ffffff;
	cursor: pointer;
	padding: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 4px;
	opacity: 0.8;
	transition: opacity 0.2s, background 0.2s;
}

.tkalu-chatbot-header-btn:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Messages Area
   ========================================================================== */
.tkalu-chatbot-messages {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #e2e9f1; /* Zalo-like light background */
}

.tkalu-chatbot-message {
	max-width: 80%;
	display: flex;
	flex-direction: column;
	animation: tkalu-fadeIn 0.2s ease-out;
}

/* Bot Message */
.tkalu-chatbot-message.tkalu-bot-message {
	align-self: flex-start;
}

.tkalu-chatbot-message.tkalu-bot-message p {
	background: #ffffff;
	color: #000000;
	padding: 10px 14px;
	border-radius: 8px;
	margin: 0;
	font-size: 14px;
	line-height: 1.5;
	box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.tkalu-chatbot-message.tkalu-bot-message a {
	color: var(--tkalu-primary-color, #0068ff);
	text-decoration: none;
}

.tkalu-chatbot-message.tkalu-bot-message a:hover {
	text-decoration: underline;
}

/* User Message */
.tkalu-chatbot-message.tkalu-user-message {
	align-self: flex-end;
}

.tkalu-chatbot-message.tkalu-user-message p {
	background: #e5efff; /* Light blue like Zalo User Bubble */
	color: #000000;
	padding: 10px 14px;
	border-radius: 8px;
	margin: 0;
	font-size: 14px;
	line-height: 1.5;
	box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Typing indicator - bong bóng "Đang trả lời..." */
.tkalu-typing-indicator {
	display: inline-flex !important;
	align-items: center;
	gap: 4px;
}

.tkalu-typing-text {
	font-size: 13px;
	font-style: italic;
	color: #888;
}

.tkalu-typing-dots {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	margin-left: 2px;
}

.tkalu-typing-dots .tkalu-dot {
	display: inline-block;
	width: 5px;
	height: 5px;
	background: #888;
	border-radius: 50%;
	animation: tkalu-bounce 1.4s infinite ease-in-out both;
}

.tkalu-typing-dots .tkalu-dot:nth-child(1) { animation-delay: -0.32s; }
.tkalu-typing-dots .tkalu-dot:nth-child(2) { animation-delay: -0.16s; }
.tkalu-typing-dots .tkalu-dot:nth-child(3) { animation-delay: 0s; }

/* Legacy loading dots (fallback) */
.tkalu-chatbot-loading {
	display: inline-block;
	width: 6px;
	height: 6px;
	background: #888;
	border-radius: 50%;
	margin-right: 2px;
	animation: tkalu-bounce 1.4s infinite ease-in-out both;
}

.tkalu-chatbot-loading:nth-child(1) { animation-delay: -0.32s; }
.tkalu-chatbot-loading:nth-child(2) { animation-delay: -0.16s; }

/* Suggestions below messages */
.tkalu-chatbot-suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 5px;
	justify-content: flex-end;
}

.tkalu-suggestion-btn {
	background: #ffffff;
	border: 1px solid var(--tkalu-primary-color, #0068ff);
	color: var(--tkalu-primary-color, #0068ff);
	padding: 6px 12px;
	border-radius: 16px;
	font-size: 12px;
	cursor: pointer;
	transition: all 0.2s;
	white-space: nowrap;
}

.tkalu-suggestion-btn:hover {
	background: var(--tkalu-primary-color, #0068ff);
	color: #ffffff;
}

/* ==========================================================================
   Footer Input Area
   ========================================================================== */
.tkalu-chatbot-footer {
	background: #ffffff;
	border-top: 1px solid #ebebeb;
	padding: 12px 16px;
}

.tkalu-chatbot-form {
	display: flex !important;
	align-items: center !important;
	background: #f0f2f5 !important;
	border-radius: 20px !important;
	padding: 4px 12px !important;
	transition: border-color 0.2s, background 0.2s;
	border: 1px solid transparent !important;
	margin: 0 !important;
	width: 100% !important;
	box-sizing: border-box !important;
}

.tkalu-chatbot-form:focus-within {
	border: 1px solid var(--tkalu-primary-color, #0068ff) !important;
	background: #ffffff !important;
}

#tkalu-chatbot-input {
	flex: 1 !important;
	border: none !important;
	background: transparent !important;
	padding: 8px 0 !important;
	font-size: 14px !important;
	outline: none !important;
	color: #333 !important;
	box-shadow: none !important;
	border-radius: 0 !important;
	margin: 0 !important;
	height: 38px !important;
	min-height: 0 !important;
	line-height: normal !important;
}

#tkalu-chatbot-input::placeholder {
	color: #999 !important;
}

/* Fix input outline and background on focus from strong themes */
#tkalu-chatbot-input:focus,
#tkalu-chatbot-input:active {
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	background: transparent !important;
}

.tkalu-chatbot-send-btn {
	background: transparent !important;
	border: none !important;
	color: var(--tkalu-primary-color, #0068ff) !important;
	cursor: pointer !important;
	padding: 6px !important;
	margin: 0 0 0 4px !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	border-radius: 50% !important;
	transition: transform 0.2s;
	box-shadow: none !important;
	min-width: 0 !important;
	height: auto !important;
}

.tkalu-chatbot-send-btn:hover {
	transform: scale(1.1);
}

.tkalu-chatbot-send-btn svg {
	width: 24px;
	height: 24px;
}

.tkalu-chatbot-disclaimer {
	font-size: 11px;
	color: #aaaaaa;
	text-align: center;
	margin: 6px 0 0 0;
}

/* ==========================================================================
   Rating Overlay
   ========================================================================== */
.tkalu-chatbot-rating {
	position: absolute;
	bottom: 80px;
	left: 50%;
	transform: translateX(-50%);
	width: 85%;
	background: #ffffff;
	border-radius: 12px;
	box-shadow: 0 4px 20px rgba(0,0,0,0.15);
	padding: 15px;
	z-index: 10000;
	text-align: center;
	border: 1px solid rgba(0,0,0,0.05);
}

.tkalu-rating-close-btn {
	position: absolute;
	top: 5px;
	right: 10px;
	font-size: 20px;
	color: #999;
	cursor: pointer;
}

.tkalu-rating-header {
	font-size: 13px;
	font-weight: 600;
	margin-bottom: 10px;
	color: #333;
}

.tkalu-rating-stars {
	display: flex;
	justify-content: center;
	gap: 5px;
}

.tkalu-star {
	font-size: 24px;
	color: #e0e0e0;
	cursor: pointer;
	transition: color 0.2s, transform 0.2s;
}

.tkalu-star:hover, .tkalu-star.hovered {
	color: #ffc107;
	transform: scale(1.1);
}

.tkalu-star.rated {
	color: var(--tkalu-primary-color, #0068ff);
}

/* ==========================================================================
   Keyframes
   ========================================================================== */
@keyframes tkalu-slideUp {
	from { opacity: 0; transform: translateY(20px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes tkalu-fadeIn {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes tkalu-slideInRight {
	from { opacity: 0; transform: translateX(20px); }
	to { opacity: 1; transform: translateX(0); }
}

@keyframes tkalu-slideInLeft {
	from { opacity: 0; transform: translateX(-20px); }
	to { opacity: 1; transform: translateX(0); }
}

@keyframes tkalu-fadeInLine {
	from { opacity: 0; transform: translateY(5px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes tkalu-bounce {
	0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
	40% { opacity: 1; transform: scale(1); }
}

/* Scrollbar styling */
.tkalu-chatbot-messages::-webkit-scrollbar {
	width: 6px;
}
.tkalu-chatbot-messages::-webkit-scrollbar-track {
	background: transparent;
}
.tkalu-chatbot-messages::-webkit-scrollbar-thumb {
	background: #c1c1c1;
	border-radius: 4px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
	/* Ghi đè vị trí nút chatbot trên mobile */
	#tkalu-chatbot-container {
		bottom: var(--tkalu-cb-mobile-bottom, 20px);
	}

	.tkalu-chatbot-box {
		position: fixed;
		top: auto;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100vw;
		height: calc(100vh - 60px);
		height: calc(100dvh - 60px);
		max-height: calc(100vh - 60px);
		max-height: calc(100dvh - 60px);
		border-radius: 16px 16px 0 0;
		box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
		z-index: 2147483647;
	}
	
	/* Cố định nút mở box */
	#tkalu-chatbot-container.is-right { right: 10px; }
	#tkalu-chatbot-container.is-left { left: 10px; }
	
	/* Khóa cuộn trang khi chat mở */
	body.tkalu-chat-open {
		overflow: hidden !important;
	}
}
