/* TradingView 视觉规范 —— 深色为默认, [data-theme="light"] 切浅色 */
:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel2: #2a2e39;
  --border: #363a45;
  --text: #d1d4dc;
  --muted: #787b86;
  --accent: #2962ff;
  --pos: #089981;
  --neg: #f23645;
  --pos-mid: #0d5c4d;
  --neg-mid: #8c2b33;
  --zero: #363a45;
  --tile-null: #2a2e39;
  --shadow: rgba(0, 0, 0, .5);
  --scrim: rgba(30, 34, 45, .88);
  --row-line: rgba(54, 58, 69, .45);
  --halo-shadow: rgba(0, 0, 0, .78);
  --legend-fade: rgba(19, 23, 34, .92);
  --tip-bg: rgba(30, 34, 45, .96);
  --font-ui: -apple-system, "Trebuchet MS", Roboto, "PingFang SC",
             "Microsoft YaHei", sans-serif;
  --font-num: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --topbar-h: 48px;
  --foot-h: 26px;
  --drawer-w: 372px;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f4f6f9;
  --panel2: #e6eaf0;
  --border: #d5dae3;
  --text: #131722;
  --muted: #6b7280;
  --accent: #1c4fd8;
  --pos: #067a68;
  --neg: #c62828;
  --pos-mid: #7ec7a8;
  --neg-mid: #f5a0a0;
  --zero: #e8ecf1;
  --tile-null: #dfe3ea;
  --shadow: rgba(19, 23, 34, .18);
  --scrim: rgba(255, 255, 255, .9);
  --row-line: rgba(120, 130, 148, .22);
  --halo-shadow: rgba(255, 255, 255, .85);
  --legend-fade: rgba(255, 255, 255, .94);
  --tip-bg: rgba(255, 255, 255, .97);
}
body.cb { --pos: #2962ff; --neg: #f7931a;
          --pos-mid: #1a3a80; --neg-mid: #8a5a1a; }
:root[data-theme="light"] body.cb { --pos: #2558e5; --neg: #d6760c;
          --pos-mid: #8aaeff; --neg-mid: #f6be82; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.num, td.num, .metric-v { font-family: var(--font-num);
  font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.muted { color: var(--muted); }

/* ---------- 顶栏 ---------- */
#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
  white-space: nowrap;
}
.brand { display: flex; align-items: baseline; gap: 7px; }
.brand-mark { color: var(--accent); font-size: 15px; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.brand-q { font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px; padding: 1px 6px; }
#tabs { display: flex; gap: 2px; height: 100%; }
#tabs a {
  display: flex; align-items: center; padding: 0 13px;
  color: var(--muted); text-decoration: none; font-size: 13px;
  border-bottom: 2px solid transparent; transition: color .15s;
}
#tabs a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 5%, transparent); }
#tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  font: 12px var(--font-ui); padding: 5px 11px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel2); color: var(--text);
  font-weight: 600; }
.seg button .sub { display: block; font-size: 9px; color: var(--muted); }

.search-box { position: relative; display: flex; align-items: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
  padding: 0 9px; color: var(--muted); }
.search-box:focus-within { border-color: var(--accent); }
.search-box input { border: 0; outline: 0; background: transparent;
  color: var(--text); font: 12px var(--font-ui); padding: 6px 7px;
  width: 190px; }
#searchDrop {
  position: absolute; top: calc(100% + 5px); left: 0; min-width: 300px;
  max-height: 380px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px var(--shadow); z-index: 50;
}
.sr-item { display: flex; align-items: center; gap: 8px;
  padding: 7px 11px; cursor: pointer; }
.sr-item:hover, .sr-item.sel { background: var(--panel2); }
.sr-badge { font-size: 10px; padding: 1px 5px; border-radius: 3px;
  border: 1px solid var(--border); color: var(--muted); flex: none; }
.sr-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sub { margin-left: auto; color: var(--muted); font-size: 11px;
  flex: none; }

.icon-btn { border: 1px solid var(--border); background: transparent;
  color: var(--muted); border-radius: 5px; width: 28px; height: 28px;
  cursor: pointer; font-size: 13px; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--panel2); }
.icon-btn.active { color: var(--accent); border-color: var(--accent); }

/* ---------- 视图区 ---------- */
#view { position: fixed; inset: var(--topbar-h) 0 var(--foot-h) 0; }
.view { position: absolute; inset: 0; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; }

.hero-head { position: absolute; top: 22px; left: 26px; pointer-events: none; }
.hero-head h1 { font-size: 26px; font-weight: 700; letter-spacing: .3px;
  text-shadow: 0 2px 14px var(--halo-shadow); }
.hero-head p { font-size: 12.5px; color: var(--muted); margin-top: 3px;
  text-shadow: 0 1px 8px var(--halo-shadow); }

.canvas-hint { position: absolute; top: 14px; right: 16px;
  font-size: 11px; color: var(--muted); opacity: .75; pointer-events: none; }

/* 底部主题图例(总览) */
.mm-legend { position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; gap: 4px; padding: 8px 14px;
  overflow-x: auto; scrollbar-width: thin;
  background: linear-gradient(transparent, var(--legend-fade) 38%);
}
.mm-legend .lg-item { display: flex; align-items: center; gap: 6px;
  flex: none; padding: 3px 9px; border-radius: 4px; cursor: pointer;
  font-size: 11.5px; color: var(--muted); border: 1px solid transparent;
  transition: all .15s; }
.mm-legend .lg-item:hover { color: var(--text); background: var(--panel); }
.mm-legend .lg-item.on { color: var(--text); border-color: var(--border);
  background: var(--panel); }
.lg-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* 色阶图例 */
.scale-legend { position: absolute; right: 14px; bottom: 34px;
  background: var(--scrim); border: 1px solid var(--border);
  border-radius: 5px; padding: 7px 10px; font-size: 10.5px;
  color: var(--muted); pointer-events: none; backdrop-filter: blur(4px); }
.scale-legend .bar { width: 170px; height: 8px; border-radius: 2px;
  margin: 5px 0 3px; }
.scale-legend .ticks { display: flex; justify-content: space-between;
  font-family: var(--font-num); }

/* 散点控制胶囊 */
.map-ctrl { position: absolute; top: 14px; left: 16px; display: flex;
  gap: 10px; align-items: center; }
.cat-legend { position: absolute; left: 16px; bottom: 34px; max-width: 300px;
  background: var(--scrim); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; backdrop-filter: blur(4px);
  max-height: 46vh; overflow-y: auto; scrollbar-width: thin; }
.cat-legend .lg-item { display: flex; align-items: center; gap: 7px;
  padding: 2.5px 5px; border-radius: 3px; cursor: pointer; font-size: 11.5px;
  color: var(--muted); }
.cat-legend .lg-item:hover { color: var(--text); background: var(--panel2); }
.cat-legend .lg-item.on { color: var(--text); background: var(--panel2); }
.cat-legend .lg-n { margin-left: auto; font-size: 10px;
  font-family: var(--font-num); }

/* ---------- 主题列表 ---------- */
#listWrap { position: absolute; inset: 0; overflow: auto; padding: 14px 16px; }
table.tv { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.tv thead th { position: sticky; top: -14px; background: var(--bg);
  color: var(--muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px;
  padding: 9px 10px 7px; text-align: right; cursor: pointer;
  border-bottom: 1px solid var(--border); user-select: none;
  white-space: nowrap; z-index: 2; }
table.tv thead th:first-child, table.tv thead th.left { text-align: left; }
table.tv thead th:hover { color: var(--text); }
table.tv thead th .arr { font-size: 9px; margin-left: 2px; }
table.tv tbody td { padding: 6.5px 10px;
  border-bottom: 1px solid var(--row-line); text-align: right;
  white-space: nowrap; }
table.tv tbody td.left { text-align: left; }
table.tv tbody tr { cursor: pointer; transition: background .1s; }
table.tv tbody tr:hover { background: var(--panel); }
.chip { display: inline-block; font-size: 10.5px; padding: 1.5px 7px;
  border-radius: 3px; font-weight: 600; }
.minibar { display: inline-block; height: 8px; border-radius: 2px;
  vertical-align: middle; margin-right: 6px; }

/* ---------- 抽屉 ---------- */
#drawer { position: fixed; top: var(--topbar-h); bottom: var(--foot-h);
  right: 0; width: var(--drawer-w); background: var(--panel);
  border-left: 1px solid var(--border); z-index: 25;
  transform: translateX(100%);
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; }
#drawer.open { transform: translateX(0); box-shadow: -12px 0 32px var(--shadow); }
#drawerClose { position: absolute; top: 10px; right: 10px; z-index: 2;
  border: 0; }
#drawerBody { overflow-y: auto; padding: 16px 16px 24px; flex: 1;
  scrollbar-width: thin; }
.d-title { font-size: 16px; font-weight: 700; line-height: 1.3;
  padding-right: 30px; }
.d-sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.d-sec { margin-top: 16px; }
.d-sec h4 { font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 7px; font-weight: 600; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 7px; }
.metric { background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 7px 9px; }
.metric .k { font-size: 10px; color: var(--muted); }
.metric .metric-v { font-size: 14.5px; font-weight: 600; margin-top: 2px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table td, .mini-table th { padding: 4.5px 6px; text-align: right;
  border-bottom: 1px solid var(--row-line); white-space: nowrap; }
.mini-table th { color: var(--muted); font-size: 10.5px; font-weight: 600;
  cursor: pointer; user-select: none; }
.mini-table td.left, .mini-table th.left { text-align: left; }
.mini-table tr.link { cursor: pointer; }
.mini-table tr.link:hover { background: var(--panel2); }
.d-note { font-size: 11px; color: var(--muted); margin-top: 8px;
  line-height: 1.5; }
.d-actions { display: flex; gap: 8px; margin-top: 12px; }
.btn { border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); border-radius: 5px; padding: 6px 12px;
  font: 12px var(--font-ui); cursor: pointer; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.spin { display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.hist { display: flex; align-items: flex-end; gap: 2px; height: 56px;
  margin-top: 4px; }
.hist .hb { flex: 1; border-radius: 2px 2px 0 0; min-height: 1px; }

/* ---------- tooltip ---------- */
#tooltip { position: fixed; z-index: 60; pointer-events: none;
  background: var(--tip-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 9px 12px; font-size: 12px;
  max-width: 300px; box-shadow: 0 8px 24px var(--shadow);
  backdrop-filter: blur(4px); line-height: 1.5; }
#tooltip .tt-title { font-weight: 700; font-size: 12.5px; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
#tooltip .tt-row .k { color: var(--muted); }
#tooltip .tt-warn { color: var(--muted); font-size: 10.5px; margin-top: 4px;
  border-top: 1px solid var(--border); padding-top: 4px; }

/* ---------- 底栏 / 加载 ---------- */
#foot { position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--foot-h); display: flex; align-items: center;
  padding: 0 14px; background: var(--panel);
  border-top: 1px solid var(--border); font-size: 10.5px;
  color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; z-index: 30; }
#loading { position: absolute; inset: 0; display: flex;
  flex-direction: column; gap: 14px; align-items: center;
  justify-content: center; }
.shimmer-block { height: 20px; width: 50%; border-radius: 6px;
  background: linear-gradient(100deg, var(--panel) 40%, var(--panel2) 50%,
    var(--panel) 60%);
  background-size: 200% 100%; animation: shim 1.2s linear infinite; }
@keyframes shim { to { background-position: -200% 0; } }
#loadFail { position: absolute; inset: 0; display: flex; flex-direction:
  column; gap: 12px; align-items: center; justify-content: center;
  color: var(--muted); }

@media (max-width: 1080px) {
  .search-box input { width: 120px; }
  #tabs a { padding: 0 9px; font-size: 12px; }
  .brand-q { display: none; }
}
@media (max-width: 900px) {
  #drawer { width: min(92vw, 380px); }
  .hero-head h1 { font-size: 20px; }
}
