/* ---------- 新消息提醒条（客户不在聊天页时，客服回复从顶部滑入） ---------- */
#msg-alert {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(var(--safe-t) + 10px);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px 16px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.985);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  box-shadow:
    0 12px 32px rgba(16, 24, 40, 0.18),
    0 0 0 1px rgba(16, 24, 40, 0.045);
  transform: translateY(-160%);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.32s cubic-bezier(0.3, 0.9, 0.3, 1),
    opacity 0.22s ease;
}
#msg-alert.show {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}
.ma-ava {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: #dbe5ff;
  color: #2f5bd0;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ma-ava img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ma-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ma-name {
  font-size: 17px;
  color: var(--blue);
  font-weight: 650;
}
.ma-text {
  font-size: 18px;
  font-weight: 650;
  color: #142033;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ma-go {
  flex-shrink: 0;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 650;
}
.ma-go:active {
  transform: scale(0.96);
}
.ma-x {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: #b0b8c5;
  font-size: 18px;
  line-height: 1;
}

/* ---------- 聊天页头 ---------- */
.chat-hd {
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-t) + 6px) calc(8px + var(--safe-r)) 8px calc(4px + var(--safe-l));
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.back-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  background: none;
  color: #2b3240;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.back-btn:active {
  background: #f1f3f7;
}

.ava-wrap {
  position: relative;
  flex-shrink: 0;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #eef1f7;
  color: var(--blue);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c7d2e5;
  box-shadow: 0 0 0 2px #fff;
  transition: background 0.25s ease;
}
.dot.on {
  background: #34c759;
}
.dot.away {
  background: #ffb020;
}
.dot.wait {
  background: #c7d2e5;
}

.head-info {
  flex: 1;
  min-width: 0;
}
.head-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head-status {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 1px;
  letter-spacing: 0.1px;
}

/* ---------- 消息区 ---------- */
#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  padding: 14px 12px 8px;
  scrollbar-width: none;
}
#chat::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  animation: msgIn 0.24s cubic-bezier(0.2, 0.8, 0.3, 1);
}
/* 同一人连续消息：只压缩间距，头像每条都显示（不要用 visibility:hidden 隐藏） */
.msg.tight {
  margin-top: -6px;
}
.msg.me {
  flex-direction: row-reverse;
}

.msg .body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 76%;
  min-width: 0;
}
.msg.me .body {
  align-items: flex-end;
}

.ava {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  overflow: visible;
  background: #dfe6f6;
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}
.ava img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  display: block;
}
.ava::after {
  content: "";
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9aa3b5;
  border: 2px solid #fff;
  box-sizing: border-box;
}
.ava[data-state="on"]::after {
  background: #22c55e;
}
.msg.me .ava {
  background: #d6e0fb;
  color: var(--blue-d);
}

.bubble {
  max-width: 100%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 15.5px;
  line-height: 1.46;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.07);
  -webkit-user-select: text;
  user-select: text;
  transition: transform 0.12s ease;
}
.msg.agent .bubble {
  background: #fff;
  color: var(--ink);
  border-top-left-radius: 6px;
}
/* 欢迎语里的可点选项（企微式蓝色文字，点一下自动发送该内容） */
.qlink {
  display: inline;
  border: none;
  background: none;
  padding: 1px 2px;
  margin: 0;
  font: inherit;
  color: #2b6cf0;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.qlink:active {
  opacity: 0.55;
}
.qreveal {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f4f7ff;
  color: #1b2b68;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
/* 会话已结束提示条（客服主动结束后显示） */
#ended-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff7e8;
  color: #8a5b00;
  font-size: 13px;
  border-top: 1px solid var(--line);
}
#ended-bar[hidden] {
  display: none;
}
#ended-bar button {
  border: none;
  background: var(--blue);
  color: #fff;
  border-radius: 16px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.msg.me .bubble {
  background: linear-gradient(180deg, #4a63db 0%, var(--blue) 100%);
  color: #fff;
  border-top-right-radius: 6px;
}

.time {
  font-size: 11px;
  color: var(--ink-3);
  padding: 0 3px;
}

.ts {
  display: flex;
  justify-content: center;
  margin: 4px 0 14px;
}
.ts span {
  background: rgba(16, 24, 40, 0.055);
  color: #7b8494;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 9px;
  letter-spacing: 0.2px;
}

.msg.system {
  justify-content: center;
  margin-bottom: 12px;
}
.msg.system .bubble {
  background: rgba(16, 24, 40, 0.055);
  color: #6c7688;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 9px;
  box-shadow: none;
  text-align: center;
}
.msg.system .time,
.msg.system .ava {
  display: none;
}

.bubble img {
  max-width: 190px;
  max-height: 240px;
  border-radius: 12px;
  display: block;
  cursor: zoom-in;
  -webkit-touch-callout: none;
  background: #eef1f6; /* 图还没下完时先垫一层浅灰，不至于是一块突兀的白 */
}
.bubble.img-wrap {
  background: transparent !important;
  padding: 0 !important;
  box-shadow: none;
}
.msg.me .bubble.img-wrap {
  background: transparent !important;
}

#to-bottom {
  position: absolute;
  right: calc(14px + var(--safe-r));
  bottom: calc(70px + var(--safe-b));
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.16);
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 9;
}
#to-bottom.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
#to-bottom:active {
  transform: scale(0.92);
}

/* ---------- 输入区 ---------- */
.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.round-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  margin-bottom: 2px;
  border: none;
  border-radius: 50%;
  background: #f0f3f8;
  color: #667085;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.12s ease,
    background 0.15s ease;
}
.round-btn:active {
  transform: scale(0.88);
  background: #e4e9f2;
}

.field {
  flex: 1;
  min-width: 0;
  background: #f2f4f8;
  border-radius: 18px;
  padding: 7px 14px;
  transition:
    background 0.18s ease,
    box-shadow 0.18s ease;
}
.field:focus-within {
  background: #fff;
  box-shadow: 0 0 0 1.5px rgba(43, 74, 203, 0.35) inset;
}
#input {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  line-height: 22px;
  height: 22px;
  max-height: 96px;
  resize: none;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
#input::placeholder {
  color: #a6afbf;
}

#send {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  margin-bottom: 2px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(180deg, #4a63db, var(--blue));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(43, 74, 203, 0.38);
  transition:
    transform 0.12s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}
#send:active:not(:disabled) {
  transform: scale(0.9);
}
#send:disabled {
  background: #e8eefb;
  color: #a9b9de;
  box-shadow: none;
}

/* 选图用的 input 不能 display:none —— 部分安卓 WebView / 国产 ROM 下
     隐藏的 input 会被判定为"不可交互"，点按钮后相册根本弹不出来。
     改成"移出屏幕但保留在布局里"，由 <label for> 原生激活，兼容性最好。 */
.pick-input {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
label.round-btn {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
label.round-btn.off {
  opacity: 0.4;
  pointer-events: none;
}

/* 收到客服发的图 → 气泡下面挂一个"识别图中二维码"胶囊，
     安卓/桌面图标模式下没有长按菜单，不给入口客户根本不知道能识别 */
.qr-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 6px 0 0 2px;
  padding: 5px 11px;
  border: none;
  border-radius: 13px;
  background: #eaf0ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
.qr-chip:active {
  transform: scale(0.96);
  background: #dfe8ff;
}
.qr-chip.busy {
  opacity: 0.6;
}
.qr-chip svg {
  flex: none;
}

#tip {
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  padding: 48px 20px 0;
  line-height: 1.6;
}
#tip button {
  margin-top: 16px;
  border: none;
  color: #fff;
  font-size: 14px;
  background: var(--blue);
  border-radius: 19px;
  padding: 9px 24px;
}
