/* ─── Knowledge Base — Editorial Dark Theme ─────────────────────────────────── */

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg-content:     #faf8f4;
  --bg-card:        #f3f0ea;
  --bg-input:       #ffffff;
  --bg-sidebar:     #0d1520;
  --bg-sidebar-hi:  #162030;
  --bg-sidebar-act: #1e2d42;
  --accent:         #c8923a;
  --accent-hi:      #e0a84f;
  --accent-dim:     #8c6425;
  --text-primary:   #1c1c2e;
  --text-secondary: #5a6072;
  --text-muted:     #8a92a0;
  --text-sidebar:   #7e95b0;
  --text-sid-act:   #f0f4f8;
  --text-sid-label: #3d5470;
  --border:         #e4dfd6;
  --border-dark:    #1e2d42;
  --border-focus:   #c8923a;
  --code-bg:        #f0ede6;
  --danger:         #c0392b;
  --success:        #27ae60;
  --warning:        #e67e22;
  --info:           #2980b9;
  --sidebar-w:      260px;
  --topbar-h:       52px;
  --radius:         6px;
  --radius-lg:      10px;
  --shadow:         0 2px 12px rgba(0,0,0,.08);
  --shadow-md:      0 4px 24px rgba(0,0,0,.13);
  --font-display:   'Crimson Pro', Georgia, serif;
  --font-body:      'Outfit', sans-serif;
  --font-mono:      'JetBrains Mono', 'Fira Code', monospace;
  --tr:             .18s ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-content);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; transition: color var(--tr); }
a:hover { color: var(--accent-hi); }
img { max-width: 100%; height: auto; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Layout shell ──────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* ═══════════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 300;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border-dark);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-sid-act) !important;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}
.brand-icon { font-size: 1.5rem; color: var(--accent); line-height: 1; }

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 1.1rem;
  padding: 5px 7px;
  border-radius: 4px;
  line-height: 1;
  transition: background var(--tr), color var(--tr);
}
.sidebar-close:hover { background: var(--bg-sidebar-hi); color: var(--text-sid-act); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 2px; }

.sidebar-section { margin-bottom: 6px; }
.sidebar-label {
  display: block;
  padding: 10px 18px 4px;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-sid-label);
}

.sidebar-links { padding: 0 8px; }
.sidebar-links li a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-sidebar);
  transition: background var(--tr), color var(--tr);
}
.sidebar-links li a:hover,
.sidebar-links li a.active {
  background: var(--bg-sidebar-act);
  color: var(--text-sid-act);
}

/* Topic tree */
.topic-tree { padding: 0 8px; }
.tt-node > a {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-sidebar);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--tr), color var(--tr);
}
.tt-node > a:hover { background: var(--bg-sidebar-hi); color: var(--text-sid-act); }
.tt-node.active > a { background: var(--bg-sidebar-act); color: var(--accent); font-weight: 500; }
.tt-node .topic-tree {
  padding-left: 14px;
  border-left: 1px solid var(--border-dark);
  margin-left: 10px;
}
.tt-node .topic-tree .tt-node > a { font-size: .83rem; padding: 5px 10px; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border-dark);
  flex-shrink: 0;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--tr);
}
.user-badge:hover { background: var(--bg-sidebar-hi); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: .85rem; font-weight: 500; color: var(--text-sid-act); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-class { font-size: .68rem; color: var(--text-sid-label); text-transform: uppercase; letter-spacing: .06em; }
.sidebar-logout {
  display: block;
  text-align: center;
  padding: 6px;
  font-size: .78rem;
  color: var(--text-sid-label);
  border-radius: var(--radius);
  transition: background var(--tr), color var(--tr);
}
.sidebar-logout:hover { background: var(--bg-sidebar-hi); color: var(--danger); }

.auth-links { display: flex; gap: 8px; }
.btn-auth {
  flex: 1; text-align: center;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 500;
  background: var(--accent);
  color: #fff !important;
  transition: background var(--tr);
}
.btn-auth:hover { background: var(--accent-hi); }
.btn-auth.secondary { background: var(--bg-sidebar-hi); color: var(--text-sidebar) !important; }
.btn-auth.secondary:hover { background: var(--bg-sidebar-act); color: var(--text-sid-act) !important; }

/* ═══════════════════════════════════════════════════════
   TOPBAR — mobile only
═══════════════════════════════════════════════════════ */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  z-index: 200;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  border-bottom: 1px solid var(--border-dark);
}
.topbar-menu {
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}
.topbar-brand { flex: 1; font-family: var(--font-display); font-size: 1.1rem; color: var(--text-sid-act) !important; }
.topbar-search { font-size: 1.1rem; color: var(--text-sidebar); }

/* ═══════════════════════════════════════════════════════
   OVERLAY
═══════════════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 250;
  opacity: 0;
  transition: opacity .25s ease;
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ═══════════════════════════════════════════════════════
   MAIN CONTENT
═══════════════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 36px 48px 64px;
  max-width: calc(100vw - var(--sidebar-w));
  min-height: 100vh;
}

/* ── Flash Messages ─────────────────────────────────────────────────────────── */
.flash {
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: .88rem;
  font-weight: 500;
  border-left: 4px solid;
}
.flash-success { background: #ecfdf5; border-color: var(--success); color: #065f46; }
.flash-error   { background: #fef2f2; border-color: var(--danger);  color: #7f1d1d; }
.flash-info    { background: #eff6ff; border-color: var(--info);    color: #1e40af; }
.flash-warning { background: #fffbeb; border-color: var(--warning); color: #78350f; }

/* ── Page Header ────────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
  font-size: .79rem;
  color: var(--text-muted);
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { color: var(--border); }

.page-title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1.18;
  color: var(--text-primary);
  letter-spacing: -.01em;
}
.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  font-size: .81rem;
  color: var(--text-muted);
}
.badge {
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.badge-published { background: #d1fae5; color: #065f46; }
.badge-draft     { background: #fef3c7; color: #78350f; }
.badge-topic     { background: #e0e7ff; color: #3730a3; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--tr);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary   { background: var(--accent);   color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: #fff; }
.btn-secondary { background: var(--bg-card);  color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text-primary); }
.btn-danger    { background: var(--danger);   color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #e74c3c; color: #fff; }
.btn-sm        { padding: 5px 12px; font-size: .79rem; }
.btn-group     { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  margin-bottom: 5px;
  font-size: .86rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--text-primary);
  background: var(--bg-input);
  outline: none;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(200,146,58,.14);
}
textarea.form-control { resize: vertical; min-height: 88px; }
select.form-control { cursor: pointer; }
.form-hint  { margin-top: 4px; font-size: .77rem; color: var(--text-muted); }
.form-error { margin-top: 4px; font-size: .8rem; color: var(--danger); }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.form-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.form-check label { font-size: .88rem; color: var(--text-secondary); cursor: pointer; }
.form-section-title {
  font-family: var(--font-display);
  font-size: .98rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Auth Pages ─────────────────────────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card {
  width: 100%;
  max-width: 420px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.auth-card-header { background: var(--bg-sidebar); padding: 26px 30px 22px; text-align: center; }
.auth-card-header .brand { font-family: var(--font-display); font-size: 1.35rem; color: white; margin-bottom: 3px; }
.auth-card-header .subtitle { font-size: .83rem; color: var(--text-sidebar); }
.auth-card-body { padding: 26px 30px 28px; }
.auth-card-footer {
  padding: 13px 30px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: .84rem;
  color: var(--text-muted);
}
.auth-card-footer a { color: var(--accent); }

/* ── Topic Grid ─────────────────────────────────────────────────────────────── */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color var(--tr), box-shadow var(--tr);
  cursor: pointer;
  display: block;
  text-decoration: none;
  color: inherit;
}
.topic-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.topic-card h3 { font-family: var(--font-display); font-size: 1.12rem; margin-bottom: 5px; color: var(--text-primary); }
.topic-card p { font-size: .83rem; color: var(--text-secondary); line-height: 1.5; }
.tc-count { margin-top: 10px; font-size: .73rem; color: var(--text-muted); }
.topic-card-new {
  border-style: dashed;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  min-height: 88px;
  font-size: .86rem;
}

/* ── Article List ───────────────────────────────────────────────────────────── */
.article-list { max-width: 820px; }
.article-item {
  padding: 19px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.article-item:first-child { padding-top: 0; }
.article-item-title { font-family: var(--font-display); font-size: 1.22rem; margin-bottom: 4px; }
.article-item-title a { color: var(--text-primary); }
.article-item-title a:hover { color: var(--accent); }
.article-item-meta { font-size: .79rem; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 3px; }
.article-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Article View ───────────────────────────────────────────────────────────── */
.article-layout {
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 40px;
  align-items: start;
}
.article-body {
  font-size: 1rem;
  line-height: 1.82;
  color: var(--text-primary);
}
.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 1.7em 0 .5em;
  line-height: 1.3;
}
.article-body h1 { font-size: 2rem; }
.article-body h2 { font-size: 1.48rem; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.article-body h3 { font-size: 1.2rem; }
.article-body h4 { font-size: 1.05rem; }
.article-body p  { margin-bottom: 1em; }
.article-body ul,
.article-body ol { margin: .7em 0 .9em 1.4em; }
.article-body ul { list-style: disc; }
.article-body ol { list-style: decimal; }
.article-body li { margin-bottom: .28em; }
.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 1.2em 0;
  background: var(--bg-card);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
  font-style: italic;
}
.article-body code {
  font-family: var(--font-mono);
  font-size: .87em;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 3px;
  color: #c0392b;
}
.article-body pre {
  background: #1c1c2e;
  border-radius: var(--radius);
  padding: 14px 18px;
  overflow-x: auto;
  margin: 1.1em 0;
}
.article-body pre code {
  background: none;
  color: #e2e8f0;
  padding: 0;
  font-size: .86rem;
}
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.1em 0;
  font-size: .9em;
  display: block;
  overflow-x: auto;
}
.article-body th,
.article-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.article-body th  { background: var(--bg-card); font-weight: 600; }
.article-body img { border-radius: var(--radius); box-shadow: var(--shadow); }
.article-body a   { border-bottom: 1px solid rgba(200,146,58,.35); }
.article-body a:hover { border-bottom-color: var(--accent); }
.article-body hr  { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

/* Rail */
.article-rail { position: sticky; top: 24px; }
.rail-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 15px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.rail-card-title {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  margin-bottom: 9px;
}
.rail-card ul li { margin-bottom: 5px; font-size: .83rem; }
.rail-card ul li a { color: var(--text-secondary); }
.rail-card ul li a:hover { color: var(--accent); }

/* ── Comments ───────────────────────────────────────────────────────────────── */
.comments-section { margin-top: 44px; }
.comments-section h3 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 18px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
}
.comment { display: flex; gap: 11px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.comment:last-of-type { border-bottom: none; }
.comment-avatar {
  width: 33px; height: 33px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .77rem;
  font-weight: 700;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.comment-meta { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.comment-author { font-weight: 600; font-size: .86rem; }
.comment-time { font-size: .76rem; color: var(--text-muted); }
.comment-body { font-size: .88rem; line-height: 1.6; white-space: pre-wrap; }
.comment-actions { margin-top: 5px; }
.comment-actions a { font-size: .75rem; color: var(--text-muted); }
.comment-actions a:hover { color: var(--danger); }

/* ── Search ─────────────────────────────────────────────────────────────────── */
.search-bar { display: flex; margin-bottom: 26px; max-width: 600px; }
.search-bar input {
  flex: 1;
  padding: 11px 15px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: .95rem;
  outline: none;
  font-family: var(--font-body);
  background: white;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar button {
  padding: 11px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tr);
}
.search-bar button:hover { background: var(--accent-hi); }
.search-result { padding: 17px 0; border-bottom: 1px solid var(--border); }
.sr-title { font-family: var(--font-display); font-size: 1.18rem; margin-bottom: 3px; }
.sr-excerpt { font-size: .87rem; color: var(--text-secondary); line-height: 1.55; }
.sr-meta { font-size: .75rem; color: var(--text-muted); margin-top: 5px; }
.search-result mark { background: rgba(200,146,58,.22); border-radius: 2px; }

/* ── Editor ─────────────────────────────────────────────────────────────────── */
.editor-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: fit-content;
  margin-bottom: 10px;
}
.editor-toggle button {
  padding: 7px 16px;
  background: none;
  border: none;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--tr);
}
.editor-toggle button.active { background: var(--accent); color: white; }

/* Quill overrides */
.ql-toolbar.ql-snow { border-color: var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--bg-card); }
.ql-container.ql-snow { border-color: var(--border); border-radius: 0 0 var(--radius) var(--radius); min-height: 280px; }
.ql-editor { font-family: var(--font-body); font-size: .96rem; min-height: 280px; }

/* ── Attachments ────────────────────────────────────────────────────────────── */
.attachment-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.attachment-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .8rem;
  color: var(--text-secondary);
}
.attachment-item a { color: var(--accent); }
.att-size { color: var(--text-muted); font-size: .73rem; }
.att-del { color: var(--text-muted); cursor: pointer; font-size: .8rem; line-height: 1; }
.att-del:hover { color: var(--danger); }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--tr), background var(--tr);
}
.upload-zone:hover { border-color: var(--accent); background: rgba(200,146,58,.03); }
.upload-zone.drag-over { border-color: var(--accent); background: rgba(200,146,58,.07); }
.upload-zone p { font-size: .85rem; color: var(--text-muted); }

/* ── Pagination ─────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; margin-top: 24px; flex-wrap: wrap; }
.pagination a {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .84rem;
  color: var(--text-secondary);
  transition: all var(--tr);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.pagination a.active { background: var(--accent); border-color: var(--accent); color: white; }

/* ── Revision History ───────────────────────────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: white;
  transition: border-color var(--tr);
}
.history-item:hover { border-color: var(--accent); }
.history-num {
  font-family: var(--font-mono);
  font-size: .78rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Admin ──────────────────────────────────────────────────────────────────── */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  text-align: center;
}
.stat-value { font-family: var(--font-display); font-size: 2.1rem; font-weight: 300; color: var(--accent); line-height: 1; margin-bottom: 5px; }
.stat-label { font-size: .73rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.data-table th,
.data-table td { padding: 10px 13px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { background: var(--bg-card); font-weight: 600; color: var(--text-secondary); font-size: .77rem; text-transform: uppercase; letter-spacing: .05em; }
.data-table tr:hover td { background: var(--bg-card); }
.data-table tr:last-child td { border-bottom: none; }

.select-ctrl {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .8rem;
  background: white;
  font-family: var(--font-body);
}

/* ── TOTP ───────────────────────────────────────────────────────────────────── */
.totp-qr { text-align: center; margin: 14px 0; }
.totp-qr img { border: 4px solid white; border-radius: var(--radius); box-shadow: 0 2px 10px rgba(0,0,0,.1); }
.totp-secret {
  font-family: var(--font-mono);
  font-size: .82rem;
  background: var(--code-bg);
  padding: 8px 12px;
  border-radius: var(--radius);
  letter-spacing: .08em;
  text-align: center;
  margin: 8px 0;
  word-break: break-all;
}

/* ── Debug Panel Clearance ──────────────────────────────────────────────────── */
/* When debug panel is open it's ~420px tall; the bar alone is 32px.            */
body.dbg-open .main-content,
body.dbg-open .auth-page { padding-bottom: 460px !important; }
body:not(.dbg-open) .main-content { padding-bottom: 64px; } /* bar clearance */

/* Tablet ≤ 1100px */
@media (max-width: 1100px) {
  .article-layout { grid-template-columns: 1fr; }
  .article-rail   { position: static; }
}

/* Mobile ≤ 768px */
@media (max-width: 768px) {
  /* Show topbar, hide sidebar by default */
  .topbar      { display: flex; }
  .sidebar     { transform: translateX(-100%); }
  .sidebar.open{ transform: translateX(0); }
  .sidebar-close { display: block; }

  /* Main shifts up for topbar */
  .main-content {
    margin-left: 0;
    padding: calc(var(--topbar-h) + 18px) 18px 48px;
    max-width: 100vw;
  }

  .page-title { font-size: 1.85rem; }
  .topic-grid { grid-template-columns: 1fr 1fr; }
  .form-2col  { grid-template-columns: 1fr; }

  /* Article items stack */
  .article-item { flex-direction: column; gap: 8px; }
  .article-item-actions { width: 100%; }

  /* Admin stats 3-col */
  .admin-stats { grid-template-columns: repeat(3, 1fr); }

  /* Hide less important table cols */
  .hide-mobile { display: none; }

  /* Auth */
  .auth-page  { padding: 14px; align-items: flex-start; padding-top: 40px; }
}

/* Small phones ≤ 480px */
@media (max-width: 480px) {
  .main-content { padding-left: 14px; padding-right: 14px; }
  .page-title   { font-size: 1.6rem; }
  .topic-grid   { grid-template-columns: 1fr; }
  .admin-stats  { grid-template-columns: repeat(2, 1fr); }
  .btn-group    { flex-direction: column; }
  .btn-group .btn { width: 100%; justify-content: center; }
}
