/* ==========================================================
   红利量化 · DividendFund Design System
   双主题（默认专业暗黑终端 / 支持清爽浅色）+ iOS PWA 安全区适配
   中国股市配色规范：红涨 (#f23645) 绿跌 (#089981)
   ========================================================== */

:root,
[data-theme="dark"] {
  --bg: #0b0f17;
  --bg-subtle: #101624;
  --surface: #131b2b;
  --surface-elevated: #192338;
  --surface-hover: #1e2a42;
  --border: rgba(148, 163, 184, 0.13);
  --border-strong: rgba(148, 163, 184, 0.24);
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --gold: #f59e0b;
  --gold-soft: rgba(245, 158, 11, 0.15);

  --up: #f23645;
  --up-soft: rgba(242, 54, 69, 0.15);
  --down: #089981;
  --down-soft: rgba(8, 153, 129, 0.15);
  --neutral-soft: rgba(148, 163, 184, 0.14);

  --header-bg: rgba(11, 15, 23, 0.84);
  --tabbar-bg: rgba(15, 22, 36, 0.9);
  --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.28);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

[data-theme="light"] {
  --bg: #f3f6fb;
  --bg-subtle: #eaeff7;
  --surface: #ffffff;
  --surface-elevated: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --gold: #d97706;
  --gold-soft: rgba(217, 119, 6, 0.12);

  --up: #e11d48;
  --up-soft: rgba(225, 29, 72, 0.1);
  --down: #059669;
  --down-soft: rgba(5, 150, 105, 0.1);
  --neutral-soft: rgba(100, 116, 139, 0.1);

  --header-bg: rgba(255, 255, 255, 0.86);
  --tabbar-bg: rgba(255, 255, 255, 0.92);
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.num, .mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.muted { color: var(--text-secondary); }
.gold-text { color: var(--gold) !important; }

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部导航 ---------- */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  height: 58px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.nav-btn:hover {
  color: var(--text);
}

.nav-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.market-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}

.market-pill.live {
  color: var(--up);
  border-color: rgba(242, 54, 69, 0.35);
  background: var(--up-soft);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.market-pill.live .pulse-dot {
  background: var(--up);
  box-shadow: 0 0 0 0 rgba(242, 54, 69, 0.7);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(242, 54, 69, 0.65); }
  70% { box-shadow: 0 0 0 7px rgba(242, 54, 69, 0); }
  100% { box-shadow: 0 0 0 0 rgba(242, 54, 69, 0); }
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.16s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.icon-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- 主体容器 ---------- */
.main-container {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 16px 36px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- 卡片与栅格 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}

.card-compact {
  padding: 14px 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ---------- 实时决策横幅 ---------- */
.signal-hero {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.14) 0%, rgba(242, 54, 69, 0.08) 100%);
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.signal-hero.alert-buy {
  background: linear-gradient(135deg, rgba(242, 54, 69, 0.18) 0%, rgba(245, 158, 11, 0.1) 100%);
  border-color: rgba(242, 54, 69, 0.4);
}

.signal-hero.alert-sell {
  background: linear-gradient(135deg, rgba(8, 153, 129, 0.18) 0%, rgba(59, 130, 246, 0.08) 100%);
  border-color: rgba(8, 153, 129, 0.4);
}

.signal-hero-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.signal-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.signal-headline {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.signal-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.signal-hero-right {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.pos-metric {
  display: flex;
  flex-direction: column;
}

.pos-metric span:first-child {
  font-size: 11.5px;
  color: var(--text-muted);
}

.pos-metric strong {
  font-size: 16px;
  font-weight: 700;
}

/* ---------- 标签徽章 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-buy { background: var(--up-soft); color: var(--up); }
.badge-sell { background: var(--down-soft); color: var(--down); }
.badge-hold { background: var(--neutral-soft); color: var(--text-secondary); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-gold { background: var(--gold-soft); color: var(--gold); }

/* ---------- 数据表格 ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.right,
.data-table td.right {
  text-align: right;
}

.data-table tbody tr.clickable {
  cursor: pointer;
  transition: background 0.14s ease;
}

.data-table tbody tr.clickable:hover {
  background: var(--surface-hover);
}

.data-table tbody tr.holding-row {
  background: rgba(59, 130, 246, 0.08);
}

.etf-cell {
  display: flex;
  flex-direction: column;
}

.etf-name {
  font-weight: 700;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.etf-code {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- 偏离度可视化进度条 ---------- */
.dev-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.dev-track {
  position: relative;
  width: 96px;
  height: 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  overflow: visible;
}

.dev-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 11px;
  border-radius: 2px;
  opacity: 0.7;
}

.dev-marker.buy-line { background: var(--up); left: 35%; }
.dev-marker.zero-line { background: var(--text-muted); left: 50%; opacity: 0.4; }
.dev-marker.sell-line { background: var(--down); left: 85%; }

.dev-dot {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- 按钮组 & 切换 Tab ---------- */
.pill-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
}

.pill-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-tab:hover { color: var(--text); }

.pill-tab.active {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
}

/* ---------- 图表容器 ---------- */
.chart-box {
  width: 100%;
  height: 350px;
}

.chart-box-sm {
  width: 100%;
  height: 270px;
}

.kline-container {
  width: 100%;
  height: 430px;
  position: relative;
}

.kline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11.5px;
  margin-bottom: 8px;
  min-height: 20px;
}

/* ---------- 行情终端头部 ---------- */
.ticker-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 14px;
  scrollbar-width: none;
}

.ticker-strip::-webkit-scrollbar { display: none; }

.ticker-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
  text-align: left;
  transition: all 0.15s ease;
}

.ticker-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.ticker-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ticker-chip-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
}

.ticker-chip-bottom {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}

.quote-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.quote-price-big {
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.8px;
}

.quote-change-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
}

.quote-ohlc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 8px 18px;
}

.ohlc-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}

.ohlc-item span:first-child { color: var(--text-muted); }

/* ---------- 策略卡片（总览 & 黄金） ---------- */
.strategy-entry-card {
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.strategy-entry-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.gold-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.16) 0%, rgba(234, 179, 8, 0.05) 100%);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.idea-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.idea-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--gold);
}

.idea-card p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ---------- 底部版权栏 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 16px 22px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.footer-sep {
  opacity: 0.45;
}

/* ---------- 底部移动端 Tab Bar ---------- */
.mobile-tabbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--tabbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}

.tab-item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
}

.tab-item.active {
  color: var(--accent);
}

/* ---------- 加载与提示 ---------- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

.ios-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 60;
  background: var(--surface-elevated);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.ios-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}

.ios-banner-content button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
}

.rule-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.rule-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ---------- 响应式断点 ---------- */
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .desktop-nav { display: none; }
  .mobile-tabbar { display: flex; }
  .header-inner { padding: 0 12px; gap: 8px; }
  .brand-sub { display: none; }
  .market-pill { font-size: 11px; padding: 4px 8px; }
  .icon-btn { width: 32px; height: 32px; }
  .main-container {
    padding: 14px 12px 18px;
  }
  .site-footer {
    padding: 14px 12px calc(76px + env(safe-area-inset-bottom));
  }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 19px; }
  .card { padding: 14px; border-radius: 15px; }
  .kline-container { height: 360px; }
  .chart-box { height: 300px; }
  .quote-price-big { font-size: 28px; }
  .quote-ohlc-grid { grid-template-columns: repeat(2, minmax(110px, 1fr)); width: 100%; }
  .dev-track { display: none; }
}
