/* ========== 智能问答悬浮窗口 ========== */
.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.chat-fab {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--brand-yellow, #f5a623);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(10, 37, 64, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  padding: 0;
}

.chat-fab:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 12px 28px rgba(10, 37, 64, 0.35);
  border-color: var(--brand-dark, #0a2540);
}

.chat-fab img,
.chat-fab svg.chat-avatar-svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.chat-fab.active img,
.chat-fab.active svg.chat-avatar-svg {
  transform: scale(1.1);
}

.chat-fab .chat-badge {
  position: absolute;
  top: 0px;
  right: 0px;
  background: #ff4d4f;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid #fff;
  animation: badge-pulse 2s ease-in-out infinite;
  z-index: 1;
}

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

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 360px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(10, 37, 64, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(16px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: bottom right;
}

.chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.chat-header {
  background: linear-gradient(135deg, var(--brand-dark, #0a2540) 0%, #1a4a7a 100%);
  color: #fff;
  padding: 20px 20px 16px;
  position: relative;
}

.chat-header-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-yellow, #f5a623);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-avatar svg {
  width: 22px;
  height: 22px;
  color: var(--brand-dark, #0a2540);
}

.chat-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.chat-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
}

.chat-status-dot.busy {
  background: #f5a623;
  box-shadow: 0 0 8px rgba(245, 166, 35, 0.6);
  animation: pulse 1.5s ease-in-out infinite;
}

.chat-status-dot.human-online {
  background: #3b82f6;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-avatar.human {
  background: #3b82f6 !important;
}

.chat-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-close svg {
  width: 16px;
  height: 16px;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f7f9fc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(10, 37, 64, 0.2);
  border-radius: 2px;
}

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: msg-in 0.3s ease;
}

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

.chat-msg.bot {
  align-self: flex-start;
}

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

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-msg.bot .chat-msg-avatar {
  background: var(--brand-yellow, #f5a623);
}

.chat-msg.user .chat-msg-avatar {
  background: var(--brand-dark, #0a2540);
}

/* 人工客服消息 */
.chat-msg.agent {
  align-self: flex-start;
}

.chat-msg.agent .chat-msg-avatar {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

.chat-msg.agent .chat-msg-avatar svg {
  color: #fff;
}

.chat-msg.agent .chat-msg-bubble {
  background: #eff6ff;
  color: #1e3a5f;
  border-top-left-radius: 4px;
  border: 1px solid #dbeafe;
}

.chat-msg-agent-name {
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
  margin-bottom: 4px;
}

/* 系统消息 */
.chat-msg.system {
  align-self: center;
  max-width: 90%;
}

.chat-msg-system {
  padding: 8px 14px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  border: 1px solid #fde68a;
}

.chat-msg-avatar svg {
  width: 16px;
  height: 16px;
}

.chat-msg.bot .chat-msg-avatar svg {
  color: var(--brand-dark, #0a2540);
}

.chat-msg.user .chat-msg-avatar svg {
  color: #fff;
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-msg.bot .chat-msg-bubble {
  background: #fff;
  color: #333;
  border-top-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(10, 37, 64, 0.06);
}

.chat-msg.user .chat-msg-bubble {
  background: var(--brand-dark, #0a2540);
  color: #fff;
  border-top-right-radius: 4px;
}

.chat-msg-bubble p {
  margin: 0 0 6px;
}

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

.chat-msg-bubble ul {
  margin: 6px 0;
  padding-left: 18px;
}

.chat-msg-bubble li {
  margin-bottom: 4px;
}

.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chat-quick-btn {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid rgba(10, 37, 64, 0.15);
  background: #fff;
  color: var(--brand-dark, #0a2540);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-quick-btn:hover {
  background: var(--brand-dark, #0a2540);
  color: #fff;
  border-color: var(--brand-dark, #0a2540);
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(10, 37, 64, 0.3);
  animation: typing 1.4s ease-in-out infinite;
}

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

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

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

.chat-input-wrap {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #eef1f5;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  border: 1px solid #e0e4ea;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
  resize: none;
  max-height: 80px;
  font-family: inherit;
  transition: border-color 0.2s;
  line-height: 1.4;
}

.chat-input:focus {
  border-color: var(--brand-dark, #0a2540);
}

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-dark, #0a2540);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  margin-bottom: 2px;
}

.chat-send:hover:not(:disabled) {
  background: #1a4a7a;
  transform: scale(1.05);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

.chat-footer {
  padding: 8px 14px 10px;
  text-align: center;
  font-size: 11px;
  color: rgba(10, 37, 64, 0.4);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.chat-lead-link {
  color: var(--brand-dark, #0a2540);
  font-weight: 600;
  text-decoration: none;
  background: rgba(245, 166, 35, 0.15);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  transition: all 0.2s;
}

.chat-lead-link:hover {
  background: rgba(245, 166, 35, 0.3);
}

.chat-human-link {
  color: #3b82f6;
  font-weight: 600;
  text-decoration: none;
  background: rgba(59, 130, 246, 0.1);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  transition: all 0.2s;
}

.chat-human-link:hover {
  background: rgba(59, 130, 246, 0.2);
}

.chat-human-link.active {
  background: #3b82f6;
  color: #fff;
}

/* 报价表单弹窗 */
.chat-lead-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 37, 64, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  padding: 20px;
}

.chat-lead-modal.show {
  opacity: 1;
  visibility: visible;
}

.chat-lead-content {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(10, 37, 64, 0.3);
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.chat-lead-modal.show .chat-lead-content {
  transform: translateY(0) scale(1);
}

.chat-lead-header {
  background: linear-gradient(135deg, #0a2540 0%, #1a4a7a 100%);
  color: #fff;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-lead-header h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.chat-lead-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.chat-lead-form {
  padding: 24px;
}

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

.chat-lead-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.chat-lead-form input,
.chat-lead-form select,
.chat-lead-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.chat-lead-form input:focus,
.chat-lead-form select:focus,
.chat-lead-form textarea:focus {
  border-color: var(--brand-yellow, #f5a623);
}

.chat-lead-form textarea {
  resize: vertical;
  min-height: 70px;
}

.chat-lead-submit {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #f5a623, #f7b733);
  color: #0a2540;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 8px;
}

.chat-lead-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(245, 166, 35, 0.4);
}

.chat-lead-tip {
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
  margin-top: 12px;
  margin-bottom: 0;
}

/* 响应式 */
@media (max-width: 640px) {
  .chat-widget {
    right: 16px;
    bottom: 16px;
  }
  .chat-fab {
    width: 52px;
    height: 52px;
    border-width: 2px;
  }
  .chat-panel {
    width: calc(100vw - 32px);
    height: 70vh;
    right: 0;
    bottom: 64px;
  }
}

/* 聊天菜单按钮 */
.chat-menu-btn {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-menu-btn:hover {
  background: rgba(255,255,255,0.2);
}

.chat-menu-btn svg {
  width: 18px;
  height: 18px;
}

/* 聊天下拉菜单 */
.chat-menu-dropdown {
  position: absolute;
  top: 60px;
  right: 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  padding: 8px;
  min-width: 160px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s ease;
}

.chat-menu-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  color: #334155;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.chat-menu-item:hover {
  background: #f1f5f9;
  color: #0a2540;
}

.chat-menu-item span:first-child {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* 快捷问题栏 */
.chat-quick-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}

.chat-quick-bar::-webkit-scrollbar {
  display: none;
}

.chat-quick-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.chat-quick-chip:hover {
  border-color: #f5a623;
  color: #f5a623;
  background: #fffbeb;
}
