/* ==========================================================================
   SÓCRATES AI · WIDGET Y ASISTENTE SOCRÁTICO TRANSVERSAL
   KILOPOLIS ACADEMIA & SAAS FACTORY
   ========================================================================== */

/* 1. Botón Flotante (FAB) */
.kilo-assistant-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1050;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 12px;
  background: linear-gradient(135deg, #0b1536 0%, #1e2a5e 50%, #2563eb 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50px;
  box-shadow: 0 10px 25px rgba(11, 21, 54, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  user-select: none;
}

.kilo-assistant-fab:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 15px 35px rgba(37, 99, 235, 0.4), 0 0 20px rgba(56, 189, 248, 0.3);
  color: #ffffff;
}

.kilo-fab-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  position: relative;
}

.kilo-fab-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid #0b1536;
  box-shadow: 0 0 8px #10b981;
  animation: kiloPulse 2s infinite;
}

@keyframes kiloPulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* 2. Overlay Oscuro de Fondo */
.kilo-assistant-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 21, 54, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1060;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.kilo-assistant-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* 3. Panel Lateral Deslizante (Drawer) */
.kilo-assistant-drawer {
  position: fixed;
  top: 0;
  right: -480px;
  width: 440px;
  max-width: 95vw;
  height: 100%;
  height: 100dvh;
  background: #ffffff;
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
  z-index: 1070;
  display: flex;
  flex-direction: column;
  transition: right 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: inherit;
}

.kilo-assistant-drawer.open {
  right: 0;
}

/* 4. Encabezado del Drawer */
.kad-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #0b1536 0%, #1e2a5e 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.kad-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kad-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #14b8a6);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.kad-title-wrap h6 {
  margin: 0;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.2px;
  color: #ffffff;
}

.kad-title-wrap small {
  color: #93c5fd;
  font-size: 0.76rem;
  display: block;
}

.kad-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kad-btn-icon {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.kad-btn-icon:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* 5. Selector de Modo / Rol */
.kad-mode-bar {
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
}

.kad-mode-chip {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
}

.kad-mode-chip.active {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* Modos de Trabajo en Tarjeta / Vista Completa (/asistente) */
.kad-mode-chip.text-start,
.kad-mode-card {
  white-space: normal !important;
  display: block !important;
  text-align: left;
}

.kad-mode-card .kad-mode-title {
  color: #0f172a;
  transition: color 0.2s ease;
}

.kad-mode-card .kad-mode-desc {
  color: #64748b;
  white-space: normal !important;
  line-height: 1.45;
  transition: color 0.2s ease;
}

.kad-mode-chip.active .text-dark,
.kad-mode-chip.active [class*="text-dark"],
.kad-mode-chip.active .kad-mode-title,
.kad-mode-card.active .kad-mode-title {
  color: #ffffff !important;
}

.kad-mode-chip.active .text-muted,
.kad-mode-chip.active [class*="text-muted"],
.kad-mode-chip.active small,
.kad-mode-chip.active .kad-mode-desc,
.kad-mode-card.active .kad-mode-desc {
  color: #ffffff !important;
  opacity: 1 !important;
  white-space: normal !important;
  line-height: 1.45;
}

/* 6. Cuerpo del Chat */
.kad-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fdfdfd;
}

/* Mensajes */
.kad-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  line-height: 1.5;
  font-size: 0.88rem;
}

.kad-msg.user {
  align-self: flex-end;
  background: #2563eb;
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 16px 16px 2px 16px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.kad-msg.assistant {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1e293b;
  padding: 12px 16px;
  border-radius: 16px 16px 16px 2px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.kad-msg.assistant p:last-child {
  margin-bottom: 0;
}

/* Markdown dentro del asistente */
.kad-msg.assistant pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
  font-size: 0.82rem;
  font-family: 'Fira Code', monospace, Consolas;
}

.kad-msg.assistant code:not(pre code) {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: monospace;
}

.kad-msg.assistant pre code {
  color: inherit;
  background: transparent;
  padding: 0;
}

.kad-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #cbd5e1;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.kad-copy-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  color: #ffffff;
}

/* Estado de Bienvenida / Empty */
.kad-welcome {
  text-align: center;
  padding: 20px 10px;
}

.kad-welcome-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.kad-welcome-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0b1536;
  margin-bottom: 6px;
}

.kad-welcome-desc {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 16px;
}

/* Sugerencias Rápidas */
.kad-quick-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kad-quick-chip {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  text-align: left;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kad-quick-chip:hover {
  border-color: #2563eb;
  background: #f0f7ff;
  color: #1d4ed8;
  transform: translateX(4px);
}

/* Indicador de Pensando */
.kad-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  padding: 10px 16px;
  border-radius: 16px;
  color: #64748b;
  font-size: 0.82rem;
}

.kad-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: kadBlink 1.4s infinite both;
}
.kad-dot:nth-child(2) { animation-delay: 0.2s; }
.kad-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes kadBlink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* 7. Barra de Entrada de Texto */
.kad-footer {
  padding: 12px 16px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.kad-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 6px 10px;
  transition: border-color 0.2s;
}

.kad-input-wrap:focus-within {
  border-color: #2563eb;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.kad-textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 0.88rem;
  color: #1e293b;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 4px 0;
}

.kad-send-btn {
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.kad-send-btn:hover:not(:disabled) {
  background: #1d4ed8;
  transform: scale(1.05);
}

.kad-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.kad-hint {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 6px;
  text-align: center;
}

/* Adaptación Móvil */
@media (max-width: 768px) {
  .kilo-assistant-fab {
    bottom: 74px; /* Flota sobre el nav-dock en caso de estar en páginas móviles */
    right: 14px;
    padding: 8px 14px 8px 10px;
    font-size: 0.84rem;
  }
  .kilo-assistant-drawer {
    width: 100%;
    max-width: 100vw;
  }
}
