:root {
  --bg: #f5f7fb;
  --bg-accent: #eef3ff;
  --paper: #ffffff;
  --paper-muted: #f8fafc;
  --ink: #111827;
  --muted: #667085;
  --muted-strong: #475467;
  --line: #dbe2ea;
  --line-strong: #c8d1dc;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --success: #027a48;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fff7ed;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 12px 24px rgba(15, 23, 42, 0.06);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(15, 23, 42, 0.04), transparent 26%),
    linear-gradient(180deg, #f8fafc 0%, #f5f7fb 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid rgba(219, 226, 234, 0.96);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  color: var(--ink);
  padding: 12px 15px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease, color 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.28);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

button:disabled {
  cursor: default;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

button.primary {
  border-color: var(--accent);
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.24);
}

button.primary:hover:not(:disabled) {
  border-color: #1d4ed8;
  background: linear-gradient(180deg, #1d4ed8 0%, #1e40af 100%);
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.3);
}

button.danger-button {
  border-color: rgba(180, 35, 24, 0.16);
  background: linear-gradient(180deg, #fff6f5 0%, #fef3f2 100%);
  color: var(--danger);
}

button.danger-button:hover:not(:disabled) {
  border-color: rgba(180, 35, 24, 0.28);
  background: #fff3f1;
  box-shadow: 0 8px 18px rgba(180, 35, 24, 0.08);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  font: inherit;
}

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

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

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: #eff4ff;
  padding: 1px 5px;
  border-radius: 6px;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.panel,
.subpanel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(219, 226, 234, 0.92);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.topbar {
  padding: 18px 22px;
}

.topbar-copy {
  max-width: 820px;
}

.eyebrow,
.section-title,
.metric-label,
.stat-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

h1 {
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h2 {
  margin-top: 6px;
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  margin-top: 6px;
  font-size: 16px;
  line-height: 1.3;
}

.topbar-copy p,
.workspace-copy {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.status-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper-muted);
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge[data-status="success"] {
  background: var(--success-soft);
  border-color: rgba(2, 122, 72, 0.18);
  color: var(--success);
}

.status-badge[data-status="warning"] {
  background: var(--warning-soft);
  border-color: rgba(181, 71, 8, 0.18);
  color: var(--warning);
}

.status-badge[data-status="danger"] {
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.16);
  color: var(--danger);
}

.status-badge[data-status="loading"] {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.16);
  color: var(--accent);
}

.control-panel {
  margin-top: 14px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field-row-single {
  grid-template-columns: 1fr;
}

.main-layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.card-head,
.subpanel-head,
.workspace-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.card-note,
.subtle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field-group {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted-strong);
}

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

.stat-item {
  min-height: 88px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
}

.stat-item-wide {
  grid-column: 1 / -1;
}

.stat-value {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}

.stat-code {
  word-break: break-all;
}

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

.action-grid-compact {
  grid-template-columns: 1fr;
}

.action-grid button {
  justify-content: flex-start;
  min-height: 44px;
  font-weight: 600;
  text-align: left;
}

.action-primary {
  width: 100%;
  margin-top: 14px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
}

.hint {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper-muted);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.notice-list {
  display: grid;
  gap: 4px;
}

.workspace-shell {
  padding: 16px;
}

.workspace-toolbar {
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(219, 226, 234, 0.92);
}

.workspace-title-group {
  min-width: 0;
}

.workspace-copy {
  margin-top: 6px;
  max-width: 520px;
}

.workspace-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.workspace-download-btn {
  min-width: 160px;
  min-height: 46px;
  padding-left: 18px;
  padding-right: 18px;
  font-weight: 700;
}

.tool-pill {
  min-width: 132px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

.tool-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tool-pill strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.4;
}

.workspace-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 14px;
  min-height: 600px;
}

.subpanel {
  padding: 14px;
  box-shadow: none;
  border-radius: 14px;
}

.library-panel,
.tree-panel {
  background: #fcfdff;
  border: 1px solid var(--line);
}

.kb-list,
.tree-root {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 520px;
  max-height: 680px;
  overflow: auto;
  padding-right: 2px;
}

.kb-card {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  text-align: left;
}

.kb-card.active {
  border-color: rgba(37, 99, 235, 0.34);
  background: linear-gradient(180deg, #f7faff 0%, #edf4ff 100%);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.06);
}

.kb-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.kb-meta {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.empty-state,
.loading-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.empty-state strong,
.loading-state strong {
  font-size: 15px;
  line-height: 1.4;
}

.empty-state span,
.loading-state span {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.tree-node {
  border-bottom: 1px solid rgba(219, 226, 234, 0.88);
}

.tree-row {
  display: grid;
  grid-template-columns: 24px 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px;
}

.tree-row:hover {
  background: #f8fbff;
}

.tree-row.is-selected {
  background: #eef4ff;
}

.tree-toggle {
  width: 24px;
  min-width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  border-color: transparent;
  background: #f4f7fb;
  color: var(--muted-strong);
  box-shadow: none;
  font-size: 14px;
  font-weight: 700;
}

.tree-toggle:disabled {
  opacity: 1;
  color: var(--muted);
  background: transparent;
}

.tree-checkbox {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.tree-label-wrap {
  min-width: 0;
}

.tree-label {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-meta {
  margin-top: 1px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}

.type-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fbfcfe;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted-strong);
  white-space: nowrap;
}

.tree-children {
  margin-left: 12px;
  padding: 0 0 0 12px;
  border-left: 1px solid rgba(219, 226, 234, 0.88);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.log-panel {
  margin-top: 18px;
  overflow: hidden;
}

.log-toggle {
  width: 100%;
  padding: 18px 20px;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  box-shadow: none;
}

.log-toggle:hover:not(:disabled) {
  background: #f8fbff;
}

.log-toggle-copy strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.4;
}

.log-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  transition: transform 0.18s ease;
}

.log-panel[data-collapsed="false"] .log-toggle-icon {
  transform: rotate(180deg);
}

.log-body {
  padding: 0 20px 20px;
}

.log-panel[data-collapsed="true"] .log-body {
  display: none;
}

.log-output {
  min-height: 140px;
  max-height: 320px;
  overflow: auto;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0f172a;
  color: #d5def0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.admin-layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-sidebar {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-main {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-fields {
  gap: 12px;
}

.admin-select {
  appearance: none;
}

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

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

.admin-actions-single {
  grid-template-columns: 1fr;
}

.admin-guarded.is-locked {
  opacity: 0.52;
}

.admin-result-card {
  padding: 0;
}

.admin-result-head {
  padding: 4px 0 12px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.admin-heading {
  margin-top: 6px;
}

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

.result-item {
  min-height: 88px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

.result-item-wide {
  grid-column: 1 / -1;
}

.result-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-item strong {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-all;
}

.admin-list-card {
  gap: 12px;
}

.admin-list-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 120px;
  gap: 10px;
}

.token-table-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff;
}

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

.token-table th,
.token-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
}

.token-table th {
  background: #f8fafc;
  color: var(--muted-strong);
  font-weight: 700;
}

.token-row {
  cursor: pointer;
}

.token-row:hover {
  background: #f8fbff;
}

.token-table-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 14px !important;
}

@media (max-width: 1199px) {
  .main-layout {
    grid-template-columns: 340px minmax(0, 1fr);
  }

  .admin-layout {
    grid-template-columns: 360px minmax(0, 1fr);
  }

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

@media (max-width: 899px) {
  .shell {
    width: min(100% - 20px, 1480px);
    padding: 18px 0 24px;
  }

  .topbar,
  .workspace-toolbar,
  .subpanel-head {
    flex-direction: column;
  }

  .status-badges,
  .workspace-tools {
    justify-content: flex-start;
    max-width: none;
  }

  .main-layout,
  .admin-layout,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .field-row,
  .action-grid-compact,
  .admin-actions,
  .result-grid,
  .admin-list-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 639px) {
  .shell {
    width: min(100% - 16px, 1480px);
  }

  .topbar,
  .card,
  .workspace-shell,
  .subpanel,
  .log-toggle,
  .log-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .tree-row {
    grid-template-columns: 28px 18px minmax(0, 1fr);
  }

  .type-chip {
    display: none;
  }
}
