/* ============================================================
   学生端浮动 AI 助教
   ============================================================ */
.ai-chat {
  position: fixed;
  right: 24px;
  bottom: 22px;
  z-index: 150;
  font-family: var(--font);
}
.ai-chat.hidden { display: none; }
.ai-chat-fab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 48px;
  padding: 0 17px 0 7px;
  border: 1px solid rgba(103, 232, 249, .25);
  border-radius: 30px;
  background: linear-gradient(135deg, #0b3a4a, #0b1220);
  color: #ecfeff;
  box-shadow: 0 14px 38px -12px rgba(8, 145, 178, .7), 0 0 0 1px rgba(34, 211, 238, .08) inset;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}
.ai-chat-fab:hover { transform: translateY(-2px); box-shadow: 0 18px 44px -12px rgba(8, 145, 178, .85); }
.ai-chat-fab.hidden { display: none; }
.ai-fab-orb {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #22d3ee, #6366f1);
  color: #041a20;
  box-shadow: 0 0 0 4px rgba(34, 211, 238, .12), 0 0 22px rgba(34, 211, 238, .4);
  animation: aiOrb 3.2s ease-in-out infinite;
}
@keyframes aiOrb { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.ai-fab-text { font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.ai-fab-dot { width: 7px; height: 7px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, .15); }

.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(382px, calc(100vw - 28px));
  height: min(620px, calc(100vh - 100px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 19px;
  box-shadow: 0 30px 80px -30px rgba(8, 15, 28, .55), 0 0 0 1px rgba(255,255,255,.02) inset;
  opacity: 0;
  transform: translateY(12px) scale(.97);
  pointer-events: none;
  transition: opacity .18s ease, transform .2s ease;
  overflow: hidden;
}
.ai-chat.open .ai-chat-panel { opacity: 1; transform: none; pointer-events: auto; }
.ai-chat-head {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 13px;
  background: linear-gradient(110deg, #0b1220, #0e2a3d 60%, #0b3a4a);
  color: #e2e8f0;
}
.ai-head-orb {
  width: 33px; height: 33px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(34,211,238,.22), rgba(99,102,241,.2));
  border: 1px solid rgba(103,232,249,.24);
  color: #67e8f9;
}
.ai-head-copy { flex: 1; min-width: 0; }
.ai-head-copy b { display: block; font-size: 13px; color: #f8fafc; }
.ai-head-copy small { display: block; font-size: 9.5px; color: #67e8f9; margin-top: 1px; }
.ai-head-copy small.local { color: #fcd34d; }
.ai-head-btn {
  width: 28px; height: 28px; border-radius: 7px; border: none;
  background: rgba(255,255,255,.06); color: #94a3b8;
  display: grid; place-items: center; cursor: pointer;
}
.ai-head-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.ai-context {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 13px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 10px; color: var(--faint);
  white-space: nowrap; overflow: hidden;
}
.ai-context > span { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.ai-context b { flex: 1; min-width: 0; color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 13px 13px 8px;
  background: radial-gradient(120% 60% at 100% 0%, rgba(6,182,212,.035), transparent 60%), var(--bg);
}
.ai-msg { display: flex; gap: 7px; margin-bottom: 11px; align-items: flex-start; }
.ai-msg-user { justify-content: flex-end; }
.ai-avatar {
  width: 24px; height: 24px; border-radius: 8px;
  display: grid; place-items: center; flex: none; margin-top: 2px;
  background: linear-gradient(145deg, rgba(34,211,238,.18), rgba(99,102,241,.15));
  color: var(--brand);
}
.ai-bubble {
  max-width: 86%;
  padding: 9px 11px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.75;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
}
.ai-msg-user .ai-bubble {
  background: linear-gradient(135deg, #0891b2, #0e7490);
  border-color: transparent;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-bubble { border-bottom-left-radius: 4px; }
.ai-mode {
  display: inline-flex; align-items: center;
  font-size: 8.5px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(245,158,11,.12); color: #b45309;
  margin-bottom: 4px;
}
.ai-notice { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 10px; color: var(--faint); }
.ai-bubble p { margin: 0 0 6px; font-size: 12px; line-height: 1.75; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble h2, .ai-bubble h3, .ai-bubble h4 { font-size: 12.5px; margin: 10px 0 5px; }
.ai-bubble ul, .ai-bubble ol { margin: 4px 0 7px; padding-left: 17px; }
.ai-bubble li { font-size: 12px; line-height: 1.7; margin: 2px 0; }
.ai-bubble code { font-family: var(--mono); font-size: 10.5px; background: var(--surface-3); color: #be185d; padding: 1px 4px; border-radius: 3px; }
.ai-bubble .code-block { margin: 7px 0; border-radius: 7px; }
.ai-bubble .code-head { padding: 5px 8px; }
.ai-bubble .code-block pre { padding: 8px 10px; }
.ai-bubble .code-block code { font-size: 10px; }
.ai-bubble a { color: var(--brand); font-weight: 600; }
.ai-bubble strong { color: var(--text); }
.ai-typing { display: flex; gap: 4px; padding: 12px 14px; }
.ai-typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--faint); animation: aiTyping 1.1s infinite; }
.ai-typing i:nth-child(2) { animation-delay: .16s; }
.ai-typing i:nth-child(3) { animation-delay: .32s; }
@keyframes aiTyping { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.ai-quick { display: flex; gap: 5px; padding: 5px 11px 3px; overflow-x: auto; background: var(--bg); }
.ai-quick::-webkit-scrollbar { height: 4px; }
.ai-quick { scrollbar-width: none; }
.ai-quick button {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 10px; padding: 5px 8px; border-radius: 20px; cursor: pointer;
}
.ai-quick button:hover { border-color: var(--brand-2); color: var(--brand); }
.ai-compose {
  display: flex; align-items: flex-end; gap: 7px;
  margin: 7px 11px 0; padding: 6px 6px 6px 11px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.ai-compose:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(6,182,212,.08); }
.ai-compose textarea {
  flex: 1; border: none; outline: none; resize: none; background: transparent;
  color: var(--text); font-family: inherit; font-size: 12px; line-height: 1.6;
  max-height: 110px; padding: 3px 0;
}
.ai-compose textarea::placeholder { color: var(--faint); }
.ai-send {
  width: 31px; height: 31px; border-radius: 9px; border: none; flex: none;
  background: linear-gradient(135deg, #0891b2, #0e7490); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.ai-send:disabled { opacity: .5; cursor: wait; }
.ai-foot {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 10px 9px; font-size: 9px; color: var(--faint);
}
@media (max-width: 600px) {
  .ai-chat { right: 12px; bottom: 12px; }
  .ai-chat-fab { height: 45px; padding-right: 13px; }
  .ai-fab-text { font-size: 12px; }
  .ai-chat-panel {
    position: fixed; left: 8px; right: 8px; bottom: 8px;
    width: auto; height: min(76vh, 620px); border-radius: 17px;
  }
}
[data-theme="dark"] .ai-bubble code { color: #f9a8d4; }
[data-theme="dark"] .ai-chat-panel { box-shadow: 0 30px 80px -20px rgba(0,0,0,.9); }
