:root {
  --bg: #0f1117;
  --bg2: #161b22;
  --bg3: #1e2530;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --primary: #58a6ff;
  --primary-dark: #1f6feb;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --sidebar-w: 280px;
  --header-h: 56px;
  --radius: 8px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Layout ─────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--header-h);
}

/* ── Header ─────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.header-logo span { color: var(--primary); }

.header-search {
  flex: 1;
  max-width: 420px;
  margin: 0 auto;
}

.header-search input {
  width: 100%;
  padding: 0.45rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}

.header-search input:focus {
  outline: none;
  border-color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem 0;
}

.sidebar-section { margin-bottom: 0.25rem; }

.sidebar-category {
  padding: 0.4rem 1rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.sidebar-category:hover { color: var(--text); }

.sidebar-category .arrow {
  transition: transform 0.2s;
  font-size: 0.8rem;
}

.sidebar-category.collapsed .arrow { transform: rotate(-90deg); }

.sidebar-links { list-style: none; }
.sidebar-links.hidden { display: none; }

.sidebar-links li a {
  display: block;
  padding: 0.3rem 1rem 0.3rem 1.5rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: all 0.15s;
}

.sidebar-links li a:hover {
  color: var(--text);
  background: var(--bg3);
  text-decoration: none;
  border-left-color: var(--border);
}

.sidebar-links li a.active {
  color: var(--primary);
  background: rgba(88,166,255,0.08);
  border-left-color: var(--primary);
  font-weight: 500;
}

.sidebar-new {
  margin: 0.75rem 1rem;
}

/* ── Main Content ────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  padding: 2.5rem 3rem;
  max-width: 900px;
}

/* ── Breadcrumb ──────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ── Article ─────────────────────────────────────────── */
.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.article-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.article-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.article-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Article content typography */
.article-body h1 { font-size: 1.6rem; margin: 2rem 0 0.75rem; }
.article-body h2 { font-size: 1.3rem; margin: 1.75rem 0 0.6rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); }
.article-body h3 { font-size: 1.1rem; margin: 1.4rem 0 0.5rem; color: var(--text-muted); }
.article-body p { margin-bottom: 1rem; }
.article-body ul, .article-body ol { margin: 0.75rem 0 1rem 1.5rem; }
.article-body li { margin-bottom: 0.3rem; }
.article-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.article-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 0.5rem 1rem;
  background: var(--bg3);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1rem 0;
  color: var(--text-muted);
}
.article-body a { color: var(--primary); }
.article-body strong { color: var(--text); }

/* Code */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  color: #e3b341;
}

.article-body pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  position: relative;
}

.article-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: #e6edf3;
  font-size: 0.88rem;
  line-height: 1.6;
}

/* Copy button on code blocks */
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.copy-btn:hover { color: var(--text); border-color: var(--primary); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }

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

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-outline:hover { color: var(--text); border-color: var(--text-muted); }

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

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

/* ── Forms ───────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
}

.form-input, .form-select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-textarea {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.88rem;
  font-family: var(--font-mono);
  line-height: 1.6;
  resize: vertical;
  min-height: 400px;
  transition: border-color 0.15s;
}

.form-textarea:focus { outline: none; border-color: var(--primary); }

/* ── Editor Layout ───────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}

.editor-preview {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  overflow-y: auto;
  max-height: 600px;
}

.editor-toolbar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.editor-toolbar button {
  padding: 0.25rem 0.55rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  transition: all 0.15s;
}

.editor-toolbar button:hover { color: var(--text); border-color: var(--primary); }

/* ── Homepage ────────────────────────────────────────── */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.category-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.15s;
}

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

.category-card-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-card ul { list-style: none; }
.category-card ul li { margin-bottom: 0.25rem; }
.category-card ul li a { font-size: 0.88rem; color: var(--text-muted); }
.category-card ul li a:hover { color: var(--primary); }

/* ── Search Results ──────────────────────────────────── */
.search-result {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  background: var(--bg2);
}

.search-result-title { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.search-result-excerpt { font-size: 0.85rem; color: var(--text-muted); }
mark { background: rgba(88,166,255,0.25); color: var(--text); border-radius: 2px; padding: 0 2px; }

/* ── Login ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.login-logo span { color: var(--primary); }
.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem; }

/* ── Alert ───────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.88rem;
  border: 1px solid;
}

.alert-success { background: rgba(63,185,80,0.1); border-color: var(--success); color: var(--success); }
.alert-error { background: rgba(248,81,73,0.1); border-color: var(--danger); color: var(--danger); }
.alert-info { background: rgba(88,166,255,0.1); border-color: var(--primary); color: var(--primary); }

/* ── Badge ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ── TOC ─────────────────────────────────────────────── */
.toc {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.85rem;
}

.toc-title { font-weight: 700; margin-bottom: 0.5rem; color: var(--text-muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; }
.toc ul { list-style: none; }
.toc li { margin-bottom: 0.2rem; }
.toc a { color: var(--text-muted); }
.toc a:hover { color: var(--primary); }
.toc .toc-h3 { padding-left: 1rem; }

/* ── Responsive ──────────────────────────────────────── */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.25rem;
}

@media (max-width: 900px) {
  .menu-toggle { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s;
    z-index: 90;
  }

  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    padding: 1.5rem 1.25rem;
  }

  .editor-layout { grid-template-columns: 1fr; }
  .home-grid { grid-template-columns: 1fr; }
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
