* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
  height: 100vh;
  overflow: hidden;
}

.page {
  height: 100vh;
  width: 100vw;
}

.hidden {
  display: none !important;
}

/* 登录页面 */
.login-container {
  max-width: 400px;
  margin: 100px auto;
  background: white;
  padding: 40px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.login-container h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  color: #666;
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: #3cc51f;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background-color: #3cc51f;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-primary:hover {
  background-color: #35b018;
}

.btn-secondary {
  padding: 8px 16px;
  background-color: #999;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}

.btn-secondary:hover {
  background-color: #888;
}

.btn-danger {
  background-color: #ff4444 !important;
  color: white !important;
}

.btn-danger:hover {
  background-color: #cc0000 !important;
}

.status-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-label {
  font-size: 14px;
  color: #666;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch.large {
  width: 54px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: '';
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.switch.large .slider:before {
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
}

.switch input:checked + .slider {
  background-color: #3cc51f;
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

.switch.large input:checked + .slider:before {
  transform: translateX(26px);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #666;
  padding: 5px 10px;
}

.btn-icon:hover {
  color: #333;
}

/* 主页面 */
.header {
  background: white;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.header-left h2 {
  font-size: 20px;
  color: #333;
  margin-bottom: 5px;
}

.header-left span {
  font-size: 14px;
  color: #666;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stats-info {
  display: flex;
  gap: 20px;
  font-size: 14px;
  color: #666;
}

.stats-info strong {
  color: #3cc51f;
  font-weight: bold;
}

.tab-bar {
  display: flex;
  background: white;
  padding: 0 20px;
  border-bottom: 1px solid #eee;
}

.tab-button {
  padding: 12px 18px;
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: #666;
  transition: color 0.2s, border-bottom 0.2s;
  border-bottom: 3px solid transparent;
}

.tab-button.active {
  color: #3cc51f;
  border-bottom-color: #3cc51f;
  font-weight: 600;
}

.overview-page {
  padding: 20px;
  overflow-y: auto;
  height: calc(100vh - 70px - 54px);
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card h3 {
  font-size: 16px;
  color: #333;
  margin-bottom: 16px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 14px;
  color: #666;
}

.info-row strong {
  color: #3cc51f;
  font-size: 18px;
}

.status-card p {
  font-size: 13px;
  color: #888;
  margin-bottom: 16px;
}

.status-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.status-text {
  font-size: 14px;
  color: #333;
}

.form-label {
  font-size: 13px;
  color: #666;
  margin-bottom: 6px;
  display: block;
}

.status-card textarea,
.welcome-card textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  resize: vertical;
  margin-bottom: 12px;
  font-family: inherit;
}

.welcome-media,
.banner-media {
  background: #fafafa;
  border: 1px dashed #ddd;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.banner-card {
  margin-top: 20px;
  display: block !important;
  visibility: visible !important;
}

.media-preview {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 14px;
  text-align: center;
}

.media-preview img {
  max-width: 100%;
  border-radius: 6px;
}

.media-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.main-content {
  display: flex;
  height: calc(100vh - 70px);
  overflow: hidden; /* 防止内容溢出 */
}

.main-content.hidden,
.overview-page.hidden {
  display: none;
}

/* 会话列表 */
.conversation-list {
  width: 320px;
  background: white;
  border-right: 1px solid #eee;
  display: flex;
  flex-direction: column;
}

.list-header {
  padding: 15px;
  border-bottom: 1px solid #eee;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-header h3 {
  font-size: 16px;
  color: #333;
}

.list-actions {
  display: flex;
  gap: 10px;
}

.list-actions input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
}

.list-actions button {
  border-radius: 6px;
  background: #f3f3f3;
}

.list-content {
  flex: 1;
  overflow-y: auto;
}

.conversation-group-title {
  padding: 10px 15px 5px;
  font-size: 12px;
  color: #999;
}

.conversation-item {
  padding: 15px;
  border-bottom: 1px solid #f3f3f3;
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  position: relative;
}

.conversation-item:hover {
  background-color: #f5f5f5;
}

.conversation-item.active {
  background-color: #e8f5e9;
}

.conversation-item .avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  flex-shrink: 0;
}


.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.conversation-name {
  font-size: 14px;
  font-weight: bold;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  font-size: 12px;
  color: #999;
}

.conversation-preview {
  font-size: 12px;
  color: #999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-badge {
  background-color: #ff4444;
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 12px;
  min-width: 20px;
  text-align: center;
}

.pin-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: #bbb;
  font-size: 16px;
  padding: 2px;
  transition: color 0.2s;
}

.pin-icon.pinned {
  color: #f5a623;
}

/* 聊天区域 */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
  overflow: hidden; /* 防止内容溢出 */
  overflow-x: visible !important; /* 允许头像超出，不被裁剪 */
  min-height: 0; /* 允许flex子元素缩小 */
}

.empty-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 16px;
}

.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  overflow-x: visible !important; /* 允许头像超出，不被裁剪 */
  min-height: 0; /* 允许flex子元素缩小 */
  padding-bottom: 0; /* 确保没有底部padding */
  margin-bottom: 0; /* 确保没有底部margin */
  position: relative; /* 确保定位上下文 */
}

/* 确保没有hidden类时显示 */
.chat-window:not(.hidden) {
  display: flex !important;
}


.chat-header {
  background: white;
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info .avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.user-name {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}

.user-status {
  font-size: 12px;
  color: #999;
}

.chat-actions {
  display: flex;
  gap: 10px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: visible !important; /* 允许头像超出，不被裁剪 */
  padding: 20px;
  padding-right: 70px; /* 右边留出空间给头像(50px)和间距(20px) */
  display: flex;
  flex-direction: column;
  gap: 15px;
  background-color: #ededed;
  min-height: 0; /* 允许flex子元素缩小 */
  max-height: calc(100% - 200px); /* 确保为输入区域留出空间 */
  position: relative; /* 确保定位正确 */
  flex-shrink: 1; /* 允许被压缩 */
}

.message-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
}

.message-item.user {
  flex-direction: row;
  justify-content: flex-start;
}

.message-item.service {
  position: relative; /* 为绝对定位的头像提供定位上下文 */
  width: 100%; /* 确保占满宽度 */
  display: flex;
  flex-direction: row; /* 改为正常方向：消息在左，头像在右 */
  justify-content: flex-end; /* 整体靠右 */
  align-items: flex-end; /* 底部对齐 */
  padding-right: 0; /* 右边没有padding，让头像紧贴边缘 */
  margin-right: -50px; /* 负边距，让头像可以超出到消息列表的padding区域外 */
}

/* 确保客服消息的头像始终固定在最右边 */
.message-item.service .avatar {
  position: absolute !important; /* 绝对定位 */
  right: -50px !important; /* 固定在最右边，超出消息项容器，紧贴消息列表的右边缘 */
  top: 0 !important; /* 顶部对齐 */
  flex-shrink: 0 !important; /* 不压缩 */
  margin-left: 0 !important;
  margin-right: 0 !important; /* 右边没有边距，紧贴边缘 */
  z-index: 1; /* 确保头像在消息内容之上 */
}

.message-item .avatar {
  width: 50px; /* 增大头像 */
  height: 50px; /* 增大头像 */
  border-radius: 50%;
  flex-shrink: 0;
}

/* 用户消息的头像在左边 */
.message-item.user .avatar {
  order: 0;
  margin-right: 10px;
  margin-left: 0;
}

.message-content {
  max-width: 75%; /* 稍微减小最大宽度，让消息更紧凑 */
  min-width: 200px; /* 设置最小宽度，避免过窄 */
  background: white;
  padding: 8px 12px; /* 统一的上下padding */
  border-radius: 10px;
  position: relative;
  word-break: break-word;
  white-space: normal; /* 正常换行，不保留多余空格和换行 */
}

.message-item.user .message-content {
  background-color: #e5e5e5;
  margin-right: auto; /* 用户消息靠左 */
  margin-left: 0;
  max-width: 50% !important; /* 用户消息最大宽度为聊天框总宽度的一半 */
  min-width: 200px; /* 设置最小宽度，避免过窄 */
}

.message-item.service .message-content {
  background-color: #d4edda;
  margin-left: 0; /* 左边没有边距 */
  margin-right: 60px !important; /* 右边留出空间给头像(50px)和间距(10px)，确保不会与头像重叠 */
  max-width: 50% !important; /* 最大宽度为聊天框总宽度的一半 */
  min-width: 200px; /* 设置最小宽度，避免过窄 */
  position: relative; /* 确保定位 */
  z-index: 0; /* 确保在头像下方 */
  word-break: break-word !important; /* 自动换行 */
  overflow-wrap: break-word !important; /* 长单词自动换行 */
  /* 移除 white-space: pre-wrap，和用户消息保持一致，不保留多余空格和换行 */
  padding: 8px 12px !important; /* 和用户消息保持一致 */
}

.message-text {
  font-size: 16px; /* 增大文字 */
  color: #333;
  line-height: 1.5; /* 稍微减小行高，从1.6改为1.5 */
  white-space: pre-wrap; /* 保留换行和空格，支持换行显示 */
  word-wrap: break-word; /* 长单词自动换行 */
  margin-bottom: 0 !important; /* 文字底部没有间距 */
  padding-bottom: 0 !important; /* 文字底部没有padding */
}

/* 时间戳样式 */
.timestamp-item {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
  width: 100%;
}

.timestamp-text {
  background-color: rgba(0, 0, 0, 0.1);
  color: #999;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 4px;
}

/* 气泡时间样式 */
.bubble-time {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.5);
  margin-bottom: 4px;
  text-align: left;
  line-height: 1.2;
}

.message-auto-tag {
  font-size: 11px;
  color: #2b5724;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: 5px;
  cursor: pointer;
}

.message-video {
  max-width: 300px;
  max-height: 300px;
  border-radius: 5px;
}

.message-item.auto-message .message-content {
  background-color: #d9f7be;
  color: #2b5724;
}

.message-time {
  font-size: 11px;
  color: #999;
  margin-top: 2px !important; /* 减少文字和时间之间的间距，从5px改为2px */
  margin-bottom: 0 !important; /* 底部没有间距 */
}

.message-status {
  font-size: 11px;
  color: #999;
  margin-top: 0 !important; /* 时间和状态之间没有间距 */
  margin-bottom: 0 !important; /* 底部没有间距 */
  display: flex;
  align-items: center;
  gap: 5px;
}

.message-actions {
  position: absolute;
  top: 5px;
  right: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message-item:hover .message-actions {
  opacity: 1;
}

.recall-btn {
  background: none;
  border: none;
  color: #999;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 5px;
}

.recall-btn:hover {
  color: #666;
}

.recalled-message {
  color: #999;
  font-style: italic;
}

.input-area {
  background: white !important;
  border-top: 1px solid #eee !important;
  padding: 12px 15px !important; /* 统一的上下padding */
  position: relative !important;
  z-index: 10 !important;
  flex-shrink: 0 !important; /* 防止被压缩 */
  flex-grow: 0 !important; /* 不允许扩展 */
  margin-bottom: 0 !important; /* 确保没有额外边距 */
  margin-top: auto !important; /* 推到底部 */
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 100% !important;
  box-sizing: border-box !important;
  min-height: 68px !important; /* 确保最小高度 */
  max-height: 200px !important; /* 限制最大高度 */
}

/* 确保即使父元素有hidden类，输入区域也能显示（如果父元素被显示） */
.chat-window:not(.hidden) .input-area,
.chat-window[style*="display: flex"] .input-area,
.chat-window[style*="display:flex"] .input-area {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* 单行布局：所有按钮和输入框在一行 */
.input-row,
.input-area .input-row,
.chat-window .input-row {
  display: flex !important;
  gap: 10px !important;
  align-items: flex-end !important; /* 底部对齐，允许输入框自动扩展 */
  width: 100% !important;
  flex-wrap: nowrap !important; /* 不换行 */
  visibility: visible !important;
  opacity: 1 !important;
  min-height: 44px !important;
}

.tool-btn,
#imageBtn,
#videoBtn {
  background: #f5f5f5 !important;
  border: 1px solid #ddd !important;
  border-radius: 5px !important;
  padding: 10px 12px !important;
  cursor: pointer !important;
  font-size: 18px !important;
  transition: background-color 0.2s !important;
  width: 44px !important; /* 固定宽度 */
  height: 44px !important; /* 固定高度 */
  min-width: 44px !important;
  min-height: 44px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important; /* 不压缩 */
  box-sizing: border-box !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.tool-btn:hover {
  background-color: #e8e8e8;
}

/* 输入框样式 */
.input-row textarea,
.input-row #messageInput,
.input-area textarea,
.input-area #messageInput {
  flex: 1 !important; /* 占据剩余空间 */
  padding: 10px 14px !important;
  border: 2px solid #ddd !important;
  border-radius: 8px !important;
  font-size: 15px !important;
  resize: none !important; /* 不允许手动调整大小 */
  font-family: inherit !important;
  height: 44px !important; /* 初始高度，与其他按钮对齐 */
  min-height: 44px !important; /* 最小高度 */
  max-height: 120px !important; /* 最大高度，防止过高 */
  line-height: 1.5 !important; /* 设置行高，支持多行显示 */
  white-space: pre-wrap !important; /* 保留换行和空格 */
  overflow-wrap: break-word !important; /* 长单词自动换行 */
  overflow-y: auto !important; /* 内容超出时显示滚动条 */
  box-sizing: border-box !important;
  background-color: #fff !important;
  align-self: flex-end !important; /* 底部对齐 */
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: auto !important;
}

.input-row textarea:focus {
  outline: none;
  border-color: #3cc51f;
}

/* 发送按钮样式 - 使用更高优先级的选择器 */
.input-row .send-btn,
.input-row #sendBtn,
.input-area .send-btn,
.input-area #sendBtn {
  padding: 10px 24px !important;
  font-size: 15px !important;
  height: 44px !important; /* 与其他按钮对齐 */
  min-height: 44px !important;
  max-height: 44px !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  background-color: #3cc51f !important;
  color: white !important;
  border: none !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  font-weight: 500 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: auto !important;
  min-width: 80px !important;
  max-width: none !important;
  box-sizing: border-box !important;
}

.input-row .send-btn:hover {
  background-color: #35b018 !important;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-dialog {
  position: relative;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  min-width: 320px;
  max-width: 90vw;
  z-index: 1;
}

.modal-dialog h3 {
  font-size: 16px;
  color: #333;
  margin-bottom: 15px;
}

#remarkInput {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #666;
}

.modal-dialog.image-preview {
  padding: 0;
  background: none;
  box-shadow: none;
}

.modal-dialog.image-preview img {
  max-width: 80vw;
  max-height: 80vh;
  border-radius: 10px;
  display: block;
}

#imagePreviewClose {
  top: -40px;
  right: -40px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

