/* HL Quant — Design System v2 */
/* Telegram Mini App 优化, 移动优先, 暗色酷炫风格 */

:root {
  --bg-deep: #0b0f19;
  --bg-base: #111827;
  --bg-surface: #1a2035;
  --bg-elevated: #232b3e;
  --bg-card: rgba(26,32,53,.85);
  --border: rgba(255,255,255,.06);
  --border-active: rgba(99,102,241,.5);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99,102,241,.35);
  --green: #10b981;
  --green-light: #34d399;
  --green-bg: rgba(16,185,129,.12);
  --red: #ef4444;
  --red-light: #f87171;
  --red-bg: rgba(239,68,68,.12);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245,158,11,.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59,130,246,.12);
  --gradient-accent: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-green: linear-gradient(135deg, #10b981, #34d399);
  --gradient-red: linear-gradient(135deg, #ef4444, #f87171);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 4px 24px rgba(0,0,0,.3);
  --shadow-glow: 0 0 20px var(--accent-glow);
  --tab-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 14px; }
body {
  font-family: -apple-system, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 8px);
}

/* ── 顶部栏 ─────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: rgba(11,15,25,.92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}
.app-header .logo {
  font-size: 16px; font-weight: 700; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.app-header .logo .icon { font-size: 20px; }
.app-header .status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 11px;
  background: var(--green-bg); color: var(--green);
}
.app-header .status-pill.offline { background: var(--red-bg); color: var(--red); }
.status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }

/* ── 底部导航 ─────────────────── */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  display: flex; align-items: stretch; justify-content: space-around;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(17,24,39,.95);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--text-muted);
  font-size: 10px; font-weight: 500; transition: color .2s;
  position: relative;
}
.tab-item .tab-icon { font-size: 22px; line-height: 1; }
.tab-item.active { color: var(--accent-light); }
.tab-item.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 2px; border-radius: 0 0 2px 2px;
  background: var(--gradient-accent);
}

/* ── 页面容器 ─────────────────── */
.page { padding: 12px 16px 20px; max-width: 600px; margin: 0 auto; }

/* ── 卡片系统 ─────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: border-color .2s, box-shadow .2s;
}
.card:active { border-color: var(--border-active); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px;
  display: flex; align-items: center; gap: 6px;
}
.card-action {
  font-size: 12px; color: var(--accent-light); cursor: pointer;
  background: none; border: none; padding: 4px 8px;
}

/* ── 英雄数值卡 (账户余额等) ─── */
.hero-card {
  background: linear-gradient(135deg, rgba(99,102,241,.15), rgba(139,92,246,.08));
  border: 1px solid rgba(99,102,241,.2);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-bottom: 16px;
  position: relative; overflow: hidden;
}
.hero-card::before {
  content: ''; position: absolute; top: -50%; right: -30%;
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.15), transparent 70%);
}
.hero-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.hero-value {
  font-size: 32px; font-weight: 800; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.hero-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── 统计网格 ─────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.stat-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.stat-value {
  font-size: 18px; font-weight: 700; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.yellow { color: var(--yellow); }

/* ── 持仓卡 ─────────────────── */
.position-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; transition: all .2s;
}
.position-card:active { background: var(--bg-elevated); }
.pos-left { flex: 1; min-width: 0; }
.pos-symbol { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.pos-meta {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
  display: flex; gap: 8px; align-items: center;
}
.pos-right { text-align: right; flex-shrink: 0; }
.pos-pnl { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-size { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Badge ─────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px;
}
.badge.long { background: var(--green-bg); color: var(--green); }
.badge.short { background: var(--red-bg); color: var(--red); }
.badge.running { background: var(--green-bg); color: var(--green); }
.badge.stopped { background: rgba(100,116,139,.15); color: var(--text-muted); }
.badge.signal { background: var(--blue-bg); color: var(--blue); }
.badge.warn { background: var(--yellow-bg); color: var(--yellow); }
.badge.error { background: var(--red-bg); color: var(--red); }

/* ── 按钮 ─────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600; border: none; cursor: pointer;
  transition: all .15s; -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gradient-accent); color: #fff; }
.btn-danger { background: var(--gradient-red); color: #fff; }
.btn-ghost {
  background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:active { background: var(--bg-elevated); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── 折叠区域 ─────────────────── */
.collapse-trigger {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; -webkit-user-select: none; user-select: none;
  padding: 4px 0;
}
.collapse-trigger .arrow {
  transition: transform .2s; font-size: 12px; color: var(--text-muted);
}
.collapse-trigger.open .arrow { transform: rotate(180deg); }
.collapse-body {
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease-out;
}
.collapse-body.open { max-height: 4000px; transition: max-height .5s ease-in; }

/* ── 表格 ─────────────────── */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.data-table th {
  text-align: left; padding: 8px 6px; color: var(--text-muted);
  font-weight: 500; border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .3px;
}
.data-table td {
  padding: 10px 6px; border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.data-table tr:last-child td { border-bottom: none; }

/* ── 策略观测卡 ─────────────── */
.strategy-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px; margin-bottom: 8px;
  transition: border-color .2s;
}
.strategy-card.state-signal { border-color: rgba(59,130,246,.5); }
.strategy-card.state-submitted { border-color: rgba(16,185,129,.5); }
.strategy-card.state-error { border-color: rgba(239,68,68,.5); }
.strategy-card.state-filtered { border-color: rgba(245,158,11,.5); }

.strategy-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.strategy-name { font-size: 14px; font-weight: 700; }
.strategy-reason {
  font-size: 12px; color: var(--text-muted); line-height: 1.4;
  margin-bottom: 10px;
}
.strategy-meta {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.meta-item {
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.meta-label { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.meta-value { font-size: 13px; font-weight: 600; color: var(--text-primary); word-break: break-word; }

/* ── 行情价格网格 ─────────────── */
.price-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.price-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px; text-align: center;
  transition: border-color .3s;
}
.price-card.up { border-color: rgba(16,185,129,.4); }
.price-card.down { border-color: rgba(239,68,68,.4); }
.price-symbol { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.price-value {
  font-size: 14px; font-weight: 700; margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.price-value.up { color: var(--green); }
.price-value.down { color: var(--red); }
.price-delta { font-size: 10px; margin-top: 2px; color: var(--text-muted); }
.price-delta.up { color: var(--green-light); }
.price-delta.down { color: var(--red-light); }

/* ── 输入框 ─────────────────── */
.input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }
.input-group { margin-bottom: 10px; }
.input-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; display: block; }

/* ── Canvas 图表区 ─────────────── */
.chart-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  margin: 12px 0;
}
.chart-container canvas { width: 100%; height: 180px; display: block; }

/* ── 闸门排名列表 ─────────────── */
.rank-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 6px; gap: 10px;
}
.rank-item.selected { border-color: rgba(16,185,129,.5); }
.rank-item.rejected { border-color: rgba(245,158,11,.4); }
.rank-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.rank-info { flex: 1; min-width: 0; }
.rank-score { font-size: 18px; font-weight: 800; flex-shrink: 0; }

/* ── 空状态 ─────────────────── */
.empty-state {
  text-align: center; padding: 32px 16px;
  color: var(--text-muted); font-size: 13px;
}
.empty-state .icon { font-size: 36px; margin-bottom: 8px; opacity: .5; }

/* ── 加载骨架 ─────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-block { height: 60px; margin-bottom: 12px; }

/* ── 通知横幅 ─────────────────── */
.notice {
  padding: 10px 14px; border-radius: var(--radius-md);
  font-size: 12px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.notice.success { background: var(--green-bg); color: var(--green); }
.notice.error { background: var(--red-bg); color: var(--red); }
.notice.warning { background: var(--yellow-bg); color: var(--yellow); }
.notice.info { background: var(--blue-bg); color: var(--blue); }

/* ── 淡入动画 ─────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp .3s ease-out both; }
.animate-in:nth-child(2) { animation-delay: .05s; }
.animate-in:nth-child(3) { animation-delay: .1s; }
.animate-in:nth-child(4) { animation-delay: .15s; }

/* ── 回测结果指标 ─────────────── */
.metric-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 8px; margin: 12px 0;
}
.metric-card {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.metric-card .label { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.metric-card .value { font-size: 15px; font-weight: 700; }

/* ── Scrollbar ─────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

/* ── 搜索框 ─────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px; margin-bottom: 12px;
}
.search-bar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 14px;
}
.search-bar input::placeholder { color: var(--text-muted); }

/* ── Section 分隔 ─────────────── */
.section-title {
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  margin: 16px 0 10px; display: flex; align-items: center; gap: 8px;
}

/* ── 接管/验收步骤 ─────────────── */
.step-row {
  display: flex; gap: 4px; margin-bottom: 10px;
}
.step-dot {
  flex: 1; height: 4px; border-radius: 2px;
  background: var(--bg-elevated);
}
.step-dot.done { background: var(--green); }
.step-dot.pending { background: var(--yellow); }

/* ── 自适应 ─────────────────── */
@media (min-width: 500px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .price-grid { grid-template-columns: repeat(4, 1fr); }
  .strategy-meta { grid-template-columns: repeat(3, 1fr); }
}
