:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --primary: #3b6cf5;
  --primary-d: #2f57c9;
  --text: #1f2733;
  --muted: #6b7686;
  --border: #e3e8ef;
  --ok: #1a9d67;
  --danger: #e04b4b;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(30, 40, 60, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 820px; margin: 0 auto; padding: 16px; }

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p.muted, .muted { color: var(--muted); font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

label { display: block; font-size: 14px; margin: 10px 0 5px; font-weight: 600; }
.req::after { content: " *"; color: var(--danger); }

input[type=text], input[type=number], input[type=tel], input[type=password],
textarea, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 60px; resize: vertical; }

/* 未显式声明 type 的文本输入框（编辑器里的选项、题目、区间等）：
   视觉样式与「问卷标题」输入框保持一致，但不设置宽度——宽度仍由各自布局决定，保持不变。 */
input:not([type]) {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}

input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }

button {
  font-size: 15px;
  font-family: inherit;
  padding: 11px 16px;
  border: none;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--primary-d); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { background: #eef1f6; color: var(--text); }
button.ghost:hover { background: #e2e7f0; }
button.danger { background: var(--danger); }
button.small { padding: 6px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* 问卷卡片操作：四等分单行，更多菜单不挤占其他按钮。 */
.survey-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.survey-actions > button,
.more-trigger {
  min-width: 0;
  min-height: 42px;
  padding: 9px 10px;
  font-size: 14px;
  white-space: nowrap;
}
.more-menu { position: relative; }
.more-trigger { width: 38px; font-size: 24px; line-height: 1; padding: 0; }
.more-popover {
  display: none;
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  right: 0;
  width: 108px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
}
.more-menu.open .more-popover { display: grid; gap: 5px; }
.more-popover button { width: 100%; padding: 8px 10px; font-size: 14px; }

a { color: var(--primary); text-decoration: none; }

/* 选项（前台题目） */
.opt {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--border);
  border-radius: 10px; margin: 8px 0; cursor: pointer; background: #fff;
}
.opt input { width: auto; }
.opt.sel { border-color: var(--primary); background: #eef3ff; }

.q-title { font-weight: 600; margin-bottom: 4px; }
.q-index { color: var(--primary); font-weight: 700; }

/* 统计条 */
.bar-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 14px; }
.bar-label { width: 44%; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: #eef1f6; border-radius: 6px; height: 18px; position: relative; }
.bar-fill { background: var(--primary); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-num { width: 46px; text-align: right; color: var(--muted); }

.stat-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 120px; background: #eef3ff; border-radius: 10px; padding: 12px; text-align: center; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat .l { font-size: 13px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; background: #eef1f6; color: var(--muted); }
.pill.on { background: #e3f5ec; color: var(--ok); }
.pill.off { background: #fdeaea; color: var(--danger); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: #eef1f6; color: var(--text); }
.tabs button.active { background: var(--primary); color: #fff; }

.result-score { font-size: 46px; font-weight: 800; color: var(--primary); text-align: center; margin: 10px 0 2px; }
.center { text-align: center; }
.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 99; box-shadow: var(--shadow);
}
.qr-box { text-align: center; }
.qr-box svg { width: 220px; height: 220px; }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.mini { font-size: 12px; color: var(--muted); }

/* ---------- 表单细节美化 ---------- */
input, textarea, select, button { transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
input:focus, textarea:focus, select:focus { box-shadow: 0 0 0 3px rgba(59, 108, 245, .12); }
button:active { transform: translateY(1px); }
button.small { border-radius: 8px; }

/* 自定义下拉箭头 */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7686' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}

/* 编辑器子项卡片 */
.field-item, .q-item, .range-item {
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.field-item, .q-item, .range-item { container-type: inline-size; }

/* 基本信息：名称优先占据可用空间；空间不足时，名称与其余设置分两行。 */
.field-main {
  display: flex;
  gap: 8px;
  align-items: center;
}
.field-label {
  flex: 1 1 130px;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  max-height: 36px;
  padding: 6px 12px;
  line-height: 22px;
}
.field-actions { display: flex; flex: none; gap: 8px; align-items: center; }
.field-actions select { width: auto; flex: none; }
.q-item .q-index { font-size: 14px; }
.inline-check {
  display: inline-flex; align-items: center; gap: 5px;
  margin: 0; font-weight: 500; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.inline-check input { width: auto; }

/* 必填 / 可空 互斥分段开关（手机友好，点按切换） */
.seg {
  display: inline-flex; flex: none;
  border: 1px solid var(--border); border-radius: 9px;
  overflow: hidden; background: #eef1f6;
}
.seg-btn {
  height: 38px; padding: 0 16px;
  background: transparent; color: var(--muted);
  border: none; border-radius: 0;
  font-size: 14px; font-weight: 600; line-height: 1;
  display: flex; align-items: center;
}
.seg-btn:hover { background: rgba(0, 0, 0, .04); }
.seg[data-required="1"] .seg-btn[data-val="1"],
.seg[data-required="0"] .seg-btn[data-val="0"] {
  background: var(--primary); color: #fff;
}

.icon-btn {
  width: 36px; height: 36px; padding: 0; flex: none; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
}
/* 题目标题 / 选项行：共用同一套三列网格，列边界像素级对齐
   列宽比例 = 选项文本 : 分值 : 删除 = 9 : 0.7 : 0.3，均不溢出卡片 */
.q-title-grid, .opt-grid {
  display: grid;
  grid-template-columns: 1fr 120px 40px; /* 选项文本(伸缩) | 步进器 | 删除(正方形) */
  gap: 8px;
  align-items: center;
}
.q-title-grid { margin-top: 6px; }
.opt-grid { margin: 6px 0; }
/* 题目框占「选项文本 + 步进器」两列，右边与步进器右边对齐，删除列留作间距 */
.q-title-grid .qt-input { grid-column: 1 / 3; }
.q-title-grid input, .opt-grid > input { width: 100%; min-width: 0; }

/* 分值步进器：左减 · 数值 · 右加，连成一体，便于手机点按 */
.stepper { display: flex; align-items: stretch; height: 40px; }
.stepper .step-btn {
  flex: none; width: 38px; padding: 0;
  background: #eef1f6; color: var(--text);
  border: 1px solid var(--border);
  font-size: 20px; font-weight: 600; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.stepper .step-btn:hover { background: #e2e7f0; }
.stepper .step-btn:first-child { border-radius: 9px 0 0 9px; border-right: none; }
.stepper .step-btn:last-child { border-radius: 0 9px 9px 0; border-left: none; }
.stepper .o-score {
  flex: none; width: 44px; text-align: center;
  border-radius: 0; padding: 0;
  appearance: textfield; -moz-appearance: textfield;
}
.stepper .o-score::-webkit-outer-spin-button,
.stepper .o-score::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* 删除按钮：正方形，宽高一致 */
.opt-grid .o-del {
  width: 40px; height: 40px; min-width: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; border-radius: 9px;
}
.del-text { background: transparent; color: var(--danger); padding: 5px 10px; font-size: 13px; }
.del-text:hover { background: #fdeaea; }

/* 总分区间：常规宽度下先填分值区间，再填写分类文本。 */
.range-item {
  display: grid;
  grid-template-columns: 72px 14px 72px 1fr 40px;
  gap: 8px; align-items: center;
}
.range-item [data-rk="label"] { grid-column: 1 / -1; grid-row: 2; }
.range-item .tilde { text-align: center; color: var(--muted); }
.range-item [data-rdel] { grid-column: 5; }
.range-item .adv { grid-column: 1 / -1; }

/* 题目选项在窄容器中拆行，避免选项文本被压缩。 */
@container (max-width: 430px) {
  .field-main { flex-direction: column; align-items: stretch; }
  .field-actions { width: 100%; }

  .opt-grid {
    grid-template-columns: 1fr 40px;
  }
  .opt-grid > input { grid-column: 1 / -1; }
  .opt-grid .stepper { grid-column: 1; }
  .opt-grid .o-del { grid-column: 2; }

}

@container (max-width: 300px) {
  .field-actions { flex-wrap: wrap; }
  .range-item { grid-template-columns: 62px 12px 62px 1fr 40px; }
}

/* 回答详情 */
.detail-q { padding: 11px 0; border-bottom: 1px solid var(--border); }
.detail-q:last-child { border-bottom: none; }
.detail-q .q-title { margin-bottom: 6px; }
a.score-link { font-weight: 700; font-size: 15px; }
.info-pills { display: flex; flex-wrap: wrap; gap: 6px; }
