/* ================= noteflow: Notion-like skin ================= */
:root {
  --nf-fg: #37352f;
  --nf-fg-2: #787774;
  --nf-fg-3: #9b9a97;
  --nf-border: rgba(55, 53, 47, 0.09);
  --nf-border-2: rgba(55, 53, 47, 0.16);
  --nf-bg: #ffffff;
  --nf-sidebar: #f7f7f5;
  --nf-hover: rgba(55, 53, 47, 0.06);
  --nf-accent: #2383e2;
  --nf-selection: rgba(35, 131, 226, 0.28);
  --nf-shadow: 0 2px 8px rgba(15, 15, 15, 0.08), 0 0 1px rgba(15, 15, 15, 0.1);
  --nf-bg-panel: #ffffff;
  --nf-callout: #f1f1ef;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Open Sans', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color: var(--nf-fg);
  font-size: 16px;
  background: var(--nf-bg);
  overflow: hidden;
}

#app { display: flex; height: 100vh; }
#scrim { position: fixed; inset: 0; background: rgba(15, 15, 15, 0.33); z-index: 400; }

/* ---------------- sidebar ---------------- */
#sidebar {
  width: var(--nf-sidebar-w, 260px); flex: none;
  background: var(--nf-sidebar);
  border-right: 1px solid var(--nf-border);
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding: 10px 8px 24px;
}
body.sidebar-collapsed #sidebar { display: none; }
body.sidebar-collapsed .nf-resizer.left { display: none; }
/* Публика (не админ): прячем список статей, оставляем содержание (TOC) */
body.guest #docList { display: none; }
body.guest .side-section:has(#docList) { display: none; }
body.guest .side-search { display: none; }
.side-brand a {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; font-weight: 600; text-decoration: none; color: var(--nf-fg);
  border-radius: 6px;
}
.side-brand a:hover { background: var(--nf-hover); }
.side-brand .logo { font-size: 18px; }
.side-btn {
  margin: 6px 8px; padding: 6px 10px; text-align: left;
  border: 1px solid var(--nf-border-2); border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--nf-fg); background: transparent;
}
.side-btn:hover { background: var(--nf-hover); }
.side-search { padding: 6px 8px 2px; }
.side-search-input {
  width: 100%; box-sizing: border-box; padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--nf-border-2); border-radius: 7px; background: var(--nf-bg);
  color: var(--nf-fg); outline: none; font-family: inherit;
}
.side-search-input:focus { border-color: var(--nf-accent); }
.search-results { list-style: none; margin: 6px 0 0; padding: 0; }
.search-results li a {
  display: block; padding: 7px 8px; border-radius: 7px; text-decoration: none; color: var(--nf-fg);
}
.search-results li a:hover { background: var(--nf-hover); }
.search-results .sr-title { display: block; font-size: 13.5px; font-weight: 600; }
.search-results .sr-snip {
  display: block; font-size: 12px; color: var(--nf-fg-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.search-results .sr-empty { padding: 7px 8px; font-size: 12.5px; color: var(--nf-fg-3); }
.side-section { margin-top: 10px; padding: 0 4px; }
.side-title {
  font-size: 11px; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--nf-fg-3); padding: 6px 4px 4px;
}
#docList { list-style: none; margin: 0; padding: 0; }
.doc-item {
  display: block; border-radius: 5px; position: relative;
  padding: 0;
}
.doc-row {
  display: flex; align-items: center; border-radius: 5px;
  padding: 3px 4px;
}
.doc-item:hover { background: var(--nf-hover); }
.doc-item.sel > .doc-row { background: rgba(55, 53, 47, 0.08); }
.doc-row[draggable="true"] { cursor: grab; }
.doc-row.dragging { opacity: 0.45; }
.doc-row.drop-target { background: var(--nf-accent); color: #fff; }
.doc-row.drop-target .doc-link { color: #fff; }
.doc-row.drop-target .doc-caret { color: #fff; }
.folder-item.drop-target { background: var(--nf-accent); border-radius: 6px; }
.folder-item.drop-target .folder-link { color: #fff; }
.doc-sub { list-style: none; margin: 0; padding: 0; }
.doc-link {
  flex: 1; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--nf-fg); text-decoration: none; padding: 3px 4px; border-radius: 4px;
}
.vis-lock { font-size: 11px; opacity: .55; margin-right: 2px; user-select: none; }
.doc-actions { display: none; gap: 2px; }
.doc-row:hover .doc-actions { display: flex; }
.mini-ic {
  border: none; background: transparent; cursor: pointer; color: var(--nf-fg-2);
  font-size: 12px; padding: 2px 5px; border-radius: 4px;
}
.mini-ic:hover { background: var(--nf-hover); color: var(--nf-fg); }
.mini-ic.danger:hover { color: #d44; }
.doc-caret {
  border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3);
  font-size: 10px; line-height: 1; padding: 4px 3px; border-radius: 4px; flex: none;
}
.doc-caret:hover { background: var(--nf-hover); color: var(--nf-fg); }

/* ---------------- folders ---------------- */
.folder-section { margin-top: 10px; padding: 0 4px; }
.folder-title { display: flex; align-items: center; justify-content: space-between; }
.side-add {
  border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3);
  font-size: 14px; line-height: 1; padding: 2px 6px; border-radius: 5px;
}
.side-add:hover { background: var(--nf-hover); color: var(--nf-fg); }
.lib-actions { display: flex; gap: 2px; margin-left: auto; }
.folder-tree { list-style: none; margin: 0; padding: 0; }
.folder-item { display: block; border-radius: 5px; position: relative; padding: 0; }
.folder-row { display: flex; align-items: center; }
.folder-item:hover { background: var(--nf-hover); }
.folder-row:hover .doc-actions { display: flex; }
.folder-link {
  flex: 1; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: none; background: transparent; text-align: left; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--nf-fg); padding: 3px 4px; border-radius: 4px;
}
.folder-link:hover { color: var(--nf-accent); }
.fm-menu {
  position: fixed; z-index: 900; min-width: 200px; max-height: 320px; overflow-y: auto;
  background: var(--nf-bg); border: 1px solid var(--nf-border); border-radius: 8px;
  box-shadow: var(--nf-shadow); padding: 4px;
}
.fm-opt {
  font-size: 13.5px; color: var(--nf-fg); padding: 6px 10px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fm-opt:hover { background: var(--nf-accent); color: #fff; }
.folder-ic { font-size: 15px; line-height: 1; margin: 0 2px 0 1px; flex: none; }
.folder-row.is-admin .folder-link { color: var(--nf-fg-2); }
.folder-row[draggable="true"] { cursor: grab; }
.folder-index { margin-bottom: 16px; }
.blog-card.folder-card .blog-card-title { font-weight: 700; }

/* ---------------- folder page (/f/:id) ---------------- */
.folder-page { max-width: 920px; margin: 0 auto; padding: 18px 6px 40px; }
.folder-page-cover {
  height: 150px; border-radius: 12px; margin-bottom: 14px;
  background-size: cover !important; background-position: center !important;
}
.folder-page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.folder-page-ic { font-size: 34px; line-height: 1; }
.folder-page-title { font-size: 30px; font-weight: 800; margin: 0; }
.folder-back {
  display: inline-block; margin: 6px 0 18px; font-size: 14px; color: var(--nf-accent);
  text-decoration: none;
}
.folder-back:hover { text-decoration: underline; }

.toc-wrap { flex: 1; overflow-y: auto; }
#toc { padding-bottom: 30px; }
#toc .toc-empty { font-size: 13px; color: var(--nf-fg-3); padding: 6px 8px; }
.toc-item {
  display: block; padding: 4px 8px; border-radius: 5px;
  font-size: 13.5px; line-height: 1.35; color: var(--nf-fg-2);
  text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-item:hover { background: var(--nf-hover); color: var(--nf-fg); }
.toc-item.active { color: var(--nf-fg); font-weight: 500; background: var(--nf-hover); }
.toc-item[data-level="1"] { padding-left: 0; font-weight: 600; }
.toc-item[data-level="2"] { padding-left: 8px; }
.toc-item[data-level="3"] { padding-left: 20px; }
.toc-item[data-level="4"] { padding-left: 30px; }
.toc-item[data-level="5"] { padding-left: 40px; }
.toc-item[data-level="6"] { padding-left: 48px; }
.toc-row { display: flex; align-items: center; gap: 2px; }
.toc-row:hover .toc-copy { opacity: 1; }
.toc-copy {
  border: none; background: transparent; cursor: pointer; font-size: 12px; line-height: 1;
  padding: 3px 4px; border-radius: 4px; color: var(--nf-fg-3); opacity: 0; transition: opacity 0.12s;
}

/* copy-link chip shown when hovering a list item (per-item anchor) */
.blk-chip {
  position: absolute; z-index: 40; display: none;
  border: 1px solid var(--nf-border-2); background: var(--nf-bg); cursor: pointer;
  color: var(--nf-fg-3); padding: 2px 5px; border-radius: 5px; line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.blk-chip:hover { color: var(--nf-accent); border-color: var(--nf-accent); }
.toc-copy:hover { background: var(--nf-hover); color: var(--nf-fg); }

/* ---------------- main column ---------------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--nf-bg); }
#topbar {
  height: 45px; flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-bottom: 1px solid var(--nf-border);
}

/* mobile overflow menu (appears as "⋯" on narrow screens) */
#moreBtn { display: none; }
#moreMenu {
  position: fixed; z-index: 600; padding: 4px; min-width: 200px;
  background: var(--nf-bg-panel); border: 1px solid var(--nf-border);
  border-radius: 9px; box-shadow: var(--nf-shadow);
}
.more-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  color: var(--nf-fg); font: inherit; font-size: 13.5px; padding: 9px 10px;
  border-radius: 6px; cursor: pointer;
}
.more-item:hover { background: var(--nf-hover); }
.icon-btn, .ghost-btn, .primary-btn {
  border: none; background: transparent; cursor: pointer; border-radius: 6px;
  padding: 6px 10px; font-size: 14px; color: var(--nf-fg);
}
.icon-btn:hover, .ghost-btn:hover { background: var(--nf-hover); }
.primary-btn { background: var(--nf-accent); color: #fff; font-weight: 500; }
.primary-btn:hover { background: #1b6dc0; }
.ghost-btn.danger:hover { background: #fdebec; color: #d44; }
#crumb {
  font-size: 14px; color: var(--nf-fg-2); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 40%;
}
.spacer { flex: 1; }
.sz { font-size: 12.5px; color: var(--nf-fg-3); }
.ghost-btn.active { background: var(--nf-hover); color: var(--nf-fg); }

/* ---------------- admin API token modal ---------------- */
.nf-modal { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: center; justify-content: center; background: rgba(15, 17, 21, 0.45); }
.nf-modal[hidden] { display: none; }
.nf-modal-box { background: var(--nf-bg); color: var(--nf-fg); width: min(520px, 92vw); border: 1px solid var(--nf-border); border-radius: 10px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28); overflow: hidden; }
.nf-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--nf-border); font-weight: 600; }
.nf-modal-head .nf-mini { padding: 4px 8px; }
.nf-modal-body { padding: 14px; }
.nf-token-row { display: flex; gap: 8px; margin: 8px 0; }
.nf-token-input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; padding: 8px 10px; border: 1px solid var(--nf-border-2, var(--nf-border)); border-radius: 6px; background: var(--nf-bg-2, #f4f5f7); color: var(--nf-fg); }
.nf-modal-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------------- blog index ---------------- */
.blog-index {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px; margin-top: 8px;
}
.blog-card {
  display: block; text-decoration: none; color: var(--nf-fg);
  border: 1px solid var(--nf-border); border-radius: 10px; overflow: hidden;
  background: var(--nf-bg); transition: border-color .15s, transform .15s;
}
.blog-card:hover { border-color: var(--nf-accent); transform: translateY(-2px); }
.blog-card-cover { height: 120px; background-size: cover !important; background-position: center !important; }
.blog-card-body { padding: 12px 14px; }
.blog-card-icon { font-size: 20px; }
.blog-card-title { font-size: 18px; font-weight: 700; margin: 4px 0 6px; line-height: 1.25; }
.blog-card-date { font-size: 12.5px; color: var(--nf-fg-3); }

#canvasScroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
#canvas {
  max-width: 900px; margin: 0 auto; padding: 40px 90px 120px; position: relative;
}
.doc-meta { font-size: 12.5px; color: var(--nf-fg-3); margin-bottom: 12px; }

#pageTitle {
  font-size: 40px; line-height: 1.2; font-weight: 700; letter-spacing: -0.011em;
  margin: 0 0 12px; color: var(--nf-fg); outline: none;
}
#pageTitle[contenteditable="true"]:hover { cursor: text; }
#pageTitle[contenteditable="true"]:empty::before { content: "Заголовок"; color: var(--nf-fg-3); }
#pageExcerpt {
  display: block; width: 100%; box-sizing: border-box;
  font-size: 15px; color: var(--nf-fg-3); margin: 0 0 12px;
  border: 1px solid var(--nf-border); border-radius: 8px; padding: 8px 10px;
  background: var(--nf-bg); outline: none; font-family: inherit;
}
#pageExcerpt:focus { border-color: var(--nf-accent); color: var(--nf-fg); }


#canvas[data-reader-font="serif"] { font-family: Georgia, 'Iowan Old Style', 'Times New Roman', serif; }
#canvas[data-reader-font="serif"] .ProseMirror,
#canvas[data-reader-font="serif"] #pageTitle,
#canvas[data-reader-font="serif"] #docMeta { font-family: inherit; }
#canvas[data-reader-width="wide"] { max-width: 1100px; }
#readerWidthBtn.on { color: var(--nf-accent); border-color: var(--nf-accent); }

/* ---------------- editor typography (Notion-like) ---------------- */
.nf-editor { outline: none; min-height: 50vh; caret-color: var(--nf-accent); }
.ProseMirror { font-size: 16px; line-height: 1.6; color: var(--nf-fg); word-break: normal; overflow-wrap: break-word; text-align: justify; hyphens: auto; -webkit-hyphens: auto; -ms-hyphens: auto; }
.ProseMirror p { margin: 0.25em 0; }
.ProseMirror > * + * { margin-top: 0.35em; }
.ProseMirror h1, .ProseMirror h2, .ProseMirror h3, .ProseMirror h4, .ProseMirror h5, .ProseMirror h6 {
  margin: 1em 0 0.35em; font-weight: 700; letter-spacing: -0.011em; color: var(--nf-fg); text-align: start; hyphens: manual;
}
.ProseMirror h1 { font-size: 30px; margin-top: 0.6em; }
.ProseMirror h2 { font-size: 24px; }
.ProseMirror h3 { font-size: 20px; }
.ProseMirror h4 { font-size: 17px; }
.ProseMirror h5, .ProseMirror h6 { font-size: 15.5px; }
.ProseMirror .is-editor-empty:first-child::before,
.ProseMirror p.is-empty::before {
  content: attr(data-placeholder); float: left; height: 0; color: var(--nf-fg-3); pointer-events: none;
}
.ProseMirror ::selection { background: var(--nf-selection); }
.ProseMirror a { color: var(--nf-accent); }
.ProseMirror strong { font-weight: 600; }
.ProseMirror code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em; background: rgba(135, 131, 120, 0.15); padding: 0.15em 0.4em; border-radius: 4px;
  hyphens: manual;
}
.ProseMirror pre {
  background: #f6f6f4; border-radius: 8px; padding: 12px 14px; overflow-x: auto;
  border: 1px solid var(--nf-border); text-align: start; hyphens: manual;
}
.ProseMirror pre code { background: none; padding: 0; font-size: 14px; }
.ProseMirror blockquote {
  border-left: 3px solid rgba(55, 53, 47, 0.35); padding-left: 14px; margin: 0.6em 0; color: var(--nf-fg-2);
}
.ProseMirror hr { border: none; border-top: 1px solid var(--nf-border-2); margin: 1.2em 0; }
.ProseMirror ul, .ProseMirror ol { padding-left: 1.6em; }
.ProseMirror li p { margin: 0.15em 0; }
.ProseMirror li > p:first-child { margin-top: 0; }

/* block anchors (every top-level block) */
.ProseMirror > * { position: relative; scroll-margin-top: 74px; }

/* ---------------- tables ---------------- */
.ProseMirror table {
  border-collapse: collapse; width: 100%; table-layout: fixed; margin: 0.6em 0;
  font-size: 0.95em;
}
.ProseMirror th, .ProseMirror td {
  border: 1px solid var(--nf-border-2); padding: 5px 10px; vertical-align: top; position: relative;
  text-align: start; hyphens: manual;
}
.ProseMirror th { background: #f7f6f3; font-weight: 600; text-align: left; }
.ProseMirror thead th { position: sticky; top: 0; z-index: 1; }
.ProseMirror th p, .ProseMirror td p { margin: 0; }
.ProseMirror .selectedCell::after {
  content: ""; position: absolute; inset: 0; background: rgba(35, 131, 226, 0.08); pointer-events: none;
}

/* floating table controls */
.nf-table-ctl {
  position: fixed; z-index: 42; display: none; gap: 4px; padding: 4px 5px;
  background: var(--nf-bg-panel); border: 1px solid var(--nf-border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.nf-tc-btn {
  border: none; background: transparent; cursor: pointer; color: var(--nf-fg);
  font-size: 12px; padding: 4px 8px; border-radius: 5px; white-space: nowrap;
}
.nf-tc-btn:hover { background: var(--nf-accent); color: #fff; }
.nf-tc-btn.danger:hover { background: #d44; }
.column-resize-handle {
  position: absolute; right: -2px; top: 0; bottom: -2px; width: 4px;
  background: var(--nf-accent); pointer-events: none;
}
.resize-cursor { cursor: col-resize; }

/* ---------------- custom block nodes ---------------- */
.nf-nodebar {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px;
  border: 1px solid var(--nf-border); border-bottom: none; border-radius: 8px 8px 0 0;
  background: #fbfbfa; font-size: 12.5px; color: var(--nf-fg-2);
}
.nf-nodename { flex: 1; font-weight: 500; }
.nf-mini {
  border: none; background: var(--nf-hover); border-radius: 5px; cursor: pointer;
  font-size: 12px; padding: 3px 8px; color: var(--nf-fg);
}
.nf-mini:hover { background: rgba(55, 53, 47, 0.12); }
.nf-mini.danger:hover { background: #fdebec; color: #d44; }
.nf-editor-pane {
  border: 1px solid var(--nf-border); border-radius: 0 0 8px 8px; padding: 10px;
  background: #fff; margin-top: -1px;
}
.nf-hint { font-size: 12px; color: var(--nf-fg-3); margin-bottom: 6px; }
.nf-code {
  width: 100%; min-height: 90px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.5; border: 1px solid var(--nf-border-2); border-radius: 6px;
  padding: 10px; color: var(--nf-fg); background: #fdfcf9; outline: none;
}
.nf-code:focus { border-color: var(--nf-accent); }
.nf-pane-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

.nf-diagram { margin: 0.8em 0; }
.nf-diagram-preview {
  border: 1px solid transparent; border-radius: 8px; padding: 12px; background: transparent;
  overflow-x: auto; text-align: center; transition: border-color 0.15s, background 0.15s;
}
.nf-diagram:hover .nf-diagram-preview {
  border-color: var(--nf-border); background: #fdfdfc;
}
.nf-diagram-preview svg { max-width: 100%; height: auto; display: inline-block; vertical-align: middle; }
/* diagram toolbar ("Диаграмма · Mermaid" + buttons): only on hover, unless editing */
.nf-diagram-bar { opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.nf-diagram:hover .nf-diagram-bar,
.nf-diagram.is-editing .nf-diagram-bar { opacity: 1; pointer-events: auto; }
.dia-empty, .dia-load { color: var(--nf-fg-3); font-size: 13px; padding: 4px 2px; }
.dia-err { color: #c0392b; font-size: 13px; white-space: pre-wrap; }

.nf-html-render { border: 1px dashed var(--nf-border-2); border-radius: 8px; padding: 10px; }
.nf-md-render { line-height: 1.6; }
.nf-md-render.md-live {
  border: 1px solid var(--nf-border); border-radius: 0 0 8px 8px; border-top: none;
  padding: 12px 14px; margin-top: -1px; background: #fff;
}
.nf-md-render table, .nf-html-render table {
  border-collapse: collapse; width: 100%; margin: 0.6em 0;
}
.nf-md-render th, .nf-md-render td, .nf-html-render th, .nf-html-render td {
  border: 1px solid var(--nf-border-2); padding: 4px 8px;
}
.nf-md-render th, .nf-html-render th { background: #f7f6f3; text-align: left; }
.nf-md-render pre, .nf-html-render pre {
  background: #f6f6f4; border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13.5px;
}
.nf-md-render code, .nf-html-render code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(135, 131, 120, 0.15); padding: 0.15em 0.4em; border-radius: 4px; font-size: 0.85em;
}
.nf-md-render pre code, .nf-html-render pre code { background: none; padding: 0; }

/* math */
.math-inline { vertical-align: middle; display: inline-block; }
.edit-math { border-radius: 4px; padding: 0 2px; cursor: pointer; transition: background 0.12s; }
.edit-math:hover { background: rgba(55, 53, 47, 0.07); }
.edit-math-block { cursor: pointer; }
/* footnote hover preview */
.fn-preview {
  position: fixed; z-index: 1000; max-width: 360px; max-height: 240px; overflow-y: auto;
  background: var(--nf-bg); border: 1px solid var(--nf-border-2); border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  font-size: 14px; line-height: 1.55; color: var(--nf-text);
}
.fn-preview p:first-child { margin-top: 0; }
.fn-preview p:last-child { margin-bottom: 0; }
.fn-preview .fn-back { display: none; }
.fn-preview-empty { color: var(--nf-muted); font-style: italic; }
.nf-math-pop {
  position: fixed; z-index: 1000; background: var(--nf-bg); border: 1px solid var(--nf-accent);
  border-radius: 8px; padding: 8px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22); max-width: 92vw;
}
.nf-math-pop .math-input { width: min(560px, 86vw); border-color: var(--nf-border-2); }
.math-input {
  font-family: ui-monospace, monospace; font-size: 14px; border: 1px solid var(--nf-accent);
  border-radius: 4px; padding: 2px 6px; width: 100%; outline: none;
}
.math-input.wide { font-size: 15px; padding: 8px 10px; }
.math-display-wrap {
  margin: 0.9em 0; padding: 10px 14px; text-align: center; border-radius: 6px; overflow-x: auto;
}
.math-display-wrap .katex-display { margin: 0.4em 0; }

/* ---------------- block grips (admin) ---------------- */
.nf-grip-ov {
  position: fixed; z-index: 40; display: none; width: 22px; height: 22px;
  align-items: center; justify-content: center; font-size: 14px; line-height: 1; color: var(--nf-fg-3);
  cursor: grab; border: 1px solid var(--nf-border); border-radius: 5px; background: var(--nf-bg-panel);
}
.nf-grip-ov:hover { color: var(--nf-fg); background: var(--nf-hover); }
.nf-grip-ov.dragging { cursor: grabbing; background: var(--nf-hover); }

.nf-drop {
  position: fixed; z-index: 39; display: none; height: 2px; background: var(--nf-accent);
  border-radius: 2px; pointer-events: none; box-shadow: 0 0 0 1px rgba(35,131,226,0.25);
}

.nf-bubble {
  position: fixed; z-index: 550; display: none; align-items: center; gap: 2px;
  background: #2b2b2b; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,0.28);
  padding: 4px; color: #eee;
}
.nf-bubble button {
  min-width: 26px; height: 26px; border: none; background: transparent; border-radius: 5px;
  font-size: 13px; cursor: pointer; color: #eee; padding: 0 6px;
}
.nf-bubble button:hover { background: rgba(255,255,255,0.14); }
.nf-bubble button.active { background: rgba(255,255,255,0.22); color: #fff; font-weight: 700; }
.nf-bubble .nf-bubble-url {
  width: 180px; height: 26px; border: 1px solid rgba(255,255,255,0.3); border-radius: 5px;
  background: #1f1f1f; color: #eee; padding: 0 8px; font-size: 13px; display: none; outline: none;
}

.nf-editor ul[data-type="taskList"] { list-style: none; padding-left: 0; margin: 4px 0; }
.nf-editor ul[data-type="taskList"] li { display: flex; gap: 8px; align-items: flex-start; margin: 2px 0; }
.nf-editor ul[data-type="taskList"] li > label { margin-top: 3px; user-select: none; }
.nf-editor ul[data-type="taskList"] li > div { flex: 1; }
.nf-editor ul[data-type="taskList"] li[data-checked="true"] > div { text-decoration: line-through; opacity: 0.6; }

.blk-menu {
  position: fixed; z-index: 600; min-width: 190px;
  background: #fff; border: 1px solid var(--nf-border); border-radius: 8px; box-shadow: var(--nf-shadow);
  padding: 4px;
}
.blk-menu-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 6px 10px; font-size: 13.5px; color: var(--nf-fg); border-radius: 5px; cursor: pointer;
}
.blk-menu-item:hover { background: var(--nf-hover); }
.blk-menu-item.danger { color: #d44; }
.blk-menu-item.danger:hover { background: #fdebec; }

/* ---------------- slash menu ---------------- */
.slash {
  position: fixed; z-index: 500; max-height: 300px; overflow-y: auto; min-width: 250px;
  background: #fff; border: 1px solid var(--nf-border); border-radius: 9px; box-shadow: var(--nf-shadow);
  padding: 4px;
}
.slash-item {
  display: flex; align-items: baseline; gap: 10px; padding: 6px 10px; border-radius: 5px; cursor: pointer;
}
.slash-cat { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--nf-fg-3); padding: 8px 10px 2px; }
.slash-ico { width: 22px; text-align: center; font-size: 14px; color: var(--nf-fg-2); flex: none; }
.slash-txt { display: flex; flex-direction: column; flex: 1; }
.slash-item b { font-size: 14px; color: var(--nf-fg); }
.slash-item small { font-size: 12px; color: var(--nf-fg-3); }
.slash-item.sel { background: #f1f0ee; }

/* ---------------- comments panel ---------------- */
#commentsPanelWrap {
  width: var(--nf-cp-w, 320px); flex: none; border-left: 1px solid var(--nf-border);
  background: var(--nf-sidebar); display: flex; flex-direction: column; overflow: hidden;
}
#commentsPanelWrap[hidden] { display: none; }
.cp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--nf-border); font-size: 14px; font-weight: 600;
}
.cp-head b { font-weight: 700; }
#commentsList { flex: 1; overflow-y: auto; padding: 12px; }
.cp-empty { font-size: 13px; color: var(--nf-fg-3); line-height: 1.5; }
.cp-card {
  background: #fff; border: 1px solid var(--nf-border); border-radius: 9px;
  padding: 10px 12px; margin-bottom: 10px; cursor: pointer;
  border-left: 3px solid #f2c94c; transition: box-shadow 0.12s;
}
.cp-card:hover { box-shadow: var(--nf-shadow); }
.cp-quote {
  font-size: 13px; color: var(--nf-fg-2); font-style: italic;
  background: rgba(255, 212, 0, 0.18); border-radius: 5px; padding: 4px 8px; margin-bottom: 6px;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.cp-headline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cp-time { font-size: 11.5px; color: var(--nf-fg-3); }
.cp-del { border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cp-del:hover { background: #fdebec; color: #d44; }
.cp-text { font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.cp-text p { margin: 0 0 6px; }
.cp-text p:last-child { margin-bottom: 0; }
.cp-text code { background: rgba(135, 131, 120, 0.18); border-radius: 4px; padding: 1px 4px; font-size: 0.9em; }
.cp-text pre { background: rgba(135, 131, 120, 0.15); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
.cp-text pre code { background: none; padding: 0; }
.cp-text a { color: var(--nf-accent); }
.cp-card.is-reply { border-left-color: var(--nf-accent); background: #fafaf8; }
.cp-reply { border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cp-reply:hover { background: var(--nf-hover); color: var(--nf-fg); }
.cp-edit-btn { border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cp-edit-btn:hover { background: var(--nf-hover); color: var(--nf-fg); }
.cp-edit { margin-top: 4px; }
.cp-edit .cm-input { margin-bottom: 8px; }
.cp-card.is-resolved { opacity: 0.55; border-left-color: #bdbdbd; }
.cp-card.is-resolved .cp-quote { background: rgba(189,189,189,0.18); }
.cp-actions { display: flex; gap: 2px; }
.cp-resolve { border: none; background: transparent; cursor: pointer; color: var(--nf-fg-3); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.cp-resolve:hover { background: #e8f5e9; color: #2e7d32; }
.cp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cp-head-title { font-size: 13px; font-weight: 600; color: var(--nf-fg-2); }
.cp-show-resolved { font-size: 12px; color: var(--nf-fg-3); display: flex; align-items: center; gap: 5px; cursor: pointer; }
.cm-hl.is-resolved { background: rgba(189,189,189,0.28); border-bottom-color: rgba(160,160,160,0.7); }

/* comment highlights in the text */
.cm-hl {
  background: rgba(255, 212, 0, 0.32); border-bottom: 2px solid rgba(240, 190, 60, 0.85);
  box-decoration-break: clone; cursor: pointer;
}
.cm-hl.is-active { background: rgba(255, 200, 40, 0.55); }
.cm-hl.is-flash { animation: cmflash 1.8s ease-out; }
@keyframes cmflash {
  0% { background: rgba(255, 190, 30, 0.85); }
  100% { background: rgba(255, 212, 0, 0.32); }
}

/* comment bubble & composer */
.cm-bubble {
  position: fixed; z-index: 700;
  background: #fff; border: 1px solid var(--nf-border); border-radius: 8px; box-shadow: var(--nf-shadow);
  padding: 4px;
}
.cm-bubble .cm-bubble-btn { display: block; }
.cm-composer {
  position: fixed; z-index: 700; width: 300px;
  background: #fff; border: 1px solid var(--nf-border); border-radius: 10px; box-shadow: var(--nf-shadow);
  padding: 12px;
}
.cm-quote-pv {
  font-size: 12.5px; color: var(--nf-fg-2); font-style: italic;
  background: rgba(255, 212, 0, 0.18); border-radius: 5px; padding: 6px 8px; margin-bottom: 8px;
  max-height: 60px; overflow-y: auto;
}
.cm-reply-pv {
  font-size: 12.5px; color: var(--nf-fg-2);
  background: rgba(55, 53, 47, 0.08); border-radius: 5px; padding: 6px 8px; margin-bottom: 8px;
}

/* ---------------- panel resizers ---------------- */
.nf-resizer {
  position: fixed; top: 0; bottom: 0; width: 7px; z-index: 60;
  cursor: col-resize; background: transparent;
}
.nf-resizer:hover { background: rgba(55, 53, 47, 0.12); }
.nf-resizer.left { left: var(--nf-sidebar-w, 260px); transform: translateX(-3px); }
.nf-resizer.right { right: var(--nf-cp-w, 320px); transform: translateX(3px); }
body:not(.comments-open) .nf-resizer.right { display: none; }
@media (max-width: 900px) { .nf-resizer { display: none; } }
.cm-input {
  width: 100%; resize: vertical; min-height: 60px;
  border: 1px solid var(--nf-border-2); border-radius: 6px; padding: 8px; font: inherit; font-size: 14px;
  outline: none;
}
.cm-input:focus { border-color: var(--nf-accent); }
.cm-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ---------------- login modal ---------------- */
#loginModal {
  position: fixed; inset: 0; z-index: 800; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 15, 15, 0.4);
}
#loginModal[hidden] { display: none; }
.lm-card {
  width: 340px; background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(15, 15, 15, 0.25);
  padding: 24px;
}
.lm-card h3 { margin: 0 0 16px; font-size: 18px; }
.lm-card input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--nf-border-2); border-radius: 8px; outline: none;
}
.lm-card input:focus { border-color: var(--nf-accent); }
.lm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.lerr { color: #d44; font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------------- mobile ---------------- */
#menuBtn { display: none; }
@media (max-width: 900px) {
  #menuBtn { display: block; }
  #sidebar {
    position: fixed; z-index: 500; left: 0; top: 0; bottom: 0;
    width: min(86vw, 320px);
    transform: translateX(-100%); transition: transform 0.18s ease;
    box-shadow: 2px 0 12px rgba(15, 15, 15, 0.1);
  }
  body.nav-open #sidebar { transform: translateX(0); }
  #canvas { padding: 24px 24px 100px; }
  #pageTitle { font-size: 30px; }
  #commentsPanelWrap {
    position: fixed; z-index: 500; top: 0; right: 0; bottom: 0; width: min(85vw, 340px);
    transform: translateX(105%); transition: transform 0.18s ease; box-shadow: -2px 0 12px rgba(15,15,15,0.1);
  }
  body.comments-open #commentsPanelWrap { transform: translateX(0); }
}

@media (max-width: 760px) {
  /* keep the topbar to one row: rare actions move into the "⋯" menu */
  #sidebarToggle, #crumb, #readerWidthBtn, #commentsToggle, #docVisToggle,
  #apiTokenBtn, #exportBtn, #importBtn { display: none !important; }
  #moreBtn { display: inline-flex; }
  #topbar { gap: 6px; padding: 0 8px; }
  #topbar .ghost-btn { padding: 4px 7px; }
  #saveState { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .slash { min-width: 0; width: min(320px, calc(100vw - 16px)); max-width: calc(100vw - 16px); }
  .nf-bubble { max-width: calc(100vw - 16px); flex-wrap: wrap; }
  .nf-table-ctl { max-width: calc(100vw - 16px); flex-wrap: wrap; }
  .lm-card { width: min(340px, calc(100vw - 32px)); }
}

/* ---------------- grip add button + restyled grip ---------------- */
.nf-grip-ov { width: auto; gap: 2px; padding: 0 3px; }
.nf-grip-handle, .nf-grip-add {
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1; color: var(--nf-fg-3); touch-action: none;
}
.nf-grip-handle { cursor: grab; }
.nf-grip-add { cursor: pointer; }
.nf-grip-handle:hover, .nf-grip-add:hover { color: var(--nf-fg); background: var(--nf-hover); }
.nf-grip-ov.dragging { cursor: grabbing; background: var(--nf-hover); }

/* narrow screens: stack the grip vertically so it fits the page margin */
@media (max-width: 760px) {
  .nf-grip-ov { flex-direction: column; width: 24px; height: auto; padding: 2px 0; gap: 0; }
  .nf-grip-ov .nf-grip-handle, .nf-grip-ov .nf-grip-add { width: 22px; height: 22px; }
}

/* ---------------- callout ---------------- */
.nf-callout {
  display: flex; gap: 10px; align-items: flex-start; margin: 0.5em 0;
  padding: 14px 16px; border-radius: 8px; background: var(--nf-callout);
  border: 1px solid var(--nf-border);
}
.nf-callout-emoji {
  flex: none; border: none; background: transparent; font-size: 20px; line-height: 1.4;
  cursor: pointer; padding: 0; border-radius: 6px;
}
.nf-callout-emoji:hover { background: var(--nf-hover); }
.nf-callout-body { flex: 1; min-width: 0; }
.nf-callout-body p { margin: 0; }
.nf-callout-body > * + * { margin-top: 0.35em; }

/* ---------------- toggle ---------------- */
.nf-toggle { display: flex; gap: 6px; align-items: flex-start; margin: 0.4em 0; }
.nf-toggle-caret {
  flex: none; border: none; background: transparent; cursor: pointer; font-size: 15px;
  color: var(--nf-fg-2); padding: 2px 4px; border-radius: 5px; margin-top: 1px;
}
.nf-toggle-caret:hover { background: var(--nf-hover); }
.nf-toggle-body { flex: 1; min-width: 0; }
.nf-toggle.collapsed > .nf-toggle-body > *:not(:first-child) { display: none; }

/* ---------------- image ---------------- */
.nf-image { margin: 0.5em 0; }
.nf-image-img { max-width: 100%; border-radius: 6px; display: block; cursor: default; }
.nf-image.editable .nf-image-img { cursor: pointer; }
.nf-image.empty .nf-image-img {
  min-height: 120px; background: var(--nf-bg-panel); border: 1px dashed var(--nf-border-2);
  border-radius: 6px; object-fit: cover; opacity: 0.6;
}
.nf-image-cap { font-size: 13px; color: var(--nf-fg-2); text-align: center; margin-top: 6px; }

/* ---------------- bookmark / link preview ---------------- */
.nf-bookmark { margin: 0.6em 0; }
.nf-bookmark-card {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit;
  border: 1px solid var(--nf-border); border-radius: 8px; padding: 12px 14px; background: var(--nf-bg-panel);
}
.nf-bookmark-card:hover { border-color: var(--nf-border-2); }
.nf-bookmark-fav { width: 28px; height: 28px; border-radius: 5px; flex: none; object-fit: contain; }
.nf-bookmark-txt { min-width: 0; }
.nf-bookmark-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nf-bookmark-desc { font-size: 13px; color: var(--nf-fg-2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.nf-bookmark-host { font-size: 12px; color: var(--nf-fg-3); margin-top: 3px; }

/* ---------------- multi-column ---------------- */
.nf-cols-wrap { margin: 0.5em 0; position: relative; }
.nf-cols { display: flex; gap: 16px; align-items: stretch; }
.nf-col { flex: 1 1 0; min-width: 0; padding: 0 2px; border-radius: 6px; }
.nf-col .ProseMirror { min-height: 1.4em; }
@media (max-width: 760px) {
  .nf-cols { flex-direction: column; gap: 8px; }
}

/* ---------------- dark theme ---------------- */
:root[data-theme="dark"] {
  --nf-fg: #e6e6e3;
  --nf-fg-2: #9b9a97;
  --nf-fg-3: #6f6e69;
  --nf-border: rgba(255, 255, 255, 0.10);
  --nf-border-2: rgba(255, 255, 255, 0.18);
  --nf-bg: #1a1a1a;
  --nf-sidebar: #212121;
  --nf-hover: rgba(255, 255, 255, 0.06);
  --nf-accent: #4a9eed;
  --nf-selection: rgba(74, 158, 237, 0.30);
  --nf-bg-panel: #262626;
  --nf-callout: #2a2a2a;
  --nf-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
:root[data-theme="dark"] body { background: var(--nf-bg); }
:root[data-theme="dark"] .nf-nodebar { background: #222222; }
:root[data-theme="dark"] .nf-editor-pane { background: #1d1d1d; }
:root[data-theme="dark"] .nf-code { background: #161616; color: var(--nf-fg); }
:root[data-theme="dark"] .ProseMirror pre { background: #161616; color: #e6e6e3; }
:root[data-theme="dark"] .ProseMirror th { background: #2a2a2a; }
:root[data-theme="dark"] .slash-item.sel { background: #2e2e2e; }
:root[data-theme="dark"] .blk-menu,
:root[data-theme="dark"] .slash,
:root[data-theme="dark"] .cm-bubble,
:root[data-theme="dark"] .cm-composer,
:root[data-theme="dark"] .lm-card,
:root[data-theme="dark"] .cp-card { background: #232323; }
:root[data-theme="dark"] .nf-diagram-preview { background: transparent; }
:root[data-theme="dark"] .nf-diagram:hover .nf-diagram-preview { background: #1c1c1c; }
:root[data-theme="dark"] .nf-md-render.md-live { background: #232323; }
:root[data-theme="dark"] .nf-html-render { background: #1d1d1d; }
:root[data-theme="dark"] .katex { filter: invert(0.9) hue-rotate(180deg); }

/* touch devices have no hover: keep diagram frame/toolbar visible */
@media (hover: none) {
  .nf-diagram-bar { opacity: 1; pointer-events: auto; }
  .nf-diagram-preview { border-color: var(--nf-border); background: #fdfdfc; }
  :root[data-theme="dark"] .nf-diagram-preview { background: #1c1c1c; }
}

/* editor focus ring */
.ProseMirror.is-focused { box-shadow: none; }

/* breadcrumb */
#crumb { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--nf-fg-muted); }
.crumb-home { color: var(--nf-fg-muted); text-decoration: none; }
.crumb-home:hover { color: var(--nf-fg); }
.crumb-sep { opacity: .5; }
.crumb-cur { color: var(--nf-fg); font-weight: 500; }
.crumb-mid { color: var(--nf-fg-muted); text-decoration: none; }
.crumb-mid:hover { color: var(--nf-fg); }

/* command palette (Ctrl/Cmd+K) */
.nf-palette { position: fixed; z-index: 60; top: 18%; left: 50%; transform: translateX(-50%); width: min(560px, 92vw); background: var(--nf-bg-panel); border: 1px solid var(--nf-border); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.25); overflow: hidden; }
.nf-palette-input { width: 100%; box-sizing: border-box; padding: 14px 16px; font-size: 15px; border: none; border-bottom: 1px solid var(--nf-border); background: transparent; color: var(--nf-fg); outline: none; }
.nf-palette-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.nf-palette-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.nf-palette-row.sel { background: var(--nf-accent); color: #fff; }
.nf-palette-ico { width: 20px; text-align: center; }
.nf-palette-label { flex: 1; }
.nf-palette-hint { font-size: 12px; opacity: .6; }
.nf-palette-row.sel .nf-palette-hint { opacity: .85; }
.nf-palette-empty { padding: 16px; color: var(--nf-fg-muted); text-align: center; }

/* touch: grip reachable on focused block without hover */
@media (hover: none) {
  .nf-grip-ov { opacity: .92; }
}

/* ---------------- page header: cover + icon ---------------- */
.page-cover {
  width: 100%;
  height: 150px;
  margin: 0 0 6px;
  background-size: cover;
  background-position: center;
  border-radius: 0 0 8px 8px;
}
.page-icon {
  font-size: 56px;
  line-height: 1;
  margin: 0 0 6px 2px;
  user-select: none;
  display: inline-block;
}
.page-icon[hidden] { display: none; }

/* editable URL slug under the title (admin only) */
.slug-editor {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  margin: 2px 0 10px; font-size: 13px; color: var(--nf-muted, #9aa4b2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.slug-editor .slug-base { opacity: 0.75; }
.slug-editor .slug-input {
  flex: 1 1 240px; min-width: 120px;
  border: 1px solid var(--nf-border, #2a2f3a); background: var(--nf-input, #0f1115);
  color: inherit; font: inherit; padding: 3px 8px; border-radius: 6px; outline: none;
}
.slug-editor .slug-input:focus { border-color: #2563eb; }

/* "Сделать главной" toggle (admin only) */
.home-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--nf-border-2); background: transparent; cursor: pointer;
  color: var(--nf-fg-2); font: inherit; font-size: 13px; padding: 4px 10px;
  border-radius: 6px; margin: 4px 0 10px; line-height: 1.3;
}
.home-btn span { pointer-events: none; }
.home-btn:hover { background: var(--nf-hover); color: var(--nf-fg); }
.home-btn.active { background: var(--nf-accent); border-color: var(--nf-accent); color: #fff; }

/* ---------------- word count footer ---------------- */
.word-count {
  margin-top: 26px;
  padding-top: 12px;
  border-top: 1px solid var(--nf-border);
  color: var(--nf-fg-muted);
  font-size: 12px;
  letter-spacing: .2px;
}

/* ---------------- [[ page-link autocomplete ---------------- */
.wiki {
  position: fixed;
  z-index: 60;
  min-width: 240px;
  max-width: 360px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--nf-bg-panel);
  border: 1px solid var(--nf-border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  padding: 6px;
}
.wiki-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.wiki-item.sel { background: var(--nf-accent); color: #fff; }
.wiki-ico { width: 20px; text-align: center; }
.wiki-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media print {
  #sidebar, #topbar, #commentsPanelWrap, .nf-grip-ov, .nf-palette, .nf-table-ctl, #scrim, #menuBtn, .wiki, .word-count, .page-cover, .page-icon, .nf-resizer { display: none !important; }
  #app { display: block; height: auto; }
  #main { overflow: visible; }
  #canvasScroll { overflow: visible; }
  html, body { overflow: visible; height: auto; }
  #canvas { max-width: none; padding: 0; }
}

/* ---------------- footnotes ---------------- */
.fn-ref {
  vertical-align: super;
  font-size: 0.72em;
  line-height: 0;
  cursor: pointer;
}
.fn-ref .fn-link {
  color: var(--nf-accent, #2563eb);
  text-decoration: none;
  font-weight: 600;
}
.fn-ref .fn-plain { display: none; }
.fn-ref.fn-raw .fn-link { display: none; }
.fn-ref.fn-raw .fn-plain { display: inline; color: var(--nf-fg); }

.fn-def {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0;
}
.fn-def .fn-label {
  font-weight: 600;
  color: var(--nf-muted, #888);
  white-space: nowrap;
  user-select: none;
}
.fn-def .fn-label .fn-marker-raw { display: none; }
.fn-def .fn-label .fn-marker-super {
  vertical-align: super;
  font-size: 0.72em;
  line-height: 0;
}
.fn-def.fn-raw-label .fn-label .fn-marker-raw { display: inline; }
.fn-def.fn-raw-label .fn-label .fn-marker-super { display: none; }
.fn-def .fn-content { flex: 1; }
.fn-def .fn-content > :first-child { margin-top: 0; }
.fn-def .fn-content > :last-child { margin-bottom: 0; }
.fn-back {
  flex: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0 2px;
  font-size: 12px;
  color: var(--nf-muted, #888);
  text-decoration: none;
}
.fn-back:hover { color: var(--nf-accent, #2563eb); text-decoration: underline; }

@media (prefers-color-scheme: dark) {
  :root[data-theme='dark'] .fn-ref .fn-link { color: #7ab7ff; }
}
/* local draft recovery banner */
.draft-banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin: 10px 0; border: 1px solid #e0a800; background: #fff8e1; border-radius: 8px; font-size: 13px; }
.draft-banner-text { color: #7a5b00; }
.draft-banner .mini-btn { font-size: 12px; padding: 4px 10px; border-radius: 6px; border: 1px solid #e0a800; background: #fff; color: #5a4400; cursor: pointer; }
.draft-banner .mini-btn.ghost { border-color: #ccc; color: #666; }
:root[data-theme='dark'] .draft-banner { background: #3a2f12; border-color: #7a5b00; }
:root[data-theme='dark'] .draft-banner-text { color: #ffd766; }
:root[data-theme='dark'] .draft-banner .mini-btn { background: #2a2410; color: #ffd766; border-color: #7a5b00; }
