/* Colaby mascot + chat (ManyChat-like) + FAB stack */
:root {
  --colaby-asst-teal: #008c95;
  --colaby-asst-teal-hover: #007780;
  --colaby-asst-bg: #f4f6f8;
  --colaby-asst-text: #111827;
  --colaby-asst-muted: #6b7280;
  --colaby-asst-border: #e5e7eb;
  --colaby-mascot-fab-size: 64px;
  --colaby-fab-gap: 12px;
  --colaby-fab-stack-offset: calc(
    var(--colaby-mascot-fab-size) + var(--colaby-fab-gap) + env(safe-area-inset-bottom, 0px) + 12px
  );
}

.colaby-mascot {
  width: 88px;
  height: 88px;
  flex-shrink: 0;
  position: relative;
}
.colaby-mascot--loading {
  visibility: hidden !important;
}
.colaby-mascot__stage {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background: #dceef8;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
}
.colaby-mascot__frame,
.colaby-mascot__fallback,
.colaby-mascot__canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}
.colaby-mascot__frame--base,
.colaby-mascot__frame--overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.colaby-mascot__frame--overlay {
  opacity: 0;
  transition: opacity 60ms linear;
  pointer-events: none;
}

/* Gestos por acción */
.colaby-mascot[data-state='idle'] .colaby-mascot__stage,
.colaby-mascot[data-state='listening'] .colaby-mascot__stage {
  animation: colaby-mascot-float 3.2s ease-in-out infinite;
}
.colaby-mascot--is-bouncy[data-state='listening'] .colaby-mascot__stage {
  animation: colaby-mascot-blah 0.44s ease-in-out infinite;
}
.colaby-mascot--is-bouncy[data-state='idle'] .colaby-mascot__stage {
  animation: colaby-mascot-float-bouncy 2.4s ease-in-out infinite;
}
.colaby-mascot--is-soft[data-state='idle'] .colaby-mascot__stage {
  animation: colaby-mascot-float 3.6s ease-in-out infinite;
}
.colaby-mascot[data-state='fidget_look'] .colaby-mascot__stage {
  animation: colaby-mascot-look-aside 1.2s ease-in-out;
}
.colaby-mascot[data-state='fidget_bored'] .colaby-mascot__stage {
  animation: colaby-mascot-sigh 1.1s ease;
}
.colaby-mascot--is-soft[data-state='fidget_bored'] .colaby-mascot__stage {
  animation: colaby-mascot-six-seven 1.25s ease-in-out;
}
.colaby-mascot[data-state='fidget_yawn'] .colaby-mascot__stage {
  animation: colaby-mascot-yawn 1.15s ease;
}
/* Hipopótamo: se agacha y se asoma de nuevo */
.colaby-mascot[data-state='fidget_peek'] .colaby-mascot__stage {
  animation: colaby-mascot-hippo 1.6s ease-in-out;
}
.colaby-mascot[data-state='fidget_ok'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.9s ease;
}
.colaby-mascot[data-state='fidget_mmm'] .colaby-mascot__stage {
  animation: colaby-mascot-mmm 1.15s ease;
}
.colaby-mascot[data-state='fidget_peace'] .colaby-mascot__stage {
  animation: colaby-mascot-look-aside 1.2s ease-in-out;
}
.colaby-mascot[data-state='fidget_kiss'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.9s ease;
}
.colaby-mascot[data-state='fidget_tongue'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.85s ease;
}
.colaby-mascot[data-state='fidget_ears'] .colaby-mascot__stage {
  animation: colaby-mascot-wiggle 0.9s ease;
}
.colaby-mascot[data-state='fidget_callme'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.9s ease;
}
.colaby-mascot[data-state='fidget_eyeroll'] .colaby-mascot__stage {
  animation: colaby-mascot-look-aside 1.15s ease-in-out;
}
.colaby-mascot[data-state='fidget_shrug'] .colaby-mascot__stage {
  animation: colaby-mascot-sigh 1.1s ease;
}
.colaby-mascot[data-state='fidget_heart'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.95s ease;
}
.colaby-mascot[data-state='fidget_angry'] .colaby-mascot__stage {
  animation: colaby-mascot-angry 1.3s ease;
}
.colaby-mascot[data-state='fidget_told_you'] .colaby-mascot__stage {
  animation: colaby-mascot-look-aside 1.2s ease-in-out;
}
.colaby-mascot[data-state='fidget_scold'] .colaby-mascot__stage {
  animation: colaby-mascot-angry 1.25s ease;
}
.colaby-mascot[data-state='fidget_hurry'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.95s ease;
}
.colaby-mascot[data-state='fidget_big_smile'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 1s ease;
}
.colaby-mascot--natu[data-state='fidget_bored'] .colaby-mascot__stage {
  animation: colaby-mascot-yawn 1.2s ease;
}
.colaby-mascot--pokeable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.colaby-mascot--pokeable:focus-visible {
  outline: 2px solid rgba(33, 150, 243, 0.55);
  outline-offset: 2px;
  border-radius: 50%;
}
.colaby-mascot[data-state='thinking'] .colaby-mascot__stage {
  animation: colaby-mascot-pulse 0.9s ease-in-out infinite;
}
.colaby-mascot[data-state='talk'] .colaby-mascot__stage {
  animation: colaby-mascot-talk 0.45s ease-in-out infinite;
}
.colaby-mascot--is-bouncy[data-state='talk'] .colaby-mascot__stage {
  animation: colaby-mascot-talk 0.35s ease-in-out infinite;
}
.colaby-mascot[data-state='reply'] .colaby-mascot__stage {
  animation: colaby-mascot-bounce 0.55s ease;
}
.colaby-mascot[data-state='confused'] .colaby-mascot__stage {
  animation: colaby-mascot-wiggle 0.6s ease;
}
.colaby-mascot[data-state='warn'] .colaby-mascot__stage {
  animation: colaby-mascot-shake 0.45s ease;
}
@keyframes colaby-mascot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes colaby-mascot-float-bouncy {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes colaby-mascot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes colaby-mascot-talk {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.03); }
}
@keyframes colaby-mascot-blah {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  25% { transform: translateY(-1px) rotate(-4deg) scale(1.02); }
  50% { transform: translateY(-3px) rotate(2deg) scale(1.04); }
  75% { transform: translateY(-1px) rotate(-3deg) scale(1.02); }
}
@keyframes colaby-mascot-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes colaby-mascot-angry {
  0% { transform: translateX(0) scale(1); }
  15% { transform: translateX(-4px) scale(1.04); }
  30% { transform: translateX(4px) scale(1.05); }
  45% { transform: translateX(-3px) scale(1.04); }
  60% { transform: translateX(3px) scale(1.03); }
  100% { transform: translateX(0) scale(1); }
}
@keyframes colaby-mascot-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}
@keyframes colaby-mascot-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
/* Clippy-ish fidgets */
@keyframes colaby-mascot-look-aside {
  0% { transform: translateX(0) rotate(0deg); }
  35% { transform: translateX(4px) rotate(4deg); }
  70% { transform: translateX(-2px) rotate(-2deg); }
  100% { transform: translateX(0) rotate(0deg); }
}
@keyframes colaby-mascot-sigh {
  0% { transform: translateY(0) scale(1) rotate(0deg); }
  35% { transform: translateY(2px) scale(0.96) rotate(-3deg); }
  100% { transform: translateY(0) scale(1) rotate(0deg); }
}
@keyframes colaby-mascot-six-seven {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  25% { transform: translateY(-2px) rotate(-4deg) scale(1.03); }
  50% { transform: translateY(0) rotate(4deg) scale(1.02); }
  75% { transform: translateY(-1px) rotate(-3deg) scale(1.03); }
  100% { transform: translateY(0) rotate(0deg) scale(1); }
}
@keyframes colaby-mascot-yawn {
  0% { transform: scale(1); }
  45% { transform: scale(1.04) translateY(-2px); }
  100% { transform: scale(1); }
}
@keyframes colaby-mascot-hippo {
  0% { transform: translateY(0); }
  30% { transform: translateY(14px); }
  70% { transform: translateY(6px); }
  100% { transform: translateY(0); }
}
@keyframes colaby-mascot-mmm {
  0% { transform: translateY(0) rotate(0deg); }
  45% { transform: translateY(-3px) rotate(-2deg); }
  100% { transform: translateY(0) rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .colaby-mascot[data-state] .colaby-mascot__stage {
    animation: none !important;
  }
}

/* Theito: solo oculta el FAB ? viejo; la top bar sigue abriendo la biblioteca */
body.colaby-assistant-theito #colabyAyudaFab,
body.colaby-assistant-theito .colaby-ayuda-fab {
  display: none !important;
}

/* Stack FABs: mascota ancla abajo; WA/scroll/ayuda arriba */
body.colaby-assistant-jazita,
body.colaby-assistant-theito {
  --colaby-fab-stack-offset: calc(
    var(--colaby-mascot-fab-size) + var(--colaby-fab-gap) + env(safe-area-inset-bottom, 0px) + 12px
  );
}
body.colaby-assistant-jazita .landing-page ~ .floating-buttons,
body.colaby-assistant-jazita .floating-buttons,
.landing-page.colaby-assistant-jazita ~ .floating-buttons {
  bottom: calc(var(--colaby-fab-stack-offset) + 8px) !important;
}
/* Panel SaaS: WA + subir arriba de Theito (mismo stack que landing/Jazita) */
body.colaby-assistant-theito .floating-buttons {
  bottom: calc(var(--colaby-fab-stack-offset) + 8px) !important;
}
body.colaby-assistant-theito .colaby-ayuda-fab {
  bottom: calc(var(--colaby-fab-stack-offset) + 4px) !important;
}

.colaby-assistant-fab {
  position: fixed !important;
  right: max(14px, env(safe-area-inset-right, 0px)) !important;
  /* Arriba del borde inferior: evita quedar bajo chrome/safe-area al cargar */
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px)) !important;
  /* Por encima del navbar/floating; debajo de modales landing (12k+) */
  z-index: 11050 !important;
  width: var(--colaby-mascot-fab-size);
  height: var(--colaby-mascot-fab-size);
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: transparent;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.2);
  transform: translateZ(0);
  /* Visible desde el primer paint; no depende del scroll */
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
body.colaby-assistant-jazita .colaby-assistant-fab--landing {
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px)) !important;
}
.colaby-assistant-fab .colaby-mascot {
  width: 100%;
  height: 100%;
}

/* Globo de saludo al aparecer (sin abrir el panel) */
.colaby-assistant-teaser {
  position: fixed !important;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(
    var(--colaby-mascot-fab-size) + 28px + env(safe-area-inset-bottom, 0px)
  );
  z-index: 11051 !important;
  max-width: min(260px, calc(100vw - 88px));
  padding: 10px 12px;
  background: #fff;
  color: var(--colaby-asst-text);
  border: 1px solid var(--colaby-asst-border);
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  font-size: 0.875rem;
  line-height: 1.35;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.colaby-assistant-teaser.is-on {
  opacity: 1;
  transform: translateY(0);
}
.colaby-assistant-teaser.is-off {
  opacity: 0;
  pointer-events: none;
}
.colaby-assistant-bubble strong {
  font-weight: 700;
  color: inherit;
}
.colaby-assistant-bubble a {
  color: var(--colaby-asst-teal);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-word;
}

.colaby-assistant-panel {
  --colaby-asst-panel-bottom: calc(
    var(--colaby-mascot-fab-size) + 24px + env(safe-area-inset-bottom, 0px)
  );
  position: fixed;
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: var(--colaby-asst-panel-bottom);
  z-index: 1041;
  width: min(380px, calc(100vw - 24px));
  max-height: min(520px, calc(100dvh - 120px));
  display: none;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  border: 1px solid var(--colaby-asst-border);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (max-width: 576px) {
  :root {
    --colaby-mascot-fab-size: 56px;
  }
  .colaby-assistant-panel {
    right: 8px;
    left: 8px;
    width: auto;
    max-height: min(70dvh, calc(100dvh - 100px));
  }
  .colaby-assistant-panel__head .colaby-mascot {
    width: 56px;
    height: 56px;
  }
}
.colaby-assistant-panel.is-open {
  display: flex;
}
.colaby-assistant-panel__head {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: linear-gradient(135deg, #0f2744, #1a4a6e);
  color: #ffffff;
}
.colaby-assistant-panel__head strong,
.colaby-assistant-panel__head span {
  color: #ffffff !important;
}
.colaby-assistant-panel__head strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
}
.colaby-assistant-panel__head span {
  display: block;
  font-size: 0.8rem;
  opacity: 0.92;
}
.colaby-assistant-panel__close {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: #ffffff !important;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

/* ManyChat-like bubbles */
.colaby-assistant-panel__msgs {
  flex: 1;
  overflow: auto;
  padding: 14px 12px;
  background: var(--colaby-asst-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.colaby-assistant-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9375rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.colaby-assistant-bubble--bot {
  align-self: flex-start;
  background: #ffffff !important;
  border: 1px solid var(--colaby-asst-border);
  color: var(--colaby-asst-text) !important;
  border-bottom-left-radius: 4px;
}
.colaby-assistant-bubble--bot a {
  color: var(--colaby-asst-teal) !important;
}
.colaby-assistant-bubble--user {
  align-self: flex-end;
  background: var(--colaby-asst-teal) !important;
  border: none;
  color: #ffffff !important;
  border-bottom-right-radius: 4px;
}
.colaby-assistant-bubble--user * {
  color: #ffffff !important;
}
.colaby-assistant-sources {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--colaby-asst-muted) !important;
}
.colaby-assistant-panel__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  background: var(--colaby-asst-bg);
}
.colaby-assistant-panel__chips button {
  border: 1px solid var(--colaby-asst-border);
  background: #fff;
  color: var(--colaby-asst-text) !important;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
}
.colaby-assistant-panel__chips button:hover {
  border-color: var(--colaby-asst-teal);
  color: var(--colaby-asst-teal) !important;
}
.colaby-assistant-panel__report {
  padding: 0 12px 8px;
  border-top: 1px solid var(--colaby-asst-border);
  background: #f8fafc;
}
.colaby-assistant-report-btn {
  width: 100%;
  border: 1px dashed #f59e0b;
  background: #fffbeb;
  color: #92400e !important;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.colaby-assistant-report-btn:hover {
  background: #fef3c7;
}
.colaby-assistant-panel__form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--colaby-asst-border);
  background: #fff;
}
.colaby-assistant-panel__form input {
  flex: 1;
  border: 1px solid var(--colaby-asst-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9375rem;
  color: var(--colaby-asst-text) !important;
  background: #fff;
}
.colaby-assistant-panel__form input::placeholder {
  color: var(--colaby-asst-muted);
}
.colaby-assistant-panel__form button {
  border: 0;
  border-radius: 10px;
  background: var(--colaby-asst-teal);
  color: #ffffff !important;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}
.colaby-assistant-panel__form button:hover {
  background: var(--colaby-asst-teal-hover);
}
.colaby-assistant-panel__form button:disabled,
.colaby-assistant-panel__form input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
