/* ── 客服浮窗 ──────────────────────────────── */
#chatFab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

#chatFab .contact-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
#chatFab.expanded .contact-btns {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

#chatFab .fab-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  transition: transform 0.2s, box-shadow 0.2s;
}
#chatFab .fab-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,0.22); }

#chatToggle {
  background: #fff;
  color: #fff;
  width: 60px;
  height: 60px;
  padding: 0;
  overflow: hidden;
}
#chatToggle .ai-avatar {
  width: 100%;
  height: 100%;
}
#chatToggle .close-icon { display: none; }
#chatFab.expanded #chatToggle .chat-icon { display: none; }
#chatFab.expanded #chatToggle .close-icon { display: flex; }

.whatsapp-btn { background: #25d366; color: #fff; }
.wechat-btn   { background: #07c160; color: #fff; }
.ai-btn       { background: #fff; color: #fff; padding: 0; overflow: hidden; }

/* ── AI 客服头像（公共基类）──────────────────── */
.ai-avatar {
  object-fit: cover;
  border-radius: 50%;
  background: #f0f2f5;
  flex-shrink: 0;
  display: block;
}
#chatFab .ai-btn .ai-avatar {
  width: 100%;
  height: 100%;
}

/* ── 聊天窗口 ─────────────────────────────── */
#chatWindow {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 9998;
  width: 380px;
  height: 540px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.34,1.56,0.64,1), opacity 0.22s;
}
#chatWindow.open {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

/* ── 聊天窗口头部 ────────────────────────── */
#chatHeader {
  background: linear-gradient(135deg, #e63946, #c1121f);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#chatHeader h3 { margin: 0; font-size: 15px; font-weight: 600; }
#chatHeader p  { margin: 2px 0 0; font-size: 12px; opacity: 0.85; }
#chatStatus {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  margin-left: auto;
}
#chatHeader .ai-avatar {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ── 消息气泡 + 头像 ────────────────────────── */
.typing-row {
  align-self: flex-start;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.typing-row .msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
}
.msg-bubble {
  max-width: calc(78% - 34px);
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-bubble.ai {
  align-self: flex-start;
  background: #fff;
  color: #222;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #f0f2f5;
  flex-shrink: 0;
}

#chatBody {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8f9fa;
}

.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user  { align-self: flex-end;  background: #e63946; color: #fff; border-bottom-right-radius: 4px; }
.msg.ai    { align-self: flex-start; background: #fff; color: #222; border: 1px solid #e5e7eb; border-bottom-left-radius: 4px; }
.msg.system {
  align-self: center;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  text-align: center;
  border: none;
  border-radius: 8px;
}
.msg .sender { font-size: 11px; opacity: 0.6; margin-bottom: 2px; display: block; }

.typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  font-size: 14px;
  color: #999;
}
.typing span {
  display: inline-block;
  width: 6px; height: 6px;
  background: #999;
  border-radius: 50%;
  margin-right: 4px;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

#chatFoot {
  border-top: 1px solid #eee;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: #fff;
}
#chatFoot textarea {
  flex: 1;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 16px; /* 16px：iOS Safari 输入框 <16px 会自动放大导致页面左右晃动 */
  line-height: 1.4;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
#chatFoot textarea:focus { border-color: #e63946; }
#chatFoot button.send  {
  background: #e63946;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}
#chatFoot button.send:hover { background: #c1121f; transform: scale(1.05); }
#chatFoot button.send:active { transform: scale(0.95); }

/* ── 手机端响应式 ──────────────────────────── */
@media (max-width: 480px) {
  #chatWindow {
    width: calc(100vw - 16px);
    height: calc(100vh - 120px);
    bottom: 88px;
    right: 8px;
    left: 8px;
    border-radius: 12px;
  }
  #chatFab { bottom: 16px; right: 16px; }
  #chatFab .fab-btn { width: 46px; height: 46px; font-size: 20px; }
  #chatToggle { width: 54px; height: 54px; font-size: 22px; }
}

/* ── 滚动条美化 ───────────────────────────── */
#chatBody::-webkit-scrollbar { width: 4px; }
#chatBody::-webkit-scrollbar-track { background: transparent; }
#chatBody::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
