/* 知识工程平台 Demo — 工业知识运营工作台 */

:root {
  --bg-body: #f4f6f8;
  --bg-panel: #ffffff;
  --bg-muted: #eef2f5;
  --bg-soft: #f8fafb;
  --nav-bg: #17212f;
  --nav-active: #243346;
  --top-bg: #ffffff;

  --text-main: #17212f;
  --text-secondary: #5e6b78;
  --text-muted: #8793a0;
  --text-inverse: #f8fafc;

  --primary: #0e7c86;
  --primary-dark: #0b6169;
  --primary-soft: #e5f3f4;
  --blue: #356b94;
  --green: #2f7d55;
  --amber: #b46d19;
  --red: #b83a3a;
  --violet: #6957a8;

  --border: #d9e1e7;
  --border-strong: #b7c4ce;
  --shadow: 0 1px 2px rgba(20, 35, 50, 0.06);

  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-width: 236px;
  --top-height: 58px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

/* App shell */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--top-height) minmax(0, 1fr);
  grid-template-areas:
    "nav top"
    "nav main";
  height: 100vh;
}

#nav {
  grid-area: nav;
  background: var(--nav-bg);
  color: var(--text-inverse);
  border-right: 1px solid #0e1722;
  padding: 16px 0;
  overflow-y: auto;
}

#nav .logo {
  padding: 0 18px 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 10px;
}

#nav .logo::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 2px;
  background: var(--primary);
}

#nav .nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 18px;
  color: #b7c5d3;
  border-left: 3px solid transparent;
}

#nav .nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
}

#nav .nav-item.active {
  background: var(--nav-active);
  border-left-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

#top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0 20px;
  background: var(--top-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

#top label,
#top .version-label {
  color: var(--text-secondary);
  font-size: 12px;
}

#top select {
  max-width: 260px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
}

#top .sep {
  color: var(--border-strong);
}

#top .spacer {
  flex: 1;
}

.top-user {
  color: var(--text-muted);
  font-size: 12px;
}

.settings-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#btn-settings::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 7px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  vertical-align: middle;
}

.settings-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 148px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(20, 35, 50, 0.14);
  z-index: 80;
}

.settings-menu.open .settings-dropdown {
  display: block;
}

#top .settings-dropdown button {
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-main);
  text-align: left;
}

#top .settings-dropdown button:hover {
  background: var(--bg-soft);
  color: var(--primary-dark);
}

#main {
  grid-area: main;
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

/* Page structure */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 2px 0 6px;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.page-header p {
  max-width: 880px;
  margin: 0;
  color: var(--text-secondary);
}

.eyebrow {
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.page-actions,
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.surface,
.glass-card,
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-title,
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-weight: 700;
  color: var(--text-main);
}

.section-title span,
.card-header {
  min-width: 0;
}

.loading {
  padding: 40px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--text-main);
}

.empty-state p {
  margin: 0;
}

/* Buttons and controls */
.btn-sm,
.btn-xs,
#top button {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-sm,
#top button {
  min-height: 32px;
  padding: 0 12px;
}

.btn-xs {
  min-height: 24px;
  padding: 0 8px;
  font-size: 12px;
}

.btn-sm:hover,
.btn-xs:hover,
#top button:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
}

.btn-sm:disabled,
.btn-xs:disabled,
#top button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.btn-sm.is-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-sm.primary,
.btn-xs.primary,
#top button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-sm.primary:hover,
.btn-xs.primary:hover,
#top button.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-sm.danger,
.btn-xs.danger {
  color: var(--red);
  border-color: #efc3c3;
}

.btn-sm.success,
.btn-xs.success {
  color: var(--green);
  border-color: #bcd9c9;
}

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.success,
.tag.maintenance {
  background: #e8f4ee;
  border-color: #bcd9c9;
  color: var(--green);
}

.status-pill.warning,
.tag.safety {
  background: #fff4df;
  border-color: #efd39b;
  color: var(--amber);
}

.status-pill.danger,
.tag.restricted {
  background: #fbeaea;
  border-color: #efc3c3;
  color: var(--red);
}

.status-pill.info,
.tag.internal {
  background: var(--primary-soft);
  border-color: #b6d9dc;
  color: var(--primary-dark);
}

.tag.public,
.tag.contractor {
  background: #eceafa;
  border-color: #d3cdea;
  color: var(--violet);
}

.text-secondary {
  color: var(--text-secondary);
}

.text-muted {
  color: var(--text-muted);
}

.text-small {
  font-size: 12px;
}

.helper-text {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

/* Dashboard */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stage-panel {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  text-align: left;
  box-shadow: var(--shadow);
}

.stage-panel:hover {
  border-color: var(--primary);
}

.stage-index {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-main);
  font-weight: 700;
}

.stage-panel.done .stage-index {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.stage-body {
  min-width: 0;
}

.stage-body strong,
.stage-body span {
  display: block;
}

.stage-body span {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 3px;
}

.stage-metric {
  text-align: right;
}

.stage-metric b {
  display: block;
  font-size: 18px;
}

.stage-metric span {
  color: var(--text-muted);
  font-size: 12px;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.metric-tile {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
}

.metric-tile b,
.metric-tile .value {
  display: block;
  font-size: 22px;
  color: var(--text-main);
}

.metric-tile span,
.metric-tile .label {
  display: block;
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 14px;
  margin-bottom: 14px;
}

.state-list,
.conclusion-list,
.blueprint-link-list {
  display: grid;
  gap: 8px;
}

.state-list div,
.conclusion-list div,
.blueprint-link-list div {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.state-list span,
.conclusion-list span,
.blueprint-link-list span {
  color: var(--text-secondary);
}

.compact-steps {
  margin: 0;
  padding-left: 20px;
  color: var(--text-secondary);
}

.compact-steps li + li {
  margin-top: 6px;
}

.query-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.query-chip {
  max-width: 100%;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-main);
  white-space: normal;
  text-align: left;
}

.query-chip:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* ── KB 内部 Tab 布局 ── */
.kb-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kb-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.kb-topbar-left h2 {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kb-topbar-scenario {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.kb-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.kb-sub-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--border);
  background: var(--bg-panel);
  padding: 0 16px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.kb-sub-tab {
  padding: 10px 18px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.kb-sub-tab:hover {
  color: var(--text-main);
}

.kb-sub-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.kb-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--border);
}

.kb-tab {
  min-height: 38px;
  padding: 0 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
}

.kb-tab:hover {
  color: var(--text-main);
  background: var(--bg-soft);
}

.kb-tab.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.kb-content {
  min-height: 420px;
}

/* Knowledge graph */
.graph-workspace {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.graph-canvas-card {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border-color: #e9e5dc;
  background: #fffdf8;
}

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 18px 13px;
  border-bottom: 1px dashed #e9e2d5;
  background: #fffdf8;
}

.graph-header h3 {
  margin: 0 0 3px;
  font-size: 16px;
  letter-spacing: 0;
}

.graph-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.graph-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  opacity: 0.88;
}

.merge-entity-btn:disabled {
  cursor: wait;
  color: var(--text-secondary);
  background: var(--bg-soft);
}

.merge-entity-btn .spinner-inline {
  margin-right: 6px;
}

.graph-search {
  width: 170px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #e1ddd4;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.78);
  outline: none;
}

.graph-search:focus {
  border-color: var(--primary);
}

.graph-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 44px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.graph-meta-empty {
  color: var(--text-muted);
  font-size: 12px;
}

.graph-legend-item,
.graph-stat-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
}

.graph-legend-item {
  padding: 0 9px;
}

.graph-legend-item:hover,
.graph-stat-row:hover,
.graph-triplet:hover {
  border-color: var(--primary);
}

.graph-legend-item b,
.graph-stat-row b {
  color: var(--text-secondary);
  font-size: 12px;
}

.graph-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d64357;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 3px var(--border);
}

.graph-dot.type-equipment { background: var(--primary); }
.graph-dot.type-component { background: var(--blue); }
.graph-dot.type-symptom { background: var(--amber); }
.graph-dot.type-cause { background: var(--red); }
.graph-dot.type-inspection_action { background: var(--violet); }
.graph-dot.type-treatment { background: var(--green); }
.graph-dot.type-spare_part { background: #607d8b; }

.graph-canvas {
  position: relative;
  width: 100%;
  height: min(54vh, 560px);
  min-height: 430px;
  background: #fffdf8;
}

.graph-canvas .empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
}

.graph-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 16px;
}

.graph-detail-card {
  min-width: 0;
  min-height: 260px;
  border-color: #e9e5dc;
  background: #fffdf8;
}

.graph-stat-list,
.graph-entity-list,
.graph-triplet-list,
.graph-chunk-list {
  display: grid;
  gap: 8px;
  max-height: 310px;
  overflow: auto;
  padding-right: 2px;
}

.graph-stat-row,
.graph-entity-row {
  justify-content: space-between;
  width: 100%;
  padding: 0 10px;
}

.graph-stat-row span,
.graph-entity-row span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.graph-entity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 1px solid #eee8dd;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-main);
}

.graph-entity-row:hover,
.graph-entity-row.active {
  border-color: #9b003f;
  background: #fff7f3;
}

.graph-entity-row b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-entity-row em {
  color: var(--text-muted);
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}

.graph-triplet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid #eee8dd;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-main);
  text-align: left;
}

.graph-triplet span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-triplet em {
  padding: 2px 7px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #eadfd3;
  color: var(--text-secondary);
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}

.graph-triplet-detailed {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  min-height: 54px;
}

.graph-triplet-detailed strong {
  min-width: 0;
  font-weight: 700;
}

.graph-triplet-detailed p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.graph-triplet.active,
.graph-triplet:hover {
  border-color: #9b003f;
  background: #fff7f3;
}

.graph-chunk-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid #eee8dd;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
}

.graph-chunk-item div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.graph-chunk-item b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-chunk-item span {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.graph-chunk-item p,
.evidence-block {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.evidence-block {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

/* ── 文件管理页 ── */
.file-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.file-toolbar-left { display: flex; align-items: baseline; gap: 12px; }
.file-toolbar-left h3 { margin: 0; font-size: 16px; }
.file-toolbar-right { display: flex; align-items: center; gap: 8px; }
.file-search { padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; width: 180px; }
.file-table th.sortable { cursor: pointer; user-select: none; }
.file-table th.sortable:hover { color: var(--primary); }
.file-table td { vertical-align: middle; }
.file-name-cell { display: flex; align-items: center; gap: 6px; }
.file-icon { font-size: 16px; }
.toggle-switch { position: relative; display: inline-block; width: 34px; height: 18px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 18px; transition: .2s; }
.toggle-slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }
.filter-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filter-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.filter-panel-head strong {
  display: block;
  font-size: 14px;
}
.filter-panel-head span {
  display: block;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
}
.filter-panel-head em {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid #b9dfe2;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-style: normal;
  font-size: 12px;
  white-space: nowrap;
}
.filter-panel .filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 0;
}
.filter-group {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}
.filter-group-title {
  margin-bottom: 8px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
}
.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}
.filter-check:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
}
.filter-check input {
  margin: 0;
  accent-color: var(--primary);
}
.filter-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.file-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  flex-wrap: wrap;
}
.file-page-info,
.file-page-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.file-page-info {
  color: var(--text-secondary);
}
.file-page-info > span + span {
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.file-page-info .file-page-size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.file-page-size select {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
}
.file-page-current {
  min-width: 56px;
  text-align: center;
  color: var(--text-secondary);
}
.file-page-controls .btn-xs:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  background: var(--bg-soft);
}
.chunk-list { max-height: 400px; overflow-y: auto; }
.chunk-item { margin-bottom: 12px; padding: 8px; background: var(--bg); border-radius: 4px; }
.chunk-item pre { margin: 4px 0 0; white-space: pre-wrap; font-size: 12px; color: var(--text-secondary); }
.file-summary { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-secondary); }

/* ── 结构化表治理 ── */
.structured-table-workspace {
  display: grid;
  gap: 14px;
}

.structured-table-panel {
  padding: 16px;
}

.structured-table-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.structured-table-header h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.structured-table-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.structured-table-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.structured-table-stats span {
  min-width: 78px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 12px;
  text-align: center;
}

.structured-table-stats b {
  display: block;
  color: var(--text-main);
  font-size: 16px;
}

.structured-doc-table td,
.structured-fact-table td {
  vertical-align: middle;
}

.structured-caliber-list {
  display: grid;
  gap: 10px;
}

.structured-caliber-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.structured-caliber-item h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.structured-caliber-item p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.55;
}

.structured-subject-btn {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font: inherit;
  font-weight: 600;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.structured-subject-btn:hover {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.structured-fact-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 680px;
}

.structured-fact-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.structured-fact-toolbar .file-search {
  width: min(320px, 100%);
}

.structured-fact-family-select {
  height: 31px;
  min-width: 180px;
  max-width: min(280px, 100%);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
}

.structured-fact-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 240px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.structured-fact-chip b {
  flex: 0 0 auto;
  color: var(--text-main);
  font-weight: 600;
}

.structured-fact-chip b::after {
  content: ":";
  color: var(--text-muted);
}

.structured-fact-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.structured-fact-drawer-head h4 {
  margin: 3px 0 0;
  font-size: 18px;
}

.structured-fact-source {
  color: var(--text-secondary);
  font-size: 12px;
}

.structured-fact-field-grid {
  display: block;
}

.structured-fact-field {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.structured-fact-field span,
.structured-fact-field em {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
}

.structured-fact-field strong {
  display: block;
  margin-top: 4px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.structured-fact-field em {
  margin-top: 6px;
  color: var(--text-muted);
}

.structured-fact-detail-table {
  width: 100%;
  table-layout: fixed;
}

.structured-fact-detail-table th:nth-child(1) {
  width: 26%;
}

.structured-fact-detail-table th:nth-child(2) {
  width: 48%;
}

.structured-fact-detail-table th:nth-child(3) {
  width: 26%;
}

.structured-fact-detail-table td {
  vertical-align: top;
  overflow-wrap: anywhere;
}

.structured-fact-detail-table strong {
  color: var(--text-main);
  font-weight: 600;
  line-height: 1.55;
}

.structured-fact-detail-table code {
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.structured-field-alias {
  color: var(--text-main);
  font-weight: 600;
}

.structured-unknown-field-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--amber);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.structured-unknown-field-btn:hover {
  color: var(--primary-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.structured-field-unknown-row {
  background: #fffaf0;
}

@media (max-width: 760px) {
  .structured-table-header {
    display: grid;
  }
  .structured-table-stats {
    justify-content: stretch;
  }
  .structured-table-stats span {
    flex: 1 1 90px;
  }
  .structured-fact-field-grid {
    overflow-x: auto;
  }
  .structured-fact-chip {
    max-width: 100%;
  }
}

/* ── 首页知识库卡片列表 ── */
.section-divider-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin: 0 0 12px; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.kb-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.kb-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.kb-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 12px rgba(14, 124, 134, 0.14);
}

.kb-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kb-card-head strong {
  font-size: 16px;
  min-width: 0;
}

.kb-card-body {
  color: var(--text-secondary);
  min-height: 20px;
}

.kb-card-meta {
  display: flex;
  gap: 20px;
}

.kb-card-meta b {
  display: block;
  font-size: 16px;
}

.kb-card-meta span {
  color: var(--text-muted);
  font-size: 12px;
}

.kb-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: 12px;
}

.kb-card-arrow {
  color: var(--primary);
  font-weight: 600;
}

/* Planning */
.planning-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 14px;
  margin-bottom: 14px;
}

.interview-panel,
.facts-panel {
  min-height: 440px;
}

.interview-feed {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  padding-right: 4px;
}

.message {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
}

.message.ai {
  background: var(--primary-soft);
}

.message.user {
  background: var(--bg-soft);
}

.message b {
  color: var(--text-secondary);
}

.answer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.answer-box input,
.search-box input,
.inline-form select,
.filter-grid select,
.modal input,
.modal select,
.modal textarea {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  outline: none;
}

.modal textarea {
  min-height: 84px;
  padding-top: 8px;
}

.answer-box input:focus,
.search-box input:focus,
.inline-form select:focus,
.filter-grid select:focus,
.modal input:focus,
.modal select:focus,
.modal textarea:focus {
  border-color: var(--primary);
}

.fact-list {
  display: grid;
  gap: 8px;
}

.fact-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.fact-item label {
  color: var(--text-secondary);
}

.fact-item p {
  margin: 0;
}

.fact-item span {
  color: var(--primary-dark);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

.data-table th {
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-weight: 700;
  white-space: nowrap;
}

.data-table tr:hover td {
  background: #fbfcfd;
}

.blueprint-table td:nth-child(3),
.blueprint-table td:nth-child(8) {
  min-width: 180px;
}

.planning-bottom-grid {
  display: grid;
  grid-template-columns: 0.9fr 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
}

.mini-table th,
.mini-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.mini-table th {
  width: 86px;
  color: var(--text-secondary);
  font-weight: 600;
}

.entity-source-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.entity-source-list a {
  color: #1976d2;
  text-decoration: none;
}

.entity-source-list a:hover {
  text-decoration: underline;
}

.source-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.source-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.source-item b,
.source-item span {
  grid-column: 1;
}

.source-item span {
  color: var(--text-secondary);
}

.source-item button {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
}

/* Ingestion */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.channel-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
}

.channel-head,
.channel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.channel-head strong {
  min-width: 0;
}

.channel-meta {
  display: grid;
  gap: 4px;
  margin: 12px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.channel-footer {
  color: var(--text-muted);
  font-size: 12px;
}

.ingestion-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 14px;
  margin-bottom: 14px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 150px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text-secondary);
}

.upload-zone strong {
  color: var(--text-main);
}

.upload-zone.dragover,
.upload-zone:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-zone.uploading {
  border-color: var(--primary);
  background: var(--primary-soft);
  pointer-events: none;
}

.upload-zone input {
  display: none;
}

.upload-progress {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 13px;
}

.inline-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.inline-form label {
  color: var(--text-secondary);
}

.admission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.admission-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.admission-card strong {
  display: block;
  margin-bottom: 8px;
}

.check-line {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 4px 0;
}

/* Governance */
.pipeline-table {
  display: grid;
  gap: 8px;
}

.pipeline-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

/* Research Plan & Planning */
.research-plan {
  display: grid;
  gap: 14px;
}

.plan-header {
  padding: 16px 0 8px;
}

.plan-header h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.plan-section {
  padding: 16px;
}

.plan-section .section-title {
  margin-bottom: 10px;
}

.plan-items {
  display: grid;
  gap: 6px;
}

.plan-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}

.plan-item:last-child {
  border-bottom: 0;
}

.planning-welcome {
  padding: 24px 0;
}

.planning-welcome h3 {
  margin: 0 0 8px;
}

.doc-link {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--text-main);
}

.doc-link strong,
.doc-link span {
  display: block;
}

.doc-link span {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 12px;
}

.pipeline-steps {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pipeline-step {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-secondary);
}

.pipeline-step.done {
  border-color: #bcd9c9;
  background: #e8f4ee;
  color: var(--green);
}

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

.issue-list {
  display: grid;
  gap: 8px;
}

.issue-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.issue-item b {
  color: var(--red);
}

.issue-item span {
  color: var(--text-secondary);
}

.entity-groups {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.entity-group {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.entity-group label {
  color: var(--text-secondary);
}

.relation-list {
  display: grid;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.relation-list div {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-secondary);
}

.relation-list b {
  color: var(--primary-dark);
}

/* Service */
.service-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-grid label {
  display: grid;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 12px;
}

.result-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.result-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.result-card header,
.result-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-card header span {
  font-weight: 700;
  color: var(--primary-dark);
}

.result-card p {
  margin: 8px 0;
  color: var(--text-secondary);
}

.result-card footer {
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 12px;
}

.score-bar {
  display: flex;
  width: 100%;
  height: 6px;
  margin: 8px 0 4px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border);
}

.score-bar i {
  display: block;
}

.score-bar .bm25 {
  background: var(--blue);
}

.score-bar .vector {
  background: var(--amber);
}

.score-bar .graph {
  background: var(--green);
}

.score-legend {
  color: var(--text-muted);
  font-size: 12px;
}

.graph-path {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid #bcd9c9;
  border-radius: var(--radius-sm);
  background: #eef8f2;
  color: var(--green);
}

.graph-path b {
  padding: 2px 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #bcd9c9;
}

.context-panel {
  position: sticky;
  top: 0;
}

.context-placeholder {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  text-align: center;
}

.context-block {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.context-block h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.context-block ul,
.context-block p {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
}

.context-block p {
  padding-left: 0;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.quality-grid div {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  text-align: center;
}

.quality-grid b {
  display: block;
  color: var(--text-main);
}

.quality-grid span {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Drawer and modal */
.drawer-bg,
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.42);
  z-index: 100;
}

.drawer-bg.open,
.modal-bg.open {
  display: block;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 92vw;
  padding: 22px;
  background: #ffffff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(20, 35, 50, 0.14);
  z-index: 101;
  overflow: auto;
  transform: translateX(100%);
  transition: transform 0.18s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer h3 {
  margin: 0 0 16px;
}

.drawer-close {
  float: right;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.drawer-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.drawer-section h4 {
  margin: 0 0 8px;
}

.file-preview-loading,
.file-preview-error,
.file-preview-empty {
  color: var(--text-secondary);
}

.file-preview-loading-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.file-preview-loading p,
.file-preview-error p {
  margin: 10px 0 0;
  line-height: 1.7;
}

.file-preview-error {
  color: #b42318;
}

.plain-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
}

.plain-list li + li {
  margin-top: 5px;
}

.trace {
  color: var(--primary-dark);
}

.modal-bg {
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-bg.open {
  display: flex;
}

.modal {
  width: min(720px, calc(100vw - 32px));
  max-height: 86vh;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(20, 35, 50, 0.18);
}

.modal h3 {
  margin: 0 0 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-group {
  display: grid;
  gap: 5px;
}

.form-group.wide {
  grid-column: 1 / -1;
}

.form-group label {
  color: var(--text-secondary);
  font-size: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.settings-form {
  display: grid;
  gap: 18px;
}

.settings-form section {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.settings-section-title {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.settings-section-title strong {
  color: var(--text-main);
}

.settings-section-title span,
.settings-note {
  color: var(--text-secondary);
  font-size: 12px;
}

.profile-switcher {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.profile-switcher .wide {
  grid-column: 1 / -1;
}

.profile-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.settings-note {
  margin: 0;
}

.test-result {
  font-size: 12px;
  margin-left: 8px;
}
.test-result.success { color: var(--green); }
.test-result.warning { color: var(--amber); }
.test-result.error { color: var(--red); }

.install-dep-link {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.install-dep-link:hover {
  color: var(--primary-dark);
}

.install-dep-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Tooltip icon */
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 4px;
}

.tooltip-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--text-main);
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.6;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  white-space: pre-line;
  width: max-content;
  max-width: 280px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.tooltip-icon:hover::after {
  opacity: 1;
}

/* Survey page */
.survey-page { max-width: 1100px; }
.survey-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.survey-tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.survey-section { margin-bottom: 16px; padding: 16px 20px; }
.survey-section h4 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.survey-section ul, .survey-section ol { margin: 0; padding-left: 20px; }
.survey-section li { margin-bottom: 6px; line-height: 1.6; }
.tag-ai { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 3px; background: #e8f4fd; color: #1976d2; font-weight: 500; }
.tag-confirm { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 3px; background: #fff3e0; color: #e65100; font-weight: 500; }
.ai-summary { line-height: 1.7; color: var(--text-secondary); }
.confirm-questions li { margin-bottom: 10px; line-height: 1.6; }

/* Login */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(245, 252, 253, 0.86) 0%, rgba(245, 252, 253, 0.48) 46%, rgba(245, 252, 253, 0.78) 100%),
    url("/static/assets/login-bg.png") center center / cover no-repeat,
    #eef7fa;
}

#login-screen.hidden {
  display: none;
}

.login-bg-decor {
  display: none;
}

.login-card {
  position: relative;
  width: min(420px, 100%);
  padding: 34px 36px 32px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 22px 58px rgba(23, 33, 47, 0.14);
  backdrop-filter: blur(14px);
}

.login-dept {
  color: var(--primary-dark);
  font-size: 12px;
  text-align: center;
  margin-bottom: 16px;
  font-weight: 600;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
}

.login-logo-dot {
  flex: 0 0 auto;
  width: 44px;
  height: 54px;
  border-radius: 0;
  background: url("/static/assets/login-logo.png") center center / contain no-repeat;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin: 8px 0 28px;
  font-size: 12px;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 15px;
}

.login-field {
  display: grid;
  gap: 5px;
}

.login-field label {
  color: var(--text-secondary);
  font-size: 12px;
}

.login-field input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(183, 196, 206, 0.88);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-main);
}

.login-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 124, 134, 0.12);
  outline: none;
}

.login-error {
  min-height: 18px;
  color: var(--red);
  text-align: center;
  font-size: 12px;
}

.login-btn {
  height: 42px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(14, 124, 134, 0.22);
}

.login-btn:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

@keyframes login-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.login-card.shake {
  animation: login-shake 0.42s ease;
}

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.login-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.login-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.login-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.login-footer-divider {
  margin: 0 8px;
  color: var(--border-color);
}

/* Knowledge Service API */
.knowledge-api-header {
  margin-bottom: 12px;
}

.knowledge-api-tabs {
  margin-bottom: 14px;
}

.knowledge-api-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  min-height: 560px;
}

.external-key-list,
.external-key-detail,
.external-doc-section,
.external-try-panel,
.external-logs {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}

.external-mcp-page {
  align-items: start;
}

.external-panel-head,
.external-key-row,
.external-auth-head,
.external-auth-tools,
.external-log-filters,
.external-detail-actions,
.external-try-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.external-panel-head,
.external-key-row,
.external-auth-head {
  justify-content: space-between;
}

.external-filter-input,
.external-log-filters input,
.external-log-filters select,
.external-try-panel input,
.external-try-panel select,
.external-try-panel textarea,
.external-detail-grid input,
.external-detail-grid textarea {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  font: inherit;
}

.external-key-list .external-filter-input {
  width: 100%;
  margin: 12px 0 4px;
}

.external-key-row {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
}

.external-key-row:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
}

.external-key-row.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.external-key-row strong,
.external-key-row small,
.external-auth-table small,
.external-auth-table strong,
.external-auth-table span {
  display: block;
}

.external-key-row small,
.external-auth-table small {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 12px;
}

.one-time-key {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #b8d8dc;
  border-radius: var(--radius-sm);
  background: #eefafa;
}

.one-time-key > div:first-child,
.one-time-key-value {
  min-width: 0;
}

.one-time-key-value {
  grid-column: 1 / -1;
  overflow: auto;
}

.one-time-key code,
.external-doc-section code,
.external-mcp-tool-table code,
.external-log-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.external-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.external-detail-grid label,
.external-try-panel label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.external-key-copy-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.external-key-copy-field .btn-xs {
  min-height: 32px;
  white-space: nowrap;
}

.external-key-copy-note {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.external-detail-grid label > span,
.external-try-panel label > span,
.external-pre-label {
  color: var(--text-secondary);
  font-size: 12px;
}

.external-detail-grid .wide {
  grid-column: 1 / -1;
}

.external-toggle-field {
  align-content: start;
}

.external-stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.external-stat-strip div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.external-stat-strip b,
.external-stat-strip span {
  display: block;
}

.external-stat-strip b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.external-stat-strip span {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 12px;
}

.external-auth-head {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.external-auth-tools,
.external-log-filters {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.external-auth-tools .external-filter-input {
  width: 180px;
}

.external-inline-check {
  display: inline-flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.external-auth-table,
.external-log-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 13px;
}

.external-auth-table th,
.external-auth-table td,
.external-log-table th,
.external-log-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.external-auth-table th,
.external-log-table th {
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-weight: 700;
  white-space: nowrap;
}

.external-auth-table tr:hover td,
.external-log-table tr:hover td {
  background: #fbfcfd;
}

.external-log-tool-name {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.knowledge-api-docs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  align-items: start;
}

.external-doc-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 16px;
}

.external-doc-title {
  align-items: flex-start;
  flex-wrap: wrap;
}

.external-doc-title > span:first-child {
  flex: 1 1 auto;
}

.external-doc-download-actions {
  display: flex;
  justify-content: flex-end;
  flex: 0 0 100%;
}

.external-doc-toc a {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 12px;
  text-decoration: none;
}

.external-doc-toc a:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
}

.external-doc-flow {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.doc-flow-step {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.doc-flow-step b {
  display: inline-grid;
  width: 22px;
  height: 22px;
  margin-bottom: 8px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
}

.doc-flow-step span {
  display: block;
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.55;
}

.external-doc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.external-doc-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.external-doc-grid span,
.external-doc-grid code {
  display: block;
}

.external-doc-grid span {
  margin-bottom: 4px;
  color: var(--text-secondary);
  font-size: 12px;
}

.external-doc-grid code {
  overflow-wrap: anywhere;
}

.external-doc-section h4 {
  margin: 18px 0 8px;
  font-size: 13px;
}

.external-doc-note {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--text-secondary);
  line-height: 1.6;
}

.external-doc-table {
  width: 100%;
  margin: 8px 0 14px;
  border-collapse: collapse;
  font-size: 12px;
}

.external-doc-table th,
.external-doc-table td {
  padding: 8px 9px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.external-doc-table th {
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-weight: 700;
  white-space: nowrap;
}

.external-doc-table td {
  background: #ffffff;
  line-height: 1.55;
}

.external-doc-table code {
  overflow-wrap: anywhere;
}

.external-mcp-section pre {
  margin-bottom: 12px;
}

.external-mcp-debug-panel textarea:disabled,
.external-mcp-debug-panel select:disabled,
.external-mcp-debug-panel input:disabled {
  background: var(--bg-soft);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.external-try-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  position: sticky;
  top: 12px;
}

.external-try-row {
  justify-content: space-between;
  flex-wrap: wrap;
}

.external-try-row label:first-child {
  min-width: 136px;
  flex: 1;
}

.external-try-panel pre,
.external-doc-section pre,
.drawer-pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #0f1720;
  color: #e5edf4;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.external-log-filters {
  justify-content: flex-start;
  margin-bottom: 10px;
}

.external-log-filters .external-filter-input {
  min-width: 190px;
}

.external-log-summary {
  color: var(--text-secondary);
  font-size: 12px;
}

.external-log-question {
  max-width: 280px;
}

/* Responsive */
@media (max-width: 1260px) {
  .workflow-grid,
  .channel-grid,
  .metrics-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .planning-layout,
  .planning-bottom-grid,
  .ingestion-layout,
  .governance-grid,
  .service-layout,
  .dashboard-grid,
  .graph-detail-grid,
  .knowledge-api-docs {
    grid-template-columns: 1fr;
  }

  .context-panel {
    position: static;
  }

  .knowledge-api-layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
      "nav"
      "top"
      "main";
  }

  #nav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px;
  }

  #nav .logo {
    display: none;
  }

  #nav .nav-item {
    border-left: 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    padding: 0 12px;
  }

  #nav .nav-item.active {
    border-left: 0;
    border-bottom-color: var(--primary);
  }

  #top {
    flex-wrap: wrap;
    height: auto;
    padding: 10px;
  }

  #main {
    padding: 14px;
  }

  .page-header,
  .graph-header,
  .result-card header,
  .result-card footer {
    display: grid;
  }

  .graph-actions {
    justify-content: stretch;
  }

  .graph-search,
  .graph-actions .btn-sm {
    width: 100%;
  }

  .graph-canvas {
    min-height: 360px;
    height: 58vh;
  }

  .stage-panel,
  .pipeline-row,
  .fact-item,
  .state-list div,
  .conclusion-list div,
  .blueprint-link-list div,
  .source-item,
  .issue-item,
  .entity-group,
  .inline-form,
  .search-box,
  .filter-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .workflow-grid,
  .channel-grid,
  .metrics-strip,
  .admission-grid,
  .quality-grid,
  .knowledge-api-layout,
  .knowledge-api-docs,
  .external-detail-grid,
  .external-stat-strip,
  .external-doc-grid,
  .external-doc-flow {
    grid-template-columns: 1fr;
  }

  .external-auth-head,
  .external-auth-tools,
  .external-log-filters,
  .external-detail-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .external-auth-tools .external-filter-input,
  .external-log-filters input,
  .external-log-filters select,
  .external-log-filters button,
  .external-detail-actions button {
    width: 100%;
  }

  .filter-panel .filter-grid {
    grid-template-columns: 1fr;
  }

  .file-pagination,
  .file-page-controls {
    justify-content: flex-start;
  }
}

.spinner-inline {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid #ccc;
  border-top-color: #1976d2;
  border-radius: 50%;
  animation: spin-inline 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes spin-inline { to { transform: rotate(360deg); } }

.datasource-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 0.85rem;
  padding: 0.9rem;
}
.datasource-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.datasource-head strong {
  display: block;
  font-size: 0.98rem;
  color: var(--text-primary);
}
.datasource-head p {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.5;
}
.datasource-stats {
  min-width: 72px;
  text-align: right;
}
.datasource-stats b {
  display: block;
  font-size: 1.35rem;
  color: var(--primary);
  line-height: 1.1;
}
.datasource-stats span {
  color: var(--text-secondary);
  font-size: 0.72rem;
}
.collected-preview {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.45rem;
}
.collected-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.1fr) minmax(180px, 1.4fr) 130px;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  background: var(--bg-muted);
  border-radius: 6px;
  font-size: 0.78rem;
}
.collected-row b,
.collected-row span {
  display: block;
}
.collected-row span,
.collected-row em,
.collected-row p {
  color: var(--text-secondary);
}
.collected-row p {
  margin: 0;
}
.collected-row em {
  font-style: normal;
  text-align: right;
}
.collected-empty {
  margin-top: 0.75rem;
  padding: 0.7rem;
  background: var(--bg-muted);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.82rem;
}
.collecting-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid #d8e7fb;
  border-radius: 8px;
  background: #f4f9ff;
}
.collecting-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-primary);
  font-size: 0.82rem;
}
.collecting-line span:last-child,
.collecting-steps {
  color: var(--text-secondary);
}
.collecting-bar {
  height: 6px;
  margin: 0.7rem 0 0.55rem;
  overflow: hidden;
  border-radius: 999px;
  background: #d9e9fb;
}
.collecting-bar i {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #58b7ff);
  animation: collect-slide 1.1s ease-in-out infinite;
}
@keyframes collect-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}
.collecting-steps {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
}
.collect-result,
.collect-error {
  margin-top: 0.75rem;
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  font-size: 0.82rem;
}
.collect-result {
  border: 1px solid #bde5cb;
  background: #f0fbf4;
  color: #176b36;
}
.collect-result b {
  margin-right: 0.5rem;
}
.collect-error {
  border: 1px solid #f0c2c2;
  background: #fff5f5;
  color: #a62b2b;
}
.image-preview-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.image-preview-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}
@media (max-width: 720px) {
  .datasource-head,
  .collected-row {
    grid-template-columns: 1fr;
    display: grid;
  }
  .datasource-stats,
  .collected-row em {
    text-align: left;
  }
}

/* ── AI Chat Interface (Anthropic-inspired design) ── */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--top-height) - 48px);
  background: #faf8f5;
  border: 1px solid #e8e4dc;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
}

.chat-header {
  padding: 20px 28px;
  border-bottom: 1px solid #ede8df;
  background: #faf8f5;
}

.chat-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: #3d3929;
}

.chat-header .eyebrow {
  color: #b8a87e;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 28px;
  background: #faf8f5;
  scroll-behavior: smooth;
}

.chat-welcome {
  text-align: center;
  padding: 64px 20px 48px;
  color: #8b8574;
}

.chat-welcome-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: #f0ebe0;
  display: grid;
  place-items: center;
  font-size: 28px;
}

.chat-welcome h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  color: #3d3929;
}

.chat-welcome p {
  margin: 0 0 28px;
  font-size: 14px;
  line-height: 1.7;
  color: #8b8574;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.chat-welcome-suggestions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

.chat-welcome-suggestions .query-chip {
  font-size: 13px;
  padding: 8px 18px;
  border: 1px solid #e0d9ca;
  border-radius: 20px;
  background: #fffdf9;
  color: #5e5540;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chat-welcome-suggestions .query-chip:hover {
  border-color: #c4a96a;
  color: #3d3929;
  background: #fdfaf3;
}

/* Message layout */
.chat-msg {
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
}

.chat-msg-user {
  align-items: flex-end;
}

.chat-msg-ai {
  align-items: flex-start;
}

/* AI messages — clean text, no bubble */
.chat-msg-ai .chat-msg-content {
  max-width: 100%;
  padding: 0;
  font-size: 15px;
  line-height: 1.75;
  color: #3d3929;
  word-break: break-word;
}

.chat-msg-ai .chat-msg-content p {
  margin: 0 0 12px;
}

.chat-msg-ai .chat-msg-content p:last-child {
  margin-bottom: 0;
}

.chat-msg-ai .chat-msg-content ul,
.chat-msg-ai .chat-msg-content ol {
  margin: 0 0 12px;
  padding-left: 20px;
}

.chat-msg-ai .chat-msg-content li {
  margin-bottom: 4px;
}

.chat-msg-ai .chat-msg-content code {
  font-size: 13px;
  background: #f0ebe0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", monospace;
}

.chat-msg-ai .chat-msg-content pre {
  background: #f5f2ea;
  border: 1px solid #e8e4dc;
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 14px;
}

.chat-msg-ai .chat-msg-content strong {
  font-weight: 600;
  color: #2d2a1f;
}

.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 10px 0 16px;
  border: 1px solid #e0d9ca;
  border-radius: 8px;
  background: #fffdf8;
}

.md-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
}

.md-table th,
.md-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #ebe4d6;
  border-right: 1px solid #ebe4d6;
  text-align: left;
  vertical-align: top;
  white-space: normal;
}

.md-table th:last-child,
.md-table td:last-child {
  border-right: 0;
}

.md-table tbody tr:last-child td {
  border-bottom: 0;
}

.md-table th {
  background: #f5f2ea;
  color: #4e4938;
  font-weight: 650;
  white-space: nowrap;
}

.md-table tbody tr:nth-child(even) td {
  background: #fffaf0;
}

.md-table .align-right,
.md-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.md-table .align-center {
  text-align: center;
}

.chat-md-table-wrap {
  max-width: min(100%, 920px);
}

/* Reference files under an AI answer */
.chat-references {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #d9d2c2;
}
.chat-ref-title {
  font-size: 12px;
  color: #8a8164;
  margin-bottom: 6px;
}
.chat-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-ref-item {
  display: inline-block;
  max-width: 100%;
  padding: 4px 10px;
  font-size: 12px;
  color: #1f6f4a;
  background: #eef5ef;
  border: 1px solid #cfe3d6;
  border-radius: 14px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-ref-item:hover {
  background: #e0efe4;
  border-color: #9fcbb0;
}

.chat-structured-panel {
  width: min(100%, 760px);
  margin: 2px 0 12px;
  padding: 12px 14px;
  border: 1px solid #d9e5d7;
  border-radius: 8px;
  background: #f5faf4;
  color: #354432;
}

.chat-structured-caliber {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 13px;
}

.chat-structured-caliber > span {
  color: #6f8a5c;
  font-weight: 650;
}

.chat-structured-caliber strong {
  font-size: 14px;
  color: #273421;
}

.chat-structured-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #68785e;
}

.chat-structured-result {
  margin-top: 8px;
  font-size: 12.5px;
  color: #3d4c36;
}

.chat-structured-result p {
  margin: 0 0 6px;
}

.chat-structured-points {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chat-structured-points span {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid #d4dfd1;
  border-radius: 999px;
  background: #fff;
  font-variant-numeric: tabular-nums;
}

/* User messages — subtle warm bubble */
.chat-msg-user .chat-msg-content {
  background: #f0ebe0;
  color: #3d3929;
  border-radius: 18px 18px 6px 18px;
  max-width: 72%;
  padding: 12px 18px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

/* Thinking / status indicators */
.chat-thinking {
  color: #b8a87e;
  font-size: 14px;
  padding: 8px 0;
}

.chat-search-info {
  color: #8b7d5c;
  font-size: 13px;
  padding: 4px 0 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid #ede8df;
}

.chat-search-info::before {
  content: "→ ";
  font-weight: 600;
}

.chat-error {
  color: #c44;
  font-size: 14px;
  padding: 4px 0;
}

.chat-typing {
  color: #b8a87e;
  font-size: 15px;
  animation: chat-blink 1.2s ease-in-out infinite;
}

@keyframes chat-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* 检索步骤进度 */
.chat-steps {
  display: grid;
  gap: 4px;
  margin: 4px 0 8px;
}
.chat-steps:empty { display: none; }
.chat-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #8b7d5c;
  line-height: 1.5;
}
.chat-step.done { color: #6f8a5c; }
.chat-step.active { color: #1976d2; }
.chat-step-done {
  display: inline-flex;
  width: 14px;
  justify-content: center;
  font-weight: 700;
  color: #6f8a5c;
}
.chat-step-spin {
  width: 11px;
  height: 11px;
  border: 2px solid #cfe0f5;
  border-top-color: #1976d2;
  border-radius: 50%;
  flex: 0 0 auto;
  animation: chat-step-rotate 0.7s linear infinite;
}
@keyframes chat-step-rotate {
  to { transform: rotate(360deg); }
}

/* 检索设置弹窗 */
.retrieval-settings { display: grid; gap: 10px; }
.retrieval-settings .rs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  color: #4a4636;
}
.retrieval-settings .rs-row > span { flex: 1; }
.retrieval-settings .rs-row input[type="number"],
.retrieval-settings .rs-row select {
  width: 120px;
  padding: 6px 8px;
  border: 1px solid #d8d2c4;
  border-radius: 6px;
  font-size: 13px;
}
.retrieval-settings .rs-switch input[type="checkbox"] { width: 18px; height: 18px; }
.retrieval-settings .rs-hint {
  margin: -4px 0 4px;
  font-size: 12px;
  color: #9a9078;
  line-height: 1.5;
}

/* Input bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid #ede8df;
  background: #fdfbf6;
}

.chat-input-bar .btn-sm {
  flex-shrink: 0;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid #e0d9ca;
  border-radius: 10px;
  background: #fffdf9;
  color: #5e5540;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chat-input-bar .btn-sm:hover {
  border-color: #c4a96a;
  background: #fdfaf3;
}

.chat-input-wrapper {
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-wrapper textarea {
  flex: 1;
  min-height: 42px;
  max-height: 160px;
  padding: 10px 16px;
  border: 1px solid #e0d9ca;
  border-radius: 10px;
  background: #fffdf9;
  outline: none;
  font-size: 15px;
  line-height: 1.5;
  color: #3d3929;
  resize: none;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-wrapper textarea:focus {
  border-color: #c4a96a;
  box-shadow: 0 0 0 3px rgba(196, 169, 106, 0.12);
}

.chat-input-wrapper .btn-sm.primary {
  flex-shrink: 0;
  min-height: 42px;
  padding: 0 22px;
  border: none;
  border-radius: 10px;
  background: #d4a853;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chat-input-wrapper .btn-sm.primary:hover {
  background: #c49a3c;
}

/* AI message label */
.chat-msg-label {
  font-size: 12px;
  font-weight: 600;
  color: #b8a87e;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* KB drawer in chat */
.chat-kb-item {
  padding: 14px 0;
  border-bottom: 1px solid #ede8df;
}

.chat-kb-item:last-child {
  border-bottom: none;
}

.chat-kb-item h4 {
  margin: 0 0 4px;
  font-size: 14px;
  color: #3d3929;
}

.chat-kb-item p {
  margin: 0;
  font-size: 13px;
  color: #8b8574;
  line-height: 1.6;
}

/* KB summary reminder badge + missing-summary UI */
.kb-summary-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #d9534f;
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 0 0 2px #fdfbf6;
  pointer-events: none;
}

.kb-summary-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #fdf3e3;
  border: 1px solid #ecd9b0;
  border-radius: 8px;
  font-size: 13px;
  color: #8a6d2f;
}

.kb-summary-panel {
  display: grid;
  gap: 10px;
}

.kb-summary-read,
.kb-summary-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.kb-summary-read {
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.kb-summary-read:hover,
.kb-summary-read:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 6px 18px rgba(20, 35, 50, 0.08);
}

.kb-summary-read.is-missing {
  border-color: #ecd9b0;
  background: #fffaf2;
}

.kb-summary-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.kb-summary-editor-head h4 {
  margin: 0 0 3px;
  font-size: 14px;
  color: var(--text-main);
}

.kb-summary-editor-head span {
  color: var(--text-secondary);
  font-size: 12px;
}

.kb-summary-edit-trigger {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px);
  white-space: nowrap;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.kb-summary-read:hover .kb-summary-edit-trigger,
.kb-summary-read:focus-within .kb-summary-edit-trigger {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.kb-summary-note {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 12px;
}

.kb-summary-note.warning {
  border-color: #ecd9b0;
  background: #fdf3e3;
  color: #8a6d2f;
}

.kb-summary-read .kb-summary-body,
.kb-summary-read .kb-summary-placeholder {
  margin: 0;
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.kb-summary-read .kb-summary-body {
  color: var(--text-main);
}

.kb-summary-read .kb-summary-placeholder {
  color: #9a6a2e;
}

.kb-summary-textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font: inherit;
  line-height: 1.6;
}

.kb-summary-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.kb-summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.kb-summary-read-actions {
  min-height: 32px;
}

.kb-summary-status {
  color: var(--text-secondary);
  font-size: 12px;
}

.kb-summary-status.success {
  color: var(--green);
}

.kb-summary-status.warning {
  color: #8a6d2f;
}

.kb-summary-status.error {
  color: var(--red);
}

.kb-no-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #b06a2c !important;
}

@media (hover: none) {
  .kb-summary-edit-trigger {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

/* Permission modal table */
.perm-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  outline: none;
}

/* ── Markdown File Viewer ── */

.md-viewer {
  font-size: 15px;
  line-height: 1.8;
  color: #3d3929;
  word-break: break-word;
}

.md-viewer h1 { font-size: 1.6em; margin: 0.8em 0 0.4em; font-weight: 700; border-bottom: 1px solid #e8e4dc; padding-bottom: 0.3em; }
.md-viewer h2 { font-size: 1.35em; margin: 0.8em 0 0.35em; font-weight: 700; }
.md-viewer h3 { font-size: 1.15em; margin: 0.7em 0 0.3em; font-weight: 600; }
.md-viewer h4 { font-size: 1.05em; margin: 0.6em 0 0.25em; font-weight: 600; }

.md-viewer p {
  margin: 0 0 0.9em;
}

.md-viewer ul, .md-viewer ol {
  margin: 0 0 0.9em;
  padding-left: 1.8em;
}

.md-viewer li {
  margin-bottom: 0.25em;
}

.md-viewer code {
  font-size: 0.88em;
  background: #f0ebe0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
}

.md-viewer pre {
  background: #f5f2ea;
  border: 1px solid #e8e4dc;
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  margin: 0 0 0.9em;
  line-height: 1.6;
}

.md-viewer pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

.md-viewer blockquote {
  margin: 0 0 0.9em;
  padding: 4px 16px;
  border-left: 4px solid #c4a96a;
  background: #fdfaf3;
  color: #6b6348;
}

.md-viewer table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 0.9em;
}

.md-viewer th, .md-viewer td {
  padding: 8px 12px;
  border: 1px solid #e0d9ca;
  text-align: left;
}

.md-viewer th {
  background: #f5f2ea;
  font-weight: 600;
}

.md-viewer img {
  max-width: 100%;
  border-radius: 6px;
}

.md-viewer a {
  color: #0e7c86;
}

.md-viewer hr {
  border: none;
  border-top: 1px solid #e8e4dc;
  margin: 1.2em 0;
}

.md-viewer input[type="checkbox"] {
  margin-right: 6px;
}

.file-content-pre {
  font-size: 13px;
  line-height: 1.6;
  padding: 16px;
  background: #f5f2ea;
  border: 1px solid #e8e4dc;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  color: #3d3929;
}

.file-content-with-tables {
  font-size: 14px;
  line-height: 1.7;
  color: #3d3929;
  white-space: pre-wrap;
  word-break: break-word;
}

.file-content-with-tables .md-table-wrap {
  white-space: normal;
}
