/* AI 智能问答弹窗样式 */

/* 弹窗打开时锁定页面，防止移动端输入框聚焦导致页面溢出 */
body.ai-chat-open,
html.ai-chat-open {
  overflow: hidden !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* 遮罩层 */
.ai-chat-modal-mask {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9999;
}

/* 弹窗主体 - 电脑端：右侧悬浮卡片 */
.ai-chat-modal-body {
  position: fixed;
  right: 20px; bottom: 80px;
  width: 420px; height: 600px;
  max-width: calc(100vw - 40px);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  background: #fff;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: aiChatSlideUp 0.3s ease;
}

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

/* 标题栏 */
.ai-chat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.ai-chat-close {
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.ai-chat-close:hover { opacity: 1; }

.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-contact {
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  opacity: 0.9;
  transition: opacity 0.2s;
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.15);
}
.ai-chat-contact:hover { opacity: 1; background: rgba(255, 255, 255, 0.25); }

/* 内容区 - flex链条：body→content→section 均需flex column */
.ai-chat-modal-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.ai-chat-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* 消息列表 */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* 消息气泡 */
.ai-msg-row {
  display: flex;
  margin-bottom: 14px;
}
.ai-msg-row.user { justify-content: flex-end; }
.ai-msg-row.assistant { justify-content: flex-start; }

.ai-msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.ai-msg-row.user .ai-msg-bubble {
  background: #1a73e8;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-row.assistant .ai-msg-bubble {
  background: #f1f3f5;
  color: #333;
  border-bottom-left-radius: 4px;
}

/* Markdown 内容样式 */
.ai-msg-bubble p { margin: 0 0 8px; }
.ai-msg-bubble p:last-child { margin-bottom: 0; }
.ai-msg-bubble h1, .ai-msg-bubble h2, .ai-msg-bubble h3, .ai-msg-bubble h4, .ai-msg-bubble h5, .ai-msg-bubble h6 {
  font-size: 14px;
  font-weight: 600;
  margin: 10px 0 6px;
  line-height: 1.5;
}
.ai-msg-bubble h1 { font-size: 15px; }
.ai-msg-bubble h2 { font-size: 15px; }
.ai-msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}
.ai-msg-bubble pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}
.ai-msg-bubble pre code { background: transparent; color: inherit; padding: 0; }
.ai-msg-bubble ul, .ai-msg-bubble ol { padding-left: 18px; margin: 4px 0; }
.ai-msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.ai-msg-bubble th, .ai-msg-bubble td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
.ai-msg-bubble th { background: #f5f5f5; }

/* 思考指示器 */
.ai-thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  color: #888;
  font-size: 13px;
}
.ai-thinking-indicator .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #aaa;
  animation: aiDotPulse 1.4s infinite ease-in-out;
}
.ai-thinking-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.ai-thinking-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

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

/* 场景引导卡片 */
.ai-scenario-guide {
  background: #f8f9ff;
  border: 1px solid #e8ecff;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}
.ai-welcome-text {
  font-size: 14px;
  color: #333;
  line-height: 1.6;
  margin-bottom: 12px;
}
.ai-scenario-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ai-scenario-tags .ai-tag {
  display: inline-block;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #d0d7ff;
  border-radius: 16px;
  font-size: 12px;
  color: #1a73e8;
  cursor: pointer;
  transition: all 0.2s;
}
.ai-scenario-tags .ai-tag:hover {
  background: #1a73e8;
  color: #fff;
  border-color: #1a73e8;
}

/* 留资引导卡片 */
.ai-lead-card {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cc 100%);
  border: 1px solid #ffe58f;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}
.ai-lead-card .lead-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}
.ai-lead-card .lead-desc {
  font-size: 13px;
  color: #666;
  margin-bottom: 12px;
  line-height: 1.5;
}
.ai-lead-card .lead-form input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.ai-lead-card .lead-form input:focus {
  outline: none;
  border-color: #1a73e8;
}
.ai-lead-card .lead-form textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
.ai-lead-card .lead-form textarea:focus {
  outline: none;
  border-color: #1a73e8;
}
.ai-lead-card .lead-btns {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.ai-lead-card .lead-btns .btn-submit {
  flex: 1;
  padding: 8px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.ai-lead-card .lead-btns .btn-submit:hover { background: #1557b0; }
.ai-lead-card .lead-btns .btn-skip {
  padding: 8px 16px;
  background: transparent;
  color: #999;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.ai-lead-card .lead-btns .btn-skip:hover { color: #666; border-color: #bbb; }

/* 回答末尾留资引导链接 */
.ai-lead-trigger {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0,0,0,0.08);
  font-size: 12px;
  color: #999;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-lead-trigger a {
  color: #1a73e8;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.ai-lead-trigger a:hover {
  text-decoration: underline;
}

/* 引用来源 */
.ai-references {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  font-size: 12px;
  color: #666;
}
.ai-references .ref-item {
  margin-bottom: 4px;
  line-height: 1.4;
}
.ai-references .ref-item:last-child { margin-bottom: 0; }

/* 输入区 */
.ai-chat-input-area {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
  background: #fff;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.ai-chat-input-area input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.ai-chat-input-area input:focus { border-color: #1a73e8; }
.ai-chat-input-area input:disabled { background: #f5f5f5; color: #999; }
.ai-chat-input-area button {
  margin-left: 8px;
  padding: 10px 18px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.ai-chat-input-area button:hover { background: #1557b0; }
.ai-chat-input-area button:disabled { background: #ccc; cursor: not-allowed; }
/* 停止按钮 */
.ai-chat-input-area button.ai-btn-stop {
  background: #ff4d4f;
}
.ai-chat-input-area button.ai-btn-stop:hover {
  background: #d93636;
}

/* 手机端：全屏覆盖 */
@media (max-width: 767px) {
  /* 手机端显示"在线咨询"入口按钮（覆盖 responsive.css 的 display:none） */
  .contacts-fix {
    display: flex !important;
  }
  .ai-chat-modal-body {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: 0;
    border-radius: 0;
    overflow: hidden;
    max-width: 100%;
    width: 100%;
    height: 100%;
  }
  .ai-chat-modal-header {
    padding: 12px 16px;
    /* 适配移动端安全区域 */
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }
  .ai-chat-input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  /* 关键修复：手机端输入框字号设为 16px，防止 iOS Safari 自动缩放 */
  .ai-chat-input-area input {
    font-size: 16px !important;
  }
  .ai-scenario-tags .ai-tag {
    font-size: 11px;
    padding: 5px 10px;
  }
}
