/* ============================================================
   成长评估问卷 Agent · 移动端竖屏样式
   蓝色卡片主题，迁移自组件原型 index.html
   ============================================================ */

/* HTML hidden 属性优先：flex/inline 型元素设了 display 后会盖过 UA 的
   [hidden]{display:none}，这里统一兜底，确保 hidden 的表单字段真正隐藏。 */
[hidden] { display: none !important; }

:root {
  --bg: #eef4fb;
  --card: #ffffff;
  --ink: #1f3247;
  --ink-soft: #5b7188;
  --blue: #4a90d9;
  --blue-deep: #2f6fb3;
  --blue-tint: #e7f0fb;
  --line: #dbe6f3;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 22px rgba(47, 111, 179, .12);
  --ok: #2fae6b;
  --warn: #e0a33b;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #d7e6f5;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 手机框：即使电脑打开也保持竖屏比例 ---------- */
.phone {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 932px;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 600px) {
  .phone {
    height: 92vh;
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(20, 60, 110, .28);
    border: 1px solid #cddcec;
  }
}

/* ---------- 屏幕切换 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  animation: fade .28s ease;
}
.screen.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #fff, #f5f9fe);
  border-bottom: 1px solid var(--line);
}
.brand-dot {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  padding: 2px;
  font-size: 11px; line-height: 1;
  letter-spacing: 0.5px;
  text-align: center;
  white-space: nowrap;
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-txt .t1 { font-weight: 600; font-size: 15px; }
.brand-txt .t2 { font-size: 11.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress {
  margin-left: auto;
  font-size: 12px; font-weight: 600;
  color: var(--blue-deep);
  background: var(--blue-tint);
  padding: 4px 10px; border-radius: 999px;
  flex: 0 0 auto;
}

/* ---------- 居中滚动容器（用于身份/麦克风/完成屏） ---------- */
.center-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 20px 16px;
}
/* 用 margin:auto 做垂直居中：内容矮时居中，内容高于容器时上下 margin 归零，
   可正常向上滚到顶部——避免 align-items:center 把超高内容顶部裁掉的经典 bug。 */
.center-scroll > .card { margin: auto; }

/* ---------- 卡片 ---------- */
.card {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
}
.lead {
  display: inline-block;
  font-size: 12px; font-weight: 600;
  color: var(--blue-deep);
  background: var(--blue-tint);
  padding: 3px 10px; border-radius: 999px;
  margin-bottom: 12px;
}
.card h1 { font-size: 21px; margin: 0 0 8px; }
.sub { font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; margin: 0 0 16px; }

/* ---------- 身份行 ---------- */
.id-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.id-row {
  display: flex; align-items: center; gap: 10px;
  background: #f6f9fd;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.id-row .k { font-size: 12.5px; color: var(--ink-soft); flex: 0 0 64px; }
.id-row .v { font-size: 16px; font-weight: 600; }
.id-row .badge {
  margin-left: auto;
  font-size: 11.5px; color: var(--blue-deep);
  background: var(--blue-tint);
  padding: 3px 9px; border-radius: 999px;
}
.hint-line { font-size: 12px; color: var(--ink-soft); text-align: center; margin: 12px 0 0; }

/* ---------- 入口表单 ---------- */
.form { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.f-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.f-sublabel { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.f-input {
  width: 100%;
  font-size: 15.5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f6f9fd;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.f-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
  background: #fff;
}
.f-input::placeholder { color: #a9b4c2; }

/* 候选 / 选项 label 胶囊 */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list:empty { display: none; }
.chip-list.static { margin-top: 2px; }
.label-chip {
  font-size: 14px;
  font-weight: 600;
  color: var(--blue-deep);
  background: var(--blue-tint);
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s, color .15s;
}
.label-chip:active { transform: translateY(1px); }
.label-chip.sel {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
}
.label-chip.readonly {
  cursor: default; color: var(--ink); background: #f6f9fd;
  border-color: var(--line);
}
.label-chip.readonly:active { transform: none; }

/* 已选中的学生 label */
.picked { display: flex; align-items: center; gap: 10px; }
.picked-chip {
  font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  padding: 9px 16px; border-radius: 999px;
}
.picked-x {
  font-size: 13px; color: var(--ink-soft);
  background: none; border: none; cursor: pointer;
  text-decoration: underline; padding: 4px;
}
.sub-wrap { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.form-err {
  font-size: 13px; color: #c0392b;
  background: #fdecea; border: 1px solid #f5b7b1;
  border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 12px;
}

/* ---------- 按钮 ---------- */
.btn-row { display: flex; flex-direction: column; gap: 10px; }
.btn {
  border: none;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  font-size: 15.5px; font-weight: 600;
  padding: 14px; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform .08s, opacity .2s, box-shadow .2s;
  box-shadow: 0 4px 14px rgba(74, 144, 217, .32);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
/* 置灰但仍可点：用于「叙述式锚定评分」未填满时，点击弹窗提示缺项 */
.btn.dim:not(:disabled) { opacity: .45; box-shadow: none; }
.btn.ghost {
  background: transparent;
  color: var(--blue-deep);
  box-shadow: none;
  border: 1px solid var(--line);
}

/* ---------- 麦克风检测 ---------- */
.mic-wrap { text-align: center; }
.mic-orb {
  width: 96px; height: 96px; margin: 8px auto 16px;
  border-radius: 50%;
  background: var(--blue-tint);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  transition: transform .12s, box-shadow .12s;
}
.mic-orb.live { box-shadow: 0 0 0 8px rgba(74,144,217,.12); }
.meter {
  height: 10px; border-radius: 999px;
  background: #eaf1f9; overflow: hidden;
  margin: 0 auto 12px; width: 80%;
}
.meter i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--ok));
  transition: width .08s linear;
}
.mic-status { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.mic-status.ok { color: var(--ok); }
.mic-status.err { color: #d1495b; }
.mic-hint { font-size: 12px; color: var(--ink-soft); min-height: 16px; margin-bottom: 16px; }

/* ============================================================
   聊天评估屏
   ============================================================ */
.chat-log {
  flex: 1 1 auto;
  min-height: 0;                    /* 允许内部滚动，避免被底部作答坞挤出视野 */
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; max-width: 100%; animation: pop .26s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.agent { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.agent .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(47,111,179,.06);
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  border-bottom-right-radius: 5px;
}
/* 重答上一题：常驻在最新一条作答气泡下方、右对齐的回退按钮 */
.redo-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -8px;                /* 贴近上方作答气泡 */
  animation: pop .2s ease;
}
.redo-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--blue-deep);
  font-size: 12.5px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(47,111,179,.12);
}
.redo-btn svg { width: 15px; height: 15px; }
.redo-btn:hover { border-color: var(--blue); }
.redo-btn:active { transform: scale(.96); }
.bubble .tag {
  display: block;
  width: fit-content;
  font-size: 10.5px; font-weight: 600; line-height: 1.4;
  color: var(--blue-deep);
  background: var(--blue-tint);
  padding: 2px 8px; border-radius: 999px;
  margin: 0 0 7px;
}
/* 打字指示 */
.typing { display: flex; gap: 4px; align-items: center; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--blue);
  opacity: .5;
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .3; transform: translateY(0);} 30% { opacity: 1; transform: translateY(-3px);} }

/* ---------- 底部作答坞 ---------- */
.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #f7fafe, #fff);
  border-top: 1px solid var(--line);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  max-height: 50vh;                 /* 至多占半屏，避免挤压对话框 */
}
/* 发送后锁定：屏蔽一切交互并置灰，等待追问/下一题时不可再点 */
.dock.locked .dock-body,
.dock.locked .send-left { pointer-events: none; opacity: .55; }
.dock-head {
  flex: 0 0 auto;
  font-size: 12.5px; color: var(--ink-soft);
  margin-bottom: 10px;
  display: none;
  align-items: center; gap: 10px;
}
.dock-head.show { display: flex; }
.dock-head .dh-text { flex: 1 1 auto; min-width: 0; }
.dock-head .voice-note { flex: 0 0 auto; margin: 0; }
.dock-body {
  flex: 1 1 auto;
  overflow-y: auto;                 /* 组件过高时内部滚动 */
  display: flex; flex-direction: column; gap: 10px;
  padding-right: 2px;
}
/* 发送行：无法判断在左，发送按钮在右下角 */
.send-row {
  flex: 0 0 auto;
  margin-top: 12px;
  display: flex; align-items: center; gap: 10px;
}
.send-left { flex: 1 1 auto; min-width: 0; display: flex; }
.send-left .unknown-row { margin-top: 0; }
#btn-send {
  flex: 0 0 auto;
  min-width: 96px;
  padding: 12px 22px;
}
.send-row .unknown-row { margin: 0; }
.send-row .btn-send { flex: 0 0 auto; padding: 13px 28px; }

/* ---------- 选项（单选/多选/排序） ---------- */
.opt-list { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.opt:active { background: #f4f9ff; }
.opt.selected { border-color: var(--blue); background: var(--blue-tint); }
.opt-mark {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border: 1.5px solid #c2d3e6;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.opt-mark.radio { border-radius: 50%; }
.opt-mark.check { border-radius: 6px; }
.opt.selected .opt-mark { background: var(--blue); border-color: var(--blue); }
.opt-rank {
  flex: 0 0 auto;
  width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid #c2d3e6;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--blue-deep);
}
.opt.selected .opt-rank { background: var(--blue); color: #fff; border-color: var(--blue); }
.opt-text { font-size: 14.5px; flex: 1 1 auto; }
.opt.exclusive.selected { border-color: var(--warn); background: #fdf6e9; }
.opt.exclusive.selected .opt-mark { background: var(--warn); border-color: var(--warn); }

/* “其他”补充框 */
.other-box {
  margin-top: 2px;
  display: none;
}
.other-box.show { display: block; }

/* ---------- 量表 / 锚定评分 档位 ---------- */
.scale-list { display: flex; flex-direction: column; gap: 8px; }
/* 叙述式锚定评分：最后一档与补充输入框之间留出间距 */
.scale-list + .input-block { margin-top: 14px; }
.scale-opt {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.scale-opt:active { background: #f4f9ff; }
.scale-opt.selected { border-color: var(--blue); background: var(--blue-tint); }
.scale-val {
  flex: 0 0 auto;
  min-width: 26px; height: 26px; padding: 0 6px;
  border-radius: 8px;
  background: #eef4fb; color: var(--blue-deep);
  font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.scale-opt.selected .scale-val { background: var(--blue); color: #fff; }
.scale-label { font-size: 13.5px; line-height: 1.5; }

/* ---------- 叙述式锚定评分：先选档，再补叙述 ---------- */
.narr-hint { font-size: 12px; color: var(--ink-soft); margin: 4px 0 0; }

/* ---------- 语音 + 文字输入块（open / rating_open 叙述） ---------- */
.input-block { display: flex; flex-direction: column; gap: 6px; }
/* 文本框 + 右侧语音图标 */
.ta-wrap { position: relative; }
.ta {
  width: 100%;
  min-height: 74px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 48px 11px 13px;     /* 右侧留出语音图标位置 */
  font-size: 14.5px; line-height: 1.6;
  font-family: inherit; color: var(--ink);
  resize: vertical;
  background: #fff;
}
.ta:focus { outline: none; border-color: var(--blue); }
/* 无语音（移动端/不支持）时文本框收回右侧留白，铺满可用宽度 */
.ta-wrap.no-mic .ta { padding-right: 13px; }
/* 图标式语音按钮，贴在文本框右侧 */
.mic-btn {
  position: absolute;
  right: 8px; bottom: 8px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--line);
  background: #fff; color: var(--blue-deep);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: border-color .15s, color .15s, background .15s;
}
.mic-btn svg { width: 18px; height: 18px; display: block; }
.mic-btn.recording {
  border-color: #d1495b; color: #fff; background: #d1495b;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(209,73,91,.4); } 50% { box-shadow: 0 0 0 6px rgba(209,73,91,0); } }
.voice-note { font-size: 11.5px; color: var(--ink-soft); }

/* ---------- 矩阵量表（紧凑网格 + 滑条） ---------- */
.matrix-legend {
  font-size: 12px; color: var(--ink-soft);
  background: var(--blue-tint);
  border-radius: 10px; padding: 9px 13px; margin-bottom: 4px;
  line-height: 1.7;
}
.matrix-legend b { color: var(--blue-deep); font-weight: 700; }

/* 2D 表头 */
.mhead {
  display: grid; grid-template-columns: 132px 1fr 1fr 66px;
  gap: 12px; align-items: end;
  font-size: 11.5px; color: var(--ink-soft); font-weight: 600;
  padding: 2px 0 4px;
}
.mhead .sp { text-align: left; }
.mhead > div { text-align: center; }

/* 数据行 */
.mrow {
  display: grid; grid-template-columns: 158px 1fr 30px 66px;
  gap: 12px; align-items: center;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.mrow.two { grid-template-columns: 132px 1fr 1fr 66px; }
.mrow:first-of-type { border-top: none; }
.mrow.unknown { opacity: .55; }

.mlabel { font-size: 13px; font-weight: 600; line-height: 1.4; }
.mlabel small { display: block; font-size: 11px; color: var(--ink-soft); font-weight: 400; margin-top: 2px; }

/* 双列的单元格：滑块在上、数值在下 */
.mcell { display: flex; align-items: center; gap: 9px; }
.mcell.two-col { flex-direction: column; gap: 4px; }

.mval {
  min-width: 20px; text-align: center;
  font-weight: 700; color: var(--blue-deep); font-size: 14px;
}
.mcell.two-col .mval { font-size: 13px; }

/* 滑块（带填充渐变） */
input[type=range].slider {
  -webkit-appearance: none; appearance: none;
  width: 100%;
  height: 6px; border-radius: 999px; outline: none; cursor: pointer;
  background: linear-gradient(90deg,
    var(--blue) 0%, var(--blue) var(--fill, 50%),
    var(--line) var(--fill, 50%), var(--line) 100%);
}
input[type=range].slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--blue); cursor: pointer;
  box-shadow: 0 2px 6px rgba(74,144,217,.4);
}
input[type=range].slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--blue); cursor: pointer;
}
input[type=range].slider.untouched::-webkit-slider-thumb { border-color: #b9c8da; }
input[type=range].slider.untouched::-moz-range-thumb { border-color: #b9c8da; }

/* 行内「无法判断」小胶囊 */
.mrow-unknown {
  justify-self: end;
  font-size: 11px; color: var(--ink-soft);
  padding: 5px 8px; border-radius: 8px;
  border: 1.5px dashed var(--line);
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s;
}
.mrow-unknown.on { border-style: solid; border-color: var(--warn); color: var(--warn); background: #fdf6e9; }
.mrow.unknown input[type=range].slider { opacity: .3; pointer-events: none; }

/* ---------- “无法判断” 行内开关 ---------- */
.unknown-row { margin-top: 4px; }
.unknown-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid var(--line);
  background: #fff; color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 999px;
  cursor: pointer;
}
.unknown-btn .bx {
  width: 16px; height: 16px; border-radius: 5px;
  border: 1.5px solid #c2d3e6;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 10px;
}
.unknown-btn.active { border-color: var(--warn); color: var(--warn); background: #fdf6e9; }
.unknown-btn.active .bx { background: var(--warn); border-color: var(--warn); }
.mx-row .unknown-btn { margin-top: 8px; font-size: 11.5px; padding: 5px 10px; }

/* 组件被“无法判断”整体禁用时的遮罩感 */
.dimmed { opacity: .4; pointer-events: none; }

/* ---------- 完成屏 ---------- */
.done-wrap { text-align: center; padding: 34px 20px; }
.done-orb {
  width: 78px; height: 78px; margin: 0 auto 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ok), #1f8f56);
  color: #fff; font-size: 40px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(47,174,107,.35);
}

/* ---------- 遮罩：加载 / 错误 ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(238,244,251,.96);
  display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  padding: 30px; text-align: center;
}
.overlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--blue-tint);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.spinner.hide { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.msg-txt { font-size: 14px; color: var(--ink-soft); line-height: 1.6; max-width: 300px; }
