/* ==========================================
   AGENTE BOTSTUDIO - WIDGET CSS
   ==========================================
   Estilos encapsulados con prefijo #botstudio-chat
   para no interferir con el CSS de la página host.
   ========================================== */

#botstudio-chat-root {
  all: initial;
  position: fixed;
  z-index: 2147483000;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  pointer-events: none;
}

#botstudio-chat-root * {
  box-sizing: border-box;
}

/* ---- Botón flotante ---- */
#botstudio-toggle-btn {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  pointer-events: auto;
}

#botstudio-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.3);
}

#botstudio-toggle-btn img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

/* ---- Ventana del chat ---- */
#botstudio-window {
  position: fixed;
  bottom: 96px;
  right: 22px;
  width: 370px;
  max-width: calc(100vw - 44px);
  height: 560px;
  max-height: calc(100vh - 130px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  animation: botstudio-fade-in 0.25s ease;
}

#botstudio-window.open {
  display: flex;
}

@keyframes botstudio-fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Cabecera ---- */
#botstudio-header {
  background: linear-gradient(135deg, #6d28d9, #4f46e5);
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#botstudio-header .bs-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

#botstudio-header .bs-status {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
}

#botstudio-header .bs-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#botstudio-header .bs-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* ---- Cuerpo de mensajes ---- */
#botstudio-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f5f6fa;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bs-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bs-bubble.user {
  align-self: flex-end;
  background: #4f46e5;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bs-bubble.bot,
.bs-bubble.human {
  align-self: flex-start;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.bs-bubble.human {
  border-left: 3px solid #f59e0b;
}

.bs-bubble.welcome {
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}

.bs-bubble.error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.bs-sender-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 3px;
  opacity: 0.7;
}

/* ---- Indicador "escribiendo..." ---- */
.bs-typing {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: none;
  gap: 5px;
}

.bs-typing.visible {
  display: flex;
}

.bs-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: botstudio-bounce 1.3s infinite ease-in-out;
}

.bs-typing span:nth-child(2) { animation-delay: 0.15s; }
.bs-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes botstudio-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Zona de entrada ---- */
#botstudio-input-area {
  flex-shrink: 0;
  padding: 10px 12px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
}

#botstudio-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

#botstudio-input:focus {
  border-color: #6d28d9;
}

#botstudio-send-btn {
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

#botstudio-send-btn:hover {
  background: #4338ca;
}

/* ---- Scrollbar ---- */
#botstudio-messages::-webkit-scrollbar { width: 6px; }
#botstudio-messages::-webkit-scrollbar-track { background: transparent; }
#botstudio-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* ---- Responsivo ---- */

@media (max-width: 600px) {
  #botstudio-window {
    right: 8px;
    left: 8px;
    bottom: 88px;
    width: auto;
    height: 65vh;
    max-height: 65vh;
    border-radius: 14px;
  }
  #botstudio-toggle-btn {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }
  #botstudio-toggle-btn img {
    width: 38px;
    height: 38px;
  }
}
