:root {
  --bg: #f7f7f5; --surface: #ffffff; --text: #1a1a1a; --muted: #6b7280;
  --border: #e5e7eb; --accent: #2563eb; --accent-soft: #eff6ff;
  --danger: #dc2626; --ok: #16a34a; --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
[data-theme="dark"] {
  --bg: #111827; --surface: #1f2937; --text: #f3f4f6; --muted: #9ca3af;
  --border: #374151; --accent: #60a5fa; --accent-soft: #1e3a5f;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: block; margin: 10px 0 4px; font-size: 14px; }

.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { font-size: 16px; }
.brand .tag { font-size: 12px; color: var(--muted); margin-left: 8px; }
.topnav { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.layout { display: flex; max-width: 1280px; margin: 0 auto; min-height: calc(100vh - 110px); }
.sidebar { width: 300px; flex: none; border-right: 1px solid var(--border); padding: 14px; background: var(--surface); }
.side-block { margin-bottom: 22px; }
.side-title { font-weight: 700; margin-bottom: 8px; }
.side-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search-box { margin-top: 10px; }
.search-results { margin-top: 6px; font-size: 13px; }
.search-results .hit { padding: 6px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-results .hit:hover { background: var(--accent-soft); }
.doc-list { list-style: none; padding: 0; margin: 6px 0 0; }
.doc-list li { padding: 8px 6px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.doc-list li.active { background: var(--accent-soft); font-weight: 700; }
/* D-03 文库树 */
.lib-tree { margin-top: 10px; }
.lib-group { margin-bottom: 10px; }
.lib-head { display: flex; gap: 4px; align-items: center; font-weight: 700; font-size: 14px; cursor: pointer; padding: 4px 2px; }
.lib-head .lib-toggle { color: var(--muted); width: 16px; }
.lib-head .lib-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-head .lib-name.selected { color: var(--accent); }
.lib-group .doc-list { margin-left: 16px; }
.outline { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.outline li { padding: 3px 0; cursor: pointer; color: var(--muted); }
.outline li:hover { color: var(--accent); }
.outline li.h2 { padding-left: 14px; }
.outline li.h3 { padding-left: 28px; }

.reader { flex: 1; min-width: 0; padding: 16px 22px; }
.reader-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.badge { font-size: 12.5px; padding: 3px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.editing { background: #fef3c7; color: #92400e; }
.doc-title { font-weight: 700; flex: 1; min-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.format-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; margin-bottom: 10px; }
.format-bar button { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 4px 9px; cursor: pointer; }
.ai-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
.ai-head { display: flex; justify-content: space-between; align-items: center; }
.ai-body { white-space: pre-wrap; margin-top: 8px; }
.ai-body mark { background: #fef08a; }
#ai-qa-box { display: flex; gap: 8px; margin-top: 10px; }
.preview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 34px; min-height: 480px; box-shadow: var(--shadow); }
.preview h1, .preview h2, .preview h3 { line-height: 1.35; margin: 1.1em 0 .5em; }
.preview h1 { font-size: 26px; }
.preview h2 { font-size: 21px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.preview table { border-collapse: collapse; width: 100%; margin: 12px 0; display: block; overflow-x: auto; }
.preview th, .preview td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.preview code { background: var(--bg); padding: 2px 5px; border-radius: 4px; font-size: 13.5px; }
.preview pre { background: #0d1117; color: #e6edf3; padding: 14px; border-radius: 8px; overflow-x: auto; }
.preview pre code { background: transparent; color: inherit; padding: 0; }
.preview blockquote { border-left: 3px solid var(--accent); margin: 12px 0; padding: 4px 14px; color: var(--muted); }
.preview img { max-width: 100%; }
.preview .math-display { overflow-x: auto; padding: 6px 0; text-align: center; }
.preview .mermaid { background: var(--bg); border-radius: 8px; padding: 10px; overflow-x: auto; text-align: center; }
.editor { width: 100%; min-height: 480px; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; font: 14px/1.7 ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface); resize: vertical; }
.empty-state h1 { font-size: 24px; }
.selling-points { list-style: none; padding: 0; }
.selling-points li { margin: 6px 0; }

.foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; background: var(--surface); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal-card { background: var(--surface); border-radius: 12px; padding: 22px; width: 420px; max-width: 100%; box-shadow: var(--shadow); }
.modal-card.wide { width: 640px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.msg { min-height: 20px; font-size: 13.5px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }
.price-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.price-table th, .price-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap; }
.pay-box { border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px; margin-top: 8px; }
.admin-wrap { max-width: 960px; margin: 0 auto; padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat b { font-size: 24px; display: block; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--surface); }
.data-table th, .data-table td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .preview { padding: 18px; }
  .brand .tag { display: none; }
}
/* D-10 打印：页眉标题＋目录只在打印时显示 */
.print-head { display: none; }
.print-toc { display: none; }
@media print {
  .topbar, .sidebar, .reader-toolbar, .format-bar, .ai-panel, .foot, .modal { display: none !important; }
  body { background: #fff; }
  .layout { display: block; }
  .preview { border: none; box-shadow: none; padding: 0; }
  .print-head { display: block; font-size: 13px; color: #666; border-bottom: 1px solid #999; padding-bottom: 6px; margin-bottom: 14px; }
  .print-toc { display: block; margin-bottom: 18px; font-size: 13.5px; }
  .print-toc ul { margin: 6px 0; padding-left: 18px; }
  .print-toc li { margin: 2px 0; }
}
