/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f8f9fa;
  --surface:    #ffffff;
  --border:     #a2a9b1;
  --border-lt:  #eaecf0;
  --text:       #202122;
  --text-muted: #54595d;
  --link:       #3366cc;
  --link-hover: #0645ad;
  --accent:     #3b5998;
  --header-h:   52px;
  --sidebar-w:  240px;
  --serif:      'Georgia', 'Times New Roman', serif;
  --sans:       -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); }

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

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

#site-logo {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  width: calc(var(--sidebar-w) - 20px);
}

#logo-mark {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent);
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

#logo-text { display: flex; flex-direction: column; line-height: 1.2; }
#logo-text strong { font-size: 13px; color: var(--text); }
#logo-text span { font-size: 11px; color: var(--text-muted); }

#search-input {
  flex: 1; max-width: 480px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 14px; font-family: var(--sans);
  background: var(--bg);
  outline: none;
}
#search-input:focus { border-color: var(--accent); background: #fff; }

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

/* ── Sidebar ─────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-lt);
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 12px 0;
}

#nav-loading { padding: 16px; font-size: 13px; color: var(--text-muted); }

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

.nav-category-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer; user-select: none;
}
.nav-category-label:hover { background: var(--bg); }
.nav-category-label .chevron { font-size: 10px; transition: transform 0.2s; }
.nav-category.open .chevron { transform: rotate(90deg); }

.nav-articles { display: none; }
.nav-category.open .nav-articles { display: block; }

.nav-article {
  display: block;
  padding: 5px 14px 5px 24px;
  font-size: 13px; color: var(--text);
  cursor: pointer; border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-article:hover { background: var(--bg); color: var(--link); }
.nav-article.active {
  background: #eaf0fb;
  border-left-color: var(--accent);
  color: var(--link);
  font-weight: 500;
}

/* search results state */
.nav-article.hidden { display: none; }
.nav-category.search-hidden { display: none; }

/* ── Main content ────────────────────────────────────────────── */
#content {
  flex: 1;
  padding: 32px 48px 64px;
  max-width: 900px;
  min-width: 0;
}

/* ── Welcome / category grid ─────────────────────────────────── */
#welcome h1 {
  font-family: var(--serif);
  font-size: 28px; font-weight: normal;
  border-bottom: 1px solid var(--border-lt);
  padding-bottom: 8px; margin-bottom: 12px;
}
#welcome > p { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

#category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border-lt);
  border-radius: 4px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cat-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}
.cat-card-name {
  font-size: 13px; font-weight: 600;
  text-transform: capitalize; margin-bottom: 4px;
}
.cat-card-count { font-size: 12px; color: var(--text-muted); }

/* ── Article ─────────────────────────────────────────────────── */
#article-meta {
  background: #f8f9fa;
  border: 1px solid var(--border-lt);
  border-radius: 2px;
  padding: 10px 14px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 20px;
  display: flex; gap: 20px; flex-wrap: wrap; align-items: center;
}
.meta-item strong { color: var(--text); }
.confidence-high   { color: #2e7d32; font-weight: 600; }
.confidence-medium { color: #e65100; font-weight: 600; }
.confidence-low    { color: #b71c1c; font-weight: 600; }

#article-body {
  font-family: var(--serif);
  font-size: 15px; line-height: 1.75;
  color: var(--text);
}

#article-body h1 {
  font-size: 26px; font-weight: normal;
  border-bottom: 1px solid var(--border-lt);
  padding-bottom: 6px; margin-bottom: 16px;
  font-family: var(--serif);
}
#article-body h2 {
  font-size: 19px; font-weight: normal;
  border-bottom: 1px solid var(--border-lt);
  padding-bottom: 4px; margin: 28px 0 12px;
  font-family: var(--serif);
}
#article-body h3 {
  font-size: 15px; font-weight: 600;
  margin: 20px 0 8px;
}
#article-body p { margin-bottom: 12px; }
#article-body ul, #article-body ol {
  margin: 0 0 12px 24px;
}
#article-body li { margin-bottom: 4px; }
#article-body strong { font-weight: 700; }
#article-body em { font-style: italic; }
#article-body code {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border-lt);
  padding: 1px 5px; border-radius: 2px;
}
#article-body pre {
  background: #f4f4f4;
  border: 1px solid var(--border-lt);
  border-radius: 2px;
  padding: 14px 16px;
  overflow-x: auto;
  margin-bottom: 14px;
  font-size: 13px;
}
#article-body pre code { background: none; border: none; padding: 0; }
#article-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 0 0 14px;
}
#article-body table {
  border-collapse: collapse;
  width: 100%; margin-bottom: 16px;
  font-size: 14px;
}
#article-body th, #article-body td {
  border: 1px solid var(--border-lt);
  padding: 7px 12px; text-align: left;
}
#article-body th { background: var(--bg); font-weight: 600; font-family: var(--sans); font-size: 13px; }
#article-body tr:hover td { background: #fafafa; }

#article-body a { color: var(--link); }
#article-body a:hover { color: var(--link-hover); text-decoration: underline; }

/* ── Scrollbar ───────────────────────────────────────────────── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-lt); border-radius: 2px; }
