* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; min-height: -webkit-fill-available; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: #eef1f6;
  color: #1f2329;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ============ 访客端 ============ */
.chat-app {
  max-width: 480px;
  margin: 0 auto;
  height: var(--app-h, 100vh);
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 0 24px rgba(0,0,0,0.08);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
}
.chat-header .avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; overflow: hidden; flex-shrink: 0;
}
.chat-header .avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header .company { font-size: 16px; font-weight: 600; }
.chat-header .status { font-size: 12px; opacity: 0.9; display: flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.online { background: #4ade80; }

.messages { flex: 1; overflow-y: auto; padding: 16px; background: #f5f7fa; }

/* ============ 顶部公告条（单向左滚 + 无缝循环） ============ */
.announcement {
  height: 36px;
  background: linear-gradient(90deg, #fff7ed, #fef3c7);
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  display: flex;
  align-items: center;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}
.announcement::before {
  content: '📣';
  padding: 0 10px 0 14px;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  background: linear-gradient(90deg, #fff7ed 70%, rgba(255,247,237,0));
}
.announcement-track {
  display: flex;
  flex-shrink: 0;        /* 不被压缩，宽度由内容撑开 */
  white-space: nowrap;
  position: relative;
  animation: announce-marquee 18s linear infinite;
  will-change: transform;
}
.announcement-item {
  white-space: nowrap;
  padding-right: 80px;
  font-size: 13px;
  line-height: 36px;
  flex-shrink: 0;
}
@keyframes announce-marquee {
  from { transform: translateX(0); }
  to   { transform: translateX(calc(-100% / var(--copies, 3))); }
}
@media (prefers-reduced-motion: reduce) {
  .announcement-track { animation: none; transform: translateX(0); }
}
.sys-msg { text-align: center; margin: 10px 0; }
.sys-msg span {
  display: inline-block; background: #e4e8ef; color: #5b6573;
  font-size: 12px; padding: 5px 12px; border-radius: 12px; max-width: 80%;
}
.row { display: flex; margin: 10px 0; align-items: flex-end; gap: 8px; }
.row .bubble-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: #cdd5e0; display: flex; align-items: center; justify-content: center;
  font-size: 16px; overflow: hidden;
}
.row .bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }
.row .bubble {
  max-width: 72%; padding: 10px 14px; border-radius: 14px; font-size: 14px;
  line-height: 1.5; word-break: break-word; white-space: pre-wrap;
}
.row.visitor { flex-direction: row-reverse; }
.row.visitor .bubble { background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }
.row.admin .bubble { background: #fff; color: #1f2329; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.time { font-size: 11px; color: #99a; margin: 2px 4px; }

.composer {
  display: flex; gap: 8px; padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #e6e9ef; background: #fff;
}
.composer input {
  flex: 1; border: 1px solid #d9dee6; border-radius: 22px; padding: 10px 16px;
  font-size: 16px; outline: none;
}
.composer input:focus { border-color: #2563eb; }
.composer button {
  border: none; background: #2563eb; color: #fff; border-radius: 22px;
  padding: 0 20px; font-size: 14px; font-weight: 600;
}
.composer button:active { background: #1d4ed8; }

/* ============ 后台 ============ */
.login-wrap {
  height: var(--app-h, 100vh);
  min-height: -webkit-fill-available;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-card { background: #fff; padding: 36px; border-radius: 16px; width: 340px; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p { font-size: 13px; color: #8a93a0; margin-bottom: 22px; }
.login-card input {
  width: 100%; border: 1px solid #d9dee6; border-radius: 10px; padding: 12px 14px;
  font-size: 14px; margin-bottom: 14px; outline: none;
}
.login-card input:focus { border-color: #2563eb; }
.login-card button {
  width: 100%; border: none; background: #2563eb; color: #fff; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 600;
}
.login-card .err { color: #e11d48; font-size: 13px; margin-bottom: 10px; min-height: 18px; }

.admin-shell { display: flex; height: var(--app-h, 100vh); min-height: -webkit-fill-available; }
.sidebar { width: 300px; background: #fff; border-right: 1px solid #e6e9ef; display: flex; flex-direction: column; }
.sidebar-head {
  padding: 16px; border-bottom: 1px solid #eef1f6; display: flex; align-items: center;
  justify-content: space-between;
}
.sidebar-head .title { font-weight: 700; font-size: 16px; }
.icon-btn {
  border: 1px solid #d9dee6; background: #fff; border-radius: 8px; padding: 6px 10px;
  font-size: 13px; color: #475569;
}
.icon-btn:hover { background: #f5f7fa; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 14px 16px; border-bottom: 1px solid #f0f2f5; cursor: pointer; display: flex; gap: 10px;
}
.conv-item:hover { background: #f5f7fa; }
.conv-item.active { background: #eef4ff; }
.conv-item .ci-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #cdd5e0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: #475569;
}
.conv-item .ci-main { flex: 1; min-width: 0; }
.conv-item .ci-name { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; }
.conv-item .ci-name .ci-time { font-size: 11px; color: #aab; font-weight: 400; }
.conv-item .ci-last { font-size: 13px; color: #8a93a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.badge {
  background: #ef4444; color: #fff; font-size: 11px; min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 5px; display: inline-flex; align-items: center;
  justify-content: center; margin-left: 6px;
}
.empty { padding: 40px 16px; text-align: center; color: #aab; font-size: 14px; }

.main { flex: 1; display: flex; flex-direction: column; background: #f5f7fa; }
.main-head { padding: 14px 20px; background: #fff; border-bottom: 1px solid #e6e9ef; font-weight: 600; }
.main-msgs { flex: 1; overflow-y: auto; padding: 18px; }

/* 后台专属布局：客服（admin）自己的消息靠右，访客消息靠左（与访客端相反） */
.main-msgs .row.admin    { flex-direction: row-reverse; justify-content: flex-start; }
.main-msgs .row.visitor  { flex-direction: row; justify-content: flex-start; }
.main-msgs .row.admin    .bubble { background: #2563eb; color: #fff; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; box-shadow: none; }
.main-msgs .row.visitor  .bubble { background: #fff; color: #1f2329; border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.main-composer { display: flex; gap: 10px; padding: 14px 20px; background: #fff; border-top: 1px solid #e6e9ef; }
.main-composer textarea {
  flex: 1; border: 1px solid #d9dee6; border-radius: 12px; padding: 12px 14px;
  font-size: 16px; resize: none; outline: none; height: 52px; font-family: inherit;
}
.main-composer textarea:focus { border-color: #2563eb; }
.main-composer button {
  border: none; background: #2563eb; color: #fff; border-radius: 12px;
  padding: 0 24px; font-weight: 600; align-self: stretch;
}

/* 设置弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 420px; max-width: 92vw;
  padding: 26px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 17px; margin-bottom: 18px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: #475569; margin-bottom: 6px; font-weight: 600; }
.field input[type=text], .field textarea {
  width: 100%; border: 1px solid #d9dee6; border-radius: 10px; padding: 10px 12px;
  font-size: 14px; outline: none; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field textarea:focus { border-color: #2563eb; }
.avatar-pick { display: flex; align-items: center; gap: 14px; }
.avatar-pick .preview {
  width: 56px; height: 56px; border-radius: 50%; background: #e4e8ef;
  display: flex; align-items: center; justify-content: center; font-size: 26px; overflow: hidden; flex-shrink: 0;
}
.avatar-pick .preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-pick .ops { font-size: 13px; color: #475569; }
.link-btn { color: #2563eb; cursor: pointer; text-decoration: underline; margin-right: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.btn-primary { border: none; background: #2563eb; color: #fff; border-radius: 10px; padding: 10px 20px; font-weight: 600; }
.btn-ghost { border: 1px solid #d9dee6; background: #fff; color: #475569; border-radius: 10px; padding: 10px 20px; }
.divider { height: 1px; background: #eef1f6; margin: 18px 0; }
.hint { font-size: 12px; color: #aab; margin-top: 6px; }
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 0.95; }

/* ============ 图片消息 ============ */
.bubble.img-bubble {
  padding: 3px;
  background: transparent !important;
  box-shadow: none !important;
}
.bubble.img-bubble img {
  max-width: 200px;
  max-height: 240px;
  border-radius: 10px;
  display: block;
  cursor: pointer;
  object-fit: cover;
}
.row.visitor .bubble.img-bubble img { border-bottom-right-radius: 4px; }
.row.admin .bubble.img-bubble img { border-bottom-left-radius: 4px; }

/* 发送框里的图片缩略图预览 */
.img-thumb {
  display: flex; align-items: center; position: relative;
  padding: 8px 14px; background: #fff; border-top: 1px solid #e6e9ef;
}
.img-thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; }
.img-thumb-x {
  position: absolute; left: 62px; top: 4px; width: 18px; height: 18px;
  background: rgba(0,0,0,.6); color: #fff; border-radius: 50%;
  font-size: 13px; line-height: 18px; text-align: center; cursor: pointer; z-index: 2;
}

/* 输入框里的图片按钮 */
.composer-icon {
  border: none; background: transparent; font-size: 20px; cursor: pointer;
  padding: 0 4px; flex-shrink: 0; line-height: 1;
}

/* 图片放大预览遮罩 */
.img-preview-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,0.82);
  display: none; align-items: center; justify-content: center; z-index: 200; cursor: zoom-out;
}
.img-preview-mask img { max-width: 90vw; max-height: 90vh; border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,0.5); }

/* ============ 移动端适配 ============ */
/* 后台：窄屏改为上下布局，避免 300px 侧边栏把主聊天区挤没 */
@media (max-width: 768px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: 36vh; border-right: none; border-bottom: 1px solid #e6e9ef; }
  .main { min-height: 0; }
  .main-head { padding: 12px 14px; }
  .main-msgs { padding: 12px; }
  .main-composer { padding: 10px 12px; }
  .main-composer textarea { height: 46px; }
  .modal { width: 92vw; padding: 20px; }
}
/* 访客端：小屏收紧间距、放大气泡占比、防止内容溢出 */
@media (max-width: 480px) {
  .chat-header { padding: 12px; gap: 10px; }
  .chat-header .company { font-size: 15px; }
  .messages { padding: 12px; }
  .row { margin: 8px 0; }
  .row .bubble { max-width: 78%; padding: 9px 12px; font-size: 15px; }
  .row .bubble-avatar { width: 30px; height: 30px; font-size: 15px; }
  .composer { padding: 10px; gap: 6px; }
  .composer input { padding: 10px 14px; font-size: 16px; }
  .composer button { padding: 0 16px; }
  .img-thumb { padding: 8px 12px; }
  .img-thumb img { width: 48px; height: 48px; }
  .img-thumb-x { left: 56px; }
}
