/* ============================================================
   访客端（移动优先）— AlipayHK 视觉语言
   布局策略沿用：整屏固定 + 消息区独立滚动，避开 iOS 软键盘问题
   ============================================================ */

body.visitor {
  background: var(--ink-50);
  color: var(--ink-800);
  --stream-bg: #f2f7fb;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  margin: 0 auto;
  background: var(--stream-bg);
  box-shadow: 0 0 0 1px rgba(13, 27, 38, 0.05);
  /* 悬浮提示条（连接/排队）以 app 为定位上下文 */
  isolation: isolate;
  overflow: hidden;
}

/* ---------------------------------------------------- 顶栏
   AlipayHK 的头部偏轻盈：白底 + 品牌色文字 + 底部细分隔线，
   比整块深色渐变更接近它的气质 */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(11px + var(--safe-t)) 16px 11px;
  background: #fff;
  border-bottom: 1px solid var(--ink-100);
  z-index: 20;
  position: relative;
}
/* 顶部一条品牌色细线，呼应主色而不喧哗 */
.topbar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-500), var(--accent-500) 70%, var(--brand-400));
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.agent-face {
  position: relative;
  flex: none;
}
.agent-face .avatar {
  width: 42px;
  height: 42px;
  box-shadow: 0 3px 12px rgba(13, 27, 38, 0.16);
}
.agent-face .dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  border: 2px solid #fff;
}

.agent-meta {
  min-width: 0;
}
.agent-name {
  font-weight: 700;
  font-size: 16.5px;
  line-height: 1.25;
  color: var(--ink-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-sub {
  font-size: 12px;
  color: var(--ink-400);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 2px;
  flex: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-500);
  transition: background 0.16s ease, color 0.16s ease, transform 0.12s ease;
}
.icon-btn:hover {
  background: var(--brand-50);
  color: var(--brand-600);
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn[disabled] {
  opacity: 0.4;
}
.icon-btn.active {
  background: var(--brand-50);
  color: var(--brand-600);
}

/* ---------------------------------------------------- 连接状态与排队
   这两条都做成居中的悬浮胶囊，不再用整行横条：
   整行色块会压住消息、看着像报错，胶囊更轻，也不打断阅读。 */

.conn-bar {
  flex: none;
  position: absolute;
  /* 顶栏高度 + 一点间距，让它浮在消息区顶部而不是压住头像 */
  top: calc(var(--safe-t) + 76px);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink-600);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(13, 27, 38, 0.14);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(13, 27, 38, 0.05);
  z-index: 30;
  animation: pill-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.conn-bar[hidden] {
  display: none;
}
/* 连接条里的转圈也做小，跟胶囊的精致度匹配 */
.conn-bar .spin {
  width: 11px;
  height: 11px;
  border-width: 1.5px;
  border-color: rgba(13, 27, 38, 0.15);
  border-top-color: var(--brand-500);
}
.conn-bar.err {
  background: rgba(255, 236, 233, 0.96);
  color: #b52a17;
  border-color: rgba(244, 68, 46, 0.18);
}
.conn-bar.err .spin {
  display: none;
}
@keyframes pill-in {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
}

/* 排队提示：与连接条同一视觉语言，但用品牌色区分 */
.queue-bar {
  flex: none;
  position: absolute;
  top: calc(var(--safe-t) + 76px);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  background: rgba(232, 247, 254, 0.96);
  color: var(--brand-800);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 156, 232, 0.16);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 156, 232, 0.14);
  z-index: 31;
  animation: pill-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.queue-bar[hidden] {
  display: none;
}
/* 两条同时出现时叠放：排队条盖在连接条上（前者信息对访客更重要） */
.conn-bar:not([hidden]) ~ .conn-bar:not([hidden]) {
  top: calc(var(--safe-t) + 76px);
}
.queue-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-500);
  flex: none;
  animation: queue-pulse 1.5s ease-in-out infinite;
}
@keyframes queue-pulse {
  0%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* ---------------------------------------------------- 消息流 */

.stream {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 10px;
  outline: none;
  scroll-behavior: smooth;
}

.stream-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 100%;
  justify-content: flex-end;
  padding-bottom: 4px;
}

.day-sep {
  align-self: center;
  margin: 16px 0 10px;
  padding: 4px 13px;
  border-radius: var(--radius-pill);
  background: rgba(13, 27, 38, 0.05);
  color: var(--ink-400);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  margin-top: 10px;
  animation: msg-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.05);
}
.row.out {
  flex-direction: row-reverse;
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
}
.row .avatar {
  width: 34px;
  height: 34px;
  font-size: 13px;
  margin-bottom: 2px;
}
.row.out .avatar {
  display: none;
}

/* ---------------------------------------------------- 客服头像（品牌图标）
   统一用图片替换文字头像：顶栏、消息气泡、通话界面共用一处定义，
   用背景图而非 <img>，省掉各处的尺寸与圆角适配。 */

.avatar.agent {
  background-image: url('/visitor/AlipayHK_AppIcon_round.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  color: transparent;
  /* 文字仍留在 DOM 里供读屏使用，但视觉上藏起来 */
  font-size: 0;
  text-indent: -9999px;
  border: 0;
}
/* 通话界面的大头像保持清晰度 */
.call-avatar.avatar.agent {
  width: 100px;
  height: 100px;
  background-size: cover;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}
/* 消息气泡旁的小头像给一点白边，避免深色气泡里糊成一团 */
.row .avatar.agent {
  box-shadow: 0 0 0 1px rgba(13, 27, 38, 0.06);
}

.bubble-col {
  max-width: min(78%, 560px);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.row.out .bubble-col {
  align-items: flex-end;
}

/* 气泡：白底收到 / 品牌蓝渐变发出，圆角偏大 */
.bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink-800);
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.55;
}
.row.in .bubble {
  border-bottom-left-radius: 6px;
}
.row.out .bubble {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-brand);
}
.bubble.pending {
  opacity: 0.72;
}
.bubble.failed {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(244, 68, 46, 0.28);
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-300);
  padding: 0 3px;
}
.meta-line .tick {
  font-size: 12px;
  line-height: 1;
}
.meta-line .tick.read {
  color: var(--brand-500);
  font-weight: 700;
}

/* 系统 / 通话记录 */
.sys-row {
  align-self: center;
  margin: 11px 0;
  max-width: 86%;
  text-align: center;
}
.sys-pill {
  display: inline-block;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  background: rgba(13, 27, 38, 0.05);
  color: var(--ink-400);
  font-size: 12px;
}
.sys-pill.call {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 600;
}

/* 图片消息 */
.media-img {
  display: block;
  max-width: min(62vw, 300px);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: zoom-in;
  background: var(--ink-100);
  box-shadow: var(--shadow);
}
.media-img img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 380px;
  object-fit: cover;
}

/* 语音消息 */
.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 100px;
  padding: 11px 15px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
}
.row.in .voice {
  border-bottom-left-radius: 6px;
}
.row.out .voice {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-brand);
}
.voice-play {
  width: 20px;
  height: 20px;
  flex: none;
}
.voice-wave {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 20px;
}
.voice-wave i {
  display: block;
  width: 2.5px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}
.voice.playing .voice-wave i {
  animation: wave 0.9s ease-in-out infinite;
  opacity: 0.95;
}
@keyframes wave {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1); }
}
.voice-secs {
  font-size: 12px;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* 文件消息 */
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  max-width: 260px;
}
.row.out .file-card {
  background: var(--brand-50);
}
.file-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--brand-700);
  flex: none;
}
.file-info {
  min-width: 0;
}
.file-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size {
  font-size: 11.5px;
  color: var(--ink-400);
}

/* 打字指示 */
.typing-row .bubble {
  padding: 13px 17px;
}
.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand-300);
  animation: bounce 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* 回到底部 */
.jump-bottom {
  position: absolute;
  right: 14px;
  bottom: 100px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--brand-700);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 15;
}
.jump-bottom[hidden] {
  display: none;
}
.jump-bottom .badge {
  position: static;
}

/* ---------------------------------------------------- 输入区 */

.composer {
  flex: none;
  background: #fff;
  border-top: 1px solid var(--ink-100);
  padding-bottom: var(--safe-b);
  z-index: 18;
}

.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 9px 12px;
}

.toolbar {
  display: flex;
  gap: 4px;
  padding: 0 2px 7px;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar {
  display: none;
}
.toolbar .icon-btn {
  color: var(--ink-400);
  width: 35px;
  height: 35px;
  flex: none;
}
.toolbar .icon-btn:hover {
  background: var(--brand-50);
  color: var(--brand-600);
}

.text-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
}

.input {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 132px;
  padding: 11px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--ink-100);
  background: var(--ink-50);
  resize: none;
  outline: none;
  line-height: 1.45;
  font-size: 15px;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.input:focus {
  border-color: var(--brand-300);
  background: #fff;
  box-shadow: 0 0 0 3px var(--brand-50);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  box-shadow: var(--shadow-brand);
  transition: transform 0.12s ease, opacity 0.16s ease;
}
.send-btn:disabled {
  background: var(--ink-200);
  box-shadow: none;
  opacity: 0.7;
}
.send-btn:active:not(:disabled) {
  transform: scale(0.9);
}

/* 表情面板 */
.emoji-panel {
  flex: none;
  background: #fff;
  border-top: 1px solid var(--ink-100);
  max-height: 220px;
  overflow-y: auto;
  padding: 12px 14px calc(12px + var(--safe-b));
  animation: panel-up 0.18s ease;
  z-index: 17;
}
.emoji-panel[hidden] {
  display: none;
}
@keyframes panel-up {
  from {
    transform: translateY(12px);
    opacity: 0.4;
  }
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 4px;
}
.emoji-grid button {
  font-size: 24px;
  padding: 7px 0;
  border-radius: var(--radius-sm);
  transition: background 0.14s ease;
}
.emoji-grid button:active {
  background: var(--brand-50);
}

/* ---------------------------------------------------- 录音浮层 */

.rec-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(80px + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  background: rgba(13, 27, 38, 0.94);
  color: #fff;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  z-index: 30;
  animation: panel-up 0.18s ease;
}
.rec-bar[hidden] {
  display: none;
}
.rec-bar.cancel-hint {
  background: rgba(244, 68, 46, 0.95);
}
.rec-cancel,
.rec-send {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.86);
  padding: 6px 4px;
  flex: none;
}
.rec-send {
  color: var(--brand-200);
}
.rec-mid {
  flex: 1 1 auto;
  min-width: 0;
}
.rec-wave {
  height: 22px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.rec-wave i {
  flex: 1 1 auto;
  max-width: 6px;
  min-height: 3px;
  border-radius: 3px;
  background: var(--brand-300);
  transition: height 0.06s linear;
}
.rec-time {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.rec-hint {
  font-size: 11.5px;
  opacity: 0.66;
}

/* ---------------------------------------------------- 弹窗 / 遮罩 */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 38, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.2s ease;
  backdrop-filter: blur(4px);
}
.sheet-mask[hidden] {
  display: none;
}
@keyframes fade-in {
  from { opacity: 0; }
}

.sheet {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 28px 24px 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: sheet-up 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes sheet-up {
  from {
    transform: translateY(20px) scale(0.97);
    opacity: 0;
  }
}
.sheet-avatar {
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}
.sheet-avatar .avatar {
  width: 58px;
  height: 58px;
  font-size: 23px;
  box-shadow: var(--shadow-brand);
}
.sheet-title {
  margin: 0 0 7px;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-900);
}
.sheet-desc {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--ink-400);
}
.sheet-main {
  width: 100%;
  margin-top: 16px;
}
.sheet-sub {
  width: 100%;
  margin-top: 9px;
}

/* ---------------------------------------------------- 通话界面 */

.call-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  padding: calc(56px + var(--safe-t)) 24px calc(48px + var(--safe-b));
  animation: fade-in 0.24s ease;
}
.call-screen[hidden] {
  display: none;
}
/* 深色主色渐变，比原先的青绿更贴合品牌蓝 */
.call-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 0%, #0a7fb8 0%, #064f75 45%, #052c42 100%);
  z-index: -1;
}
.call-body {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6vh;
}
.call-avatar {
  width: 100px;
  height: 100px;
  font-size: 38px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.26);
  margin-bottom: 12px;
  position: relative;
}
.call-screen.incoming .call-avatar::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(92, 195, 242, 0.5);
  animation: ripple 1.6s ease-out infinite;
}
@keyframes ripple {
  from {
    transform: scale(0.9);
    opacity: 0.9;
  }
  to {
    transform: scale(1.25);
    opacity: 0;
  }
}
.call-name {
  font-size: 22px;
  font-weight: 700;
}
.call-status {
  font-size: 14.5px;
  opacity: 0.78;
}
.call-timer {
  font-size: 30px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  margin-top: 6px;
}
.call-timer[hidden] {
  display: none;
}
.call-note {
  font-size: 12.5px;
  opacity: 0.6;
  margin-top: 15vh;
  text-align: center;
  line-height: 1.7;
  max-width: 300px;
}

.call-actions {
  display: flex;
  gap: 26px;
  align-items: center;
  justify-content: center;
}
.call-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  transition: transform 0.14s ease, filter 0.16s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.call-btn:active {
  transform: scale(0.92);
}
.call-btn.accept {
  background: linear-gradient(135deg, #33dd94, var(--ok));
}
.call-btn.reject {
  background: linear-gradient(135deg, #ff6b52, #d93a22);
}
.call-btn.mute {
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(6px);
  width: 56px;
  height: 56px;
}
.call-btn.mute.on {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink-800);
}
.call-btn-label {
  font-size: 11.5px;
  opacity: 0.7;
  margin-top: 8px;
  display: block;
  text-align: center;
}
.call-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------------------------------------------------- 图片预览 */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(6, 14, 20, 0.94);
  display: grid;
  place-items: center;
  animation: fade-in 0.18s ease;
}
.lightbox[hidden] {
  display: none;
}
.lightbox img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: var(--radius);
  object-fit: contain;
}
.lb-close {
  position: absolute;
  top: calc(14px + var(--safe-t));
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

/* 极窄屏 */
@media (max-width: 340px) {
  .bubble-col { max-width: 84%; }
  .toolbar .icon-btn { width: 31px; height: 31px; }
}
