/* ============================================================
   在线客服 UI —— 微信聊天风格
   用户浮窗 + 客服工作台
   ============================================================ */

/* ---------- 用户浮窗 ---------- */
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.chat-launcher {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #07c160;
  color: #fff;
  border: none;
  box-shadow: 0 6px 20px rgba(7, 193, 96, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.chat-launcher:hover { transform: scale(1.06); box-shadow: 0 8px 26px rgba(7,193,96,.5); }
.chat-launcher:active { transform: scale(0.95); }

.chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  background: #fa5151;
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

.chat-window {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #ededed;
  border-radius: 10px;
  box-shadow: 0 12px 60px rgba(0,0,0,0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.chat-window.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* 微信头部：白色 + 左箭头 */
.chat-header {
  background: #ededed;
  color: #111;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e0e0e0;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-back { background: none; border: none; font-size: 20px; color: #111; cursor: pointer; padding: 0 4px; }
.chat-avatar {
  width: 36px; height: 36px; border-radius: 6px;
  background: #07c160; color: #fff; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.chat-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.chat-subtitle { font-size: 11px; color: #999; display: flex; align-items: center; gap: 5px; margin-top: 1px; }
.chat-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #bbb; }
.chat-status-dot.online { background: #07c160; }
.chat-close { background: none; border: none; font-size: 16px; color: #999; cursor: pointer; padding: 4px; }
.chat-close:hover { color: #111; }

/* 离线提示条 */
.chat-offline-bar {
  background: #fff7e6; color: #b06a00; font-size: 12px;
  padding: 8px 14px; text-align: center; border-bottom: 1px solid #ffe1b3; display: none;
}

/* 聊天区背景 */
.chat-body {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  background: #ededed;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}

.chat-empty { text-align: center; color: #aaa; font-size: 13px; margin-top: 30px; line-height: 1.9; }
.chat-empty::before { content: '💬'; display: block; font-size: 34px; margin-bottom: 6px; }

/* 消息行结构：头像在外侧 */
.chat-row { display: flex; align-items: flex-start; gap: 8px; width: 100%; }
.chat-row.self { justify-content: flex-end; }

.chat-row-avatar {
  width: 40px; height: 40px; border-radius: 5px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
  background: #576b95;
}
.chat-row.self .chat-row-avatar { background: #07c160; }
.chat-row-avatar-img { object-fit: cover; }

.chat-col { max-width: 72%; display: flex; flex-direction: column; }
.chat-row.self .chat-col { align-items: flex-end; }

.chat-bubble {
  padding: 9px 12px; font-size: 14px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap; position: relative;
}
/* 对方：白色，左侧小三角 */
.chat-row.other .chat-bubble {
  background: #fff; color: #111; border-radius: 5px;
}
.chat-row.other .chat-bubble::before {
  content: ''; position: absolute; left: -6px; top: 15px;
  border: 6px solid transparent; border-right-color: #fff; border-left: 0; border-top: 0;
  border-bottom-width: 9px;
}
/* 自己：微信绿，右侧小三角 */
.chat-row.self .chat-bubble {
  background: #95ec69; color: #111; border-radius: 5px;
}
.chat-row.self .chat-bubble::after {
  content: ''; position: absolute; right: -6px; top: 15px;
  border: 6px solid transparent; border-left-color: #95ec69; border-right: 0; border-top: 0;
  border-bottom-width: 9px;
}
/* 系统消息：居中灰条（无头像） */
.chat-row.system { justify-content: center; }
.chat-row.system .chat-col { max-width: 94%; align-items: center; }
.chat-row.system .chat-bubble {
  background: rgba(0,0,0,0.08); color: #888; border-radius: 4px; font-size: 12px; padding: 5px 12px;
  text-align: center;
}
.chat-row.system .chat-bubble::before, .chat-row.system .chat-bubble::after { display: none; }

/* 时间戳（消息气泡上方小字：自己发的靠右，对方靠左） */
.chat-time {
  color: #b2b2b2; font-size: 11px; line-height: 1.4; margin-bottom: 3px;
}
.chat-row.self .chat-time { text-align: right; }
.chat-row.other .chat-time { text-align: left; }
/* 已读回执（管理端：客服消息气泡下方小字） */
.chat-msg-status { display: block; text-align: right; font-size: 11px; line-height: 1.4; margin-top: 2px; color: #b2b2b2; }
.chat-msg-status.read { color: #07c160; }

/* 底部输入栏 */
.chat-footer {
  padding: 8px; background: #f7f7f7; border-top: 1px solid #e0e0e0;
  display: flex; flex-direction: column;
}
.chat-input-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; border-radius: 6px; padding: 8px;
}
.chat-tools {
  display: flex; align-items: center; gap: 4px; color: #666;
  padding: 2px 4px;
}
.chat-tools svg { width: 24px; height: 24px; }
/* 图片消息气泡 */
.chat-bubble-img { padding: 4px; background: transparent !important; }
.chat-bubble-img::before, .chat-bubble-img::after { display: none !important; }
.chat-img {
  max-width: 200px; max-height: 200px;
  border-radius: 6px; display: block; margin: 2px;
  object-fit: contain;
}
/* 聊天图片按钮 */
.chat-image-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 34px; padding: 0 4px;
  background: none; border: none; color: #666; cursor: pointer;
}
.chat-image-btn:hover { color: #07c160; }
.chat-image-btn svg { width: 22px; height: 22px; }
/* 待发送附件预览条 */
.chat-attach-bar { padding: 8px 8px 0; }
.chat-attach-item { position: relative; display: inline-block; }
.chat-attach-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid #ddd; display: block; }
.chat-attach-del { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; line-height: 18px; text-align: center; border: none; cursor: pointer; }
.chat-attach-del:hover { background: rgba(0,0,0,.75); }
/* 游客邮箱收集表单 */
.chat-email-gate { padding: 10px 14px; background: #f0fdf4; border-top: 1px solid #e2e8f0; }
.chat-email-title { font-size: 13px; font-weight: 700; color: #0f172a; }
.chat-email-desc { font-size: 11.5px; color: #64748b; margin-top: 3px; line-height: 1.5; }
.chat-email-row { display: flex; gap: 8px; margin-top: 9px; }
.chat-email-input {
  flex: 1; min-width: 0; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 8px 10px; font-size: 13px; outline: none; font-family: inherit;
}
.chat-email-input:focus { border-color: #07c160; }
.chat-email-ok {
  border: none; background: #07c160; color: #fff; font-size: 13px; font-weight: 600;
  border-radius: 8px; padding: 8px 14px; cursor: pointer; flex-shrink: 0; font-family: inherit;
}
.chat-email-err { font-size: 11.5px; color: #dc2626; margin-top: 6px; }
.chat-input {
  flex: 1; border: none; outline: none; font-size: 14px; resize: none;
  max-height: 90px; line-height: 1.5; color: #111; background: transparent; font-family: inherit;
}
.chat-send {
  border: none; background: #07c160; color: #fff; font-size: 13px; font-weight: 600;
  border-radius: 5px; padding: 7px 16px; cursor: pointer; transition: opacity .15s; flex-shrink: 0;
}
.chat-send:hover { opacity: .9; }
.chat-send:disabled { background: #d5d5d5; cursor: not-allowed; }

@media (max-width: 480px) {
  .chat-widget { bottom: 14px; right: 14px; }
  .chat-window { width: calc(100vw - 28px); height: calc(100vh - 100px); max-height: none; }
}

/* ---------- 客服工作台 ---------- */
.chat-workspace {
  display: flex; height: calc(100vh - 60px);
  margin: -28px; /* 铺满 .page 内边距 */
  background: #ededed; overflow: hidden;
  width: auto;
}
/* 顶栏仍为白色页头 */
.chat-workspace .chat-toolbar {
  display: none;
}

/* 左侧会话列表 */
.chat-session-list {
  width: 320px; min-width: 320px; max-width: 320px;
  display: flex; flex-direction: column; background: #fff; border-right: 1px solid #e0e0e0;
}
.chat-session-header { padding: 14px 14px 10px; border-bottom: 1px solid #ededed; }
.chat-session-header .header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.chat-session-header h2 { font-size: 15px; margin: 0; font-weight: 600; color: #111; }
.chat-session-search {
  display: flex; align-items: center; gap: 8px; background: #f2f2f2;
  border-radius: 6px; padding: 7px 10px; margin-bottom: 8px;
}
.chat-session-search input { border: none; background: transparent; outline: none; flex: 1; font-size: 13px; color: #111; }
.chat-session-search svg { width: 15px; height: 15px; color: #999; }
.chat-session-tabs { display: flex; gap: 6px; }
.chat-session-tab {
  flex: 1; padding: 7px 0; border: none; background: #f2f2f2;
  border-radius: 6px; font-size: 12.5px; cursor: pointer; color: #666; font-weight: 500;
}
.chat-session-tab.active { background: #07c160; color: #fff; }

.chat-session-items { flex: 1; overflow-y: auto; }
.chat-session-item {
  padding: 12px 14px; cursor: pointer; display: flex; align-items: center; gap: 11px;
  border-bottom: 1px solid #f5f5f5; transition: background .12s;
}
.chat-session-item:hover { background: #f7f7f7; }
.chat-session-item.active { background: #e8f7ee; }
.chat-session-avatar {
  width: 42px; height: 42px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff; background: #576b95;
}
.chat-session-avatar.online { background: #07c160; }
.chat-session-info { flex: 1; min-width: 0; }
.chat-session-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; color: #111; }
.chat-session-preview { font-size: 12px; color: #999; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-session-time { font-size: 11px; color: #c0c0c0; margin-top: 2px; }
.chat-session-unread {
  min-width: 19px; height: 19px; padding: 0 5px; background: #fa5151; color: #fff;
  border-radius: 10px; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.chat-session-empty { text-align: center; color: #aaa; font-size: 13px; padding: 60px 20px; line-height: 1.9; }
.chat-session-empty::before { content: '🗂️'; display: block; font-size: 32px; margin-bottom: 8px; }

/* 右侧聊天区 */
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #ededed; }
.chat-main-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #aaa; font-size: 14px; gap: 10px;
}
.chat-main-empty::before { content: '💬'; font-size: 52px; opacity: .4; }
.chat-main-empty .hint { font-size: 13px; }

.chat-main-header {
  padding: 12px 20px; border-bottom: 1px solid #e0e0e0; display: flex; align-items: center; justify-content: space-between;
  background: #ededed;
}
.chat-main-user { display: flex; align-items: center; gap: 11px; }
.chat-main-avatar {
  width: 42px; height: 42px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px; color: #fff; background: #07c160;
}
.chat-main-name-row { display: flex; align-items: center; gap: 8px; }
.chat-main-name { font-size: 15px; font-weight: 600; color: #111; }
.chat-main-status { font-size: 12px; color: #999; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.chat-main-actions { display: flex; gap: 8px; }

.chat-main-body { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }

.chat-main-footer { padding: 12px 20px; border-top: 1px solid #e0e0e0; background: #f7f7f7; }
.chat-quick-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chat-quick-btn {
  padding: 5px 12px; border: 1px solid #e0e0e0; background: #fff; border-radius: 5px;
  font-size: 12px; cursor: pointer; color: #555;
}
.chat-quick-btn:hover { background: #e8f7ee; color: #07c160; border-color: #07c160; }

.chat-admin-input { display: flex; gap: 10px; align-items: flex-end; }
.chat-admin-input textarea {
  flex: 1; border: none; border-radius: 6px; padding: 11px 14px; font-size: 14px;
  resize: none; outline: none; min-height: 44px; max-height: 130px; font-family: inherit;
  line-height: 1.5; background: #fff;
}
.chat-admin-input button:not(.chat-image-btn) {
  padding: 12px 20px; border: none; border-radius: 6px; cursor: pointer;
  background: #07c160; color: #fff; font-size: 14px; font-weight: 600;
}
.chat-admin-input button:disabled { background: #c5e8d2; cursor: not-allowed; }

.badge-small { font-size: 11px; padding: 3px 9px; border-radius: 4px; font-weight: 600; }
.badge-open { background: #e8f7ee; color: #07c160; }
.badge-closed { background: #f0f0f0; color: #999; }

.chat-body::-webkit-scrollbar, .chat-session-items::-webkit-scrollbar, .chat-main-body::-webkit-scrollbar { width: 5px; }
.chat-body::-webkit-scrollbar-thumb, .chat-session-items::-webkit-scrollbar-thumb, .chat-main-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ---------- 删除功能 ---------- */
.ses-check { width: 16px; height: 16px; accent-color: #07c160; flex-shrink: 0; cursor: pointer; }
.bulk-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 2px 12px;
  border-bottom: 1px solid #f0f0f0; margin-bottom: 4px;
}

.msg-del {
  position: absolute; top: 4px; right: 8px;
  width: 18px; height: 18px; line-height: 16px; text-align: center;
  font-size: 10px; color: #bbb; background: transparent; border: none;
  cursor: pointer; border-radius: 4px; opacity: 0; transition: opacity .12s, background .12s;
  z-index: 2;
}
.chat-row:hover .msg-del { opacity: 1; }
.msg-del:hover { background: #fee2e2; color: #dc2626; }
.chat-pause-bar {
  margin: 6px 10px; padding: 8px 12px;
  background: #fff7ed; border: 1px solid #fed7aa; color: #b45309;
  border-radius: 8px; font-size: 12px; line-height: 1.5; text-align: center;
}

/* ============================================================
   深色模式 + 移动端工作台适配（追加）
   ============================================================ */

/* ---------- 深色模式覆盖 ---------- */
[data-theme="dark"] .chat-window,
[data-theme="dark"] .chat-widget { color-scheme: dark; }

[data-theme="dark"] .chat-window { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .chat-header { background: var(--card); border-bottom-color: var(--border); color: var(--foreground); }
[data-theme="dark"] .chat-body { background: var(--background); }
[data-theme="dark"] .chat-footer { background: var(--card); border-top-color: var(--border); }
[data-theme="dark"] .chat-input { color: var(--foreground); }
[data-theme="dark"] .chat-row .msg-bubble { color: var(--foreground); }
[data-theme="dark"] .chat-row.user .msg-bubble { background: #14532d; color: #d1fae5; }
[data-theme="dark"] .chat-row.admin .msg-bubble { background: var(--card); border: 1px solid var(--border); }
[data-theme="dark"] .chat-time { color: var(--muted-foreground); }
[data-theme="dark"] .chat-email-form { background: var(--card); }
[data-theme="dark"] .chat-email-form input { background: var(--background); color: var(--foreground); border-color: var(--border); }
[data-theme="dark"] .chat-email-hint { color: var(--muted-foreground); }
[data-theme="dark"] .chat-online { color: var(--muted-foreground); }

/* 工作台 */
[data-theme="dark"] .chat-workspace { background: var(--bg); }
[data-theme="dark"] .chat-session-list { background: var(--card); border-right-color: var(--border); }
[data-theme="dark"] .chat-session-header { border-bottom-color: var(--border); }
[data-theme="dark"] .chat-session-header h2 { color: var(--foreground); }
[data-theme="dark"] .chat-session-search { background: var(--muted); }
[data-theme="dark"] .chat-session-search input { color: var(--foreground); }
[data-theme="dark"] .chat-session-search svg { color: var(--muted-foreground); }
[data-theme="dark"] .chat-session-tab { background: var(--muted); color: var(--muted-foreground); }
[data-theme="dark"] .chat-session-tab.active { background: #07c160; color: #fff; }
[data-theme="dark"] .chat-session-item { border-bottom-color: var(--border); }
[data-theme="dark"] .chat-session-item:hover { background: var(--muted); }
[data-theme="dark"] .chat-session-item.active { background: rgba(7, 193, 96, 0.12); }
[data-theme="dark"] .chat-session-name { color: var(--foreground); }
[data-theme="dark"] .chat-session-preview { color: var(--muted-foreground); }
[data-theme="dark"] .chat-session-time { color: var(--muted-foreground); }
[data-theme="dark"] .chat-session-empty { color: var(--muted-foreground); }
[data-theme="dark"] .chat-main { background: var(--bg); }
[data-theme="dark"] .chat-main-empty { color: var(--muted-foreground); }
[data-theme="dark"] .chat-main-header { background: var(--card); border-bottom-color: var(--border); }
[data-theme="dark"] .chat-main-name { color: var(--foreground); }
[data-theme="dark"] .chat-main-status { color: var(--muted-foreground); }
[data-theme="dark"] .chat-main-footer { background: var(--card); border-top-color: var(--border); }
[data-theme="dark"] .chat-quick-btn { background: var(--muted); border-color: var(--border); color: var(--foreground); }
[data-theme="dark"] .chat-quick-btn:hover { background: rgba(7, 193, 96, 0.15); color: #07c160; border-color: #07c160; }
[data-theme="dark"] .chat-admin-input textarea { background: var(--background); color: var(--foreground); }
[data-theme="dark"] .chat-admin-input button:disabled { background: #1f3a2b; }
[data-theme="dark"] .badge-closed { background: var(--muted); color: var(--muted-foreground); }
[data-theme="dark"] .chat-body::-webkit-scrollbar-thumb,
[data-theme="dark"] .chat-session-items::-webkit-scrollbar-thumb,
[data-theme="dark"] .chat-main-body::-webkit-scrollbar-thumb { background: var(--border); }
[data-theme="dark"] .bulk-bar { border-bottom-color: var(--border); }
[data-theme="dark"] .msg-del:hover { background: rgba(239, 68, 68, 0.15); }
[data-theme="dark"] .chat-pause-bar { background: var(--warning-soft); border-color: var(--warning); color: var(--warning-text); }
[data-theme="dark"] .chat-typing-bar { background: var(--muted); color: var(--muted-foreground); }
[data-theme="dark"] .chat-session-src { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .chat-main-email { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* 落地页登录/注册上的聊天窗（login/register 页） */
[data-theme="dark"] .kf-landing .chat-window { box-shadow: 0 12px 40px rgba(0,0,0,.6); }

/* ---------- 移动端：客服工作台三栏 → 单栏流式 ---------- */
@media (max-width: 860px) {
  .chat-workspace { margin: 0; height: calc(100vh - var(--header-height, 58px)); }
  .chat-session-list {
    width: 100%; min-width: 0; max-width: none;
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 5;
    transform: translateX(0);
  }
  .chat-workspace.chatting .chat-session-list { transform: translateX(-100%); }
  .chat-workspace.chatting .chat-main { display: flex; }
  .chat-main { display: none; }
  .chat-main-header { padding: 10px 12px; }
  .chat-main-body { padding: 12px; }
  .chat-main-footer { padding: 10px 12px; }
  .chat-session-item { padding: 11px 12px; }
  .chat-main-actions .btn-sm { padding: 6px 10px; font-size: 12px; }
  .chat-main-email { max-width: 150px; }
}
