/* ========================================
   访客端聊天界面样式
   主色调: #0067ed
   字体: 微软雅黑
   ======================================== */

/* CSS 变量 */
:root {
  --primary: #0067ed;
  --primary-light: #3385f0;
  --primary-dark: #0052c9;
  --primary-bg: #e8f2ff;
  --bg-main: #f5f5f5;
  --bg-white: #ffffff;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border-color: #e8e8e8;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 18px;
  --font-family: "Microsoft YaHei", "微软雅黑", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

/* 去掉所有按钮的触控反馈 */
button,
.btn-close,
.btn-send,
.tool-btn,
.btn-switch-shortcut,
.btn-load-history,
.btn-scroll-bottom,
.emoji-item,
.btn-rating-submit,
.btn-remove-preview,
.btn-phone-submit,
.modal-close,
.shortcut-tip {
  -webkit-tap-highlight-color: transparent;
  -moz-tap-highlight-color: transparent;
  -ms-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Reset */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   整体容器
   ======================================== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-white);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
}

/* ========================================
   顶部导航栏
   ======================================== */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
}

.btn-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

/* ========================================
   中间聊天区域
   ======================================== */
.chat-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: #f5f6f8;
  position: relative;
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar {
  width: 5px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

/* 加载历史 */
.load-history {
  text-align: center;
  padding: 12px 0;
}

.btn-load-history {
  display: inline-block;
  padding: 6px 20px;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-family);
}

/* 消息列表 */
.message-list {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
}

/* 系统通知 */
.system-notice {
  text-align: center;
  padding: 8px 0;
}

.system-notice span {
  display: inline-block;
  padding: 4px 14px;
  font-size: 12px;
  color: var(--text-muted);
  background: #eee;
  border-radius: 20px;
}

/* ========================================
   消息气泡
   ======================================== */
.message-item {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeInUp 0.3s ease;
}

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

/* 客服消息 - 左侧 */
.message-item.agent {
  align-self: flex-start;
  flex-direction: row;
}

.message-item.agent .message-avatar {
  order: 0;
}

.message-item.agent .message-content-wrapper {
  order: 1;
}

/* 访客消息 - 右侧 */
.message-item.visitor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* 头像 */
.message-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-avatar .avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

/* 消息内容包装 */
.message-content-wrapper {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.message-item.agent .message-meta {
  flex-direction: row;
}

.message-item.visitor .message-meta {
  flex-direction: row-reverse;
}

.message-sender {
  font-weight: 500;
  color: var(--text-secondary);
}

.message-time {
  color: var(--text-muted);
  font-size: 11px;
}

/* 气泡 */
.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  max-width: 100%;
}

/* 客服气泡 */
.message-item.agent .message-bubble {
  background: var(--bg-white);
  color: var(--text-primary);
  border-top-left-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* 访客气泡 */
.message-item.visitor .message-bubble {
  background: var(--primary);
  color: #ffffff;
  border-top-right-radius: var(--radius-sm);
}

/* 图片消息 */
.message-image {
  max-width: 220px;
  border-radius: var(--radius-md);
  cursor: pointer;
  overflow: hidden;
}

.message-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
}

/* 文件消息 */
.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
}

.message-item.visitor .message-file {
  color: #fff;
}

.message-item.agent .message-file {
  background: #f5f5f5;
  color: var(--text-primary);
}

.message-file-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.message-file-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-file-size {
  font-size: 11px;
  opacity: 0.7;
}

/* 语音消息 */
.message-voice {
  min-width: 120px;
}

.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  min-width: 100px;
}

.voice-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary, #0067ed);
  color: #fff;
  font-size: 12px;
  flex-shrink: 0;
}

.voice-duration {
  font-size: 13px;
  color: var(--text-secondary, #666);
}

.voice-player.playing .voice-icon {
  background: var(--danger, #e74c3c);
  animation: voice-pulse 1s infinite;
}

@keyframes voice-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* 录音状态 */
.tool-btn.recording,
.btn-voice.recording {
  background: #ffe0e0 !important;
  animation: recording-blink 1s infinite;
}

@keyframes recording-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 滚动到底部按钮 */
.btn-scroll-bottom {
  position: absolute;
  bottom: 8px;
  right: 20px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  z-index: 5;
  display: none;
}

.btn-scroll-bottom.visible {
  display: flex;
}

/* ========================================
   底部输入区域
   ======================================== */
.chat-footer {
  flex-shrink: 0;
  background: var(--bg-white);
  border-top: 1px solid var(--border-color);
  z-index: 10;
}

/* 工具栏 */
.input-toolbar {
  display: flex;
  align-items: center;
  padding: 6px 12px 0;
  gap: 2px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
}

.tool-btn.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.tool-btn.active svg circle,
.tool-btn.active svg path,
.tool-btn.active svg rect {
  stroke: var(--primary);
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

.shortcut-tip {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px;
  background: #f5f5f5;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}

.btn-switch-shortcut {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

/* 表情面板 */
.emoji-panel {
  display: none;
  border-top: 1px solid var(--border-color);
  padding: 8px;
  background: #fafafa;
  max-height: 220px;
  overflow-y: auto;
}

.emoji-panel.open {
  display: block;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  padding: 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  user-select: none;
}

/* 图片预览 */
.image-preview {
  padding: 8px 12px 0;
  border-top: 1px solid var(--border-color);
}

.preview-container {
  position: relative;
  display: inline-block;
}

.preview-container img {
  max-width: 100px;
  max-height: 80px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  object-fit: cover;
}

.btn-remove-preview {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #666;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 输入区域 */
.input-area {
  padding: 8px 12px 6px;
}

/* 电话输入 */
.phone-input-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  padding: 6px 10px;
  background: #f8f9fa;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  align-items: center;
}

.phone-input-wrapper .phone-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.phone-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  font-family: var(--font-family);
  color: var(--text-primary);
  padding: 4px 0;
}

.phone-input::placeholder {
  color: #bbb;
}

.btn-phone-submit {
  flex-shrink: 0;
  padding: 4px 14px;
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-family);
  white-space: nowrap;
}

/* 消息输入 */
.msg-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 12px;
}

.msg-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 103, 237, 0.1);
}

.msg-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: var(--font-family);
  color: var(--text-primary);
  line-height: 1.5;
  padding: 6px 0;
  max-height: 100px;
  min-height: 22px;
}

.msg-input::placeholder {
  color: #bbb;
}

.btn-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* 底部版权 */
.footer-copyright {
  text-align: center;
  padding: 4px 0 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.footer-copyright strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ========================================
   弹窗 / 模态框
   ======================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.modal-dialog {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.25s ease;
  overflow: hidden;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
}

.modal-body {
  padding: 20px;
}

/* 评价 */
.rating-prompt {
  text-align: center;
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.star-rating {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.star {
  font-size: 36px;
  color: #ddd;
  cursor: pointer;
  user-select: none;
}

.star.active {
  color: #ffb800;
}

.rating-comment {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: var(--font-family);
  resize: none;
  outline: none;
  margin-bottom: 16px;
}

.rating-comment:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 103, 237, 0.1);
}

.btn-rating-submit {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 15px;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-family);
  font-weight: 500;
}

/* 图片查看器 */
.image-viewer {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.image-viewer img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.img-viewer-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: #fff;
  font-size: 30px;
}

/* ========================================
   响应式设计
   ======================================== */
@media (min-width: 768px) {
  .chat-container {
    max-width: 420px;
    height: 100vh;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
  }

  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8eaed;
  }
}

@media (max-width: 480px) {
  .chat-header {
    height: 50px;
    padding: 0 12px;
  }

  .header-logo {
    width: 30px;
    height: 30px;
  }

  .header-title {
    font-size: 15px;
  }

  .message-item {
    max-width: 90%;
  }

  .message-bubble {
    font-size: 13px;
    padding: 8px 12px;
  }

  .emoji-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .emoji-item {
    font-size: 20px;
  }

  .input-toolbar {
    padding: 4px 8px 0;
  }

  .tool-btn {
    width: 32px;
    height: 32px;
  }

  .msg-input-wrapper {
    padding: 3px 3px 3px 10px;
  }
}

@media (max-width: 360px) {
  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }

  .message-item {
    max-width: 92%;
  }
}
