:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #111827;
  --muted: #6b7280;
  --line: rgba(15, 23, 42, 0.08);
  --brand: #2563eb;
  --brand-soft: rgba(37, 99, 235, 0.1);
  --success: #059669;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Source Han Sans SC", sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

button {
  border: 0;
  border-radius: 999px;
  padding: 9px 15px;
  cursor: pointer;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.16);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(37, 99, 235, 0.34);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.admin-stage {
  min-height: 100vh;
  padding: 28px 20px 36px;
  overflow-x: auto;
}

.admin-shell {
  width: 1320px;
  min-width: 1320px;
  max-width: 1320px;
  margin: 0 auto;
}

.admin-window {
  border-radius: 24px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.ghost-button,
.toggle-paste {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  box-shadow: none;
  text-decoration: none;
}

.admin-scroll {
  padding: 24px 32px 32px;
  display: grid;
  gap: 18px;
}

.admin-section {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.admin-section.compact {
  padding: 14px 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 20px;
}

.section-head-inline {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.section-note {
  margin-bottom: 14px;
  color: var(--muted);
  line-height: 1.7;
}

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

.dataset-grid,
.file-list {
  display: grid;
  gap: 10px;
}

.import-card,
.overview-right,
.file-item,
.search-results,
.dataset-card {
  border: 1px solid rgba(26, 26, 26, 0.08);
  background: #fff;
  border-radius: 18px;
}

.import-card {
  padding: 14px;
  transition: border-color 160ms ease, background 160ms ease;
}

.import-card.drag-over {
  border-color: var(--brand);
  background: rgba(37, 99, 235, 0.04);
}

.mini-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.lexicon-card input[type="file"] {
  display: none;
}

.action-row,
.button-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.toggle-paste {
  gap: 4px;
  margin-top: 12px;
  padding: 6px 11px;
}

.toggle-icon {
  transition: transform 180ms ease;
}

.toggle-paste.open .toggle-icon {
  transform: rotate(45deg);
}

.paste-section {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.paste-select-block {
  display: grid;
  gap: 6px;
}

.paste-select-label {
  color: var(--muted);
  font-size: 11px;
}

.paste-select-shell {
  position: relative;
}

.paste-select-shell::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--brand-soft);
  transform: translateY(-50%);
  pointer-events: none;
}

.paste-select-shell:hover::before,
.paste-select-shell:focus-within::before {
  background: rgba(37, 99, 235, 0.16);
}

.paste-select-shell::after {
  content: "";
  position: absolute;
  top: calc(50% - 3px);
  right: 19px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid rgba(37, 99, 235, 0.8);
  border-bottom: 1.5px solid rgba(37, 99, 235, 0.8);
  transform: rotate(45deg);
  pointer-events: none;
}

#adminKnowledgeTarget {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 46px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 245, 245, 0.98));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

#adminKnowledgeTarget:hover {
  border-color: rgba(37, 99, 235, 0.24);
}

.paste-section.hidden,
.import-progress.hidden,
.search-results.hidden,
.hidden {
  display: none;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 18px;
  text-align: center;
  border: 1.5px dashed rgba(26, 26, 26, 0.14);
  border-radius: 18px;
  cursor: pointer;
  transition: all 180ms ease;
  background: rgba(255, 255, 255, 0.7);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: rgba(37, 99, 235, 0.34);
  background: rgba(37, 99, 235, 0.04);
}

.drop-zone-icon {
  color: var(--muted);
  opacity: 0.5;
  margin-bottom: 6px;
}

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

.drop-zone-link {
  color: var(--brand);
}

.drop-zone-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.drop-zone input[type="file"] {
  display: none;
}

.import-status {
  margin-top: 8px;
  color: var(--success);
  font-size: 11px;
}

.import-status.error {
  color: var(--danger);
}

.import-status:empty {
  display: none;
}

.progress-bar,
.file-progress {
  height: 4px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill,
.file-progress-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
}

.progress-info,
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.progress-info {
  margin-top: 6px;
}

.progress-text,
.file-meta,
.dataset-meta,
.drill-placeholder,
.search-empty {
  color: var(--muted);
  font-size: 11px;
}

.progress-delete,
.file-delete,
.drill-delete {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress-delete:hover,
.file-delete:hover,
.drill-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.file-row {
  padding: 9px 10px;
}

.file-icon,
.dataset-icon,
.drill-idx {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.file-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
}

.file-info,
.dataset-info,
.drill-text {
  flex: 1;
  min-width: 0;
}

.file-name,
.dataset-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

.file-progress-value {
  color: var(--brand);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.file-item[data-status="reading"],
.file-item[data-status="parsing"] {
  border-color: rgba(37, 99, 235, 0.18);
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.04), #fff);
}

.file-item[data-status="reading"] .file-meta,
.file-item[data-status="parsing"] .file-meta {
  color: var(--brand);
  font-weight: 600;
}

.file-item[data-status="reading"] .file-progress-fill,
.file-item[data-status="parsing"] .file-progress-fill {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.85), #60a5fa);
  transition: width 160ms ease;
}

.file-item[data-status="reading"] .file-icon,
.file-item[data-status="parsing"] .file-icon {
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.06);
}

.search-bar input {
  border-radius: 14px;
  background: var(--panel-soft);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  overflow: auto;
  max-height: 280px;
  margin-top: 0;
  z-index: 20;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.insight-workspace {
  display: flex;
  flex-direction: column;
  min-height: min(84vh, calc(100vh - 140px));
  max-height: calc(100vh - 120px);
}

.search-section {
  position: relative;
  flex: none;
  margin-bottom: 14px;
}

.search-group-title {
  padding: 7px 12px 4px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-top: 1px solid rgba(27, 26, 24, 0.05);
  line-height: 1.5;
  cursor: pointer;
  transition: background 160ms ease;
}

.search-item .drill-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
}

.search-item:hover {
  background: rgba(37, 99, 235, 0.05);
}

.search-item mark {
  background: rgba(37, 99, 235, 0.14);
  color: var(--brand);
  border-radius: 3px;
}

.overview-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.overview-left {
  min-width: 0;
  min-height: 0;
}

.overview-right {
  overflow: hidden;
  min-width: 0;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: none;
}

.directory-panel {
  height: 100%;
  border: 1px solid rgba(26, 26, 26, 0.06);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  padding: 10px 12px;
  overflow: auto;
}

.directory-group + .directory-group {
  margin-top: 14px;
}

.directory-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dataset-grid.directory-list {
  grid-template-columns: 1fr;
}

.dataset-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.dataset-card:hover,
.dataset-card.active {
  border-color: rgba(37, 99, 235, 0.22);
  background: rgba(37, 99, 235, 0.04);
}

.directory-item {
  position: relative;
  border: 0;
  border-radius: 12px;
  background: transparent;
  gap: 8px;
  padding: 10px 28px 10px 8px;
  box-shadow: none;
}

.directory-item::after {
  content: "";
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-top: 1.5px solid rgba(111, 107, 99, 0.7);
  border-right: 1.5px solid rgba(111, 107, 99, 0.7);
  transform: rotate(45deg);
}

.directory-item.active::after,
.directory-item:hover::after {
  border-color: rgba(37, 99, 235, 0.88);
}

.directory-item:hover,
.directory-item.active {
  border-color: transparent;
  background: rgba(37, 99, 235, 0.06);
}

.directory-item.removable::after {
  display: none;
}

.directory-item .dataset-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.doc-list-delete,
.doc-delete {
  width: 24px;
  height: 24px;
  padding: 0;
  margin-left: auto;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.doc-list-delete svg,
.doc-delete svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.dataset-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
}

.directory-item .dataset-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 11px;
}

.directory-item .dataset-name {
  display: inline;
  flex: 1;
  font-size: 13px;
}

.directory-item .dataset-meta {
  flex: none;
  white-space: nowrap;
  margin-left: 0;
  color: var(--muted);
  font-size: 11px;
}

.drill-item.focused {
  background: rgba(37, 99, 235, 0.08);
}

.doc-icon {
  background: rgba(15, 138, 95, 0.12);
  color: var(--success);
}

.drill-placeholder {
  margin: 14px;
  padding: 40px 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
}

.drill-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.drill-head h3 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overview-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.overview-section .section-head {
  flex: none;
}

.overview-section #drillPanel,
.overview-section #drillPlaceholder {
  height: 100%;
}

.overview-section #drillPanel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.drill-body {
  overflow-x: auto;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  height: 100%;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
}

.drill-body > * {
  flex: none;
}

.drill-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: none;
}

.knowledge-detail-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.knowledge-detail-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.knowledge-snippet-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.knowledge-rule-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.knowledge-rule-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.knowledge-rule-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.knowledge-rule-index {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(26, 26, 26, 0.06);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.knowledge-rule-delete {
  margin-left: auto;
}

.knowledge-rule-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.knowledge-rule-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
}

.knowledge-rule-meaning {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft, rgba(99, 102, 241, 0.08));
  color: var(--ink);
  font-weight: 500;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.knowledge-rule-source {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--ink);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.knowledge-image-item {
  gap: 10px;
}

.knowledge-image-summary {
  margin-top: 10px;
  color: var(--ink);
  line-height: 1.7;
}

.knowledge-image-rule-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.knowledge-image-rule {
  padding-top: 10px;
  border-top: 1px solid rgba(26, 26, 26, 0.08);
}

.knowledge-image-rule:first-child {
  padding-top: 0;
  border-top: 0;
}

.knowledge-image-error {
  margin-top: 10px;
  color: #b45309;
  line-height: 1.6;
}

.knowledge-table-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: none;
}

.knowledge-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.knowledge-table-title {
  font-size: 12px;
  font-weight: 700;
}

.knowledge-table-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  border: 1px solid rgba(37, 99, 235, 0.16);
  color: var(--brand);
  font-size: 11px;
}

.knowledge-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid rgba(26, 26, 26, 0.08);
  border-radius: 14px;
  background: #fff;
  scrollbar-gutter: stable both-edges;
}

.knowledge-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.knowledge-table th,
.knowledge-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(27, 26, 24, 0.06);
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 140px;
}

.knowledge-table th {
  position: sticky;
  top: 0;
  background: var(--panel-soft);
  font-weight: 700;
  z-index: 1;
}

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

.knowledge-table tbody tr.focused td {
  background: rgba(37, 99, 235, 0.08);
}

.lexicon-detail {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.lexicon-detail-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.lexicon-detail-meta {
  color: var(--muted);
  font-size: 12px;
}

.lexicon-table-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lexicon-table-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.lexicon-table-wrap {
  overflow: hidden;
  border: 1px solid rgba(26, 26, 26, 0.08);
  border-radius: 14px;
  background: #fff;
}

.lexicon-table {
  width: 100%;
  table-layout: fixed;
}

.lexicon-table th,
.lexicon-table td {
  min-width: 0;
}

.lexicon-table th:last-child,
.lexicon-table td:last-child,
.lexicon-action-cell {
  width: 5ch;
  min-width: 5ch;
  max-width: 5ch;
  padding-left: 0;
  padding-right: 0;
  text-align: center;
}

.drill-idx {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 10px;
  margin-top: 1px;
}

.drill-tag {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 10px;
}

.drill-text {
  line-height: 1.7;
  color: var(--ink);
  white-space: normal;
  word-break: break-word;
}

.admin-footer {
  padding: 12px 24px 18px;
  display: flex;
  justify-content: center;
  border-top: 1px solid rgba(27, 26, 24, 0.06);
  background: rgba(255, 255, 255, 0.35);
}

.footer-brand {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: rgba(111, 107, 99, 0.35);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #fff;
  background: rgba(27, 26, 24, 0.92);
  box-shadow: var(--shadow);
}

.toast.error {
  background: rgba(183, 59, 40, 0.95);
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(26, 26, 26, 0.24);
  backdrop-filter: blur(4px);
}

.confirm-modal.hidden {
  display: none;
}

.confirm-dialog {
  width: min(420px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid rgba(26, 26, 26, 0.08);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

.confirm-dialog h3 {
  font-size: 18px;
}

.confirm-dialog p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.7;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 720px) {
  .admin-stage {
    padding: 14px;
  }

  .admin-scroll {
    padding-left: 16px;
    padding-right: 16px;
  }

  .insight-workspace {
    min-height: 740px;
    max-height: none;
  }

  .action-row,
  .button-row {
    flex-direction: column;
    align-items: stretch;
  }
}
