/* 鹰小保 H5 手机版 —— 复刻微信小程序对话页观感（社保蓝 + 朝阳金）
   单位：小程序 rpx 按 750rpx 设计稿换算为 px（÷2，1rpx≈0.5px）
   适老化：正文 ≥16px、触控热区 ≥44px、灰字 #5E6A78 / 占位 #7A8494 对比度 ≥4.5:1 */

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  background: #F2F5FA;
  color: #1F2329;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* 移动端动态视口，避开地址栏伸缩导致的跳动 */
  background: #F2F5FA;
}

/* ---------- 顶部导航（社保蓝渐变） ---------- */
.nav {
  flex-shrink: 0;
  background: linear-gradient(135deg, #1B4FD6 0%, #2A62E8 100%);
  color: #fff;
  box-shadow: 0 3px 12px rgba(27, 79, 214, 0.18);
  padding-top: env(safe-area-inset-top);
}

.nav-inner {
  height: 52px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 导航按钮：白圆热区（对齐小程序 clear-btn 观感），内层图标社保蓝 */
.nav-clear, .nav-tts {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(15, 59, 168, 0.25);
  transition: background 0.15s, transform 0.1s;
}
.nav-clear:active, .nav-tts:active { background: #E9EFFB; transform: scale(0.94); }

/* 语音开关：开=社保蓝实心喇叭，关=浅底静音；朗读中脉冲高亮 */
.nav-tts { color: #1B4FD6; }
.nav-tts .tts-on { display: none; }
.nav-tts .tts-off { display: block; color: #8A94A6; }
.nav-tts.on { background: #fff; color: #1B4FD6; }
.nav-tts.on .tts-on { display: block; }
.nav-tts.on .tts-off { display: none; }
.nav-tts.speaking { animation: ttsPulse 1.1s ease-in-out infinite; }
@keyframes ttsPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5); }
  50% { box-shadow: 0 0 0 5px rgba(255, 255, 255, 0); }
}

/* 服务状态灯：手机版只保留小圆点，文字隐藏（DOM 仍需存在供 app.js 驱动） */
.status { display: inline-flex; align-items: center; }
.status-text { display: none; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  transition: background 0.6s, box-shadow 0.6s;
}
.status.ok .status-dot {
  background: #4ADE80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: breathe 2.4s ease-in-out infinite;
}
.status.bad .status-dot {
  background: #F87171;
  box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.7);
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5); }
  50% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0); }
}

/* ---------- 后端不可达提示条 ---------- */
.banner {
  flex-shrink: 0;
  background: #FDECEC;
  color: #B03A3A;
  font-size: 13px;
  text-align: center;
  padding: 8px 14px;
  animation: fadeIn 0.4s ease both;
}

/* ---------- 消息区 ---------- */
.list {
  flex: 1;
  height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #EBF2FB 0%, #F2F5FA 160px);
  padding: 14px 14px 0;
  scrollbar-width: none;
}
.list::-webkit-scrollbar { width: 0; height: 0; display: none; }
.list-bottom { height: 16px; }

/* ---------- 欢迎屏 ---------- */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 28px;
  animation: rise 0.5s ease both;
}
.welcome.fade-out { animation: fadeOut 0.3s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.welcome-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #EADFC2;
  box-shadow: 0 8px 20px rgba(27, 79, 214, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.welcome-avatar { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; }

.welcome-title {
  margin-top: 16px;
  font-size: 20px;
  font-weight: 600;
  color: #1F2329;
  letter-spacing: 0.5px;
}
.welcome-sub {
  margin-top: 6px;
  font-size: 13px;
  color: #5E6A78;
  letter-spacing: 0.5px;
}

.quick-header { margin-top: 32px; display: flex; align-items: center; }
.quick-line {
  width: 24px;
  height: 1px;
  background: linear-gradient(90deg, rgba(204, 163, 81, 0), #CCA351);
}
.quick-header .quick-line:last-child {
  background: linear-gradient(90deg, #CCA351, rgba(204, 163, 81, 0));
}
.quick-label {
  margin: 0 10px;
  font-size: 14px;
  color: #8A6A28; /* 朝阳金加深，对比度达标 */
  letter-spacing: 1px;
}

.quick-list { width: 100%; margin-top: 14px; }
.quick-item {
  width: 100%;
  background: #fff;
  border: none;
  border-radius: 10px;
  margin-bottom: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(31, 35, 41, 0.05);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  animation: rise 0.5s ease both;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.quick-item:nth-child(1) { animation-delay: 0.1s; }
.quick-item:nth-child(2) { animation-delay: 0.2s; }
.quick-item:nth-child(3) { animation-delay: 0.3s; }
.quick-item:active { background: #F3F7FE; transform: scale(0.99); }

.quick-bar {
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background: linear-gradient(180deg, #E3C878, #CCA351);
  margin-right: 11px;
  flex-shrink: 0;
}
.quick-text { font-size: 16px; color: #1F2329; line-height: 1.5; }

/* 电脑/大屏版入口：欢迎屏底部次级链接 */
.to-pc {
  margin-top: 22px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  background: #fff;
  color: #5E6A78;
  font-size: 13px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(31, 35, 41, 0.05);
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.to-pc:active { background: #F3F7FE; transform: scale(0.97); }

/* ---------- 对话气泡（纵向：头像在上、气泡在下） ---------- */
.row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 16px;
  animation: rise 0.3s ease both;
}
.row.user { align-items: flex-end; }

.msg-head { display: flex; align-items: center; margin-bottom: 5px; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 1px solid #EADFC2;
  flex-shrink: 0;
}
.msg-name { margin-left: 6px; font-size: 12px; color: #5E6A78; font-weight: 500; }

.bubble {
  max-width: 100%;
  padding: 11px 14px;
  font-size: 16px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 2px 7px rgba(31, 35, 41, 0.05);
}
.bubble.user {
  background: linear-gradient(135deg, #1B4FD6, #2A62E8);
  color: #fff;
  border-radius: 12px 4px 12px 12px;
  max-width: 88%;
}
.bubble.assistant {
  background: #fff;
  color: #1F2329;
  border-radius: 4px 12px 12px 12px;
}

/* 等待首包：三点跳动 */
.typing { padding: 13px 15px; }
.dots { display: flex; align-items: center; }
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #A9BEEF;
  margin-right: 6px;
  animation: blink 1.2s infinite both;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; margin-right: 0; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Markdown 渲染（.md 容器，对应 markdown.js 输出的 class） ---------- */
.bubble .md { font-size: 16px; line-height: 1.7; word-break: break-word; }
.md p.md-p { margin: 0 0 8px; }
.md p.md-lead { margin-bottom: 4px; }
.md .md-h {
  margin: 10px 0 6px;
  font-weight: 600;
  color: #1B4FD6;
  font-size: 17px;
  line-height: 1.4;
}
.md h3.md-h, .md h4.md-h { font-size: 16px; }
.md .md-h-first { margin-top: 0; }
.md .md-strong { font-weight: 600; color: #0F3BA8; }
.md .md-ul, .md .md-ol { margin: 0 0 8px; padding-left: 20px; }
.md .md-ul li, .md .md-ol li { margin: 4px 0; }
.md .md-label { color: #5E6A78; font-weight: 600; }
.md .md-hr { border: none; border-top: 1px solid #E3E9F2; margin: 10px 0; }
.md .md-code {
  background: #F1F4F9;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 14px;
  font-family: Consolas, "Courier New", monospace;
}
.md .md-link { color: #1B4FD6; text-decoration: underline; }
.md .md-quote {
  margin: 0 0 8px;
  padding: 5px 10px;
  border-left: 3px solid #CCA351;
  background: #FBF7EE;
  color: #5E6A78;
  border-radius: 0 5px 5px 0;
}

/* 真表格：手机端窄屏，横向滚动而非压缩变形 */
.md .md-table-wrap {
  margin: 8px 0 10px;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #E3E9F2;
  -webkit-overflow-scrolling: touch;
}
.md .md-table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
.md .md-table th {
  background: #F0F5FF;
  color: #1B4FD6;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid #E3E9F2;
  white-space: nowrap;
}
.md .md-table td {
  padding: 7px 12px;
  border-bottom: 1px solid #F0F3F8;
  color: #1F2329;
  vertical-align: top;
}
.md .md-table tr:last-child td { border-bottom: none; }
.md .md-table tr:nth-child(even) td { background: #FAFCFF; }
.md .md-table-wrap { scrollbar-width: thin; }
.md .md-table-wrap::-webkit-scrollbar { height: 6px; width: 6px; display: block; }
.md .md-table-wrap::-webkit-scrollbar-thumb { background: #C6D2EC; border-radius: 3px; }
.md .md-table-wrap::-webkit-scrollbar-track { background: transparent; }

/* ---------- 输入区 ---------- */
.bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 9px 12px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -3px 12px rgba(31, 35, 41, 0.04);
}
.input {
  flex: 1;
  background: #F1F4F9;
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  color: #1F2329;
  resize: none;
  outline: none;
  max-height: 120px;
  transition: border-color 0.3s, background 0.3s;
}
.input::placeholder { color: #7A8494; }
.input:focus { border-color: #2A62E8; background: #fff; }

.send {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: none;
  border-radius: 50%;
  background: #C6D2EC;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.25s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.send.on { background: linear-gradient(135deg, #1B4FD6, #2A62E8); }
.send.stop { background: #5E6A78; }
.send:active { transform: scale(0.92); }
.send .send-stop-icon { display: none; }
.send.stop .send-arrow { display: none; }
.send.stop .send-stop-icon {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #fff;
}

/* ---------- 清空确认弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 60, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.25s ease both;
}
.modal-mask.closing { animation: fadeOut 0.25s ease both; }
.modal {
  width: 300px;
  max-width: calc(100vw - 48px);
  background: #fff;
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: 0 18px 50px rgba(15, 30, 60, 0.25);
  animation: popIn 0.3s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.9) translateY(14px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-title { font-size: 18px; font-weight: 600; color: #1F2329; }
.modal-text { margin-top: 10px; font-size: 15px; color: #5E6A78; line-height: 1.6; }
.modal-btns { margin-top: 20px; display: flex; justify-content: flex-end; gap: 12px; }
.modal-btn {
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background 0.25s, transform 0.15s;
}
.modal-btn:active { transform: scale(0.96); }
.modal-btn.ghost { background: #F1F4F9; color: #5E6A78; }
.modal-btn.primary { background: linear-gradient(135deg, #1B4FD6, #2A62E8); color: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(31, 35, 41, 0.88);
  color: #fff;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 12px;
  max-width: 78vw;
  z-index: 200;
  animation: fadeIn 0.3s ease both;
  transition: opacity 0.4s;
}
.toast.closing { opacity: 0; }
