/* ============ 经典 QQ 风格 客服系统 公共样式 ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font: 12px/1.6 "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  color: #333; background: #d7e7f7;
  background-image: linear-gradient(160deg, #cfe3f7 0%, #a7c8e8 100%);
  overflow: hidden;
}
:root {
  --qq-blue: #4a90d9;
  --qq-blue-dark: #2d6da4;
  --qq-border: #a8c8e8;
  --qq-border-light: #cfe0f2;
  --qq-bg: #eef5fc;
  --panel: #ffffff;
  --text: #333;
  --muted: #8a9aab;
  --bubble-in: #ffffff;
  --bubble-in-border: #c9dcf0;
  --bubble-out: #a7d8f7;
  --bubble-out-border: #6cb0e0;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; outline: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c3d6ea; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a8c2dd; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- 窗口外壳 ---------------- */
.qq-window {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  background: var(--panel);
  border: 1px solid #8fb8dd;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(20, 60, 110, .28);
  overflow: hidden;
}
.qq-titlebar {
  flex: 0 0 auto; height: 46px; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; color: #fff; user-select: none;
  background: linear-gradient(180deg, #6cb0e6 0%, #4a90d9 48%, #3a7fc8 52%, #2d6da4 100%);
  border-bottom: 1px solid #245c8f;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .35);
}
.qq-titlebar .tb-avatar {
  width: 32px; height: 32px; border-radius: 3px; background: #fff; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); object-fit: cover; flex: 0 0 auto;
}
.qq-titlebar .tb-info { flex: 1 1 auto; min-width: 0; }
.qq-titlebar .tb-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qq-titlebar .tb-sub { font-size: 11px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qq-titlebar .tb-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.tb-btn {
  height: 24px; padding: 0 10px; color: #fff; font-size: 12px;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.45);
  border-radius: 3px; transition: background .15s;
}
.tb-btn:hover { background: rgba(255,255,255,.34); }
.tb-btn.danger { background: rgba(220, 60, 60, .55); border-color: rgba(255,180,180,.6); }
.tb-btn.danger:hover { background: rgba(220, 60, 60, .8); }

/* ---------------- 主体布局 ---------------- */
.qq-body { flex: 1 1 auto; display: flex; min-height: 0; }
.qq-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------------- 消息区 ---------------- */
.msg-list {
  flex: 1 1 auto; overflow-y: auto; padding: 14px 16px;
  background: #f7fbff;
  background-image:
    radial-gradient(circle at 12px 12px, rgba(120,170,220,.06) 1.5px, transparent 1.6px);
  background-size: 24px 24px;
}
.msg-time { text-align: center; margin: 12px 0 10px; }
.msg-time span {
  display: inline-block; padding: 2px 10px; font-size: 11px; color: #8a9aab;
  background: rgba(210, 226, 242, .7); border-radius: 10px;
}
.msg-sys { text-align: center; margin: 8px 0; }
.msg-sys span {
  display: inline-block; max-width: 82%; padding: 4px 12px; font-size: 11px; color: #6f8598;
  background: #eaf2fa; border: 1px solid #d6e5f4; border-radius: 12px;
}
.msg-row { display: flex; margin-bottom: 14px; align-items: flex-start; gap: 9px; }
.msg-row.me { flex-direction: row-reverse; }
.msg-avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 4px; overflow: hidden;
  background: #fff; border: 1px solid #b9d3ea; box-shadow: 0 1px 2px rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-col { max-width: 68%; min-width: 0; display: flex; flex-direction: column; }
.msg-row.me .msg-col { align-items: flex-end; }
.msg-meta { font-size: 11px; color: #93a5b6; margin: 0 2px 4px; display: flex; gap: 6px; align-items: center; }
.msg-bubble {
  position: relative; padding: 8px 12px; font-size: 13px; line-height: 1.65;
  border-radius: 5px; word-break: break-word; white-space: pre-wrap;
  background: var(--bubble-in); border: 1px solid var(--bubble-in-border);
  box-shadow: 0 1px 2px rgba(60, 100, 140, .08);
}
.msg-bubble::before, .msg-bubble::after {
  content: ''; position: absolute; top: 11px; width: 0; height: 0;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.msg-row:not(.me) .msg-bubble::before { left: -8px; border-right: 8px solid var(--bubble-in-border); }
.msg-row:not(.me) .msg-bubble::after { left: -7px; border-right: 8px solid var(--bubble-in); }
.msg-row.me .msg-bubble {
  background: linear-gradient(180deg, #bde4fb 0%, var(--bubble-out) 100%);
  border-color: var(--bubble-out-border); color: #123;
}
.msg-row.me .msg-bubble::before { right: -8px; border-left: 8px solid var(--bubble-out-border); }
.msg-row.me .msg-bubble::after { right: -7px; border-left: 8px solid var(--bubble-out); }
.msg-bubble.plain { background: none !important; border: none !important; box-shadow: none; padding: 0; }
.msg-bubble.plain::before, .msg-bubble.plain::after { display: none; }
.msg-bubble img.msg-image {
  max-width: 220px; max-height: 220px; border-radius: 4px; display: block; cursor: zoom-in;
  border: 1px solid #cfe0f2; background: #fff;
}
.msg-bubble img.msg-sticker { width: 92px; height: 92px; display: block; }
.msg-status { font-size: 11px; color: #9bb0c4; margin-top: 3px; }
.msg-status.failed { color: #e05252; cursor: pointer; }

/* ---------------- 输入区 ---------------- */
.composer { flex: 0 0 auto; border-top: 1px solid #cfe0f2; background: #fff; display: flex; flex-direction: column; }
.composer-toolbar {
  height: 34px; display: flex; align-items: center; gap: 4px; padding: 0 8px;
  background: linear-gradient(180deg, #fbfdff 0%, #eef5fc 100%);
  border-bottom: 1px solid #e6eff8;
}
.tool-btn {
  width: 28px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 3px; font-size: 16px; color: #4a7ba7;
}
.tool-btn:hover { background: #dcebf9; border-color: #b7d5ef; }
.tool-btn.active { background: #cfe4f7; border-color: #8fbde4; }
.toolbar-spacer { flex: 1 1 auto; }
.toolbar-tip { font-size: 11px; color: #9bb0c4; padding-right: 4px; }
.composer-input {
  flex: 1 1 auto; min-height: 78px; max-height: 200px; padding: 8px 12px; font-size: 13px; line-height: 1.6;
  border: none; resize: none; background: #fff; color: #333;
}
.composer-actions {
  height: 42px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 10px 8px;
}
.btn {
  height: 27px; padding: 0 16px; font-size: 12px; border-radius: 3px; border: 1px solid #a9c9e6;
  background: linear-gradient(180deg, #ffffff 0%, #e9f2fb 100%); color: #2c5d8c;
}
.btn:hover { background: linear-gradient(180deg, #f4f9ff 0%, #dbeafa 100%); }
.btn:active { background: #d3e6f8; }
.btn.primary {
  border-color: #2f7cc0; color: #fff;
  background: linear-gradient(180deg, #7ec0f0 0%, #4a90d9 50%, #3d84cf 51%, #2f7cc0 100%);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- 表情面板 ---------------- */
.emoji-panel {
  position: absolute; z-index: 60; width: 372px; background: #fff;
  border: 1px solid #8fb8dd; border-radius: 5px; box-shadow: 0 8px 24px rgba(30, 70, 120, .3);
  display: none; overflow: hidden;
}
.emoji-panel.open { display: block; }
.emoji-tabs { display: flex; background: linear-gradient(180deg,#f7fbff,#e8f2fb); border-bottom: 1px solid #d5e6f5; }
.emoji-tab { padding: 7px 16px; font-size: 12px; color: #4a7ba7; background: none; border: none; border-right: 1px solid #e2eefa; }
.emoji-tab.active { background: #fff; color: #1f5a8c; font-weight: 700; box-shadow: inset 0 -2px 0 #4a90d9; }
.emoji-grid { display: grid; padding: 8px; max-height: 208px; overflow-y: auto; }
.emoji-grid.faces { grid-template-columns: repeat(12, 1fr); gap: 2px; }
.emoji-grid.stickers { grid-template-columns: repeat(6, 1fr); gap: 6px; }
.emoji-cell {
  display: flex; align-items: center; justify-content: center; border: 1px solid transparent;
  border-radius: 3px; background: none; padding: 3px;
}
.emoji-grid.faces .emoji-cell { height: 28px; font-size: 19px; line-height: 1; }
.emoji-grid.stickers .emoji-cell { height: 54px; }
.emoji-grid.stickers .emoji-cell img { width: 44px; height: 44px; }
.emoji-cell:hover { background: #e3f0fc; border-color: #a8cdec; }

/* ---------------- 侧栏（坐席台/会话列表） ---------------- */
.side {
  width: 232px; flex: 0 0 232px; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #f4f9fe 0%, #e8f1fa 100%);
  border-right: 1px solid #cfe0f2; min-height: 0;
}
.side-head {
  height: 32px; display: flex; align-items: center; padding: 0 10px; gap: 8px;
  font-size: 12px; font-weight: 700; color: #2c5d8c;
  background: linear-gradient(180deg,#e4f0fb,#d3e6f8); border-bottom: 1px solid #c2daf0;
}
.side-list { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.side-section { font-size: 11px; color: #6d8ba6; padding: 6px 10px 3px; background: #e9f2fb; border-bottom: 1px solid #dcebf8; }
.conv-item {
  display: flex; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #e6f0fa; cursor: pointer; align-items: center;
}
.conv-item:hover { background: #e2f0fd; }
.conv-item.active { background: linear-gradient(180deg,#cfe6fb,#b9d9f6); box-shadow: inset 3px 0 0 #2f7cc0; }
.conv-avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 4px; border: 1px solid #b9d3ea; background: #fff;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 14px;
}
.conv-meta { flex: 1 1 auto; min-width: 0; }
.conv-name { font-size: 12px; font-weight: 700; color: #2b4a66; display: flex; align-items: center; gap: 4px; }
.conv-name .tag { font-size: 10px; font-weight: 400; color: #fff; background: #7fa9d0; border-radius: 2px; padding: 0 4px; }
.conv-last { font-size: 11px; color: #8a9aab; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-right { flex: 0 0 auto; text-align: right; }
.conv-time { font-size: 10px; color: #9bb0c4; }
.badge {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; margin-top: 3px;
  font-size: 10px; color: #fff; background: #e5484d; border-radius: 8px; text-align: center;
}
.empty-tip { padding: 24px 12px; text-align: center; color: #9bb0c4; font-size: 12px; }

/* ---------------- 通用小组件 ---------------- */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #b9c6d2; }
.dot.online { background: #4caf50; box-shadow: 0 0 4px rgba(76,175,80,.7); }
.dot.busy { background: #ff9800; }
.dot.offline { background: #b9c6d2; }
.pill {
  display: inline-block; padding: 1px 7px; font-size: 11px; border-radius: 9px;
  background: #e8f2fb; color: #3c74a8; border: 1px solid #c9deef;
}
.pill.warn { background: #fff4e0; color: #a26a12; border-color: #f0d9ae; }
.pill.ok { background: #e7f7e9; color: #2e7d32; border-color: #bfe6c3; }
.pill.err { background: #fdeaea; color: #c62828; border-color: #f3c2c2; }

.mask {
  position: fixed; inset: 0; background: rgba(12, 34, 56, .45); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.mask.open { display: flex; }
.dialog {
  background: #fff; border-radius: 6px; border: 1px solid #8fb8dd; min-width: 300px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(10, 40, 80, .35); overflow: hidden;
}
.dialog-head {
  height: 36px; display: flex; align-items: center; padding: 0 12px; font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(180deg,#5ba3e0,#2d6da4);
}
.dialog-body { padding: 14px 16px; font-size: 12px; max-height: 66vh; overflow-y: auto; }
.dialog-foot { padding: 10px 14px; display: flex; justify-content: flex-end; gap: 8px; background: #f5faff; border-top: 1px solid #e2eefa; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; margin-bottom: 4px; color: #4a6f92; }
.input, .select, .textarea {
  width: 100%; padding: 6px 8px; font-size: 12px; border: 1px solid #b9d3ea; border-radius: 3px; background: #fff;
}
.input:focus, .select:focus, .textarea:focus { border-color: #4a90d9; box-shadow: 0 0 0 2px rgba(74,144,217,.15); }
.textarea { resize: vertical; min-height: 62px; }

.image-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 200; display: none;
  align-items: center; justify-content: center; cursor: zoom-out;
}
.image-viewer.open { display: flex; }
.image-viewer img { max-width: 92vw; max-height: 92vh; box-shadow: 0 10px 40px rgba(0,0,0,.6); }

.toast-wrap { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 6px; }
.toast {
  padding: 7px 16px; font-size: 12px; color: #fff; background: rgba(40, 60, 80, .92);
  border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.25); animation: toastIn .18s ease;
}
.toast.err { background: rgba(190, 50, 50, .94); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.typing-tip { font-size: 11px; color: #4a90d9; padding: 2px 16px; height: 18px; background: #f7fbff; }

/* ---------------- 移动端 H5 ---------------- */
@media (max-width: 768px) {
  body { background: #eef5fc; }
  .qq-window { border: none; border-radius: 0; box-shadow: none; height: 100%; }
  .qq-titlebar { height: 50px; padding: 0 10px; }
  .side { display: none; }
  .side.mobile-open {
    display: flex; position: absolute; z-index: 80; top: 0; bottom: 0; left: 0; width: 78%;
    box-shadow: 4px 0 20px rgba(0,0,0,.25);
  }
  .msg-col { max-width: 74%; }
  .msg-list { padding: 10px 10px 6px; }
  .composer-input { min-height: 56px; font-size: 14px; }
  .emoji-panel { width: 100% !important; left: 0 !important; right: 0; border-radius: 0; border-left: none; border-right: none; }
  .emoji-grid.faces { grid-template-columns: repeat(8, 1fr); gap: 4px; }
  .emoji-grid.faces .emoji-cell { height: 34px; font-size: 22px; }
  .emoji-grid.stickers { grid-template-columns: repeat(4, 1fr); }
  .emoji-grid.stickers .emoji-cell { height: 66px; }
  .emoji-grid.stickers .emoji-cell img { width: 54px; height: 54px; }
  .tool-btn { width: 34px; height: 30px; font-size: 19px; }
  .composer-toolbar { height: 40px; }
  .btn { height: 32px; padding: 0 18px; font-size: 13px; }
  .msg-bubble { font-size: 14px; }
  .dialog { width: 100%; }
}

/* ---------------- 机器人 / 自动回复 / 失效图 ---------------- */
.msg-avatar.bot-avatar {
  background: linear-gradient(160deg, #8ec5f0, #4a90d9);
  font-size: 19px; color: #fff;
}
.auto-badge {
  display: inline-block; padding: 0 5px; font-size: 10px; line-height: 14px;
  color: #3c74a8; background: #e8f2fb; border: 1px solid #c9deef; border-radius: 7px;
}
.img-broken {
  padding: 18px 22px; font-size: 12px; color: #9bb0c4;
  background: #f4f8fc; border: 1px dashed #cfe0f2; border-radius: 4px;
}

/* ---------------- 历史加载 / 可访问性 ---------------- */
.load-more {
  text-align: center; padding: 8px; margin-bottom: 6px; font-size: 12px; color: #4a7ba7;
  cursor: pointer; border-radius: 4px; background: rgba(226, 240, 253, .7);
}
.load-more:hover { background: #d7e9fa; }
.load-more.done { color: #9bb0c4; cursor: default; background: transparent; }
.rate-stars span:focus-visible,
.btn:focus-visible, .tb-btn:focus-visible, .tool-btn:focus-visible,
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: 2px solid #2f7cc0; outline-offset: 1px;
}
.msg-sys span, .conv-last, .toolbar-tip { color: #6b8199; }
