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

:root {
  --color-pass: #22c55e;
  --color-minor: #f59e0b;
  --color-fail: #ef4444;
  --color-brand: #3b82f6;
  --color-region: #6366f1;
  --color-sev-a: #facc15;
  --color-sev-b: #f97316;
  --color-sev-c: #dc2626;
  --color-bg: #f1f5f9;
  --color-card: #ffffff;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  padding: 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header .subtitle {
  color: var(--color-muted);
  font-size: 0.95rem;
}

/* Range selector */
.range-selector {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.range-selector button {
  padding: 0.5rem 1.25rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: var(--color-card);
  color: var(--color-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.range-selector button:hover {
  border-color: var(--color-brand);
  color: var(--color-brand);
}

.range-selector button.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

/* Summary cards */
.summary-cards {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.card {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.5rem;
  text-align: center;
  min-width: 160px;
  flex: 0 1 auto;
}

.card-label {
  display: block;
  font-size: 0.8rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.card-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
}

/* Loading */
.loading {
  text-align: center;
  margin: 2rem 0;
}

.loading[hidden] {
  display: none;
}

.loading-text {
  font-size: 0.95rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
}

.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  margin: 0 auto;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--color-brand);
  border-radius: 4px;
  transition: width 0.2s ease;
}

/* Error message */
.error-message {
  text-align: center;
  margin: 2rem 0;
  padding: 1.5rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
}

.error-message[hidden] {
  display: none;
}

.error-message p {
  color: var(--color-fail);
  margin-bottom: 0.75rem;
}

.error-message button {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--color-fail);
  border-radius: 8px;
  background: #fff;
  color: var(--color-fail);
  font-size: 0.875rem;
  cursor: pointer;
}

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #1d4ed8;
}

.filter-bar[hidden] {
  display: none;
}

.filter-bar button {
  padding: 0.25rem 0.75rem;
  border: 1px solid #93c5fd;
  border-radius: 6px;
  background: #fff;
  color: #1d4ed8;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-bar button:hover {
  background: #dbeafe;
}

/* Help tip */
.help-tip {
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
  font-style: italic;
}

.help-tip[hidden] {
  display: none;
}

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.charts-grid[hidden] {
  display: none;
}

.chart-container {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.chart-container h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}

.chart-wrap {
  position: relative;
  height: 320px;
}

.chart-container:last-child .chart-wrap {
  height: 500px;
}

/* Defects table */
.defects-table-section {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.defects-table-section[hidden] {
  display: none;
}

.defects-table-section h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.defects-note {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
  font-style: italic;
}

.defects-table-wrap {
  max-height: 480px;
  overflow-y: auto;
}

.defects-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.defects-table th,
.defects-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.defects-table th {
  position: sticky;
  top: 0;
  background: var(--color-card);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.defects-table td:nth-child(n+3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.defects-table th:nth-child(n+3) {
  text-align: right;
}

.defects-table tbody tr:hover {
  background: #f8fafc;
}

.sev-a { color: #a16207; }
.sev-b { color: #c2410c; }
.sev-c { color: #dc2626; font-weight: 600; }

/* Severity filter */
.sev-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.sev-btn {
  padding: 0.3rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: var(--color-card);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sev-btn:hover {
  opacity: 0.85;
}

.sev-btn-a { color: #a16207; border-color: #facc15; }
.sev-btn-a.active { background: #facc15; color: #422006; }

.sev-btn-b { color: #c2410c; border-color: #f97316; }
.sev-btn-b.active { background: #f97316; color: #fff; }

.sev-btn-c { color: #dc2626; border-color: #dc2626; }
.sev-btn-c.active { background: #dc2626; color: #fff; }

/* Footer */
footer {
  text-align: center;
  padding: 1rem 0;
  color: var(--color-muted);
  font-size: 0.8rem;
}

footer a {
  color: var(--color-brand);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 280px;
  }

  .summary-cards {
    flex-direction: column;
    align-items: center;
  }

  .card {
    width: 100%;
    max-width: 300px;
  }
}
