/* ============================================================
   「AI 学长」离线问答助手 —— 组件样式表
   与站点方案 A 玻璃拟态一致：
   - 面板/悬浮球背景：var(--card-bg-strong)（深色即 rgba(15,23,42,0.60)）+ blur
   - 边框：var(--card-border)（无 style.css 时回退 rgba(255,255,255,0.10)）
   - hover 青色发光：0 0 20px rgba(6,182,212,0.15)
   全部颜色取自 style.css 既有 CSS 变量，自动适配深浅双主题。
   接入：head 引入本文件 + </body> 前引入 assets/js/assistant.js 即可。
   ============================================================ */

/* ----------------------------------------------------------
   一、右下角悬浮球（玻璃圆钮：✨ + 「问学长」）
   ---------------------------------------------------------- */
.ai-fab {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  z-index: 990;
  width: 3.6rem;
  height: 3.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  border-radius: 50%;
  background: var(--card-bg-strong, rgba(15, 23, 42, 0.60));
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  backdrop-filter: blur(12px) saturate(1.4);
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  box-shadow: var(--shadow, 0 8px 30px rgba(6, 182, 212, 0.10));
  color: var(--text, #e2e8f0);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease,
    background 0.25s ease, border-color 0.25s ease;
}

.ai-fab:hover,
.ai-fab:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent-border, rgba(34, 211, 238, 0.35));
  /* 青色微发光（方案 A 指定值） */
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15),
    var(--shadow-hover, 0 14px 44px rgba(6, 182, 212, 0.20));
}

.ai-fab-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.ai-fab-text {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-dim, #94a3b8);
  letter-spacing: 0.05em;
}

/* 面板打开时悬浮球轻微收敛，仍可点击用于关闭 */
.ai-fab[aria-expanded="true"] {
  opacity: 0.75;
  transform: scale(0.92);
}

/* ----------------------------------------------------------
   二、聊天面板（玻璃大卡片）
   ---------------------------------------------------------- */
.ai-panel {
  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + 3.6rem + 0.85rem + env(safe-area-inset-bottom, 0px));
  z-index: 991;
  width: min(380px, calc(100vw - 2rem));
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-lg, 1.5rem);
  background: var(--card-bg-strong, rgba(15, 23, 42, 0.60));
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  box-shadow: var(--shadow-hover, 0 14px 44px rgba(6, 182, 212, 0.20));
  /* 收起态：透明下沉，不可交互 */
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease,
    transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-panel:hover {
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15),
    var(--shadow-hover, 0 14px 44px rgba(6, 182, 212, 0.20));
}

/* 展开态（JS 切换 .ai-open） */
.ai-panel.ai-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
}

/* ---------- 标题栏 ---------- */
.ai-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.7rem;
  border-bottom: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
}

.ai-title {
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text, #e2e8f0);
}

.ai-sub {
  margin-top: 0.1rem;
  font-size: 0.72rem;
  color: var(--text-faint, #64748b);
}

/* 关闭按钮：小玻璃圆钮 */
.ai-close {
  flex: none;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  border-radius: 50%;
  color: var(--text-dim, #94a3b8);
  background: var(--card-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
}

.ai-close:hover,
.ai-close:focus-visible {
  color: var(--text, #e2e8f0);
  transform: rotate(90deg);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15);
}

/* ---------- 消息区 ---------- */
.ai-msgs {
  flex: 1 1 auto;
  min-height: 9rem;
  overflow-y: auto;
  padding: 0.9rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
}

/* 消息气泡：弹簧曲线弹入 */
.ai-msg {
  max-width: 88%;
  padding: 0.55rem 0.85rem;
  border-radius: 0.9rem;
  font-size: 0.88rem;
  line-height: 1.65;
  animation: ai-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* 恢复历史会话时不重放动画 */
.ai-msg.ai-no-anim {
  animation: none;
}

/* 消息正文：textContent 写入，靠 pre-line 呈现换行（安全，无 innerHTML） */
.ai-msg-text {
  white-space: pre-line;
  word-break: break-word;
}

/* 用户消息：右侧渐变气泡 */
.ai-msg.ai-user {
  align-self: flex-end;
  background: var(--grad, linear-gradient(135deg, #22d3ee, #3b82f6));
  color: #f0fdff;
  border-bottom-right-radius: 0.3rem;
}

/* 机器人消息：左侧玻璃气泡 */
.ai-msg.ai-bot {
  align-self: flex-start;
  background: var(--card-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  color: var(--text, #e2e8f0);
  border-bottom-left-radius: 0.3rem;
}

@keyframes ai-pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 「相关问题」快捷按钮（附在机器人气泡内） ---------- */
.ai-rel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.ai-rel-btn {
  padding: 0.22rem 0.7rem;
  border-radius: var(--radius-pill, 999px);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent, #22d3ee);
  background: var(--accent-soft, rgba(34, 211, 238, 0.12));
  border: 1px solid var(--accent-border, rgba(34, 211, 238, 0.35));
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.ai-rel-btn:hover,
.ai-rel-btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15);
}

/* ---------- 打字三点指示 ---------- */
.ai-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.2rem 0;
}

.ai-typing-dots i {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--accent, #22d3ee);
  opacity: 0.4;
  animation: ai-blink 1s ease-in-out infinite;
}

.ai-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-blink {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- 快捷问题胶囊区 ---------- */
.ai-chips {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 5.6rem;
  overflow-y: auto;
  padding: 0.55rem 0.9rem;
  border-top: 1px dashed var(--card-border, rgba(255, 255, 255, 0.10));
  scrollbar-width: thin;
}

.ai-chip {
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-pill, 999px);
  font-size: 0.78rem;
  color: var(--text-dim, #94a3b8);
  background: var(--card-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease,
    color 0.25s ease, border-color 0.25s ease;
}

.ai-chip:hover,
.ai-chip:focus-visible {
  transform: translateY(-2px);
  color: var(--accent, #22d3ee);
  border-color: var(--accent-border, rgba(34, 211, 238, 0.35));
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15);
}

/* ---------- 输入区：输入框 + 发送按钮 ---------- */
.ai-inputbar {
  flex: none;
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem 0.75rem;
  border-top: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
}

.ai-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-pill, 999px);
  font-size: 0.88rem;
  color: var(--text, #e2e8f0);
  background: var(--card-bg, rgba(255, 255, 255, 0.07));
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.ai-input::placeholder {
  color: var(--text-faint, #64748b);
}

.ai-input:focus {
  border-color: var(--accent-border, rgba(34, 211, 238, 0.35));
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15);
}

.ai-send {
  flex: none;
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius-pill, 999px);
  font-size: 0.88rem;
  font-weight: 600;
  color: #f0fdff;
  background: var(--grad, linear-gradient(135deg, #22d3ee, #3b82f6));
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(34, 211, 238, 0.25);
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
}

.ai-send:hover,
.ai-send:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.15),
    0 10px 26px rgba(34, 211, 238, 0.35);
}

.ai-send:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

/* ----------------------------------------------------------
   三、移动端适配（不遮挡正文内容）
   ---------------------------------------------------------- */
@media (max-width: 768px) {
  .ai-fab {
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    width: 3.2rem;
    height: 3.2rem;
  }

  .ai-fab-icon { font-size: 1.05rem; }
  .ai-fab-text { font-size: 0.56rem; }

  .ai-panel {
    right: 1rem;
    bottom: calc(1rem + 3.2rem + 0.7rem + env(safe-area-inset-bottom, 0px));
    max-height: min(70vh, calc(100vh - 6.5rem));
  }
}

/* ----------------------------------------------------------
   四、尊重系统「减少动态效果」设置
   ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ai-fab,
  .ai-panel,
  .ai-msg,
  .ai-chip,
  .ai-rel-btn,
  .ai-close,
  .ai-send {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .ai-typing-dots i { animation: none; opacity: 0.7; }
}
