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

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --accent: #5c6bc0;
  --accent-dark: #3949ab;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Layout ---- */

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

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

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

header p {
  color: var(--muted);
  font-size: 14px;
}

/* ---- Controls ---- */

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-width: 160px;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.15);
}

button {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

#filter-info {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

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

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -2px;
  border-radius: 0;
  transition: color 0.15s;
}

.tab:hover {
  color: var(--accent);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---- Tab panels ---- */

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---- Card ---- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

.card .hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: -8px;
  margin-bottom: 14px;
  line-height: 1.6;
}

.section-gap {
  margin-top: 20px;
}

/* ---- Stats grid ---- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--muted);
}

/* ---- Charts row ---- */

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 860px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

.chart-container {
  position: relative;
  height: 280px;
}

.chart-container-large {
  position: relative;
  height: 460px;
}

.chart-container-radar {
  position: relative;
  height: 420px;
}

/* ---- Tables ---- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: #f8f9fa;
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: #f9fafb;
}

.cpu-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ---- Compare controls ---- */

.compare-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.vs {
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
}

/* ---- Badges ---- */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-muted { background: #f3f4f6; color: var(--muted); font-weight: 500; }

/* ---- Heatmap ---- */

.heatmap {
  overflow-x: auto;
}

.heatmap th:first-child,
.heatmap td:first-child {
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  left: 0;
  background: #f8f9fa;
  z-index: 1;
}

.heatmap tbody td:first-child {
  background: white;
}

.heat-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
}

/* ---- Fingerprinting score ---- */

.fp-score {
  font-size: 72px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, var(--accent), #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 20px 0 4px;
  line-height: 1;
}

.fp-score-label {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.fp-viability {
  text-align: center;
  margin-bottom: 24px;
}

.fp-metrics {
  margin-top: 20px;
}

/* ---- Note box ---- */

.note {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.note-warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* ---- Runs legend controls ---- */

#runs-legend-controls {
  margin-top: 14px;
  margin-bottom: 6px;
}

.btn-sm {
  background: #f3f4f6;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
}

.btn-sm:hover {
  background: var(--border);
}

/* ---- Run legend ---- */

#runs-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  max-height: 150px;
  overflow-y: auto;
  padding-right: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 10px;
  background: #f3f4f6;
  border-radius: 999px;
  cursor: pointer;
  transition: opacity 0.15s;
  user-select: none;
  border: 1px solid transparent;
}

.legend-item:hover {
  border-color: var(--border);
}

.legend-item.hidden-lines {
  opacity: 0.35;
  text-decoration: line-through;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Loading overlay ---- */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 999;
  font-size: 15px;
  color: var(--muted);
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Error ---- */

.error-msg {
  background: #fef2f2;
  color: #b91c1c;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #fecaca;
  margin: 12px 0;
  font-size: 13px;
}

/* ---- Numeric formatting ---- */

.num {
  font-variant-numeric: tabular-nums;
}

.faster { color: #16a34a; font-weight: 600; }
.slower { color: #dc2626; font-weight: 600; }
