:root {
  --bg: #f4f5fa;
  --sidebar: #1e2140;
  --sidebar-2: #262a52;
  --card: #ffffff;
  --ink: #2a2c3a;
  --title: #16182a;
  --sub: #8b8fa3;
  --line: #ececf3;
  --accent: #9d8af0;
  --good: #5bb98a;
  --fair: #e9b949;
  --low: #e8836b;
  --shadow: 0 8px 24px rgba(40, 38, 80, 0.07);
  --shadow-hi: 0 14px 36px rgba(40, 38, 80, 0.13);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 256px; flex-shrink: 0; background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #fff; padding: 22px 16px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-dot { width: 36px; height: 36px; border-radius: 11px; background: linear-gradient(135deg, #9d8af0, #7ea6f8); box-shadow: 0 6px 16px rgba(125,110,240,.4); }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: 1px; }
.brand-sub { font-size: 11px; color: #b9bce0; margin-top: 2px; }
.side-title { font-size: 11px; letter-spacing: 1px; color: #8e93c4; text-transform: uppercase; margin-top: 4px; }

.search-input, .token-input {
  width: 100%; box-sizing: border-box; padding: 9px 12px; border-radius: 11px;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.07);
  color: #fff; font-size: 13px; margin-bottom: 6px;
}
.search-input::placeholder, .token-input::placeholder { color: #9a9ec4; }
.search-input:focus, .token-input:focus { outline: none; border-color: rgba(157,138,240,.7); background: rgba(255,255,255,.12); }
.token-input { margin-bottom: 10px; font-size: 12px; }

.user-nav { display: flex; flex-direction: column; gap: 8px; flex: 1; overflow-y: auto; padding-right: 2px; }
.nav-empty { color: #b9bce0; font-size: 13px; padding: 14px; text-align: center; }

.member-nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 13px;
  background: rgba(255,255,255,.05); border: 1px solid transparent; cursor: pointer;
  text-align: left; color: #e7e8f5; transition: all .15s; width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,.1); }
.nav-item.active { background: rgba(157,138,240,.22); border-color: rgba(157,138,240,.55); }
.nav-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.nav-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-name { font-size: 14px; font-weight: 700; }
.nav-name small { font-size: 11px; color: #b9bce0; font-weight: 500; margin-left: 5px; }
.nav-status { font-size: 11px; color: #c7c9e6; }
.nav-emoji { font-size: 15px; }
.nav-emoji.unbound { opacity: .5; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.mode-pill { font-size: 11px; padding: 6px 11px; border-radius: 999px; background: rgba(157,138,240,.2); color: #cbbcff; font-weight: 600; text-align: center; }
.mode-pill.demo { background: #4a3a1a; color: #f0c46e; }
.mode-pill.err { background: #4a2330; color: #ff9b8a; }
.refresh-btn { font-size: 13px; font-weight: 600; color: #fff; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: 8px 14px; cursor: pointer; transition: all .15s; }
.refresh-btn:hover { background: rgba(255,255,255,.2); }

/* ── Main ── */
.main { flex: 1; padding: 26px 30px 50px; min-width: 0; }
.main-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.main-head h1 { font-size: 24px; font-weight: 800; color: var(--title); }
.detail-meta { font-size: 13px; color: var(--sub); margin-top: 4px; }
.csv-btn { font-size: 13px; font-weight: 600; color: var(--accent); background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; cursor: pointer; transition: all .15s; }
.csv-btn:hover { border-color: var(--accent); box-shadow: var(--shadow); }

/* KPI */
.kpi { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi-card { background: var(--card); border-radius: 16px; padding: 15px 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.kpi-label { font-size: 12px; color: var(--sub); margin-bottom: 7px; }
.kpi-value { font-size: 25px; font-weight: 800; color: var(--title); line-height: 1; }
.kpi-value small { font-size: 13px; font-weight: 600; color: var(--sub); margin-left: 3px; }
.kpi-extra { font-size: 11px; color: var(--sub); margin-top: 6px; }

/* Detail */
.detail { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.overview { display: flex; align-items: center; gap: 20px; background: var(--card); border-radius: 18px; padding: 18px 22px; box-shadow: var(--shadow); }
.ov-score { display: flex; flex-direction: column; align-items: center; min-width: 90px; }
.ov-num { font-size: 40px; font-weight: 800; line-height: 1; }
.ov-unit { font-size: 12px; color: var(--sub); margin-top: 4px; }
.ov-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.ov-tag { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.ov-tag.grey { background: #f1f1f7; color: #767a8e; }

.groups { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.group { background: var(--card); border-radius: 18px; padding: 18px 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.group-title { font-size: 13px; font-weight: 700; color: var(--title); margin-bottom: 14px; padding-left: 10px; border-left: 3px solid var(--accent); }
.g-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 12px; }
.metric { }
.mk { font-size: 11px; color: var(--sub); margin-bottom: 4px; }
.mv { font-size: 17px; font-weight: 700; color: var(--title); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.mv small { font-size: 11px; font-weight: 600; color: var(--sub); }
.mv.na { color: #b9bccb; font-weight: 500; }
.mv.small { font-size: 12px; font-weight: 500; color: var(--sub); }
.mflag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.mflag.ok { background: #e7f6ee; color: #2f9e6b; }
.mflag.hi { background: #fdeae4; color: #d2664c; }
.mflag.lo { background: #fdf3da; color: #b9862a; }
.phase-tag { font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; color: #fff; }

.empty-box { background: var(--card); border-radius: 18px; padding: 40px 24px; text-align: center; color: var(--sub); font-size: 14px; line-height: 1.7; box-shadow: var(--shadow); border: 1px dashed var(--line); }

/* Trend */
.sec-title { font-size: 15px; font-weight: 700; color: var(--title); margin: 6px 0 14px; }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.chart-card { background: var(--card); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.chart-card.full { grid-column: 1 / -1; }
.chart-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--sub); margin-bottom: 10px; }
.chart-head b { font-size: 16px; color: var(--title); }
.spark { width: 100%; height: 90px; display: block; }
.chart-empty { font-size: 12px; color: var(--sub); text-align: center; padding: 30px 0; }
.phase-bar { display: flex; gap: 3px; height: 22px; }
.phase-seg { flex: 1; border-radius: 3px; }
.phase-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 11px; color: var(--sub); }
.phase-legend span { display: flex; align-items: center; gap: 5px; }
.phase-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Raw table */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.raw-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.raw-table th { background: #f7f7fc; color: var(--sub); font-weight: 600; padding: 10px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.raw-table th:first-child, .raw-table td:first-child { text-align: left; }
.raw-table td { padding: 9px 10px; text-align: right; border-bottom: 1px solid #f3f3f8; white-space: nowrap; }
.raw-table tbody tr:hover { background: #fafaff; }

.foot { margin-top: 28px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--sub); }

/* Responsive */
@media (max-width: 980px) {
  .kpi { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .member-nav { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .nav-item { width: auto; flex: 1; min-width: 140px; }
  .side-foot { flex-direction: row; width: 100%; margin-top: 8px; }
  .groups { grid-template-columns: 1fr; }
  .g-metrics { grid-template-columns: repeat(2, 1fr); }
}
