/* Aleph — Núcleo: el punto que contiene todos los puntos */

.nucleus {
  --threads-w: 252px;
  flex: none; min-height: 0; display: grid;
  grid-template-columns: var(--threads-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - var(--chrome-h));
}
.nucleus:has(.threads.is-collapsed) { --threads-w: 58px; }
.nucleus[data-state="active"] { grid-template-columns: var(--threads-w) minmax(0, 1fr) minmax(320px, 410px); }
.nucleus > [hidden] { display: none !important; }

/* ---------- Hilos: línea de tiempo vertical ---------- */
.threads { border-right: 1px solid var(--line); background: #060a10; display: flex; flex-direction: column; min-height: 0; }
.threads-head { display: flex; align-items: center; gap: 6px; padding: 12px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.threads-head h2 { font-size: var(--fs-14); flex: 1; }
.thread-new svg { width: 15px; height: 15px; }
.thread-list { list-style: none; margin: 0; padding: 10px 8px 24px 0; overflow-y: auto; position: relative; flex: 1; }
.thread-list::before { content: ""; position: absolute; left: 23px; top: 14px; bottom: 14px; width: 1px; background: linear-gradient(var(--line-2), transparent); }
.thread-day { font-size: 11px; color: var(--ink-3); padding: 12px 0 4px 40px; }
.thread {
  display: grid; grid-template-columns: 30px minmax(0, 1fr); align-items: start; padding: 7px 8px 7px 18px; border-radius: 0 8px 8px 0;
  color: var(--ink); position: relative;
}
.thread:hover { background: var(--s1); text-decoration: none; }
.thread[aria-current="true"] { background: var(--s2); }
.thread[aria-current="true"] .thread-title { color: var(--ink); }
.thread-node { margin-top: 5px; position: relative; z-index: 1; box-shadow: 0 0 0 3px #060a10; }
.thread-text { display: grid; gap: 2px; min-width: 0; }
.thread-title { font-size: var(--fs-13); color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.thread-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 11px; color: var(--ink-3); }
.thread-proj { color: var(--ink-2); }
.thread-working { color: var(--cyan); }
.thread-empty { padding: 16px 16px 0 40px; }
.threads.is-collapsed .threads-head { flex-direction: column; padding: 10px 6px; }
.threads.is-collapsed .threads-head h2, .threads.is-collapsed .thread-new span, .threads.is-collapsed .thread-text, .threads.is-collapsed .thread-day, .threads.is-collapsed .thread-empty { display: none; }
.threads.is-collapsed .thread-new { width: 34px; padding: 0; }
.threads.is-collapsed .thread { grid-template-columns: 1fr; padding: 8px 0 8px 20px; }

/* ---------- Portada ---------- */
.nx-hero { overflow-y: auto; padding: 0 var(--gap-5) var(--gap-7); display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; justify-items: center; }
.nx-hero > * { width: min(860px, 100%); }
.hero-field { position: relative; height: clamp(230px, 36vh, 380px); margin-top: var(--gap-2); }
.field-host { position: absolute; inset: 0; -webkit-mask-image: radial-gradient(ellipse 58% 60% at 50% 50%, #000 66%, transparent 100%); mask-image: radial-gradient(ellipse 58% 60% at 50% 50%, #000 66%, transparent 100%); }
.side-field .field-host { -webkit-mask-image: none; mask-image: none; }
.field-host .stage-canvas { display: block; }
.hero-copy { text-align: center; margin: -6px 0 var(--gap-4); }
.hero-title { font-size: clamp(22px, 2.6vw, 32px); line-height: 1.15; letter-spacing: .005em; }
.hero-lead { color: var(--ink-2); max-width: 64ch; margin: 10px auto 0; font-size: var(--fs-16); }
.hero-notice { margin-top: var(--gap-4); }

.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: var(--gap-4); }
.suggestion {
  display: grid; gap: 4px; text-align: left; padding: 10px 12px; border-radius: var(--r-2); border: 1px solid var(--line);
  background: var(--s1); color: var(--ink-2); cursor: pointer; font-size: var(--fs-13); line-height: 1.4;
}
.suggestion:hover { border-color: var(--line-2); color: var(--ink); }
.suggestion .sg-tag { font-size: 11px; color: var(--cyan); font-weight: 600; }
.suggestion.is-secondary .sg-tag { color: var(--ink-3); }
.suggestion.is-secondary { background: transparent; }

.roster { margin-top: var(--gap-6); }
.roster-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--gap-2); }
.roster-head h2 { font-size: var(--fs-16); }
.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr)); gap: 6px; }
.roster-agent { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--s1); min-width: 0; }
.ra-text { display: grid; min-width: 0; line-height: 1.3; }
.ra-text strong { font-family: var(--font-display); font-weight: 600; letter-spacing: .02em; }
.ra-text span { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Compositor ---------- */
.composer-box {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 10px 10px 8px 14px; border-radius: 14px; border: 1px solid var(--line-2);
  background: linear-gradient(180deg, #0e1622, #0b121c); box-shadow: 0 0 0 1px rgba(76, 212, 230, 0), 0 18px 40px rgba(0, 0, 0, .35);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.composer-box:focus-within { border-color: rgba(76, 212, 230, .55); box-shadow: 0 0 0 3px rgba(76, 212, 230, .08), 0 18px 40px rgba(0, 0, 0, .35); }
.composer-box.is-big { padding: 14px 12px 10px 16px; }
.composer-input { width: 100%; border: 0; outline: none; background: transparent; resize: none; color: var(--ink); line-height: 1.5; min-height: 44px; max-height: 220px; padding: 2px 0; }
.composer-box.is-big .composer-input { font-size: var(--fs-16); min-height: 64px; }
.composer-input::placeholder { color: var(--ink-3); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.composer-opts { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.opt {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-2);
  background: transparent; color: var(--ink-2); cursor: pointer; font-size: var(--fs-13); max-width: 220px;
}
.opt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt svg { width: 15px; height: 15px; flex: none; }
.opt:hover { color: var(--ink); border-color: #36485f; }
.opt[aria-pressed="true"] { color: var(--cyan); border-color: rgba(76, 212, 230, .55); background: rgba(76, 212, 230, .08); }
.opt-project.is-set { color: var(--gold); border-color: rgba(240, 194, 90, .45); background: rgba(240, 194, 90, .06); }
.composer-send { display: flex; align-items: center; gap: 10px; }
.send {
  width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--cyan); color: #04121a; transition: transform .12s var(--ease), background .15s var(--ease);
}
.send:hover { background: #79e2ef; }
.send:active { transform: scale(.94); }
.send svg { width: 18px; height: 18px; }
.send.is-stop { background: var(--s3); color: var(--ink); border: 1px solid var(--line-2); }
.send.is-busy { color: transparent; position: relative; }
.send.is-busy::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #04121a; border-color: #04121a transparent #04121a transparent; animation: spin .8s linear infinite; }

/* ---------- Conversación ---------- */
.nx-convo { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.convo-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-3); padding: 12px var(--gap-5); border-bottom: 1px solid var(--line); }
.convo-back { display: none; }
.convo-title { min-width: 0; flex: 1; }
.convo-title h1 { font-size: var(--fs-18); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-meta { display: flex; gap: 10px; align-items: center; font-size: var(--fs-12); color: var(--ink-3); margin-top: 2px; flex-wrap: wrap; }
.convo-meta .tag svg { width: 13px; height: 13px; }
.convo-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.msg-list { position: relative; max-width: 820px; margin: 0 auto; padding: var(--gap-5) var(--gap-5) var(--gap-6) calc(var(--gap-5) + 30px); display: grid; gap: var(--gap-5); }
.msg-list::before { content: ""; position: absolute; left: calc(var(--gap-5) + 9px); top: 28px; bottom: 30px; width: 1px; background: linear-gradient(180deg, rgba(76, 212, 230, .35), rgba(162, 139, 250, .2) 60%, transparent); }
.msg-loading { display: grid; gap: 10px; }
.convo-foot { padding: 10px var(--gap-5) 14px; border-top: 1px solid var(--line); background: rgba(7, 11, 18, .9); }
.convo-foot .composer-box { max-width: 820px; margin: 0 auto; }

.spine-node { position: absolute; left: -26px; top: 6px; width: 12px; height: 12px; border-radius: 50%; }
.spine-node.is-user { border: 1.5px solid var(--ink-3); background: var(--bg); }
.spine-node.is-aleph { background: radial-gradient(circle, #ffffff 0, #9eeaf5 35%, rgba(76, 212, 230, .2) 70%); box-shadow: 0 0 12px rgba(76, 212, 230, .7); }
.spine-node.is-aleph.is-live { animation: aleph-node 1.2s var(--ease) infinite; background: radial-gradient(circle, #ffffff 0, #c8b9ff 35%, rgba(162, 139, 250, .2) 70%); box-shadow: 0 0 14px rgba(162, 139, 250, .8); }
@keyframes aleph-node { 50% { transform: scale(1.35); } }

.msg-u, .msg-a { position: relative; min-width: 0; }
.mu-body { display: grid; gap: 4px; grid-template-columns: minmax(0, 1fr); }
.mu-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-16); color: var(--ink); }
.mu-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-opt { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-3); }
.mini-opt svg { width: 12px; height: 12px; }

.ma-body { display: grid; gap: 10px; min-width: 0; grid-template-columns: minmax(0, 1fr); }
.thought { display: grid; gap: 6px; min-width: 0; grid-template-columns: minmax(0, 1fr); }
.thought[hidden] { display: none; }
.thought-row { display: flex; align-items: center; gap: 8px; }
.filament { flex: 1; height: 26px; min-width: 60px; max-width: 420px; }
.thought-toggle { display: inline-flex; align-items: center; gap: 4px; border: 0; background: transparent; color: var(--violet); cursor: pointer; font-size: var(--fs-13); padding: 2px 4px; border-radius: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.thought-toggle:hover { background: var(--violet-wash); }
.thought-toggle svg { width: 14px; height: 14px; transition: transform .15s var(--ease); }
.thought-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.thought-text { white-space: pre-wrap; overflow-wrap: anywhere; color: #cbbffd; font-size: var(--fs-13); border-left: 1px solid rgba(162, 139, 250, .4); padding: 4px 0 4px 12px; max-height: 320px; overflow-y: auto; }
.tool-nodes { list-style: none; margin: 0; padding: 0 0 0 4px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tool-node { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--ink-2); min-width: 0; max-width: 100%; }
.tn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 6px rgba(240, 194, 90, .7); flex: none; }
.tool-node.is-error .tn-dot { background: var(--red); box-shadow: 0 0 6px rgba(239, 95, 111, .7); }
.tn-verb { color: var(--gold); flex: none; }
.tn-sum { font-family: var(--font-mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ma-text:empty { display: none; }
.ma-text { font-size: var(--fs-14); }
.caret { display: inline-block; width: 7px; height: 1.05em; vertical-align: -2px; background: var(--cyan); margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.ma-error { display: flex; gap: 8px; align-items: center; color: var(--red); font-size: var(--fs-13); }
.ma-error svg { width: 16px; height: 16px; }
.ma-meta { display: flex; align-items: center; gap: 10px; min-height: 28px; }
.ma-meta:empty { display: none; }

/* ---------- Panel lateral: el Aleph y el Consejo ---------- */
.nx-side { border-left: 1px solid var(--line); display: grid; grid-template-rows: minmax(240px, 44%) minmax(0, 1fr); min-height: 0; background: #05080d; }
.side-field { position: relative; border-bottom: 1px solid var(--line); overflow: hidden; background: var(--bg); }
.side-panel { display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px 8px; }
.side-head h2 { font-size: var(--fs-14); }
.side-roster { overflow-y: auto; padding: 0 12px 16px; display: grid; gap: 8px; align-content: start; }

/* Etiquetas del campo */
.aleph-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.aleph-label { position: absolute; left: 0; top: 0; display: grid; justify-items: center; line-height: 1.2; white-space: nowrap; text-shadow: 0 1px 4px #000; will-change: transform; }
.aleph-label strong { font-family: var(--font-display); font-size: 12px; font-weight: 600; letter-spacing: .03em; }
.aleph-label span { font-size: 10.5px; color: var(--gold); max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.aleph-label[data-align="start"] { justify-items: start; text-align: left; }
.aleph-label[data-align="end"] { justify-items: end; text-align: right; }
.aleph-fallback { position: absolute; inset: 0; display: grid; place-items: center; }
.aleph-fallback span { width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle, #fff 0, #9eeaf5 18%, rgba(76, 212, 230, .25) 45%, transparent 70%); box-shadow: 0 0 60px rgba(76, 212, 230, .4); animation: aleph-node 3s var(--ease) infinite; }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .nucleus[data-state="active"] { grid-template-columns: var(--threads-w) minmax(0, 1fr) 320px; }
  .suggestions { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .nucleus, .nucleus[data-state="active"] { display: flex; flex-direction: column; height: auto; min-height: calc(100vh - var(--chrome-h)); }
  .nucleus[data-state="active"] .threads { display: none; }
  .nucleus[data-state="empty"] .threads { order: 3; border-right: 0; border-top: 1px solid var(--line); }
  .nucleus[data-state="empty"] .threads.is-collapsed .thread-text, .nucleus[data-state="empty"] .threads.is-collapsed .threads-head h2 { display: grid; }
  .threads-head [aria-label="Plegar hilos"], .threads-head [aria-label="Mostrar hilos"] { display: none; }
  .nx-side { order: 1; grid-template-rows: 170px; border-left: 0; border-bottom: 1px solid var(--line); }
  .nx-side .side-panel { display: none; }
  .nx-convo { order: 2; min-height: calc(100vh - var(--chrome-h) - 170px); }
  .convo-back { display: inline-flex; }
  .convo-scroll { overflow: visible; }
  .convo-foot { position: sticky; bottom: 0; z-index: 5; }
  .msg-list { padding: var(--gap-4) var(--gap-4) var(--gap-5) calc(var(--gap-4) + 26px); }
  .msg-list::before { left: calc(var(--gap-4) + 7px); }
  .spine-node { left: -24px; }
  .convo-head { padding: 10px var(--gap-4); }
  .convo-foot { padding: 8px var(--gap-3) 10px; }
  .nx-hero { padding: 0 var(--gap-4) var(--gap-6); }
  .hero-field { height: clamp(200px, 30vh, 280px); }
}
@media (max-width: 480px) {
  .composer-hint { display: none; }
  .opt { padding: 0 8px; }
  .opt span { max-width: 84px; }
  .hero-lead { font-size: var(--fs-14); }
  .roster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Archivos que tocó el Núcleo y deshacer */
.ma-files { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.ma-files[hidden] { display: none; }
.file-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.file-chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 260px; padding: 3px 9px 3px 7px; border-radius: 999px;
  border: 1px solid rgba(240, 194, 90, .28); background: rgba(240, 194, 90, .07); color: #f3d491;
  font-family: var(--font-mono); font-size: 11.5px; cursor: pointer;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip svg { width: 12px; height: 12px; flex: none; color: var(--gold); }
.file-chip:hover { border-color: var(--gold); background: rgba(240, 194, 90, .13); }
.file-chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.convo-actions { flex-wrap: nowrap; }
.convo-revert svg { color: var(--orange); }
.revert-list { margin: 0; padding: 8px 12px 8px 26px; max-height: 180px; overflow-y: auto; font-size: 12px; color: var(--ink-2); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-2); overflow-wrap: anywhere; }
@media (max-width: 1100px) {
  .convo-revert .btn-label { display: none; }
}

/* Decisiones pendientes que pidió el Núcleo en esta conversación */
.chat-approvals { max-width: 820px; margin: 0 auto 10px; display: grid; gap: 8px; max-height: 42vh; overflow-y: auto; }
.chat-approvals-head { display: flex; align-items: center; gap: 8px; color: var(--orange); }
.chat-approvals-head svg { width: 16px; height: 16px; }
.approval.in-chat { border-color: rgba(243, 154, 79, .45); background: rgba(243, 154, 79, .06); }
@media (max-width: 900px) {
  /* El encabezado del hilo queda a mano (renombrar, deshacer, borrar) mientras se lee la conversación. */
  .convo-head { position: sticky; top: var(--chrome-h); z-index: 6; background: var(--bg); }
  .convo-foot { background: var(--bg); }
  .chat-approvals { max-height: 38vh; }
}
@media (max-width: 480px) {
  /* Compositor compacto: opciones en una fila desplazable y el botón de enviar a la derecha. */
  .composer-bar { flex-wrap: nowrap; }
  .composer-opts { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; flex: 1; }
  .composer-opts::-webkit-scrollbar { display: none; }
  .opt { flex: none; }
}
