/* 在线咨询：高端轻奢聊天组件（.cw）
 * 设计要点：深蓝渐变头部 + 玻璃质感 + 柔和阴影 + 大圆角气泡
 */
.cw {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 99990;
  width: 0;
  pointer-events: none;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

.cw-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  display: none;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: min(560px, calc(100vh - 150px));
  max-height: calc(100vh - 150px);
  overflow: hidden;
  background: #fff;
  border-radius: 20px;
  border: 1px solid rgba(15, 32, 56, .06);
  box-shadow: 0 32px 72px -18px rgba(12, 28, 52, .42), 0 2px 8px rgba(12, 28, 52, .06);
  pointer-events: auto;
  transform-origin: bottom right;
  animation: cw-panel-in .26s cubic-bezier(.2, .8, .3, 1);
}
.cw-panel.is-open { display: flex; }
@keyframes cw-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 头部 */
.cw-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #16233a 0%, #22395f 60%, #2a4a7c 100%);
  color: #fff;
  overflow: hidden;
}
.cw-head::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -60px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(90, 170, 255, .28), transparent 70%);
  pointer-events: none;
}
.cw-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 42px;
  border: 2px solid rgba(255, 255, 255, .35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
}
.cw-meta { flex: 1 1 auto; min-width: 0; position: relative; z-index: 1; }
.cw-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
  letter-spacing: .2px;
}
.cw-status {
  position: relative;
  padding-left: 12px;
  color: #7ee2a8;
  font-size: 12px;
  font-weight: 400;
}
.cw-status::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: #2fc25b;
  box-shadow: 0 0 0 3px rgba(47, 194, 91, .22);
}
.cw-status.is-offline { color: #c8d0da; }
.cw-status.is-offline::before { background: #8c97a5; box-shadow: 0 0 0 3px rgba(140, 151, 165, .22); }
.cw-sub {
  margin: 4px 0 0;
  color: rgba(226, 235, 248, .72);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-close {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}
.cw-close:hover { background: rgba(255, 255, 255, .26); transform: rotate(90deg); }

/* 消息区 */
.cw-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 14px;
  background: linear-gradient(180deg, #f7f9fc 0%, #eef3f9 100%);
  box-shadow: inset 0 8px 16px -12px rgba(16, 32, 56, .16);
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 140, 165, .35) transparent;
}
.cw-body::-webkit-scrollbar { width: 6px; }
.cw-body::-webkit-scrollbar-thumb { background: rgba(120, 140, 165, .32); border-radius: 3px; }
.cw-body::-webkit-scrollbar-track { background: transparent; }
.cw-messages {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cw-msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  max-width: 100%;
}
.cw-msg.is-me { flex-direction: row-reverse; }
.cw-msg.is-system { justify-content: center; }
.cw-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 32px;
  border: 1px solid rgba(15, 32, 56, .08);
  box-shadow: 0 2px 6px rgba(15, 32, 56, .1);
}
.cw-bubble {
  max-width: 76%;
  padding: 11px 14px 8px;
  background: #fff;
  border: 1px solid rgba(15, 32, 56, .06);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 6px 16px -6px rgba(16, 32, 56, .16), 0 1px 2px rgba(16, 32, 56, .04);
}
.cw-bubble p {
  margin: 0;
  color: #1d2b3f;
  font-size: 14px;
  line-height: 21px;
  word-break: break-word;
}
.cw-bubble time {
  display: block;
  margin-top: 5px;
  color: #9aa7b8;
  font-size: 10.5px;
  line-height: 14px;
  text-align: right;
}
.cw-msg.is-me .cw-bubble {
  background: linear-gradient(135deg, #3d8bfd 0%, #0066cf 100%);
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 8px 20px -8px rgba(0, 102, 207, .55);
}
.cw-msg.is-me .cw-bubble p { color: #fff; }
.cw-msg.is-me .cw-bubble time { color: rgba(255, 255, 255, .75); }
.cw-msg.is-failed .cw-bubble { background: #fdecec; border-color: #f5c2c2; }
.cw-msg.is-failed .cw-bubble p { color: #c0392b; }

/* 会话结束提示 */
.cw-ended-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 6px auto;
}
.cw-ended-tip {
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(120, 140, 165, .12);
  color: #5b6c82;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}
.cw-restart {
  height: 34px;
  padding: 0 18px;
  border: 0;
  border-radius: 17px;
  background: linear-gradient(135deg, #3d8bfd 0%, #0066cf 100%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px -8px rgba(0, 102, 207, .6);
  transition: transform .2s ease, filter .2s ease;
}
.cw-restart:hover { transform: translateY(-1px); filter: brightness(1.06); }

/* 输入区 */
.cw-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px;
  background: #fff;
  border-top: 1px solid rgba(15, 32, 56, .06);
}
.cw-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(15, 32, 56, .1);
  border-radius: 21px;
  background: #f2f5fa;
  color: #1d2b3f;
  font-size: 14px;
  outline: none;
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
.cw-input::placeholder { color: #98a5b7; }
.cw-input:focus {
  border-color: #0066cf;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 102, 207, .1);
}
.cw-input:disabled { background: #f2f5fa; color: #98a5b7; cursor: not-allowed; }
.cw-send {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 21px;
  background: linear-gradient(135deg, #3d8bfd 0%, #0066cf 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px -8px rgba(0, 102, 207, .6);
  transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
}
.cw-send:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 12px 22px -8px rgba(0, 102, 207, .66); }
.cw-send:disabled { background: #c3cedd; box-shadow: none; cursor: not-allowed; transform: none; }

/* 启动器 */
.cw-launcher {
  position: fixed;
  right: 24px;
  bottom: 32px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 25px;
  background: linear-gradient(135deg, #3d8bfd 0%, #0066cf 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
  cursor: pointer;
  box-shadow: 0 14px 30px -10px rgba(0, 102, 207, .6), 0 2px 6px rgba(0, 102, 207, .2);
  pointer-events: auto;
  transition: transform .22s ease, box-shadow .22s ease, filter .22s ease;
}
.cw-launcher:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: 0 20px 38px -12px rgba(0, 102, 207, .66), 0 2px 6px rgba(0, 102, 207, .2);
}
.cw-launcher svg { width: 20px; height: 20px; fill: currentColor; }
.cw.is-open .cw-launcher { display: none; }

/* 未读气泡：客服回复时出现 */
.cw-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: 11px;
  background: linear-gradient(135deg, #ff5f5f 0%, #e53935 100%);
  border: 2px solid #fff;
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 10px rgba(229, 57, 53, .45);
  animation: cw-badge-pulse 1.8s ease-in-out infinite;
}
@keyframes cw-badge-pulse {
  0%, 100% { box-shadow: 0 4px 10px rgba(229, 57, 53, .45); }
  50% { box-shadow: 0 0 0 6px rgba(229, 57, 53, .16), 0 4px 10px rgba(229, 57, 53, .45); }
}

/* 提示气泡：玻璃质感 */
.cw-toast {
  position: fixed;
  right: 24px;
  bottom: 96px;
  max-width: 260px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(18, 31, 51, .92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  box-shadow: 0 18px 40px -12px rgba(6, 16, 30, .55);
  pointer-events: auto;
  z-index: 9999;
  animation: cw-toast-in .3s cubic-bezier(.2, .8, .3, 1);
}
@keyframes cw-toast-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 768px) {
  .cw-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 78vh;
    max-height: none;
    border-radius: 22px 22px 0 0;
  }
  .cw-launcher { right: 16px; bottom: 20px; }
  .cw-toast { right: 16px; bottom: 88px; left: 16px; max-width: none; }
}
