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

:root {
  --bg: #f0f4fa;
  --bg-secondary: #ffffff;
  --bg-card: #f5f8fd;
  --border: #dce6f2;
  --text: #1a1a1a;
  --text-secondary: #5a6a7a;
  --text-muted: #9ab0c4;
  --primary: #1677ff;
  --primary-hover: #0958d9;
  --primary-bg: rgba(22, 119, 255, 0.1);
  --primary-light: rgba(22, 119, 255, 0.06);
  --success: #52c41a;
  --bot-bg: #ffffff;
  --user-bg: #1677ff;
  --user-text: #ffffff;
  --header-bg: linear-gradient(135deg, #1677ff 0%, #0958d9 100%);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ========== 聊天容器 ========== */
.chat-container {
  width: 100%;
  max-width: 800px;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: 0 0 40px rgba(22, 119, 255, 0.08);
}

/* ========== 头部 ========== */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--header-bg);
  border-bottom: none;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(22, 119, 255, 0.15);
}

.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
}

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

.header-info h1 {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

.status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.btn-transfer {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 500;
}

.btn-transfer:hover { background: rgba(255, 255, 255, 0.3); }

/* ========== 联系方式弹窗 ========== */
.contact-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

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

.contact-modal {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  animation: modalUp 0.25s ease;
  overflow: hidden;
}

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

.contact-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: linear-gradient(135deg, #1677ff 0%, #0958d9 100%);
}

.contact-modal-header h3 {
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}

.contact-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.contact-close:hover { color: #fff; }

.contact-modal-body { padding: 24px; }

.contact-tip {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
  text-align: center;
}

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

.contact-form label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.contact-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}

.contact-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.1);
}

.contact-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 12px;
}

.contact-modal-footer {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.contact-modal-footer button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.btn-cancel {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-cancel:hover { background: var(--border); }

.btn-submit {
  background: var(--primary);
  color: #fff;
}

.btn-submit:hover { background: var(--primary-hover); }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== 消息中的转人工提示 ========== */
.contact-tip-msg {
  text-align: center;
  margin: 4px 0 12px;
}

.btn-leave-contact {
  padding: 10px 28px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(22, 119, 255, 0.25);
}

.btn-leave-contact:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 119, 255, 0.3);
}

.btn-icon:hover { color: #fff; background: rgba(255, 255, 255, 0.2); }

/* ========== 消息区域 ========== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }

/* ========== 欢迎消息 ========== */
.welcome-msg {
  text-align: center;
  padding: 40px 20px;
  margin: auto;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--primary);
}

.welcome-msg h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome-msg p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.quick-btn {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.quick-btn:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
  color: var(--primary);
}

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

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

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message.user .msg-avatar {
  background: var(--primary);
  color: #fff;
}

.message.bot .msg-avatar {
  background: var(--primary-bg);
  color: var(--primary);
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.message.user .msg-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: var(--radius-sm);
}

.message.bot .msg-bubble {
  background: var(--bot-bg);
  color: #1a1a1a;
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }

/* ========== 聊天图片 ========== */
.chat-image {
  max-width: 220px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 8px;
  display: block;
  transition: opacity 0.2s;
}

.chat-image:hover {
  opacity: 0.9;
}

.chat-image-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: pointer;
}

.chat-image-modal img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

/* ========== 打字指示器 ========== */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ========== 输入区域 ========== */
.chat-input-area {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.1);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 4px 0;
}

#messageInput::placeholder { color: var(--text-muted); }

.btn-send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { background: var(--border); cursor: not-allowed; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}
