/* BaiqueAI 聊天 Widget 样式 */
/* 现代渐变风格 · 响应式 · 移动端优先 */

:root {
  --bq-primary: #667eea;
  --bq-primary-end: #764ba2;
  --bq-bg: rgba(255,255,255,0.98);
  --bq-radius: 16px;
  --bq-shadow: 0 8px 40px rgba(0,0,0,0.15);
  --bq-user-bg: #f0f2f5;
  --bq-user-color: #1a1a1a;
  --bq-font: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --bq-chat-width: 494px;
  --bq-chat-height: 702px;
  --bq-fab-size: 56px;
  --bq-fab-bottom: 60px;
  --bq-fab-right: 24px;
}

/* FAB 悬浮按钮 */
#baiqueai-fab {
  position: fixed;
  bottom: var(--bq-fab-bottom);
  right: var(--bq-fab-right);
  width: var(--bq-fab-size);
  height: var(--bq-fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bq-primary) 0%, var(--bq-primary-end) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(102,126,234,0.45);
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .25s ease, box-shadow .25s ease;
  font-size: 26px;
  outline: none;
  overflow: hidden;
  padding: 0;
}
/* FAB 头像模式 */
#baiqueai-fab img {
  pointer-events: none;
}
#baiqueai-fab:hover { transform: scale(1.1); box-shadow: 0 6px 28px rgba(102,126,234,0.6); }
#baiqueai-fab:active { transform: scale(0.96); }

/* 消息角标 */
#baiqueai-fab .bq-badge {
  position: absolute;
  top: -3px; right: -3px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  display: none;
}

/* ─────────────── 悬浮提示气泡 ─────────────── */
#baiqueai-tooltip-wrap {
  position: fixed;
  bottom: calc(var(--bq-fab-bottom) + var(--bq-fab-size) + 16px);
  right: var(--bq-fab-right);
  z-index: 99997;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#baiqueai-root[data-position="bottom-left"] #baiqueai-tooltip-wrap {
  right: auto;
  left: var(--bq-fab-right);
  align-items: flex-start;
}

.bq-tooltip-bubble {
  position: relative;
  background: linear-gradient(135deg, var(--bq-primary) 0%, var(--bq-primary-end) 100%);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-family: var(--bq-font);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(102,126,234,0.35);
  animation: bqTooltipBounce 2s infinite;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bq-tooltip-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 24px;
  border-width: 7px 7px 0 0;
  border-style: solid;
  border-color: var(--bq-primary-end) transparent transparent transparent;
}

#baiqueai-root[data-position="bottom-left"] .bq-tooltip-bubble::after {
  right: auto;
  left: 24px;
  border-width: 7px 0 0 7px;
  border-color: var(--bq-primary-end) transparent transparent transparent;
}

/* 脉冲环 */
.bq-tooltip-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200%;
  height: 200%;
  border-radius: 50%;
  border: 2px solid var(--bq-primary);
  opacity: 0;
  animation: bqTooltipPulseRing 2s infinite;
  pointer-events: none;
}

@keyframes bqTooltipBounce {
  0%, 100% { transform: translateY(0); }
  15% { transform: translateY(-6px); }
  30% { transform: translateY(0); }
  45% { transform: translateY(-3px); }
  60% { transform: translateY(0); }
  80% { transform: translateY(-1px); }
}

@keyframes bqTooltipPulseRing {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0.8; }
  100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

#baiqueai-tooltip-wrap.bq-tooltip-hidden {
  display: none;
}

/* ─────────────── 聊天窗口容器 ─────────────── */
#baiqueai-widget {
  position: fixed;
  bottom: calc(var(--bq-fab-bottom) + var(--bq-fab-size) + 12px);
  right: var(--bq-fab-right);
  width: var(--bq-chat-width);
  height: var(--bq-chat-height);
  border-radius: var(--bq-radius);
  background: var(--bq-bg);
  box-shadow: var(--bq-shadow);
  display: flex;
  flex-direction: column;
  z-index: 99999;
  font-family: var(--bq-font);
  font-size: 14px;
  overflow: hidden;
  transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .3s ease;
  transform-origin: bottom right;
}

#baiqueai-widget.bq-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9) translateY(10px);
}

/* 左下角 */
#baiqueai-root[data-position="bottom-left"] #baiqueai-fab,
#baiqueai-root[data-position="bottom-left"] #baiqueai-widget {
  right: auto;
  left: var(--bq-fab-right);
}
#baiqueai-root[data-position="bottom-left"] #baiqueai-widget {
  transform-origin: bottom left;
}

/* ─────────────── 窗口头部 ─────────────── */
#baiqueai-header {
  background: linear-gradient(135deg, var(--bq-primary) 0%, var(--bq-primary-end) 100%);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#baiqueai-header .bq-title {
  font-size: 15px;
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
#baiqueai-header .bq-title img {
  width: 24px; height: 24px; border-radius: 50%; object-fit: cover;
}
#baiqueai-header .bq-header-actions {
  display: flex; gap: 8px;
}
#baiqueai-header button {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  border-radius: 8px;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
#baiqueai-header button:hover { background: rgba(255,255,255,.35); }

/* ─────────────── 消息列表 ─────────────── */
#baiqueai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
#baiqueai-messages::-webkit-scrollbar { width: 4px; }
#baiqueai-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* 消息气泡 */
.bq-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: bqFadeIn .25s ease;
}
@keyframes bqFadeIn {
  from { opacity:0; transform: translateY(8px); }
  to   { opacity:1; transform: translateY(0); }
}

.bq-msg-ai  { justify-content: flex-start; }
.bq-msg-user{ justify-content: flex-end; }

.bq-msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bq-primary), var(--bq-primary-end));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}
.bq-msg-avatar-img {
  background: none;
}

.bq-bubble {
  max-width: 78%;
  border-radius: 18px;
  padding: 10px 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.bq-msg-ai  .bq-bubble {
  background: linear-gradient(135deg, var(--bq-primary) 0%, var(--bq-primary-end) 100%);
  color: #fff;
  border-bottom-left-radius: 4px;
}
.bq-msg-user .bq-bubble {
  background: var(--bq-user-bg);
  color: var(--bq-user-color);
  border-bottom-right-radius: 4px;
}

/* 打字动画 */
.bq-typing-indicator {
  display: flex; gap: 4px; align-items: center;
  padding: 6px 4px;
}
.bq-typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,.8);
  animation: bqTyping 1.2s infinite ease-in-out;
}
.bq-typing-indicator span:nth-child(2) { animation-delay: .2s; }
.bq-typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes bqTyping {
  0%,80%,100% { transform: scale(0.8); opacity:.5; }
  40%          { transform: scale(1);   opacity:1; }
}

/* ─────────────── 快捷操作按钮 ─────────────── */
#baiqueai-quick-actions {
  padding: 4px 16px 0;
  flex-shrink: 0;
}
.bq-quick-btn {
  display: inline-block;
  background: #f0f2f5;
  color: #555;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid #e5e7eb;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--bq-font);
}
.bq-quick-btn:hover {
  background: var(--bq-primary);
  color: #fff;
  border-color: var(--bq-primary);
}

/* ─────────────── 输入区域 ─────────────── */
#baiqueai-input-area {
  padding: 12px 16px 14px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
#baiqueai-input {
  flex: 1;
  border: 2px solid transparent;
  background: #f0f2f5;
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--bq-font);
  resize: none;
  max-height: 120px;
  min-height: 42px;
  outline: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
  line-height: 1.5;
}
#baiqueai-input:focus {
  border-color: var(--bq-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(102,126,234,.12);
}
#baiqueai-send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bq-primary), var(--bq-primary-end));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  flex-shrink: 0;
}
#baiqueai-send-btn:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(102,126,234,.4); }
#baiqueai-send-btn:active { transform: scale(0.94); }
#baiqueai-send-btn:disabled { opacity: .5; cursor: default; }

/* ─────────────── 底部说明 ─────────────── */
#baiqueai-footer {
  text-align: center;
  font-size: 11px;
  color: #9ca3af;
  padding: 4px 0 8px;
  flex-shrink: 0;
}
#baiqueai-footer a { color: #9ca3af; text-decoration: none; }

/* ─────────────── 文章卡片 ─────────────── */
.bq-bubble-ai-rich {
  white-space: normal !important;
}
.bq-card {
  display: block;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  margin: 8px 0 4px;
  overflow: hidden;
  text-decoration: none;
  color: #fff;
  transition: background .2s, transform .15s;
  cursor: pointer;
}
.bq-card:hover {
  background: rgba(255,255,255,0.22);
  transform: translateY(-1px);
}
.bq-card + .bq-card {
  margin-top: 6px;
}
.bq-card-body {
  padding: 10px 12px;
}
.bq-card-type {
  display: inline-block;
  font-size: 11px;
  opacity: 0.75;
  margin-bottom: 4px;
}
.bq-card-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  line-height: 1.4;
}
.bq-card-excerpt {
  font-size: 12px;
  opacity: 0.85;
  margin: 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─────────────── 响应式 ─────────────── */
@media (max-width: 479px) {
  #baiqueai-widget {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
  }
  #baiqueai-fab {
    width: 60px; height: 60px;
    bottom: 20px; right: 20px;
    font-size: 28px;
  }
  #baiqueai-input { font-size: 16px; /* 防 iOS 缩放 */ }
}
@media (min-width: 480px) and (max-width: 767px) {
  :root { --bq-chat-width: 340px; --bq-chat-height: 500px; }
}
@media (prefers-reduced-motion: reduce) {
  .bq-msg, #baiqueai-widget, #baiqueai-fab { animation: none !important; transition: none !important; }
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #baiqueai-fab { bottom: calc(var(--bq-fab-bottom) + env(safe-area-inset-bottom)); }
  #baiqueai-widget { bottom: calc(var(--bq-fab-bottom) + var(--bq-fab-size) + 12px + env(safe-area-inset-bottom)); }
}
