@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');

:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #dbe4ef;
  --text: #0f172a;
  --muted: #475569;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #dbeafe;
  --accent: #f97316;
  --ok: #16a34a;
  --warn: #ca8a04;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --max: 1200px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 8% -2%, rgba(37, 99, 235, 0.18), transparent 28%),
    radial-gradient(circle at 95% 0%, rgba(249, 115, 22, 0.16), transparent 30%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
  background: rgba(244, 247, 251, 0.82);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

.brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-flex;
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-text {
  line-height: 1;
}

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

.nav a {
  text-decoration: none;
  font-size: 0.86rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 5px 10px;
  color: #334155;
}

.nav a:hover {
  background: #ffffff;
  border-color: var(--line);
}

.nav a.active {
  background: var(--brand-soft);
  border-color: #b5d0ff;
  color: var(--brand-dark);
  font-weight: 700;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.topbar-project-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 240px;
}

.topbar-subline {
  border-top: 1px solid var(--line);
}

.topbar-subline-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 8px 14px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-tabline {
  border-top: 1px solid var(--line);
}

.topbar-tabline-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 8px 14px 10px;
}

.topbar-tab-grid {
  display: grid;
  gap: 6px;
}

.topbar-tabs-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.topbar-tabs {
  border-color: #d3e1f3;
  background: #f4f8ff;
}

.topbar-tabs-compact {
  padding: 6px;
  gap: 6px;
}

.topbar-tabs-compact .tab-btn {
  padding: 6px 8px;
  min-height: 32px;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-step-num {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #1e3a8a;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border: 1px solid #93c5fd;
}

.topbar-project-switch label {
  font-size: 0.78rem;
  color: #475569;
  white-space: nowrap;
}

.topbar-project-select {
  height: 34px;
  min-width: 150px;
  padding: 6px 9px;
  border-radius: 9px;
  border: 1px solid #cfdceb;
  background: #fff;
}

.topbar-project-refresh {
  padding: 6px 9px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.topbar-kb-metrics {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  min-height: 34px;
}

.kb-mini-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid #dbe7f6;
  background: #ffffff;
  color: #334155;
  padding: 4px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid #c8d7ea;
  background: #eff5ff;
  color: #1e3a8a;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid #c8d7ea;
  background: #eff5ff;
  color: #1e3a8a;
}

.chip.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.chip.danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.container {
  max-width: var(--max);
  margin: 0 auto;
  width: 100%;
  padding: 14px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.card h1,
.card h2,
.card h3,
.card p {
  margin: 0;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.title-row h2 {
  font-size: 1.02rem;
}

.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

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

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

.kpi {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.kpi .label {
  color: var(--muted);
  font-size: 0.78rem;
}

.kpi .value {
  font-size: 1.4rem;
  font-weight: 700;
}

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

.field label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

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

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  width: 100%;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand), #3b82f6);
  color: #fff;
}

.btn-light {
  border-color: var(--line);
  background: #fff;
  color: #0f172a;
}

.btn-selected-entity {
  border-color: #86efac;
  background: #ecfdf3;
  color: #166534;
}

.btn-danger {
  background: #fff5f5;
  border-color: #fecaca;
  color: #991b1b;
}

.btn-link {
  background: none;
  border: none;
  color: var(--brand-dark);
  padding: 0;
}

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

.knowledge-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.knowledge-main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.project-panel {
  position: sticky;
  top: 70px;
}

.project-list {
  display: grid;
  gap: 8px;
  max-height: 72vh;
  overflow: auto;
  padding-right: 2px;
}

.project-item {
  width: 100%;
  text-align: left;
  border: 1px solid #dbe4ef;
  border-radius: 10px;
  background: #fff;
  padding: 9px 10px;
  display: grid;
  gap: 3px;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.project-item:hover {
  border-color: #bfdbfe;
  background: #f8fbff;
}

.project-item.active {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.project-item-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
}

.project-item-meta {
  font-size: 0.73rem;
  color: #475569;
}

.project-summary {
  border: 1px solid #d8e6fb;
  border-radius: 12px;
  background: linear-gradient(135deg, #f7fbff, #ffffff);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.project-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.project-summary-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #0f172a;
}

.project-summary-compact {
  padding: 9px 11px;
}

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

.summary-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: #0f172a;
}

.summary-meta {
  font-size: 0.78rem;
  color: #475569;
  background: #f8fbff;
  border: 1px solid #dbe7f6;
  border-radius: 999px;
  padding: 2px 8px;
}

.project-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.meta-item {
  border: 1px solid #e3ebf5;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 2px;
}

.meta-item span {
  font-size: 0.74rem;
  color: #64748b;
}

.meta-item b {
  font-size: 0.95rem;
  color: #0f172a;
}

.tab-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.step-chip {
  border: 1px solid #dbe4ef;
  border-radius: 10px;
  background: #fff;
  color: #334155;
  padding: 9px 10px;
  font-size: 0.82rem;
  text-align: center;
}

.step-chip.active {
  border-color: #b5d0ff;
  background: #eff6ff;
  color: #1d4ed8;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #f8fbff;
}

.tab-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #475569;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.tab-btn.active {
  border-color: #c9dcff;
  background: #fff;
  color: var(--brand-dark);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.12);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: grid;
}

.subtabs {
  grid-template-columns: repeat(2, minmax(120px, 180px));
  justify-content: start;
}

.subtab-pane {
  display: none;
}

.subtab-pane.active {
  display: grid;
}

.category-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 12px;
}

.category-table .category-row {
  cursor: pointer;
}

.category-table .category-row.selected td {
  background: #f0f7ff;
}

.category-path {
  font-weight: 600;
  color: #0f172a;
}

.field-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #dbe4ef;
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  min-height: 40px;
  font-size: 0.82rem;
  color: #334155;
}

.field-check input {
  width: auto;
  margin: 0;
}

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

.csv-text {
  min-height: 240px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  text-align: left;
  background: #f8fbff;
  color: #334155;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  padding: 8px;
}

tbody td {
  border-bottom: 1px solid #edf2f7;
  padding: 8px;
  color: #334155;
  vertical-align: top;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
}

.status.active {
  background: #ecfdf3;
  color: #166534;
}

.status.disabled {
  background: #f1f5f9;
  color: #334155;
}

.status.deleted {
  background: #fff1f2;
  color: #9f1239;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid #d3e3fb;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
}

.result {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  color: #1e293b;
}

.qa-answer {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 110px;
  max-height: 360px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #0f172a;
}

.qa-citation-list {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hint {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.82rem;
}

.warn {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.danger {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.markdown-view {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  min-height: 100px;
  font-size: 0.92rem;
  line-height: 1.55;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  background: #fff;
}

.workspace-split {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 12px;
}

.panel {
  border: 1px solid #dbe4ef;
  border-radius: 12px;
  background: #fcfdff;
  padding: 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-head h3 {
  font-size: 0.95rem;
}

.hint-inline {
  font-size: 0.76rem;
  color: #64748b;
}

.table-wrap table tbody tr.selected td {
  background: #eff6ff;
}

.entity-current {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid #cfe1ff;
  background: #f3f8ff;
  border-radius: 10px;
  padding: 8px 10px;
}

.entity-current b {
  font-size: 0.9rem;
  color: #0f172a;
}

.article-editor textarea {
  min-height: 170px;
}

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

.entry-grid .field textarea {
  min-height: 100px;
}

.field-note {
  font-size: 0.74rem;
  color: #64748b;
}

.tab-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 9px 10px;
  font-size: 0.82rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-left-color: var(--danger);
}

@media (max-width: 960px) {
  .topbar-inner {
    grid-template-columns: 1fr;
  }
  .topbar-subline-inner {
    align-items: stretch;
  }
  .topbar-tabline-inner {
    padding-top: 8px;
  }
  .topbar-project-switch {
    min-width: 0;
    width: 100%;
  }
  .topbar-kb-metrics {
    width: 100%;
    flex-wrap: wrap;
  }
  .topbar-project-select {
    min-width: 0;
    width: 100%;
  }
  .knowledge-shell {
    grid-template-columns: 1fr;
  }
  .workspace-split,
  .entry-grid {
    grid-template-columns: 1fr;
  }
  .category-layout {
    grid-template-columns: 1fr;
  }
  .project-panel {
    position: static;
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .tabs,
  .tab-steps,
  .project-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .topbar-tabs-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .subtabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .tabs,
  .tab-steps,
  .project-meta-grid {
    grid-template-columns: 1fr;
  }
  .topbar-tabs-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .subtabs {
    grid-template-columns: 1fr;
  }
}
