/* 聊天组件样式 */
#chat-widget {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 聊天按钮 */
.chat-button {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(26, 26, 26, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.chat-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(26, 26, 26, 0.4);
}

.chat-button.active {
  background: linear-gradient(135deg, #333 0%, #555 100%);
}

.chat-icon {
  font-size: 24px;
  color: #ffffff;
}

.chat-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ff4757;
  color: white;
  border-radius: 50%;
  min-width: 20px;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 4px;
  box-sizing: border-box;
  animation: pulse 2s infinite;
  text-align: center;
  white-space: nowrap;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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

/* 聊天按钮提示框 */
.chat-tooltip {
  position: absolute;
  right: 75px;
  top: 50%;
  transform: translateY(-50%);
  background: #1a1a1a;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 1;
  visibility: visible;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
}

.chat-tooltip::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #1a1a1a;
}

.chat-button:hover .chat-tooltip {
  transform: translateY(-50%) translateX(-4px);
}

/* 聊天窗口 */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  height: 500px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window:not(.hidden) {
  transform: translateY(0);
  opacity: 1;
}

/* 聊天头部 */
.chat-header {
  background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
  color: #ffffff;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title {
  display: flex;
  flex-direction: column;
}

.chat-status {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.chat-status.online {
  color: #2ed573;
}

.chat-status.connecting {
  color: #ffa502;
}

.chat-subtitle {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 300;
}

.close-btn {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.close-btn:hover {
  background: rgba(255, 71, 87, 0.9);
  color: #fff;
  transform: rotate(90deg) scale(1.1);
}

.close-btn:active {
  transform: rotate(90deg) scale(1.05);
}

.close-btn i {
  font-size: 16px;
}

/* 聊天头部操作按钮 */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 消息区域 */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* 日期分隔线 */
.date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 16px;
}

.date-divider span {
  background: #e9ecef;
  color: #555;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid #dde2e6;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}

/* 欢迎消息 */
.welcome-message {
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  color: #ffffff;
  margin-bottom: 20px;
}

.welcome-text p {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.5;
}

.welcome-text p:first-child {
  font-size: 16px;
  font-weight: 600;
}

/* 消息样式 - 确保消息对齐正确 */
.message {
  display: flex;
  margin-bottom: 16px;
  animation: messageSlideIn 0.3s ease-out;
  width: 100%;
  box-sizing: border-box;
}

.message.grouped {
  margin-top: 4px;
}

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

.user-message {
  justify-content: flex-end;
  flex-direction: row;
}

.admin-message {
  justify-content: flex-start;
  flex-direction: row;
}

.message-content {
  max-width: 80%;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
}

.user-message .message-content {
  background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.user-message.grouped .message-content {
  border-top-right-radius: 6px;
}

.admin-message .message-content {
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #e0e0e0;
  border-bottom-left-radius: 6px;
}

.admin-message.grouped .message-content {
  border-top-left-radius: 6px;
}

.error-message .message-content {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ffcdd2;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
}

.admin-message .message-time {
  text-align: left;
}

/* 文件消息样式 */
.file-message {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.file-icon {
  font-size: 24px;
}

.file-info {
  flex: 1;
}

.file-name {
  font-weight: 500;
  margin-bottom: 4px;
}

.file-size {
  font-size: 12px;
  color: #666;
}

.file-download {
  background: #1a1a1a;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
}

.image-message {
  max-width: 200px;
  border-radius: 8px;
  overflow: hidden;
}

.image-message img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.image-message img:hover {
  transform: scale(1.02);
}

/* 图片灯箱 */
.image-lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.image-lightbox-overlay.active {
  display: flex;
}

.image-lightbox-content {
  max-width: 90vw;
  max-height: 90vh;
}

.image-lightbox-content img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

/* 输入区域 */
.chat-input {
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  padding: 20px;
}

.input-container {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.file-upload-btn {
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  min-width: 44px;
  height: 44px;
}

.file-upload-btn:hover {
  background: #e0e0e0;
}

.file-input {
  display: none;
}

.upload-progress {
  background: #e3f2fd;
  border-radius: 4px;
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
}

.upload-progress-bar {
  background: #2196f3;
  height: 100%;
  transition: width 0.3s ease;
}

#message-input {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
  resize: none;
  min-height: 20px;
  max-height: 100px;
}

#message-input:focus {
  border-color: #1a1a1a;
}

#message-input::placeholder {
  color: #999;
}

.send-btn {
  background: #f0f0f0;
  border: none;
  border-radius: 20px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #666;
  min-width: 60px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  white-space: nowrap;
  box-sizing: border-box;
}

.send-btn.active {
  background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
  color: #ffffff;
  transform: translateY(-1px);
}

.send-btn:hover {
  transform: translateY(-1px);
}

.send-btn.active:hover {
  box-shadow: 0 4px 12px rgba(26, 26, 26, 0.3);
}

.input-tips {
  margin-top: 8px;
  text-align: center;
}

.input-tips span {
  font-size: 11px;
  color: #999;
}

/* 响应式设计 */
@media (max-width: 768px) {
  #chat-widget {
    bottom: 20px;
    right: 20px;
  }
  
  .chat-window {
    width: calc(100vw - 40px);
    height: calc(100vh - 40px);
    bottom: 20px;
    right: 20px;
    border-radius: 12px;
  }
  
  .chat-button {
    width: 50px;
    height: 50px;
  }
  
  .chat-icon {
    font-size: 20px;
  }
  
  .chat-tooltip {
    right: 65px;
    font-size: 12px;
    padding: 6px 10px;
  }
  
  .send-btn {
    padding: 10px 16px;
    font-size: 13px;
    min-width: 56px;
    height: 44px;
  }
  
  .input-container {
    gap: 8px;
  }
  
  .file-upload-btn {
    min-width: 40px;
    height: 44px;
    padding: 10px;
  }
}

@media (max-width: 480px) {
  #chat-widget {
    bottom: 15px;
    right: 15px;
  }
  
  .chat-window {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    bottom: 15px;
    right: 15px;
  }
  
  .chat-header {
    padding: 15px;
  }
  
  .chat-messages {
    padding: 15px;
  }
  
  .chat-input {
    padding: 15px;
  }
  
  .chat-tooltip {
    right: 60px;
    font-size: 11px;
    padding: 5px 8px;
  }
  
  .send-btn {
    padding: 10px 14px;
    font-size: 12px;
    min-width: 52px;
    height: 44px;
    border-radius: 22px;
  }
  
  .input-container {
    gap: 8px;
  }
  
  .file-upload-btn {
    min-width: 40px;
    height: 44px;
    padding: 8px;
    font-size: 14px;
  }
  
  #message-input {
    padding: 10px 14px;
    font-size: 14px;
    height: 44px;
    min-height: 44px;
  }
}

/* 隐藏状态 */
.hidden {
  display: none !important;
}

/* 加载动画 */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #1a1a1a;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 打字指示器 */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  max-width: 80px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingDot {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}
