/* ===== AI 客服悬浮聊天窗 ===== */
.chat-trigger {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s, box-shadow 0.3s;
  font-size: 24px;
}
.chat-trigger:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}
.chat-trigger .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.chat-window {
  position: fixed;
  bottom: 90px;
  left: 24px;
  z-index: 9998;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}
.chat-window.open { display: flex; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-header {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chat-header .info { flex: 1; }
.chat-header .info h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.chat-header .info p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.8;
}
.chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  opacity: 0.7;
  padding: 4px;
}
.chat-close:hover { opacity: 1; }

.chat-phone {
  background: #dc2626;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 20px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.2s;
}
.chat-phone:hover { background: #b91c1c; }

.chat-body,
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}
.message.assistant strong { color: #2563eb; }
.message .typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.message .typing-dots span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: dotBounce 1.4s infinite;
}
.message .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.message .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.6); }
  40% { transform: scale(1); }
}
.message .time {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 4px;
  text-align: right;
}
.message.user .time { color: rgba(255,255,255,0.7); }

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}
.chat-input-area input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input-area input:focus { border-color: #2563eb; }
.chat-input-area button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.chat-input-area button:hover { background: #1d4ed8; }
.chat-input-area button:disabled { background: #94a3b8; cursor: not-allowed; }

/* 快捷问题 */
.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 4px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-quick button {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #2563eb;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.chat-quick button:hover { background: #dbeafe; border-color: #93c5fd; }

/* 消息中的 Markdown 样式 */
.message.assistant strong { color: #2563eb; }
.message.assistant p { margin: 4px 0; }

@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .chat-trigger { bottom: 16px; left: 16px; }
}