/* ==========================================================================
   OPTIBOT WIDGET
   OptiCore Systems IA v3.0
   ========================================================================== */

.optibot-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ── BOTÓN FLOTANTE ── */
.optibot-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  box-shadow: var(--cyan-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.3s var(--ease), background 0.3s;
  /* Entrada animada */
  animation: optibot-entrance 0.8s 3s both;
}
@keyframes optibot-entrance {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);    opacity: 1; }
}

.optibot-toggle:hover  { transform: scale(1.06); background: var(--cyan-hover); }
.optibot-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* Indicador de no-leídos */
.optibot-toggle[data-unread]::after {
  content: attr(data-unread);
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

.bot-icon { font-size: 1.75rem; line-height: 1; }

.bot-tooltip {
  position: absolute;
  right: 70px;
  background: var(--card);
  border: 1px solid var(--cyan);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  transform: translateX(8px);
}
.optibot-toggle:hover .bot-tooltip,
.optibot-toggle:focus .bot-tooltip {
  opacity: 1;
  transform: translateX(0);
}

/* ── VENTANA DE CHAT ── */
.optibot-window {
  width: 340px;
  height: 490px;
  max-height: calc(100vh - 110px);
  background: var(--bg2);
  border: 1px solid var(--card-b);
  border-radius: var(--r-lg);
  box-shadow:
    0 0 0 1px rgba(0, 210, 255, 0.14),
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 80px rgba(0, 210, 255, 0.05);
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  /* Accesibilidad: el diálogo debe ser anunciado */
}

.optibot-window.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* ── HEADER ── */
.optibot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--card-b);
  flex-shrink: 0;
}

.optibot-info { display: flex; align-items: center; gap: 10px; }
.bot-avatar   { font-size: 1.45rem; line-height: 1; }
.bot-text     { display: flex; flex-direction: column; }
.bot-text strong { font-family: var(--fh); font-size: 0.96rem; color: var(--cyan); }
.bot-text span   { font-size: 0.72rem; color: var(--muted); }

/* Indicador online */
.bot-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--green);
}
.bot-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

.optibot-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
.optibot-close:hover  { color: var(--red); background: rgba(255, 82, 82, 0.1); }
.optibot-close:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ── MENSAJES ── */
/* aria-live="polite" debe estar en el HTML */
.optibot-messages {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Scrollbar dentro del chat */
.optibot-messages::-webkit-scrollbar { width: 4px; }
.optibot-messages::-webkit-scrollbar-thumb { background: rgba(0, 210, 255, 0.2); border-radius: 2px; }

.msg {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}

.bot-msg {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-b);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.user-msg {
  background: var(--cyan-06);
  color: var(--cyan);
  border: 1px solid rgba(0, 210, 255, 0.2);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Indicador de escritura animado */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ── ÁREA DE INPUT ── */
.optibot-input-area {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--card-b);
  gap: 10px;
  flex-shrink: 0;
}

.optibot-input-area input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--fb);
  font-size: 0.88rem;
  outline: none;
  min-width: 0;
}
.optibot-input-area input::placeholder { color: rgba(255, 255, 255, 0.28); }

#optibot-send {
  background: var(--cyan);
  color: var(--bg);
  border: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, background 0.2s;
}
#optibot-send:hover  { transform: scale(1.12); background: var(--cyan-hover); }
#optibot-send:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#optibot-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── RESPONSIVE — full-screen en móvil ── */
@media (max-width: 480px) {
  .optibot-widget {
    bottom: 0;
    right: 0;
    left: 0;
    align-items: flex-end;
  }
  .optibot-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
  }
  .optibot-window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    margin-bottom: 0;
    z-index: 2001;
  }
}