/* ── Reset & Base ──────────────────────────────────────────────────── */

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

[hidden] {
  display: none !important;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-card: #16161f;
  --bg-card-hover: #1c1c28;
  --bg-input: #1e1e2a;
  --border: #2a2a3a;
  --border-hover: #3a3a50;

  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;

  --accent: #7c5cfc;
  --accent-hover: #6a48e8;
  --accent-glow: rgba(124, 92, 252, 0.15);
  --accent-subtle: rgba(124, 92, 252, 0.08);

  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  --font: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --transition: 150ms ease;
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth Gate ─────────────────────────────────────────────────────── */

#auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 3rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 1rem;
  animation: pulse-glow 2s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
  from { text-shadow: 0 0 8px var(--accent-glow); }
  to   { text-shadow: 0 0 24px var(--accent-glow), 0 0 48px rgba(124, 92, 252, 0.08); }
}

.auth-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

#auth-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 1rem;
}

#auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#auth-form button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

#auth-form button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

#auth-form button:active {
  transform: translateY(0);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left .logo {
  font-size: 1.4rem;
  color: var(--accent);
}

.header-left h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.env-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.6rem;
  background: rgba(251, 191, 36, 0.1);
  color: var(--warning);
  border: 1px solid rgba(251, 191, 36, 0.2);
  border-radius: var(--radius-sm);
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-ghost:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-card);
}

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

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Stats Grid ────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ── Charts ────────────────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.chart-card h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.chart-card canvas {
  width: 100% !important;
  max-height: 240px;
}

/* ── Table ─────────────────────────────────────────────────────────── */

.table-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.table-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#email-search {
  padding: 0.5rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font);
  outline: none;
  width: 220px;
  transition: border-color var(--transition);
}

#email-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-secondary {
  padding: 0.5rem 0.85rem;
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid rgba(124, 92, 252, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
}

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

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

thead th {
  text-align: left;
  padding: 0.75rem 1.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

tbody td {
  padding: 0.7rem 1.5rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover {
  background: var(--bg-card-hover);
}

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

td.empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Source badge in table */
.source-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: var(--radius-sm);
}

.source-badge.unknown {
  background: rgba(136, 136, 160, 0.1);
  color: var(--text-muted);
}

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

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

.pagination button {
  padding: 0.4rem 0.7rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
}

.pagination button:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pagination .page-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 0.5rem;
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  main { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .table-header { flex-direction: column; gap: 0.75rem; align-items: stretch; }
  .table-actions { flex-direction: column; }
  #email-search { width: 100%; }
  header { padding: 0.75rem 1rem; }
}
