/* ===== AI 悬浮助手 ===== */
#ai-widget, #ai-widget * { box-sizing: border-box; }

#ai-widget {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: #1f2937;
}

#ai-fab {
  position: relative;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #ec4899 100%);
  box-shadow: 0 10px 28px rgba(99, 102, 241, .38), 0 3px 8px rgba(15, 23, 42, .18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition: transform .18s ease, box-shadow .18s ease;
}
#ai-fab:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 34px rgba(99, 102, 241, .46); }
#ai-fab:active { transform: scale(.97); }
#ai-fab .ai-fab-spark { font-size: 20px; line-height: 1; }
#ai-fab .ai-fab-text { font-size: 9px; font-weight: 700; letter-spacing: .12em; opacity: .92; margin-top: 1px; }
#ai-fab.ai-thinking { animation: ai-pulse 1.25s ease-in-out infinite; }
@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 10px 28px rgba(99, 102, 241, .38), 0 0 0 0 rgba(99, 102, 241, .30); }
  50% { box-shadow: 0 10px 28px rgba(99, 102, 241, .38), 0 0 0 12px rgba(99, 102, 241, 0); }
}

#ai-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  width: 390px;
  max-width: calc(100vw - 28px);
  height: 620px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid #e6e9f2;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .20), 0 4px 14px rgba(15, 23, 42, .08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
}
#ai-widget.ai-open #ai-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
#ai-widget.ai-open #ai-fab { transform: scale(.92); }

.ai-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  color: #fff;
  background: linear-gradient(120deg, #4f46e5 0%, #6d5ce7 50%, #8b5cf6 100%);
}
.ai-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ai-orb {
  width: 34px; height: 34px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.18);
  font-size: 17px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}
.ai-title b { display: block; font-size: 14px; letter-spacing: .01em; }
.ai-title small { display: block; font-size: 11px; opacity: .78; margin-top: 1px; }
.ai-head-actions { display: flex; gap: 4px; }
.ai-head-actions button {
  width: 30px; height: 30px; border: 0; border-radius: 9px;
  background: rgba(255,255,255,.14); color: #fff; cursor: pointer;
  font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.ai-head-actions button:hover { background: rgba(255,255,255,.25); }

.ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 10px;
  background:
    radial-gradient(circle at 100% 0%, rgba(99, 102, 241, .055), transparent 38%),
    linear-gradient(180deg, #fbfcff 0%, #f7f8fc 100%);
  scrollbar-width: thin;
}
.ai-messages::-webkit-scrollbar { width: 6px; }
.ai-messages::-webkit-scrollbar-thumb { background: #d6dae8; border-radius: 6px; }

.ai-msg { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 12px; }
.ai-msg.ai-user { flex-direction: row-reverse; }
.ai-avatar {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(135deg, #eef0ff, #f7edff);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; margin-top: 2px;
  box-shadow: inset 0 0 0 1px rgba(99,102,241,.12);
}
.ai-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
  line-height: 1.62;
}
.ai-assistant .ai-bubble {
  background: #fff;
  border: 1px solid #e7eaf3;
  border-top-left-radius: 5px;
  color: #263041;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .035);
}
.ai-user .ai-bubble {
  background: linear-gradient(135deg, #5b54e8, #7c5ce8);
  color: #fff;
  border-top-right-radius: 5px;
  box-shadow: 0 4px 12px rgba(91, 84, 232, .22);
}

.ai-trace {
  margin: -4px 0 12px 36px;
  padding: 7px 10px;
  border-left: 2px solid #c7cbf9;
  background: rgba(99, 102, 241, .045);
  border-radius: 0 8px 8px 0;
  color: #7c85a3;
  font-size: 11.5px;
  line-height: 1.7;
}

.ai-typing { display: flex; align-items: center; gap: 4px; padding: 12px 14px; }
.ai-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #a5aec8;
  animation: ai-bounce 1.2s infinite ease-in-out;
}
.ai-typing i:nth-child(2) { animation-delay: .15s; }
.ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

.ai-confirm {
  margin: 0 0 14px 36px;
  background: #fff;
  border: 1px solid #dfe3f7;
  border-radius: 13px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, .08);
}
.ai-confirm-title { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: #6366f1; text-transform: uppercase; margin-bottom: 6px; }
.ai-confirm-body { font-size: 13px; color: #2d3748; line-height: 1.6; margin-bottom: 10px; word-break: break-word; white-space: pre-wrap; }
.ai-confirm-list { display: flex; flex-direction: column; gap: 4px; }
.ai-confirm-item { padding-left: 18px; position: relative; }
.ai-confirm-item::before { content: '•'; position: absolute; left: 4px; color: #6366f1; font-weight: 700; }
.ai-confirm-actions { display: flex; gap: 8px; }
.ai-btn {
  border: 1px solid #d9deee;
  background: #fff;
  color: #4b5563;
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  font-weight: 600;
}
.ai-btn:hover { background: #f5f6fb; }
.ai-btn-primary { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.ai-btn-primary:hover { background: #4338ca; }
.ai-btn:disabled { opacity: .55; cursor: default; }
.ai-confirm-status { margin-top: 8px; font-size: 11.5px; color: #8a94a6; }

.ai-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 6px;
  border-top: 1px solid #eef0f6;
  background: #fff;
}
#ai-input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 110px;
  resize: none;
  border: 1px solid #dfe3ee;
  border-radius: 11px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: #1f2937;
  background: #f9fafc;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
#ai-input:focus { border-color: #a5aaf5; background: #fff; box-shadow: 0 0 0 3px rgba(99, 102, 241, .10); }
#ai-input:disabled { background: #f1f2f7; color: #9aa3b5; }
#ai-send {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 15px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, #5b54e8, #7c5ce8);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(91, 84, 232, .25);
}
#ai-send:disabled { opacity: .55; cursor: default; box-shadow: none; }
#ai-send:hover:not(:disabled) { filter: brightness(1.05); }
.ai-foot {
  flex: 0 0 auto;
  padding: 0 12px 8px;
  text-align: center;
  font-size: 10.5px;
  color: #a3aab9;
  background: #fff;
}

@media (max-width: 560px) {
  #ai-widget { right: 14px; bottom: 14px; }
  #ai-fab { width: 54px; height: 54px; }
  #ai-panel {
    right: 10px;
    left: 10px;
    bottom: 80px;
    width: auto;
    height: calc(100vh - 104px);
    max-height: none;
    border-radius: 16px;
  }
  .ai-bubble { max-width: 86%; }
}
