:root {
  color-scheme: light;
  --app-bg: #eef2f7;
  --sidebar: #101828;
  --sidebar-soft: #1d2939;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #17202c;
  --muted: #667085;
  --line: #d9e2ee;
  --line-strong: #b8c6d8;
  --red: #df4248;
  --red-soft: #fff0f0;
  --blue: #2563eb;
  --blue-soft: #eaf2ff;
  --green: #15936c;
  --green-soft: #e9f8f1;
  --yellow: #b98218;
  --shadow: 0 18px 45px rgba(16, 24, 40, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--app-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.topbar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 248px;
  padding: 26px 22px;
  background: var(--sidebar);
  color: #fff;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar::after {
  content: "选号 · 回测 · 模拟";
  display: block;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #9fb0c7;
  font-size: 12px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: inherit;
  opacity: 0.66;
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  margin-top: 18px;
  border: 1px solid rgba(125, 211, 252, 0.24);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(20, 184, 166, 0.14);
  color: #9df4d3;
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  width: auto;
  margin-left: 248px;
  padding: 28px clamp(22px, 3.2vw, 44px) 56px;
}

.nav-tabs {
  position: fixed;
  left: 22px;
  top: 190px;
  z-index: 35;
  width: 204px;
  display: grid;
  gap: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 42px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 14px;
  background: transparent;
  color: #cbd5e1;
  white-space: nowrap;
}

.nav-tab:hover {
  background: var(--sidebar-soft);
  border-color: rgba(255, 255, 255, 0.08);
  color: #fff;
  transform: none;
}

.nav-tab.active {
  border-color: rgba(255, 255, 255, 0.16);
  background: #ffffff;
  color: var(--sidebar);
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.risk-note {
  margin-left: 248px;
  border: 0;
  border-bottom: 1px solid #f0db9c;
  padding: 12px clamp(22px, 3.2vw, 44px);
  background: #fff8e7;
  color: #6a4e0c;
  font-size: 13px;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(300px, 0.75fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.home-copy,
.home-latest {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.home-copy {
  padding: 28px;
}

.home-copy h2 {
  max-width: 680px;
  margin-bottom: 10px;
  font-size: clamp(30px, 4.6vw, 54px);
  line-height: 1.05;
}

.home-copy p {
  max-width: 620px;
  margin-bottom: 0;
  font-size: 15px;
}

.home-latest {
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 22px;
}

.home-latest strong {
  font-size: 42px;
  line-height: 1;
}

.home-latest .ball-row {
  justify-content: flex-start;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.quick-action,
.hub-card {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 112px;
  border-color: #cad6e8;
  padding: 18px;
  text-align: left;
  background: #fff;
}

.quick-action strong,
.hub-card strong,
.strategy-item strong {
  font-size: 18px;
}

.quick-action span,
.hub-card span,
.strategy-item span {
  color: var(--muted);
  font-size: 13px;
}

.quick-action.primary,
.hub-card.primary {
  border-color: var(--sidebar);
  background: var(--sidebar);
  color: #fff;
}

.quick-action.primary span,
.hub-card.primary span {
  color: #d6e1ef;
}

.home-strategy-panel {
  margin-bottom: 12px;
}

.home-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
  font-size: 13px;
}

.home-meta strong {
  color: var(--text);
}

.latest-band {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) 1fr;
  gap: 24px;
  align-items: center;
  margin-bottom: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.latest-band h2 {
  font-size: clamp(34px, 6vw, 60px);
  line-height: 0.95;
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.ball {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.13), 0 8px 16px rgba(223, 66, 72, 0.16);
}

.ball.blue {
  background: var(--blue);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.13), 0 8px 16px rgba(37, 99, 235, 0.18);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.metric-card {
  min-height: 106px;
  padding: 18px;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02);
}

.metric-label,
.hint,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1.05;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02);
}

#watchlist > .panel:first-child {
  position: relative;
  overflow: hidden;
  padding: 22px;
  border-color: #c9d6e8;
  box-shadow: var(--shadow);
}

#watchlist > .panel:first-child::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--red), var(--blue), var(--green));
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head p {
  margin: 6px 0 0;
}

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

.strategy-item {
  display: grid;
  gap: 5px;
  min-height: 86px;
  padding: 14px;
  text-align: left;
  background: #fff;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
}

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

.filter-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.78fr) minmax(420px, 1.22fr);
  gap: 18px;
}

.watch-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(360px, 0.95fr);
  gap: 18px;
}

.rank-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.rank-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-soft);
}

.rank-item strong {
  display: block;
  color: var(--red);
  font-size: 19px;
}

.blue-list .rank-item strong {
  color: var(--blue);
}

.bar-chart {
  display: grid;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: 58px 1fr 48px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e9eef4;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--yellow);
}

.form-panel {
  align-self: start;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--text);
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.form-actions button,
.simulation-form button,
#refreshDraws,
#refreshWatchlist,
#clearSettledWatch {
  border-color: var(--sidebar);
  background: var(--sidebar);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
}

.inline-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.simulation-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(92px, 0.6fr) minmax(100px, 0.6fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.simulation-hub {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(130px, 0.5fr);
  gap: 12px;
  align-items: stretch;
  margin-bottom: 16px;
}

.simulation-hub label {
  justify-content: center;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.manual-simulation {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}

.manual-simulation summary {
  cursor: pointer;
  font-weight: 700;
}

.candidate-list,
.draw-list,
.strategy-cards,
.backtest-list,
.experiment-summary,
.ai-list,
.watch-list {
  display: grid;
  gap: 10px;
}

.candidate-item,
.draw-item,
.strategy-card,
.backtest-item,
.summary-chip,
.ai-item,
.watch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-soft);
}

.candidate-item {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) auto;
  background: #fff;
}

.candidate-item .ball-row,
.watch-main .ball-row {
  justify-content: flex-start;
}

.draw-meta {
  min-width: 112px;
}

.strategy-card,
.backtest-item {
  align-items: flex-start;
}

.strategy-card p,
.backtest-item p {
  margin: 4px 0 0;
}

.strategy-card-actions,
.candidate-actions,
.watch-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.candidate-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.candidate-meta strong {
  color: var(--text);
}

.watch-add-button {
  min-width: 92px;
  border-color: transparent;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.18);
}

.watch-counts {
  margin-bottom: 12px;
}

.watch-counts .metric-card:first-child {
  border-color: #c7d7fe;
  background: linear-gradient(180deg, #fff, #f3f7ff);
}

.watch-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 172px auto;
  align-items: center;
  background: #fff;
}

.watch-hit {
  border-color: #f0c2b9;
  background: #fff7f4;
}

.watch-main {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.watch-meta {
  display: grid;
  gap: 4px;
  font-size: 13px;
}

.watch-meta span {
  color: var(--muted);
}

.watch-result {
  display: grid;
  gap: 5px;
  min-width: 132px;
  font-size: 13px;
  justify-items: start;
}

.watch-badge {
  width: fit-content;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eef2ef;
  color: var(--muted);
  font-weight: 800;
}

.watch-badge.win {
  background: var(--red-soft);
  color: var(--red);
}

.watch-badge.miss {
  background: #ecefeb;
  color: var(--muted);
}

.watch-badge.pending {
  background: var(--blue-soft);
  color: var(--blue);
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 18px;
  color: var(--muted);
  background: var(--surface-soft);
}

@media (max-width: 1020px) {
  .metric-grid,
  .metric-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-layout,
  .watch-layout,
  .analysis-grid,
  .strategy-layout,
  .home-hero,
  .quick-actions,
  .simulation-hub {
    grid-template-columns: 1fr;
  }

  .strategy-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    width: auto;
    padding: 18px 16px;
    background: var(--sidebar);
  }

  .topbar::after {
    display: none;
  }

  h1 {
    font-size: 26px;
  }

  .risk-note,
  .layout {
    margin-left: 0;
  }

  .layout {
    padding: 0 14px 48px;
  }

  .risk-note {
    padding: 10px 14px;
  }

  .nav-tabs {
    position: sticky;
    left: auto;
    right: auto;
    top: 0;
    bottom: auto;
    z-index: 40;
    width: auto;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 0 -14px 18px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    border-top: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
  }

  .nav-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 72px;
    justify-content: center;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 0 10px;
  }

  .nav-tab.active {
    background: var(--sidebar);
    color: #fff;
  }

  .latest-band {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .ball-row {
    justify-content: flex-start;
  }

  .rank-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .status-pill {
    margin-top: 12px;
  }

  .metric-grid,
  .metric-grid.compact,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .candidate-item,
  .watch-item {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .draw-item,
  .strategy-card,
  .backtest-item,
  .toolbar,
  .panel-head,
  .inline-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .candidate-actions,
  .watch-actions,
  .watch-result {
    width: 100%;
  }

  .watch-add-button,
  .simulation-form,
  .watch-actions button {
    width: 100%;
  }

  .simulation-form {
    grid-template-columns: 1fr;
  }

  .home-copy {
    padding: 20px;
  }

  .home-copy h2 {
    font-size: 32px;
  }
}
