/* Pantalla 32: base de conocimiento en Markdown (16-oct-2026). Solo tokens. Prefijo propio `kb-`.
   El editor Live Preview (CodeMirror 6, /vendor/live-editor.js) usa las clases cm-* de webbrain, aquí contra tokens. */

/* ---------- Distribución: árbol de carpetas | lista o nota ---------- */
.kb-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.kb-arbol { padding: 10px; position: sticky; top: calc(var(--topbar-h) + 12px); max-height: calc(100vh - var(--topbar-h) - 24px); overflow-y: auto; }
.kb-arbol-toggle { display: none; }
.kb-arbol-cuerpo { display: grid; gap: 4px; }
.kb-arbol-cuerpo .search-box, .kb-arbol-cuerpo .buscador { margin-bottom: 6px; }
.kb-arbol-cab { display: flex; align-items: center; justify-content: space-between; margin: 8px 4px 2px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.kb-grupo { display: grid; gap: 2px; }
.kb-nodo-fila { display: flex; align-items: center; gap: 2px; min-width: 0; }
.kb-nodo-fila .kebab { flex: none; opacity: .65; }
.kb-nodo-fila:hover .kebab, .kb-nodo-fila .kebab:focus-visible { opacity: 1; }
.kb-expandir { flex: none; width: 24px; height: 30px; border: 0; background: none; color: var(--ink-3); cursor: pointer; border-radius: var(--radius-sm); }
.kb-expandir.vacio { visibility: hidden; }
.kb-expandir:hover:not(:disabled) { background: var(--sunken); color: var(--ink-1); }
.kb-nodo { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; min-height: 34px; padding: 6px 8px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink-2); font: 500 13.5px var(--font-ui); text-align: left; cursor: pointer; }
.kb-nodo i { color: var(--ink-3); width: 16px; text-align: center; }
.kb-nodo:hover { background: var(--sunken); color: var(--ink-1); }
.kb-nodo[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.kb-nodo[aria-pressed="true"] i { color: var(--accent); }
.kb-nodo-nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-cuenta { flex: none; font-size: 11.5px; color: var(--ink-3); background: var(--sunken); border-radius: 999px; padding: 1px 7px; }
.kb-subcarpetas { display: grid; gap: 2px; margin-left: 26px; padding-left: 6px; border-left: 1px solid var(--border); }

/* ---------- Lista de notas ---------- */
.kb-principal { padding: 18px 20px; min-width: 0; }
.kb-lista-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.kb-lista-cab h2 { font: 700 1.15rem var(--font-brand); margin: 0; }
.kb-fila { cursor: pointer; }
.kb-fila .who { min-width: 0; }
.kb-extracto { margin-top: 3px; font-size: 12.5px; color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- Nota ---------- */
.kb-nota-cab { display: grid; gap: 4px; margin-bottom: 12px; }
.kb-nota-cab-linea { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kb-nota-acciones { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.kb-subiendo { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.kb-ruta { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.kb-titulo { font: 800 1.5rem/1.25 var(--font-brand); margin: 2px 0 0; color: var(--ink-1); overflow-wrap: anywhere; }
.kb-titulo-input { font: 700 1.25rem var(--font-brand); height: auto; padding: 8px 12px; }
.kb-nota-meta { font-size: 12.5px; }
.kb-error { margin-bottom: 12px; }
.kb-ayuda { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; }
.kb-ayuda code { font-family: var(--font-mono); background: var(--sunken); border-radius: 4px; padding: 0 4px; }
.kb-cargando { padding: 8px 0; }

/* Historial */
.kb-historial { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--sunken); padding: 10px 12px; display: grid; gap: 6px; }
.kb-historial-cab { display: flex; align-items: center; justify-content: space-between; }
.kb-version { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--card); font-size: 13px; }

/* ---------- Editor / visor (CodeMirror 6) ---------- */
.kb-editor { min-height: 220px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.kb-editor:focus-within:not(.kb-editor-lectura) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.kb-editor-lectura { border-color: transparent; background: none; }
.kb-editor .cm-editor { color: var(--ink-1); background: none; }
.kb-editor .cm-editor.cm-focused { outline: none; }
.kb-editor .cm-scroller { font-family: var(--font-ui); font-size: 15px; line-height: 1.7; overflow: visible; }
.kb-editor .cm-content { padding: 18px 20px 28px; caret-color: var(--accent); overflow-wrap: anywhere; min-height: 200px; }
.kb-editor-lectura .cm-content { padding: 4px 0 20px; }
.kb-editor .cm-line { padding: 0; }
.kb-editor .cm-selectionBackground, .kb-editor .cm-focused .cm-selectionBackground, .kb-editor ::selection { background: var(--accent-soft) !important; }
.kb-editor .cm-cursor { border-left-color: var(--accent); }

.kb-editor .cm-syntax { color: var(--ink-3); font-weight: 400; }
.kb-editor .cm-line.cm-h { font-family: var(--font-brand); font-weight: 700; line-height: 1.3; padding-top: .7em; padding-bottom: .25em; }
.kb-editor .cm-line.cm-h1 { font-size: 1.7em; font-weight: 800; }
.kb-editor .cm-line.cm-h2 { font-size: 1.35em; border-bottom: 1px solid var(--border); }
.kb-editor .cm-line.cm-h3 { font-size: 1.15em; }
.kb-editor .cm-line.cm-h4, .kb-editor .cm-line.cm-h5 { font-size: 1em; color: var(--ink-2); }
.kb-editor .cm-line.cm-h6 { font-size: .85em; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.kb-editor .cm-strong { font-weight: 700; }
.kb-editor .cm-em { font-style: italic; }
.kb-editor .cm-strike { text-decoration: line-through; color: var(--ink-3); }
.kb-editor .cm-highlight { background: var(--warning-soft); color: var(--ink-1); border-radius: 4px; }
.kb-editor .cm-inline-code { font-family: var(--font-mono); font-size: .88em; background: var(--sunken); color: var(--accent-strong); padding: .12em .4em; border-radius: 6px; }
.kb-editor .cm-wikilink, .kb-editor .cm-embed-ref { color: var(--accent-strong); font-weight: 500; background: var(--accent-soft); border-radius: 6px; padding: 0 4px; cursor: pointer; }
.kb-editor .cm-embed-ref { border: 1px dashed var(--accent); }
.kb-editor .cm-wikilink-src { color: var(--accent); }
.kb-editor .cm-link { color: var(--info); text-decoration: underline; text-underline-offset: 3px; }
.kb-editor .cm-link[data-href] { cursor: pointer; }
.kb-editor .cm-url { color: var(--ink-3); }
.kb-editor .cm-tag { color: var(--info); background: var(--info-soft); border-radius: 999px; padding: 1px 7px; font-size: .85em; font-weight: 600; }
.kb-editor .cm-bullet, .kb-editor .cm-list-num { color: var(--ink-3); }
.kb-editor .cm-line.cm-task-done { color: var(--ink-3); text-decoration: line-through; }
.kb-editor .cm-task-checkbox { appearance: none; -webkit-appearance: none; display: inline-grid; place-content: center; width: 18px; height: 18px; margin: 0 8px 0 0; vertical-align: -4px;
  border: 2px solid var(--border-strong); border-radius: 5px; background: var(--card); cursor: pointer; }
.kb-editor .cm-task-checkbox:checked { background: var(--success); border-color: var(--success); }
.kb-editor .cm-task-checkbox:checked::before { content: ''; width: 9px; height: 9px; background: var(--card); clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%); }
.kb-editor .cm-task-checkbox:disabled { cursor: default; }
.kb-editor .cm-line.cm-quote { padding-left: 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); color: var(--ink-2); }
.kb-editor .cm-line.cm-codeblock { font-family: var(--font-mono); font-size: .86em; padding: 0 16px; background: var(--sunken); color: var(--ink-1); }
.kb-editor .cm-line.cm-codeblock-first { padding-top: 8px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; position: relative; }
.kb-editor .cm-line.cm-codeblock-last { padding-bottom: 8px; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.kb-editor .cm-line.cm-codeblock-first.cm-codeblock-last { border-radius: var(--radius-sm); }
.kb-editor .cm-code-info { color: var(--ink-3); }
.kb-editor .cm-hr { display: inline-block; width: 100%; height: 1px; vertical-align: middle; background: var(--border-strong); }
.kb-editor .cm-line.cm-frontmatter { font-family: var(--font-mono); font-size: .82em; padding: 0 12px; background: var(--sunken); color: var(--ink-2); }
.kb-editor .cm-line.cm-table-line { font-family: var(--font-mono); font-size: .84em; white-space: pre-wrap; }
.kb-editor .cm-image { display: inline-block; max-width: 100%; }
.kb-editor .cm-image img { display: block; max-width: 100%; border-radius: var(--radius-sm); margin: .4em 0; box-shadow: var(--shadow); }

/* Botón de copiar (en `código` y en bloques de código) */
.kb-editor .cm-copy { display: inline-grid; place-items: center; width: 24px; height: 22px; margin-left: 3px; vertical-align: -3px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card); color: var(--ink-3); font-size: 11px; cursor: pointer; line-height: 1; }
.kb-editor .cm-copy:hover { color: var(--accent); border-color: var(--accent); }
.kb-editor .cm-copy.cm-copy-ok { color: var(--success); border-color: var(--success); }
.kb-editor .cm-copy.cm-copy-block { position: absolute; top: 6px; right: 8px; width: 28px; height: 26px; margin: 0; z-index: 1; }
@media (pointer: coarse) {
  .kb-editor .cm-copy { width: 32px; height: 30px; vertical-align: -8px; }
  .kb-editor .cm-copy.cm-copy-block { width: 36px; height: 34px; }
}

/* ---------- Teléfono ---------- */
@media (max-width: 760px) {
  .kb-layout { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .kb-arbol { position: static; max-height: none; padding: 6px; }
  .kb-arbol-toggle { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 8px 10px; border: 0; background: none; color: var(--ink-1); font: 600 14px var(--font-ui); cursor: pointer; }
  .kb-arbol-toggle span { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kb-arbol-cuerpo { display: none; padding: 4px; }
  .kb-arbol.abierto .kb-arbol-cuerpo { display: grid; }
  .kb-nodo { min-height: 44px; }
  .kb-principal { padding: 14px 12px; }
  .kb-titulo { font-size: 1.3rem; }
  .kb-editor .cm-content { padding: 14px 12px 24px; }
}
