/* ============ 基础 ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 6px 20px rgba(0, 0, 0, .05);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ============ 顶部导航 ============ */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
}

.brand-logo { font-size: 24px; }

.header-nav { display: flex; gap: 22px; }

.header-nav a {
  color: var(--text-muted);
  font-size: 15px;
  transition: color .15s;
}

.header-nav a:hover { color: var(--primary); }

/* ============ Hero ============ */
.hero {
  background: linear-gradient(135deg, #2563eb 0%, #6d28d9 100%);
  color: #fff;
  padding: 56px 0;
  text-align: center;
}

.hero h1 { margin: 0 0 8px; font-size: 34px; letter-spacing: 2px; }

.hero p { margin: 0; opacity: .9; font-size: 16px; }

/* ============ 分类标签 ============ */
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 28px 0 20px;
}

.tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
}

.tab:hover { border-color: var(--primary); color: var(--primary); }

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ============ 文章卡片 ============ */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding-bottom: 48px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .18s, box-shadow .18s;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.card-cover {
  height: 150px;
  width: 100%;
  object-fit: cover;
  display: block;
  background: #eef1f7;
}

.card-cover-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: #94a3b8;
}

.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

.card-tag {
  align-self: flex-start;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.card-title { margin: 0; font-size: 18px; line-height: 1.4; }

.card-summary {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-meta { font-size: 12px; color: #9ca3af; }

/* ============ 空状态 ============ */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
  font-size: 15px;
}

/* ============ 页脚 ============ */
.site-footer {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 28px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.site-footer p { margin: 4px 0; }

.site-footer a { color: var(--text-muted); }

.site-footer a:hover { color: var(--primary); }

/* ============ 文章阅读页 ============ */
.article-page { padding-top: 28px; padding-bottom: 56px; max-width: 820px; }

.back-link { display: inline-block; margin-bottom: 20px; color: var(--text-muted); }

.back-link:hover { color: var(--primary); }

.article {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 44px;
}

.article-title { margin: 0 0 14px; font-size: 28px; line-height: 1.4; }

.article-meta {
  color: var(--text-muted);
  font-size: 13px;
  padding-bottom: 18px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.article-meta .tag {
  background: #eef2ff;
  color: var(--primary);
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
}

.article-content { font-size: 16px; color: #374151; }

.article-content h1, .article-content h2, .article-content h3 { margin: 1.4em 0 .6em; color: var(--text); }

.article-content h2 { font-size: 22px; }
.article-content h3 { font-size: 18px; }

.article-content p { margin: .8em 0; }

.article-content img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 1em auto;
}

/* 行内代码 */
.article-content :not(pre) > code {
  background: #f1f5f9;
  color: #d946ef;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .9em;
}

/* 代码块（<pre> 与 Quill 代码块统一深色样式，配合 highlight.js 主题着色） */
.article-content pre,
.article-content .ql-code-block-container {
  margin: 1em 0;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  background: #0d1117;
  color: #c9d1d9;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre;
}

.article-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
}

.article-content .ql-code-block { white-space: pre; }

.article-content blockquote {
  margin: 1em 0;
  padding: 8px 16px;
  border-left: 4px solid var(--primary);
  background: #f8fafc;
  color: var(--text-muted);
  border-radius: 0 8px 8px 0;
}

.article-content ul, .article-content ol { padding-left: 24px; }

/* ============ 按钮 / 输入 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  background: #fff;
  color: var(--text);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost { background: #fff; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }

.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-block { width: 100%; }

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s;
}

.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

/* ============ 登录 ============ */
.login-mask {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e3a8a 0%, #6d28d9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 34px 32px;
  width: 320px;
  box-shadow: var(--shadow-lg);
}

.login-box h2 { margin: 0 0 6px; text-align: center; }

.login-tip { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 18px; }

.login-box input {
  margin-bottom: 14px;
}

.login-err { color: var(--danger); font-size: 13px; text-align: center; min-height: 20px; margin: 10px 0 0; }

/* ============ 后台布局 ============ */
.admin-body { overflow: hidden; }

.admin-layout { display: flex; height: 100vh; }

.admin-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.admin-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.admin-search { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  overflow-y: auto;
  flex: 1;
}

.admin-list-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-list-item:hover { background: #f1f5f9; }

.admin-list-item.active { background: #eef2ff; color: var(--primary); font-weight: 600; }

.admin-list-item .cat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.admin-sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.admin-sidebar-foot .btn { flex: 1; }

/* ============ 后台主区 ============ */
.admin-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--bg);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.editor-head h2 { margin: 0; font-size: 20px; }

.editor-actions { display: flex; gap: 10px; }

.editor-form {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-row { display: flex; gap: 12px; }

.field-row .input { flex: 1; }

.field-row select.input { flex: 0 0 200px; }

.cover-row { align-items: center; flex-wrap: wrap; }

.cover-preview { display: flex; align-items: center; gap: 10px; }

.cover-preview img {
  height: 56px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
}

/* ============ 分类管理弹窗 ============ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  width: 500px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg);
}

.modal-box h3 { margin: 0 0 16px; font-size: 17px; }

.cat-add { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

.cat-add .input { flex: 1; min-width: 120px; }

.cat-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }

.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.cat-item:last-child { border-bottom: none; }

.color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

.cat-name { flex: 1; }

.cat-count { color: var(--text-muted); font-size: 12px; }

.cat-del:disabled { opacity: .4; cursor: not-allowed; }

.modal-foot { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ============ Quill 编辑器 ============ */
.editor-container {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

#quillToolbar {
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

#editor {
  min-height: 380px;
  font-size: 16px;
}

.ql-editor { min-height: 380px; }

.ql-editor img { max-width: 100%; border-radius: 6px; }

/* 编辑器内代码块：深色背景，配合 github-dark 语法高亮 */
.ql-editor .ql-code-block-container {
  background: #0d1117;
  color: #c9d1d9;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
}
.ql-editor .ql-code-block {
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
}

/* ============ 首页搜索树 ============ */
.content-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding-bottom: 48px;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 76px;
}

.main-col { flex: 1; min-width: 0; }

.sidebar-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.sidebar-title { font-weight: 700; font-size: 15px; margin-bottom: 12px; }

.sidebar-box .input { margin-bottom: 12px; }

.tree {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 14px;
}

.tree-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.tree-label:hover { background: #f1f5f9; }

.tree-label.active { background: #eef2ff; color: var(--primary); font-weight: 600; }

.tree-arrow { font-size: 12px; width: 14px; color: var(--text-muted); flex-shrink: 0; }

.tree-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 0 8px;
  border-radius: 999px;
}

.tree-children { list-style: none; margin: 0; padding: 0 0 0 16px; }

.tree-leaf {
  padding: 5px 8px 5px 22px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-leaf:hover { background: #f8fafc; color: var(--primary); }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .content-layout { flex-direction: column; }

  .sidebar { width: 100%; position: static; }

  .hero h1 { font-size: 26px; }

  .article { padding: 24px 20px; }

  .admin-layout { flex-direction: column; height: auto; }

  .admin-sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }

  .field-row { flex-direction: column; }

  .field-row select.input { flex: 1; }
}
