/* PlaneaBot IA — widget de chat (frontend) */

#planeabot-root {
	--planeabot-color: #2563eb;
	--planeabot-color-contrast: #ffffff;
	position: fixed;
	z-index: 999999;
	bottom: 20px;
}

#planeabot-root[data-position="bottom-right"] {
	right: 20px;
}

#planeabot-root[data-position="bottom-left"] {
	left: 20px;
}

#planeabot-root * {
	box-sizing: border-box;
}

/* Botón flotante */
.planeabot-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--planeabot-color);
	color: var(--planeabot-color-contrast);
	border: none;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
	padding: 0;
}

.planeabot-launcher:hover {
	transform: scale(1.06);
	box-shadow: 0 8px 26px rgba(0, 0, 0, 0.3);
}

.planeabot-launcher svg {
	width: 28px;
	height: 28px;
}

.planeabot-launcher img {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	object-fit: cover;
}

/* Panel de chat */
.planeabot-panel {
	position: absolute;
	bottom: 76px;
	width: 380px;
	max-width: calc(100vw - 40px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	pointer-events: none;
	transition: opacity 0.18s ease, transform 0.18s ease;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
	line-height: 1.45;
	color: #1f2937;
}

#planeabot-root[data-position="bottom-right"] .planeabot-panel {
	right: 0;
}

#planeabot-root[data-position="bottom-left"] .planeabot-panel {
	left: 0;
}

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

/* Cabecera */
.planeabot-header {
	background: var(--planeabot-color);
	color: var(--planeabot-color-contrast);
	padding: 10px 16px;
	display: flex;
	align-items: center;
	gap: 10px;
}

.planeabot-header-avatar {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	flex-shrink: 0;
}

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

.planeabot-header-info {
	flex: 1;
	min-width: 0;
}

.planeabot-header-name {
	font-weight: 700;
	font-size: 15px;
}

.planeabot-header-status {
	font-size: 12px;
	opacity: 0.85;
}

.planeabot-close {
	background: transparent;
	border: none;
	color: inherit;
	cursor: pointer;
	font-size: 26px;
	line-height: 1;
	padding: 2px 4px;
	opacity: 0.9;
}

.planeabot-close:hover {
	opacity: 1;
}

/* Mensajes */
.planeabot-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	background: #f7f8fa;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.planeabot-bubble {
	max-width: 85%;
	padding: 10px 13px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.planeabot-bubble--bot {
	background: #fff;
	border: 1px solid #e5e7eb;
	border-bottom-left-radius: 4px;
	align-self: flex-start;
}

.planeabot-bubble--user {
	background: var(--planeabot-color);
	color: var(--planeabot-color-contrast);
	border-bottom-right-radius: 4px;
	align-self: flex-end;
}

.planeabot-sources {
	font-size: 12px;
	margin-top: 6px;
}

.planeabot-sources a {
	color: var(--planeabot-color);
	text-decoration: none;
	display: inline-block;
	margin-right: 8px;
}

.planeabot-sources a:hover {
	text-decoration: underline;
}

/* Indicador de escritura */
.planeabot-typing {
	display: inline-flex;
	gap: 4px;
	align-items: center;
}

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

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

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

@keyframes planeabot-bounce {
	0%, 80%, 100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	40% {
		transform: translateY(-5px);
		opacity: 1;
	}
}

/* Formulario de lead */
.planeabot-lead {
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	padding: 12px;
	align-self: stretch;
}

.planeabot-lead-title {
	font-weight: 700;
	margin-bottom: 8px;
}

.planeabot-lead input,
.planeabot-lead textarea {
	width: 100%;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	padding: 8px 10px;
	margin-bottom: 8px;
	font-size: 14px;
	font-family: inherit;
}

.planeabot-lead textarea {
	resize: vertical;
	min-height: 60px;
}

.planeabot-lead button {
	width: 100%;
	background: var(--planeabot-color);
	color: var(--planeabot-color-contrast);
	border: none;
	border-radius: 8px;
	padding: 10px;
	cursor: pointer;
	font-weight: 600;
	font-size: 14px;
}

.planeabot-lead .planeabot-lead-msg {
	font-size: 13px;
	margin-top: 4px;
}

.planeabot-lead .planeabot-lead-msg.err {
	color: #b91c1c;
}

.planeabot-lead .planeabot-lead-msg.ok {
	color: #15803d;
}

/* Pie con input */
.planeabot-input {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid #e5e7eb;
	background: #fff;
}

.planeabot-input textarea {
	flex: 1;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	padding: 9px 12px;
	font-size: 14px;
	font-family: inherit;
	resize: none;
	max-height: 90px;
	line-height: 1.4;
}

.planeabot-input textarea:focus {
	outline: none;
	border-color: var(--planeabot-color);
}

.planeabot-send {
	background: var(--planeabot-color);
	color: var(--planeabot-color-contrast);
	border: none;
	border-radius: 10px;
	padding: 0 14px;
	cursor: pointer;
	font-weight: 600;
	flex-shrink: 0;
}

.planeabot-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.planeabot-footer-credit {
	text-align: center;
	font-size: 11px;
	color: #9ca3af;
	padding: 0 0 8px;
	background: #fff;
}

.planeabot-footer-credit a {
	color: #9ca3af;
	text-decoration: none;
}

@media (max-width: 480px) {
	.planeabot-panel,
	#planeabot-root[data-position="bottom-right"] .planeabot-panel,
	#planeabot-root[data-position="bottom-left"] .planeabot-panel {
		position: fixed;
		inset: 0;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		transform: translateY(18px) scale(1);
	}
	#planeabot-root.planeabot-open .planeabot-panel {
		transform: translateY(0) scale(1);
	}
	.planeabot-messages {
		padding: 14px;
	}
}

html.planeabot-noscroll {
	overflow: hidden;
}

/* Botón de WhatsApp */
.planeabot-wa-bar {
	padding: 10px 12px 0;
	background: #f7f8fa;
}

.planeabot-wa-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	box-sizing: border-box;
	background: #0e7a3c;
	color: #fff;
	text-decoration: none;
	font-weight: 600;
	font-size: 14px;
	padding: 10px 14px;
	border-radius: 10px;
}

.planeabot-wa-btn:hover {
	background: #0a5f2f;
	color: #fff;
}

.planeabot-wa-btn svg {
	flex-shrink: 0;
}

.planeabot-wa-btn--alt {
	margin-top: 8px;
}

/* Markdown en respuestas del bot */
.planeabot-bubble--rich {
	white-space: normal;
}

.planeabot-bubble--rich > div {
	margin: 0 0 3px;
}

.planeabot-bubble--rich > div:last-child {
	margin-bottom: 0;
}

.planeabot-md-h {
	font-weight: 700;
	margin: 4px 0 2px;
}

.planeabot-bubble--rich ul,
.planeabot-bubble--rich ol {
	margin: 4px 0;
	padding-left: 20px;
}

.planeabot-bubble--rich li {
	margin: 2px 0;
}

.planeabot-bubble--rich strong {
	font-weight: 700;
}

.planeabot-bubble--rich code {
	background: rgba(0, 0, 0, 0.06);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 13px;
}

.planeabot-bubble--rich a {
	color: var(--planeabot-color);
	text-decoration: underline;
}

/* Foco visible para navegación por teclado (accesibilidad) */
.planeabot-launcher:focus-visible,
.planeabot-close:focus-visible,
.planeabot-send:focus-visible,
.planeabot-wa-btn:focus-visible,
.planeabot-input textarea:focus-visible,
.planeabot-lead input:focus-visible,
.planeabot-lead textarea:focus-visible,
.planeabot-lead button:focus-visible,
.planeabot-bubble--rich a:focus-visible,
.planeabot-sources a:focus-visible {
	outline: 3px solid #1f6feb;
	outline-offset: 2px;
}

.planeabot-panel[inert] {
	pointer-events: none;
}

/* Botón "Dejar mis datos" en la cabecera */
.planeabot-header-cta {
	background: rgba(255, 255, 255, 0.18);
	color: var(--planeabot-color-contrast);
	border: 1px solid rgba(255, 255, 255, 0.4);
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	padding: 5px 10px;
	cursor: pointer;
	white-space: nowrap;
	flex-shrink: 0;
}

.planeabot-header-cta:hover {
	background: rgba(255, 255, 255, 0.3);
}

/* Botón pequeño "Quiero que me contacten" bajo el input */
.planeabot-leadcta-bar {
	text-align: left;
	padding: 2px 12px 8px;
	background: #fff;
}

.planeabot-leadcta {
	display: inline-block;
	background: #111827;
	color: #ffffff;
	border: none;
	border-radius: 8px;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.2;
	padding: 5px 10px;
	cursor: pointer;
}

.planeabot-leadcta:hover {
	background: #000000;
}

/* Formulario de lead compacto */
.planeabot-lead-field {
	display: flex;
	flex-direction: column;
	gap: 5px;
	margin-bottom: 12px;
}

.planeabot-lead-field > span {
	font-size: 13px;
	font-weight: 600;
	color: #374151;
}

.planeabot-lead-field input {
	margin-bottom: 0 !important;
}

.planeabot-lead-row {
	display: flex;
	gap: 8px;
}

.planeabot-lead-row .planeabot-lead-field {
	flex: 1;
	min-width: 0;
}

.planeabot-lead-submit {
	margin-top: 2px;
}

/* Cabecera del formulario de lead con botón cerrar */
.planeabot-lead-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 8px;
}

.planeabot-lead-head .planeabot-lead-title {
	margin-bottom: 0;
}

.planeabot-lead .planeabot-lead-close {
	width: auto;
	background: transparent;
	border: none;
	color: #9ca3af;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	padding: 0 2px;
	margin: 0;
	flex-shrink: 0;
}

.planeabot-lead .planeabot-lead-close:hover {
	background: transparent;
	color: #4b5563;
}
