:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --border-strong: #d0d5db;
  --text: #1f2329;
  --text-2: #5b6470;
  --text-3: #8b94a0;
  --accent: #2f6df0;
  --accent-weak: #eaf1fe;
  --accent-2: #0f9d8c;
  --danger: #d9483b;
  --code-bg: #f4f5f7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --maxw: 1180px;
  font-size: 15px;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  height: 56px; padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; cursor: pointer; user-select: none; }
.logo { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.logo-accent { color: var(--accent); }
.brand-sub { color: var(--text-3); font-size: 12.5px; }
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 14px;
}
.search input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  height: 34px; padding: 0 14px; border-radius: 8px;
  font-size: 13.5px; cursor: pointer; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #245ed6; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdecea; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 280px 1fr;
  max-width: var(--maxw); margin: 0 auto; min-height: calc(100vh - 56px - 44px);
}
.sidebar {
  border-right: 1px solid var(--border); padding: 18px 14px;
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px); overflow-y: auto;
}
.cat-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.cat-nav button {
  text-align: left; padding: 7px 10px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-2); cursor: pointer; font-size: 13.5px;
}
.cat-nav button:hover { background: var(--surface-2); color: var(--text); }
.cat-nav button.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.side-list-title { font-size: 12px; color: var(--text-3); padding: 0 10px 6px; text-transform: uppercase; letter-spacing: .5px; }
.article-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.article-list li button {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; border: none;
  background: transparent; cursor: pointer; color: var(--text); font-size: 13.5px; line-height: 1.4;
}
.article-list li button:hover { background: var(--surface-2); }
.article-list li button.active { background: var(--accent-weak); color: var(--accent); }
.article-list .li-cat { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }

.content { padding: 28px 36px 60px; min-width: 0; }

/* ---------- Home ---------- */
.hero { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 28px 30px; box-shadow: var(--shadow); }
.hero h1 { margin: 0 0 8px; font-size: 26px; }
.hero p { margin: 0; color: var(--text-2); max-width: 720px; }
.hero .tags { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.path { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 22px; }
.path-card { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.path-card .n { font-size: 12px; color: var(--accent); font-weight: 700; }
.path-card h4 { margin: 6px 0 6px; font-size: 15px; }
.path-card p { margin: 0; color: var(--text-2); font-size: 13px; }

.cat-section { margin-top: 30px; }
.cat-section h2 { font-size: 17px; border-left: 3px solid var(--accent); padding-left: 10px; margin: 0 0 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin: 0; font-size: 15.5px; }
.card .sum { color: var(--text-2); font-size: 13px; flex: 1; }
.card .meta { font-size: 11.5px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Article ---------- */
.breadcrumb { font-size: 12.5px; color: var(--text-3); margin-bottom: 10px; }
.breadcrumb a { color: var(--accent); cursor: pointer; }
.article-head h1 { margin: 0 0 6px; font-size: 25px; }
.article-head .meta { color: var(--text-3); font-size: 13px; margin-bottom: 6px; }
.article-head .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- Markdown ---------- */
.markdown { color: var(--text); }
.markdown h1 { font-size: 24px; margin: 26px 0 12px; }
.markdown h2 { font-size: 19px; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 16px; margin: 20px 0 8px; }
.markdown p { margin: 10px 0; }
.markdown ul, .markdown ol { margin: 10px 0; padding-left: 24px; }
.markdown li { margin: 4px 0; }
.markdown a { color: var(--accent); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.markdown code { background: var(--code-bg); padding: 2px 6px; border-radius: 5px; font-size: 13px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
.markdown pre { background: #0f172a; color: #e6edf3; padding: 14px 16px; border-radius: 10px; overflow-x: auto; margin: 14px 0; }
.markdown pre code { background: transparent; color: inherit; padding: 0; font-size: 13px; line-height: 1.55; }
.markdown blockquote { border-left: 3px solid var(--accent-2); background: #effaf8; margin: 14px 0; padding: 8px 14px; color: var(--text-2); border-radius: 0 8px 8px 0; }
.markdown table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.markdown th { background: var(--surface-2); font-weight: 600; }
.markdown tr:nth-child(even) td { background: #fafbfc; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* ---------- Empty / loading ---------- */
.empty { color: var(--text-3); padding: 40px 0; text-align: center; }
.loading { color: var(--text-3); padding: 30px 0; }

/* ---------- Modal ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 880px; box-shadow: 0 20px 60px rgba(16,24,40,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.admin-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.input { height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 13.5px; }
.input:focus { outline: none; border-color: var(--accent); }
.admin-msg { font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.admin-msg.ok { color: var(--accent-2); }
.admin-msg.err { color: var(--danger); }
.admin-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.admin-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.admin-list li .t { flex: 1; cursor: pointer; }
.admin-list li .t:hover { color: var(--accent); }

.editor { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; }
.editor-row { display: flex; gap: 8px; margin-bottom: 8px; }
.editor-row .input { flex: 1; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: 13px; }
textarea.input { height: 320px; padding: 10px; resize: vertical; line-height: 1.55; }
.preview { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; overflow-y: auto; height: 320px; background: var(--surface); }
.preview-title { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.editor-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 12px 20px; text-align: center; color: var(--text-3); font-size: 12.5px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .content { padding: 20px; }
  .editor-grid { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
}
