:root {
  --bg: #f5f7fb;
  --ink: #132238;
  --muted: #667085;
  --line: #d9e0ea;
  --panel: #ffffff;
  --green: #15a979;
  --red: #d84848;
  --blue: #3366d6;
  --teal: #2eb8b8;
  --yellow: #f2b90c;
  --orange: #ef7d32;
  --violet: #7d5cc6;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

.dashboard-shell {
  width: min(1600px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 0 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #356b70;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.run-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.run-meta span {
  padding: 7px 10px;
  background: #e9eef5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 24px rgba(23, 34, 56, 0.05);
}

.metric {
  min-height: 112px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric.primary {
  border-color: #b8d5cf;
  background: #f5fbf9;
}

.metric span,
.metric small,
.muted {
  color: var(--muted);
}

.metric span {
  font-size: 13px;
}

.metric strong {
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.metric small {
  font-size: 12px;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.panel {
  min-height: 260px;
  padding: 16px;
  overflow: hidden;
}

.trend-panel {
  grid-column: span 9;
}

.distribution-panel {
  grid-column: span 3;
}

.detail-panel,
.loss-panel,
.gain-panel {
  grid-column: span 4;
}

.flow-panel {
  grid-column: span 8;
}

.summary-panel {
  grid-column: span 4;
  min-height: 560px;
}

.history-panel,
.top100-panel {
  grid-column: 1 / -1;
  overflow-x: auto;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.date-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-tabs button {
  border: 1px solid var(--line);
  background: #f7f9fc;
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.date-tabs button.active {
  color: #fff;
  background: #2d6f75;
  border-color: #2d6f75;
}

.trend-chart {
  width: 100%;
  height: 300px;
  display: block;
}

.trend-hit {
  cursor: pointer;
}

.trend-tooltip {
  pointer-events: none;
}

.donut-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  justify-items: center;
}

.donut {
  width: min(220px, 100%);
  height: 220px;
}

.legend {
  display: grid;
  gap: 8px;
  font-size: 13px;
  width: min(240px, 100%);
}

.legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 8px 7px;
  border-bottom: 1px solid #edf1f6;
  text-align: right;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-table {
  min-width: 900px;
}

.top100-table {
  min-width: 1240px;
}

.top100-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
}

.top100-table tbody tr:hover {
  background: #f8fbff;
}

.top100-table .rank-cell {
  width: 48px;
  color: var(--muted);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.top100-table .entity-cell {
  min-width: 160px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.top100-table .entity-cell strong {
  font-weight: 700;
}

.top100-table .type-cell {
  max-width: 156px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #31445f;
  font-size: 12px;
  font-weight: 700;
}

.category-lending { background: #fff5c9; color: #7a5a00; }
.category-bridge { background: #dff7f8; color: #16666b; }
.category-cex { background: #fff0e5; color: #a64b13; }
.category-dex { background: #e5f6ee; color: #167049; }
.category-yield { background: #fde9e9; color: #9f2727; }
.category-other { background: #eee8fa; color: #6341a1; }

.bar-list {
  display: grid;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 74px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 14px;
  background: #eef2f7;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
}

.bar-fill.gain {
  background: var(--blue);
}

.bar-fill.loss {
  background: var(--red);
}

.bar-value {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.flow-chart {
  width: 100%;
  min-height: 500px;
  display: block;
}

.flow-head-tools {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.info-button {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #c7d4e5;
  border-radius: 50%;
  background: #f4f8fd;
  color: #38536f;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.info-button:hover,
.info-button:focus-visible {
  border-color: #2d6f75;
  background: #e8f4f3;
  color: #1f5f65;
  outline: none;
}

.info-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  width: min(360px, calc(100vw - 48px));
  display: grid;
  gap: 7px;
  padding: 12px 14px;
  color: #26364e;
  background: #ffffff;
  border: 1px solid #cfd9e7;
  border-radius: var(--radius);
  box-shadow: 0 14px 30px rgba(23, 34, 56, 0.16);
  font-size: 12px;
  line-height: 1.55;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}

.info-popover strong {
  font-size: 13px;
  color: var(--ink);
}

.info-button:hover + .info-popover,
.info-button:focus-visible + .info-popover,
.info-popover:hover {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.flow-node {
  cursor: pointer;
}

.flow-link-hit {
  cursor: pointer;
}

.flow-tooltip {
  pointer-events: none;
}

.summary {
  max-height: 498px;
  overflow: auto;
  padding-right: 8px;
  color: #26364e;
  font-size: 14px;
  line-height: 1.68;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trend-panel,
  .distribution-panel,
  .detail-panel,
  .loss-panel,
  .gain-panel,
  .flow-panel,
  .summary-panel {
    grid-column: span 6;
  }

  .history-panel,
  .top100-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .dashboard-shell {
    width: min(100vw - 24px, 720px);
    padding-top: 16px;
  }

  .topbar,
  .run-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .layout-grid {
    grid-template-columns: 1fr;
  }

  .trend-panel,
  .distribution-panel,
  .detail-panel,
  .loss-panel,
  .gain-panel,
  .flow-panel,
  .summary-panel,
  .history-panel,
  .top100-panel {
    grid-column: 1;
  }

  .donut-wrap {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 86px minmax(0, 1fr) 64px;
  }
}
