/* ==========================================================
   File Search Demo · Suite Agéntica Evoltis · versión SOHO
   Paleta profesional tipo AI/enterprise.
   ========================================================== */
:root {
  --bg: #0b1220;
  --bg-2: #111a2b;
  --panel: #0f1a2e;
  --panel-2: #152341;
  --border: #1e2e4f;
  --border-2: #2a3d63;
  --text: #e6edf8;
  --text-dim: #a5b3cc;
  --text-mute: #6b7a99;
  --accent: #14b8a6;        /* teal principal */
  --accent-2: #22d3ee;       /* cyan secundario */
  --accent-deep: #0e7f70;
  --warn: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --chip-bg: rgba(20, 184, 166, 0.12);
  --chip-border: rgba(20, 184, 166, 0.35);
  --code-bg: #0a1322;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-2: 0 12px 32px rgba(0,0,0,0.45);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans);
  background:
    radial-gradient(ellipse 1200px 600px at 80% -10%, rgba(20,184,166,0.08), transparent 60%),
    radial-gradient(ellipse 1000px 500px at 0% 100%, rgba(34,211,238,0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h2, h3 { margin: 0; font-weight: 600; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(10, 17, 32, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: #041315;
  box-shadow: var(--shadow-1);
}
.brand-title { font-size: 14px; font-weight: 600; letter-spacing: 0.1px; }
.brand-version { color: var(--text-mute); font-weight: 400; }
.brand-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.status-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
  color: var(--text-dim);
}
.status-chip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 10px currentColor;
}
.status-chip.ok .dot { background: var(--success); }
.status-chip.err .dot { background: var(--danger); }
.status-meta {
  padding-left: 8px;
  border-left: 1px solid var(--border-2);
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ============ LAYOUT ============ */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 400px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel-header {
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.hint {
  font-size: 11.5px;
  color: var(--text-mute);
  display: block;
}

/* ============ LIBRARY ============ */
.library .panel-header { padding-bottom: 14px; }
.dropzone {
  margin: 14px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius);
  background: rgba(20, 184, 166, 0.03);
  text-align: center;
  color: var(--text-dim);
  transition: all 0.2s ease;
  cursor: pointer;
}
.dropzone:hover,
.dropzone.drag {
  border-color: var(--accent);
  background: rgba(20, 184, 166, 0.08);
  color: var(--text);
}
.dropzone svg { color: var(--accent); margin-bottom: 8px; }
.dz-primary { font-weight: 500; color: var(--text); }
.dz-secondary { font-size: 12px; margin-top: 4px; }
.dz-meta { font-size: 11px; color: var(--text-mute); margin-top: 8px; font-family: var(--font-mono); }
.link-btn {
  background: none; border: none; color: var(--accent-2);
  cursor: pointer; font-size: inherit; text-decoration: underline;
  text-underline-offset: 2px; padding: 0;
}
.link-btn:hover { color: var(--accent); }

.upload-queue {
  padding: 0 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.upload-queue:empty { display: none; }
.upload-item {
  font-size: 12px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.upload-item .ui-name {
  display: flex; justify-content: space-between; align-items: center;
}
.upload-item .ui-stage { color: var(--text-mute); font-family: var(--font-mono); font-size: 11px; }
.upload-item.ok .ui-stage { color: var(--success); }
.upload-item.err .ui-stage { color: var(--danger); }
.bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.bar > div {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%; transition: width 0.3s ease;
}
.upload-item.loading .bar > div { animation: pulse 1.5s ease-in-out infinite; width: 60% !important; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

.panel-section {
  padding: 10px 14px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-mute); margin-bottom: 10px;
}
.icon-btn {
  background: none; border: 1px solid var(--border-2);
  color: var(--text-dim); padding: 4px 6px; border-radius: 4px;
  cursor: pointer; display: flex; align-items: center;
}
.icon-btn:hover { color: var(--accent-2); border-color: var(--accent); }

.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-list .empty {
  color: var(--text-mute); font-size: 12px;
  text-align: center; padding: 20px 0;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.doc-item {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex; gap: 10px; align-items: flex-start;
  transition: border-color 0.15s;
}
.doc-item:hover { border-color: var(--border-2); }
.doc-icon {
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}
.doc-meta { flex: 1; min-width: 0; }
.doc-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}
.doc-info {
  font-size: 10.5px;
  color: var(--text-mute);
  margin-top: 2px;
  font-family: var(--font-mono);
}
.doc-delete {
  background: none; border: none; color: var(--text-mute);
  cursor: pointer; padding: 2px; opacity: 0; transition: all 0.15s;
}
.doc-item:hover .doc-delete { opacity: 1; }
.doc-delete:hover { color: var(--danger); }

.panel-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 11px;
  flex-shrink: 0;
}
.mini-row { display: flex; justify-content: space-between; padding: 2px 0; }
.mini-label { color: var(--text-mute); }
.mini-value { color: var(--text-dim); }
.mini-value.mono { font-family: var(--font-mono); font-size: 10.5px; }

/* ============ CHAT ============ */
.chat-header { padding-bottom: 14px; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex; flex-direction: column; gap: 18px;
  min-height: 0;
}
.welcome {
  margin: auto;
  max-width: 520px;
  text-align: center;
  color: var(--text-dim);
  padding: 30px 20px;
}
.welcome-icon {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
}
.welcome h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.welcome-sub { margin-bottom: 22px; }
.chips {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.chip {
  padding: 7px 13px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.chip:hover {
  background: rgba(20, 184, 166, 0.2);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.msg {
  display: flex; gap: 12px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--panel-2); color: var(--text-dim); border: 1px solid var(--border); }
.msg.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #041315;
}
.msg-body {
  flex: 1; min-width: 0;
  padding: 12px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  overflow-wrap: break-word;
}
.msg.user .msg-body { background: rgba(20, 184, 166, 0.06); border-color: var(--border-2); }
.msg-body pre {
  background: var(--code-bg);
  padding: 10px 12px; border-radius: 6px;
  overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px;
}
.msg-body code {
  background: var(--code-bg); padding: 1px 5px; border-radius: 3px;
  font-family: var(--font-mono); font-size: 12.5px;
}
.msg-body pre code { background: none; padding: 0; }
.msg-body table {
  border-collapse: collapse; margin: 8px 0; font-size: 12.5px;
  width: 100%;
}
.msg-body th, .msg-body td {
  border: 1px solid var(--border-2); padding: 6px 8px; text-align: left;
}
.msg-body th { background: var(--panel); color: var(--accent-2); font-weight: 600; }
.msg-body p { margin: 0 0 8px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 4px 0 8px; padding-left: 22px; }
.msg-body li { margin-bottom: 3px; }
.msg-body .cite-ref {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  margin: 0 2px;
  font-size: 10px; font-weight: 600; font-family: var(--font-mono);
  background: var(--chip-bg); color: var(--accent);
  border: 1px solid var(--chip-border);
  border-radius: 4px; vertical-align: super;
  cursor: pointer; transition: all 0.15s;
}
.msg-body .cite-ref:hover { background: var(--accent); color: #041315; }

.msg-meta {
  font-size: 10.5px; color: var(--text-mute);
  font-family: var(--font-mono);
  margin-top: 8px;
  display: flex; gap: 14px; flex-wrap: wrap;
}
.msg-meta span::before { content: '·'; margin-right: 6px; color: var(--border-2); }
.msg-meta span:first-child::before { content: ''; margin: 0; }

.typing {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 16px;
}
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.4s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%,80%,100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; gap: 10px; align-items: flex-end;
  flex-shrink: 0;
  background: var(--panel);
}
.composer textarea {
  flex: 1;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  max-height: 180px;
  outline: none;
  transition: border-color 0.15s;
}
.composer textarea:focus { border-color: var(--accent); }
.composer textarea::placeholder { color: var(--text-mute); }
#btn-send {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  border: none; border-radius: var(--radius);
  color: #041315; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(20,184,166,0.25);
}
#btn-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(20,184,166,0.4); }
#btn-send:active { transform: scale(0.96); }
#btn-send:disabled {
  background: var(--border-2); color: var(--text-mute); cursor: not-allowed;
  box-shadow: none;
}

/* ============ CITATIONS ============ */
.citations-body {
  flex: 1; overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 0;
}
.citations-body .empty {
  text-align: center; color: var(--text-mute); padding: 40px 16px;
  font-size: 12.5px;
}
.citations-body .empty svg { margin-bottom: 10px; }

.chunk-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.chunk-card.highlight { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chunk-head {
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.chunk-idx {
  width: 22px; height: 22px; border-radius: 5px;
  background: var(--chip-bg); color: var(--accent);
  border: 1px solid var(--chip-border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.chunk-title {
  flex: 1; min-width: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chunk-text {
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
  max-height: 200px; overflow-y: auto;
  white-space: pre-wrap;
}
.chunk-text:empty::before { content: '(sin texto de contexto)'; color: var(--text-mute); font-style: italic; }
.chunk-foot {
  padding: 8px 14px;
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text-mute);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between;
}

.citations-summary {
  padding: 10px 12px;
  background: rgba(20, 184, 166, 0.05);
  border: 1px solid var(--chip-border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.citations-summary strong { color: var(--accent-2); }

/* ============ FOOTER ============ */
.footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-mute);
  background: rgba(10, 17, 32, 0.6);
}
.conf-badge {
  padding: 3px 8px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--warn);
  border-radius: 4px;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.08em;
}
.sep { color: var(--border-2); }

/* ============ TOASTS ============ */
.toasts {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
}
.toast {
  padding: 12px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  animation: slideInRight 0.25s ease;
  min-width: 240px;
  max-width: 400px;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============ RESPONSIVE ============ */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 280px 1fr 340px; }
}
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .library { max-height: 240px; }
  .citations { max-height: 280px; }
}

/* ============ SCROLLBARS ============ */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }
