:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;
  --danger: #d03b3b;

  --series-found: #2a78d6;
  --series-ban: #e34948;
  --series-unban: #1baf7a;
  --series-restore: #eb6834;

  /* Sequential blue ramp, near-surface (low) -> full saturation (high) */
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success: #0ca30c;
    --danger: #e66767;

    --series-found: #3987e5;
    --series-ban: #e66767;
    --series-unban: #199e70;
    --series-restore: #d95926;

    /* reversed: near dark-surface (low) -> brightest (high) for max contrast */
    --seq-1: #0d366b;
    --seq-2: #184f95;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #9ec5f4;
    --seq-7: #cde2fb;
  }
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.topbar .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

.logout-link {
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
}

.logout-link:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ---------- Filter row ---------- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-row select,
.filter-row input {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}

.filter-row .preset-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.filter-row .preset-group button {
  background: var(--surface-1);
  color: var(--text-secondary);
  border: none;
  border-right: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.filter-row .preset-group button:last-child {
  border-right: none;
}

.filter-row .preset-group button.active {
  background: var(--series-found);
  color: #fff;
}

.refresh-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Stat tiles ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stat-tile .value.danger { color: var(--danger); }
.stat-tile .value.accent { color: var(--series-found); }

/* ---------- Chart cards ---------- */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
}

.card .card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

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

.chart-wrap.pie {
  height: 260px;
}

/* ---------- Heatmap ---------- */
.heatmap-wrap {
  overflow-x: auto;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: 34px repeat(24, minmax(16px, 1fr));
  gap: 2px;
  min-width: 560px;
}

.heatmap-hour-label,
.heatmap-day-label {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.heatmap-hour-label {
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 2px;
}

.heatmap-day-label {
  justify-content: flex-end;
  padding-right: 6px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--gridline);
  cursor: default;
  transition: outline-color 0.1s ease;
  outline: 1px solid transparent;
  outline-offset: 1px;
}

.heatmap-cell:hover,
.heatmap-cell:focus-visible {
  outline: 1.5px solid var(--text-primary);
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.heatmap-legend-scale {
  height: 10px;
  width: 120px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--gridline),
    var(--seq-1),
    var(--seq-3),
    var(--seq-5),
    var(--seq-7)
  );
}

.heatmap-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.heatmap-tooltip.visible {
  opacity: 1;
}

.heatmap-tooltip strong {
  color: var(--text-primary);
}

/* ---------- Tables ---------- */
.table-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gridline);
  padding: 0 8px 8px;
}

tbody td {
  padding: 8px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.badge.Found { color: var(--series-found); }
.badge.Ban { color: var(--series-ban); }
.badge.Unban { color: var(--series-unban); }
.badge.RestoreBan { color: var(--series-restore); }

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.pagination button {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
}

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

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

.attribution {
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  margin-top: 24px;
}

.attribution a {
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .table-grid { grid-template-columns: 1fr; }
}

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
}

.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.auth-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}

.auth-card p.hint {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 20px;
}

.auth-card label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.auth-card input {
  width: 100%;
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 14px;
  font-family: inherit;
}

.auth-card button {
  width: 100%;
  background: var(--series-found);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.auth-card button:hover {
  filter: brightness(1.08);
}

.auth-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
