/* ============================================================
   AI 助手样式（ai_assistant.css）
   - 右下角可拖动悬浮图标 + 75vw 对话面板
   - 全站功能图标/栏目/按钮悬停微交互
   - 尊重 prefers-reduced-motion
   ============================================================ */

:root {
  --ai-accent: #6366f1;
  --ai-accent-2: #8b5cf6;
  --ai-accent-soft: rgba(99, 102, 241, 0.12);
  --ai-radius: 14px;
  --ai-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  --ai-shadow-hover: 0 14px 40px rgba(15, 23, 42, 0.28);
}

/* ---------- 悬浮图标 ---------- */
.ai-fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  z-index: 9998;
  background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-2));
  box-shadow: var(--ai-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  user-select: none;
  touch-action: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.ai-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: var(--ai-shadow-hover); }
.ai-fab:active { cursor: grabbing; transform: scale(0.96); }
.ai-fab .ai-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 12px;
  height: 12px;
  border-radius: 6px;
  background: #22c55e;
  border: 2px solid #fff;
}
.ai-fab.status-connecting .ai-fab-badge { background: #f59e0b; }
.ai-fab.status-offline .ai-fab-badge { background: #ef4444; }
.ai-fab .ai-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
.ai-fab.has-unread .ai-unread { display: flex; }

/* ---------- 面板 ---------- */
.ai-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 9996;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.ai-panel-backdrop.open { opacity: 1; pointer-events: auto; }

.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(75vw, 1100px);
  min-width: 360px;
  background: #fff;
  z-index: 9997;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 40px rgba(15, 23, 42, 0.25);
}
.ai-panel.open { transform: translateX(0); }

.ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #eef0f3;
  background: linear-gradient(135deg, var(--ai-accent-soft), #fff);
}
.ai-header h3 { margin: 0; font-size: 15px; font-weight: 700; color: #0f172a; }
.ai-header .ai-status-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 10px;
  background: #e2e8f0;
  color: #475569;
  font-weight: 600;
}
.ai-header .ai-status-pill.ok { background: #dcfce7; color: #166534; }
.ai-header .ai-status-pill.err { background: #fee2e2; color: #991b1b; }
.ai-header select { font-size: 12px; padding: 4px 6px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
.ai-header .spacer { flex: 1; }
.ai-header button { border: none; background: #f1f5f9; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; color: #475569; }
.ai-header button:hover { background: #e2e8f0; }

.ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: #fafbfc; }
.ai-msg { max-width: 86%; padding: 10px 14px; border-radius: 12px; line-height: 1.55; font-size: 13.5px; word-break: break-word; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--ai-accent); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.assistant { align-self: flex-start; background: #fff; color: #0f172a; border: 1px solid #eef0f3; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.ai-msg.system { align-self: center; background: #f1f5f9; color: #64748b; font-size: 12px; padding: 6px 12px; }
.ai-msg.error { align-self: center; background: #fef2f2; color: #b91c1c; font-size: 12px; border: 1px solid #fecaca; }
.ai-msg a { color: inherit; text-decoration: underline; }
.ai-msg code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.ai-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 16px; }
.ai-typing span { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: ai-bounce 1.2s infinite; }
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* 工具调用卡片 */
.ai-tool-card { align-self: flex-start; width: 100%; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 8px 12px; font-size: 12px; color: #475569; }
.ai-tool-card .t-name { font-weight: 700; color: var(--ai-accent); }
.ai-tool-card .t-args { color: #64748b; margin-top: 2px; word-break: break-all; }
.ai-tool-card.ok { border-color: #86efac; background: #f0fdf4; }
.ai-tool-card.err { border-color: #fca5a5; background: #fef2f2; }

/* 写操作确认卡片 */
.ai-confirm { align-self: stretch; background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 12px 14px; }
.ai-confirm h4 { margin: 0 0 6px; font-size: 13px; color: #92400e; }
.ai-confirm pre { margin: 6px 0; background: #fff; padding: 8px; border-radius: 6px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.ai-confirm .row { display: flex; gap: 8px; margin-top: 8px; }
.ai-confirm button { flex: 1; padding: 8px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; }
.ai-confirm .btn-ok { background: #16a34a; color: #fff; }
.ai-confirm .btn-cancel { background: #e2e8f0; color: #475569; }

/* 创作结果卡片 */
.ai-create-card { align-self: flex-start; width: 100%; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; }
.ai-create-card img { width: 100%; display: block; max-height: 360px; object-fit: contain; background: #f1f5f9; }
.ai-create-card .meta { padding: 8px 12px; font-size: 12px; color: #64748b; }
.ai-create-card .acts { display: flex; gap: 6px; padding: 0 12px 12px; flex-wrap: wrap; }
.ai-create-card .acts button { padding: 6px 10px; border: 1px solid #e2e8f0; background: #fff; border-radius: 7px; cursor: pointer; font-size: 12px; color: #334155; }
.ai-create-card .acts button:hover { background: var(--ai-accent-soft); border-color: var(--ai-accent); color: var(--ai-accent); }

/* 输入区 */
.ai-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid #eef0f3; background: #fff; }
.ai-input textarea { flex: 1; resize: none; border: 1px solid #e2e8f0; border-radius: 10px; padding: 9px 12px; font-size: 13.5px; font-family: inherit; max-height: 120px; min-height: 38px; outline: none; }
.ai-input textarea:focus { border-color: var(--ai-accent); box-shadow: 0 0 0 3px var(--ai-accent-soft); }
.ai-input button { width: 42px; border: none; border-radius: 10px; background: var(--ai-accent); color: #fff; cursor: pointer; font-size: 16px; }
.ai-input button:disabled { background: #cbd5e1; cursor: not-allowed; }
.ai-quick { display: flex; gap: 6px; padding: 0 16px 8px; flex-wrap: wrap; }
.ai-quick button { font-size: 11px; padding: 4px 10px; border: 1px solid #e2e8f0; background: #fff; border-radius: 12px; cursor: pointer; color: #475569; }
.ai-quick button:hover { background: var(--ai-accent-soft); border-color: var(--ai-accent); color: var(--ai-accent); }

/* 设置子视图 */
.ai-settings { padding: 16px; overflow-y: auto; }
.ai-settings h4 { margin: 14px 0 6px; font-size: 13px; color: #0f172a; }
.ai-settings label { display: block; font-size: 12px; color: #475569; margin: 8px 0 3px; }
.ai-settings input, .ai-settings select { width: 100%; padding: 7px 9px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 13px; box-sizing: border-box; }
.ai-settings .provider-card { border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fafbfc; }
.ai-settings .row2 { display: flex; gap: 8px; }
.ai-settings .row2 > div { flex: 1; }
.ai-settings .save-btn { margin-top: 12px; padding: 9px 16px; background: var(--ai-accent); color: #fff; border: none; border-radius: 9px; cursor: pointer; font-weight: 600; width: 100%; }
.ai-settings .hint { font-size: 11px; color: #94a3b8; margin-top: 4px; }

/* ============================================================
   全站悬停微交互（FR-7 / AC-9）
   不改变布局，仅 transform + 阴影 + 过渡
   ============================================================ */
.btn, button, .icon-btn, .nav-item, .nav-child, .xk-item, .xk-dd-item,
.asset-card, .kpi-card, .stat-card, .order-card, .menu-item, .sidebar-item {
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}
.btn:hover, button:hover { transform: translateY(-1px); }
.nav-item:hover, .nav-child:hover, .xk-item:hover, .xk-dd-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.18);
}
.asset-card:hover, .kpi-card:hover, .stat-card:hover, .order-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}
table tbody tr { transition: background-color 0.15s ease; }
table tbody tr:hover { background-color: var(--ai-accent-soft); }
.icon, .lucide, svg { transition: transform 0.18s ease; }
.btn:hover .icon, .btn:hover .lucide, button:hover .icon, button:hover .lucide { transform: scale(1.12); }

/* 尊重“减少动态效果” */
@media (prefers-reduced-motion: reduce) {
  .ai-fab, .ai-panel, .ai-panel-backdrop, .ai-typing span,
  .btn, button, .nav-item, .nav-child, .xk-item, .xk-dd-item,
  .asset-card, .kpi-card, .stat-card, .order-card, .icon, .lucide, svg {
    transition: none !important;
    animation: none !important;
  }
  .ai-fab:hover, .btn:hover, button:hover, .nav-item:hover, .asset-card:hover { transform: none !important; }
}

@media (max-width: 768px) {
  .ai-panel { width: 100vw; min-width: 0; }
  .ai-fab { width: 48px; height: 48px; font-size: 22px; right: 16px; bottom: 16px; }
}
