/* CON AI Chat - Frontend Widget */
#cac-chat-widget {
	--cac-primary: #2563eb;
	--cac-primary-dark: color-mix(in srgb, var(--cac-primary) 85%, black);
	--cac-radius: 16px;
	--cac-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
	--cac-shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.18);
	position: fixed;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
	font-size: 14px;
	line-height: 1.5;
}

/* Honeypot - invisible to humans */
.cac-hp-f {
	position: absolute !important;
	left: -9999px !important;
	top: -9999px !important;
	width: 1px !important;
	height: 1px !important;
	opacity: 0 !important;
	overflow: hidden !important;
	pointer-events: none !important;
	z-index: -1 !important;
}

/* Position */
#cac-chat-widget.cac-pos-bottom-right {
	bottom: 20px;
	right: 20px;
}
#cac-chat-widget.cac-pos-bottom-left {
	bottom: 20px;
	left: 20px;
}

/* Greeting Bubble */
#cac-chat-bubble {
	position: absolute;
	bottom: 70px;
	background: #fff;
	color: #1a1a1a;
	padding: 12px 36px 12px 16px;
	border-radius: 16px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
	font-size: 14px;
	line-height: 1.4;
	max-width: 260px;
	cursor: pointer;
	transition: opacity 0.2s, transform 0.2s;
	white-space: normal;
	word-wrap: break-word;
}
.cac-pos-bottom-right #cac-chat-bubble {
	right: 0;
}
.cac-pos-bottom-left #cac-chat-bubble {
	left: 0;
}
/* Speech bubble tail */
#cac-chat-bubble::after {
	content: '';
	position: absolute;
	bottom: -8px;
	width: 16px;
	height: 16px;
	background: #fff;
	transform: rotate(45deg);
	box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.06);
}
.cac-pos-bottom-right #cac-chat-bubble::after {
	right: 24px;
}
.cac-pos-bottom-left #cac-chat-bubble::after {
	left: 24px;
}
#cac-chat-bubble-close {
	position: absolute;
	top: 6px;
	right: 8px;
	background: none;
	border: none;
	font-size: 18px;
	line-height: 1;
	color: #9ca3af;
	cursor: pointer;
	padding: 2px 4px;
	border-radius: 4px;
	transition: color 0.15s;
}
#cac-chat-bubble-close:hover {
	color: #374151;
}
/* Animate in */
.cac-bubble-animate {
	animation: cac-bubble-in 0.4s ease-out;
}
@keyframes cac-bubble-in {
	from {
		opacity: 0;
		transform: translateY(10px) scale(0.95);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Toggle Button */
#cac-chat-toggle {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--cac-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: var(--cac-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
	position: relative;
}
#cac-chat-toggle:hover {
	transform: scale(1.08);
	box-shadow: var(--cac-shadow-lg);
	background: var(--cac-primary-dark);
}
#cac-chat-toggle:active {
	transform: scale(0.95);
}
/* Custom icon toggle */
#cac-chat-toggle.cac-toggle-custom {
	background: transparent;
	box-shadow: none;
	padding: 0;
	overflow: hidden;
}
#cac-chat-toggle.cac-toggle-custom img {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	object-fit: cover;
	display: block;
}
#cac-chat-toggle.cac-toggle-custom:hover {
	box-shadow: var(--cac-shadow-lg);
}
/* When chat open with custom icon, show X with colored bg */
#cac-chat-toggle.cac-toggle-custom svg#cac-icon-close {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
}
#cac-chat-toggle.cac-toggle-custom.cac-open {
	background: var(--cac-primary);
}

/* Chat Window */
#cac-chat-window {
	width: 380px;
	height: 520px;
	position: absolute;
	bottom: 76px;
	background: #fff;
	border-radius: var(--cac-radius);
	box-shadow: var(--cac-shadow-lg);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: cac-slide-up 0.25s ease-out;
}
.cac-pos-bottom-right #cac-chat-window {
	right: 0;
}
.cac-pos-bottom-left #cac-chat-window {
	left: 0;
}

@keyframes cac-slide-up {
	from {
		opacity: 0;
		transform: translateY(16px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.cac-hidden {
	display: none !important;
}

/* Header */
#cac-chat-header {
	background: var(--cac-primary);
	color: #fff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-shrink: 0;
}
.cac-header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}
.cac-header-dot {
	width: 10px;
	height: 10px;
	background: #4ade80;
	border-radius: 50%;
	display: inline-block;
	animation: cac-pulse 2s infinite;
}
@keyframes cac-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.5; }
}
.cac-header-title {
	font-weight: 600;
	font-size: 15px;
}
#cac-chat-close {
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	transition: background 0.15s;
}
#cac-chat-close:hover {
	background: rgba(255, 255, 255, 0.2);
}

/* AI Disclosure Bar (EU AI Act) */
#cac-ai-notice {
	background: #f8f9fa;
	color: #6b7280;
	font-size: 11px;
	text-align: center;
	padding: 4px 12px;
	border-bottom: 1px solid #e5e7eb;
	flex-shrink: 0;
	letter-spacing: 0.2px;
}

/* GDPR Consent Overlay */
#cac-consent {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px 20px;
	background: #fff;
	z-index: 10;
}
.cac-consent-inner {
	text-align: center;
	max-width: 300px;
}
.cac-consent-icon {
	margin-bottom: 12px;
}
#cac-consent-text {
	font-size: 13px;
	line-height: 1.55;
	color: #374151;
	margin: 0 0 18px 0;
}
#cac-consent-text a {
	color: var(--cac-primary);
	text-decoration: underline;
	text-underline-offset: 2px;
}
#cac-consent-accept {
	display: inline-block;
	color: #fff;
	border: none;
	padding: 10px 28px;
	border-radius: 24px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: transform 0.15s, opacity 0.15s;
}
#cac-consent-accept:hover {
	transform: scale(1.04);
	opacity: 0.9;
}
#cac-consent-accept:active {
	transform: scale(0.96);
}

/* When consent visible, hide messages and input */
#cac-chat-window:has(#cac-consent:not(.cac-hidden)) #cac-chat-messages,
#cac-chat-window:has(#cac-consent:not(.cac-hidden)) #cac-chat-input-area {
	display: none;
}

/* Messages */
#cac-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	scroll-behavior: smooth;
}
#cac-chat-messages::-webkit-scrollbar {
	width: 5px;
}
#cac-chat-messages::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 3px;
}

.cac-msg {
	padding: 10px 14px;
	border-radius: 16px;
	max-width: 82%;
	word-wrap: break-word;
	overflow-wrap: break-word;
}
.cac-msg-user {
	background: var(--cac-primary);
	color: #fff;
	align-self: flex-end;
	border-bottom-right-radius: 4px;
}
.cac-msg-bot {
	background: #f1f3f5;
	color: #1a1a1a;
	align-self: flex-start;
	border-bottom-left-radius: 4px;
}
.cac-msg-bot a {
	color: var(--cac-primary);
	text-decoration: underline;
	text-underline-offset: 2px;
}
.cac-msg-bot a:hover {
	opacity: 0.8;
}

/* WhatsApp button */
.cac-whatsapp-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	background: #25D366;
	color: #fff !important;
	padding: 10px 18px;
	border-radius: 24px;
	text-decoration: none !important;
	font-weight: 600;
	font-size: 14px;
	margin-top: 8px;
	transition: background 0.15s, transform 0.15s;
	box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}
.cac-whatsapp-btn:hover {
	background: #1da851;
	transform: scale(1.03);
}
.cac-whatsapp-btn:active {
	transform: scale(0.97);
}
.cac-whatsapp-btn svg {
	flex-shrink: 0;
}

/* Product cards */
.cac-products {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 4px 12px;
	width: 100%;
}
.cac-product-card {
	display: flex;
	align-items: center;
	gap: 12px;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	padding: 8px;
	text-decoration: none;
	color: #1a1a1a;
	transition: border-color 0.15s, box-shadow 0.15s;
	overflow: hidden;
}
.cac-product-card:hover {
	border-color: var(--cac-primary);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.cac-product-img {
	width: 64px;
	height: 64px;
	border-radius: 8px;
	object-fit: cover;
	flex-shrink: 0;
	background: #f3f4f6;
}
.cac-product-no-img {
	display: flex;
	align-items: center;
	justify-content: center;
}
.cac-product-info {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1;
}
.cac-product-name {
	font-weight: 600;
	font-size: 13px;
	line-height: 1.3;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.cac-product-price {
	font-size: 13px;
	color: var(--cac-primary);
	font-weight: 500;
}

/* Typing indicator */
.cac-typing {
	display: flex;
	gap: 4px;
	padding: 12px 16px;
	align-self: flex-start;
	background: #f1f3f5;
	border-radius: 16px;
	border-bottom-left-radius: 4px;
}
.cac-typing span {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #9ca3af;
	animation: cac-bounce 1.4s infinite ease-in-out;
}
.cac-typing span:nth-child(1) { animation-delay: 0s; }
.cac-typing span:nth-child(2) { animation-delay: 0.2s; }
.cac-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cac-bounce {
	0%, 60%, 100% { transform: translateY(0); }
	30% { transform: translateY(-6px); }
}

/* Input Area */
#cac-chat-input-area {
	padding: 12px;
	border-top: 1px solid #e5e7eb;
	display: flex;
	gap: 8px;
	align-items: flex-end;
	flex-shrink: 0;
	background: #fff;
}
#cac-chat-input {
	flex: 1;
	border: 1px solid #d1d5db;
	border-radius: 12px;
	padding: 10px 14px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.4;
	resize: none;
	outline: none;
	max-height: 120px;
	transition: border-color 0.15s;
}
#cac-chat-input:focus {
	border-color: var(--cac-primary);
}
#cac-chat-input::placeholder {
	color: #9ca3af;
}
#cac-chat-send {
	width: 36px;
	height: 36px;
	background: none;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	padding: 4px;
	transition: transform 0.15s, opacity 0.15s;
}
#cac-chat-send svg {
	width: 24px;
	height: 24px;
}
#cac-chat-send:hover {
	transform: scale(1.1);
	opacity: 0.8;
}
#cac-chat-send:active {
	transform: scale(0.9);
}
#cac-chat-send:disabled {
	opacity: 0.3;
	cursor: not-allowed;
}

/* Mobile responsive */
@media (max-width: 480px) {
	#cac-chat-bubble {
		max-width: 220px;
		font-size: 13px;
		bottom: 68px;
	}
	#cac-chat-window {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100% !important;
		height: 80vh;
		border-radius: 16px 16px 0 0;
		z-index: 1000000;
		animation: cac-slide-up-mobile 0.25s ease-out;
		overflow: hidden;
	}

	/* Drag handle on header */
	#cac-chat-header {
		cursor: grab;
		touch-action: none;
		user-select: none;
		-webkit-user-select: none;
		position: relative;
	}
	#cac-chat-header::before {
		content: '';
		position: absolute;
		top: 6px;
		left: 50%;
		transform: translateX(-50%);
		width: 36px;
		height: 4px;
		background: rgba(255, 255, 255, 0.4);
		border-radius: 2px;
	}
	#cac-chat-header.cac-dragging {
		cursor: grabbing;
	}

	/* Prevent textarea from growing too much on mobile;
	   font-size 16px prevents iOS auto-zoom on focus */
	#cac-chat-input {
		max-height: 80px;
		font-size: 16px;
	}

	/* Keep input area pinned at bottom */
	#cac-chat-input-area {
		flex-shrink: 0;
		padding-bottom: max(12px, env(safe-area-inset-bottom));
	}
}

@keyframes cac-slide-up-mobile {
	from {
		opacity: 0;
		transform: translateY(40%);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}
