/* ============================================================
   资金流向看板 — 视觉方向:暗色机构级交易终端
   墨蓝底 + 香槟金强调色,衬线大标题 + 等宽数字,克制而精确
   ============================================================ */

:root {
  --ink: #0a1220;
  --ink-raised: #101d33;
  --ink-raised-2: #142338;
  --ink-line: rgba(201, 162, 39, 0.16);
  --ink-line-soft: rgba(255, 255, 255, 0.06);

  --gold: #c9a227;
  --gold-bright: #e8c766;
  --gold-dim: rgba(201, 162, 39, 0.55);

  --text-primary: #eef1f6;
  --text-secondary: #93a0b4;
  --text-tertiary: #5b667a;

  --positive: #4fd1a5;
  --negative: #e2725b;

  --font-display: "Songti SC", "STSong", "Noto Serif SC", serif;
  --font-body: "PingFang SC", -apple-system, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text-primary);
  font-family: var(--font-body);
}

body {
  position: relative;
  min-height: 100vh;
}

/* 细颗粒纹理,避免大面积纯色平板感 */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.05;
  background-image: radial-gradient(rgba(255, 255, 255, 0.9) 0.6px, transparent 0.6px);
  background-size: 3px 3px;
  mix-blend-mode: overlay;
}

/* ---------------- Header ---------------- */

.topbar {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--ink-line);
  background:
    repeating-linear-gradient(90deg, var(--ink-line-soft) 0, var(--ink-line-soft) 1px, transparent 1px, transparent 96px),
    linear-gradient(180deg, #0c1626 0%, var(--ink) 100%);
}

.topbar-glow {
  position: absolute;
  top: -180px;
  left: -120px;
  width: 520px;
  height: 420px;
  background: radial-gradient(circle, rgba(201, 162, 39, 0.22) 0%, rgba(201, 162, 39, 0) 68%);
  pointer-events: none;
}

.topbar-inner {
  position: relative;
  z-index: 2;
  max-width: 1440px;
  margin: 0 auto;
  padding: 30px 32px 26px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold-dim);
  animation: fadeSlideUp 0.6s ease both;
}

.topbar-title h1 {
  margin: 0 0 22px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 14px;
  animation: fadeSlideUp 0.6s ease 0.05s both;
}

.month-tag {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  color: var(--gold);
  border: 1px solid var(--ink-line);
  border-radius: 20px;
  padding: 3px 14px;
  letter-spacing: 0.04em;
}

.kpi-row {
  display: flex;
  gap: 1px;
  flex-wrap: wrap;
  background: var(--ink-line);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  overflow: hidden;
}

.kpi-card {
  flex: 1 1 150px;
  background: var(--ink-raised);
  padding: 14px 20px;
  min-width: 150px;
  animation: fadeSlideUp 0.5s ease both;
}

.kpi-card.muted { background: #0d1728; }

.kpi-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.kpi-value {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
}

.kpi-card.muted .kpi-value { color: var(--text-secondary); }

/* stagger the KPI cards on load */
.kpi-card:nth-child(1) { animation-delay: 0.08s; }
.kpi-card:nth-child(2) { animation-delay: 0.14s; }
.kpi-card:nth-child(3) { animation-delay: 0.20s; }
.kpi-card:nth-child(4) { animation-delay: 0.26s; }
.kpi-card:nth-child(5) { animation-delay: 0.32s; }
.kpi-card:nth-child(6) { animation-delay: 0.38s; }

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------------- Tabs ---------------- */

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 0 32px;
  background: rgba(10, 18, 32, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--ink-line-soft);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  padding: 15px 18px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-tertiary);
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.tab-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold);
}
.tab-btn.active .tab-index { color: var(--gold-dim); }

/* ---------------- Main content ---------------- */

main {
  position: relative;
  z-index: 2;
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

.panel { display: none; animation: fadeSlideUp 0.35s ease both; }
.panel.active { display: block; }

.panel-head { margin-bottom: 18px; }
.panel-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
}
.panel-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-tertiary);
}

.controls {
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
}
.controls input[type="range"] {
  vertical-align: middle;
  margin: 0 10px;
  accent-color: var(--gold);
}
.threshold-val {
  font-family: var(--font-mono);
  color: var(--gold);
}
.hint {
  font-size: 11.5px;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
}
.hint::before {
  content: "◆ ";
  color: var(--gold-dim);
}

.checkbox-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox-label input { position: absolute; opacity: 0; }
.checkbox-box {
  width: 14px; height: 14px;
  border: 1px solid var(--ink-line);
  border-radius: 2px;
  display: inline-block;
  position: relative;
}
.checkbox-label input:checked + .checkbox-box { background: var(--gold); border-color: var(--gold); }
.checkbox-label input:checked + .checkbox-box::after {
  content: "";
  position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid var(--ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.chart {
  width: 100%;
  height: 560px;
  background: var(--ink-raised);
  border: 1px solid var(--ink-line-soft);
  border-radius: var(--radius);
  transition: border-color 0.25s ease;
  cursor: pointer;
}
.chart:hover { border-color: var(--ink-line); }

/* ---------------- Sankey + 钻取面板 双栏布局 ---------------- */

.flow-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}
.flow-layout .chart { margin: 0; }

.drill-panel {
  background: var(--ink-raised);
  border: 1px solid var(--ink-line-soft);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
}

.drill-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink-line-soft);
}
.drill-label {
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
}
.drill-selected {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-bright);
}

.view-toggle {
  margin-left: auto;
  display: inline-flex;
  border: 1px solid var(--ink-line);
  border-radius: 20px;
  overflow: hidden;
}
.toggle-btn {
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.toggle-btn.active { background: var(--gold); color: var(--ink); font-weight: 600; }
.toggle-btn:not(.active):hover { color: var(--text-secondary); }

.bar-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
}
.bar-col { display: flex; flex-direction: column; min-width: 0; }
.bar-col h4 {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}
.bar-chart { flex: 1; min-height: 320px; width: 100%; }

#panel-search .bar-pair { margin: 18px 0 8px; }
#panel-search .bar-chart { min-height: 280px; }
#panel-search .drill-head { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }

/* ---------------- Search ---------------- */

#search-box {
  width: 100%;
  max-width: 520px;
  padding: 12px 16px;
  font-size: 14px;
  font-family: var(--font-body);
  background: var(--ink-raised);
  border: 1px solid var(--ink-line-soft);
  border-radius: var(--radius);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
}
#search-box::placeholder { color: var(--text-tertiary); }
#search-box:focus { border-color: var(--gold-dim); }

.search-results {
  margin-top: 6px;
  max-width: 520px;
  max-height: 260px;
  overflow-y: auto;
}
.search-item {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.search-item:hover {
  background: var(--ink-raised-2);
  border-left-color: var(--gold);
  color: var(--text-primary);
}
.search-empty { padding: 9px 14px; color: var(--text-tertiary); font-size: 13px; }

.ego-summary { margin-top: 26px; animation: fadeSlideUp 0.3s ease both; }
.ego-summary h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}
.tag {
  font-family: var(--font-body);
  background: var(--ink-raised-2);
  border: 1px solid var(--ink-line);
  color: var(--gold);
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 20px;
}

#detail-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
  font-size: 13px;
}
#detail-table th, #detail-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--ink-line-soft);
  text-align: left;
}
#detail-table th {
  cursor: pointer;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.02em;
  user-select: none;
}
#detail-table th:hover { color: var(--gold); }
#detail-table td.col-amount, #detail-table th.col-amount { text-align: right; }
#detail-table td:nth-child(5) {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-primary);
}
#detail-table tbody tr { transition: background 0.15s ease; }
#detail-table tbody tr:hover { background: var(--ink-raised); }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- Footer ---------------- */

.pagefoot {
  position: relative;
  z-index: 2;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 32px 32px;
  font-size: 11.5px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

/* ============================================================
   移动端适配 — 平板断点:双栏挤成单栏之前先松一口气
   ============================================================ */
@media (max-width: 980px) {
  .flow-layout {
    grid-template-columns: 1fr;
  }
  .drill-panel { min-height: 0; }
}

/* ============================================================
   移动端适配 — 手机断点:桑基图和柱状图钻取面板改成上下堆叠,
   避免两栏并排在窄屏上挤成一团看不清
   ============================================================ */
@media (max-width: 640px) {
  .topbar-inner { padding: 20px 16px 18px; }
  .topbar-glow { width: 320px; height: 260px; top: -120px; left: -80px; }
  .topbar-title h1 { font-size: 22px; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
  .eyebrow { font-size: 10.5px; letter-spacing: 0.2em; }

  .kpi-row { gap: 1px; }
  .kpi-card { flex: 1 1 45%; min-width: 45%; padding: 10px 14px; }
  .kpi-value { font-size: 17px; }

  .tabs {
    padding: 0 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 12px 12px; font-size: 13px; white-space: nowrap; flex: 0 0 auto; }

  main { padding: 18px 14px 40px; }
  .panel-head h2 { font-size: 16.5px; }
  .panel-sub { font-size: 11.5px; }

  .controls { gap: 10px; }
  .hint { flex-basis: 100%; }

  /* 桑基图和右侧钻取面板改成上下堆叠,各自撑满宽度 */
  .flow-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .chart { height: 420px; }
  .drill-panel { padding: 14px; }
  .drill-selected { font-size: 15px; }

  /* 流入/流出两列柱状图在手机上也改成上下堆叠,否则每列窄到看不清标签 */
  .bar-pair { grid-template-columns: 1fr; gap: 18px; }
  .bar-chart { min-height: 260px; }
  #panel-search .bar-chart { min-height: 240px; }

  .view-toggle { margin-left: 0; }
  .drill-head { justify-content: flex-start; }

  #search-box { max-width: none; }
  .search-results { max-width: none; }

  /* 明细表列数多,手机上不换行、整行保持一行,靠左右滑动查看,比文字换行更可读 */
  #detail-table { min-width: 640px; }
  #detail-table th, #detail-table td { white-space: nowrap; }
}
