/* AI 助手 · 悬浮按钮与对话窗 */
#aiFab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 40;
  box-shadow: 0 6px 20px rgba(37, 99, 235, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .18s ease, box-shadow .18s ease;
  -webkit-tap-highlight-color: transparent;
}
#aiFab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 10px 26px rgba(37, 99, 235, .45); }
#aiFab:active { transform: scale(.96); }
#aiFab .ai-dot {
  position: absolute; top: 4px; right: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #22c55e; border: 2px solid #fff;
}
#aiFab.hidden { display: none; }

/* 面板 */
#aiPanel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  width: 400px;
  height: min(620px, calc(100vh - 130px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, .22), 0 2px 8px rgba(15, 23, 42, .08);
  z-index: 45;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}
#aiPanel.open { display: flex; animation: aiIn .2s ease-out; }
@keyframes aiIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.ai-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  flex: 0 0 auto;
}
.ai-head .ai-title { font-size: 15px; font-weight: 600; flex: 1; }
.ai-head .ai-sub { font-size: 11px; opacity: .82; font-weight: 400; margin-left: 6px; }
.ai-head button {
  background: rgba(255, 255, 255, .16); border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.ai-head button:hover { background: rgba(255, 255, 255, .3); }

.ai-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
  -webkit-overflow-scrolling: touch;
}
.ai-msg { display: flex; margin-bottom: 12px; }
.ai-msg.me { justify-content: flex-end; }
.ai-bubble {
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.ai-msg.me .ai-bubble {
  background: #2563eb; color: #fff; border-color: #2563eb;
  border-bottom-right-radius: 4px;
}
.ai-msg.bot .ai-bubble { border-bottom-left-radius: 4px; }
.ai-bubble b { font-weight: 600; }

.ai-sys {
  text-align: center;
  font-size: 12px;
  color: #0f766e;
  background: #ecfdf5;
  border: 1px solid #d1fae5;
  border-radius: 8px;
  padding: 5px 10px;
  margin: 0 auto 10px;
  max-width: 92%;
  width: fit-content;
}
.ai-sys.err { color: #b91c1c; background: #fef2f2; border-color: #fee2e2; }

.ai-thinking { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.ai-thinking i {
  width: 6px; height: 6px; border-radius: 50%; background: #94a3b8;
  animation: aiBlink 1.2s infinite;
}
.ai-thinking i:nth-child(2) { animation-delay: .2s; }
.ai-thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes aiBlink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ai-chip {
  font-size: 12.5px; padding: 6px 11px; border-radius: 14px;
  background: #fff; border: 1px solid #cbd5e1; color: #334155;
  cursor: pointer; line-height: 1.3;
}
.ai-chip:hover { border-color: #2563eb; color: #2563eb; background: #eff6ff; }

.ai-foot {
  flex: 0 0 auto;
  border-top: 1px solid #e5e7eb;
  padding: 10px 12px;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 110px;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  background: #fff;
  color: #111827;
}
.ai-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.ai-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  border: none; border-radius: 10px;
  cursor: pointer; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.ai-btn.send { background: #2563eb; color: #fff; }
.ai-btn.send:hover { background: #1d4ed8; }
.ai-btn.send:disabled { background: #cbd5e1; cursor: not-allowed; }
.ai-btn.mic { background: #f1f5f9; color: #334155; }
.ai-btn.mic:hover { background: #e2e8f0; }
.ai-btn.mic.rec { background: #ef4444; color: #fff; animation: aiRec 1.2s infinite; }
@keyframes aiRec { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .5); } 50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); } }

/* 手机：全屏底部抽屉 */
@media (max-width: 640px) {
  #aiFab { right: 14px; bottom: 14px; width: 52px; height: 52px; font-size: 22px; }
  #aiPanel {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    height: 82vh;
    max-height: 82vh;
    border-radius: 16px 16px 0 0;
    border: none;
  }
  #aiPanel.open { animation: aiUp .24s ease-out; }
  @keyframes aiUp { from { transform: translateY(100%); } to { transform: none; } }
  .ai-head { padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
  .ai-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .ai-bubble { font-size: 15px; }
}

/* 给内容底部留出悬浮按钮的空间 */
@media (max-width: 640px) {
  body { padding-bottom: 78px; }
}
