/* ═══════════════════════════════════════════════════════════
   CHAT.CSS — EstudaAI
   Histórico de conversas (painel deslizante) + edição de
   mensagens enviadas no chat.
   ═══════════════════════════════════════════════════════════ */

#chat-panel {
  position: relative;
}

/* ── Edição de mensagens enviadas pelo usuário ───────────── */
.msg.user .msg-bubble {
  position: relative;
}

.msg-edit-btn {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.14s;
}

.msg.user:hover .msg-edit-btn {
  display: flex;
}

.msg-edit-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.msg-edit-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-edit-textarea {
  width: 100%;
  min-width: 220px;
  resize: vertical;
  min-height: 60px;
  background: var(--bg);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
  padding: 8px 10px;
}

.msg-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.msg-edit-actions button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
}

.msg-edit-actions .msg-edit-save {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.msg-edit-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* ════════════════════════════════════════════════════════════
   CHAT
════════════════════════════════════════════════════════════ */
#chat-panel {
  flex-direction: column;
}

#chat-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1c0800, #3d1200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 16px rgba(220, 80, 0, 0.45);
}

.ai-info h3 {
  font-family: "Syne", sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.ai-status {
  font-size: 12px;
  color: var(--accent3);
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent3);
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* Mensagens */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.msg.ai .msg-avatar {
  background: linear-gradient(135deg, #1c0800, #3d1200);
  border: none;
  box-shadow: 0 0 10px rgba(220, 80, 0, 0.35);
}

.msg-bubble {
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.65;
}

.msg.ai .msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  color: var(--text);
}

.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border-radius: 16px 4px 16px 16px;
}

/* Atalhos rápidos */
#quick-prompts {
  padding: 12px 24px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.qp {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.qp:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 138, 255, 0.08);
}

/* Área de input */
#input-area {
  padding: 16px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  padding: 13px 16px;
  font-family: "DM Sans", sans-serif;
  font-size: 14.5px;
  resize: none;
  min-height: 50px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#user-input:focus {
  border-color: var(--accent);
}
#user-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
  box-shadow: 0 4px 16px rgba(79, 138, 255, 0.35);
}

#send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(79, 138, 255, 0.5);
}
#send-btn:active {
  transform: scale(0.96);
}

/* Indicador de digitação */
.typing {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

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

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}
/* Elementos de Markdown renderizado dentro das mensagens da IA */
.msg-bubble-content p { margin: 0 0 10px; }
.msg-bubble-content p:last-child { margin-bottom: 0; }
.msg-bubble-content ul,
.msg-bubble-content ol { margin: 8px 0; padding-left: 22px; }
.msg-bubble-content li { margin-bottom: 4px; }
.msg-bubble-content strong { color: var(--accent); }
.msg-bubble-content h1,
.msg-bubble-content h2,
.msg-bubble-content h3 { margin: 14px 0 8px; line-height: 1.3; }
.msg-bubble-content h1:first-child,
.msg-bubble-content h2:first-child,
.msg-bubble-content h3:first-child { margin-top: 0; }
.msg-bubble-content code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.9em;
}
.msg-bubble-content pre {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-bubble-content pre code { background: none; padding: 0; }
.msg-bubble-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding-left: 12px;
  opacity: 0.85;
}
.msg-bubble-content a { color: var(--accent); text-decoration: underline; }