/* ============================================================
   Atlas — design system
   ============================================================ */
:root {
  --sidebar-w: 286px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --ease: cubic-bezier(.2, .7, .3, 1);
}

html[data-theme="dark"] {
  --bg: #0e1015;
  --sidebar: #12151c;
  --panel: #161a23;
  --panel-2: #1c212c;
  --panel-3: #232936;
  --border: #262d3b;
  --border-soft: #1e2431;
  --text: #e7eaf0;
  --text-strong: #ffffff;
  --muted: #98a2b3;
  --muted-2: #6b7686;
  --accent: #5b93ff;
  --accent-soft: rgba(91, 147, 255, .16);
  --accent-text: #cfe0ff;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, .14);
  --ok: #4ade80;
  --warn: #fbbf24;
  --code-bg: #10141c;
  --mark: #ffd166;
  --selection: rgba(91, 147, 255, .3);
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-comment: #8b949e;
  --hl-number: #79c0ff;
  --hl-title: #d2a8ff;
  --hl-attr: #79c0ff;
  --hl-builtin: #ffa657;
  --hl-meta: #8b949e;
  --hl-variable: #ffa657;
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --panel-2: #f3f5f8;
  --panel-3: #e9edf3;
  --border: #e2e6ee;
  --border-soft: #eef1f6;
  --text: #1b2130;
  --text-strong: #0b1020;
  --muted: #5d6675;
  --muted-2: #8a93a3;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .1);
  --accent-text: #1d4ed8;
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, .08);
  --ok: #067647;
  --warn: #b54708;
  --code-bg: #f4f6fa;
  --mark: #7a5b00;
  --selection: rgba(37, 99, 235, .18);
  --shadow: 0 10px 30px rgba(16, 24, 40, .1);
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-comment: #6e7781;
  --hl-number: #0550ae;
  --hl-title: #8250df;
  --hl-attr: #0550ae;
  --hl-builtin: #953800;
  --hl-meta: #6e7781;
  --hl-variable: #953800;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--selection); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------- layout ---------------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; }
.main-wrap { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

/* ---------------- sidebar ---------------- */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 14px 14px 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 650; font-size: 15.5px; letter-spacing: -.01em; color: var(--text-strong); }
.brand-tag { font-size: 11.5px; color: var(--muted-2); margin-top: -2px; }

.side-search { margin: 10px 12px 6px; position: relative; }
.side-search input {
  width: 100%; padding: 8px 10px 8px 30px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  outline: none; font-size: 13.5px;
}
.side-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.side-search svg { position: absolute; left: 9px; top: 9px; opacity: .55; }

.side-nav { padding: 4px 8px; }
.side-link {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px;
  color: var(--text); font-size: 13.8px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
}
.side-link:hover { background: var(--panel-2); text-decoration: none; }
.side-link.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.side-link .ico { width: 16px; text-align: center; opacity: .9; }
.side-link .count { margin-left: auto; font-size: 11px; color: var(--muted-2); }

.side-section { padding: 12px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2); font-weight: 650; display: flex; align-items: center; justify-content: space-between; }
.side-section .add-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 5px; }
.side-section .add-btn:hover { background: var(--panel-2); color: var(--accent); }

.side-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 12px; }
.sidebar-foot { border-top: 1px solid var(--border-soft); padding: 8px; display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 650; color: #fff; flex: none; background: linear-gradient(140deg, #6366f1, #0ea5e9); }
.who { min-width: 0; }
.who b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: 11px; color: var(--muted-2); text-transform: capitalize; }

/* tree */
.space-block { margin: 2px 0 8px; }
.space-row { display: flex; align-items: center; gap: 7px; padding: 6px 10px 6px 12px; cursor: pointer; border-radius: 7px; margin: 0 6px; }
.space-row:hover { background: var(--panel-2); }
.space-row.active { background: var(--panel-2); }
.space-row .chev { width: 12px; font-size: 9px; color: var(--muted-2); transition: transform .15s var(--ease); }
.space-row.open .chev { transform: rotate(90deg); }
.space-row .s-ico { font-size: 14px; }
.space-row .s-name { font-size: 13.5px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.space-row .s-badge { font-size: 10px; color: var(--muted-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }

.tree { list-style: none; margin: 2px 0 0; padding: 0 0 0 10px; }
.tree .tree { padding-left: 12px; margin-left: 8px; border-left: 1px solid var(--border-soft); }
.tree-item {
  display: flex; align-items: center; gap: 6px; padding: 4.5px 8px; margin: 0 6px 0 0;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text);
  position: relative; border: 1px solid transparent;
}
.tree-item:hover { background: var(--panel-2); }
.tree-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.tree-item .twisty { width: 12px; font-size: 9px; color: var(--muted-2); flex: none; text-align: center; }
.tree-item .t-ico { font-size: 12px; opacity: .85; flex: none; }
.tree-item .t-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-item .t-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--warn); flex: none; }
.tree-item.dragging { opacity: .45; }
.tree-item.drop-into { background: var(--accent-soft); border-color: var(--accent); }
.tree-item.drop-before::before { content: ''; position: absolute; left: 0; right: 0; top: -2px; height: 2px; background: var(--accent); border-radius: 2px; }
.tree-empty { color: var(--muted-2); font-size: 12px; padding: 4px 18px 6px 28px; font-style: italic; }

/* ---------------- topbar ---------------- */
.topbar {
  height: 52px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border-soft); background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; flex: 1; }
.crumbs a { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: .45; }
.crumbs .current { color: var(--text-strong); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.offline-pill { font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--warn); background: rgba(251, 191, 36, .12); border: 1px solid rgba(251, 191, 36, .35);
  padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none;
  color: var(--muted); cursor: pointer; display: grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { color: var(--warn); }

/* ---------------- view ---------------- */
.view { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.view-inner { max-width: 860px; margin: 0 auto; padding: 30px 32px 120px; }
.view-wide { max-width: 1120px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font-size: 13.3px; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.3px; border-radius: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- page view ---------------- */
.page-head { margin-bottom: 18px; }
.page-title { font-size: 31px; line-height: 1.2; font-weight: 700; letter-spacing: -.022em; color: var(--text-strong); margin: 0 0 8px; }
.page-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted-2); }
.page-meta .dot { opacity: .5; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1.5px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--panel-3); color: var(--muted); border: 1px solid var(--border); }
.badge.draft { background: rgba(251, 191, 36, .13); color: var(--warn); border-color: transparent; }
.badge.folder { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

.page-actions { display: flex; gap: 8px; margin: 16px 0 22px; flex-wrap: wrap; }

/* prose */
.prose { font-size: 15.4px; line-height: 1.7; color: var(--text); overflow-wrap: break-word; }
.prose > *:first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { color: var(--text-strong); font-weight: 650; letter-spacing: -.015em; line-height: 1.3; margin: 1.9em 0 .6em; scroll-margin-top: 70px; }
.prose h1 { font-size: 26px; } .prose h2 { font-size: 21px; } .prose h3 { font-size: 17.5px; } .prose h4 { font-size: 15.5px; }
.prose p { margin: 0 0 1em; }
.prose ul, .prose ol { margin: 0 0 1em; padding-left: 1.5em; }
.prose li { margin: .25em 0; }
.prose li > p { margin: 0; }
.prose blockquote { margin: 1.1em 0; padding: .3em 0 .3em 1em; border-left: 3px solid var(--accent); color: var(--muted); background: var(--panel-2); border-radius: 0 8px 8px 0; }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code { font-family: var(--mono); font-size: .87em; background: var(--panel-3); padding: .16em .4em; border-radius: 5px; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; margin: 1.1em 0; }
.prose pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }

/* highlight.js token colors — theme-aware via the vars above */
.prose pre code.hljs { display: block; overflow-x: auto; background: transparent; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-name, .hljs-tag { color: var(--hl-keyword); font-weight: 600; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-template-string { color: var(--hl-string); }
.hljs-comment, .hljs-quote, .hljs-deletion { color: var(--hl-comment); font-style: italic; }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-title.function_, .hljs-title.class_ { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-selector-attr, .hljs-selector-class, .hljs-selector-id, .hljs-property { color: var(--hl-attr); }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title { color: var(--hl-builtin); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--hl-meta); }
.hljs-variable, .hljs-template-variable, .hljs-params { color: var(--hl-variable); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.prose img { max-width: 100%; border-radius: var(--radius); display: block; margin: 1.2em auto; border: 1px solid var(--border-soft); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 1.2em 0; font-size: 14px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.prose th { background: var(--panel-2); font-weight: 650; color: var(--text-strong); }
.prose a.wiki-link { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.prose a.wiki-link:hover { background: var(--accent-soft); text-decoration: none; }
.prose a.wiki-link.missing { color: var(--danger); border-bottom: 1px dashed var(--danger); }
.prose a.wiki-link.missing::after { content: '?'; font-size: .8em; vertical-align: super; margin-left: 1px; opacity: .8; }
.prose li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.15em; }
.prose input[type="checkbox"] { margin-right: .5em; accent-color: var(--accent); }
.prose mark { background: var(--accent-soft); color: var(--accent-text); padding: 0 2px; border-radius: 3px; }

/* tag chips */
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 18px 0 0; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); cursor: pointer; }
.tag:hover { color: var(--accent); border-color: var(--accent); }

/* child pages */
.child-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 10px 0 0; }
.child-card { display: block; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); }
.child-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.child-card b { display: block; font-size: 13.8px; font-weight: 600; margin-bottom: 2px; }
.child-card span { font-size: 12px; color: var(--muted-2); }

.section { margin-top: 42px; }
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-head h2 { font-size: 15px; font-weight: 650; margin: 0; color: var(--text-strong); letter-spacing: -.01em; }
.section-head .n { font-size: 11.5px; color: var(--muted-2); background: var(--panel-2); border-radius: 999px; padding: 1px 7px; }
.section-head .spacer { flex: 1; }

/* comments */
.comment { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border-soft); }
.comment:first-of-type { border-top: 0; }
.comment.resolved { opacity: .6; }
.comment-body { flex: 1; min-width: 0; }
.comment-top { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.comment-top b { font-size: 13px; color: var(--text-strong); }
.comment-top time { color: var(--muted-2); font-size: 11.5px; }
.comment-text { font-size: 14px; margin-top: 3px; white-space: pre-wrap; overflow-wrap: break-word; }
.comment-actions { display: flex; gap: 4px; margin-top: 4px; }
.comment-actions button { background: none; border: 0; color: var(--muted-2); font-size: 11.5px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.comment-actions button:hover { color: var(--accent); background: var(--panel-2); }
.comment-form { display: flex; gap: 10px; margin-top: 14px; }
.comment-form textarea { flex: 1; min-height: 62px; resize: vertical; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); outline: none; }
.comment-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* anchored comments */
.anchor-quote { margin: 6px 0 4px; padding: 6px 10px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 6px 6px 0; font-size: 13px; color: var(--text);
  cursor: pointer; white-space: pre-wrap; overflow-wrap: break-word; }
.anchor-quote:hover { filter: brightness(1.12); }
.anchor-quote.missing { border-left-color: var(--muted-2); background: var(--panel-2); color: var(--muted); text-decoration: line-through; }
mark.anchor-hl { background: var(--accent-soft); color: inherit; border-bottom: 2px solid var(--accent); border-radius: 2px; padding: 0 1px; scroll-margin-top: 90px; }
mark.anchor-hl.flash { animation: anchor-flash 1.6s ease-out; }
@keyframes anchor-flash { 0%, 40% { background: var(--accent); color: var(--accent-fg, #fff); } 100% { background: var(--accent-soft); } }
.sel-comment-btn { position: fixed; z-index: 60; padding: 5px 11px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel); color: var(--text-strong);
  box-shadow: 0 6px 20px rgba(0,0,0,.35); cursor: pointer; }
.sel-comment-btn:hover { border-color: var(--accent); color: var(--accent); }

/* live collaboration + drag targets */
.presence { margin-left: auto; font-size: 12px; color: var(--muted-2); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.live-banner { display: flex; align-items: center; gap: 12px; margin: 10px 0 14px; padding: 9px 13px;
  border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; font-size: 13px; color: var(--text-strong); }
.live-banner[hidden] { display: none; }
.child-card.dragging { opacity: .45; }
.child-card.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
.page-head.drop-target { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 8px; }

/* attachments */
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); font-size: 13px; }
.att .a-ico { width: 26px; height: 26px; border-radius: 6px; background: var(--panel-3); display: grid; place-items: center; font-size: 12px; }
.att .a-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .a-size { color: var(--muted-2); font-size: 11.5px; }
.att img.thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 6px; }

/* ---------------- cards / home ---------------- */
.hero { padding: 8px 0 26px; }
.hero h1 { font-size: 27px; margin: 0 0 6px; letter-spacing: -.02em; color: var(--text-strong); }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--panel);
  padding: 15px 16px; display: block; color: var(--text);
}
a.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card .c-top { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.card .c-ico { font-size: 18px; }
.card .c-title { font-weight: 650; font-size: 14.5px; color: var(--text-strong); }
.card .c-desc { font-size: 12.8px; color: var(--muted); line-height: 1.5; margin-bottom: 10px; min-height: 2.4em; }
.card .c-foot { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--muted-2); }

.list-rows { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.row-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border-soft); color: var(--text); font-size: 13.5px; }
.row-item:first-child { border-top: 0; }
.row-item:hover { background: var(--panel-2); text-decoration: none; }
.row-item .r-title { font-weight: 550; }
.row-item .r-sub { color: var(--muted-2); font-size: 12px; }
.row-item .r-right { margin-left: auto; color: var(--muted-2); font-size: 11.5px; white-space: nowrap; }

/* ---------------- editor ---------------- */
.editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.title-input {
  width: 100%; font-size: 27px; font-weight: 700; letter-spacing: -.02em; color: var(--text-strong);
  background: transparent; border: 0; outline: none; padding: 6px 0; font-family: inherit;
}
.title-input::placeholder { color: var(--muted-2); }
.editor-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 7px 0; border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--text-strong); box-shadow: 0 1px 2px rgba(0,0,0,.15); font-weight: 550; }

.md-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.md-pane textarea {
  width: 100%; min-height: 65vh; resize: vertical; padding: 15px 17px;
  font-family: var(--mono); font-size: 13.3px; line-height: 1.65;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  outline: none; tab-size: 2;
}
.md-pane textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.md-preview { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 16px 18px; min-height: 65vh; overflow-y: auto; max-height: 78vh; }
.md-preview .prose { font-size: 14.5px; }
.pane-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2); font-weight: 650; margin-bottom: 6px; }
.md-toolbar { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; margin-bottom: 8px; }

.rt-toolbar { border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--panel-2); padding: 6px 8px; margin-bottom: 0; }
.rt-sep { width: 1px; height: 18px; background: var(--border); display: inline-block; margin: 0 4px; }
.rt-select { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; font-size: 12.5px; color: var(--text); }
.rt-editor {
  border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius);
  background: var(--panel); padding: 18px 20px; min-height: 60vh; outline: none; font-size: 15.4px;
}
.rt-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rt-editor.is-empty::before { content: attr(data-placeholder); color: var(--muted-2); }
.rt-editor table { width: 100%; }

.editor-foot { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-soft); position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, transparent); padding-bottom: 6px; }
.save-state { font-size: 12.5px; color: var(--muted-2); }
.save-state.dirty { color: var(--warn); }
.kbd { font-family: var(--mono); font-size: 10.5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--muted-2); }

/* wiki autocomplete */
.ac-pop { position: absolute; z-index: 60; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow); padding: 4px; min-width: 230px; max-height: 260px; overflow-y: auto; }
.ac-item { display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ac-item:hover, .ac-item.sel { background: var(--accent-soft); color: var(--accent-text); }
.ac-item .ac-sub { margin-left: auto; font-size: 11px; color: var(--muted-2); }

/* ---------------- history / diff ---------------- */
.rev-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.rev-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border-soft); font-size: 13px; }
.rev-row:first-child { border-top: 0; }
.rev-row:hover { background: var(--panel-2); }
.rev-no { font-family: var(--mono); font-size: 12px; color: var(--muted-2); width: 34px; }
.rev-note { flex: 1; min-width: 0; }
.rev-note b { font-weight: 550; }
.rev-note span { color: var(--muted-2); font-size: 11.5px; }
.diff { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-family: var(--mono); font-size: 12.4px; line-height: 1.6; }
.diff-line { padding: 1px 12px; white-space: pre-wrap; word-break: break-word; }
.diff-line.add { background: rgba(74, 222, 128, .13); color: var(--ok); }
.diff-line.del { background: rgba(255, 107, 107, .12); color: var(--danger); }
.diff-line.ctx { color: var(--muted); }
.diff-line.blank { background: var(--panel-2); color: var(--muted-2); }

/* ---------------- forms / admin ---------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 90px; resize: vertical; }
.hint { font-size: 11.8px; color: var(--muted-2); margin-top: 4px; }
.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tr:hover td { background: var(--panel-2); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 8px 13px; font-size: 13px; color: var(--muted); cursor: pointer; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-weight: 700; color: var(--text-strong); letter-spacing: -.02em; }
.stat span { font-size: 11.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .05em; }

/* ---------------- search ---------------- */
.search-hero { margin-bottom: 18px; }
.search-hero h1 { font-size: 22px; margin: 0 0 4px; color: var(--text-strong); }
.search-results { display: flex; flex-direction: column; gap: 4px; }
.result { display: block; padding: 12px 14px; border-radius: var(--radius); border: 1px solid transparent; color: var(--text); }
.result:hover { background: var(--panel); border-color: var(--border); text-decoration: none; }
.result .r-head { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--text-strong); }
.result .r-crumb { font-size: 11.5px; color: var(--muted-2); margin-left: auto; }
.result .r-snip { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.55; }
.result .r-snip mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 2px; padding: 0 1px; }

/* ---------------- auth / setup ---------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; color: var(--text-strong); }
.auth-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.auth-err { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; margin-bottom: 12px; display: none; }
.auth-err.show { display: block; }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted-2); margin-top: 16px; }

/* ---------------- modal / toast ---------------- */
.modal-back { position: fixed; inset: 0; background: rgba(5, 8, 14, .55); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 480px; padding: 20px; max-height: 86vh; overflow-y: auto; }
.modal h2 { font-size: 17px; margin: 0 0 4px; color: var(--text-strong); }
.modal p.m-sub { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal.wide { max-width: 720px; }

.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--panel-3); border: 1px solid var(--border); color: var(--text); padding: 9px 14px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow); animation: toast-in .18s var(--ease); }
.toast.err { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.empty { text-align: center; padding: 48px 20px; color: var(--muted-2); font-size: 13.5px; }
.empty b { display: block; font-size: 15px; color: var(--muted); margin-bottom: 4px; }
.skeleton { height: 14px; border-radius: 5px; background: var(--panel-2); animation: pulse 1.3s infinite; margin-bottom: 9px; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------------- responsive ---------------- */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 90; transform: translateX(-100%); transition: transform .2s var(--ease); box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .md-wrap { grid-template-columns: 1fr; }
  .view-inner { padding: 22px 18px 100px; }
  .menu-btn { display: grid !important; }
}
.menu-btn { display: none; }

/* ---------------- v1.1: tasks, palette, filters, health ---------------- */

/* interactive GFM task checkboxes */
.prose input.task-toggle {
  appearance: none; width: 15px; height: 15px; margin: 0 7px 0 0; vertical-align: -2px;
  border: 1.5px solid var(--border); border-radius: 4px; background: var(--panel-2);
  cursor: pointer; position: relative; transition: background .12s var(--ease), border-color .12s var(--ease);
}
.prose input.task-toggle:hover { border-color: var(--accent); }
.prose input.task-toggle:checked { background: var(--accent); border-color: var(--accent); }
.prose input.task-toggle:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.prose input.task-toggle:disabled { opacity: .6; cursor: progress; }
.prose li:has(> input.task-toggle:checked) { color: var(--muted-2); text-decoration: line-through; }
.prose li:has(> input.task-toggle:checked) a { text-decoration: line-through; }

/* table of contents */
.toc {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px;
  padding: 10px 14px; margin: 0 0 18px; font-size: 12.5px; line-height: 1.7;
}
.toc-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); margin-bottom: 6px; font-weight: 650; }
.toc a { display: block; color: var(--muted); text-decoration: none; border-radius: 5px; padding: 1px 4px; }
.toc a:hover { color: var(--text-strong); background: var(--panel-3); }
.toc .toc-h3 { padding-left: 16px; font-size: 12px; }

/* command palette */
.palette-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 300;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh;
  animation: fade-in .12s var(--ease);
}
.palette {
  width: min(620px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 18px 60px rgba(0,0,0,.45); overflow: hidden;
}
.palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent;
  color: var(--text-strong); font-size: 15px; padding: 15px 18px; outline: none;
}
.palette-results { max-height: 46vh; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; background: none; color: var(--text); font-size: 13.5px;
  border-radius: 8px; cursor: pointer; text-decoration: none;
}
.palette-item.active, .palette-item:hover { background: var(--panel-2); text-decoration: none; }
.palette-item .p-title { font-weight: 550; }
.palette-item .p-space { margin-left: auto; color: var(--muted-2); font-size: 11.5px; }
.palette-hint { padding: 12px 14px; color: var(--muted-2); font-size: 12.5px; }
@keyframes fade-in { from { opacity: 0; } }

/* notification bell */
.icon-btn[data-bell] { position: relative; }
.bell-count {
  position: absolute; top: -3px; right: -3px; min-width: 15px; height: 15px; padding: 0 4px;
  background: var(--danger); color: #fff; border-radius: 999px; font-size: 9.5px;
  font-weight: 700; line-height: 15px; text-align: center;
}
.row-item.notif.read { opacity: .55; }
.row-item.notif .r-title { font-weight: 500; }

/* search filters + saved searches */
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filter-row .select, .filter-row .input { height: 34px; font-size: 12.5px; }
.saved-searches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.saved-searches .hint { color: var(--muted-2); font-size: 11.5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px;
}
.chip a { color: var(--text); text-decoration: none; }
.chip a:hover { color: var(--accent); }
.chip-x {
  border: 0; background: none; color: var(--muted-2); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 1px 5px; border-radius: 999px;
}
.chip-x:hover { color: var(--danger); background: var(--danger-soft); }

/* knowledge health card */
.health-card { margin-top: 26px; }
.health-summary { display: flex; gap: 28px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.health-stat b { display: block; font-size: 22px; font-weight: 650; color: var(--text-strong); letter-spacing: -.02em; }
.health-stat span { font-size: 12px; color: var(--muted-2); }
.health-detail { margin-top: 12px; }
.health-detail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2); margin: 0 0 6px; font-weight: 650; }

/* threaded comments */
.comment.reply { margin-left: 26px; border-left: 2px solid var(--border); padding-left: 12px; }
.comment-form textarea { min-height: 64px; }
.comment-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.link-btn { border: 0; background: none; color: var(--muted-2); font-size: 11.5px; cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.link-btn:hover { color: var(--accent); background: var(--panel-2); }

/* print: drop chrome so "Print / PDF" yields a clean document */
@media print {
  .sidebar, .topbar, .toc, .page-actions, .comment-form, .health-card,
  .toast-root, .palette-back, .modal-back { display: none !important; }
  .app-shell { display: block; }
  .view-inner { padding: 0 !important; max-width: 100% !important; }
  .prose { color: #000; }
  .prose a { color: #000; text-decoration: underline; }
  .prose input.task-toggle { border-color: #555; }
}
