/* ═══════════════════════════════════════════════════════════════════════════
   Wiki — grafo de conocimiento (wiki.html) + páginas (dist/wiki/*.html)
   Reusa los tokens de styles.css. Estética coherente con el árbol.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Los filtros por rama viven ahora en el command palette (⌘K), solo en la wiki.
   El zoom es por scroll/pinch (los botones se retiraron); la barra superior se
   eliminó para ganar espacio. */

/* ── Lienzo del grafo ─────────────────────────────────────────────────────── */
.wiki-graph-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 22px 22px;
  overflow: hidden;
}
.wiki-graph { position: absolute; inset: 0; }
.wiki-graph-svg { display: block; cursor: grab; }
.wiki-graph-svg:active { cursor: grabbing; }
.wiki-graph-empty {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Inter', sans-serif; color: var(--muted);
}

/* Aristas */
.wiki-graph-link {
  stroke: var(--border);
  stroke-width: 0.8px;
  opacity: 0.65;
  transition: opacity .2s, stroke .2s;
}
.wiki-graph-link.is-dim { opacity: 0.07; }
/* Aristas de parentesco (backbone familiar): más tenues y punteadas que los enlaces temáticos */
.wiki-graph-link--familia { stroke-dasharray: 4 4; opacity: 0.28; }
.wiki-graph-link--familia.is-dim { opacity: 0.06; }
/* Aristas hacia un tag: tenues y con el color del tag, para que los hubs «tiren» sin saturar */
.wiki-graph-link--tag { stroke: #64748b; opacity: 0.32; }
.wiki-graph-link--tag.is-dim { opacity: 0.06; }
.wiki-graph-link.is-filtered-out { display: none; }

/* Nodos */
.wiki-graph-node { cursor: pointer; }
.wiki-graph-dot {
  stroke: var(--surface);
  stroke-width: 2px;
  transition: opacity .2s, transform .12s;
}
.wiki-graph-dot--persona { stroke-width: 1.5px; }
.wiki-graph-node.is-dim { opacity: 0.22; }
.wiki-graph-node.is-focus .wiki-graph-dot { stroke: var(--text); stroke-width: 2.5px; }
.wiki-graph-node.is-filtered-out { display: none; }
.wiki-graph-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
/* Nombres ocultos por defecto (disco limpio); aparecen al acercar el zoom… */
.wiki-graph-svg.is-zoomed-in .wiki-graph-label { opacity: 1; }
/* …o sobre el nodo en foco y sus vecinos al hacer hover/seleccionar */
.wiki-graph-node.is-focus .wiki-graph-label { opacity: 1; }
.wiki-graph-svg:has(.wiki-graph-node.is-focus) .wiki-graph-node:not(.is-dim) .wiki-graph-label { opacity: 1; }
.wiki-graph-node.is-dim .wiki-graph-label { opacity: 0.3; }

/* ── Leyenda ──────────────────────────────────────────────────────────────── */
.wiki-legend {
  position: absolute;
  bottom: 14px;
  left: 14px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(4px);
}
.wiki-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--muted);
}
.wiki-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ── Card de métricas del grafo (bajo el zoom; runtime desde wiki-graph.json) ─ */
.wiki-stats-card {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 158px;
  z-index: 3;
  padding: 10px 12px 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(4px);
  font-family: var(--mono, 'IBM Plex Mono', monospace);
}
.wiki-stats-kicker {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 7px;
}
.wiki-stats-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 10.5px;
  color: var(--muted);
  padding: 2.5px 0;
}
.wiki-stats-row b {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.wiki-stats-bar {
  height: 3px;
  margin: 4px 0 2px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.wiki-stats-bar span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
}

/* ── Panel lateral (al seleccionar un nodo) ───────────────────────────────── */
.wiki-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  bottom: 14px;
  width: 300px;
  z-index: 1001;   /* por encima del modal de lectura (1000): queda usable al costado */
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.12);
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .28s;
  pointer-events: none;
}
.wiki-panel.is-open { transform: translateX(0); opacity: 1; pointer-events: auto; }
/* Misma cruz que el panel del árbol (.tree-panel-close): sin caja, solo el ícono centrado */
.wiki-panel-close {
  position: absolute; top: 18px; right: 18px; z-index: 10;
  background: none; border: none; padding: 4px;
  color: var(--muted); cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s;
}
.wiki-panel-close:hover { color: var(--text); }
.wiki-panel-body { overflow-y: auto; padding: 20px; }

.wiki-panel-head { margin-bottom: 18px; padding-right: 28px; }
.wiki-panel-type, .wiki-panel-type--persona {
  display: inline-block;
  font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; color: #fff; background: var(--accent);
  margin-bottom: 10px;
}
.wiki-panel-type--persona { background: #1e40af; }
.wiki-panel-type--lugar   { background: #4a7c59; }
.wiki-panel-type--fuente  { background: #854d0e; }
.wiki-panel-type--evento  { background: #8f4632; }
.wiki-panel-type--post    { background: #3f5e6b; }
.wiki-panel-type--tag     { background: #64748b; }
.wiki-panel-title {
  font-family: 'Source Serif 4', serif; font-size: 1.3rem; font-weight: 600;
  line-height: 1.2; margin: 0 0 8px; color: var(--text);
}
.wiki-panel-summary {
  font-family: 'Source Serif 4', serif; font-size: 0.9rem; line-height: 1.5;
  color: var(--muted); margin: 0;
}
.wiki-panel-group { margin-bottom: 18px; }
.wiki-panel-group-title {
  font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text);
  margin: 0 0 9px;
}
.wiki-panel-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.wiki-panel-btn {
  display: block; text-align: center; font-family: 'Inter', sans-serif;
  font-size: 13px; font-weight: 600; padding: 9px 14px; border-radius: 9px;
  cursor: pointer; text-decoration: none; border: 1px solid var(--border);
  transition: background .15s, border-color .15s, color .15s;
}
.wiki-panel-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.wiki-panel-btn--primary:hover { filter: brightness(1.08); }
.wiki-panel-btn--ghost { background: var(--bg); color: var(--text); }
.wiki-panel-btn--ghost:hover { border-color: var(--accent); }

/* Chips clickeables del panel (botones). Solo heredamos la familia, no el tamaño:
   `font: inherit` pisaba el font-size del chip y lo agrandaba al del body. */
.wiki-chips button.wiki-chip { font-family: inherit; }
button.wiki-chip { background: var(--bg); }
.wiki-chip--out { opacity: 0.7; }

/* En el panel lateral los chips van compactos y subordinados al título del grupo */
.wiki-panel .wiki-chips { gap: 5px; }
.wiki-panel .wiki-chip {
  font-size: 14px;
  font-weight: 400;
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--muted);
}
.wiki-panel .wiki-chip:hover { color: var(--text); border-color: var(--accent); }
.wiki-panel .wiki-chip--persona { color: #1e40af; }
[data-theme="dark"] .wiki-panel .wiki-chip--persona { color: #93b4ff; }

/* ═══════════════════════════════════════════════════════════════════════════
   Páginas wiki (dist/wiki/*.html)
   ═══════════════════════════════════════════════════════════════════════════ */
.wiki-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}
.wiki-page-header { margin: 18px 0 28px; }
.wiki-type-badge {
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  margin-bottom: 14px;
}
.wiki-type-badge--lugar   { background: #4a7c59; }
.wiki-type-badge--fuente  { background: #854d0e; }
.wiki-type-badge--evento  { background: #8f4632; }
.wiki-type-badge--persona { background: #1e40af; }
.wiki-type-badge--tema    { background: var(--accent); }
.wiki-type-badge--post    { background: #3f5e6b; }
.wiki-type-badge--tag     { background: #64748b; }
.wiki-page-title {
  font-family: 'Source Serif 4', serif;
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 12px;
  color: var(--text);
}
.wiki-page-summary {
  font-family: 'Source Serif 4', serif;
  font-size: 1.12rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}
.wiki-page-content {
  font-family: 'Source Serif 4', serif;
  font-size: 1.07rem;
  line-height: 1.75;
  color: var(--text);
}
/* Lede: el primer párrafo abre como entradilla editorial */
.wiki-page-content > p:first-of-type {
  font-size: 1.2rem;
  line-height: 1.6;
  color: var(--muted);
}
.wiki-page-content > p:first-of-type strong { color: var(--text); }
/* h2 con marcador de acento + kicker mono, da ritmo de sección estilo wiki */
.wiki-page-content h2 {
  font-family: 'Hanken Grotesk', sans-serif;
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 44px 0 14px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  color: var(--text);
}
.wiki-page-content h2::before {
  content: "";
  display: block;
  width: 26px;
  height: 3px;
  margin-bottom: 12px;
  border-radius: 2px;
  background: var(--accent);
}
.wiki-page-content h3 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 28px 0 10px;
}
.wiki-page-content p { margin: 0 0 18px; }
.wiki-page-content ul, .wiki-page-content ol { margin: 0 0 18px; padding-left: 1.3em; }
.wiki-page-content li { margin-bottom: 6px; }
.wiki-page-content li::marker { color: var(--accent); }
.wiki-page-content strong { font-weight: 700; }
.wiki-page-content mark {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: inherit;
  padding: 0 3px;
  border-radius: 3px;
}

/* Enlaces wiki dentro del cuerpo */
.wiki-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 2px;
  padding: 0 1px;
  transition: background .15s, border-color .15s;
}
.wiki-link:hover {
  border-bottom-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.wiki-link--persona { color: #1e40af; border-bottom-color: rgba(30,64,175,0.35); }
[data-theme="dark"] .wiki-link--persona { color: #93b4ff; border-bottom-color: rgba(147,180,255,0.4); }
.wiki-link--missing {
  color: var(--muted);
  border-bottom: 1px dashed var(--muted);
  cursor: help;
}

/* Relacionados (enlaces salientes + backlinks) */
.wiki-related { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); }
.wiki-related-group { margin-bottom: 22px; }
.wiki-related-title {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
.wiki-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.wiki-chip {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.wiki-chip:hover { border-color: var(--accent); background: var(--surface); }
.wiki-chip--persona { color: #1e40af; }
[data-theme="dark"] .wiki-chip--persona { color: #93b4ff; }
.wiki-chip--post { color: #3f5e6b; }
[data-theme="dark"] .wiki-chip--post { color: #8fb3c4; }
.wiki-chip--tag {
  color: #64748b;
  background: color-mix(in srgb, #64748b 8%, transparent);
  border-color: color-mix(in srgb, #64748b 25%, transparent);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Modal de lectura (markdown renderizado sobre el grafo)
   ═══════════════════════════════════════════════════════════════════════════ */
.wiki-modal {
  /* Backdrop uniforme en toda la pantalla (sin costura). La tarjeta se ancla a la
     izquierda vía padding: izquierda 40px = gap a #wikiPanel (panel 300 + margen 14 +
     40 de aire = 354 a la derecha). El panel se eleva por encima (z-index abajo). */
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: flex-start;
  padding: 34px 354px 34px 40px;
  background: rgba(0,0,0,0.40);
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.wiki-modal.is-open { opacity: 1; visibility: visible; }
[data-theme="dark"] .wiki-modal { background: rgba(0,0,0,0.6); }
.wiki-modal-card {
  position: relative;
  width: 100%; max-width: none; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.30);
  transform: translateY(12px) scale(.985);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}
.wiki-modal.is-open .wiki-modal-card { transform: none; }
.wiki-modal-close {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--muted); cursor: pointer;
}
.wiki-modal-close:hover { color: var(--text); }
.wiki-modal-body { overflow-y: auto; padding: 48px 56px 56px; }
.wiki-modal-loading { font-family: 'Inter', sans-serif; color: var(--muted); }
.wiki-modal-title {
  font-family: 'Source Serif 4', serif; font-size: 2rem; font-weight: 700;
  line-height: 1.15; margin: 12px 0 10px; color: var(--text);
}
.wiki-modal-summary {
  font-family: 'Source Serif 4', serif; font-size: 1.1rem; font-style: italic;
  line-height: 1.5; color: var(--muted); margin: 0 0 8px;
}
.wiki-modal-body > .wiki-page-content { margin-top: 24px; }

/* Tipografía del contenido (modal y páginas comparten .wiki-page-content) */
.wiki-page-content blockquote {
  margin: 28px 0; padding: 6px 0 6px 26px;
  border-left: 3px solid var(--accent);
  font-family: 'Source Serif 4', serif;
  font-size: 1.15rem; font-style: italic;
  line-height: 1.6; color: var(--text);
}
.wiki-page-content blockquote p:last-child { margin-bottom: 0; }
.wiki-page-content hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
.wiki-page-content .table-wrapper {
  overflow-x: auto; margin: 24px 0;
  border: 1px solid var(--border); border-radius: 10px;
}
.wiki-page-content table {
  width: 100%; border-collapse: collapse;
  font-family: 'IBM Plex Sans', sans-serif; font-size: 0.9rem;
}
.wiki-page-content th, .wiki-page-content td {
  text-align: left; padding: 9px 14px;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.wiki-page-content tbody tr:last-child td { border-bottom: none; }
.wiki-page-content tbody tr:nth-child(even) { background: color-mix(in srgb, var(--muted) 5%, transparent); }
.wiki-page-content tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.wiki-page-content thead th {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600; color: var(--muted);
  font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase;
  background: color-mix(in srgb, var(--muted) 6%, transparent);
  border-bottom: 1px solid var(--border);
}
.wiki-page-content code {
  font-family: 'JetBrains Mono', monospace; font-size: 0.85em;
  background: var(--bg); padding: 1px 5px; border-radius: 4px;
}

/* Figuras (imágenes con pie + lightbox) */
.wiki-page-content .wiki-figure { margin: 30px 0; }
.wiki-page-content .wiki-figure img {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: zoom-in;
}
.wiki-page-content .wiki-figure figcaption {
  margin-top: 9px; text-align: center;
  font-family: 'IBM Plex Sans', sans-serif; font-size: 0.82rem;
  line-height: 1.45; color: var(--muted);
}
/* Galería «Documentos» (media de arbol.json, generada en build-wiki.js) */
.wiki-page-content .wiki-docs-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin: 20px 0 28px;
}
.wiki-page-content .wiki-docs-grid .wiki-figure { margin: 0; }
.wiki-page-content .wiki-docs-grid .wiki-figure figcaption {
  text-align: left; font-size: 0.75rem; margin-top: 6px;
}
.wiki-page-content .wiki-doc-file { margin: 6px 0; }
.wiki-page-content .wiki-doc-file a { font-family: 'IBM Plex Sans', sans-serif; font-size: 0.9rem; }
.wiki-page-content .wiki-pending {
  font-style: italic; color: var(--muted);
}

/* Diagramas Mermaid */
.wiki-page-content .mermaid {
  margin: 30px 0; text-align: center; overflow-x: auto;
}
.wiki-page-content .mermaid svg { max-width: 100%; height: auto; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .wiki-panel { left: 10px; right: 10px; width: auto; top: auto; bottom: 10px; max-height: 55%;
    transform: translateY(calc(100% + 24px)); z-index: 40; }  /* bajo el modal full-screen */
  .wiki-panel.is-open { transform: translateY(0); }
  .wiki-legend { display: none; }
  .wiki-stats-card { display: none; }
  .wiki-modal { padding: 0; }
  .wiki-modal-card { max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .wiki-modal-body { padding: 28px 22px 48px; }
  .wiki-modal-title { font-size: 1.6rem; }
  .wiki-page { padding: 20px 18px 60px; }
  .wiki-page-title { font-size: 1.7rem; }
}
