/*
 * Chenda Shengye — AI 销售助手（外贸站）
 *
 * 外观参照中文站 chenda-ai-agent.html：
 *   黑底圆形“AI”悬浮球（62px）+ 绿色在线点 + 白色圆角聊天面板（380×600）
 * 组件挂在所有页面的右下角，样式独立于主题，避免和 custom.css 里的弹窗冲突。
 */

.cd-ai {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9990;
  font-family: "Nunito Sans", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", "Microsoft YaHei", sans-serif;
}

/* ---------- 悬浮球 ---------- */
.cd-ai__fab {
  position: relative;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #111;
  color: #fff;
  box-shadow: 0 16px 45px rgba(0, 0, 0, .2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .24s ease, box-shadow .28s ease;
}

.cd-ai__fab:hover { transform: translateY(-3px); box-shadow: 0 20px 52px rgba(0, 0, 0, .26); }
.cd-ai__fab:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.cd-ai__fab.is-hidden { opacity: 0; transform: scale(.7); pointer-events: none; }

.cd-ai__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #78c58a;
  animation: cd-ai-pulse 2.4s ease-in-out infinite;
}

.cd-ai__fab-label {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .01em;
  line-height: 1;
}

/* 首次进入的一次性提示气泡 */
.cd-ai__tip {
  position: absolute;
  right: 72px;
  bottom: 14px;
  width: 200px;
  box-sizing: border-box;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  color: #222;
  font-size: 11px;
  line-height: 1.5;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .16);
  border: 1px solid #ececea;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  white-space: pre-line;
}

.cd-ai__tip.is-on { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- 面板 ---------- */
.cd-ai__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  height: 600px;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, .985);
  border: 1px solid #e9e9e7;
  border-radius: 22px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, .2);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(.98);
  transition: opacity .26s cubic-bezier(.2, .8, .2, 1), visibility .26s, transform .26s cubic-bezier(.2, .8, .2, 1);
}

.cd-ai__panel.is-open { opacity: 1; visibility: visible; transform: none; }

.cd-ai__head {
  flex: none;
  height: 74px;
  padding: 17px 19px;
  box-sizing: border-box;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cd-ai__title { font-weight: 700; font-size: 18px; line-height: 1.2; color: #111; }
.cd-ai__sub { font-size: 10px; color: #888; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.cd-ai__sub i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #72bc7d; }

.cd-ai__head-actions { display: flex; align-items: center; gap: 2px; }
.cd-ai__icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #999;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease, color .2s ease;
}
.cd-ai__icon-btn:hover { background: #f4f4f2; color: #111; }

/* ---------- 消息区 ---------- */
.cd-ai__msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.cd-ai__msg { display: flex; margin-bottom: 12px; }
.cd-ai__msg.is-ai { justify-content: flex-start; }
.cd-ai__msg.is-user { justify-content: flex-end; }

.cd-ai__bubble {
  max-width: 84%;
  padding: 11px 13px;
  border-radius: 15px;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.cd-ai__msg.is-ai .cd-ai__bubble { background: #f5f5f3; color: #222; border-top-left-radius: 5px; }
.cd-ai__msg.is-user .cd-ai__bubble { background: #111; color: #fff; border-top-right-radius: 5px; }

/* 打字指示 */
.cd-ai__typing { display: inline-flex; gap: 4px; align-items: center; height: 8px; }
.cd-ai__typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #b9b9b5;
  animation: cd-ai-type 1.1s infinite ease-in-out;
}
.cd-ai__typing span:nth-child(2) { animation-delay: .18s; }
.cd-ai__typing span:nth-child(3) { animation-delay: .36s; }

/* ---------- 快捷问题 ---------- */
.cd-ai__quick {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 15px 10px;
}

.cd-ai__chip {
  border: 1px solid #e4e4e1;
  background: #fff;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.1;
  color: #444;
  cursor: pointer;
  font-family: inherit;
  transition: background .2s ease, border-color .2s ease;
}
.cd-ai__chip:hover { background: #f4f4f2; border-color: #d8d8d4; }
.cd-ai__chip:focus-visible { outline: 2px solid #111; outline-offset: 2px; }

/* ---------- 询盘表单（聊天内卡片） ---------- */
.cd-ai__lead {
  margin: 2px 0 12px;
  padding: 12px 13px;
  background: #fff;
  border: 1px solid #e3e3df;
  border-radius: 13px;
}
.cd-ai__lead-title { font-size: 12px; font-weight: 700; color: #111; margin: 0 0 4px; }
.cd-ai__lead-note { font-size: 10px; color: #8a8a86; line-height: 1.5; margin: 0 0 9px; }

.cd-ai__lead-field { display: block; margin-bottom: 6px; }
.cd-ai__lead-input,
.cd-ai__lead-textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #e1e1de;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: #222;
  background: #fff;
  font-family: inherit;
  outline: none;
}
.cd-ai__lead-textarea { min-height: 58px; resize: vertical; }
.cd-ai__lead-input:focus,
.cd-ai__lead-textarea:focus { border-color: #111; }

.cd-ai__lead-submit {
  margin-top: 4px;
  border: 0;
  background: #111;
  color: #fff;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .2s ease;
}
.cd-ai__lead-submit:hover { opacity: .86; }
.cd-ai__lead-submit:disabled { opacity: .5; cursor: default; }

.cd-ai__lead-msg { font-size: 10px; line-height: 1.5; margin: 7px 0 0; color: #8a8a86; }
.cd-ai__lead-msg.is-error { color: #b3261e; }
.cd-ai__lead-msg.is-ok { color: #2e7d46; }

/* ---------- 输入区 ---------- */
.cd-ai__form {
  flex: none;
  display: flex;
  gap: 7px;
  padding: 11px 12px;
  border-top: 1px solid #eee;
  background: inherit;
}

.cd-ai__input {
  flex: 1;
  min-width: 0;
  border: 1px solid #e1e1de;
  border-radius: 11px;
  padding: 11px 12px;
  outline: none;
  font-size: 12px;
  line-height: 1.4;
  color: #222;
  background: #fff;
  font-family: inherit;
}
.cd-ai__input:focus { border-color: #aaa; }

.cd-ai__send {
  flex: none;
  border: 0;
  border-radius: 11px;
  background: #111;
  color: #fff;
  padding: 0 15px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .2s ease;
}
.cd-ai__send:hover { opacity: .86; }

.cd-ai__note {
  flex: none;
  text-align: center;
  color: #aaa;
  font-size: 9px;
  line-height: 1.5;
  padding: 0 12px 9px;
}

/* ---------- 深色模式 ---------- */
html.montana-dark .cd-ai__panel { background: #151517; border-color: #2b2b2e; box-shadow: 0 26px 80px rgba(0, 0, 0, .6); }
html.montana-dark .cd-ai__head { border-bottom-color: #27272a; }
html.montana-dark .cd-ai__title { color: #f2f2f0; }
html.montana-dark .cd-ai__sub { color: #9a9a96; }
html.montana-dark .cd-ai__icon-btn:hover { background: #232326; color: #fff; }
html.montana-dark .cd-ai__msg.is-ai .cd-ai__bubble { background: #232326; color: #ececea; }
html.montana-dark .cd-ai__msg.is-user .cd-ai__bubble { background: #f2f2f0; color: #111; }
html.montana-dark .cd-ai__chip { background: #1b1b1e; border-color: #333337; color: #ddddda; }
html.montana-dark .cd-ai__chip:hover { background: #26262a; }
html.montana-dark .cd-ai__lead { background: #1b1b1e; border-color: #333337; }
html.montana-dark .cd-ai__lead-title { color: #f2f2f0; }
html.montana-dark .cd-ai__lead-input,
html.montana-dark .cd-ai__lead-textarea { background: #232326; border-color: #3a3a3f; color: #ececea; }
html.montana-dark .cd-ai__lead-submit { background: #f2f2f0; color: #111; }
html.montana-dark .cd-ai__form { border-top-color: #27272a; }
html.montana-dark .cd-ai__input { background: #232326; border-color: #3a3a3f; color: #ececea; }
html.montana-dark .cd-ai__send { background: #f2f2f0; color: #111; }
html.montana-dark .cd-ai__note { color: #7e7e7a; }

/* ---------- 移动端 ---------- */
@media (max-width: 600px) {
  .cd-ai { right: 14px; bottom: 14px; }
  .cd-ai__fab { width: 56px; height: 56px; }
  .cd-ai__fab-label { font-size: 15px; }
  .cd-ai__panel {
    width: min(380px, calc(100vw - 28px));
    height: min(600px, calc(100vh - 100px));
    bottom: 70px;
  }
  .cd-ai__tip { right: 66px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .cd-ai__fab, .cd-ai__panel, .cd-ai__tip { transition: none; }
  .cd-ai__dot, .cd-ai__typing span { animation: none; }
}

@keyframes cd-ai-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

@keyframes cd-ai-type {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-3px); opacity: 1; }
}
