/* ==========================================================
   前台在线客服聊天窗（多主题通用，全部使用 csw- 前缀避免冲突）
   ========================================================== */
.csw {
  --csw-main: #0B63E5;
  --csw-main-dark: #084ec0;
  --csw-main-soft: #EAF2FF;
  --csw-tx: #16233B;
  --csw-sub: #8A94A3;
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 99990;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.csw * { box-sizing: border-box; }

/* ---------- 浮动入口 ---------- */
.csw-entry {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 14px;
  border: 0;
  border-radius: 26px;
  background: linear-gradient(135deg, var(--csw-main), #2c8bf5);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .5px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 10px 26px rgba(11, 99, 229, .34), 0 2px 6px rgba(16, 24, 40, .12);
  transition: transform .18s ease, box-shadow .18s ease;
  outline: none;
}
.csw-entry:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(11, 99, 229, .4); }
.csw-entry:active { transform: translateY(0) scale(.98); }
/* 拖动中：取消悬浮动画与文本选中，光标改为抓取 */
.csw.dragging { user-select: none; -webkit-user-select: none; }
.csw.dragging .csw-entry { cursor: grabbing; transform: none; box-shadow: 0 14px 34px rgba(11, 99, 229, .45); transition: none; }
.csw.dragging .csw-entry:hover { transform: none; }
.csw-entry-ic { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.csw-entry-ic svg { width: 18px; height: 18px; }
.csw-dot {
  position: absolute;
  top: 2px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #F04438;
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

/* ---------- 面板 ---------- */
/* 桌面端由脚本按按钮位置计算 fixed 坐标（跟随拖动、自动避让窗口边缘） */
.csw-panel {
  position: fixed;
  left: auto;
  top: auto;
  right: 22px;
  bottom: 88px;
  width: 372px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: #F7F9FC;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .22), 0 4px 12px rgba(16, 24, 40, .08);
  opacity: 0;
  transform: translateY(14px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .22s cubic-bezier(.4, 0, .2, 1);
  pointer-events: none;
}
.csw-panel.on { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
/* hidden 属性需真正隐藏（display:flex 会覆盖浏览器默认的 [hidden]{display:none}） */
.csw-panel[hidden] { display: none; }

.csw-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--csw-main), #2c8bf5);
  color: #fff;
}
.csw-head-l { display: flex; align-items: center; gap: 10px; min-width: 0; }
.csw-avatar { width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: inline-flex; align-items: center; justify-content: center; flex: none; overflow: hidden; }
.csw-avatar svg { width: 20px; height: 20px; }
.csw-avatar img, .csw-msg .av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.csw-head b { display: block; font-size: 14.5px; line-height: 1.4; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csw-state { display: block; font-size: 11.5px; opacity: .9; line-height: 1.5; }
.csw-state.is-on::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: #6EE7B7; vertical-align: 1px; }
.csw-state.is-off::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: #FCD34D; vertical-align: 1px; }
.csw-close { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .16); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; transition: background .15s; }
.csw-close:hover { background: rgba(255, 255, 255, .28); }
.csw-end { flex: none; height: 28px; padding: 0 10px; border: 1px solid rgba(255, 255, 255, .42); border-radius: 14px; background: transparent; color: #fff; font-size: 11.5px; cursor: pointer; transition: background .15s; }
.csw-end:hover { background: rgba(255, 255, 255, .18); }

/* ---------- 消息区 ---------- */
.csw-body { flex: 1; overflow-y: auto; padding: 14px 14px 6px; -webkit-overflow-scrolling: touch; }
.csw-loading { text-align: center; color: var(--csw-sub); font-size: 12.5px; padding: 26px 0; }
.csw-msg { display: flex; gap: 8px; margin: 12px 0; align-items: flex-start; }
.csw-msg .av { flex: none; width: 32px; height: 32px; border-radius: 50%; background: #fff; border: 1px solid #E4E8EF; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--csw-main); overflow: hidden; }
.csw-msg .wrap { max-width: 76%; }
.csw-msg .bub { padding: 9px 12px; border-radius: 12px 12px 12px 4px; background: #fff; border: 1px solid #E9EDF3; color: #344054; font-size: 13.5px; line-height: 1.72; word-break: break-word; white-space: pre-wrap; box-shadow: 0 1px 2px rgba(16, 24, 40, .03); }
.csw-msg .tm { margin-top: 4px; font-size: 11px; color: #A6B0BF; }
.csw-msg.me { flex-direction: row-reverse; }
.csw-msg.me .av { background: var(--csw-main-soft); border-color: #CFE0FF; }
.csw-msg.me .wrap { text-align: right; }
.csw-msg.me .bub { background: var(--csw-main); border-color: var(--csw-main); color: #fff; border-radius: 12px 12px 4px 12px; box-shadow: 0 3px 10px rgba(11, 99, 229, .22); }
.csw-msg.sys { justify-content: center; }
.csw-msg.sys .av { display: none; }
.csw-msg.sys .wrap { max-width: 88%; text-align: center; }
.csw-msg.sys .bub { background: #EEF1F6; border-color: #E4E8EF; color: #667085; font-size: 12.5px; border-radius: 8px; box-shadow: none; }

/* ---------- 快捷问题 ---------- */
.csw-quick { flex: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 14px 10px; }
.csw-quick button { border: 1px solid #CFE0FF; background: #fff; color: var(--csw-main); border-radius: 14px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; transition: background .15s, border-color .15s; }
.csw-quick button:hover { background: var(--csw-main-soft); border-color: #A8C6FF; }

/* ---------- 输入区 ---------- */
.csw-foot { flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; background: #fff; border-top: 1px solid #EDF0F5; }
.csw-foot textarea {
  flex: 1;
  min-height: 38px;
  max-height: 96px;
  padding: 9px 11px;
  border: 1px solid #DFE4EC;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--csw-tx);
  resize: none;
  outline: none;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  background: #FBFCFE;
}
.csw-foot textarea:focus { border-color: var(--csw-main); box-shadow: 0 0 0 3px rgba(11, 99, 229, .1); background: #fff; }
.csw-send {
  flex: none;
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--csw-main);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.csw-send:hover { background: var(--csw-main-dark); }
.csw-send:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 留言 ---------- */
.csw-leave { flex: none; padding: 12px; background: #fff; border-top: 1px solid #EDF0F5; }
.csw-leave[hidden] { display: none; }
.csw-leave-t { font-size: 12.5px; color: #667085; line-height: 1.7; margin-bottom: 9px; }
.csw-leave input, .csw-leave textarea {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid #DFE4EC;
  border-radius: 8px;
  font-size: 13px;
  color: var(--csw-tx);
  outline: none;
  font-family: inherit;
  resize: none;
  background: #FBFCFE;
}
.csw-leave input:focus, .csw-leave textarea:focus { border-color: var(--csw-main); background: #fff; }
.csw-leave-b { display: flex; gap: 8px; justify-content: flex-end; }
.csw-btn { height: 34px; padding: 0 16px; border: 0; border-radius: 8px; background: var(--csw-main); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.csw-btn:hover { background: var(--csw-main-dark); }
.csw-btn-ghost { height: 34px; padding: 0 14px; border: 1px solid #DFE4EC; border-radius: 8px; background: #fff; color: #475467; font-size: 13px; cursor: pointer; }
.csw-btn-ghost:hover { background: #F5F7FA; }

/* ---------- 评价 ---------- */
.csw-rate { flex: none; padding: 14px; background: #fff; border-top: 1px solid #EDF0F5; }
.csw-rate[hidden] { display: none; }
.csw-rate-t { font-size: 12.5px; color: #667085; margin-bottom: 8px; text-align: center; }
.csw-stars { text-align: center; margin-bottom: 10px; }
.csw-stars span { font-size: 26px; color: #DDE3EC; cursor: pointer; padding: 0 3px; transition: color .12s, transform .12s; display: inline-block; }
.csw-stars span.on { color: #F79009; }
.csw-stars span:hover { transform: scale(1.12); }

/* ---------- 移动端：全屏 ---------- */
@media (max-width: 640px) {
  .csw { right: 14px; bottom: 14px; }
  .csw-entry { width: 52px; height: 52px; padding: 0; justify-content: center; border-radius: 50%; }
  .csw-entry-tx { display: none; }
  .csw-entry-ic { background: transparent; }
  .csw-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    transform: translateY(24px);
  }
  .csw-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .csw-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .csw-foot textarea { font-size: 16px; }
  .csw-leave input, .csw-leave textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .csw-entry, .csw-panel, .csw-stars span { transition: none; }
}