/* ========== 基础：手机优先 ========== */
:root {
  --pink-light: #ffe3ef;
  --pink-mid: #ffc9df;
  --pink-deep: #f49ac2;
  --ink: #2f2f33;
  --sub: #8c8c94;
  --line: #ececf0;
  --bg: #f6f6f9;
  --card: #ffffff;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 18px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.05);
}
.card.center { text-align: center; }

.card-title {
  font-size: 19px;
  margin: 0 0 14px;
  text-align: center;
}

.para { margin: 10px 0; color: #444; }
.para.tip { color: var(--sub); font-size: 14px; background: #faf7fa; padding: 10px 12px; border-radius: 10px; }

/* ========== 按钮：柔和粉色渐变 ========== */
.btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  color: #7a3b57;
  background: linear-gradient(135deg, #ffe0ec 0%, #ffc4db 100%);
  box-shadow: 0 4px 12px rgba(244, 154, 194, 0.35);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; box-shadow: none; cursor: not-allowed; }

/* ========== 知情同意页 ========== */
.consent-card .para-wrap {
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 14px;
}
.agree-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #555;
  margin-top: 10px;
}
.agree-line input { width: 18px; height: 18px; accent-color: var(--pink-deep); }

/* ========== 问卷题 ========== */
.q-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.q-item:last-of-type { border-bottom: none; }
.q-text { font-weight: 600; margin-bottom: 10px; }
.q-text .q-idx { color: var(--pink-deep); margin-right: 4px; }
.q-optional { color: var(--sub); font-weight: 400; font-size: 13px; }

.opt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}
.opt-row.selected {
  border-color: var(--pink-deep);
  background: #fff4f9;
}
.opt-row .dot {
  width: 16px; height: 16px;
  border: 1.5px solid #ccc;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.opt-row[data-type="checkbox"] .dot { border-radius: 5px; }
.opt-row.selected .dot {
  border-color: var(--pink-deep);
  background: var(--pink-deep);
}
.opt-row.selected .dot::after {
  content: "";
  position: absolute;
  left: 4.5px; top: 1.5px;
  width: 4px; height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.q-textinput {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
.q-textinput:focus { outline: none; border-color: var(--pink-deep); }

/* 量表题 1-7 */
.scale-row { display: flex; gap: 6px; margin: 12px 0 4px; }
.scale-btn {
  flex: 1;
  max-width: 52px;
  aspect-ratio: 1.15;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  color: #666;
  cursor: pointer;
}
.scale-btn.selected {
  background: linear-gradient(135deg, #ffd3e4, #ffb6d2);
  border-color: transparent;
  color: #6d3350;
  font-weight: 700;
}
.scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--sub);
}
.scale-labels span:first-child { text-align: left; }
.scale-labels span:last-child { text-align: right; }

.form-error {
  color: #d9534f;
  font-size: 14px;
  margin-top: 10px;
  text-align: center;
}

/* ========== 聊天页 ========== */
.chat-app {
  max-width: 640px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh; /* 移动端动态视口：键盘弹出时随可视区收缩 */
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd0e2, #ffafcd);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(244, 154, 194, 0.4);
}
.ai-name { font-weight: 600; font-size: 16px; }
.ai-status { font-size: 12px; color: var(--sub); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(180deg, #fdfbfc 0%, #f7f5f8 100%);
}

.chat-hint {
  text-align: center;
  font-size: 13px;
  color: var(--sub);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: msgIn 0.25s ease-out;
}
.msg-row.user { justify-content: flex-end; }
.msg-row .avatar { width: 34px; height: 34px; font-size: 13px; }

.bubble {
  max-width: 76%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-row.ai .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: #333;
}
.msg-row.user .bubble {
  background: linear-gradient(135deg, #ffd3e4, #ffb6d2);
  border-bottom-right-radius: 5px;
  color: #6d3350;
  font-weight: 500;
}

/* “正在输入”指示器 */
.typing .bubble {
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
}
.typing .dot3 {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #c9c9d0;
  animation: blink 1.2s infinite;
}
.typing .dot3:nth-child(2) { animation-delay: 0.2s; }
.typing .dot3:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 输入栏 */
.input-bar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.input-bar textarea {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  line-height: 1.5;
}
.input-bar textarea:focus { outline: none; border-color: var(--pink-deep); }
.send-btn {
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  color: #7a3b57;
  background: linear-gradient(135deg, #ffd3e4, #ffb6d2);
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn[disabled] { opacity: 0.45; }

/* 对话结束卡片 */
.chat-end-card {
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}
.end-hint { text-align: center; color: var(--sub); font-size: 14px; margin: 0 0 6px; }

/* ========== 非拟人化版本：机械、中性、无头像 ========== */
body.machine .chat-app { background: #f5f5f6; }
body.machine .chat-header {
  border-bottom: 2px solid #444;
  background: #f0f0f1;
}
body.machine .avatar { display: none; }
body.machine .ai-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #333;
}
body.machine .ai-status { display: none; }
body.machine .chat-body {
  background: #f5f5f6;
  gap: 18px;
}
body.machine .chat-hint {
  background: #fff;
  border: 1px solid #d8d8dc;
  border-radius: 2px;
  font-family: "Courier New", monospace;
}
body.machine .msg-row .bubble {
  border-radius: 3px;
  max-width: 86%;
}
body.machine .msg-row.ai .bubble {
  background: #fff;
  border: 1px solid #c9c9ce;
  border-left: 3px solid #666;
  font-size: 14px;
}
body.machine .msg-row.ai::before {
  content: "系统输出";
  font-size: 11px;
  color: #888;
  font-family: "Courier New", monospace;
  position: absolute;
  transform: translateY(-16px);
}
body.machine .msg-row.ai { position: relative; padding-top: 14px; }
body.machine .msg-row.user .bubble {
  background: #e6e6e9;
  color: #333;
  font-weight: 400;
}
body.machine .input-bar { background: #f0f0f1; border-top: 2px solid #444; }
body.machine .input-bar textarea {
  border-radius: 2px;
  border: 1px solid #999;
  font-family: "Courier New", monospace;
}
body.machine .send-btn {
  border-radius: 2px;
  background: #555;
  color: #fff;
}
body.machine .chat-end-card { background: #f0f0f1; }

/* ========== 页面轻提示 ========== */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  max-width: 86%;
  background: rgba(47, 47, 51, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  text-align: center;
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== 登录页 ========== */
.login-card { margin-top: 18vh; text-align: center; }
.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd0e2, #ffafcd);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(244, 154, 194, 0.4);
}
.login-input {
  width: 100%;
  padding: 13px 16px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  text-align: center;
}
.login-input:focus { outline: none; border-color: var(--pink-deep); }
.login-card .form-error { margin-top: 10px; }

/* ========== 问卷分区标题 ========== */
.q-section {
  margin: 22px 0 2px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: #7a3b57;
  background: #fff4f9;
  border-radius: 10px;
}

/* ========== 聊天辅助工具条（跳过/超时提示） ========== */
.chat-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px 0;
  background: #fff;
  min-height: 34px;
}
.idle-hint button {
  border: 1px dashed var(--pink-deep);
  background: #fff4f9;
  color: #c05c8a;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  animation: idlePulse 1.6s infinite;
}
@keyframes idlePulse { 0%, 100% { opacity: 0.65; } 50% { opacity: 1; } }
.skip-btn {
  border: none;
  background: transparent;
  color: var(--sub);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  flex-shrink: 0;
  padding: 6px 4px;
}
.skip-btn[disabled] { opacity: 0.4; }
.typing-text::after {
  content: "▋";
  color: var(--pink-deep);
  animation: blink 0.9s infinite;
}
body.machine .chat-tools { background: #f0f0f1; }
body.machine .idle-hint button {
  border: 1px dashed #666;
  background: #fff;
  color: #444;
  border-radius: 2px;
  font-family: "Courier New", monospace;
  animation: none;
}
body.machine .skip-btn { color: #555; }

/* ========== 结束页 ========== */
.done-mark {
  width: 56px; height: 56px;
  margin: 6px auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd3e4, #ffb6d2);
  color: #fff;
  font-size: 28px;
  display: grid;
  place-items: center;
}
.pid { color: #d9739e; letter-spacing: 1px; }
