/* ==========================================================================
   COT·PRO — CFTC COT 数据分析终端
   专业金融终端风格 · Design Tokens · 高信息密度 · 深/浅色模式 · 响应式
   颜色语义：绝对数量 = 中性（白/灰白）；方向数据 = 红涨/绿跌
   热力色阶：低=绿 → 中=灰 → 高=橙 → 极高=红；缺失 = 独立深灰
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-num: "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas,
    "Roboto Mono", monospace;

  /* 方向语义（仅方向数据使用） */
  --up: #f0483e;        /* 正 / 多头 / 增 */
  --down: #00b578;      /* 负 / 空头 / 减 */
  --up-bg: rgba(240, 72, 62, 0.12);
  --down-bg: rgba(0, 181, 120, 0.12);

  /* 图表系列色（全站统一，中性指标不使用红绿方向语义） */
  --c-oi: #3d8bf0;          /* OI / 净持仓 主线：蓝 */
  --c-net: #3d8bf0;
  --c-price: #f5a623;       /* 价格：黄橙 */
  --c-z: #9a8cf0;           /* Z-Score：紫 */
  --c-cot: #3d8bf0;         /* COT Index：蓝 */
  --c-pct: #33b1c9;         /* 历史分位：青 */
  --c-spread: #e8b339;      /* 套利：黄 */
  --c-nr: #8a8f98;          /* 非报告：灰 */

  /* 热力色阶（COT Index / 历史分位 / %OI 分位共用） */
  --heat-0: #00b578;
  --heat-25: #4ade80;
  --heat-50: #788ea0;
  --heat-75: #f07a3c;
  --heat-100: #f0483e;
  --heat-na: #565d6b;       /* 缺失数据：独立深灰，与极低值区分 */

  /* 品牌 */
  --accent: #12b886;
  --accent-bg: rgba(18, 184, 134, 0.1);
  --accent-2: #3d8bf0;
  --warn: #f5a623;

  /* 分类色 */
  --c-agr: #e8b339;
  --c-energy: #e0533d;
  --c-metal: #9a8cf0;
  --c-rate: #3d8bf0;
  --c-fx: #33b1c9;
  --c-equity: #c678dd;
  --c-cryp: #f7931a;
  --c-other: #8a8f98;

  /* 几何 */
  --radius: 6px;            /* 卡片统一小圆角 6px */
  --radius-sm: 4px;
  --radius-lg: 8px;
  --topbar-h: 42px;
  --statusbar-h: 26px;
  --sidebar-w: 264px;
  --row-h: 30px;            /* 表格标准行高 */
  --th-h: 30px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.25);      /* 极弱阴影 */
  --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.35);     /* 浮层 */
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-0: #0b0e13;         /* app background */
  --bg-1: #10141c;         /* surface / panel */
  --bg-2: #151a24;         /* raised / hover */
  --bg-3: #1c2230;         /* active / input */
  --bg-4: #242c3d;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text-0: #e6eaf2;       /* primary text（含绝对数量） */
  --text-1: #aab4c5;       /* secondary */
  --text-2: #6b7688;       /* muted */
  --text-3: #4a5263;       /* faint */
  --num: #e6eaf2;          /* 绝对数量：灰白 */
  --scrollbar: #2a3242;
  --tooltip-bg: rgba(16, 20, 28, 0.97);
  --sticky-bg: #151a24;    /* sticky 单元格背景 */
  --mask: rgba(0, 0, 0, 0.55);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-0: #eef1f5;
  --bg-1: #f7f8fb;
  --bg-2: #ffffff;
  --bg-3: #eef1f6;
  --bg-4: #e3e7ee;
  --border: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.26);
  --text-0: #1a2333;
  --text-1: #46536b;
  --text-2: #7a8698;
  --text-3: #a8b0bf;
  --num: #1a2333;
  --scrollbar: #c3cad6;
  --tooltip-bg: rgba(255, 255, 255, 0.98);
  --sticky-bg: #ffffff;
  --mask: rgba(15, 23, 42, 0.4);
  --shadow-1: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-2: 0 8px 28px rgba(15, 23, 42, 0.16);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-0);
  background: var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; height: 100vh; }
.num, td.num, .mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }
button { font-family: inherit; }
:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 1px; }

/* ---------- Icon system（统一 outline 线性图标） ---------- */
.ico {
  width: 16px; height: 16px; flex: 0 0 auto;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px;
}
.ico-sm { width: 13px; height: 13px; }
.ico-lg { width: 18px; height: 18px; }

/* ---------- Top bar ---------- */
#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 10px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 50;
}
.tb-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 6px; white-space: nowrap; user-select: none; }
.brand-mark { color: var(--accent); display: inline-flex; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: 0.5px; }
.brand-accent { color: var(--accent); }
.brand-sub { font-size: 10px; color: var(--text-2); letter-spacing: 1px; text-transform: uppercase; margin-left: 6px; }

.icon-btn {
  width: 28px; height: 28px; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-1); font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-0); }
.icon-btn:active { background: var(--bg-4); }

.tb-center { flex: 1; display: flex; justify-content: center; min-width: 0; }
#report-type-bar {
  display: flex; align-items: center; gap: 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px;
}
.rt-group { display: flex; align-items: center; }
.rt-group + .rt-group { border-left: 1px solid var(--border); margin-left: 2px; padding-left: 2px; }
.rt-btn {
  border: none; background: transparent; color: var(--text-1);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.3px;
  padding: 4px 10px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.rt-btn:hover { color: var(--text-0); background: var(--bg-3); }
.rt-btn.active { background: var(--accent); color: #fff; }
.rt-group#rt-fop .rt-btn { font-size: 11px; color: var(--text-2); }
.rt-group#rt-fop .rt-btn.active { background: var(--accent-2); color: #fff; }

.tb-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lang-seg { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; display: inline-flex; }
.lang-seg .seg-btn {
  border: none; background: transparent; color: var(--text-2); font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 3px; cursor: pointer; line-height: 1.4;
  display: inline-flex; align-items: center; gap: 4px;
}
.lang-seg .seg-btn:hover { color: var(--text-0); }
.lang-seg .seg-btn.active { background: var(--accent); color: #fff; }

.search-box { position: relative; }
.search-box input {
  width: 210px; height: 28px; padding: 0 8px 0 28px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-0); font-size: 12px; outline: none;
  transition: border-color 0.12s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box .search-ico {
  position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
  color: var(--text-2); pointer-events: none; display: inline-flex;
}
.search-dropdown {
  position: absolute; top: 32px; right: 0; width: 380px; max-height: 420px; overflow: auto;
  background: var(--tooltip-bg); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-2); z-index: 200;
}
.search-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.search-item:hover { background: var(--bg-3); }
.search-item .si-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .si-code { color: var(--text-2); font-family: var(--font-num); font-size: 11px; }
.search-item .si-cat { font-size: 10px; padding: 1px 6px; border-radius: 3px; color: #fff; flex: 0 0 auto; }
.search-item .si-cot { font-family: var(--font-num); font-size: 11px; width: 64px; text-align: right; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text-0);
  border-radius: var(--radius-sm); padding: 4px 10px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--border-strong); background: var(--bg-3); }
.btn:active { background: var(--bg-4); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #10a87a; border-color: #10a87a; filter: none; }
.btn-danger { background: transparent; border-color: #e5484d; color: #e5484d; }
.btn-danger:hover { background: rgba(229, 72, 77, 0.12); border-color: #e5484d; color: #ff6b70; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 2px 8px; font-size: 11px; height: 22px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- Main layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 auto;
  background: var(--bg-1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  transition: margin-left 0.15s ease;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
#nav { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.nav-section { padding: 8px 0; border-bottom: 1px solid var(--border); }
.nav-section-grow { flex: 1; overflow: hidden; display: flex; flex-direction: column; border-bottom: none; }
.nav-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-2); padding: 4px 12px 6px; display: flex; justify-content: space-between; align-items: center;
}
.nav-count { font-family: var(--font-num); font-weight: 400; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 5.5px 12px; cursor: pointer;
  color: var(--text-1); font-size: 12.5px; border-left: 2px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-0); }
.nav-item.active {
  background: var(--accent-bg); color: var(--accent);
  border-left-color: var(--accent); font-weight: 600;
}
.nav-ico { width: 16px; display: inline-flex; color: var(--text-2); flex: 0 0 auto; }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-item:hover .nav-ico { color: var(--text-0); }

#market-tree { flex: 1; overflow: auto; padding-bottom: 10px; }
.tree-group { margin-top: 2px; }
.tree-group-head {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px; cursor: pointer;
  font-size: 12px; color: var(--text-1); user-select: none;
}
.tree-group-head:hover { background: var(--bg-2); }
.tree-group-head .tg-arrow { display: inline-flex; color: var(--text-2); transition: transform 0.12s; width: 12px; flex: 0 0 auto; }
.tree-group-head.open .tg-arrow { transform: rotate(90deg); }
.tree-group-head .tg-name { flex: 1; font-weight: 600; }
.tree-group-head .tg-count { font-family: var(--font-num); font-size: 10.5px; color: var(--text-2); }
.tg-dot { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.tree-items { display: none; }
.tree-group.open .tree-items { display: block; }
.tree-item {
  display: flex; align-items: center; gap: 6px; padding: 3px 12px 3px 30px; cursor: pointer;
  font-size: 12px; color: var(--text-1); white-space: nowrap; overflow: hidden;
}
.tree-item:hover { background: var(--bg-2); color: var(--text-0); }
.tree-item.active { color: var(--accent); background: var(--accent-bg); }
.tree-item .ti-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tree-item .ti-exch { font-size: 9.5px; color: var(--text-3); font-family: var(--font-num); }
.tree-item .ti-cot { font-family: var(--font-num); font-size: 10.5px; width: 34px; text-align: right; }

/* 移动端侧栏遮罩 */
#sidebar-mask {
  display: none; position: fixed; inset: var(--topbar-h) 0 var(--statusbar-h) 0;
  background: var(--mask); z-index: 85;
}
#sidebar-mask.show { display: block; }

/* ---------- Content ---------- */
#content { flex: 1; min-width: 0; overflow: auto; position: relative; background: var(--bg-0); }
.view { padding: 12px 14px 20px; }
.view-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--text-2); font-size: 12.5px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Loading skeleton ---------- */
.skel { position: relative; overflow: hidden; background: var(--bg-3); border-radius: 4px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  animation: skel 1.2s infinite;
}
@keyframes skel { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skel-table tbody td { padding: 0 !important; }
.skel-table .skel { height: 16px; margin: 5px 8px; }
.skel-chart { height: 220px; }

/* ---------- KPI strip ---------- */
.kpi-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; margin-bottom: 12px; }
.kpi-card {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0;
  min-height: 62px; justify-content: center;
  transition: border-color 0.12s;
}
.kpi-card:hover { border-color: var(--border-strong); }
.kpi-card .kpi-label {
  font-size: 10px; color: var(--text-2); letter-spacing: 0.6px; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-card .kpi-value {
  font-family: var(--font-num); font-size: 18px; font-weight: 700; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-card .kpi-sub {
  font-family: var(--font-num); font-size: 10.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-card .kpi-value.up { color: var(--up); }
.kpi-card .kpi-value.down { color: var(--down); }
.kpi-card .kpi-value.accent { color: var(--accent); }
.kpi-card .kpi-value.warn { color: var(--warn); }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px;
}
.panel-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 12.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.panel-title::before { content: ""; width: 3px; height: 13px; background: var(--accent); border-radius: 2px; }
.panel-body { padding: 10px 12px; }
.panel-head .spacer { flex: 1; }

/* ---------- Controls / inputs / select / tabs ---------- */
.control-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg .seg-btn {
  border: none; background: transparent; color: var(--text-1); font-size: 11.5px;
  padding: 3px 9px; border-radius: 3px; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.seg .seg-btn:hover { color: var(--text-0); background: var(--bg-3); }
.seg .seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.seg .seg-btn.active.alt { background: var(--accent-2); }
.field-label { font-size: 11px; color: var(--text-2); white-space: nowrap; }
select, input[type="text"], input[type="number"], input[type="search"], input[type="date"] {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-0); font-size: 12px; padding: 4px 7px; outline: none; height: 26px;
  transition: border-color 0.12s;
}
select:hover, input:hover { border-color: var(--border-strong); }
select:focus, input:focus { border-color: var(--accent); }
input[type="number"] { width: 90px; font-family: var(--font-num); }
input[type="date"] { font-family: var(--font-num); font-size: 11.5px; }
.filter-group { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-2); }
.filter-group input { width: 76px; }
.filter-group label { white-space: nowrap; }
.filter-group input::placeholder { color: var(--text-3); }

/* 详情页内部 Tabs（非一级导航） */
.dt-tabs { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.dt-tabs .seg-btn { border: none; background: transparent; color: var(--text-1); font-size: 11.5px; font-weight: 600; padding: 4px 12px; border-radius: 3px; cursor: pointer; white-space: nowrap; transition: background 0.12s, color 0.12s; }
.dt-tabs .seg-btn:hover { color: var(--text-0); background: var(--bg-3); }
.dt-tabs .seg-btn.active { background: var(--accent); color: #fff; }

/* 详情页 Sticky 条件栏 */
.dt-sticky {
  /* sticky top is relative to the scrollport of #content, whose top edge
     already sits below the topbar: top:0 pins the bar to the topbar */
  position: sticky; top: 0; z-index: 40;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  padding: 5px 14px; margin: 0 -14px 10px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: var(--shadow-1);
}
.dt-sticky .dt-sb-name { font-weight: 700; font-size: 12.5px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tables（统一 Table System） ---------- */
.table-wrap { overflow: auto; max-height: 62vh; }
table.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg-2); color: var(--text-2); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.4px; text-transform: uppercase; padding: 6px 8px; text-align: right;
  border-bottom: 1px solid var(--border-strong); white-space: nowrap; cursor: pointer; user-select: none;
  height: var(--th-h);
}
.data-table thead th:hover { color: var(--text-0); background: var(--bg-3); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th.sorted-asc::after { content: " ▲"; font-size: 9px; color: var(--accent); }
.data-table th.sorted-desc::after { content: " ▼"; font-size: 9px; color: var(--accent); }
.data-table tbody td { padding: 4.5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; height: var(--row-h); }
.data-table tbody tr { cursor: pointer; transition: background 0.08s; }
.data-table tbody tr:hover { background: var(--bg-2); }
.data-table tbody tr.row-extreme { background: linear-gradient(90deg, rgba(245, 166, 35, 0.08), transparent); }
.data-table .num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; color: var(--num); }
.data-table td.up { color: var(--up); }
.data-table td.down { color: var(--down); }
.data-table td.muted, .data-table td.na { color: var(--text-2); }
.data-table td.na { font-style: italic; cursor: help; }
.data-table .mname { font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
/* Sticky 首列 + Sticky 表头组合 */
.data-table th:first-child { position: sticky; left: 0; z-index: 6; background: var(--bg-2); }
.data-table td:first-child { position: sticky; left: 0; z-index: 3; background: var(--bg-1); }
.data-table tbody tr:hover td:first-child { background: var(--bg-2); }
.data-table tbody tr.row-extreme td:first-child { background: var(--bg-1); }
/* 两級表头（导出页） */
.data-table thead tr.group-th th { position: sticky; top: 0; z-index: 7; background: var(--bg-3); color: var(--text-1); cursor: default; }
.data-table thead tr.sub-th th { top: var(--th-h); }
.data-table thead tr.group-th th:first-child { left: 0; z-index: 9; }
.data-table thead tr.sub-th th:first-child { left: 0; z-index: 8; }

.data-table .badge {
  font-size: 9.5px; padding: 1px 6px; border-radius: 3px; font-weight: 600; letter-spacing: 0.3px;
  display: inline-block; vertical-align: 1px;
}
.badge-up { background: var(--up-bg); color: var(--up); }
.badge-down { background: var(--down-bg); color: var(--down); }
.badge-warn { background: rgba(245, 166, 35, 0.15); color: var(--warn); }
.badge-accent { background: rgba(18, 184, 134, 0.14); color: var(--accent); }
.badge-muted { background: var(--bg-4); color: var(--text-2); }
.data-table tbody tr.row-anomaly { background: linear-gradient(90deg, rgba(245, 166, 35, 0.05), transparent); }
.data-table tbody tr.row-anomaly:hover { background: var(--bg-2); }
.cat-chip {
  font-size: 10px; padding: 1px 7px; border-radius: 3px; color: #fff; font-weight: 600; white-space: nowrap;
  display: inline-block; vertical-align: 1px;
}
.pager { display: flex; align-items: center; gap: 10px; padding: 8px 4px 2px; font-size: 11.5px; color: var(--text-1); }
.pager .pager-info { font-family: var(--font-num); }
.table-empty { padding: 30px; text-align: center; color: var(--text-2); font-size: 12.5px; }
.table-loading { position: relative; }

/* ---------- Heatmap ---------- */
.heatmap-wrap { overflow: auto; }
.heatmap-canvas { display: block; }
.heat-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2); }
.heat-legend .grad { width: 140px; height: 10px; border-radius: 3px; display: inline-block; }
.heat-cell { cursor: pointer; }
.heat-row-label { font-size: 10.5px; color: var(--text-1); white-space: nowrap; padding-right: 8px; text-align: right; }
.heat-row-label:hover { color: var(--text-0); cursor: pointer; }
.heat-cat-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; color: var(--text-2); }
/* 时间热力图：左侧 sticky 标签列 + 右侧滚动画布 */
.hm-layout { display: flex; }
.hm-labels { position: sticky; left: 0; z-index: 5; background: var(--bg-1); flex: 0 0 auto; }

/* ---------- Scanner ---------- */
.scanner-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.col-picker { position: relative; }
.col-menu {
  position: absolute; top: 100%; right: 0; z-index: 100; min-width: 240px; max-height: 340px; overflow: auto;
  background: var(--tooltip-bg); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 8px;
}
.col-menu label { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 3px 4px; cursor: pointer; color: var(--text-1); }
.col-menu label:hover { color: var(--text-0); }
.col-menu .col-group-title { font-size: 11px; font-weight: 700; color: var(--text-2); padding: 6px 4px 2px; border-top: 1px solid var(--border); margin-top: 4px; }

/* ---------- Compare ---------- */
.compare-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.compare-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 14px; padding: 2px 6px 2px 9px; font-size: 11.5px;
  max-width: 220px;
}
.chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .chip-x { cursor: pointer; color: var(--text-2); padding: 1px 3px; border-radius: 4px; display: inline-flex; }
.chip .chip-x:hover { color: var(--up); background: var(--up-bg); }
.chip .chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- Detail ---------- */
.detail-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.detail-header > div:first-child { min-width: 0; flex: 1; }
.detail-title { font-size: 17px; font-weight: 800; letter-spacing: 0.3px; }
.detail-sub { font-family: var(--font-num); font-size: 11.5px; color: var(--text-2); }
.chart-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.chart-panel { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.chart-panel .cp-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--border); font-size: 11.5px; font-weight: 600; color: var(--text-1);
}
.chart-panel .cp-head .cp-title { display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-panel .cp-head .cp-title::before { content: ""; width: 8px; height: 8px; border-radius: 2px; }
.chart-box { width: 100%; height: 240px; }
.chart-box.tall { height: 300px; }
.chart-box.short { height: 150px; }

/* 指标定义 Tooltip（详情 KPI） */
.metric-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; border-radius: 50%;
  border: 1px solid var(--text-2); color: var(--text-2);
  font-size: 9px; font-weight: 700; cursor: help; vertical-align: 1px; margin-left: 4px;
  font-style: normal; font-family: var(--font-ui);
}
.metric-tip:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Status bar ---------- */
#statusbar {
  height: var(--statusbar-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--bg-1); border-top: 1px solid var(--border);
  font-family: var(--font-num); font-size: 10.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden;
}
#statusbar .spacer { flex: 1; }
#statusbar .sep { color: var(--text-3); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 44px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); color: var(--text-0); border: 1px solid var(--border-strong);
  padding: 8px 16px; border-radius: var(--radius); font-size: 12px; box-shadow: var(--shadow-2); z-index: 300;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .brand-sub { display: none; }
  .search-box input { width: 150px; }
  .kpi-strip { grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 820px) {
  .np-summary { gap: 8px; padding: 6px 8px; }
  .np-chip { font-size: 10.5px; }
  #sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: var(--statusbar-h); z-index: 90; box-shadow: var(--shadow-2); }
  #sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
  #report-type-bar .rt-btn { padding: 4px 7px; font-size: 10.5px; }
  .search-box input { width: 110px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .chart-box { height: 200px; }
  #statusbar { font-size: 9.5px; }
}
@media (max-width: 640px) {
  /* two-row topbar: row 1 = brand/search/lang/theme, row 2 = report types */
  :root { --topbar-h: 72px; }
  #topbar { flex-wrap: wrap; height: var(--topbar-h); align-content: center; gap: 4px 8px; padding: 4px 6px; }
  .tb-left { order: 1; flex: 0 0 auto; }
  .tb-right { order: 2; margin-left: auto; flex: 0 0 auto; }
  .tb-center { order: 3; flex: 1 1 100%; justify-content: flex-start; overflow-x: auto; max-width: 100%; }
  #report-type-bar { flex: 0 0 auto; }
  .brand-name { font-size: 12.5px; }
  .brand-mark { display: none; }
  .rt-btn { padding: 3px 6px; font-size: 10px; }
  .search-box input { width: 96px; }
  .lang-seg .seg-btn { padding: 1px 5px; font-size: 10px; }
  .view { padding: 8px 8px 14px; }
  .kpi-strip { gap: 6px; margin-bottom: 8px; }
  .kpi-card { padding: 6px 8px; min-height: 56px; }
  .kpi-value { font-size: 15px; }
  .kpi-label { font-size: 9px; }
  .kpi-sub { font-size: 9.5px; }
  .chart-box { height: 160px !important; }
  .table-wrap { max-height: 55vh; }
  .data-table { min-width: 900px; }          /* keep columns usable, horizontal scroll */
  #ov-cats .cat-sum { grid-template-columns: 92px 38px 68px 80px 62px 62px 1fr; font-size: 10.5px; gap: 6px; }
  .detail-title { font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-sub { font-size: 9.5px; }
  .dt-sb-name { max-width: 140px; }
  .control-bar { gap: 6px; }
  .seg .seg-btn { padding: 2px 6px; font-size: 10.5px; }
  .np-summary .dist-bar { min-width: 140px; }
  .search-dropdown { width: 300px; right: auto; left: 0; }
  .dt-sticky { margin: 0 -8px 8px; padding: 5px 8px; }
}

/* ---------- Percentile report: net position distribution bar ---------- */
.dist-bar {
  position: relative; display: block; height: 12px; border-radius: 3px;
  background: var(--bg-4); overflow: visible; cursor: help;
}
.dist-fill {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px;
  background: linear-gradient(90deg, var(--heat-0), var(--heat-25), var(--heat-50), var(--heat-75), var(--heat-100));
  opacity: 0.55;
}
.dist-bar i { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--text-1); opacity: 0.85; z-index: 1; }
.dist-dot {
  top: 50% !important; transform: translate(-50%, -50%);
  width: 9px !important; height: 9px !important; border-radius: 50%;
  background: var(--bg-1) !important; border: 2px solid var(--text-1);
  opacity: 1 !important; z-index: 2;
}
.dist-dot.dot-up { border-color: var(--up); }
.dist-dot.dot-down { border-color: var(--down); }

/* ---------- Detail: net %OI historical percentile panel ---------- */
.np-summary {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
}
.np-summary .dist-bar { flex: 1; min-width: 200px; }
.np-chip { font-size: 11px; color: var(--text-1); white-space: nowrap; font-family: var(--font-num); }
.np-chip b { color: var(--text-0); font-weight: 600; }

/* Export view multi-select dropdowns: anchor to the left edge of the trigger */
.msel .col-menu { right: auto; left: 0; }

/* Latest-report table: fold + drag-sort */
tr.drag-src { opacity: 0.5; }
tr.drag-over { outline: 1px dashed var(--accent); background: var(--bg-3) !important; }
#dt-fold { cursor: pointer; }

/* Chart panels: collapse + drag reorder */
.cp-fold {
  cursor: pointer; font-size: 11px; font-weight: 700; color: var(--text-1);
  background: var(--bg-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 1px 6px; margin-right: 6px; user-select: none;
  line-height: 1.6; min-width: 22px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.cp-fold:hover { background: var(--bg-4); color: var(--accent); border-color: var(--accent); }
.cp-grip { user-select: none; display: inline-flex; color: var(--text-2); cursor: grab; }
.chart-panel.drag-src { opacity: 0.55; }
.chart-panel.drag-over { outline: 1px dashed var(--accent); }
.chart-panel .cp-head { cursor: grab; touch-action: pan-y; }
.chart-panel .cp-head:active { cursor: grabbing; }

/* Overview category distribution legend: 0-100 decile scale */
.cat-legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-2); }
.cat-legend .grad { width: 180px; height: 10px; border-radius: 3px; display: inline-block; }
.dl-scale { display: inline-flex; gap: 8px; font-family: var(--font-num); font-size: 9px; color: var(--text-3); }
.dl-tick { width: 16px; text-align: center; }
.na-chip {
  display: inline-block; font-size: 9.5px; font-weight: 600; letter-spacing: 0.3px;
  background: var(--heat-na); color: #d8dce4; border-radius: 3px; padding: 1px 6px; cursor: help;
}
@media (max-width: 1100px) { .dl-scale { display: none; } .cat-legend .grad { width: 120px; } }

/* Export table: two-level header + sticky date & market columns */
.ev-table { min-width: 1100px; }
.ev-table th.sticky-date, .ev-table td.sticky-date { position: sticky; left: 0; z-index: 8; background: var(--bg-2); }
.ev-table td.sticky-date { background: var(--bg-1); z-index: 4; }
.ev-table th.sticky-mkt, .ev-table td.sticky-mkt { position: sticky; left: 96px; z-index: 7; background: var(--bg-2); min-width: 220px; }
.ev-table td.sticky-mkt { background: var(--bg-1); z-index: 4; }
.ev-table tbody tr:hover td.sticky-date, .ev-table tbody tr:hover td.sticky-mkt { background: var(--bg-2); }
.ev-table thead tr.sub-th th.sticky-date { z-index: 10; }
.ev-table thead tr.sub-th th.sticky-mkt { z-index: 9; }
.ev-table thead tr.group-th th { top: 0; }
.ev-table thead tr.sub-th th { top: var(--th-h); }
.ev-table th.dir-h { color: var(--text-2); }
.ev-table th.sp-th { background: var(--bg-3); }

/* ---------- Mobile filter bottom sheet ---------- */
.filter-toggle { display: none; align-items: center; gap: 5px; }
.filter-sheet-mask {
  display: none; position: fixed; inset: 0; background: var(--mask); z-index: 95;
}
.filter-sheet-mask.show { display: block; }
.filter-sheet { position: relative; }
@media (max-width: 820px) {
  .filter-toggle { display: inline-flex; }
  .filter-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 96;
    max-height: 70vh; overflow: auto;
    background: var(--bg-1); border-top: 1px solid var(--border-strong);
    border-radius: 10px 10px 0 0; box-shadow: 0 -6px 28px rgba(0,0,0,0.35);
    transform: translateY(105%); transition: transform 0.18s ease;
    padding: 10px 12px;
  }
  .filter-sheet.open { transform: translateY(0); }
  .filter-sheet .scanner-filters { border-bottom: none; padding: 0; }
  .filter-sheet .filter-group { width: 100%; }
  .filter-sheet .filter-group input, .filter-sheet .filter-group select { flex: 1; width: auto !important; }
}

/* overview category summary (migrated from inline <style> in native overview.js) */
.cat-sum { display:grid; grid-template-columns: 110px 52px 90px 110px 76px 76px 1fr; gap:10px; align-items:center; padding:6px 8px; border-radius:4px; font-size:12px; cursor:pointer; }
.cat-sum:hover { background: var(--bg-2); }
.cat-sum .muted { color: var(--text-2); font-family: var(--font-num); font-size:11px; }
.cat-heat { display:flex; gap:2px; align-items:stretch; height:16px; min-width:160px; }
.ch-seg { border-radius:2px; cursor:help; }
.cat-sum .warn { color: var(--warn); font-weight:600; }

/* search box: id-scoped padding so the icon never overlaps the placeholder
   (the generic input rule below wins on equal specificity otherwise) */
#global-search input { padding: 0 8px 0 28px; }

/* keep market names to their keywords on phones/tablets; full name via title */
@media (max-width: 820px) {
  .detail-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .cp-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-header { min-width: 0; }
}
