/* ============================================================
   AI 助手 · 通用弹窗样式
   悬浮球（气泡形态）+ 弹窗，电脑/手机通用
   ============================================================ */

:root {
  --ai-primary: #4a6cf7;
  --ai-primary-dark: #3b5de7;
  --ai-primary-light: #eef2ff;
  --ai-bg: #ffffff;
  --ai-bg-soft: #f9fafc;
  --ai-text: #0b1b3a;
  --ai-text-sub: #6b7280;
  --ai-border: #edf0f5;
  --ai-shadow-lg: 0 24px 60px -12px rgba(11, 27, 58, 0.18);
  --ai-radius-lg: 20px;
  --ai-z: 999999;
}

* {
  box-sizing: border-box;
}

/* ============================================================
   悬浮球入口（气泡形态 + 机器人图标 + AI 文字）
   ============================================================ */
.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 50%;
  width: 88px;
  height: 60px;
  /* 左下角尖角，做成对话气泡 */
  border-radius: 20px 20px 20px 6px;
  background: linear-gradient(145deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    0 10px 25px -5px rgba(139, 92, 246, 0.5),
    0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  z-index: var(--ai-z);
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  padding: 0 14px;
  animation: aiFabPulse 2.4s ease-in-out infinite;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* 气泡小尾巴 */
.ai-fab::after {
  content: '';
  position: absolute;
  left: 6px;
  bottom: -6px;
  width: 16px;
  height: 16px;
  background: #a855f7;
  border-radius: 0 0 0 4px;
  transform: rotate(45deg);
  z-index: -1;
}

/* 内部：图标 + AI 文字 */
.ai-fab-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.ai-fab-inner i {
  font-size: 20px;
  animation: aiFabWiggle 3.5s ease-in-out infinite;
}

.ai-fab-inner .ai-fab-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

/* 图标轻微摆动，让悬浮球"活"起来 */
@keyframes aiFabWiggle {
  0%, 100% { transform: rotate(0deg); }
  10% { transform: rotate(-9deg); }
  20% { transform: rotate(9deg); }
  30% { transform: rotate(-5deg); }
  40% { transform: rotate(5deg); }
  50%, 90% { transform: rotate(0deg); }
}

/* 呼吸光圈 */
@keyframes aiFabPulse {
  0%, 100% {
    box-shadow:
      0 10px 25px -5px rgba(139, 92, 246, 0.5),
      0 0 0 0 rgba(139, 92, 246, 0.5),
      0 4px 12px rgba(0, 0, 0, 0.08);
  }
  50% {
    box-shadow:
      0 10px 25px -5px rgba(139, 92, 246, 0.6),
      0 0 0 14px rgba(139, 92, 246, 0),
      0 4px 12px rgba(0, 0, 0, 0.08);
  }
}

.ai-fab:hover {
  transform: translateY(-3px) scale(1.05);
  animation: none;
  box-shadow:
    0 18px 35px -8px rgba(139, 92, 246, 0.65),
    0 4px 12px rgba(0, 0, 0, 0.08);
}

.ai-fab:hover .ai-fab-inner i {
  animation: none;
}

.ai-fab:active {
  transform: scale(0.95);
}

/* 小红点（有新消息提示） */
.ai-fab .ai-fab-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 13px;
  height: 13px;
  background: #ff4d4f;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  box-shadow: 0 2px 6px rgba(255, 77, 79, 0.5);
  z-index: 2;
}

.ai-fab.has-dot .ai-fab-dot {
  display: block;
}

/* 打开状态：变圆角矩形关闭按钮 */
.ai-fab.open {
  animation: none;
  background: linear-gradient(145deg, #8b5cf6, #a855f7);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  padding: 0;
}

.ai-fab.open::after {
  display: none;
}

.ai-fab.open .ai-fab-inner i {
  font-size: 22px;
  animation: none;
}

/* 手机端稍微缩小 */
@media (max-width: 640px) {
  .ai-fab {
    right: 16px;
    bottom: 72px;
    width: 80px;
    height: 54px;
    border-radius: 18px 18px 18px 5px;
    padding: 0 12px;
  }
  .ai-fab-inner i {
    font-size: 18px;
  }
  .ai-fab-inner .ai-fab-text {
    font-size: 16px;
  }
}

/* ============================================================
   弹窗容器
   ============================================================ */
.ai-modal {
  position: fixed;
  inset: 0;
  z-index: var(--ai-z);
  display: none;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.ai-modal.open {
  display: block;
  pointer-events: auto;
  opacity: 1;
}

/* 聊天卡片 */
.ai-card {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--ai-bg);
  overflow: hidden;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: 420px;
  height: 640px;
  max-height: calc(100vh - 60px);
  border-radius: var(--ai-radius-lg);
  box-shadow: var(--ai-shadow-lg);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

.ai-modal.open .ai-card {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

/* ============================================================
   头部
   ============================================================ */
.ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--ai-border);
  background: #fff;
  flex-shrink: 0;
}

.ai-avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(145deg, #6366f1, #a855f7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 6px 12px -6px rgba(139, 92, 246, 0.5);
}

.ai-title-wrap {
  flex: 1;
  min-width: 0;
}

.ai-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ai-text);
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-sub {
  font-size: 12px;
  color: var(--ai-text-sub);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15);
}

.ai-status-dot.offline {
  background: #9ca3af;
  box-shadow: 0 0 0 2px rgba(156, 163, 175, 0.15);
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ai-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ai-icon-btn:hover {
  background: #f1f5f9;
  color: var(--ai-primary);
}

.ai-icon-btn:active {
  transform: scale(0.92);
}

/* ============================================================
   消息区域
   ============================================================ */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--ai-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: aiFadeIn 0.28s ease;
}

.ai-msg.user {
  flex-direction: row-reverse;
}

.ai-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: #eef2f7;
  color: var(--ai-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.ai-msg.user .ai-msg-avatar {
  background: var(--ai-primary);
  color: #fff;
}

.ai-msg-bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  background: #fff;
  color: #1e293b;
  border: 1px solid var(--ai-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.ai-msg.user .ai-msg-bubble {
  background: var(--ai-primary);
  border-color: var(--ai-primary);
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(74, 108, 247, 0.5);
}

.ai-msg-bubble.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.ai-msg-time {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 4px;
  padding: 0 4px;
  opacity: 0.7;
}

.ai-msg.user .ai-msg-time {
  text-align: right;
}

/* 打字动画 */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
  font-size: 13px;
  padding: 6px 2px;
}

.ai-typing .dots {
  display: flex;
  gap: 4px;
}

.ai-typing .dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cbd5e1;
  animation: aiPulse 1.4s infinite both;
}

.ai-typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

@keyframes aiFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 快捷问题 */
.ai-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.ai-quick button {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.ai-quick button:hover {
  border-color: var(--ai-primary);
  color: var(--ai-primary);
  background: var(--ai-primary-light);
}

/* ============================================================
   输入区
   ============================================================ */
.ai-input-area {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--ai-border);
  flex-shrink: 0;
}

.ai-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #f2f5fa;
  border: 1px solid #e4e9f2;
  border-radius: 22px;
  padding: 4px 4px 4px 16px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.ai-input-box:focus-within {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
  background: #fff;
}

.ai-input-box textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ai-text);
  padding: 9px 0;
  max-height: 100px;
  min-height: 22px;
  overflow-y: auto;
}

.ai-input-box textarea::placeholder {
  color: #94a3b8;
}

.ai-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--ai-primary);
  color: #fff;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.ai-send-btn:hover {
  background: var(--ai-primary-dark);
}

.ai-send-btn:active {
  transform: scale(0.9);
}

.ai-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.ai-footer-tip {
  text-align: center;
  font-size: 11px;
  color: #b0bccd;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

/* 滚动条 */
.ai-messages::-webkit-scrollbar {
  width: 5px;
}
.ai-messages::-webkit-scrollbar-track {
  background: transparent;
}
.ai-messages::-webkit-scrollbar-thumb {
  background: #d6dde8;
  border-radius: 10px;
}
.ai-messages::-webkit-scrollbar-thumb:hover {
  background: #b8c2d1;
}

/* ============================================================
   响应式：手机端全屏
   ============================================================ */
@media (max-width: 640px) {
  .ai-card {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  .ai-modal.open .ai-card {
    transform: none;
  }

  .ai-messages {
    padding: 14px 12px;
  }

  .ai-msg-bubble {
    max-width: 82%;
    font-size: 14px;
  }

  .ai-header {
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .ai-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 640px) and (orientation: landscape) {
  .ai-card {
    height: 100%;
  }
  .ai-header {
    padding: 8px 14px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .ai-messages {
    padding: 10px 12px;
  }
}