/* ETF flow tracker - page styles. Light theme, GitHub-like palette, no web fonts (works offline / in mainland China). */
:root {
  --bg: #ffffff;
  --card: #f6f8fa;
  --border: #d0d7de;
  --line: #eaeef2;
  --text: #1f2328;
  --muted: #57606a;
  --faint: #8b949e;
  --up: #cf222e;      /* A-share convention: up / inflow = red */
  --down: #1a7f37;    /* down / outflow = green */
  --tab: #1f6feb;
  --range: #238636;
  --accent: #58a6ff;
  --font: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", system-ui, sans-serif;
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.6 var(--font); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 56px; }

/* ---------- header ---------- */
.page-head h1 { font-size: 22px; font-weight: 700; line-height: 1.4; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.page-head .src { color: var(--muted); font-size: 12px; margin-top: 10px; }
.page-head .src .ex { white-space: nowrap; }
.page-head .notice { color: var(--up); font-size: 12px; margin-top: 3px; }
.page-head .note { color: var(--muted); font-size: 12px; margin-top: 3px; }
.page-head .updated { color: var(--faint); font-size: 12px; margin-top: 3px; }

h2 {
  font-size: 17px; font-weight: 700; line-height: 1.4; color: var(--text);
  margin-bottom: 10px; padding-left: 10px; border-left: 3px solid var(--accent);
}

/* ---------- tables ---------- */
.tbl {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 12px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th.tl, td.tl { text-align: left; }
th { background: var(--card); color: var(--muted); font-weight: 600; }
tbody tr + tr { border-top: 1px solid var(--line); }
tbody tr:hover { background: #f6f8fa; }
td.empty { text-align: center; color: var(--faint); }
.up { color: var(--up); }
.down { color: var(--down); }

/* summary grid: left table spans both rows, two TOP-5 tables stacked on the right */
.tbl-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: 1fr 1fr;
  gap: 16px; margin-top: 22px;
}
.tbl-grid > section { display: flex; flex-direction: column; min-width: 0; }
.tbl-grid .span2 { grid-row: 1 / 3; }
.tbl-grid .tbl { flex: 1 1 auto; display: flex; flex-direction: column; }
.tbl-grid .tbl table { flex: 1 1 auto; }

/* ---------- controls ---------- */
.controls { margin-top: 24px; }
.tabs, .ranges { display: flex; flex-wrap: wrap; gap: 8px; }
.ranges { margin-top: 8px; }
.tabs button, .ranges button {
  cursor: pointer; background: var(--card); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  font: 600 13px/1.6 var(--font); padding: 5px 14px;
  transition: color .15s, border-color .15s, background-color .15s;
}
.ranges button { font-size: 12px; padding: 3px 12px; }
.tabs button:hover, .ranges button:hover { color: var(--text); border-color: var(--faint); }
.tabs button.active { background: var(--tab); border-color: var(--tab); color: #fff; }
.ranges button.active { background: var(--range); border-color: var(--range); color: #fff; }
button:focus-visible { outline: 2px solid var(--tab); outline-offset: 2px; }
.noscript { margin-top: 12px; color: var(--up); font-size: 13px; }

/* ---------- chart sections ---------- */
.cat { display: none; margin-top: 30px; }
.cat.active { display: block; }
.cat h2 { font-size: 18px; }
.card {
  position: relative; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; margin-top: 14px; overflow: hidden;
}
.card h3 { font-size: 14px; font-weight: 600; line-height: 1.5; color: var(--text); padding: 12px 16px 0; }
.chart { width: 100%; height: 420px; }
.chart.short { height: 340px; }
.chart-msg {
  display: flex; align-items: center; justify-content: center; height: 100%;
  padding: 24px 12px; color: var(--faint); font-size: 13px; text-align: center;
}
.chart-msg.err { color: var(--muted); }

/* floating list of a subcategory's ETFs (legend / line hover); max-height keeps it inside the card (which clips),
   app.js lists only as many names as fit (at most 60, 12 on narrow charts) */
.etf-pop {
  position: absolute; top: 46px; right: 12px; z-index: 8; display: none; pointer-events: none;
  max-width: min(600px, calc(100% - 24px)); max-height: calc(100% - 54px); overflow: hidden; padding: 6px 10px;
  background: rgba(255, 255, 255, .96); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 2px 8px rgba(31, 35, 40, .08);
  font-size: 12px; line-height: 1.7; color: var(--muted); text-align: left;
}
.etf-pop b { color: var(--text); }
.etf-pop .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.etf-pop .l { font-size: 11px; line-height: 1.55; margin-top: 2px; }
.etf-pop .more { color: var(--faint); }

/* ECharts axis tooltip content; fixed px line heights: app.js (TT_FIXED_H, TT_ROW_H) lists only the rows that fit */
.tt-h { font-weight: 600; color: var(--text); line-height: 18px; margin-bottom: 2px; }
.tt-r { display: flex; align-items: center; gap: 4px; line-height: 20px; }
.tt-n { flex: 1 1 auto; padding-right: 14px; color: var(--muted); }
.tt-v { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.tt-more { color: var(--faint); line-height: 20px; }

/* ---------- overview table ---------- */
.overview { margin-top: 36px; }
.overview .hint { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }
.sortable th { padding: 0; }
.sortable td { padding-left: 9px; padding-right: 9px; }
.sortable th button {
  display: block; width: 100%; padding: 7px 9px; border: 0; background: none;
  font: inherit; color: inherit; text-align: inherit; white-space: nowrap; cursor: pointer;
}
.sortable th button:hover { color: var(--text); }
.sortable th button::after {
  content: "\2195"; display: inline-block; width: 12px; margin-left: 1px;
  font-size: 11px; color: var(--border); text-align: center;
}
.sortable th[aria-sort="descending"] button::after { content: "\25BC"; color: var(--tab); font-size: 9px; }
.sortable th[aria-sort="ascending"] button::after { content: "\25B2"; color: var(--tab); font-size: 9px; }
.sortable td.cat-name { color: var(--muted); }

/* ---------- footer ---------- */
.foot {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; line-height: 1.8;
}
.foot p + p { margin-top: 4px; }

/* ---------- narrow screens ---------- */
@media (max-width: 960px) {
  th, td { padding: 7px 9px; }
  .sortable th { padding: 0; }
  .sortable th button { padding: 7px 9px; }
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .wrap { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 19px; }
  h2 { font-size: 16px; }
  .cat h2 { font-size: 17px; }
  .tbl-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; }
  .tbl-grid .span2 { grid-row: auto; }
  th, td { padding: 6px 8px; }
  .sortable td { padding-left: 8px; padding-right: 8px; }
  .sortable th button { padding: 6px 8px; }
  /* keep 细分行业 visible while the wide overview table scrolls sideways; 大类 scrolls away (pinning both
     would leave less than one data column on a phone) */
  .sortable th:nth-child(2), .sortable td:nth-child(2) {
    position: sticky; left: 0; z-index: 1; background: #fff; box-shadow: 1px 0 0 var(--line);
  }
  .sortable th:nth-child(2) { background: var(--card); }
  .tabs button { padding: 4px 11px; }
  .card h3 { font-size: 13px; padding: 10px 12px 0; }
  .chart { height: 360px; }
  .chart.short { height: 300px; }
  .etf-pop { top: 40px; right: 8px; max-width: calc(100% - 16px); max-height: calc(100% - 48px); }
}
