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

:root {
  --sidebar-w: 270px;
  --topbar-h: 56px;
  --brand: #0066ff;
  --brand-dark: #0050cc;
  --brand-light: #e8f0fe;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f8f9fc;
  --card-bg: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e40af;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .25s ease;
  z-index: 200;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.logo-icon { font-size: 22px; }

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}

.logo-sub {
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .8px;
}

#nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

#nav-menu::-webkit-scrollbar { width: 4px; }
#nav-menu::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.nav-category {
  margin-bottom: 4px;
}

.nav-category-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .8px;
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}

.nav-category-title:hover { color: #94a3b8; }

.nav-category-title .arrow {
  font-size: 10px;
  transition: transform .2s;
}

.nav-category-title.open .arrow { transform: rotate(90deg); }

.nav-items { display: none; }
.nav-items.open { display: block; }

.nav-item {
  display: block;
  padding: 7px 18px 7px 28px;
  font-size: 13.5px;
  color: var(--sidebar-text);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1.4;
}

.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
}

.nav-item-empty {
  color: #475569;
  font-style: italic;
  font-size: 12px;
  cursor: default;
}

.nav-item.active {
  background: rgba(30, 64, 175, .35);
  border-left-color: var(--brand);
  color: #fff;
  font-weight: 500;
}

.nav-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  color: #64748b;
  font-size: 13px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.back-link {
  font-size: 13px;
  color: #64748b;
  text-decoration: none;
  transition: color .15s;
}
.back-link:hover { color: #94a3b8; }

/* ── Main wrapper ── */
#main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ── */
#topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

#menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

#menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

#breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}

#search-input {
  width: 220px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  transition: border-color .2s, box-shadow .2s;
}

#search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,102,255,.1);
}

/* ── Content area ── */
#content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
}

/* ── Home screen ── */
.welcome-hero {
  max-width: 640px;
  margin: 0 auto 48px;
  text-align: center;
}

.welcome-hero h1 {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 16px;
  color: var(--text);
}

.welcome-hero .brand { color: var(--brand); }

.welcome-hero p {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 28px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary {
  padding: 11px 22px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, transform .1s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-primary:hover { background: var(--brand-dark); transform: translateY(-1px); }

.btn-secondary {
  padding: 11px 22px;
  background: transparent;
  color: var(--brand);
  border: 1.5px solid var(--brand);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-secondary:hover { background: var(--brand-light); }

/* ── Category grid ── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.category-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  cursor: pointer;
  transition: box-shadow .2s, transform .15s, border-color .2s;
}

.category-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  transform: translateY(-2px);
  border-color: var(--brand);
}

.category-card .cat-icon { font-size: 28px; margin-bottom: 10px; }

.category-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.category-card p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.category-card .cat-count {
  margin-top: 12px;
  font-size: 12px;
  color: var(--brand);
  font-weight: 500;
}

/* ── Article ── */
.article-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  max-width: 760px;
}

#article-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
}

#article-title {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

.article-body {
  max-width: 760px;
  line-height: 1.75;
  color: #374151;
}

.article-body h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--text);
}

.article-body h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text);
}

.article-body p { margin-bottom: 14px; }

.article-body ul, .article-body ol {
  padding-left: 22px;
  margin-bottom: 14px;
}

.article-body li { margin-bottom: 6px; }

.article-body code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: #be123c;
}

.article-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 14px;
  font-size: 13px;
}

.article-body pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.article-body blockquote {
  border-left: 3px solid var(--brand);
  padding: 10px 16px;
  margin: 16px 0;
  background: var(--brand-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #1e40af;
}

.article-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 14px 0;
  box-shadow: var(--shadow);
}

.article-body a { color: var(--brand); text-decoration: underline; }

.article-body a.doc-link {
  color: var(--brand);
  text-decoration: underline;
  text-decoration-style: dashed;
  cursor: pointer;
}
.article-body a.doc-link::before { content: '→ '; font-size: 12px; }

.article-nav {
  display: flex;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  max-width: 760px;
}

.article-nav button {
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, background .15s;
}

.article-nav button:hover {
  border-color: var(--brand);
  background: var(--brand-light);
  color: var(--brand);
}

/* ── Search ── */
#search-screen h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}

.search-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}

.search-item:hover {
  box-shadow: var(--shadow);
  border-color: var(--brand);
}

.search-item h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.search-item p  { font-size: 13px; color: var(--text-muted); }
.search-item .search-cat { font-size: 11px; color: var(--brand); font-weight: 500; margin-bottom: 4px; }

.no-results {
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 0;
}

/* ── Error ── */
.error-box {
  text-align: center;
  padding: 60px 20px;
  max-width: 400px;
  margin: 0 auto;
}

.error-icon { font-size: 48px; display: block; margin-bottom: 16px; }
.error-box h2 { font-size: 20px; margin-bottom: 10px; }
.error-box p  { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }

/* ── Spinner ── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid #334155;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile overlay ── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
  }

  #sidebar.open { transform: translateX(0); }
  #overlay.open { display: block; }
  #menu-toggle { display: flex; }

  #content-area { padding: 20px 18px; }

  .welcome-hero h1 { font-size: 26px; }
  .category-grid { grid-template-columns: 1fr 1fr; }
  #search-input { width: 140px; }
}

@media (max-width: 480px) {
  .category-grid { grid-template-columns: 1fr; }
}
