:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --success: #16a34a;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --accent: #818cf8;
    --accent-soft: #312e81;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-brand { font-weight: 600; margin-right: 1rem; }

.nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav a:hover, .nav a.active { color: var(--accent); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { font-size: 1.4rem; margin-bottom: 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.filters input, .filters select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.filters button {
  padding: 0.45rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

canvas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

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

a { color: var(--accent); }

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.badge.success { background: #dcfce7; color: var(--success); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.neutral { background: var(--accent-soft); color: var(--accent); }

.pagination {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.pagination button {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.pagination button:disabled { opacity: 0.5; cursor: default; }

pre.json-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.section { margin-bottom: 2rem; }

.heatmap-table {
  border-collapse: separate;
  border-spacing: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.7rem;
}

.heatmap-table th {
  color: var(--text-muted);
  font-weight: 400;
  text-align: center;
  padding: 1px 2px;
}

.heatmap-table td.hm-label {
  color: var(--text-muted);
  text-align: right;
  padding-right: 0.5rem;
  white-space: nowrap;
}

.heatmap-cell {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--accent);
}

.subnav {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.subnav a.active { font-weight: 600; color: var(--text); text-decoration: none; }
