:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e3e8ef;
  --border-strong: #d0d7e2;
  --text: #1f2733;
  --text-soft: #5b6675;
  --muted: #8b95a5;
  --accent: #2b6cff;
  --accent-soft: #eaf1ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --success: #079455;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.muted { color: var(--muted); font-size: 13px; }

/* ------------------------------ 通用控件 ------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: #b9c3d1; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(43, 108, 255, 0.3); }
.btn.primary:hover { background: #1f5ae0; border-color: #1f5ae0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: #eef2f7; color: var(--text); }
.btn.danger { color: var(--danger); border-color: #f5c2bd; background: var(--danger-soft); }
.btn.danger:hover { background: #fde7e5; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

input[type="text"], input[type="search"], input[type="password"], input[type="file"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 108, 255, 0.14);
}

/* ------------------------------ 登录页 ------------------------------ */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 15% 0%, #e8efff 0%, rgba(232, 239, 255, 0) 60%),
    radial-gradient(700px 380px at 90% 100%, #eafaf3 0%, rgba(234, 250, 243, 0) 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 28px 24px;
  box-shadow: var(--shadow);
}

.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 19px; margin: 0 0 2px; }
.auth-brand p { margin: 0; }

.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #2b6cff, #4d8bff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 19px;
  line-height: 1;
  font-family: var(--sans);
  box-shadow: 0 6px 14px rgba(43, 108, 255, 0.28);
}
.brand-mark.small { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }

.tabs { display: flex; gap: 4px; background: #f1f4f9; padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-soft);
  font-weight: 500;
}
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }

.form-error {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  border: 1px solid #f5c2bd;
}

.auth-hint { margin: 16px 0 0; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.7; }

/* ------------------------------ 主布局 ------------------------------ */

.layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-head { display: flex; gap: 10px; align-items: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-box input { padding: 8px 12px; background: #f7f9fc; }

.cat-list { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

.cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: var(--text-soft);
  text-align: left;
  font-size: 14px;
}
.cat-item:hover { background: #f4f7fb; color: var(--text); }
.cat-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-item .cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat-item.active .count { color: var(--accent); }
.cat-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; flex: none; }

.cat-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none;
}
.user-meta { min-width: 0; line-height: 1.3; }
.user-meta strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.role-tag {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: #eef2f7; color: var(--text-soft);
}
.role-tag.admin { background: #fff2e5; color: #b25b00; }
.role-tag.viewer { background: #f1f4f9; color: var(--muted); }

.foot-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ------------------------------ 内容区 ------------------------------ */

.content { overflow-y: auto; padding: 28px 34px 60px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h2 { margin: 0 0 4px; font-size: 22px; }
.page-head .crumbs { font-size: 13px; color: var(--muted); }

.doc-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.doc-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 132px;
}
.doc-card:hover { border-color: #c3d2ff; box-shadow: var(--shadow); transform: translateY(-1px); }
.doc-card h3 { margin: 0; font-size: 15px; line-height: 1.45; }
.doc-card .excerpt { color: var(--text-soft); font-size: 13px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card .meta { margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: #f1f4f9; color: var(--text-soft); font-size: 12px; }
.pill.cat { background: var(--accent-soft); color: var(--accent); }

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
}
.empty h3 { margin: 0 0 6px; color: var(--text-soft); font-size: 15px; }

/* ------------------------------ 文档阅读 ------------------------------ */

.doc-view { max-width: 860px; }
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 6px; }
.doc-title { margin: 0; font-size: 28px; line-height: 1.35; }
.doc-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.doc-actions { display: flex; gap: 8px; flex: none; }

.markdown-body { font-size: 15.5px; line-height: 1.78; color: #202836; word-wrap: break-word; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 1.8em 0 0.6em; line-height: 1.4; font-weight: 650;
}
.markdown-body h1 { font-size: 1.7em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 1.4em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 1.18em; }
.markdown-body h4 { font-size: 1.05em; }
.markdown-body p { margin: 0 0 1em; }
.markdown-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(43, 108, 255, 0.3); }
.markdown-body a:hover { border-bottom-color: var(--accent); }
.markdown-body ul, .markdown-body ol { margin: 0 0 1em; padding-left: 1.6em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 0.3em 0; }
.markdown-body blockquote {
  margin: 0 0 1em; padding: 10px 16px; color: var(--text-soft);
  border-left: 3px solid #c9d7ff; background: #f7f9ff; border-radius: 0 8px 8px 0;
}
.markdown-body blockquote > :last-child { margin-bottom: 0; }
.markdown-body code {
  font-family: var(--mono); font-size: 0.88em; background: #f1f4f9;
  padding: 0.15em 0.4em; border-radius: 5px; border: 1px solid #e6ebf2;
}
.markdown-body pre.code-block {
  margin: 0 0 1em; padding: 14px 16px; background: #f8fafc;
  border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto;
}
.markdown-body pre.code-block code { background: none; border: none; padding: 0; font-size: 13.5px; line-height: 1.65; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.markdown-body img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); display: block; margin: 0.4em 0 1em; }
.markdown-body .table-wrap { overflow-x: auto; margin: 0 0 1em; }
.markdown-body table { border-collapse: collapse; width: 100%; font-size: 14px; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-body th { background: #f7f9fc; font-weight: 600; }
.markdown-body del { color: var(--muted); }

/* ------------------------------ 编辑器 ------------------------------ */

.editor { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 88px); }
.editor-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.editor-top .title-input { flex: 1; min-width: 220px; font-size: 18px; font-weight: 600; padding: 10px 12px; }
.editor-top select { width: auto; min-width: 150px; }

.toolbar { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.toolbar button {
  border: 1px solid transparent; background: transparent; border-radius: 7px;
  padding: 5px 9px; cursor: pointer; color: var(--text-soft); font-size: 13px; min-width: 32px;
}
.toolbar button:hover { background: #f1f4f9; color: var(--text); }
.toolbar .divider { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

.editor-split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: 0; }
.editor-pane { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; min-height: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); background: #fbfcfe; }
.pane-body { flex: 1; overflow: auto; min-height: 0; }
#editor-textarea {
  width: 100%; height: 100%; border: none; border-radius: 0; padding: 16px 18px;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.75; resize: none; outline: none;
  background: transparent; tab-size: 2;
}
.preview-body { padding: 16px 22px 40px; }

.editor-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.editor-foot .hint { font-size: 12px; color: var(--muted); }
.editor-foot .actions { display: flex; gap: 8px; }

.attach-strip { display: flex; gap: 10px; overflow-x: auto; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.attach-item { position: relative; flex: none; width: 96px; }
.attach-item img { width: 96px; height: 68px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; background: #f7f9fc; }
.attach-item .name { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.attach-item .del {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
  border: none; background: rgba(20, 25, 33, 0.62); color: #fff; cursor: pointer; font-size: 12px; line-height: 1;
  display: grid; place-items: center;
}
.attach-item .del:hover { background: var(--danger); }
.attach-empty { font-size: 12px; color: var(--muted); align-self: center; }

.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: #f79009; display: inline-block; margin-right: 5px; }

/* ------------------------------ 弹窗 / 提示 ------------------------------ */

.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.42);
  display: grid; place-items: center; padding: 20px; z-index: 60;
}
.modal {
  width: 100%; max-width: 560px; background: var(--panel); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.25); overflow: hidden; max-height: 84vh; display: flex; flex-direction: column;
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal header h3 { margin: 0; font-size: 16px; }
.modal .body { padding: 18px 20px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fbfcfe; }
.modal .row { display: flex; gap: 8px; align-items: center; }
.modal .row + .row { margin-top: 10px; }
.modal .list { margin-top: 16px; border-top: 1px solid var(--border); }
.modal .list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.modal .list-item .grow { flex: 1; min-width: 0; }
.modal .list-item .sub { font-size: 12px; color: var(--muted); }

.toasts { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast {
  padding: 10px 14px; border-radius: 10px; background: #1f2733; color: #fff; font-size: 13px;
  box-shadow: var(--shadow); animation: slide-in 0.18s ease-out; max-width: 380px;
}
.toast.error { background: #b42318; }
.toast.success { background: #0b7a4b; }
@keyframes slide-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* ------------------------------ 响应式 ------------------------------ */

@media (max-width: 1024px) {
  .editor-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 1px solid var(--border); max-height: 46vh; overflow-y: auto; }
  .sidebar .search-box, .cat-list { flex-basis: 100%; }
  .sidebar-foot { border-top: none; padding-top: 0; flex-basis: 100%; }
  .content { padding: 18px 16px 48px; }
  .editor { height: auto; }
  .doc-title { font-size: 22px; }
  .doc-head { flex-direction: column; }
}
