/* 智能客服 */
.cs-root { position: fixed; right: 22px; bottom: 24px; z-index: 90; font-family: var(--font); }
.cs-launch {
  display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 18px 0 14px;
  border-radius: 999px; border: 0; cursor: pointer; color: #fff; font-size: 14px; font-weight: 700;
  background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7));
  box-shadow: 0 12px 28px rgba(52, 120, 229, .35); transition: transform .18s, box-shadow .18s;
}
.cs-launch:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(52, 120, 229, .42); }
.cs-launch-icon { display: grid; place-items: center; }
.cs-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

.cs-panel {
  position: absolute; right: 0; bottom: 62px; width: 380px; max-height: min(640px, calc(100vh - 120px));
  display: flex; flex-direction: column; overflow: hidden;
  background: #fff; border: 1px solid #e1e7f0; border-radius: 18px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .18);
  animation: csIn .2s ease both;
}
@keyframes csIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.cs-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #edf1f7; background: linear-gradient(120deg, #f2f7ff, #f7f4ff); }
.cs-avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800; background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7)); }
.cs-head-main { display: flex; flex-direction: column; line-height: 1.35; }
.cs-head-main b { font-size: 14.5px; color: #0f1a2b; }
.cs-status { font-size: 11.5px; color: #6a778d; }
.cs-icon-btn { margin-left: auto; width: 30px; height: 30px; border: 0; border-radius: 9px; background: transparent; color: #59677b; cursor: pointer; display: grid; place-items: center; }
.cs-icon-btn:hover { background: #e8eef9; }

.cs-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #fbfcff; }
.cs-msg { display: flex; gap: 8px; align-items: flex-start; }
.cs-msg.user { flex-direction: row-reverse; }
.cs-bubble { max-width: 78%; padding: 10px 12px; border-radius: 14px; font-size: 13.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.cs-msg.bot .cs-bubble { background: #fff; border: 1px solid #e6ecf6; color: #243247; border-top-left-radius: 6px; }
.cs-msg.user .cs-bubble { background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7)); color: #fff; border-top-right-radius: 6px; }
.cs-msg.agent .cs-bubble { background: #eefbf3; border: 1px solid #cdebd8; color: #14532d; border-top-left-radius: 6px; }
.cs-mini { width: 26px; height: 26px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7)); }
.cs-msg.user .cs-mini { display: none; }

.cs-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.cs-card {
  border: 1px solid #e6ecf6; border-radius: 12px; background: #fff; padding: 10px 12px;
  transition: border-color .16s, transform .16s;
}
.cs-card:hover { border-color: #bcd4f7; transform: translateY(-1px); }
.cs-card-top { display: flex; align-items: center; gap: 8px; }
.cs-card-logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 800; background: #3478e5; flex: none; }
.cs-card-title { font-size: 13.5px; font-weight: 700; color: #0f1a2b; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-card-price { font-size: 14px; font-weight: 800; color: #f43f5e; }
.cs-card-desc { margin-top: 6px; font-size: 12px; color: #6a778d; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cs-card-actions { display: flex; gap: 8px; margin-top: 8px; }
.cs-card-actions a {
  flex: 1; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; text-decoration: none;
  background: #edf5ff; color: #2463c7;
}
.cs-card-actions a.primary { background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7)); color: #fff; }

.cs-quick { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; border-top: 1px solid #edf1f7; background: #fff; }
.cs-quick:empty { display: none; }
.cs-chip { flex: none; height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid #dbe6f7; background: #fff; color: #3478e5; font-size: 12px; cursor: pointer; }
.cs-chip:hover { background: #edf5ff; }

.cs-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid #edf1f7; background: #fff; }
.cs-form textarea {
  flex: 1; resize: none; max-height: 88px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid #dbe6f7; font: inherit; font-size: 13px; line-height: 1.5; color: #0f1a2b; background: #fff;
}
.cs-form textarea:focus { outline: none; border-color: #3478e5; box-shadow: 0 0 0 3px rgba(52, 120, 229, .12); }
.cs-send { width: 40px; border: 0; border-radius: 10px; background: var(--grad-brand, linear-gradient(120deg, #3478e5, #6c5ce7)); color: #fff; cursor: pointer; display: grid; place-items: center; }
.cs-send:disabled { opacity: .5; cursor: default; }
.cs-foot { padding: 0 12px 10px; font-size: 10.5px; color: #93a1b5; background: #fff; }

.cs-typing { display: inline-flex; gap: 3px; padding: 12px 14px; }
.cs-typing i { width: 5px; height: 5px; border-radius: 50%; background: #9db6da; animation: csDot 1.1s infinite; }
.cs-typing i:nth-child(2) { animation-delay: .15s; }
.cs-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes csDot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* 手机：全屏面板 + 底部 dock 上方 */
@media (max-width: 900px) {
  .cs-root { right: 14px; bottom: 86px; }
  .cs-launch { width: 46px; height: 46px; padding: 0; justify-content: center; }
  .cs-launch-text { display: none; }
  .cs-panel {
    position: fixed; inset: 0 0 0 0; width: auto; max-height: none; border-radius: 0; border: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .cs-panel { animation: csInMobile .22s ease both; }
  @keyframes csInMobile { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
}
@media (max-width: 900px) {
  .cs-body { padding: 12px 12px 90px; }
}

/* 深色 */
html[data-theme="dark"] .cs-panel { background: #0f1a2b; border-color: #22304a; }
html[data-theme="dark"] .cs-head { background: linear-gradient(120deg, #142134, #171a33); border-bottom-color: #22304a; }
html[data-theme="dark"] .cs-head-main b { color: #e9f0fb; }
html[data-theme="dark"] .cs-status { color: #93a6c0; }
html[data-theme="dark"] .cs-icon-btn { color: #b9c9e0; }
html[data-theme="dark"] .cs-icon-btn:hover { background: #1b2a42; }
html[data-theme="dark"] .cs-body { background: #0b1422; }
html[data-theme="dark"] .cs-msg.bot .cs-bubble { background: #16233a; border-color: #24344f; color: #dbe7f7; }
html[data-theme="dark"] .cs-msg.agent .cs-bubble { background: #14291f; border-color: #245038; color: #bdf0d0; }
html[data-theme="dark"] .cs-card { background: #131f33; border-color: #24344f; }
html[data-theme="dark"] .cs-card-title { color: #e9f0fb; }
html[data-theme="dark"] .cs-card-desc { color: #94a7c0; }
html[data-theme="dark"] .cs-card-actions a { background: #1b2c46; color: #9dc3f5; }
html[data-theme="dark"] .cs-quick { background: #0f1a2b; border-top-color: #22304a; }
html[data-theme="dark"] .cs-chip { background: #131f33; border-color: #24344f; color: #9dc3f5; }
html[data-theme="dark"] .cs-form { background: #0f1a2b; border-top-color: #22304a; }
html[data-theme="dark"] .cs-form textarea { background: #131f33; border-color: #24344f; color: #e9f0fb; }
html[data-theme="dark"] .cs-foot { background: #0f1a2b; color: #6c819c; }

/* 布局兜底：气泡与卡片不许撑破面板 */
.cs-panel { overflow: hidden; }
.cs-body { min-height: 0; }
.cs-msg { width: 100%; max-width: 100%; min-width: 0; }
.cs-bubble { max-width: 82%; min-width: 0; overflow-wrap: anywhere; }
.cs-cards, .cs-card { max-width: 100%; min-width: 0; box-sizing: border-box; }
.cs-card { overflow: hidden; }
.cs-card-top { min-width: 0; }
.cs-card-title { min-width: 0; }
.cs-card-actions { flex-wrap: wrap; }
.cs-card-actions a { flex: 1 1 0; min-width: 96px; }

/* 气泡是 pre-wrap，卡片里必须恢复正常换行，否则模板缩进会变成空行把卡片撑高 */
.cs-cards, .cs-card, .cs-card * { white-space: normal; }
.cs-card-desc { -webkit-line-clamp: 2; }

/* hidden 属性必须真的隐藏（作者样式的 display:flex 会覆盖 UA 的 [hidden]） */
.cs-panel[hidden] { display: none !important; }
.cs-launch[hidden] { display: none !important; }

/* 面板给固定高度，消息多了只滚消息区，不把输入栏挤出面板 */
.cs-panel { height: min(640px, calc(100vh - 120px)); max-height: min(640px, calc(100vh - 120px)); }
.cs-body { flex: 1 1 auto; min-height: 0; }
.cs-quick, .cs-form, .cs-foot { flex: none; }

@media (max-width: 640px) {
  .cs-panel { height: 100%; max-height: 100%; }
  .cs-body { padding-bottom: 12px; }
}
