/* Admin console — dense, neutral, operational
   Reference: Stripe Dashboard / Linear settings / Ant Design Pro
   No gradients, no glass, no decorative pills, no serif display.
*/

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --text-3: #667085;
  --text-4: #98a2b3;
  --accent: #0e7490;
  --accent-soft: #ecfeff;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --edit: #e11d48;
  --edit-soft: #fff1f2;
  --edit-border: #fda4af;
  --edit-focus: 0 0 0 3px rgba(225, 29, 72, 0.16);
  --focus: 0 0 0 3px rgba(14, 116, 144, 0.18);
  --font: "PingFang SC", "Helvetica Neue", "Segoe UI", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --rail: 300px;
  --top: 48px;
  --foot: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* —— Top bar —— */
.topbar {
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}
.topbar-nav {
  display: flex;
  gap: 4px;
}
.topbar-nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-3);
  font-size: 13px;
}
.topbar-nav a:hover { color: var(--text); background: var(--bg); }
.topbar-nav a.is-active {
  color: var(--text);
  background: var(--bg);
  font-weight: 550;
}
.topbar-meta {
  font-size: 12px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}
.topbar-meta.is-dirty { color: var(--warn); }
.topbar-meta.is-ok { color: #067647; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.topbar-user {
  font-size: 12px;
  color: var(--text-2);
  font-weight: 500;
}

/* —— Layout —— */
.layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  height: calc(100vh - var(--top));
  min-height: 0;
}

/* —— Rail —— */
.rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.rail-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: var(--bg);
  border-radius: 8px;
}
.rail-tab {
  border: none;
  background: transparent;
  border-radius: 6px;
  height: 30px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rail-tab:hover { color: var(--text); }
.rail-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-weight: 600;
}
.rail-tab .count {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-4);
  font-size: 11px;
}
.rail-tab.is-active .count { color: var(--edit); }
.rail-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: none;
}
.rail-title .count {
  font-weight: 500;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}

/* 可编辑字段：水红色提示 */
.field label .edit-hint,
.sub-block-hd .edit-hint,
.answer-row-hd .edit-hint {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--edit);
  background: var(--edit-soft);
  border: 1px solid var(--edit-border);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 16px;
  flex-shrink: 0;
}
.input.is-editable,
textarea.input.is-editable,
.crit-row textarea,
.crit-row .point,
.answer-row textarea,
.answer-score-field .point {
  border-color: var(--edit-border);
  background: var(--edit-soft);
}
.input.is-editable:focus,
textarea.input.is-editable:focus,
.crit-row textarea:focus,
.crit-row .point:focus,
.answer-row textarea:focus,
.answer-score-field .point:focus {
  border-color: var(--edit);
  box-shadow: var(--edit-focus);
  background: #fff;
}
textarea.input.is-editable.compact {
  min-height: 0;
}

.input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: var(--focus); }
textarea.input {
  height: auto;
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.55;
}
select.input { appearance: auto; }

.rail-list {
  flex: 1;
  overflow: auto;
  padding: 6px;
}

.q-row {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0 0 1px;
}
.q-row:hover { background: #f2f4f7; }
.q-row.is-active {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.q-row-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.q-row-id .mod-badge {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  color: var(--edit);
  background: var(--edit-soft);
  border: 1px solid var(--edit-border);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 14px;
}
.q-row.is-active .q-row-id { color: var(--accent); }
.q-row-title {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.q-row-dim {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-4);
  font-size: 12px;
}

/* —— Workspace —— */
.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}
.blank {
  margin: auto;
  color: var(--text-4);
  font-size: 13px;
}
.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  background: var(--bg);
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.editor-idline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-3);
}
.editor-idline code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}
.editor-idline .sep { color: var(--text-4); }
.dot-dirty {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  display: inline-block;
}
.editor-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  max-width: 720px;
}
.editor-head-actions { display: flex; gap: 8px; flex-shrink: 0; }

.editor-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
}

.editor-body {
  min-width: 0;
  overflow: auto;
  padding: 16px 20px 28px;
}

.side-toc {
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
}
.side-toc-item {
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1.35;
  position: relative;
}
.side-toc-item:hover {
  color: var(--text);
  background: var(--bg);
}
.side-toc-item.is-active {
  color: var(--text);
  font-weight: 600;
  background: var(--bg);
}
.side-toc-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--text);
  border-radius: 1px;
}

.waterfall-sec {
  max-width: 880px;
  scroll-margin-top: 8px;
}
.sub-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.sub-block:first-of-type {
  margin-top: 8px;
  padding-top: 0;
  border-top: none;
}
.sub-block-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.sub-block-hd h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.section-hd h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}
.section-hd p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-4);
  font-weight: 400;
}
.section-bd { padding: 16px; }

.form-grid {
  display: grid;
  gap: 14px;
}
.field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field .help {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-4);
}

.stats-row {
  display: flex;
  gap: 24px;
  margin-bottom: 12px;
  padding: 0 2px;
  font-size: 12px;
  color: var(--text-3);
}
.stats-row strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

/* Criteria table-like rows */
.crit-table { display: flex; flex-direction: column; gap: 0; }
.crit-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 88px 108px;
  gap: 8px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.crit-row:first-child { border-top: none; padding-top: 0; }
.crit-row.unq { grid-template-columns: 36px minmax(0, 1fr) 108px; }
.crit-idx {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-4);
  padding-top: 8px;
  text-align: center;
}
.crit-row textarea {
  width: 100%;
  min-height: 64px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  resize: vertical;
  background: #fff;
  outline: none;
}
.crit-row textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }
.crit-row .point {
  height: 32px;
  width: 100%;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
}
.crit-row .point:focus { border-color: var(--accent); box-shadow: var(--focus); }
.crit-ops {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  padding-top: 2px;
}
.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 12px;
}
.icon-btn:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Answers list */
.answer-table {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.answer-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}
.answer-row-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.answer-idx {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-4);
}
.answer-tag {
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}
.answer-score-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-3);
}
.answer-score-field .point {
  width: 72px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
}
.answer-score-field .point:focus {
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.answer-row textarea {
  width: 100%;
  min-height: 96px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  resize: vertical;
  background: #fff;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
}
.answer-row textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus);
}
.icon-btn.is-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: #fda29b;
  color: var(--danger);
}

.crit-empty {
  padding: 20px 0;
  color: var(--text-4);
  font-size: 12px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

/* Rules */
.rules-table {
  width: 100%;
  border-collapse: collapse;
}
.rules-table th,
.rules-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.rules-table th {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rules-table td:first-child {
  width: 160px;
  font-weight: 500;
  color: var(--text-2);
}
.rules-table .tip {
  font-size: 12px;
  color: var(--text-4);
  font-weight: 400;
  display: block;
  margin-top: 2px;
}
.rules-table input {
  width: 120px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  outline: none;
}
.rules-table input:focus { border-color: var(--accent); box-shadow: var(--focus); }

/* Buttons */
.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #1d2939; border-color: #1d2939; }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #912018; }
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-3);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

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

/* Footer */
.editor-foot {
  height: var(--foot);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.foot-right { display: flex; gap: 8px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 50;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  pointer-events: none;
}
.toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.is-err { background: var(--danger); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.12);
}
.modal-card-wide {
  width: min(720px, 100%);
  max-height: min(84vh, 900px);
  display: flex;
  flex-direction: column;
  padding: 0;
}
.modal-card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-card-hd h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}
.modal-scroll {
  padding: 16px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.modal-card-wide .modal-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  margin: 0;
}

.hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.hist-table th,
.hist-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.hist-table th {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-4);
}
.hist-table code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
}
.hist-table .mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  white-space: nowrap;
}
.hist-ops {
  white-space: nowrap;
  text-align: right;
}
.hist-ops .btn {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  margin-left: 4px;
}
.hist-preview .field { margin-bottom: 14px; }
.hist-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.hist-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.55;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
}
.hist-ol {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-2);
}

/* —— 数据管理页 —— */
.data-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.data-span { grid-column: 1 / -1; }
.check-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  cursor: pointer;
}
.check-label input { width: auto; }
.validate-box {
  font-size: 12px;
  line-height: 1.5;
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.validate-box.is-ok {
  border-color: #abefc6;
  background: #ecfdf3;
  color: #067647;
}
.validate-box.is-err {
  border-color: #fda29b;
  background: var(--danger-soft);
  color: var(--danger);
}
.validate-box ul {
  margin: 6px 0 0;
  padding-left: 18px;
}
.section-bd code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
}

@media (max-width: 900px) {
  .data-grid { grid-template-columns: 1fr; }
}
.modal-card h2 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.modal-card p {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-3);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - var(--top)); }
  .rail { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .crit-row, .crit-row.unq { grid-template-columns: 1fr; }
  .crit-ops { justify-content: flex-start; }
  .editor-head { flex-direction: column; }
  .editor-main { grid-template-columns: 1fr; }
  .side-toc {
    border-left: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px 12px;
    order: -1;
  }
  .side-toc-item.is-active::before { display: none; }
}
