/* Kwacko AI Chatbot Widget — professional UI. Scoped, theme-agnostic (Hello Elementor friendly). */

#ai-chatbot-root {
	--ai-chatbot-accent: #7cb342;
	--ai-chatbot-bottom: 24px;
	--ai-chatbot-side: 24px;
	--ai-chatbot-accent-dark: color-mix(in srgb, var(--ai-chatbot-accent) 78%, #000);
	--ai-chatbot-text: #1f2330;
	--ai-chatbot-muted: #6b7280;
	position: fixed;
	bottom: var(--ai-chatbot-bottom);
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	box-sizing: border-box;
}

#ai-chatbot-root.ai-chatbot-side-right { right: var(--ai-chatbot-side); }
#ai-chatbot-root.ai-chatbot-side-left { left: var(--ai-chatbot-side); }

#ai-chatbot-root *,
#ai-chatbot-root *::before,
#ai-chatbot-root *::after {
	box-sizing: border-box;
}

/* ---------- Launcher button ---------- */
#ai-chatbot-toggle {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 62px;
	height: 62px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--ai-chatbot-accent), var(--ai-chatbot-accent-dark));
	color: #fff;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ai-chatbot-side-right #ai-chatbot-toggle { margin-left: auto; }

#ai-chatbot-toggle::before {
	content: "";
	position: absolute;
	inset: -4px;
	border-radius: 50%;
	border: 2px solid var(--ai-chatbot-accent);
	opacity: 0.55;
	animation: ai-chatbot-pulse 2.4s ease-out infinite;
}

@keyframes ai-chatbot-pulse {
	0% { transform: scale(1); opacity: 0.55; }
	70% { transform: scale(1.35); opacity: 0; }
	100% { opacity: 0; }
}

#ai-chatbot-toggle:hover {
	transform: translateY(-2px) scale(1.04);
	box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
}

#ai-chatbot-toggle:focus-visible {
	outline: 3px solid rgba(255, 255, 255, 0.7);
	outline-offset: 2px;
}

/* Force the launcher icon to render white and centred, regardless of theme SVG rules. */
#ai-chatbot-toggle svg {
	display: block;
	margin: auto;
	width: 30px;
	height: 30px;
	pointer-events: none;
}

#ai-chatbot-toggle .ai-chatbot-icon-open > path,
#ai-chatbot-toggle .ai-chatbot-icon-close > path,
#ai-chatbot-toggle .ai-chatbot-icon-close > line {
	fill: #fff !important;
	stroke: #fff !important;
}

/* Dots inside the chat bubble follow the accent colour. */
#ai-chatbot-toggle .ai-chatbot-icon-open > circle {
	fill: var(--ai-chatbot-accent) !important;
}

#ai-chatbot-toggle .ai-chatbot-icon-close { display: none; }
#ai-chatbot-root.is-open #ai-chatbot-toggle .ai-chatbot-icon-open { display: none; }
#ai-chatbot-root.is-open #ai-chatbot-toggle .ai-chatbot-icon-close { display: block; }
#ai-chatbot-root.is-open #ai-chatbot-toggle::before { display: none; }
#ai-chatbot-root.is-open #ai-chatbot-toggle {
	width: 52px;
	height: 52px;
	position: relative;
	margin-top: 12px;
}
#ai-chatbot-root.is-open #ai-chatbot-toggle svg {
	width: 22px;
	height: 22px;
}

/* ---------- Panel ---------- */
#ai-chatbot-panel {
	position: absolute;
	bottom: 80px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 580px;
	max-height: calc(100vh - 130px);
	display: flex;
	flex-direction: column;
	background: #fff;
	border-radius: 20px;
	overflow: hidden;
	box-shadow: 0 20px 60px rgba(15, 23, 42, 0.28);
	opacity: 0;
	transform: translateY(16px) scale(0.96);
	transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
	pointer-events: none;
}

.ai-chatbot-side-right #ai-chatbot-panel { right: 0; transform-origin: bottom right; }
.ai-chatbot-side-left #ai-chatbot-panel { left: 0; transform-origin: bottom left; }

#ai-chatbot-panel[hidden] { display: none; }

#ai-chatbot-root.is-open #ai-chatbot-panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* ---------- Header ---------- */
.ai-chatbot-header {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 16px 16px 18px;
	background: linear-gradient(135deg, var(--ai-chatbot-accent), var(--ai-chatbot-accent-dark));
	color: #fff;
}

.ai-chatbot-avatar {
	position: relative;
	flex-shrink: 0;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.22);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.3px;
}

.ai-chatbot-status-dot {
	position: absolute;
	right: -1px;
	bottom: -1px;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: #22c55e;
	border: 2px solid var(--ai-chatbot-accent);
}

.ai-chatbot-heading {
	display: flex;
	flex-direction: column;
	line-height: 1.25;
	flex: 1;
	min-width: 0;
}

.ai-chatbot-title { font-size: 15.5px; font-weight: 700; }

.ai-chatbot-subtitle {
	font-size: 12px;
	opacity: 0.92;
	margin-top: 2px;
	display: flex;
	align-items: center;
	gap: 5px;
}

.ai-chatbot-subtitle::before {
	content: "";
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
	animation: ai-chatbot-live 2s infinite;
}

@keyframes ai-chatbot-live {
	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); }
}

.ai-chatbot-header-close {
	flex-shrink: 0 !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 28px !important;
	height: 28px !important;
	min-width: 28px !important;
	max-width: 28px !important;
	padding: 0 !important;
	border: none !important;
	border-radius: 50% !important;
	background: rgba(255, 255, 255, 0.16) !important;
	color: #fff !important;
	cursor: pointer !important;
	transition: background 0.15s ease;
}

.ai-chatbot-header-close:hover { background: rgba(255, 255, 255, 0.3); }

.ai-chatbot-header-close svg {
	display: block !important;
	width: 16px !important;
	height: 16px !important;
}

.ai-chatbot-header-close svg path {
	fill: #fff !important;
}

/* ---------- Messages ---------- */
.ai-chatbot-messages {
	flex: 1;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 18px 16px;
	background: #f4f6f9;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}

.ai-chatbot-messages::-webkit-scrollbar { width: 7px; }
.ai-chatbot-messages::-webkit-scrollbar-thumb { background: #cdd3dd; border-radius: 4px; }

.ai-chatbot-msg {
	max-width: 84%;
	padding: 11px 14px;
	border-radius: 16px;
	font-size: 14px;
	line-height: 1.5;
	white-space: pre-wrap;
	word-wrap: break-word;
	overflow-wrap: anywhere;
	animation: ai-chatbot-pop 0.22s ease;
}

@keyframes ai-chatbot-pop {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}

.ai-chatbot-msg-user {
	align-self: flex-end;
	background: linear-gradient(135deg, var(--ai-chatbot-accent), var(--ai-chatbot-accent-dark));
	color: #fff;
	border-bottom-right-radius: 5px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.ai-chatbot-msg-bot {
	align-self: flex-start;
	background: #fff;
	color: var(--ai-chatbot-text);
	border: 1px solid #e6e8ee;
	border-bottom-left-radius: 5px;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.ai-chatbot-msg-error {
	align-self: center;
	background: #fdecea;
	color: #b3261e;
	border: 1px solid #f5c6c2;
	font-size: 13px;
	text-align: center;
}

/* Typing indicator */
.ai-chatbot-typing {
	align-self: flex-start;
	display: inline-flex;
	gap: 4px;
	padding: 13px 15px;
	background: #fff;
	border: 1px solid #e6e8ee;
	border-radius: 16px;
	border-bottom-left-radius: 5px;
}

.ai-chatbot-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9aa1b1;
	animation: ai-chatbot-bounce 1.2s infinite ease-in-out;
}

.ai-chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

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

/* ---------- Quick replies ---------- */
.ai-chatbot-quick {
	display: flex !important;
	flex-wrap: wrap !important;
	gap: 6px !important;
	padding: 8px 16px 10px !important;
	background: #f4f6f9 !important;
}

.ai-chatbot-quick:empty { display: none; }

.ai-chatbot-chip {
	display: inline-flex !important;
	align-items: center !important;
	width: auto !important;
	max-width: none !important;
	border: 1.5px solid var(--ai-chatbot-accent) !important;
	background: #fff !important;
	color: var(--ai-chatbot-accent-dark) !important;
	font-size: 12px !important;
	font-weight: 600 !important;
	padding: 5px 12px !important;
	border-radius: 20px !important;
	cursor: pointer !important;
	transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
	font-family: inherit !important;
	white-space: nowrap !important;
	line-height: 1.3 !important;
	box-sizing: border-box !important;
	margin: 0 !important;
}

.ai-chatbot-chip:hover {
	background: var(--ai-chatbot-accent);
	color: #fff;
	transform: translateY(-1px);
}

/* ---------- Input ---------- */
.ai-chatbot-input {
	display: flex;
	align-items: center;
	gap: 9px;
	padding: 10px 14px;
	background: #fff;
	border-top: 1px solid #eceef2;
}

#ai-chatbot-text {
	flex: 1;
	resize: none;
	height: 44px;
	min-height: 44px;
	max-height: 120px;
	padding: 10px 14px;
	border: 1px solid #d9dde4;
	border-radius: 22px;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	color: var(--ai-chatbot-text);
	outline: none;
	overflow: hidden;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	background: #f8fafc;
	vertical-align: middle;
}

#ai-chatbot-text:focus {
	border-color: var(--ai-chatbot-accent);
	background: #fff;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-chatbot-accent) 18%, transparent);
}

#ai-chatbot-send {
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	flex-shrink: 0 !important;
	width: 44px !important;
	height: 44px !important;
	border: none !important;
	border-radius: 50% !important;
	background: linear-gradient(135deg, var(--ai-chatbot-accent), var(--ai-chatbot-accent-dark)) !important;
	color: #fff !important;
	cursor: pointer !important;
	box-shadow: 0 3px 10px color-mix(in srgb, var(--ai-chatbot-accent) 40%, transparent) !important;
	transition: transform 0.12s ease, opacity 0.15s ease;
	padding: 0 !important;
}

#ai-chatbot-send svg {
	display: block !important;
	width: 20px !important;
	height: 20px !important;
	fill: #fff !important;
	stroke: none !important;
	pointer-events: none !important;
}

#ai-chatbot-send svg path {
	fill: #fff !important;
}

#ai-chatbot-send:hover:not(:disabled) { transform: scale(1.06); }

#ai-chatbot-send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
	box-shadow: none;
}

/* ---------- Footer ---------- */
.ai-chatbot-footer {
	text-align: center;
	font-size: 11px;
	color: var(--ai-chatbot-muted);
	padding: 0 0 10px;
	background: #fff;
	letter-spacing: 0.2px;
}

/* ---------- Mobile (full-height sheet) ---------- */
@media (max-width: 560px) {
	#ai-chatbot-root {
		--ai-chatbot-side: 16px;
		--ai-chatbot-bottom: 16px;
	}

	#ai-chatbot-panel {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: none;
		border-radius: 0;
		/* Respect notches / safe areas on phones */
		padding-bottom: env(safe-area-inset-bottom);
	}

	.ai-chatbot-side-right #ai-chatbot-panel,
	.ai-chatbot-side-left #ai-chatbot-panel {
		right: 0;
		left: 0;
		transform-origin: center bottom;
	}

	.ai-chatbot-header { padding: 16px; }

	/* Hide launcher when panel is open on mobile — header close is enough */
	#ai-chatbot-root.is-open #ai-chatbot-toggle { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	#ai-chatbot-toggle::before,
	.ai-chatbot-msg,
	.ai-chatbot-typing span,
	.ai-chatbot-subtitle::before { animation: none; }

	#ai-chatbot-panel { transition: opacity 0.15s ease; }
}
