: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%;
  max-width: 860px;
  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: 900px) {
  body {
    padding: 16px;
  }
  .chat-shell {
    height: calc(100vh - 32px);
    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: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #1e40af;
}

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

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

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

.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: column;
  max-width: 82%;
}

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

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

.msg-sender {
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 4px;
  padding: 0 4px;
}

.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: 12px 14px;
  }
  .msg-row {
    max-width: 88%;
  }
  .chat-img, .chat-video {
    max-width: 220px;
  }
}

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

.composer textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.45;
  max-height: 120px;
  min-height: 42px;
  resize: none;
  outline: none;
  font-family: inherit;
  background: #f8fafc;
}

.composer textarea:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn-send {
  flex-shrink: 0;
  height: 42px;
  padding: 0 20px;
  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;
}

.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);
}
