:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg-page: #eef2f7;
  --bg-card: #ffffff;
  --bg-chat: #f5f7fb;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
  --visitor-bubble: #2563eb;
  --agent-bubble: #ffffff;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  overflow: hidden;
}

.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg-card);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

@media (min-width: 960px) {
  body {
    padding: 14px;
  }
  .chat-shell {
    max-width: 1080px;
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid rgba(226, 232, 240, 0.9);
  }
}

/* 顶部栏 */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  color: #fff;
}

.agent-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.agent-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid rgba(255, 255, 255, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.agent-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.status-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #1e40af;
  transition: background-color 0.2s ease;
}
.status-dot.is-amber { background: #f59e0b; }
.status-dot.is-red   { background: #ef4444; }
.status-dot.is-gray  { background: #94a3b8; }

.agent-text {
  min-width: 0;
}

.agent-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex-wrap: nowrap;
}

.agent-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(4px);
}

.agent-status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.agent-status-pill.is-green {
  background: rgba(34, 197, 94, 0.24);
  color: #ecfdf5;
  border-color: rgba(134, 239, 172, 0.55);
}
.agent-status-pill.is-green::before { background: #4ade80; box-shadow: 0 0 6px #4ade80; }

.agent-status-pill.is-amber {
  background: rgba(245, 158, 11, 0.28);
  color: #fef3c7;
  border-color: rgba(253, 224, 71, 0.55);
}
.agent-status-pill.is-amber::before { background: #fbbf24; }

.agent-status-pill.is-red {
  background: rgba(239, 68, 68, 0.28);
  color: #fee2e2;
  border-color: rgba(252, 165, 165, 0.55);
}
.agent-status-pill.is-red::before { background: #f87171; }

.agent-status-pill.is-gray {
  background: rgba(148, 163, 184, 0.28);
  color: #e2e8f0;
  border-color: rgba(203, 213, 225, 0.5);
}
.agent-status-pill.is-gray::before { background: #cbd5e1; }

.agent-sub {
  font-size: 12px;
  opacity: 0.88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.notice-btn {
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.notice-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.visitor-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #93c5fd;
}

/* 消息滚动区 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 20px;
  background: var(--bg-chat);
  -webkit-overflow-scrolling: touch;
}

.load-more-wrap {
  text-align: center;
  margin: 6px 0 14px;
}

.btn-load-more {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-sub);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-load-more:hover {
  color: var(--primary);
  border-color: #bfdbfe;
}

/* 预留欢迎信息区 */
.preset-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.preset-divider {
  text-align: center;
  font-size: 11px;
  color: #94a3b8;
  margin: 4px 0 2px;
}

/* 单条消息布局 */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.time-sep {
  text-align: center;
  font-size: 11px;
  color: #94a3b8;
  margin: 4px 0;
}

.msg-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  max-width: 86%;
}

.msg-row.visitor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.agent {
  align-self: flex-start;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg-row.visitor .msg-main {
  align-items: flex-end;
}

.msg-row.agent .msg-main {
  align-items: flex-start;
}

.msg-sender {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 4px;
  padding: 0 4px;
}

.auto-reply-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.4;
}

.msg-receipt {
  margin-top: 3px;
  padding: 0 4px;
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.3;
}

.msg-receipt.is-read {
  color: #2563eb;
  font-weight: 500;
}

.msg-bubble {
  position: relative;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.msg-row.visitor .msg-bubble {
  background: var(--visitor-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.agent .msg-bubble {
  background: var(--agent-bubble);
  color: var(--text-main);
  border: 1px solid #e9eef5;
  border-bottom-left-radius: 4px;
}

.msg-row.visitor .msg-bubble a {
  color: #dbeafe;
  text-decoration: underline;
}

.msg-row.agent .msg-bubble a {
  color: var(--primary);
  text-decoration: underline;
}

/* 图片与视频消息 */
.msg-bubble.media-bubble {
  padding: 6px;
  background: #fff !important;
  border: 1px solid #e2e8f0;
  color: var(--text-main) !important;
}

.chat-img {
  display: block;
  max-width: 240px;
  max-height: 300px;
  border-radius: 10px;
  cursor: zoom-in;
  object-fit: cover;
  background: #f1f5f9;
}

.chat-video {
  display: block;
  width: 260px;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  background: #000;
}

.media-caption {
  margin-top: 6px;
  padding: 0 4px 2px;
  font-size: 13px;
  color: var(--text-main);
}

/* 链接卡片消息 */
.link-card {
  display: block;
  text-decoration: none !important;
  color: inherit !important;
  min-width: 210px;
  max-width: 300px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid #dbeafe;
  transition: border-color 0.15s, background 0.15s;
}

.link-card:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}

.link-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #1d4ed8;
  margin-bottom: 4px;
}

.link-card-desc {
  font-size: 12.5px;
  color: #475569;
  margin-bottom: 6px;
  line-height: 1.45;
}

.link-card-url {
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 上传进度条 */
.upload-bar {
  flex-shrink: 0;
  padding: 8px 16px;
  background: #eff6ff;
  border-top: 1px solid #dbeafe;
}

.upload-bar-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #1d4ed8;
  margin-bottom: 5px;
}

.upload-track {
  height: 5px;
  background: #dbeafe;
  border-radius: 999px;
  overflow: hidden;
}

.upload-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.15s linear;
}

/* 底部输入区 */
.chat-footer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #334155;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: var(--primary);
}

.paste-tip {
  margin-left: auto;
  font-size: 11.5px;
  color: #94a3b8;
}

@media (max-width: 640px) {
  .paste-tip {
    display: none;
  }
  .chat-header {
    padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
    gap: 8px;
  }
  .agent-avatar {
    width: 36px;
    height: 36px;
  }
  .agent-name {
    font-size: 14.5px;
  }
  .agent-status-pill {
    padding: 1px 7px;
    font-size: 10.5px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .agent-sub {
    font-size: 11px;
  }
  .visitor-badge {
    padding: 4px 8px;
    font-size: 11px;
    max-width: 115px;
    overflow: hidden;
  }
  .visitor-badge span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .notice-btn {
    padding: 4px 8px;
    font-size: 11.5px;
  }
  .msg-row {
    max-width: 92%;
    gap: 8px;
  }
  .msg-avatar {
    width: 32px;
    height: 32px;
  }
  .chat-img, .chat-video {
    max-width: min(230px, 64vw);
  }
  .composer textarea {
    font-size: 16px; /* 防止 iOS Safari 聚焦自动放大页面 */
    min-height: 78px;
  }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  overflow: hidden;
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.composer-box:focus-within {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.pending-media-tray {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 4px;
  overflow-x: auto;
  flex-wrap: nowrap;
  border-bottom: 1px dashed #e2e8f0;
  background: rgba(239, 246, 255, 0.45);
}

.pending-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
  max-width: 180px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.pending-chip img {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.pending-chip .pending-vid-thumb {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: #0f172a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.pending-chip-info {
  min-width: 0;
  padding-right: 14px;
}

.pending-chip-name {
  font-size: 11.5px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
}

.pending-chip-size {
  font-size: 10.5px;
  color: var(--text-sub);
}

.pending-chip-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(239, 68, 68, 0.35);
}

.composer textarea {
  width: 100%;
  border: none;
  border-radius: 0;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.5;
  min-height: 92px;
  max-height: 220px;
  resize: none;
  outline: none;
  font-family: inherit;
  background: transparent;
}

.composer textarea:focus {
  border-color: transparent;
  background: transparent;
  box-shadow: none !important;
}

.btn-send {
  flex-shrink: 0;
  height: 44px;
  padding: 0 22px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-send:hover {
  background: var(--primary-dark);
}

.btn-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 拖拽遮罩 */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.12);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.drop-overlay.show {
  display: flex;
}

.drop-box {
  padding: 24px 32px;
  border-radius: 16px;
  background: #fff;
  border: 2px dashed var(--primary);
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.16);
}

/* 弹窗与灯箱 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.modal-close {
  border: none;
  background: none;
  font-size: 22px;
  color: #64748b;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  max-height: 55vh;
  overflow: auto;
}

.modal-body img, .modal-body video {
  max-width: 100%;
  max-height: 46vh;
  border-radius: 10px;
}

.modal-meta {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn-cancel {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
}

.btn-primary {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 8px 18px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
}

.preset-notice-card {
  max-width: 480px;
}

.preset-notice-head {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border-bottom: none;
}

.preset-notice-head .modal-close {
  color: rgba(255, 255, 255, 0.85);
}

.preset-notice-body {
  padding: 16px;
  background: #f5f7fb;
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preset-notice-body .msg-row {
  max-width: 100%;
  width: 100%;
}

.preset-notice-body .chat-img {
  max-width: 100%;
  max-height: 320px;
}

.preset-notice-body .chat-video {
  width: 100%;
  max-width: 100%;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.lightbox img {
  max-width: 94vw;
  max-height: 90vh;
  border-radius: 8px;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  top: 22px;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ======================== 丝滑交互与微动效优化 (v1.0.4) ======================== */
button, .tool-btn, .btn-send, .notice-btn, .btn-load-more, .btn-primary, .btn-cancel, .modal-close, .lightbox-close {
  transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1),
              background-color 0.18s ease,
              border-color 0.18s ease,
              box-shadow 0.18s ease,
              opacity 0.18s ease;
  user-select: none;
  touch-action: manipulation;
}

button:active:not(:disabled),
.tool-btn:active,
.btn-send:active:not(:disabled),
.notice-btn:active,
.btn-load-more:active,
.btn-primary:active,
.btn-cancel:active {
  transform: scale(0.95);
}

.btn-send:hover:not(:disabled),
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.composer textarea {
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.composer textarea:focus {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.chat-img {
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s ease;
}

.chat-img:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
}

.msg-row.is-new {
  animation: vMsgIn 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes vMsgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-mask, .lightbox {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: vMaskIn 0.18s ease-out both;
}

.modal-card, .lightbox img {
  animation: vCardPop 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes vMaskIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes vCardPop {
  from { opacity: 0; transform: translateY(12px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 细滑滚动条 */
.chat-body::-webkit-scrollbar,
.preset-notice-body::-webkit-scrollbar {
  width: 6px;
}
.chat-body::-webkit-scrollbar-thumb,
.preset-notice-body::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
}
.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.65);
}
