/* ==========================================================================
   招商智能问答 · 官网浮层对话组件
   --------------------------------------------------------------------------
   独立文件，不修改 style.css。
   全部选择器以 .faqchat 前缀命名空间隔离，与全站现有类零冲突。
   颜色/圆角/阴影复用 style.css 的 CSS 变量（带兜底值，style.css 加载失败也能看）。
   ========================================================================== */

/* ---------- 无障碍：仅供读屏 ---------- */
.faqchat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 启动按钮 ---------- */
.faqchat-launcher {
  position: fixed;
  right: 20px;
  /* 右侧垂直居中：不再与右下角 .to-top 争位，长页面上也不会被页脚顶掉 */
  top: 50%;
  transform: translateY(-50%);
  z-index: 46;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px 11px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--c-primary, #534ab7);
  color: #fff;
  font-family: inherit;
  font-size: var(--fs-sm, 14px);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(26, 26, 46, 0.12));
  transition: transform 0.2s var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
    background 0.2s var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)),
    opacity 0.2s var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
}
.faqchat-launcher:hover {
  background: var(--c-primary-dark, #3c3489);
  /* 悬停上浮 2px，必须带上 -50% 的居中位移，否则按钮会掉到屏幕下半部 */
  transform: translateY(calc(-50% - 2px));
}
.faqchat-launcher:focus-visible {
  outline: 2px solid var(--c-primary-dark, #3c3489);
  outline-offset: 3px;
}
.faqchat-launcher svg {
  width: 18px;
  height: 18px;
  flex: none;
  display: block;
}
/* 首次进入的呼吸提示（不打扰：只在未打开过时出现） */
@media (prefers-reduced-motion: no-preference) {
  .faqchat-launcher.is-hinting {
    animation: faqchat-hint 2.6s var(--ease, ease-in-out) 2;
  }
  @keyframes faqchat-hint {
    0%,
    100% {
      box-shadow: 0 0 0 0 rgba(83, 74, 183, 0.42);
    }
    55% {
      box-shadow: 0 0 0 12px rgba(83, 74, 183, 0);
    }
  }
}
.faqchat-launcher[hidden] {
  display: none;
}

/* ---------- 面板容器 ---------- */
.faqchat {
  /* 垂直位移集中到一个变量：宽屏是 -50%（右侧居中），小屏抽屉会被覆盖为 0 */
  --faqchat-ty: -50%;
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(var(--faqchat-ty));
  z-index: 60;
  display: none;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: min(660px, calc(100dvh - 116px));
  overflow: hidden;
  background: var(--c-bg, #fff);
  border: 1px solid var(--c-border-strong, rgba(26, 26, 46, 0.16));
  border-radius: var(--r-lg, 16px);
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(26, 26, 46, 0.12));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-sm, 14px);
  line-height: 1.6;
  color: var(--c-text, #1a1a2e);
  text-align: left;
}
.faqchat.is-open {
  display: flex;
}
@media (prefers-reduced-motion: no-preference) {
  .faqchat.is-open {
    animation: faqchat-rise 0.22s var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1)) both;
  }
  @keyframes faqchat-rise {
    from {
      opacity: 0;
      transform: translateY(calc(var(--faqchat-ty) + 10px)) scale(0.99);
    }
    to {
      opacity: 1;
      transform: translateY(var(--faqchat-ty));
    }
  }
}

/* ---------- 头部 ---------- */
.faqchat__head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px 13px 16px;
  background: var(--c-primary-light, #eeedfe);
  border-bottom: 1px solid var(--c-border, rgba(26, 26, 46, 0.08));
}
.faqchat__id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.faqchat__avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--c-primary, #534ab7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.faqchat__avatar svg {
  width: 18px;
  height: 18px;
  display: block;
}
.faqchat__name {
  margin: 0;
  font-size: var(--fs-body, 16px);
  font-weight: 600;
  line-height: 1.3;
  color: var(--c-primary-dark, #3c3489);
}
.faqchat__sub {
  margin: 1px 0 0;
  font-size: var(--fs-xs, 13px);
  line-height: 1.35;
  color: var(--c-text-muted, #555559);
}
.faqchat__close {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--c-text-muted, #555559);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.18s var(--ease, ease), color 0.18s var(--ease, ease);
}
.faqchat__close:hover {
  background: rgba(26, 26, 46, 0.08);
  color: var(--c-text, #1a1a2e);
}
.faqchat__close:focus-visible {
  outline: 2px solid var(--c-primary, #534ab7);
  outline-offset: 2px;
}

/* ---------- 对话区 ---------- */
.faqchat__log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 6px;
  background: var(--c-bg-soft, #f7f7fa);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.faqchat__row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 100%;
}
.faqchat__row--me {
  align-items: flex-end;
}
/* 气泡 */
.faqchat__bubble {
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.faqchat__row--bot .faqchat__bubble {
  align-self: flex-start;
  max-width: 94%;
  background: var(--c-bg, #fff);
  border: 1px solid var(--c-border, rgba(26, 26, 46, 0.08));
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(26, 26, 46, 0.06));
}
.faqchat__row--me .faqchat__bubble {
  align-self: flex-end;
  max-width: 86%;
  background: var(--c-primary, #534ab7);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.faqchat__row--sys .faqchat__bubble {
  align-self: center;
  max-width: 100%;
  background: transparent;
  color: var(--c-text-hint, #888780);
  font-size: var(--fs-xs, 13px);
  text-align: center;
  padding: 2px 6px;
}
/* 富文本答案需要更大宽度（表格） */
.faqchat__row--bot .faqchat__bubble--rich {
  max-width: 100%;
}
.faqchat__bubble p {
  margin: 0 0 8px;
}
.faqchat__bubble p:last-child {
  margin-bottom: 0;
}
.faqchat__bubble strong {
  font-weight: 600;
  color: var(--c-primary-dark, #3c3489);
}
.faqchat__row--me .faqchat__bubble strong {
  color: inherit;
}
.faqchat__bubble code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--c-primary-light, #eeedfe);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.faqchat__bubble ul,
.faqchat__bubble ol {
  margin: 0 0 8px;
  padding-left: 1.25em;
}
.faqchat__bubble ul:last-child,
.faqchat__bubble ol:last-child {
  margin-bottom: 0;
}
.faqchat__bubble li {
  margin-bottom: 3px;
}
.faqchat__bubble blockquote {
  margin: 8px 0 0;
  padding: 8px 11px;
  border-left: 3px solid var(--c-primary-mid, #cecbf6);
  border-radius: 0 8px 8px 0;
  background: var(--c-primary-light, #eeedfe);
  color: var(--c-text-muted, #555559);
  font-size: var(--fs-xs, 13px);
}
.faqchat__bubble blockquote:first-child {
  margin-top: 0;
}
/* 表格（语料里的价格/门槛多用表格，窄屏必须可横向滚动） */
.faqchat__tw {
  margin: 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.faqchat__tw:last-child {
  margin-bottom: 0;
}
.faqchat__bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  line-height: 1.5;
}
.faqchat__bubble th,
.faqchat__bubble td {
  padding: 6px 8px;
  border: 1px solid var(--c-border-strong, rgba(26, 26, 46, 0.16));
  text-align: left;
  vertical-align: top;
  /* 面板只有 384px 宽，表格必须换行而不是横向滚动；
     超长不可断词（如长数字串）就地断行，避免撑破气泡 */
  white-space: normal;
  overflow-wrap: anywhere;
}
.faqchat__bubble th {
  background: var(--c-primary-light, #eeedfe);
  color: var(--c-primary-dark, #3c3489);
  font-weight: 600;
}
/* 首列是项目名，给它一点最小宽度，避免被挤成一列一字 */
.faqchat__bubble th:first-child,
.faqchat__bubble td:first-child {
  min-width: 4.5em;
}

/* ---------- 候选追问（L2）---------- */
.faqchat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.faqchat__chip {
  padding: 7px 12px;
  border: 1px solid var(--c-primary-mid, #cecbf6);
  border-radius: 999px;
  background: var(--c-bg, #fff);
  color: var(--c-primary, #534ab7);
  font-family: inherit;
  font-size: var(--fs-xs, 13px);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s var(--ease, ease), color 0.18s var(--ease, ease);
}
.faqchat__chip:hover:not(:disabled) {
  background: var(--c-primary, #534ab7);
  color: #fff;
}
.faqchat__chip:focus-visible {
  outline: 2px solid var(--c-primary, #534ab7);
  outline-offset: 2px;
}
.faqchat__chip:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---------- 等待态（不写「AI 正在思考」）---------- */
.faqchat__typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--c-text-hint, #888780);
  font-size: var(--fs-xs, 13px);
}
.faqchat__typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-primary-mid, #cecbf6);
  animation: faqchat-blink 1.2s infinite ease-in-out;
}
.faqchat__typing i:nth-child(2) {
  animation-delay: 0.18s;
}
.faqchat__typing i:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes faqchat-blink {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .faqchat__typing i {
    animation: none;
    opacity: 0.7;
  }
}

/* ---------- 底部动作条（L3 兜底 / 转化出口）---------- */
.faqchat__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.faqchat__act {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--c-primary, #534ab7);
  color: #fff;
  font-family: inherit;
  font-size: var(--fs-xs, 13px);
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  transition: background 0.18s var(--ease, ease);
}
.faqchat__act:hover {
  background: var(--c-primary-dark, #3c3489);
  color: #fff;
}
.faqchat__act--ghost {
  background: transparent;
  color: var(--c-primary, #534ab7);
  border: 1px solid var(--c-primary-mid, #cecbf6);
}
.faqchat__act--ghost:hover {
  background: var(--c-primary-light, #eeedfe);
  color: var(--c-primary-dark, #3c3489);
}

/* ---------- 留资卡（对话内收口，不跳页）----------
   出现时机由 JS 控制：每会话至多一次，且先有 ≥2 轮问答 + 问到高意图问题。
   视觉上刻意用主色浅底与答案气泡区分，让它看起来像"服务升级"而不是广告位。 */
.faqchat__lead {
  border: 1px solid var(--c-primary-mid, #cecbf6);
  background: var(--c-primary-light, #eeedfe);
}
.faqchat__lead-t {
  margin: 0 0 4px;
  font-size: var(--fs-sm, 14px);
  font-weight: 600;
  line-height: 1.4;
  color: var(--c-primary-dark, #3c3489);
}
.faqchat__lead-d {
  margin: 0 0 10px;
  font-size: var(--fs-xs, 13px);
  line-height: 1.55;
  color: var(--c-text-muted, #555559);
}
.faqchat__lead-d strong {
  color: var(--c-primary-dark, #3c3489);
}
.faqchat__lead-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.faqchat__lead-input {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--c-border-strong, rgba(26, 26, 46, 0.16));
  border-radius: var(--r-sm, 8px);
  background: var(--c-bg, #fff);
  color: var(--c-text, #1a1a2e);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
}
.faqchat__lead-input::placeholder {
  color: var(--c-text-hint, #888780);
}
.faqchat__lead-input:focus {
  outline: 0;
  border-color: var(--c-primary, #534ab7);
  box-shadow: 0 0 0 3px rgba(83, 74, 183, 0.12);
}
.faqchat__lead-note {
  display: block;
  margin-bottom: 8px;
  resize: vertical;
}
/* 同意勾选：默认不勾，手机号属个人信息，必须显式同意 */
.faqchat__agree {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0 0 9px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--c-text-muted, #555559);
  cursor: pointer;
}
.faqchat__agree input {
  flex: none;
  margin: 2px 0 0;
  accent-color: var(--c-primary, #534ab7);
}
.faqchat__agree a {
  color: var(--c-primary, #534ab7);
}
.faqchat__lead-btn {
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--r-md, 10px);
  background: var(--c-primary, #534ab7);
  color: #fff;
  font-family: inherit;
  font-size: var(--fs-sm, 14px);
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.18s var(--ease, ease);
}
.faqchat__lead-btn:hover:not(:disabled) {
  background: var(--c-primary-dark, #3c3489);
}
.faqchat__lead-btn:disabled {
  background: var(--c-primary-mid, #cecbf6);
  cursor: default;
}
.faqchat__lead-tip {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--c-text-muted, #555559);
}
.faqchat__lead-tip.is-error {
  color: var(--c-danger, #c0392b);
}
.faqchat__lead-tip:empty {
  display: none;
}
.faqchat__lead-alt {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--c-text-hint, #888780);
}
.faqchat__lead-alt a {
  color: var(--c-text-muted, #555559);
}
/* 成功后回归普通气泡样式，不再抢注意力 */
.faqchat__lead.is-done {
  background: var(--c-bg, #fff);
  border-color: var(--c-border, rgba(26, 26, 46, 0.08));
}
/* 蜜罐：正常访客看不见 */
.faqchat__hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ---------- 输入区 ---------- */
.faqchat__form {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--c-bg, #fff);
  border-top: 1px solid var(--c-border, rgba(26, 26, 46, 0.08));
}
.faqchat__input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 84px;
  padding: 9px 12px;
  border: 1px solid var(--c-border-strong, rgba(26, 26, 46, 0.16));
  border-radius: var(--r-md, 10px);
  background: var(--c-bg, #fff);
  color: var(--c-text, #1a1a2e);
  font-family: inherit;
  font-size: var(--fs-sm, 14px);
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.18s var(--ease, ease), box-shadow 0.18s var(--ease, ease);
}
.faqchat__input::placeholder {
  color: var(--c-text-hint, #888780);
}
.faqchat__input:focus {
  outline: 0;
  border-color: var(--c-primary, #534ab7);
  box-shadow: 0 0 0 3px rgba(83, 74, 183, 0.12);
}
.faqchat__send {
  flex: none;
  padding: 9px 16px;
  border: 0;
  border-radius: var(--r-md, 10px);
  background: var(--c-primary, #534ab7);
  color: #fff;
  font-family: inherit;
  font-size: var(--fs-sm, 14px);
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  transition: background 0.18s var(--ease, ease);
}
.faqchat__send:hover:not(:disabled) {
  background: var(--c-primary-dark, #3c3489);
}
.faqchat__send:disabled {
  background: var(--c-primary-mid, #cecbf6);
  cursor: default;
}

/* ---------- 页脚（合规公示位）---------- */
.faqchat__foot {
  flex: none;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--c-border, rgba(26, 26, 46, 0.08));
  background: var(--c-bg, #fff);
}
.faqchat__note {
  margin: 0 0 4px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--c-text-hint, #888780);
}
.faqchat__links {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--c-text-hint, #888780);
}
.faqchat__links a {
  color: var(--c-text-muted, #555559);
  text-decoration: none;
  border-bottom: 1px solid var(--c-border-strong, rgba(26, 26, 46, 0.16));
}
.faqchat__links a:hover {
  color: var(--c-primary, #534ab7);
  border-bottom-color: var(--c-primary-mid, #cecbf6);
}

/* ---------- 小屏：底部抽屉 ---------- */
@media (max-width: 560px) {
  .faqchat-launcher {
    right: 12px;
    /* 小屏同样保持垂直居中（bottom 已在基础规则里去掉） */
    padding: 10px 15px 10px 12px;
  }
  .faqchat {
    right: 0;
    left: 0;
    /* 抽屉从底部升起：先归零居中位移，再改 top 锚点，动画 keyframes 才不会错位 */
    --faqchat-ty: 0%;
    top: auto;
    bottom: 0;
    width: auto;
    max-width: none;
    height: 88dvh;
    border-radius: var(--r-lg, 16px) var(--r-lg, 16px) 0 0;
    border-bottom: 0;
  }
  .faqchat__log {
    padding: 14px 12px 6px;
  }
  .faqchat__row--bot .faqchat__bubble {
    max-width: 100%;
  }
}

/* ---------- 打印：不输出 ---------- */
@media print {
  .faqchat,
  .faqchat-launcher {
    display: none !important;
  }
}
