:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37,99,235,.10);
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --mark: #fde68a;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 250px;
  --list-w: 420px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #242a32;
    --border: #2d343d;
    --text: #e6e8eb;
    --muted: #8b95a3;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59,130,246,.16);
    --warn-bg: #3a2f10;
    --warn-text: #fcd34d;
    --mark: #7c5e00;
    --code-bg: #0d1117;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); margin: 0; font-size: 13px; }
kbd {
  font: 11px/1 var(--mono);
  padding: 2px 5px; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface); color: var(--muted);
}
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
h1, h2, h3 { margin: 0; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.primary kbd { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-text { border-color: transparent; background: transparent; color: var(--danger); }
.btn.danger-text:hover { background: rgba(220,38,38,.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; justify-content: center; height: 38px; }
.btn.small-btn { height: 28px; padding: 0 10px; font-size: 13px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; flex: none;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; font-size: 13px; color: var(--primary); cursor: pointer; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
input[type=text], input[type=password], input[type=search], input[type=date], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea { resize: vertical; min-height: 60px; line-height: 1.55; }
input[type=search]::-webkit-search-cancel-button { display: none; }
.badge { font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.n { font-size: 12px; color: var(--muted); font-weight: normal; }

/* ---------- 品牌 ---------- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; letter-spacing: .2px; color: inherit; text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--primary); position: relative; flex: none; }
.brand-mark::before { content: ""; position: absolute; left: 5px; right: 5px; top: 6px; height: 2px; border-radius: 1px; background: #fff; box-shadow: 0 4px 0 #fff, 0 8px 0 rgba(255,255,255,.6); }
.brand-mark.big { width: 44px; height: 44px; border-radius: 12px; opacity: .85; }
.brand-mark.big::before { left: 10px; right: 10px; top: 12px; height: 4px; border-radius: 2px; box-shadow: 0 8px 0 #fff, 0 16px 0 rgba(255,255,255,.6); }

/* ---------- 登录 ---------- */
.login-view { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { font-size: 20px; }
.login-card p.muted { margin: -8px 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- 布局 ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 5;
}
.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 640px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 34px; padding-right: 32px; height: 36px; background: var(--surface-2); border-color: transparent; }
.search input:focus { background: var(--surface); border-color: var(--primary); }
.search #search-clear { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; }
/* 最近搜索下拉 */
.search-recent {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30; padding: 6px; min-width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.search-recent .sr-head { display: flex; align-items: center; padding: 4px 8px 6px; font-size: 11.5px; color: var(--muted); }
.search-recent .sr-head .link-btn { margin-left: auto; font-size: 11.5px; }
.search-recent .sr-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px 7px 10px; border-radius: 7px;
  font-size: 13.5px; color: var(--text); cursor: pointer;
}
.search-recent .sr-clock { flex: none; color: var(--muted); font-size: 13px; }
.search-recent .sr-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-recent .sr-item:hover, .search-recent .sr-item.active { background: var(--surface-2); }
.search-recent .sr-item .sr-del {
  flex: none; width: 22px; height: 22px; border: 0; border-radius: 50%; background: none; color: var(--muted);
  font-size: 16px; line-height: 1; cursor: pointer; opacity: 0;
}
.search-recent .sr-item:hover .sr-del, .search-recent .sr-item.active .sr-del { opacity: 1; }
.search-recent .sr-item .sr-del:hover { background: var(--border); color: var(--text); }
@media (hover: none) { .search-recent .sr-item .sr-del { opacity: 1; } }
.scope { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topbar #jump-btn { margin-left: auto; }
.user-menu { position: relative; }
.pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 150px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.pop button { border: 0; background: none; font: inherit; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.pop button:hover { background: var(--surface-2); }
.pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
body:not(.is-admin) .admin-only { display: none; }

.body { flex: 1; display: flex; min-height: 0; }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w); flex: none; padding: 12px 10px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item, .kind-head, .entity {
  display: flex; align-items: center; gap: 6px; border-radius: 8px; width: 100%;
}
.nav-item {
  justify-content: space-between; padding: 7px 10px; cursor: pointer; border: 0; background: none;
  font: inherit; color: var(--text); text-align: left;
}
.nav-item:hover, .entity:hover, .kind-head:hover { background: var(--surface-2); }
.nav-item.active, .entity.active, .kind-head.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active .n, .entity.active .n { color: var(--primary); }
.side-filter input { height: 32px; padding: 4px 10px; background: var(--surface-2); border-color: transparent; font-size: 13px; }
.side-filter input:focus { background: var(--surface); border-color: var(--primary); }
.kind-list { display: flex; flex-direction: column; gap: 8px; }
.kind-head { padding: 2px 2px 2px 0; }
.kind-head button { border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.kind-toggle { width: 20px; color: var(--muted) !important; font-size: 11px !important; padding: 0; flex: none; }
.kind-name { flex: 1; text-align: left; padding: 5px 0; font-size: 12px !important; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--muted) !important; display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.kind-head.active .kind-name { color: var(--primary) !important; }
.kind-add { width: 24px; height: 24px; border-radius: 6px; color: var(--muted) !important; font-size: 16px !important; line-height: 1; flex: none; }
.kind-add:hover { background: var(--border) !important; color: var(--text) !important; }
.entity-list { display: flex; flex-direction: column; gap: 1px; margin-top: 2px; }
.entity { padding-right: 4px; }
.entity.archived { opacity: .55; }
.entity-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; border: 0; background: none; font: inherit; color: inherit;
  text-align: left; cursor: pointer; padding: 6px 4px 6px 22px;
}
.entity-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-meta { font-size: 11.5px; color: var(--muted); font-weight: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.entity-edit { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 5px; display: none; font-size: 13px; }
.entity:hover .entity-edit { display: block; }
.entity:hover .n { display: none; }
.entity-edit:hover { background: var(--border); color: var(--text); }
@media (hover: none) { .entity-edit { display: block; } .entity:hover .n { display: inline; } }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex: none; box-shadow: 0 0 0 2px var(--surface); }
.kind-name .dot { align-self: center; }
.entity-empty { padding: 4px 22px; }
.archived-toggle { align-self: flex-start; padding: 2px 10px; font-size: 12px; }
.side-title { font-size: 12px; font-weight: 600; letter-spacing: .4px; color: var(--muted); padding: 0 10px 6px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; border: 0; font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted);
}
button.tag:hover { color: var(--text); }
.tag.active { background: var(--primary); color: #fff; }
.tag.active .n { color: rgba(255,255,255,.8); }
.tag.mini, .chip.mini { font-size: 11.5px; padding: 0 6px; cursor: inherit; }
.sidebar-mask { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 19; }

/* ---------- 备注流 ---------- */
.list-pane {
  width: var(--list-w); flex: none; overflow-y: auto; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; background: var(--bg);
}
.list-head { padding: 14px 16px 6px; }
.lh-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lh-row h2 { font-size: 17px; overflow-wrap: anywhere; }
.lh-count { margin-right: auto; }
.lh-meta { margin-top: 4px; }
.lh-meta code { font: 12.5px var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 5px; cursor: pointer; }
.lh-desc { margin-top: 4px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.filters { display: flex; gap: 6px; padding: 4px 12px 8px; align-items: center; flex-wrap: wrap; }
.filters select, .filters input { width: 84px; height: 28px; padding: 2px 6px; font-size: 12.5px; border-radius: 6px; color: var(--muted); background: transparent; }
.filters input[type=date] { width: 104px; }
.active-tags { display: flex; gap: 5px; flex-wrap: wrap; padding: 0 16px 8px; }
.quick { padding: 0 12px 10px; }
.quick textarea { min-height: 38px; height: 38px; resize: none; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; }
.quick-bar { display: flex; align-items: center; gap: 10px; padding: 6px 4px 0; }
.quick-bar .muted { margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list { display: flex; flex-direction: column; padding: 0 12px; gap: 6px; }
.note-item {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius); cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); transition: border-color .12s, box-shadow .12s;
}
.note-item:hover { border-color: var(--muted); }
.note-item.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.note-item.pinned { background: linear-gradient(0deg, var(--primary-soft), var(--primary-soft)), var(--surface); }
.ni-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ni-top { display: flex; align-items: baseline; gap: 6px; }
.pin { font-size: 11px; flex: none; }
.ni-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ni-time { flex: none; font-size: 12px; color: var(--muted); }
.ni-snippet { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.ni-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--muted); }
.ni-author { margin-left: auto; }
.ni-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; flex: none; background: var(--surface-2); align-self: center; }
.list-update {
  position: sticky; top: 8px; z-index: 3; align-self: center; margin: 8px 0 -4px; padding: 6px 16px; border: 0; border-radius: 99px;
  background: var(--primary); color: #fff; font: inherit; font-size: 13px; cursor: pointer; box-shadow: var(--shadow); flex: none;
}
.list-update:hover { background: var(--primary-hover); }
.note-item.flash { animation: note-flash 2.4s ease-out; }
@keyframes note-flash { 0%, 35% { box-shadow: 0 0 0 2px var(--primary); background: var(--primary-soft); } 100% { box-shadow: none; } }
.list-more { padding: 18px 16px 28px; text-align: center; min-height: 40px; }

/* ---------- 阅读 ---------- */
.reader { flex: 1; min-width: 0; overflow-y: auto; background: var(--surface); }
.reader-inner { max-width: 920px; margin: 0 auto; padding: 16px 28px 60px; }
.reader-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; position: sticky; top: 0; background: var(--surface); padding: 8px 0 10px; z-index: 2; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.reader-bar .danger-text { margin-left: auto; }
.back-btn { display: none; }
.reader-title { font-size: 24px; line-height: 1.3; overflow-wrap: anywhere; }
.reader-meta { margin-top: 6px; }
.reader-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.reader-body { margin-top: 20px; }
.reader-atts { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.reader-atts .side-title { padding-left: 0; }
.reader-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; color: var(--muted); }
.reader-empty ul { list-style: none; padding: 0; margin: 8px 0 0; line-height: 2.4; font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 6px; font: inherit; font-size: 12.5px;
  background: var(--primary-soft); color: var(--primary); border: 0;
}
.chip.link { cursor: pointer; }
.chip.link:hover { text-decoration: underline; }
.chip-sub { font-size: 11px; opacity: .7; }
.att-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.att-card {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); max-width: 100%; text-decoration: none; color: inherit;
}
.att-card.image { padding: 0; overflow: hidden; }
.att-card.image img { display: block; height: 96px; width: auto; max-width: 220px; object-fit: cover; }
.att-icon { flex: none; min-width: 34px; height: 24px; padding: 0 4px; border-radius: 5px; background: var(--surface-2); color: var(--muted); font: 600 10px/24px var(--mono); text-align: center; }
.att-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-actions { display: inline-flex; gap: 10px; margin-left: 6px; }

/* ---------- Markdown 正文 ---------- */
.md { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.4em 0 .5em; line-height: 1.35; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.28em; padding-bottom: .25em; border-bottom: 1px solid var(--border); } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md p, .md ul, .md ol, .md blockquote, .md .code-wrap, .md .table-wrap { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li > input[type=checkbox] { margin-right: 6px; }
.md a { color: var(--primary); }
.md img { max-width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; }
.md blockquote { padding: 2px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md code { font: .88em var(--mono); background: var(--surface-2); padding: .12em .4em; border-radius: 4px; }
.md pre { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg); font-size: 13px; line-height: 1.55; tab-size: 4; }
.md pre code, .md pre code.hljs { background: none; padding: 0; font-size: inherit; white-space: pre; }
.code-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 3px 6px 3px 14px; border-bottom: 1px solid var(--border); min-height: 28px; }
.code-lang { font: 11.5px var(--mono); color: var(--muted); }
.code-copy { border: 0; background: none; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 5px; }
.code-copy:hover { background: var(--surface-2); color: var(--text); }
.table-wrap { overflow-x: auto; }
.md table, .table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.md th, .md td, .table th, .table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: middle; }
.md th, .table th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.table tr.disabled td { opacity: .5; }
.table td input, .table td select { height: 30px; padding: 2px 8px; min-width: 90px; }
.table.keys td { border-left: 0; border-right: 0; }

/* ---------- 编辑器 ---------- */
.editor { height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 14px 20px 10px; }
.ed-head { display: flex; gap: 8px; align-items: center; }
.ed-title { flex: 1; font-size: 17px !important; font-weight: 600; height: 40px; }
.ed-row { display: flex; align-items: flex-start; gap: 8px; }
.ed-label { flex: none; width: 34px; padding-top: 7px; font-size: 12.5px; color: var(--muted); }
.chip-picker {
  flex: 1; position: relative; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; min-height: 34px;
  padding: 3px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.chip-picker:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.chips { display: contents; }
.chip-input { flex: 1; min-width: 160px; border: 0 !important; box-shadow: none !important; padding: 3px 4px !important; background: transparent !important; }
.chip-x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 14px; line-height: 1; opacity: .6; }
.chip-x:hover { opacity: 1; }
.chip-drop {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; max-height: 260px; overflow-y: auto; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.chip-opt { display: flex; width: 100%; align-items: baseline; gap: 8px; border: 0; background: none; font: inherit; color: var(--text); text-align: left; padding: 6px 9px; border-radius: 6px; cursor: pointer; }
.chip-opt.active, .chip-opt:hover { background: var(--surface-2); }
.chip-opt.create { color: var(--primary); }
.chip-opt .chip-sub { margin-left: auto; color: var(--muted); }
.ed-toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.ed-tool { min-width: 30px; height: 28px; padding: 0 7px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: 600 13px var(--mono); cursor: pointer; }
.ed-tool:hover { background: var(--surface-2); color: var(--text); }
.ed-spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--muted); padding: 3px 10px; cursor: pointer; }
.seg button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.ed-main { flex: 1; min-height: 200px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-main[data-mode=edit] { grid-template-columns: 1fr; }
.ed-main[data-mode=edit] .ed-preview { display: none; }
.ed-main[data-mode=preview] { grid-template-columns: 1fr; }
.ed-main[data-mode=preview] .ed-text { display: none; }
.ed-text { height: 100%; min-height: 0; resize: none; font: 13.5px/1.65 var(--mono); tab-size: 2; }
.ed-preview { min-height: 0; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; background: var(--bg); }
.ed-atts { display: flex; flex-wrap: wrap; gap: 6px; max-height: 96px; overflow-y: auto; }
.att { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 12.5px; background: var(--bg); }
.att img { width: 32px; height: 24px; object-fit: cover; border-radius: 4px; }
.att .att-name { max-width: 160px; }
.ed-foot { min-height: 18px; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 84vh; }
.modal.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; }
.modal-head h3 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 4px 20px 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .btn.danger:first-child, .modal-foot .btn:first-child:not(:only-child):nth-last-child(n+3) { margin-right: auto; }
.confirm-text { margin: 6px 0; white-space: pre-wrap; line-height: 1.7; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form p { margin: 0; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; }
.token-box { display: flex; gap: 8px; align-items: center; }
.token-box code { flex: 1; font: 12.5px var(--mono); padding: 8px 10px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; }
.token-usage { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.token-usage .row { justify-content: space-between; }
.token-example-wrap { position: relative; }
.token-example-wrap .code-copy { position: absolute; right: 6px; top: 6px; background: var(--surface); border: 1px solid var(--border); }
.token-tip { border-top: 1px solid var(--border); padding-top: 10px; }
.token-tip summary { cursor: pointer; font-size: 13px; color: var(--primary); user-select: none; }
.token-tip[open] summary { margin-bottom: 8px; }
.token-tip p { margin: 0 0 8px; line-height: 1.7; }
.token-tip .token-example-wrap { margin-bottom: 8px; }
.token-example { margin: 0; font: 12px/1.6 var(--mono); padding: 10px 12px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; padding-right: 56px; white-space: pre; }
.rev { display: grid; grid-template-columns: 220px 1fr; gap: 16px; min-height: 320px; }
.rev-list { display: flex; flex-direction: column; gap: 3px; max-height: 60vh; overflow-y: auto; }
.rev-item { display: flex; flex-direction: column; gap: 2px; border: 0; background: none; font: inherit; color: var(--text); text-align: left; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.rev-item:hover, .rev-item.active { background: var(--surface-2); }
.rev-item.active { box-shadow: inset 3px 0 0 var(--primary); }
.rev-view { max-height: 60vh; overflow-y: auto; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 14px; }
.jump-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.jump-item { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; border: 0; background: none; font: inherit; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.jump-item.active, .jump-item:hover { background: var(--surface-2); }

/* ---------- 图片放大 / 拖拽 / 上传队列 / 提示 ---------- */
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; overflow: auto; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.lightbox-open { position: fixed; right: 20px; top: 16px; }
.drop-overlay { position: fixed; inset: 0; z-index: 70; background: rgba(37,99,235,.18); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-overlay div { padding: 22px 40px; border: 2px dashed var(--primary); border-radius: 16px; background: var(--surface); font-size: 18px; font-weight: 600; color: var(--primary); }
.upload-queue { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 6px; width: 300px; max-width: calc(100vw - 32px); }
.up-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 8px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 12.5px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-text { color: var(--muted); }
.up-item.error .up-text { color: var(--danger); grid-column: 1 / -1; white-space: normal; }
.up-track { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.up-bar { height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.toasts { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 9px 16px; border-radius: 99px; background: #1f2328; color: #fff; font-size: 13.5px; box-shadow: var(--shadow); max-width: 86vw; transition: opacity .3s, transform .3s; }
.toast.clickable { pointer-events: auto; cursor: pointer; }
.toast.clickable:hover { filter: brightness(1.25); }
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- 角色权限 / 标签管理 ---------- */
.roles { display: grid; grid-template-columns: 190px 1fr; gap: 18px; min-height: 380px; }
.role-list { display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--border); padding-right: 12px; }
.role-item { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; border: 0; background: none; font: inherit; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.role-item:hover { background: var(--surface-2); }
.role-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.role-add { padding: 8px 10px; text-align: left; }
.role-pane { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.role-pane p { margin: 0; line-height: 1.7; }
.grant-table { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.grant-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--border); }
.grant-row:last-child { border-bottom: 0; }
.grant-row.head { background: var(--surface-2); }
.grant-row.sub { padding-left: 40px; background: var(--bg); font-size: 13px; }
.grant-name { display: flex; align-items: center; gap: 4px; min-width: 0; flex-wrap: wrap; }
.grant-name .kind-toggle { border: 0; background: none; cursor: pointer; }
.grant-eff { margin-left: 8px; font-size: 11.5px; padding: 0 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.grant-eff.lv-read { background: var(--warn-bg); color: var(--warn-text); }
.grant-eff.lv-write { background: var(--primary-soft); color: var(--primary); }
.grant-row .seg { flex: none; }
.users-table { overflow: visible; }
.role-cell { min-width: 220px; }
.role-cell .chip-picker { min-height: 30px; padding: 2px 5px; }
.role-cell .chip-input { min-width: 60px; }
tr.no-role td { background: var(--warn-bg); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 4px 0; color: var(--text); }
.checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tag-rows { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.tag.unused { opacity: .55; border: 1px dashed var(--border); background: transparent; }
.entity-ro { font-size: 10.5px; color: var(--warn-text); background: var(--warn-bg); border-radius: 4px; padding: 0 4px; flex: none; }
.side-empty { padding: 8px 10px; line-height: 1.8; }

/* ---------- 日历 ---------- */
:root { --k0: #2563eb; --k1: #16a34a; --k2: #d97706; --k3: #9333ea; --k4: #dc2626; --k5: #0891b2; --k6: #db2777; --k7: #65a30d; }
@media (prefers-color-scheme: dark) {
  :root { --k0: #60a5fa; --k1: #4ade80; --k2: #fbbf24; --k3: #c084fc; --k4: #f87171; --k5: #22d3ee; --k6: #f472b6; --k7: #a3e635; }
}
body.cal-mode .sidebar, body.cal-mode .list-pane, body.cal-mode .reader, body.cal-mode .sidebar-mask { display: none !important; }
body.cal-mode .scope { display: none; }
body.cal-mode #cal-btn { background: var(--primary-soft); color: var(--primary); }
.calendar { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.cal-head { flex: none; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.cal-nav { display: flex; align-items: center; gap: 4px; }
.cal-nav .icon-btn { font-size: 22px; }
.cal-title { position: relative; font-size: 18px; font-weight: 600; min-width: 116px; text-align: center; cursor: pointer; border-radius: 6px; padding: 2px 6px; }
.cal-title:hover { background: var(--surface-2); }
/* 原生月份选择器盖在标题上、透明：点标题就弹出浏览器自带的选月面板 */
.cal-month-input { position: absolute; inset: 0; width: 100% !important; height: 100%; opacity: 0; cursor: pointer; padding: 0 !important; }
.cal-spacer { flex: 1; }
.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-filters { display: flex; align-items: center; gap: 8px; }
.cal-filters select { width: auto; max-width: 160px; height: 30px; padding: 2px 8px; font-size: 13px; }
.cal-mine { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.cal-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.cal-dot.k0 { background: var(--k0); } .cal-dot.k1 { background: var(--k1); } .cal-dot.k2 { background: var(--k2); } .cal-dot.k3 { background: var(--k3); }
.cal-dot.k4 { background: var(--k4); } .cal-dot.k5 { background: var(--k5); } .cal-dot.k6 { background: var(--k6); } .cal-dot.k7 { background: var(--k7); }
.cal-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: auto repeat(6, minmax(0, 1fr)); }
.cal-weekday { padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal-cell { min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 2px; padding: 4px 6px 4px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-weekday:nth-child(7n), .cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.weekend, .cal-weekday.weekend { background: var(--bg); }
.cal-cell.other-month { opacity: .45; }
.cal-cell.has-notes { cursor: pointer; }
.cal-cell.has-notes:hover { box-shadow: inset 0 0 0 1px var(--muted); }
.cal-date { flex: none; display: flex; align-items: center; justify-content: space-between; height: 22px; }
.cal-num { font-size: 12.5px; color: var(--muted); padding: 1px 6px; border-radius: 99px; }
.cal-cell.today .cal-num { background: var(--primary); color: #fff; font-weight: 600; }
.cal-count { font-size: 11px; color: var(--muted); background: var(--surface-2); border-radius: 99px; padding: 0 7px; }
.cal-items { display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.cal-item { display: flex; align-items: center; gap: 5px; height: 20px; padding: 0 4px; border-radius: 4px; font-size: 12.5px; color: var(--text); text-decoration: none; }
.cal-item:hover { background: var(--primary-soft); color: var(--primary); }
.cal-time { flex: none; font: 11px var(--mono); color: var(--muted); }
.cal-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-more { align-self: flex-start; height: 20px; border: 0; background: none; padding: 0 4px; font: inherit; font-size: 12px; color: var(--primary); cursor: pointer; }
.cal-more:hover { text-decoration: underline; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 3px; padding: 2px 4px; }
.cal-day-list { display: flex; flex-direction: column; gap: 4px; }
.cal-day-item { display: flex; align-items: flex-start; gap: 12px; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--text); border: 1px solid transparent; }
.cal-day-item:hover { background: var(--surface-2); border-color: var(--border); }
.cal-day-item .cal-time { padding-top: 3px; font-size: 12px; }
.cal-day-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.cal-day-title { font-weight: 600; overflow-wrap: anywhere; }
.cal-day-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-open { flex: none; padding-top: 3px; opacity: 0; }
.cal-day-item:hover .cal-open { opacity: 1; }
.chip.mini .cal-dot { width: 6px; height: 6px; }

/* ---------- 窄屏 ---------- */
@media (max-width: 1280px) {
  :root { --sidebar-w: 220px; --list-w: 340px; }
  #jump-btn kbd, #new-btn kbd, #cal-btn kbd { display: none; }
}
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .brand-text, #jump-btn, .scope, .new-text, #cal-btn kbd, .cal-legend, .cal-head kbd { display: none; }
  .cal-head { gap: 8px; padding: 8px 10px; }
  .cal-filters { width: 100%; }
  .cal-filters select { flex: 1; min-width: 0; }
  .cal-cell { padding: 3px; align-items: center; }
  .cal-date { flex-direction: column; height: auto; gap: 2px; }
  .cal-count { display: none; }
  .cal-dots { justify-content: center; }
  .cal-weekday { text-align: center; padding: 6px 0; }
  .topbar { gap: 8px; padding: 0 10px; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: 0; z-index: 20; width: min(300px, 84vw); transform: translateX(-100%); transition: transform .18s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .list-pane { width: auto; flex: 1; border-right: 0; }
  .reader { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 15; display: none; }
  body.reading .reader { display: block; }
  .back-btn { display: inline-flex; }
  .reader-inner { padding: 8px 16px 60px; }
  .reader-title { font-size: 20px; }
  .editor { padding: 10px 12px; }
  .ed-head { flex-wrap: wrap; }
  .ed-title { flex-basis: 100%; }
  .rev { grid-template-columns: 1fr; }
  .roles { grid-template-columns: 1fr; }
  .role-list { border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 8px; flex-direction: row; flex-wrap: wrap; }
  .grant-row { flex-wrap: wrap; }
  .rev-list { max-height: 140px; }
}
