/* ============ 访客聊天页 · 企业级 ============ */
.chat-body { overflow: hidden; }
.chat-app {
  height: 100vh; height: 100dvh; max-width: 900px; margin: 0 auto;
  display: flex; flex-direction: column; background: var(--bg);
  box-shadow: 0 0 80px rgba(11,21,38,.08);
  position: relative;
}

/* 顶部：白底毛玻璃 + 渐变品牌块 */
.chat-header {
  background: rgba(255,255,255,.86); backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px; z-index: 5; flex-shrink: 0;
}
.chat-brand { display: flex; align-items: center; gap: 13px; }
.chat-logo {
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; box-shadow: 0 6px 16px rgba(47,84,235,.30);
}
.chat-brand h1 { font-size: 17px; font-weight: 800; letter-spacing: .5px; }
.chat-brand p {
  font-size: 12px; margin-top: 2px; display: inline-flex; align-items: center; gap: 6px;
  color: var(--txt-2);
  background: #f2f5fb; border-radius: 100px; padding: 2px 11px; font-weight: 500;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ok   { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.dot-wait { background: var(--warn); box-shadow: 0 0 0 3px rgba(217,119,6,.14); }
.dot-off  { background: #b6bfce; }

/* 消息区 */
.chat-main {
  flex: 1; overflow-y: auto; padding: 20px 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth;
}
.chat-welcome {
  margin: 7vh auto 14px; text-align: center; color: var(--txt-2);
  animation: fadeUp .5s ease; max-width: 320px;
}
.welcome-icon {
  width: 84px; height: 84px; margin: 0 auto 16px; border-radius: 26px;
  background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; box-shadow: 0 14px 34px rgba(47,84,235,.30);
}
.chat-welcome h2 { font-size: 19px; color: var(--txt); margin-bottom: 8px; font-weight: 800; letter-spacing: .5px; }
.chat-welcome p { font-size: 13px; line-height: 1.8; }
.chat-welcome .welcome-media {
  max-width: 100%; border-radius: 12px; margin: 14px auto 0; display: block;
  box-shadow: 0 8px 22px rgba(11,21,38,.12);
}
.chat-welcome .welcome-media.welcome-media { background: #f2f5fa; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.msg-row { display: flex; gap: 9px; margin-top: 12px; animation: fadeUp .28s ease; align-items: flex-start; }
.msg-row.mine { flex-direction: row-reverse; }
/* 气泡包裹层：宽度上限在这里计算（相对 msg-row，无循环依赖），bubble 只需 100% */
.msg-body { min-width: 0; max-width: min(72%, 470px); }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px; color: #fff;
}
.msg-row.them .msg-avatar { background: linear-gradient(135deg, #2f54eb, #6d28d9); box-shadow: 0 3px 10px rgba(47,84,235,.25); }
.msg-row.mine .msg-avatar { background: linear-gradient(135deg, #334155, #1e293b); }
.msg-avatar img {
  width: 100%; height: 100%; border-radius: 11px; object-fit: cover;
  background: #fff;
}
.msg-bubble {
  max-width: 100%; padding: 11px 15px; border-radius: 16px;
  font-size: 14px; line-height: 1.65; word-break: break-word; position: relative;
  white-space: pre-wrap; width: fit-content;
}
.msg-row.them .msg-bubble {
  background: #fff; border: 1px solid var(--line);
  border-top-left-radius: 6px; box-shadow: var(--shadow-sm);
}
.msg-row.mine .msg-bubble {
  background: var(--grad); color: #fff; border-top-right-radius: 6px;
  box-shadow: 0 5px 16px rgba(47,84,235,.28);
}
.msg-time { font-size: 11px; color: var(--txt-3); margin-top: 5px; }
.msg-row.mine .msg-time { text-align: right; color: rgba(255,255,255,.95); text-shadow: 0 1px 3px rgba(0,0,0,.45); }
/* 发送者标签：一眼分清谁发的 */
.msg-sender {
  font-size: 10.5px; color: var(--txt-3); font-weight: 600;
  letter-spacing: .5px; margin-bottom: 3px;
}
.msg-row.them .msg-sender { color: var(--primary); }
.msg-row.mine .msg-sender { text-align: right; color: rgba(255,255,255,.95); text-shadow: 0 1px 3px rgba(0,0,0,.45); }
.msg-row.them .msg-sender, .msg-row.them .msg-time { text-shadow: 0 1px 3px rgba(255,255,255,.85); }
.msg-img { max-width: 100%; border-radius: 10px; display: block; cursor: zoom-in; max-height: 320px; }
.msg-video { max-width: 100%; border-radius: 10px; display: block; max-height: 340px; }
.msg-system {
  align-self: center; background: #eef1f8; color: var(--txt-2);
  font-size: 12px; padding: 5px 15px; border-radius: 100px; margin-top: 12px;
}

/* 已读 / 未读标识（仅自己发出的消息显示） */
.msg-read { font-size: 11px; margin-left: 6px; color: inherit; opacity: .7; }
.msg-read.is-read { opacity: 1; font-weight: 600; }
.msg-row.mine .msg-read.is-read::before { content: "✓ "; }
/* 客服工作台为浅色底，已读用绿色更醒目 */
.wb-msglist .msg-read.is-read { color: var(--ok); }

/* 撤回按钮（限时显示） */
.msg-recall {
  font-size: 11px; color: var(--txt-3); background: none; border: none;
  padding: 0 2px; margin-left: 8px; cursor: pointer; font-family: inherit;
  text-shadow: none;
}
.msg-recall:hover { color: var(--primary); text-decoration: underline; }
.msg-row.mine .msg-recall { color: rgba(255,255,255,.85); text-shadow: 0 1px 3px rgba(0,0,0,.45); }
.msg-row.mine .msg-recall:hover { color: #fff; }
.wb-msglist .msg-row.mine .msg-recall { color: var(--txt-3); text-shadow: none; }
.wb-msglist .msg-row.mine .msg-recall:hover { color: var(--primary); }

/* 已撤回消息：居中提示 */
.msg-recalled-row { display: flex; justify-content: center; margin-top: 12px; animation: fadeUp .28s ease; }
.msg-recalled {
  background: #eef1f8; color: var(--txt-3); font-size: 12px;
  padding: 4px 14px; border-radius: 100px;
}

/* 输入区：浮起容器 */
.chat-footer {
  flex-shrink: 0; padding: 12px 16px 9px; background: #fff; border-top: 1px solid var(--line);
  position: relative;
}
.chat-inputbar {
  display: flex; align-items: flex-end; gap: 4px;
  background: #f2f5fa; border: 1.5px solid transparent;
  border-radius: 16px; padding: 4px 6px 4px 8px;
  transition: border-color .18s, box-shadow .18s;
}
.chat-inputbar:focus-within {
  border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 4px rgba(47,84,235,.08);
}
.chat-inputbar textarea {
  flex: 1; border: none; outline: none; resize: none; font-family: inherit;
  font-size: 14px; line-height: 1.55; padding: 9px 4px; max-height: 110px;
  background: transparent;
}
.send-btn {
  width: 42px; height: 42px; border: none; border-radius: 13px; cursor: pointer;
  background: var(--grad); color: #fff; font-size: 19px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s; box-shadow: 0 4px 14px rgba(47,84,235,.35);
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(47,84,235,.42); }
.send-btn:disabled { opacity: .5; }
.chat-tip { text-align: center; font-size: 11px; color: var(--txt-3); margin-top: 8px; }
.chat-service-link { color: var(--txt-3) !important; font-weight: 500; }
.chat-service-link:hover { color: var(--primary) !important; }
.chat-service-link i { font-size: 12px; }

/* 表情面板：客服端与访客端共用，统一锚定在输入框上方
   （不再依赖 .up 修饰类，避免移动端特异性冲突把面板推到屏幕外） */
.emoji-panel {
  position: absolute; bottom: calc(100% + 8px); left: 12px; right: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 10px; width: 304px; max-width: calc(100vw - 24px);
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 50;
  animation: fadeUp .18s ease;
}
.emoji-panel button {
  border: none; background: transparent; font-size: 21px; cursor: pointer;
  padding: 4px; border-radius: 8px; transition: background .12s, transform .12s;
}
.emoji-panel button:hover { background: var(--grad-soft); transform: scale(1.12); }

/* 图片预览大图 */
.img-viewer {
  position: fixed; inset: 0; background: rgba(11,21,38,.82); z-index: 999;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
  animation: fadeIn .2s ease; backdrop-filter: blur(4px);
}
.img-viewer img { max-width: 92vw; max-height: 92vh; border-radius: 12px; box-shadow: var(--shadow-lg); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 移动端 */
@media (max-width: 640px) {
  .chat-app { max-width: 100%; }
  .msg-body { max-width: 80%; }
  .chat-header { padding: 12px 16px; }
  .emoji-panel {
    position: fixed; left: 12px; right: 12px; bottom: 86px; top: auto;
    transform: none; width: auto; max-width: none; grid-template-columns: repeat(8, 1fr);
  }
}

/* ============ 访客登录状态（顶部） ============ */
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-user {
  display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
  background: var(--grad-soft); border: 1px solid var(--line);
  border-radius: 100px; padding: 5px 6px 5px 13px; font-size: 13px; font-weight: 600;
  color: var(--txt); max-width: 46%;
}
.chat-user .cu-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px;
}
.chat-user .cu-out {
  border: none; background: #fff; color: var(--txt-2); cursor: pointer;
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 15px; transition: .15s; flex-shrink: 0;
}
.chat-user .cu-out:hover { background: var(--err); color: #fff; }

/* ============ 访客注册 / 登录弹窗 ============ */
.vmodal { position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; }
.vmodal-mask { position: absolute; inset: 0; background: rgba(11,21,38,.5); backdrop-filter: blur(5px); animation: fadeIn .2s ease; }
.vmodal-box {
  position: relative; width: 400px; max-width: 100%; max-height: 92vh; overflow-y: auto;
  background: #fff; border-radius: 20px; padding: 26px 24px 20px;
  box-shadow: 0 30px 80px rgba(11,21,38,.30); animation: vPop .24s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes vPop { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
.vmodal-x {
  position: absolute; top: 14px; right: 14px; border: none; background: #f2f5fb;
  color: var(--txt-2); width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  font-size: 19px; display: flex; align-items: center; justify-content: center; transition: .15s;
}
.vmodal-x:hover { background: var(--line-2); color: var(--txt); }
.vmodal-head { text-align: center; margin-bottom: 18px; }
.vmodal-ico {
  width: 54px; height: 54px; border-radius: 17px; background: var(--grad); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 27px;
  box-shadow: 0 8px 20px rgba(47,84,235,.32); margin-bottom: 12px;
}
.vmodal-head h2 { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.vmodal-head p { font-size: 13px; color: var(--txt-3); margin-top: 5px; line-height: 1.55; }

.vmodal-tabs {
  display: flex; background: #f2f5fb; border-radius: 12px; padding: 4px; margin-bottom: 16px;
}
.vtab {
  flex: 1; border: none; background: transparent; padding: 9px 0; border-radius: 9px;
  font-size: 14px; font-weight: 700; color: var(--txt-2); cursor: pointer; transition: .18s;
}
.vtab.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(16,24,40,.08); }

.vform { display: flex; flex-direction: column; gap: 11px; }
.vfield {
  display: flex; align-items: center; gap: 9px; background: #f7f9fd;
  border: 1px solid var(--line); border-radius: 12px; padding: 0 13px;
  transition: border-color .15s, background .15s;
}
.vfield:focus-within { border-color: var(--primary); background: #fff; }
.vfield > i { color: var(--txt-3); font-size: 17px; flex-shrink: 0; }
.vfield input {
  flex: 1; border: none; background: transparent; outline: none;
  padding: 12px 0; font-size: 14px; color: var(--txt); min-width: 0;
}
.vfield-cap input { padding-right: 6px; }
.vcap {
  width: 108px; height: 38px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); object-fit: cover; flex-shrink: 0; background: #f6f7fc;
}
.vbtn {
  margin-top: 4px; border: none; border-radius: 12px; padding: 13px 0;
  background: var(--grad); color: #fff; font-size: 15px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 0 8px 20px rgba(47,84,235,.25); transition: .18s;
}
.vbtn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.vbtn:disabled { opacity: .6; cursor: default; transform: none; }
.vmodal-foot {
  margin-top: 14px; font-size: 12px; color: var(--txt-3); text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.valert {
  border-radius: 11px; padding: 9px 13px; font-size: 13px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 7px;
}
.valert.err { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.valert.ok  { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }

/* 工作台会话项：访客邮箱小标签 */
.sess-mail {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--primary);
  background: rgba(47,84,235,.08); border-radius: 6px; padding: 1px 7px; margin: 3px 0 2px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

@media (max-width: 640px) {
  .vmodal-box { padding: 22px 18px 18px; border-radius: 18px; }
  .chat-user { padding-left: 10px; }
  .chat-user .cu-name { max-width: 90px; }
}
