/* ============================================================
 * front.css · 右下角客服气泡
 *
 * 位置为什么选这里：买家的动线是「看商品 → 点购买 → 卡在某个说明上」，鼠标与视线都停在页面
 * 右半，且右下角在桌面与手机上都是全站唯一空着的角落（左下是面包屑/公告）。
 * 层级取 78：移动底部导航 60、更多面板 59，弹窗层 80、购买弹层 82——气泡要压在导航之上、
 * 任何弹窗之下，否则买家开着「联系客服」还能点到弹窗背后去。
 * 手机上必须抬到 62px 的导航条之上（含安全区），不然第一屏就把气泡点不住。
 * 颜色一律取主题的 --theme- 系列、--surface、--border- 系列、--shadow- 系列，不自带配色，皮肤与深色模式跟随站点。
 * ============================================================ */

.dscs-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 78;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--font-sans);
  /* 容器本身不吃命中：收起来时只剩气泡那颗，别让一块透明方框挡住页面 */
  pointer-events: none;
}

.dscs-root > * {
  pointer-events: auto;
}

/* ---------------- 入口气泡 ---------------- */
.dscs-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 18px 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px color-mix(in srgb, var(--theme-secondary) 16%, transparent);
  color: var(--accent-deep);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease), transform var(--motion-base) var(--motion-spring), opacity var(--motion-base) linear;
}

.dscs-fab > i {
  font-size: 18px;
  color: var(--accent);
}

.dscs-fab:hover {
  border-color: color-mix(in srgb, var(--theme-primary) 52%, var(--border-soft));
  color: var(--accent);
  transform: translateY(-1px);
}

.dscs-fab:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

.dscs-fab-text {
  white-space: nowrap;
}

/* 桌面上先收成一颗圆钮：商品页右下角那颗「去支付」是大按钮，带文字的胶囊会盖住它约 70px 的
   点击区——客服入口不能挡买卖的路。悬停或键盘聚焦时才展开成胶囊，这时鼠标已经冲着气泡来了，
   不存在误挡。手机端同样收圆钮（见下面「手机」那段），只是没有悬停可以展开。 */
@media (min-width: 901px) {
  /* 桌面端离右边缘再远一点：商品页「去支付」那颗大按钮的右缘离容器边只有十几像素，
     圆钮收在 18px 处与它只差 1px，站点改内边距就会重新压上去。 */
  .dscs-root {
    right: 26px;
  }

  .dscs-fab {
    width: 48px;
    height: 48px;
    padding: 0;
    gap: 0;
    justify-content: center;
  }

  .dscs-fab-text {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width var(--motion-base) var(--motion-ease), opacity var(--motion-fast) linear;
  }

  .dscs-fab:hover,
  .dscs-fab:focus-visible {
    width: auto;
    gap: 8px;
    padding: 0 18px 0 15px;
    justify-content: flex-start;
  }

  .dscs-fab:hover .dscs-fab-text,
  .dscs-fab:focus-visible .dscs-fab-text {
    max-width: 140px;
    opacity: 1;
  }
}

/* 未读点：只在真的有客服回复、且窗口没打开时出现 */
.dscs-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--gold);
}

.dscs-dot[hidden] {
  display: none;
}

.dscs-root.is-open .dscs-fab {
  display: none;
}

/* ---------------- 会话面板 ---------------- */
.dscs-panel {
  display: flex;
  flex-direction: column;
  width: min(384px, calc(100vw - 28px));
  height: min(552px, calc(100dvh - 96px));
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lift);
  color: var(--ink);
  animation: dscs-in var(--motion-base) var(--motion-ease);
}

.dscs-panel[hidden] {
  display: none;
}

@keyframes dscs-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.dscs-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-veil);
}

.dscs-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid color-mix(in srgb, var(--theme-primary) 26%, var(--border-soft));
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 17px;
}

.dscs-head-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  margin-right: auto;
}

.dscs-head-copy strong {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dscs-state {
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dscs-state.is-on {
  color: var(--accent);
}

.dscs-state.is-away {
  color: var(--gold);
}

.dscs-state.is-staff {
  color: var(--ink-soft);
}

/* 头部动作：一律描边，不填背景（和后台的 ghost 键同一口径） */
.dscs-hbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 9px;
  flex: none;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}

.dscs-hbtn > i {
  font-size: 15px;
}

/* 头部三枚挤不下文字：结束收成图标，标题仍在 title 里 */
.dscs-hbtn.is-icon {
  width: 30px;
  padding: 0;
  justify-content: center;
}

.dscs-hbtn:hover {
  border-color: color-mix(in srgb, var(--theme-primary) 46%, var(--border-soft));
  color: var(--accent);
}

/* 已经在人工手里的会话：「人工」这颗收成看不见的状态，别给一个按不动的按钮 */
.dscs-hbtn:disabled,
.dscs-hbtn[disabled] {
  opacity: .38;
  cursor: default;
  pointer-events: none;
}

/* ---------------- 消息区 ---------------- */
.dscs-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}

.dscs-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  max-width: 86%;
}

.dscs-msg.is-me {
  align-self: flex-end;
  align-items: flex-end;
}

.dscs-tag {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: .02em;
}

.dscs-bubble {
  position: relative;
  padding: 9px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 4px 14px 14px 14px;
  background: var(--surface-muted);
  font-size: 13.5px;
  line-height: 1.62;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.dscs-msg.is-me .dscs-bubble {
  /* 买家自己说的话是唯一允许填色的一处：一眼分清谁说的，靠的是底色而不是描边 */
  border-color: color-mix(in srgb, var(--theme-primary) 30%, transparent);
  border-radius: 14px 4px 14px 14px;
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.dscs-msg.is-staff .dscs-bubble {
  border-color: color-mix(in srgb, var(--theme-accent) 40%, var(--border-soft));
}

.dscs-msg time {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

/* 有帮助投票：贴在 AI 气泡右下角，平时淡着，hover 那条才清楚 */
.dscs-thumb {
  display: inline-flex;
  margin-left: 8px;
  vertical-align: -2px;
}

.dscs-thumb button {
  display: inline-flex;
  padding: 2px;
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 13px;
  cursor: pointer;
  transition: color var(--motion-fast) var(--motion-ease);
}

.dscs-thumb button:hover:not(:disabled) {
  color: var(--gold);
}

.dscs-thumb button.is-on,
.dscs-thumb button:disabled {
  color: var(--gold);
  cursor: default;
}

.dscs-sys {
  align-self: center;
  max-width: 92%;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.dscs-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: auto 0;
  padding: 0 26px;
  color: var(--ink-faint);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
}

.dscs-empty > i {
  font-size: 30px;
  color: color-mix(in srgb, var(--theme-primary) 34%, transparent);
}

/* 正在输入：三个点，不引第三方加载动画 */
.dscs-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 13px 14px;
}

.dscs-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .35;
  animation: dscs-blink 1.1s var(--motion-ease) infinite;
}

.dscs-dots i:nth-child(2) { animation-delay: .16s }
.dscs-dots i:nth-child(3) { animation-delay: .32s }

@keyframes dscs-blink {
  0%, 60%, 100% { opacity: .28; transform: translateY(0) }
  30% { opacity: .95; transform: translateY(-2px) }
}

/* ---------------- 快捷提问 ---------------- */
.dscs-quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px 2px;
}

.dscs-quick[hidden] {
  display: none;
}

.dscs-quick-tip {
  width: 100%;
  font-size: 11.5px;
  color: var(--ink-faint);
}

.dscs-chip {
  padding: 5px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}

.dscs-chip:hover {
  border-color: color-mix(in srgb, var(--theme-primary) 52%, var(--border-soft));
  color: var(--accent);
}

/* ---------------- 输入区 ---------------- */
.dscs-foot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-veil);
}

.dscs-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 116px;
  /* 一行要占 20.25px 行高 + 上下 16px 内边距 + 2px 边框：38px 装不下，
     差的那零点几像素就会让输入框右边长出一条竖滚动条。 */
  min-height: 40px;
  padding: 8px 11px;
  /* 高度由 front.js 逐行撑开，撑到 max-height 才加 is-scroll 把滚动条还回来 */
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  transition: border-color var(--motion-fast) var(--motion-ease), box-shadow var(--motion-fast) var(--motion-ease);
}

.dscs-input::placeholder {
  color: var(--ink-faint);
}

.dscs-input.is-scroll {
  overflow-y: auto;
}

.dscs-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--theme-primary) 52%, var(--border-soft));
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.dscs-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid color-mix(in srgb, var(--theme-primary) 42%, var(--border-soft));
  border-radius: 12px;
  background: none;
  color: var(--accent);
  font-size: 17px;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--motion-ease), opacity var(--motion-fast) var(--motion-ease);
}

.dscs-send:hover:not(:disabled) {
  border-color: var(--accent);
}

.dscs-send:disabled {
  opacity: .45;
  cursor: default;
}

.dscs-note {
  margin: 0;
  padding: 0 14px 11px;
  border-top: 1px dashed var(--border-soft);
  padding-top: 8px;
  color: var(--ink-faint);
  font-size: 11px;
  line-height: 1.55;
}

/* ---------------- 手机 ---------------- */
/* 底部导航条占 62px + 最多 10px 下边距 + 安全区，气泡必须整个抬到它上面。
   形态与桌面一致收成圆钮：列表滚到中段时，带文字的胶囊正好压在右列的分类/商品卡上
   （390 视口里它占 111×42，下面那条就是「会员权益」那一格）。触屏没有悬停，
   所以文字是直接不渲染，而不是像桌面那样等 hover 展开。 */
@media (max-width: 900px) {
  .dscs-root {
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom));
  }

  .dscs-fab {
    width: 46px;
    height: 46px;
    padding: 0;
    gap: 0;
    justify-content: center;
  }

  .dscs-fab-text {
    display: none;
  }

  /* 向下浏览时整颗推出去（见 front.js 的 watchScroll）：藏起来就不许再接点击，
     否则买家点的是气泡，生效的却是它原来位置上的商品卡。 */
  .dscs-root.is-tuck .dscs-fab {
    transform: translateX(calc(100% + 12px));
    opacity: 0;
    pointer-events: none;
  }

  .dscs-panel {
    width: calc(100vw - 24px);
    height: min(70dvh, 520px);
  }

  .dscs-msg {
    max-width: 90%;
  }

  /* 手机上头部只剩「收起」够用：人工与结束收进气泡宽度里放不下，改为不换行 + 省略 */
  .dscs-hbtn span {
    display: none;
  }

  .dscs-hbtn {
    padding: 0 7px;
  }
}

@media (max-width: 620px) {
  .dscs-head-copy strong {
    font-size: 13.5px;
  }

  .dscs-note {
    display: none;
  }
}

/* 触屏没有 hover：让按下的反馈落在 active 上 */
.dscs-fab:active,
.dscs-hbtn:active,
.dscs-chip:active,
.dscs-send:active {
  transform: none;
  border-color: color-mix(in srgb, var(--theme-primary) 62%, var(--border-soft));
  color: var(--accent-deep);
}

@media (prefers-reduced-motion: reduce) {
  .dscs-root *,
  .dscs-fab {
    animation: none !important;
    transition: none !important;
  }
}
