/* 客服系统 - 访客端样式（QQ 风格白色主题 + 移动端适配） */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #3f7ff5;
  --primary-light: #5b8cff;
  --bg: #f5f6f7;
  --panel: #ffffff;
  --border: #e8eaed;
  --text: #1f2329;
  --muted: #8a9099;
  --bubble-visitor: #3f7ff5;
  --bubble-admin: #ffffff;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #e9ebee;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* 主容器：手机端铺满，桌面端居中 */
.chat-app {
  width: 100%;
  max-width: 640px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* 头部标题栏（蓝色，QQ 风格，始终显示） */
.chat-header {
  flex-shrink: 0;
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #3f7ff5, #5b8cff);
  color: #fff;
  z-index: 10;
}
.agent-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.agent-info { flex: 1; min-width: 0; }
.agent-name { font-size: 16px; font-weight: 600; line-height: 1.2; }
.agent-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.agent-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #5cff9b;
  box-shadow: 0 0 0 2px rgba(92, 255, 155, 0.3);
}

/* 消息区（浅灰背景） */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}
.chat-messages::-webkit-scrollbar { width: 0; }

/* 消息行 + 头像 */
.msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: msgIn 0.28s ease;
}
.msg.visitor { flex-direction: row-reverse; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #dde4f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.msg.admin .msg-avatar { background: #e4edff; }
.msg.visitor .msg-avatar { background: #e6f3e6; }

.msg-main { max-width: 72%; display: flex; flex-direction: column; }
.msg.visitor .msg-main { align-items: flex-end; }
.msg.admin .msg-main { align-items: flex-start; }

.bubble {
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  position: relative;
}
.msg.visitor .bubble {
  background: var(--bubble-visitor);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg.admin .bubble {
  background: var(--bubble-admin);
  color: var(--text);
  border-top-left-radius: 4px;
  border: 1px solid var(--border);
}
.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
}
.msg-sending {
  color: #3f7ff5;
  font-size: 10px;
}

/* 媒体消息 */
.bubble.media { padding: 5px; }
.media-thumb {
  display: block;
  max-width: 210px;
  max-height: 200px;
  border-radius: 10px;
  cursor: zoom-in;
  object-fit: cover;
}
.media-video {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  background: #000;
}
.video-pending {
  width: 170px;
  height: 100px;
  background: linear-gradient(135deg, #3f7ff5, #5b8cff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border-radius: 10px;
}

/* 系统提示 */
.sys-tip {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px;
}
.sys-tip.warn { color: #e5484d; }

/* 表情面板 */
.emoji-panel {
  display: none;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 10px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  max-height: 180px;
  overflow-y: auto;
  flex-shrink: 0;
}
.emoji-panel.show { display: grid; }
.emoji-panel span {
  font-size: 22px;
  text-align: center;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-panel span:active { background: #f0f2f5; transform: scale(1.2); }

/* 底部输入区（白色，元素不溢出） */
.chat-input {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: #f0f2f5;
  font-size: 19px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: #e2e6ec; }
#msgInput {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  border: none;
  border-radius: 19px;
  background: #f0f2f5;
  font-size: 15px;
  outline: none;
  color: var(--text);
}
#msgInput::placeholder { color: var(--muted); }
.send-btn {
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: 19px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:active { background: #2f6fe0; }

/* 上传遮罩（带进度条） */
.upload-tip {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.upload-box {
  width: 82%;
  max-width: 320px;
  background: #fff;
  border-radius: 14px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.upload-name {
  font-size: 14px;
  color: #333;
  margin-bottom: 14px;
  word-break: break-all;
}
.upload-bar-wrap {
  width: 100%;
  height: 8px;
  background: #e8eaed;
  border-radius: 4px;
  overflow: hidden;
}
.upload-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3f7ff5, #5b8cff);
  border-radius: 4px;
  transition: width 0.2s ease;
}
.upload-pct {
  font-size: 13px;
  color: #666;
  margin-top: 10px;
}

/* 灯箱 */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img, .lightbox video { max-width: 96vw; max-height: 88vh; border-radius: 8px; object-fit: contain; }
.lightbox .lb-close {
  position: absolute;
  top: 18px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

/* 桌面端：加一点留白 */
@media (min-width: 641px) {
  body { padding: 20px 0; }
  .chat-app { height: calc(100vh - 40px); border-radius: 18px; border: 1px solid var(--border); }
}
