/* ============================================================
 * 客服挂件样式 —— 对接 js/script.js 的 DOM 契约
 * 类名/ID 与 script.js 一一对应；配色沿用 index 主题变量。
 * 旧落地页的挂件 CSS 已丢失，这里按契约重建。
 * ============================================================ */

/* ---------- 浮动客服按钮 ---------- */
.cs-fab{
  position:fixed; right:22px; bottom:22px; z-index:900;
  width:60px; height:60px; border-radius:50%; border:none; cursor:pointer;
  background:linear-gradient(135deg,var(--rose),var(--amber-deep));
  color:#fff; display:flex; align-items:center; justify-content:center;
  box-shadow:0 12px 30px -8px rgba(255,77,109,.7);
  transition:transform .15s ease, box-shadow .25s ease;
}
.cs-fab:hover{ transform:translateY(-3px) scale(1.04); box-shadow:0 18px 38px -8px rgba(255,77,109,.85); }
.cs-fab svg{ width:28px; height:28px; }
.cs-fab::after{
  content:""; position:absolute; top:-2px; right:-2px;
  width:13px; height:13px; border-radius:50%; background:var(--amber);
  border:2px solid var(--curtain);
  box-shadow:0 0 0 0 rgba(246,194,107,.6); animation:pulse 2s infinite;
}

/* ---------- 聊天弹窗 overlay ---------- */
.chat-modal{
  position:fixed; inset:0; z-index:1000; display:none;
  align-items:center; justify-content:center; padding:20px;
  background:rgba(10,4,16,.72); backdrop-filter:blur(6px);
}
.chat-modal.active{ display:flex; }
.chat-card{
  width:100%; max-width:420px; height:min(640px,88vh);
  background:var(--curtain-2); border:1px solid var(--line);
  border-radius:20px; overflow:hidden; display:flex; flex-direction:column;
  box-shadow:0 30px 80px -20px rgba(0,0,0,.7);
}

/* ---------- 顶部条 ---------- */
.chat-head{
  display:flex; align-items:center; gap:12px; padding:16px 18px;
  background:linear-gradient(135deg,var(--plum),var(--plum-2));
  border-bottom:1px solid var(--line);
}
.chat-modal.chat-mode .chat-head--intro{ display:none; }
.chat-head .ava{
  width:40px; height:40px; border-radius:50%; flex:0 0 auto;
  display:flex; align-items:center; justify-content:center;
  font-family:var(--serif); font-weight:700; color:#fff;
  background:linear-gradient(135deg,var(--rose),var(--amber-deep));
}
.chat-head .who{ flex:1; min-width:0; }
.chat-head .who b{ display:block; font-size:.98rem; color:var(--cream); }
.chat-head .who small{ font-size:.72rem; color:var(--amber); display:flex; align-items:center; gap:.4em; }
.chat-head .who small::before{ content:""; width:7px; height:7px; border-radius:50%; background:#3ddc84; }
.chat-x{
  background:transparent; border:none; color:var(--mist); cursor:pointer;
  font-size:1.5rem; line-height:1; width:32px; height:32px; border-radius:8px;
}
.chat-x:hover{ background:rgba(255,255,255,.08); color:var(--cream); }

/* ---------- 表单态 ---------- */
/* chat-body 必须是 flex 纵向容器，子级聊天界面才能撑满高度、把输入框钉在底部 */
.chat-body{ flex:1; min-height:0; display:flex; flex-direction:column; }

/* 隐藏聊天区滚动条（仍可滚动，只是不显示滚动条） */
.chat-body, #chatMessages{ scrollbar-width:none; -ms-overflow-style:none; }
.chat-body::-webkit-scrollbar, #chatMessages::-webkit-scrollbar{ width:0; height:0; display:none; }
#chatFormContainer{ padding:22px 20px; overflow-y:auto; }
#chatFormContainer.hidden{ display:none; }
.chat-form-intro{ color:var(--mist); font-size:.9rem; margin-bottom:18px; }
.cs-field{ margin-bottom:14px; }
.cs-field label{ display:block; font-size:.82rem; color:var(--cream); margin-bottom:6px; }
.cs-field input, .cs-field textarea{
  width:100%; background:var(--curtain); border:1px solid var(--line);
  border-radius:10px; padding:11px 13px; color:var(--cream); font:inherit; font-size:.92rem;
}
.cs-field input:focus, .cs-field textarea:focus{ outline:none; border-color:var(--amber); }
.cs-field textarea{ resize:vertical; min-height:70px; }
.cs-start-btn{
  width:100%; margin-top:6px; border:none; cursor:pointer;
  background:var(--rose); color:#fff; font-weight:700; font-size:.98rem;
  border-radius:999px; padding:14px; box-shadow:0 8px 26px -8px rgba(255,77,109,.7);
}
.cs-start-btn:hover{ transform:translateY(-1px); }

/* ---------- 连接态 ---------- */
#connectingContainer, #successContainer{ display:none; padding:46px 24px; text-align:center; }
#connectingContainer.active, #successContainer.active{ display:block; }
.cs-spinner{
  width:46px; height:46px; margin:0 auto 20px; border-radius:50%;
  border:3px solid var(--line); border-top-color:var(--amber); animation:cs-spin 1s linear infinite;
}
@keyframes cs-spin{ to{ transform:rotate(360deg); } }
.cs-connect-text{ color:var(--mist); font-size:.95rem; }
#successContainer .ava{
  width:64px; height:64px; border-radius:50%; margin:0 auto 14px;
  display:flex; align-items:center; justify-content:center;
  font-family:var(--serif); font-weight:700; font-size:1.5rem; color:#fff;
  background:linear-gradient(135deg,var(--rose),var(--amber-deep));
}
#successContainer b{ color:var(--cream); font-size:1.05rem; }
#successContainer p{ color:var(--mist); font-size:.88rem; margin:8px 0 20px; }

/* ---------- 聊天界面态 ---------- */
#chatInterfaceContainer{ display:none; flex:1; min-height:0; flex-direction:column; }
#chatInterfaceContainer.active{ display:flex; }
#chatMessages{
  flex:1; overflow-y:auto; padding:18px; display:flex; flex-direction:column; gap:10px;
  background:var(--curtain);
}
.chat-message{
  max-width:78%; padding:10px 14px; border-radius:14px; font-size:.92rem;
  line-height:1.5; word-wrap:break-word; white-space:normal;
}
.chat-message.agent{ align-self:flex-start; background:var(--plum-2); color:var(--cream); border-bottom-left-radius:4px; }
.chat-message.user{ align-self:flex-end; background:var(--rose); color:#fff; border-bottom-right-radius:4px; }
.chat-message.image-message{ padding:4px; }
.chat-message.image-message img{ max-width:200px; border-radius:10px; display:block; cursor:pointer; }
.image-loading{ display:flex; align-items:center; gap:8px; color:var(--mist); font-size:.85rem; padding:6px; }
.loading-spinner-small{
  width:16px; height:16px; border-radius:50%;
  border:2px solid var(--line); border-top-color:var(--amber); animation:cs-spin .8s linear infinite;
}

/* 客服正在输入 */
.chat-typing, .typing-indicator-visitor{ align-self:flex-start; }
.typing-indicator-visitor .typing-dots, .chat-typing{
  display:inline-flex; gap:4px; padding:12px 14px; background:var(--plum-2); border-radius:14px; border-bottom-left-radius:4px;
}
.chat-typing span, .typing-indicator-visitor .typing-dots span{
  width:7px; height:7px; border-radius:50%; background:var(--mist); animation:cs-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2), .typing-indicator-visitor .typing-dots span:nth-child(2){ animation-delay:.2s; }
.chat-typing span:nth-child(3), .typing-indicator-visitor .typing-dots span:nth-child(3){ animation-delay:.4s; }
@keyframes cs-bounce{ 0%,60%,100%{ transform:translateY(0); opacity:.5; } 30%{ transform:translateY(-5px); opacity:1; } }

/* 已发送提示 */
.sent-indicator{ align-self:flex-end; font-size:.7rem; color:var(--mist-dim); }
.sent-indicator::before{ content:"✓ Terkirim"; }

/* ---------- 输入栏 ---------- */
.chat-input-bar{
  display:flex; align-items:center; gap:6px; padding:12px 12px;
  border-top:1px solid var(--line); background:var(--curtain-2); position:relative;
}
.chat-action-btn{
  background:transparent; border:none; cursor:pointer; color:var(--mist);
  width:34px; height:34px; border-radius:8px; font-size:1.2rem; flex:0 0 auto;
}
.chat-action-btn:hover{ background:rgba(255,255,255,.08); color:var(--amber); }
#chatInput{
  /* min-width:0 关键：让输入框可收缩，否则窄屏会把发送按钮挤出边界被裁掉 */
  flex:1 1 auto; min-width:0; background:var(--curtain); border:1px solid var(--line); border-radius:999px;
  padding:11px 14px; color:var(--cream); font:inherit; font-size:.92rem;
}
#chatInput:focus{ outline:none; border-color:var(--amber); }
.chat-send-btn{
  flex:0 0 auto; width:40px; height:40px; border-radius:50%; border:none; cursor:pointer;
  background:var(--rose); color:#fff; display:flex; align-items:center; justify-content:center;
}
.chat-send-btn svg{ width:18px; height:18px; }

/* emoji 选择器 */
#emojiPicker{
  display:none; position:absolute; bottom:62px; left:14px; right:14px;
  background:var(--plum); border:1px solid var(--line); border-radius:12px;
  padding:10px; flex-wrap:wrap; gap:4px; max-height:160px; overflow-y:auto;
}
#emojiPicker.active{ display:flex; }
#emojiPicker button{
  background:transparent; border:none; cursor:pointer; font-size:1.3rem;
  width:36px; height:36px; border-radius:8px;
}
#emojiPicker button:hover{ background:rgba(255,255,255,.1); }

/* ---------- 图片大图预览 ---------- */
.image-preview-overlay{
  position:fixed; inset:0; z-index:1100; background:rgba(0,0,0,.9);
  display:flex; align-items:center; justify-content:center; cursor:zoom-out;
}
.image-preview-overlay img{ max-width:92%; max-height:92%; border-radius:8px; }
.image-preview-overlay .close-preview{
  position:absolute; top:18px; right:24px; color:#fff; font-size:2rem; cursor:pointer;
}

/* ---------- 复制提示 toast ---------- */
#copyToast{
  position:fixed; left:50%; bottom:90px; transform:translateX(-50%) translateY(20px);
  background:var(--plum-2); color:var(--cream); border:1px solid var(--line);
  padding:10px 18px; border-radius:999px; font-size:.85rem; z-index:1200;
  opacity:0; pointer-events:none; transition:opacity .25s, transform .25s;
}
#copyToast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

/* ---------- APK 下载条（由 widget.config 控制，默认隐藏）---------- */
#apkDownloadBar, #pageApkBar{ display:none; }
#apkDownloadBar.active, #pageApkBar.active{
  display:flex; align-items:center; gap:10px; padding:10px 14px;
  background:var(--plum); border-bottom:1px solid var(--line); font-size:.85rem; color:var(--cream);
}
#apkDownloadBar .apk-btn, #pageApkBar .apk-btn{
  margin-left:auto; background:var(--amber-deep); color:#231; border:none; border-radius:999px;
  padding:7px 14px; font-weight:700; cursor:pointer; font-size:.82rem;
}

/* ---------- 身份证上传（由 widget.config 控制，默认隐藏）---------- */
#idCardUploadSection{ display:none; }

/* ---------- 移动端：保持悬浮卡片（四周留距离 + 朦胧背景），不全屏 ---------- */
@media (max-width:480px){
  .chat-modal{ padding:14px; }
  .chat-card{ max-width:100%; height:min(640px, calc(100vh - 28px)); border-radius:16px; }
}
