:root {
  --bg: #1e1e22;
  --bg-2: #26262b;
  --bg-3: #2f2f35;
  --bg-hover: #34343b;
  --border: #3a3a42;
  --text: #dcdce2;
  --text-2: #a0a0ab;
  --text-3: #8d8d99;
  --accent: #a78bfa;
  --accent-2: #8b5cf6;
  --accent-bg: rgba(167, 139, 250, .14);
  --danger: #f87171;
  --ok: #4ade80;
  --code-bg: #2a2a30;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 8px;
  --side-w: 270px;
  --right-w: 300px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  /* Colores del grafo */
  --g-node: #9ca3af;
  --g-note: #c4b5fd;
  --g-file: #67e8f9;
  --g-missing: #6b6b75;
  --g-link: rgba(160, 160, 175, .28);
  --g-focus: #f0abfc;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-2: #f6f6f8;
    --bg-3: #ececf0;
    --bg-hover: #e6e6ec;
    --border: #dedee5;
    --text: #1f1f24;
    --text-2: #55555f;
    --text-3: #696974;
    --accent: #7c3aed;
    --accent-2: #6d28d9;
    --accent-bg: rgba(124, 58, 237, .1);
    --code-bg: #f1f1f4;
    --shadow: 0 10px 30px rgba(0, 0, 0, .15);
    --g-note: #7c3aed;
    --g-file: #0891b2;
    --g-missing: #b5b5bf;
    --g-link: rgba(80, 80, 95, .25);
    --g-focus: #db2777;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
kbd {
  font: 12px var(--mono); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg-3);
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-3); cursor: pointer; text-decoration: none; color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--text-2);
  font-size: 17px; flex: none;
}
.icon:hover { background: var(--bg-hover); color: var(--text); }
.icon.active { color: var(--accent); }
.icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { background: none; border: 0; color: var(--text-3); cursor: pointer; padding: 0; font-size: 13px; }
.link:hover { color: var(--text); }
.chip {
  font-size: 11px; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text-2); cursor: pointer; margin-left: auto;
}

/* ---------- Layout ---------- */
#app { display: flex; height: 100%; height: 100dvh; }
#sidebar {
  width: var(--side-w); flex: none; display: flex; flex-direction: column;
  background: var(--bg-2); border-right: 1px solid var(--border); min-height: 0;
}
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#rightbar {
  width: var(--right-w); flex: none; background: var(--bg-2); border-left: 1px solid var(--border);
  overflow-y: auto; display: flex; flex-direction: column;
}
body.right-closed #rightbar { display: none; }

.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 8px; }
.brand { font-weight: 650; letter-spacing: .2px; flex: 1; }
.side-actions { display: flex; gap: 1px; padding: 0 8px 6px; }
.side-actions .icon { width: 29px; }
.search-box { padding: 4px 12px 8px; }
.search-box input, .graph-head input {
  width: 100%; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); outline: none;
}
.search-box input:focus, .graph-head input:focus, .modal input:focus { border-color: var(--accent); }
.side-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3);
}

/* ---------- Árbol de archivos ---------- */
.tree { flex: 1; overflow-y: auto; padding: 2px 6px 20px; min-height: 0; user-select: none; }
.tree.drop-root { background: var(--accent-bg); }
.t-row {
  display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 5px;
  cursor: pointer; color: var(--text-2); font-size: 14px; white-space: nowrap;
}
.t-row:hover { background: var(--bg-hover); color: var(--text); }
.t-row.active { background: var(--accent-bg); color: var(--text); }
.t-row.drop { outline: 1.5px dashed var(--accent); background: var(--accent-bg); }
.t-row .arrow { width: 14px; flex: none; text-align: center; font-size: 10px; color: var(--text-3); transition: transform .12s; }
.t-row.open .arrow { transform: rotate(90deg); }
.t-row .ico { width: 16px; flex: none; text-align: center; font-size: 13px; opacity: .8; }
.t-row .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.t-row .ext { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--bg-3); color: var(--text-3); text-transform: uppercase; }
.t-row .more { visibility: hidden; width: 22px; height: 22px; font-size: 14px; }
.t-row:hover .more, .t-row.active .more { visibility: visible; }
.t-children { margin-left: 10px; padding-left: 6px; border-left: 1px solid var(--border); }
.tree-empty { color: var(--text-3); font-size: 13px; padding: 14px 10px; }

.search-results { overflow-y: auto; max-height: 50%; padding: 0 8px 8px; border-bottom: 1px solid var(--border); }
.sr-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.sr-item:hover, .sr-item.sel { background: var(--bg-hover); }
.sr-item .p { font-size: 14px; }
.sr-item .d { font-size: 11px; color: var(--text-3); }
.sr-item .s { font-size: 12px; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sr-item mark { background: var(--accent-bg); color: var(--accent); border-radius: 2px; }

/* ---------- Barra superior ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 50px;
  border-bottom: 1px solid var(--border);
}
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow: hidden; color: var(--text-3); font-size: 14px; }
.crumbs span { white-space: nowrap; }
.crumbs .cur {
  color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; cursor: text;
  padding: 2px 4px; border-radius: 4px; outline: none;
}
.crumbs .cur:hover { background: var(--bg-hover); }
.crumbs .cur[contenteditable="true"] { background: var(--bg-3); box-shadow: 0 0 0 1.5px var(--accent); }
.save-state { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.save-state.err { color: var(--danger); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; flex: none; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-bg); color: var(--accent); }

/* ---------- Contenido ---------- */
#content { flex: 1; min-height: 0; position: relative; display: flex; }
.welcome { margin: auto; text-align: center; padding: 30px; max-width: 520px; color: var(--text-2); }
.welcome h1 { color: var(--text); margin: 16px 0 6px; font-size: 1.5em; }
.welcome-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 20px 0; }
.hint { font-size: 13px; color: var(--text-3); }
.hint code { font-family: var(--mono); background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }

.note-view { flex: 1; display: flex; min-width: 0; }
#editor {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: var(--bg);
  padding: 28px max(24px, calc((100% - 760px) / 2)); font: 15px/1.7 var(--mono); tab-size: 2;
}
#preview { flex: 1; min-width: 0; overflow-y: auto; padding: 28px max(24px, calc((100% - 760px) / 2)) 80px; }
.note-view.mode-edit #preview, .note-view.mode-read #editor { display: none; }
.note-view.mode-split #editor { border-right: 1px solid var(--border); padding: 28px 24px; }
.note-view.mode-split #preview { padding: 28px 24px 80px; }

/* ---------- Markdown ---------- */
.md { line-height: 1.7; word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.4em 0 .5em; }
.md h1 { font-size: 1.9em; }
.md h2 { font-size: 1.5em; }
.md h3 { font-size: 1.22em; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li > ul, .md li > ol { margin: 0; }
.md li:has(> input[type=checkbox]) { list-style: none; margin-left: -1.3em; }
.md input[type=checkbox] { accent-color: var(--accent); margin-right: 6px; cursor: pointer; }
.md blockquote { border-left: 1px solid var(--text-3); margin-left: 0; padding: 2px 0 2px 14px; color: var(--text-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 2px 5px; border-radius: 4px; }
.md pre { background: var(--code-bg); padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--bg-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.md img { max-width: 100%; border-radius: 6px; }
.md a.internal { color: var(--accent); text-decoration: none; cursor: pointer; }
.md a.internal:hover { text-decoration: underline; }
.md a.internal.missing { opacity: .6; text-decoration: underline dashed; }
.md a.external::after { content: " ↗"; font-size: .8em; opacity: .6; }
.md .tag {
  color: var(--accent); background: var(--accent-bg); padding: 1px 7px; border-radius: 99px;
  font-size: .88em; cursor: pointer; white-space: nowrap;
}
.md .embed-note { border: 1px solid var(--border); padding: 10px 16px; margin: 0 0 1em; background: var(--bg-2); border-radius: 8px; }
.md .embed-note .embed-title { font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.md iframe.embed-pdf { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 6px; }
.md video, .md audio { max-width: 100%; }

/* ---------- Preguntar a tus notas ---------- */
.ask-view { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ask-scroll { flex: 1; overflow-y: auto; scrollbar-width: thin; }
.ask-inner { max-width: 760px; margin: 0 auto; padding: 32px 24px 24px; }
.ask-empty { padding: 8vh 0 0; }
.ask-empty h1 { font-size: 1.6em; margin: 0 0 8px; letter-spacing: -.01em; }
.ask-empty p { color: var(--text-2); margin: 0 0 24px; max-width: 58ch; }
.ask-suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.ask-suggest button {
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text); border-radius: 10px; padding: 9px 14px;
  cursor: pointer; text-align: left; font-size: 14px; transition: background-color 160ms cubic-bezier(.23, 1, .32, 1), transform 160ms cubic-bezier(.23, 1, .32, 1);
}
.ask-suggest button:active, .ask-send:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) { .ask-suggest button:hover { background: var(--bg-hover); } }
.ask-turn + .ask-turn { margin-top: 28px; }
.ask-q { margin-left: auto; width: fit-content; max-width: 85%; background: var(--bg-3); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; }
.ask-a { margin-top: 16px; }
.ask-a.md > :last-child { margin-bottom: 0; }
.ask-status { color: var(--text-3); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.ask-a .caret { display: inline-block; width: 7px; height: 1.05em; vertical-align: -2px; margin-left: 2px; background: var(--accent); animation: pulse .7s infinite alternate; }
.ask-error { color: var(--danger); }
.ask-sources { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); }
.ask-sources .more { border-style: dashed; }
.ask-sources button {
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-2); border-radius: 99px; padding: 3px 10px; cursor: pointer; font-size: 12.5px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) { .ask-sources button:hover { color: var(--text); background: var(--bg-hover); } }
.ask-composer { padding: 10px 24px 14px; border-top: 1px solid var(--border); }
.ask-box {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 14px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-2);
}
.ask-box:focus-within { border-color: var(--accent); }
.ask-box textarea { flex: 1; resize: none; border: 0; outline: none; background: none; max-height: 200px; padding: 6px 0; line-height: 1.5; }
.ask-send { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent-2); color: #fff; cursor: pointer; display: grid; place-items: center; flex: none; transition: transform 160ms cubic-bezier(.23, 1, .32, 1), opacity 160ms; }
.ask-send:disabled { opacity: .45; cursor: default; }
.ask-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ask-send .i-stop { display: none; fill: currentColor; stroke: none; }
.ask-send.busy .i-send { display: none; }
.ask-send.busy .i-stop { display: block; }
.ask-hint { max-width: 760px; margin: 6px auto 0; font-size: 12px; color: var(--text-3); }
@media (max-width: 760px) {
  .ask-inner { padding: 20px 16px; }
  .ask-composer { padding: 8px 10px 10px; }
}
@media (prefers-reduced-motion: reduce) { .ask-a .caret { animation: none; } }

/* ---------- Visor de archivos ---------- */
.file-view { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 16px; overflow: auto; }
.file-view img, .file-view video { max-width: 100%; max-height: calc(100% - 70px); border-radius: 6px; }
.file-view iframe { width: 100%; flex: 1; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.file-view pre { align-self: stretch; flex: 1; margin: 0; overflow: auto; background: var(--code-bg); padding: 16px; border-radius: 6px; font: 13px/1.6 var(--mono); }
.file-card { text-align: center; color: var(--text-2); }
.file-card .big { font-size: 56px; }
.file-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- Panel derecho ---------- */
.panel { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin-bottom: 8px; }
.count { font-weight: 400; }
#localGraph { width: 100%; height: 260px; display: block; border-radius: 8px; background: #000; cursor: grab; touch-action: none; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.link-list li:hover { background: var(--bg-hover); }
.link-list li .ctx { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list li.missing { color: var(--text-3); font-style: italic; }
.link-list .empty { color: var(--text-3); font-size: 13px; cursor: default; }
.link-list .empty:hover { background: none; }

/* ---------- Vista de grafo «Brain» (siempre oscura) ---------- */
.brain {
  --b-bg: #000;
  --b-panel: rgba(10, 10, 16, .86);
  --b-line: rgba(255, 255, 255, .09);
  --b-line-2: rgba(255, 255, 255, .16);
  --b-text: #e9eaf3;
  --b-text-2: #a9acc0;
  --b-text-3: #7d8098;
  --b-accent: #39ff14;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  position: fixed; inset: 0; z-index: 40; background: var(--b-bg); color: var(--b-text);
  color-scheme: dark; font-size: 14px; overflow: hidden;
}
.brain ::selection { background: rgba(57, 255, 20, .3); color: #fff; }
.brain :focus-visible { outline: 2px solid var(--b-accent); outline-offset: 2px; border-radius: 6px; }
.brain .num { font-variant-numeric: tabular-nums; }
#bigGraph, #wavesCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#bigGraph { cursor: grab; }

.brain-bar {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3;
  display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 14px; flex-wrap: wrap;
  background: var(--b-panel); border: 1px solid var(--b-line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.brain-title { font-weight: 650; letter-spacing: .01em; }
.brain-search { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: 32px; border-radius: 8px; background: rgba(255, 255, 255, .05); border: 1px solid var(--b-line); }
.brain-search:focus-within { border-color: rgba(57, 255, 20, .55); }
.brain-search svg { width: 15px; height: 15px; flex: none; }
.brain-search input { width: 190px; border: 0; background: none; outline: none; color: var(--b-text); }
.brain-search input:focus-visible { outline: none; }
.brain-search input::placeholder { color: var(--b-text-3); }
.brain svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brain-seg { display: inline-flex; padding: 3px; border-radius: 9px; background: rgba(255, 255, 255, .05); border: 1px solid var(--b-line); }
.brain-seg button { border: 0; background: none; color: var(--b-text-2); height: 26px; padding: 0 12px; border-radius: 7px; cursor: pointer; font-size: 13px; transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out); }
.brain-seg button.on { background: rgba(255, 255, 255, .12); color: var(--b-text); }
.brain-status { color: var(--b-text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.brain-btn, .brain-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; border-radius: 8px;
  border: 1px solid var(--b-line); background: rgba(255, 255, 255, .04); color: var(--b-text); cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
.brain-btn { padding: 0 12px; font-size: 13px; }
.brain-icon { width: 32px; padding: 0; }
.brain-btn svg, .brain-icon svg { width: 17px; height: 17px; }
.brain-btn[aria-expanded="true"] { border-color: rgba(57, 255, 20, .5); background: rgba(57, 255, 20, .08); }
.brain-btn:active, .brain-icon:active, .brain-seg button:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) {
  .brain-btn:hover, .brain-icon:hover { background: rgba(255, 255, 255, .09); border-color: var(--b-line-2); }
  .brain-seg button:hover:not(.on) { color: var(--b-text); }
}
.brain-link { border: 0; background: none; color: var(--b-text-3); font-size: 12.5px; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.brain-link:hover { color: var(--b-text); }

/* Panel de filtros (sale de su botón) */
.brain-pop {
  position: absolute; top: 62px; right: 56px; z-index: 4; width: 280px; padding: 14px 16px 16px;
  background: rgba(12, 12, 19, .96); border: 1px solid var(--b-line-2); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .6);
  transform-origin: top right; transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.brain-pop.enter { opacity: 0; transform: scale(.97) translateY(-4px); }
.brain-pop section + section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--b-line); }
.brain-pop h2 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--b-text-2); display: flex; justify-content: space-between; }
.brain-pop input[type=range] { width: 100%; accent-color: var(--b-accent); }
.brain-pop .brain-link { margin-top: 14px; }
.brain-checks { display: grid; gap: 7px; }
.brain-checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--b-text); font-size: 13px; }
.brain-checks input { accent-color: var(--b-accent); margin: 0; }
.brain-checks .count { margin-left: auto; color: var(--b-text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.swatch { width: 18px; height: 0; border-top: 2px solid; flex: none; }
.swatch.dash { border-top-style: dashed; }
.swatch.dot { border-top-style: dotted; }
.shape { width: 10px; height: 10px; flex: none; border-radius: 50%; display: inline-block; }
.shape.dot { background: #e9eaf3; }
.shape.ring { border: 2px solid #e9eaf3; }
.shape.square { background: #96dcff; border-radius: 2px; width: 9px; height: 9px; }
.shape.hollow { border: 1.5px solid #787a8c; }
.shape.faint { background: rgba(233, 234, 243, .35); }
.shape.spin { border: 2px solid #e9eaf3; border-right-color: transparent; }

/* Leyenda de grupos */
.brain-legend {
  position: absolute; left: 12px; top: 76px; z-index: 2; width: 220px; max-height: calc(100% - 160px); overflow-y: auto;
  padding: 6px; background: var(--b-panel); border: 1px solid var(--b-line); border-radius: 12px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .15) transparent;
}
.brain-legend h2 { margin: 4px 8px 6px; font-size: 11.5px; font-weight: 600; color: var(--b-text-3); letter-spacing: .02em; }
.brain-legend button {
  display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: none; color: var(--b-text-2);
  padding: 6px 8px; border-radius: 7px; cursor: pointer; text-align: left; font-size: 13px;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.brain-legend button .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brain-legend button .count { color: var(--b-text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.brain-legend button i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.brain-legend button.on { background: rgba(255, 255, 255, .1); color: var(--b-text); }
.brain-legend.isolating button:not(.on) { opacity: .45; }
@media (hover: hover) and (pointer: fine) { .brain-legend button:hover { background: rgba(255, 255, 255, .06); color: var(--b-text); } }

/* Línea temporal */
.brain-timeline {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 2;
  width: min(620px, calc(100% - 520px)); min-width: 300px;
  display: flex; align-items: center; gap: 12px; padding: 7px 14px 7px 7px;
  background: var(--b-panel); border: 1px solid var(--b-line); border-radius: 12px;
}
.brain-timeline input[type=range] { flex: 1; accent-color: var(--b-accent); }
#timeLabel { color: var(--b-text-2); font-size: 12.5px; white-space: nowrap; min-width: 168px; text-align: right; }
#btnPlay .i-pause, #btnPlay.playing .i-play { display: none; }
#btnPlay.playing .i-pause { display: block; }
#btnPlay .i-play { fill: currentColor; stroke: none; }

.graph-stats { position: absolute; left: 16px; bottom: 18px; font-size: 12px; color: var(--b-text-3); pointer-events: none; line-height: 1.6; z-index: 1; }

/* Panel lateral de detalle */
.brain-panel {
  position: absolute; top: 76px; right: 12px; bottom: 76px; z-index: 3; width: 360px;
  display: flex; flex-direction: column; overflow: hidden;
  background: rgba(10, 10, 16, .92); border: 1px solid var(--b-line); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.brain-panel.enter { opacity: 0; transform: translateX(12px); }
.bp-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--b-line); }
.bp-kind { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--b-text-3); }
.bp-kind i { width: 8px; height: 8px; border-radius: 50%; }
.bp-close { margin-left: auto; width: 28px; height: 28px; }
.bp-title { margin: 6px 0 4px; font-size: 18px; line-height: 1.3; font-weight: 650; text-wrap: balance; }
.bp-meta { color: var(--b-text-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.bp-actions { display: flex; gap: 8px; margin-top: 12px; }
.bp-actions .primary { background: #e9eaf3; color: #0a0a10; border-color: #e9eaf3; font-weight: 600; }
@media (hover: hover) and (pointer: fine) { .bp-actions .primary:hover { background: #fff; border-color: #fff; } }
.bp-body { flex: 1; overflow-y: auto; padding: 4px 16px 16px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .15) transparent; }
.bp-body h3 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--b-text-2); display: flex; align-items: center; gap: 8px; }
.bp-body h3 .count { color: var(--b-text-3); font-weight: 400; font-variant-numeric: tabular-nums; }
.bp-excerpt { color: var(--b-text-2); font-size: 13px; line-height: 1.6; margin: 12px 0 0; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.bp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.bp-chip {
  border: 1px solid var(--b-line-2); background: rgba(255, 255, 255, .04); color: var(--b-text); border-radius: 99px;
  padding: 3px 10px; font-size: 12.5px; cursor: pointer; transition: background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.bp-chip:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) { .bp-chip:hover { background: rgba(255, 255, 255, .1); } }
.bp-conn { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bp-conn li { padding: 8px 10px; border-radius: 8px; cursor: pointer; transition: background-color 160ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .bp-conn li:hover { background: rgba(255, 255, 255, .06); } }
.bp-conn .who { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--b-text); }
.bp-conn .who .shape { width: 8px; height: 8px; }
.bp-conn .w { margin-left: auto; width: 44px; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .1); flex: none; overflow: hidden; }
.bp-conn .w b { display: block; height: 100%; background: var(--b-accent); border-radius: 2px; }
.bp-conn .why { margin: 3px 0 0 16px; color: var(--b-text-3); font-size: 12.5px; line-height: 1.5; }
.bp-empty { color: var(--b-text-3); font-size: 13px; margin: 14px 0; }

/* Tooltip de aristas */
.brain-tip {
  position: fixed; z-index: 6; max-width: 320px; pointer-events: none;
  padding: 9px 11px; border-radius: 10px; font-size: 12.5px; line-height: 1.5;
  background: rgba(14, 14, 22, .97); border: 1px solid var(--b-line-2); color: var(--b-text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .6);
}
.brain-tip .t { display: flex; align-items: center; gap: 7px; font-weight: 600; margin-bottom: 3px; }
.brain-tip .r { color: var(--b-text-2); }
.brain-tip .r + .r { margin-top: 2px; }
.brain-tip .f { color: var(--b-text-3); margin-top: 5px; font-variant-numeric: tabular-nums; }

.brain-intro { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; pointer-events: none; color: var(--b-text-3); text-align: center; padding: 24px; }

@media (max-width: 1100px) {
  .brain-timeline { width: calc(100% - 270px); left: auto; right: 12px; transform: none; }
  .brain-panel { width: 330px; }
}
@media (max-width: 760px) {
  .brain-bar { top: 8px; left: 8px; right: 8px; gap: 8px; padding: 6px; }
  .brain-title { display: none; }
  .brain-search { flex: 1; min-width: 120px; }
  .brain-search input { width: 100%; }
  .brain-bar .brain-btn span { display: none; }
  .brain-bar .brain-btn { width: 32px; padding: 0; }
  #btnGraphFit { display: none; }
  .brain-search { min-width: 0; }
  .brain-status { order: 9; width: 100%; padding-left: 4px; }
  .brain-pop { right: 8px; left: 8px; width: auto; top: 96px; }
  .brain-legend { top: auto; bottom: 64px; left: 8px; right: 8px; width: auto; max-height: none; display: flex; overflow-x: auto; overflow-y: hidden; gap: 2px; padding: 4px; }
  .brain-legend h2 { display: none; }
  .brain-legend button { width: auto; white-space: nowrap; flex: none; }
  .brain-legend button .name { overflow: visible; }
  .brain-timeline { left: 8px; right: 8px; bottom: 8px; width: auto; min-width: 0; transform: none; }
  #timeLabel { min-width: 0; font-size: 12px; }
  .brain-panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 62%; border-radius: 16px 16px 0 0; }
  .brain-panel.enter { transform: translateY(16px); }
  .graph-stats { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .brain *, .brain *::before { transition-duration: 0ms !important; }
}

/* ---------- Popups ---------- */
.suggest, .menu {
  position: fixed; z-index: 60; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; min-width: 200px; max-width: 360px;
}
.suggest { max-height: 280px; overflow-y: auto; }
.suggest .it, .menu button {
  display: block; width: 100%; text-align: left; padding: 6px 10px; border-radius: 5px; border: 0;
  background: none; cursor: pointer; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.suggest .it .d { color: var(--text-3); font-size: 12px; margin-left: 6px; }
.suggest .it.sel, .suggest .it:hover, .menu button:hover { background: var(--bg-hover); }
.suggest .it.new { color: var(--accent); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.modal-back { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; width: min(440px, 100%); }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
.modal input { width: 100%; padding: 9px 11px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); outline: none; margin-bottom: 14px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.dropzone { position: fixed; inset: 0; z-index: 80; background: rgba(139, 92, 246, .15); border: 3px dashed var(--accent); display: grid; place-items: center; pointer-events: none; }
.dropzone div { background: var(--bg-2); padding: 16px 24px; border-radius: 10px; font-size: 18px; box-shadow: var(--shadow); }
.uploads { position: fixed; right: 16px; bottom: 16px; z-index: 65; width: min(340px, calc(100% - 32px)); background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 12px; font-size: 13px; }
.uploads .up { margin-bottom: 8px; }
.uploads .up:last-child { margin-bottom: 0; }
.uploads .bar { height: 5px; border-radius: 3px; background: var(--bg-3); overflow: hidden; margin-top: 4px; }
.uploads .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.uploads .up.err { color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; background: var(--bg-3); border: 1px solid var(--border); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100% - 32px); }
.toast.err { border-color: var(--danger); color: var(--danger); }
.scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, .45); }

/* Propiedades (frontmatter) */
.md table.props { display: table; width: 100%; font-size: 13px; margin-bottom: 1.4em; border-collapse: collapse; }
.md table.props th, .md table.props td { border: 0; border-bottom: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top; }
.md table.props th { background: none; color: var(--text-3); font-weight: 500; width: 110px; white-space: nowrap; }

/* ---------- IA ---------- */
.side-foot { flex-wrap: wrap; }
.ai-pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text-2); border-radius: 99px; padding: 2px 9px; font-size: 12px; cursor: pointer;
}
.ai-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.ai-pill.ok::before { background: #2fd40f; }
.ai-pill.busy::before { background: #e6d400; animation: pulse 1s infinite alternate; }
.ai-pill.err::before { background: var(--danger); }
@keyframes pulse { from { opacity: .4; } to { opacity: 1; } }
.ai-info { font-size: 13px; color: var(--text-2); margin: 0 0 12px; line-height: 1.7; }
.ai-info b { color: var(--text); font-weight: 600; }
.ai-info .bad { color: var(--danger); }
.ai-info .good { color: var(--ok); }
.rec-time { font: 600 42px/1 var(--mono); text-align: center; margin: 10px 0 14px; letter-spacing: 1px; }
.rec-time.on { color: #ff3355; }
.rec-level { width: 100%; height: 48px; display: block; margin-bottom: 14px; border-radius: 8px; background: #000; }
.quick-text { width: 100%; min-height: 160px; resize: vertical; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); outline: none; margin-bottom: 12px; font: 15px/1.6 var(--font); }
.quick-text:focus { border-color: var(--accent); }
.link-list li .score { float: right; font-size: 11px; color: var(--text-3); }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100%; overflow: auto; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(139, 92, 246, .18), transparent), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo h1 { font-size: 22px; margin: 12px 0 4px; }
.login-logo p { margin: 0; color: var(--text-3); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 8px; }
.login-card label { font-size: 13px; color: var(--text-2); }
.login-card input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; padding: 10px; margin-top: 6px; }
.btn.google { background: #fff; color: #1f1f1f; border-color: #dadce0; font-weight: 500; }
.btn.google:hover { background: #f4f4f6; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 13px; margin: 16px 0 10px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-error { background: rgba(248, 113, 113, .12); border: 1px solid var(--danger); color: var(--danger); padding: 9px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }

/* ---------- Responsive ---------- */
.only-mobile { display: none; }
@media (max-width: 1100px) {
  #rightbar { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow); }
  .hide-narrow { display: none; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .only-mobile { display: inline-grid; }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; width: min(85vw, 320px);
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.side-open #sidebar { transform: none; }
  #rightbar { width: min(90vw, 340px); }
  #topbar { padding: 6px 8px; gap: 4px; }
  #editor, #preview { padding: 18px 16px 80px; }
  #editor { font-size: 15px; }
  .t-row { padding: 7px 6px; font-size: 15px; }
  .t-row .more { visibility: visible; }

  .save-state { display: none; }
}
