/* =====================================================================
 * Foliage v1.0 — spa.css
 * SPA 用户中心专用样式层 (Vue 3, 11 路由)
 * 设计原则:
 *   - 不重复 components.css: 复用 .btn / .card / .badge / .grid 等
 *   - 增量提供: SPA 专属布局/动效/可视化(KPI/Sparkline/Timeline)
 *   - 配置驱动: 0 hardcode, 全部走 tokens.css CSS 变量
 *   - 双主题: Dark (默认) + Light 通过 [data-theme="light"] 切换
 *   - 响应式: 1024px 断点 (与 base.css 对齐)
 * ===================================================================== */

/* =====================================================================
 * §1 SPA 布局 — AppHeader / AppSidebar / AppMain
 * ===================================================================== */

/* AppHeader 升级 (Vue 内) — 与 base.html site-header 不重复 */
.app-header {
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--header-height, 64px);
  padding: 0 var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: var(--z-sticky, 200);
}
.app-header .brand-link {
  display: flex; align-items: center; gap: var(--space-2);
  font-weight: var(--weight-bold); color: var(--text);
  text-decoration: none; flex-shrink: 0;
  font-size: var(--text-lg);
}
.app-header .brand-link img { width: 32px; height: 32px; border-radius: var(--radius-sm); }
.app-header .brand-link .brand-text-zh {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.app-header .header-search {
  flex: 1; max-width: 480px; min-width: 0; position: relative;
  margin: 0 auto;
}
.app-header .header-search input {
  width: 100%; height: 36px;
  padding: 0 var(--space-3) 0 36px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-full, 9999px);
  color: var(--text); font-size: var(--text-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.app-header .header-search input:focus {
  outline: none; border-color: var(--accent); background: var(--bg);
}
.app-header .header-search .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.app-header .header-actions {
  display: flex; align-items: center; gap: var(--space-1);
  flex-shrink: 0;
}
.app-header .icon-btn {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent;
  color: var(--text-muted); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition-fast);
  position: relative;
}
.app-header .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.app-header .icon-btn .badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: var(--radius-full, 9999px);
  background: var(--up-color, #ef4444); border: 2px solid var(--surface);
}
.app-header .user-menu-trigger {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 4px 10px 4px 4px; height: 36px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-full, 9999px);
  cursor: pointer; transition: all var(--transition-fast);
  color: var(--text);
}
.app-header .user-menu-trigger:hover { border-color: var(--accent); }
.app-header .user-avatar {
  width: 28px; height: 28px; border-radius: var(--radius-full, 9999px);
  background: var(--gradient, linear-gradient(135deg, #5b9aff 0%, #a78bfa 100%));
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-inverse); font-size: var(--text-xs); font-weight: var(--weight-bold);
  flex-shrink: 0;
}
.app-header .user-name {
  font-size: var(--text-sm); max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* AppSidebar 折叠态 (桌面专属) */
.app-sidebar.collapsed {
  width: 60px !important;
}
.app-sidebar.collapsed .sidebar-section-label,
.app-sidebar.collapsed .sidebar-item span,
.app-sidebar.collapsed .sidebar-footer {
  display: none;
}
.app-sidebar.collapsed .sidebar-item {
  padding: 12px; justify-content: center;
}
.app-sidebar.collapsed .sidebar-item.active {
  border-right: none;
  border-radius: var(--radius);
  margin: 0 var(--space-2);
}
.sidebar-collapse-btn {
  position: absolute; top: 12px; right: -12px;
  width: 24px; height: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-full, 9999px);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 10; color: var(--text-muted);
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.sidebar-collapse-btn:hover {
  color: var(--accent); border-color: var(--accent);
  transform: scale(1.1);
}

/* SPA Main — 与 sidebar 折叠协调 */
.app-body { transition: padding var(--transition); }
.app-main {
  flex: 1; min-height: 0; overflow-y: auto;
  background: var(--bg);
  background-image: radial-gradient(ellipse 60% 40% at 50% 0%, rgba(91, 154, 255, 0.04), transparent 70%);
  padding: var(--space-6);
  transition: padding var(--transition);
}


/* =====================================================================
 * §2 Hero 区域 — 用户档案头 (AccountView 等使用)
 * ===================================================================== */
.hero-card {
  position: relative;
  padding: var(--space-7);
  background: var(--gradient-soft, linear-gradient(135deg, rgba(91,154,255,0.15) 0%, rgba(167,139,250,0.15) 100%));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.hero-card::before {
  content: ''; position: absolute; inset: 0;
  background: var(--surface); opacity: 0.6; z-index: 0;
}
.hero-card > * { position: relative; z-index: 1; }
.hero-card .hero-row {
  display: flex; align-items: center; gap: var(--space-5);
  flex-wrap: wrap;
}
.hero-card .hero-avatar {
  width: 72px; height: 72px; border-radius: var(--radius-full, 9999px);
  background: var(--gradient, linear-gradient(135deg, #5b9aff 0%, #a78bfa 100%));
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-inverse); font-size: var(--text-3xl); font-weight: var(--weight-bold);
  flex-shrink: 0;
  box-shadow: var(--shadow-glow, 0 0 24px rgba(91, 154, 255, 0.25));
}
.hero-card .hero-info { flex: 1; min-width: 200px; }
.hero-card .hero-info h2 {
  margin: 0 0 var(--space-1) 0; font-size: var(--text-2xl);
}
.hero-card .hero-info .hero-meta {
  display: flex; gap: var(--space-3); flex-wrap: wrap;
  color: var(--text-muted); font-size: var(--text-sm);
}
.hero-card .hero-actions {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
}
.hero-card .hero-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4); margin-top: var(--space-6);
  padding-top: var(--space-5); border-top: 1px solid var(--border);
}
.hero-card .hero-stat-label {
  color: var(--text-muted); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.hero-card .hero-stat-value {
  font-size: var(--text-2xl); font-weight: var(--weight-bold);
  color: var(--text); margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}


/* =====================================================================
 * §3 KPI 卡 (KpiDelta 组件 + 通用)
 * ===================================================================== */
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.kpi-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.kpi-card .kpi-label {
  color: var(--text-muted); font-size: var(--text-sm);
  display: flex; align-items: center; gap: var(--space-1);
}
.kpi-card .kpi-value {
  font-size: var(--text-3xl); font-weight: var(--weight-bold);
  color: var(--text); margin-top: var(--space-2);
  font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline; gap: var(--space-1);
}
.kpi-card .kpi-value-unit {
  font-size: var(--text-sm); font-weight: var(--weight-normal);
  color: var(--text-muted);
}
.kpi-card .kpi-delta {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  margin-top: var(--space-2);
  padding: 2px 8px; border-radius: var(--radius-full, 9999px);
}
.kpi-card .kpi-delta.up { color: var(--up-color); background: var(--up-bg); }
.kpi-card .kpi-delta.down { color: var(--down-color); background: var(--down-bg); }
.kpi-card .kpi-delta.neutral { color: var(--text-muted); background: var(--surface-2); }
.kpi-card.kpi-card-accent {
  border-color: var(--accent-soft-3, rgba(91, 154, 255, 0.32));
  background: var(--accent-soft, rgba(91, 154, 255, 0.15));
}
.kpi-card.kpi-card-pro {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #000; border-color: transparent;
}
.kpi-card.kpi-card-pro .kpi-label,
.kpi-card.kpi-card-pro .kpi-value { color: #000; }

/* KPI loading shimmer */
@keyframes kpi-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.kpi-card.is-loading .kpi-value {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: kpi-shimmer 1.4s linear infinite;
  color: transparent;
  border-radius: var(--radius-sm);
  min-height: 1.5em;
  min-width: 60%;
}


/* =====================================================================
 * §4 MiniSparkline — 7 日走势 (SVG)
 * ===================================================================== */
.sparkline {
  display: inline-block; vertical-align: middle;
  line-height: 0;
}
.sparkline svg { display: block; }
.sparkline .sparkline-line {
  fill: none; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.sparkline.up .sparkline-line { stroke: var(--up-color); }
.sparkline.down .sparkline-line { stroke: var(--down-color); }
.sparkline.neutral .sparkline-line { stroke: var(--text-muted); }
.sparkline .sparkline-area {
  opacity: 0.15; stroke: none;
}
.sparkline.up .sparkline-area { fill: var(--up-color); }
.sparkline.down .sparkline-area { fill: var(--down-color); }
.sparkline.neutral .sparkline-area { fill: var(--text-muted); }
.sparkline .sparkline-baseline {
  stroke: var(--border); stroke-width: 0.5;
  stroke-dasharray: 2 2; opacity: 0.5;
}


/* =====================================================================
 * §5 Timeline — 时间线 (Token 流水 / 订单)
 * ===================================================================== */
.timeline {
  position: relative;
  padding-left: var(--space-6);
}
.timeline::before {
  content: ''; position: absolute;
  left: 11px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: var(--space-5);
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: -22px; top: 4px;
  width: 14px; height: 14px; border-radius: var(--radius-full, 9999px);
  background: var(--surface);
  border: 2px solid var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
}
.timeline-dot.up { border-color: var(--up-color); }
.timeline-dot.down { border-color: var(--down-color); }
.timeline-dot.warning { border-color: var(--yellow); }
.timeline-dot.success { border-color: var(--status-ok, #22c55e); }
.timeline-dot.success::after { content: ''; width: 6px; height: 6px; background: var(--status-ok, #22c55e); border-radius: var(--radius-full, 9999px); }
.timeline-content {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: var(--space-3); flex-wrap: wrap;
}
.timeline-title {
  font-weight: var(--weight-medium);
  color: var(--text);
}
.timeline-desc {
  color: var(--text-muted); font-size: var(--text-sm);
  margin-top: 2px;
}
.timeline-time {
  color: var(--text-dim); font-size: var(--text-xs);
  white-space: nowrap;
}
.timeline-amount {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
.timeline-amount.up { color: var(--up-color); }
.timeline-amount.down { color: var(--down-color); }


/* =====================================================================
 * §6 EmptyState 插画槽 (增强版)
 * ===================================================================== */
.empty-state-card .empty-illustration {
  width: 80px; height: 80px;
  margin: 0 auto var(--space-3);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-radius: var(--radius-full, 9999px);
  color: var(--text-muted);
}
.empty-state-card .empty-illustration svg {
  width: 40px; height: 40px;
}


/* =====================================================================
 * §7 微交互 — 路由切换 fade-in / 卡片悬停 / 数字滚动
 * ===================================================================== */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.app-main > * {
  animation: fade-in-up 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.card { transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast); }
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  border-color: var(--accent-soft-3, rgba(91, 154, 255, 0.32));
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card.clickable:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Skeleton shimmer */
@keyframes skeleton-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: var(--radius-sm);
}
/* 卡片骨架 */
.skeleton.skeleton-card-block {
  height: 100px;
  border-radius: var(--radius-md);
}
.skeleton.skeleton-kpi {
  height: 90px; border-radius: var(--radius-md);
}
.skeleton.skeleton-circle {
  border-radius: var(--radius-full, 9999px);
  width: 72px; height: 72px;
}


/* =====================================================================
 * §8 升级/Pro 视觉强调
 * ===================================================================== */
.upgrade-banner {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-5);
  background: linear-gradient(135deg, rgba(91, 154, 255, 0.12) 0%, rgba(167, 139, 250, 0.12) 100%);
  border: 1px solid var(--accent-soft-3, rgba(91, 154, 255, 0.32));
  border-radius: var(--radius-md);
}
.upgrade-banner .upgrade-icon {
  width: 48px; height: 48px; border-radius: var(--radius);
  background: var(--gradient);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-inverse); flex-shrink: 0;
}
.upgrade-banner .upgrade-info { flex: 1; min-width: 200px; }
.upgrade-banner .upgrade-info h4 {
  margin: 0; color: var(--text); font-size: var(--text-lg);
}
.upgrade-banner .upgrade-info p {
  margin-top: 4px; color: var(--text-muted); font-size: var(--text-sm);
}
.upgrade-banner .upgrade-cta { flex-shrink: 0; }


/* =====================================================================
 * §9 Pro 卡视觉强化 (PaymentView 用)
 * ===================================================================== */
.pro-card-featured {
  position: relative;
  background: linear-gradient(135deg, rgba(91, 154, 255, 0.08) 0%, rgba(167, 139, 250, 0.08) 100%);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-glow, 0 0 24px rgba(91, 154, 255, 0.25));
}
.pro-card-featured::after {
  content: '推荐';
  position: absolute; top: -10px; right: 16px;
  padding: 2px 10px;
  background: var(--gradient);
  color: var(--text-inverse); font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full, 9999px);
}
.save-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--badge-success-bg, rgba(22, 163, 74, 0.12));
  color: var(--badge-success, #16a34a);
  border-radius: var(--radius-full, 9999px);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  margin-left: var(--space-2);
}


/* =====================================================================
 * §10 焦点增强 (a11y)
 * ===================================================================== */
.app-main a:focus-visible,
.app-main button:focus-visible,
.app-main input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* =====================================================================
 * §11 减少动效 (a11y)
 * ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  .app-main > *,
  .kpi-card.is-loading .kpi-value,
  .skeleton { animation: none !important; }
  .kpi-card { transition: none; }
  .kpi-card:hover { transform: none; }
}


/* =====================================================================
 * §12 周报 Markdown 渲染 (v-html 全局样式, scoped 样式无法穿透 v-html)
 * ===================================================================== */
.weekly-content { line-height: 1.85; font-size: 0.95rem; color: var(--text); }
.weekly-content > p:first-child { margin-top: 0; }
.weekly-content > p:last-child { margin-bottom: 0; }
.weekly-content p { margin: 10px 0; }
.weekly-content h1,
.weekly-content h2,
.weekly-content h3,
.weekly-content h4,
.weekly-content h5,
.weekly-content h6 {
  margin-top: 22px;
  margin-bottom: 8px;
  font-weight: var(--weight-semibold, 600);
  line-height: 1.4;
}
.weekly-content h1 { font-size: 1.3rem; }
.weekly-content h2 { font-size: 1.2rem; }
.weekly-content h3 { font-size: 1.1rem; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.weekly-content h4 { font-size: 1rem; }
.weekly-content h5,
.weekly-content h6 { font-size: 0.9rem; }
.weekly-content ul,
.weekly-content ol { padding-left: 22px; margin: 8px 0; }
.weekly-content li { margin: 4px 0; }
.weekly-content li::marker { color: var(--accent, #5b9aff); }
.weekly-content strong { font-weight: var(--weight-semibold, 600); color: var(--text); }
.weekly-content em { font-style: italic; }
.weekly-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.weekly-content blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent, #5b9aff);
  background: var(--bg-hover, rgba(255, 255, 255, 0.03));
  border-radius: 0 var(--radius-sm, 6px) var(--radius-sm, 6px) 0;
  color: var(--text-muted, #999);
  font-size: 0.875rem;
}
.weekly-content code {
  padding: 2px 6px;
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-hover, rgba(255, 255, 255, 0.06));
  font-size: 0.875em;
}
.weekly-content a {
  color: var(--accent, #5b9aff);
  text-decoration: none;
}
.weekly-content a:hover { text-decoration: underline; }
.weekly-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.875rem;
}
.weekly-content th,
.weekly-content td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
}
.weekly-content th {
  background: var(--bg-hover, rgba(255, 255, 255, 0.03));
  font-weight: var(--weight-semibold, 600);
}
