/* ===== 在线客服：悬浮挂件 + 聊天气泡窗（用户端 / 管理端共用） ===== */

/* 挂件：可全屏拖动，位置记忆到 localStorage（由 app.js / admin.js 写入 left/top） */
#cs-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 800;
  width: 64px;
  height: 64px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, .35));
}
#cs-widget:active { cursor: grabbing; }
#cs-widget img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
  display: block;
  pointer-events: none;
}
#cs-widget .cs-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger, #ff4d6d);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  display: none;
}
#cs-widget .cs-badge.show { display: block; }

/* 聊天弹窗 */
.cs-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 850;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 480px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--panel2, #ffffff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .35);
}
.cs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line, #e5e7eb);
}
.cs-head-title { display: flex; align-items: center; gap: 10px; }
.cs-head-avatar { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; }
.cs-head-title b { display: block; font-size: 14px; color: var(--text, #111); }
.cs-head-title span { font-size: 12px; color: var(--muted, #888); }
.cs-close {
  background: none;
  border: none;
  color: var(--muted, #888);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.cs-close:hover { color: var(--text, #111); }

.cs-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cs-msg { display: flex; flex-direction: column; max-width: 82%; }
.cs-msg.me { align-self: flex-end; }
.cs-msg.other { align-self: flex-start; }
.cs-bubble {
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.cs-msg.me .cs-bubble {
  background: var(--blue, #2563eb);
  color: #fff;
  border-top-right-radius: 4px;
}
.cs-msg.other .cs-bubble {
  background: var(--panel, #f1f5f9);
  color: var(--text, #111);
  border-top-left-radius: 4px;
}
.cs-meta { font-size: 11px; color: var(--muted, #999); margin-top: 3px; }
.cs-msg.me .cs-meta { text-align: right; }
.cs-empty { margin: auto; color: var(--muted, #999); font-size: 13px; text-align: center; }

.cs-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line, #e5e7eb);
  align-items: flex-end;
}
.cs-foot textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line, #e5e7eb);
  background: var(--panel, #fff);
  color: var(--text, #111);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13.5px;
  line-height: 1.4;
  max-height: 96px;
  outline: none;
}
.cs-foot textarea:focus { border-color: var(--blue, #2563eb); }
.cs-send {
  flex: none;
  border: none;
  background: var(--blue, #2563eb);
  color: #fff;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  cursor: pointer;
}
.cs-send:disabled { opacity: .6; cursor: not-allowed; }

@media (max-width: 640px) {
  #cs-widget { width: 56px; height: 56px; right: 14px; bottom: 74px; }
  .cs-panel { right: 10px; bottom: 80px; width: calc(100vw - 20px); height: 70vh; }
}

/* ===== 管理端客服两栏：会话列表 + 对话区 ===== */
.cs-admin {
  display: flex;
  gap: 14px;
  height: calc(100vh - 150px);
  min-height: 420px;
}
.cs-admin-list {
  width: 300px;
  flex: none;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 14px;
  overflow-y: auto;
  padding: 8px;
}
.cs-thread {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.cs-thread:hover { background: var(--line, rgba(34, 211, 238, .08)); }
.cs-thread.active {
  background: var(--line, rgba(34, 211, 238, .12));
  border-color: var(--line-strong, rgba(45, 212, 238, .45));
}
.cs-thread-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cs-thread-name { font-size: 14px; font-weight: 600; color: var(--text, #111); }
.cs-thread-time { font-size: 11px; color: var(--muted, #999); flex: none; }
.cs-thread-last {
  font-size: 12.5px;
  color: var(--muted, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cs-thread .cs-dot {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger, #ff4d6d);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  flex: none;
}
.cs-admin-main {
  flex: 1;
  background: var(--panel2, #fff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cs-admin-chat { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
@media (max-width: 900px) {
  .cs-admin { flex-direction: column; height: auto; }
  .cs-admin-list { width: 100%; max-height: 200px; }
}
