:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-soft: #e8efff;
  --good: #15803d;
  --good-soft: #dcfce7;
  --ok: #0369a1;
  --ok-soft: #e0f2fe;
  --mid: #b45309;
  --mid-soft: #fef3c7;
  --low: #b91c1c;
  --low-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }

.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.topbar { background: linear-gradient(120deg, #1e3a8a, #1d4ed8 60%, #2563eb); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 18px; padding-bottom: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); font-weight: 700; letter-spacing: .5px; }
.brand h1 { margin: 0; font-size: 20px; line-height: 1.25; }
.brand p { margin: 2px 0 0; opacity: .85; font-size: 13px; }
.source-link { color: #fff; text-decoration: none; font-size: 13px; padding: 7px 12px; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; white-space: nowrap; }
.source-link:hover { background: rgba(255,255,255,.12); }

main { padding-top: 18px; padding-bottom: 24px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; padding: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
select, input[type="search"] {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none;
}
select:focus, input[type="search"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(15,23,42,.12); }
.btn { height: 38px; display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #cbd5e1; background: var(--surface-2); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1e40af; border-color: #1e40af; }
.btn[disabled] { opacity: .55; cursor: default; }
.filters .spacer { flex: 1; }

/* ---------- Breadcrumbs ---------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 14px 2px 10px; font-size: 13px; color: var(--muted); }
.crumbs button { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; font-weight: 500; }
.crumbs strong { color: var(--text); }

/* ---------- Summary ---------- */
.summary { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 14px; }
.total-card { padding: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
.total-card h2 { margin: 0; font-size: 15px; }
.total-card .sub { color: var(--muted); font-size: 13px; }
.ring { position: relative; width: 150px; height: 150px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; }
.ring .val b { font-size: 32px; line-height: 1; }
.ring .val small { color: var(--muted); }
.growth { font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.growth.up { color: var(--good); background: var(--good-soft); }
.growth.down { color: var(--low); background: var(--low-soft); }

.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.group-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.group-card .name { font-size: 13px; color: var(--muted); font-weight: 500; }
.group-card .score { font-size: 24px; font-weight: 700; line-height: 1.1; }
.group-card .score small { font-size: 13px; font-weight: 500; color: var(--muted); }
.bar { height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; }
.group-card .pct { font-size: 12px; color: var(--muted); }

/* ---------- Charts ---------- */
.grid-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 14px 0; }
.chart { padding: 14px 16px 12px; min-width: 0; }
.chart h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.chart svg { width: 100%; height: auto; display: block; }
.chart .empty { color: var(--muted); padding: 30px 0; text-align: center; }
.axis text, .lbl { font-size: 11px; fill: var(--muted); }
.grid-line { stroke: #e9eef5; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-wrap svg { width: 140px; height: 140px; flex: none; transform: rotate(-90deg); }
.donut-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; min-width: 180px; }
.donut-list li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; }
.donut-list li i { width: 12px; height: 12px; border-radius: 3px; }
.donut-list b { font-variant-numeric: tabular-nums; }
.donut-list small { display: block; color: var(--muted); }

/* ---------- Table ---------- */
.table-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.table-head h2 { margin: 0; font-size: 16px; }
.table-head .tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.table-head input[type="search"] { width: 240px; max-width: 100%; }
.tabs { padding: 10px 16px 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid #eef2f7; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
th.sorted { color: var(--primary); }
th .arrow { font-size: 10px; margin-left: 3px; }
th.left, td.left { text-align: left; }
td.name { white-space: normal; min-width: 220px; font-weight: 500; }
tr.drill { cursor: pointer; }
tr.drill:hover td { background: #f5f8ff; }
tr.drill td.name::after { content: " ›"; color: var(--muted); }
.rank { display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 6px; border-radius: 7px; background: var(--surface-2); font-weight: 600; font-size: 12px; }
.rank.top { background: #fef3c7; color: #92400e; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.lv-good { color: var(--good); background: var(--good-soft); }
.lv-ok { color: var(--ok); background: var(--ok-soft); }
.lv-mid { color: var(--mid); background: var(--mid-soft); }
.lv-low { color: var(--low); background: var(--low-soft); }
.delta-up { color: var(--good); }
.delta-down { color: var(--low); }
.muted { color: var(--muted); }
.table-foot { padding: 10px 16px; color: var(--muted); font-size: 12px; }

/* ---------- States ---------- */
.state { padding: 40px 16px; text-align: center; color: var(--muted); }
.state.error { color: var(--low); }
.spinner { width: 28px; height: 28px; margin: 0 auto 10px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { opacity: .5; pointer-events: none; transition: opacity .2s; }

.site-footer { color: var(--muted); font-size: 12px; padding-top: 8px; padding-bottom: 28px; text-align: center; }
.site-footer p { margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .summary { grid-template-columns: 1fr; }
  .grid-charts { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .brand h1 { font-size: 17px; }
  .brand p { display: none; }
  .field { min-width: calc(50% - 7px); flex: 1; }
  .field.scope { min-width: 100%; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
  .filters .spacer { display: none; }
  .filters .btn { flex: 1; justify-content: center; }
  .table-head input[type="search"] { width: 100%; }
  .table-head .tools { width: 100%; }
  .groups { grid-template-columns: 1fr 1fr; }
}
