:root {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --green: #2da44e;
  --red: #f03d3d;
  --up: #f03d3d;    /* 涨：红 */
  --down: #2da44e;  /* 跌：绿 */
  --blue: #388bfd;
  --gold: #d4a017;
  --radius: 10px;
  --transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- 动画 ---- */
.fade-in {
  opacity: 1;
  animation: fadeInUp 0.45s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.delay-1 { animation-delay: 0.05s; }
.delay-2 { animation-delay: 0.10s; }
.delay-3 { animation-delay: 0.15s; }
.delay-4 { animation-delay: 0.20s; }
.delay-5 { animation-delay: 0.25s; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 无 JS 时也保证内容可见 */
.no-js .fade-in { opacity: 1; animation: none; }

/* ---- 登录页 ---- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #1a2332 0%, var(--bg) 70%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
}

.login-logo {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  background: var(--up);
  color: #fff;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
  letter-spacing: 0.5px;
}

.login-title { margin: 0 0 4px; font-size: 22px; }
.login-sub { color: var(--text-muted); margin: 0 0 28px; font-size: 13px; }

.login-form { text-align: left; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 15px;
  transition: border-color var(--transition);
}
.field input:focus { outline: none; border-color: var(--blue); }

.error-msg { color: var(--red); font-size: 13px; margin: 0 0 12px; }

/* ---- 按钮 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  font-weight: 500; cursor: pointer; border: none;
  transition: all var(--transition);
}
.btn-primary { background: #238636; color: #fff; }
.btn-primary:hover { background: #2ea043; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(15, 20, 25, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 12px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand > div { min-width: 0; }
.brand-icon {
  width: 40px; height: 40px;
  background: var(--up);
  color: #fff;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
  letter-spacing: 0.3px;
}
.brand h1 {
  margin: 0; font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subtitle { margin: 0; font-size: 11px; color: var(--text-muted); }
.topbar-actions {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.status-bar {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  word-break: break-word;
}
.status-bar b { color: var(--text); font-weight: 600; }
.status-sep { margin: 0 2px; }

/* ---- 主容器 ---- */
.dash-container {
  max-width: 1200px; margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ---- 日期控制栏 ---- */
.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}
.control-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.control-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}
.preset-btn {
  padding: 6px 12px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.preset-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}
.preset-btn.active {
  background: rgba(56, 139, 253, 0.12);
  color: var(--blue);
  border-color: var(--blue);
}
.control-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-left: auto;
}
.control-dates label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.control-dates input[type="date"] {
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  color-scheme: dark;
}
.control-dates input[type="date"]:focus {
  outline: none;
  border-color: var(--blue);
}

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.section-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-word;
}

.sub-title {
  margin: 16px 0 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
  margin-bottom: 16px;
}
.section-header .section-title { margin-bottom: 0; }
.chevron {
  font-size: 12px; color: var(--text-muted);
  transition: transform var(--transition);
}
.section-header.open .chevron { transform: rotate(180deg); }

.collapsible {
  max-height: 0; overflow: hidden;
  transition: max-height 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
  opacity: 0;
}
.collapsible.open {
  max-height: 3000px; opacity: 1;
  margin-top: 16px;
  overflow: visible;
}
.collapsible.open > .sub-title:first-child { margin-top: 0; }

.badge {
  display: inline-block;
  background: rgba(56, 139, 253, 0.15);
  color: var(--blue);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---- 图表 ---- */
.chart-box { width: 100%; height: 380px; }
.chart-sm { height: 280px; }

/* ---- KPI ---- */
.kpi-row, .metrics-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.kpi-box, .metric-box {
  flex: 1 1 120px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 110px;
}
.kpi-label, .metric-label {
  font-size: 11px; color: var(--text-muted); margin-bottom: 4px;
}
.kpi-value, .metric-value {
  font-size: 18px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.55;
  word-break: break-word;
}

.meta-row {
  font-size: 12px; color: var(--text-muted);
  margin-top: 8px; line-height: 1.8;
}

.buy-label { color: var(--up); }
.sell-label { color: var(--down); }

/* ---- 表格 ---- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.table-scroll-tall {
  max-height: 480px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  isolation: isolate;
}
.collapsible.open .table-scroll-tall { min-height: 480px; }

.data-table {
  width: 100%; border-collapse: separate;
  border-spacing: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.table-scroll-tall .data-table thead {
  position: sticky;
  top: 0;
  z-index: 4;
}
.data-table th {
  text-align: left; padding: 8px 10px;
  color: var(--text-muted); font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-scroll-tall .data-table th {
  position: sticky;
  top: 0;
  z-index: 5;
  background-color: var(--bg-card);
  box-shadow: 0 1px 0 var(--border), 0 4px 6px rgba(15, 20, 25, 0.92);
}
.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.5);
  white-space: nowrap;
}
.data-table tbody tr {
  transition: background var(--transition);
}
.data-table tbody tr:hover { background: rgba(56, 139, 253, 0.06); }

.pos { color: var(--up); }
.neg { color: var(--down); }
.bench { color: #7f7f7f; }
.neu { color: var(--text-muted); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ---- Tab ---- */
.tab-bar { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
  padding: 6px 16px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; font-size: 13px;
  transition: all var(--transition);
}
.tab.active, .tab:hover {
  background: rgba(56, 139, 253, 0.12);
  color: var(--blue); border-color: var(--blue);
}

/* ---- 月/周收益 ---- */
.period-panel { padding: 4px 2px; }

.year-block { margin-bottom: 20px; }
.year-block:last-child { margin-bottom: 0; }
.year-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.month-cell {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  transition: border-color var(--transition);
}
.month-cell:hover { border-color: var(--text-muted); }
.month-cell .month-name {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.month-cell .month-pct {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.month-cell .month-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.week-month-block {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.week-month-block:last-child { margin-bottom: 0; }
.week-month-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 14px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.week-month-title {
  font-weight: 600;
  font-size: 14px;
  margin-right: auto;
}
.week-month-stat { font-variant-numeric: tabular-nums; white-space: nowrap; }

.week-list { padding: 4px 0; }
.week-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 14px;
  font-size: 13px;
  border-bottom: 1px solid rgba(48, 54, 61, 0.6);
  font-variant-numeric: tabular-nums;
}
.week-row:last-child { border-bottom: none; }
.week-label { min-width: 100px; color: var(--text-muted); }
.week-range { font-size: 11px; color: var(--text-muted); }

/* ---- 响应式 ---- */
@media (max-width: 768px) {
  .status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 0;
    font-size: 11px;
  }
  .status-sep { display: none; }
  .status-item { flex: 1 1 100%; }

  .dash-container { padding: 12px 12px calc(48px + env(safe-area-inset-bottom, 0)); }

  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .subtitle { display: none; }
  .brand-icon { width: 36px; height: 36px; font-size: 12px; }
  .brand h1 { font-size: 15px; }
  .btn-sm { min-height: 36px; padding: 8px 12px; }

  .control-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px;
  }
  .control-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 100%;
  }
  .control-label {
    grid-column: 1 / -1;
    margin: 0 0 2px;
  }
  .preset-btn {
    min-height: 36px;
    padding: 8px 6px;
    font-size: 12px;
  }
  .control-dates {
    margin-left: 0;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .control-dates label {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }
  .control-dates input[type="date"] {
    width: 100%;
    min-height: 40px;
    font-size: 16px;
  }

  .section-card { padding: 14px 12px; margin-bottom: 14px; }
  .section-title { font-size: 15px; margin-bottom: 12px; }
  .section-header { margin-bottom: 12px; min-height: 40px; }
  .section-header .section-title { font-size: 15px; }

  .chart-box { height: min(72vw, 300px); min-height: 240px; }
  .chart-sm { height: min(68vw, 260px); min-height: 220px; }

  .metrics-grid { flex-direction: column; }
  .metric-box, .kpi-box { flex: 1 1 auto; min-width: 0; width: 100%; }
  .kpi-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-value, .metric-value { font-size: 16px; }
  .metric-sub { font-size: 10px; }

  .two-col { grid-template-columns: 1fr; gap: 12px; }
  .table-scroll-tall { max-height: min(420px, 52vh); }
  .collapsible.open .table-scroll-tall { min-height: min(300px, 42vh); }

  .tab-bar { width: 100%; }
  .tab { flex: 1; text-align: center; min-height: 38px; }

  .month-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .month-cell { padding: 10px 6px; }
  .month-cell .month-pct { font-size: 15px; }

  .week-month-header, .week-row { font-size: 12px; gap: 6px 10px; }
  .week-month-title { width: 100%; margin-right: 0; margin-bottom: 2px; }
  .week-month-stat { font-size: 11px; }

  .page-error { margin: 10px 12px; font-size: 13px; }
  .toast {
    left: 12px; right: 12px; transform: translateY(80px);
    bottom: calc(16px + env(safe-area-inset-bottom, 0));
    text-align: center;
  }
  .toast.show { transform: translateY(0); }
}

@media (max-width: 480px) {
  .dash-container { padding: 10px 10px calc(40px + env(safe-area-inset-bottom, 0)); }

  .topbar-actions { gap: 6px; }
  .btn-sm { padding: 8px 10px; font-size: 11px; }

  .control-presets { grid-template-columns: repeat(2, 1fr); }
  .preset-btn[data-preset="all"] { grid-column: 1 / -1; }

  .chart-box { height: min(78vw, 260px); min-height: 220px; }
  .chart-sm { height: min(74vw, 240px); min-height: 200px; }

  .section-title { font-size: 14px; }
  .kpi-row { grid-template-columns: 1fr; }
  .kpi-value, .metric-value { font-size: 15px; }

  .data-table { font-size: 11px; }
  .data-table th, .data-table td { padding: 6px 8px; }

  .month-grid { grid-template-columns: repeat(2, 1fr); }
  .month-cell .month-pct { font-size: 14px; }

  .week-month-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px;
  }
  .week-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 12px;
  }
  .week-label { min-width: 0; }
}
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 12px 24px; border-radius: 8px;
  font-size: 14px; z-index: 999;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.toast.show { transform: translateX(-50%) translateY(0); }

.page-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.72);
  color: var(--text);
  font-size: 15px;
  z-index: 200;
}

.page-error {
  margin: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  background: rgba(231, 0, 11, 0.12);
  border: 1px solid rgba(231, 0, 11, 0.35);
  color: #ffb4b4;
  font-size: 14px;
}

.empty-hint {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 16px;
  font-size: 14px;
}

/* ---- 移动端：模块导航（上下半圆） ---- */
.section-nav-dock {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  z-index: 150;
  display: flex;
  flex-direction: column;
  width: 52px;
  border-radius: 26px;
  overflow: hidden;
  background: rgba(22, 27, 34, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(88, 96, 105, 0.45);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.section-nav-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: #79b8ff;
  cursor: pointer;
  transition:
    background 0.22s ease,
    color 0.22s ease,
    transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.section-nav-up {
  border-radius: 26px 26px 0 0;
}

.section-nav-down {
  border-radius: 0 0 26px 26px;
}

.section-nav-up::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(139, 148, 158, 0.35) 20%,
    rgba(139, 148, 158, 0.35) 80%,
    transparent 100%
  );
  pointer-events: none;
}

.section-nav-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.18s ease, opacity 0.22s ease;
}

.section-nav-btn:not(.is-disabled):active {
  background: rgba(56, 139, 253, 0.14);
  transform: scale(0.96);
}

.section-nav-btn:not(.is-disabled):active .section-nav-icon {
  transform: scale(0.92);
}

.section-nav-up:not(.is-disabled):active {
  color: #a5d3ff;
}

.section-nav-down:not(.is-disabled):active {
  color: #a5d3ff;
}

.section-nav-btn.is-disabled {
  color: #484f58;
  cursor: not-allowed;
  pointer-events: none;
}

.section-nav-btn.is-disabled .section-nav-icon {
  opacity: 0.38;
}

@media (min-width: 769px) and (max-width: 1199px) {
  .topbar-inner {
    padding-left: 50px;
    padding-right: 50px;
  }
  .dash-container {
    padding-left: 50px;
    padding-right: 50px;
  }
}

@media (min-width: 769px) {
  .section-nav-dock { display: none; }
}

/* ---- Toast ---- */