/* ══════════════════════════════════════════════════════════════════
   ASISTENTE IA — burbuja flotante + panel de chat
   Diseñado para ser un "extra" discreto: una esquina, sin invadir.
   La lógica está en assets/js/chat.js · el backend en api/
   ══════════════════════════════════════════════════════════════════ */

.chat {
  position: fixed;
  right: 1.6rem;
  bottom: 1.6rem;
  z-index: var(--z-chat);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1rem;
}

/* ---------- Burbuja flotante (FAB) ---------- */
.chat__fab {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--grad);
  color: #03271b;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 28px rgba(0, 229, 160, 0.35);
  transition: transform 0.3s var(--ease), box-shadow 0.3s;
  /* llama la atención al cargar, solo 3 veces para no ser pesado */
  animation: fab-pulse 2.6s ease-out 1.2s 3;
}
.chat__fab:hover { transform: scale(1.08); box-shadow: 0 10px 34px rgba(0, 229, 160, 0.5); }
.chat__fab:active { transform: scale(0.96); }
.chat__fab svg { width: 25px; height: 25px; position: absolute; transition: opacity 0.2s, transform 0.3s var(--ease); }
.chat__fab-close { opacity: 0; transform: rotate(-90deg); }
.chat.open .chat__fab-icon { opacity: 0; transform: rotate(90deg); }
.chat.open .chat__fab-close { opacity: 1; transform: rotate(0); }

@keyframes fab-pulse {
  0%   { box-shadow: 0 8px 28px rgba(0, 229, 160, 0.35), 0 0 0 0 rgba(0, 229, 160, 0.45); }
  60%  { box-shadow: 0 8px 28px rgba(0, 229, 160, 0.35), 0 0 0 16px rgba(0, 229, 160, 0); }
  100% { box-shadow: 0 8px 28px rgba(0, 229, 160, 0.35), 0 0 0 0 rgba(0, 229, 160, 0); }
}

/* Tooltip de la burbuja */
.chat__tip {
  position: absolute;
  right: calc(100% + 0.9rem);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  white-space: nowrap;
  padding: 0.45rem 0.9rem;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: 0.75rem;
  color: var(--txt-2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, transform 0.25s var(--ease), visibility 0.25s;
  pointer-events: none;
}
.chat__fab:hover .chat__tip, .chat__fab:focus-visible .chat__tip {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) translateX(0);
}
.chat.open .chat__tip { display: none; }

/* ---------- Panel ---------- */
.chat__panel {
  width: min(384px, calc(100vw - 2.5rem));
  height: min(560px, calc(100vh - 8rem));
  height: min(560px, calc(100svh - 8rem));
  display: flex;
  flex-direction: column;
  background: rgba(9, 14, 25, 0.92);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-in 0.32s var(--ease);
}
.chat__panel[hidden] { display: none; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 21, 38, 0.7);
}
.chat__head h3 { font-size: 1rem; }
.chat__status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.15rem;
}
.chat__status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  transition: background 0.3s;
}
.chat__status-text { font-size: 0.7rem; color: var(--txt-3); letter-spacing: 0.05em; }

/* Estados del asistente (chat.js cambia data-state) */
.chat__panel[data-state="online"] .chat__status-dot { background: var(--mint); box-shadow: 0 0 8px rgba(0, 229, 160, 0.8); }
.chat__panel[data-state="demo"] .chat__status-dot { background: var(--warn); }
.chat__panel[data-state="checking"] .chat__status-dot { background: var(--warn); animation: blink 1s steps(1) infinite; }
.chat__panel[data-state="error"] .chat__status-dot { background: var(--err); }

.chat__close {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  color: var(--txt-3);
  transition: color 0.2s, background 0.2s;
}
.chat__close:hover { color: var(--txt-1); background: rgba(148, 163, 184, 0.1); }
.chat__close svg { width: 16px; height: 16px; }

/* Aviso de modo demo */
.chat__banner {
  padding: 0.5rem 1.15rem;
  background: rgba(251, 191, 36, 0.08);
  border-bottom: 1px solid rgba(251, 191, 36, 0.25);
  color: var(--warn);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}
.chat__banner[hidden] { display: none; }

/* ---------- Mensajes ---------- */
.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  scrollbar-width: thin;
}
.chat__msg {
  max-width: 86%;
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msg-in 0.25s var(--ease);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.chat__msg--ai {
  align-self: flex-start;
  background: rgba(20, 30, 50, 0.85);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--txt-1);
}
.chat__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(0, 229, 160, 0.16), rgba(34, 211, 238, 0.14));
  border: 1px solid rgba(0, 229, 160, 0.3);
  border-bottom-right-radius: 4px;
  color: var(--txt-1);
}
.chat__msg--error {
  align-self: flex-start;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

/* Indicador "escribiendo…" */
.chat__typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 0.85rem 1rem;
  background: rgba(20, 30, 50, 0.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat__typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--txt-3);
  animation: typing-dot 1.2s ease-in-out infinite;
}
.chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.chat__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Sugerencias ---------- */
.chat__sugs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0 1.15rem 0.8rem;
}
.chat__sug {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: rgba(14, 22, 38, 0.6);
  font-size: 0.76rem;
  color: var(--txt-2);
  transition: border-color 0.2s, color 0.2s;
}
.chat__sug:hover { border-color: rgba(0, 229, 160, 0.5); color: var(--mint); }

/* ---------- Formulario ---------- */
.chat__form {
  display: flex;
  gap: 0.55rem;
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--line);
  background: rgba(13, 21, 38, 0.5);
}
.chat__input {
  flex: 1;
  padding: 0.65rem 0.95rem;
  background: rgba(5, 8, 15, 0.7);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--txt-1);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.chat__input:focus { outline: none; border-color: rgba(0, 229, 160, 0.5); }
.chat__input::placeholder { color: var(--txt-3); }
.chat__input:disabled { opacity: 0.55; }

.chat__send {
  width: 42px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: var(--grad);
  color: #03271b;
  transition: transform 0.2s var(--ease), opacity 0.2s, box-shadow 0.2s;
}
.chat__send:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0, 229, 160, 0.35); }
.chat__send:disabled { opacity: 0.45; transform: none; box-shadow: none; cursor: not-allowed; }
.chat__send svg { width: 17px; height: 17px; }

.chat__disclaimer {
  padding: 0 1.15rem 0.8rem;
  font-size: 0.65rem;
  color: var(--txt-3);
  letter-spacing: 0.04em;
  text-align: center;
}

/* ---------- Móvil: el panel ocupa casi toda la pantalla ---------- */
@media (max-width: 480px) {
  .chat { right: 1rem; bottom: 1rem; }
  .chat__panel {
    position: fixed;
    inset: auto 0.75rem 5.6rem 0.75rem;
    width: auto;
    height: min(72vh, 560px);
  }
  .chat__fab { width: 54px; height: 54px; }
  .chat__tip { display: none; }
}
