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

:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --border:      #21262d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --accent2:     #a371f7;
  --accent3:     #D4846A;
  --warning-bg:  #1c1f26;
  --warning-border: #30363d;
  --warning-text: #cdd9e5;
  --link:        #58a6ff;
  --chat-user-bg: #2d333b;
  --chat-bot-bg:  #1f2937;
}

body.light-mode {
  --bg:          #f6f8fa;
  --surface:     #ffffff;
  --border:      #d0d7de;
  --text:        #1f2328;
  --text-muted:  #636c76;
  --accent:      #0969da;
  --accent2:     #8250df;
  --accent3:     #D4846A;
  --warning-bg:  #eff6ff;
  --warning-border: #bfdbfe;
  --warning-text: #1e3a8a;
  --link:        #0969da;
  --chat-user-bg: #e1e4e8;
  --chat-bot-bg:  #f0f2f4;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.6;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 2rem 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header p.subtitle { margin-top: 0.4rem; font-size: 0.9rem; color: var(--text-muted); }

.header-nav { margin-top: 0.75rem; }
.header-nav a { font-size: 0.85rem; color: var(--link); text-decoration: none; }
.header-nav a:hover { text-decoration: underline; }

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed; top: 16px; right: 16px;
  padding: 8px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 0.85rem; font-family: inherit;
  z-index: 100; transition: background 0.2s;
}
.theme-toggle:hover { background: var(--border); }

/* ── Layout ── */
main { flex: 1; }

.container { max-width: 90%; margin: 0 auto; padding: 24px 16px; }
@media (min-width: 768px) { .container { max-width: 80%; padding: 32px 20px; } }
@media (min-width: 1200px) { .container { max-width: 1000px; } }

/* ── Controls bar (search + buttons) ── */
.controls-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 180px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.ctrl-btn {
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.ctrl-btn:hover { background: var(--border); }

.no-results {
  display: none;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── Quick-nav index with category groups ── */
.index {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.index-cat {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.cat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
  padding-right: 4px;
  min-width: 120px;
}

.index-cat a {
  padding: 4px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-decoration: none;
  color: var(--link);
  font-size: 0.82rem;
  transition: border-color 0.2s;
}
.index-cat a:hover { border-color: var(--accent); }

/* ── Category section headings ── */
.category-section { margin-bottom: 8px; }

.category-heading {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.category-section:first-of-type .category-heading { margin-top: 0; }

/* ── Topic details ── */
details {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--surface);
  overflow: hidden;
  scroll-margin-top: 20px;
}

details summary {
  cursor: pointer; padding: 15px 18px;
  list-style: none;
  display: flex; align-items: flex-start; gap: 12px;
  user-select: none;
}
details summary::-webkit-details-marker { display: none; }
details:hover > summary { background: rgba(88,166,255,0.04); }

.topic-num {
  font-size: 0.72rem; font-weight: 700;
  color: var(--text-muted);
  background: var(--border);
  border-radius: 4px; padding: 2px 6px;
  flex-shrink: 0; margin-top: 3px;
  font-family: monospace; letter-spacing: 0.03em;
}

.topic-main { flex: 1; }
.topic-title { font-size: 0.97rem; font-weight: 700; color: var(--accent); display: block; }
.topic-brief { font-size: 0.83rem; color: var(--text-muted); margin-top: 3px; display: block; line-height: 1.45; }

.summary-arrow {
  color: var(--text-muted); font-size: 0.8rem;
  flex-shrink: 0; margin-top: 4px;
  transition: transform 0.2s;
}
details[open] .summary-arrow { transform: rotate(90deg); }

/* ── Topic content ── */
.topic-content {
  padding: 4px 20px 20px;
  border-top: 1px solid var(--border);
}

.topic-content h3 {
  font-size: 1rem; font-weight: 700; color: var(--accent);
  margin: 18px 0 9px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.topic-content p { margin-bottom: 11px; font-size: 0.92rem; }
.topic-content ul, .topic-content ol { margin: 0 0 11px 22px; font-size: 0.92rem; }
.topic-content li { margin-bottom: 5px; }
.topic-content strong { font-weight: 600; }
.topic-content em { color: var(--text-muted); font-style: italic; }
.topic-content hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.topic-content a { color: var(--link); text-decoration: underline dotted; }

.topic-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0; padding: 6px 14px;
  color: var(--text-muted); font-style: italic; font-size: 0.91rem;
}

/* ── Tables ── */
.topic-content table {
  width: 100%; border-collapse: collapse;
  margin: 14px 0; font-size: 0.87rem;
  overflow-x: auto; display: block;
}
.topic-content th { background: var(--border); color: var(--text); padding: 8px 12px; text-align: left; font-weight: 600; white-space: nowrap; }
.topic-content td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.topic-content tr:last-child td { border-bottom: none; }

/* ── Related topics ── */
.related-topics {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.related-topics strong { margin-right: 4px; white-space: nowrap; }

.related-topics a {
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--link);
  text-decoration: none;
  font-size: 0.8rem;
  transition: border-color 0.2s;
}
.related-topics a:hover { border-color: var(--accent); }

/* ── Back to top ── */
.back-to-top {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--accent); color: white;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer; opacity: 0.85; transition: opacity 0.2s;
  border: none; font-family: inherit;
}
.back-to-top:hover { opacity: 1; }

/* ── Footer ── */
footer {
  text-align: center; padding: 1.25rem;
  font-size: 0.8rem; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
