/* =========================================================================
 * ai-style.css —— “小A” AI 交互式答疑助手样式
 * -------------------------------------------------------------------------
 * 使用说明：
 *   1. 所有样式均以 .ai- 前缀命名，与网站原有样式隔离，不影响现有页面。
 *   2. 配色与网站现有主题（蓝色系）保持一致：
 *       主色 #2f7cf6 / 深蓝 #1e4fd8 / 浅蓝 #eaf3ff / 边框 #dbeafe
 *   3. 本文件需在 index.html 的 <head> 中通过 <link> 引入。
 * ========================================================================= */

/* =========================================================================
 * 1. 头像悬浮球（可拖拽）
 * -------------------------------------------------------------------------
 * 默认位置：bottom:160px; left:16px（底部导航栏左上方，不重叠）
 * 拖动后由 JS 写入 left/top 定位，可覆盖任意区域（含底部导航栏）。
 * 头像是透明背景 PNG，因此**去掉白色圆形底与描边**，只保留轻阴影，
 * 让角色图直接以透明背景显示；整体缩小后更小巧，不遮挡页面内容。
 * ========================================================================= */
.ai-fab {
  position: fixed;                 /* 固定定位，所有视图统一可见 */
  left: 16px;
  bottom: 160px;
  width: 54px;                     /* 头像直径 54px（原 72px，缩小） */
  height: 54px;
  z-index: 500;                    /* 高于底部导航栏(100)，低于网站弹层(998+) */
  border-radius: 50%;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;              /* 阻止浏览器把拖动当成页面滚动 */
  -webkit-tap-highlight-color: transparent;
}

/* 头像图片：透明底 · 不裁剪 · 无白圈 */
.ai-fab-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;               /* 保留圆形布局（与呼吸环对齐） */
  object-fit: contain;             /* 透明图完整显示，不裁掉角色边缘 */
  border: none;                    /* 去掉白色描边 */
  background: transparent;         /* 去掉白色圆底，露出透明背景 */
  box-shadow: none;                /* 不用方块阴影，改用在下方 drop-shadow */
  filter: drop-shadow(0 3px 8px rgba(47, 124, 246, 0.28)); /* 仅留柔和投影 */
  pointer-events: none;            /* 让事件始终落在 .ai-fab 容器上（方便拖拽） */
}

/* 呼吸灯光环（悬浮球外圈脉动） */
.ai-fab::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid rgba(47, 124, 246, 0.45);
  animation: aiBreath 2.4s ease-in-out infinite;
  pointer-events: none;
}

/* 拖动中的状态 */
.ai-fab.ai-dragging {
  cursor: grabbing;
  opacity: 0.92;
  transition: none !important;
}

/* 吸附动画（松手瞬间平滑滑向边缘） */
.ai-fab.ai-snapping {
  transition: left 0.22s ease, top 0.22s ease;
}

/* 气泡显示期间：头像轻轻晃动（吸引注意但不强制） */
.ai-fab.ai-shaking .ai-fab-img {
  animation: aiShake 0.6s ease-in-out infinite;
}

@keyframes aiBreath {
  0%, 100% { transform: scale(1);    opacity: 0.65; }
  50%      { transform: scale(1.14); opacity: 0.25; }
}

@keyframes aiShake {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-4deg); }
  50%      { transform: rotate(3deg); }
  75%      { transform: rotate(-2deg); }
}

/* =========================================================================
 * 2. 主动弹出气泡（QQ 风格，带小尾巴指向小A头像）
 * -------------------------------------------------------------------------
 * 默认显示在头像上方；当头像贴近屏幕顶部时 JS 会自动切换到头像下方，
 * 并通过 .ai-bubble--below 翻转尾巴方向。
 * ========================================================================= */
.ai-bubble {
  position: fixed;
  z-index: 510;                    /* 略高于头像 */
  max-width: 264px;
  width: max-content;
  padding: 10px 14px;
  background: #ffffff;
  border: 1.5px solid #cfe1ff;
  border-radius: 14px 14px 14px 4px;   /* 左下角小圆角，配合尾巴 */
  box-shadow: 0 6px 20px rgba(30, 90, 255, 0.16);
  font-size: 13.5px;
  line-height: 1.6;
  color: #1f2d3d;
  word-break: break-word;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transform-origin: left bottom;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 气泡尾巴（指向头像的三角） */
.ai-bubble::after {
  content: "";
  position: absolute;
  left: 26px;
  bottom: -7px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 8px 0 0;       /* 朝右下 */
  border-color: #ffffff transparent transparent transparent;
  filter: drop-shadow(1px 1px 0 #cfe1ff);
}

/* 显示状态 */
.ai-bubble.ai-bubble--show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;            /* 可点击 → 打开对话框 */
  animation: aiBubbleIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes aiBubbleIn {
  0%   { opacity: 0; transform: translateY(8px) scale(0.92); }
  100% { opacity: 1; transform: translateY(0)  scale(1); }
}

/* 头像在屏幕上方时：气泡显示在头像下方、尾巴朝上 */
.ai-bubble.ai-bubble--below {
  border-radius: 14px 14px 4px 14px;
  transform-origin: left top;
}
.ai-bubble.ai-bubble--below::after {
  bottom: auto;
  top: -7px;
  border-width: 0 8px 8px 0;      /* 朝右上 */
  border-color: transparent #ffffff transparent transparent;
}

/* =========================================================================
 * 3. 对话框外层容器 + 遮罩
 * ========================================================================= */
.ai-chat {
  position: fixed;
  inset: 0;
  z-index: 950;                    /* 高于头像/底部导航，低于网站全屏遮罩 */
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 16px 88px 16px;       /* 底部留出空间，不贴屏幕底 */
}

.ai-chat.ai-chat--show {
  display: flex;
}

/* 半透明遮罩：点击遮罩可关闭对话框 */
.ai-chat-mask {
  position: absolute;
  inset: 0;
  background: rgba(23, 42, 76, 0.28);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: aiMaskIn 0.25s ease;
}

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

/* =========================================================================
 * 4. 对话框主体（毛玻璃 + 圆角）
 * ========================================================================= */
.ai-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: 100%;
  height: 480px;
  max-height: calc(100vh - 110px);
  background: rgba(255, 255, 255, 0.92);     /* 毛玻璃 */
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  border-radius: 20px;
  box-shadow: 0 18px 60px rgba(20, 45, 100, 0.28);
  border: 1px solid rgba(207, 225, 255, 0.9);
  overflow: hidden;
}

/* 打开动画：由 JS 依据头像位置设置 transform-origin，从头像处放大展开 */
.ai-chat.ai-chat--show .ai-dialog {
  animation: aiDialogIn 0.30s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

/* JS 在设置动画原点前会临时加上该 class，暂时停用入场动画 */
.ai-dialog.ai-no-anim {
  animation: none !important;
}

@keyframes aiDialogIn {
  from { opacity: 0; transform: scale(0.18); }
  to   { opacity: 1; transform: scale(1); }
}

/* ----- 4.1 标题栏 ----- */
.ai-dialog-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #eaf3ff, #dbeafe);   /* 与首页 hero 同色系 */
  border-bottom: 1px solid #cfe1ff;
}

.ai-header-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(47, 124, 246, 0.25);
  background: #fff;
}

.ai-header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: #1e3a8a;
}

.ai-header-tools {
  display: flex;
  gap: 6px;
}

.ai-icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  color: #4b6ea8;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.ai-icon-btn:active {
  background: #d6e6ff;
  transform: scale(0.92);
}

/* ----- 4.2 消息列表 ----- */
.ai-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 0% 0%, rgba(234, 243, 255, 0.6), transparent 40%),
    rgba(248, 252, 255, 0.6);
}

/* 单条消息行 */
.ai-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
}

/* 小A 行：头像在左 */
.ai-row--ai {
  justify-content: flex-start;
}

/* 用户行：整体靠右 */
.ai-row--user {
  justify-content: flex-end;
}

/* 消息侧小头像 */
.ai-row-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 5px rgba(47, 124, 246, 0.25);
  background: #fff;
  margin-top: 2px;
}

/* 文本气泡 */
.ai-msg-bubble {
  max-width: 78%;
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-line;           /* 保留 AI 回复里的换行 */
}

/* 小A气泡：白底 + 蓝边框（左对齐） */
.ai-row--ai .ai-msg-bubble {
  background: #ffffff;
  border: 1px solid #dbeafe;
  border-radius: 4px 16px 16px 16px;
  color: #1f2d3d;
  box-shadow: 0 2px 8px rgba(30, 90, 255, 0.06);
}

/* 用户气泡：蓝色渐变（右对齐） */
.ai-row--user .ai-msg-bubble {
  background: linear-gradient(135deg, #4a90ff, #2f7cf6);
  color: #ffffff;
  border-radius: 16px 4px 16px 16px;
  box-shadow: 0 3px 10px rgba(47, 124, 246, 0.22);
}

/* 正在输入动画点 */
.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 4px 16px 16px 16px;
}
.ai-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7fa9e8;
  animation: aiTypingDot 1.2s ease-in-out infinite;
}
.ai-typing i:nth-child(2) { animation-delay: 0.18s; }
.ai-typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes aiTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* 消息进入动画 */
.ai-row {
  animation: aiMsgIn 0.22s ease both;
}
@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- 4.3 「原文参考」卡片 ----- */
.ai-ref-card {
  max-width: 85%;
  background: #f2f7ff;
  border: 1px solid #cfe1ff;
  border-left: 4px solid #2f7cf6;
  border-radius: 4px 14px 14px 14px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ai-ref-card:active {
  background: #e3eeff;
  transform: scale(0.98);
}

.ai-ref-head {
  font-size: 12.5px;
  font-weight: 700;
  color: #1e4fd8;
  margin-bottom: 3px;
}
.ai-ref-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: #3a4a5d;
  word-break: break-word;
}
.ai-ref-tip {
  margin-top: 5px;
  font-size: 12px;
  color: #2f7cf6;
  font-weight: 500;
}

/* ----- 4.4 快捷提问按钮 ----- */
.ai-quick {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 12px 2px;
  background: rgba(248, 252, 255, 0.7);
  border-top: 1px solid rgba(219, 234, 254, 0.6);
}
.ai-quick.ai-quick--hide {
  display: none;
}

.ai-quick-btn {
  padding: 6px 12px;
  border: 1.5px solid #bcd7ff;
  border-radius: 16px;
  background: #ffffff;
  color: #2f5cb0;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
.ai-quick-btn:active {
  background: #2f7cf6;
  border-color: #2f7cf6;
  color: #fff;
  transform: scale(0.95);
}

/* ----- 4.5 输入框与发送按钮 ----- */
.ai-inputbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 6px;
  background: #ffffff;
  border-top: 1px solid #e6efff;
}

.ai-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  border: 1.5px solid #cfe1ff;
  border-radius: 19px;
  outline: none;
  font-size: 14px;
  color: #1f2d3d;
  background: #f8fbff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-input:focus {
  border-color: #2f7cf6;
  box-shadow: 0 0 0 3px rgba(47, 124, 246, 0.14);
  background: #fff;
}
.ai-input::placeholder { color: #9db6d8; }

.ai-send-btn {
  flex-shrink: 0;
  height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: 19px;
  background: linear-gradient(135deg, #4a90ff, #2f7cf6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.ai-send-btn:active { transform: scale(0.94); }
.ai-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ----- 4.6 底部标注 ----- */
.ai-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 4px 0 7px;
  font-size: 10.5px;
  color: #9db6d8;
  background: #ffffff;
  border-top: 1px solid #f0f6ff;
}

/* 对话框滚动条美化 */
.ai-msgs::-webkit-scrollbar { width: 5px; }
.ai-msgs::-webkit-scrollbar-thumb { background: #cfe1ff; border-radius: 4px; }
.ai-msgs::-webkit-scrollbar-track { background: transparent; }

/* =========================================================================
 * 5. 移动端适配：对话框覆盖屏幕约 90%（高度 90%、宽度 94%），更聚焦对话
 * ========================================================================= */
@media (max-width: 520px) {
  .ai-chat {
    padding: 0;
  }
  .ai-dialog {
    width: 94vw;                   /* 宽度约 94%，留少量边距更精致 */
    max-width: 94vw;
    height: 90vh;                  /* 高度约 90%（兜底） */
    height: 90dvh;                 /* 移动端动态视口高度约 90% */
    max-height: 90dvh;
    border-radius: 16px;           /* 保留圆角，不贴死屏幕边 */
    border: 1px solid rgba(207, 225, 255, 0.9);
  }
}

/* =========================================================================
 * 6. 调试面板（仅 URL 带 ?aidebug=1 时由 JS 创建，平时不渲染）
 * ========================================================================= */
.ai-debug-panel {
  position: fixed;
  left: 12px;
  bottom: 260px;
  z-index: 99999;
  width: min(320px, calc(100vw - 24px));
  max-height: 45vh;
  overflow: hidden;
  background: rgba(20, 26, 40, 0.92);
  color: #e8f1ff;
  border-radius: 12px;
  font: 12px/1.6 "Microsoft YaHei", monospace;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}
.ai-debug-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: #2f7cf6;
  font-weight: 600;
}
.ai-debug-close {
  cursor: pointer;
  padding: 0 4px;
  color: #fff;
}
.ai-debug-body {
  max-height: calc(45vh - 30px);
  overflow-y: auto;
  padding: 6px 10px;
  word-break: break-all;
}
.ai-debug-body div {
  border-bottom: 1px dashed rgba(255, 255, 255, 0.15);
  padding: 2px 0;
}

/* =========================================================================
 * 7. 点击“原文参考”跳转后的目标高亮（蓝色呼吸描边，数秒后自动消失）
 * ========================================================================= */
.ai-jump-target {
  outline: 3px solid rgba(47, 124, 246, 0.95) !important;
  outline-offset: 3px !important;
  border-radius: 10px;
  animation: aiJumpPulse 1.1s ease-in-out infinite;
}
@keyframes aiJumpPulse {
  0%, 100% { outline-color: rgba(47, 124, 246, 0.95); }
  50%      { outline-color: rgba(47, 124, 246, 0.25); }
}

