:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-subtle: #f3f4f6;
  --line: #d9dde3;
  --line-strong: #c7ccd4;
  --text: #1f2328;
  --muted: #667085;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --ok: #16803a;
  --warn: #9a6700;
  --danger: #cf222e;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: #fbfbfc;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  flex: 0 0 34px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(31, 68, 161, .18);
}
.brand strong { display: block; font-size: 14px; line-height: 1.2; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
nav { display: grid; gap: 2px; }
.nav-item {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #4b5563;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.nav-item:hover { background: #eef1f4; color: var(--text); }
.nav-item.active {
  background: #e9eef9;
  color: #174ea6;
  font-weight: 600;
}
.sidebar-foot {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 18px;
  display: flex;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #d29922; }
.dot.ok { background: #1a7f37; }
main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}
.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .08em;
}
h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 650;
}
.top-actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid #1f6feb;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 7px 11px;
  font-weight: 600;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--brand-hover); }
.btn.ghost {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}
.btn.ghost:hover { background: var(--surface-subtle); }
.btn.danger { border-color: #d1242f; background: #fff; color: var(--danger); }
.content { padding: 22px 28px 36px; }
.grid { display: grid; gap: 12px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.3fr) minmax(320px, .9fr); }
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}
button.card {
  color: inherit;
  font: inherit;
  text-align: left;
}
.card h2, .card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
}
.stat-label { color: var(--muted); font-size: 11px; }
.stat-value {
  margin-top: 5px;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -.02em;
}
.stat-note { margin-top: 4px; color: var(--muted); font-size: 11px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 0 8px;
}
.section-title h2 { margin: 0; font-size: 13px; font-weight: 650; }
.muted { color: var(--muted); }
.kicker { color: var(--brand); font-size: 11px; font-weight: 600; }
.list { display: grid; gap: 0; }
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding: 10px 2px;
  border-bottom: 1px solid #eceff3;
}
.list-item:last-child { border-bottom: 0; }
.list-item strong { display: block; margin-bottom: 3px; font-size: 12px; font-weight: 600; }
.list-item p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  background: #f2f4f7;
  color: #59636e;
  padding: 2px 6px;
  font-size: 10px;
  white-space: nowrap;
}
.badge.ok { background: #dafbe1; color: var(--ok); }
.badge.warn { background: #fff8c5; color: var(--warn); }
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 9px;
  outline: none;
  font-size: 12px;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: #0969da;
  box-shadow: 0 0 0 2px rgba(9,105,218,.12);
}
.toolbar .input { flex: 1; min-width: 240px; }
.toolbar .select { width: auto; min-width: 140px; }
.textarea { min-height: 220px; resize: vertical; line-height: 1.55; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-group { display: grid; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { color: #4b5563; font-size: 11px; font-weight: 500; }
.result {
  padding: 10px 2px;
  border: 0;
  border-bottom: 1px solid #eceff3;
  border-radius: 0;
  cursor: pointer;
  transition: background .12s ease;
}
.result:hover { background: #f8f9fb; transform: none; }
.result:last-child { border-bottom: 0; }
.result-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.result-title { font-size: 12px; font-weight: 650; }
.path {
  margin-top: 3px;
  color: #57606a;
  font-size: 10px;
  word-break: break-all;
}
.snippet {
  margin-top: 6px;
  color: #57606a;
  font-size: 11px;
  line-height: 1.5;
}
.tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
pre {
  margin: 0;
  padding: 12px;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  background: #f6f8fa;
  color: #24292f;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
}
.split {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 138px);
  align-items: stretch;
}
.split > .card {
  min-height: 0;
  height: calc(100vh - 138px);
  overflow: hidden;
}
.split > .card:first-child {
  display: flex;
  flex-direction: column;
}
.split > .card:first-child > .list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}
.viewer {
  height: calc(100vh - 138px);
  min-height: 520px;
  max-height: none;
  overflow: auto;
}
.empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  color: #8c959f;
  border: 1px dashed #d0d7de;
  border-radius: 6px;
  background: #fbfcfd;
}
.actions { display: flex; gap: 7px; flex-wrap: wrap; }
.metric-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #eceff3;
  font-size: 12px;
}
.metric-line:last-child { border-bottom: 0; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: 420px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  box-shadow: 0 8px 24px rgba(31,35,40,.12);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .18s ease;
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #ff8182; color: var(--danger); }
.loading { opacity: .55; pointer-events: none; }
.code-note {
  padding: 9px 10px;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  background: #f6f8fa;
  color: #57606a;
  font-size: 11px;
}
@media (max-width: 980px) {
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .grid.two, .split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-foot { position: static; margin: 16px 8px 0; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .grid.stats, .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: auto; }
}

.compact-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 680px;
}

.ingest-card { max-width: 920px; }
.tabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  margin: -2px -2px 16px;
}
.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 2px 9px;
  cursor: pointer;
  font-size: 12px;
}
.tab.active {
  border-bottom-color: var(--brand);
  color: var(--text);
  font-weight: 600;
}
.upload-zone {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed #b8bec8;
  border-radius: 6px;
  background: #fafbfc;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.upload-zone:hover,
.upload-zone.dragging {
  border-color: #0969da;
  background: #f6f8ff;
}
.upload-title {
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}
.upload-hint {
  color: var(--muted);
  font-size: 11px;
}
.upload-queue { margin-top: 14px; }
.upload-list-head {
  display: flex;
  justify-content: space-between;
  padding: 0 2px 7px;
  color: var(--muted);
  font-size: 11px;
}
.upload-file {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-top: 1px solid #eceff3;
}
.file-main {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.file-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.file-main span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}
.file-remove {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #6e7781;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.file-remove:hover { background: #f1f2f4; color: var(--danger); }
.upload-meta { margin-top: 14px; }
.upload-actions { margin-top: 12px; }
.upload-actions .btn:disabled {
  cursor: not-allowed;
  opacity: .5;
}
.upload-summary {
  margin-top: 16px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f9fa;
  font-size: 12px;
  font-weight: 600;
}

.reference-list {
  padding: 0;
  overflow: hidden;
}
.reference-head,
.reference-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 90px 78px;
  gap: 12px;
  align-items: center;
}
.reference-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #f6f8fa;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}
.reference-row {
  padding: 10px 12px;
  border-bottom: 1px solid #eceff3;
}
.reference-row:last-child { border-bottom: 0; }
.reference-name { min-width: 0; }
.reference-name strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.reference-sub {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reference-size {
  color: #57606a;
  font-size: 11px;
}
@media (max-width: 720px) {
  .reference-head { display: none; }
  .reference-row {
    grid-template-columns: 1fr auto;
  }
  .reference-row .reference-size { display: none; }
}

.workflow-repo {
  padding: 12px 2px;
  border-bottom: 1px solid #eceff3;
}
.workflow-repo:last-child { border-bottom: 0; }
.workflow-repo-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}
.workflow-repo-head strong {
  display: block;
  font-size: 13px;
}
.workflow-meta {
  margin-top: 8px;
  color: #57606a;
  font-size: 11px;
}
.workflow-commits {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid #e5e7eb;
  color: #4b5563;
  font-size: 11px;
}
.commit-hash {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #0969da;
}

.workflow-config { max-width: 980px; }
.workflow-config-form {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.workflow-config-form .select { width: 100%; }
.workflow-targets { margin-top: 12px; }
.workflow-target {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 2px;
  border-top: 1px solid #eceff3;
}
.workflow-target-path {
  min-width: 0;
  overflow: hidden;
  color: #374151;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.workflow-empty { min-height: 92px; }
@media (max-width: 720px) {
  .workflow-config-form { grid-template-columns: 1fr; }
  .workflow-target { grid-template-columns: auto 1fr auto; }
}

.markdown-body {
  padding: 4px 2px 28px;
  color: #24292f;
  line-height: 1.7;
  font-size: 13px;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.4em 0 .6em;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 24px; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px; }
.markdown-body h2 { font-size: 19px; border-bottom: 1px solid #eef0f2; padding-bottom: 6px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body p { margin: .7em 0; }
.markdown-body blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid #d0d7de;
  background: #f6f8fa;
  color: #57606a;
}
.markdown-body code {
  padding: 2px 4px;
  border-radius: 4px;
  background: #f1f3f5;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .92em;
}
.markdown-body .md-code {
  margin: 12px 0;
  overflow: auto;
}
.markdown-body .md-code code {
  padding: 0;
  background: transparent;
}
.markdown-body ul,
.markdown-body ol { padding-left: 22px; }
.md-task {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  list-style: none;
  margin-left: -20px;
}
.md-table-wrap { overflow-x: auto; margin: 12px 0; }
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid #dfe3e8;
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}
.markdown-body th { background: #f6f8fa; }
.wiki-link,
.relation-link {
  border: 0;
  background: transparent;
  color: #0969da;
  padding: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.wiki-link:hover,
.relation-link:hover { text-decoration: underline; }
.note-relations {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 18px;
  padding: 10px 0 12px;
  border-top: 1px solid #eceff3;
  border-bottom: 1px solid #eceff3;
}
.relation-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}
.relation-items {
  display: flex;
  gap: 6px 10px;
  flex-wrap: wrap;
}
.graph-layout { display: grid; gap: 14px; }
.graph-card, .canvas-card { min-height: 0; }
.graph-stage {
  min-height: 560px;
  height: calc(100vh - 210px);
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fbfcfd;
}
.knowledge-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.graph-edge {
  stroke: #c9d0d8;
  stroke-width: 1.2;
  opacity: .75;
}
.graph-node { cursor: pointer; }
.graph-node circle {
  fill: #ffffff;
  stroke: #57606a;
  stroke-width: 1.5;
}
.graph-node:hover circle {
  fill: #eaf2ff;
  stroke: #0969da;
  stroke-width: 2;
}
.graph-node text {
  fill: #4b5563;
  font-size: 10px;
  pointer-events: none;
}
.canvas-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 12px;
  min-height: 520px;
}
.canvas-list {
  max-height: 620px;
  overflow-y: auto;
  border-right: 1px solid #eceff3;
  padding-right: 10px;
}
.canvas-item {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 9px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.canvas-item:hover,
.canvas-item.active { background: #f1f4f8; }
.canvas-item strong { font-size: 12px; }
.canvas-item span { color: var(--muted); font-size: 10px; }
.canvas-stage {
  min-width: 0;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fbfcfd;
}
.canvas-path {
  padding: 7px 10px;
  border-bottom: 1px solid #e5e7eb;
  color: var(--muted);
  font-size: 10px;
}
.canvas-svg {
  width: 100%;
  min-height: 500px;
  height: 60vh;
  display: block;
}
.canvas-edge {
  stroke: #9aa4b2;
  stroke-width: 2;
}
.canvas-node { cursor: default; }
.canvas-node[data-note] { cursor: pointer; }
.canvas-node rect {
  fill: #fff;
  stroke: #aeb7c2;
  stroke-width: 1.4;
}
.canvas-node[data-note]:hover rect {
  fill: #eef5ff;
  stroke: #0969da;
}
.canvas-node-label {
  color: #24292f;
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}
@media (max-width: 900px) {
  .note-relations { grid-template-columns: 1fr; }
  .canvas-layout { grid-template-columns: 1fr; }
  .canvas-list {
    max-height: 190px;
    border-right: 0;
    border-bottom: 1px solid #eceff3;
    padding-right: 0;
    padding-bottom: 8px;
  }
}

.workflow-folder-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.folder-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 35, 40, .34);
}
.folder-picker {
  width: min(860px, 94vw);
  max-height: min(760px, 90vh);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(31,35,40,.18);
}
.folder-picker-head,
.folder-picker-toolbar,
.folder-picker-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.folder-picker-head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.folder-picker-toolbar {
  border-bottom: 1px solid #eceff3;
}
.folder-picker-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: #57606a;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-picker-list {
  min-height: 280px;
  max-height: 410px;
  overflow-y: auto;
  padding: 6px 14px;
}
.folder-picker-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  border-bottom: 1px solid #f0f1f3;
}
.folder-picker-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 2px;
  text-align: left;
  cursor: pointer;
}
.folder-picker-name:hover { color: #0969da; }
.folder-picker-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-icon { font-size: 14px; }
.folder-picker-selected {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.folder-picker-selected-title {
  margin-bottom: 8px;
  color: #57606a;
  font-size: 11px;
  font-weight: 600;
}
.folder-picker-selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 100px;
  overflow-y: auto;
}
.folder-selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 360px;
  padding: 4px 7px;
  border: 1px solid #d8dee4;
  border-radius: 5px;
  background: #fff;
  font-size: 10px;
}
.folder-selected-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-selected-chip button {
  border: 0;
  background: transparent;
  color: #6e7781;
  cursor: pointer;
}
.folder-picker-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}
@media (max-width: 720px) {
  .workflow-folder-actions { align-items: flex-start; flex-direction: column; }
  .folder-picker-overlay { padding: 8px; }
  .folder-picker { width: 100%; max-height: 96vh; }
}
