/* 智能客服聊天组件（仿 visit-popup 的固定定位模式） */

.chat-widget-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0052cc;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 24px;
  z-index: 9998;
  box-shadow: 0 4px 15px #557ad1;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px #557ad1;
}

.chat-widget-window {
  display: none;
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 380px;
  height: 520px;
  max-height: 70vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 5px 20px #557ad1;
  z-index: 9999;
  font-family: "Nunito", sans-serif;
  overflow: hidden;
  flex-direction: column;
}

.chat-widget-window.open {
  display: flex;
}

.chat-widget-header {
  padding: 14px 20px;
  background-color: #0052cc;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-widget-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: white;
  letter-spacing: 1px;
}

.chat-widget-close {
  color: white;
  font-size: 26px;
  line-height: 1;
  font-weight: 300;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.chat-widget-close:hover {
  opacity: 1;
}

/* 首次使用：身份收集表单 */
.chat-identity {
  padding: 25px;
}

.chat-identity .form-group {
  margin-bottom: 16px;
}

.chat-identity label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.chat-identity label .required {
  color: #ff4d4f;
  margin-left: 4px;
}

.chat-identity input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  box-sizing: border-box;
  font-size: 14px;
  color: #333;
  background-color: #f9f9f9;
  transition: border-color 0.3s, background-color 0.3s;
}

.chat-identity input:focus {
  outline: none;
  border-color: #0052cc;
  background-color: #fff;
}

.chat-identity .privacy-group {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.chat-identity .privacy-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
  cursor: pointer;
}

.chat-identity .privacy-group label {
  font-size: 13px;
  font-weight: 400;
  margin-bottom: 0;
  display: inline;
  cursor: pointer;
}

.chat-identity .privacy-group a {
  color: #0052cc;
  text-decoration: underline;
}

.chat-identity button {
  width: 100%;
  padding: 12px;
  background: #0052cc;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
}

.chat-identity .chat-identity-tip {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  min-height: 18px;
  color: #dc3545;
}

/* 聊天主区域 */
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: #f5f7fa;
}

.chat-msg {
  display: flex;
  margin-bottom: 12px;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg .bubble {
  padding: 9px 13px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg-col {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

.chat-msg.ai .bubble {
  background: #fff;
  color: #0d3a3c;
  border: 1px solid #eee;
}

.chat-ai-tag {
  font-size: 10px;
  color: #bfc9d1;
  margin-top: 3px;
  transform: scale(0.92);
  transform-origin: left center;
}

.chat-ai-tag::before {
  content: '✦';
  margin-right: 3px;
  color: #d3dbe2;
}

.chat-msg.user .bubble {
  background: #0052cc;
  color: #fff;
}

.chat-msg.ai .bubble.typing {
  color: #999;
}

.chat-msg.ai .bubble.typing::after {
  content: '…';
  animation: chat-blink 1s steps(1, end) infinite;
}

@keyframes chat-blink {
  50% { opacity: 0; }
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 14px;
  background: #f9f9f9;
  box-sizing: border-box;
}

.chat-input-area input:focus {
  outline: none;
  border-color: #0052cc;
  background: #fff;
}

.chat-input-area button {
  padding: 9px 18px;
  background: #0052cc;
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-input-area button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .chat-widget-window {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 70vh;
    max-height: none;
    border-radius: 12px 12px 0 0;
  }

  .chat-widget-btn {
    bottom: 20px;
    right: 20px;
  }
}
