/* AI 智能客服悬浮组件 - v2.0 与整体设计语言统一 */

#chatWidget * { box-sizing: border-box; }

.chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0EA5E9;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(14, 165, 233, .3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  padding: 0;
  overflow: visible;
  transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-fab:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 28px rgba(14, 165, 233, .4);
}

.chat-fab:active {
  transform: translateY(0) scale(0.98);
}

.chat-fab-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.chat-fab-online {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00B42A;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.chat-fab-label {
  position: absolute;
  right: 72px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  color: #0EA5E9;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: all .2s ease;
  border: 1px solid #CFFAFE;
}

.chat-fab:hover .chat-fab-label {
  opacity: 1;
  transform: translateY(-50%) translateX(-4px);
}

.chat-fab .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #F53F3F;
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
  display: none;
  min-width: 20px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(245, 63, 63, .3);
}

.chat-fab .badge.show { display: block; }

.chat-window {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 380px;
  height: 580px;
  max-height: 82vh;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 56px rgba(15, 23, 42, .18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

.chat-window.open { display: flex; animation: chatFadeIn .25s cubic-bezier(0.4, 0, 0.2, 1); }

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
  background: linear-gradient(135deg, #0EA5E9 0%, #0369A1 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.chat-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

.chat-header .title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}

.chat-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, .5);
}

.chat-header-name {
  color: #fff;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chat-header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00B42A;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .3);
  display: inline-block;
  margin-right: 6px;
}

.chat-header .status-text {
  font-size: 11px;
  opacity: 0.85;
  font-weight: 400;
  display: block;
  margin-top: 1px;
}

.chat-header .close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: background .15s ease;
  opacity: 0.85;
}

.chat-header .close:hover { background: rgba(255, 255, 255, .2); opacity: 1; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: #F5F7FA;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #C9CED8;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #7A869A;
}

.chat-msg {
  display: flex;
  width: 100%;
  line-height: 1.6;
  font-size: 14px;
}

.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.chat-msg .chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  word-break: break-word;
  position: relative;
  line-height: 1.6;
  font-size: 14px;
}

.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(14, 165, 233, .2);
}

.chat-msg.assistant .chat-bubble {
  background: #fff;
  color: #232B3A;
  border: 1px solid #E4E7ED;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* 打字光标 */
.chat-cursor {
  display: inline-block;
  color: #0EA5E9;
  font-weight: bold;
  animation: blink 0.8s step-end infinite;
  margin-left: 1px;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Markdown 渲染样式 */
.chat-msg.assistant .chat-bubble p { margin: 0 0 8px; }
.chat-msg.assistant .chat-bubble p:last-child { margin-bottom: 0; }
.chat-msg.assistant .chat-bubble strong { color: #0284C7; font-weight: 600; }
.chat-msg.assistant .chat-bubble em { font-style: italic; }
.chat-msg.assistant .chat-bubble code {
  background: #F7F8FA;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, "Menlo", monospace;
  color: #BE185D;
  border: 1px solid #E4E7ED;
}
.chat-msg.assistant .chat-bubble ul,
.chat-msg.assistant .chat-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}
.chat-msg.assistant .chat-bubble li { margin: 2px 0; }
.chat-msg.assistant .chat-bubble h1,
.chat-msg.assistant .chat-bubble h2,
.chat-msg.assistant .chat-bubble h3 {
  margin: 10px 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: #141824;
  letter-spacing: -0.01em;
}

.chat-msg.assistant .sources {
  margin-top: 6px;
  font-size: 11px;
  color: #7A869A;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chat-msg.assistant .sources .tag {
  background: #CFFAFE;
  color: #0284C7;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

.chat-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #E4E7ED;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  font-size: 13px;
  color: #7A869A;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #C9CED8;
  animation: chatDot 1.4s infinite;
}

.chat-typing .dot:nth-child(2) { animation-delay: .2s; }
.chat-typing .dot:nth-child(3) { animation-delay: .4s; }

@keyframes chatDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input {
  border-top: 1px solid #EEF0F5;
  padding: 12px 14px;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  position: relative;
}

.chat-input textarea {
  flex: 1;
  border: 1.5px solid #E4E7ED;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  min-height: 42px;
  outline: none;
  background: #fff;
  color: #232B3A;
  transition: all .2s ease;
  line-height: 1.5;
}

.chat-input textarea:hover { border-color: #C9CED8; }
.chat-input textarea:focus { border-color: #0EA5E9; box-shadow: 0 0 0 3px #CFFAFE; }

.chat-input button {
  background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all .2s ease;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(14, 165, 233, 0.2);
}

.chat-input button:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(14, 165, 233, 0.3); }
.chat-input button:active { transform: translateY(0); }
.chat-input button:disabled {
  background: #C9CED8;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 表情按钮 */
.chat-input .emoji-btn {
  background: #fff;
  color: #7A869A;
  border: 1.5px solid #E4E7ED;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  height: 42px;
  width: 42px;
  cursor: pointer;
  transition: all .2s ease;
}

.chat-input .emoji-btn:hover {
  background: #F7F8FA;
  color: #0EA5E9;
  border-color: #0EA5E9;
}

/* 表情面板 */
.emoji-panel {
  display: none;
  position: absolute;
  bottom: 64px;
  left: 14px;
  right: 14px;
  max-height: 220px;
  background: #fff;
  border: 1px solid #E4E7ED;
  border-radius: 14px;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  z-index: 10;
  flex-direction: column;
}

.emoji-panel.open { display: flex; }

.emoji-cats {
  display: flex;
  gap: 4px;
  padding: 8px 8px 4px;
  border-bottom: 1px solid #EEF0F5;
  flex-wrap: wrap;
}

.emoji-cat {
  padding: 4px 10px;
  font-size: 12px;
  color: #7A869A;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
  font-weight: 500;
}

.emoji-cat:hover { background: #F7F8FA; }
.emoji-cat.active { background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%); color: #fff; }

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-item {
  font-size: 20px;
  text-align: center;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s ease;
  line-height: 1;
}

.emoji-item:hover { background: #CFFAFE; }

.chat-welcome {
  text-align: center;
  color: #7A869A;
  font-size: 13px;
  padding: 18px 16px;
  background: #fff;
  border-radius: 14px;
  margin-bottom: 8px;
  border: 1px solid #E4E7ED;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.chat-welcome b { color: #0EA5E9; font-weight: 600; }

/* 快捷问题 */
.chat-quick-questions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.chat-quick-btn {
  text-align: left;
  background: #fff;
  border: 1px solid #E4E7ED;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: #3D4858;
  cursor: pointer;
  transition: all .15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}

.chat-quick-btn:hover {
  background: #CFFAFE;
  border-color: #0EA5E9;
  color: #0EA5E9;
}

.chat-quick-btn svg { flex-shrink: 0; }

@media (max-width: 640px) {
  .chat-window {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
  .chat-fab { bottom: 20px; right: 20px; width: 56px; height: 56px; }
  .chat-fab-avatar { width: 50px; height: 50px; }
}

/* ===== 主动唤醒气泡 ===== */
.chat-proactive {
  position: fixed;
  bottom: 100px;
  right: 22px;
  max-width: 280px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 40px 14px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9997;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.chat-proactive.show { opacity: 1; transform: translateY(0); }
.chat-proactive .pb-arrow {
  position: absolute;
  bottom: -8px;
  right: 28px;
  width: 14px;
  height: 14px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 4px 4px 8px rgba(0,0,0,.06);
}
.chat-proactive .pb-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.chat-proactive .pb-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-proactive .pb-body { flex: 1; min-width: 0; }
.chat-proactive .pb-text {
  font-size: 13px;
  line-height: 1.55;
  color: #1F2937;
  margin-bottom: 10px;
}
.chat-proactive .pb-actions { display: flex; gap: 8px; }
.chat-proactive .pb-yes {
  background: linear-gradient(135deg, #0EA5E9, #0369A1);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.chat-proactive .pb-yes:hover { opacity: .9; }
.chat-proactive .pb-no {
  background: transparent;
  color: #6B7280;
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chat-proactive .pb-no:hover { color: #374151; }
.chat-proactive .pb-close {
  position: absolute;
  top: 6px; right: 10px;
  background: none;
  border: none;
  color: #C0C4CC;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px;
}
.chat-proactive .pb-close:hover { color: #6B7280; }
@media (max-width: 640px) {
  .chat-proactive { bottom: 90px; right: 14px; left: 14px; max-width: none; }
  .chat-proactive .pb-arrow { right: auto; left: 24px; }
}

/* ============ 快捷操作按钮 ============ */
.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px 44px;
  padding-bottom: 8px;
}
.quick-btn {
  padding: 7px 14px;
  background: #F0F9FF;
  border: 1px solid #BAE6FD;
  border-radius: 20px;
  color: #0369A1;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.quick-btn:hover {
  background: linear-gradient(135deg, #22D3EE 0%, #0EA5E9 100%);
  color: #fff;
  border-color: #0EA5E9;
  transform: translateY(-1px);
}

/* ============ 留资表单 ============ */
.chat-lead-form {
  margin: 8px 0 8px 12px;
  padding: 16px;
  background: linear-gradient(135deg, #F0F9FF 0%, #E0F2FE 100%);
  border: 1px solid #BAE6FD;
  border-radius: 12px;
  max-width: calc(100% - 20px);
}
.lead-title {
  font-size: 14px;
  font-weight: 600;
  color: #0C4A6E;
  margin-bottom: 12px;
  line-height: 1.4;
}
.lead-field {
  margin-bottom: 10px;
}
.lead-field input,
.lead-field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #BAE6FD;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  box-sizing: border-box;
  transition: all 0.2s;
  resize: none;
}
.lead-field input:focus,
.lead-field textarea:focus {
  outline: none;
  border-color: #0EA5E9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}
.lead-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.lead-submit {
  flex: 1;
  padding: 10px 0;
  background: linear-gradient(135deg, #22D3EE 0%, #0EA5E9 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.lead-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}
.lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.lead-cancel {
  padding: 10px 16px;
  background: #fff;
  color: #64748B;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.lead-cancel:hover {
  color: #334155;
  border-color: #CBD5E1;
}
.lead-tip {
  padding: 8px 12px;
  margin-bottom: 10px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 6px;
  font-size: 12px;
  color: #DC2626;
  text-align: center;
  animation: leadTipFadeIn 0.25s ease;
}
@keyframes leadTipFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
