:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1a1d21;
  --muted: #5c6570;
  --line: #dde2e8;
  --accent: #1f6feb;
  --accent-soft: #e8f1ff;
  --chip: #eef2f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.brand {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.brand h1 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  line-height: 1.3;
}
.brand h1 a { color: inherit; }
.brand h1 a:hover { text-decoration: none; }
.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.search-wrap {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
#search {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
}
#search:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.tree {
  overflow: auto;
  padding: 10px 8px 24px;
  flex: 1;
}
.tree details { margin: 2px 0; }
.tree summary {
  cursor: pointer;
  list-style: none;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover { background: var(--chip); }
.topic { margin: 2px 0 6px 10px; }
.topic-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 4px 8px;
}
.doc-link {
  display: block;
  padding: 5px 8px 5px 14px;
  border-radius: 6px;
  font-size: 0.86rem;
  color: var(--text);
}
.doc-link:hover, .doc-link.active {
  background: var(--accent-soft);
  text-decoration: none;
}
.doc-link .count {
  color: var(--muted);
  font-size: 0.75rem;
}
.main {
  min-width: 0;
  padding: 20px 28px 40px;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 0.88rem; }
.card ul { margin: 0; padding-left: 18px; font-size: 0.86rem; }
.doc-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.doc-header h2 { margin: 0 0 8px; font-size: 1.35rem; line-height: 1.3; }
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}
.chip {
  background: var(--chip);
  border-radius: 999px;
  padding: 2px 10px;
}
.related {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.related h3 { margin: 0 0 10px; font-size: 0.95rem; }
.related ul { margin: 0; padding-left: 18px; }
.related li { margin: 4px 0; font-size: 0.9rem; }
.related .reason {
  color: var(--muted);
  font-size: 0.82rem;
}
.content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.content h1, .content h2, .content h3 { margin-top: 1.2em; }
.content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
  margin: 12px 0;
}
.content th, .content td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: top;
}
.content th { background: var(--chip); }
.content pre {
  background: #0d1117;
  color: #e6edf3;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
  font-size: 0.85rem;
}
.search-results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}
.search-results h3 { margin: 0 0 10px; font-size: 0.95rem; }
.search-hit {
  display: block;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.search-hit:last-child { border-bottom: none; }
.search-hit small { color: var(--muted); }
.footer-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.8rem;
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; max-height: 45vh; }
}
.kb-chat { position: fixed; right: 20px; bottom: 20px; z-index: 40; font-family: inherit; }
.kb-chat-toggle {
  width: 52px; height: 52px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.35rem; font-weight: 700;
  cursor: pointer; box-shadow: 0 8px 20px rgba(31, 111, 235, 0.35);
}
.kb-chat-toggle:hover { filter: brightness(1.05); }
.kb-chat-panel {
  position: absolute; right: 0; bottom: 64px; width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 120px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 16px 40px rgba(16, 24, 40, 0.16);
  display: flex; flex-direction: column; overflow: hidden;
}
.kb-chat-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--accent-soft);
}
.kb-chat-head p { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }
.kb-chat-close {
  border: 0; background: transparent; font-size: 1.4rem; line-height: 1;
  color: var(--muted); cursor: pointer;
}
.kb-chat-log { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.kb-chat-msg { display: flex; }
.kb-chat-msg.user { justify-content: flex-end; }
.kb-chat-bubble {
  max-width: 92%; padding: 8px 11px; border-radius: 12px; font-size: 0.9rem;
  background: var(--chip);
}
}
.kb-chat-msg.user .kb-chat-bubble { background: var(--accent); color: #fff; }
.kb-chat-sources { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.kb-chat-sources a { font-size: 0.78rem; }
.kb-chat-form {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 10px; border-top: 1px solid var(--line);
}
.kb-chat-form textarea {
  width: 100%; resize: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit; font-size: 0.9rem;
}
.kb-chat-form button {
  border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  padding: 0 12px; cursor: pointer; font: inherit; font-size: 0.88rem;
}
.kb-chat-form button:disabled { opacity: 0.6; cursor: wait; }
