/* Troopy en la web: lanzador flotante + modal de chat. Posición fixed (CLS 0); animación solo con transform/opacity. */

.troop-chat {
	--tc-primary: var(--troop-primary, #00bf80);
	--tc-secondary: var(--troop-secondary, #33bbff);
	--tc-text: var(--troop-text, #232749);
	--tc-heading: var(--troop-heading, #2f2e36);
	--tc-border: var(--troop-border, #e8e9eb);
	--tc-bg-alt: var(--troop-bg-alt, #f2f3f5);
	position: fixed;
	right: 1.5rem;
	bottom: 1.5rem;
	z-index: 998;
	font-family: var(--troop-font-body, 'Open Sans', sans-serif);
	font-size: 15px;
	line-height: 1.45;
	color: var(--tc-text);
}

.troop-chat.is-open {
	z-index: 10000; /* por encima del header fijo: en mobile el modal es pantalla completa */
}

.troop-chat *,
.troop-chat *::before,
.troop-chat *::after {
	box-sizing: border-box;
}

.troop-chat button {
	font: inherit;
	cursor: pointer;
}

/* Lanzador: el avatar mismo es el botón */
.troop-chat-launcher {
	display: block;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
	transition: transform 0.2s ease;
}

.troop-chat-launcher img {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 50%;
}

.troop-chat-launcher:hover {
	transform: scale(1.08);
}

.troop-chat-launcher:focus-visible,
.troop-chat button:focus-visible,
.troop-chat a:focus-visible,
.troop-chat textarea:focus-visible {
	outline: 3px solid var(--tc-secondary);
	outline-offset: 2px;
}

.troop-chat.is-open .troop-chat-launcher {
	visibility: hidden;
}

/* Etiqueta "¿Te ayudo?" */
.troop-chat-teaser {
	position: absolute;
	right: 68px;
	bottom: 8px;
	display: flex;
	align-items: center;
	gap: 0.25rem;
	max-width: 240px;
	padding: 0.35rem 0.4rem 0.35rem 0.85rem;
	border-radius: 999px;
	background: #ffffff;
	color: var(--tc-heading);
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
	animation: troop-chat-teaser-in 0.25s ease both;
}

.troop-chat-teaser[hidden] {
	display: none;
}

.troop-chat-teaser-open {
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font-weight: 600;
	text-align: left;
}

.troop-chat-teaser-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--tc-bg-alt);
	color: var(--tc-text);
	flex: none;
}

.troop-chat-teaser-close svg {
	width: 12px;
	height: 12px;
}

@keyframes troop-chat-teaser-in {
	from { opacity: 0; transform: translateX(8px); }
	to { opacity: 1; transform: none; }
}

/* Panel */
.troop-chat-panel {
	position: absolute;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	width: 380px;
	height: min(600px, calc(100dvh - 3rem));
	background: #ffffff;
	border: 1px solid var(--tc-border);
	border-radius: 16px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.troop-chat-panel.is-open {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
}

.troop-chat-head {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.65rem 0.7rem;
	background: var(--troop-dark-bg, #12141a);
	color: #ffffff;
	flex: none;
}

.troop-chat-head img {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	flex: none;
}

.troop-chat-head strong {
	flex: 1;
	min-width: 0;
	font-family: var(--troop-font-heading, 'Noto Sans', sans-serif);
	font-size: 0.88rem;
	font-weight: 700;
	line-height: 1.2;
}

.troop-chat-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.12);
	color: #ffffff;
	flex: none;
	transition: background-color 0.2s ease;
}

.troop-chat-close:hover {
	background: rgba(255, 255, 255, 0.24);
	color: #ffffff;
}

.troop-chat-close svg {
	width: 14px;
	height: 14px;
}

/* Mensajes */
.troop-chat-log {
	flex: 1;
	min-height: 0;
	padding: 0.9rem 0.75rem;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--tc-bg-alt);
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
}

.troop-chat-row {
	display: flex;
	align-items: flex-end;
	gap: 0.4rem;
	max-width: 92%;
}

.troop-chat-row-user {
	align-self: flex-end;
	justify-content: flex-end;
}

.troop-chat-row img {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	flex: none;
}

.troop-chat-bubble {
	padding: 0.55rem 0.8rem;
	border-radius: 14px;
	background: #ffffff;
	border: 1px solid var(--tc-border);
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.troop-chat-row-user .troop-chat-bubble {
	background: var(--tc-primary);
	border-color: var(--tc-primary);
	color: #04281c;
}

.troop-chat-typing .troop-chat-bubble {
	color: #6b7280;
	font-style: italic;
}

/* CTA: mismo criterio que los botones del sitio (.troop-header-cta): en hover cambia el fondo, el texto sigue blanco.
   El selector con "a" le gana al a:hover global de troop-design-system.css, que pintaba el texto de celeste. */
.troop-chat a.troop-chat-cta {
	display: inline-block;
	margin-top: 0.5rem;
	padding: 0.45rem 0.9rem;
	border-radius: 999px;
	background: linear-gradient(135deg, var(--tc-primary), #0090c2);
	color: #ffffff;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
	font-weight: 700;
	text-decoration: none;
	transition: filter 0.2s ease, transform 0.2s ease;
}

.troop-chat a.troop-chat-cta-wa {
	background: #25d366;
}

.troop-chat a.troop-chat-cta:hover,
.troop-chat a.troop-chat-cta:focus-visible {
	color: #ffffff;
	filter: brightness(0.9);
	transform: translateY(-1px);
}

/* Opciones (botones del menú) */
.troop-chat-options {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding-left: 28px;
}

.troop-chat-option {
	display: flex;
	flex-direction: column;
	gap: 0.1rem;
	width: 100%;
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--tc-primary);
	border-radius: 12px;
	background: #ffffff;
	color: var(--tc-heading);
	text-align: left;
	transition: background-color 0.15s ease;
}

.troop-chat-option:hover:not(:disabled) {
	background: rgba(0, 191, 128, 0.12);
	color: var(--tc-heading);
}

.troop-chat-option:disabled {
	opacity: 0.55;
	cursor: default;
}

.troop-chat-option.is-chosen {
	opacity: 1;
	background: rgba(0, 191, 128, 0.16);
}

.troop-chat-option-title {
	font-weight: 700;
}

.troop-chat-option-desc {
	font-size: 0.82rem;
	color: #5b6270;
}

/* Input */
.troop-chat-form {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	padding: 0.6rem 0.75rem;
	border-top: 1px solid var(--tc-border);
	background: #ffffff;
	flex: none;
}

.troop-chat-form textarea {
	flex: 1;
	min-width: 0;
	max-height: 110px;
	padding: 0.5rem 0.7rem;
	border: 1px solid #cfd3da;
	border-radius: 12px;
	background: #ffffff;
	color: var(--tc-text);
	font: inherit;
	resize: none;
}

.troop-chat-form.is-disabled textarea {
	background: var(--tc-bg-alt);
	cursor: not-allowed;
}

.troop-chat-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--tc-primary);
	color: #04281c;
	flex: none;
}

.troop-chat-send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.troop-chat-send svg {
	width: 18px;
	height: 18px;
}

.troop-chat-foot {
	margin: 0;
	padding: 0.4rem 0.9rem 0.6rem;
	background: #ffffff;
	color: #5b6270;
	font-size: 0.74rem;
	line-height: 1.35;
	flex: none;
}

/* Mobile: pantalla completa; el input respeta el teclado virtual y la barra del sistema */
@media (max-width: 576px) {
	.troop-chat {
		right: 1rem;
		bottom: 1rem;
	}

	.troop-chat-launcher {
		width: 52px;
		height: 52px;
	}

	.troop-chat-teaser {
		right: 62px;
		max-width: calc(100vw - 6rem);
	}

	.troop-chat-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100dvh;
		border: 0;
		border-radius: 0;
		transform-origin: bottom center;
	}

	.troop-chat-head {
		padding: 0.8rem 0.9rem;
	}

	.troop-chat-close {
		width: 44px;
		height: 44px;
	}

	.troop-chat-close svg {
		width: 18px;
		height: 18px;
	}

	.troop-chat-form textarea {
		font-size: 16px; /* evita el zoom automático de iOS al enfocar */
	}

	.troop-chat-foot {
		padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
	}
}

@media (prefers-reduced-motion: reduce) {
	.troop-chat-panel,
	.troop-chat-panel.is-open,
	.troop-chat-launcher,
	.troop-chat-option {
		transition: none;
	}

	.troop-chat-teaser {
		animation: none;
	}
}
