/* ============================================================
   TORRES TI MX — Asistente de IA (widget de chat)
   Vive abajo a la DERECHA (posición típica de un chat).
   ============================================================ */

.ai-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 90;
  display: grid; place-items: center;
  width: 58px; height: 58px; border-radius: 50%;
  border: 0; cursor: pointer; color: #fff;
  background: var(--grad);
  box-shadow: 0 14px 30px -8px rgba(37, 99, 235, .6);
  transition: transform .2s;
}
.ai-fab:hover { transform: scale(1.08); }
.ai-fab svg { width: 27px; height: 27px; }

/* Mientras nadie ha abierto el chat, el botón "llama": onda expansiva + sacudida.
   La clase is-alert se quita al abrir el panel por primera vez. */
.ai-fab.is-alert { animation: ai-fab-nudge 5s ease-in-out infinite; }
.ai-fab.is-alert::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  animation: ai-fab-ring 2.5s ease-out infinite;
}
@keyframes ai-fab-ring {
  0%   { box-shadow: 0 0 0 0 rgba(124, 58, 237, .5); }
  70%  { box-shadow: 0 0 0 18px rgba(124, 58, 237, 0); }
  100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0); }
}
@keyframes ai-fab-nudge {
  0%, 78%, 100% { transform: none; }
  82% { transform: rotate(-10deg) scale(1.08); }
  86% { transform: rotate(8deg) scale(1.08); }
  90% { transform: rotate(-5deg) scale(1.04); }
  94% { transform: rotate(0) scale(1); }
}
.ai-fab__badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--cyan); color: var(--dark);
  font-family: var(--font-body); font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px; letter-spacing: .04em;
}

/* ---------- Panel ---------- */
/* La altura descuenta el header fijo (71px) + el botón + un respiro,
   para que el panel nunca quede tapado por la barra superior.
   Se usa dvh (viewport dinámico) para que en móviles y laptops con
   escalado la barra del navegador no "coma" el panel. */
.ai-panel {
  position: fixed; right: 24px; bottom: 96px; z-index: 99;
  width: min(380px, calc(100vw - 48px)); height: min(560px, calc(100dvh - 184px));
  display: none; flex-direction: column; overflow: hidden;
  background: var(--white); border-radius: var(--radius);
  border: 1px solid rgba(15, 23, 42, .08);
  box-shadow: 0 30px 60px -20px rgba(15, 23, 42, .45);
}
.ai-panel.is-open { display: flex; }

.ai-panel__head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; background: var(--grad); color: #fff;
}
.ai-panel__head h3 { font-size: 15px; color: #fff; margin: 0; }
.ai-panel__head p { font-size: 12px; opacity: .85; margin: 0; }
.ai-panel__close {
  margin-left: auto; background: transparent; border: 0; cursor: pointer;
  color: #fff; font-size: 22px; line-height: 1; padding: 4px 6px; border-radius: 8px;
}
.ai-panel__close:hover { background: rgba(255, 255, 255, .18); }

.ai-log {
  flex: 1; overflow-y: auto; padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--light);
  min-height: 110px; /* la conversación nunca queda aplastada por las sugerencias */
}

.ai-msg {
  max-width: 84%; padding: 11px 14px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word;
}
.ai-msg--bot  { align-self: flex-start; background: var(--white); color: var(--dark);
                border: 1px solid rgba(15, 23, 42, .07); border-bottom-left-radius: 5px; }
.ai-msg--user { align-self: flex-end; background: var(--blue); color: #fff;
                border-bottom-right-radius: 5px; }
.ai-msg--error { align-self: center; background: #FEF2F2; color: #991B1B;
                 border: 1px solid #FECACA; font-size: 13px; }

/* Botón de escape a WhatsApp que la IA inserta con [WHATSAPP] */
.ai-wa {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  background: #25D366; color: #fff; text-decoration: none;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 22px -10px rgba(37, 211, 102, .8);
}
.ai-wa:hover { filter: brightness(1.06); }

/* Puntitos de "escribiendo…" */
.ai-typing { display: flex; gap: 4px; align-items: center; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gray-2);
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; }
                       30% { transform: translateY(-5px); opacity: 1; } }

/* Sugerencias iniciales (si no caben, esta zona hace scroll en vez de
   robarle espacio a la conversación) */
.ai-chips {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 14px;
  background: var(--light); flex: none; max-height: 118px; overflow-y: auto;
}
.ai-chip {
  background: var(--white); border: 1px solid rgba(37, 99, 235, .25); color: var(--blue);
  font-family: var(--font-body); font-size: 12.5px; padding: 7px 12px;
  border-radius: 999px; cursor: pointer; transition: background .15s;
}
.ai-chip:hover { background: rgba(37, 99, 235, .07); }

/* ---------- Barra de escritura ---------- */
.ai-form {
  display: flex; gap: 8px; padding: 12px; background: var(--white);
  border-top: 1px solid rgba(15, 23, 42, .08);
}
.ai-form input {
  flex: 1; border: 1px solid rgba(15, 23, 42, .14); border-radius: 999px;
  padding: 11px 16px; font-family: var(--font-body); font-size: 14px; color: var(--dark);
  outline: none;
}
.ai-form input:focus { border-color: var(--blue); }
.ai-form button {
  display: grid; place-items: center; width: 42px; height: 42px; flex: none;
  border: 0; border-radius: 50%; cursor: pointer; color: #fff; background: var(--grad);
}
.ai-form button:disabled { opacity: .45; cursor: not-allowed; }
.ai-form button svg { width: 18px; height: 18px; }

.ai-disclaimer {
  padding: 0 14px 10px; background: var(--white);
  font-size: 10.5px; color: var(--gray); text-align: center;
}

/* ============================================================
   Robot invitador — se asoma cada 5 s hasta que abren el chat.
   Es un <button>: clicarlo abre el asistente.
   ============================================================ */
.ai-teaser {
  position: fixed; right: 20px; bottom: 94px; z-index: 89;
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0; cursor: pointer;
  opacity: 0; pointer-events: none;
  transform: translateY(18px) scale(.85); transform-origin: bottom right;
  transition: opacity .3s ease, transform .45s cubic-bezier(.34, 1.56, .64, 1);
}
.ai-teaser.is-visible { opacity: 1; pointer-events: auto; transform: none; }

.ai-teaser__bubble {
  position: relative; max-width: 200px; text-align: left;
  background: var(--white); color: var(--dark);
  font-family: var(--font-body); font-size: 13.5px; line-height: 1.45;
  padding: 12px 14px; border-radius: 16px 16px 4px 16px;
  border: 1px solid rgba(37, 99, 235, .18);
  box-shadow: 0 18px 38px -14px rgba(15, 23, 42, .35);
}
.ai-teaser__bubble strong { color: var(--blue); }

.ai-teaser__robot {
  width: 80px; height: auto; flex: none;
  filter: drop-shadow(0 10px 14px rgba(15, 23, 42, .18));
}

/* Piezas animadas del robot (el SVG va inline, así el CSS le llega) */
.ai-robot__body { animation: ai-robot-float 3s ease-in-out infinite; }
@keyframes ai-robot-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.ai-robot__eye {
  transform-box: fill-box; transform-origin: center;
  animation: ai-robot-blink 4.2s infinite;
}
@keyframes ai-robot-blink {
  0%, 91%, 98%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(.12); }
}

/* Logo TI del pecho: late con un brillo morado */
.ai-robot__chest {
  transform-box: fill-box; transform-origin: center;
  animation: ai-robot-chest 2s ease-in-out infinite;
}
@keyframes ai-robot-chest {
  0%, 100% { transform: scale(1); filter: none; }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 5px rgba(124, 58, 237, .9)); }
}

.ai-robot__arm--r {
  transform-box: fill-box; transform-origin: 50% 12%;
  animation: ai-robot-wave 2.6s ease-in-out infinite;
}
@keyframes ai-robot-wave {
  0%, 55%, 100% { transform: rotate(0); }
  65% { transform: rotate(24deg); }
  75% { transform: rotate(-8deg); }
  85% { transform: rotate(16deg); }
}

/* ---------- Responsive ---------- */

@media (max-width: 520px) {
  .ai-panel { left: 12px; right: 12px; width: auto; bottom: 88px; height: calc(100dvh - 172px); }
  .ai-fab { right: 16px; bottom: 20px; }
  .ai-teaser { right: 14px; bottom: 88px; }
  .ai-teaser__robot { width: 62px; }
  .ai-teaser__bubble { max-width: 158px; font-size: 12.5px; padding: 10px 12px; }
}

/* Pantallas "chaparras" (laptops con escalado de Windows, ventanas chicas):
   se compacta todo para que la conversación siempre tenga espacio. */
@media (max-height: 700px) {
  .ai-panel { bottom: 86px; height: calc(100dvh - 168px); }
  .ai-log { padding: 14px; gap: 10px; }
  .ai-msg { font-size: 13.5px; padding: 9px 12px; }
  .ai-chips { padding: 0 14px 10px; max-height: 84px; }
  .ai-chip { font-size: 12px; padding: 6px 10px; }
  .ai-form { padding: 10px; }
  .ai-form input { padding: 9px 14px; }
  .ai-disclaimer { font-size: 9.5px; padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-fab, .ai-fab.is-alert::before, .ai-typing span,
  .ai-robot__body, .ai-robot__eye, .ai-robot__chest, .ai-robot__arm--r {
    transition: none; animation: none;
  }
  .ai-teaser { transition: opacity .2s ease; transform: none; }
}
