/**
 * EES N° 23 - Sistema Escolar Integrado
 * Estilos Nativos para el Widget Flotante del Chatbot con IA
 * Base de cálculo 62.5% (1rem = 10px) • Flexbox y Grid puros
 */

/* ==========================================================================
   1. BOTÓN LANZADOR FLOTANTE (LAUNCHER)
   ========================================================================== */
.chatbot-launcher {
  position: fixed;
  bottom: 2.4rem;
  right: 2.4rem;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(135deg, #0f2942 0%, #1e3a8a 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999.9rem;
  padding: 0.8rem 1.6rem 0.8rem 1rem;
  cursor: pointer;
  box-shadow: 0 1rem 3rem rgba(15, 41, 66, 0.35), 0 0.3rem 0.8rem rgba(0, 0, 0, 0.12);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  text-decoration: none;
}

.chatbot-launcher:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 1.4rem 3.6rem rgba(15, 41, 66, 0.45), 0 0.4rem 1.2rem rgba(0, 0, 0, 0.18);
  background: linear-gradient(135deg, #0d2238 0%, #173278 100%);
}

.chatbot-launcher:active {
  transform: translateY(0) scale(0.98);
}

.chatbot-launcher-icon-wrap {
  position: relative;
  width: 4.2rem;
  height: 4.2rem;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.15);
}

.chatbot-launcher-icon-wrap img {
  width: 2.8rem;
  height: 2.8rem;
  object-fit: cover;
  border-radius: 50%;
}

.chatbot-launcher-badge-online {
  position: absolute;
  top: -0.2rem;
  right: -0.2rem;
  width: 1.2rem;
  height: 1.2rem;
  background-color: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
  animation: chatbotPulse 2s infinite;
}

.chatbot-launcher-text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.15;
}

.chatbot-launcher-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.02em;
}

.chatbot-launcher-subtitle {
  font-size: 1.1rem;
  color: #93c5fd;
  font-weight: 500;
}

/* ==========================================================================
   2. VENTANA PRINCIPAL DEL CHATBOT (WIDGET FLOTANTE)
   ========================================================================== */
.chatbot-window {
  position: fixed;
  bottom: 8.8rem;
  right: 2.4rem;
  width: 40rem;
  max-width: calc(100vw - 3.2rem);
  height: 58rem;
  max-height: calc(100vh - 11rem);
  background: #ffffff;
  border-radius: 1.8rem;
  box-shadow: 0 2rem 5rem rgba(15, 41, 66, 0.28), 0 0.6rem 1.6rem rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(15, 41, 66, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(2rem) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}

.chatbot-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ==========================================================================
   3. CABECERA DEL CHATBOT
   ========================================================================== */
.chatbot-header {
  background: linear-gradient(135deg, #0f2942 0%, #1e3a8a 100%);
  color: #ffffff;
  padding: 1.4rem 1.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.chatbot-avatar {
  position: relative;
  width: 3.8rem;
  height: 3.8rem;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.2rem;
  box-shadow: 0 0.2rem 0.5rem rgba(0,0,0,0.15);
}

.chatbot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chatbot-avatar-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 1rem;
  height: 1rem;
  background-color: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.chatbot-header-text h4 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
}

.chatbot-header-text span {
  font-size: 1.15rem;
  color: #bfdbfe;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chatbot-header-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.chatbot-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

/* ==========================================================================
   4. HISTORIAL DE MENSAJES (BODY)
   ========================================================================== */
.chatbot-body {
  flex: 1;
  padding: 1.6rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  background-color: #f8fafc;
  scroll-behavior: smooth;
}

.chatbot-msg-group {
  display: flex;
  gap: 0.8rem;
  max-width: 88%;
}

.chatbot-msg-group.bot {
  align-self: flex-start;
}

.chatbot-msg-group.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatbot-msg-bubble {
  padding: 1.2rem 1.4rem;
  border-radius: 1.6rem;
  font-size: 1.35rem;
  line-height: 1.5;
  word-break: break-word;
}

.chatbot-msg-group.bot .chatbot-msg-bubble {
  background: #ffffff;
  color: #0f172a;
  border-bottom-left-radius: 0.4rem;
  box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;
}

.chatbot-msg-group.user .chatbot-msg-bubble {
  background: linear-gradient(135deg, #0f2942 0%, #1e3a8a 100%);
  color: #ffffff;
  border-bottom-right-radius: 0.4rem;
  box-shadow: 0 0.3rem 1rem rgba(15, 41, 66, 0.2);
}

.chatbot-msg-time {
  font-size: 1.05rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 0.4rem;
  display: block;
}

.chatbot-msg-group.user .chatbot-msg-time {
  text-align: right;
  color: rgba(255, 255, 255, 0.7);
}

/* Formato dentro de las burbujas del bot */
.chatbot-msg-bubble p {
  margin: 0 0 0.8rem 0;
}

.chatbot-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chatbot-msg-bubble strong {
  font-weight: 700;
  color: inherit;
}

.chatbot-msg-bubble ul,
.chatbot-msg-bubble ol {
  margin: 0.4rem 0 0.8rem 1.8rem;
  padding: 0;
}

.chatbot-msg-bubble li {
  margin-bottom: 0.3rem;
}

.chatbot-msg-bubble a {
  color: #2563eb;
  text-decoration: underline;
  font-weight: 600;
}

.chatbot-msg-group.user .chatbot-msg-bubble a {
  color: #93c5fd;
}

/* ==========================================================================
   5. SUGERENCIAS RÁPIDAS (QUICK PROMPT CHIPS)
   ========================================================================== */
.chatbot-suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.chatbot-chip {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 999.9rem;
  padding: 0.7rem 1.2rem;
  font-size: 1.2rem;
  color: #1e3a8a;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 0.1rem 0.3rem rgba(0, 0, 0, 0.04);
}

.chatbot-chip:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
  transform: translateX(3px);
}

/* ==========================================================================
   6. INDICADOR DE CARGA (TYPING INDICATOR)
   ========================================================================== */
.chatbot-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 1.2rem 1.6rem;
  background: #ffffff;
  border-radius: 1.6rem;
  border-bottom-left-radius: 0.4rem;
  border: 1px solid #e2e8f0;
  box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.05);
}

.chatbot-typing-dot {
  width: 0.75rem;
  height: 0.75rem;
  background-color: #0f2942;
  border-radius: 50%;
  opacity: 0.4;
  animation: chatbotBounce 1.4s infinite ease-in-out both;
}

.chatbot-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes chatbotBounce {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.3;
  }
  40% {
    transform: scale(1.1);
    opacity: 1;
    background-color: #1e3a8a;
  }
}

@keyframes chatbotPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    box-shadow: 0 0 0 0.6rem rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* ==========================================================================
   7. ÁREA DE ENTRADA DE TEXTO (FOOTER)
   ========================================================================== */
.chatbot-footer {
  padding: 1.2rem 1.6rem 1.4rem;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.chatbot-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 999.9rem;
  padding: 0.4rem 0.6rem 0.4rem 1.4rem;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.chatbot-input-wrap:focus-within {
  background: #ffffff;
  border-color: #1e3a8a;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.chatbot-input-field {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1.35rem;
  color: #0f172a;
  outline: none;
  font-family: inherit;
  padding: 0.6rem 0;
}

.chatbot-input-field::placeholder {
  color: #94a3b8;
}

.chatbot-send-btn {
  width: 3.8rem;
  height: 3.8rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f2942 0%, #1e3a8a 100%);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.2s, background 0.2s;
}

.chatbot-send-btn:hover:not(:disabled) {
  transform: scale(1.06);
  background: linear-gradient(135deg, #0d2238 0%, #173278 100%);
}

.chatbot-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chatbot-disclaimer {
  display: block;
  text-align: center;
  margin-top: 0.8rem;
  font-size: 1.05rem;
  color: #64748b;
}

/* Bloquear scroll del fondo cuando el chat está en pantalla completa en móviles */
body.chatbot-open-noscroll {
  overflow: hidden !important;
  touch-action: none;
}

/* ==========================================================================
   8. RESPONSIVE (MÓVILES Y PANTALLAS TÁCTILES PEQUEÑAS)
   ========================================================================== */
@media (max-width: 768px) {
  /* Lanzador compacto tipo burbuja flotante */
  .chatbot-launcher {
    bottom: 1.8rem;
    right: 1.8rem;
    padding: 0.6rem;
    border-radius: 50%;
  }

  .chatbot-launcher-text {
    display: none;
  }

  .chatbot-launcher-icon-wrap {
    width: 4.6rem;
    height: 4.6rem;
  }

  .chatbot-launcher-icon-wrap img {
    width: 3.2rem;
    height: 3.2rem;
  }

  /* Ventana en pantalla completa limpia sin desbordes */
  .chatbot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    z-index: 999999 !important;
  }

  /* Cabecera optimizada con notch / safe area */
  .chatbot-header {
    padding: 1.2rem 1.4rem;
    padding-top: max(1.2rem, env(safe-area-inset-top));
    padding-left: max(1.4rem, env(safe-area-inset-left));
    padding-right: max(1.4rem, env(safe-area-inset-right));
  }

  .chatbot-avatar {
    width: 3.6rem;
    height: 3.6rem;
  }

  .chatbot-header-text h4 {
    font-size: 1.35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 19rem;
  }

  .chatbot-header-text span {
    font-size: 1.1rem;
  }

  .chatbot-header-btn {
    width: 3.8rem;
    height: 3.8rem;
  }

  /* Cuerpo de conversación fluido y con scroll táctil acelerado */
  .chatbot-body {
    padding: 1.4rem 1.2rem;
    gap: 1.2rem;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .chatbot-msg-group {
    max-width: 92%;
  }

  .chatbot-msg-bubble {
    font-size: 1.4rem;
    padding: 1.2rem 1.3rem;
  }

  /* Área inferior / teclado virtual */
  .chatbot-footer {
    padding: 0.8rem 1.2rem 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    padding-left: max(1.2rem, env(safe-area-inset-left));
    padding-right: max(1.2rem, env(safe-area-inset-right));
    background: #ffffff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .chatbot-input-wrap {
    padding: 0.4rem 0.6rem 0.4rem 1.2rem;
    background: #f8fafc;
  }

  .chatbot-input-field {
    /* 1.6rem = 16px exactos: OBLIGATORIO para evitar que iOS/Safari haga zoom automático al tocar el campo */
    font-size: 1.6rem !important;
    padding: 0.8rem 0;
  }

  .chatbot-send-btn {
    width: 4rem;
    height: 4rem;
  }

  .chatbot-disclaimer {
    font-size: 1rem;
    margin-top: 0.5rem;
  }

  .chatbot-chip {
    font-size: 1.25rem;
    padding: 0.8rem 1.2rem;
  }
}
