:root {
  --bg: #070b14;
  --bg2: #0c1220;
  --panel: #0f1728;
  --panel2: #131d31;
  --line: #1e2b45;
  --text: #dbe4f2;
  --muted: #7f8ba3;
  --up: #ff4d5e;
  --down: #1ecb84;
  --accent: #4c8dff;
  --warn: #ffb020;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #070b14;
  background-image: radial-gradient(1200px 600px at 20% -10%, #122040 0%, transparent 55%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body { padding-bottom: 30px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: #080d18;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #ff4d5e, #ff8a3d);
  color: #fff; font-weight: 700; font-size: 20px;
  box-shadow: 0 6px 18px rgba(255, 77, 94, .3);
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .5px; }
.brand .sub { margin: 0; color: var(--muted); font-size: 12px; }

.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); color: var(--muted); background: var(--panel);
}
.pill.open { color: #ffd166; border-color: #6b5312; background: #2a2109; }
.pill.closed { color: #9fb0cc; }
.ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ts.warn { color: var(--warn); }
.auto { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
select, input, button { font-family: inherit; font-size: 13px; }

select, input[type=number], input[type=text], input:not([type]) {
  background: #0b1424; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; outline: none;
}
select:focus, input:focus { border-color: var(--accent); }

.btn {
  background: #16223a; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 14px; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, #2b62d9, #4c8dff); border-color: #4c8dff; color: #fff; }

main { max-width: 1500px; margin: 0 auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; }

/* ===== 指数卡片 ===== */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: 14px; }
.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  position: relative; overflow: hidden; display: flex; flex-direction: column;
}
.card::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 120px; height: 120px;
  border-radius: 50%; background: radial-gradient(circle, rgba(76,141,255,.16), transparent 70%);
}
.card .cname { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }
.card .price { font-size: 26px; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.card .chg { font-size: 13px; font-variant-numeric: tabular-nums; }
.card .met {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px;
  margin-top: auto; padding-top: 10px;
  border-top: 1px dashed var(--line); font-size: 11px; color: var(--muted);
}
.card .met span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card .met em { font-style: normal; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.card .met b {
  color: var(--text); font-weight: 600; font-size: 13px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

/* ===== 通用面板 ===== */
.grid2 { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; align-items: stretch; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; min-width: 0;
  display: flex; flex-direction: column;
  contain: layout style;
}
.grid2 > .panel .table-wrap { flex: 1 1 auto; max-height: none; }
.grid2 > .panel canvas { height: 260px; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-h h2 { margin: 0; font-size: 15px; letter-spacing: .3px; }
.hint { color: var(--muted); font-size: 11.5px; }

.tabs { display: flex; gap: 6px; }
.tabs button {
  background: #0b1424; color: var(--muted); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.tabs button.active { color: #fff; border-color: #33508a; background: #16233d; }
.tabs.sub { margin-bottom: 8px; }

/* ===== 赛道卡片 ===== */
.tracks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 10px; }
.track {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: linear-gradient(180deg, #101a2d, #0d1524);
  display: flex; flex-direction: column; height: 100%;
}
.track .th { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.track .tname { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px; flex: none;
  border: 1px solid #33415e; color: #a9b8d4;
}
.track .tag.main { color: #ff9d7a; border-color: #6b3a26; }
.track .tag.risk { color: #7fd7ff; border-color: #1e4b63; }
.track .tag.def { color: #ffd166; border-color: #63511f; }
.track .num {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px;
  font-size: 12px; color: var(--muted); margin: 4px 0 8px; font-variant-numeric: tabular-nums;
}
.track .num span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .num b { font-size: 13.5px; }
.chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: auto; }
.chip {
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
  padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: #0b1424; cursor: default;
}
.chip .cn { font-size: 11.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .cv { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.u { border-color: #50222b; }
.chip.d { border-color: #17452f; }

/* ===== 表格 ===== */
.table-wrap { overflow: auto; max-height: 420px; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; background: #0d1729; color: var(--muted);
  font-weight: 500; text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th:first-child, thead th.l { text-align: left; }
tbody td { padding: 6px 8px; border-bottom: 1px solid #142035; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody td.l { text-align: left; }
tbody tr:hover { background: #101c31; }
tbody td .code { color: var(--muted); font-size: 11px; margin-left: 4px; }
.rank { color: var(--muted); width: 22px; }

/* ===== 持仓表 ===== */
#holdTable td, #holdTable th { font-size: 12.5px; }

/* ===== 全市场排行：固定列宽、20 行、无横向滚动 ===== */
.rank-table { table-layout: fixed; width: 100%; }
.rank-table th, .rank-table td { overflow: hidden; text-overflow: ellipsis; }
.rank-table th:nth-child(1), .rank-table td:nth-child(1) { width: 24px; padding-left: 2px; padding-right: 2px; }
.rank-table th:nth-child(2), .rank-table td:nth-child(2) { width: 116px; }
.rank-table th:nth-child(3), .rank-table td:nth-child(3) { width: 54px; }
.rank-table th:nth-child(4), .rank-table td:nth-child(4) { width: 54px; }
.rank-table th:nth-child(5), .rank-table td:nth-child(5) { width: 58px; }
.rank-table th:nth-child(6), .rank-table td:nth-child(6) { width: 58px; }
.rank-table th:nth-child(7), .rank-table td:nth-child(7) { width: 60px; }
.rank-table th:nth-child(8), .rank-table td:nth-child(8) { width: 54px; }
.rank-table th:nth-child(9), .rank-table td:nth-child(9) { width: 54px; }
.rank-table th, .rank-table td { padding-left: 3px; padding-right: 3px; }
.grid2 > .panel .table-wrap { overflow-x: hidden; }

.tag-risk { color: var(--up); border: 1px solid #5b2530; padding: 0 6px; border-radius: 6px; font-size: 11px; }
.hold-form { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.hold-form label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
#holdMsg.ok { color: var(--down); }
#holdMsg.err { color: var(--up); }

/* ===== 图表 ===== */
canvas { width: 100%; height: 220px; display: block; }
.chart-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== 盘面温度 ===== */
.mood { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.mood .m {
  background: #0b1424; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; text-align: center;
}
.mood .m .k { font-size: 11px; color: var(--muted); }
.mood .m .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== 赛道逻辑 ===== */
.logic { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 1fr; gap: 10px; }
.logic .lg {
  background: #0b1424; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  height: 100%;
}
.logic .lg h3 { margin: 0 0 4px; font-size: 13px; }
.logic .lg p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.65; }

footer { max-width: 1500px; margin: 8px auto 0; padding: 10px 22px 0; color: #56617a; font-size: 11.5px; }
footer p { margin: 3px 0; }

@media (max-width: 1100px) {
  .grid2 { grid-template-columns: 1fr; }
  .tracks { grid-template-columns: 1fr 1fr; }
  .logic { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; }
  .tracks, .logic { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  main { padding: 12px; }
  .mood { grid-template-columns: repeat(3, 1fr); }
}
