/* ── Área de trabajo: paneles, pestañas y vistas ─────────────── */
.panes { flex: 1; display: flex; min-height: 0; }
.pane { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-divisor { flex: none; width: 1px; background: var(--border); position: relative; cursor: col-resize; }
.pane-divisor::after { content: ""; position: absolute; inset: 0 -3px; z-index: 2; transition: background .15s; }
.pane-divisor:hover::after { background: color-mix(in srgb, var(--accent) 55%, transparent); }

.tabbar {
  display: flex; align-items: stretch; gap: 4px; flex: none;
  height: var(--tabbar-h); padding: 0 6px 0 6px;
  background: var(--bg-side); border-bottom: 1px solid var(--border);
}
.tabbar.is-drop { box-shadow: inset 0 -2px 0 var(--accent); }
.tabs { flex: 1; display: flex; align-items: flex-end; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabbar-tools { display: flex; align-items: center; gap: 2px; }

.tab {
  position: relative; flex: 0 1 200px; min-width: 90px;
  display: flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 6px 0 10px;
  border-radius: 7px 7px 0 0;
  color: var(--muted); font-size: 13px; cursor: default; user-select: none;
  transition: background .12s, color .12s;
}
.tab:hover { background: var(--bg-hover); color: var(--text-2); }
.tab.is-active { background: var(--bg); color: var(--text); box-shadow: 0 1px 0 var(--bg), 0 0 0 1px var(--border); clip-path: inset(-1px -1px 0 -1px); }
.pane.is-active .tab.is-active .tab-titulo { font-weight: 500; }
/* Franja arriba de la pestaña activa: del color de acento en el panel activo */
.tab.is-active::before {
  content: ""; position: absolute; top: 0; left: 8px; right: 8px; height: 2px; border-radius: 0 0 2px 2px;
  background: var(--border-strong); transition: background .15s;
}
.pane.is-active .tab.is-active::before { background: var(--accent); }
.panes.dividido .pane:not(.is-active) .tab.is-active { color: var(--text-2); }
.tab svg.icon { width: 15px; height: 15px; opacity: .7; }
.tab-titulo { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tab-punto { display: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.tab.is-sucia .tab-punto { display: block; }
.tab.is-error .tab-punto { background: var(--danger); }
.tab-cerrar {
  display: grid; place-items: center; flex: none;
  width: 20px; height: 20px; padding: 0; border: 0; border-radius: 4px;
  background: none; color: var(--muted); opacity: 0;
}
.tab:hover .tab-cerrar, .tab.is-active .tab-cerrar { opacity: 1; }
.tab.is-sucia:not(:hover) .tab-cerrar { display: none; }
.tab-cerrar:hover { background: var(--bg-active); color: var(--text); }
.tab-cerrar svg.icon { width: 14px; height: 14px; opacity: 1; }

.pane-body { flex: 1; position: relative; min-height: 0; display: flex; flex-direction: column; }
.pane-vacio { flex: 1; display: grid; place-content: center; text-align: center; padding: 24px; }
.pane-vacio[hidden] { display: none; }
.pane-vacio-icono {
  display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 18px;
  border-radius: 20px; background: var(--accent-soft); color: var(--accent-text);
}
.pane-vacio-icono svg.icon { width: 34px; height: 34px; stroke-width: 1.5; }
.pane-vacio h2 { margin: 0 0 6px; font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -.01em; }
.pane-vacio > p { margin: 0 0 22px; color: var(--muted); }
.empty-actions { list-style: none; margin: 0 auto; padding: 0; display: grid; gap: 2px; width: min(320px, 100%); }
.empty-actions li { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: var(--radius-sm); }
.empty-actions li:hover { background: var(--bg-hover); }
.empty-actions .link-btn { margin-right: auto; display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); }
.empty-actions .link-btn svg.icon { width: 16px; height: 16px; color: var(--muted); }
.empty-actions li:hover .link-btn { color: var(--text); text-decoration: none; }

.vista { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.vista[hidden] { display: none; }
.vista-cabecera {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none;
  height: 38px; padding: 0 8px 0 16px;
}
.migas { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.miga { overflow: hidden; text-overflow: ellipsis; }
.miga-sep { opacity: .5; }
.miga-actual { color: var(--text-2); font-weight: 500; }
.vista-acciones { display: flex; gap: 2px; flex: none; }

.vista-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-padding: 80px 0; }
.vista-contenido { padding: 28px 48px 45vh; margin: 0 auto; }
body.legible .vista-contenido { max-width: calc(var(--ancho-lectura) + 96px); }
.vista-contenido { font-size: var(--editor-font-size); font-family: var(--font-texto); }

.titulo-inline {
  margin: 0 0 .6em; padding: 0;
  font-size: 2em; font-weight: 700; line-height: 1.2; letter-spacing: -.02em;
  color: var(--text); outline: none; word-break: break-word; text-wrap: balance;
  caret-color: var(--accent);
}
.titulo-inline:empty::before { content: "Sin título"; color: var(--muted); }
.vista-error { color: var(--danger); }

/* ── Árbol de archivos ────────────────────────────────────── */
#tree { outline: none; }
#tree.is-drop { background: var(--accent-soft); }
.arbol { font-size: 13.5px; }
.arbol-hijos { position: relative; }
.arbol-hijos::before {
  content: ""; position: absolute; top: 0; bottom: 2px;
  left: calc(var(--nivel) * 16px + 12px); width: 1px; background: var(--border);
}
.fila {
  display: flex; align-items: center; gap: 4px;
  height: 28px; padding: 0 8px 0 calc(var(--nivel) * 16px + 41px);   /* el nombre, alineado con el de las carpetas (flecha + ícono) */
  border-radius: var(--radius-sm); color: var(--text-2);
  cursor: default; user-select: none; outline: none;
}
.fila-carpeta { padding-left: calc(var(--nivel) * 16px + 4px); font-weight: 500; }
.fila:hover { background: var(--bg-hover); color: var(--text); }
.fila.is-selected { box-shadow: inset 0 0 0 1px var(--border-strong); }
#tree:focus-within .fila.is-selected { box-shadow: inset 0 0 0 1.5px var(--accent); }
.fila.is-active { background: var(--bg-active); color: var(--text); }
.fila.is-drop { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.fila.is-dragging { opacity: .45; }
.fila-chevron { width: 16px !important; height: 16px !important; color: var(--muted); flex: none; }
.fila-icono { width: 15px !important; height: 15px !important; color: var(--muted); flex: none; margin-left: -2px; }
.fila-carpeta[aria-expanded="true"] .fila-icono { color: var(--accent-text); opacity: .8; }
.fila-nombre { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fila-tipo { font-size: 10px; font-weight: 600; letter-spacing: .04em; color: var(--muted); padding: 1px 5px; border-radius: 4px; background: var(--bg-hover); }
.fila-input {
  flex: 1; min-width: 0; height: 24px; padding: 0 6px; margin-left: -6px;
  border: 1px solid var(--accent); border-radius: 4px; outline: none;
  background: var(--bg); color: var(--text); font-weight: inherit;
}
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }

/* ── Menú contextual ─────────────────────────────────────── */
.menu {
  position: fixed; z-index: 80; min-width: 200px; max-width: 320px; padding: 5px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); animation: menu-in .12s var(--ease);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-3px); } }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  height: 30px; padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font-size: 13px; text-align: left;
}
.menu-item span { flex: 1; }
.menu-item svg.icon { width: 15px; height: 15px; color: var(--muted); }
.menu-item kbd { border: 0; background: none; padding: 0; color: var(--muted); font-size: 11px; }
.menu-item:hover, .menu-item:focus { background: var(--bg-hover); outline: none; }
.menu-item.is-danger, .menu-item.is-danger svg.icon { color: var(--danger); }
.menu-item.is-danger:hover, .menu-item.is-danger:focus { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--border); }

.modal-sm { width: min(420px, calc(100vw - 32px)); }
.confirm-body { padding: 22px 22px 8px; }
.confirm-body h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.confirm-body p { margin: 0; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 14px; }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }

/* Barra de estado */
.estado-guardado.is-pendiente, .estado-guardado.is-guardando { color: var(--text-2); }
.estado-guardado.is-error { color: var(--danger); }

@media (max-width: 768px) {
  .vista-contenido { padding: 18px 16px 45vh; }
  .vista-cabecera { padding-left: 12px; }
  /* Sin hover: la X solo en la activa, para dejarle lugar al título (las pestañas se desplazan) */
  .tab { min-width: 120px; }
  .tab:not(.is-active) .tab-cerrar { display: none; }
  .tab-cerrar { opacity: 1; }
}

/* ── Pestañas apiladas ────────────────────────────────────── */
/* Cada vista queda al lado de la anterior; al desplazar, las que salen se pegan a un costado y
   dejan a la vista su lomo (el título en vertical), como en Obsidian */
.lomo { display: none; }
.pane.apilado .pane-body {
  --lomo: 34px; --ancho-ap: min(720px, calc(100% - (var(--n, 1) - 1) * var(--lomo)));
  flex-direction: row; overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth;
}
.pane.apilado .vista {
  flex: 0 0 var(--ancho-ap); min-width: 0;
  display: grid; grid-template-columns: var(--lomo) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
  position: sticky; left: calc(var(--i) * var(--lomo)); right: calc((var(--despues) + 1) * var(--lomo) - var(--ancho-ap));
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: -8px 0 14px -12px rgb(0 0 0 / .35);
}
.pane.apilado .vista[hidden] { display: none; }
.pane.apilado .vista > :not(.lomo) { grid-column: 2; }
.pane.apilado .vista > .lomo {
  grid-column: 1; grid-row: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 12px 0;
  writing-mode: vertical-rl; border: 0; border-right: 1px solid var(--border); background: var(--bg-side);
  color: var(--muted); font: 500 13px var(--font-ui); cursor: pointer; overflow: hidden; white-space: nowrap;
}
.pane.apilado .vista > .lomo:hover { color: var(--text); background: var(--bg-hover); }
.pane.apilado .vista.is-activa > .lomo { color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.lomo svg.icon { width: 15px; height: 15px; flex: none; opacity: .75; }
.lomo-titulo { overflow: hidden; text-overflow: ellipsis; }

/* ── Marcadores (panel izquierdo) ─────────────────────────── */
.side-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.side-panel[hidden] { display: none; }
.mk-fila {
  display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px 0 calc(var(--nivel) * 16px + 8px);
  border-radius: var(--radius-sm); color: var(--text-2); cursor: default; user-select: none; outline: none;
}
.mk-fila:hover { background: var(--bg-hover); color: var(--text); }
.mk-fila:focus-visible { box-shadow: inset 0 0 0 1.5px var(--accent); }
.mk-fila svg.icon { width: 15px; height: 15px; color: var(--muted); flex: none; }
.mk-grupo { font-weight: 500; padding-left: 4px; }
.mk-grupo svg.icon:first-child { width: 16px; height: 16px; }
.mk-texto { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mk-fila.is-rota .mk-texto { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.mk-fila.is-dragging { opacity: .45; }
.mk-fila.is-drop { box-shadow: inset 0 2px 0 var(--accent); }
.mk-fila.is-drop-dentro { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.mk-fin { min-height: 40px; flex: 1; }
.mk-fin.is-drop { box-shadow: inset 0 2px 0 var(--accent); }
.mk-lista { display: flex; flex-direction: column; }
.busq-marcar { margin-right: -4px; }

/* Otra ventana cambió la nota mientras había cambios sin guardar */
.aviso-externa {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, #f59e0b 12%, var(--bg)); border: 1px solid color-mix(in srgb, #f59e0b 45%, transparent);
  font-family: var(--font-ui); font-size: 13px; color: var(--text);
}
.aviso-externa-texto { display: flex; align-items: center; gap: 8px; }
.aviso-externa-texto svg.icon { width: 16px; height: 16px; color: #d97706; flex: none; }
.aviso-externa-botones { display: flex; gap: 6px; }
