:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --line: #d8d1c3;
  --text: #2f2b24;
  --brand: #1f7a66;
  --brand-weak: #d8efe8;
  --warn: #9d661f;
  --warn-bg: #fff2df;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% -10%, #ece2d0 0, transparent 45%),
    radial-gradient(circle at 90% 0%, #e7efe7 0, transparent 35%),
    var(--bg);
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

.app { max-width: 1200px; margin: 0 auto; padding: 20px; }
.steps { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin-bottom: 16px; }
.step {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f6f0;
  padding: 10px;
  text-align: center;
  font-weight: 700;
}
.step.done { background: #e6f5ef; border-color: #8ac5b4; }
.step.active { background: #eaf2ff; border-color: #8cb3e5; }
.step-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  margin-right: 6px;
  font-size: 12px;
  background: #d9d9d9;
}
.step.done .step-mark { background: #4ea488; color: #fff; }
.step.active .step-mark { background: #2f73ce; color: #fff; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  min-height: 440px;
}
.hidden { display: none; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.toolbar-right { display: flex; gap: 8px; }

h3 { margin: 8px 0 14px; }
.grid { display: grid; gap: 10px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}
.section-title {
  margin-bottom: 8px;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  margin: 0 8px 8px 0;
  cursor: pointer;
  user-select: none;
}
.choice.active { border-color: var(--brand); background: var(--brand-weak); }
.choice.disabled { opacity: .5; cursor: not-allowed; }
.root-group {
  border: 1px dashed #c8c0b2;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 10px;
}
.root-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.root-title { font-weight: 700; margin-bottom: 6px; color: #3f3a31; }
.root-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mini-btn {
  padding: 6px 12px;
  font-size: 12px;
}
.sub-option-wrap {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.sub-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfbf7;
}
.sub-option-compact {
  padding: 6px 10px;
  font-size: 12px;
}
.metric-inline-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #d9e7e1;
  border-radius: 10px;
  background: #f6fbf9;
}
.metric-inline-options-site {
  border-color: #e5ded1;
  background: #fcf8f1;
}
.citation-inline-options {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}
.metric-inline-title {
  font-size: 12px;
  font-weight: 700;
  color: #285d51;
}
.question-pane {
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.step2-grid select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #7a6a52 50%),
    linear-gradient(135deg, #7a6a52 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
.step2-grid select::-ms-expand {
  display: none;
}
.step2-grid select:focus {
  outline: 2px solid #cfe6de;
  outline-offset: 1px;
  border-color: #79a897;
}
.step2-grid .control-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-label {
  font-size: 13px;
  font-weight: 700;
  color: #5a5042;
  line-height: 1.2;
  min-height: 18px;
}
.step2-grid select,
.step2-grid .input {
  height: 42px;
}
.step2-tips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.step2-tip-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.step2-tip-divider {
  color: #b8ad99;
}
.step2-tip-accent {
  color: #1f7a66;
  font-weight: 700;
}

.notice {
  border: 1px solid #ead6a8;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0;
}
.notice.danger {
  border-color: #efb2b2;
  background: #fff0f0;
  color: #bf2a2a;
  font-weight: 700;
}
.question-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.question-grid .choice {
  margin: 0;
  min-height: 42px;
  justify-content: flex-start;
  border-radius: 12px;
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
}
.dim-toggle.active {
  border-color: var(--brand);
  background: var(--brand-weak);
}
.card + .card {
  margin-top: 2px;
}
.search-input {
  border: 1px solid #7fbcae;
  background: #f7fffc;
}
.search-input:focus {
  outline: 2px solid #ccebe2;
  border-color: #3f9b84;
}
.search-status {
  color: #9d661f;
}
.question-grid .choice.question-match:not(.active) {
  border-color: #c9872d;
  background: #fff3de;
  box-shadow: 0 0 0 1px rgba(201, 135, 45, 0.12);
}
.question-grid .choice.active.question-match {
  box-shadow: 0 0 0 2px rgba(201, 135, 45, 0.4);
}
.question-grid .choice.question-muted {
  opacity: .45;
}
.question-empty {
  grid-column: 1 / -1;
  padding: 6px 2px 0;
}
.metric-desc {
  margin-top: 6px;
  color: #6c6355;
  font-size: 12px;
  line-height: 1.4;
}
.metric-grid {
  align-items: start;
}
.field-grid {
  align-items: start;
}
.field-grid .card {
  height: auto;
  align-self: start;
}
.metric-grid .card { height: auto; align-self: start; }
.metric-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-start;
  align-items: stretch;
}
.metric-card-disabled {
  opacity: .55;
}
.metric-main-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.metric-main-option input {
  margin-top: 2px;
}
.metric-inline-options {
  margin-top: 2px;
}

.preview-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.preview-table th, .preview-table td { border: 1px solid var(--line); padding: 6px 8px; }
.preview-table th { background: #f4f4f4; }
.loading-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 140px;
  padding: 18px;
  border: 1px solid #d9e7e1;
  border-radius: 14px;
  background:
    radial-gradient(circle at top left, #eef9f5 0, transparent 45%),
    #fff;
}
.loading-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #d7ece5;
  border-top-color: #1f7a66;
  border-radius: 50%;
  animation: preview-spin 0.9s linear infinite;
  flex: 0 0 auto;
}
.loading-title {
  font-size: 17px;
  font-weight: 700;
  color: #245e51;
}
@keyframes preview-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.nav {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  position: sticky;
  bottom: 8px;
  z-index: 10;
  background: rgba(255, 253, 248, 0.95);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  backdrop-filter: blur(2px);
}
.spacer { flex: 1; }
button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.ghost { background: #fff; }
.tiny-tip { color: #7a6a52; font-size: 12px; margin-top: 6px; }
.dim-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-right: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}
.dim-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

@media (max-width: 900px) {
  .steps { grid-template-columns: repeat(4, 1fr); }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .question-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .root-head { flex-direction: column; }
  .question-pane { max-height: none; }
  .panel { min-height: 380px; }
}
