/* ==========================================================
   在线客服 - 前台样式
   ========================================================== */
:root{
  --primary:#2563eb;
  --primary-dark:#1d4ed8;
  --primary-light:#eff6ff;
  --bg:#f5f7fb;
  --panel:#ffffff;
  --border:#e5e8ef;
  --text:#1f2937;
  --text-2:#6b7280;
  --text-3:#9ca3af;
  --radius:14px;
  --shadow:0 4px 24px rgba(17,24,39,.08);
}
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{
  font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
  background:var(--bg);color:var(--text);font-size:14px;
  display:flex;align-items:center;justify-content:center;
  overflow:hidden;
}

/* ---------- 容器 ---------- */
.app{
  width:100%;height:100%;max-width:820px;max-height:100vh;
  background:var(--panel);display:flex;flex-direction:column;
  box-shadow:var(--shadow);overflow:hidden;
  position:relative;
}
@media(min-width:900px){
  body{padding:24px}
  .app{height:calc(100vh - 48px);border-radius:18px}
}

/* ---------- 头部 ---------- */
.chat-header{
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 18px;border-bottom:1px solid var(--border);
  background:linear-gradient(135deg,#2563eb,#1e40af);
  color:#fff;flex-shrink:0;
}
.hd-left{display:flex;align-items:center;gap:12px}
.avatar{
  width:40px;height:40px;border-radius:50%;background:rgba(255,255,255,.18);
  display:flex;align-items:center;justify-content:center;flex-shrink:0;
  backdrop-filter:blur(4px);
}
.avatar svg{width:22px;height:22px}
.hd-info h1{font-size:16px;font-weight:600;line-height:1.3}
.status{display:flex;align-items:center;gap:5px;font-size:12px;opacity:.9;margin-top:2px}
.dot{width:6px;height:6px;border-radius:50%;background:#4ade80;display:inline-block;box-shadow:0 0 0 3px rgba(74,222,128,.25)}
.hd-btn{
  width:36px;height:36px;border-radius:50%;border:none;background:rgba(255,255,255,.15);
  color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;
  transition:.2s;
}
.hd-btn:hover{background:rgba(255,255,255,.28);transform:rotate(90deg)}
.hd-btn svg{width:17px;height:17px}

/* ---------- 消息区 ---------- */
.chat-body{
  flex:1;overflow-y:auto;padding:18px 16px 8px;
  background:var(--bg);scroll-behavior:smooth;
}
.chat-body::-webkit-scrollbar{width:6px}
.chat-body::-webkit-scrollbar-thumb{background:#cfd5e0;border-radius:3px}
.chat-body::-webkit-scrollbar-thumb:hover{background:#b3bccd}

.msg-tip{text-align:center;margin-bottom:18px}
.msg-tip span{
  display:inline-block;background:#dbe3f0;color:var(--text-2);
  font-size:11px;padding:3px 12px;border-radius:10px;
}
.msg-tip p{
  margin-top:10px;font-size:12.5px;color:var(--text-3);
  background:#fff;padding:8px 14px;border-radius:10px;display:inline-block;
  box-shadow:0 1px 4px rgba(17,24,39,.04);
}

/* ---------- 消息气泡 ---------- */
.msg{display:flex;gap:10px;margin-bottom:16px;align-items:flex-end;animation:fade .25s ease}
@keyframes fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.msg.me{flex-direction:row-reverse}
.msg-avatar{
  width:34px;height:34px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-size:12px;font-weight:600;color:#fff;
  background:linear-gradient(135deg,#94a3b8,#64748b);
}
.msg.me .msg-avatar{background:linear-gradient(135deg,#3b82f6,#2563eb)}
.msg-content{max-width:calc(100% - 110px);display:flex;flex-direction:column;gap:4px}
.msg.me .msg-content{align-items:flex-end}
.bubble{
  padding:10px 14px;border-radius:14px;line-height:1.6;
  word-break:break-word;white-space:pre-wrap;
  background:#fff;box-shadow:0 1px 3px rgba(17,24,39,.06);
  border-top-left-radius:4px;font-size:14px;
}
.msg.me .bubble{
  background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;
  border-top-left-radius:14px;border-top-right-radius:4px;
}
.msg-time{font-size:11px;color:var(--text-3);padding:0 4px}

/* 图片消息 */
.bubble.media{padding:4px;background:#fff;overflow:hidden}
.msg.me .bubble.media{background:rgba(37,99,235,.1)}
.bubble.media img{
  max-width:220px;max-height:280px;border-radius:10px;display:block;cursor:zoom-in;
  object-fit:cover;
}
.bubble.media video{
  max-width:260px;max-height:300px;border-radius:10px;display:block;background:#000;
}
/* 文件消息 */
.file-card{
  display:flex;align-items:center;gap:11px;padding:11px 14px;
  background:#fff;border-radius:12px;text-decoration:none;color:inherit;
  box-shadow:0 1px 3px rgba(17,24,39,.06);border-top-left-radius:4px;
  min-width:200px;max-width:260px;transition:.2s;
}
.msg.me .file-card{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;border-radius:12px;border-top-right-radius:4px}
.file-card:hover{transform:translateY(-1px);box-shadow:0 4px 12px rgba(17,24,39,.12)}
.file-icon{
  width:38px;height:38px;border-radius:9px;background:var(--primary-light);color:var(--primary);
  display:flex;align-items:center;justify-content:center;flex-shrink:0;font-size:10px;font-weight:700;
  text-transform:uppercase;
}
.msg.me .file-icon{background:rgba(255,255,255,.2);color:#fff}
.file-icon svg{width:19px;height:19px}
.file-meta{overflow:hidden;min-width:0}
.file-meta strong{display:block;font-size:13px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.file-meta small{font-size:11px;color:var(--text-3)}
.msg.me .file-meta small{color:rgba(255,255,255,.75)}

/* ---------- 输入区 ---------- */
.chat-footer{
  border-top:1px solid var(--border);background:#fff;flex-shrink:0;
  padding:8px 12px 12px;
  padding-bottom:calc(12px + env(safe-area-inset-bottom));
}
.attach-bar{display:flex;flex-wrap:wrap;gap:8px}
.attach-bar:not(:empty){padding:6px 2px 8px}
.attach-item{
  position:relative;width:58px;height:58px;border-radius:10px;overflow:hidden;
  border:1px solid var(--border);background:var(--bg);display:flex;align-items:center;justify-content:center;
}
.attach-item img{width:100%;height:100%;object-fit:cover}
.attach-item .fi{font-size:9px;color:var(--text-2);font-weight:600;text-align:center;padding:4px;word-break:break-all;line-height:1.2}
.attach-item .rm{
  position:absolute;top:-6px;right:-6px;width:19px;height:19px;border-radius:50%;
  background:#ef4444;color:#fff;border:2px solid #fff;font-size:12px;line-height:1;
  cursor:pointer;display:flex;align-items:center;justify-content:center;
}

.tool-bar{display:flex;gap:6px;padding:4px 2px 6px}
.tool{
  width:34px;height:34px;border-radius:9px;border:none;background:transparent;
  color:var(--text-2);cursor:pointer;display:flex;align-items:center;justify-content:center;
  transition:.18s;
}
.tool:hover{background:var(--primary-light);color:var(--primary)}
.tool svg{width:19px;height:19px}

.input-row{display:flex;align-items:flex-end;gap:9px}
#msgInput{
  flex:1;border:1px solid var(--border);border-radius:20px;padding:10px 16px;
  font-family:inherit;font-size:14px;line-height:1.5;resize:none;outline:none;
  max-height:110px;min-height:40px;transition:.2s;background:var(--bg);
  color:var(--text);
}
#msgInput:focus{border-color:var(--primary);background:#fff;box-shadow:0 0 0 3px rgba(37,99,235,.1)}
.send-btn{
  height:40px;padding:0 18px;border-radius:20px;border:none;flex-shrink:0;
  background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;cursor:pointer;
  display:flex;align-items:center;justify-content:center;transition:.2s;
  box-shadow:0 3px 10px rgba(37,99,235,.3);
  font-family:inherit;font-size:14px;font-weight:500;letter-spacing:2px;white-space:nowrap;
}
.send-btn:hover{transform:scale(1.04);box-shadow:0 5px 16px rgba(37,99,235,.42)}
.send-btn:active{transform:scale(.96)}
.send-btn:disabled{opacity:.4;cursor:not-allowed;transform:none;box-shadow:none}

/* ---------- 图片预览 ---------- */
.lightbox{
  position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.9);z-index:999;
  display:none;align-items:center;justify-content:center;padding:24px;
}
.lightbox.show{display:flex;animation:fade .2s}
.lightbox img{max-width:100%;max-height:100%;border-radius:8px;object-fit:contain}
.lb-close{
  position:absolute;top:18px;right:24px;width:42px;height:42px;border-radius:50%;
  background:rgba(255,255,255,.16);border:none;color:#fff;font-size:26px;
  cursor:pointer;line-height:1;transition:.2s;
}
.lb-close:hover{background:rgba(255,255,255,.3)}

/* ---------- 上传遮罩 ---------- */
.upload-mask{
  position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(17,24,39,.55);z-index:1000;
  display:none;align-items:center;justify-content:center;backdrop-filter:blur(3px);
}
.upload-mask.show{display:flex}
.up-box{
  background:#fff;border-radius:16px;padding:28px 34px;text-align:center;
  box-shadow:0 20px 50px rgba(0,0,0,.25);min-width:200px;
}
.up-ring{position:relative;width:76px;height:76px;margin:0 auto 14px}
.up-ring svg{width:100%;height:100%;transform:rotate(-90deg)}
.up-ring svg circle{transition:stroke-dashoffset .25s}
.up-ring span{
  position:absolute;top:0;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center;
  font-size:15px;font-weight:600;color:var(--primary);
}
.up-box p{font-size:13px;color:var(--text-2);max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin:0 auto}

/* ---------- 空状态 ---------- */
.empty-tip{text-align:center;color:var(--text-3);font-size:13px;padding:30px 0}

@media(max-width:480px){
  .bubble.media img{max-width:180px}
  .bubble.media video{max-width:200px}
  .chat-body{padding:14px 12px 6px}
}

/* ==========================================================
   语音消息
   ========================================================== */
.voice-bubble{
  display:flex;align-items:center;gap:10px;padding:10px 15px 10px 12px;
  background:#fff;border-radius:14px;border-top-left-radius:4px;
  box-shadow:0 1px 3px rgba(17,24,39,.06);cursor:pointer;
  min-width:120px;max-width:210px;transition:.18s;user-select:none;
}
.voice-bubble:hover{box-shadow:0 4px 14px rgba(17,24,39,.12)}
.msg.me .voice-bubble{
  background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;
  border-top-left-radius:14px;border-top-right-radius:4px;
}
.vb-icon{
  width:25px;height:25px;border-radius:50%;flex-shrink:0;
  background:var(--primary-light);color:var(--primary);
  display:flex;align-items:center;justify-content:center;
}
.msg.me .vb-icon{background:rgba(255,255,255,.22);color:#fff}
.vb-icon svg{width:14px;height:14px}
.vb-wave{flex:1;display:flex;align-items:center;gap:2.5px;height:19px;min-width:50px}
.vb-wave i{
  display:block;width:2.5px;border-radius:2px;background:currentColor;
  opacity:.42;flex:1;max-width:3px;
}
.msg.me .vb-wave i{opacity:.6;background:#fff}
.vb-time{font-size:12px;flex-shrink:0;opacity:.8;font-variant-numeric:tabular-nums}
.voice-bubble.playing .vb-wave i{animation:vbanim .9s ease-in-out infinite}
.voice-bubble.playing .vb-wave i:nth-child(2){animation-delay:.1s}
.voice-bubble.playing .vb-wave i:nth-child(3){animation-delay:.2s}
.voice-bubble.playing .vb-wave i:nth-child(4){animation-delay:.3s}
.voice-bubble.playing .vb-wave i:nth-child(5){animation-delay:.4s}
.voice-bubble.playing .vb-wave i:nth-child(6){animation-delay:.5s}
.voice-bubble.playing .vb-wave i:nth-child(7){animation-delay:.6s}
@keyframes vbanim{0%,100%{transform:scaleY(.45)}50%{transform:scaleY(1.35)}}

/* 录音面板 */
.rec-mask{
  position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(15,23,42,.55);z-index:1700;
  display:none;align-items:center;justify-content:center;padding:20px;
  backdrop-filter:blur(3px);
}
.rec-mask.show{display:flex;animation:fade .18s}
.rec-box{
  background:#fff;border-radius:16px;padding:24px 26px;
  width:100%;max-width:340px;box-shadow:0 22px 60px rgba(0,0,0,.3);text-align:center;
}
.rec-head{display:flex;align-items:center;justify-content:center;gap:9px;font-size:15px;margin-bottom:16px;color:var(--text)}
.rec-dot{width:10px;height:10px;border-radius:50%;background:#ef4444;animation:recpulse 1.1s ease-in-out infinite}
@keyframes recpulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.35;transform:scale(.78)}}
.rec-wave{height:54px;display:flex;align-items:center;justify-content:center;gap:3px;margin-bottom:10px}
.rec-wave i{display:block;width:3.5px;height:8px;border-radius:2px;background:var(--primary);opacity:.75;transition:height .09s linear}
.rec-time{font-size:26px;font-weight:600;color:var(--text);font-variant-numeric:tabular-nums;letter-spacing:1px;margin-bottom:5px}
.rec-tip{font-size:12px;color:var(--text-3);margin-bottom:20px}
.rec-tip.warn{color:#dc2626;font-weight:500}
.rec-foot{display:flex;gap:10px}
.rec-foot button{
  flex:1;border:none;border-radius:10px;padding:11px;font-family:inherit;
  font-size:14px;cursor:pointer;transition:.18s;
}
.btn-c{background:#f1f5f9;color:var(--text-2)}
.btn-c:hover{background:#e2e8f0}
.btn-p{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;box-shadow:0 4px 12px rgba(37,99,235,.3)}
.btn-p:hover{transform:translateY(-1px)}
