/* ==========================================================================
   知识手册 · 全局样式（紫色主题）
   布局：左侧目录树 / 中间正文 / 右侧本章大纲
   ========================================================================== */

:root {
  --primary: #7c3aed;
  --primary-dark: #5b21b6;
  --primary-light: #a78bfa;
  --primary-soft: #f3efff;
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #2b2540;
  --text-soft: #6b6480;
  --border: #e8e4f3;
  --shadow: 0 6px 20px rgba(91, 33, 182, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}
button, input, textarea { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d9d2ec; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-light); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 整体三栏骨架 ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 左侧栏 ---------- */
.sidebar {
  width: 292px;
  flex: 0 0 292px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px 12px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, #6d28d9 0%, #8b5cf6 55%, #c084fc 100%);
  box-shadow: 0 8px 22px rgba(109, 40, 217, 0.28);
}
.brand-icon { font-size: 30px; line-height: 1; }
.brand-title { font-size: 19px; font-weight: 700; letter-spacing: 0.5px; }
.brand-subtitle { font-size: 10px; opacity: 0.82; letter-spacing: 1.4px; text-transform: uppercase; }

.search-wrap { margin: 16px 0 10px; }
.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #faf9fe;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.search-input:focus {
  border-color: var(--primary-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}
.search-hint { margin-top: 8px; font-size: 12px; color: var(--text-soft); }

.doc-tree, .search-results { flex: 1 1 auto; overflow-y: auto; }

.category-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 9px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(91, 33, 182, 0.04);
}
.category-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(90deg, #faf8ff, #fff);
  border: 0;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-weight: 600;
}
.category-header:hover { background: var(--primary-soft); }
.cat-name { flex: 1; font-size: 13.5px; }
.cat-count {
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 1px 8px;
}
.cat-arrow { color: var(--text-soft); font-size: 12px; transition: transform 0.2s; }
.category-card.expanded .cat-arrow { transform: rotate(180deg); }
.doc-list { display: none; padding: 4px 8px 8px; }
.category-card.expanded .doc-list { display: block; }
.doc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 7px 10px 7px 20px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: 13px;
  position: relative;
}
.doc-item::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary-light);
  transform: translateY(-50%);
}
.doc-item:hover { background: var(--primary-soft); color: var(--primary-dark); }
.doc-item.active {
  background: linear-gradient(90deg, #ede7ff, #fff);
  color: var(--primary-dark);
  font-weight: 600;
}

.search-result {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 8px;
  cursor: pointer;
}
.search-result:hover { border-color: var(--primary-light); box-shadow: var(--shadow); }
.result-cat { font-size: 11px; color: var(--primary); margin-bottom: 2px; }
.result-title { font-weight: 600; font-size: 13.5px; color: var(--text); }
.result-snippet {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-snippet mark { background: #fde68a; color: #92400e; border-radius: 3px; padding: 0 2px; }

.sidebar-footer {
  font-size: 11px;
  color: var(--text-soft);
  text-align: center;
  padding-top: 10px;
  margin-top: 4px;
  border-top: 1px dashed var(--border);
}
.admin-entry {
  display: inline-block;
  margin-left: 8px;
  color: var(--primary);
  text-decoration: none;
  opacity: .75;
}
.admin-entry:hover { opacity: 1; text-decoration: underline; }

/* ---------- 中间正文区 ---------- */
.content { flex: 1 1 auto; overflow-y: auto; padding: 0 32px 60px; }
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  margin-bottom: 16px;
  background: rgba(246, 245, 251, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.toolbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.breadcrumb {
  color: var(--text-soft);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }
.tool-btn {
  border: 0;
  border-radius: 9px;
  padding: 7px 13px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s, filter 0.15s;
}
.tool-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn-print { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.btn-feedback { background: linear-gradient(135deg, #f97316, #ea580c); }
.menu-btn { display: none; background: linear-gradient(135deg, #7c3aed, #5b21b6); }

.doc-article {
  max-width: 880px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 40px 48px;
}

/* ---------- Markdown 正文排版 ---------- */
.doc-article h1, .doc-article h2, .doc-article h3 { scroll-margin-top: 84px; }
.doc-article h1 {
  font-size: 26px;
  margin: 0 0 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary-soft);
  color: var(--primary-dark);
}
.doc-article h2 {
  font-size: 21px;
  margin: 30px 0 12px;
  padding-left: 12px;
  border-left: 4px solid var(--primary);
  color: var(--primary-dark);
}
.doc-article h3 { font-size: 17px; margin: 22px 0 10px; color: #4c1d95; }
.doc-article p { margin: 10px 0; }
.doc-article ul, .doc-article ol { padding-left: 24px; margin: 10px 0; }
.doc-article li { margin: 4px 0; }
.doc-article blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  border-left: 4px solid var(--primary-light);
  background: var(--primary-soft);
  border-radius: 0 8px 8px 0;
  color: #5b4b7a;
}
.doc-article blockquote p { margin: 2px 0; }
.doc-article code {
  background: #f3f1fa;
  color: #7c3aed;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: "JetBrains Mono", Consolas, Monaco, monospace;
}
.doc-article pre {
  background: #1e1b2e;
  border-radius: 10px;
  padding: 16px 18px;
  overflow: auto;
  margin: 16px 0;
}
.doc-article pre code {
  background: transparent;
  color: #e8e6f0;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}
.doc-article table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13.5px; }
.doc-article th {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}
.doc-article th, .doc-article td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.doc-article tr:nth-child(even) td { background: #fbfaff; }
.doc-article img { max-width: 100%; border-radius: 8px; }
.doc-article hr { border: 0; border-top: 1px dashed var(--border); margin: 24px 0; }
.doc-article a { color: var(--primary); }
.doc-article mark.search-hit { background: #fde68a; color: #92400e; border-radius: 3px; padding: 0 2px; }

.welcome { text-align: center; padding: 40px 20px; color: var(--text-soft); }
.welcome h1 { border: 0; }
.welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 28px;
}
.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfaff;
  font-size: 12px;
}
.welcome-card strong { color: var(--primary-dark); font-size: 14px; }
.welcome-icon { font-size: 24px; }
.loading, .error { padding: 48px 20px; text-align: center; color: var(--text-soft); }
.error { color: #dc2626; }

/* ---------- 右侧大纲 ---------- */
.toc-panel {
  width: 236px;
  flex: 0 0 236px;
  padding: 22px 16px;
  border-left: 1px solid var(--border);
  background: var(--card);
  overflow-y: auto;
}
.toc-title {
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 14px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-soft);
}
.toc-list { display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: block;
  text-decoration: none;
  color: var(--text-soft);
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 7px;
  border-left: 2px solid transparent;
  line-height: 1.5;
}
.toc-item:hover { background: var(--primary-soft); color: var(--primary-dark); }
.toc-item.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
  border-left-color: var(--primary);
}
.toc-level-2 { padding-left: 22px; }
.toc-level-3 { padding-left: 34px; font-size: 12px; }
.toc-empty { font-size: 12px; color: var(--text-soft); }

/* ---------- 反馈弹窗与提示 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 55, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  width: min(460px, 92vw);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(30, 20, 55, 0.28);
  padding: 24px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h3 { margin: 0; color: var(--primary-dark); }
.modal-close { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--text-soft); }
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-field input, .form-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  outline: none;
}
.form-field textarea { min-height: 110px; resize: vertical; }
.form-field input:focus, .form-field textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn { border: 0; border-radius: 9px; padding: 9px 18px; cursor: pointer; font-weight: 600; }
.btn-secondary { background: #f1eef8; color: var(--text); }
.btn-primary { background: linear-gradient(135deg, #7c3aed, #5b21b6); color: #fff; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #1e1b2e;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 13px;
}

/* ---------- 站点密码解锁层 ---------- */
.site-lock {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #6d5bd0 0%, #8b7ae4 55%, #a99bf0 100%);
}
.site-lock-card {
  width: 100%; max-width: 400px; background: #fff;
  border-radius: 18px; padding: 38px 34px 28px; text-align: center;
  box-shadow: 0 18px 50px rgba(50, 35, 120, 0.28);
}
.lock-icon { font-size: 46px; margin-bottom: 10px; }
.site-lock-card h1 { margin: 0 0 8px; font-size: 21px; color: #4c1d95; }
.site-lock-card > p { margin: 0 0 22px; color: #6b6f85; font-size: 13px; }
#unlockForm input {
  width: 100%; padding: 12px 14px; border: 1px solid #e6e8f0;
  border-radius: 9px; font-size: 15px; outline: none; box-sizing: border-box;
}
#unlockForm input:focus {
  border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}
#unlockForm button {
  width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 9px;
  background: linear-gradient(135deg, #7c3aed, #5b21b6); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
}
#unlockForm button:disabled { opacity: 0.6; cursor: not-allowed; }
.lock-error {
  background: #fff0f0; color: #e5484d; border: 1px solid #ffd6d6;
  border-radius: 8px; padding: 8px 12px; margin-top: 10px; font-size: 13px; text-align: left;
}
.site-lock-card .lock-foot {
  margin: 18px 0 0; font-size: 12px; color: #9ca0b3;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .toc-panel { display: none; }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 12px 0 30px rgba(30, 20, 55, 0.15);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .content { padding: 0 14px 40px; }
  .doc-article { padding: 22px 18px 32px; }
  .menu-btn { display: inline-flex; align-items: center; }
  .breadcrumb { font-size: 12px; }
  .btn-print, .btn-feedback { padding: 7px 9px; font-size: 11.5px; }
}

/* ---------- 打印 / 另存 PDF：只保留正文 ---------- */
@media print {
  .sidebar, .toc-panel, .toolbar, .modal-overlay, .toast, .menu-btn { display: none !important; }
  .app-shell, .content { display: block; height: auto; overflow: visible; padding: 0; }
  .doc-article {
    box-shadow: none;
    border: 0;
    border-radius: 0;
    padding: 0;
    max-width: none;
  }
  .doc-article pre { white-space: pre-wrap; word-break: break-word; background: #f6f6f6; }
  .doc-article pre code { color: #333; }
  body { background: #fff; font-size: 12px; }
  a { text-decoration: none; color: inherit; }
  h1, h2, h3 { page-break-after: avoid; }
  table, pre, blockquote { page-break-inside: avoid; }
}
