/* Variables para tema oscuro */
:root {
  --aimara-primary: #00c2cb;
  --aimara-dark: #00a0a7;
}

[data-theme="dark"] {
  --bg-main: #212121;
  --bg-chat: #212121;
  --bg-message-user: #2f2f2f;
  --bg-message-bot: #212121;
  --bg-header: #212121;
  --bg-input: #2f2f2f;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8ea0;
  --border-color: #4d4d4f;
  --border-light: #565869;
  --hover-bg: #2f2f2f;
  --shadow: rgba(0, 0, 0, 0.3);
}

/* Variables para tema claro */
[data-theme="light"] {
  --bg-main: #ffffff;
  --bg-chat: #ffffff;
  --bg-message-user: #f7f7f8;
  --bg-message-bot: #ffffff;
  --bg-header: #ffffff;
  --bg-input: #ffffff;
  --text-primary: #2d3748;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border-color: #e2e8f0;
  --border-light: #cbd5e0;
  --hover-bg: #f7fafc;
  --shadow: rgba(0, 0, 0, 0.1);
}

/* Reset y base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  /* CORRECCIÓN FINAL: Usar 100dvh para la altura dinámica del viewport */
  height: 100dvh;
  overflow: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout principal sin sidebar */
.app-container {
  display: flex;
  flex-direction: column;
  /* CORRECCIÓN FINAL: Usar 100dvh para la altura dinámica del viewport */
  height: 100dvh;
  width: 100%;
}

/* Header del chat */
.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s ease;
  flex-shrink: 0; /* Evita que el header se comprima */
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.aimara-logo {
  height: 32px;
  width: auto;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  transition: transform 0.3s ease;
}

.aimara-logo:hover {
  transform: scale(1.05);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chaybot-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chaybot-icon {
  color: var(--aimara-primary);
  font-size: 22px;
}

.version-badge {
  background: var(--aimara-primary);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

/* Toggle de tema */
.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  width: 60px;
  height: 32px;
}

.theme-toggle:hover {
  background: var(--hover-bg);
}

.toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: var(--aimara-primary);
  border-radius: 50%;
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
}

[data-theme="light"] .toggle-slider {
  transform: translateX(28px);
}

.new-chat-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 16px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat-btn:hover {
  background: var(--hover-bg);
}

/* Área de mensajes */
.messages-area {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  background: var(--bg-chat);
  transition: background-color 0.3s ease;
}

.messages-container {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* Welcome message */
.welcome-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  padding: 40px 20px;
}

.welcome-icon {
  font-size: 48px;
  color: var(--aimara-primary);
  margin-bottom: 24px;
}

.welcome-title {
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.welcome-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 500px;
  line-height: 1.5;
  margin-bottom: 32px;
}

.example-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  max-width: 600px;
  width: 100%;
}

.example-prompt {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.example-prompt:hover {
  background: var(--hover-bg);
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.prompt-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.prompt-desc {
  font-size: 13px;
  color: var(--text-muted);
}

/* Estilos para los mensajes según tu script.js */
.message-wrapper {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeInUp 0.3s ease-out;
}

.message-wrapper.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
}

.message-wrapper.user .avatar {
  background: var(--aimara-primary);
  color: white;
}

.message-wrapper.bot .avatar {
  background: var(--aimara-dark);
  color: white;
}

.message {
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 12px 16px;
  max-width: 100%;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  word-wrap: break-word;
}

.message-wrapper.user .message {
  background: var(--bg-message-user);
}

.message-wrapper.bot .message {
  background: var(--bg-message-bot);
}

.timestamp {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message-wrapper.user .timestamp {
  text-align: left;
}

/* Indicador de escritura */
.typing-indicator .message {
  background: var(--bg-message-bot);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 16px;
}

.typing-indicator .message span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--aimara-primary);
  animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-8px);
  }
}

/* Input área tipo "isla" - CORREGIDO */
.input-area {
  padding: 16px 24px 24px;
  background: var(--bg-chat);
  transition: all 0.3s ease;
  flex-shrink: 0; /* Evita que el input area se comprima */
}

.input-container {
  max-width: 768px;
  margin: 0 auto;
  position: relative;
}

.input-wrapper {
  position: relative;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: 15px;
  /* CORRECCIÓN: Ajustar el padding para centrar el placeholder */
  padding: 8px 8px 8px 12px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px var(--shadow);
  display: flex;
  align-items: center;
}

.input-wrapper:focus-within {
  border-color: var(--aimara-primary);
  /*box-shadow: 0 0 0 4px rgba(0, 194, 203, 0.1), 0 4px 20px var(--shadow);*/
  transform: translateY(-2px);
}

.message-input {
  flex-grow: 1; /* Permite que el input ocupe todo el espacio disponible */
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  /* CORRECCIÓN: Eliminar el padding derecho para que no afecte el placeholder */
  padding-right: 0;
  /* CORRECCIÓN: Ajustar el padding para evitar superposición */
  padding-left: 0;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.send-button {
  /* CORRECCIÓN: Posicionar el botón de forma relativa al flexbox */
  position: static;
  transform: none;
  width: 40px;
  height: 40px;
  background: var(--aimara-primary);
  border: none;
  border-radius: 25%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 16px;
  /*box-shadow: 0 4px 15px rgba(0, 194, 203, 0.3);*/
  flex-shrink: 0; /* Evita que el botón se comprima */
}

.send-button:hover:not(:disabled) {
  background: var(--aimara-dark);
  transform: scale(1.1);
  /*box-shadow: 0 6px 20px rgba(0, 194, 203, 0.4);*/
}

.send-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Scrollbar personalizada */
.messages-area::-webkit-scrollbar {
  width: 8px;
}

.messages-area::-webkit-scrollbar-track {
  background: transparent;
}

.messages-area::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .chat-header {
    padding: 12px 16px;
  }

  .header-right {
    gap: 8px;
  }

  .new-chat-btn span {
    display: none;
  }

  .messages-container {
    padding: 16px;
  }

  .input-area {
    padding: 16px;
  }

  .welcome-section {
    min-height: 300px;
    padding: 20px;
  }

  .welcome-title {
    font-size: 24px;
  }

  .example-prompts {
    grid-template-columns: 1fr;
  }

  .chaybot-title {
    font-size: 16px;
  }

  .header-center {
    gap: 8px;
  }

  .version-badge {
    display: none;
  }
}

/* Animaciones */
.message-wrapper {
  animation: fadeInUp 0.3s ease-out;
}

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

/* Transiciones suaves para el cambio de tema */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.example-prompt,
.message-wrapper,
.input-wrapper,
.new-chat-btn,
.theme-toggle {
  transition: all 0.3s ease;
}
/* ================================================================ */
/* == ESTILOS MEJORADOS PARA LAS RESPUESTAS DEL BOT (MARKDOWN) == */
/* ================================================================ */

/* Selector base para todos los estilos de contenido del bot */
.message-wrapper.bot .message {
  /* Mejora la legibilidad general del texto del bot */
  line-height: 1.7; 
  font-size: 15.5px;
}

/* Estilo para Párrafos (el texto normal) */
.message-wrapper.bot .message p {
  /* Añade espacio entre párrafos para que no se amontonen */
  margin-bottom: 12px;
}
.message-wrapper.bot .message p:last-child {
  /* Evita que el último párrafo tenga un margen extra al final */
  margin-bottom: 0;
}

/* Estilo para Títulos (###) */
.message-wrapper.bot .message h3 {
  color: var(--aimara-primary); /* O el color que prefieras para los títulos */
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.2em;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

/* Estilo para Listas (* y 1.) */
.message-wrapper.bot .message ul,
.message-wrapper.bot .message ol {
  padding-left: 25px; /* Indentación correcta de la lista */
  margin-top: 10px;
  margin-bottom: 15px;
}

.message-wrapper.bot .message li {
  margin-bottom: 8px; /* Espacio entre cada punto de la lista */
  padding-left: 5px;
}

/* Estilo para Negritas (**) */
.message-wrapper.bot .message strong {
  color: var(--aimara-primary); /* Usa tu color de acento para resaltar */
  font-weight: 600;
}

/* Estilo para el Separador (---) */
.message-wrapper.bot .message hr {
  border: none;
  height: 1px;
  background-color: var(--border-color); /* Usa el color de borde de tu tema */
  margin: 24px 0; /* Buen espacio vertical para que actúe como separador */
}

/* Estilo específico para la sección de "Siguientes Pasos" */
.message-wrapper.bot .message strong:last-of-type {
  /* Asumiendo que "Siguientes Pasos:" es el último elemento en negrita */

  color: var(--text-secondary); /* Un color ligeramente diferente para distinguirlo */
  font-weight: 500;
}
.message-wrapper.bot .message .siguientes-pasos {
  display: block; /* Le damos el salto de línea que querías */
  margin-top: 10px;
  margin-bottom: 10px;
  color: var(--text-secondary); /* Le damos el color secundario */
  font-weight: 500;
}