/* ============================================================
   DocsPortal — main.css
   Design: clean, minimal, enterprise documentation
   ============================================================ */

/* ---- Design tokens ---------------------------------------- */
:root {
  --color-bg:           #ffffff;
  --color-bg-subtle:    #f8f9fa;
  --color-bg-muted:     #f1f3f5;
  --color-border:       #e4e7ec;
  --color-border-subtle:#eef0f3;

  --color-text:         #111827;
  --color-text-muted:   #6b7280;
  --color-text-subtle:  #9ca3af;

  --color-accent:       #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-accent-light: #eff6ff;

  --color-success:      #16a34a;
  --color-warning:      #d97706;
  --color-danger:       #dc2626;
  --color-info:         #0891b2;

  --font-sans:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:      0.75rem;
  --text-sm:      0.875rem;
  --text-base:    1rem;
  --text-lg:      1.125rem;
  --text-xl:      1.25rem;
  --text-2xl:     1.5rem;
  --text-3xl:     1.875rem;

  --radius-sm:    4px;
  --radius:       6px;
  --radius-lg:    10px;

  --shadow-sm:    0 1px 2px rgba(0,0,0,0.05);
  --shadow:       0 1px 4px rgba(0,0,0,0.08);

  --header-h:     56px;
  --sidebar-w:    260px;
  --content-max:  780px;
  --toc-w:        220px;
}

[data-theme="dark"] {
  --color-bg:           #0f1117;
  --color-bg-subtle:    #161b22;
  --color-bg-muted:     #1c2128;
  --color-border:       #30363d;
  --color-border-subtle:#21262d;

  --color-text:         #e6edf3;
  --color-text-muted:   #8b949e;
  --color-text-subtle:  #6e7681;

  --color-accent:       #58a6ff;
  --color-accent-hover: #79b8ff;
  --color-accent-light: #1c2d3e;
}

/* ---- Reset ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Top header ------------------------------------------- */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
}

.header-inner {
  width: 100%;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--color-text);
  text-decoration: none;
  flex-shrink: 0;
  min-width: var(--sidebar-w);
}
.logo-mark { color: var(--color-accent); font-size: 1.2em; }
.logo-img  { height: 36px; width: auto; max-width: 180px; object-fit: contain; }

/* Search */
.header-search { flex: 1; max-width: 480px; }

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap .search-icon {
  position: absolute;
  left: 0.75rem;
  width: 16px;
  height: 16px;
  color: var(--color-text-subtle);
  pointer-events: none;
}

.search-input-wrap input[type="search"] {
  width: 100%;
  padding: 0.45rem 2.5rem 0.45rem 2.2rem;
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input-wrap input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.search-input-wrap kbd {
  position: absolute;
  right: 0.6rem;
  font-size: 11px;
  font-family: var(--font-sans);
  color: var(--color-text-subtle);
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  pointer-events: none;
}

/* Header controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.theme-toggle:hover { background: var(--color-bg-muted); }
.theme-toggle svg { width: 18px; height: 18px; }

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

/* ---- Buttons ---------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: var(--text-sm); font-family: var(--font-sans);
  font-weight: 500; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-decoration: none;
}
.btn-sm { padding: 0.35rem 0.85rem; }
.btn-md { padding: 0.5rem 1.1rem; }

.btn-primary {
  background: var(--color-accent); color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-hover); text-decoration: none; }

.btn-ghost {
  background: transparent; color: var(--color-text-muted);
  border-color: var(--color-border);
}
.btn-ghost:hover { background: var(--color-bg-muted); text-decoration: none; }

.btn-danger {
  background: transparent; color: #dc2626;
  border-color: #fecaca;
}
.btn-danger:hover { background: #fef2f2; text-decoration: none; }
[data-theme="dark"] .btn-danger { color: #f87171; border-color: #7f1d1d; }
[data-theme="dark"] .btn-danger:hover { background: #1e0505; }

/* ---- Page layout ------------------------------------------ */
.page-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
  width: 100%;
}

/* ---- Sidebar ---------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 0;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-bg-subtle);
}

.sidebar-nav { padding: 0 0.75rem; }

.sidebar-back {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: 1rem;
  padding: 0 0.5rem;
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.25rem 1.25rem;
  margin-bottom: 0.5rem;
}

/* Sidebar divider (editor toolbar separator) */
.sidebar-divider {
  height: 1px;
  background: var(--color-border);
  margin: 1rem 1.25rem 1rem;
}

/* Category group */
.nav-category { margin-bottom: 0.25rem; }

.nav-category-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.nav-category-toggle:hover { background: var(--color-bg-muted); }

.nav-category-toggle .chevron {
  width: 12px; height: 12px;
  color: var(--color-text-subtle);
  transition: transform 0.2s;
}
.nav-category-toggle[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

/* Article links */
.nav-articles {
  list-style: none;
  padding-left: 0.75rem;
  overflow: hidden;
}

.nav-articles[aria-expanded="false"],
.nav-category-toggle[aria-expanded="false"] + .nav-articles {
  display: none;
}

.nav-article {
  display: block;
  padding: 0.35rem 0.75rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  border-radius: var(--radius);
  transition: background 0.1s, color 0.1s;
  border-left: 2px solid transparent;
}
.nav-article:hover {
  background: var(--color-bg-muted);
  color: var(--color-text);
  text-decoration: none;
}
.nav-article.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: var(--color-accent-light);
  font-weight: 500;
}
[data-theme="dark"] .nav-article.active { background: #1c2d3e; }

/* Subcategory (section) inside a root category */
.nav-subcategory-item { list-style: none; }

.nav-subcategory-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.5rem 0.3rem 0.25rem;
  margin-top: 0.3rem;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}
.nav-subcategory-toggle:hover {
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
}

.nav-subcategory-toggle .chevron-sm {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  color: var(--color-text-subtle);
  transition: transform 0.2s;
}
.nav-subcategory-toggle[aria-expanded="false"] .chevron-sm {
  transform: rotate(-90deg);
}
.nav-subcategory-toggle[aria-expanded="false"] + .nav-articles-sub {
  display: none;
}

.nav-articles-sub {
  list-style: none;
  padding-left: 0.5rem;
  margin-bottom: 0.25rem;
}

.nav-empty-sub {
  display: block;
  padding: 0.25rem 0.75rem;
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  font-style: italic;
}

/* ---- Main content area ------------------------------------ */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem;
}

/* ---- Article ---------------------------------------------- */
.doc-article { width: 100%; }

/* Breadcrumbs */
.breadcrumbs ol {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: 1.75rem;
}
.breadcrumbs li + li::before { content: "/"; margin-right: 0.35rem; }
.breadcrumbs a { color: var(--color-text-muted); }
.breadcrumbs a:hover { color: var(--color-text); }
.breadcrumbs [aria-current="page"] { color: var(--color-text); }

/* Article header */
.article-header { margin-bottom: 2rem; }
.article-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.article-header-row h1 { flex: 1; }
.article-edit-btn { flex-shrink: 0; margin-top: 0.4rem; }

.article-editor-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-top: 0.3rem;
}
.article-editor-tracking {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  margin-top: 0.35rem;
  margin-bottom: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* Docs home header row */
.docs-home-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.docs-home-header-row > div { flex: 1; }

.article-header h1 {
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 0.75rem;
}
.article-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.article-tags {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.tag {
  font-size: var(--text-xs);
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* ---- Prose (rendered Markdown) ---------------------------- */
.prose { line-height: 1.8; }

.prose h1, .prose h2, .prose h3,
.prose h4, .prose h5, .prose h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.6em;
  color: var(--color-text);
  scroll-margin-top: calc(var(--header-h) + 1rem);
}
.prose h2 { font-size: var(--text-2xl); border-bottom: 1px solid var(--color-border); padding-bottom: 0.35em; }
.prose h3 { font-size: var(--text-xl); }
.prose h4 { font-size: var(--text-lg); }

.prose p { margin-bottom: 1.1em; }

.prose a { color: var(--color-accent); text-decoration: underline; text-underline-offset: 3px; }
.prose a:hover { color: var(--color-accent-hover); }

.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 1em; }
.prose li { margin-bottom: 0.3em; }

.prose blockquote {
  border-left: 3px solid var(--color-border);
  padding: 0.5rem 1rem;
  color: var(--color-text-muted);
  font-style: italic;
  margin: 1.25em 0;
}

/* Inline code */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.15em 0.4em;
}

/* Code blocks */
.prose pre {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25em 0;
  font-size: var(--text-sm);
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25em 0;
  font-size: var(--text-sm);
}
.prose th, .prose td {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--color-border);
  text-align: left;
}
.prose th {
  background: var(--color-bg-muted);
  font-weight: 600;
}
.prose tr:nth-child(even) td { background: var(--color-bg-subtle); }

/* Admonitions */
.admonition {
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 1.25em 0;
  border-left: 4px solid;
  font-size: var(--text-sm);
}
.admonition-title { font-weight: 600; margin-bottom: 0.4em; }

.admonition-note    { border-color: var(--color-info);    background: #f0f9ff; }
.admonition-tip     { border-color: var(--color-success); background: #f0fdf4; }
.admonition-warning { border-color: var(--color-warning); background: #fffbeb; }
.admonition-danger  { border-color: var(--color-danger);  background: #fef2f2; }

[data-theme="dark"] .admonition-note    { background: #0c1e2e; }
[data-theme="dark"] .admonition-tip     { background: #0a1e10; }
[data-theme="dark"] .admonition-warning { background: #1e1500; }
[data-theme="dark"] .admonition-danger  { background: #1e0505; }

/* Heading anchors */
.header-anchor {
  opacity: 0;
  margin-left: 0.4em;
  font-size: 0.8em;
  color: var(--color-text-subtle);
  text-decoration: none;
  transition: opacity 0.15s;
}
h2:hover .header-anchor,
h3:hover .header-anchor { opacity: 1; }

/* ---- Article navigation (prev/next) ----------------------- */
.article-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}
.article-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.article-nav a:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}
.article-nav-next a { text-align: right; }
.nav-label { font-size: var(--text-xs); color: var(--color-text-muted); }
.nav-title  { font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }

/* ---- Docs home -------------------------------------------- */
.docs-home-header {
  margin-bottom: 2.5rem;
}
.docs-home-header h1 { font-size: var(--text-3xl); font-weight: 600; margin-bottom: 0.5rem; }
.docs-home-header p  { color: var(--color-text-muted); }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

/* Section divider label (between subcategories and direct articles) */
.section-divider-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

/* Article list (category browse view) */
.article-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.article-list-item {
  display: block;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  text-decoration: none;
  background: var(--color-bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.article-list-item:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.article-list-item h3 {
  font-size: var(--text-base);
  font-weight: 600;
  margin: 0;
}
.article-list-excerpt {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0.25rem 0 0;
}

.category-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  background: var(--color-bg);
}
.category-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.category-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.category-card h2 { font-size: var(--text-lg); font-weight: 600; }
.category-card p  { font-size: var(--text-sm); color: var(--color-text-muted); flex: 1; }
.category-count { font-size: var(--text-xs); color: var(--color-text-subtle); margin-top: auto; }

.empty-state { color: var(--color-text-muted); font-size: var(--text-sm); }

/* ---- Auth pages ------------------------------------------- */
.auth-page {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  min-height: calc(100vh - var(--header-h));
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-header { margin-bottom: 1.5rem; text-align: center; }
.auth-title  { font-size: var(--text-2xl); font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label { font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }
.form-hint  { font-size: var(--text-xs); color: var(--color-text-subtle); }

.form-input {
  padding: 0.55rem 0.8rem;
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.form-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}
.form-input-code {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  letter-spacing: 0.3em;
  text-align: center;
}

.btn-full { width: 100%; justify-content: center; padding: 0.6rem 1rem; }

.auth-error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
}
[data-theme="dark"] .auth-error { background: #1e0505; border-color: #7f1d1d; }

.auth-success {
  font-size: var(--text-sm);
  color: var(--color-success);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
}
[data-theme="dark"] .auth-success { background: #0a1e10; border-color: #166534; }

.auth-totp-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.auth-footer {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: 1.25rem;
}

/* ---- Modal ------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%; max-width: 440px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.modal-title { font-size: var(--text-xl); font-weight: 600; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ---- Admin ------------------------------------------------- */
.admin-content {
  padding: 2rem;
}
.admin-page-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.admin-stat-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: var(--color-bg);
}
.stat-value { font-size: var(--text-3xl); font-weight: 700; }
.stat-label { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 0.2rem; }
.stat-link  { font-size: var(--text-xs); color: var(--color-accent); margin-top: 0.75rem; display: block; }

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.admin-table th {
  background: var(--color-bg-subtle);
  padding: 0.6rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
}
.admin-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--color-border-subtle);
  vertical-align: middle;
  white-space: nowrap;
}
.admin-table td.col-wrap { white-space: normal; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--color-bg-subtle); }
.table-loading { text-align: center; color: var(--color-text-muted); padding: 2rem !important; }

.badge {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.badge-green  { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.badge-red    { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.badge-yellow { background: #fefce8; color: #a16207; border-color: #fde68a; }
[data-theme="dark"] .badge-green  { background: #0a1e10; border-color: #166534; }
[data-theme="dark"] .badge-red    { background: #1e0505; border-color: #7f1d1d; }
[data-theme="dark"] .badge-yellow { background: #1c1500; border-color: #78350f; color: #fcd34d; }

/* ---- Search results page ---------------------------------- */
.search-page { max-width: 720px; }

.search-header { margin-bottom: 2rem; }
.search-title  { font-size: var(--text-2xl); font-weight: 600; margin-bottom: 1rem; }
.search-title em { font-style: normal; color: var(--color-accent); }

.search-input-lg { max-width: 100%; }
.search-input-lg input[type="search"] {
  font-size: var(--text-base);
  padding: 0.65rem 2.75rem 0.65rem 2.5rem;
}

.search-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: 1.25rem;
}
.search-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: 1rem;
}

.search-results { list-style: none; display: flex; flex-direction: column; gap: 1.25rem; }

.search-result {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-result:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow);
}

.result-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  display: block;
  margin-bottom: 0.4rem;
  text-decoration: none;
}
.result-title:hover { color: var(--color-accent); text-decoration: none; }

.result-excerpt {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: 0.6rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}
.result-category {
  background: var(--color-accent-light);
  color: var(--color-accent);
  border-radius: 99px;
  padding: 0.15rem 0.5rem;
  font-weight: 500;
}
.result-date { margin-left: auto; }

.search-pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}
.pagination-info { font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---- Error pages ------------------------------------------ */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 0;
  max-width: 480px;
}
.error-code {
  font-size: 5rem;
  font-weight: 700;
  color: var(--color-border);
  line-height: 1;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
}
.error-title   { font-size: var(--text-2xl); font-weight: 600; margin-bottom: 0.6rem; }
.error-message { font-size: var(--text-base); color: var(--color-text-muted); margin-bottom: 1.5rem; }
.error-actions { display: flex; gap: 0.5rem; }

/* Header auth username chip */
.header-username {
  font-size: 0.8125rem;
  color: var(--color-text-subtle);
  padding: 0 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  max-width: 140px;
  text-overflow: ellipsis;
  text-decoration: none;
}
a.header-username:hover { color: var(--color-text); }

/* ---- Article type badge ----------------------------------- */
.article-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid;
}
.type-markdown     { color: #2563eb; background: #eff6ff; border-color: #bfdbfe; }
.type-html         { color: #7c3aed; background: #f5f3ff; border-color: #ddd6fe; }
.type-api_reference{ color: #059669; background: #ecfdf5; border-color: #a7f3d0; }
[data-theme="dark"] .type-markdown      { color: #93c5fd; background: #1e3a5f; border-color: #1e40af; }
[data-theme="dark"] .type-html          { color: #c4b5fd; background: #2e1065; border-color: #6d28d9; }
[data-theme="dark"] .type-api_reference { color: #6ee7b7; background: #064e3b; border-color: #065f46; }

/* ---- API Reference styles --------------------------------- */
.api-reference {}

.api-endpoint-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.2rem 0.6rem;
  vertical-align: middle;
}
.endpoint-path {
  font-size: 0.875em;
  color: var(--color-text);
  background: none;
  border: none;
  padding: 0;
}

.method-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  flex-shrink: 0;
}
.method-get     { background: #16a34a; }
.method-post    { background: #2563eb; }
.method-put     { background: #d97706; }
.method-patch   { background: #0891b2; }
.method-delete  { background: #dc2626; }
.method-head    { background: #7c3aed; }
.method-options { background: #6b7280; }

/* API reference parameter / response tables */
.api-reference table { font-size: var(--text-sm); }
.api-reference th { background: var(--color-bg-muted); font-weight: 600; }
.api-reference code { font-size: 0.85em; }

/* ---- HTML article type ------------------------------------ */
.html-content { padding: 0; }
.html-content section { margin-bottom: 2rem; }

/* Full HTML document rendered in a sandboxed iframe */
.html-iframe-wrap { width: 100%; }
.html-iframe-wrap iframe {
  width: 100%;
  border: none;
  display: block;
  min-height: 70vh;
}

/* ---- Editor — template picker overlay --------------------- */
.template-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.template-picker-box {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 640px;
  width: 100%;
  margin: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.template-picker-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.template-picker-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}
.template-picker-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 520px) {
  .template-picker-cards { grid-template-columns: 1fr; }
}
.template-card {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1rem;
  cursor: pointer;
  background: var(--color-bg);
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.template-card:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}
.template-card-icon { font-size: 1.6rem; margin-bottom: 0.5rem; display: block; }
.template-card-name { font-size: var(--text-sm); font-weight: 600; display: block; margin-bottom: 0.25rem; }
.template-card-desc { font-size: var(--text-xs); color: var(--color-text-muted); display: block; }
.template-picker-skip {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  text-align: center;
}
.template-picker-skip a { color: var(--color-text-muted); }

/* ---- Editor — reference panel ----------------------------- */
.reference-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  background: var(--color-bg-subtle);
  font-size: var(--text-sm);
}
.ref-section h2 {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}
.ref-section h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 1rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
}
.ref-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
  margin-bottom: 0.25rem;
  align-items: baseline;
}
.ref-syntax {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ref-desc {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}
.ref-block {
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text);
  margin-bottom: 0.75rem;
  white-space: pre;
  overflow-x: auto;
}
.ref-note {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

/* ---- Article status badges -------------------------------- */
.status-badge {
  display: inline-flex; align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 99px; font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.03em; text-transform: capitalize; border: 1px solid;
}
.status-published { color: #166534; background: #dcfce7; border-color: #86efac; }
.status-draft     { color: #92400e; background: #fef3c7; border-color: #fcd34d; }
.status-archived  { color: #4b5563; background: #f3f4f6; border-color: #d1d5db; }
[data-theme="dark"] .status-published { color: #4ade80; background: #052e16; border-color: #166534; }
[data-theme="dark"] .status-draft     { color: #fbbf24; background: #292524; border-color: #78350f; }
[data-theme="dark"] .status-archived  { color: #9ca3af; background: #1f2937; border-color: #374151; }

/* ---- My Articles page ------------------------------------- */
.my-articles-page { max-width: 100%; }
.my-articles-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.my-articles-title { font-size: var(--text-2xl); font-weight: 600; }

.ma-tabs {
  display: flex; gap: 0.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0;
}
.ma-tab {
  padding: 0.5rem 1rem;
  font-size: var(--text-sm); font-weight: 500;
  color: var(--color-text-muted);
  background: none; border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 0.1s, border-color 0.1s;
}
.ma-tab:hover { color: var(--color-text); background: var(--color-bg-muted); }
.ma-tab.active { color: var(--color-accent); border-bottom-color: var(--color-accent); font-weight: 600; }

/* ---- Article editor meta (bottom of article, editors only) */
.article-editor-meta {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.75rem;
  margin-top: 2rem; padding: 0.75rem 1rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.editor-meta-item { display: flex; align-items: center; gap: 0.25rem; }
.editor-meta-private {
  color: var(--color-warning); font-weight: 600;
}
.editor-meta-actions { margin-left: auto; display: flex; gap: 0.35rem; }

/* ---- DB stats panel --------------------------------------- */
.db-stats-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  max-width: 860px;
}
.db-stats-header {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.25rem;
}
.db-total-size {
  font-size: var(--text-2xl); font-weight: 700; color: var(--color-text);
}
.db-total-label {
  font-size: var(--text-sm); color: var(--color-text-muted);
}
.db-section-label {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--color-text-muted);
  margin: 1rem 0 0.5rem;
}
.db-proj-note {
  font-size: var(--text-xs); font-weight: 400; text-transform: none;
  letter-spacing: 0; color: var(--color-text-subtle); margin-left: 0.35rem;
}

/* Table rows */
.db-table-row {
  display: grid;
  grid-template-columns: 160px 90px 1fr 70px 52px;
  align-items: center; gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: var(--text-sm);
}
.db-table-row:last-child { border-bottom: none; }
.db-table-name  { font-family: var(--font-mono); font-size: 0.8rem; color: var(--color-text); }
.db-table-rows  { color: var(--color-text-muted); font-size: var(--text-xs); text-align: right; }
.db-table-size  { text-align: right; font-weight: 500; white-space: nowrap; }
.db-table-pct   { color: var(--color-text-subtle); font-size: var(--text-xs); text-align: right; }

/* Progress bars */
.db-bar-wrap {
  height: 8px; background: var(--color-bg-muted);
  border-radius: 99px; overflow: hidden;
}
.db-bar {
  height: 100%; background: var(--color-accent);
  border-radius: 99px; min-width: 2px;
  transition: width 0.4s ease;
}
.db-bar-pred { background: #059669; }

/* Article average grid */
.db-avg-grid {
  display: flex; flex-wrap: wrap; gap: 0.75rem;
}
.db-avg-item {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem; min-width: 120px;
}
.db-avg-val   { font-size: var(--text-xl); font-weight: 700; color: var(--color-text); }
.db-avg-label { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 0.1rem; }

/* Prediction rows */
.db-pred-row {
  display: grid;
  grid-template-columns: 160px 1fr 120px 80px;
  align-items: center; gap: 0.6rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-border-subtle);
  font-size: var(--text-sm);
}
.db-pred-row:last-child { border-bottom: none; }
.db-pred-label { font-weight: 500; }
.db-pred-note  { font-size: var(--text-xs); color: var(--color-text-subtle); }
.db-pred-size  { text-align: right; font-weight: 500; white-space: nowrap; }
.db-pred-total {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 0.75rem; padding-top: 0.75rem;
  border-top: 2px solid var(--color-border);
  font-weight: 700; font-size: var(--text-base);
}

@media (max-width: 700px) {
  .db-table-row  { grid-template-columns: 1fr 60px 70px; }
  .db-table-rows, .db-table-pct, .db-bar-wrap { display: none; }
  .db-pred-row   { grid-template-columns: 1fr 80px; }
  .db-pred-note, .db-bar-wrap { display: none; }
}

/* ---- Sidebar empty state ---------------------------------- */
.nav-empty {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  padding: 0.5rem 1.25rem;
}

/* ---- 2FA setup styles ------------------------------------- */
.auth-qr-wrap {
  display: flex;
  justify-content: center;
  margin: 1rem 0 0.75rem;
}
.auth-qr-img {
  width: 180px;
  height: 180px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px;
  background: #fff;
}
.auth-secret-label {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  text-align: center;
  margin-bottom: 0.25rem;
}
.auth-secret-text {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  text-align: center;
  letter-spacing: 0.08em;
  word-break: break-all;
  margin-bottom: 0.75rem;
}
[data-theme="dark"] .auth-qr-img { background: #fff; }

/* ---- Scrollbar -------------------------------------------- */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

/* ---- Responsive ------------------------------------------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { padding: 1.5rem; }
  .logo { min-width: auto; }
  .search-input-wrap kbd { display: none; }
}

@media (max-width: 600px) {
  .article-nav { grid-template-columns: 1fr; }
  .header-search { display: none; }
}
