/* ============================================================
   PROFESSOR NEURAL — Avatar flutuante + chat
   (antigo Capitão IA, repaginado: gênio nerd, paleta tech roxo/ciano)
   Posicionável (qualquer canto) · arrastável · voz · animações
   ============================================================ */

#capitao-root {
  position: fixed;
  z-index: 9999;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --cap-primary: #8b5cf6;       /* roxo Neural */
  --cap-primary-light: #06b6d4;  /* ciano cibernético */
  --cap-accent: #a78bfa;
  --cap-bg: #0a0a14;
  --cap-card: #ffffff;
  --cap-text: #0f172a;
  --cap-text-soft: #334155;
  --cap-muted: #64748b;
  --cap-border: #e5e7eb;
}

/* ============================================================
   AVATAR (botão flutuante) — agora com glow neural pulsante
   ============================================================ */
.cap-avatar {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #f5f3ff 0%, #ede9fe 50%, #ddd6fe 100%);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 4px rgba(139, 92, 246, 0.18),
    0 0 28px rgba(6, 182, 212, 0.35),
    0 12px 36px -8px rgba(139, 92, 246, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform .25s, box-shadow .25s;
  position: relative;
  user-select: none;
}
.cap-avatar:hover {
  transform: scale(1.06);
  box-shadow:
    0 0 0 6px rgba(139, 92, 246, 0.25),
    0 0 36px rgba(6, 182, 212, 0.55),
    0 18px 44px -10px rgba(139, 92, 246, 0.65);
}
.cap-avatar:active { cursor: grabbing; }
.cap-avatar.dragging { transition: none; cursor: grabbing; }

/* Animação de "respirar" sutil */
.cap-avatar.idle {
  animation: capBreathe 4s ease-in-out infinite;
}
@keyframes capBreathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Glow indicador ativo */
.cap-avatar::before {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #10b981;
  border: 2.5px solid white;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

/* Badge de notificação (quando IA tem algo a dizer) */
.cap-avatar.has-notif::after {
  content: '!';
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  animation: capPulse 1.5s ease-in-out infinite;
}
@keyframes capPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Neurônios pulsando no SVG do Professor */
.cap-neurons circle {
  animation: capNeuronPulse 2.4s ease-in-out infinite;
}
.cap-neurons circle:nth-child(1) { animation-delay: 0s; }
.cap-neurons circle:nth-child(2) { animation-delay: 0.4s; }
.cap-neurons circle:nth-child(3) { animation-delay: 0.8s; }
.cap-neurons circle:nth-child(4) { animation-delay: 1.2s; }
.cap-neurons circle:nth-child(5) { animation-delay: 1.6s; }
@keyframes capNeuronPulse {
  0%, 100% { opacity: 0.4; r: 1.2; }
  50%      { opacity: 1;   r: 2; }
}

/* SVG do Professor dentro do avatar */
.cap-svg {
  width: 92%;
  height: 92%;
  pointer-events: none;
}

/* ============================================================
   JANELA DE CHAT
   ============================================================ */
.cap-chat {
  position: fixed;
  width: 380px;
  height: 560px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  background: var(--cap-card);
  border-radius: 20px;
  box-shadow:
    0 24px 60px -12px rgba(0, 0, 0, 0.25),
    0 4px 16px rgba(0, 0, 0, 0.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--cap-border);
  transform: scale(0.95) translateY(10px);
  opacity: 0;
  transition: opacity .25s, transform .25s;
}
.cap-chat.open {
  display: flex;
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* Header do chat */
.cap-head {
  background: linear-gradient(135deg, var(--cap-primary), var(--cap-primary-light));
  color: white;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}
.cap-head-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cap-head-info { flex: 1; min-width: 0; }
.cap-head-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.015em;
}
.cap-head-status {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.cap-head-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 6px #34d399;
}
.cap-head-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.cap-head-close:hover { background: rgba(255, 255, 255, 0.22); }

/* Corpo do chat (mensagens) */
.cap-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafafa;
  scrollbar-width: thin;
}
.cap-body::-webkit-scrollbar { width: 6px; }
.cap-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* Mensagens */
.cap-msg {
  display: flex;
  gap: 8px;
  max-width: 92%;
  animation: capMsgIn .35s cubic-bezier(.4, 0, .2, 1);
}
@keyframes capMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.cap-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.cap-msg-bot { align-self: flex-start; }
.cap-msg-bubble {
  background: white;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  color: var(--cap-text-soft);
  line-height: 1.55;
  border: 1px solid var(--cap-border);
  word-wrap: break-word;
}
.cap-msg-bubble strong { color: var(--cap-text); font-weight: 600; }
.cap-msg-bubble code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  color: var(--cap-primary);
}
.cap-msg-bubble pre {
  background: #1f2937;
  color: #f9fafb;
  padding: 10px 12px;
  border-radius: 8px;
  margin: 6px 0;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}
.cap-msg-bubble pre code { background: transparent; color: inherit; padding: 0; }
.cap-msg-user .cap-msg-bubble {
  background: linear-gradient(135deg, var(--cap-primary), var(--cap-primary-light));
  color: white;
  border: none;
  border-bottom-right-radius: 4px;
}
.cap-msg-user .cap-msg-bubble strong { color: white; }
.cap-msg-bot .cap-msg-bubble { border-bottom-left-radius: 4px; }
.cap-fb { margin-top: 8px; display: flex; gap: 4px; }
.cap-fb-btn { background: transparent; border: 1px solid var(--cap-border); padding: 3px 9px; border-radius: 999px; cursor: pointer; font-size: 13px; transition: background .15s, border-color .15s; }
.cap-fb-btn:hover { background: var(--cap-border); }
.cap-fb-thanks { font-size: 11.5px; color: var(--cap-muted); font-style: italic; }

.cap-msg-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cap-primary), var(--cap-primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cap-msg-mini-avatar svg { width: 18px; height: 18px; }

/* Indicador "digitando" */
.cap-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: white;
  border: 1px solid var(--cap-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.cap-typing span {
  width: 7px;
  height: 7px;
  background: var(--cap-muted);
  border-radius: 50%;
  animation: capTyping 1.4s ease-in-out infinite;
}
.cap-typing span:nth-child(2) { animation-delay: 0.2s; }
.cap-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes capTyping {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.9); }
  30% { opacity: 1; transform: scale(1.1); }
}

/* Mensagem de boas-vindas (estado vazio) */
.cap-welcome {
  text-align: center;
  padding: 24px 16px;
  color: var(--cap-muted);
}
.cap-welcome-avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cap-primary), var(--cap-primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
}
.cap-welcome h4 {
  color: var(--cap-text);
  font-size: 16px;
  margin: 0 0 6px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.cap-welcome p {
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0;
}
.cap-quick-q {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
}
.cap-quick-q button {
  background: white;
  border: 1px solid var(--cap-border);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--cap-text-soft);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.cap-quick-q button:hover {
  border-color: var(--cap-primary);
  color: var(--cap-primary);
}

/* Input área */
.cap-foot {
  border-top: 1px solid var(--cap-border);
  background: white;
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.cap-input {
  flex: 1;
  border: 1.5px solid var(--cap-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--cap-text);
  background: var(--cap-card);
  resize: none;
  max-height: 100px;
  min-height: 42px;
  transition: border-color .15s;
}
.cap-input:focus { outline: none; border-color: var(--cap-primary); }
.cap-foot-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: var(--cap-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
}
.cap-foot-btn:hover { background: var(--cap-primary-light); }
.cap-foot-btn:active { transform: scale(0.95); }
.cap-foot-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cap-foot-btn-mic {
  background: white;
  color: var(--cap-text-soft);
  border: 1.5px solid var(--cap-border);
}
.cap-foot-btn-mic:hover { background: #f3f4f6; }
.cap-foot-btn-mic.recording {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
  animation: capPulse 1s ease-in-out infinite;
}

/* Mobile */
@media (max-width: 480px) {
  .cap-chat {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    right: 0 !important;
    max-width: 100%;
    max-height: 100%;
  }
}

/* Indicador de erro */
.cap-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin: 8px 0;
}

/* Quando avatar está oculto */
.cap-avatar.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0);
}
