/* ============================================================
   Inkwell — notes app (UI v2.1)
   Requires assets/tokens.css to be loaded FIRST (shared design
   tokens + dual theme). Every selector from v1 is preserved.
   ============================================================ */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }

/* focus ring — accessibility, applies everywhere */
:where(button, input, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

button {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r); padding: 5px 10px; cursor: pointer; font: inherit; font-size: 13px;
  transition: background var(--t), border-color var(--t), color var(--t), transform var(--t);
  line-height: 1.4;
}
button:hover { background: var(--elevated); border-color: var(--accent-line); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
  box-shadow: var(--sh-1);
}
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
button.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

input, textarea {
  background: var(--bg2); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r); padding: 7px 11px; font: inherit; outline: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--fg-faint); }

kbd {
  background: var(--bg3); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: var(--r-sm); padding: 1.5px 6px; font-size: 12px; font-family: var(--mono);
  color: var(--fg-dim);
}
code { font-family: var(--mono); background: var(--bg3); padding: 1.5px 5px; border-radius: var(--r-sm); font-size: .9em; }

/* ---------- auth ---------- */
.auth-wrap {
  display: grid; place-items: center; min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.auth-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: 40px 44px; width: 350px; display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: var(--sh-3);
}
.auth-logo { font-size: 44px; color: var(--accent); line-height: 1; }
.auth-card h1 { margin: 0; font-size: 27px; letter-spacing: .4px; font-weight: 650; }
.auth-sub { margin: 0 0 6px; color: var(--fg-dim); font-size: 13.5px; }
.auth-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }
.auth-back { color: var(--fg-dim); font-size: 13px; text-decoration: none; transition: color var(--t); }
.auth-back:hover { color: var(--accent); }
.auth-card button { padding: 10px; }

/* ---------- layout ---------- */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: var(--sb-w); min-width: var(--sb-w); max-width: var(--sb-w);
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
#mainPane { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- sidebar resizer (NEW) ---------- */
#sbResize {
  width: 6px; flex: 0 0 6px; cursor: col-resize; background: transparent;
  position: relative; z-index: 5; margin-left: -3px; margin-right: -3px;
  transition: background var(--t);
}
#sbResize::after {
  content: ''; position: absolute; inset: 0 2px;
  background: transparent; border-radius: 2px; transition: background var(--t);
}
#sbResize:hover::after, #sbResize:focus-visible::after { background: var(--accent-line); }
#sbResize.dragging::after { background: var(--accent); }
body.sb-resizing { cursor: col-resize; user-select: none; }
body.sb-resizing * { cursor: col-resize !important; }

/* ---------- editor ⇄ reading divider (NEW) ---------- */
#paneResize { display: none; }
#editorWrap.mode-split #paneResize {
  display: block; flex: 0 0 6px; width: 6px; cursor: col-resize;
  position: relative; z-index: 4; margin: 0 -3px; background: transparent;
}
#paneResize::after {
  content: ''; position: absolute; inset: 0 2px; border-radius: 2px;
  background: transparent; transition: background var(--t);
}
/* Read mode: same handle, pinned to the right edge of the centred column.
   Dragging widens/narrows the measure symmetrically. */
#editorWrap.mode-view #paneResize {
  display: block; position: absolute; top: 0; bottom: 0; width: 10px; flex: none; margin: 0;
  left: calc(50% + min(var(--read-w), 100% - 24px) / 2 - 5px);
  cursor: col-resize; z-index: 4;
}
#editorWrap.mode-view #paneResize::after { inset: 0 4px; }
/* read mode has no border to hint at, so show a faint grip that
   brightens on hover — otherwise the handle is undiscoverable */
#editorWrap.mode-view #paneResize::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 3px; height: 44px; margin: -22px 0 0 -1.5px; border-radius: 3px;
  background: var(--border); transition: background var(--t), height var(--t);
}
#editorWrap.mode-view #paneResize:hover::before { background: var(--accent); height: 72px; margin-top: -36px; }
#editorWrap.mode-view #paneResize.dragging::before { background: var(--accent); }
#paneResize:hover::after, #paneResize:focus-visible::after { background: var(--accent-line); }
#paneResize.dragging::after { background: var(--accent); }

/* ---------- sidebar ---------- */
.sb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 12px 9px; gap: 8px;
}
.sb-logo {
  font-weight: 700; color: var(--accent); font-size: 15px; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-actions { display: flex; gap: 3px; flex-shrink: 0; }
.sb-actions button { padding: 4px 7px; font-size: 13px; background: transparent; border-color: transparent; }
.sb-actions button:hover { background: var(--bg3); border-color: var(--border); }
.sb-search { padding: 0 12px 9px; }
.sb-search input { width: 100%; font-size: 13.5px; padding: 6px 11px; }
#searchResults {
  max-height: 40vh; overflow-y: auto;
  border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border);
}
.sr { padding: 8px 14px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border-soft); transition: background var(--t); }
.sr:hover { background: var(--bg3); }
.sr b { display: block; font-weight: 600; }
.sr span { color: var(--fg-dim); font-size: 12px; display: block; margin-top: 2px; }
.sr.none { color: var(--fg-dim); cursor: default; }
.sb-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.1px; font-weight: 600;
  color: var(--fg-faint); padding: 12px 14px 5px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}

/* tools that live inside a section label (wrap / collapse-all) */
.sb-label-tools { display: flex; gap: 2px; }
.sb-label-tools button {
  background: transparent; border-color: transparent; color: var(--fg-faint);
  padding: 1px 5px; font-size: 12px; line-height: 1; border-radius: var(--r-sm);
}
.sb-label-tools button:hover { background: var(--bg3); color: var(--fg-dim); border-color: var(--border); }
.sb-label-tools button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

#tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 6px 10px; }
#tree.droproot { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: var(--r); }
.tree-level { list-style: none; margin: 0; padding-left: 0; }
/* tighter indent + guide rail so deep trees stay readable */
.tree-level .tree-level {
  padding-left: 12px; margin-left: 6px;
  border-left: 1px solid var(--border-soft);
}
.tree-level .tree-level:hover { border-left-color: var(--border); }

.tree-row {
  display: flex; align-items: center; gap: 5px; padding: 4.5px 8px; border-radius: var(--r-sm);
  cursor: pointer; font-size: 13.5px; user-select: none; white-space: nowrap;
  position: relative; transition: background var(--t), color var(--t);
}
.tree-row:hover { background: var(--bg3); }
.tree-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-row.active::before {
  content: ''; position: absolute; left: 0; top: 15%; bottom: 15%;
  width: 2.5px; border-radius: 0 2px 2px 0; background: var(--accent);
}
.tree-row.dropover { outline: 2px dashed var(--accent); outline-offset: -2px; }
.tree-row.colored { box-shadow: inset 3px 0 0 var(--nc); }
.tree-row.colored .ticon, .tree-row.colored .tlabel { color: var(--nc); }
.tree-row.colored.active { box-shadow: inset 3px 0 0 var(--nc); }
.tree-row.editing { padding: 2px 8px; }
.tree-row.editing:hover { background: none; }
.inline-input {
  flex: 1; min-width: 0; font-size: 13px; padding: 3px 8px;
  border-radius: var(--r-sm); border-color: var(--accent);
}
.twisty { width: 13px; color: var(--fg-faint); font-size: 10px; flex-shrink: 0; transition: color var(--t); }
.tree-row:hover .twisty { color: var(--fg-dim); }
.ticon { flex-shrink: 0; font-size: 13px; opacity: .8; }
.tlabel { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* optional wrap mode — toggled from the sidebar header */
#tree.wrap .tree-row { white-space: normal; align-items: flex-start; }
#tree.wrap .tlabel { overflow: visible; text-overflow: clip; word-break: break-word; }
#tree.wrap .twisty, #tree.wrap .ticon { margin-top: 1px; }

.badge { font-size: 11px; color: var(--accent2); }
.badge:not(.pub) { color: var(--warn); }
#pinnedList .tree-row .ticon { color: var(--warn); }
/* Tags must never squeeze the Notes tree out of the sidebar.
   #tree has overflow:auto so its automatic min-height is 0 and it happily
   shrinks to nothing; #tagWrap had overflow:visible, so its min-height resolved
   to its content and it refused to shrink at all. A long tag list therefore ate
   the whole column. Now the section is capped and scrolls internally, and the
   tree keeps a floor. */
#tagWrap {
  flex: 0 0 auto; display: flex; flex-direction: column; min-height: 0;
  max-height: min(34vh, 240px); border-top: 1px solid var(--border);
}
#tagWrap.collapsed { max-height: none; }
#tagWrap.collapsed #tagList { display: none; }
#tagList { padding: 4px 12px 10px; display: flex; flex-wrap: wrap; gap: 5px;
           overflow-y: auto; overflow-x: hidden; min-height: 0; }
/* long tags (imported headings can be 50+ chars) must not force a wide row */
#tagList .tagchip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tree { min-height: 96px; }
/* the Tags label doubles as the collapse toggle */
#tagWrap .sb-section-label { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
#tagWrap .sb-section-label:hover { color: var(--accent); }
#tagWrap .sb-section-label .caret { transition: transform var(--t); font-size: 9px; opacity: .7; }
#tagWrap.collapsed .sb-section-label .caret { transform: rotate(-90deg); }
#tagWrap .sb-section-label .count { margin-left: auto; opacity: .6; font-weight: 400; }
.tagchip {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 20px;
  padding: 2.5px 10px; font-size: 12px; cursor: pointer; color: var(--accent);
  transition: border-color var(--t), background var(--t);
}
.tagchip em { font-style: normal; color: var(--fg-faint); }
.tagchip:hover { border-color: var(--accent); background: var(--accent-soft); }
.sb-foot {
  border-top: 1px solid var(--border); padding: 9px 12px; display: flex; gap: 6px; align-items: center;
  background: var(--panel);
}
.sb-foot a { color: var(--fg-dim); text-decoration: none; font-size: 13px; transition: color var(--t); }
.sb-foot a:hover { color: var(--accent); }
.sb-foot button { background: transparent; border-color: transparent; }
.sb-foot button:hover { background: var(--bg3); border-color: var(--border); }
.sb-foot button:last-child { margin-left: auto; }

/* ---------- welcome ---------- */
#welcome { flex: 1; display: grid; place-items: center; }
.welcome-inner { text-align: center; color: var(--fg-dim); max-width: 520px; padding: 20px; }
.welcome-logo { font-size: 62px; color: var(--accent); opacity: .5; line-height: 1; }
.welcome-inner h2 { color: var(--fg); margin: 14px 0 6px; font-weight: 650; }
.hints { margin-top: 26px; font-size: 13px; line-height: 2.3; }

/* ---------- editor ---------- */
#editorWrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#noteBar { display: flex; align-items: center; gap: 10px; padding: 12px 18px 6px; }
#noteTitle {
  flex: 1; min-width: 0; font-size: 22px; font-weight: 700; background: transparent;
  border: none; padding: 2px 4px; letter-spacing: -.2px;
}
#noteTitle:focus { border: none; box-shadow: 0 2px 0 var(--accent); border-radius: 0; }
.notebar-actions { display: flex; gap: 4px; flex-shrink: 0; }
.notebar-actions button { font-size: 14px; padding: 5px 9px; background: transparent; border-color: transparent; }
.notebar-actions button:hover { background: var(--bg3); border-color: var(--border); }
#toolbar {
  display: flex; align-items: center; gap: 3px; padding: 5px 18px 9px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
#toolbar button { padding: 4px 8px; font-size: 13px; min-width: 30px; background: transparent; border-color: transparent; }
#toolbar button:hover { background: var(--bg3); border-color: var(--border); }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.tb-flex { flex: 1; }
#panes { flex: 1; display: flex; overflow: hidden; min-height: 0; position: relative; }
/* split mode: editor gets a draggable share, preview takes the rest */
#editorWrap.mode-split #editor { flex: 0 0 var(--editor-basis); }
#editorWrap.mode-split #preview { flex: 1 1 auto; }
#editor {
  flex: 1; min-width: 0; border: none; border-radius: 0; resize: none; padding: 20px 24px;
  font-family: var(--mono); font-size: 14px; line-height: 1.7; background: var(--bg);
  box-shadow: none;
}
#editor:focus { box-shadow: none; }
#preview {
  flex: 1; min-width: 0; overflow-y: auto; padding: 20px 28px;
  border-left: 1px solid var(--border); background: var(--bg2);
}
#editorWrap.mode-edit #preview { display: none; }
#editorWrap.mode-view #editor { display: none; }
#editorWrap.mode-view #preview {
  border-left: none; margin: 0 auto; width: 100%; padding: 30px 40px 80px;
  max-width: min(var(--read-w), 100% - 24px);
  background: var(--bg);
}
#editorWrap.mode-view #panes { background: var(--bg); }
#editorWrap.mode-view #toolbar [data-md],
#editorWrap.mode-view #btnDraw,
#editorWrap.mode-view #btnImage,
#editorWrap.mode-view .tb-sep { display: none; }
#modeSwitch { display: flex; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
#modeSwitch button { border: none; border-radius: 0; padding: 4px 11px; background: transparent; }
#modeSwitch button + button { border-left: 1px solid var(--border); }
#modeSwitch button.on { background: var(--accent-soft); color: var(--accent); }
#statusBar {
  display: flex; gap: 18px; padding: 6px 18px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--fg-dim); background: var(--panel);
}
#saveState { color: var(--accent2); }
#backlinksPanel {
  border-top: 1px solid var(--border); padding: 9px 18px; max-height: 120px; overflow-y: auto;
  background: var(--panel);
}
.bl-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.1px; font-weight: 600; color: var(--fg-faint); margin-bottom: 6px; }
#backlinksList a { display: inline-block; margin-right: 14px; color: var(--accent); cursor: pointer; font-size: 13px; }
#backlinksList a:hover { text-decoration: underline; }

/* ---------- markdown content ---------- */
.md-content { font-size: 15.5px; line-height: 1.72; }
.md-content > *:first-child { margin-top: 0; }
.md-content h1, .md-content h2, .md-content h3 {
  border-bottom: 1px solid var(--border); padding-bottom: 6px;
  margin-top: 1.6em; margin-bottom: .6em; letter-spacing: -.2px; font-weight: 650;
}
.md-content h4, .md-content h5, .md-content h6 { margin-top: 1.4em; margin-bottom: .5em; font-weight: 650; }
.md-content h1 { font-size: 1.75em; }
.md-content h2 { font-size: 1.4em; }
.md-content h3 { font-size: 1.15em; border-bottom: none; }
.md-content a { color: var(--accent); text-underline-offset: 2px; }
.md-content blockquote {
  margin: 1em 0; padding: 8px 16px; border-left: 3px solid var(--accent);
  color: var(--fg-dim); background: var(--accent-soft);
  border-radius: 0 var(--r) var(--r) 0;
}
.md-content blockquote > *:first-child { margin-top: 0; }
.md-content blockquote > *:last-child { margin-bottom: 0; }
.md-content pre {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r);
  padding: 13px 15px; overflow-x: auto; line-height: 1.6;
}
:root[data-theme="light"] .md-content pre { background: #f6f7f9; }
.md-content pre code { background: none; padding: 0; font-size: 13.5px; }
.md-content table { border-collapse: collapse; margin: 14px 0; display: block; overflow-x: auto; max-width: 100%; }
.md-content th, .md-content td { border: 1px solid var(--border); padding: 7px 13px; }
.md-content th { background: var(--bg3); font-weight: 650; text-align: left; }
.md-content tr:nth-child(even) { background: var(--bg2); }
.md-content img { max-width: 100%; border-radius: var(--r); }
.md-content img.editable-draw { cursor: pointer; border: 1px solid var(--border); transition: border-color var(--t); }
.md-content img.editable-draw:hover { border-color: var(--accent); }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }
.md-content input[type="checkbox"] { accent-color: var(--accent2); cursor: pointer; margin-right: 4px; }
.md-content ul, .md-content ol { padding-left: 1.5em; }
.md-content li { margin: .25em 0; }
.wikilink { color: var(--accent2); cursor: pointer; border-bottom: 1px dashed var(--accent2); }
.wikilink.missing { color: var(--fg-dim); border-bottom-color: var(--fg-dim); }
.wikilink:hover { filter: brightness(1.2); }
.pv-tag { color: var(--accent); background: var(--accent-soft); border-radius: 12px; padding: .5px 8px; font-size: .88em; }

/* ---------- context menu / toast ---------- */
.ctxmenu {
  position: fixed; z-index: 100; background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 5px; min-width: 190px; box-shadow: var(--sh-2);
}
.ctxitem { padding: 7px 12px; border-radius: var(--r-sm); cursor: pointer; font-size: 13.5px; transition: background var(--t); }
.ctxitem:hover { background: var(--bg3); }
.ctx-colors { display: flex; gap: 6px; padding: 9px 12px 7px; margin-top: 4px; border-top: 1px solid var(--border); }
.ctx-swatch {
  width: 17px; height: 17px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-sizing: border-box; transition: transform var(--t);
}
.ctx-swatch:hover { transform: scale(1.18); }
.ctx-swatch.active { border-color: var(--fg); }
.ctx-swatch.none { background: transparent; border: 1px solid var(--fg-dim); position: relative; }
.ctx-swatch.none::after {
  content: ''; position: absolute; left: 1px; right: 1px; top: 6px; height: 1px;
  background: var(--danger); transform: rotate(-45deg);
}
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(90px);
  background: var(--elevated); border: 1px solid var(--accent); color: var(--fg);
  padding: 10px 18px; border-radius: var(--r-lg); font-size: 13.5px; z-index: 200;
  transition: transform .28s var(--ease), opacity .28s var(--ease); max-width: 80vw;
  box-shadow: var(--sh-2); opacity: 0;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.err { border-color: var(--danger); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 50; display: grid; place-items: center;
  animation: modalIn .16s var(--ease);
}
@keyframes modalIn { from { opacity: 0 } to { opacity: 1 } }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--sh-3); overflow: hidden;
  animation: boxIn .18s var(--ease);
}
@keyframes boxIn { from { transform: translateY(8px) scale(.99); opacity: .6 } to { transform: none; opacity: 1 } }

/* drawing */
.draw-box { padding: 12px; }
.draw-toolbar { display: flex; align-items: center; gap: 5px; padding: 2px 2px 11px; flex-wrap: wrap; }
#drawCanvas {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r);
  max-width: calc(96vw - 24px); max-height: 78vh; touch-action: none; cursor: crosshair; display: block;
}
.dcolor { width: 22px; height: 22px; border-radius: 50%; padding: 0; border: 2px solid transparent; margin: 0 1px; }
.dcolor.active { border-color: var(--fg); }
.dtool.active { background: var(--accent-soft); border-color: var(--accent-line); }
#drawSize { width: 90px; accent-color: var(--accent); }

/* quick switcher */
.qs-box { width: 520px; max-width: 92vw; padding: 12px; }
#qsInput { width: 100%; font-size: 16px; margin-bottom: 9px; padding: 10px 12px; }
#qsList { max-height: 46vh; overflow-y: auto; }
.qs-item {
  display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: var(--r);
  cursor: pointer; font-size: 14px; transition: background var(--t);
}
.qs-item em { color: var(--fg-dim); font-style: normal; font-size: 12px; white-space: nowrap; }
.qs-item:hover, .qs-item.sel { background: var(--accent-soft); color: var(--accent); }
.qs-item.none { color: var(--fg-dim); cursor: default; }

/* graph */
.graph-box { width: 88vw; height: 84vh; padding: 14px; display: flex; flex-direction: column; }
.graph-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 10px; color: var(--fg-dim); font-size: 14px;
}
#graphCanvas { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r); cursor: grab; }

/* history */
.hist-box { width: 820px; max-width: 94vw; padding: 14px; display: flex; flex-direction: column; max-height: 84vh; }
.hist-cols { display: flex; gap: 12px; flex: 1; min-height: 300px; overflow: hidden; }
#histList { width: 240px; overflow-y: auto; border-right: 1px solid var(--border); padding-right: 8px; }
.hist-item {
  padding: 8px 10px; border-radius: var(--r); cursor: pointer; font-size: 13px;
  display: flex; justify-content: space-between; gap: 8px; transition: background var(--t);
}
.hist-item em { color: var(--fg-dim); font-style: normal; font-size: 11px; }
.hist-item:hover, .hist-item.sel { background: var(--accent-soft); color: var(--accent); }
.hist-item.none { color: var(--fg-dim); cursor: default; }
#histPreview {
  flex: 1; overflow: auto; margin: 0; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r); padding: 13px; font-family: var(--mono); font-size: 13px; white-space: pre-wrap;
}
.hist-foot { padding-top: 12px; text-align: right; }

/* trash */
.trash-box { width: 580px; max-width: 94vw; padding: 14px; max-height: 76vh; display: flex; flex-direction: column; }
#trashList { overflow-y: auto; }
.trash-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid var(--border-soft); font-size: 14px;
}
.trash-item.none { color: var(--fg-dim); }
.trash-item button { font-size: 12px; }

/* ---------- scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); background-clip: content-box; }

/* ---------- mobile ---------- */
@media (max-width: 780px) {
  /* override the *variable*, not the width — otherwise resizing silently
     stops working and any persisted width is ignored. */
  :root { --sb-w: 232px; }
  #panes { flex-direction: column; }
  /* stacked: the same flex-basis variable now drives height */
  #editorWrap.mode-split #paneResize {
    width: auto; height: 10px; flex: 0 0 10px; cursor: row-resize; margin: -3px 0;
  }
  #editorWrap.mode-split #paneResize::after { inset: 4px 0; }
  #preview { border-left: none; border-top: 1px solid var(--border); }
  #noteBar, #toolbar, #statusBar, #backlinksPanel { padding-left: 12px; padding-right: 12px; }
}

/* coarse pointers (touch) need a larger grab target than 6px */
@media (pointer: coarse) {
  #sbResize { width: 16px; flex-basis: 16px; margin-left: -8px; margin-right: -8px; }
  #sbResize::after { inset: 0 6px; }
  #editorWrap.mode-split #paneResize { width: 16px; flex-basis: 16px; margin: 0 -8px; }
  #paneResize::after { inset: 0 6px; }
}
