:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1a1d24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-d: #4338ca;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.55; font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit; font-size: 14px; width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.stack > * + * { margin-top: 14px; }

/* 按钮 */
.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 14px; font-weight: 500; color: var(--ink); }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--danger); border-color: #fca5a5; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 布局 */
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 22px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 17px; color: var(--brand); }
.container { max-width: 960px; margin: 0 auto; padding: 26px 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 14px; }

/* 徽标/状态 */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge.draft { background: #f3f4f6; color: #6b7280; }
.badge.published { background: #dcfce7; color: #15803d; }
.badge.closed { background: #fee2e2; color: #b91c1c; }

/* 认证页 */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }

/* 问卷列表 */
.survey-item { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.survey-item h3 { margin: 0 0 4px; font-size: 16px; }

/* 编辑器 */
.q-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 16px; }
.q-card .q-head { display: flex; gap: 10px; align-items: center; }
.q-type-pill { font-size: 12px; background: #eef2ff; color: var(--brand); padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.opt-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.opt-row input { flex: 1; }
.add-q-bar { display: flex; flex-wrap: wrap; gap: 8px; }

/* 统计 */
.stat-q { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 16px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 70px; gap: 10px; align-items: center; margin: 7px 0; font-size: 13px; }
.bar-track { background: #f3f4f6; border-radius: 6px; height: 22px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 6px; min-width: 2px; transition: width .3s; }
.kpi { font-size: 28px; font-weight: 700; }
.tag { display: inline-block; background: #f3f4f6; border-radius: 6px; padding: 3px 8px; margin: 3px; font-size: 13px; }
.text-list { max-height: 260px; overflow: auto; }
.text-list .item { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }

/* 公开填写页 */
.fill-wrap { max-width: 680px; margin: 0 auto; padding: 30px 20px 80px; }
.fill-q { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.fill-q .q-title { font-weight: 600; margin-bottom: 10px; }
.fill-q .req { color: var(--danger); }
.choice { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; margin-top: 7px; cursor: pointer; }
.choice:hover { border-color: var(--brand); }
.choice input { width: auto; }
.scale-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.scale-opts .sc { flex: 1; min-width: 40px; text-align: center; padding: 10px 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.scale-opts .sc.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.progress { height: 6px; background: #eef2ff; border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress > div { height: 100%; background: var(--brand); transition: width .3s; }

/* toast */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; }
.matrix-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix-table th, .matrix-table td { border: 1px solid var(--line); padding: 7px; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 语言切换器 */
.lang-switch { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-btn { border: none; background: #fff; padding: 5px 11px; font-size: 13px; color: var(--muted); cursor: pointer; border-left: 1px solid var(--line); }
.lang-btn:first-child { border-left: none; }
.lang-btn.on { background: var(--brand); color: #fff; }
.fill-wrap .lang-switch { margin-bottom: 16px; }

/* AI 调研：向导模板卡片 */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tpl-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; background: #fff; transition: border-color .15s, background .15s; }
.tpl-card:hover { border-color: var(--brand); }
.tpl-card.on { border-color: var(--brand); background: #eef2ff; }
.tpl-card .tpl-name { font-weight: 600; margin-bottom: 3px; }

/* 提示块 / 低样本预警 */
.callout { background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px; padding: 10px 12px; font-size: 14px; color: var(--ink); }
.callout.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* AI 结论 */
.concl-summary { white-space: pre-wrap; background: #fafafe; border: 1px solid var(--line); border-radius: 8px; padding: 14px; font-size: 15px; line-height: 1.7; }
.rec-item { border-left: 3px solid var(--brand); background: #fafafe; border-radius: 0 8px 8px 0; padding: 10px 12px; }
.rec-item .rec-hyp { font-weight: 600; margin-bottom: 4px; }

/* 对话式需求收集：消息流 + 气泡 + 输入行 + 确认卡片 */
.chat-wrap { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.bubble { max-width: 82%; }
.bubble.bot { align-self: flex-start; }
.bubble.user { align-self: flex-end; text-align: right; }
.bubble-who { margin-bottom: 3px; }
.bubble-text { display: inline-block; padding: 9px 13px; border-radius: 14px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; text-align: left; }
.bubble.bot .bubble-text { background: #f3f4f6; color: var(--ink); border-bottom-left-radius: 4px; }
.bubble.user .bubble-text { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.bubble.thinking .bubble-text { background: transparent; padding: 4px 0; }
.slot-progress { white-space: nowrap; }

.input-row { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; position: sticky; bottom: 0; background: var(--bg); padding: 8px 0; }
.input-row .chat-input { flex: 1; resize: none; min-height: 44px; max-height: 140px; }
.input-row .btn { min-height: 44px; white-space: nowrap; }

.confirm-card { margin-top: 12px; }
.confirm-dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.confirm-dl dt { font-size: 13px; color: var(--muted); align-self: center; }
.confirm-dl dd { margin: 0; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.confirm-dl .slot-val { flex: 1; word-break: break-word; }

@media (max-width: 560px) {
  .chat-wrap { max-height: 56vh; }
  .bubble { max-width: 92%; }
  .confirm-dl { grid-template-columns: 1fr; gap: 2px 0; }
  .confirm-dl dt { margin-top: 8px; }
}

@media print {
  .topbar, .btn, label, textarea, .lang-switch { display: none !important; }
  .card { box-shadow: none; border: none; }
  body { background: #fff; }
}
