:root {
  --bg: #f3efe6;
  --paper: #fbf9f4;
  --surface: #ffffff;
  --ink: #2b2a28;
  --ink-soft: #6f6c66;
  --ink-faint: #b8b3aa;
  --line: rgba(43, 42, 40, 0.12);
  --line-strong: rgba(43, 42, 40, 0.24);
  --accent: #3b6db5;
  --accent-soft: rgba(59, 109, 181, 0.14);
  --accent-ink: rgba(59, 109, 181, 0.85);
  --highlight: #fff3a8;
  --danger: #b03a2e;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-card: 0 1px 0 rgba(43, 42, 40, 0.04), 0 4px 16px rgba(43, 42, 40, 0.06);
  --shadow-pop: 0 12px 32px rgba(43, 42, 40, 0.18);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: 0; cursor: pointer; }

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

/* ---------- FLASH ---------- */
.flash-stack {
  position: fixed; top: 16px; right: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
}
.flash {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; gap: 10px;
  transition: opacity 200ms, transform 200ms;
}
.flash-hide { opacity: 0; transform: translateY(-4px); }
.flash-close {
  font-size: 18px; line-height: 1; color: var(--ink-soft);
  padding: 0 2px;
}
.flash-close:hover { color: var(--ink); }

/* ---------- BUTTONS ---------- */
.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 6px 12px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; line-height: 1;
  border: 1px solid transparent; transition: background 120ms, color 120ms, border 120ms;
}
.primary-btn { background: var(--accent); color: #fff; padding: 8px 16px; }
.primary-btn:hover { background: #2f5d9f; }
.ghost-btn { color: var(--ink-soft); }
.ghost-btn:hover { color: var(--ink); background: rgba(43, 42, 40, 0.05); }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.danger:hover { background: rgba(176, 58, 46, 0.08); }
.danger-btn { background: var(--danger); color: #fff; padding: 8px 16px; }
.danger-btn:hover { background: #8c2d23; }
.icon-btn {
  width: 28px; height: 28px; padding: 0; color: var(--ink);
  border: 1px solid var(--line); background: var(--surface);
}
.icon-btn:hover { border-color: var(--ink-soft); }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.primary:hover { background: #2f5d9f; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { border-color: var(--danger); background: rgba(176, 58, 46, 0.08); }

/* ---------- LANDING ---------- */
body.landing { background: var(--bg); }
.landing-stage {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
}
.landing-card {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 48px 40px; text-align: center;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.brand-mark {
  width: 56px; height: 56px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; margin-bottom: 4px;
}
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.brand-tag { color: var(--ink-soft); font-size: 14px; }
.google-btn {
  margin-top: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; min-width: 260px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-weight: 600;
}
.google-btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.landing-fineprint { font-size: 11px; color: var(--ink-soft); margin-top: 4px; }

/* ---------- CONFIRM PAGE ---------- */
body.centered { background: var(--bg); }
.confirm-stage { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.confirm-card {
  width: min(440px, 100%); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 32px; box-shadow: var(--shadow-card);
}
.confirm-card h1 { font-size: 18px; margin-bottom: 8px; }
.confirm-card p { color: var(--ink-soft); margin-bottom: 24px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- WORKSPACE LAYOUT ---------- */
body.workspace-body { background: var(--bg); overflow: hidden; }

.workspace {
  --sidebar-w: 260px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 6px 1fr;
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
  height: 100vh;
  height: 100dvh;
}
.workspace.has-links { grid-template-columns: var(--sidebar-w) 6px 1fr 360px; }

.sidebar-resizer {
  cursor: col-resize;
  background: transparent;
  border-right: 1px solid var(--line);
  margin-left: -1px;
  position: relative;
  user-select: none;
  touch-action: none;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging,
.sidebar-resizer:focus-visible {
  background: var(--accent);
  border-right-color: var(--accent);
  outline: none;
}
body.resizing-sidebar { cursor: col-resize; user-select: none; }
body.resizing-sidebar * { cursor: col-resize !important; }

/* SIDEBAR */
.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-width: 0;
}
.sidebar-head {
  padding: 14px 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-square {
  width: 14px; height: 14px; border-radius: 3px; background: var(--accent);
}
.brand-text { font-weight: 700; letter-spacing: -0.01em; }
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-search {
  margin: 0 14px 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 10px;
  color: var(--ink-soft);
}
.sidebar-search input {
  flex: 1; border: 0; background: transparent; outline: none;
  font-size: 12.5px;
}
.sidebar-search input::placeholder { color: var(--ink-faint); }

.tree {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 4px 4px 12px;
  scrollbar-width: thin;
  display: flex; flex-direction: column;
}
.sidebar-foot {
  flex: none;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; font-size: 12px;
  background: var(--paper);
}
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg); color: var(--ink-soft);
  border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.email { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.logout-form { margin: 0; }

/* TREE NODES */
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; padding-left: calc(8px + var(--depth, 0) * 14px);
  border-radius: 4px; cursor: pointer; position: relative;
  border-left: 2px solid transparent;
  color: var(--ink);
}
.tree-row:hover { background: rgba(43, 42, 40, 0.04); }
.tree-row.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.tree-row.drop-target { background: var(--accent-soft); outline: 1px dashed var(--accent); }
.tree-row.dragging { opacity: 0.35; }
.tree-row .chev {
  width: 12px; height: 12px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-soft); transition: transform 120ms;
}
.tree-row.open .chev { transform: rotate(90deg); }
.tree-row .leaf-spacer { width: 12px; }
.tree-row .icon { color: var(--ink-soft); display: inline-flex; }
.tree-row.active .icon { color: var(--accent); }
.tree-row .label {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px;
}
.tree-row .badge {
  font-size: 10px; color: var(--ink-faint);
  margin-left: auto; opacity: 1; transition: opacity 120ms;
}
.tree-row .match-hint {
  font-size: 10.5px; color: var(--ink-faint);
  margin-left: 6px; flex: 2; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-row:hover .match-hint { display: none; }
.tree-row .hover-actions {
  display: none; align-items: center; gap: 4px; margin-left: auto;
}
.tree-row:hover .badge { display: none; }
.tree-row:hover .hover-actions { display: inline-flex; }
.tree-row.renaming .label { display: none; }
.tree-row .rename-input {
  flex: 1; min-width: 0; padding: 1px 6px; border: 1px solid var(--accent);
  background: var(--surface); border-radius: 3px; font-size: 12.5px; outline: none;
}
.hover-icon-btn {
  width: 18px; height: 18px; border-radius: 3px; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
}
.hover-icon-btn:hover { background: rgba(43, 42, 40, 0.08); color: var(--ink); }

.drop-indicator {
  height: 2px; background: var(--accent); margin: 1px 0 1px;
  margin-left: calc(8px + var(--depth, 0) * 14px);
  border-radius: 2px;
}

/* Trash pinned at the bottom of the tree. */
.tree-branch.trash-branch {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.tree-row.trash-row .icon,
.tree-row.trash-row .label { color: var(--ink-soft); }
.tree-row.trash-row.drop-target {
  background: rgba(176, 58, 46, 0.10);
  outline-color: var(--danger);
}
.tree-row.trash-row .hover-icon-btn:hover {
  color: var(--danger);
  background: rgba(176, 58, 46, 0.10);
}

/* ---------- MAIN ---------- */
.main {
  display: flex; flex-direction: column;
  background: var(--surface);
  min-width: 0;
  position: relative;
}
.topbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sidebar-toggle { display: none; }
.breadcrumb {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-soft);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.breadcrumb .crumb { white-space: nowrap; }
.breadcrumb .crumb.current { color: var(--ink); font-weight: 600; }
.breadcrumb .sep { color: var(--ink-faint); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 11px; color: var(--ink-soft); min-width: 90px; text-align: right; }
.ai-improve-btn { padding: 6px 8px; color: var(--accent); }
.ai-improve-btn:hover { color: var(--accent); background: rgba(56, 110, 184, 0.10); }
.ai-improve-btn.is-busy { opacity: 0.6; cursor: progress; }
.ai-improve-btn.is-busy svg { animation: ai-spin 1.1s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }

.editor-pane {
  flex: 1; overflow-y: auto; background: var(--surface); position: relative;
}
.editor-shell {
  max-width: 780px; margin: 0 auto;
  padding: 32px 56px 56px;
}
.note-title {
  width: 100%; border: 0; outline: none; background: transparent;
  font-size: 28px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 16px; color: var(--ink);
}
.note-title::placeholder { color: var(--ink-faint); }

/* QUILL OVERRIDES */
.quill-host { background: var(--surface); }
.ql-toolbar.ql-snow {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius);
  background: var(--paper);
  margin-bottom: 12px;
  padding: 6px 8px;
}
.ql-container.ql-snow {
  border: 0 !important;
  font-size: 14.5px;
  font-family: inherit;
}
.ql-editor {
  padding: 0; min-height: 320px;
  line-height: 1.65; color: var(--ink);
}
.ql-editor h1 { font-size: 22px; margin: 18px 0 10px; }
.ql-editor h2 { font-size: 18px; margin: 16px 0 8px; }
.ql-editor h3 { font-size: 15px; margin: 14px 0 6px; }
.ql-editor blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 12px 0; color: var(--ink-soft);
}
.ql-editor .note-link {
  color: var(--accent);
  text-decoration: underline; text-decoration-style: dotted;
  font-weight: 600;
}
.ql-editor .note-link.unresolved {
  color: var(--danger);
  text-decoration-style: wavy;
}

/* ---------- TABLES ---------- */
.ql-editor table,
.view-body table {
  border-collapse: collapse;
  margin: 12px 0;
  width: auto;
  table-layout: auto;
}
.ql-editor td,
.view-body td {
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  min-width: 64px;
  vertical-align: top;
}
.ql-editor td:focus-within {
  background: var(--accent-soft);
}

/* Insert-size picker (10×10 hover grid) */
.table-picker {
  position: absolute;
  z-index: 60;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
}
.table-picker[hidden] { display: none; }
.table-picker-grid {
  display: grid;
  grid-template-columns: repeat(10, 18px);
  grid-template-rows: repeat(10, 18px);
  gap: 2px;
}
.table-picker-cell {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 2px;
  cursor: pointer;
}
.table-picker-cell.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.table-picker-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

/* Floating per-cell action toolbar */
.table-tools {
  position: absolute;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.table-tools[hidden] { display: none; }
.table-tools button {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 3px;
  padding: 4px 6px;
  font: 600 11px/1 var(--mono, ui-monospace, monospace);
  color: var(--ink);
  cursor: pointer;
}
.table-tools button:hover { background: var(--accent-soft); }
.table-tools button.danger { color: var(--danger); }
.table-tools button.danger:hover { background: rgba(220, 60, 60, 0.12); }
.table-tools-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 2px 4px;
}

/* ---------- VIEW MODE ---------- */
.note-view {
  max-width: 780px; margin: 0 auto;
  padding: 32px 56px 56px;
}
.view-title {
  font-size: 28px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 6px; color: var(--ink); line-height: 1.25;
}
.view-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  font-size: 12px; color: var(--ink-soft);
  margin-bottom: 18px;
}
.view-meta-sep { color: var(--line-strong); }
.note-tabs {
  display: flex; gap: 2px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
}
.note-tabs[hidden] { display: none; }
.note-tab {
  appearance: none; background: transparent; border: 0;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--ink-soft); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.note-tab:hover { color: var(--ink); }
.note-tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.note-tabs-action { margin-left: auto; font-size: 11px; align-self: center; }
.view-body {
  font-size: 14.5px; line-height: 1.65; color: var(--ink);
  min-height: 160px;
}
.view-body p { margin: 8px 0; }
.view-body h1 { font-size: 22px; margin: 18px 0 10px; }
.view-body h2 { font-size: 18px; margin: 16px 0 8px; }
.view-body h3 { font-size: 15px; margin: 14px 0 6px; }
.view-body ul, .view-body ol { margin: 8px 0; padding-left: 24px; }
.view-body li { margin: 2px 0; }
/* Quill 2 stores both bullet and numbered lists as <ol data-list="…">;
   keep view-mode markers consistent with edit-mode. */
.view-body ol[data-list="bullet"] { list-style-type: disc; }
.view-body ol[data-list="ordered"] { list-style-type: decimal; }
.view-body li[data-list="bullet"] { list-style-type: disc; }
.view-body li[data-list="ordered"] { list-style-type: decimal; }
.view-body .ql-ui { display: none; }
.view-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; margin: 12px 0; color: var(--ink-soft);
}
.view-body pre, .view-body code {
  font-family: var(--mono); font-size: 13px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px;
}
.view-body code { padding: 0 4px; }
.view-body pre { padding: 10px 12px; overflow-x: auto; }
.view-body pre code { border: 0; padding: 0; background: transparent; }
.view-body a { color: var(--accent); text-decoration: underline; text-decoration-color: var(--line-strong); }
.view-body a:hover { text-decoration-color: var(--accent); }
.view-body .wiki-link {
  color: var(--accent); font-weight: 600;
  text-decoration: underline; text-decoration-style: dotted;
}
.view-body .wiki-link:hover { background: var(--accent-soft); border-radius: 3px; }
.view-body .wiki-link.unresolved {
  color: var(--danger);
  text-decoration-style: wavy;
  cursor: help;
}
.view-body .view-empty { color: var(--ink-soft); font-style: italic; }
.view-body img { max-width: 100%; height: auto; cursor: zoom-in; }

/* ---------- IMAGE LIGHTBOX ---------- */
.image-lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10, 12, 16, 0.92);
  display: flex; flex-direction: column;
  user-select: none;
}
.image-lightbox[hidden] { display: none; }
.image-lightbox-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.35);
  color: #f4f4f5;
}
.image-lightbox-btn {
  width: 32px; height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f4f5;
  border-radius: 6px;
  font-size: 16px; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.image-lightbox-btn:hover { background: rgba(255, 255, 255, 0.18); }
.image-lightbox-zoom {
  min-width: 56px; text-align: center;
  font-size: 13px; font-variant-numeric: tabular-nums;
  color: #d4d4d8;
}
.image-lightbox-close { margin-left: auto; }
.image-lightbox-stage {
  flex: 1; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
}
.image-lightbox-stage.dragging { cursor: grabbing; }
.image-lightbox-img {
  max-width: 100%; max-height: 100%;
  transform-origin: center center;
  transition: transform 80ms ease-out;
  pointer-events: none;
  -webkit-user-drag: none;
}
.image-lightbox-stage.dragging .image-lightbox-img { transition: none; }

/* ---------- ATTACHMENTS ---------- */
.quill-host.drop-files {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  background: var(--accent-soft);
}
.view-body .attachment-chip,
.ql-editor a[href^="/attachments/"] {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin: 2px 4px 2px 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.2;
  vertical-align: middle;
  max-width: 100%;
}
.view-body .attachment-chip:hover,
.ql-editor a[href^="/attachments/"]:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}
.view-body .attachment-chip .att-icon { color: var(--ink-soft); display: inline-flex; }
.view-body .attachment-chip.is-pdf .att-icon { color: var(--danger); }
.view-body .attachment-chip .att-name { font-weight: 600; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-body .attachment-chip .att-size { color: var(--ink-soft); font-size: 11px; }
.view-body .attachment-chip .att-action {
  margin-left: 4px; padding: 2px 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; color: var(--accent);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 24px; color: var(--ink-soft); gap: 12px;
  height: 100%;
}
.empty-state h2 { color: var(--ink); font-size: 18px; }
.empty-state[hidden] { display: none; }

.empty-row {
  font-size: 12px; color: var(--ink-soft);
  padding: 10px 16px;
}

/* ---------- LINKS PANEL ---------- */
.links-panel {
  background: var(--paper); border-left: 1px solid var(--line-strong);
  display: flex; flex-direction: column; min-width: 0;
}
.links-panel[hidden] { display: none; }
.links-panel-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.links-panel-body { flex: 1; overflow-y: auto; }
.links-section + .links-section { border-top: 1px solid var(--line-strong); }
.links-section-head {
  padding: 12px 16px 6px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.links-section-head strong { font-size: 12px; letter-spacing: 0.3px; color: var(--ink); }
.links-section-sub { color: var(--ink-soft); font-size: 11px; }
.links-section-body { padding-bottom: 6px; }
.link-card {
  padding: 10px 16px; border-top: 1px solid var(--line);
  cursor: pointer; display: block;
}
.link-card:first-child { border-top: 0; }
.link-card:hover { background: var(--surface); text-decoration: none; }
.link-card.unresolved { opacity: 0.7; }
.link-card .lc-title { font-size: 12.5px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.link-card.unresolved .lc-title { color: var(--danger); }
.link-card .lc-folder { font-size: 10px; color: var(--ink-soft); margin-top: 2px; }
.link-card .lc-tag {
  margin-left: auto; font-size: 9px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.8px;
}

/* ---------- PICKER ---------- */
.picker {
  position: fixed; z-index: 50; width: 340px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.picker[hidden] { display: none; }
.picker-head {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; color: var(--ink-soft);
  font-size: 11.5px;
}
.picker-query { color: var(--accent); font-weight: 700; }
.picker-hint { margin-left: auto; font-size: 10px; color: var(--ink-faint); }
.picker-list { list-style: none; max-height: 280px; overflow-y: auto; }
.picker-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; border-left: 2px solid transparent;
}
.picker-item:hover, .picker-item.active {
  background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent);
}
.picker-item .pi-title { font-weight: 500; font-size: 12.5px; }
.picker-item.active .pi-title, .picker-item:hover .pi-title { font-weight: 700; }
.picker-item .pi-folder { font-size: 10px; color: var(--ink-soft); }
.picker-item.create {
  border-top: 1px dashed var(--line); color: var(--accent); font-weight: 600;
}

/* ---------- CONTEXT MENU ---------- */
.ctx-menu {
  position: fixed; z-index: 60;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  list-style: none; min-width: 180px; padding: 6px 0;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu li {
  padding: 6px 12px; cursor: pointer;
  font-size: 12px; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.ctx-menu li:hover { background: var(--accent-soft); color: var(--accent); }
.ctx-menu li .kbd { font-family: var(--mono); font-size: 10px; color: var(--ink-soft); }
.ctx-menu li.danger { color: var(--danger); }
.ctx-menu li.danger:hover { background: rgba(176, 58, 46, 0.08); color: var(--danger); }
.ctx-menu .divider { height: 1px; background: var(--line); margin: 4px 0; padding: 0; pointer-events: none; }

/* ---------- SCRIM (mobile) ---------- */
.sidebar-scrim {
  display: none;
  position: fixed; inset: 0; z-index: 30;
  background: rgba(43, 42, 40, 0.42); border: 0; padding: 0;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace.has-links { grid-template-columns: 1fr; }
  .sidebar-resizer { display: none; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: min(300px, 86vw); z-index: 40;
    transform: translateX(-100%); transition: transform 200ms ease;
    box-shadow: var(--shadow-pop);
  }
  .workspace.sidebar-open .sidebar { transform: translateX(0); }
  .workspace.sidebar-open .sidebar-scrim { display: block; }
  .sidebar-toggle { display: inline-flex; }
  .editor-shell { padding: 22px 18px 56px; }
  .note-view { padding: 22px 18px 56px; }
  .note-title, .view-title { font-size: 22px; }
  .links-panel {
    position: fixed; inset: 0; z-index: 50;
    border-left: 0; border-top: 1px solid var(--line-strong);
  }
  .topbar { padding: 10px 16px; }
  .save-status { display: none; }
}

@media (max-width: 480px) {
  .editor-shell { padding: 16px 14px 56px; }
  .note-view { padding: 16px 14px 56px; }
  .topbar-actions .ghost-btn { padding: 6px 8px; font-size: 12px; }
  .picker { width: calc(100vw - 24px); left: 12px !important; }
}
