:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

/* Top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0;
  height: 56px;
  display: flex;
  align-items: center;
}
.topbar .brand {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  margin-right: 32px;
}
.topbar .brand i {
  color: var(--primary);
  margin-right: 6px;
}
.topbar .nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.topbar .nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s;
}
.topbar .nav-links a:hover {
  background: var(--bg);
  color: var(--text);
}
.topbar .nav-links a.active {
  background: #eef2ff;
  color: var(--primary);
}
.topbar .user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar .user-name {
  color: var(--text-muted);
  font-size: 13px;
}
.topbar .logout-btn {
  color: var(--text-muted);
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 6px;
}
.topbar .logout-btn:hover { background: var(--bg); color: var(--danger); }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
}
.stat-delta {
  font-size: 12px;
  margin-top: 6px;
}
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-delta.muted { color: var(--text-muted); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.panel-body { padding: 18px; }
.panel-body.no-pad { padding: 0; }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 18px;
}
.tabs button {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: 500;
  margin-bottom: -1px;
}
.tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tabs button:hover:not(.active) { color: var(--text); }

/* Tables */
.table-clean {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-clean th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 18px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-clean td {
  padding: 12px 18px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.table-clean tr:last-child td { border-bottom: none; }
.table-clean tr:hover td { background: #fafbfc; }
.table-clean .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 500;
}

/* Track row */
.track-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.track-rank.top { background: #fef3c7; color: #92400e; }
.track-title {
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  display: block;
}
.track-title:hover { color: var(--primary); }
.track-artist {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Site badge */
.site-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
}

/* Delta */
.delta {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

/* Forms */
.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Buttons */
.btn {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 6px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: #4338ca; color: white; }
.btn-light {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-light:hover { background: var(--bg); }
.btn-icon {
  padding: 5px 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { color: var(--danger); border-color: var(--danger); }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .form-control { min-width: 280px; }

/* Sparkline mini chart */
.spark {
  width: 80px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
}

/* Time toggle */
.time-toggle {
  display: inline-flex;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}
.time-toggle button {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-weight: 500;
}
.time-toggle button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Badge */
.badge-success { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.badge-warning { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.badge-danger  { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.badge-info    { background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.badge-danger  { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.badge-muted   { background: var(--bg); color: var(--text-muted); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }

/* Pagination */
.pagination-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.pagination-wrap .pages { display: flex; gap: 4px; }
.pagination-wrap .pages a, .pagination-wrap .pages span {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--surface);
  font-weight: 500;
}
.pagination-wrap .pages a:hover { background: var(--bg); color: var(--text); }
.pagination-wrap .pages .active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty i { font-size: 32px; opacity: 0.4; display: block; margin-bottom: 8px; }

/* Login */
.login-wrap {
  max-width: 360px;
  margin: 80px auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.login-wrap h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 24px;
  text-align: center;
}
.login-wrap label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.login-wrap .form-control {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.login-wrap .btn-primary {
  width: 100%;
  padding: 10px;
}
.login-wrap .alert {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}
