/* ============================================================================
   AI 客服浮动窗（深蓝 #1A364D + 金 #C8A24B 主题）
   位置：左下角，避免与右下角 WhatsApp 冲突
   ============================================================================ */
.chat-widget {
  --cw-navy: #1A364D;
  --cw-navy-2: #24435f;
  --cw-gold: #C8A24B;
  --cw-gold-soft: #f3e8cf;
  --cw-blue: #2563EB;
  --cw-blue-2: #1D4ED8;
  --cw-bg: #ffffff;
  --cw-text: #1f2937;
  --cw-muted: #94a3b8;
  --cw-bot: #f1f5f9;
  --cw-radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* 浮动按钮 */
.chat-fab {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--cw-blue), var(--cw-blue-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.34);
  z-index: 280;
  transition: transform .18s ease, box-shadow .18s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 32px rgba(37, 99, 235, 0.42); }
.chat-fab-icon { width: 26px; height: 26px; }
/* 关窗后有新消息：图标脉冲闪烁 + 金色光环，强提示（不依赖声音） */
.chat-fab.has-new { animation: cw-pulse 1.1s ease-in-out infinite; }
@keyframes cw-pulse {
  0%, 100% { box-shadow: 0 10px 24px rgba(37, 99, 235, 0.30); }
  50% { box-shadow: 0 0 0 6px rgba(200, 162, 75, 0.55), 0 10px 24px rgba(37, 99, 235, 0.30); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-fab.has-new { animation: none; box-shadow: 0 0 0 4px rgba(200, 162, 75, 0.6); }
}

/* 关窗时新消息气泡预览（显示内容，点击打开窗口） */
.chat-peek {
  position: fixed;
  z-index: 9998;
  display: none;
  align-items: flex-start;
  gap: 8px;
  max-width: 300px;
  padding: 10px 12px;
  background: #fff;
  color: #1A364D;
  border: 1px solid rgba(26, 54, 77, 0.12);
  border-left: 3px solid #C8A24B;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(26, 54, 77, 0.22);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  animation: cw-peek-in .25s ease;
}
.chat-peek.show { display: flex; }
.chat-peek-who {
  flex: 0 0 auto;
  font-weight: 800;
  color: #C8A24B;
  font-size: 11px;
  padding-top: 1px;
  white-space: nowrap;
}
.chat-peek-text {
  flex: 1 1 auto;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
@keyframes cw-peek-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* 面板 */
.chat-panel {
  position: fixed;
  left: 20px;
  bottom: 90px;
  width: 370px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--cw-bg);
  border-radius: var(--cw-radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 281;
  border: 1px solid rgba(200, 162, 75, 0.25);
}
.chat-panel[hidden] { display: none; }

/* 头部 */
.chat-header {
  background: linear-gradient(135deg, var(--cw-navy), var(--cw-navy-2));
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--cw-gold);
  color: var(--cw-navy);
  font-weight: 800;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-title-text { display: flex; flex-direction: column; line-height: 1.2; }
.chat-title-text strong { font-size: 14px; }
.chat-title-text small { font-size: 11px; color: rgba(255,255,255,0.72); }
.chat-close {
  background: transparent; border: none; color: #fff;
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
  opacity: 0.85;
}
.chat-close:hover { opacity: 1; }
.chat-mute {
  background: transparent; border: none; color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px;
  opacity: 0.85; filter: grayscale(0);
}
.chat-mute:hover { opacity: 1; }
.chat-mute.muted { opacity: 0.55; filter: grayscale(1); }

/* 消息区 */
.chat-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8fafc;
}
.chat-msg { display: flex; max-width: 85%; }
.chat-msg .bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user { align-self: flex-end; justify-content: flex-end; }
.chat-msg.user .bubble { background: var(--cw-navy); color: #fff; border-bottom-right-radius: 4px; border-bottom-left-radius: 14px; }
/* AI 应答跟随客服：与 agent 同处左侧（访客消息在右侧） */
.chat-msg.bot  { align-self: flex-start !important; }
.chat-msg.bot .bubble { background: var(--cw-bot); color: var(--cw-text); border-bottom-left-radius: 4px; }
.chat-msg.agent { align-self: flex-start; }
.chat-msg.agent .chat-label { font-size: 11px; color: var(--cw-gold); font-weight: 700; margin: 0 0 2px 2px; }
.chat-msg.agent .bubble { background: var(--cw-gold-soft); color: var(--cw-navy); border-bottom-left-radius: 4px; border: 1px solid rgba(200,162,75,0.4); }
.chat-msg.system { align-self: center; max-width: 92%; }
.chat-msg.system .bubble { background: transparent; color: var(--cw-muted); font-size: 12px; text-align: center; }

/* 图片消息 */
.bubble img.chat-img {
  display: block;
  max-width: 180px;
  max-height: 220px;
  width: auto;
  border-radius: 10px;
  margin: 2px 0 4px;
  object-fit: cover;
  cursor: zoom-in;
}

/* 商品卡片：垂直堆叠，每个产品独占一行，避免横向压缩 */
.chat-products {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.chat-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: #fff;
  transition: transform .15s ease, box-shadow .15s ease;
}
.chat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(15,23,42,0.12); }
.chat-card-img { width: 80px; height: 80px; object-fit: cover; background: #eef2f7; display: block; flex: 0 0 auto; }
.chat-card-body { flex: 1 1 auto; padding: 8px 10px; min-width: 0; }
.chat-card-name {
  font-size: 13px; font-weight: 600; color: var(--cw-text);
  line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-card-meta { font-size: 11px; color: var(--cw-muted); margin-top: 4px; }
.chat-card-meta b { color: var(--cw-navy); }

/* 快捷问题 + 输入 */
.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
  border-top: 1px solid #eef2f7;
}
.chat-quick button {
  border: 1px solid rgba(200,162,75,0.5);
  background: #fffdf8;
  color: var(--cw-navy);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease;
}
.chat-quick button:hover { background: var(--cw-gold-soft); }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}
.chat-input-row input {
  flex: 1 1 auto;
  border: 1px solid #d8dee9;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  outline: none;
}
.chat-input-row input:focus { border-color: var(--cw-gold); }
.chat-input-row button {
  border: none;
  background: var(--cw-navy);
  color: #fff;
  font-weight: 600;
  padding: 0 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13.5px;
}
.chat-input-row button:hover { background: var(--cw-navy-2); }
.chat-input-row button:disabled { opacity: 0.55; cursor: default; }
.chat-img-btn { font-size: 16px; padding: 0 12px; line-height: 1; }

.chat-foot { padding: 0 12px 12px; display: flex; gap: 8px; }
.chat-handoff-btn {
  flex: 1 1 auto;
  width: auto;
  border: 1px dashed var(--cw-gold);
  background: #fffdf8;
  color: var(--cw-navy);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
.chat-handoff-btn:hover { background: var(--cw-gold-soft); }
.chat-handoff-btn.active { background: var(--cw-gold); color: #fff; border-style: solid; }

/* 在 WhatsApp 上继续（绿色，区别于转人工金色虚线） */
.chat-wa-btn {
  flex: 1 1 auto;
  width: auto;
  margin-top: 0;
  border: 1px solid #25D366;
  background: #e9fbf0;
  color: #128C4B;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
.chat-wa-btn:hover { background: #d4f7e2; }

.chat-typing { font-style: italic; color: var(--cw-muted); font-size: 12.5px; padding: 2px 2px; }

/* 移动端 */
@media (max-width: 720px) {
  .chat-fab { left: 16px; bottom: calc(58px + 16px); width: 52px; height: 52px; }
  .chat-panel {
    left: 10px; right: 10px;
    bottom: calc(58px + 10px);
    width: auto;
    height: calc(100vh - 58px - 80px);
    max-height: none;
  }
}
