
:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-elevated: #243044;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-dim: rgba(88,166,255,0.15);
  --border: #30363d;
  --success: #3fb950;
  --warning: #d29922;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }

/* ── Header ── */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 2rem; background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.site-header h1 { margin: 0; font-size: 1.25rem; }
.site-header h1 a { color: var(--text); text-decoration: none; }
.site-header h1 a:hover { color: var(--accent); }

.search-box { display: flex; align-items: center; gap: 0.5rem; }
.search-box input {
  width: 280px; padding: 0.5rem 0.75rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 0.9rem;
}
.search-box input:focus { outline: none; border-color: var(--accent); }

.ai-search-btn {
  padding: 0.4rem 0.75rem; border: 1px solid var(--accent); border-radius: 6px;
  background: transparent; color: var(--accent); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.ai-search-btn:hover { background: var(--accent); color: var(--bg); }

/* ── Layout ── */
.layout { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
  width: 260px; min-width: 260px; padding: 1rem 0;
  background: var(--bg-card); border-right: 1px solid var(--border); overflow-y: auto;
}
.nav-list { list-style: none; margin: 0; padding: 0 1rem; }
.nav-list li { margin: 0.2rem 0; }
.nav-list a {
  display: block; padding: 0.35rem 0.6rem; color: var(--text-muted);
  text-decoration: none; border-radius: 6px; font-size: 0.85rem;
}
.nav-list a:hover { color: var(--accent); background: rgba(88,166,255,0.08); }
.nav-list li.active a { color: var(--accent); background: var(--accent-dim); }

.content { flex: 1; padding: 2rem 3rem; overflow-y: auto; max-width: 900px; }

/* ── Doc content ── */
.doc-content h1 { font-size: 1.75rem; margin-top: 0; }
.doc-content h2 { font-size: 1.35rem; margin-top: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.doc-content h3 { font-size: 1.15rem; margin-top: 1.5rem; }
.doc-content table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
.doc-content th, .doc-content td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.doc-content th { background: var(--bg-card); }
.doc-content code { background: var(--bg-card); padding: 0.2rem 0.4rem; border-radius: 4px; font-size: 0.9em; }
.doc-content pre { background: var(--bg-card); padding: 1rem; border-radius: 6px; overflow-x: auto; }
.doc-content pre code { background: none; padding: 0; }
.doc-content a { color: var(--accent); }
.doc-content a:hover { text-decoration: underline; }
.doc-content hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.doc-content ul, .doc-content ol { padding-left: 1.5rem; }

/* ── Index: Filter Bar ── */
.idx-filter-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0 1.5rem; }
.idx-filter-btn {
  padding: 0.4rem 0.9rem; border: 1px solid var(--border); border-radius: 20px;
  background: transparent; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; transition: all 0.2s;
}
.idx-filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.idx-filter-btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.idx-total-badge { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }

/* ── Index: Source Blocks ── */
.idx-source-block { margin-bottom: 2.5rem; }
.idx-source-block.hidden { display: none; }
.idx-source-header { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 1rem; }
.idx-source-icon { font-size: 1.5rem; margin-top: 0.1rem; }
.idx-source-header h2 { margin: 0; font-size: 1.3rem; border: none; padding: 0; }
.idx-source-count { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }
.idx-source-desc { margin: 0.2rem 0 0; font-size: 0.85rem; color: var(--text-muted); }

/* ── Index: Category Sections ── */
.idx-categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.75rem; }
.idx-category {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem 1rem; transition: border-color 0.2s;
}
.idx-category:hover { border-color: var(--accent); }
.idx-category.hidden { display: none; }
.idx-cat-toggle {
  margin: 0; font-size: 0.95rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  user-select: none; color: var(--text);
}
.idx-cat-toggle::before { content: "▸ "; color: var(--text-muted); font-size: 0.8em; transition: transform 0.2s; }
.idx-cat-toggle.open::before { content: "▾ "; }
.idx-cat-count { font-size: 0.75rem; color: var(--text-muted); background: var(--bg); padding: 0.1rem 0.5rem; border-radius: 10px; }
.idx-cat-list { list-style: none; padding: 0; margin: 0.5rem 0 0; display: none; }
.idx-cat-list.open { display: block; }
.idx-cat-list li { margin: 0.3rem 0; }
.idx-cat-list a {
  color: var(--accent); text-decoration: none; font-size: 0.85rem;
  display: block; padding: 0.2rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.idx-cat-list a:hover { text-decoration: underline; }

/* ── Index: Sidebar Nav ── */
.idx-sidebar-nav { padding: 0.5rem 1rem; border-top: 1px solid var(--border); margin-top: 0.5rem; }
.idx-nav-list { list-style: none; padding: 0; margin: 0; }
.idx-nav-group { margin-bottom: 0.5rem; }
.idx-nav-group-label {
  display: block; padding: 0.3rem 0.5rem; font-size: 0.9rem; font-weight: 600;
  color: var(--text); text-decoration: none; border-radius: 4px;
}
.idx-nav-group-label:hover { background: rgba(88,166,255,0.08); }
.idx-nav-sublist { list-style: none; padding: 0 0 0 1rem; margin: 0.2rem 0 0; }
.idx-nav-sub { margin: 0.15rem 0; }
.idx-nav-sub a {
  font-size: 0.8rem; color: var(--text-muted); text-decoration: none;
  padding: 0.15rem 0.4rem; display: block; border-radius: 4px;
}
.idx-nav-sub a:hover { color: var(--accent); background: rgba(88,166,255,0.08); }

/* ── Search Results Overlay ── */
.search-overlay {
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); z-index: 200; display: flex; justify-content: center; padding-top: 2rem;
}
.search-overlay.hidden { display: none; }
.search-results-panel {
  width: 680px; max-height: 70vh; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
}
.search-results-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.search-results-list { overflow-y: auto; padding: 0.5rem; flex: 1; }
.search-result-item {
  padding: 0.75rem 1rem; border-radius: 8px; cursor: pointer; transition: background 0.15s;
}
.search-result-item:hover { background: var(--accent-dim); }
.search-result-item .sr-title { font-weight: 600; color: var(--accent); margin-bottom: 0.25rem; }
.search-result-item .sr-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.search-result-item .sr-summary { font-size: 0.85rem; color: var(--text-muted); }
.search-result-item .sr-highlight { color: var(--warning); font-weight: 500; }
.search-no-results { padding: 2rem; text-align: center; color: var(--text-muted); }

/* ── AI Chat Panel ── */
.ai-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4); transition: transform 0.2s, background 0.2s;
}
.ai-fab:hover { transform: scale(1.08); background: var(--accent-hover); }

.ai-panel {
  position: fixed; bottom: 88px; right: 24px; z-index: 300;
  width: 400px; height: 520px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.ai-panel.hidden { display: none; }

.ai-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; background: var(--bg-elevated);
  border-bottom: 1px solid var(--border); font-weight: 600;
}
.ai-panel-actions { display: flex; gap: 0.25rem; }
.ai-icon-btn {
  background: none; border: none; color: var(--text-muted); font-size: 1.2rem;
  cursor: pointer; padding: 0.2rem 0.4rem; border-radius: 4px;
}
.ai-icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.08); }

.ai-settings {
  padding: 0.75rem 1rem; background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.ai-settings.hidden { display: none; }
.ai-settings label {
  display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem;
}
.ai-settings input {
  width: 100%; padding: 0.35rem 0.5rem; margin-top: 0.2rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 0.85rem;
}
.ai-settings button {
  margin-top: 0.5rem; padding: 0.4rem 1rem; background: var(--accent);
  color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}

.ai-messages {
  flex: 1; overflow-y: auto; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem;
}
.ai-msg {
  max-width: 88%; padding: 0.6rem 0.8rem; border-radius: 12px;
  font-size: 0.9rem; line-height: 1.5; word-break: break-word;
}
.ai-msg-bot { background: var(--bg-elevated); align-self: flex-start; }
.ai-msg-user { background: var(--accent-dim); color: var(--accent-hover); align-self: flex-end; }
.ai-msg-loading { font-style: italic; color: var(--text-muted); }
.ai-msg a { color: var(--accent); }
.ai-msg code { background: var(--bg); padding: 0.15rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.ai-msg .ai-sources { margin-top: 0.5rem; font-size: 0.8rem; color: var(--text-muted); }
.ai-msg .ai-sources a { color: var(--accent); text-decoration: none; }
.ai-msg .ai-confidence { display: inline-block; margin-top: 0.3rem; font-size: 0.75rem; padding: 0.15rem 0.4rem; border-radius: 4px; background: rgba(63,185,80,0.15); color: var(--success); }

.ai-input-row {
  display: flex; gap: 0.5rem; padding: 0.75rem;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
}
.ai-input-row input {
  flex: 1; padding: 0.5rem 0.75rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.9rem;
}
.ai-input-row input:focus { outline: none; border-color: var(--accent); }
.ai-input-row button {
  padding: 0.5rem 1rem; background: var(--accent); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9rem;
}
.ai-input-row button:hover { background: var(--accent-hover); }
.ai-input-row button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .ai-panel { width: calc(100vw - 32px); right: 16px; bottom: 80px; height: 60vh; }
  .search-results-panel { width: calc(100vw - 32px); }
}
