/* Notas · estilos propios */
body { overflow: hidden; }
.shell {
  display: grid; height: 100dvh;
  grid-template-columns: 290px minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}
.topbar { grid-area: top; }
.top-mid { margin: 0 auto; }
.topbar .top-actions { margin-left: 0; }

/* Lateral */
.side { grid-area: side; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.side-top { display: flex; gap: 6px; padding: 10px 10px 8px; }
.search { position: relative; flex: 1; }
.search .ic { position: absolute; left: 9px; top: 8px; width: 14px; height: 14px; color: var(--text-3); pointer-events: none; }
.search kbd { position: absolute; right: 7px; top: 6px; pointer-events: none; }
.search input { width: 100%; height: 30px; padding: 0 26px 0 29px; border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }
.search input::-webkit-search-cancel-button { display: none; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 10px 8px; }
.tags:empty { display: none; }
.tagbtn { height: 22px; padding: 0 8px; border: 1px solid var(--border); border-radius: 99px; background: var(--panel); font-size: 11.5px; color: var(--text-2); }
.tagbtn small { color: var(--text-3); }
.tagbtn:hover { background: var(--hover); }
.tagbtn.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.tagbtn.on small { color: inherit; opacity: .7; }
.list { flex: 1; overflow: auto; padding: 0 6px 10px; display: flex; flex-direction: column; gap: 1px; }
.note { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none; text-align: left; }
.note:hover { background: var(--hover); }
.note.sel { background: var(--accent-soft); }
.n-t { display: flex; align-items: center; gap: 5px; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-t .pin { width: 12px; height: 12px; color: var(--star); fill: currentColor; }
.n-s { color: var(--text-2); font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.n-d { color: var(--text-3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note mark { background: var(--accent-soft); color: var(--accent); border-radius: 2px; }
.side-foot { padding: 8px 14px; border-top: 1px solid var(--border); }

/* Principal */
.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 10px; border-bottom: 1px solid var(--border); }
.tb-group { display: flex; gap: 1px; overflow-x: auto; scrollbar-width: none; }
.fmt { min-width: 28px; height: 28px; padding: 0 6px; border: 0; border-radius: 6px; background: none; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.fmt:hover { background: var(--hover); color: var(--text); }
.fmt[data-fmt="3"] { font-style: italic; font-family: Georgia, serif; }
.fmt[data-fmt="4"] { text-decoration: line-through; }
#pinBtn.on { color: var(--star); }
#pinBtn.on .ic { fill: currentColor; }
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.panes.view-edit { grid-template-columns: 1fr; }
.panes.view-edit #preview { display: none; }
.panes.view-read { grid-template-columns: 1fr; }
.panes.view-read #editor { display: none; }
#editor {
  width: 100%; height: 100%; padding: 22px 28px 40px; border: 0; outline: 0; resize: none;
  background: var(--panel); color: var(--text);
  font: 400 14px/1.75 var(--mono); tab-size: 2;
  border-right: 1px solid var(--border);
}
.panes.view-edit #editor { padding-inline: max(28px, calc((100% - 760px) / 2)); border-right: 0; }
#editor::placeholder { color: var(--text-3); }
.status { padding: 6px 14px; border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Vista previa Markdown */
.md { overflow: auto; padding: 22px 32px 48px; font-size: 14.5px; line-height: 1.7; color: var(--text); }
.panes.view-read .md { padding-inline: max(32px, calc((100% - 720px) / 2)); }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; letter-spacing: -.02em; margin: 1.4em 0 .5em; }
.md h1 { font-size: 26px; font-weight: 600; }
.md h2 { font-size: 19px; font-weight: 600; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 16px; font-weight: 600; }
.md p { margin: .6em 0; }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md code { padding: 1px 5px; border-radius: 4px; background: var(--sunken); font: 400 .88em var(--mono); }
.md pre { margin: .9em 0; padding: 12px 14px; border-radius: 8px; background: var(--sunken); border: 1px solid var(--border); overflow: auto; }
.md pre code { padding: 0; background: none; font-size: 12.5px; line-height: 1.6; }
.md blockquote { margin: .9em 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--border-2); color: var(--text-2); }
.md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li { margin: .15em 0; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md li.task input { width: 14px; height: 14px; margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--accent); cursor: pointer; }
.md li.task.done { color: var(--text-3); text-decoration: line-through; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md img { max-width: 100%; border-radius: 8px; }
.md mark { background: color-mix(in srgb, var(--star) 30%, transparent); color: inherit; padding: 0 2px; border-radius: 2px; }
.md .tbl-wrap { max-height: none; margin: .9em 0; }
.md table { width: 100%; border-collapse: collapse; font-size: 13px; }
.md th, .md td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.md th { background: var(--sunken); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.hashtag { padding: 0 4px; border: 0; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font: inherit; font-size: .92em; cursor: pointer; }

@media print {
  .topbar, .side, .toolbar, .status, #editor { display: none !important; }
  body, .shell, .main, .panes, .md { display: block !important; height: auto !important; overflow: visible !important; background: #fff !important; color: #000 !important; }
  .md { padding: 0 !important; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px auto auto; grid-template-areas: "top" "side" "main"; }
  .side { border-right: 0; border-bottom: 1px solid var(--border); }
  .list { max-height: 260px; }
  .main { min-height: 80vh; }
  .panes, .panes.view-split { grid-template-columns: 1fr; grid-template-rows: 50vh auto; }
  .toolbar { flex-wrap: wrap; height: auto; padding: 6px 10px; }
}

/* Carpetas y tareas */
.folders { display: grid; gap: 1px; padding: 0 6px 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.fold { position: relative; display: flex; align-items: center; gap: 6px; width: 100%; height: 30px; padding: 0 28px 0 10px; border: 0; border-radius: 7px; background: none; text-align: left; color: var(--text-2); font-size: 12.5px; }
.fold:hover { background: var(--hover); color: var(--text); }
.fold.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.fold-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold small { color: var(--text-3); font-variant-numeric: tabular-nums; }
.fold-x { position: absolute; right: 6px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 4px; color: var(--text-3); opacity: 0; }
.fold:hover .fold-x { opacity: 1; }
.fold-x:hover { background: var(--danger-soft); color: var(--danger); }
.fold.add { color: var(--text-3); padding-right: 10px; }
.fold-in { height: 30px; font-size: 12.5px; }
.folder-sel { height: 28px; width: auto; max-width: 160px; font-size: 12px; }
.trow { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 10px; border-radius: 8px; }
.trow:hover { background: var(--hover); }
.trow input { margin: 3px 0 0; accent-color: var(--accent); cursor: pointer; }
.trow span { display: block; font-size: 13px; line-height: 1.4; }
.t-note { padding: 0; border: 0; background: none; color: var(--text-3); font-size: 11.5px; text-align: left; }
.t-note:hover { color: var(--accent); text-decoration: underline; }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 8px 6px 14px; }

/* Modo sin distracciones */
.zen-exit { display: none; }
body.zen .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
body.zen .side, body.zen .status { display: none; }
body.zen .toolbar { opacity: 0; transition: opacity .25s; }
body.zen .toolbar:hover, body.zen .toolbar:focus-within { opacity: 1; }
body.zen #editor { padding-inline: max(28px, calc((100% - 720px) / 2)); padding-top: 48px; font-size: 15.5px; border-right: 0; }
body.zen .zen-exit { display: block; position: fixed; right: 14px; bottom: 14px; z-index: 5; padding: 6px 12px; border: 1px solid var(--border); border-radius: 99px; background: var(--panel); color: var(--text-3); font-size: 12px; opacity: .6; }
body.zen .zen-exit:hover { opacity: 1; color: var(--text); }

/* ───────── Móvil: la lista o la nota, a pantalla completa ───────── */
@media (max-width: 700px) {
  .shell { grid-template-rows: 48px auto; min-height: 100dvh; }
  body[data-mview="list"] .main, body[data-mview="note"] .side { display: none; }
  body[data-mview="note"] .shell { grid-template-areas: "top" "main"; grid-template-rows: 48px minmax(0, 1fr); height: 100dvh; min-height: 0; }
  body[data-mview="note"] { overflow: hidden; }
  .side { border-bottom: 0; min-height: calc(100dvh - 48px); }
  .side-top { position: sticky; top: 0; z-index: 3; padding: 10px 12px; background: var(--bg); }
  .list { max-height: none; overflow: visible; padding: 0 8px 24px; }
  /* Carpetas: una tira de etiquetas que se desliza */
  .folders { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 0 12px 10px; margin-bottom: 6px; }
  .folders::-webkit-scrollbar { display: none; }
  .fold { flex: none; width: auto; height: 36px; padding: 0 12px; border-radius: 18px; background: var(--sunken); font-size: 14px; }
  .fold .fold-n { flex: none; }
  .fold-x { display: none; }
  .fold-in { height: 36px; width: 160px; flex: none; }
  .tags { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 0 12px 10px; }
  .note { padding: 12px; border-bottom: 1px solid var(--border); border-radius: 0; }
  .note.sel { border-radius: 10px; }
  .n-t { font-size: 15px; }
  .n-s { font-size: 13.5px; }
  .n-d { font-size: 12px; }
  .side-foot { padding: 8px 12px max(8px, env(safe-area-inset-bottom)); }

  /* Nota: barra con volver, vista y acciones; debajo, el formato deslizable */
  .main { min-height: 0; }
  .toolbar { flex-wrap: wrap; gap: 4px; height: auto; padding: 6px 8px; }
  .back-btn { padding: 0 10px 0 4px; }
  .back-btn .ic { width: 18px; height: 18px; }
  #viewSeg [data-view="split"], #mdBtn, #htmlBtn, #printBtn, #zenBtn, #delBtn, #histBtn, .folder-sel { display: none; }
  #fmt { order: 9; flex: 1 1 100%; gap: 2px; margin: 2px -8px -6px; padding: 4px 8px; border-top: 1px solid var(--border); }
  .toolbar .grow { flex: 1; }
  .panes, .panes.view-split { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  #editor, .panes.view-edit #editor { padding: 16px 16px 40px; border-right: 0; }
  .md, .panes.view-read .md { padding: 16px 16px 48px; }
  .status { padding: 6px 12px max(6px, env(safe-area-inset-bottom)); }
}

/* Pantallas táctiles */
:root[data-input="touch"] #editor { font-size: 16px; }
:root[data-input="touch"] .search input { height: 42px; font-size: 16px; }
:root[data-input="touch"] .search .ic { top: 14px; }
:root[data-input="touch"] .search kbd { display: none; }
:root[data-input="touch"] .side-top .btn { min-height: 42px; }
:root[data-input="touch"] .fmt { min-width: 40px; height: 40px; font-size: 14px; }
:root[data-input="touch"] .fold { min-height: 36px; }
:root[data-input="touch"] .tagbtn { height: 32px; padding: 0 12px; font-size: 13px; flex: none; }
:root[data-input="touch"] .trow { grid-template-columns: 24px minmax(0, 1fr); padding: 12px 10px; }
:root[data-input="touch"] .trow input { width: 20px; height: 20px; }
:root[data-input="touch"] .trow span { font-size: 15px; }
:root[data-input="touch"] .t-note { min-height: 32px; font-size: 13px; }
:root[data-input="touch"] .md li.task input { width: 20px; height: 20px; }

/* ───────── Extras: plantillas, orden, enlaces, imágenes, versiones y mapa ───────── */
.new-grp { display: inline-flex; }
.new-grp #newBtn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.tpl-btn { padding: 0 6px; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255, 255, 255, .25); }
.tpl-btn .ic { width: 14px; height: 14px; }
.list-tools { display: flex; align-items: center; gap: 4px; padding: 0 10px 8px; }
.list-tools .input { flex: 1; min-width: 0; height: 28px; padding: 0 6px; font-size: 12px; }
.list-tools .icon-btn { flex: none; }
.panes { position: relative; }
.wikilink { padding: 0 3px; border: 0; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font: inherit; cursor: pointer; text-decoration: none; }
.wikilink:hover { text-decoration: underline; }
.wikilink.missing { background: none; color: var(--text-3); border-bottom: 1px dashed currentColor; border-radius: 0; }
.backlinks { margin-top: 2.2em; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.backlinks h4 { flex: 1 1 100%; margin: 0 0 4px; color: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.backlinks .wikilink { padding: 3px 8px; border-radius: 99px; font-size: 13px; }
.md img.nimg { display: block; margin: .6em 0; }
.md img.lost { min-height: 40px; padding: 10px; border: 1px dashed var(--border-2); color: var(--text-3); font-size: 12px; }
.wl-sug { position: absolute; left: 16px; bottom: 16px; z-index: 6; display: grid; min-width: 240px; max-width: min(420px, calc(100% - 32px)); max-height: 260px; overflow: auto; padding: 4px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow-lg); }
.wl-sug[hidden] { display: none; }
.wl-sug .sug-t { padding: 4px 8px; color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.wl-sug button { padding: 7px 8px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: 13px; color: var(--text); }
.wl-sug button.on, .wl-sug button:hover { background: var(--accent-soft); }
.hist-modal { width: min(900px, 100%); }
.hist-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; height: min(60vh, 520px); margin-top: 10px; }
.hist-list { display: grid; align-content: start; gap: 2px; overflow: auto; }
.hv { display: grid; gap: 1px; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; color: var(--text); }
.hv:hover { background: var(--hover); } .hv.on { background: var(--accent-soft); }
.hv small { color: var(--text-3); font-size: 11.5px; } .hv .add { color: var(--ok); } .hv .del { color: var(--danger); }
.hist-prev { overflow: auto; padding: 12px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--sunken); }
.map-modal { width: min(1000px, 100%); }
.map-modal .modal-h { gap: 8px; }
.map-svg { display: block; width: 100%; height: min(64vh, 600px); margin-top: 8px; border-radius: 12px; background: var(--sunken); cursor: grab; touch-action: none; }
.map-svg line { stroke: var(--border-2); stroke-width: 1.5; }
.map-svg .gn circle { fill: var(--accent); stroke: var(--panel); stroke-width: 2; cursor: pointer; }
.map-svg .gn.cur circle { fill: #e5484d; }
.map-svg .gn text { fill: var(--text-2); font: 500 11px var(--sans); text-anchor: middle; pointer-events: none; }
.map-empty { text-align: center; }
@media (max-width: 700px) {
  .hist-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 70dvh; }
  .hist-list { grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; }
  #htmlDlBtn { display: none; }
  .list-tools { padding: 0 12px 10px; }
}
:root[data-input="touch"] .list-tools .input { height: 38px; font-size: 14px; }
:root[data-input="touch"] .wl-sug button { padding: 11px 10px; font-size: 15px; }
