/* InkPage — app.css */
:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f7f5;
  --bg-elev: #ffffff;
  --bg-soft: #f1f1ef;
  --text: #37352f;
  --text-muted: #787774;
  --text-faint: #a5a29a;
  --hover: rgba(55, 53, 47, .06);
  --hover-strong: rgba(55, 53, 47, .1);
  --border: rgba(55, 53, 47, .12);
  --accent: #2383e2;
  --accent-soft: rgba(35, 131, 226, .14);
  --danger: #e03e3e;
  --shadow: 0 0 0 1px rgba(15, 15, 15, .05), 0 3px 6px rgba(15, 15, 15, .1), 0 9px 24px rgba(15, 15, 15, .2);
  --code-bg: #f7f6f3;
  --inline-code: #eb5757;
  --sb-w: 248px;
  --content-w: 720px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;

  --c-gray: #787774; --c-brown: #9f6b53; --c-orange: #d9730d; --c-yellow: #cb912f; --c-green: #448361;
  --c-blue: #337ea9; --c-purple: #9065b0; --c-pink: #c14c8a; --c-red: #d44c47;
  --b-gray: #f1f1ef; --b-brown: #f4eeee; --b-orange: #fbecdd; --b-yellow: #fbf3db; --b-green: #edf3ec;
  --b-blue: #e7f3f8; --b-purple: #f6f3f9; --b-pink: #faf1f5; --b-red: #fdebec;
  --p-none: rgba(227, 226, 224, .5);
  --p-gray: #e3e2e0; --p-brown: #eee0da; --p-orange: #fadec9; --p-yellow: #fdecc8; --p-green: #dbeddb;
  --p-blue: #d3e5ef; --p-purple: #e8deee; --p-pink: #f5e0e9; --p-red: #ffe2dd;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #191919;
  --bg-sidebar: #202020;
  --bg-elev: #252525;
  --bg-soft: #2a2a2a;
  --text: #e6e6e4;
  --text-muted: #9b9b9b;
  --text-faint: #6b6b6b;
  --hover: rgba(255, 255, 255, .055);
  --hover-strong: rgba(255, 255, 255, .1);
  --border: rgba(255, 255, 255, .1);
  --accent: #529cca;
  --accent-soft: rgba(82, 156, 202, .2);
  --danger: #ff6b6b;
  --shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 3px 6px rgba(0, 0, 0, .4), 0 9px 24px rgba(0, 0, 0, .5);
  --code-bg: #202020;
  --inline-code: #ff8a80;
  --c-gray: #9b9b9b; --c-brown: #ba856f; --c-orange: #c77d48; --c-yellow: #ca9849; --c-green: #529e72;
  --c-blue: #5e9fe8; --c-purple: #9d68d3; --c-pink: #d15796; --c-red: #df5452;
  --b-gray: #2f2f2f; --b-brown: #4a3228; --b-orange: #5c3b23; --b-yellow: #56452f; --b-green: #243d30;
  --b-blue: #143a4e; --b-purple: #3c2d49; --b-pink: #4e2c3c; --b-red: #522e2a;
  --p-none: rgba(255, 255, 255, .06);
  --p-gray: #474747; --p-brown: #5c4033; --p-orange: #7a4a26; --p-yellow: #7a6331; --p-green: #2d5940;
  --p-blue: #28456c; --p-purple: #493064; --p-pink: #69314c; --p-red: #6e3630;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
kbd { font-family: var(--font); font-size: 11px; color: var(--text-faint); }
mark { background: rgba(255, 212, 0, .35); color: inherit; border-radius: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.small-text { font-size: 13px; margin: 4px 0; }
.pad { padding: 8px 10px; font-size: 13px; }
body.resizing { cursor: col-resize; user-select: none; }

#app { display: flex; height: 100vh; }

/* ============ 側邊欄 ============ */
#sidebar {
  width: var(--sb-w); flex: none; background: var(--bg-sidebar); display: flex; flex-direction: column;
  position: relative; transition: margin-left .2s ease; font-size: 14px; color: var(--text-muted); user-select: none;
}
body.sb-collapsed #sidebar { margin-left: calc(-1 * var(--sb-w)); }
.sb-head { display: flex; align-items: center; padding: 8px 8px 4px 10px; gap: 4px; }
.ws-name { flex: 1; display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; min-width: 0; color: var(--text); font-weight: 600; }
.ws-name:hover { background: var(--hover); }
.ws-logo { width: 22px; height: 22px; border-radius: 5px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 12px; flex: none; }
.ws-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-actions { padding: 2px 6px 8px; }
.sb-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 8px; border-radius: 6px; text-align: left; min-height: 28px; }
.sb-item:hover { background: var(--hover); color: var(--text); }
.sb-item kbd { margin-left: auto; }
.sb-ico { width: 20px; text-align: center; flex: none; font-size: 14px; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.sb-section { margin-bottom: 14px; }
.sb-label { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; padding: 2px 8px; color: var(--text-faint); height: 26px; }
.sb-label .icon-btn { opacity: 0; }
.sb-label:hover .icon-btn { opacity: 1; }
.sb-foot { padding: 6px; border-top: 1px solid var(--border); }
.storage-info { font-size: 11px; color: var(--text-faint); padding: 4px 8px 2px; }
.sb-resizer { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 5; }
.sb-resizer:hover { background: linear-gradient(90deg, transparent 2px, var(--border) 2px, var(--border) 4px, transparent 4px); }

.tree-row {
  display: flex; align-items: center; gap: 2px; height: 30px; padding-right: 4px; border-radius: 6px; cursor: pointer; position: relative;
}
.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--hover-strong); color: var(--text); font-weight: 500; }
.tree-row.dragging { opacity: .4; }
.tree-row.drop-inside { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.tree-row.drop-before::before, .tree-row.drop-after::after { content: ""; position: absolute; left: 8px; right: 4px; height: 2px; background: var(--accent); border-radius: 2px; }
.tree-row.drop-before::before { top: -1px; }
.tree-row.drop-after::after { bottom: -1px; }
.caret, .caret-spacer { width: 20px; height: 20px; flex: none; border-radius: 4px; display: grid; place-items: center; font-size: 16px; color: var(--text-faint); transition: transform .12s; }
.caret:hover { background: var(--hover-strong); }
.caret.open { transform: rotate(90deg); }
.tree-icon { width: 22px; text-align: center; flex: none; font-size: 15px; }
.tree-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-acts { display: none; gap: 1px; }
.tree-row:hover .row-acts { display: flex; }
.tree-empty { font-size: 13px; color: var(--text-faint); padding: 3px 8px 3px 30px; }

.icon-btn { width: 28px; height: 28px; border-radius: 6px; display: inline-grid; place-items: center; color: var(--text-muted); flex: none; font-size: 15px; }
.icon-btn.sm { width: 22px; height: 22px; font-size: 14px; }
.icon-btn:hover { background: var(--hover-strong); color: var(--text); }
.icon-btn.on { color: #e6a700; }

/* ============ 主區域 ============ */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#topbar { height: 44px; display: flex; align-items: center; gap: 6px; padding: 0 10px 0 12px; flex: none; }
#btnExpand { display: none; }
body.sb-collapsed #btnExpand { display: inline-grid; }
#breadcrumb { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; font-size: 14px; overflow: hidden; }
.bc-item { display: flex; align-items: center; gap: 5px; padding: 2px 6px; border-radius: 5px; white-space: nowrap; min-width: 0; }
.bc-item:hover { background: var(--hover); }
.bc-title { overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.bc-sep, .bc-more { color: var(--text-faint); }
.tb-right { display: flex; align-items: center; gap: 2px; }
#saveState { font-size: 12px; color: var(--text-faint); opacity: 0; transition: opacity .3s; margin-right: 6px; }
#saveState.show { opacity: 1; }
#saveState.err { color: var(--danger); }
#scroller { flex: 1; overflow-y: auto; overflow-x: hidden; }
#page { padding-bottom: 30vh; }

.banner { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 16px; font-size: 14px; flex-wrap: wrap; }
.banner.danger { background: var(--danger); color: #fff; }
.banner.danger .btn { color: #fff; border-color: rgba(255,255,255,.6); background: transparent; }
.banner.warn { background: var(--b-yellow); color: var(--text); }

/* ============ 頁首 ============ */
.cover { height: 30vh; max-height: 280px; min-height: 140px; position: relative; }
.cover-acts { position: absolute; right: 16px; bottom: 12px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.cover:hover .cover-acts { opacity: 1; }
.cover-btn { background: rgba(255,255,255,.9); color: #37352f; font-size: 12px; padding: 4px 10px; border-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
[data-cover="g1"] { background: linear-gradient(120deg, #f6d365, #fda085); }
[data-cover="g2"] { background: linear-gradient(120deg, #a1c4fd, #c2e9fb); }
[data-cover="g3"] { background: linear-gradient(120deg, #84fab0, #8fd3f4); }
[data-cover="g4"] { background: linear-gradient(120deg, #e0c3fc, #8ec5fc); }
[data-cover="g5"] { background: linear-gradient(120deg, #fccb90, #d57eeb); }
[data-cover="g6"] { background: linear-gradient(120deg, #434343, #000000); }
[data-cover="g7"] { background: linear-gradient(120deg, #ff9a9e, #fecfef); }
[data-cover="g8"] { background: linear-gradient(120deg, #2b5876, #4e4376); }
.cover-grid { display: grid; grid-template-columns: repeat(4, 64px); gap: 8px; padding: 10px; }
.cover-swatch { height: 40px; border-radius: 6px; }
.cover-swatch:hover { outline: 2px solid var(--accent); }

.page-head, .blocks, .row-props, .db-host, .page-tail { width: min(var(--content-w), calc(100% - 96px)); margin: 0 auto; }
#page.full-width .page-head, #page.full-width .blocks, #page.full-width .row-props, #page.full-width .page-tail { width: calc(100% - 192px); }
#page.is-db .page-head, #page.is-db .db-host { width: calc(100% - 192px); max-width: 1400px; }
.page-head { padding-top: 64px; position: relative; }
.page-head.has-cover { padding-top: 24px; }
.page-head.has-cover.has-icon { padding-top: 0; }
.page-icon { font-size: 72px; line-height: 1; padding: 4px; border-radius: 8px; margin-bottom: 4px; }
.page-head.has-cover .page-icon { margin-top: -42px; position: relative; }
.page-icon:hover { background: var(--hover); }
.page-ctrls { display: flex; gap: 4px; height: 30px; opacity: 0; transition: opacity .15s; margin-bottom: 4px; }
.page-head:hover .page-ctrls, .page-ctrls:focus-within { opacity: 1; }
.ghost-btn { font-size: 14px; color: var(--text-faint); padding: 4px 8px; border-radius: 5px; }
.ghost-btn:hover { background: var(--hover); color: var(--text-muted); }
.page-title { font-size: 40px; font-weight: 700; line-height: 1.2; outline: none; padding: 3px 2px; margin-bottom: 8px; word-break: break-word; }
.page-title:empty::before { content: attr(data-placeholder); color: var(--text-faint); opacity: .6; }

/* ============ 區塊 ============ */
.blocks { padding-top: 4px; }
.blk { position: relative; padding-left: calc(var(--indent, 0) * 26px); margin: 1px 0; }
.blk.hidden { display: none; }
.blk-gutter { position: absolute; top: 0; left: calc(var(--indent, 0) * 26px - 50px); width: 48px; height: 30px; display: flex; align-items: center; justify-content: flex-end; gap: 0; opacity: 0; transition: opacity .1s; }
.blk:hover > .blk-gutter, .blk.focused > .blk-gutter { opacity: 1; }
.blk.focused:not(:hover) > .blk-gutter { opacity: 0; }
.blk[data-type="h1"] > .blk-gutter { top: 22px; height: 40px; }
.blk[data-type="h2"] > .blk-gutter { top: 14px; height: 36px; }
.blk[data-type="h3"] > .blk-gutter { top: 8px; height: 32px; }
.g-btn { width: 22px; height: 24px; border-radius: 4px; color: var(--text-faint); font-size: 15px; display: grid; place-items: center; letter-spacing: -3px; }
.g-handle { cursor: grab; font-size: 13px; padding-right: 3px; }
.g-btn:hover { background: var(--hover-strong); color: var(--text-muted); }
.blk-body { display: flex; align-items: flex-start; min-height: 30px; border-radius: 4px; }
.blk.selected > .blk-body { background: var(--accent-soft); }
.blk.dragging { opacity: .35; }
.blk-content { flex: 1; min-width: 0; outline: none; padding: 3px 2px; white-space: pre-wrap; word-break: break-word; caret-color: var(--text); }
.blk-content:empty::before { content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; }
.blk[data-type="text"] .blk-content:empty:not(:focus)::before { content: ""; }
.blocks > .blk:only-child[data-type="text"] .blk-content:empty::before { content: attr(data-placeholder); }
.blk-content code { font-family: var(--mono); font-size: 85%; background: var(--hover-strong); color: var(--inline-code); padding: .15em .35em; border-radius: 4px; }
.blk-content a, .page-title a { color: inherit; text-decoration: underline; text-decoration-color: var(--text-faint); text-underline-offset: 3px; cursor: pointer; }
.blk-content a:hover { text-decoration-color: var(--text); }

.blk[data-type="h1"] { margin-top: 28px; }
.blk[data-type="h2"] { margin-top: 18px; }
.blk[data-type="h3"] { margin-top: 10px; }
.blk[data-type="h1"] .blk-content { font-size: 1.875em; font-weight: 700; line-height: 1.3; }
.blk[data-type="h2"] .blk-content { font-size: 1.5em; font-weight: 650; line-height: 1.3; }
.blk[data-type="h3"] .blk-content { font-size: 1.25em; font-weight: 600; line-height: 1.3; }

.marker { flex: none; width: 24px; text-align: center; padding-top: 3px; user-select: none; }
.bullet-marker { font-size: 1.25em; line-height: 1.2; }
.num-marker { width: auto; min-width: 24px; padding-right: 4px; text-align: right; }

.todo-box { flex: none; width: 16px; height: 16px; margin: 6px 8px 0 4px; border: 1.5px solid var(--text-muted); border-radius: 3px; display: grid; place-items: center; font-size: 12px; line-height: 1; color: #fff; }
.todo-box:hover { background: var(--hover-strong); }
.todo-box.on { background: var(--accent); border-color: var(--accent); }
.blk.checked .blk-content { text-decoration: line-through; color: var(--text-faint); }

.toggle-arrow { flex: none; width: 24px; height: 24px; margin-top: 3px; border-radius: 4px; font-size: 11px; display: grid; place-items: center; transition: transform .12s; color: var(--text); }
.toggle-arrow:hover { background: var(--hover-strong); }
.toggle-arrow.open { transform: rotate(90deg); }
.toggle-wrap { flex: 1; min-width: 0; }
.toggle-empty { display: none; font-size: 14px; color: var(--text-faint); padding: 2px 2px 4px 0; cursor: pointer; }
.toggle-empty:hover { color: var(--text-muted); }
.blk[data-type="toggle"]:not(.toggle-has-children) .toggle-arrow.open + .toggle-wrap .toggle-empty { display: block; }

.blk[data-type="quote"] .blk-body { border-left: 3px solid currentColor; padding-left: 12px; margin: 4px 0; }
.blk[data-type="quote"] .blk-content { font-size: 1.05em; }

.blk[data-type="callout"] .blk-body { background: var(--b-gray); padding: 12px 14px 12px 10px; border-radius: 6px; margin: 4px 0; gap: 8px; }
.callout-icon { flex: none; width: 28px; height: 28px; font-size: 20px; border-radius: 4px; }
.callout-icon:hover { background: var(--hover-strong); }

.blk[data-type="code"] .blk-body { flex-direction: column; background: var(--code-bg); border-radius: 6px; margin: 4px 0; position: relative; }
.code-head { display: flex; justify-content: space-between; width: 100%; padding: 6px 10px 0; opacity: .0; transition: opacity .15s; }
.blk[data-type="code"]:hover .code-head, .blk[data-type="code"].focused .code-head { opacity: 1; }
.code-lang { background: transparent; border: 0; font-size: 12px; color: var(--text-muted); border-radius: 4px; padding: 2px 4px; cursor: pointer; }
.code-lang:hover { background: var(--hover-strong); }
.code-lang option { background: var(--bg-elev); }
.code-copy { font-size: 12px; color: var(--text-muted); padding: 2px 8px; border-radius: 4px; }
.code-copy:hover { background: var(--hover-strong); }
.code-content { width: 100%; margin: 0; padding: 4px 18px 18px !important; font-family: var(--mono); font-size: 14px; line-height: 1.6; tab-size: 2; overflow-x: auto; white-space: pre; }

.divider { width: 100%; padding: 10px 0; cursor: pointer; outline: none; }
.divider hr { border: 0; border-top: 1px solid var(--border); margin: 0; }

.img-ph { width: 100%; display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--bg-soft); border-radius: 6px; color: var(--text-muted); font-size: 14px; margin: 4px 0; text-align: left; }
.img-ph:hover { background: var(--hover-strong); }
.img-wrap { position: relative; max-width: 100%; margin: 6px 0; border-radius: 4px; }
.img-wrap img { display: block; width: 100%; height: auto; border-radius: 4px; }
.img-wrap.broken { min-height: 60px; background: var(--bg-soft); }
.img-wrap.broken::after { content: "圖片無法載入"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--text-muted); }
.img-resize { position: absolute; right: -6px; top: 50%; width: 8px; height: 48px; margin-top: -24px; border-radius: 4px; background: rgba(15,15,15,.6); border: 1px solid rgba(255,255,255,.9); cursor: ew-resize; opacity: 0; }
.img-wrap:hover .img-resize { opacity: 1; }
.blk.selected .img-wrap { outline: 3px solid var(--accent-soft); }
.img-picker { display: flex; flex-direction: column; gap: 8px; padding: 12px; width: 320px; }
.img-picker .or { text-align: center; color: var(--text-faint); font-size: 12px; }

.page-link { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 4px; color: inherit; text-decoration: none; flex: 1; font-weight: 500; }
.page-link:hover { background: var(--hover); }
.pl-title { border-bottom: 1px solid var(--border); }
.page-link.gone { color: var(--text-faint); }

.page-tail { height: 120px; cursor: text; }

/* 區塊顏色 */
[data-color="gray"], .blk[data-blk-color="gray"] .blk-content, .mi-icon[data-color="gray"] { color: var(--c-gray); }
[data-color="brown"], .blk[data-blk-color="brown"] .blk-content, .mi-icon[data-color="brown"] { color: var(--c-brown); }
[data-color="orange"], .blk[data-blk-color="orange"] .blk-content, .mi-icon[data-color="orange"] { color: var(--c-orange); }
[data-color="yellow"], .blk[data-blk-color="yellow"] .blk-content, .mi-icon[data-color="yellow"] { color: var(--c-yellow); }
[data-color="green"], .blk[data-blk-color="green"] .blk-content, .mi-icon[data-color="green"] { color: var(--c-green); }
[data-color="blue"], .blk[data-blk-color="blue"] .blk-content, .mi-icon[data-color="blue"] { color: var(--c-blue); }
[data-color="purple"], .blk[data-blk-color="purple"] .blk-content, .mi-icon[data-color="purple"] { color: var(--c-purple); }
[data-color="pink"], .blk[data-blk-color="pink"] .blk-content, .mi-icon[data-color="pink"] { color: var(--c-pink); }
[data-color="red"], .blk[data-blk-color="red"] .blk-content, .mi-icon[data-color="red"] { color: var(--c-red); }
[data-bg="gray"], .blk[data-blk-color="gray-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="gray-bg"] .blk-body { background: var(--b-gray); }
[data-bg="brown"], .blk[data-blk-color="brown-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="brown-bg"] .blk-body { background: var(--b-brown); }
[data-bg="orange"], .blk[data-blk-color="orange-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="orange-bg"] .blk-body { background: var(--b-orange); }
[data-bg="yellow"], .blk[data-blk-color="yellow-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="yellow-bg"] .blk-body { background: var(--b-yellow); }
[data-bg="green"], .blk[data-blk-color="green-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="green-bg"] .blk-body { background: var(--b-green); }
[data-bg="blue"], .blk[data-blk-color="blue-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="blue-bg"] .blk-body { background: var(--b-blue); }
[data-bg="purple"], .blk[data-blk-color="purple-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="purple-bg"] .blk-body { background: var(--b-purple); }
[data-bg="pink"], .blk[data-blk-color="pink-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="pink-bg"] .blk-body { background: var(--b-pink); }
[data-bg="red"], .blk[data-blk-color="red-bg"] > .blk-body, .blk[data-type="callout"][data-blk-color="red-bg"] .blk-body { background: var(--b-red); }
span[data-bg] { border-radius: 3px; padding: 0 2px; }
.mi-icon[data-bg] { color: transparent; border-radius: 4px; width: 18px; height: 18px; border: 1px solid var(--border); }
.mi-icon[data-bg]::before { content: "A"; color: var(--text); font-size: 12px; }

.drop-line { position: fixed; height: 4px; background: var(--accent); opacity: .6; border-radius: 2px; pointer-events: none; z-index: 50; display: none; }

/* ============ 浮層 / 選單 ============ */
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.popover { position: fixed; pointer-events: auto; background: var(--bg-elev); border-radius: 8px; box-shadow: var(--shadow); max-height: 70vh; overflow-y: auto; font-size: 14px; animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu { padding: 6px; min-width: 220px; max-width: 320px; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 5px 8px; border-radius: 5px; text-align: left; min-height: 30px; }
.menu-item.active, .menu-item:hover { background: var(--hover-strong); }
.menu-item.danger { color: var(--danger); }
.mi-icon { width: 20px; text-align: center; flex: none; display: inline-grid; place-items: center; }
.mi-label { flex: 1; }
.mi-hint { color: var(--text-faint); font-size: 12px; }
.mi-check { color: var(--accent); margin-left: auto; }
.menu-sep { height: 1px; background: var(--border); margin: 5px -6px; }
.menu-header { font-size: 12px; color: var(--text-faint); padding: 6px 8px 4px; font-weight: 500; }
.menu-input { padding: 4px; }

.slash-pop { width: 320px; max-height: 380px; }
.slash-list { padding: 6px; }
.slash-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 4px 6px; border-radius: 5px; text-align: left; }
.slash-item.active { background: var(--hover-strong); }
.slash-icon { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 6px; display: grid; place-items: center; background: var(--bg); font-size: 15px; font-weight: 600; flex: none; }
.slash-text { display: flex; flex-direction: column; min-width: 0; }
.slash-label { font-size: 14px; }
.slash-desc { font-size: 12px; color: var(--text-muted); }
.slash-empty { padding: 8px 10px; color: var(--text-muted); }

#fmtbar { position: fixed; z-index: 120; display: none; align-items: center; gap: 1px; padding: 3px; background: var(--bg-elev); border-radius: 7px; box-shadow: var(--shadow); }
#fmtbar.show { display: flex; }
.tb-btn { min-width: 30px; height: 30px; padding: 0 6px; border-radius: 4px; font-size: 14px; display: grid; place-items: center; }
.tb-btn.wide { padding: 0 8px; color: var(--text-muted); white-space: nowrap; }
.tb-btn:hover { background: var(--hover-strong); }
.tb-btn.on { color: var(--accent); }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 3px; }
.tb-a { text-decoration: underline; font-weight: 600; }

.emoji-pop { width: 360px; }
.emoji-head { display: flex; gap: 6px; padding: 10px 10px 6px; position: sticky; top: 0; background: var(--bg-elev); }
.emoji-head .input { flex: 1; }
.emoji-grid { display: grid; grid-template-columns: repeat(10, 1fr); padding: 0 8px 10px; }
.emoji-group { grid-column: 1 / -1; font-size: 12px; color: var(--text-faint); padding: 8px 2px 2px; }
.emoji { font-size: 22px; height: 32px; border-radius: 5px; }
.emoji:hover { background: var(--hover-strong); }

#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #2f2f2f; color: #fff; padding: 8px 10px 8px 14px; border-radius: 6px; font-size: 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); animation: pop .15s; transition: opacity .3s; }
.toast.out { opacity: 0; }
.toast-btn { color: #7cc4ff; font-weight: 500; padding: 2px 6px; border-radius: 4px; }
.toast-btn:hover { background: rgba(255,255,255,.1); }

.modal-wrap { position: fixed; inset: 0; background: rgba(15,15,15,.45); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg-elev); border-radius: 10px; box-shadow: var(--shadow); width: 100%; max-width: 640px; max-height: 76vh; display: flex; flex-direction: column; overflow: hidden; }
.modal.small { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.modal-title { font-weight: 600; }
.confirm { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.confirm p { margin: 0; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.btn-row.left { justify-content: flex-start; }

.btn { border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 14px; background: var(--bg-elev); white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.sm { padding: 3px 8px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.input { width: 100%; border: 1px solid var(--border); background: var(--bg-soft); border-radius: 6px; padding: 7px 10px; outline: none; font-size: 14px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.sm { padding: 5px 8px; }

.settings { padding: 4px 20px 20px; overflow-y: auto; }
.set-sec { padding: 12px 0; border-bottom: 1px solid var(--border); }
.set-sec:last-child { border: 0; }
.set-sec h3 { font-size: 14px; margin: 0 0 10px; }
.seg { display: inline-flex; background: var(--bg-soft); border-radius: 7px; padding: 3px; gap: 2px; }
.seg-btn { padding: 4px 14px; border-radius: 5px; font-size: 14px; }
.seg-btn.on { background: var(--bg-elev); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.kbd-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; font-size: 13px; }
.kbd-row { display: flex; gap: 10px; align-items: center; }
.kbd-row kbd { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.info-list { padding: 8px 20px 20px; }
.info-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }

.trash { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 200px; overflow: hidden; }
.trash-list { overflow-y: auto; }
.trash-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.trash-item:hover { background: var(--hover); }
.trash-open { flex: 1; display: flex; flex-direction: column; text-align: left; padding: 6px 8px; min-width: 0; }
.trash-open small { color: var(--text-faint); font-size: 12px; }
.empty-note { color: var(--text-muted); text-align: center; padding: 30px 10px; font-size: 14px; }

.search-modal { max-width: 620px; }
.search-box { display: flex; flex-direction: column; min-height: 0; }
.search-input { border: 0; border-bottom: 1px solid var(--border); padding: 16px 18px; font-size: 17px; outline: none; background: transparent; }
.search-results { overflow-y: auto; padding: 6px; max-height: 56vh; }
.search-item { display: flex; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; text-align: left; align-items: flex-start; }
.search-item.active { background: var(--hover-strong); }
.si-icon { font-size: 18px; width: 24px; text-align: center; flex: none; }
.si-main { display: flex; flex-direction: column; min-width: 0; }
.si-title { font-weight: 500; }
.si-path, .si-snippet { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty-page { text-align: center; padding: 18vh 20px; color: var(--text-muted); }
.empty-emoji { font-size: 56px; }

/* ============ 資料庫 ============ */
.db-host { padding-bottom: 40px; }
.db-toolbar { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); margin-bottom: 4px; gap: 10px; flex-wrap: wrap; }
.db-tabs { display: flex; gap: 2px; }
.db-tab { padding: 6px 10px; font-size: 14px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.db-tab.on { color: var(--text); border-color: var(--text); font-weight: 500; }
.db-tab:hover { color: var(--text); }
.db-tools { display: flex; gap: 6px; align-items: center; padding: 4px 0; flex-wrap: wrap; }
.db-search { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 3px 8px; font-size: 13px; width: 150px; outline: none; }
.db-search:hover { background: var(--hover); }
.db-search:focus { border-color: var(--border); background: var(--bg-elev); }
.db-scroll { overflow-x: auto; }
.db-table { border-collapse: collapse; font-size: 14px; table-layout: fixed; min-width: 100%; }
.db-table th { text-align: left; font-weight: 400; color: var(--text-muted); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); position: relative; height: 34px; padding: 0; }
.db-table th:last-child, .db-table td:last-child { border-right: 0; }
.db-table .th-act, .db-table .td-act { width: 30px; border-right: 0 !important; border-bottom-color: transparent; }
.db-table .th-add { width: 60px; }
.th-btn { width: 100%; height: 34px; display: flex; align-items: center; gap: 6px; padding: 0 8px; text-align: left; white-space: nowrap; overflow: hidden; }
.th-btn:hover { background: var(--hover); }
.th-icon { color: var(--text-faint); font-size: 12px; min-width: 16px; }
.col-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 2; }
.col-resize:hover { background: var(--accent); opacity: .5; }
.db-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; height: 36px; vertical-align: middle; }
.db-table tr:hover td:not(.td-act) { background: var(--hover); }
.td-act { text-align: center; }
.row-act-btn { opacity: 0; color: var(--text-faint); font-size: 12px; letter-spacing: -2px; width: 22px; height: 24px; border-radius: 4px; }
tr:hover .row-act-btn { opacity: 1; }
.row-act-btn:hover { background: var(--hover-strong); }
.cell-title { display: flex; align-items: center; gap: 6px; padding: 0 8px; min-height: 36px; position: relative; }
.cell-title-icon { font-size: 14px; }
.cell-title-text { flex: 1; outline: none; font-weight: 500; min-width: 20px; padding: 6px 0; word-break: break-word; }
.cell-title-text:empty::before { content: attr(data-placeholder); color: var(--text-faint); font-weight: 400; }
.open-btn { display: none; font-size: 12px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; background: var(--bg-elev); white-space: nowrap; }
tr:hover .open-btn { display: block; }
.open-btn:hover { background: var(--hover-strong); }
.cell-input { width: 100%; height: 36px; border: 0; background: transparent; padding: 0 8px; outline: none; font-size: 14px; }
.cell-input:focus { box-shadow: inset 0 0 0 2px var(--accent-soft); background: var(--bg-elev); }
.cell-input[type="number"] { text-align: right; }
.cell-url { display: flex; align-items: center; }
.url-go { padding: 0 8px; color: var(--text-muted); text-decoration: none; }
.cell-check { display: flex; align-items: center; height: 36px; padding: 0 10px; cursor: pointer; }
.cell-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.cell-select { width: 100%; min-height: 36px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px 8px; text-align: left; }
.pill { display: inline-flex; align-items: center; padding: 0 7px; border-radius: 4px; font-size: 13px; line-height: 21px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; background: var(--p-gray); color: var(--text); }
.pill[data-c="none"] { background: var(--p-none); }
.pill[data-c="gray"] { background: var(--p-gray); } .pill[data-c="brown"] { background: var(--p-brown); }
.pill[data-c="orange"] { background: var(--p-orange); } .pill[data-c="yellow"] { background: var(--p-yellow); }
.pill[data-c="green"] { background: var(--p-green); } .pill[data-c="blue"] { background: var(--p-blue); }
.pill[data-c="purple"] { background: var(--p-purple); } .pill[data-c="pink"] { background: var(--p-pink); }
.pill[data-c="red"] { background: var(--p-red); }
.db-add-row { display: block; width: 100%; text-align: left; padding: 6px 38px; color: var(--text-faint); font-size: 14px; border-bottom: 1px solid var(--border); }
.db-add-row:hover { background: var(--hover); color: var(--text-muted); }
.db-count { font-size: 12px; color: var(--text-faint); padding: 8px 4px; }

.opt-picker { width: 280px; }
.opt-head { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-elev); }
.opt-list { padding: 4px; max-height: 300px; overflow-y: auto; }
.opt-row { display: flex; align-items: center; border-radius: 5px; }
.opt-row:hover { background: var(--hover); }
.opt-pick { flex: 1; display: flex; align-items: center; gap: 6px; padding: 4px 6px; text-align: left; }
.opt-create { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px; border-radius: 5px; font-size: 13px; }
.opt-create:hover { background: var(--hover); }
.opt-edit { padding: 10px; width: 220px; display: flex; flex-direction: column; gap: 10px; }
.opt-colors { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.color-dot { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); }
.color-dot.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.color-dot[data-c="gray"] { background: var(--p-gray); } .color-dot[data-c="brown"] { background: var(--p-brown); }
.color-dot[data-c="orange"] { background: var(--p-orange); } .color-dot[data-c="yellow"] { background: var(--p-yellow); }
.color-dot[data-c="green"] { background: var(--p-green); } .color-dot[data-c="blue"] { background: var(--p-blue); }
.color-dot[data-c="purple"] { background: var(--p-purple); } .color-dot[data-c="pink"] { background: var(--p-pink); }
.color-dot[data-c="red"] { background: var(--p-red); }

.board { display: flex; gap: 14px; overflow-x: auto; padding: 8px 0 20px; align-items: flex-start; }
.board-col { flex: none; width: 260px; border-radius: 8px; padding: 6px; transition: background .1s; }
.board-col.drag-over { background: var(--accent-soft); }
.board-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 8px; font-size: 14px; }
.board-cards { display: flex; flex-direction: column; gap: 8px; min-height: 10px; }
.card { background: var(--bg-elev); border-radius: 6px; box-shadow: 0 0 0 1px var(--border), 0 2px 4px rgba(15,15,15,.06); padding: 10px; cursor: pointer; font-size: 14px; }
:root[data-theme="dark"] .card { background: var(--bg-soft); }
.card:hover { background: var(--hover); }
.card.dragging { opacity: .4; }
.card-title { font-weight: 500; word-break: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.card-prop { font-size: 12px; color: var(--text-muted); }
.board-add { width: 100%; text-align: left; padding: 6px; color: var(--text-faint); font-size: 14px; border-radius: 6px; margin-top: 4px; }
.board-add:hover { background: var(--hover); }
.board-newcol { flex: none; padding: 8px 12px; color: var(--text-faint); font-size: 14px; border-radius: 6px; white-space: nowrap; }
.board-newcol:hover { background: var(--hover); }

.row-props { padding: 4px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 14px; font-size: 14px; }
.rp-row { display: flex; align-items: center; min-height: 36px; }
.rp-name { width: 160px; flex: none; display: flex; align-items: center; gap: 8px; color: var(--text-muted); padding: 0 6px; }
.rp-val { flex: 1; min-width: 0; border-radius: 5px; }
.rp-val:hover { background: var(--hover); }
.rp-foot { padding-top: 4px; }

/* ============ 響應式 ============ */
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 60; height: 100%; box-shadow: var(--shadow); }
  .page-head, .blocks, .row-props, .db-host, .page-tail,
  #page.full-width .page-head, #page.full-width .blocks, #page.is-db .page-head, #page.is-db .db-host { width: calc(100% - 56px); }
  .page-title { font-size: 30px; }
  .blk-gutter { display: none; }
  .kbd-list { grid-template-columns: 1fr; }
  .rp-name { width: 110px; }
}
@media print {
  #sidebar, #topbar, .blk-gutter, .page-ctrls, .page-tail { display: none !important; }
  body { overflow: visible; }
  #scroller { overflow: visible; }
}
.page-ctrls:empty { display: none; }
body:not(.ready) #sidebar { transition: none; }
.tb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 3px; }
@media (max-width: 760px) {
  body.sb-collapsed #sidebar { box-shadow: none; }
}

/* ============ 伺服器模式：驗證畫面 ============ */
body.auth-open #app { visibility: hidden; }
#authScreen { position: fixed; inset: 0; z-index: 400; background: var(--bg-sidebar); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 24px; overflow-y: auto; }
.auth-card { width: 100%; max-width: 380px; background: var(--bg-elev); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 28px 22px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.ws-logo.lg { width: 34px; height: 34px; font-size: 18px; border-radius: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h1 { font-size: 22px; margin: 0 0 4px; }
.auth-form.in-modal { padding: 4px 20px 20px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-muted); }
.auth-field .input { font-size: 15px; padding: 9px 11px; color: var(--text); }
.code-input { letter-spacing: .3em; font-family: var(--mono); }
.code-input::placeholder { letter-spacing: normal; font-family: var(--font); }
.auth-err { color: var(--danger); font-size: 13px; min-height: 1em; }
.auth-err:empty { display: none; }
.btn.wide { width: 100%; padding: 10px; font-size: 15px; }
.btn:disabled { opacity: .6; cursor: default; }
.auth-note { font-size: 12px; color: var(--text-muted); margin: 14px 0 0; line-height: 1.6; }
.auth-steps { margin: 0; padding-left: 20px; font-size: 13px; color: var(--text-muted); line-height: 1.7; }
.qr { width: 200px; height: 200px; margin: 4px auto; background: #fff; border-radius: 8px; padding: 4px; }
.qr svg { width: 100%; height: 100%; display: block; }
.secret-row { text-align: center; font-size: 12px; }
.secret { font-family: var(--mono); font-size: 12px; background: var(--bg-soft); padding: 2px 6px; border-radius: 4px; word-break: break-all; user-select: all; }

/* 權限 / 唯讀 */
.access-badge { margin-left: 8px; font-size: 12px; color: var(--text-muted); background: var(--bg-soft); border-radius: 10px; padding: 1px 8px; white-space: nowrap; cursor: default; }
body.server-mode .access-badge { cursor: pointer; }
.tree-badge { font-size: 11px; opacity: .75; flex: none; margin-left: 2px; }
.banner.info { background: var(--b-blue); color: var(--text); }
#page.readonly .blk-gutter, #page.readonly .page-ctrls, #page.readonly .page-tail, #page.readonly .cover-acts,
#page.readonly .img-resize, #page.readonly .code-lang, #page.readonly .toggle-empty { display: none !important; }
#page.readonly .todo-box { cursor: default; }
.db-ro .db-add-row, .db-ro .th-add, .db-ro .board-add, .db-ro .board-newcol, .db-ro .row-act-btn, .db-ro .col-resize, .db-ro .rp-foot { display: none !important; }
.db-ro .th-btn:disabled, .db-ro .cell-select:disabled { opacity: 1; cursor: default; color: inherit; }
.db-ro input:disabled { opacity: 1; color: inherit; background: transparent; }

/* 成員管理 */
.users-modal { max-width: 640px; }
.users { padding: 0 20px 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.add-user { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.user-list { display: flex; flex-direction: column; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.user-row.disabled { opacity: .55; }
.user-main { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.user-acts { display: flex; gap: 4px; flex-wrap: wrap; }
@media (max-width: 560px) { .add-user { grid-template-columns: 1fr; } }

/* ============ 即時協作：他人游標 / 在線成員 ============ */
#page { position: relative; }
#cursorLayer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.rcaret { position: absolute; width: 2px; border-radius: 1px; transition: left .08s linear, top .08s linear; }
.rcaret::before { content: ""; position: absolute; top: -3px; left: -2px; width: 6px; height: 6px; border-radius: 50%; background: inherit; }
.rname { position: absolute; bottom: 100%; left: -1px; margin-bottom: 3px; color: #fff; font-size: 11px; line-height: 1; padding: 3px 5px; border-radius: 4px 4px 4px 0; white-space: nowrap; font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.rsel { position: absolute; opacity: .22; border-radius: 2px; }
.blk.remote-editing > .blk-body { box-shadow: -3px 0 0 -1px var(--remote); }
#presenceBar { display: flex; align-items: center; margin-right: 6px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; border: 2px solid var(--bg); margin-left: -6px; cursor: default; }
.avatar:first-child { margin-left: 0; }
.presence-dots { display: inline-flex; gap: 2px; margin-right: 4px; flex: none; }
.pdot { width: 7px; height: 7px; border-radius: 50%; }
body.rt-offline #topbar { box-shadow: inset 0 -2px 0 var(--danger); }
