/* ================================================================
   Agente Aduanas Chile — Hoja de estilos principal
   Paleta: #1a2744 navy, #f0f4f8 bg, #2563eb accent blue
   ================================================================ */

/* ---- Reset y variables ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --navy: #1a2744;
  --navy-dark: #111c33;
  --navy-light: #243358;
  --navy-hover: #2e4070;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --bg: #f0f4f8;
  --bg-card: #ffffff;
  --bg-user-msg: #2563eb;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-on-navy: #e2e8f0;
  --text-on-navy-muted: #94a3b8;
  --border: #e2e8f0;
  --border-nav: rgba(255,255,255,0.08);
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --sidebar-width: 300px;
  --header-height: 72px;
  --input-area-height: 110px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  overflow: hidden;
}

/* ================================================================
   LAYOUT
   ================================================================ */
body {
  display: flex;
  height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition), min-width var(--transition);
  position: relative;
  z-index: 100;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

/* ---- Main content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ================================================================
   SIDEBAR — componentes
   ================================================================ */

/* Header del sidebar */
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border-nav);
  flex-shrink: 0;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  color: #60a5fa;
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: 0.01em;
}
.logo-ia {
  color: #60a5fa;
  font-style: italic;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-on-navy-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Secciones del sidebar */
.sidebar-section {
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border-nav);
  flex-shrink: 0;
}

.sidebar-section--grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-bottom: none;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--text-on-navy-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.section-header svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* Botón ojo "Ver documentos" en el section-header */
.btn-ver-docs {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 5px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background var(--transition), color var(--transition);
}
.btn-ver-docs:hover { background: rgba(255,255,255,0.2); color: #fff; }
.btn-ver-docs svg { width: 13px; height: 13px; flex-shrink: 0; }
.btn-ver-docs-count {
  background: rgba(37,99,235,0.6);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
}

/* ---- Tarjeta de estado del scraper ---- */
.scraper-status-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-nav);
  border-radius: var(--radius);
  padding: 10px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.status-row:last-child { margin-bottom: 0; }

.status-label {
  font-size: 11px;
  color: var(--text-on-navy-muted);
  white-space: nowrap;
}

.status-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-on-navy);
  text-align: right;
}

.status-date {
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
}

.status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(100,116,139,0.3);
  color: #94a3b8;
}

.status-badge.ok {
  background: rgba(22,163,74,0.2);
  color: #4ade80;
}

.status-badge.running {
  background: rgba(37,99,235,0.25);
  color: #60a5fa;
  animation: pulse-badge 1.5s infinite;
}

.status-badge.error {
  background: rgba(220,38,38,0.2);
  color: #f87171;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Botón actualizar */
.btn-update {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 7px 10px;
  background: rgba(37,99,235,0.2);
  border: 1px solid rgba(37,99,235,0.3);
  border-radius: var(--radius);
  color: #60a5fa;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn-update:hover {
  background: rgba(37,99,235,0.35);
  border-color: rgba(37,99,235,0.5);
}

.btn-update:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-update svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.btn-update.spinning svg {
  animation: spin 1s linear infinite;
}

/* Botón limpiar y re-indexar */
.btn-reset-normativa {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
  padding: 7px 10px;
  background: rgba(220,38,38,0.15);
  border: 1px solid rgba(220,38,38,0.3);
  border-radius: var(--radius);
  color: #fca5a5;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.btn-reset-normativa:hover {
  background: rgba(220,38,38,0.3);
  border-color: rgba(220,38,38,0.5);
}
.btn-reset-normativa:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-reset-normativa svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ---- Filtros ---- */
.filter-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-on-navy-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.filter-btn svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.filter-btn:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text-on-navy);
}

.filter-btn.active {
  background: rgba(37,99,235,0.2);
  border-color: rgba(37,99,235,0.4);
  color: #60a5fa;
}

/* ---- Zona de carga ---- */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px;
  border: 1.5px dashed rgba(255,255,255,0.2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 8px;
  flex-shrink: 0;
  max-height: 90px;
}

.upload-zone:hover {
  border-color: rgba(96,165,250,0.5);
  background: rgba(37,99,235,0.08);
}

.upload-zone.drag-over {
  border-color: #60a5fa;
  background: rgba(37,99,235,0.15);
  transform: scale(1.01);
}

.upload-zone svg {
  width: 22px;
  height: 22px;
  color: #60a5fa;
  margin-bottom: 2px;
}

.upload-text {
  font-size: 12px;
  font-weight: 600;
  color: #93c5fd;
}

.upload-subtext {
  font-size: 10px;
  color: var(--text-on-navy-muted);
}

/* ---- Lista de documentos ---- */
.documents-list {
  min-height: 80px;
  padding-right: 2px;
}

.documents-list::-webkit-scrollbar {
  width: 4px;
}

.documents-list::-webkit-scrollbar-track {
  background: transparent;
}

.documents-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 999px;
}

.docs-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 4px;
  color: var(--text-on-navy-muted);
  font-size: 12px;
}

.docs-empty {
  padding: 16px 4px;
  color: var(--text-on-navy-muted);
  font-size: 12px;
  text-align: center;
  font-style: italic;
}

.doc-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--radius);
  margin-bottom: 3px;
  transition: background var(--transition);
}

.doc-item:hover {
  background: rgba(255,255,255,0.06);
}

/* ---- Botón explorador ---- */
.btn-explorer {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  color: var(--text-on-navy);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 8px;
}
.btn-explorer:hover { background: rgba(255,255,255,0.12); }
.btn-explorer svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }
.btn-explorer-count {
  margin-left: auto;
  background: rgba(37,99,235,0.5);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

/* ---- Modal explorador ---- */
.explorer-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 720px;
  max-width: calc(100vw - 32px);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.explorer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
}
.explorer-header-left { display: flex; align-items: center; gap: 8px; }
.explorer-header-left svg { width: 16px; height: 16px; opacity: 0.8; }
.explorer-header-left h3 { font-size: 14px; font-weight: 600; }
.explorer-total { font-size: 12px; color: var(--text-on-navy-muted); margin-left: 4px; }
.explorer-header-right { display: flex; align-items: center; gap: 8px; }
.explorer-toolbar {
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.explorer-search-wrap {
  position: relative; display: flex; align-items: center;
}
.explorer-search-icon {
  position: absolute; left: 10px; width: 14px; height: 14px;
  color: #94a3b8; pointer-events: none;
}
.explorer-search-input {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 12px 7px 32px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.explorer-search-input::placeholder { color: #94a3b8; }
.explorer-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.explorer-view-toggle { display: flex; gap: 2px; }
.view-btn {
  background: none; border: none; color: rgba(255,255,255,0.5);
  cursor: pointer; padding: 4px; border-radius: 4px; display: flex;
}
.view-btn svg { width: 15px; height: 15px; }
.view-btn.active { color: #fff; background: rgba(255,255,255,0.15); }
.explorer-close {
  background: none; border: none; color: rgba(255,255,255,0.7);
  font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.explorer-close:hover { background: rgba(255,255,255,0.15); color: #fff; }

.explorer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
}

/* Grid view */
.explorer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.explorer-file-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: box-shadow var(--transition);
}
.explorer-file-card:hover { box-shadow: var(--shadow-md); }
.explorer-card-thumb {
  width: 100%; height: 100px;
  background: #f8fafc; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.explorer-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.explorer-card-thumb:hover { opacity: 0.85; }
.explorer-card-icon {
  width: 100%; height: 100px;
  background: #f1f5f9;
  display: flex; align-items: center; justify-content: center;
}
.explorer-card-icon svg { width: 36px; height: 36px; color: #94a3b8; }
.explorer-file-info {
  padding: 8px 10px 10px;
  display: flex; flex-direction: column; gap: 2px;
  flex: 1;
}
.explorer-file-name {
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.explorer-file-meta { font-size: 11px; color: var(--text-muted); }
.explorer-delete-btn {
  position: absolute; top: 5px; right: 5px;
  background: rgba(0,0,0,0.45); border: none;
  border-radius: 4px; padding: 3px; cursor: pointer;
  opacity: 0; transition: opacity var(--transition);
  display: flex;
}
.explorer-file-card:hover .explorer-delete-btn { opacity: 1; }
.explorer-delete-btn svg { width: 13px; height: 13px; color: #fff; }
.explorer-delete-btn:hover { background: var(--error); }

/* List view */
.explorer-list { display: flex; flex-direction: column; gap: 4px; }
.explorer-list-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px;
  transition: box-shadow var(--transition);
}
.explorer-list-row:hover { box-shadow: var(--shadow); }
.explorer-list-thumb {
  width: 40px; height: 40px; border-radius: 4px;
  overflow: hidden; cursor: pointer; flex-shrink: 0;
  border: 1px solid var(--border);
}
.explorer-list-thumb img { width: 100%; height: 100%; object-fit: cover; }
.explorer-list-icon {
  width: 40px; height: 40px; border-radius: 4px;
  background: #f1f5f9; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.explorer-list-icon svg { width: 20px; height: 20px; color: #94a3b8; }
.explorer-list-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.explorer-list-row .explorer-delete-btn {
  position: static; opacity: 0;
  background: #f1f5f9; border-radius: 4px; padding: 5px;
}
.explorer-list-row:hover .explorer-delete-btn { opacity: 1; }
.explorer-list-row .explorer-delete-btn svg { color: var(--text-secondary); }
.explorer-list-row .explorer-delete-btn:hover { background: var(--error); }
.explorer-list-row .explorer-delete-btn:hover svg { color: #fff; }

/* Empty state */
.explorer-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; padding: 48px 24px;
  color: var(--text-muted);
}
.explorer-empty svg { width: 40px; height: 40px; opacity: 0.3; }
.explorer-empty p { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.explorer-empty span { font-size: 12px; text-align: center; }

.doc-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.doc-thumb {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.15);
  transition: border-color var(--transition);
}

.doc-thumb:hover {
  border-color: #60a5fa;
}

.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview-card {
  background: var(--navy);
  border-radius: var(--radius-lg);
  overflow: hidden;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
}
.pdf-preview-card {
  background: var(--navy);
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: 88vw;
  max-width: 1100px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}
.explorer-file-card { cursor: pointer; }
.explorer-list-row { cursor: pointer; }

.doc-icon svg {
  width: 14px;
  height: 14px;
  color: #93c5fd;
}

.doc-info {
  flex: 1;
  min-width: 0;
}

.doc-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-on-navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.doc-meta {
  font-size: 10px;
  color: var(--text-on-navy-muted);
  margin-top: 1px;
}

.btn-delete-doc {
  flex-shrink: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: transparent;
  padding: 2px;
  border-radius: 4px;
  transition: all var(--transition);
  line-height: 0;
}

.doc-item:hover .btn-delete-doc {
  color: #f87171;
}

.btn-delete-doc:hover {
  background: rgba(220,38,38,0.15) !important;
}

.btn-delete-doc svg {
  width: 13px;
  height: 13px;
}

/* ================================================================
   MAIN CONTENT — Header del chat
   ================================================================ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 10;
}

.sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  line-height: 0;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
}

.chat-header-title {
  flex: 1;
  min-width: 0;
}

.chat-header-title h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-title p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Botón info fuentes */
.btn-sources-info {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px;
  cursor: pointer;
  color: var(--primary);
  transition: all var(--transition);
  line-height: 0;
  flex-shrink: 0;
}
.btn-sources-info:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}
.btn-sources-info svg { width: 18px; height: 18px; }

/* Modal fuentes */
.sources-modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: 540px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
}
.sources-modal-body {
  padding: 20px 24px 24px;
}
.sources-intro {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 20px;
}
.source-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.source-item:last-of-type { border-bottom: none; }
.source-item-logo {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  flex-shrink: 0; color: #fff;
}
.source-logo-aduana  { background: #1e40af; }
.source-logo-bcn     { background: #7c3aed; }
.source-logo-sii     { background: #b45309; }
.source-logo-interno { background: #065f46; }
.source-item-info {
  display: flex; flex-direction: column; gap: 2px;
}
.source-item-info strong { font-size: 13px; color: var(--text); }
.source-item-info span   { font-size: 11px; color: var(--primary); font-weight: 500; }
.source-item-info p      { font-size: 12px; color: var(--text-muted); margin: 4px 0 0; line-height: 1.5; }
.sources-footer {
  display: flex; gap: 8px; align-items: flex-start;
  margin-top: 16px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: var(--radius);
  font-size: 11px; color: var(--text-muted); line-height: 1.5;
}

.btn-clear-chat {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  line-height: 0;
  flex-shrink: 0;
}

.btn-clear-chat:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: var(--error);
}

.btn-clear-chat svg {
  width: 16px;
  height: 16px;
}

/* ================================================================
   ÁREA DE CHAT
   ================================================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
  width: 6px;
}

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

.chat-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

/* ---- Pantalla de bienvenida ---- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.welcome-icon {
  width: 60px;
  height: 60px;
  background: var(--accent-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.welcome-icon svg {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.welcome-screen h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-screen > p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 28px;
}

.suggested-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.query-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.query-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.query-chip:hover {
  background: var(--accent-light);
  border-color: #93c5fd;
  color: var(--accent);
}

/* ---- Mensajes ---- */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: 12px;
  animation: fadeInUp 0.25s ease;
}

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

/* Mensaje del usuario */
.message--user {
  flex-direction: row-reverse;
}

.message--user .message-bubble {
  background: var(--bg-user-msg);
  color: #ffffff;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  max-width: 75%;
}

/* Mensaje del asistente */
.message--assistant {
  flex-direction: row;
}

.message--assistant .message-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  border: 1px solid var(--border);
  max-width: 85%;
  box-shadow: var(--shadow);
}

/* Avatar */
.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.message--user .message-avatar {
  background: #1d4ed8;
}

.message--assistant .message-avatar {
  background: var(--navy);
}

.message-avatar svg {
  width: 16px;
  height: 16px;
  color: white;
}

/* Burbuja */
.message-bubble {
  padding: 12px 16px;
}

.message-text {
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

/* ---- Markdown rendered elements ---- */
.message-text .md-p { margin: 0 0 8px 0; }
.message-text .md-p:last-child { margin-bottom: 0; }
.message-text .md-h1 { font-size: 18px; font-weight: 700; margin: 14px 0 6px; color: var(--navy); }
.message-text .md-h2 { font-size: 16px; font-weight: 700; margin: 12px 0 5px; color: var(--navy); border-bottom: 2px solid var(--border); padding-bottom: 4px; }
.message-text .md-h3 { font-size: 14px; font-weight: 700; margin: 10px 0 4px; color: var(--navy); }
.message-text .md-h4 { font-size: 14px; font-weight: 700; font-style: italic; margin: 8px 0 3px; color: var(--text-primary); }
.message-text .md-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.message-text .md-ul,
.message-text .md-ol { padding-left: 20px; margin: 6px 0 10px; }
.message-text .md-ul li,
.message-text .md-ol li { margin-bottom: 4px; }
.message-text .md-quote { border-left: 3px solid var(--accent); background: var(--accent-light); color: var(--text-secondary); padding: 8px 12px; margin: 8px 0; border-radius: 0 var(--radius) var(--radius) 0; font-style: italic; font-size: 13px; }
.message-text .md-pre { background: #1e293b; color: #e2e8f0; padding: 12px 14px; border-radius: var(--radius); overflow-x: auto; font-family: var(--font-mono); font-size: 12px; margin: 8px 0; }
.message-text .md-code { background: #f1f5f9; color: #dc2626; padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: 12px; }
.message-text .md-link { color: var(--accent); text-decoration: underline; }
.message-text .md-link:hover { color: var(--accent-hover); }

/* ---- Tablas markdown ---- */
.message-text .md-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.message-text .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.message-text .md-table thead {
  background: #3b5998;
  color: #fff;
}
.message-text .md-table thead th {
  padding: 9px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.15);
}
.message-text .md-table thead th:last-child { border-right: none; }
.message-text .md-table tbody tr { border-bottom: 1px solid var(--border); }
.message-text .md-table tbody tr:last-child { border-bottom: none; }
.message-text .md-table tbody tr:nth-child(even) { background: #f8fafc; }
.message-text .md-table tbody tr:hover { background: var(--accent-light); }
.message-text .md-table tbody td {
  padding: 8px 14px;
  border-right: 1px solid var(--border);
  vertical-align: top;
}
.message-text .md-table tbody td:last-child { border-right: none; }

.message--user .message-text {
  color: white;
}

/* Sources del mensaje del asistente */
.message-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.sources-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 7px;
}

.sources-text-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.source-text-item {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.source-text-type {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-right: 6px;
}

/* Indicador de carga */
.message--loading .message-text {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-style: italic;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s infinite ease-in-out;
}

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

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ================================================================
   INPUT DEL CHAT
   ================================================================ */
.chat-input-area {
  flex-shrink: 0;
  padding: 12px 24px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.filter-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.filter-indicator svg {
  width: 11px;
  height: 11px;
  color: var(--accent);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
}

#chatInput::placeholder {
  color: var(--text-muted);
}

.btn-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:active {
  transform: scale(0.94);
}

.btn-send:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.btn-send svg {
  width: 16px;
  height: 16px;
  color: white;
}

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

.input-hint kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
}

/* ================================================================
   SPINNERS Y LOADING
   ================================================================ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.mini-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: rgba(255,255,255,0.6);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* ================================================================
   OVERLAY DE CARGA DE DOCUMENTOS
   ================================================================ */
.upload-progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}

.upload-progress-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  min-width: 220px;
}

.upload-progress-text {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

/* ================================================================
   MODAL METADATA
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  backdrop-filter: blur(3px);
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
  background: var(--navy);
  color: #fff;
}

.modal-header svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-input {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg);
  font-family: var(--font);
  transition: border-color var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}

.btn-modal-cancel {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-modal-cancel:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.btn-modal-confirm {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-modal-confirm svg {
  width: 15px;
  height: 15px;
}

.btn-modal-confirm:hover {
  background: var(--accent-hover);
}

/* ================================================================
   TOAST NOTIFICATIONS
   ================================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  min-width: 260px;
  max-width: 400px;
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast--success {
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  color: #15803d;
}

.toast--error {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.toast--info {
  background: var(--accent-light);
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.toast--warning {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
}

.toast svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ================================================================
   UTILIDADES
   ================================================================ */
.hidden {
  display: none !important;
}

/* ================================================================
   RESPONSIVO
   ================================================================ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(0);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.collapsed {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    transform: translateX(-100%);
  }

  .main-content {
    width: 100%;
  }

  .chat-area {
    padding: 16px;
  }

  .message--user .message-bubble,
  .message--assistant .message-bubble {
    max-width: 90%;
  }

  .chat-input-area {
    padding: 10px 16px 14px;
  }

  .welcome-screen {
    padding: 24px 12px;
  }

  .query-chip {
    font-size: 11px;
    padding: 6px 12px;
  }
}
