:root {
  --bg: #f7f7f5; --panel: #ffffff; --panel2: #f0efec; --text: #1f2328; --muted: #6b7078;
  --border: #e3e2de; --accent: #6d5ce7; --accent-soft: #ece9fd; --danger: #c93c3c;
  --code: #f3f2ef; --shadow: 0 8px 30px rgba(0,0,0,.12);
  --t-note:#6d5ce7; --t-learning:#1f9d74; --t-code:#d9822b; --t-feature:#2f80ed; --t-project:#b94fd1;
  --t-journal:#8a8f98; --t-ai-memory:#e0457b; --t-ai-doc:#f06292; --t-document:#5b8c3a;
  --t-person:#c7a200; --t-reference:#17a2b8; --t-ghost:#b8bcc4; --t-tag:#9aa0a6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b; --panel: #1e2024; --panel2: #25282d; --text: #e6e6e6; --muted: #9096a0;
    --border: #30333a; --accent: #9b8cff; --accent-soft: #2c2850; --code: #262930;
    --shadow: 0 8px 30px rgba(0,0,0,.5); --t-ghost:#555a63;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--danger); min-height: 1.2em; }
button { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 11px; cursor: pointer; font: inherit; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button.icon { padding: 5px 8px; } button.danger:hover { border-color: var(--danger); color: var(--danger); }
button.ghost { background: transparent; } button.on { background: var(--accent-soft); border-color: var(--accent); }
input, select, textarea { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 9px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.spacer { flex: 1; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }

/* lock */
.lock { position: fixed; inset: 0; display: grid; place-items: center; }
.lock-card { width: min(380px, 92vw); text-align: center; background: var(--panel); padding: 34px 28px;
  border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.lock-card .logo { font-size: 42px; color: var(--accent); line-height: 1; }
.lock-card h1 { margin: 8px 0 4px; font-size: 22px; }
.lock-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.lock-card input { padding: 10px 12px; }
.lock-card button { padding: 10px; background: var(--accent); color: #fff; border: none; }

/* layout */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { font-weight: 600; color: var(--accent); margin-right: 6px; }
#search { width: min(420px, 40vw); }
.body { flex: 1; display: flex; min-height: 0; }
.side { width: 290px; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.right { width: 240px; border-left: 1px solid var(--border); padding: 10px 12px; overflow: auto; background: var(--panel); }
.right h4 { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#localgraph { width: 100%; height: 220px; background: var(--bg); border-radius: 8px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#filters { padding: 8px; border-bottom: 1px solid var(--border); max-height: 42%; overflow: auto; }
#filters .grp { font-size: 11px; text-transform: uppercase; color: var(--muted); margin: 8px 6px 2px; letter-spacing: .06em; }
#filters a { display: flex; align-items: center; gap: 7px; padding: 3px 8px; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; }
#filters a:hover { background: var(--panel2); } #filters a.on { background: var(--accent-soft); }
#filters a .c { margin-left: auto; color: var(--muted); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-weight: 600; font-size: 12px; }
.list-head select { padding: 2px 4px; font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0 6px 10px; overflow: auto; flex: 1; }
.list li { padding: 7px 9px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.list li:hover { background: var(--panel2); } .list li.on { background: var(--accent-soft); border-color: var(--accent); }
.list .t { font-weight: 500; display: flex; gap: 6px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.list .s { color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.empty { margin: auto; text-align: center; max-width: 460px; padding: 20px; }
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 14px 20px 6px; }
.meta-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.title { flex: 1; font-size: 24px; font-weight: 650; border: none; background: transparent; padding: 4px 0; }
#n-folder { width: 170px; } #n-tags { width: 170px; }
.seg { display: inline-flex; } .seg button { border-radius: 0; } .seg button:first-child { border-radius: 7px 0 0 7px; }
.seg button:last-child { border-radius: 0 7px 7px 0; } .seg button + button { border-left: none; }
.panes { flex: 1; display: flex; gap: 14px; min-height: 0; }
.pane { flex: 1; min-width: 0; display: flex; position: relative; }
.panes.edit .view-pane, .panes.view .edit-pane { display: none; }
#n-body { flex: 1; resize: none; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 12px; }
.view-pane { overflow: auto; }
.md { flex: 1; padding: 4px 6px 30px; max-width: 820px; }
.md h1, .md h2, .md h3 { line-height: 1.25; } .md a { color: var(--accent); }
.md pre { background: var(--code); padding: 12px; border-radius: 8px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.md blockquote { border-left: 3px solid var(--accent); margin: 0; padding: 2px 12px; color: var(--muted); }
.md img { max-width: 100%; }
a.wikilink { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; text-decoration: none; cursor: pointer; }
a.wikilink.ghost { opacity: .6; border-bottom: 1px dashed var(--accent); }
span.tag { color: var(--accent); cursor: pointer; }
.note-foot { display: flex; justify-content: space-between; padding: 6px 2px; }
.attachment { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--panel); overflow: hidden; }
.attachment .bar { display: flex; gap: 8px; align-items: center; padding: 6px 10px; font-size: 12px; border-bottom: 1px solid var(--border); }
.attachment iframe, .attachment img { width: 100%; height: 55vh; border: none; display: block; object-fit: contain; background: #fff; }
.mini { list-style: none; padding: 0; margin: 0; } .mini li { padding: 2px 0; } .mini a { color: var(--accent); cursor: pointer; }

.ac { position: absolute; z-index: 5; list-style: none; margin: 0; padding: 4px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; min-width: 220px; }
.ac li { padding: 4px 8px; border-radius: 5px; cursor: pointer; } .ac li.on, .ac li:hover { background: var(--accent-soft); }

/* overlays */
.overlay { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; }
.graph-bar { display: flex; gap: 12px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
#graph-svg { flex: 1; width: 100%; }
.gnode text { font-size: 11px; fill: var(--text); pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.glink { stroke: var(--muted); stroke-opacity: .45; }
.modal { background: rgba(0,0,0,.35); align-items: center; justify-content: center; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 20px 22px; width: min(560px, 94vw); box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 12px; color: var(--muted); }
.modal-card input, .modal-card select { color: var(--text); font-size: 13px; }
.modal-card > input { display: block; width: 100%; margin: 6px 0; }
.modal-card .row { display: flex; gap: 8px; margin-top: 8px; }
.modal-card hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.drop { position: fixed; inset: 12px; border: 3px dashed var(--accent); border-radius: 18px; background: rgba(109,92,231,.12);
  display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); z-index: 30; pointer-events: none; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; z-index: 40; box-shadow: var(--shadow); }

/* scopes, inbox, settings */
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; padding: 0; }
.lock-card .left { text-align: left; margin: 4px 0 0; }
.qr { width: 190px; height: 190px; margin: 0 auto; background: #fff; border-radius: 10px; padding: 4px; }
.secret { word-break: break-all; user-select: all; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
.pill.shared { background: var(--accent-soft); color: var(--accent); }
.banner { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 7px 10px; margin-bottom: 10px; border-radius: 10px;
  background: var(--accent-soft); border: 1px solid var(--accent); font-size: 13px; }
.modal-card.wide { width: min(760px, 96vw); }
.modal-head { display: flex; align-items: center; gap: 8px; } .modal-head h3 { margin: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 12px 0 6px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tabs button { background: transparent; border-color: transparent; } .tabs button.on { background: var(--accent-soft); border-color: var(--accent); }
.modal-card h4 { margin: 16px 0 6px; }
.scope-row { display: grid; grid-template-columns: 150px 1fr auto; gap: 8px; margin: 6px 0; align-items: center; }
.scope-row.head { margin-bottom: 0; }
.checks { display: flex; flex-direction: column; gap: 2px; margin: 8px 0; }
.modal-card label.inline { flex-direction: row; align-items: center; gap: 8px; margin: 4px 0; color: var(--text); font-size: 13px; }
.tokform { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tokform > input { width: 100%; }
#t-result { margin-top: 10px; } .mono { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; resize: vertical; }
.grants, .audit { list-style: none; padding: 0; margin: 0; }
.grants li { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin: 6px 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.audit li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.hist { display: grid; grid-template-columns: 200px 1fr; gap: 12px; min-height: 260px; }
.hist a { cursor: pointer; color: var(--accent); } .hist a.on { font-weight: 700; }
#h-body { margin: 0; background: var(--code); border-radius: 8px; padding: 10px; overflow: auto; max-height: 55vh; white-space: pre-wrap; font-size: 12px; }

@media (max-width: 1100px) { .right { display: none; } }
@media (max-width: 760px) {
  .side { position: absolute; z-index: 10; top: 49px; bottom: 0; box-shadow: var(--shadow); }
  .side.closed { display: none; } #search { flex: 1; width: auto; min-width: 80px; } .brand { display: none; }
  .panes.split .edit-pane { display: none; }
  .topbar { gap: 5px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .topbar .lbl, .wide-only { display: none; }
  .editor { padding: 10px 10px 4px; } .title { font-size: 20px; }
  #n-folder, #n-tags { width: 46%; }
  .scope-row { grid-template-columns: 1fr; } .scope-row.head { display: none; }
  .hist { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; } /* stops iOS zooming into fields */
}
@media (min-width: 761px) { .side.closed { display: none; } }
