/* =============================================================
   在线客服 Widget - 用户端（Aceternity 风格）
   圆润、渐变蓝、可爱动效、emoji 弹层
   ============================================================= */

/* 隐藏属性兜底（HTML5 hidden 与 display:flex 冲突） */
.cs-widget [hidden] { display: none !important; }

/* ---------- 根容器 + 悬浮按钮 ---------- */
.cs-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  /* ★ 默认隐藏：登录后才由 JS 显示（首屏登录页不出现客服按钮） */
  display: none;
}

.cs-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 10px 28px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s, opacity 0.2s;
  position: relative;
}
.cs-launcher:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 14px 32px rgba(37, 99, 235, 0.5); }
.cs-launcher:active { transform: scale(0.96); }
.cs-launcher svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
/* 打开时切换为折叠图标（↓） */
.cs-ico-collapse { display: none; }
.cs-launcher.cs-active .cs-ico-bubble { display: none; }
.cs-launcher.cs-active .cs-ico-collapse { display: block; }
.cs-launcher.cs-active { transform: rotate(180deg); }

.cs-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

/* ---------- 聊天窗口（默认收起，位于悬浮按钮上方） ---------- */
.cs-window {
  position: fixed;
  right: 20px;
  bottom: 96px;               /* 悬浮按钮（60px 高 + 20px 底距）上方弹出 */
  width: 400px;
  height: 660px;
  max-height: calc(100vh - 116px);
  max-width: calc(100vw - 40px);
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.05);
  /* 收起态：向下+缩小贴回按钮 */
  transform-origin: bottom center;
  transform: translateY(28px) scale(0.4);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.25s ease-out;
}
.cs-window.cs-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ---------- 头部（参考图风格：头像 + 名称 + 状态 + ...） ---------- */
.cs-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
  flex-shrink: 0;
}
.cs-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  position: relative;
}
.cs-header-info { flex: 1; min-width: 0; }
.cs-header-title { font-size: 15px; font-weight: 700; color: #0f172a; display: block; line-height: 1.2; }
.cs-header-sub { font-size: 11.5px; color: #94a3b8; display: block; margin-top: 2px; }
.cs-header-actions { display: flex; align-items: center; gap: 4px; }
.cs-icon-btn {
  border: none;
  background: transparent;
  color: #64748b;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  font-size: 20px;
  line-height: 1;
}
.cs-icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cs-icon-btn:hover { background: #f1f5f9; color: #0f172a; }
.cs-icon-btn.cs-btn-close { font-size: 24px; }
.cs-icon-btn[hidden] { display: none !important; }

/* ---------- 聊天区 ---------- */
.cs-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
}
.cs-msgs { display: flex; flex-direction: column; gap: 8px; }

.cs-msg-row { display: flex; width: 100%; }
.cs-msg-row.from-user { justify-content: flex-end; }
.cs-msg-row.from-agent { justify-content: flex-start; }
.cs-msg-row.from-system { justify-content: center; }

.cs-msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.from-user .cs-msg-bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 6px;
}
.from-agent .cs-msg-bubble {
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 6px;
}
.cs-msg-system {
  background: transparent;
  box-shadow: none;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
  max-width: 92%;
  padding: 4px 10px;
}
.cs-msg-sender { font-size: 11px; color: #64748b; margin-bottom: 3px; font-weight: 600; }
.cs-msg-time { font-size: 10px; opacity: 0.65; margin-left: 6px; white-space: nowrap; }
.from-user .cs-msg-time { color: rgba(255, 255, 255, 0.8); }
.cs-msg-img {
  max-width: 180px;
  max-height: 180px;
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
}
.cs-msg-file { color: #2563eb; text-decoration: underline; }

.cs-loading, .cs-error {
  font-size: 12px;
  color: #94a3b8;
  text-align: center;
  padding: 8px;
}
.cs-error { color: #ef4444; }

/* ---------- 输入栏（圆角蓝色边框风格 + 工具按钮） ---------- */
.cs-footer {
  position: relative;
  padding: 10px 12px 12px;
  background: #fff;
  flex-shrink: 0;
}
.cs-input-shell {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 22px;
  padding: 4px 4px 4px 6px;
  transition: border-color 0.15s, background 0.15s;
}
.cs-input-shell:focus-within {
  border-color: #3b82f6;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}
.cs-tool-btn {
  border: none;
  background: transparent;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 17px;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.cs-tool-btn:hover { background: #e2e8f0; color: #2563eb; }

.cs-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 100px;
  line-height: 1.5;
  color: #0f172a;
}
.cs-input::placeholder { color: #94a3b8; }

.cs-send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.cs-send-btn:hover:not(:disabled) { transform: scale(1.08); }
.cs-send-btn:active:not(:disabled) { transform: scale(0.94); }
.cs-send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.cs-send-btn svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 图片放大（lightbox） ---------- */
.cs-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: cs-fade 0.18s ease-out;
}
.cs-lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
@keyframes cs-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .cs-window.cs-open {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    height: 90vh;
    max-height: none;
  }
  .cs-widget { right: 14px; bottom: 14px; }
}