/* ============================================================================
   8210 · 公开聊天挂件样式（chat.js 专用）
   适用：landing（/）、客户自助页（/c/*）、分享页（/s/*）
   不适用：/staff、/growth
   说明：所有类名统一 cw- 前缀，避免和 app.css / landing.css 冲突；
        不引外部字体与图片，图标全部内联 SVG。
   ========================================================================== */

.cw-root {
  --cw-paper: #faf7f2;
  --cw-paper-2: #f4ede3;
  --cw-ink: #141210;
  --cw-ink-2: #2b2521;
  --cw-ink-3: #4b4038;
  --cw-dim: #7c6c5e;
  --cw-muted: #a3917e;
  --cw-gold: #d7b47a;
  --cw-gold-2: #b8904f;
  --cw-gold-soft: #f7edda;
  --cw-line: #e9ddcc;
  --cw-line-2: #d9c7ae;
  --cw-ok: #4f9468;
  --cw-err: #bd5b4c;
  --cw-r: 16px;
  --cw-font: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", -apple-system, "Segoe UI", Roboto, sans-serif;
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 150;
  font-family: var(--cw-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--cw-ink-2);
  -webkit-tap-highlight-color: transparent;
}
.cw-root[hidden] { display: none !important; }
/* 挂件内部所有 [hidden] 同样强制隐藏 */
.cw-root [hidden] { display: none !important; }
/* 首页底部有移动操作条时，悬浮按钮上移避让 */
.cw-root.cw-raised { bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }

/* ---------- 浮动按钮 ---------- */
.cw-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  margin-left: auto;
  padding: 0;
  border: 1px solid rgba(184, 144, 79, .45);
  border-radius: 50%;
  background: linear-gradient(140deg, #ecd3a4 0%, #d7b47a 48%, #c09755 100%);
  color: #241b10;
  box-shadow: 0 14px 34px rgba(120, 86, 40, .34), 0 2px 8px rgba(0, 0, 0, .12);
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s ease;
}
.cw-fab:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 18px 40px rgba(120, 86, 40, .42); }
.cw-fab:active { transform: translateY(0) scale(.98); }
.cw-fab svg { width: 27px; height: 27px; }
.cw-fab::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid rgba(215, 180, 122, .38);
  pointer-events: none;
}
.cw-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border: 2px solid #fffaf2;
  border-radius: 999px;
  background: #c2543f;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
}
.cw-badge[hidden] { display: none; }

/* ---------- 面板 ---------- */
.cw-panel {
  position: fixed;
  right: 16px;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  width: 372px;
  height: min(620px, calc(100vh - 118px));
  max-height: calc(100vh - 96px);
  overflow: hidden;
  background: #fffdf9;
  border: 1px solid var(--cw-line-2);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(48, 32, 16, .28), 0 4px 14px rgba(48, 32, 16, .1);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(.985);
  transform-origin: bottom right;
  transition: opacity .24s ease, transform .24s ease, visibility .24s;
}
.cw-root.is-open .cw-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

/* ---------- 头部 ---------- */
.cw-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background:
    radial-gradient(220px 120px at 90% 0%, rgba(150, 108, 54, .5) 0%, transparent 70%),
    linear-gradient(135deg, #1d1814 0%, #2b2320 100%);
  color: #f4ece1;
}
.cw-avatar {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(215, 180, 122, .55);
  background: radial-gradient(circle at 32% 28%, #f2ddb4, #d7b47a 70%);
  color: #2b1f0f;
  font-family: Georgia, "Songti SC", "SimSun", serif;
  font-size: 14px;
  font-weight: 700;
}
.cw-head-txt { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cw-head-txt strong {
  font-size: 14px;
  font-weight: 600;
  color: #f7efe3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: #bcae9c; }
.cw-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--cw-gold);
  box-shadow: 0 0 0 3px rgba(215, 180, 122, .18);
}
.cw-dot.is-bot { background: #e0b96e; }
.cw-dot.is-human { background: #79c494; box-shadow: 0 0 0 3px rgba(121, 196, 148, .18); }
.cw-dot.is-closed { background: #a3917e; box-shadow: none; }
.cw-head-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.cw-hbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 9px;
  background: rgba(255, 255, 255, .06);
  color: #e7dccd;
  font-size: 13px;
  line-height: 1;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}
.cw-hbtn:hover { background: rgba(255, 255, 255, .14); border-color: rgba(215, 180, 122, .55); color: #fff; }
.cw-hbtn:disabled { opacity: .5; cursor: not-allowed; }
.cw-hbtn.cw-handoff { font-size: 11.5px; padding: 0 9px; color: #e8cb9a; }

/* ---------- 消息区 ---------- */
.cw-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 13px 8px;
  background:
    radial-gradient(320px 180px at 100% 0%, rgba(240, 224, 197, .5) 0%, transparent 70%),
    linear-gradient(180deg, #fbf7f0 0%, #f8f2e8 100%);
  scrollbar-width: thin;
  scrollbar-color: var(--cw-line-2) transparent;
}
.cw-log::-webkit-scrollbar { width: 5px; }
.cw-log::-webkit-scrollbar-thumb { background: var(--cw-line-2); border-radius: 99px; }
.cw-log:focus { outline: none; }

.cw-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; margin-bottom: 12px; }
.cw-msg.is-user { align-items: flex-end; }
.cw-msg.is-system { align-items: center; }
.cw-bubble {
  max-width: 88%;
  padding: 9px 12px;
  border: 1px solid var(--cw-line);
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  color: var(--cw-ink-2);
  font-size: 13.5px;
  line-height: 1.68;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 8px rgba(64, 44, 24, .04);
}
.cw-msg.is-user .cw-bubble {
  border-color: transparent;
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, #ecd3a4 0%, #d7b47a 100%);
  color: #241b10;
}
.cw-msg.is-staff .cw-bubble { border-color: rgba(184, 144, 79, .45); background: #fffdf7; }
.cw-who {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--cw-gold-2);
}
.cw-time { margin-top: 4px; font-size: 9.5px; color: var(--cw-muted); }
.cw-msg.is-user .cw-time { text-align: right; }
.cw-system {
  max-width: 90%;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(20, 18, 16, .07);
  color: var(--cw-dim);
  font-size: 10.5px;
  line-height: 1.6;
  text-align: center;
}
.cw-msg.is-error .cw-system { background: rgba(189, 91, 76, .1); color: #a4483a; }

/* 消息内图片 / 语音 */
.cw-img {
  display: block;
  max-width: 190px;
  max-height: 190px;
  margin-top: 6px;
  border-radius: 10px;
  border: 1px solid var(--cw-line);
  object-fit: cover;
  cursor: zoom-in;
  background: linear-gradient(145deg, #f5e8d3, #ddc39e);
}
.cw-audio { display: block; width: 210px; max-width: 100%; height: 34px; margin-top: 6px; }
.cw-msg.is-user .cw-img { border-color: rgba(36, 27, 16, .18); }

/* 建议快捷语 */
.cw-sugs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; max-width: 92%; }
.cw-sug {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--cw-line-2);
  border-radius: 999px;
  background: #fffdf9;
  color: var(--cw-gold-2);
  font-size: 11.5px;
  transition: .18s ease;
}
.cw-sug:hover { border-color: var(--cw-gold); background: var(--cw-gold-soft); }

/* 消息卡片（套餐/案例等） */
.cw-cards { display: flex; flex-direction: column; gap: 7px; margin-top: 7px; max-width: 92%; }
.cw-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cw-line-2);
  border-radius: 12px;
  background: #fffdf9;
  text-align: left;
  transition: .18s ease;
}
.cw-card:hover { border-color: var(--cw-gold); background: var(--cw-gold-soft); }
.cw-card-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cw-card-title { font-size: 12.5px; font-weight: 700; color: var(--cw-ink); }
.cw-card-desc { font-size: 11px; line-height: 1.5; color: var(--cw-dim); }
.cw-card-arrow { margin-left: auto; flex: none; color: var(--cw-gold-2); font-size: 16px; }

/* ---------- 快捷问题 ---------- */
.cw-quick {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 13px 10px;
  background: #f8f2e8;
}
.cw-quick[hidden] { display: none; }
.cw-quick-title { font-size: 10px; letter-spacing: .1em; color: var(--cw-muted); }
.cw-quick-list { display: flex; flex-direction: column; gap: 6px; }
.cw-quick-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid var(--cw-line);
  border-radius: 11px;
  background: #fffdf9;
  color: var(--cw-ink-3);
  font-size: 12.5px;
  text-align: left;
  transition: .18s ease;
}
.cw-quick-btn::before { content: "💬"; font-size: 12px; opacity: .7; }
.cw-quick-btn:hover { border-color: var(--cw-gold); color: var(--cw-gold-2); background: var(--cw-gold-soft); }
.cw-root.is-chatting .cw-quick { display: none; }

/* ---------- 待发送附件 ---------- */
.cw-pending {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 13px 0;
  border-top: 1px solid var(--cw-line);
  background: #fffdf9;
}
.cw-pending[hidden] { display: none; }
.cw-pend {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
  padding: 4px 7px;
  border: 1px solid var(--cw-line);
  border-radius: 9px;
  background: var(--cw-paper);
  font-size: 10.5px;
  color: var(--cw-dim);
}
.cw-pend img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.cw-pend .cw-pend-ico {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--cw-gold-soft);
  color: var(--cw-gold-2);
}
.cw-pend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-pend-del {
  flex: none;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--cw-line);
  color: var(--cw-dim);
  font-size: 11px;
  line-height: 1;
}
.cw-pend-del:hover { background: var(--cw-err); color: #fff; }

/* ---------- 输入区 ---------- */
.cw-compose {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 9px 11px;
  border-top: 1px solid var(--cw-line);
  background: #fffdf9;
}
.cw-tools { display: flex; gap: 2px; padding-bottom: 3px; }
.cw-tool {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--cw-dim);
  transition: .18s ease;
}
.cw-tool:hover { background: var(--cw-gold-soft); color: var(--cw-gold-2); border-color: var(--cw-line); }
.cw-tool svg { width: 18px; height: 18px; }
.cw-compose textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 38px;
  max-height: 96px;
  padding: 8px 12px;
  border: 1px solid var(--cw-line-2);
  border-radius: 13px;
  background: var(--cw-paper);
  color: var(--cw-ink);
  font-family: var(--cw-font);
  font-size: 13.5px;
  line-height: 1.55;
  resize: none;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.cw-compose textarea::placeholder { color: var(--cw-muted); }
.cw-compose textarea:focus { border-color: var(--cw-gold); background: #fff; box-shadow: 0 0 0 3px rgba(215, 180, 122, .16); }
.cw-send {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(184, 144, 79, .5);
  border-radius: 50%;
  background: linear-gradient(135deg, #ecd3a4, #d7b47a 55%, #c09755);
  color: #241b10;
  transition: .18s ease;
}
.cw-send:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(184, 144, 79, .3); }
.cw-send:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.cw-send svg { width: 19px; height: 19px; }

/* ---------- 联系 / 复制 ---------- */
.cw-contact {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding: 7px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--cw-line);
  background: #f8f2e8;
}
.cw-call {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--cw-line-2);
  border-radius: 999px;
  background: #fffdf9;
  color: var(--cw-ink-3);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.cw-call:hover { border-color: var(--cw-gold); color: var(--cw-gold-2); }
.cw-call svg { width: 14px; height: 14px; color: var(--cw-gold-2); }
.cw-copy {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--cw-gold-2);
  font-size: 11px;
  white-space: nowrap;
}
.cw-copy:hover { background: var(--cw-gold-soft); }
.cw-contact-note { margin-left: auto; font-size: 9.5px; color: var(--cw-muted); white-space: nowrap; }

/* ---------- 留资小表单 ---------- */
.cw-lead {
  margin: 4px 0 12px;
  padding: 13px;
  border: 1px solid rgba(184, 144, 79, .4);
  border-radius: 14px;
  background: linear-gradient(180deg, #fffdf8 0%, #fdf6ea 100%);
  box-shadow: 0 6px 18px rgba(184, 144, 79, .1);
}
.cw-lead-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 9px; }
.cw-lead-head strong { font-size: 13px; color: var(--cw-ink); }
.cw-lead-head span { font-size: 10.5px; line-height: 1.55; color: var(--cw-dim); }
.cw-lead-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.cw-lead-field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 7px; }
.cw-lead-field span { font-size: 10.5px; color: var(--cw-dim); }
.cw-lead-field input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--cw-line-2);
  border-radius: 9px;
  background: #fff;
  font-family: var(--cw-font);
  font-size: 12.5px;
  outline: none;
}
.cw-lead-field input:focus { border-color: var(--cw-gold); box-shadow: 0 0 0 3px rgba(215, 180, 122, .16); }
.cw-lead-consent { display: flex; align-items: flex-start; gap: 6px; margin: 2px 0 9px; font-size: 10px; line-height: 1.55; color: var(--cw-muted); }
.cw-lead-consent input { flex: none; width: 15px; height: 15px; margin: 0; accent-color: var(--cw-gold-2); }
.cw-lead-submit {
  width: 100%;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(135deg, #e8cb9a, #d7b47a 50%, #c29a59);
  color: #241b10;
  font-size: 12.5px;
  font-weight: 700;
}
.cw-lead-submit:disabled { opacity: .6; cursor: not-allowed; }
.cw-lead-err { margin-top: 6px; font-size: 10.5px; color: var(--cw-err); }
.cw-lead-done { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; margin: 4px 0 12px; border: 1px solid rgba(79, 148, 104, .35); border-radius: 12px; background: rgba(79, 148, 104, .07); color: #3d7a53; font-size: 11.5px; line-height: 1.6; }
.cw-lead-done::before { content: "✓"; font-weight: 700; }

/* ---------- Toast ---------- */
.cw-toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  z-index: 160;
  max-width: min(84vw, 380px);
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(20, 18, 16, .95);
  border: 1px solid rgba(215, 180, 122, .35);
  color: #f7efe3;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 8px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  pointer-events: none;
}
.cw-toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.cw-toast.is-error { border-color: rgba(189, 91, 76, .6); }

/* ---------- 移动端：半屏面板 ---------- */
@media (max-width: 640px) {
  .cw-root { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .cw-root.cw-raised { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .cw-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 72vh;
    max-height: calc(100vh - 72px);
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    transform: translateY(102%);
    transform-origin: bottom center;
    box-shadow: 0 -20px 60px rgba(48, 32, 16, .3);
  }
  .cw-root.is-open .cw-panel { transform: translateY(0); }
  .cw-root.is-open .cw-fab { opacity: 0; pointer-events: none; transform: scale(.9); }
  .cw-head { padding-top: max(13px, env(safe-area-inset-top, 0px)); }
  .cw-log { padding: 12px 12px 6px; }
  .cw-contact { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .cw-toast { bottom: calc(26px + env(safe-area-inset-bottom, 0px)); }
  .cw-quick-btn { min-height: 42px; }
  .cw-fab { width: 56px; height: 56px; }
}

@media (min-width: 641px) {
  .cw-quick-title { display: block; }
}

/* 打开状态下窄屏禁止背景滚动（由 JS 加 body 类） */
body.cw-lock { overflow: hidden; }

/* 动效降级 */
@media (prefers-reduced-motion: reduce) {
  .cw-panel, .cw-fab, .cw-toast, .cw-tool, .cw-send, .cw-hbtn { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}
