/**
 * 智能客服组件样式 - 天鸿智算
 * 主题色：红色渐变
 */

/* ==========================================
   悬浮按钮样式
   ========================================== */
.float-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ff6b6b 0%, #dc2626 100%);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
  z-index: 998;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.float-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(220, 38, 38, 0.6);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .float-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
    bottom: 1.5rem;
    right: 1.5rem;
  }
}

/* ==========================================
   客服弹窗样式
   ========================================== */

/* iframe 容器 */
.cs-iframe-container {
  flex: 1;
  position: relative;
  background: #f8f9fa;
  overflow: hidden;
}

.cs-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* 加载状态 */
.cs-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
}

.cs-loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: #dc2626;
  border-radius: 50%;
  animation: cs-spin 1s linear infinite;
}

@keyframes cs-spin {
  to { transform: rotate(360deg); }
}

.cs-loading-text {
  color: #64748b;
  font-size: 14px;
}

/* 弹窗遮罩 */
.cs-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.cs-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* 弹窗容器 */
.cs-modal {
  width: 100%;
  max-width: 420px;
  height: 600px;
  max-height: 90vh;
  background: white;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cs-modal-overlay.active .cs-modal {
  transform: scale(1) translateY(0);
}

/* 弹窗头部 - 红色主题 */
.cs-modal-header {
  background: linear-gradient(135deg, #ff6b6b 0%, #dc2626 100%);
  padding: 16px 20px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cs-modal-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cs-modal-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.cs-modal-header-text h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.cs-modal-header-text p {
  font-size: 12px;
  opacity: 0.9;
  margin: 2px 0 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cs-status-dot {
  width: 8px;
  height: 8px;
  background: #2ecc71;
  border-radius: 50%;
  animation: cs-pulse 2s infinite;
}

@keyframes cs-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.cs-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.cs-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* 头部操作按钮组 */
.cs-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 清空对话按钮 */
.cs-clear-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 14px;
}

.cs-clear-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

/* 消息操作按钮 */
.cs-message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}

.cs-message:hover .cs-message-actions {
  opacity: 1;
}

.cs-message-action-btn {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cs-message-action-btn:hover {
  background: #f3f4f6;
  color: #6b7280;
}

.cs-message-action-btn.copied {
  color: #10b981;
}

/* 确认弹窗 */
.cs-confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  backdrop-filter: blur(4px);
}

.cs-confirm-modal {
  background: white;
  border-radius: 16px;
  padding: 24px 32px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  animation: cs-confirm-slide 0.3s ease;
}

@keyframes cs-confirm-slide {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.cs-confirm-icon {
  font-size: 48px;
  color: #f59e0b;
  margin-bottom: 16px;
}

.cs-confirm-modal h4 {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
}

.cs-confirm-modal p {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 24px;
}

.cs-confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.cs-confirm-cancel,
.cs-confirm-confirm {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.cs-confirm-cancel {
  background: #f3f4f6;
  color: #4b5563;
}

.cs-confirm-cancel:hover {
  background: #e5e7eb;
}

.cs-confirm-confirm {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
}

.cs-confirm-confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .cs-clear-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
}

/* 弹窗内容区 - 消息列表 */
.cs-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cs-modal-body::-webkit-scrollbar {
  width: 6px;
}

.cs-modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.cs-modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

/* 欢迎消息 */
.cs-welcome {
  text-align: center;
  padding: 20px 0;
}

.cs-welcome h4 {
  color: #2d3748;
  font-size: 18px;
  margin-bottom: 8px;
}

.cs-welcome p {
  color: #718096;
  font-size: 14px;
  line-height: 1.6;
}

/* 消息气泡 */
.cs-message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  width: auto;
  animation: cs-message-slide 0.3s ease;
  box-sizing: border-box;
}

.cs-message.user {
  margin-left: auto;
  align-self: flex-end;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

/* 消息内容包装器 */
.cs-message-content-wrapper {
  display: flex;
  flex-direction: column;
  max-width: calc(100% - 44px);
  min-width: 0;
}

@keyframes cs-message-slide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.cs-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* 用户头像 - 红色主题 */
.cs-message.user .cs-message-avatar {
  background: linear-gradient(135deg, #ff6b6b 0%, #dc2626 100%);
}

.cs-message.ai .cs-message-avatar {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cs-message-content {
  background: white;
  padding: 10px 14px;
  border-radius: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  font-size: 14px;
  line-height: 1.5;
  color: #2d3748;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  box-sizing: border-box;
}

/* 用户消息 - 红色主题 */
.cs-message.user .cs-message-content {
  background: linear-gradient(135deg, #ff6b6b 0%, #dc2626 100%);
  color: white;
  border-bottom-right-radius: 4px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  min-height: 44px;
  display: flex;
  align-items: center;
  max-width: min(400px, 70vw);
  box-sizing: border-box;
}

.cs-message.ai .cs-message-content {
  border-bottom-left-radius: 4px;
}

/* 正在思考消息的特殊样式 - 更紧凑 */
#csThinkingIndicator .cs-message-content {
  padding: 8px 12px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border: 1px solid #e9ecef;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  white-space: nowrap;
}

#csThinkingIndicator {
  max-width: 120px !important;
}

.cs-message-time {
  font-size: 11px;
  color: #a0aec0;
  margin-top: 4px;
  text-align: right;
}

.cs-message.user .cs-message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* ==========================================
   正在思考 - 精致紧凑样式
   ========================================== */

/* 思考提示容器 - 紧凑设计 */
.cs-thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid #e9ecef;
}

.cs-thinking-text {
  font-size: 13px;
  color: #6c757d;
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* 动画点 - 更小巧精致 */
.cs-thinking-dots {
  display: flex;
  align-items: center;
  gap: 3px;
}

.cs-thinking-dots span {
  width: 5px;
  height: 5px;
  background: #adb5bd;
  border-radius: 50%;
  animation: cs-thinking-bounce 1.4s ease-in-out infinite both;
}

.cs-thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.cs-thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.cs-thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes cs-thinking-bounce {
  0%, 80%, 100% { 
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% { 
    transform: scale(1);
    opacity: 1;
    background: #dc2626;
  }
}

/* 行内紧凑思考样式 */
.cs-thinking-compact {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: #6c757d;
}

.cs-thinking-text {
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.cs-thinking-dots-inline {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.cs-thinking-dots-inline span {
  display: inline-block;
  width: 4px;
  height: 4px;
  background: #adb5bd;
  border-radius: 50%;
  animation: cs-thinking-inline 1.4s ease-in-out infinite both;
}

.cs-thinking-dots-inline span:nth-child(1) { animation-delay: -0.32s; }
.cs-thinking-dots-inline span:nth-child(2) { animation-delay: -0.16s; }
.cs-thinking-dots-inline span:nth-child(3) { animation-delay: 0s; }

@keyframes cs-thinking-inline {
  0%, 80%, 100% { 
    transform: scale(0.8);
    opacity: 0.4;
  }
  40% { 
    transform: scale(1.2);
    opacity: 1;
    background: #dc2626;
  }
}

/* 旧版加载动画 - 保持兼容 */
.cs-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.cs-typing span {
  width: 6px;
  height: 6px;
  background: #cbd5e0;
  border-radius: 50%;
  animation: cs-typing 1.4s infinite;
}

.cs-typing span:nth-child(2) { animation-delay: 0.2s; }
.cs-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cs-typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* 输入区域 */
.cs-input-area {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.cs-input-wrapper {
  flex: 1;
  background: #f7fafc;
  border-radius: 24px;
  padding: 4px;
  display: flex;
  align-items: center;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
}

/* 输入框聚焦 - 红色主题 */
.cs-input-wrapper:focus-within {
  border-color: #dc2626;
  background: white;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.cs-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 16px;
  font-size: 14px;
  color: #2d3748;
  outline: none;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  font-family: inherit;
}

.cs-input::placeholder { color: #a0aec0; }

/* 发送按钮 - 红色主题 */
.cs-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ff6b6b 0%, #dc2626 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.cs-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
}

.cs-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 连接状态 */
.cs-connection-status {
  padding: 8px 16px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  text-align: center;
  display: none;
}

.cs-connection-status.error {
  background: #fee2e2;
  color: #991b1b;
}

.cs-connection-status.show {
  display: block;
}

/* PC端适配 - 用户消息宽度自适应 */
@media (min-width: 769px) {
  .cs-message.user .cs-message-content {
    display: inline-flex;
    width: auto;
    max-width: min(400px, 50vw);
  }
}

/* 移动端适配 */
@media (max-width: 480px) {
  .cs-modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  
  .cs-modal {
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  
  /* 移动端消息适配 - 防止超边 */
  .cs-message {
    max-width: 85% !important;
    width: auto !important;
    padding: 0 10px;
    box-sizing: border-box;
  }
  
  .cs-message.user {
    justify-content: flex-end;
    padding-right: 10px;
  }
  
  /* 移动端头像样式 */
  .cs-message-avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
    flex-shrink: 0;
  }
  
  /* 移动端消息内容包装器 */
  .cs-message-content-wrapper {
    max-width: calc(100vw - 70px) !important;
    min-width: 0;
    flex: 1;
  }
  
  /* 移动端消息内容 - 覆盖PC端max-width: 400px */
  .cs-message-content {
    max-width: 100% !important;
    width: auto;
    font-size: 15px;
    padding: 10px 12px;
    word-break: break-all;
    overflow-wrap: break-word;
    box-sizing: border-box;
  }
  
  /* 用户消息移动端适配 */
  .cs-message.user .cs-message-content {
    max-width: 100% !important;
  }
  
  /* 移动端模态框 */
  .cs-modal {
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  .cs-modal-body {
    padding: 15px 0;
    overflow-x: hidden;
  }

  /* 移动端输入框适配 - 防止聚焦时变宽 */
  .cs-input-area {
    padding: 12px 15px;
    gap: 10px;
    box-sizing: border-box;
  }

  .cs-input-wrapper {
    flex: 1;
    min-width: 0;
    max-width: calc(100vw - 85px);
    box-sizing: border-box;
  }

  .cs-input-wrapper:focus-within {
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
    max-width: calc(100vw - 85px);
  }

  .cs-input {
    padding: 10px 14px;
    font-size: 16px;
    min-height: 40px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .cs-send-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }
}
