/* ==========================================================================
   BOT.CSS — Bot Asistente IA (Sarita) y Notificaciones Toast del Dashboard
   Diseñado para SOFTCOM. Respeta temas (claro/oscuro), variables CSS y
   comportamiento responsivo.
   ========================================================================== */

/* Contenedor flotante del bot */
.bot_container {
  position: fixed;
  right: 315px;
  bottom: 48px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  animation: botFloating 3.2s ease-in-out infinite;
  pointer-events: auto;
  transition: right 0.28s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

/* Cuando el historial está oculto o en pantalla inicial sin sidebar */
body:has(#panel_contenido.oculto) .bot_container,
body:has(#chk_historial:checked) .bot_container {
  right: 28px;
}


/* Animación de flotación suave */
@keyframes botFloating {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-9px);
  }
}

/* Envoltura interactiva del avatar */
.bot_avatar_wrap {
  width: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.35));
}

.bot_avatar_wrap:hover {
  transform: scale(1.1);
  filter: drop-shadow(0 10px 25px var(--primary-glow, rgba(99, 102, 241, 0.4)));
}

.bot_avatar_wrap:active {
  transform: scale(0.96);
}

/* Imagen del Bot */
.bot_image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  transition: transform 0.3s ease;
}

/* Estado: Pensando / Procesando / Buscando */
.bot_container.buscando .bot_image,
.bot_container.procesando .bot_image,
.bot_container.thinking .bot_image {
  animation: botThinking 0.4s ease-in-out infinite alternate, botGlow 1.5s ease-in-out infinite;
}

@keyframes botThinking {
  from {
    transform: rotate(-6deg) scale(0.98);
  }
  to {
    transform: rotate(6deg) scale(1.03);
  }
}

@keyframes botGlow {
  0%, 100% {
    filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(56, 189, 248, 0.75)) drop-shadow(0 0 35px rgba(99, 102, 241, 0.45));
  }
}

/* Estado: Alerta de Error (Leve sacudida) */
.bot_container.bot-shake .bot_avatar_wrap {
  animation: botShake 0.4s ease-in-out;
}

@keyframes botShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Estado: Éxito (Rebote alegre) */
.bot_container.bot-bounce .bot_avatar_wrap {
  animation: botBounce 0.5s ease-in-out;
}

@keyframes botBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-14px) scale(1.15); }
  70% { transform: translateY(3px) scale(0.95); }
}

/* ==========================================================================
   ANIMACIONES DE BÚSQUEDA (SPINNER) Y GUARDADO (COMER DISKETTE)
   ========================================================================== */

/* ICONO QUE SE COME EL BOT */
.icono-guardar {
  position: absolute;
  left: 50%;
  top: -10px;
  transform: translate(-50%, -100%) scale(0);
  font-size: 34px;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}

.icono-guardar.comer {
  animation: guardarBot 1.2s cubic-bezier(.4, 0, .2, 1) forwards;
}

@keyframes guardarBot {
  0% {
    transform: translate(-50%, -100%) scale(0) rotate(-180deg) translateY(-30px);
    opacity: 0;
  }
  20% {
    transform: translate(-50%, -100%) scale(1.2) rotate(0deg) translateY(0);
    opacity: 1;
  }
  40% {
    transform: translate(-50%, -100%) scale(1) rotate(20deg);
    opacity: 1;
  }
  55% {
    transform: translate(-50%, -100%) scale(1) rotate(-15deg);
    opacity: 1;
  }
  70% {
    transform: translate(-50%, -100%) scale(1) rotate(10deg);
    opacity: 1;
  }
  85% {
    transform: translate(-50%, -100%) scale(1) rotate(-5deg);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -100%) scale(0) rotate(0deg);
    opacity: 0;
  }
}

/* BUSCADOR CON SPINNER ARRIBA DEL BOT */
.buscador-anim {
  position: absolute;
  left: 50%;
  top: -14px;
  transform: translate(-50%, -100%) scale(0);
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 1005 !important;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.buscador-anim.activo {
  opacity: 1 !important;
  transform: translate(-50%, -100%) scale(1) !important;
  animation: buscarAparecer .4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

@keyframes buscarAparecer {
  0%   { opacity: 0; transform: translate(-50%, -100%) scale(0) translateY(18px); }
  60%  { opacity: 1; transform: translate(-50%, -100%) scale(1.15) translateY(-5px); }
  100% { opacity: 1; transform: translate(-50%, -100%) scale(1) translateY(0); }
}

.spinner-bot,
.buscador-anim .spinner,
.buscador-anim .spinner-bot {
  display: block !important;
  visibility: visible !important;
  position: relative !important;
  width: 32px !important;
  height: 32px !important;
  box-sizing: border-box !important;
  border: 3.5px solid rgba(56, 189, 248, 0.25) !important;
  border-top-color: #38bdf8 !important;
  border-radius: 50% !important;
  animation: girarBot 0.7s linear infinite !important;
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.8)) !important;
}

@keyframes girarBot {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes girarBot {
  to { transform: rotate(360deg); }
}

/* Movimiento del bot al comer */
.bot_container.comiendo .bot_avatar_wrap,
.bot_container.comiendo .bot_image,
.bot-container.comiendo .bot-image {
  animation: movimientoBot .35s ease-in-out 2 !important;
}

@keyframes movimientoBot {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(-4px) rotate(-1deg); }
  50%  { transform: translateX(4px) rotate(1deg); }
  75%  { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}

/* ==========================================================================
   GLOBO DE MENSAJE / TOAST DEL BOT
   ========================================================================== */
.bot_mensaje {
  position: absolute;
  right: 90px;
  bottom: 12px;
  width: 320px;
  max-width: calc(100vw - 125px);
  background: var(--db-card-bg, #1e1e22);
  border: 1px solid var(--db-card-border, rgba(255, 255, 255, 0.1));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  color: var(--db-text-main, #f3f4f6);
  font-family: var(--font-family, inherit);
  font-size: var(--control-font-size-md, 13px);
  line-height: var(--leading-normal, 1.45);
  opacity: 0;
  transform: translateY(12px) scale(0.94);
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.2s ease,
              box-shadow 0.2s ease;
  z-index: 1001;
}

/* Mostrar globo */
.bot_mensaje.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Triángulo apuntador al bot */
.bot_mensaje::after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: 22px;
  width: 14px;
  height: 14px;
  background: var(--db-card-bg, #1e1e22);
  border-top: 1px solid var(--db-card-border, rgba(255, 255, 255, 0.1));
  border-right: 1px solid var(--db-card-border, rgba(255, 255, 255, 0.1));
  transform: rotate(45deg);
  transition: background 0.2s ease, border-color 0.2s ease;
}

/* Header del globo */
.bot_mensaje_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

/* Título e icono */
.bot_mensaje_titulo_wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bot_tipo_icono {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary, #6366f1);
}

.bot_mensaje_titulo {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary, #818cf8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

/* Botón cerrar del globo */
.bot_mensaje_cerrar {
  background: none;
  border: none;
  color: var(--db-text-muted, #94a3b8);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
  transition: color 0.15s ease, transform 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bot_mensaje_cerrar:hover {
  color: var(--db-text-main, #fff);
  transform: scale(1.15);
}

/* Cuerpo del texto */
.bot_mensaje_texto {
  font-size: 12.5px;
  color: var(--db-text-main, #e2e8f0);
  word-break: break-word;
  line-height: 1.42;
}

/* ==========================================================================
   TIPOS DE NOTIFICACIÓN TOAST (SUCCESS / ERROR / WARNING / INFO)
   ========================================================================== */

/* Éxito */
.bot_mensaje.toast-tipo-success {
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(16, 185, 129, 0.2);
}
.bot_mensaje.toast-tipo-success::after {
  border-top-color: rgba(16, 185, 129, 0.4);
  border-right-color: rgba(16, 185, 129, 0.4);
}
.bot_mensaje.toast-tipo-success .bot_tipo_icono,
.bot_mensaje.toast-tipo-success .bot_mensaje_titulo {
  color: #10b981;
}

/* Error */
.bot_mensaje.toast-tipo-error {
  border-color: rgba(239, 68, 68, 0.45);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(239, 68, 68, 0.25);
}
.bot_mensaje.toast-tipo-error::after {
  border-top-color: rgba(239, 68, 68, 0.45);
  border-right-color: rgba(239, 68, 68, 0.45);
}
.bot_mensaje.toast-tipo-error .bot_tipo_icono,
.bot_mensaje.toast-tipo-error .bot_mensaje_titulo {
  color: #ef4444;
}

/* Advertencia */
.bot_mensaje.toast-tipo-warning {
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(245, 158, 11, 0.2);
}
.bot_mensaje.toast-tipo-warning::after {
  border-top-color: rgba(245, 158, 11, 0.45);
  border-right-color: rgba(245, 158, 11, 0.45);
}
.bot_mensaje.toast-tipo-warning .bot_tipo_icono,
.bot_mensaje.toast-tipo-warning .bot_mensaje_titulo {
  color: #f59e0b;
}

/* Información / Predeterminado */
.bot_mensaje.toast-tipo-info {
  border-color: var(--primary, rgba(99, 102, 241, 0.4));
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--primary-glow, rgba(99, 102, 241, 0.2));
}
.bot_mensaje.toast-tipo-info::after {
  border-top-color: var(--primary, rgba(99, 102, 241, 0.4));
  border-right-color: var(--primary, rgba(99, 102, 241, 0.4));
}
.bot_mensaje.toast-tipo-info .bot_tipo_icono,
.bot_mensaje.toast-tipo-info .bot_mensaje_titulo {
  color: var(--primary, #818cf8);
}

/* ==========================================================================
   ANIMACIÓN PUNTOS DE PENSAMIENTO
   ========================================================================== */
.bot_thinking_dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.bot_thinking_dots span {
  width: 5px;
  height: 5px;
  background: var(--primary, #6366f1);
  border-radius: 50%;
  display: inline-block;
  animation: botDots 1.1s infinite ease-in-out;
}

.bot_thinking_dots span:nth-child(2) { animation-delay: 0.2s; }
.bot_thinking_dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes botDots {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* ==========================================================================
   ADAPTACIÓN AL TEMA CLARO (LIGHT THEME)
   ========================================================================== */
body.light-theme .bot_mensaje {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #0f172a;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.12);
}

body.light-theme .bot_mensaje::after {
  background: #ffffff;
  border-top-color: #e2e8f0;
  border-right-color: #e2e8f0;
}

body.light-theme .bot_mensaje_texto {
  color: #334155;
}

body.light-theme .bot_mensaje_cerrar {
  color: #94a3b8;
}

body.light-theme .bot_mensaje_cerrar:hover {
  color: #0f172a;
}

body.light-theme .bot_mensaje.toast-tipo-success {
  border-color: #86efac;
  box-shadow: 0 14px 30px rgba(16, 185, 129, 0.14);
}
body.light-theme .bot_mensaje.toast-tipo-success::after {
  border-top-color: #86efac;
  border-right-color: #86efac;
}
body.light-theme .bot_mensaje.toast-tipo-success .bot_tipo_icono,
body.light-theme .bot_mensaje.toast-tipo-success .bot_mensaje_titulo {
  color: #059669;
}

body.light-theme .bot_mensaje.toast-tipo-error {
  border-color: #fca5a5;
  box-shadow: 0 14px 30px rgba(239, 68, 68, 0.14);
}
body.light-theme .bot_mensaje.toast-tipo-error::after {
  border-top-color: #fca5a5;
  border-right-color: #fca5a5;
}
body.light-theme .bot_mensaje.toast-tipo-error .bot_tipo_icono,
body.light-theme .bot_mensaje.toast-tipo-error .bot_mensaje_titulo {
  color: #dc2626;
}

body.light-theme .bot_mensaje.toast-tipo-warning {
  border-color: #fde68a;
  box-shadow: 0 14px 30px rgba(245, 158, 11, 0.14);
}
body.light-theme .bot_mensaje.toast-tipo-warning::after {
  border-top-color: #fde68a;
  border-right-color: #fde68a;
}
body.light-theme .bot_mensaje.toast-tipo-warning .bot_tipo_icono,
body.light-theme .bot_mensaje.toast-tipo-warning .bot_mensaje_titulo {
  color: #d97706;
}

body.light-theme .bot_mensaje.toast-tipo-info {
  border-color: #bfdbfe;
  box-shadow: 0 14px 30px rgba(99, 102, 241, 0.12);
}
body.light-theme .bot_mensaje.toast-tipo-info::after {
  border-top-color: #bfdbfe;
  border-right-color: #bfdbfe;
}
body.light-theme .bot_mensaje.toast-tipo-info .bot_tipo_icono,
body.light-theme .bot_mensaje.toast-tipo-info .bot_mensaje_titulo {
  color: #4f46e5;
}

/* ==========================================================================
   AJUSTES RESPONSIVOS Y DE IMPRESIÓN
   ========================================================================== */
@media (max-width: 768px) {
  .bot_container {
    right: 14px;
    bottom: 50px;
  }
  .bot_avatar_wrap {
    width: 60px;
    height: 60px;
  }
  .bot_mensaje {
    right: 70px;
    bottom: 6px;
    width: 270px;
  }
}

@media print {
  .bot_container {
    display: none !important;
  }
}
