/* ========== 知识库面板 ========== */
.knowledge-panel {
  flex-shrink: 0;
}

.knowledge-panel .collapsible-content {
  overflow: hidden;
}

.knowledge-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow-y: auto;
}

/* Knowledge stats */
.knowledge-stats {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.knowledge-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  padding: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.knowledge-tab {
  flex: 1;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.knowledge-tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--panel-strong) 62%, transparent);
}

.knowledge-tab.active {
  color: var(--text);
  background: var(--panel-strong);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

.knowledge-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.knowledge-tab-panel {
  display: none;
}

.knowledge-tab-panel.active {
  display: block;
}

.knowledge-overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
  margin-top: 14px;
}

.knowledge-health-card,
.knowledge-insight-list {
  padding: 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--panel-strong);
}

.knowledge-health-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.knowledge-card-kicker,
.inspector-kicker {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.knowledge-health-title {
  margin-top: 4px;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

.knowledge-health-score {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
}

.knowledge-health-track {
  height: 8px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
}

.knowledge-health-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--transition-slow);
}

.knowledge-health-desc {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.knowledge-insight-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.knowledge-insight-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.knowledge-insight-item strong {
  font-size: 13px;
}

.knowledge-insight-item span {
  color: var(--text-muted);
  font-size: 12px;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.stats-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stats-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.stats-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.knowledge-indexing-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 10px 0 16px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border-subtle));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel-strong));
}

.knowledge-indexing-status > div:not(.indexing-spinner) {
  flex: 1;
  min-width: 0;
}

.knowledge-indexing-status[hidden] {
  display: none;
}

.indexing-spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: indexing-spin 900ms linear infinite;
}

.indexing-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.indexing-desc {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.indexing-progress {
  flex-basis: 100%;
  height: 4px;
  margin-left: 30px;
  margin-top: -4px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, var(--border-subtle));
}

.indexing-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

@keyframes indexing-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .indexing-spinner,
  .global-knowledge-spinner {
    animation: none;
  }
}

/* Entity graph panel */
.knowledge-graph-panel {
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  margin-bottom: 16px;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 500;
}

.graph-scope {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}

.graph-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-level-select {
  height: 28px;
  padding: 0 28px 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.graph-meta {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.knowledge-graph {
  min-height: 280px;
  padding: 10px;
  background: #090b10;
}

.knowledge-graph-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  min-height: 560px;
}

.knowledge-graph-workspace .knowledge-graph {
  min-height: 560px;
}

.knowledge-graph-workspace .graph-canvas {
  min-height: 520px;
}

.knowledge-graph-workspace .knowledge-graph-canvas {
  height: 520px;
}

.knowledge-graph-inspector {
  padding: 14px;
  overflow: auto;
  border-left: 1px solid var(--border-subtle);
  background: var(--panel-strong);
}

.inspector-empty,
.inspector-heading,
.inspector-section {
  padding: 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.inspector-empty p,
.inspector-text {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.inspector-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.inspector-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.inspector-metric {
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
}

.inspector-metric span {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
}

.inspector-metric strong {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
}

.inspector-section {
  margin-top: 10px;
}

.inspector-section-title {
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.inspector-row {
  padding: 7px 0;
  border-top: 1px solid var(--border-subtle);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.graph-canvas {
  position: relative;
  min-height: 420px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--on-dark-soft) 22%, transparent);
  background: var(--surface-dark);
}

.graph-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
}

.graph-control-button {
  min-width: 34px;
  height: 28px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: var(--radius-xs);
  background: rgba(30, 41, 59, 0.78);
  color: #e5e7eb;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.graph-control-button:hover {
  background: color-mix(in srgb, var(--surface-dark-elevated) 78%, var(--accent));
  border-color: color-mix(in srgb, var(--accent) 46%, var(--on-dark-soft));
  color: var(--on-dark);
}

.graph-control-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.graph-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: min(420px, calc(100% - 24px));
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  background: rgba(15, 23, 42, 0.78);
  color: rgba(226, 232, 240, 0.72);
  font-size: 11px;
  pointer-events: none;
}

.knowledge-graph-canvas {
  display: block;
  width: 100%;
  height: 420px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.knowledge-graph-canvas.is-dragging {
  cursor: grabbing;
}

.knowledge-graph-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.graph-evidence-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.graph-community-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.graph-community-panel:empty {
  display: none;
}

.graph-community-panel-title {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.graph-community-item {
  padding: 8px 10px;
  background: var(--panel-strong);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.graph-community-header {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.graph-community-swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 16%, transparent);
}

.graph-community-name {
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-community-count {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.graph-community-summary {
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.graph-evidence-item {
  padding: 8px 10px;
  background: var(--panel-strong);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

.graph-evidence-item.is-selected,
.graph-evidence-item.is-connected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow-xs);
}

.graph-evidence-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-evidence-meta {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 11px;
}

.graph-evidence-text {
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Docs list panel */
.knowledge-docs-panel {
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 500;
}

.docs-actions {
  display: flex;
  gap: 6px;
}

.docs-list {
  overflow: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 140px;
}

.doc-item {
  padding: 10px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
}

.doc-item:hover {
  box-shadow: var(--shadow-xs);
}

.doc-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.doc-name-section {
  flex: 1;
  min-width: 0;
}

.doc-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.doc-name-clickable {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.doc-name-clickable:hover {
  color: var(--accent);
}

.doc-meta-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-chunks {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.doc-delete-btn {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-subtle);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.doc-delete-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.doc-graph-btn {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  background: var(--panel-strong);
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.doc-graph-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.doc-desc-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.doc-category {
  color: var(--accent);
}

.doc-tags {
  color: var(--text-subtle);
}

/* Query panel */
.knowledge-query-panel {
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.query-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 500;
}

.query-mode-hint {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-align: right;
}

.query-form {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.query-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: all var(--transition-base);
}

.query-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.query-options {
  display: flex;
  gap: 8px;
  align-items: center;
}

.query-advanced-options {
  flex: 1;
  min-width: 180px;
}

.query-advanced-options summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  list-style: none;
  padding: 6px 0;
}

.query-advanced-options summary::-webkit-details-marker {
  display: none;
}

.query-select {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.query-num-input {
  width: 50px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  text-align: center;
}

.query-results {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.query-result-summary {
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border-subtle));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-soft) 48%, transparent);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

.query-result-summary-low {
  border-color: color-mix(in srgb, var(--warning) 35%, var(--border-subtle));
  background: var(--warning-soft);
}

.query-result-item {
  padding: 10px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.query-result-low {
  border-color: color-mix(in srgb, var(--warning) 28%, var(--border-subtle));
}

.query-result-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.query-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.query-result-doc-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-result-score {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
}

.query-result-meta,
.query-result-debug,
.query-result-why {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.query-result-why {
  margin-bottom: 8px;
  white-space: normal;
}

.query-result-meta {
  margin-bottom: 6px;
}

.query-result-debug {
  margin-top: 8px;
  font-family: var(--font-mono);
  white-space: normal;
}

.query-result-debug summary {
  cursor: pointer;
  color: var(--text-subtle);
}

.query-result-content {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
