/* ==========================================================
   红尘客服 · 共享样式
   纯前端零依赖，file:// 直接打开即可运行
   ========================================================== */

:root {
  --brand: #3b6cf6;
  --brand-dark: #2a51d0;
  --brand-soft: #eaf0ff;
  --bg: #f3f5fa;
  --panel: #ffffff;
  --line: #e7eaf3;
  --line-soft: #f0f2f8;
  --text: #1b2233;
  --text-2: #4a5468;
  --muted: #8b95a9;
  --danger: #f5455c;
  --ok: #12b76a;
  --warn: #f79009;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 26px rgba(22, 38, 74, 0.08);
  --shadow-sm: 0 2px 8px rgba(22, 38, 74, 0.06);
  --sidebar: #182036;
  --sidebar-2: #212b45;
  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: inherit;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: #cdd3e2;
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover { background: #b3bbcd; }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* -------------------------------------------------- 通用组件 */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn:hover { border-color: #c9d2e8; color: var(--brand); background: #fbfcff; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 108, 246, 0.28);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fff1f3; border-color: #ffd3d9; color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
}
.tag-waiting { background: #fff4e5; color: #d97706; }
.tag-active { background: #e7f8f0; color: #0e9f6e; }
.tag-closed { background: #f0f2f7; color: var(--muted); }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  user-select: none;
}
.avatar.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 13px; }
.avatar.lg { width: 52px; height: 52px; border-radius: 15px; font-size: 19px; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.16); }
.dot.off { background: #b6bdcb; }

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex: none;
}

.toast-wrap {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 10px;
  background: rgba(24, 32, 54, 0.92);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease;
  max-width: 80vw;
}
.toast.err { background: rgba(219, 45, 70, 0.95); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: none; }
}

/* 弹窗 */
dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(520px, 92vw);
  box-shadow: 0 24px 70px rgba(15, 25, 50, 0.3);
  color: var(--text);
}
dialog::backdrop { background: rgba(17, 24, 43, 0.45); }
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.dlg-body { padding: 18px 20px; max-height: 62vh; overflow: auto; }
.dlg-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 0 0 16px 16px;
}
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field .desc { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.field input:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 108, 246, 0.12);
}
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { width: 16px; height: 16px; accent-color: var(--brand); }

/* -------------------------------------------------- 消息气泡（两端共用） */

.msgs-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 22px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

.day-sep {
  align-self: center;
  margin: 12px 0 10px;
  padding: 3px 11px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--muted);
  font-size: 12px;
  user-select: none;
}

.sys-msg {
  align-self: center;
  max-width: 76%;
  margin: 6px 0;
  padding: 4px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.045);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

.row {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  max-width: 74%;
  margin-top: 9px;
}
.row.me { align-self: flex-end; flex-direction: row-reverse; }
.row .avatar { margin-top: 2px; }

.bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: 13px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  white-space: pre-wrap;
  min-width: 42px;
}
.row:not(.me) .bubble { border-top-left-radius: 4px; }
.row.me .bubble {
  background: var(--brand);
  color: #fff;
  border-top-right-radius: 4px;
}
.bubble .txt { word-break: break-word; }
.bubble .meta {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.row.me .bubble .meta { justify-content: flex-end; color: rgba(255, 255, 255, 0.72); }
.bubble .auto-flag {
  display: inline-block;
  margin-bottom: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(245, 69, 92, 0.12);
  color: var(--danger);
  font-size: 11px;
}

.bubble img.msg-img {
  display: block;
  max-width: 230px;
  max-height: 230px;
  border-radius: 9px;
  cursor: zoom-in;
  background: #f0f2f7;
}

.typing {
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0 41px;
  padding: 7px 13px;
  border-radius: 13px 13px 13px 4px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 13px;
}
.typing.on { display: inline-flex; }
.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #b6bdcb;
  animation: bounce 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.scroll-bottom {
  position: absolute;
  right: 18px;
  bottom: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--muted);
  display: none;
  place-items: center;
  z-index: 5;
}
.scroll-bottom.on { display: grid; }

/* -------------------------------------------------- 输入区（两端共用） */

.composer {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 9px 14px 12px;
  position: relative;
}
.composer-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  transition: 0.15s;
}
.tool-btn:hover { background: var(--brand-soft); color: var(--brand); }
.composer-tools .hint {
  margin-left: auto;
  font-size: 12px;
  color: #b3bbcd;
}
.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 140px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfe;
  resize: none;
  outline: none;
  line-height: 1.65;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.composer textarea:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 108, 246, 0.1);
}
.composer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.composer-foot .tip { font-size: 12px; color: #b3bbcd; }
.send-btn {
  margin-left: auto;
  height: 34px;
  padding: 0 22px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(59, 108, 246, 0.28);
  transition: 0.15s;
}
.send-btn:hover { background: var(--brand-dark); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* 待发送图片预览条 */
.pending {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px dashed #cfd8ee;
  border-radius: 10px;
  background: #fafbff;
  max-height: 130px;
  overflow: auto;
}
.pending.on { display: flex; }
.pending .item {
  position: relative;
  width: 74px;
  height: 74px;
  border-radius: 9px;
  overflow: hidden;
  background: #eef1f8;
}
.pending .item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pending .item .x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  line-height: 19px;
  text-align: center;
}
.pending .item .x:hover { background: var(--danger); }
.pending .item .loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.75);
  font-size: 11px;
  color: var(--brand);
}

/* 表情面板 */
.emoji-panel {
  position: absolute;
  left: 12px;
  bottom: 100%;
  margin-bottom: 6px;
  width: 306px;
  max-height: 232px;
  overflow: auto;
  padding: 8px;
  display: none;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 30;
}
.emoji-panel.on { display: grid; }
.emoji-panel button {
  height: 28px;
  border-radius: 6px;
  font-size: 17px;
  line-height: 1;
}
.emoji-panel button:hover { background: var(--brand-soft); }

/* -------------------------------------------------- 登录遮罩 / 网络状态 */

.lock {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(150deg, #1b2440, #26325a);
}
.lock-box {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 30px 26px 24px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.lock-logo {
  width: 54px; height: 54px; border-radius: 17px; margin: 0 auto 16px;
  background: linear-gradient(135deg, #4b7cff, #7c5cf6);
  color: #fff; display: grid; place-items: center; font-size: 26px;
  box-shadow: 0 8px 22px rgba(76, 92, 246, 0.45);
}
.lock-box h2 { margin: 0 0 7px; font-size: 18px; }
.lock-box p { margin: 0 0 20px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.lock-box input {
  width: 100%; height: 42px; padding: 0 14px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fafbfe;
  text-align: center; outline: none; transition: .15s; font-size: 15px;
  letter-spacing: 2px;
}
.lock-box input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(59,108,246,.12); }
.lock-box button {
  width: 100%; height: 42px; border-radius: 10px; font-weight: 600; font-size: 15px;
  background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(59,108,246,.32);
}
.lock-box button:hover { background: var(--brand-dark); }
.lock-box button:disabled { opacity: .6; cursor: not-allowed; }
.lock-tip { margin: 14px 0 0; font-size: 12.5px; color: var(--danger); min-height: 18px; }

.netbar {
  flex: none;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 16px;
  background: #fff7e6; color: #b45309; font-size: 13px;
  border-bottom: 1px solid #fde68a;
}.netbar .spin {
  width: 13px; height: 13px; flex: none;
  border: 2px solid #f0c98a; border-top-color: #b45309;
  border-radius: 50%; animation: spin .8s linear infinite;
}
.netbar.off { background: #fff1f3; color: #b42318; border-bottom-color: #fecdd3; }
.netbar.off .spin { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 二维码 */
.qr-dialog { text-align: center; }
.qr-lead { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.qr-holder {
  display: inline-block; padding: 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
  line-height: 0;
}
.qr-holder canvas { display: block; width: 180px; height: 180px; image-rendering: pixelated; }
.qr-hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.qr-hint.err { color: var(--danger); }

/* 拖拽遮罩 */
.dropzone {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(59, 108, 246, 0.08);
  border: 2px dashed var(--brand);
  border-radius: 12px;
  margin: 10px;
  color: var(--brand);
  font-size: 15px;
  font-weight: 600;
  z-index: 40;
  pointer-events: none;
}
.dropzone.on { display: grid; }

/* 图片查看器 */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  place-items: center;
  background: rgba(10, 14, 26, 0.86);
  cursor: zoom-out;
  padding: 40px;
}
.lightbox.on { display: grid; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
