/* AI 助手悬浮窗：右下角常驻头像 + 招手动画 + 问候气泡；点击后在右下角弹出内嵌聊天面板（非全屏）。 */

.ai-fab {
  position: fixed;
  right: 10%;
  bottom: 20%;
  z-index: 350;
  width: 76px;
  height: 76px;
  user-select: none;
  /* 无边框窗口顶部是原生 app-region:drag 拖动区，会抢占鼠标。标记 no-drag，
     让悬浮助手拖到顶部时仍能正常被拖动、点击，而不是被“边边”当成拖窗口而卡住。 */
  -webkit-app-region: no-drag;
  app-region: no-drag;
}
.ai-fab[hidden] { display: none; }

/* 拖拽结束吸附到边缘时的平滑过渡；拖拽进行中不加该类，保证头像跟手不延迟 */
.ai-fab.snapping {
  transition: left .24s cubic-bezier(.22, .61, .36, 1), top .24s cubic-bezier(.22, .61, .36, 1);
}

/* 气泡绝对定位在头像四周，朝向随象限切换（见 .bubble-below / .bubble-start） */
.ai-fab-bubble {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  max-width: 200px;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, #6a5cff, #8a7bff);
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
  box-shadow: 0 10px 26px rgba(106, 92, 255, .34);
  opacity: 0;
  transform: translateY(6px) scale(.94);
  transform-origin: bottom right;
  transition: opacity .28s ease, transform .28s ease;
  pointer-events: none;
}
.ai-fab-bubble::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: #7468ff;
  border-radius: 0 0 3px 0;
  transform: rotate(45deg);
}
.ai-fab.show-bubble .ai-fab-bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.ai-fab.bubble-start .ai-fab-bubble {
  right: auto;
  left: 0;
  border-radius: 14px 14px 14px 4px;
  transform-origin: bottom left;
}
.ai-fab.bubble-start .ai-fab-bubble::after { right: auto; left: 16px; }
.ai-fab.bubble-below .ai-fab-bubble {
  bottom: auto;
  top: calc(100% + 12px);
  transform-origin: top right;
}
.ai-fab.bubble-below.bubble-start .ai-fab-bubble { transform-origin: top left; }
.ai-fab.bubble-below .ai-fab-bubble::after { bottom: auto; top: -5px; }

.ai-fab-btn {
  position: relative;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  background: radial-gradient(120% 120% at 30% 22%, #8073ff 0%, #5a47e6 58%, #4a39c8 100%);
  box-shadow: 0 12px 28px rgba(74, 57, 200, .42), inset 0 1px 0 rgba(255, 255, 255, .28);
  display: grid;
  place-items: center;
  transition: transform .2s ease, box-shadow .2s ease;
  animation: ai-fab-float 3.6s ease-in-out infinite;
}
.ai-fab-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 18px 36px rgba(74, 57, 200, .5);
}
.ai-fab-btn:active { transform: scale(.96); }
.ai-fab.dragging .ai-fab-btn {
  cursor: grabbing;
  animation: none;
  transform: scale(1.06);
  box-shadow: 0 20px 40px rgba(74, 57, 200, .55);
}

.ai-fab-avatar {
  font-size: 38px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .2));
}

.ai-fab-wave {
  position: absolute;
  right: -2px;
  bottom: -2px;
  font-size: 28px;
  transform-origin: 72% 80%;
  animation: ai-wave 2.6s ease-in-out infinite;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .25));
}

.ai-fab-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ff5470;
  border: 2px solid #fff;
}

@keyframes ai-wave {
  0%, 58%, 100% { transform: rotate(0deg); }
  10% { transform: rotate(16deg); }
  20% { transform: rotate(-12deg); }
  30% { transform: rotate(16deg); }
  42% { transform: rotate(-9deg); }
  50% { transform: rotate(13deg); }
}
@keyframes ai-fab-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* 内嵌聊天面板：浮在右下角，不铺满全屏 */
.ai-panel {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 600;
  width: min(520px, calc(100vw - 32px));
  height: min(660px, calc(100vh - 96px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(120, 110, 220, .18);
  box-shadow: 0 24px 60px rgba(20, 20, 60, .28), 0 4px 14px rgba(0, 0, 0, .12);
  opacity: 0;
  transform: translateY(16px) scale(.96);
  transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s ease;
}
.ai-panel.open { opacity: 1; transform: translateY(0) scale(1); }
.ai-panel[hidden] { display: none; }

.ai-panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  background: linear-gradient(135deg, #6a5cff, #5a47e6);
  color: #fff;
}
.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.ai-panel-dot {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: rgba(255, 255, 255, .18);
}
.ai-panel-title strong { display: block; font-size: 14px; font-weight: 700; }
.ai-panel-title small {
  display: block;
  font-size: 11px;
  opacity: .82;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-panel-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.ai-panel-tools button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .15s ease;
}
.ai-panel-tools button:hover { background: rgba(255, 255, 255, .3); }
.ai-panel-close { font-size: 20px; }

.ai-panel-body {
  position: relative;
  flex: 1 1 auto;
  background: #f3f4fa;
}
.ai-panel-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

.ai-panel-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #6a5cff;
  font-size: 13px;
  font-weight: 600;
  background: #f3f4fa;
  transition: opacity .3s ease;
}
.ai-panel-loading.hide { opacity: 0; pointer-events: none; }
.ai-panel-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(106, 92, 255, .2);
  border-top-color: #6a5cff;
  animation: ai-spin .8s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-panel-foot {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-size: 11px;
  color: #8a8aa3;
  text-align: center;
  background: #fff;
  border-top: 1px solid rgba(0, 0, 0, .05);
}
.ai-panel-foot .ai-panel-ext-inline {
  color: #6a5cff;
  font-weight: 600;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}

@media (max-width: 520px) {
  .ai-fab { right: 16px; bottom: 16px; }
  .ai-panel {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
    height: min(70vh, 560px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-fab-btn,
  .ai-fab-wave { animation: none; }
}
