/* ============ collapsible sidebar (desktop) ============ */
:root { --sb-w: 252px; --sb-rail: 62px; --sb-ease: cubic-bezier(.32, .72, 0, 1); }

@media (min-width: 821px) {
  .sidebar-slot { position: relative; width: var(--sb-w); transition: width 420ms var(--sb-ease); z-index: 20; }
  .sb-collapsed .sidebar-slot { width: var(--sb-rail); }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: var(--sb-w); transition: width 420ms var(--sb-ease); }
  .sb-collapsed .sidebar { width: var(--sb-rail); scrollbar-width: none; }
  .sb-collapsed .sidebar::-webkit-scrollbar { display: none; }

  /* Everything except the icons fades while the rail is slim. */
  .sidebar :is(.label, .count, .brand-name, .search-btn span, .search-btn kbd, .nav-section > *, .tree-acts, .tree-tog, .live-dot) {
    transition: opacity 220ms var(--ease) 120ms; }
  .sb-collapsed .sidebar :is(.label, .count, .brand-name, .search-btn span, .search-btn kbd, .nav-section > *, .tree-acts, .tree-tog, .live-dot) {
    opacity: 0; pointer-events: none; transition: opacity 120ms var(--ease); }
  .sidebar .nav-item { transition: background var(--t), color var(--t), padding 420ms var(--sb-ease); }
  .sb-collapsed .sidebar .nav-item { padding-left: 10px; }
  .sb-collapsed .sidebar .nav-empty { opacity: 0; }
  .nav-section { position: relative; }
  .nav-section::after { content: ""; position: absolute; left: 12px; right: 12px; top: 58%; border-top: 1px solid var(--line-2); opacity: 0; transition: opacity 200ms; }
  .sb-collapsed .sidebar .nav-section::after { opacity: 1; }

  /* In the rail, the open arrows sit on top of the logo and show when you hover it. */
  .brand-row { position: relative; }
  .sb-collapsed .sb-toggle { position: absolute; left: 4px; top: 2px; width: 32px; height: 32px; border-radius: 9px; opacity: 0; transition: opacity 160ms var(--ease); }
  .sb-collapsed .brand-row:hover .sb-toggle, .sb-collapsed .sb-toggle:focus-visible { opacity: 1; background: var(--surface-2); color: var(--text); }
  .sb-collapsed .logo { transition: opacity 160ms var(--ease); }
  .sb-collapsed .brand-row:hover .logo { opacity: 0; }
}
.sb-toggle { flex: none; }

/* ============ page tree ============ */
.tree-row { position: relative; }
.tree-row.dragging { opacity: .45; }
.nav-item.page { cursor: pointer; }
.tree-ic { position: relative; flex: none; width: 18px; height: 18px; display: grid; place-items: center; color: var(--dim); }
.tree-ic .emoji { width: auto; font-size: 15px; line-height: 1; transition: opacity 120ms; }
.tree-ic > .ic { transition: opacity 120ms; }
.tree-tog { position: absolute; inset: -3px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); opacity: 0; transition: opacity 120ms, background var(--t); }
.tree-tog:hover { background: var(--line); color: var(--text); }
.tree-tog .ic { transition: transform 240ms var(--ease); }
.tree-tog.open .ic { transform: rotate(90deg); }
.nav-item.page:hover .tree-tog, .tree-tog:focus-visible { opacity: 1; }
.nav-item.page:hover .tree-ic:has(.tree-tog) .emoji, .nav-item.page:hover .tree-ic:has(.tree-tog) > .ic { opacity: 0; }
.tree-acts { display: none; align-items: center; margin-right: -6px; }
.nav-item.page:hover .tree-acts, .tree-acts:focus-within { display: flex; }
.nav-item.page:hover .count { display: none; }
.icon-btn.xs { width: 22px; height: 22px; border-radius: 6px; }
.icon-btn.xs:hover { background: var(--line); }
.tree-row.drop-before > .nav-item { box-shadow: inset 0 2px 0 var(--accent); border-radius: 0; }
.tree-row.drop-after > .nav-item { box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.tree-row.drop-inside > .nav-item { background: var(--accent-soft); color: var(--text); }
.nav-section.drop-root { color: var(--accent); }
#favs .nav { margin-bottom: 2px; }

/* ============ topbar: breadcrumbs + page actions ============ */
.top-crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; font-size: 14px; color: var(--muted); }
.top-crumbs a { display: inline-flex; align-items: center; gap: 6px; padding: 4px 7px; border-radius: 7px; min-width: 0; max-width: 220px; transition: background var(--t), color var(--t); }
.top-crumbs a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-crumbs a:hover { background: var(--surface-2); color: var(--text); }
.top-crumbs a.here { color: var(--text); font-weight: 600; }
.top-crumbs .emoji { font-size: 14px; }
.top-crumbs .sep { color: var(--dim); }
.top-actions { display: flex; align-items: center; gap: 2px; }
.top-actions .edited { font-size: 13px; color: var(--dim); margin-right: 6px; white-space: nowrap; }
.top-actions .icon-btn.on { color: #e0a526; }
.top-actions .icon-btn.on svg { fill: currentColor; }
@media (max-width: 1000px) { .top-actions .edited { display: none; } }

/* ============ document ============ */
.doc { --doc-w: 740px; animation: rise 360ms var(--ease); }
.doc.wide { --doc-w: 1120px; }
.doc-cover { position: relative; height: clamp(150px, 24vh, 250px); border-radius: 18px; margin-top: 2px; }
.cover-actions { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px; opacity: 0; transition: opacity var(--t); }
.doc-cover:hover .cover-actions, .cover-actions:focus-within { opacity: 1; }
.cover-actions .btn { background: color-mix(in oklab, var(--surface) 86%, transparent); backdrop-filter: blur(8px); }
.doc-inner { max-width: var(--doc-w); margin: 0 auto; padding-left: 54px; transition: max-width 400ms var(--ease); }
.doc-head { position: relative; padding-top: 18px; }
.has-cover .doc-head { padding-top: 0; }
.has-cover .doc-tools { position: absolute; top: 10px; left: 96px; }
.doc-icon { display: grid; place-items: center; width: 84px; height: 84px; margin: 0 0 4px -6px; border-radius: 16px; font-size: 62px; line-height: 1; transition: background var(--t), transform 300ms var(--spring); }
.doc-icon:hover { background: var(--surface-2); }
.doc-icon:active { transform: scale(.94); }
.has-cover .doc-icon { margin-top: -46px; position: relative; }
.has-cover .doc-head:not(:has(.doc-icon)) { padding-top: 44px; }
.has-cover .doc-head:not(:has(.doc-icon)) .doc-tools { left: -8px; top: 8px; margin: 0; }
.doc-tools { display: flex; gap: 2px; height: 30px; margin-left: -8px; opacity: 0; transition: opacity 200ms; }
.doc-head:hover .doc-tools, .doc-tools:focus-within { opacity: 1; }
.doc-tools:empty { display: none; }
.doc-tools button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; font-size: 13px; color: var(--dim); transition: background var(--t), color var(--t); }
.doc-tools button:hover { background: var(--surface-2); color: var(--muted); }
.doc-title { font-size: clamp(32px, 4vw, 42px); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; outline: none; padding: 6px 0 4px; word-break: break-word; cursor: text; }
.doc-title:empty::before { content: attr(data-ph); color: var(--dim); opacity: .7; pointer-events: none; }
.doc-meta { font-size: 13px; color: var(--dim); margin-top: 4px; }
.doc-blocks { display: flex; flex-direction: column; padding: 14px 0 6px; }
.doc-tail { min-height: 28vh; cursor: text; }

/* ============ blocks ============ */
.blk { position: relative; display: flex; align-items: flex-start; margin: 1px 0 1px calc(var(--ind, 0) * 26px); border-radius: 6px; }
.blk-gutter { position: absolute; left: -52px; top: 3px; display: flex; opacity: 0; transition: opacity 140ms; }
.blk:hover > .blk-gutter { opacity: 1; }
.blk-btn { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--dim); cursor: pointer; transition: background 120ms, color 120ms; }
.blk-btn:hover { background: var(--surface-2); color: var(--muted); }
.grip { cursor: grab; }
.grip:active { cursor: grabbing; }
.blk-body { flex: 1; min-width: 0; }
.blk-text { outline: none; padding: 3px 2px; min-height: 1.6em; line-height: 1.65; word-break: break-word; white-space: pre-wrap; caret-color: var(--accent); }
.blk-text:empty::before { content: attr(data-ph); color: var(--dim); pointer-events: none; }
.t-text .blk-text:empty:not(:focus)::before { content: none; }
.blk.dragging { opacity: .35; }
.blk.drop-above::after, .blk.drop-below::after { content: ""; position: absolute; left: 0; right: 0; height: 3px; border-radius: 3px; background: var(--accent); opacity: .75; pointer-events: none; }
.blk.drop-above::after { top: -2px; }
.blk.drop-below::after { bottom: -2px; }

/* inline formatting */
.blk-text b, .blk-text strong { font-weight: 700; }
.blk-text code { font: .86em/1 ui-monospace, "Cascadia Code", Consolas, monospace; padding: 2px 5px; border-radius: 5px; background: var(--surface-2); color: #c25b52; }
[data-theme="dark"] .blk-text code { color: #ef8f86; }
.blk-text a { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--text) 35%, transparent); text-underline-offset: 3px; cursor: pointer; }
.blk-text a:hover { text-decoration-color: var(--accent); color: var(--accent-ink); }

/* headings */
.t-h1 { margin-top: 26px; }
.t-h2 { margin-top: 20px; }
.t-h3 { margin-top: 12px; }
.t-h1 .blk-text { font: 800 30px/1.3 var(--display); letter-spacing: -.025em; }
.t-h2 .blk-text { font: 700 23px/1.32 var(--display); letter-spacing: -.02em; }
.t-h3 .blk-text { font: 700 18.5px/1.38 var(--display); letter-spacing: -.01em; }
.t-h1 .blk-gutter { top: 10px; }
.t-h2 .blk-gutter { top: 6px; }
.t-h3 .blk-gutter { top: 3px; }
.blk:first-child.t-h1, .blk:first-child.t-h2, .blk:first-child.t-h3 { margin-top: 2px; }

/* to-do */
.blk-check { flex: none; width: 18px; height: 18px; margin: 6px 8px 0 3px; border-radius: 5px; border: 1.8px solid var(--line-2); display: grid; place-items: center; transition: background 180ms var(--ease), border-color 180ms, transform 200ms var(--spring); }
.blk-check:hover { border-color: var(--accent); }
.blk-check svg { width: 13px; height: 13px; fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset 240ms var(--ease) 40ms; }
.blk-check.on { background: var(--accent); border-color: var(--accent); animation: pop 340ms var(--spring); }
.blk-check.on svg { stroke-dashoffset: 0; }
.t-todo.checked .blk-text { color: var(--dim); text-decoration: line-through; text-decoration-color: color-mix(in oklab, var(--dim) 70%, transparent); }

/* lists */
.blk-bullet { flex: none; width: 24px; height: 28px; display: grid; place-items: center; }
.blk-bullet::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.blk-bullet[data-lvl="1"]::before { background: none; border: 1.5px solid currentColor; width: 5px; height: 5px; }
.blk-bullet[data-lvl="2"]::before { border-radius: 1px; width: 5px; height: 5px; }
.blk-num { flex: none; min-width: 24px; padding: 3px 6px 0 0; text-align: right; line-height: 1.65; font-variant-numeric: tabular-nums; color: var(--muted); }

/* toggle */
.blk-tog { flex: none; width: 24px; height: 24px; margin-top: 2px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); transition: background 120ms; }
.blk-tog:hover { background: var(--surface-2); }
.blk-tog .ic { transition: transform 240ms var(--ease); }
.blk-tog.open .ic { transform: rotate(90deg); }

/* quote, callout, code */
.t-quote .blk-body { border-left: 3px solid var(--text); padding-left: 14px; margin: 4px 0; }
.t-quote .blk-text { font-size: 17px; }
.t-callout { gap: 10px; padding: 12px 16px 12px 12px; margin-top: 6px; margin-bottom: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.t-callout .blk-gutter { top: 14px; left: -52px; }
.blk-callout-ic { flex: none; font-size: 20px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; transition: background 120ms; }
.blk-callout-ic:hover { background: var(--line); }
.t-code { margin: 6px 0; }
.t-code .blk-text { font: 13.5px/1.6 ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; tab-size: 2; overflow-x: auto; white-space: pre; }
.t-code .blk-gutter { top: 12px; }

/* divider, page link, focus ring for non-text blocks */
.blk-hr { padding: 11px 2px; outline: none; border-radius: 6px; cursor: default; }
.blk-hr hr { border: 0; border-top: 1px solid var(--line-2); }
.blk-focus:focus-visible, .blk-focus:focus { outline: none; background: var(--accent-soft); }
.blk-hr:focus hr { border-top-color: var(--accent); }
.blk-page { display: flex; align-items: center; gap: 8px; padding: 4px 6px; margin-left: -4px; border-radius: 7px; font-weight: 600; transition: background var(--t); outline: none; }
.blk-page:hover { background: var(--surface-2); }
.blk-page .emoji { font-size: 17px; }
.blk-page > .ic { color: var(--muted); }
.blk-page .u { text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 4px; }
.blk-page small { font-weight: 500; color: var(--dim); font-size: 12px; }
.t-page .blk-gutter { top: 4px; }

/* inline task list */
.tw { margin: 10px 0; padding: 16px 16px 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); outline: none; }
.tw.blk-focus:focus { background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.tw-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tw-h > span:first-child { display: inline-flex; align-items: center; gap: 8px; font: 700 15px var(--display); }
.tw-h .ic { color: var(--accent); }
.tw .quick-add { margin-bottom: 6px; }
.tw-empty { padding: 6px 4px 8px; }
.tw .done-group { margin-top: 6px; }
.tw .done-group.open .group-toggle .ic { transform: rotate(90deg); }
.t-tasks .blk-gutter { top: 18px; }

/* ============ popovers, slash menu, toolbar ============ */
.pop { position: fixed; z-index: 70; min-width: 230px; max-width: 330px; max-height: min(440px, 64vh); overflow-y: auto; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); animation: pop-in 170ms var(--ease); transform-origin: top left; }
.pop.out { animation: pop-out 120ms var(--ease) forwards; pointer-events: none; }
.pop-h { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pop-sec { font: 700 11px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); padding: 8px 8px 4px; }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border-radius: 8px; text-align: left; font-size: 14px; color: var(--text); transition: background 80ms; }
.pop-item:hover, .pop-item.sel { background: var(--surface-2); }
.pop-item.danger { color: var(--danger); }
.pop-item kbd { margin-left: auto; }
.pop-item > span:last-child { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.pop-ic { display: grid; place-items: center; color: var(--muted); }
.pop-item.danger .pop-ic { color: inherit; }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.pop-foot { padding: 6px 8px 2px; font-size: 12px; color: var(--dim); }
.pop-empty { padding: 14px 10px; font-size: 13px; color: var(--muted); }
.slash { width: 300px; }
.slash .pop-item > span:last-child { display: block; }
.slash .pop-item b { display: block; font-weight: 600; font-size: 14px; }
.slash .pop-item small { display: block; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-ic { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font: 700 13px var(--display); color: var(--muted); }
.pi-g { flex: none; width: 22px; text-align: center; font: 700 12px var(--display); color: var(--muted); }
.turn-grid { display: grid; grid-template-columns: 1fr 1fr; }
.turn-grid .pop-item { font-size: 13px; padding: 6px; }
.blk-pop { width: 290px; max-width: 290px; }
.emoji-pop { width: 344px; max-width: 344px; }
.eg { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; }
.eg button { height: 34px; border-radius: 8px; font-size: 20px; transition: background 80ms, transform 160ms var(--spring); }
.eg button:hover { background: var(--surface-2); transform: scale(1.15); }
.cover-pop { width: 300px; }
.cover-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 4px 4px; }
.cover-grid button { height: 46px; border-radius: 9px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .06); transition: transform 200ms var(--spring); }
.cover-grid button:hover { transform: scale(1.06); }

.fmt { position: fixed; z-index: 70; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--text); color: var(--bg); border-radius: 10px; box-shadow: var(--shadow-lg); animation: pop-in 120ms var(--ease); }
.fmt[hidden], .fmt-link[hidden] { display: none; }
.fmt button { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 7px; font-size: 14px; display: grid; place-items: center; color: inherit; }
.fmt button:hover, .fmt button.on { background: color-mix(in oklab, var(--bg) 20%, transparent); }
.fmt code { font: 600 12px ui-monospace, Consolas, monospace; }
.fmt.linking > button { display: none; }
.fmt input { width: 240px; height: 30px; padding: 0 8px; border: 0; outline: 0; background: transparent; color: inherit; font-size: 13px; }
.fmt input::placeholder { color: color-mix(in oklab, var(--bg) 55%, transparent); }

@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.97); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(-2px) scale(.98); } }

@media (max-width: 820px) {
  .doc-inner { padding-left: 0; }
  .blk-gutter { display: none; }
  .doc-tools { opacity: 1; }
  .doc-icon { font-size: 50px; width: 68px; height: 68px; }
}
