/* ───────────────────────────────────────────────
   VaultReader — style.css
   3-panel flex layout, light + dark, responsive
─────────────────────────────────────────────── */

/* ── Custom properties ───────────────────────── */
:root {
  --bg:          #ffffff;
  --bg2:         #f5f5f5;
  --bg3:         #ececec;
  --border:      #d8d8d8;
  --text:        #1a1a1a;
  --text2:       #555555;
  --text3:       #888888;
  --accent:      #b91c1c;
  --accent-dim:  #ef4444;
  --link:        #1d72b8;
  --link-wiki:   #9b1c1c;
  --link-wiki-missing: #cc4444;
  --sidebar-w:   240px;
  --backlinks-w: 260px;
  --font:        system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:        "JetBrains Mono", "Fira Mono", "Cascadia Code", Consolas, monospace;
  --radius:      6px;
  --shadow:      0 1px 3px rgba(0,0,0,.12);
  --transition:  0.18s ease;
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 15px;
  --text-lg:   18px;
  --text-xl:   22px;
  --text-2xl:  27px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #1e1e2e;
    --bg2:         #181825;
    --bg3:         #313244;
    --border:      #45475a;
    --text:        #cdd6f4;
    --text2:       #bac2dc; /* bumped from #a6adc8 for AA contrast on sidebar */
    --text3:       #6c7086;
    --accent:      #e88080; /* slightly desaturated from #f87171 */
    --accent-dim:  #fca5a5;
    --link:        #89b4fa;
    --link-wiki:   #fca5a5;
    --link-wiki-missing: #f38ba8;
  }
}
[data-theme="dark"] {
  --bg:          #1e1e2e;
  --bg2:         #181825;
  --bg3:         #313244;
  --border:      #45475a;
  --text:        #cdd6f4;
  --text2:       #bac2dc; /* see note above */
  --text3:       #6c7086;
  --accent:      #e88080;
  --accent-dim:  #fca5a5;
  --link:        #89b4fa;
  --link-wiki:   #fca5a5;
  --link-wiki-missing: #f38ba8;
}

/* ── Reset / Base ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Spinner (used wherever we'd show "Loading…") ── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: vr-spin 0.8s linear infinite;
  vertical-align: -2px;
}
.spinner-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text3);
}
@keyframes vr-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Modal/overlay entrance — subtle scale-in over 140ms.
   Two keyframes: one that includes the centered translate (for boxes
   positioned with translate(-50%, -50%)), one for non-centered boxes. */
@keyframes vr-pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes vr-pop-in-centered {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* Keyboard focus indicator. :focus-visible fires only for keyboard nav,
   so mouse clicks don't get the ring. Accent-coloured so it survives the
   dark theme background (the default UA ring was rgb(16,16,16) and invisible). */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
/* Inputs and the share/admin pop-ins already manage their own border;
   keep their built-in focus styling rather than doubling up. */
input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline-offset: 0; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Public-demo banner ──────────────────────── */
.demo-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 28px;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #fff;
  font-size: var(--text-xs);
}
.demo-banner-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
#app.has-banner {
  margin-top: 28px;
  height: calc(100vh - 28px);
}

/* ── Sidebar ─────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition), width var(--transition);
  z-index: 100;
}
#sidebar.closed {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

/* ── Sidebar resize handle ─────────────────────── */
#sidebar-resizer {
  flex: 0 0 4px;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  border-right: 1px solid var(--border);
  margin-left: -1px;            /* sits over the sidebar's right border */
  z-index: 101;
  transition: background var(--transition);
  user-select: none;
  touch-action: none;
}
#sidebar-resizer:hover,
#sidebar-resizer.dragging {
  background: var(--accent);
  border-right-color: var(--accent);
}
body.sidebar-resizing,
body.sidebar-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.sidebar-header {
  padding: 10px 12px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.app-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  --vr-ink: var(--text);
  --vr-accent: var(--accent);
}
.app-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text);
  flex: 1;
}

/* About tab header: the logo at display size */
.about-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0 14px;
  text-align: center;
}
.app-icon.about-logo { width: 72px; height: 72px; }
.about-name { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: .02em; }

/* Folders | Recent switch in the sidebar header */
.sb-view-toggle {
  flex: 1;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg3);
  border-radius: 6px;
}
.sb-view-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.sb-view-toggle button:hover { color: var(--text); }
.sb-view-toggle button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}

/* Recent view: name + age on one line, folder path dimmed below */
.recent-item {
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  padding-top: 6px;
  padding-bottom: 6px;
}
.recent-main { display: flex; align-items: baseline; gap: 8px; width: 100%; min-width: 0; }
.recent-main .fl-name { flex: 1; min-width: 0; }
.recent-time { flex-shrink: 0; font-size: 11px; color: var(--text3); }
.recent-where {
  font-size: 11px;
  color: var(--text3);
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-where:empty { display: none; }

/* ── Vault icon row ───────────────────────────── */
.vault-icons {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.vault-icons::-webkit-scrollbar { display: none; }

.vault-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 10px 4px;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  color: var(--text3);
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.vault-btn:last-child { border-right: none; }
.vault-btn:hover { background: var(--bg3); color: var(--text); }
.vault-btn.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg2));
  outline: 2px solid var(--accent);
  outline-offset: -3px;
  border-radius: 6px;
}
.vault-btn.active::after { display: none; } /* remove old underline indicator */
.vault-btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vault-btn-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
}
/* vault-btn-label removed — icons only, title on hover */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text2);
  padding: 4px 6px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon.active { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.bl-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 199;
  cursor: pointer;
  /* must NOT cover #toolbar — toolbar z-index sits above */
}
.btn-backlinks { position: relative; }
.bl-badge {
  position: absolute;
  top: 2px; right: 2px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  padding: 1px 3px;
  border-radius: 6px;
  min-width: 13px;
  text-align: center;
}

.vault-selector {
  padding: 8px 14px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.vault-selector select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 8px;
  cursor: pointer;
  outline: none;
  appearance: none;
}

/* ── Breadcrumb ──────────────────────────────── */
.breadcrumb {
  padding: 6px 12px 7px;
  font-size: 11px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  line-height: 1.45;
  word-break: break-word;
  /* Allow wrapping; break long folder names mid-word so the path
     stays fully readable instead of truncating. */
}
.bc-item {
  color: var(--accent);
  cursor: pointer;
  border-radius: 3px;
  padding: 0 2px;
}
.bc-item:hover { background: var(--bg3); text-decoration: none; }
.bc-sep { margin: 0 1px; color: var(--text3); opacity: 0.5; }
/* Last bc-item visually emphasised — that's where you are. */
.breadcrumb > span:last-child .bc-item {
  font-weight: 600;
  color: var(--text);
}

/* ── File list (commander style) ─────────────── */
.file-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.fl-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text2);
  border-bottom: 1px solid transparent;
  transition: background var(--transition), color var(--transition);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}
.fl-item:hover { background: var(--bg3); color: var(--text); }
.fl-item.drop-target {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}
/* Source row gets dimmed during the drag so the user sees what's
   moving. Removed on dragend. */
.fl-item.dragging {
  opacity: .35;
  transition: opacity .12s ease;
}
.fl-item.selected {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
.fl-item[draggable="true"] { cursor: grab; }
.fl-item[draggable="true"]:active { cursor: grabbing; }

/* Bulk action bar */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg);
  border-top: 1px solid var(--accent);
  flex-shrink: 0;
}
.bulk-count {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-right: auto;
}
.bulk-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.bulk-btn:hover { background: var(--bg3); border-color: var(--accent); }
.bulk-btn-danger { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.bulk-btn-danger:hover { filter: brightness(1.1); }
.bulk-btn-x {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
}
.bulk-btn-x:hover { color: var(--text); }
.fl-item.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-weight: 500;
}
.fl-icon { font-size: 13px; flex-shrink: 0; display: flex; align-items: center; color: var(--text3); }
.fl-name {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.fl-up { color: var(--text3); font-style: italic; }
.fl-dir { color: var(--text); font-weight: 500; }
.fl-dir .fl-icon { color: var(--accent); }
.fl-file .fl-icon { color: var(--text3); }
.fl-icon-dir { color: var(--accent); }
/* Non-note rows: dimmer text + small extension chip on the right */
.fl-non-note .fl-name { color: var(--text2); }
.fl-non-note.active .fl-name { color: var(--text); }
.fl-ext {
  flex-shrink: 0;
  margin-left: auto;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text3);
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 3px;
}
.fl-non-note.active .fl-ext { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Per-kind icon colors so a folder of mixed types is scannable at a
   glance. Active-row override keeps the icon legible against the
   accent-tinted active background. */
.fl-kind-image .fl-icon { color: #2563eb; }
.fl-kind-pdf   .fl-icon { color: #b91c1c; }
.fl-kind-code  .fl-icon { color: #16a34a; }
.fl-kind-media .fl-icon { color: #d97706; }
.fl-kind-file  .fl-icon { color: var(--text3); }
.fl-item.active .fl-icon { color: var(--accent); }
@media (prefers-color-scheme: dark) {
  .fl-kind-image .fl-icon { color: #93c5fd; }
  .fl-kind-pdf   .fl-icon { color: #fca5a5; }
  .fl-kind-code  .fl-icon { color: #86efac; }
  .fl-kind-media .fl-icon { color: #fcd34d; }
}

/* ── Legacy tree (keep for compat) ───────────── */
.tree-scroll { flex: 1; overflow-y: auto; }
.tree-node { user-select: none; }
.tree-item { display:flex; align-items:center; gap:5px; padding:3px 14px; font-size:13px; cursor:pointer; color:var(--text2); }
.tree-item:hover { background: var(--bg3); }
.tree-item.active { background: var(--accent); color:#fff; }
.tree-icon { font-size:11px; flex-shrink:0; color:var(--text3); }
.tree-label { overflow:hidden; text-overflow:ellipsis; flex:1; }
.tree-children { padding-left:14px; }

/* ── Main area ───────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Toolbar ─────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  min-height: 46px;
  box-shadow: 0 1px 0 var(--border);
  position: relative;
  z-index: 201; /* above bl-backdrop (199) and backlinks panel (200) */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #toolbar { background: #16182a; }
}
[data-theme="dark"] #toolbar { background: #16182a; }
.toolbar-spacer { flex: 1; min-width: 0; }
#breadcrumb-row {
  flex-shrink: 0;
  padding: 4px 12px 5px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
#breadcrumb-row > .toolbar-breadcrumb {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.fm-toggle.inline {
  flex-shrink: 0;
}

/* Copy-path button on the breadcrumb row. Sits left of fm-toggle, both
   pushed to the right edge by margin-left: auto on the first one. */
.tb-copypath {
  margin-left: auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text3);
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.tb-copypath:hover {
  background: var(--bg3);
  color: var(--text);
}
.tb-copypath.copied {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #breadcrumb-row { background: #16182a; }
}
[data-theme="dark"] #breadcrumb-row { background: #16182a; }
.toolbar-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  /* No max-width — let it run the full row, scroll if absolutely huge */
  overflow: hidden;
  text-overflow: ellipsis;
}
.tb-vault {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
}
.tb-vault:hover { background: var(--bg3); text-decoration: none; }
.tb-sep { color: var(--text3); margin: 0 1px; opacity: 0.6; }
.tb-seg {
  color: var(--text2);
  cursor: pointer;
  padding: 1px 5px;
  border-radius: 4px;
  max-width: 240px;       /* was 120 — wider segments fit on the dedicated row */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.85;
  display: inline-block;
  vertical-align: middle;
}
.tb-seg:hover { background: var(--bg3); color: var(--text); opacity: 1; }
.tb-note {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;       /* was 240 — much more room on its own line */
  display: inline-block;
  vertical-align: middle;
}
.btn-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.btn-group .btn {
  background: none;
  border: none;
  padding: 5px 14px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  color: var(--text2);
  transition: background var(--transition), color var(--transition);
}
.btn-group .btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.btn-group .btn:not(.active):hover { background: var(--bg3); color: var(--text); }
.btn-group .btn + .btn { border-left: 1px solid var(--border); }

.save-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.save-status.saving { background: var(--bg3); color: var(--text3); }
.save-status.saved  { background: #e6f4ea; color: #2e7d32; }
.save-status.error  { background: #fdecea; color: #c62828; }
@media (prefers-color-scheme: dark) {
  .save-status.saved  { background: #1e3a22; color: #a5d6a7; }
  .save-status.error  { background: #3b1212; color: #ef9a9a; }
}

/* ── Content area ────────────────────────────── */
#content-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Frontmatter bar ─────────────────────────── */
.frontmatter-bar {
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.fm-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 14px;
}
.fm-toggle {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--text3);
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.fm-toggle:hover { background: var(--bg3); color: var(--text2); }
.fm-toggle.open {
  background: var(--bg3);
  color: var(--accent);
  border-color: var(--border);
}
.fm-toggle-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 14px;
  padding: 0 4px;
  background: var(--bg);
  border-radius: 7px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text2);
  font-family: var(--mono);
}
.fm-toggle.open .fm-toggle-badge { background: var(--accent); color: var(--bg); }
.fm-content {
  padding: 6px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

/* ── Undo toasts (bottom-right stack) ──────────── */
#toast-stack {
  position: fixed;
  right: 16px;
  bottom: 28px;          /* above status bar */
  z-index: 1200;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  min-width: 240px;
  max-width: 360px;
  font-size: 13px;
}
.toast-msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Pending-mode toast (long-running operation like docx export) — spinner
   + slightly muted background so it reads as "in progress". */
.toast-pending { background: var(--bg2); color: var(--text); border: 1px solid var(--border); }
.toast-spinner {
  flex-shrink: 0;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: toast-spin 0.9s linear infinite;
}
@keyframes toast-spin { to { transform: rotate(360deg); } }
.toast-undo {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.toast-undo:hover { filter: brightness(1.15); }
.toast-close {
  background: transparent;
  border: none;
  color: var(--bg2);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  opacity: 0.6;
}
.toast-close:hover { opacity: 1; }
.toast-enter, .toast-leave {
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast-enter-start, .toast-leave-end { opacity: 0; transform: translateX(20px); }
.toast-enter-end, .toast-leave-start { opacity: 1; transform: translateX(0); }

/* Save-status fade — gentle 250ms enter/leave so "✓ Saved" doesn't snap out */
.save-status-anim { transition: opacity 250ms ease, transform 250ms ease; }
.save-status-fade-start { opacity: 0; transform: translateY(-2px); }
.save-status-fade-end   { opacity: 1; transform: none; }

/* Frontmatter panel expand/collapse */
.fm-anim-enter, .fm-anim-leave {
  transition: max-height 220ms ease, opacity 180ms ease;
}
.fm-anim-enter-start { max-height: 0; opacity: 0; }
.fm-anim-enter-end   { max-height: 600px; opacity: 1; }
.fm-anim-leave-start { max-height: 600px; opacity: 1; }
.fm-anim-leave-end   { max-height: 0; opacity: 0; }
.fm-field {
  display: flex;
  gap: 8px;
  font-size: 12px;
}
.fm-props {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11px;
  flex: 1;
  min-width: 0;
}
.fm-prop {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  color: var(--text3);
  font-family: var(--mono);
  cursor: default;
}
.fm-prop-label {
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 10px;
  opacity: .7;
}
.fm-prop-value {
  color: var(--text2);
  font-weight: 600;
}
.fm-key { color: var(--accent); font-weight: 600; font-family: var(--mono); flex-shrink: 0; }
.fm-val { color: var(--text2); }
.fm-val-object { font-family: var(--mono); font-size: 11px; }
.fm-field { align-items: center; flex-wrap: wrap; }
.fm-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.fm-chip {
  display: inline-flex;
  align-items: center;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 9px;
  line-height: 1.5;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.fm-chip:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ── Preview ─────────────────────────────────── */
#preview {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  max-width: 860px;
  width: 100%;
  margin-inline: auto;
  align-self: flex-start;
}

/* ── Inline file viewer (non-md attachments) ─── */
#viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
  background: var(--bg2);
}
.viewer-name { font-family: var(--mono); font-size: 11px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60ch; }
.viewer-size { color: var(--text3); font-size: 11px; }
.viewer-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background: var(--bg2);
}
.viewer-image img { max-width: 100%; max-height: 100%; box-shadow: 0 4px 18px rgba(0,0,0,.18); border-radius: 4px; background: #fff; }
.viewer-pdf { flex: 1; width: 100%; border: 0; background: var(--bg2); }
.viewer-text {
  flex: 1;
  margin: 0;
  padding: 16px 24px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  background: var(--bg);
  color: var(--text);
}
.viewer-audio { margin: 24px auto; width: 80%; max-width: 600px; }
.viewer-video { flex: 1; width: 100%; max-height: 100%; background: #000; }

/* prose styles */
#preview {
  font-size: var(--text-base);
  line-height: 1.75;
}
#preview h1 { font-size: var(--text-2xl); font-weight: 700; margin: 1.5rem 0 0.75rem; line-height: 1.25; }
#preview h2 { font-size: var(--text-xl); font-weight: 600; margin: 1.25rem 0 0.6rem; }
#preview h3 { font-size: var(--text-lg); font-weight: 600; margin: 1rem 0 0.5rem; }
#preview p { margin: 0 0 0.875rem; }
#preview ul, #preview ol { padding-left: 1.5rem; margin: 0 0 0.875rem; }
#preview li { margin: 0.2rem 0; }
#preview code { font-family: var(--mono); font-size: 0.88em; background: var(--bg3); padding: 0.15em 0.4em; border-radius: 3px; }
#preview pre { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; overflow-x: auto; margin: 0 0 1rem; }
#preview pre code { background: none; padding: 0; font-size: 0.85em; }

/* Code-block copy button. The .code-block wrapper is injected by
   decorateCodeBlocks() after each render — it positions the button in
   the top-right and reuses the inner <pre>'s margin so layout doesn't
   shift. The button is hidden until hover so it doesn't compete with
   the code visually. */
#preview .code-block {
  position: relative;
  margin: 0 0 1rem;
}
#preview .code-block > pre {
  margin: 0;
}
#preview .code-copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  padding: 0;
  background: var(--bg);
  color: var(--text3);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s, border-color .12s;
}
#preview .code-block:hover .code-copy-btn,
#preview .code-copy-btn:focus-visible {
  opacity: 1;
}
#preview .code-copy-btn:hover {
  color: var(--text);
  background: var(--bg2);
}
#preview .code-copy-btn.copied {
  opacity: 1;
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
}

/* ── Mermaid diagrams ────────────────────────── */
#preview .mermaid {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 1em 0;
  text-align: center;
  overflow-x: auto;
  display: flex;
  justify-content: center;
}
#preview .mermaid svg {
  max-width: 100%;
  height: auto;
}
/* Mermaid SVG element styling */
#preview .mermaid svg {
  font-family: var(--font);
}
#preview .mermaid svg .node rect,
#preview .mermaid svg .node circle,
#preview .mermaid svg .node polygon,
#preview .mermaid svg .node ellipse {
  rx: 6;
  ry: 6;
}
#preview .mermaid svg .edgePath .path {
  stroke: var(--text3);
  stroke-width: 1.5px;
}
#preview .mermaid svg .cluster rect {
  rx: 8;
  fill: var(--bg3);
  stroke: var(--border);
  stroke-dasharray: 4 2;
}
#preview .mermaid svg text {
  fill: var(--text);
  font-size: 13px;
}
#preview .mermaid svg .label {
  color: var(--text);
}
/* No .edgeLabel rule: mermaid sizes each edge label's foreignObject from
   its own metrics, and in v11 .edgeLabel also matches the HTML span inside
   it — extra padding/font-size there pushes the text out of the clip box
   and leaves an empty label. */
#preview blockquote { border-left: 3px solid var(--accent-dim); padding: 0.25rem 0 0.25rem 1rem; color: var(--text2); margin: 0 0 0.875rem; background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 0 4px 4px 0; }
#preview a { color: var(--link); }
#preview a.wikilink { color: var(--link-wiki); }
#preview hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
#preview .table-wrap { overflow-x: auto; margin: 0 0 1rem; }
#preview table { border-collapse: collapse; width: 100%; margin: 0; font-size: var(--text-sm); display: block; overflow-x: auto; max-width: 100%; }
#preview th, #preview td { border: 1px solid var(--border); padding: 0.4rem 0.75rem; text-align: left; }
#preview th { background: var(--bg2); font-weight: 600; }
#preview img { max-width: 100%; height: auto; border-radius: var(--radius); }

/* task list */
#preview input[type=checkbox] { margin-right: 6px; cursor: default; }

/* ── Callouts (Obsidian admonition syntax) ───────────── */
/* Generated by renderCallouts() from `> [!type] Title` blockquotes. */
.callout {
  margin: 1rem 0;
  padding: 0.55rem 0.9rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 3%, transparent);
}
.callout-title {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--accent);
  margin-bottom: 0.35rem;
  letter-spacing: 0.01em;
}
.callout-icon { display: none; }
.callout-body > :first-child { margin-top: 0; }
.callout-body > :last-child  { margin-bottom: 0; }
.callout-body p { margin: 0.4rem 0; }

/* wikilinks */
a.wikilink {
  color: var(--link-wiki);
  text-decoration: none;
  border-bottom: 1px dashed var(--link-wiki);
  cursor: pointer;
}
a.wikilink:hover { text-decoration: none; background: var(--bg3); border-radius: 2px; }
a.wikilink-missing {
  color: var(--link-wiki-missing);
  border-bottom-color: var(--link-wiki-missing);
}

/* ── CM6 Editor ──────────────────────────────── */
#editor-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#cm-editor {
  flex: 1;
  overflow: auto;
  font-family: var(--mono);
  font-size: 14px;
  min-width: 0; /* allow flex child to shrink so lineWrapping has a real width */
}
.cm-editor { height: 100%; max-width: 100%; }
.cm-scroller { overflow: auto; }
/* Mobile: hide gutter (line numbers eat horizontal real estate) and force
   long tokens (URLs, code) to break instead of pushing the editor wide. */
@media (max-width: 700px) {
  #cm-editor .cm-gutters { display: none; }
  #cm-editor .cm-content { overflow-wrap: anywhere; word-break: break-word; }
  #cm-editor { overflow-x: hidden; }
}

/* ── Editor toolbar ────────────────────────────── */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-wrap: wrap;
  flex-shrink: 0;
}
#editor-toolbar .et-btn {
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
#editor-toolbar .et-btn:hover {
  background: var(--bg3);
  color: var(--text);
}
#editor-toolbar .et-btn.active,
#editor-toolbar .et-btn:active {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--border);
}
#editor-toolbar .et-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}
.et-mermaid-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  min-width: 160px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  padding: 4px;
}
.et-mermaid-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.et-mermaid-menu button:hover {
  background: var(--bg2);
}
@media (max-width: 700px) {
  #editor-toolbar { display: none; }
}

/* ── Template picker (overlay) ─────────────────── */
#tpl-overlay {
  position: fixed; inset: 0; z-index: 750;
  background: rgba(0,0,0,0.35);
}
.tpl-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: vr-pop-in-centered 140ms ease-out;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 540px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.tpl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.tpl-title { font-weight: 700; font-size: 13px; color: var(--text); }
.tpl-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tpl-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.tpl-item:hover { background: var(--bg3); border-color: var(--accent); }
.tpl-name { font-weight: 600; color: var(--text); font-size: 13px; }
.tpl-preview {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

/* ── Tags overlay ─────────────────────────────── */
#tags-overlay {
  position: fixed; inset: 0; z-index: 750;
  background: rgba(0,0,0,0.35);
}
.tags-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: vr-pop-in-centered 140ms ease-out;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 600px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.tags-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.tags-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}
.tags-filter-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
}
.tags-cloud {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}
.tag-cloud-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tag-cloud-item:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.tag-cloud-count {
  background: var(--bg3);
  color: var(--text3);
  border-radius: 999px;
  font-size: 10px;
  padding: 1px 6px;
  font-weight: 600;
  font-family: var(--mono);
}
.tag-cloud-item:hover .tag-cloud-count {
  background: var(--bg);
  color: var(--accent);
}

/* ── Graph view (full-screen) ──────────────────── */
#graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.graph-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
/* Mobile: graph header was wrapping to 5 lines. Stack title vertically,
   shrink scope chips so canvas isn't crushed. */
@media (max-width: 700px) {
  .graph-header {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
    font-size: 11px;
  }
  .graph-header .graph-title { font-size: 12px; }
  .graph-header .graph-scope-btn,
  .graph-header .graph-scope-current { font-size: 11px; padding: 1px 5px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .graph-header .graph-vault-select { font-size: 11px; padding: 1px 3px; max-width: 90px; }
}
.graph-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.graph-vault-select { width: auto !important; }
.graph-scope {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
  font-family: var(--mono);
}
.graph-scope-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text3);
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.graph-scope-btn:hover { background: var(--bg3); color: var(--text); }
.graph-scope-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}
.graph-scope-sep { color: var(--text3); }
.graph-scope-current {
  color: var(--accent);
  font-weight: 600;
  padding: 2px 8px;
}
.graph-depth {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text2);
}
.graph-depth-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.graph-depth-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.graph-hint {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text3);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.graph-stats {
  font-size: 12px;
  color: var(--text3);
  margin-left: auto;
}
#graph-canvas {
  flex: 1;
  background: var(--bg);
}

/* ── Outline (right rail) ──────────────────────── */
#outline {
  flex: 0 0 220px;
  width: 220px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  z-index: 50;
}
.outline-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.outline-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
}
.outline-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.outline-item {
  display: block;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text2);
  text-decoration: none;
  border-radius: 4px;
  border-left: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  transition: background var(--transition), color var(--transition);
}
.outline-item:hover {
  background: var(--bg3);
  color: var(--text);
}
.outline-item.active {
  border-left-color: var(--accent);
  background: var(--bg3);
  color: var(--text);
}
.outline-h1 { padding-left: 8px; font-weight: 600; }
.outline-h2 { padding-left: 18px; }
.outline-h3 { padding-left: 28px; font-size: 11px; color: var(--text3); }
@media (max-width: 900px) {
  #outline {
    position: fixed;
    top: 0; right: 0; bottom: 24px;
    width: 240px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.18);
    z-index: 110;
  }
}
@media (max-width: 700px) {
  #outline { width: 100%; }
}

/* ── Pinned recents ──────────────────────────── */
.recent-item.pinned,
.fv-item.pinned {
  background: linear-gradient(90deg, rgba(184,28,28,0.06), transparent 70%);
}
.recent-pin,
.fv-pin {
  display: inline-flex;
  font-size: 11px;
  margin-right: 4px;
  flex-shrink: 0;
  filter: grayscale(.3);
}
.recent-item.pinned .recent-title,
.fv-item.pinned .fv-name {
  font-weight: 600;
}

/* CM6 autocomplete panel uses .cm-tooltip-autocomplete (themed by the
   bundle). Override only what we need for contrast in dark mode. */
.cm-tooltip.cm-tooltip-autocomplete > ul {
  font-family: var(--font);
  font-size: 13px;
  max-height: 280px;
}
.cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected] {
  background: var(--accent);
  color: #fff;
}
.cm-completionDetail { color: var(--text3); font-style: normal; font-size: 11px; }

/* ── Backlinks panel — right-side overlay drawer ─ */
#backlinks {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--backlinks-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
#backlinks.closed {
  transform: translateX(110%);
  pointer-events: none;
}
#backlinks:not(.closed) {
  pointer-events: auto;
}

.backlinks-header {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  user-select: none;
}
.bl-close {
  margin-left: auto;
  padding: 4px;
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.bl-close:hover { background: var(--bg3); color: var(--text); }
.backlinks-header h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text3);
  flex: 1;
}
.backlinks-header .count {
  font-size: 11px;
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 10px;
  color: var(--text3);
}
.backlinks-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.backlink-item {
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.backlink-item:hover { background: var(--bg3); }
.backlink-title { font-size: 13px; font-weight: 500; color: var(--text); }
.backlink-excerpt { font-size: 11px; color: var(--text3); margin-top: 3px; line-height: 1.4; }

/* ── Search overlay ──────────────────────────── */
#search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.search-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
  width: 560px;
  max-width: 90vw;
  overflow: hidden;
}
.search-input-wrap {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.search-input-wrap span { color: var(--text3); font-size: 16px; }
.search-input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
}
.search-results { max-height: 360px; overflow-y: auto; }
.search-save-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
}
.search-saved {
  padding: 8px 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.search-saved-label {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  padding: 0 8px 6px;
}
.search-saved-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 4px;
  padding: 0;
}
.search-saved-item:hover { background: var(--bg2); }
.search-saved-name {
  flex: 1;
  background: transparent;
  border: none;
  text-align: left;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}
.search-saved-query {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.search-saved-del {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
}
.search-saved-del:hover { background: var(--accent); color: var(--bg); }
.search-result {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.search-result:hover, .search-result.focused {
  background: var(--bg3);
}
.sr-path { font-size: 11px; color: var(--text3); margin-bottom: 2px; display: flex; align-items: center; gap: 5px; }
.sr-kind { font-size: 11px; opacity: .8; }
.sr-image .sr-title { color: var(--text2); font-style: italic; }
.sr-title { font-size: 14px; font-weight: 500; }
.sr-excerpt { font-size: 12px; color: var(--text2); margin-top: 3px; }
.search-empty { padding: 24px; text-align: center; color: var(--text3); font-size: 14px; }

/* ── Scrollbars ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ── Responsive / mobile ─────────────────────── */
@media (max-width: 700px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(0);
  }
  #sidebar.closed { transform: translateX(-100%); width: var(--sidebar-w); min-width: var(--sidebar-w); }
  #sidebar-resizer { display: none; }
  #backlinks {
    width: 100% !important;
    left: 0;
    right: 0;
    top: auto;
    bottom: 24px; /* above status bar */
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
  }
  #backlinks.closed { transform: translateY(110%); }
  #preview { padding: 16px; }

  /* ─ P0 Fix #001: Folder view scrolling ─────── */
  .folder-view {
    flex: 1;
    overflow-y: auto;
  }

  /* ─ P0 Fix #002: Breadcrumb text truncation ─ */
  .tb-seg { max-width: 60px; }    /* reduced from 120px */
  .tb-note { max-width: 100px; }  /* reduced from 240px */

  /* ─ P0 Fix #003: Touch targets (44px minimum) */
  .fl-item {
    padding: 8px 14px;            /* increased from 5px 14px */
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .fv-item {
    padding: 10px 8px;            /* increased from 7px 8px */
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .btn-icon {
    padding: 6px 8px;             /* increased from 4px 6px */
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ── Empty state ─────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  gap: 10px;
}
.empty-state .icon { font-size: 48px; }
.empty-state p { font-size: 14px; }

/* ── Mobile sidebar scrim ────────────────────── */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
  cursor: pointer;
}
@media (max-width: 700px) {
  .sidebar-scrim { display: block; }
  /* only show scrim on mobile — x-show handles visibility */
}

/* ── Search highlight ────────────────────────── */
mark {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
  font-style: normal;
}

/* ── Recent files (empty state) ──────────────── */
.recent-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); padding: 8px 0 4px; }
.recent-item { display:flex; gap:8px; align-items:baseline; padding: 5px 8px; border-radius: 4px; cursor:pointer; font-size:13px; }
.recent-item:hover { background: var(--bg3); }
.recent-vault { font-size: 11px; color: var(--text3); min-width: 60px; }
.recent-title { color: var(--text); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ── Note missing (404) ──────────────────────── */
.note-missing { padding: 2rem; color: var(--text2); font-style: italic; }
.note-missing p { margin: 0.5rem 0; }

/* ── Folder view (main pane) ─────────────────── */
.folder-view {
  padding: 20px 24px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}
.fv-section { margin-bottom: 28px; }
.fv-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.fv-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  flex: 1;
}
.fv-sort-btns { display: flex; gap: 2px; }
.fv-sort-btn {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  transition: all var(--transition);
}
.fv-sort-btn:hover { background: var(--bg3); color: var(--text); }
.fv-sort-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.fv-list { display: flex; flex-direction: column; gap: 1px; }
.fv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: background var(--transition);
  min-width: 0;
}
.fv-item:hover { background: var(--bg3); }
.fv-icon { font-size: 10px; color: var(--text3); flex-shrink: 0; width: 14px; display: flex; align-items: center; }
.fv-item-dir .fv-icon { color: var(--accent); }
.fv-icon-dir { color: var(--accent); }
.fv-icon-file { color: var(--text3); }
.fv-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fv-item-dir .fv-name { font-weight: 500; }
.fv-meta {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
  white-space: nowrap;
}
.fv-vault { color: var(--accent); opacity: .7; }
.fv-empty { padding: 24px 16px; font-size: 13px; color: var(--text3); font-style: italic; display: flex; align-items: center; gap: 12px; }
.fv-empty-cta {
  font-size: 12px;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.fv-empty-cta:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ── Status bar ──────────────────────────────── */
#status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 24px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 0;
  font-size: 11px;
  color: var(--text3);
  z-index: 90;
  user-select: none;
}
.sb-brand-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none; cursor: pointer;
  color: var(--text3); font-size: 11px; font-family: var(--font); font-weight: 500;
  padding: 0; white-space: nowrap; flex-shrink: 0;
  transition: color var(--transition);
}
.sb-brand-btn:hover { color: var(--text2); }
.sb-sep { color: var(--text3); margin: 0 6px; flex-shrink: 0; }
.sb-context { flex: 1; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-num { color: var(--text2); font-variant-numeric: tabular-nums; }
.sb-dim { color: var(--text3); font-style: italic; }
.sb-sync {
  margin-left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: default;
}
.sb-sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
}
.sb-sync-label { color: var(--text3); }
.sb-instance { color: var(--text3); font-variant-numeric: tabular-nums; }
/* traffic light colours */
.sb-sync-synced  { color: #22c55e; }
.sb-sync-syncing { color: #f59e0b; }
.sb-sync-error   { color: #ef4444; }
.sb-sync-unknown { color: var(--text3); }
/* pulse animation when syncing */
.sb-sync-syncing .sb-sync-dot {
  animation: sb-pulse 1.2s ease-in-out infinite;
}
@keyframes sb-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* push main content up so status bar doesn't overlap */
#app { padding-bottom: 24px; }

/* ── Utility ─────────────────────────────────── */
[x-cloak] { display: none !important; }

/* ── Settings pane ───────────────────────────── */
#settings-pane {
  position: fixed; inset: 0; z-index: 800;
  /* no background overlay — pane is self-contained */
}
#settings-pane { background: rgba(0,0,0,0.35); }
.settings-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: vr-pop-in-centered 140ms ease-out;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 16px;
  width: 540px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  display: flex; flex-direction: column; gap: 12px;
}
.settings-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin: 0 -16px;
  padding: 0 12px;
}
.settings-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color var(--transition), border-color var(--transition);
  margin-bottom: -1px;
  font-family: inherit;
}
.settings-tab:hover { color: var(--text2); }
.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.settings-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 5px;
  background: var(--bg3);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text2);
}
.settings-tab.active .settings-tab-badge {
  background: var(--accent);
  color: var(--bg);
}
.settings-tab-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  padding-right: 2px;
}
.settings-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  font-weight: 600;
  margin-top: 4px;
}
.settings-hint {
  font-size: 12px;
  color: var(--text3);
}
.settings-empty {
  font-size: 12px;
  color: var(--text3);
  text-align: center;
  padding: 20px 10px;
  font-style: italic;
}
.settings-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.settings-link:hover { text-decoration: underline; }
.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}
.settings-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.att-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--bg2);
}
.att-item:hover { background: var(--bg3); }
.att-item.orphan {
  border-color: var(--accent);
  background: linear-gradient(90deg, rgba(184,28,28,0.08), transparent 50%);
}
.att-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg3);
  flex-shrink: 0;
}
.att-meta {
  flex: 1;
  min-width: 0;
}
.att-path {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-sub {
  font-size: 10px;
  color: var(--text3);
  display: flex;
  gap: 4px;
  align-items: center;
}
.att-dot { opacity: .5; }
.att-refs { color: var(--text2); }
.att-refnotes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.att-refnote {
  display: inline-flex;
  align-items: center;
  background: var(--bg);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10px;
  font-family: inherit;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.att-refnote:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.att-refnote-more {
  font-size: 10px;
  color: var(--text3);
  font-style: italic;
  align-self: center;
}
.att-orphan-tag {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 9px;
}
.att-del {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
.att-del:hover { background: var(--accent); color: var(--bg); }

.trash-vault-tag {
  display: inline-block;
  background: var(--bg3);
  color: var(--text2);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-family: var(--mono);
  margin-right: 8px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.trash-item-meta {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.trash-item-meta .trash-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
}
.settings-title {
  font-size: 13px; font-weight: 700;
  color: var(--text); letter-spacing: .02em;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.settings-label {
  font-size: 13px; color: var(--text2);
}
.settings-toggle {
  width: 36px; height: 20px;
  background: var(--bg3); border: none; border-radius: 10px;
  cursor: pointer; position: relative;
  transition: background .2s ease;
  flex-shrink: 0;
}
.settings-toggle.on { background: var(--accent); }
.settings-toggle-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s ease;
  pointer-events: none;
}
.settings-toggle.on .settings-toggle-knob { transform: translateX(16px); }

/* ── Modal ───────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; z-index: 1100;     /* above settings (800), tags (750), graph (700), search (1000) */
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 28px;
  min-width: 360px;
  max-width: 92vw;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  animation: vr-pop-in 140ms ease-out;
}
.modal-title {
  font-size: 16px; font-weight: 700;
  color: var(--text); letter-spacing: -.01em;
}
.modal-input {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 13px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  width: 100%; box-sizing: border-box;
  transition: border-color var(--transition);
}
.modal-input:focus { border-color: var(--accent); }
.modal-error {
  font-size: 12px; color: #ef4444; margin-top: -6px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px;
}
/* shared .btn style used in modals and elsewhere */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 16px;
  font-size: 13px; font-weight: 500; font-family: var(--font);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg3); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover { opacity: .88; background: var(--accent); }
.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.btn-danger:hover { background: #b91c1c; opacity: 1; }

/* ── Modal body text ─────────────────────────── */
.modal-body {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 4px;
  line-height: 1.5;
}

/* ── Context Menu ────────────────────────────── */
#ctx-menu {
  position: fixed; z-index: 600;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px;
  min-width: 152px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  display: flex; flex-direction: column;
}
.ctx-item {
  background: none; border: none;
  padding: 7px 12px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.ctx-item:hover { background: var(--bg3); }
.ctx-danger { color: #ef4444 !important; }
.ctx-danger:hover { background: rgba(239,68,68,.12) !important; }

/* ── Mode toggle (preview ↔ edit) ────────────── */
.btn-mode-toggle { color: var(--text3); }
.btn-mode-toggle:hover { color: var(--text); }
.btn-mode-toggle.editing { color: var(--accent); }

/* ── New item button + dropdown ──────────────── */
.btn-newnote { color: var(--accent); }
.btn-copylink.copied { color: #22c55e; }
.btn-copybody.copied { color: #22c55e; }
.btn-pasteappend[disabled] { opacity: .35; cursor: not-allowed; }
.btn-pasteappend:not([disabled]):hover { color: var(--accent); }
.new-dropdown {
  position: fixed;
  z-index: 700;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
}
.new-dropdown-item {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none;
  padding: 7px 10px;
  font-size: 13px; font-family: var(--font);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  text-align: left; white-space: nowrap;
}
.new-dropdown-item:hover { background: var(--bg3); }
.new-dropdown-kbd {
  margin-left: auto;
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
}

/* ── Share button + popover ─────────────────────────────── */
.btn-share-wrap { position: relative; }
.btn-share { position: relative; }
.btn-share.active { color: var(--accent); }
.btn-share .bl-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 14px; height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.share-pop {
  position: fixed;
  width: 320px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  z-index: 900;
  font-size: var(--text-sm);
  overflow: hidden;
}
/* On phones the anchor button often ends up off-screen after a toolbar
   scroll, dragging the popover with it. Override the inline top/left from
   the toolbar-anchored math and center it instead. */
@media (max-width: 700px) {
  .share-pop {
    width: auto !important;
    left: 12px !important;
    right: 12px !important;
    top: 56px !important;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
}
.share-pop-section { padding: 8px 10px; }
.share-pop-section + .share-pop-section { border-top: 1px solid var(--border); }
.share-pop-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
  margin: 2px 4px 6px;
}
.share-pop-item {
  padding: 6px 6px 8px;
  border-radius: 6px;
}
.share-pop-item + .share-pop-item { margin-top: 2px; border-top: 1px solid var(--border); padding-top: 8px; }
.share-pop-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text2);
}
.share-pop-mode {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg3);
  color: var(--text2);
  letter-spacing: .04em;
}
.share-pop-mode.rw { background: var(--accent); color: #fff; }
.share-pop-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.share-pop-expiry { font-size: 11px; color: var(--text3); }
.share-pop-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.share-pop-actions .btn-sm {
  font-size: 11px;
  padding: 3px 7px;
  display: inline-flex; align-items: center; gap: 3px;
}
.share-pop-actions .btn-sm.copied { color: var(--accent); }
.share-pop-actions .btn-danger { color: var(--accent); }
.share-pop-actions .btn-danger:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.share-pop-quick {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text);
}
.share-pop-quick:hover { background: var(--bg2); }
.share-pop-quick + .share-pop-quick { margin-top: 1px; }
.share-pop-quick-title {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
}
.share-pop-quick-sub {
  display: block;
  font-size: 11px;
  color: var(--text3);
  margin-top: 1px;
}
.share-pop-quick-more {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

/* ── Toolbar mobile fixes (max-width: 700px) ─────────────────────── */
@media (max-width: 700px) {
  /* Toolbar: tighter, note title only — no full path.
     overflow-x:auto contains horizontal overflow INSIDE the toolbar so the
     page itself doesn't scroll sideways (previously left the hamburger
     off-screen with no obvious way back). */
  #toolbar {
    padding: 6px 10px;
    gap: 5px;
    min-height: 42px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    /* fade-out indicator on the right so users know to scroll */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }
  #toolbar::-webkit-scrollbar { display: none; }
  /* Pin the hamburger so opening the sidebar is always reachable, no
     matter how far the toolbar has been scrolled. */
  #toolbar > button:first-child {
    position: sticky;
    left: 0;
    background: var(--bg2);
    z-index: 2;
    box-shadow: 6px 0 6px -4px rgba(0,0,0,.15);
  }
  [data-theme="dark"] #toolbar > button:first-child { background: #16182a; }
  /* Make sure the main column doesn't grow wider than viewport (the cause
     of the page-level horizontal scroll that hid the hamburger). */
  #main { max-width: 100vw; min-width: 0; }

  /* Title area gets flex: 1 but truncates aggressively */
  .toolbar-title {
    min-width: 0;
    flex: 1;
    font-size: 12px;
  }

  /* Hide intermediate path segments — show only vault + note title */
  .tb-sep,
  .tb-seg { display: none; }

  /* Keep vault name and note title, both very short */
  .tb-vault { font-size: 11px; padding: 2px 3px; max-width: 50px; }
  .tb-note  { font-size: 12px; max-width: 120px; }

  /* btn-group: shrink Preview/Edit labels */
  .btn-group { flex-shrink: 0; }
  .btn-group .btn {
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
  }

  /* Hide copy-link button on mobile to save space */
  .btn-copylink { display: none; }

  /* Backlinks button: tighter */
  .btn-backlinks { padding: 4px 5px; }
  .btn-newnote   { padding: 4px 5px; }
  .btn-icon { min-height: 44px; padding: 10px 8px; }
  #toolbar button { min-height: 44px; }
  .btn-backlinks, .btn-newnote, .btn-search, .btn-copylink, .btn-mode-toggle { min-height: 44px; padding: 10px 8px; }
}

/* ── P1 Mobile Optimizations (max-width: 480px) ─────────────────── */

@media (max-width: 480px) {
  
  /* P1-004: Vault icons size reduction (38px fixed width) */
  .vault-icons {
    gap: 0;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .vault-icons::-webkit-scrollbar { display: none; }
  
  .vault-btn {
    flex: 0 0 38px;                     /* Fixed width instead of flex: 1 */
    padding: 8px 2px;                  /* Reduced horizontal padding */
    min-width: 38px;
  }
  
  .vault-btn-icon {
    width: 24px;                        /* Reduced from 28px */
    height: 24px;
  }
  
  /* P1-005: Toolbar layout optimization */
  /* Hide secondary toolbar buttons on ultra-narrow screens */
  @media (max-width: 375px) {
    .btn-copylink { display: none; }    /* Hide copy wikilink button */
  }
  
  /* Make breadcrumb horizontally scrollable instead of truncating */
  .toolbar-breadcrumb {
    max-width: 180px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    padding-bottom: 2px;                /* Room for scrollbar */
  }
  .toolbar-breadcrumb::-webkit-scrollbar {
    height: 4px;
  }
  .toolbar-breadcrumb::-webkit-scrollbar-track {
    background: transparent;
  }
  .toolbar-breadcrumb::-webkit-scrollbar-thumb {
    background: var(--text3);
    border-radius: 2px;
  }
  
  /* P1-006: Modal sizing (360px min-width is too wide for 375px screen) */
  .modal-box {
    min-width: auto;                    /* Allow shrinking */
    width: calc(100% - 16px);           /* 8px margin each side */
    max-width: 360px;
  }
  
  .modal-box .modal-title { 
    font-size: 14px;                    /* Reduced from 16px */
  }
  
  .modal-box input,
  .modal-box textarea {
    font-size: 16px;                    /* Prevent zoom on iOS */
    padding: 8px 12px;
  }
  
  /* P1-008: Dropdown z-index and positioning (JS handles bounds) */
  .new-dropdown {
    position: fixed;                    /* Use viewport coordinates */
    z-index: 500;                       /* Above toolbar (201) and sidebar (100) */
  }
  
  /* Ensure dropdown stays within viewport */
  .new-dropdown.left { left: auto; }
  .new-dropdown.right { right: 8px; }
  
  /* P2 Bonus: Status bar optimization */
  #status-bar {
    font-size: 10px;
    height: 20px;
    padding: 0 8px;
  }
  
  .sb-context { display: none; }        /* Hide path context */
  .sb-sep { margin: 0 4px; }            /* Reduce spacing */
  
  /* Show only sync status on very small screens */
  @media (max-width: 360px) {
    .sb-brand-btn { display: none; }    /* Hide brand button */
  }
  
}

/* ── Ultra-mobile refinements (max-width: 375px) ────────────────── */

@media (max-width: 375px) {
  
  /* Even smaller sidebar for SE-sized screens */
  .vault-btn {
    flex: 0 0 36px;
    padding: 6px 2px;
  }
  
  .vault-btn-icon {
    width: 22px;
    height: 22px;
  }
  
  /* Smaller font for breadcrumbs */
  .breadcrumb { font-size: 11px; }
  
  /* Collapse file list item icons */
  .fl-icon { font-size: 12px; }
  
  /* Reduce padding on very small screens */
  .fl-item { padding: 6px 12px; }
  .fv-item { padding: 8px 6px; }
  
}


/* ─── Admin Panel ──────────────────────────────────────── */
#admin-panel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  display: flex; align-items: flex-start; justify-content: flex-end;
}
.admin-box {
  background: var(--bg);
  border-left: 1px solid var(--border);
  width: 340px; max-width: 95vw;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: -4px 0 24px rgba(0,0,0,.25);
}
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.admin-title { font-weight: 700; font-size: 15px; color: var(--text); }
.admin-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); margin-top: 4px; }
.admin-hint { font-size: 12px; color: var(--text3); margin: 0; line-height: 1.5; }
.admin-hint code { background: var(--bg2); border-radius: 3px; padding: 1px 4px; font-size: 11px; }
/* Vault list (in settings → Vaults tab) */
.vault-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg2);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.vault-row:hover { background: var(--bg3); border-color: var(--accent); }
.vault-row-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text2);
}
.vault-row-icon svg, .vault-row-icon img { width: 100%; height: 100%; object-fit: contain; }
.vault-row-meta { flex: 1; min-width: 0; }
.vault-row-name { font-weight: 600; color: var(--text); font-size: 13px; }
.vault-row-sub {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.vault-row-sep { opacity: .5; }
.vault-row-tag {
  background: var(--accent);
  color: var(--bg);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.admin-rw-list { display: flex; flex-direction: column; gap: 4px; }
.admin-rw-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border-radius: 6px; padding: 7px 10px;
  font-size: 13px; font-family: monospace; color: var(--text);
}
.admin-rw-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-rw-remove { background: none; border: none; cursor: pointer; color: var(--text3); font-size: 12px; padding: 2px 4px; border-radius: 4px; }
.admin-rw-remove:hover { color: var(--danger,#e55); background: var(--bg3); }
.admin-rw-empty { font-size: 12px; color: var(--text3); font-style: italic; padding: 4px 0; }
.admin-add-row { display: flex; gap: 6px; }
.admin-add-input {
  flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 13px; color: var(--text);
  font-family: monospace; outline: none;
}
.admin-add-input:focus { border-color: var(--accent); }
.admin-add-btn { flex-shrink: 0; }
.admin-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.admin-restart-btn { width: 100%; justify-content: center; }
.btn-danger { background: #c0392b !important; color: #fff !important; }
.btn-danger:hover { background: #e74c3c !important; }


/* ─── Move Picker Modal ──────────────────────────────────── */
#move-picker-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 400;
  display: flex; align-items: center; justify-content: center;
}
.move-picker-box {
  background: var(--bg, #ffffff);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 380px; max-width: 95vw;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.35);
  overflow: hidden;
}
.move-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text2);
}
.move-picker-header strong { color: var(--text); }
.move-picker-header em { color: var(--accent); font-style: normal; font-weight: 600; }
.move-picker-title { flex: 1; }

.move-picker-breadcrumb {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  padding: 8px 16px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.mpb-seg {
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-size: 12px; padding: 2px 4px;
  border-radius: 4px; font-weight: 500;
}
.mpb-seg:hover { background: var(--bg3); }
.mpb-sep { color: var(--text3); margin: 0 1px; }

.move-picker-list {
  flex: 1; overflow-y: auto;
  padding: 6px 0;
  min-height: 120px;
}
.mp-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 16px;
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--text); text-align: left;
  transition: background .1s;
}
.mp-item:hover { background: var(--bg2); }
.mp-item-up { color: var(--text3); font-style: italic; }
.mp-item-dir svg:first-child { color: var(--accent); flex-shrink: 0; }
.mp-item-dir span { flex: 1; }
.mp-chevron { color: var(--text3); flex-shrink: 0; }
.mp-empty { padding: 16px; text-align: center; font-size: 12px; color: var(--text3); font-style: italic; }

.move-picker-dest {
  padding: 10px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  display: flex; align-items: center; gap: 8px;
}
.mp-dest-label { color: var(--text3); white-space: nowrap; }
.mp-dest-path {
  color: var(--text); font-family: monospace; font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mp-dest-path strong { color: var(--accent); }

.move-picker-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}


/* ─── Share Modal ──────────────────────────────────────────── */
#share-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.share-modal-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; width: 400px; max-width: 95vw;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  overflow: hidden;
}
.share-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text2);
}
.share-modal-title { flex: 1; font-weight: 500; }
.share-modal-title em { color: var(--accent); font-style: normal; font-weight: 600; }
.share-modal-form, .share-modal-result { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.share-form-row { display: flex; flex-direction: column; gap: 5px; }
.share-form-toggle-row { flex-direction: row; align-items: center; justify-content: space-between; }
.share-label { font-size: 12px; font-weight: 600; color: var(--text2); }
.share-hint { font-weight: 400; color: var(--text3); }
.share-input, .share-select {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 13px; color: var(--text);
  outline: none; width: 100%;
}
.share-input:focus, .share-select:focus { border-color: var(--accent); }
.share-modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; }
.btn.copied { background: #16a34a !important; color: #fff !important; }

.share-result-label { font-size: 13px; font-weight: 600; color: var(--text1); }
.share-result-link {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-family: monospace; font-size: 12px; color: var(--accent);
  word-break: break-all; line-height: 1.5;
}

/* ─── Active shares in admin ───────────────────────────────── */
.share-active-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.share-active-item:last-child { border-bottom: none; }
.share-active-meta { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.share-active-path { font-family: monospace; font-size: 12px; color: var(--text); word-break: break-all; }
.share-active-label { font-size: 11px; color: var(--text3); font-style: italic; }
.share-active-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.share-tiny-badge {
  font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 8px; color: #fff;
}
.share-tiny-badge.ro { background: #666; }
.share-tiny-badge.editable { background: var(--accent); }
.share-tiny-badge.expires { background: #2563eb; font-weight: 400; }
.share-active-actions { display: flex; gap: 4px; flex-shrink: 0; }
.share-copy-btn, .share-revoke-btn {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  border-radius: 4px; color: var(--text3); font-size: 12px;
}
.share-copy-btn:hover { color: var(--accent); background: var(--bg2); }
.share-revoke-btn:hover { color: #e55; background: var(--bg2); }


/* ── Keyboard shortcuts modal ────────────────── */
#shortcuts-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
}
.shortcuts-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(360px, 92vw);
  box-shadow: var(--shadow); padding: 16px;
}
.shortcuts-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;
}
.shortcuts-title { font-weight: 600; font-size: 14px; }
.shortcuts-list { display: flex; flex-direction: column; gap: 6px; }
.shortcut-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--bg2);
}
.shortcut-row:last-child { border-bottom: none; }
.sc-keys {
  font-family: var(--mono); font-size: 11px; background: var(--bg2); padding: 3px 6px;
  border-radius: 4px; border: 1px solid var(--border); color: var(--text2);
}
.sc-desc { font-size: 13px; color: var(--text); }

/* ── Trash modal ─────────────────────────────── */
#trash-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
}
.trash-box {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(420px, 94vw);
  max-height: 80vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.trash-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.trash-title { font-weight: 600; font-size: 14px; }
.trash-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.trash-empty { padding: 24px 16px; text-align: center; font-size: 13px; color: var(--text3); }
.trash-list { display: flex; flex-direction: column; gap: 2px; }
.trash-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; font-size: 13px; border-bottom: 1px solid var(--bg2);
}
.trash-item:last-child { border-bottom: none; }
.trash-name { color: var(--text); word-break: break-all; flex: 1; }
.trash-actions { display: flex; gap: 6px; flex-shrink: 0; }
.trash-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; flex-shrink: 0;
}
