/* ==========================================================================
   在线咨询（网页客服）样式
   全部使用 .cb- 前缀，与 style-v2.css 零冲突，不修改任何既有样式。
   仅有一处例外：body.has-chatbot 时把「返回顶部」按钮上移，避免被悬浮球挡住。
   ========================================================================== */

:root {
  --cb-primary: #2563eb;
  --cb-primary-dark: #1e40af;
  --cb-primary-light: #eff6ff;
  --cb-text: #111827;
  --cb-muted: #6b7280;
  --cb-border: #e5e7eb;
  --cb-bg: #f7f8fa;
}

/* ---------- 悬浮触发器 ---------- */
.cb-trigger {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(37, 99, 235, .35);
  transition: background .25s, transform .25s, box-shadow .25s;
  padding: 0;
}

.cb-trigger:hover {
  background: var(--cb-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(37, 99, 235, .45);
}

.cb-trigger:active { transform: translateY(0); }

.cb-trigger svg {
  width: 28px;
  height: 28px;
  display: block;
}

/* 触发器右上角小红点 */
.cb-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 600;
  display: none;
  box-shadow: 0 0 0 2px #fff;
}

.cb-badge.show { display: block; }

/* ---------- 会话窗口 ---------- */
.cb-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 480px;
  max-height: calc(100vh - 130px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, .18);
  z-index: 401;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Segoe UI', sans-serif;
  color: var(--cb-text);
  line-height: 1.6;
}

.cb-panel.open {
  display: flex;
  animation: cbIn .22s ease-out;
}

@keyframes cbIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 标题栏 ---------- */
.cb-head {
  flex: 0 0 50px;
  height: 50px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 14px;
}

.cb-head-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}

.cb-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  flex: 0 0 8px;
}

.cb-head-actions { display: flex; gap: 2px; }

.cb-head-actions button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, .85);
  cursor: pointer;
  padding: 6px 8px;
  line-height: 1;
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.cb-head-actions button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .15);
}

.cb-head-actions svg { width: 16px; height: 16px; display: block; }

/* ---------- 消息区 ---------- */
.cb-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--cb-bg);
  -webkit-overflow-scrolling: touch;
}

.cb-body::-webkit-scrollbar { width: 6px; }
.cb-body::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.cb-welcome-bubble {
  background: #fff;
  border: 1px solid var(--cb-border);
  border-radius: 12px 12px 12px 2px;
  padding: 10px 12px;
  color: #374151;
}

.cb-welcome-tip {
  margin-top: 8px;
  font-size: 12px;
  color: var(--cb-muted);
  text-align: center;
  line-height: 1.5;
}

/* FAQ 列表：首屏直接展示，进入对话视图后隐藏 */
.cb-quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.cb-panel.in-chat .cb-quick-grid { display: none; }

/* 首屏（非对话视图）时隐藏消息流：历史保留在 DOM，回到首屏时不会出现旧气泡 */
.cb-panel:not(.in-chat) .cb-stream { display: none; }

.cb-quick-item {
  border: 1px solid var(--cb-border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: border-color .18s, color .18s, background .18s;
  line-height: 1.4;
  font-family: inherit;
}

.cb-quick-item:hover {
  border-color: var(--cb-primary);
  color: var(--cb-primary);
  background: var(--cb-primary-light);
}

.cb-time {
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  margin: 2px 0 10px;
}

/* 消息气泡 */
.cb-msg {
  display: flex;
  margin-bottom: 10px;
  animation: cbMsgIn .2s ease-out;
}

@keyframes cbMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.cb-msg.user { justify-content: flex-end; }

.cb-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}

.cb-msg.bot .cb-bubble {
  background: #fff;
  border: 1px solid var(--cb-border);
  border-radius: 12px 12px 12px 2px;
  color: #374151;
}

.cb-msg.user .cb-bubble {
  background: var(--cb-primary);
  color: #fff;
  border-radius: 12px 12px 2px 12px;
}

/* 客服答复里的公司联系卡片 */
.cb-contact {
  margin-top: 10px;
  border-top: 1px dashed var(--cb-border);
  padding-top: 10px;
}

.cb-contact-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--cb-text);
  margin-bottom: 2px;
}

.cb-contact-hours {
  font-size: 11px;
  color: var(--cb-muted);
  margin-bottom: 6px;
}

.cb-contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: #374151;
}

.cb-contact-row .cb-k { color: var(--cb-muted); flex: 0 0 auto; }
.cb-contact-row .cb-v { text-align: right; }

.cb-contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.cb-btn {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
  font-family: inherit;
  transition: opacity .18s;
}

.cb-btn:hover { opacity: .88; }

.cb-btn-primary { background: var(--cb-primary); color: #fff; }
.cb-btn-ghost { background: var(--cb-primary-light); color: var(--cb-primary); }

/* ---------- 输入区 ---------- */
.cb-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--cb-border);
  background: #fff;
  padding: 8px 10px 9px;
}

/* FAQ 答案里的"还有其他常见问题"小尾巴按钮：
   位置 = 答案气泡下方，承接「有问题如何联系我们」的视觉分量；
   点击只是去掉 .in-chat 类 → 回到首屏 FAQ 列表，不跳页。 */
.cb-tail-link {
  display: block;
  margin-top: 8px;
  padding: 0;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--cb-primary);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  line-height: 1.5;
}

.cb-tail-link:hover { text-decoration: underline; }

.cb-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.cb-input {
  flex: 1;
  border: 1px solid var(--cb-border);
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 80px;
  line-height: 1.5;
  font-family: inherit;
  color: var(--cb-text);
  background: #fff;
}

.cb-input:focus { border-color: var(--cb-primary); }

.cb-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .18s;
}

.cb-send svg { width: 18px; height: 18px; display: block; }
.cb-send:hover { background: var(--cb-primary-dark); }
.cb-send:disabled { background: #cbd5e1; cursor: not-allowed; }

.cb-foot-note {
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  margin-top: 6px;
}

/* ---------- 轻提示（复制成功等） ---------- */
.cb-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 130px;
  background: rgba(17, 24, 39, .9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.cb-toast.show { opacity: 1; }

/* ---------- 移动端 ---------- */
@media (max-width: 480px) {
  .cb-trigger {
    width: 52px;
    height: 52px;
    right: 16px;
    bottom: 16px;
  }

  .cb-trigger svg { width: 24px; height: 24px; }

  .cb-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 76vh;
    max-height: 76vh;
    border-radius: 14px 14px 0 0;
  }
}

/* 动态隐藏悬浮球时（例如打印、全屏地图） */
.cb-hidden { display: none !important; }

/* 返回顶部按钮避让：有悬浮球时整体上移 76px（数值由 chatbot.js 计算写入） */
body.has-chatbot .back-to-top { transition: bottom .25s; }

/* 会话窗口打开时，隐藏返回顶部按钮，避免被窗口压住 */
body.cb-panel-open .back-to-top {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none;
}
