:root {
  font: 15px/1.5 system-ui, sans-serif;
  color: #24233b;
  background: #f9f9fd;
  --ink: #24233b;
  --muted: #605e77;
  --accent: #5740a7;
  --soft: #efeafa;
  --border: #e5e2ef;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid #6b50c6; outline-offset: 3px; }
[hidden] { display: none !important; }
.workspace { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #f3f1fa; border-right: 1px solid var(--border); padding: 27px 15px 19px; display: flex; flex-direction: column; min-width: 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 7px; color: var(--ink); text-decoration: none; font-weight: 750; font-size: 15px; letter-spacing: -.025em; }
.brand-icon { display: grid; place-items: center; width: 35px; height: 35px; flex: 0 0 35px; border-radius: 11px; background: #5942a6; color: #fff; font-size: 20px; }
.brand small { display: block; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: normal; }
.sidebar nav { margin-top: 40px; }
.nav-label { margin: 21px 10px 7px; font-size: 10px; font-weight: 750; letter-spacing: .11em; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 9px 10px; border: 0; background: transparent; border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
.nav span { color: var(--accent); min-width: 14px; }
.nav small { margin-left: auto; color: var(--muted); }
.nav:hover, .nav.active { background: #eae3f7; }
.nav.active { color: #463183; font-weight: 700; }
.category-search { width: 100%; margin-bottom: 6px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; color: var(--ink); background: #fff; font-size: 12px; }
#categories { max-height: 55vh; overflow: auto; padding: 2px 3px; }
.category-branch { list-style: none; margin: 0; padding: 0; }
.category-branch .category-branch { margin-left: 7px; padding-left: 3px; border-left: 1px solid #ded5ee; }
.category-row { display: flex; align-items: flex-start; margin: 1px 0; }
.category-toggle, .category-marker { display: grid; flex: 0 0 15px; place-items: center; min-height: 26px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--accent); font-size: 12px; }
.category-toggle:hover, .category-name:hover, .category-name.active { background: #eae3f7; }
.category-name { display: flex; flex: 1; align-items: baseline; justify-content: space-between; gap: 5px; min-width: 0; text-align: left; padding: 4px; border: 0; border-radius: 5px; background: transparent; font-size: 12px; overflow-wrap: anywhere; }
.category-name.active { color: #463183; font-weight: 700; }
.category-name small { color: var(--muted); }
.category-crumbs { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.sidebar-footer { margin-top: auto; padding-top: 36px; }
.sidebar-footer p { margin: 12px 10px 0; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.topbar { min-height: 72px; padding: 13px clamp(20px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 20px; background: #fff; border-bottom: 1px solid var(--border); }
.search { display: flex; align-items: center; gap: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; flex: 1; max-width: 420px; background: #faf9fd; }
.search span { font-size: 22px; line-height: 1; }
.search input { width: 100%; border: 0; background: transparent; min-width: 0; padding: 4px; color: var(--ink); }
.search kbd { border: 1px solid var(--border); border-radius: 4px; min-width: 19px; text-align: center; font-size: 11px; }
.private { white-space: nowrap; color: var(--muted); font-size: 12px; }
.private span[aria-hidden] { display: inline-block; vertical-align: middle; width: 7px; height: 7px; border-radius: 50%; background: #39826e; margin-right: 5px; }
.content { max-width: 1500px; margin: auto; padding: 32px clamp(20px, 3vw, 42px); }
.masthead { display: flex; align-items: end; justify-content: space-between; gap: 15px; margin-bottom: 24px; }
h1 { margin: 0; font-size: clamp(29px, 4vw, 44px); letter-spacing: -.05em; line-height: 1.15; }
#summary { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.switch { display: flex; gap: 3px; border: 1px solid var(--border); padding: 3px; border-radius: 10px; background: #f1eef7; flex-shrink: 0; }
.switch button { border: 0; padding: 6px 10px; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 650; font-size: 13px; }
.switch button[aria-pressed=true] { color: var(--accent); background: white; box-shadow: 0 1px 3px #31276020; }
.panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: start; gap: 18px; }
.results-panel, .reader, .map-panel { background: #fff; border: 1px solid var(--border); border-radius: 13px; min-width: 0; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 53px; padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.results-head select { padding: 4px; max-width: 48%; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }
.results { padding: 6px; }
.source-row { display: grid; grid-template-columns: 35px minmax(0, 1fr); gap: 10px; align-items: start; text-align: left; width: 100%; padding: 12px 10px; background: #fff; border: 1px solid transparent; border-bottom-color: var(--border); border-radius: 7px; }
.source-row:last-child { border-bottom-color: transparent; }
.source-row:hover, .source-row[aria-pressed=true] { background: #f4effb; border-color: #e2d9f4; }
.source-row strong, .note h3 { display: block; line-height: 1.35; overflow-wrap: anywhere; }
.source-row small { display: block; margin-top: 5px; color: var(--muted); }
.file-icon { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 8px; color: #5941a1; background: #eee8f9; }
.reader { padding: clamp(17px, 2.5vw, 28px); }
.reader header { border-bottom: 1px solid var(--border); padding-bottom: 19px; }
.reader h2 { font-size: clamp(21px, 2.4vw, 30px); line-height: 1.16; letter-spacing: -.035em; margin: 11px 0 7px; overflow-wrap: anywhere; }
.reader .meta, .reader .abstract, .empty, dialog p { color: var(--muted); overflow-wrap: anywhere; }
.reader .meta, .reader .abstract { margin: 0 0 12px; font-size: 13px; }
.reader .abstract { margin-top: 12px; margin-bottom: 0; white-space: pre-wrap; }
.reader-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.pill { display: inline-block; padding: 3px 8px; border-radius: 6px; background: var(--soft); color: #503789; font-size: 11px; font-weight: 650; }
.outline, .primary { border-radius: 7px; padding: 5px 9px; border: 1px solid var(--border); background: white; color: var(--accent); font-weight: 650; font-size: 12px; text-decoration: none; }
.outline:hover { background: var(--soft); }
.note-list h2 { font-size: 16px; letter-spacing: -.01em; margin: 18px 0 10px; }
.note { padding: 12px; margin-top: 8px; background: #faf9fd; border: 1px solid var(--border); border-radius: 8px; }
.note h3 { margin: 0; font-size: 13px; }
.note .page { display: inline-block; color: #513693; font-size: 11px; margin-top: 4px; font-weight: 680; }
.note p { margin: 7px 0 0; font-size: 13px; color: #49465c; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { padding: 13px; margin: 0; }
.more { margin: 8px 14px 14px; }
.knowledge-panel { grid-column: 1 / -1; }
.knowledge-toolbar { flex-wrap: wrap; justify-content: flex-start; gap: 12px; }
.knowledge-toolbar label { display: flex; align-items: center; gap: 7px; }
.knowledge-toolbar label:first-child { flex: 1 1 260px; min-width: 0; }
.knowledge-toolbar select { width: 100%; max-width: 380px; }
.knowledge-toolbar input { accent-color: var(--accent); }
#knowledge-results-count { margin-left: auto; }
.knowledge-card, .knowledge-section { border: 1px solid var(--border); border-radius: 8px; margin: 6px; }
.knowledge-card summary, .knowledge-section summary { cursor: pointer; padding: 10px 12px; overflow-wrap: anywhere; }
.knowledge-card summary:hover, .knowledge-section summary:hover { background: #f4effb; border-radius: 8px; }
.knowledge-card summary strong, .knowledge-section summary strong { margin-right: 8px; }
.knowledge-meta { color: var(--muted); font-size: 12px; }
.knowledge-card .pill { margin-right: 8px; }
.knowledge-body { padding: 0 12px 12px 25px; }
.knowledge-text { margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.knowledge-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.knowledge-section > summary { background: var(--soft); color: var(--accent); border-radius: 8px; }
.knowledge-section-items { margin: 8px; padding-left: 6px; border-left: 2px solid #e8def6; }
.knowledge-section-items:empty { display: none; }
.map-panel { padding: 13px; overflow: auto; }
.map-panel:has(.map-viewport) { grid-column: 1 / -1; }
.map-panel:has(.map-viewport) + .reader { grid-column: 1 / -1; }
.map-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; margin: 2px 3px 10px; font-size: 12px; }
.map-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 3px 10px; }
.map-level { min-width: 46px; text-align: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.map-viewport { position: relative; height: clamp(350px, 61vh, 640px); overflow: clip; border: 1px solid var(--border); border-radius: 9px; background: #faf9fd radial-gradient(#ded7ec 1px, transparent 1px) 0 0 / 16px 16px; cursor: grab; touch-action: none; }
.map-viewport.dragging { cursor: grabbing; user-select: none; }
.map-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.map-connector { position: absolute; background: #c4b5e3; pointer-events: none; }
.map-graph-node { position: absolute; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 3px; padding: 7px 29px 7px 10px; border: 1px solid #dcd1f1; border-radius: 8px; background: #fff; text-align: left; box-shadow: 0 2px 5px #34216413; }
.map-graph-node:hover { border-color: #9f89d2; background: #f7f3ff; }
.map-graph-node.graph-category, .map-graph-node.graph-section { background: #f1eafb; color: #4c338b; }
.map-graph-node.graph-group { background: #f7f4fd; color: #4c338b; }
.map-graph-node.graph-source { border-color: #bdabe4; }
.map-graph-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; font-size: 13px; line-height: 1.2; }
.map-graph-meta { color: var(--muted); font-size: 11px; }
.map-graph-toggle { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--accent); font-weight: 700; }
.map-canvas { display: grid; gap: 8px; position: relative; padding: 18px 10px; border-radius: 8px; background: #faf9fd radial-gradient(#ded7ec 1px, transparent 1px) 0 0 / 16px 16px; }
.map-node { position: relative; text-align: left; width: 100%; border: 1px solid #dcd1f1; background: #fff; border-radius: 8px; padding: 9px; font-size: 12px; overflow-wrap: anywhere; }
.map-node.root { margin: 0; background: #5b42a8; color: white; font-size: 15px; font-weight: 700; }
.map-category, .map-source, .map-knowledge-note { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.map-category { background: #f8f4ff; }
.map-node-meta { flex-shrink: 0; color: var(--accent); font-size: 11px; }
.map-label { margin: 3px 0 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.map-knowledge-section > summary { cursor: pointer; background: var(--soft); color: var(--accent); }
.map-section-title strong { margin-right: 8px; }
.map-knowledge-section > .branches { margin-top: 6px; }
.branches { display: grid; gap: 8px; margin-left: 18px; padding-left: 13px; border-left: 2px solid #b5a4dc; }
.branches > .map-node::before { content: ''; position: absolute; width: 13px; height: 2px; background: #b5a4dc; left: -14px; top: 50%; }
.map-node:hover, .map-node[aria-pressed=true] { box-shadow: 0 0 0 2px #cfc0ed; }
dialog { width: min(475px, 93vw); border: 1px solid var(--border); border-radius: 13px; padding: 24px; color: var(--ink); }
dialog::backdrop { background: #22153d70; }
.dialog-close { float: right; }
dialog h2 { margin: 0; }
dialog p, dialog details { font-size: 13px; }
.file-label { display: grid; gap: 7px; font-weight: 650; }
.file-label input { width: 100%; }
.primary { display: block; background: var(--accent); color: white; padding: 8px 12px; margin-top: 16px; }
.primary:disabled { opacity: .5; cursor: default; }
a { color: var(--accent); }
@media (max-width: 900px) { .workspace { grid-template-columns: 175px minmax(0, 1fr); } .panes { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 590px) {
  .workspace { display: block; }
  .sidebar { padding: 12px; border-right: 0; }
  .sidebar nav, .sidebar-footer { margin: 0; padding-top: 8px; display: flex; align-items: center; flex-wrap: wrap; gap: 3px; }
  .sidebar .nav { width: auto; font-size: 12px; padding: 5px 6px; }
  .nav-label { display: none; }
  .category-search { flex-basis: 100%; margin-top: 6px; }
  #categories { flex-basis: 100%; max-height: 32vh; }
  .private, .search kbd { display: none; }
  .topbar { min-height: 54px; }
  .content { padding-top: 18px; }
  .switch button { padding: 5px; }
}
