/* ============================================
   MIA WIDGET — Global Chat Assistant
   Namespace: .rl-mia--
   ============================================ */

/* ---- Global Mia design tokens ----
   :root, not .rl-mia--widget: mia-fab.php and mia-bottom-nav.php render as
   siblings (not descendants) of .rl-mia--widget via separate includes in
   MiaWidget::render_widget(), so scoping these to .rl-mia--widget left
   #rl-scroll-top's var()-based bottom/width/height invalid (computed to
   "" → calc() invalid → falls back to auto/static position, ~10000px
   below the viewport). */
:root {
	--rl-mia-panel-w: 380px;
	--rl-mia-panel-h: 640px;
	--rl-mia-fab-h: 56px;
	--rl-mia-fab-gap: 12px;
	--rl-mia-scrolltop-size: 48px;
	--rl-mia-avatar-size: 48px;
	--rl-mia-header-h: 64px;
	--rl-mia-input-h: 56px;
	--rl-mia-z-fab: 500;
	--rl-mia-z-backdrop: 940;
	--rl-mia-z-panel: 950;
}

/* ============================================
   FAB TRIGGER (desktop only — mobile uses bottom nav)
   ============================================ */
.rl-mia--fab {
	position: fixed;
	bottom: 24px;
	right: 24px;
	height: var(--rl-mia-fab-h);
	max-width: min(360px, calc(100vw - 48px));
	padding: 0 20px 0 8px;
	border-radius: var(--wp--custom--radius--pill);
	background: var(--cat-current, var(--wp--preset--color--coral));
	color: var(--wp--preset--color--white);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 10px;
	box-shadow: var(--wp--preset--shadow--lg);
	z-index: var(--rl-mia-z-fab);
	transition:
		transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		box-shadow var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--fab:hover {
	transform: scale(1.03);
	box-shadow: var(--wp--preset--shadow--xl);
}

.rl-mia--fab:active {
	transform: scale(0.98);
}

.rl-mia--fab:focus-visible {
	outline: 3px solid var(--wp--preset--color--white);
	outline-offset: 2px;
}

.rl-mia--fab-avatar {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: transparent;
	border: 2px solid rgba(255, 255, 255, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 1rem;
}

.rl-mia--fab-label {
	font-size: 0.875rem;
	font-weight: 700;
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Pulse animation */
.rl-mia--fab-pulse {
	animation: rl-mia-pulse 300ms ease-out;
}

@keyframes rl-mia-pulse {

	0% {
		transform: scale(1);
	}

	50% {
		transform: scale(1.05);
	}

	100% {
		transform: scale(1);
	}
}

/* Badge on FAB */
.rl-mia--fab-badge {
	position: absolute;
	top: -4px;
	right: -4px;
	background: var(--wp--preset--color--score-red);
	color: var(--wp--preset--color--white);
	font-size: 0.625rem;
	font-weight: 700;
	padding: 2px 6px;
	border-radius: var(--wp--custom--radius--pill);
	opacity: 0;
	transform: scale(0);
	transition:
		opacity var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--fab-badge.is-visible {
	opacity: 1;
	transform: scale(1);
}

/* ============================================
   SCROLL TO TOP (desktop only — stacked under the FAB)
   ============================================ */
.rl-scroll-top {
	position: fixed;
	right: 24px;
	bottom: calc(24px + var(--rl-mia-fab-h) + var(--rl-mia-fab-gap));
	width: var(--rl-mia-scrolltop-size);
	height: var(--rl-mia-scrolltop-size);
	border-radius: 50%;
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--text-primary);
	border: 1px solid var(--wp--preset--color--border);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--wp--preset--shadow--md);
	z-index: var(--rl-mia-z-fab);
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
	transition:
		opacity var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		visibility var(--wp--custom--motion--duration-fast);
}

.rl-scroll-top.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.rl-scroll-top:hover {
	border-color: var(--wp--preset--color--accent-blue);
	color: var(--wp--preset--color--accent-blue);
}

.rl-scroll-top:focus-visible {
	outline: 3px solid var(--wp--preset--color--accent-blue);
	outline-offset: 2px;
}

/* Mobile: FAB and desktop scroll-top hide — bottom nav covers both roles */
@media (max-width: 767.98px) {

	.rl-mia--fab,
	.rl-scroll-top {
		display: none !important;
	}
}

/* ============================================
   CONTAINER & BACKDROP
   ============================================ */
.rl-mia--container {
	position: fixed;
	inset: 0;
	overflow: hidden; /* clips glow/chip children that extend past viewport edge */
	z-index: var(--rl-mia-z-panel);
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	pointer-events: none;
	visibility: hidden;
	opacity: 0;
	transition: opacity var(--wp--custom--motion--duration-normal) var(--wp--custom--motion--ease-out);
}

.rl-mia--container.is-open {
	pointer-events: auto;
	visibility: visible;
	opacity: 1;
}

.rl-mia--backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	z-index: var(--rl-mia-z-backdrop);
	pointer-events: auto;
}

/* ============================================
   PANEL (Mobile-first: bottom sheet base, desktop overlay at min-width)
   ============================================ */
.rl-mia--panel {
	position: relative;
	z-index: var(--rl-mia-z-panel);
	width: 100%;
	max-width: 100%;
	height: 85vh;
	max-height: 85vh;
	background: var(--wp--preset--color--white);
	border-radius: var(--wp--custom--radius--lg) var(--wp--custom--radius--lg) 0 0;
	box-shadow: var(--wp--preset--shadow--xl);
	margin: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform: translateY(100%);
	transition: transform var(--wp--custom--motion--duration-normal) var(--wp--custom--motion--ease-out);
}

.rl-mia--container.is-open .rl-mia--panel {
	transform: translateY(0);
}

/* Mobile: panel full-screen. JS sobreescribe height/bottom inline cuando el teclado abre. */
@media (max-width: 767.98px) {

	.rl-mia--panel {
		height: 100dvh;
		max-height: 100dvh;
		border-radius: 0;
	}
}

/* Desktop: floating panel */
@media (min-width: 768px) {

	.rl-mia--panel {
		width: var(--rl-mia-panel-w);
		max-width: calc(100vw - 32px);
		height: var(--rl-mia-panel-h);
		max-height: calc(100vh - 100px);
		border-radius: var(--wp--custom--radius--lg);
		margin: 0 24px calc(24px + var(--rl-mia-fab-h) + 16px) 0;
		transform: translateX(120%);
	}

	.rl-mia--container.is-open .rl-mia--panel {
		transform: translateX(0);
	}
}

/* ============================================
   HEADER
   ============================================ */
.rl-mia--header {
	display: flex;
	align-items: center;
	gap: var(--wp--custom--spacing--sm);
	padding: var(--wp--custom--spacing--md) var(--wp--custom--spacing--lg);
	border-bottom: 1px solid var(--wp--preset--color--border-light);
	flex-shrink: 0;
	background: var(--wp--preset--color--white);
}

.rl-mia--avatar {
	width: var(--rl-mia-avatar-size);
	height: var(--rl-mia-avatar-size);
	border-radius: 50%;
	background: linear-gradient(135deg, var(--wp--preset--color--accent-blue) 0%, var(--wp--preset--color--accent-teal) 100%);
	color: var(--wp--preset--color--white);
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: "Plus Jakarta Sans", "PJS Fallback", -apple-system, BlinkMacSystemFont, sans-serif;
	font-size: 1.25rem;
	font-weight: 700;
	flex-shrink: 0;
}

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

.rl-mia--header-title {
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.3;
	margin: 0;
	color: var(--wp--preset--color--text-primary);
}

.rl-mia--header-subtitle {
	font-size: 0.75rem;
	color: var(--wp--preset--color--text-muted);
}

.rl-mia--close {
	width: 40px;
	height: 40px;
	border-radius: var(--wp--custom--radius--sm);
	background: var(--wp--preset--color--bg-soft);
	border: none;
	color: var(--wp--preset--color--text-secondary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition:
		background var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		color var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--close:hover {
	background: var(--wp--preset--color--border-light);
	color: var(--wp--preset--color--text-primary);
}

/* ============================================
   BODY (scrollable messages area)
   ============================================ */
.rl-mia--body {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain; /* evita que el scroll del chat propague al body de la página */
	padding: var(--wp--custom--spacing--md);
	display: flex;
	flex-direction: column;
	gap: var(--wp--custom--spacing--sm);
	scrollbar-width: thin;
}

.rl-mia--body::-webkit-scrollbar {
	width: 6px;
}

.rl-mia--body::-webkit-scrollbar-thumb {
	background: var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--pill);
}

/* ============================================
   MESSAGES
   ============================================ */
.rl-mia--message {
	display: flex;
	gap: var(--wp--custom--spacing--sm);
}

.rl-mia--message--mia {
	justify-content: flex-start;
}

.rl-mia--message--user {
	justify-content: flex-end;
}

.rl-mia--message-bubble {
	max-width: 80%;
	padding: var(--wp--custom--spacing--sm) var(--wp--custom--spacing--md);
	border-radius: var(--wp--custom--radius--lg);
	font-size: 0.9375rem;
	line-height: 1.5;
	word-break: break-word;
}

.rl-mia--message--mia .rl-mia--message-bubble {
	background: var(--wp--preset--color--bg-soft);
	color: var(--wp--preset--color--text-primary);
	border-bottom-left-radius: var(--wp--custom--radius--sm);
}

.rl-mia--message--user .rl-mia--message-bubble {
	background: var(--wp--preset--color--accent-teal);
	color: var(--wp--preset--color--white);
	border-bottom-right-radius: var(--wp--custom--radius--sm);
}

/* ============================================
   CHIPS
   ============================================ */
.rl-mia--chips {
	display: flex;
	gap: var(--wp--custom--spacing--xs);
	overflow-x: auto;
	padding-bottom: var(--wp--custom--spacing--xs);
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.rl-mia--chips::-webkit-scrollbar {
	display: none;
}

.rl-mia--chip {
	flex-shrink: 0;
	padding: 6px 14px;
	font-size: 0.8125rem;
	font-weight: 500;
	color: var(--wp--preset--color--text-secondary);
	background: var(--wp--preset--color--bg-soft);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--pill);
	cursor: pointer;
	transition:
		background var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		color var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		border-color var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--chip:hover {
	background: var(--wp--preset--color--accent-blue-soft);
	color: var(--wp--preset--color--accent-blue);
	border-color: var(--wp--preset--color--accent-blue);
}

.rl-mia--chip:focus-visible,
.rl-mia--close:focus-visible {
	outline: 3px solid var(--wp--preset--color--accent-blue, #2563eb);
	outline-offset: 2px;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */
.rl-mia--typing {
	display: none;
	align-items: center;
	gap: 4px;
	padding: var(--wp--custom--spacing--sm) var(--wp--custom--spacing--md);
}

.rl-mia--typing.is-visible {
	display: flex;
}

.rl-mia--typing span {
	width: 6px;
	height: 6px;
	background: var(--wp--preset--color--text-muted);
	border-radius: 50%;
	animation: rl-mia-typing 1s ease-in-out infinite;
}

.rl-mia--typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.rl-mia--typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes rl-mia-typing {

	0%,
 60%,
 100% {
		transform: translateY(0);
		opacity: 0.4;
	}

	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* ============================================
   INPUT BAR
   ============================================ */
.rl-mia--input-bar {
	padding: var(--wp--custom--spacing--sm) var(--wp--custom--spacing--md);
	border-top: 1px solid var(--wp--preset--color--border-light);
	background: var(--wp--preset--color--white);
	flex-shrink: 0;
}

.rl-mia--form {
	display: flex;
	align-items: center;
	gap: var(--wp--custom--spacing--sm);
}

.rl-mia--input {
	flex: 1;
	padding: 10px 16px;
	font-family: "Plus Jakarta Sans", "PJS Fallback", -apple-system, BlinkMacSystemFont, sans-serif;
	font-size: 0.9375rem;
	color: var(--wp--preset--color--text-primary);
	background: var(--wp--preset--color--bg-soft);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: var(--wp--custom--radius--pill);
	outline: none;
	transition:
		border-color var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		box-shadow var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--input:focus {
	border-color: var(--wp--preset--color--accent-blue);
	box-shadow: var(--wp--preset--shadow--ring);
}

.rl-mia--input::placeholder {
	color: var(--wp--preset--color--text-muted);
}

.rl-mia--input:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.rl-mia--send {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--wp--preset--color--accent-blue);
	color: var(--wp--preset--color--white);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition:
		background var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		transform var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--send:hover {
	background: var(--wp--preset--color--blue-deep);
	transform: scale(1.05);
}

.rl-mia--send:active {
	transform: scale(0.95);
}

.rl-mia--send:disabled {
	background: var(--wp--preset--color--border);
	cursor: not-allowed;
	transform: none;
}

/* ============================================
   RATE LIMIT MESSAGE
   ============================================ */
.rl-mia--rate-limit {
	font-size: 0.8125rem;
	color: var(--wp--preset--color--text-muted);
	text-align: center;
	padding: var(--wp--custom--spacing--sm);
}

/* ============================================
   ACCESSIBILITY — Reduced motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {

	.rl-mia--fab,
	.rl-scroll-top,
	.rl-mia--container,
	.rl-mia--panel,
	.rl-mia--close,
	.rl-mia--chip,
	.rl-mia--send,
	.rl-mia--input,
	.rl-mia--message-bubble {
		transition: none !important;
		animation: none !important;
	}

	.rl-mia--fab-pulse {
		animation: none !important;
	}
}

/* Hide widget when printing */
@media print {

	.rl-mia--widget,
	.rl-mia--fab,
	.rl-scroll-top {
		display: none !important;
	}
}

/* ============================================
   PRODUCT CARDS (Mia recommendations)
   ============================================ */
.rl-mia--product-cards {
	list-style: none;
	margin: 0;
	padding: 0 0 4px 0;
	display: flex;
	gap: var(--wp--custom--spacing--sm);
	overflow-x: auto;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.rl-mia--product-cards::-webkit-scrollbar {
	display: none;
}

.rl-mia--product-card {
	flex: 0 0 148px;
	background: var(--wp--preset--color--white);
	border: 1px solid var(--wp--preset--color--border-light);
	border-radius: var(--wp--custom--radius--md);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow: var(--wp--preset--shadow--sm);
	transition: box-shadow var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--product-card:hover {
	box-shadow: var(--wp--preset--shadow--md);
}

.rl-mia--product-card__img {
	display: block;
	width: 100%;
	aspect-ratio: 4 / 3;
	object-fit: contain;
	background: var(--wp--preset--color--bg-soft);
	padding: 8px;
	box-sizing: border-box;
}

.rl-mia--product-card__img--placeholder {
	width: 100%;
	aspect-ratio: 4 / 3;
	background: var(--wp--preset--color--bg-soft);
}

.rl-mia--product-card__body {
	padding: 8px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	flex: 1;
}

.rl-mia--product-card__title {
	font-size: 0.6875rem;
	font-weight: 600;
	line-height: 1.35;
	color: var(--wp--preset--color--text-primary);
	margin: 0;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.rl-mia--product-card__meta {
	display: flex;
	align-items: center;
	gap: 6px;
}

.rl-mia--product-card__price {
	font-size: 0.6875rem;
	font-weight: 700;
	color: var(--wp--preset--color--text-secondary);
	white-space: nowrap;
}

.rl-mia--product-card__ctas {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin-top: auto;
}

.rl-mia--product-card__cta {
	display: block;
	padding: 5px 8px;
	border-radius: var(--wp--custom--radius--sm);
	font-size: 0.625rem;
	font-weight: 600;
	text-align: center;
	text-decoration: none;
	line-height: 1.3;
	transition:
		background var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out),
		color var(--wp--custom--motion--duration-fast) var(--wp--custom--motion--ease-out);
}

.rl-mia--product-card__cta--review {
	background: var(--wp--preset--color--accent-blue);
	color: var(--wp--preset--color--white);
}

.rl-mia--product-card__cta--review:hover {
	background: var(--wp--preset--color--blue-deep, #1d4ed8);
	color: var(--wp--preset--color--white);
}

.rl-mia--product-card__cta--ml {
	background: var(--wp--preset--color--bg-soft);
	color: var(--wp--preset--color--text-secondary);
	border: 1px solid var(--wp--preset--color--border);
}

.rl-mia--product-card__cta--ml:hover {
	background: var(--wp--preset--color--border-light);
	color: var(--wp--preset--color--text-primary);
}

.rl-mia--product-card__cta:focus-visible {
	outline: 3px solid var(--wp--preset--color--accent-blue);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

	.rl-mia--product-card {
		transition: none !important;
	}

	.rl-mia--product-card__cta {
		transition: none !important;
	}
}

/* Reset para <button> usados como trigger de Mia (clases diseñadas para <a>). */
button[data-mia-trigger] {
	background: none;
	border: none;
	padding: 0;
	font: inherit;
	cursor: pointer;
	text-align: inherit;
	color: inherit;
}
