/* ============ 全站在线客服聊天窗 ============ */
.chat-widget { position: fixed; right: 22px; bottom: 22px; z-index: 2000; font-family: inherit; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chat-fab {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #2f6bff, #1b3aff);
  color: #fff; border: none; border-radius: 999px;
  padding: 12px 18px; cursor: pointer; box-shadow: 0 8px 24px rgba(27,58,255,.35);
  font-size: 15px; font-weight: 600; line-height: 1; font-family: inherit; position: relative;
  transition: transform .15s ease, box-shadow .15s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(27,58,255,.45); }
.chat-fab-ic { width: 20px; height: 20px; display: grid; place-items: center; font-size: 18px; }

/* 未读消息数量徽标（微信式红点）：后台回复后显示在在线咨询按钮右上角 */
.chat-fab-badge {
  position: absolute; top: -6px; right: -6px; z-index: 5;
  min-width: 19px; height: 19px; padding: 0 5px; box-sizing: border-box;
  border-radius: 999px; background: #ff3b30; color: #fff;
  font-size: 12px; font-weight: 700; line-height: 19px; text-align: center;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25);
  animation: chatBadgePop .2s ease;
}
@keyframes chatBadgePop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* WhatsApp 咨询漂浮按钮（位于在线咨询上方，后台配置号码后渲染） */
.chat-wa {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: #fff; border: none; border-radius: 999px; text-decoration: none;
  padding: 12px 18px; box-shadow: 0 8px 24px rgba(18,140,126,.35);
  font-size: 15px; font-weight: 600; line-height: 1; font-family: inherit;
  transition: transform .15s ease, box-shadow .15s ease;
}
.chat-wa:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(18,140,126,.45); color: #fff; }
.chat-wa-ic { width: 20px; height: 20px; display: grid; place-items: center; }
.chat-wa-ic svg { display: block; width: 100%; height: 100%; }

.chat-panel {
  position: absolute; right: 0; bottom: 140px; width: 360px; max-width: calc(100vw - 32px);
  height: 520px; max-height: calc(100vh - 120px);
  background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(10,18,38,.28);
  display: flex; flex-direction: column; transform-origin: bottom right;
  animation: chatPop .18s ease;
}
@keyframes chatPop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, #0a1226, #14224a); color: #fff; padding: 12px 14px;
}
.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.14);
  display: grid; place-items: center; font-size: 18px;
}
.chat-title strong { display: block; font-size: 15px; }
.chat-title small { color: #9fb3d9; font-size: 12px; }
.chat-close { background: none; border: none; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; opacity: .8; }
.chat-close:hover { opacity: 1; }

.chat-body { flex: 1; overflow-y: auto; padding: 14px; background: #f5f7fb; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.chat-msg.customer { align-self: flex-end; background: #2f6bff; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.ai { align-self: flex-start; background: #eef2ff; color: #1a2342; border-bottom-left-radius: 4px; }
.chat-msg.staff { align-self: flex-start; background: #fff; color: #1a2342; border: 1px solid #e2e8f5; border-bottom-left-radius: 4px; }
.chat-msg.system { align-self: center; background: transparent; color: #8a94a6; font-size: 12px; }

.chat-typing { display: flex; gap: 4px; padding: 4px 16px 8px; background: #f5f7fb; }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: #b9c4d8; animation: chatBlink 1.2s infinite; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatBlink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #eef1f6; background: #fff; }
.chat-input input { flex: 1; border: 1px solid #dfe5ef; border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none; }
.chat-input input:focus { border-color: #2f6bff; }
.chat-input button { background: #2f6bff; color: #fff; border: none; border-radius: 10px; padding: 0 18px; font-weight: 600; cursor: pointer; }
.chat-input button:hover { background: #1b54e6; }

@media (max-width: 480px) {
  .chat-widget { right: 12px; bottom: 12px; }
  .chat-panel { position: fixed; right: 0; bottom: 0; width: 100vw; max-width: 100vw; height: 78vh; max-height: 78vh; border-radius: 16px 16px 0 0; }
}

/* ============ 后台对话台 ============ */
.chat-console { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 62vh; align-items: start; }
.chat-list { border: 1px solid var(--a-line); border-radius: var(--a-radius); background: #fff; overflow: hidden; display: flex; flex-direction: column; max-height: 78vh; }
.chat-list-bar { padding: 12px; border-bottom: 1px solid var(--a-line); }
.chat-search { width: 100%; border: 1px solid var(--a-line); border-radius: 9px; padding: 9px 12px; font-size: 13px; font-family: inherit; background: #fff; color: var(--a-text); }
.chat-search:focus { outline: none; border-color: var(--a-brand); box-shadow: 0 0 0 3px rgba(255,106,26,.12); }
.chat-filter { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--a-line); background: #fafbfd; }
.cf-btn { flex: 1; border: 1px solid var(--a-line); background: #fff; color: var(--a-muted); border-radius: 8px; padding: 7px 4px; font-size: 13px; cursor: pointer; }
.cf-btn:hover { color: var(--a-text); }
.cf-btn.on { background: var(--a-brand); border-color: var(--a-brand); color: #fff; font-weight: 600; }
.chat-list-box { overflow-y: auto; flex: 1; }
.chat-list-empty { text-align: center; color: var(--a-muted); padding: 40px 16px; font-size: 14px; }

.chat-session { display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid #f0f2f6; cursor: pointer; }
.chat-session:hover { background: #f7f9fc; }
.chat-session.on { background: #fff3ec; }
.cs-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--a-brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.cs-main { flex: 1; min-width: 0; }
.cs-row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cs-name { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: 14px; color: var(--a-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdh-no { font-size: 12px; font-weight: 700; color: var(--a-brand); background: rgba(47,107,255,.12); border: 1px solid rgba(47,107,255,.25); padding: 1px 7px; border-radius: 6px; letter-spacing: .3px; }
.cs-badge { background: var(--a-err); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; }
.cs-no { flex: none; font-size: 11px; font-weight: 700; color: var(--a-brand); background: rgba(47,107,255,.12); border: 1px solid rgba(47,107,255,.25); padding: 1px 6px; border-radius: 6px; letter-spacing: .3px; }
.cs-row2 { margin-top: 3px; }
.cs-prev { color: var(--a-muted); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-row3 { margin-top: 5px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cs-time { color: #aab2c5; font-size: 12px; }
.cs-status { font-size: 12px; display: inline-flex; align-items: center; gap: 5px; color: var(--a-muted); }
.cs-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #b6bfd2; }
.cs-status.dot-open { color: var(--a-ok); }
.cs-status.dot-open::before { background: var(--a-ok); }
.cs-status.dot-closed { color: var(--a-muted); }

.chat-detail { border: 1px solid var(--a-line); border-radius: var(--a-radius); background: #fff; display: flex; flex-direction: column; max-height: 78vh; overflow: hidden; }
.chat-detail-empty { display: grid; place-items: center; gap: 12px; color: var(--a-muted); padding: 60px 20px; text-align: center; }
.chat-detail-empty .empty-ic { width: 46px; height: 46px; color: #cdd5e6; }
.chat-detail-head { padding: 14px 16px; border-bottom: 1px solid var(--a-line); }
.cdh-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cdh-title { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--a-text); }
.cdh-title .cs-status { font-size: 12px; }
.cdh-actions { display: flex; gap: 8px; }
.cd-btn { border: 1px solid var(--a-line); background: #fff; color: var(--a-text); border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; }
.cd-btn:hover { border-color: var(--a-brand); color: var(--a-brand); }
.cd-btn.ghost { color: var(--a-err); border-color: #f3c7c7; }
.cdh-meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.cdh-meta span { font-size: 12px; color: var(--a-muted); }
.cdh-meta i { font-style: normal; margin-right: 5px; color: #aab2c5; }

.chat-detail-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; padding: 12px 16px; background: #fafbfd; border-bottom: 1px solid var(--a-line); }
.cdi-item { font-size: 13px; color: var(--a-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdi-item i { font-style: normal; display: block; font-size: 11px; color: #aab2c5; margin-bottom: 2px; }
.cdi-item a { color: var(--a-blue); text-decoration: none; }

.chat-detail-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: #f5f7fb; min-height: 280px; }
.chat-bubble { max-width: 76%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; position: relative; }
.chat-bubble.customer { align-self: flex-end; background: var(--a-blue); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.ai { align-self: flex-start; background: #eef2ff; color: #1a2342; border-bottom-left-radius: 4px; }
.chat-bubble.staff { align-self: flex-start; background: #fff; color: var(--a-text); border: 1px solid #e2e8f5; border-bottom-left-radius: 4px; }
.chat-bubble.system { align-self: center; background: transparent; color: var(--a-muted); font-size: 12px; }
.cb-time { display: block; font-size: 10px; opacity: .6; margin-top: 4px; text-align: right; }

.chat-detail-form { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--a-line); background: #fff; align-items: flex-end; }
.chat-detail-form textarea { flex: 1; border: 1px solid var(--a-line); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit; resize: none; max-height: 140px; color: var(--a-text); line-height: 1.5; }
.chat-detail-form textarea:focus { outline: none; border-color: var(--a-brand); box-shadow: 0 0 0 3px rgba(255,106,26,.12); }

@media (max-width: 760px) {
  .chat-console { grid-template-columns: 1fr; }
  .chat-list { max-height: 40vh; }
  .chat-detail { max-height: none; }
}

/* ============ 消息内图片（前台 + 后台共用） ============ */
.chat-img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; margin: 2px 0 6px; object-fit: cover; cursor: zoom-in; }

/* ============ 前台：附件按钮 + 图片预览 ============ */
.chat-input .chat-attach { background: #f1f4fa; border: 1px solid #dfe5ef; border-radius: 10px; padding: 0 11px; font-size: 15px; cursor: pointer; flex: none; }
.chat-input .chat-attach:hover { background: #e8edf7; }
.chat-preview { padding: 8px 12px 0; background: #fff; }
.chat-preview img { display: block; max-width: 180px; max-height: 120px; border-radius: 10px; border: 1px solid #e2e8f5; }
.chat-preview button { position: absolute; margin-left: -22px; margin-top: 6px; width: 18px; height: 18px; line-height: 16px; border-radius: 50%; border: none; background: rgba(20,26,46,.75); color: #fff; font-size: 12px; cursor: pointer; }

/* ============ 后台：回复工具栏 ============ */
.chat-detail { position: relative; }
.chat-reply-tools { display: flex; align-items: center; gap: 6px; padding: 10px 14px 0; background: #fff; }
.crt-btn { width: 34px; height: 34px; border: 1px solid var(--a-line); background: #fff; border-radius: 9px; font-size: 16px; cursor: pointer; line-height: 1; display: grid; place-items: center; }
.crt-btn:hover { border-color: var(--a-brand); background: #fff8f3; }
.crt-preview { position: relative; display: inline-flex; align-items: center; margin-left: 6px; }
.crt-preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 9px; border: 1px solid var(--a-line); }
.crt-preview button { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; line-height: 16px; border-radius: 50%; border: none; background: rgba(20,26,46,.75); color: #fff; font-size: 12px; cursor: pointer; padding: 0; }

/* ============ 后台：表情弹层 ============ */
.emoji-pop {
  position: absolute; left: 14px; bottom: 74px; z-index: 30;
  width: 316px; max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--a-line); border-radius: 12px;
  box-shadow: 0 14px 40px rgba(10,18,38,.16); padding: 10px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
}
.emoji-cell { background: none; border: none; font-size: 22px; line-height: 1; padding: 6px 0; border-radius: 8px; cursor: pointer; }
.emoji-cell:hover { background: #f2f5fb; transform: scale(1.12); }

/* ============ 后台：常用语弹层 ============ */
.quick-pop {
  position: absolute; left: 14px; bottom: 74px; z-index: 30;
  width: 340px; max-height: 300px; overflow-y: auto;
  background: #fff; border: 1px solid var(--a-line); border-radius: 12px;
  box-shadow: 0 14px 40px rgba(10,18,38,.16); padding: 12px;
}
.quick-sec + .quick-sec { margin-top: 12px; border-top: 1px solid #f0f2f6; padding-top: 10px; }
.quick-h { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--a-muted); margin-bottom: 8px; }
.quick-del-all { background: none; border: none; color: var(--a-err); font-size: 12px; cursor: pointer; }
.quick-cell {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--a-line); background: #fafbfd; border-radius: 9px;
  padding: 8px 10px; font-size: 13px; color: var(--a-text); cursor: pointer; margin-bottom: 6px; line-height: 1.45;
}
.quick-cell:hover { border-color: var(--a-brand); background: #fff8f3; }
.quick-row { display: flex; align-items: center; gap: 6px; }
.quick-row .quick-cell { margin-bottom: 6px; }
.quick-del { flex: none; width: 22px; height: 22px; border: none; background: #f0f2f6; color: #8a94a6; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1; margin-bottom: 6px; }
.quick-del:hover { background: #fde8e8; color: var(--a-err); }
.quick-add { width: 100%; border: 1px dashed #c9d2e2; background: #fff; border-radius: 9px; padding: 8px; font-size: 13px; color: var(--a-brand); cursor: pointer; margin-top: 4px; }
.quick-add:hover { background: #fff8f3; }

/* ============ hidden 属性兜底（关键） ============
 * 弹层/打字指示器等元素若 CSS 显式设置了 display（grid/flex 等），
 * 会覆盖浏览器对 [hidden] 的默认 display:none，导致 hidden 属性失效、
 * 元素一直占位无法收起。此规则保证 hidden 始终生效。 */
[hidden] { display: none !important; }
