/* Base */
body {
  font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
  background: #1c1c1c;
  margin: 0;
  height: 100vh;
}

/* Overlay con blur (cubre toda la pantalla y desenfoca el fondo) */
.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,28,28,0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px); /* Safari */
  display: flex;              /* visible por defecto */
  align-items: flex-start;    /* mantiene el chat arriba */
  justify-content: center;
  padding-top: 20px;          /* como tenías antes */
  z-index: 999;
}

/* Contenedor principal del chat */
.chat-wrapper {
  width: 95%;
  max-width: 750px;
  height: 80vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  background: #74A199;
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header .logo {
  height: 32px;
}

.brand-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #fff;
}

.close-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

.close-btn:hover {
  color: #ff4d4d;
}

/* Caja de mensajes */
.chat-box {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  background: #fafafa;
}

/* Scrollbar estilizado */
.chat-box::-webkit-scrollbar {
  width: 6px;
}
.chat-box::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
.chat-box::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* Bloque de bienvenida */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
}

.welcome-logo {
  width: 80px;
  height: auto;
  margin-bottom: 8px;
}

.welcome-text {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.welcome-subtext {
  font-size: 14px;
  color: #555;
  margin-top: 4px;
}

/* Mensajes base */
.msg {
  line-height: 1.4;
  word-wrap: break-word;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mensajes del usuario */
.user-row {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0;
}

.user-msg {
  display: inline-block;
  background: #74A199;
  color: #fff;
  border-radius: 12px;
  border-bottom-right-radius: 0;
  padding: 10px 14px;
  max-width: 70%;
  width: fit-content;
  transition: background 0.2s;
}

.user-msg:hover {
  background: #5f837d;
}

/* Mensajes del asistente */
.assistant-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.assistant-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.assistant-msg {
  background: #eaeaea;
  color: #333;
  border-radius: 12px;
  border-bottom-left-radius: 0;
  padding: 10px 14px;
  max-width: 80%;
  display: inline-block;
  white-space: normal;
}

/* Barra de entrada */
.input-container {
  display: flex;
  align-items: center;
  padding: 10px;
  border-top: 1px solid #ddd;
  background: #f9f9f9;
}

#userInput {
  flex: 1;
  border: 1px solid #ccc;
  border-radius: 25px;
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}

#userInput:focus {
  border-color: #74A199;
  box-shadow: 0 0 5px rgba(116, 161, 153, 0.5);
}

#sendBtn {
  margin-left: 10px;
  background: #74A199;
  color: #fff;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}

#sendBtn:hover {
  background: #5f837d;
}

#sendBtn:active {
  transform: scale(0.95);
}

/* Animación "escribiendo..." */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eaeaea;
  color: #333;
  border-radius: 12px;
  border-bottom-left-radius: 0;
  padding: 6px 10px;
  max-width: fit-content;
  margin: 6px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  background: #555;
  border-radius: 50%;
  display: inline-block;
  animation: blink 1.4s infinite both !important;
}

.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; }
}

/* Responsividad */
@media (max-width: 420px) {
  .assistant-avatar { width: 28px; height: 28px; }
  .assistant-msg, .user-msg { font-size: 13px; padding: 8px 12px; }
  .chat-wrapper { height: 85vh; }
}

/* ============================
   NORMALIZACIÓN DE MARKDOWN
   ============================ */

/* Elimina márgenes automáticos de <p> que agrandan la burbuja */
.assistant-msg p {
  margin: 0;
  padding: 0;
}

/* Ajusta negritas para que encajen con tu estilo */
.assistant-msg strong {
  font-weight: 600;
}

/* Listas sin márgenes excesivos */
.assistant-msg ul,
.assistant-msg ol {
  margin: 4px 0;
  padding-left: 18px;
}

/* Tablas Markdown compactas */
.assistant-msg table {
  margin: 6px 0;
  border-collapse: collapse;
  width: 100%;
}

.assistant-msg table th,
.assistant-msg table td {
  border: 1px solid #ccc;
  padding: 4px 6px;
  font-size: 13px;
}

/* Evita que Markdown meta saltos de línea enormes */
.assistant-msg > *:first-child {
  margin-top: 0;
}
.assistant-msg > *:last-child {
  margin-bottom: 0;
}

/* Evitar que Markdown convierta el contenido en bloques grandes */
.assistant-msg p,
.assistant-msg div,
.assistant-msg pre {
  display: inline;
}

/* Normalizar listas Markdown dentro de la burbuja del asistente */
.assistant-msg ul,
.assistant-msg ol {
  margin: 0;
  padding-left: 14px; /* sangría mínima */
}

.assistant-msg li {
  margin: 0;
  padding: 0;
  line-height: 1.3;
}

