/* ============================================================================
   AI 客服浮动窗（深蓝 #1A364D + 金 #C8A24B 主题）
   位置：左下角，避免与右下角 WhatsApp 冲突
   ============================================================================ */
.chat-widget {
  --cw-navy: #1A364D;
  --cw-navy-2: #24435f;
  --cw-gold: #C8A24B;
  --cw-gold-soft: #f3e8cf;
  --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-navy), var(--cw-navy-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(26, 54, 77, 0.32);
  z-index: 280;
  transition: transform .18s ease, box-shadow .18s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 16px 32px rgba(26, 54, 77, 0.38); }
.chat-fab-icon { width: 26px; height: 26px; }
.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-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; }
.chat-msg.bot  { align-self: flex-start; }
.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 .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; }

/* 商品卡片 */
.chat-products {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.chat-card {
  flex: 0 0 130px;
  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: 100%; height: 120px; object-fit: cover; background: #eef2f7; display: block; }
.chat-card-body { padding: 7px 8px; }
.chat-card-name {
  font-size: 12px; font-weight: 600; color: var(--cw-text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  height: 32px;
}
.chat-card-meta { font-size: 11px; color: var(--cw-muted); margin-top: 3px; }
.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-foot { padding: 0 12px 12px; }
.chat-handoff-btn {
  width: 100%;
  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; }

.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;
  }
}
