:root {
  --fog: #e9eef2;
  --surface: #ffffff;
  --ink: #172026;
  --graphite: #525e67;
  --line: #d3dbe1;
  --cobalt: #2443d6;
  --cobalt-soft: #dfe5ff;
  --moss: #276b43;
  --moss-soft: #dcefe3;
  --brick: #b3362b;
  --brick-soft: #f6dedb;
  --ochre: #a86b12;
  --ochre-soft: #f5e8cf;
  --rail-off: #dde3e8;
  --radius: 10px;
  --display: "Bricolage Grotesque", "IBM Plex Sans", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fog: #0f1418;
    --surface: #172026;
    --ink: #e6ecef;
    --graphite: #93a1ab;
    --line: #2a353d;
    --cobalt: #7d94ff;
    --cobalt-soft: #1f2a5c;
    --moss: #6cc794;
    --moss-soft: #183527;
    --brick: #f08378;
    --brick-soft: #3d1c19;
    --ochre: #e0a94f;
    --ochre-soft: #3a2b12;
    --rail-off: #2a353d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fog);
  color: var(--ink);
  font: 15px/1.5 var(--body);
}

h1, h2 { font-family: var(--display); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
code, .mono { font-family: var(--mono); font-size: 0.85em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

/* Barra superior ------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 1.6rem; font-weight: 700; white-space: nowrap; }
.brand-sub { color: var(--graphite); font-size: 0.9rem; }
.brand-mark {
  width: 22px; height: 12px; align-self: center;
  background: linear-gradient(90deg, var(--cobalt) 0 30%, transparent 30% 36%, var(--cobalt) 36% 66%, transparent 66% 72%, var(--moss) 72%);
  border-radius: 3px;
}
.topbar-meta { display: flex; gap: 10px; align-items: center; }
.chip {
  font-family: var(--mono); font-size: 0.78rem; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--graphite);
}

main { padding: 0 clamp(16px, 4vw, 40px) 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1440px; margin: 0 auto; }
main > * { min-width: 0; }

/* Botones -------------------------------------------------------------- */
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 8px 14px; font-weight: 500; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
.primary { background: var(--cobalt); color: #fff; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover:not(:disabled) { background: var(--surface); }
.danger { background: var(--brick); color: #fff; }
.small { padding: 4px 10px; font-size: 0.85rem; }

/* Estadísticas --------------------------------------------------------- */
.stats {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.stat { padding: 14px 18px; display: grid; gap: 2px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat-value { font-family: var(--display); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--graphite); font-size: 0.82rem; }
.stat-active .stat-value { color: var(--cobalt); }
.stat-ok .stat-value { color: var(--moss); }
.stat-bad .stat-value { color: var(--brick); }
.stat-dup .stat-value { color: var(--ochre); }

/* Subida ----------------------------------------------------------------- */
.intake { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 20px; }
.intake > * { min-width: 0; }
.dropzone {
  display: grid; place-content: center; gap: 6px; text-align: center; min-height: 190px; padding: 24px;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone input { position: absolute; opacity: 0; pointer-events: none; width: 1px; }
.dropzone:focus-within, .dropzone.over { border-color: var(--cobalt); background: var(--cobalt-soft); }
.dropzone-title { font-family: var(--display); font-size: 1.3rem; font-weight: 700; }
.dropzone-hint { color: var(--graphite); font-size: 0.9rem; }
.dropzone-formats { font-family: var(--mono); font-size: 0.72rem; color: var(--graphite); max-width: 36ch; margin: 6px auto 0; }

.uploads, .documents, .search {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.upload-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 210px; overflow: auto; }
.upload-list li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 0.9rem; }
.upload-list .empty { display: block; color: var(--graphite); }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-state { font-family: var(--mono); font-size: 0.78rem; color: var(--graphite); }
.upload-state.ok { color: var(--moss); }
.upload-state.bad { color: var(--brick); }
.upload-bar { grid-column: 1 / -1; height: 4px; background: var(--rail-off); border-radius: 2px; overflow: hidden; }
.upload-bar span { display: block; height: 100%; background: var(--cobalt); transform: scaleX(0); transform-origin: left; transition: transform 0.2s; }

/* Tabla ------------------------------------------------------------------ */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select, .search-form input, .search-form select, #key-input, #message-filter {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--fog);
}
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-weight: 600; color: var(--graphite); font-size: 0.78rem; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-cell { max-width: 280px; }
.file-name { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-hash { font-family: var(--mono); font-size: 0.72rem; color: var(--graphite); }
.type-tag { font-family: var(--mono); font-size: 0.78rem; color: var(--graphite); white-space: nowrap; }
.error-cell { color: var(--brick); max-width: 220px; font-size: 0.85rem; }
.error-cell.note { color: var(--graphite); }
.date-cell { white-space: nowrap; color: var(--graphite); font-size: 0.85rem; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty-row td { color: var(--graphite); text-align: center; padding: 28px; }

.status {
  display: inline-block; font-family: var(--mono); font-size: 0.72rem; font-weight: 500; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px; background: var(--cobalt-soft); color: var(--cobalt); white-space: nowrap;
}
.status[data-status="UPLOADED"], .status[data-status="QUEUED"] { background: var(--rail-off); color: var(--graphite); }
.status[data-status="SUCCESS"] { background: var(--moss-soft); color: var(--moss); }
.status[data-status="FAILED"] { background: var(--brick-soft); color: var(--brick); }
.status[data-status="DUPLICATE"] { background: var(--ochre-soft); color: var(--ochre); }

/* Firma: el riel de etapas. Cada segmento es una etapa real del pipeline. */
.rail { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; width: 168px; }
.rail span { height: 8px; border-radius: 2px; background: var(--rail-off); }
.rail span.done { background: var(--cobalt); }
.rail span.current { background: var(--cobalt); animation: pulse 1.2s ease-in-out infinite; }
.rail[data-final="SUCCESS"] span { background: var(--moss); }
.rail[data-final="DUPLICATE"] span { background: var(--ochre); opacity: 0.7; }
.rail[data-final="FAILED"] span.done { background: var(--graphite); }
.rail[data-final="FAILED"] span.failed { background: var(--brick); }
.rail-caption { display: block; font-family: var(--mono); font-size: 0.7rem; color: var(--graphite); margin-top: 4px; }

@keyframes pulse { 50% { opacity: 0.35; } }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--graphite); font-size: 0.85rem; }

/* Búsqueda ----------------------------------------------------------------- */
.search-form { display: flex; gap: 8px; flex-wrap: wrap; }
.search-form input { flex: 1 1 280px; }
.search-results { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.search-results li { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.result-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; color: var(--graphite); margin-bottom: 6px; }
.result-score { font-family: var(--mono); color: var(--cobalt); }
.result-content { white-space: pre-wrap; font-size: 0.88rem; max-height: 9em; overflow: hidden; margin: 0; }

/* Diálogos ----------------------------------------------------------------- */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  padding: 20px; width: min(440px, calc(100vw - 32px));
}
.dialog.wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(15 20 24 / 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#key-input { width: 100%; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 0.88rem; margin: 0 0 16px; }
.kv dt { color: var(--graphite); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.detail-section { margin-top: 16px; }
.detail-section h3 { font-size: 0.85rem; color: var(--graphite); font-weight: 600; margin: 0 0 8px; }
.events { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; display: grid; gap: 4px; }
.events li { display: grid; grid-template-columns: 150px 110px 1fr; gap: 8px; align-items: center; }
.events .status { justify-self: start; }
.chunk { border: 1px solid var(--line); padding: 8px 10px; margin-bottom: 8px; background: var(--fog); border-radius: 6px; }
.chunk pre { white-space: pre-wrap; margin: 4px 0 0; font-size: 0.82rem; font-family: var(--body); }
.chunk-meta { display: block; font-family: var(--mono); font-size: 0.72rem; color: var(--graphite); overflow-wrap: anywhere; }
pre.json { font-family: var(--mono); font-size: 0.75rem; background: var(--fog); padding: 10px; border-radius: 6px; overflow: auto; max-height: 220px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px));
  background: var(--ink); color: var(--fog); padding: 10px 14px; border-radius: 8px; font-size: 0.9rem;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat:nth-child(5) { border-left: 0; }
  .stat:nth-child(n + 5) { border-top: 1px solid var(--line); }
  .intake { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { border-left: 0; border-top: 1px solid var(--line); }
  .stat:first-child, .stat:nth-child(2) { border-top: 0; }
  .brand-sub, .chip { display: none; }
  .topbar { padding: 14px 16px; }
  .events li { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Navegación entre vistas -------------------------------------------------- */
.views { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.views a {
  color: var(--graphite); text-decoration: none; font-weight: 500; font-size: 0.9rem;
  padding: 5px 14px; border-radius: 999px;
}
.views a:hover { color: var(--ink); }
.views a[aria-current="page"] { background: var(--ink); color: var(--surface); }
[hidden] { display: none !important; }

/* Vista de correo ------------------------------------------------------------ */
.mail-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.mail-head h2 { font-size: 1.5rem; }
.lede { margin: 6px 0 0; color: var(--graphite); max-width: 60ch; }
.mail-switch { display: flex; gap: 8px; }
.mail-switch select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); }
.mail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.mail-grid > * { min-width: 0; }

.mail-form, .mail-status {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.mail-form fieldset { border: 0; margin: 0 0 18px; padding: 0 0 18px; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.mail-form fieldset:last-of-type { border-bottom: 0; padding-bottom: 0; }
.mail-form legend { font-family: var(--display); font-weight: 700; font-size: 1rem; padding: 0; margin-bottom: 12px; }
.field { display: grid; gap: 5px; font-size: 0.88rem; }
.field > span { color: var(--graphite); font-weight: 500; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--fog); width: 100%;
}
.field textarea { font-family: var(--mono); font-size: 0.85rem; resize: vertical; }
.field input:user-invalid { border-color: var(--brick); }
.mail-form small { color: var(--graphite); font-size: 0.8rem; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.field-row .grow { flex: 1 1 160px; }
.field-row .narrow { flex: 0 0 120px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.88rem; }
.check input { margin-top: 3px; accent-color: var(--cobalt); }
.form-message { min-height: 1.4em; margin: 0 0 10px; font-size: 0.88rem; }
.form-message.ok { color: var(--moss); }
.form-message.bad { color: var(--brick); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-text { color: var(--brick); margin-left: auto; }

.mail-status { display: grid; gap: 14px; position: sticky; top: 16px; }
.status-line { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 1.1rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rail-off); }
.dot[data-state="active"] { background: var(--moss); box-shadow: 0 0 0 4px var(--moss-soft); }
.dot[data-state="polling"] { background: var(--cobalt); animation: pulse 1.2s ease-in-out infinite; }
.dot[data-state="error"] { background: var(--brick); box-shadow: 0 0 0 4px var(--brick-soft); }
.dot[data-state="paused"] { background: var(--ochre); }
.send-to { margin: 0; font-size: 0.9rem; color: var(--graphite); }
.send-to strong { color: var(--ink); font-family: var(--mono); font-weight: 500; overflow-wrap: anywhere; }
.kv.compact { margin: 0; }
.error-box { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--brick-soft); color: var(--brick); font-size: 0.85rem; overflow-wrap: anywhere; }

.attachment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 0.82rem; }
.attachment-list .skipped { color: var(--graphite); }
.subject-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.origin-tag { font-family: var(--mono); font-size: 0.7rem; color: var(--cobalt); margin-left: 6px; }

@media (max-width: 960px) {
  .mail-grid { grid-template-columns: 1fr; }
  .mail-status { position: static; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .views { order: 3; width: 100%; justify-content: center; }
}

.file-actions { justify-content: flex-start; margin-bottom: 14px; }
.result-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.result-head { align-items: center; }

/* Login --------------------------------------------------------------------------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; display: grid; gap: 14px;
}
.login-card .lede { margin: 0; }
.login-form { display: grid; gap: 14px; }
.login-form .primary { width: 100%; padding: 10px; }

/* Menú de usuario --------------------------------------------------------------------- */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: grid; text-align: right; gap: 0;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-name { font-weight: 600; font-size: 0.88rem; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 0.72rem; color: var(--graphite); font-family: var(--mono); }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; display: grid; gap: 6px; min-width: 190px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
.user-menu-panel button { text-align: left; }

/* Carga de proyectos ----------------------------------------------------------------- */
.project-upload {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.project-intro p { color: var(--graphite); font-size: 0.9rem; margin: 8px 0 0; }
.project-form { display: grid; gap: 12px; }
.project-pickers { display: flex; gap: 8px; flex-wrap: wrap; }
.picker {
  display: inline-flex; align-items: center; cursor: pointer; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; font-weight: 500; position: relative;
}
.picker:hover { background: var(--fog); }
.picker:focus-within { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.picker input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.project-selection { margin: 0; font-size: 0.88rem; color: var(--graphite); }
.project-bar { height: 6px; }
.muted { color: var(--graphite); font-size: 0.82rem; }

/* Proyectos y usuarios ----------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tech { font-family: var(--mono); font-size: 0.7rem; padding: 2px 7px; border-radius: 999px; background: var(--fog); border: 1px solid var(--line); white-space: nowrap; }
.tech.more { color: var(--graphite); }
.file-tree { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 340px; overflow: auto; }
.file-tree li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; font-size: 0.82rem; }
.file-tree .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deps h4 { margin: 8px 0 2px; font-size: 0.8rem; }
.deps p { margin: 0; font-size: 0.78rem; color: var(--graphite); overflow-wrap: anywhere; }
.roles-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.role-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 4px; align-content: start; font-size: 0.85rem; }
.role-card span { color: var(--graphite); }
#user-form { display: grid; gap: 12px; }
#user-form input:disabled, #user-form select:disabled { opacity: 0.6; }

@media (max-width: 960px) {
  .project-upload { grid-template-columns: 1fr; }
}

/* Bases de datos ------------------------------------------------------------------- */
.schema-chip { cursor: pointer; }
.schema-chip:hover { border-color: var(--cobalt); color: var(--cobalt); }
#db-tables-body input[type="number"] { width: 110px; }
#db-tables-body input[type="text"] { width: 100%; min-width: 160px; }
#db-tables-body input[type="number"], #db-tables-body input[type="text"] {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--fog); font-size: 0.85rem;
}
#db-tables-body input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--cobalt); }
#db-tables-body tr.is-view .type-tag { color: var(--ochre); }

.server-dbs { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--fog); display: grid; gap: 8px; }
.server-dbs .panel-head { margin-bottom: 0; }
.server-db-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-height: 240px; overflow: auto; }
.server-db-list label { display: flex; gap: 8px; align-items: center; font-size: 0.88rem; padding: 6px 8px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.server-db-list label.connected { opacity: 0.7; cursor: default; }
.server-db-list .tag { margin-left: auto; font-family: var(--mono); font-size: 0.68rem; color: var(--moss); }
.server-db-list .use { margin-left: auto; }
.limit-warning { color: var(--ochre); max-width: 180px; }

/* Preguntar (RAG) ------------------------------------------------------------------- */
.ask-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; min-height: calc(100vh - 140px); }
.ask-sidebar { display: grid; align-content: start; gap: 10px; }
.conversation-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); max-height: calc(100vh - 220px); overflow-x: hidden; overflow-y: auto; }
.conversation-list li { display: flex; min-width: 0; align-items: center; border-radius: 8px; }
.conversation-list li:hover { background: var(--surface); }
.conversation-link {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; padding: 8px 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; color: var(--ink);
}
.conversation-link[aria-current="true"] { font-weight: 600; color: var(--cobalt); }
.conversation-delete { background: transparent; border: 0; color: var(--graphite); padding: 4px 8px; visibility: hidden; }
.conversation-list li:hover .conversation-delete, .conversation-delete:focus-visible { visibility: visible; }
.ask-main {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.ask-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.ask-header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-messages { overflow-y: auto; padding: 18px; display: grid; align-content: start; gap: 14px; max-height: calc(100vh - 300px); min-height: 360px; }
.ask-empty { color: var(--graphite); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 70ch; }
.ask-empty p { flex-basis: 100%; margin: 0 0 4px; }
.msg { max-width: 82ch; line-height: 1.6; }
.msg-user { justify-self: end; background: var(--cobalt-soft); color: var(--ink); padding: 10px 14px; border-radius: 12px 12px 2px 12px; }
.msg-user p { margin: 0; white-space: pre-wrap; }
.msg-assistant { justify-self: start; }
.msg-assistant .md p { margin: 0 0 10px; }
.msg-assistant .md ul, .msg-assistant .md ol { margin: 0 0 10px; padding-left: 22px; }
.msg-assistant .md h3, .msg-assistant .md h4, .msg-assistant .md h5 { margin: 12px 0 6px; font-family: var(--display); }
.msg-assistant .md code { background: var(--fog); padding: 1px 5px; border-radius: 4px; }
.msg-assistant .md pre.code { background: var(--fog); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); font-size: 0.82rem; }
.md-table { border-collapse: collapse; margin: 0 0 10px; font-size: 0.86rem; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.typing { color: var(--graphite); font-style: italic; }
.pending .typing::after { content: " ▍"; animation: pulse 1s ease-in-out infinite; }
.cite {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.4em; height: 1.4em; padding: 0 4px;
  margin: 0 1px; font-size: 0.72rem; font-family: var(--mono); font-weight: 600; vertical-align: super; line-height: 1;
  background: var(--cobalt-soft); color: var(--cobalt); border: 0; border-radius: 999px;
}
.cite:hover { background: var(--cobalt); color: #fff; }
.sources { margin-top: 6px; font-size: 0.85rem; }
.sources summary { cursor: pointer; color: var(--graphite); font-weight: 500; }
.source-list { margin: 8px 0 0; padding-left: 22px; display: grid; gap: 4px; }
.source-list li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.source-name { font-weight: 500; overflow-wrap: anywhere; }
.source-location { color: var(--graphite); }
.msg-meta { display: block; margin-top: 6px; font-family: var(--mono); font-size: 0.7rem; color: var(--graphite); }
.ask-form { border-top: 1px solid var(--line); padding: 12px 14px; display: grid; gap: 8px; }
.ask-form textarea {
  width: 100%; resize: vertical; min-height: 52px; max-height: 240px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--fog); font: inherit;
}
.ask-controls { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.ask-scope-label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--graphite); }
.ask-scope-label select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--fog); max-width: 320px; }

/* Configuración de IA ----------------------------------------------------------------- */
.ai-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.ai-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0; display: grid; gap: 12px; align-content: start; min-width: 0; }
.ai-card legend { font-family: var(--display); font-weight: 700; font-size: 1rem; padding: 0 4px; }
.ai-card .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--fog); width: 100%; font: inherit; resize: vertical; }
.ai-wide { grid-column: 1 / -1; }

/* Tokens --------------------------------------------------------------------------------- */
.token-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.token-list li { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 0.86rem; }
.token-list li button { margin-left: auto; }
.token-created { margin-top: 14px; border: 1px solid var(--moss); border-radius: 8px; padding: 12px; background: var(--moss-soft); }
.token-created h3 { font-size: 0.85rem; margin: 12px 0 4px; }
.token-created pre { white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
#token-form { align-items: end; margin-top: 12px; }

@media (max-width: 960px) {
  .ask-layout { grid-template-columns: 1fr; }
  .conversation-list { max-height: 180px; }
  .ai-grid { grid-template-columns: 1fr; }
}
