/*  ─────────────────────────────────────────────────────────
 *  El Guardia (IA) — UI walking-guardian + panel de chat
 *  ─────────────────────────────────────────────────────── */

:root {
	--aig-gold:      #d4ad54;
	--aig-gold-soft: rgba(212,173,84,.45);
	--aig-bg-deep:   #11131a;
	--aig-bg-card:   #1a1d28;
	--aig-bg-line:   rgba(255,255,255,.08);
	--aig-text:      #e8e9ec;
	--aig-muted:     #9aa0aa;
	--aig-accent:    #7b3030;
	--aig-blue:      #2a3f6e;
}

/* ────────  Escenario: faja inferior por la que patrulla  ──────── */
.aig-stage {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	height: 170px;
	pointer-events: none;
	z-index: 38;                /* debajo de .wlm-stack (~50) y de modales */
	overflow: hidden;
}

.aig-character {
	position: absolute;
	left: 24px;
	bottom: 12px;
	width: 96px;
	height: 132px;
	padding: 0;
	margin: 0;
	background: transparent;
	border: 0;
	cursor: pointer;
	pointer-events: auto;
	transition: filter .25s ease, transform .25s ease;
	-webkit-tap-highlight-color: transparent;
}

.aig-character:focus-visible {
	outline: 2px solid var(--aig-gold);
	outline-offset: 4px;
	border-radius: 6px;
}

.aig-character-shadow {
	position: absolute;
	left: 50%;
	bottom: 0;
	width: 78px;
	height: 14px;
	margin-left: -39px;
	border-radius: 50%;
	background: radial-gradient(ellipse at center, rgba(0,0,0,.55) 0%, rgba(0,0,0,.35) 35%, rgba(0,0,0,0) 75%);
	filter: blur(1.5px);
	transform: scaleX(1);
	transition: transform .15s ease, opacity .15s ease;
	z-index: 1;
}

.aig-character-body {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	z-index: 2;
	transform-origin: 50% 100%;
	animation: aig-walk 540ms ease-in-out infinite;
	will-change: transform;
}

.aig-character-body[data-state="idle"] {
	animation: aig-idle 2400ms ease-in-out infinite;
}

.aig-character-body[data-state="alert"] {
	animation: aig-alert 280ms ease-in-out 3;
}

.aig-character-sprite {
	max-width: 100%;
	max-height: 100%;
	height: auto;
	width: auto;
	user-select: none;
	-webkit-user-drag: none;
	image-rendering: -webkit-optimize-contrast;
	image-rendering: crisp-edges;
	filter: drop-shadow(0 4px 6px rgba(0,0,0,.45));
}

/* Espejado cuando camina a la izquierda: aplicado al sprite img, no al body,
   así no rompe la animación de transform del body. */
.aig-character[data-facing="left"] .aig-character-sprite {
	transform: scaleX(-1);
}
.aig-character[data-facing="right"] .aig-character-sprite {
	transform: scaleX(1);
}

/* Pausa la animación si está hablando (panel abierto) */
.aig-character[data-talking="1"] .aig-character-body {
	animation: aig-idle 2200ms ease-in-out infinite;
}

/* ────────  Burbujita de habla contextual  ──────── */
.aig-bubble {
	position: absolute;
	left: 100%;
	bottom: 70%;
	margin-left: 14px;
	min-width: 140px;
	max-width: 260px;
	padding: 8px 12px 9px;
	background: var(--aig-bg-card);
	color: var(--aig-text);
	border: 1px solid var(--aig-gold-soft);
	border-radius: 10px;
	box-shadow: 0 14px 30px rgba(0,0,0,.55), 0 0 0 1px rgba(0,0,0,.4) inset;
	font-size: 13px;
	line-height: 1.35;
	z-index: 3;
	opacity: 0;
	transform: translateY(6px);
	transition: opacity .2s ease, transform .2s ease;
	pointer-events: none;
}
.aig-bubble:not([hidden]) {
	opacity: 1;
	transform: translateY(0);
}
.aig-bubble::before {
	content: "";
	position: absolute;
	left: -6px;
	bottom: 14px;
	width: 0;
	height: 0;
	border-top: 6px solid transparent;
	border-bottom: 6px solid transparent;
	border-right: 8px solid var(--aig-gold-soft);
}
.aig-bubble::after {
	content: "";
	position: absolute;
	left: -5px;
	bottom: 15px;
	width: 0;
	height: 0;
	border-top: 5px solid transparent;
	border-bottom: 5px solid transparent;
	border-right: 7px solid var(--aig-bg-card);
}

.aig-character[data-facing="right"] .aig-bubble {
	left: 100%;
	right: auto;
	margin-left: 14px;
	margin-right: 0;
}
.aig-character[data-facing="left"] .aig-bubble {
	left: auto;
	right: 100%;
	margin-right: 14px;
	margin-left: 0;
}
.aig-character[data-facing="left"] .aig-bubble::before {
	left: auto;
	right: -6px;
	border-right: 0;
	border-left: 8px solid var(--aig-gold-soft);
}
.aig-character[data-facing="left"] .aig-bubble::after {
	left: auto;
	right: -5px;
	border-right: 0;
	border-left: 7px solid var(--aig-bg-card);
}

.aig-character-badge {
	position: absolute;
	top: 4px;
	right: -4px;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 9px;
	background: var(--aig-accent);
	color: #fff;
	font-size: 11px;
	font-weight: 800;
	line-height: 18px;
	text-align: center;
	border: 2px solid var(--aig-bg-deep);
	box-shadow: 0 4px 10px rgba(0,0,0,.5);
	z-index: 4;
}

/* Hover effect: el guardia se ilumina y se "alza" un poquito */
.aig-character:hover {
	filter: drop-shadow(0 0 8px var(--aig-gold-soft));
	transform: translateY(-3px);
}

/* ────────  Animaciones  ──────── */
/* Caminata: combinación de bob vertical + rocking lateral para que parezca marchar */
@keyframes aig-walk {
	0%   { transform: translateY(0)    rotate(0deg); }
	25%  { transform: translateY(-6px) rotate(-2.5deg); }
	50%  { transform: translateY(0)    rotate(0deg); }
	75%  { transform: translateY(-6px) rotate(2.5deg); }
	100% { transform: translateY(0)    rotate(0deg); }
}
@keyframes aig-idle {
	0%, 100% { transform: translateY(0) scale(1); }
	50%      { transform: translateY(-2px) scale(1.01); }
}
@keyframes aig-alert {
	0%, 100% { transform: translateY(0) scale(1); }
	50%      { transform: translateY(-8px) scale(1.06); }
}

/* Reduced motion: parar todo */
@media (prefers-reduced-motion: reduce) {
	.aig-character-body,
	.aig-character-body[data-state="idle"],
	.aig-character-body[data-state="alert"] {
		animation: none !important;
	}
	.aig-character {
		transition: none !important;
	}
}

/* ────────  Panel de chat  ──────── */
.aig-panel {
	position: fixed;
	left: 24px;
	bottom: 168px;          /* arriba del guardia caminando */
	width: 420px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 200px);
	background: linear-gradient(180deg, #181b25 0%, #11131a 100%);
	border: 1px solid var(--aig-gold-soft);
	border-radius: 14px;
	box-shadow: 0 30px 60px rgba(0,0,0,.7), 0 0 0 1px rgba(0,0,0,.4) inset;
	color: var(--aig-text);
	display: none;
	flex-direction: column;
	z-index: 42;
	overflow: hidden;
	transform: translateY(20px);
	opacity: 0;
	transition: transform .25s cubic-bezier(.2,.7,.2,1), opacity .2s ease;
}
.aig-panel.is-open {
	display: flex;
	opacity: 1;
	transform: translateY(0);
}

.aig-panel::before {
	content: "";
	position: absolute;
	left: 38px;
	bottom: -8px;
	width: 16px;
	height: 16px;
	background: linear-gradient(135deg, transparent 0 50%, #11131a 50% 100%);
	border-right: 1px solid var(--aig-gold-soft);
	border-bottom: 1px solid var(--aig-gold-soft);
	transform: rotate(45deg);
}

.aig-panel-head {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 14px;
	background: linear-gradient(180deg, rgba(212,173,84,.06) 0%, rgba(212,173,84,0) 100%);
	border-bottom: 1px solid var(--aig-bg-line);
	flex-shrink: 0;
}

.aig-panel-portrait {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	object-fit: cover;
	object-position: center 18%;
	background: var(--aig-bg-deep);
	border: 2px solid var(--aig-gold-soft);
	box-shadow: 0 0 0 1px rgba(0,0,0,.6);
	flex-shrink: 0;
}

.aig-panel-title-wrap {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	line-height: 1.2;
}
.aig-panel-title-wrap strong {
	font-size: 15px;
	color: var(--aig-text);
	font-weight: 800;
	letter-spacing: .01em;
}
.aig-panel-sub {
	font-size: 12px;
	color: var(--aig-muted);
}

.aig-panel-actions {
	display: flex;
	gap: 6px;
}
.aig-panel-iconbtn {
	background: rgba(255,255,255,.04);
	border: 1px solid var(--aig-bg-line);
	color: var(--aig-text);
	width: 32px;
	height: 32px;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease;
}
.aig-panel-iconbtn:hover {
	background: rgba(212,173,84,.12);
	border-color: var(--aig-gold-soft);
}

/* Body */
.aig-panel-body {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}
.aig-panel-body::-webkit-scrollbar {
	width: 8px;
}
.aig-panel-body::-webkit-scrollbar-thumb {
	background: rgba(255,255,255,.1);
	border-radius: 4px;
}

.aig-msg {
	max-width: 88%;
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.aig-msg[data-role="user"] {
	align-self: flex-end;
	align-items: flex-end;
}
.aig-msg[data-role="assistant"] {
	align-self: flex-start;
	align-items: flex-start;
}
.aig-msg-bubble {
	padding: 9px 12px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.aig-msg[data-role="user"] .aig-msg-bubble {
	background: var(--aig-blue);
	color: #f0f3fa;
	border: 1px solid rgba(123,150,210,.4);
	border-bottom-right-radius: 4px;
}
.aig-msg[data-role="assistant"] .aig-msg-bubble {
	background: rgba(212,173,84,.08);
	color: var(--aig-text);
	border: 1px solid var(--aig-gold-soft);
	border-bottom-left-radius: 4px;
}
.aig-msg-bubble p {
	margin: 0 0 8px;
}
.aig-msg-bubble p:last-child {
	margin: 0;
}
.aig-msg-bubble strong {
	color: var(--aig-gold);
}
.aig-msg-bubble code {
	background: rgba(0,0,0,.3);
	border-radius: 4px;
	padding: 1px 5px;
	font-size: 90%;
}
.aig-msg-bubble ul,
.aig-msg-bubble ol {
	margin: 6px 0;
	padding-left: 22px;
}
.aig-msg-bubble li {
	margin: 2px 0;
}

.aig-msg-actions {
	display: flex;
	gap: 6px;
	margin-top: 2px;
}
.aig-msg-rate {
	background: transparent;
	border: 0;
	color: var(--aig-muted);
	font-size: 12px;
	padding: 2px 4px;
	cursor: pointer;
	border-radius: 4px;
}
.aig-msg-rate:hover {
	color: var(--aig-text);
	background: rgba(255,255,255,.05);
}
.aig-msg-rate.is-active {
	color: var(--aig-gold);
}

/* Compose */
.aig-panel-compose {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 10px 12px 12px;
	border-top: 1px solid var(--aig-bg-line);
	background: rgba(0,0,0,.18);
	flex-shrink: 0;
}
.aig-panel-suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}
.aig-suggestion {
	background: rgba(212,173,84,.08);
	border: 1px solid var(--aig-gold-soft);
	color: var(--aig-text);
	font-size: 12px;
	padding: 5px 10px;
	border-radius: 999px;
	cursor: pointer;
	transition: background .15s ease, transform .1s ease;
	white-space: nowrap;
}
.aig-suggestion:hover {
	background: rgba(212,173,84,.18);
	transform: translateY(-1px);
}
.aig-panel-compose-row {
	display: flex;
	gap: 8px;
}
.aig-panel-input {
	flex: 1;
	background: var(--aig-bg-deep);
	border: 1px solid var(--aig-bg-line);
	color: var(--aig-text);
	font-size: 14px;
	padding: 10px 12px;
	border-radius: 10px;
	transition: border-color .15s ease;
	min-width: 0;
}
.aig-panel-input:focus {
	outline: none;
	border-color: var(--aig-gold-soft);
}
.aig-panel-input::placeholder {
	color: var(--aig-muted);
}
.aig-panel-send {
	background: linear-gradient(180deg, #d4ad54 0%, #a3811d 100%);
	border: 1px solid #d4ad54;
	color: #1a1d28;
	width: 44px;
	height: 44px;
	border-radius: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex-shrink: 0;
	transition: filter .15s ease;
}
.aig-panel-send:hover { filter: brightness(1.1); }
.aig-panel-send:disabled {
	background: var(--aig-bg-line);
	border-color: var(--aig-bg-line);
	color: var(--aig-muted);
	cursor: not-allowed;
}

.aig-panel-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 11px;
	color: var(--aig-muted);
	min-height: 14px;
}
.aig-panel-quota {
	font-variant-numeric: tabular-nums;
}
.aig-panel-thinking {
	display: inline-flex;
	gap: 4px;
	align-items: center;
}
.aig-dot {
	width: 6px;
	height: 6px;
	background: var(--aig-gold);
	border-radius: 50%;
	animation: aig-thinking 900ms ease-in-out infinite;
}
.aig-dot:nth-child(2) { animation-delay: 150ms; }
.aig-dot:nth-child(3) { animation-delay: 300ms; }
@keyframes aig-thinking {
	0%, 80%, 100% { opacity: .25; transform: translateY(0); }
	40%           { opacity: 1;  transform: translateY(-3px); }
}

/* ────────  Layout impacts (no tapar contenido del feed)  ──────── */
body.social-body {
	padding-bottom: 0;
}

/* ────────  Mobile  ──────── */
@media (max-width: 767px) {
	.aig-stage {
		height: 0;
		pointer-events: none;
	}
	.aig-character {
		left: 12px;
		bottom: 86px;            /* arriba del wlm-stack en mobile */
		width: 64px;
		height: 88px;
		position: fixed;
		pointer-events: auto;
		z-index: 39;
	}
	.aig-character-body {
		animation: aig-idle 2400ms ease-in-out infinite !important;
	}
	.aig-character-shadow {
		width: 50px;
		height: 10px;
		margin-left: -25px;
	}
	.aig-bubble {
		display: none !important;
	}
	.aig-panel {
		left: 0;
		right: 0;
		bottom: 0;
		width: 100vw;
		max-width: 100vw;
		height: 75vh;
		max-height: 75vh;
		border-radius: 16px 16px 0 0;
	}
	.aig-panel::before {
		display: none;
	}
	.aig-panel.is-open {
		transform: translateY(0);
	}
}

/* ────────  Coordinación con otros widgets flotantes  ──────── */
/* Cuando el messenger está abierto en desktop, corremos el panel para no chocar */
body.has-messenger-open .aig-panel {
	transform: translateY(0) translateX(-460px);
}
@media (max-width: 1100px) {
	body.has-messenger-open .aig-panel {
		transform: translateY(0);
	}
}
