:root {
  --bg: #ffffff;
  --bg-subtle: #f7f8f9;
  --bg-hover: #f1f2f4;
  --bg-active: #e6f4f1;
  --surface: #ffffff;
  --border: #dfe1e6;
  --border-strong: #c1c7d0;
  --text: #172b4d;
  --text-muted: #5e6c84;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-text: #0f766e;
  --on-accent: #ffffff;
  --danger: #c9372c;
  --danger-hover: #ae2e24;
  --shadow: 0 8px 24px rgba(9, 30, 66, 0.16), 0 0 1px rgba(9, 30, 66, 0.3);
  --mark: #fef08a;
  --info-bg: #e9f2ff; --info-fg: #0c66e4;
  --note-bg: #f3f0ff; --note-fg: #6e5dc6;
  --success-bg: #dcfff1; --success-fg: #1f845a;
  --warning-bg: #fff7d6; --warning-fg: #a54800;
  --error-bg: #ffeceb; --error-fg: #c9372c;
  --code-bg: #f4f5f7;
  --comment-mark: #fff0b3;
  --comment-mark-active: #ffe380;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-height: 56px;
  color-scheme: light;
}
.dark {
  --bg: #1d2125;
  --bg-subtle: #22272b;
  --bg-hover: #2c333a;
  --bg-active: #143c38;
  --surface: #282e33;
  --border: #38414a;
  --border-strong: #4f5b66;
  --text: #dee4ea;
  --text-muted: #9fadbc;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-text: #5eead4;
  --on-accent: #06302c;
  --danger: #f87168;
  --danger-hover: #fd9891;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.2);
  --mark: #7a6a00;
  --info-bg: #09326c; --info-fg: #85b8ff;
  --note-bg: #352c63; --note-fg: #b8acf6;
  --success-bg: #164b35; --success-fg: #7ee2b8;
  --warning-bg: #533f04; --warning-fg: #f5cd47;
  --error-bg: #5d1f1a; --error-fg: #fd9891;
  --code-bg: #2c333a;
  --comment-mark: #5c4a00;
  --comment-mark-active: #7a6300;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 16px; }
[hidden] { display: none !important; }
.icon { flex: none; vertical-align: -3px; }
.muted { color: var(--text-muted); }
.muted a { color: inherit; }
.pad { padding: 16px; margin: 0; }
.pad-lg { padding: 20px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 4px; padding: 7px 9px; max-width: 100%;
}
input[type='checkbox'], input[type='radio'] { padding: 0; accent-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
input:disabled { background: var(--bg-subtle); color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; color: var(--text); background: var(--bg-hover);
  border: 1px solid transparent; border-radius: 4px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-danger { background: var(--danger); color: #fff; }
.dark .btn-danger { color: #2a0f0c; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger-quiet { color: var(--danger); }
.btn-on { background: var(--bg-active); color: var(--accent-text); }
.btn-sm { padding: 3px 9px; font-size: 13px; }
.btn-block { width: 100%; padding: 9px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.on { color: var(--accent-text); }
.icon-btn.on .icon { fill: currentColor; fill-opacity: 0.25; }
.link-btn { font: inherit; color: var(--accent-text); background: none; border: 0; padding: 0; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* Top navigation */
.topnav {
  position: sticky; top: 0; z-index: 30; height: var(--nav-height); display: flex; align-items: center; gap: 8px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 16px; margin-right: 8px; }
.brand:hover { text-decoration: none; }
.topnav-links { display: flex; height: 100%; gap: 2px; }
.topnav-links a { display: flex; align-items: center; padding: 0 10px; color: var(--text-muted); font-weight: 500; border-bottom: 2px solid transparent; border-top: 2px solid transparent; }
.topnav-links a:hover { color: var(--text); text-decoration: none; background: var(--bg-subtle); }
.topnav-links a.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.topnav-spacer { flex: 1; }
.search-box { position: relative; display: flex; align-items: center; color: var(--text-muted); }
.search-box > .icon { position: absolute; left: 9px; pointer-events: none; }
.search-box input { width: 220px; padding-left: 30px; background: var(--bg-subtle); }
.search-pop {
  position: absolute; top: calc(100% + 6px); right: 0; width: 400px; max-width: calc(100vw - 24px); max-height: 70vh; overflow: auto;
  background: var(--surface); border-radius: 6px; box-shadow: var(--shadow); padding: 6px 0; color: var(--text);
}
.pop-group { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding: 8px 12px 4px; }
.pop-item { display: flex; align-items: center; gap: 10px; padding: 6px 12px; color: var(--text); }
.pop-item:hover { background: var(--bg-hover); text-decoration: none; }
.pop-item span { display: flex; flex-direction: column; min-width: 0; }
.pop-item b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item small { color: var(--text-muted); }
.pop-all { display: block; border-top: 1px solid var(--border); margin-top: 6px; padding: 8px 12px 4px; }
.bell-count {
  position: absolute; top: 1px; right: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.avatar-btn { border: 0; background: none; padding: 0; border-radius: 50%; cursor: pointer; display: flex; }
.avatar, .space-badge { display: inline-flex; align-items: center; justify-content: center; flex: none; font-weight: 600; color: #fff; }
.avatar { border-radius: 50%; }
.space-badge { border-radius: 4px; }
.tint-0 { background: #0f766e; } .tint-1 { background: #1d4ed8; } .tint-2 { background: #7c3aed; } .tint-3 { background: #be185d; }
.tint-4 { background: #b45309; } .tint-5 { background: #15803d; } .tint-6 { background: #0369a1; } .tint-7 { background: #4b5563; }

/* Dropdown menus */
.dropdown {
  position: absolute; z-index: 50; min-width: 200px; background: var(--surface); border-radius: 6px; box-shadow: var(--shadow); padding: 6px 0;
}
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 14px; font: inherit; text-align: left;
  color: var(--text); background: none; border: 0; cursor: pointer;
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--bg-hover); text-decoration: none; outline: none; }
.dropdown-item.danger { color: var(--danger); }
.notice-pop { width: 380px; max-width: calc(100vw - 16px); max-height: 70vh; overflow: auto; padding: 0; }
.notice-head { font-weight: 700; font-size: 15px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notice { display: flex; gap: 10px; padding: 10px 14px; color: var(--text); }
.notice:hover { background: var(--bg-hover); text-decoration: none; }
.notice.unread { background: var(--bg-active); }
.notice > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.notice small { color: var(--text-muted); }
.notice b { font-weight: 600; }
.mention-menu { top: 100%; left: 0; }

/* Layout */
.page-wrap { max-width: 1120px; margin: 0 auto; padding: 28px 24px 64px; }
.narrow-wrap { max-width: 620px; display: flex; flex-direction: column; gap: 16px; }
.page-heading { font-size: 26px; font-weight: 600; }
.page-head { margin-bottom: 16px; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head p { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bg-hover); color: var(--text-muted); font-size: 12px; font-weight: 600; text-align: center; }
.home-cols { display: grid; grid-template-columns: 3fr 2fr; gap: 28px; align-items: start; }
.home-cols > .section { min-width: 0; }
.filter { width: 280px; margin-bottom: 16px; }
.loading { display: flex; justify-content: center; padding: 64px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.empty-state { text-align: center; padding: 64px 24px; }
.empty-state p { color: var(--text-muted); }
.banner { background: var(--info-bg); color: var(--text); padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 3px; background: var(--bg-hover); color: var(--text-muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-green { background: var(--success-bg); color: var(--success-fg); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; }
.tab { font: inherit; font-weight: 500; color: var(--text-muted); background: none; border: 0; padding: 8px 10px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); box-shadow: inset 0 -2px 0 var(--accent); }
a.tab:hover { text-decoration: none; }
.admin-tabs { margin-top: 14px; }

/* Space and page lists */
.space-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.space-card { position: relative; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; min-width: 0; }
.space-card:hover { box-shadow: var(--shadow); }
.space-card-link { display: flex; gap: 12px; align-items: center; color: var(--text); padding-right: 28px; }
.space-card-link:hover { text-decoration: none; }
.space-card-link span:last-child { display: flex; flex-direction: column; min-width: 0; }
.space-card-link small { color: var(--text-muted); }
.space-card p { margin: 10px 0 0; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.star-space { position: absolute; top: 8px; right: 8px; }
.page-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; color: var(--text); border-bottom: 1px solid var(--border); }
.page-row:last-child { border-bottom: 0; }
.page-row:hover { background: var(--bg-hover); text-decoration: none; }
.page-row-icon { color: var(--accent-text); display: flex; }
.page-row-main { display: flex; flex-direction: column; min-width: 0; }
.page-row-main b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-row-main small { color: var(--text-muted); }
.feed-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: 0; }
.feed-item > div { min-width: 0; }
.feed-item b { font-weight: 600; }
.feed-message { color: var(--text-muted); font-style: italic; }

/* Space layout */
.space-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: calc(100vh - var(--nav-height)); }
.sidebar {
  position: sticky; top: var(--nav-height); align-self: start; height: calc(100vh - var(--nav-height)); overflow-y: auto;
  background: var(--bg-subtle); border-right: 1px solid var(--border); padding: 14px 10px 32px;
}
.side-space { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 6px; border-radius: 4px; }
.side-space:hover { background: var(--bg-hover); text-decoration: none; }
.side-space span:last-child { display: flex; flex-direction: column; min-width: 0; }
.side-space b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-space small { color: var(--text-muted); }
.side-links { margin: 10px 0; display: flex; flex-direction: column; gap: 1px; }
.side-links a { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 4px; color: var(--text); font-weight: 500; }
.side-links a:hover { background: var(--bg-hover); text-decoration: none; }
.side-links a.active { background: var(--bg-active); color: var(--accent-text); }
.side-title { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 2px; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.side-title .icon-btn { width: 24px; height: 24px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree-row { display: flex; align-items: center; gap: 2px; min-height: 30px; border-radius: 4px; padding-right: 4px; position: relative; }
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); }
.tree-row.active a { color: var(--accent-text); font-weight: 600; }
.tree-row a { flex: 1; min-width: 0; color: var(--text); padding: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row a:hover { text-decoration: none; }
.tree-toggle, .tree-add { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex: none; padding: 0; color: var(--text-muted); background: none; border: 0; border-radius: 3px; cursor: pointer; }
.tree-toggle:hover, .tree-add:hover { background: var(--border); color: var(--text); }
.tree-toggle .icon { transition: transform 0.1s; }
.tree-toggle.open .icon { transform: rotate(90deg); }
.tree-toggle-spacer { width: 22px; flex: none; }
.tree-add { opacity: 0; }
.tree-row:hover .tree-add, .tree-add:focus-visible { opacity: 1; }
.tree-lock { color: var(--text-muted); display: flex; }
.drop-inside { outline: 2px solid var(--accent); outline-offset: -2px; }
.drop-before::before, .drop-after::after { content: ''; position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); }
.drop-before::before { top: -1px; }
.drop-after::after { bottom: -1px; }

.side-toggle { display: none; }

/* Page view */
.page-view { max-width: 900px; margin: 0 auto; padding: 18px 40px 80px; }
.page-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; min-width: 0; }
.crumbs a { color: var(--text-muted); }
.page-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.page-title { font-size: 30px; font-weight: 600; margin: 8px 0 14px; overflow-wrap: anywhere; }
.byline { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.byline a { color: inherit; }
.page-meta { margin-top: 40px; display: flex; flex-direction: column; gap: 14px; padding-top: 16px; border-top: 1px solid var(--border); }
.likes { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.labels { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.labels-title { margin-right: 4px; font-weight: 500; }
.labels input { padding: 3px 8px; font-size: 13px; width: 150px; }
.label { display: inline-flex; align-items: center; gap: 2px; padding: 1px 7px; background: var(--bg-hover); border-radius: 3px; font-size: 13px; }
.label a { color: var(--accent-text); }
.label button { display: flex; padding: 1px; background: none; border: 0; color: var(--text-muted); cursor: pointer; }
.label-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
#attachments-section, #comments-section { margin-top: 32px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 7px 10px; border-bottom: 2px solid var(--border); }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cell-person { display: inline-flex; align-items: center; gap: 8px; }
.all-pages-title { display: flex; align-items: center; gap: 8px; min-width: 220px; color: var(--text-muted); }
.all-pages-title a { overflow-wrap: anywhere; }
.sort-head { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.sort-head:hover, .sort-head.active { color: var(--text); }
.version-head { margin-top: 28px; }
.version-body { border: 1px solid var(--border); border-radius: 6px; padding: 16px 20px; }
.blog-card { display: block; padding: 18px 0; color: var(--text); border-bottom: 1px solid var(--border); }
.blog-card:hover { text-decoration: none; }
.blog-card:hover h2 { color: var(--accent-text); }
.blog-card h2 { font-size: 20px; margin-bottom: 6px; }
.blog-card p { margin: 8px 0 0; color: var(--text-muted); }
.byline-small { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; }

/* Document content */
.doc-body { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.doc-body .ProseMirror { outline: none; min-height: 40px; }
.doc-body.editing .ProseMirror { min-height: 50vh; padding-bottom: 120px; }
.doc-body h1 { font-size: 26px; margin: 28px 0 8px; font-weight: 600; }
.doc-body h2 { font-size: 21px; margin: 24px 0 6px; font-weight: 600; }
.doc-body h3 { font-size: 18px; margin: 20px 0 4px; font-weight: 600; }
.doc-body h4, .doc-body h5, .doc-body h6 { font-size: 15px; margin: 16px 0 4px; font-weight: 700; }
.doc-body p { margin: 8px 0; }
.doc-body ul, .doc-body ol { padding-left: 26px; margin: 8px 0; }
.doc-body li p { margin: 2px 0; }
.doc-body blockquote { margin: 10px 0; padding-left: 14px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.doc-body hr { border: 0; border-top: 2px solid var(--border); margin: 20px 0; }
.doc-body code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }
.doc-body pre { background: var(--code-bg); padding: 12px 14px; border-radius: 4px; overflow-x: auto; line-height: 1.5; margin: 12px 0; }
.doc-body pre code { background: none; padding: 0; font-size: 13px; }
.doc-body img { max-width: 100%; height: auto; border-radius: 3px; }
.doc-body img.ProseMirror-selectednode { outline: 2px solid var(--accent); }
.doc-body mark { border-radius: 2px; padding: 0 1px; color: inherit; }
.dark .doc-body mark[data-color] { color: #1d2125; }
.doc-body .tableWrapper { overflow-x: auto; margin: 12px 0; }
.doc-body table { border-collapse: collapse; width: 100%; table-layout: fixed; }
.doc-body th, .doc-body td { border: 1px solid var(--border-strong); padding: 7px 10px; vertical-align: top; min-width: 60px; position: relative; }
.doc-body th { background: var(--bg-subtle); text-align: left; font-weight: 600; }
.doc-body th p, .doc-body td p { margin: 0; }
.doc-body .selectedCell { background: var(--bg-active); }
.doc-body .column-resize-handle { position: absolute; top: 0; right: -2px; bottom: 0; width: 4px; background: var(--accent); pointer-events: none; }
.doc-body .resize-cursor { cursor: col-resize; }
.doc-body ul[data-type='taskList'] { list-style: none; padding-left: 2px; }
.doc-body ul[data-type='taskList'] li { display: flex; gap: 8px; align-items: flex-start; }
.doc-body ul[data-type='taskList'] li > label { margin-top: 3px; flex: none; }
.doc-body ul[data-type='taskList'] li > div { flex: 1; min-width: 0; }
.doc-body ul[data-type='taskList'] li[data-checked='true'] > div { color: var(--text-muted); text-decoration: line-through; }
.doc-body .is-editor-empty:first-child::before { content: attr(data-placeholder); float: left; height: 0; color: var(--text-muted); pointer-events: none; }
.sd-panel { display: block; position: relative; margin: 12px 0; padding: 10px 14px 10px 42px; border-radius: 4px; }
.sd-panel::before { position: absolute; left: 14px; top: 11px; width: 18px; height: 18px; border-radius: 50%; color: var(--bg); font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; }
.sd-panel p { margin: 4px 0; }
.sd-panel-info { background: var(--info-bg); } .sd-panel-info::before { content: 'i'; background: var(--info-fg); }
.sd-panel-note { background: var(--note-bg); } .sd-panel-note::before { content: '✎'; background: var(--note-fg); }
.sd-panel-success { background: var(--success-bg); } .sd-panel-success::before { content: '✓'; background: var(--success-fg); }
.sd-panel-warning { background: var(--warning-bg); } .sd-panel-warning::before { content: '!'; background: var(--warning-fg); }
.sd-panel-error { background: var(--error-bg); } .sd-panel-error::before { content: '×'; background: var(--error-fg); }
.sd-status { display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 11px; font-weight: 700; line-height: 18px; text-transform: uppercase; vertical-align: 1px; white-space: nowrap; }
.editing .sd-status, .editing .sd-date { cursor: pointer; }
.sd-status-grey { background: var(--bg-hover); color: var(--text-muted); }
.sd-status-blue { background: var(--info-bg); color: var(--info-fg); }
.sd-status-green { background: var(--success-bg); color: var(--success-fg); }
.sd-status-yellow { background: var(--warning-bg); color: var(--warning-fg); }
.sd-status-red { background: var(--error-bg); color: var(--error-fg); }
.sd-status-purple { background: var(--note-bg); color: var(--note-fg); }
.sd-date { display: inline-block; padding: 0 6px; border-radius: 3px; background: var(--bg-hover); font-size: 13px; white-space: nowrap; }
.sd-mention { display: inline-block; padding: 0 6px; border-radius: 10px; background: var(--bg-hover); color: var(--accent-text); font-weight: 500; }
.sd-expand { margin: 10px 0; border: 1px solid var(--border); border-radius: 4px; }
.sd-expand-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; }
.sd-expand-toggle { width: 22px; height: 22px; padding: 0; border: 0; background: none; color: var(--text-muted); cursor: pointer; }
.sd-expand-title { flex: 1; border: 0; background: transparent; padding: 2px 4px; font-weight: 500; }
.sd-expand-label { flex: 1; text-align: left; font: inherit; font-weight: 500; color: var(--text); background: none; border: 0; cursor: pointer; padding: 0; }
.sd-expand-body { display: none; padding: 0 14px 8px 36px; }
.sd-expand.open .sd-expand-body { display: block; }
.sd-toc { margin: 12px 0; padding: 10px 14px; background: var(--bg-subtle); border-radius: 4px; display: flex; flex-direction: column; }
.sd-toc-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.sd-toc-item { padding: 1px 0; }
.sd-toc-l2 { padding-left: 14px; } .sd-toc-l3 { padding-left: 28px; } .sd-toc-l4, .sd-toc-l5, .sd-toc-l6 { padding-left: 42px; }
.sd-children { margin: 12px 0; }
.sd-muted { color: var(--text-muted); font-size: 13px; }
.sd-comment-mark { background: var(--comment-mark); border-bottom: 2px solid #d4a300; cursor: pointer; }
.sd-comment-mark.active { background: var(--comment-mark-active); }
.ProseMirror-selectednode.sd-status, .ProseMirror-selectednode.sd-date, .ProseMirror-selectednode.sd-mention { outline: 2px solid var(--accent); }

/* Comments */
.comment { display: flex; gap: 10px; margin-bottom: 18px; scroll-margin-top: 80px; }
.comment-main { flex: 1; min-width: 0; }
.comment-head b { font-weight: 600; }
.comment-head a { color: var(--text); }
.comment-text { margin: 2px 0; overflow-wrap: anywhere; }
.comment-actions { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; margin-top: 2px; }
.comment-actions button { font: inherit; background: none; border: 0; padding: 0; color: var(--text-muted); cursor: pointer; }
.comment-actions button:hover { color: var(--text); text-decoration: underline; }
.comment-quote { margin: 4px 0; padding: 2px 10px; border-left: 3px solid #d4a300; color: var(--text-muted); font-size: 13px; }
.comment-replies { margin-top: 12px; }
.comment-group { font-size: 13px; color: var(--text-muted); margin: 18px 0 10px; font-weight: 600; }
.comment-form textarea { display: block; margin-top: 6px; }
.comment-form-actions { display: flex; gap: 6px; margin-top: 6px; }
.new-comment { margin-top: 18px; }
.inline-comment-btn { position: absolute; z-index: 40; background: var(--surface); box-shadow: var(--shadow); }
.inline-comment-card { position: absolute; z-index: 40; width: 340px; max-width: calc(100vw - 16px); max-height: 60vh; overflow: auto; background: var(--surface); box-shadow: var(--shadow); border-radius: 6px; padding: 12px; }
.mini-comment { display: flex; gap: 8px; margin-bottom: 10px; }
.mini-comment > div { min-width: 0; }

/* Forms and dialogs */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label, .create-top label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.stack label small, .radio small { font-weight: 400; }
.stack input:not([type='checkbox']), .stack select, .stack textarea { width: 100%; }
.stack p { margin: 0; }
.stack h2 { margin-bottom: 2px; }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; }
.narrow { max-width: 520px; }
.form-error { color: var(--danger); margin: 0; }
.radio-group { border: 0; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.radio-group legend { font-weight: 500; padding: 0; margin-bottom: 6px; }
.radio { display: flex !important; flex-direction: row !important; align-items: flex-start; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.radio input { margin-top: 3px; }
.radio span { display: flex; flex-direction: column; }
.radio b { font-weight: 500; }
.radio small { color: var(--text-muted); }
.modal { width: 520px; max-width: calc(100vw - 24px); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.modal[open] { display: flex; flex-direction: column; }
.modal-wide { width: 820px; }
.modal::backdrop { background: rgba(9, 30, 66, 0.5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px 8px; }
.modal-head h2 { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-body > p:first-child { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }
.add-person { margin: 10px 0; }
.add-person select { width: 100%; }
.person-list { list-style: none; margin: 8px 0 12px; padding: 0; }
.person-list li { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.person-list li > span:nth-child(2) { flex: 1; min-width: 0; }
.create-top { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.create-top label { flex: 1; min-width: 180px; }
.create-top select { width: 100%; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.template-card { display: flex; gap: 12px; align-items: flex-start; text-align: left; font: inherit; color: var(--text); padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.template-card:hover, .template-card:focus-visible { border-color: var(--accent); background: var(--bg-active); }
.template-card span:last-child { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.template-card b { font-weight: 600; }
.template-card small { color: var(--text-muted); }
.template-icon { display: flex; color: var(--accent-text); }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.danger-row p { margin: 2px 0 0; }

/* Editor screen */
.editor-screen { display: flex; flex-direction: column; height: calc(100vh - var(--nav-height)); }
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.save-state { color: var(--text-muted); font-size: 13px; margin-left: 8px; }
.save-state[data-kind='error'] { color: var(--danger); }
.change-note { width: 200px; }
.editor-toolbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 4px 16px; }
.tb-row { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: center; }
.tb-table { padding-top: 4px; margin-top: 4px; border-top: 1px solid var(--border); }
.tb-btn { min-width: 30px; height: 30px; padding: 0 5px; font: inherit; color: var(--text); background: none; border: 0; border-radius: 4px; cursor: pointer; }
.tb-btn:hover { background: var(--bg-hover); }
.tb-btn.active { background: var(--bg-active); color: var(--accent-text); }
.tb-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 5px; }
.tb-select { padding: 4px 6px; border-color: transparent; background: transparent; font-weight: 500; }
.tb-select:hover { background: var(--bg-hover); }
.tb-color { font-weight: 700; border-bottom: 3px solid #2563eb; }
.tb-hl { font-weight: 700; background: #fef08a; color: #1f2937; padding: 0 4px; border-radius: 2px; }
.tb-label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-right: 6px; }
.tb-text { font: inherit; font-size: 13px; color: var(--text); background: none; border: 0; padding: 3px 8px; border-radius: 4px; cursor: pointer; }
.tb-text:hover { background: var(--bg-hover); }
.editor-scroll { flex: 1; overflow-y: auto; background: var(--bg); }
.editor-page { max-width: 860px; margin: 0 auto; padding: 28px 40px; }
.title-input { width: 100%; border: 0; outline: none; resize: none; overflow: hidden; background: transparent; padding: 0; font-size: 30px; font-weight: 600; line-height: 1.25; margin-bottom: 14px; }

/* Editor menus */
.ed-menu, .ed-popover { position: absolute; z-index: 60; background: var(--surface); box-shadow: var(--shadow); border-radius: 6px; color: var(--text); font-size: 14px; }
.ed-menu { width: 300px; max-height: 300px; overflow-y: auto; padding: 6px 0; }
.ed-menu-group { padding: 6px 12px 2px; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.ed-menu-empty { padding: 8px 12px; color: var(--text-muted); }
.ed-menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 12px; font: inherit; color: var(--text); text-align: left; background: none; border: 0; cursor: pointer; }
.ed-menu-item:hover, .ed-menu-item.active { background: var(--bg-hover); }
.ed-menu-glyph { display: flex; align-items: center; justify-content: center; flex: none; width: 30px; height: 30px; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 4px; font-size: 12px; font-weight: 600; }
.ed-menu-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ed-menu-text small { color: var(--text-muted); font-size: 12px; }
.ed-popover { padding: 10px; }
.ed-form { display: flex; flex-direction: column; gap: 8px; width: 260px; }
.ed-form-row { display: flex; gap: 12px; }
.ed-input { width: 100%; }
.ed-swatches { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ed-swatch { width: 24px; height: 24px; padding: 0; border: 1px solid var(--border-strong); border-radius: 4px; cursor: pointer; }
.ed-status-swatch { width: 28px; height: 22px; padding: 0; border: 1px solid var(--border-strong); border-radius: 3px; cursor: pointer; }
.ed-link-btn { font: inherit; font-size: 13px; color: var(--accent-text); background: none; border: 0; padding: 2px 4px; cursor: pointer; }
.ed-emoji { display: grid; grid-template-columns: repeat(6, 34px); gap: 2px; }
.ed-emoji button { font-size: 18px; width: 34px; height: 34px; padding: 0; background: none; border: 0; border-radius: 4px; cursor: pointer; }
.ed-emoji button:hover { background: var(--bg-hover); }
.ed-insert { width: 260px; max-height: 340px; overflow-y: auto; margin: -4px; }

/* API tokens */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner-warning { background: var(--warning-bg); }

/* Document import */
.import-zone { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; margin-bottom: 8px; border: 1px dashed var(--border-strong); border-radius: 6px; }
.import-zone.dragging { border-color: var(--accent); background: var(--bg-active); }
.import-text { display: flex; flex-direction: column; flex: 1 1 240px; min-width: 0; }
.import-status { margin: 4px 0 8px; }
.template-heading { font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 14px 0 8px; }
.import-notes { margin: 6px 0 0; padding-left: 20px; }

/* Confluence sync */
.sync-form, .sync-running { margin-top: 16px; }
.sync-running progress { width: 100%; }
.sync-report p { margin: 6px 0; }
.sync-issues { margin-top: 10px; }
.sync-issues summary { cursor: pointer; font-weight: 500; margin-bottom: 8px; }
.space-picks { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.banner-error { background: var(--error-bg); }
.source-note { margin-top: 2px; }

/* History diff */
.diff { border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; }
.diff-line { padding: 3px 8px; border-radius: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff-line.added { background: var(--success-bg); }
.diff-line.removed { background: var(--error-bg); }
.diff-line.changed { background: var(--bg-subtle); }
.diff ins { background: var(--success-bg); color: var(--success-fg); text-decoration: none; font-weight: 500; }
.diff del { background: var(--error-bg); color: var(--error-fg); }

/* Search */
.search-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.search-form input { flex: 1 1 260px; min-width: 0; }
.search-form select { flex: 0 1 160px; min-width: 0; }
.results { display: flex; flex-direction: column; }
.result { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; color: var(--text); border-bottom: 1px solid var(--border); }
.result:hover { text-decoration: none; }
.result:hover .result-title { text-decoration: underline; }
.result-title { font-size: 16px; font-weight: 500; color: var(--accent-text); }
.result-snippet { overflow-wrap: anywhere; }
.result mark, .search-form mark { background: var(--mark); color: inherit; font-weight: 600; }
.pager { display: flex; gap: 8px; margin-top: 16px; }

/* People */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.person-card { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 20px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.person-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.profile-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.profile-head p { margin: 2px 0; }

/* Sign in */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--bg-subtle); }
.auth-card { width: 400px; max-width: 100%; padding: 32px; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.auth-card h1 { font-size: 20px; font-weight: 600; }
.auth-card > p { margin: 4px 0 18px; }
.demo-user { display: flex; align-items: center; gap: 12px; padding: 10px; font: inherit; color: var(--text); text-align: left; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.demo-user:hover { background: var(--bg-hover); }
.demo-user span:last-child { display: flex; flex-direction: column; min-width: 0; }
.demo-user small { color: var(--text-muted); }

/* Toasts */
#toasts { position: fixed; left: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { padding: 10px 14px; border-radius: 4px; background: #172b4d; color: #fff; box-shadow: var(--shadow); max-width: 420px; }
.toast-error { background: #ae2e24; }
.toast-success { background: #1f6f54; }

/* Small screens */
@media (max-width: 900px) {
  .home-cols { grid-template-columns: minmax(0, 1fr); }
  .space-layout { grid-template-columns: minmax(0, 1fr); }
  .side-toggle { display: flex; justify-content: flex-start; margin: 10px 16px 0; overflow: hidden; }
  .sidebar { display: none; position: static; height: auto; max-height: 60vh; margin-top: 10px; border-right: 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .sidebar.open { display: block; }
  .page-view { padding: 16px 16px 64px; }
  .editor-page { padding: 20px 16px; }
  .change-note { flex: 1 1 100%; order: 5; width: auto; }
  .editor-screen { height: auto; min-height: calc(100vh - var(--nav-height)); }
  .editor-toolbar { position: sticky; top: var(--nav-height); z-index: 10; }
  .tb-row { justify-content: flex-start; }
}
@media (max-width: 720px) {
  .topnav { height: auto; min-height: var(--nav-height); flex-wrap: wrap; padding: 8px 16px; }
  .topnav-links { order: 5; flex: 1 1 100%; height: 36px; }
  .topnav-spacer { display: none; }
  .brand span { display: none; }
  .search-box { flex: 1; min-width: 0; }
  .search-box input { width: 100%; }
  .page-wrap { padding: 20px 16px 48px; }
  .page-title, .title-input { font-size: 24px; }
  .filter { width: 100%; }
  #create-btn span { display: none; }
}

/* Export to PDF */
@media print {
  .topnav, .sidebar, .no-print, #toasts { display: none !important; }
  .space-layout { display: block; }
  .page-view { max-width: none; padding: 0; }
  body { background: #fff; color: #000; }
  .sd-comment-mark { background: none; border: 0; }
  .sd-expand-body { display: block; }
}
