/* Chatbot de leads (CRM NC). Carregado em todas as páginas por inc/chatbot.php. */
#crm-chatbot-toggle, #crm-chat-bubble, #crm-chatbot-window {
	--crm-cor: #001453; --crm-cor-escura: #000c35; --crm-texto: #1f2937; --crm-suave: #6b7280;
	--crm-borda: #e5e7eb; --crm-fundo: #f6f7f9; --crm-verde: #22c55e;
	font-family: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
	box-sizing: border-box;
}
#crm-chatbot-window *, #crm-chat-bubble * { box-sizing: border-box; }

/* Botão flutuante com a foto da consultora */
#crm-chatbot-toggle {
	position: fixed; right: 24px; bottom: 24px; z-index: 99999;
	width: 64px; height: 64px; padding: 0; border: 3px solid #fff; border-radius: 50%;
	background: var(--crm-cor); cursor: pointer; overflow: visible;
	box-shadow: 0 8px 24px rgba(17, 24, 39, .28);
	transition: transform .2s ease, box-shadow .2s ease;
	animation: crmPulse 2.4s infinite;
}
#crm-chatbot-toggle img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
#crm-chatbot-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 28px rgba(17, 24, 39, .32); }
#crm-chatbot-toggle.active { animation: none; }
#crm-chatbot-toggle .crm-online { position: absolute; right: 1px; bottom: 3px; }
.crm-online { width: 14px; height: 14px; border-radius: 50%; background: var(--crm-verde); border: 2px solid #fff; display: block; }
@keyframes crmPulse {
	0% { box-shadow: 0 0 0 0 rgba(248, 127, 2, .45), 0 8px 24px rgba(17, 24, 39, .28); }
	70% { box-shadow: 0 0 0 16px rgba(248, 127, 2, 0), 0 8px 24px rgba(17, 24, 39, .28); }
	100% { box-shadow: 0 0 0 0 rgba(248, 127, 2, 0), 0 8px 24px rgba(17, 24, 39, .28); }
}

/* Balão de boas-vindas */
#crm-chat-bubble {
	position: fixed; right: 24px; bottom: 100px; z-index: 99998;
	display: flex; align-items: flex-start; gap: 10px;
	max-width: 290px; padding: 14px 34px 14px 14px;
	background: #fff; color: var(--crm-texto); border-radius: 16px 16px 4px 16px;
	box-shadow: 0 10px 30px rgba(17, 24, 39, .18); cursor: pointer;
	font-size: 14px; line-height: 1.45; animation: crmBubbleIn .35s ease;
}
#crm-chat-bubble[hidden] { display: none; }
#crm-chat-bubble img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
#crm-chat-bubble p { margin: 0; }
#crm-chat-bubble strong { display: block; font-size: 13px; color: var(--crm-cor-escura); }
#crm-chat-bubble .crm-bubble-close {
	position: absolute; top: 6px; right: 8px; width: 24px; height: 24px; padding: 0;
	background: none; border: 0; border-radius: 50%; color: #9ca3af; font-size: 18px; line-height: 1; cursor: pointer;
}
#crm-chat-bubble .crm-bubble-close:hover { background: var(--crm-fundo); color: var(--crm-texto); }
@keyframes crmBubbleIn { from { opacity: 0; transform: translateY(10px) scale(.95); } to { opacity: 1; transform: none; } }

/* Janela */
#crm-chatbot-window {
	display: none; position: fixed; right: 24px; bottom: 100px; z-index: 99999;
	width: 380px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100vh - 128px);
	flex-direction: column; overflow: hidden;
	background: #fff; border-radius: 20px;
	box-shadow: 0 24px 64px rgba(17, 24, 39, .28);
	animation: crmChatSlideUp .28s ease;
}
#crm-chatbot-window.open { display: flex; }
@keyframes crmChatSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.crm-chat-header {
	display: flex; align-items: center; gap: 12px; padding: 16px 16px 16px 18px;
	background: linear-gradient(135deg, var(--crm-cor) 0%, var(--crm-cor-escura) 100%); color: #fff;
}
.crm-chat-header-avatar { position: relative; width: 44px; height: 44px; flex-shrink: 0; }
.crm-chat-header-avatar img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255, 255, 255, .85); display: block; }
.crm-chat-header-avatar .crm-online { position: absolute; right: -1px; bottom: 0; width: 12px; height: 12px; }
.crm-chat-header-info { min-width: 0; }
.crm-chat-header-info strong { display: block; margin: 0; font-size: 16px; font-weight: 600; color: #fff !important; line-height: 1.2; }
.crm-chat-header-info span { display: block; margin-top: 2px; font-size: 12px; color: rgba(255, 255, 255, .9) !important; }
.crm-chat-close {
	margin-left: auto; width: 34px; height: 34px; padding: 0; flex-shrink: 0;
	background: rgba(255, 255, 255, .15); border: 0; border-radius: 50%;
	color: #fff; font-size: 22px; line-height: 1; cursor: pointer; transition: background .2s;
}
.crm-chat-close:hover { background: rgba(255, 255, 255, .3) !important; color: #fff !important; }

/* Mensagens */
.crm-chat-messages {
	flex: 1; overflow-y: auto; padding: 18px 16px; background: var(--crm-fundo);
	display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth;
}
.crm-chat-msg {
	position: relative; max-width: 80%; padding: 10px 14px; border-radius: 16px;
	font-size: 14px; line-height: 1.5; color: var(--crm-texto); word-wrap: break-word;
	animation: crmMsgIn .2s ease;
}
@keyframes crmMsgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.crm-chat-msg.bot {
	align-self: flex-start; margin-left: 34px; background: #fff;
	border: 1px solid var(--crm-borda); border-bottom-left-radius: 4px;
	box-shadow: 0 1px 2px rgba(17, 24, 39, .04);
}
.crm-chat-msg.bot::before {
	content: ''; position: absolute; left: -34px; bottom: 0; width: 26px; height: 26px; border-radius: 50%;
	background: url(../img/chatbot-avatar.webp) center / cover no-repeat;
}
.crm-chat-msg.user {
	align-self: flex-end; background: var(--crm-cor); color: #fff; border-bottom-right-radius: 4px;
}
.crm-chat-msg.typing { font-size: 0; padding: 12px 16px; }
.crm-chat-msg.typing::after {
	content: ''; display: block; width: 34px; height: 8px;
	background:
		radial-gradient(circle 4px, #9ca3af 95%, transparent) 0 50% / 8px 8px no-repeat,
		radial-gradient(circle 4px, #9ca3af 95%, transparent) 13px 50% / 8px 8px no-repeat,
		radial-gradient(circle 4px, #9ca3af 95%, transparent) 26px 50% / 8px 8px no-repeat;
	animation: crmTyping 1s infinite ease-in-out;
}
@keyframes crmTyping { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* Opções */
.crm-chat-options {
	display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
	align-self: stretch; margin-left: 34px; padding: 2px 0;
}
.crm-chat-option-btn {
	padding: 9px 10px; border: 1.5px solid var(--crm-cor); border-radius: 12px;
	background: #fff; color: var(--crm-cor-escura);
	font: 500 13px/1.3 inherit; text-align: center; cursor: pointer;
	transition: background .15s, color .15s, transform .15s;
}
.crm-chat-option-btn:hover, .crm-chat-option-btn:focus-visible { background: var(--crm-cor); color: #fff; transform: translateY(-1px); outline: none; }

/* Campo de mensagem */
.crm-chat-input-area { display: flex; gap: 8px; padding: 12px 14px; background: #fff; border-top: 1px solid var(--crm-borda); }
.crm-chat-input-area input {
	flex: 1; min-width: 0; padding: 11px 16px; border: 1.5px solid var(--crm-borda); border-radius: 24px;
	font-size: 16px; color: var(--crm-texto); background: var(--crm-fundo); outline: none; transition: border-color .2s, background .2s;
}
.crm-chat-input-area input:focus { border-color: var(--crm-cor); background: #fff; }
.crm-chat-input-area button {
	display: flex; align-items: center; justify-content: center; flex-shrink: 0;
	width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
	background: var(--crm-cor); color: #fff; cursor: pointer;
	box-shadow: 0 4px 12px rgba(248, 127, 2, .35); transition: background .2s, transform .2s;
}
.crm-chat-input-area button:hover { background: var(--crm-cor-escura); transform: scale(1.05); }
.crm-chat-input-area button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* WhatsApp e rodapé */
.crm-chat-whatsapp { display: none; padding: 14px 16px; background: #fff; border-top: 1px solid var(--crm-borda); text-align: center; }
.crm-chat-whatsapp a {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
	padding: 12px 20px; border-radius: 24px; background: #25d366; color: #fff; text-decoration: none;
	font-weight: 600; font-size: 15px; box-shadow: 0 4px 12px rgba(37, 211, 102, .35);
}
.crm-chat-whatsapp a:hover { background: #1ebe5a; }
.crm-chat-legal { margin: 0; padding: 8px 14px 10px; background: #fff; color: var(--crm-suave); font-size: 11px; line-height: 1.4; text-align: center; }

@media (max-width: 480px) {
	#crm-chatbot-window { right: 0; bottom: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
	#crm-chatbot-toggle { right: 16px; bottom: 16px; width: 58px; height: 58px; }
	#crm-chat-bubble { right: 16px; bottom: 88px; max-width: calc(100vw - 32px); }
}
@media (prefers-reduced-motion: reduce) {
	#crm-chatbot-toggle, #crm-chat-bubble, #crm-chatbot-window, .crm-chat-msg, .crm-chat-msg.typing::after { animation: none; }
}
