:root {
  --ifm-color-primary: #2e8555;
  --ifm-color-primary-dark: #29784c;
  --ifm-color-primary-darker: #277148;
  --ifm-color-primary-darkest: #205d3b;
  --ifm-color-primary-light: #33925d;
  --ifm-color-primary-lighter: #359962;
  --ifm-color-primary-lightest: #3cad6e;

  --bg: #ffffff;
  --bg-secondary: #f6f8f7;
  --text: #1c1e21;
  --text-secondary: #4d5156;
  --border: #e3e6e8;
  --code-bg: #f0f2f0;
  --navbar-height: 60px;
  --content-max-width: 1400px;
  font-size: 16px;

  /* Article-content accent: only colors things inside .article-body
     (headings, inline code, blockquotes, links) — the "主题" picker in the
     editor changes only this, never the site chrome's --ifm-color-primary. */
  --article-accent: var(--ifm-color-primary);
  --article-accent-light: var(--ifm-color-primary-light);
}

[data-theme='dark'] {
  --ifm-color-primary: #25c2a0;
  --ifm-color-primary-dark: #21af92;
  --ifm-color-primary-darker: #1fa588;
  --ifm-color-primary-darkest: #1a8870;
  --ifm-color-primary-light: #29d5b0;
  --ifm-color-primary-lighter: #32d8b4;
  --ifm-color-primary-lightest: #4fddbf;

  --article-accent: var(--ifm-color-primary);
  --article-accent-light: var(--ifm-color-primary-light);

  --bg: #1b1b1d;
  --bg-secondary: #242526;
  --text: #e3e3e3;
  --text-secondary: #a6a6a6;
  --border: #3b3d3f;
  --code-bg: #2b2b2d;
}

/* ---------- Article content accent themes ---------- */
/* "forest" (the default green) lives in :root / [data-theme=dark] above.
   These only override --article-accent / --article-accent-light — the
   site chrome (nav, buttons, sidebars, TOC, category badge) always stays
   the fixed green --ifm-color-primary, regardless of which theme is picked. */
:root[data-accent='azure'] { --article-accent: #2563eb; --article-accent-light: #3b82f6; }
:root[data-accent='azure'][data-theme='dark'] { --article-accent: #60a5fa; --article-accent-light: #93c5fd; }

:root[data-accent='violet'] { --article-accent: #7c3aed; --article-accent-light: #8b5cf6; }
:root[data-accent='violet'][data-theme='dark'] { --article-accent: #a78bfa; --article-accent-light: #c4b5fd; }

:root[data-accent='amber'] { --article-accent: #d97706; --article-accent-light: #f59e0b; }
:root[data-accent='amber'][data-theme='dark'] { --article-accent: #fbbf24; --article-accent-light: #fcd34d; }

:root[data-accent='rose'] { --article-accent: #e11d48; --article-accent-light: #f43f5e; }
:root[data-accent='rose'][data-theme='dark'] { --article-accent: #fb7185; --article-accent-light: #fda4af; }

:root[data-accent='ink'] { --article-accent: #3f3f46; --article-accent-light: #52525b; }
:root[data-accent='ink'][data-theme='dark'] { --article-accent: #a1a1aa; --article-accent-light: #d4d4d8; }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Helvetica, Arial, sans-serif;
  line-height: 1.65;
}

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

/* ---------- Navbar ---------- */
.navbar {
  height: var(--navbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.navbar-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
  width: 34px;
  height: 34px;
}
.navbar-menu-toggle:hover { background: var(--bg-secondary); }

.navbar-logo {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.navbar-logo .dot { color: var(--ifm-color-primary); }

.navbar-logo-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 6px;
  border: 1px solid var(--ifm-color-primary);
  color: var(--ifm-color-primary);
  background: transparent;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: var(--ifm-color-primary); color: #fff; text-decoration: none; }

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

.btn-ghost {
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text); }

.btn-danger {
  border-color: #e53e3e;
  color: #e53e3e;
}
.btn-danger:hover { background: #e53e3e; color: #fff; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
}
.theme-toggle:hover { background: var(--bg-secondary); }

.social-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: transparent;
  flex-shrink: 0;
}
.social-icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--ifm-color-primary);
  text-decoration: none;
}

/* ---------- Layout (3 columns) ---------- */
.layout {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 240px;
  width: 100%;
  align-items: start;
  transition: grid-template-columns 0.2s ease;
}

.layout.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr) 240px;
}
.layout.toc-collapsed {
  grid-template-columns: 224px minmax(0, 1fr) 0px;
}
.layout.sidebar-collapsed.toc-collapsed {
  grid-template-columns: 0px minmax(0, 1fr) 0px;
}

.sidebar-left {
  border-right: 1px solid var(--border);
  padding: 24px 14px 60px 16px;
  position: sticky;
  top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  transition: padding 0.2s ease;
}

.layout.sidebar-collapsed .sidebar-left {
  padding: 24px 0 60px;
  border-right: none;
}

.layout.sidebar-collapsed .sidebar-left > * {
  opacity: 0;
  pointer-events: none;
}

.sidebar-category { margin-bottom: 18px; }

.sidebar-category-title {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 6px 10px;
}

.sidebar-article-list {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
}

.sidebar-link {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.92rem;
  color: var(--text);
  border-left: 2px solid transparent;
}
.sidebar-link:hover { background: var(--bg-secondary); text-decoration: none; }
.sidebar-link.active {
  color: var(--ifm-color-primary);
  background: var(--bg-secondary);
  border-left-color: var(--ifm-color-primary);
  font-weight: 600;
}

.content {
  padding: 32px 48px 80px;
  min-width: 0;
}

.article-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.article-category {
  background: var(--bg-secondary);
  color: var(--ifm-color-primary);
  border: 1px solid var(--ifm-color-primary-lightest);
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.78rem;
}

.article-title {
  font-size: 2rem;
  margin: 4px 0 10px;
  line-height: 1.25;
}

.article-body { font-size: 1rem; }
.article-body h1 { font-size: 1.6rem; margin-top: 2em; }
.article-body h2 {
  font-size: 1.4rem;
  margin-top: 2em;
  padding-left: 12px;
  border-left: 5px solid var(--article-accent);
}
.article-body h3 {
  font-size: 1.15rem;
  margin-top: 1.6em;
  padding-left: 10px;
  border-left: 4px solid var(--article-accent-light);
}
.article-body p { margin: 1em 0; color: var(--text); }
.article-body a { color: var(--article-accent); text-decoration: underline; }
.article-body ul, .article-body ol { padding-left: 1.4em; }
.article-body li { margin: 0.3em 0; }
.article-body strong { font-weight: 700; color: var(--text); }
.article-body em { font-style: italic; color: var(--text-secondary); }
.article-body blockquote {
  margin: 1em 0;
  padding: 4px 16px;
  border-left: 3px solid var(--article-accent);
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.article-body code {
  background: color-mix(in srgb, var(--article-accent) 12%, transparent);
  color: var(--article-accent);
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.88em;
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Courier New', monospace;
}
.article-body pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
}
.article-body pre code {
  background: none;
  color: inherit;
  font-weight: 400;
  padding: 0;
}
.article-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.92em;
}
.article-body th, .article-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.article-body img { max-width: 100%; border-radius: 6px; }
.article-body hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

.empty-state {
  color: var(--text-secondary);
  padding: 60px 0;
  text-align: center;
  font-size: 1rem;
}

.sidebar-right {
  padding: 28px 20px 60px 12px;
  position: sticky;
  top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  font-size: 0.86rem;
  transition: padding 0.2s ease;
}

.layout.toc-collapsed .sidebar-right {
  padding: 28px 0 60px;
}
.layout.toc-collapsed .sidebar-right > * {
  opacity: 0;
  pointer-events: none;
}

.toc-heading {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }

.toc-item a {
  display: block;
  padding: 4px 0 4px 14px;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.toc-item a:hover { color: var(--text); text-decoration: none; }
.toc-item.active a {
  color: var(--ifm-color-primary);
  border-left-color: var(--ifm-color-primary);
  font-weight: 600;
}
.toc-level-3 a { padding-left: 28px; font-size: 0.94em; }
.toc-empty { color: var(--text-secondary); }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 20px 28px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.site-footer a {
  color: var(--text-secondary);
  text-decoration: underline;
}
.site-footer a:hover { color: var(--ifm-color-primary); }

/* ---------- Mobile ---------- */
.sidebar-backdrop { display: none; }

@media (max-width: 996px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-right { display: none; }
  #toc-toggle { display: none; }
  .navbar-menu-toggle { display: inline-flex; }
  .sidebar-left {
    position: fixed;
    left: 0;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    width: 280px;
    background: var(--bg);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
  }
  .sidebar-left.open { transform: translateX(0); }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: var(--navbar-height) 0 0 0;
    background: rgba(0,0,0,0.35);
    z-index: 150;
  }
  .content { padding: 24px 20px 60px; }
}

/* ---------- Editor page ---------- */
/* Reuses .layout / .sidebar-left from the reader page so the editor's
   article tree looks and behaves exactly like the public sidebar
   (edge-aligned, sticky, collapsible, same mobile drawer). */
.editor-page-layout {
  grid-template-columns: 224px minmax(0, 1fr);
}
.editor-page-layout.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr);
}

.editor-cat-group { margin-bottom: 4px; }

.editor-cat-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  text-align: left;
}
.editor-cat-header:hover { background: var(--bg-secondary); }

.editor-cat-arrow {
  color: var(--text-secondary);
  font-size: 0.7rem;
  width: 10px;
  flex-shrink: 0;
}
.editor-cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-cat-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.editor-cat-list { list-style: none; margin: 2px 0 6px; padding: 0 0 0 18px; }
.editor-cat-empty { font-size: 0.8rem; color: var(--text-secondary); padding: 4px 8px; }

.editor-article-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
}
.editor-article-item:hover { background: var(--bg-secondary); }
.editor-article-item.active { background: var(--bg-secondary); }

.editor-article-title-btn {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: none;
  text-align: left;
  padding: 6px 4px;
  font-size: 0.86rem;
  cursor: pointer;
  color: var(--text);
}
.editor-article-item.active .editor-article-title-btn {
  color: var(--ifm-color-primary);
  font-weight: 600;
}

.editor-article-del-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0.55;
}
.editor-article-del-btn:hover { opacity: 1; background: var(--border); }

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 16px;
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row { display: flex; gap: 12px; }
.field { flex: 1; display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field input[type="text"],
.field input[type="password"],
.field textarea,
.field select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.field input[type="text"]:focus,
.field input[type="password"]:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--ifm-color-primary);
}

.field textarea {
  font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace;
  resize: vertical;
  min-height: 420px;
  line-height: 1.5;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  font-size: 0.86rem;
  color: var(--text-secondary);
}
.upload-row input[type="file"] { font-size: 0.86rem; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.preview-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  overflow-y: auto;
  max-height: 640px;
  background: var(--bg);
}
.preview-pane .article-title { font-size: 1.5rem; }

.status-msg {
  font-size: 0.86rem;
  padding: 4px 0;
  min-height: 1.4em;
}
.status-msg.success { color: var(--ifm-color-primary); }
.status-msg.error { color: #e53e3e; }

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 40px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.article-manage-list { display: flex; flex-direction: column; gap: 8px; }

.manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
}
.manage-item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.manage-item-title { font-weight: 600; font-size: 0.94rem; }
.manage-item-meta { font-size: 0.78rem; color: var(--text-secondary); }
.manage-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.manage-item-actions .btn { padding: 5px 12px; font-size: 0.82rem; }

.category-add-row {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}
.category-add-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.category-add-row input[type="text"]:focus {
  outline: none;
  border-color: var(--ifm-color-primary);
}

.theme-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.theme-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
  text-align: left;
}
.theme-card:hover { border-color: var(--ifm-color-primary-lightest); }
.theme-card.is-active {
  border-color: var(--ifm-color-primary);
  background: color-mix(in srgb, var(--ifm-color-primary) 8%, var(--bg-secondary));
}

.theme-card-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border);
}

.theme-card-name {
  flex: 1;
  font-weight: 600;
}

.theme-card-check {
  color: var(--ifm-color-primary);
  font-weight: 700;
  visibility: hidden;
}
.theme-card.is-active .theme-card-check { visibility: visible; }

.content-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.editor-mode-tab {
  background: none;
  border: none;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.editor-mode-tab:hover { color: var(--text); }
.editor-mode-tab.is-active {
  background: var(--bg);
  color: var(--ifm-color-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.richtext-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--bg-secondary);
}
.richtext-toolbar button {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 9px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.richtext-toolbar button:hover { background: var(--bg); border-color: var(--border); }
.richtext-toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 2px 2px;
}

.richtext-editor {
  border: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  padding: 12px 14px;
  min-height: 420px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
}
.richtext-editor:focus { outline: none; border-color: var(--ifm-color-primary); }
.richtext-editor h1, .richtext-editor h2, .richtext-editor h3 { margin: 0.9em 0 0.4em; line-height: 1.3; }
.richtext-editor h1 { font-size: 1.5rem; }
.richtext-editor h2 { font-size: 1.25rem; }
.richtext-editor h3 { font-size: 1.1rem; }
.richtext-editor p { margin: 0.6em 0; }
.richtext-editor ul, .richtext-editor ol { padding-left: 1.4em; margin: 0.6em 0; }
.richtext-editor blockquote {
  margin: 0.6em 0;
  padding: 2px 14px;
  border-left: 3px solid var(--article-accent);
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.richtext-editor a { text-decoration: underline; color: var(--article-accent); }
.richtext-editor code {
  background: color-mix(in srgb, var(--article-accent) 12%, transparent);
  color: var(--article-accent);
  padding: 1px 6px;
  border-radius: 5px;
  font-weight: 500;
  font-size: 0.9em;
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Courier New', monospace;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

@media (max-width: 900px) {
  .editor-grid { grid-template-columns: 1fr; }
  .field textarea { min-height: 280px; }
}

/* ---------- Auth screen ---------- */
.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 80px 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 28px 24px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin: 0;
}

.auth-card p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.auth-card .btn {
  width: 100%;
  justify-content: center;
}
