/* ============================================================
   IntelliX AI — 嵌入式浮窗 v9
   白底 · 微光 · 精密 · 科技感细节
   ============================================================ */

/* ═══ 变量 ═══ */
:root {
  --ai-bg: #ffffff;
  --ai-bg-soft: #fafbfc;
  --ai-bg-card: #f8fafb;
  --ai-bubble-ai: #f7f8fa;
  --ai-bubble-user: #eef3ff;
  --ai-text: #1a1a1a;
  --ai-text-secondary: #5c5c66;
  --ai-text-muted: #8e8e96;
  --ai-border: rgba(0,0,0,0.06);
  --ai-border-strong: rgba(0,0,0,0.10);
  --ai-shadow: 0 1px 3px rgba(0,0,0,0.03), 0 8px 32px rgba(0,0,0,0.07);
  --ai-blue: #1a5feb;
  --ai-blue-light: #eef3ff;
  --ai-blue-glow: rgba(26,95,235,0.10);
  --ai-green: #16a34a;
  --ai-red: #ef4444;
  --ai-overlay: rgba(0,0,0,0.05);
  --ai-header-bg: #fafbfc;
  --ai-input-bg: #f7f8fa;
  --ai-chip-bg: rgba(0,0,0,0.03);
  --ai-chip-hover: rgba(0,0,0,0.06);
}

/* ═══ 导航按钮 ═══ */
.nav-ai-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: 8px;
  background: #0d0d0d; color: #fff;
  border: 1px solid rgba(255,255,255,0.10);
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer; text-decoration: none;
  transition: all 0.25s; white-space: nowrap;
  font-family: inherit; position: relative;
}
.nav-ai-btn:hover {
  background: #1a1a1a;
  border-color: rgba(255,255,255,0.18);
  box-shadow: 0 0 20px rgba(59,130,246,0.15);
  transform: translateY(-1px);
}
.nav-ai-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #22c55e; flex-shrink: 0;
  box-shadow: 0 0 6px rgba(34,197,94,0.5);
  animation: navAiDotPulse 2s ease-in-out infinite;
}
@keyframes navAiDotPulse { 0%,100%{opacity:1} 50%{opacity:0.45} }
.nav-ai-label { color: #d4d4d4; }
@media (max-width:600px) { .nav-ai-label{display:none} .nav-ai-btn{padding:8px 12px} }

/* ═══ 遮罩 ═══ */
.ai-overlay {
  position: fixed; inset: 0; z-index: 1999;
  background: rgba(0,0,0,0.04);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.ai-overlay.open { opacity: 1; visibility: visible; }

/* ═══ 浮窗 ═══ */
.ai-popover {
  position: fixed; z-index: 2000;
  width: 420px; max-height: 500px; min-height: 220px;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.50) inset,
    0 0 0 1px rgba(0,0,0,0.06),
    0 4px 32px rgba(0,0,0,0.08),
    0 1px 2px rgba(0,0,0,0.04);
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden;
  transform: translateY(-8px) scale(0.96);
  transition: opacity 0.22s cubic-bezier(0.16,1,0.3,1),
              box-shadow 0.5s;
  font-family: "PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
  overflow: hidden;
}

/* ── 顶部微光条 ── */
.ai-popover::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px; z-index: 10;
  background: linear-gradient(90deg, transparent, rgba(34,197,94,0.30), transparent);
  opacity: 0.35; pointer-events: none; border-radius: 16px 16px 0 0;
  transition: opacity 0.5s;
}

/* ── 边缘光晕（AI 思考时增强） ── */
.ai-popover.thinking {
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.50) inset,
    0 0 0 1px rgba(34,197,94,0.12),
    0 4px 32px rgba(0,0,0,0.08),
    0 0 40px rgba(34,197,94,0.08);
}
.ai-popover.thinking::before { opacity: 0.8; }

/* ── 背景微网格 ── */
.ai-popover::after {
  content: '';
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(26,95,235,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(26,95,235,0.012) 1px, transparent 1px);
  background-size: 20px 20px;
  border-radius: 16px;
  opacity: 0.5;
}

.ai-popover.open {
  opacity: 1; visibility: visible;
  transform: translateY(0) scale(1);
}

/* ═══ 标题栏 ═══ */
.ai-header {
  display: flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 16px; flex-shrink: 0; position: relative; z-index: 2;
  background: rgba(255,255,255,0.35);
  border-bottom: 1px solid rgba(0,0,0,0.04);
  border-radius: 16px 16px 0 0;
}
.ai-header-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: #d1d5db;
  transition: all 0.4s;
}
.ai-header-dot.thinking {
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34,197,94,0.5);
  animation: aiDotThink 1.5s ease-in-out infinite;
}
@keyframes aiDotThink { 0%,100%{opacity:1} 50%{opacity:0.35} }

.ai-header-title {
  flex: 1; font-family: "Inter","SF Pro Display",-apple-system,sans-serif;
  font-size: 13px; font-weight: 600; color: var(--ai-text);
  letter-spacing: -0.01em;
}
.ai-header-close {
  width: 26px; height: 26px; border-radius: 6px; border: none; flex-shrink: 0;
  background: transparent; color: var(--ai-text-muted);
  font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; line-height: 1;
}
.ai-header-close:hover {
  background: rgba(239,68,68,0.06); color: #ef4444;
  transform: rotate(90deg);
}

/* ═══ 消息区 ═══ */
.ai-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 14px 16px; position: relative; z-index: 2;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.06) transparent;
}
.ai-body::-webkit-scrollbar { width: 3px; }
.ai-body::-webkit-scrollbar-track { background: transparent; }
.ai-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.06); border-radius: 3px; }

/* ── 欢迎 ── */
.ai-welcome { margin-bottom: 2px; }
.ai-welcome-msg {
  font-size: 13px; color: var(--ai-text-secondary); line-height: 1.7;
}

/* ═══ 消息气泡 ═══ */
.ai-msg {
  margin-bottom: 8px; max-width: 86%;
  padding: 10px 14px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.65;
  word-break: break-word;
  animation: aiMsgIn 0.25s cubic-bezier(0.22,1,0.36,1);
  position: relative;
}
@keyframes aiMsgIn { from{opacity:0;transform:translateY(5px)} to{opacity:1;transform:translateY(0)} }

.ai-msg.user {
  margin-left: auto; text-align: right;
  background: rgba(26,95,235,0.08); color: var(--ai-blue);
  font-weight: 500; border-bottom-right-radius: 4px;
}

.ai-msg.assistant {
  margin-right: auto; text-align: left;
  background: rgba(0,0,0,0.03); color: var(--ai-text);
  border-bottom-left-radius: 4px;
  border-left: 2px solid rgba(26,95,235,0.15);
}

/* ── 数字发光 ── */
.ai-num {
  color: var(--ai-blue); font-weight: 600;
  font-family: "SF Mono","Menlo","Monaco","Courier New",monospace;
}
.ai-num.green { color: var(--ai-green); }

/* ── 流式光标 ── */
.ai-cursor {
  display: inline-block; width: 1.5px; height: 14px;
  background: var(--ai-blue); margin-left: 2px; vertical-align: text-bottom;
  border-radius: 1px;
  animation: aiBreathe 1.2s ease-in-out infinite;
}
@keyframes aiBreathe { 0%,100%{opacity:0.25} 50%{opacity:1} }

/* ═══ 数据卡片 ═══ */
.ai-data-card {
  margin: 6px 0 8px; padding: 14px 16px;
  background: rgba(255,255,255,0.50);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(26,95,235,0.10);
  border-radius: 12px;
  position: relative; overflow: hidden;
  animation: aiCardIn 0.28s cubic-bezier(0.22,1,0.36,1);
}
/* 卡片顶部微光 */
.ai-data-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(26,95,235,0.15), transparent);
}
@keyframes aiCardIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
.ai-data-card .ai-card-title {
  font-size: 10px; font-weight: 600; color: var(--ai-text-muted);
  margin-bottom: 10px; letter-spacing: 0.07em; text-transform: uppercase;
}
.ai-data-card .ai-card-row { display: flex; gap: 18px; flex-wrap: wrap; }
.ai-data-card .ai-card-metric { display: flex; flex-direction: column; min-width: 56px; }
.ai-data-card .ai-card-value {
  font-family: "SF Mono","Menlo","Monaco","Courier New",monospace;
  font-size: 20px; font-weight: 700; color: var(--ai-blue);
  letter-spacing: -0.03em; line-height: 1.1;
}
.ai-data-card .ai-card-value.green { color: var(--ai-green); }
.ai-data-card .ai-card-label {
  font-size: 9px; color: var(--ai-text-muted);
  text-transform: uppercase; letter-spacing: 0.07em; margin-top: 2px;
}

/* ═══ 建议区 ═══ */
.ai-suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 16px 10px; flex-shrink: 0; position: relative; z-index: 2;
}
.ai-suggestions:empty { display: none; }
.ai-chip {
  padding: 6px 13px; border-radius: 7px;
  border: 1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.50);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--ai-text-secondary);
  font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all 0.18s; white-space: nowrap;
}
.ai-chip:hover {
  background: var(--ai-chip-hover); color: var(--ai-text);
  border-color: rgba(0,0,0,0.12);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.ai-chip:active { transform: scale(0.97); }

/* ═══ 输入区 ═══ */
.ai-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; flex-shrink: 0; position: relative; z-index: 2;
  background: rgba(255,255,255,0.30);
  border-top: 1px solid rgba(0,0,0,0.04);
}
.ai-input {
  flex: 1; background: rgba(255,255,255,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px; padding: 10px 14px;
  font-family: inherit; font-size: 14px; color: var(--ai-text);
  outline: none; transition: all 0.25s;
}
.ai-input::placeholder { color: #b0b0b8; font-size: 13px; }
.ai-input:focus {
  background: rgba(255,255,255,0.85);
  border-color: var(--ai-blue);
  box-shadow: 0 0 0 4px rgba(26,95,235,0.06);
}

/* ── 发送按钮 ── */
.ai-send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--ai-blue); color: #fff;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
.ai-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 20px rgba(26,95,235,0.30);
}
.ai-send-btn:active { transform: scale(0.93); }
.ai-send-btn.stop {
  background: #ef4444;
}
.ai-send-btn.stop:hover {
  box-shadow: 0 0 20px rgba(239,68,68,0.30);
}

/* ═══ 错误 ═══ */
.ai-error { color: var(--ai-red); font-style: italic; }

/* ═══ 响应式 ═══ */
@media (max-width:640px) {
  .ai-popover {
    width: 100%; max-height: 60vh; border-radius: 16px 16px 0 0;
    bottom: 0 !important; left: 0 !important; right: 0 !important; top: auto !important;
    transform: translateY(100%);
  }
  .ai-popover.open { transform: translateY(0); }
  .ai-header { border-radius: 16px 16px 0 0; }
}
@media (max-width:380px) {
  .ai-popover { width: 100%; max-height: 72vh; }
}
