:root {
  --bg: #0d1117;
  --card-bg: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --blue: #58a6ff;
  --gray: #6e7681;
  --bar-bg: #21262d;
  --bar-green: #238636;
  --bar-yellow: #9e6a03;
  --bar-red: #da3633;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 1.5rem;
  margin: 0 auto;
  min-width: min-content;
}

header { margin-bottom: 1.5rem; }

.top-grid {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: flex-start;
}
.top-left { display: flex; flex-direction: column; gap: 1rem; }
.top-left .card { margin-bottom: 0; }
.top-right { margin-bottom: 0; flex-shrink: 0; }

@media (max-width: 900px) {
  .top-grid { flex-direction: column; }
  .top-right { width: 100% !important; height: auto !important; }
  .top-left { width: 100% !important; }
}

h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
.subtitle { color: var(--text-muted); font-size: 0.85rem; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.overall-card { text-align: center; padding: 1.5rem; }

.big-number { font-size: 3rem; font-weight: 700; line-height: 1.1; }
.big-number.green { color: var(--green); }
.big-number.yellow { color: var(--yellow); }
.big-number.red { color: var(--red); }

.scope-badge {
  display: inline-block;
  background: var(--bar-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
  margin-left: 0.5rem;
}

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  font-weight: 600; color: var(--text-muted); font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.03em;
  position: sticky; top: 0; background: var(--card-bg);
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--blue); }
th[data-sort]::after { content: ''; margin-left: 0.3em; font-size: 0.65em; opacity: 0.4; }
th[data-sort].sort-asc::after { content: '\25B2'; opacity: 1; color: var(--blue); }
th[data-sort].sort-desc::after { content: '\25BC'; opacity: 1; color: var(--blue); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.pct, th.pct { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
td.na { color: var(--text-muted); text-align: center; }
td.zero { color: var(--red); text-align: right; font-weight: 600; }

.bar-col { width: 120px; min-width: 120px; }
.bar-container { width: 100%; height: 16px; background: var(--bar-bg); border-radius: 3px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease; }
.bar-target { position: absolute; top: 0; height: 100%; width: 2px; background: rgba(255,255,255,0.5); }

.status-pass { color: var(--green); }
.status-warn { color: var(--yellow); }
.status-fail { color: var(--red); }

.pkg-name { cursor: pointer; color: var(--blue); }
.pkg-name:hover { text-decoration: underline; }
.pkg-dimmed { opacity: 0.4; }

/* Gap analysis bar */
.gap-bar { display: flex; height: 20px; border-radius: 3px; overflow: hidden; margin: 0.5rem 0; }
.gap-bar-in { background: var(--bar-green); }
.gap-bar-out { background: var(--bar-bg); }
.gap-modules-list { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

/* Filters & search */
.filters { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.filter-btn {
  background: var(--bar-bg); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.25rem 0.6rem;
  border-radius: 20px; font-size: 0.75rem; cursor: pointer;
}
.filter-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.search-input {
  width: 100%; background: var(--bar-bg); border: 1px solid var(--border);
  color: var(--text); padding: 0.4rem 0.6rem; border-radius: 4px;
  font-size: 0.8rem; margin-bottom: 0.75rem;
}
.search-input:focus { outline: none; border-color: var(--blue); }

.close-btn {
  float: right; background: var(--bar-bg); border: 1px solid var(--border);
  color: var(--text); padding: 0.25rem 0.75rem; border-radius: 4px;
  cursor: pointer; font-size: 0.8rem;
}

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.section-header h2 { margin-bottom: 0; }
.header-actions { display: flex; gap: 0.5rem; }

.copy-btn {
  background: var(--bar-bg); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.3rem 0.7rem;
  border-radius: 4px; font-size: 0.75rem; cursor: pointer;
}
.copy-btn:hover { color: var(--text); border-color: var(--blue); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* Canvas charts */
#trend-chart { display: block; width: 100%; }
#donut-chart { display: block; margin: 0 auto; }
#mutator-chart { display: block; width: 100%; }

.chart-toggles { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.toggle-btn {
  background: var(--bar-bg); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.25rem 0.6rem;
  border-radius: 20px; font-size: 0.75rem; cursor: pointer;
  transition: all 0.15s ease;
}
.toggle-btn.active { color: #fff; border-color: currentColor; }
.toggle-btn[data-module="overall"].active { background: var(--blue); border-color: var(--blue); }

.legend {
  display: flex; gap: 1.5rem; flex-wrap: wrap;
  font-size: 0.75rem; color: var(--text-muted);
  margin-bottom: 0.75rem; padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.legend-item { display: flex; align-items: center; gap: 0.3rem; }
.legend-swatch {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 2px; font-size: 9px; text-align: center;
  line-height: 14px; font-weight: 600;
}

footer {
  text-align: center; color: var(--text-muted);
  font-size: 0.75rem; margin-top: 2rem; padding: 1rem 0;
}
footer code {
  background: var(--bar-bg); padding: 0.15rem 0.4rem;
  border-radius: 3px; font-size: 0.7rem;
}

.loading { text-align: center; padding: 2rem; color: var(--text-muted); }
.error { color: var(--red); text-align: center; padding: 2rem; }
