:root {
  --bg: #f5f2fb;
  --panel: rgba(255, 255, 255, 0.98);
  --panel-strong: #ffffff;
  --line: #d2c6e7;
  --line-soft: #ece6f6;
  --text: #2d2240;
  --muted: #6f6188;
  --accent: #6a3da1;
  --accent-soft: #efe7fb;
  --accent-strong: #4e2878;
  --ok: #6a3da1;
  --danger: #b03b63;
  --title-font: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(106, 61, 161, 0.045) 0, rgba(106, 61, 161, 0.045) 1px, transparent 1px, transparent 24px),
    linear-gradient(225deg, rgba(106, 61, 161, 0.03) 0, rgba(106, 61, 161, 0.03) 1px, transparent 1px, transparent 24px),
    linear-gradient(180deg, #faf8fd, #f2eef9);
  background-size: 24px 24px, 24px 24px, auto;
}
a { color: inherit; text-decoration: none; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
code {
  padding: 2px 6px;
  border-radius: 7px;
  background: #f1e9fb;
}

.eyebrow {
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ok);
  font-weight: 800;
}

.sidebar .eyebrow {
  color: rgba(247, 243, 252, 0.72);
}

.admin-shell {
  width: min(1840px, calc(100vw - 16px));
  margin: 8px auto;
  height: calc(100vh - 16px);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.sidebar,
.panel,
.login-card,
.banner,
.stat-card,
.list-card,
.meta-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(72, 42, 110, 0.06);
}

.sidebar,
.panel,
.login-card,
.stat-card,
.list-card,
.meta-card {
  background: var(--panel);
}

.sidebar {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100vh - 16px);
  position: sticky;
  top: 8px;
  color: #f7f3fc;
  background: linear-gradient(180deg, #5b2f88 0%, #4a236f 100%);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 46px rgba(56, 28, 92, 0.18);
}

.sidebar-brand h1 {
  margin: 8px 0 6px;
  font-size: 1.48rem;
  font-family: var(--title-font);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar-brand p {
  margin: 0;
  color: rgba(247, 243, 252, 0.78);
  line-height: 1.6;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(247, 243, 252, 0.78);
  font-weight: 700;
  font-size: 0.98rem;
  transition: 0.18s ease;
  border: 1px solid transparent;
}

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

.nav-item.active {
  background: rgba(255, 255, 255, 0.96);
  color: var(--accent-strong);
  border-color: rgba(255, 255, 255, 0.32);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-meta {
  display: grid;
  gap: 10px;
}

.meta-card {
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.meta-card span {
  display: block;
  color: rgba(247, 243, 252, 0.72);
  margin-bottom: 7px;
}

.meta-card strong {
  font-size: 1rem;
  color: #fff;
}

.sidebar-logout {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.sidebar .ghost-button {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
}

.admin-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.page-header h2 {
  margin: 6px 0 4px;
  font-size: 1.75rem;
  font-family: var(--title-font);
  font-weight: 700;
  color: var(--accent-strong);
}

.page-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.96rem;
}

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

.chip,
.citation-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.84rem;
  border: 1px solid #dcccf2;
  font-weight: 700;
}

.banner {
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #fff;
}

.banner.success {
  color: var(--accent);
  border-color: #dac8f1;
  background: #f5effd;
}

.banner.error {
  color: var(--danger);
  border-color: #efcad7;
  background: #fff5f8;
}

.page-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) rgba(225, 214, 241, 0.72);
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.page-content::-webkit-scrollbar,
.table-shell::-webkit-scrollbar,
.card-list::-webkit-scrollbar,
.message-list::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.page-content::-webkit-scrollbar-thumb,
.table-shell::-webkit-scrollbar-thumb,
.card-list::-webkit-scrollbar-thumb,
.message-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.page-content::-webkit-scrollbar-track,
.table-shell::-webkit-scrollbar-track,
.card-list::-webkit-scrollbar-track,
.message-list::-webkit-scrollbar-track {
  background: rgba(225, 214, 241, 0.72);
  border-radius: 999px;
}

.stats-grid,
.content-grid,
.form-grid {
  display: grid;
  gap: 14px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

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

.content-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.content-grid.two-wide {
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 1.18fr);
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card {
  padding: 14px 16px;
  border-top: 4px solid var(--accent);
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.stat-card strong {
  font-size: 1.58rem;
  font-family: var(--title-font);
  color: var(--accent-strong);
}

.panel {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.panel-head h3,
.panel-head h4 {
  margin: 0 0 4px;
  font-family: var(--title-font);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 1.12rem;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.editor-field {
  display: grid;
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-toolbar label {
  display: block;
  margin: 0;
}

.knowledge-textarea {
  min-height: 220px;
  font-size: 0.95rem;
  line-height: 1.68;
}

.editor-caption {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

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

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

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(109, 62, 162, 0.58);
  box-shadow: 0 0 0 4px rgba(109, 62, 162, 0.12);
}

textarea {
  min-height: 116px;
  resize: vertical;
  line-height: 1.6;
}

.primary-button,
.ghost-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.94rem;
  white-space: nowrap;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff;
}

.ghost-button,
.mini-button {
  background: var(--panel-strong);
  border-color: var(--line);
}

.ghost-button:hover,
.mini-button:hover,
.primary-button:hover {
  filter: brightness(0.98);
}

.mini-button.danger {
  color: var(--danger);
  border-color: #efcad7;
}

.action-row,
.meta-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

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

.inline-form input {
  width: 150px;
  min-width: 0;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.checkbox-row input {
  width: auto;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  max-height: min(62vh, 100%);
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) rgba(225, 214, 241, 0.72);
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

thead th {
  padding: 12px 14px;
  background: #f6f0fc;
  color: var(--accent-strong);
  text-transform: uppercase;
  font-size: 0.78rem;
  text-align: left;
  letter-spacing: 0.04em;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.table-subtext {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.55;
}

.card-list {
  display: grid;
  gap: 10px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) rgba(225, 214, 241, 0.72);
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
}

.card-list.compact {
  gap: 8px;
}

.list-card {
  padding: 12px 14px;
  display: grid;
  gap: 4px;
  transition: 0.18s ease;
  border-radius: 14px;
}

.list-card:hover {
  transform: translateY(-1px);
  border-color: #b99adb;
}

.list-card.active {
  border-color: #8b62be;
  background: linear-gradient(180deg, #f8f2ff, #f3ecfd);
  box-shadow: inset 4px 0 0 var(--accent);
}

.list-card strong {
  font-size: 0.98rem;
}

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

.list-card p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
  font-size: 0.92rem;
}

.result-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-strong);
}

.plain-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.7;
}

.warning-text {
  color: #8d5a00;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 18px 0;
}

.empty-state {
  padding: 22px 16px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  background: rgba(244, 238, 252, 0.88);
  font-size: 0.92rem;
}

.session-shell {
  display: grid;
  grid-template-columns: 250px 300px minmax(0, 1fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.side-panel {
  min-width: 0;
  height: 100%;
}

.chat-panel {
  min-width: 0;
  height: 100%;
}

.message-list {
  display: grid;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) rgba(225, 214, 241, 0.72);
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
}

.side-panel .card-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 8px;
}

.message-bubble {
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.message-bubble.user {
  background: linear-gradient(180deg, #fffefe, #faf7ff);
}

.message-bubble.assistant {
  background: linear-gradient(180deg, #f6f0fc, #efe8fa);
}

.editor-dialog {
  width: min(1180px, calc(100vw - 72px));
  height: min(86vh, 920px);
  padding: 0;
  border: none;
  background: transparent;
}

.editor-dialog::backdrop {
  background: rgba(42, 24, 69, 0.48);
  backdrop-filter: blur(4px);
}

.editor-dialog-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(46, 24, 76, 0.24);
}

.editor-dialog-head,
.editor-dialog-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.editor-dialog-head {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}

.editor-dialog-head h3 {
  margin: 8px 0 6px;
  font-family: var(--title-font);
  color: var(--accent-strong);
  font-size: 1.2rem;
}

.editor-dialog-head p {
  margin: 0;
  color: var(--muted);
}

.editor-dialog-textarea {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  resize: none;
  line-height: 1.72;
  font-size: 0.97rem;
  background: #fcfbff;
  color: var(--text);
}

.editor-dialog-textarea:focus {
  outline: none;
  border-color: rgba(106, 61, 161, 0.58);
  box-shadow: 0 0 0 4px rgba(106, 61, 161, 0.12);
}

.editor-dialog-foot {
  justify-content: flex-end;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.citation-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(560px, calc(100vw - 24px));
  padding: 32px;
}

.login-card h1 {
  margin: 8px 0;
  font-size: 2rem;
  font-family: var(--title-font);
  color: var(--accent-strong);
}

.login-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

@media (max-width: 1200px) {
  html, body {
    overflow: auto;
  }

  .admin-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

  .admin-main,
  .page-content {
    overflow: visible;
  }

  .session-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .side-panel,
  .chat-panel,
  .table-shell,
  .side-panel .card-list,
  .message-list {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 920px) {
  .stats-grid,
  .content-grid.two,
  .content-grid.two-wide,
  .form-grid.two,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
  }

  .editor-toolbar,
  .editor-dialog-head,
  .editor-dialog-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-dialog {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
  }

  .editor-dialog-shell {
    padding: 18px;
    border-radius: 16px;
  }
}
