/* ==========================================================================
   美尔健生物 - 智能客服悬浮挂件样式 (AI Chat Widget)
   ========================================================================== */

:root {
  --mg-ai-primary: #059669;
  --mg-ai-primary-hover: #047857;
  --mg-ai-primary-light: #ecfdf5;
  --mg-ai-primary-border: #a7f3d0;
  --mg-ai-text: #1f2937;
  --mg-ai-text-muted: #6b7280;
  --mg-ai-bg: #f9fafb;
  --mg-ai-card-bg: #ffffff;
  --mg-ai-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  --mg-ai-radius: 16px;
}
/* 彻底移除旧版右侧悬浮侧栏，仅保留右下角AI在线客服“小美” */
.xin-2112-client-1,
#client-2112,
.my-kefu,
.client-2112-cont,
.client-2112-cont-weixin,
[id^="client-2112"],
[class*="xin-2112"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  position: absolute !important;
  left: -9999px !important;
  top: -9999px !important;
}

/* 浮动呼出按钮 - 药丸胶囊型，醒目展示“AI客服” */
#mg-ai-trigger {
  position: fixed;
  bottom: 30px;
  right: 28px;
  height: 52px;
  padding: 0 20px 0 16px;
  border-radius: 26px;
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  box-shadow: 0 8px 24px rgba(5, 150, 105, 0.4);
  cursor: pointer;
  z-index: 99998;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

#mg-ai-trigger:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 12px 28px rgba(5, 150, 105, 0.55);
}

#mg-ai-trigger .mg-ai-icon {
  width: 26px;
  height: 26px;
  fill: #ffffff;
  flex-shrink: 0;
}

#mg-ai-trigger .mg-ai-btn-text {
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

#mg-ai-trigger .mg-ai-badge {
  position: absolute;
  top: -6px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  border: 2px solid #fff;
  animation: pulseBadge 2s infinite;
  white-space: nowrap;
}

@keyframes pulseBadge {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* 浮动回到顶部按钮 */
#mg-back-to-top {
  position: fixed;
  bottom: 92px;
  right: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  color: #059669;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99997;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
  user-select: none;
  border: 1px solid #e5e7eb;
}

#mg-back-to-top.mg-show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#mg-back-to-top:hover {
  background: #f0fdf4;
  color: #047857;
  border-color: #a7f3d0;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(5, 150, 105, 0.2);
}

#mg-back-to-top .mg-btt-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#mg-back-to-top .mg-btt-text {
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  margin-top: -2px;
}

/* 首次欢迎气泡浮动提示 */
#mg-ai-bubble-hint {
  position: fixed;
  bottom: 100px;
  right: 30px;
  background: #ffffff;
  color: #1f2937;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  line-height: 1.45;
  max-width: 230px;
  z-index: 99997;
  border: 1px solid rgba(16, 185, 129, 0.2);
  animation: fadeInHint 0.5s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

#mg-ai-bubble-hint::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 25px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #ffffff;
}

#mg-ai-bubble-hint .mg-hint-close {
  color: #9ca3af;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

#mg-ai-bubble-hint .mg-hint-close:hover {
  color: #4b5563;
}

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

/* 聊天主体窗口 */
#mg-ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 390px;
  height: 610px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: var(--mg-ai-radius);
  box-shadow: var(--mg-ai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  border: 1px solid rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.92) translateY(20px);
  transform-origin: bottom right;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

#mg-ai-chat-window.mg-show {
  opacity: 1;
  visibility: visible;
  transform: scale(1) translateY(0);
}

/* 顶部状态栏 */
.mg-ai-header {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.mg-ai-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mg-ai-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.mg-ai-avatar svg {
  width: 24px;
  height: 24px;
  fill: #059669;
}

.mg-ai-title-wrap h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.mg-ai-title-wrap .mg-ai-sub {
  font-size: 11px;
  opacity: 0.88;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.mg-ai-title-wrap .mg-ai-status-dot {
  width: 7px;
  height: 7px;
  background: #34d399;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px #34d399;
}

.mg-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mg-ai-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.mg-ai-header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* 快捷栏与人工切换 */
.mg-ai-notice-bar {
  background: #ecfdf5;
  border-bottom: 1px solid #d1fae5;
  padding: 7px 14px;
  font-size: 12px;
  color: #065f46;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mg-ai-switch-human-btn {
  background: #059669;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.mg-ai-switch-human-btn:hover {
  background: #047857;
}

/* 消息流区域 */
.mg-ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.mg-ai-body::-webkit-scrollbar {
  width: 5px;
}

.mg-ai-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* 消息行 */
.mg-msg-row {
  display: flex;
  gap: 8px;
  max-width: 88%;
}

.mg-msg-row.mg-bot {
  align-self: flex-start;
}

.mg-msg-row.mg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.mg-msg-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #059669;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.mg-msg-content {
  background: #ffffff;
  padding: 10px 14px;
  border-radius: 14px;
  border-top-left-radius: 3px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #1f2937;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.04);
  word-break: break-word;
  white-space: pre-wrap;
}

.mg-msg-row.mg-user .mg-msg-content {
  background: #059669;
  color: #ffffff;
  border-radius: 14px;
  border-top-right-radius: 3px;
  border: none;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}

.mg-msg-time {
  font-size: 10.5px;
  color: #94a3b8;
  margin-top: 4px;
  align-self: flex-end;
}

/* 推荐问题标签卡 */
.mg-qa-suggestions {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mg-qa-chip {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mg-qa-chip:hover {
  background: #dcfce7;
  border-color: #86efac;
  transform: translateX(3px);
}

.mg-qa-chip::after {
  content: "→";
  font-size: 11px;
  opacity: 0.6;
}

/* 转人工及官方联系专属卡片 */
.mg-human-card {
  margin-top: 10px;
  background: #ffffff;
  border: 1px solid #fecaca;
  border-left: 4px solid #ef4444;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.08);
}

.mg-human-card.primary-mode {
  border-color: #a7f3d0;
  border-left: 4px solid #059669;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.08);
}

.mg-human-title {
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.mg-human-card.primary-mode .mg-human-title {
  color: #065f46;
}

.mg-human-phones {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.mg-phone-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 7px 10px;
  border-radius: 6px;
  color: #0f172a;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.2s;
}

.mg-phone-btn:hover {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

.mg-phone-btn .mg-phone-tag {
  font-size: 11px;
  color: #64748b;
  font-weight: normal;
}

.mg-qrcode-wrap {
  text-align: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #e2e8f0;
}

.mg-qrcode-img {
  width: 140px;
  height: 140px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 4px;
  cursor: pointer;
  transition: transform 0.2s;
}

.mg-qrcode-img:hover {
  transform: scale(1.05);
}

.mg-qrcode-hint {
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
}

/* 输入区域 */
.mg-ai-footer {
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.mg-ai-input-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.mg-ai-input-box:focus-within {
  border-color: #059669;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.mg-ai-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  color: #1f2937;
  padding: 6px 0;
}

.mg-ai-input::placeholder {
  color: #9ca3af;
  font-size: 12.5px;
}

.mg-ai-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #059669;
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.mg-ai-send-btn:hover {
  background: #047857;
  transform: scale(1.05);
}

.mg-ai-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

.mg-ai-send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.mg-ai-bottom-note {
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  margin-top: 6px;
}

/* 等待中动效 (Typing Indicator) */
.mg-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  width: fit-content;
}

.mg-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: mgBounce 1.4s infinite ease-in-out;
}

.mg-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.mg-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes mgBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* 微信二维码放大查看遮罩层 */
#mg-ai-qr-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

#mg-ai-qr-modal.mg-show {
  display: flex;
}

#mg-ai-qr-modal img {
  max-width: 320px;
  width: 85%;
  border-radius: 12px;
  box-shadow: 0 20px 35px rgba(0,0,0,0.4);
  background: #ffffff;
  padding: 8px;
}

/* 移动端适配 */
@media (max-width: 768px) {
  #mg-ai-trigger,
  #mg-ai-bubble-hint,
  #mg-back-to-top {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  #mg-ai-chat-window {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }
}
