/* ── VARIABLES GLOBALES ──*/
:root {
  --chat-primary: #1e3a8a; /* Azul fuerte GEIPER */
  --chat-bg: #f8fafc;
  --chat-surface: #ffffff;
  --chat-text: #334155;
  --chat-border: #e2e8f0;
  --bot-msg-bg: #f1f5f9;
  --user-msg-bg: #1e3a8a;
  --user-msg-text: #ffffff;
  --chat-sidebar-w: 300px;
}

/* ── LAYOUT PRINCIPAL ── */
.chat-container {
  display: flex;
  height: calc(100vh - 80px); /* Ocupa el alto restando el header */
  margin-top: 80px; /* Empuja el contenedor debajo del header */
  background-color: var(--chat-bg);
  font-family: 'Inter', system-ui, sans-serif;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.chat-sidebar {
  width: var(--chat-sidebar-w);
  background: var(--chat-surface);
  border-right: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  box-shadow: 2px 0 10px rgba(0,0,0,0.02);
}

.sidebar-header {
  padding: 0 20px 20px 20px;
  border-bottom: 1px solid var(--chat-border);
}

.sidebar-header h2 {
  font-size: 1.25rem;
  color: var(--chat-primary);
  margin-bottom: 5px;
}

.sidebar-header p {
  font-size: 0.95rem;
  color: #64748b;
}

.bot-list {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bot-option {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  padding: 15px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s ease;
}

.bot-option:hover {
  background: #f8fafc;
  border-color: var(--chat-border);
}

.bot-option.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.bot-option i {
  font-size: 1.5rem;
  color: var(--chat-primary);
}

.bot-option .bot-info h3 {
  font-size: 1rem;
  color: #0f172a;
  margin-bottom: 3px;
  font-weight: 600;
}

.bot-option .bot-info p {
  font-size: 0.85rem;
  color: #64748b;
  line-height: 1.3;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--chat-border);
  font-size: 0.85rem;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

/* ── MAIN CHAT AREA ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  position: relative;
}

.chat-header {
  padding: 20px 30px;
  background: var(--chat-surface);
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h2 {
  font-size: 1.3rem;
  color: #0f172a;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.clear-chat-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.1rem;
  cursor: pointer;
  transition: color 0.2s;
}

.clear-chat-btn:hover {
  color: #ef4444;
}

/* ── CHAT MESSAGES ── */
.chat-messages {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 15px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e2e8f0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-content {
  background: var(--bot-msg-bg);
  padding: 15px 20px;
  border-radius: 0 16px 16px 16px;
  color: var(--chat-text);
  font-size: 1.05rem;
  line-height: 1.6;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message-content p {
  margin-bottom: 10px;
}
.message-content p:last-child {
  margin-bottom: 0;
}
.message-content ul, .message-content ol {
  margin: 10px 0;
  padding-left: 20px;
}

/* Boton de "ofrecer" el listado de documentos tras el primer intercambio */
.offer-docs-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  background: var(--azul-medio, #1e40af);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.offer-docs-btn:hover {
  opacity: 0.85;
}
.offer-docs-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Títulos y subtítulos dentro de las respuestas del bot */
.message-content h1,
.message-content h2,
.message-content h3 {
  color: var(--azul-medio, #1e40af);
  font-weight: 700;
  line-height: 1.3;
  margin-top: 16px;
  margin-bottom: 8px;
}
.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
  margin-top: 0;
}
.message-content h1 { font-size: 1.25rem; }
.message-content h2 { font-size: 1.15rem; }
.message-content h3 { font-size: 1.05rem; }

/* Tablas generadas por markdown dentro de las respuestas del bot */
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 0.9rem;
  overflow-x: auto;
  display: block;
}
.message-content table thead {
  background: var(--azul-medio, #1e40af);
}
.message-content table th {
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--azul-medio, #1e40af);
}
.message-content table td {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
}
.message-content table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.03);
}
.message-content table tbody tr:hover {
  background: rgba(30, 64, 175, 0.06);
}

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

.message.user-message .message-content {
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
  border-radius: 16px 0 16px 16px;
}

.message.user-message .message-avatar {
  display: none; /* Hide avatar for user to save space, or use an icon */
}

/* Typography styles for bot markdown */
.message-content strong {
  font-weight: 600;
  color: #0f172a;
}
.message.user-message .message-content strong {
  color: #fff;
}

/* Loading indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  background: #cbd5e1;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ── INPUT AREA ── */
.chat-input-area {
  padding: 20px;
  background: var(--chat-surface);
  border-top: 1px solid var(--chat-border);
}

#chatForm {
  display: flex;
  gap: 15px;
  background: #f1f5f9;
  padding: 8px 15px;
  border-radius: 24px;
  align-items: center;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}

#chatForm:focus-within {
  border-color: var(--chat-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

#chatInput {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  font-size: 1rem;
  outline: none;
  color: var(--chat-text);
}

.send-btn {
  background: var(--chat-primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.send-btn:hover {
  background: #1e40af;
  transform: scale(1.05);
}

.send-btn:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  transform: none;
}

.disclaimer {
  text-align: center;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 10px;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .chat-container {
    flex-direction: column;
    height: calc(100vh - 60px);
  }
  .chat-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--chat-border);
    padding: 10px 0;
  }
  .bot-list {
    flex-direction: row;
    overflow-x: auto;
    padding: 10px 15px;
  }
  .bot-option {
    padding: 10px;
    min-width: 200px;
  }
  .sidebar-header {
    display: none;
  }
  .message {
    max-width: 90%;
  }
}
