:root {
  --primary:      #2563eb;
  --primary-h:    #1d4ed8;
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;
  --info:         #0891b2;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --radius:       0.625rem;
  --shadow:       0 1px 3px 0 rgb(0 0 0 / .07), 0 1px 2px -1px rgb(0 0 0 / .07);
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-bar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 2.5rem;
}

.logo {
  font-weight: 800;
  font-size: 1.125rem;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-link {
  padding: 0.375rem 0.875rem;
  border-radius: 0.375rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #eff6ff; color: var(--primary); font-weight: 600; }

/* ── Main layout ─────────────────────────────────────────────────────────── */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

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

/* ── Period selector ─────────────────────────────────────────────────────── */

.period-selector {
  display: flex;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.25rem;
}

.tab {
  padding: 0.375rem 1.125rem;
  border-radius: 0.375rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.card-value {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.card-delta {
  margin-top: 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
}
.card-delta.positive { color: var(--success); }
.card-delta.negative { color: var(--danger); }
.card-delta.neutral  { color: var(--text-muted); }

/* ── Sections ────────────────────────────────────────────────────────────── */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.75rem;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.section-header h2 { font-size: 0.9375rem; font-weight: 600; }

.section-sub { font-size: 0.8125rem; color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */

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

th {
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.875rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

td {
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafd; }

tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #eff6ff; }
tr.row-link:focus { outline: none; }
tr.row-link:focus td { background: #eff6ff; box-shadow: inset 2px 0 0 var(--primary); }

.clear-filter {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.clear-filter:hover { text-decoration: underline; }

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

.rank { color: var(--text-muted); font-weight: 600; width: 2.5rem; }

.domain { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 0.8125rem; }

/* ── Bar chart cells ─────────────────────────────────────────────────────── */

.bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
}
.bar-fill {
  height: 0.5rem;
  background: var(--primary);
  border-radius: 2px;
  opacity: 0.65;
  min-width: 2px;
  max-width: 100px;
}
.bar-wrap span { min-width: 2.5rem; text-align: right; font-size: 0.8125rem; color: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.175rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge-newsletter     { background: #ede9fe; color: #5b21b6; }
.badge-company        { background: #dbeafe; color: #1e40af; }
.badge-individual     { background: #dcfce7; color: #166534; }
.badge-free_provider  { background: #fef3c7; color: #92400e; }

/* ── Grade & score ───────────────────────────────────────────────────────── */

.grade {
  font-weight: 800;
  font-size: 0.9375rem;
  margin-right: 0.25rem;
}
.grade-a { color: var(--success); }
.grade-b { color: var(--info); }
.grade-c { color: var(--warning); }
.grade-d { color: #ea580c; }
.grade-f { color: var(--danger); }

.score-num { font-size: 0.75rem; color: var(--text-muted); }

/* ── From cell ───────────────────────────────────────────────────────────── */

.from-addr {
  font-size: 0.875rem;
  word-break: break-all;
}
.from-domain {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: ui-monospace, "SFMono-Regular", monospace;
  margin-top: 0.1rem;
}

.date-cell {
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.page-btn {
  padding: 0.4rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--primary);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background 0.1s;
}
.page-btn:hover { background: var(--bg); }
.page-btn.disabled { color: var(--text-muted); pointer-events: none; opacity: 0.5; }

.page-info { font-size: 0.8125rem; color: var(--text-muted); }

/* ── Empty state ─────────────────────────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 3.5rem 2rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}
