/* Stats dashboard — dark theme, pink accents, sibling to Apilog */

:root {
  --bg: #0e0e10;
  --bg-card: #18181b;
  --bg-hover: #1e1e22;
  --border: #2a2a2e;
  --text: #e4e4e7;
  --text-dim: #71717a;
  --text-muted: #52525b;
  --pink: #ec4899;
  --pink-dim: rgba(236, 72, 153, 0.15);
  --green: #22c55e;
  --blue: #3b82f6;
  --orange: #f59e0b;
  --purple: #a855f7;
  --cyan: #06b6d4;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  flex-wrap: wrap;
}

.nav-brand {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--pink), #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-right: 8px;
}

.nav-app-switch {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.nav-app-switch:hover { color: var(--text-dim); }

#nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.nav-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font);
  transition: all 0.15s;
}
.nav-btn:hover { color: var(--text); background: var(--bg-hover); }
.nav-btn.active {
  color: var(--pink);
  border-color: var(--pink);
  background: var(--pink-dim);
}

.pills {
  display: flex;
  gap: 4px;
}
.pill {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font);
  transition: all 0.15s;
}
.pill:hover { border-color: var(--text-dim); color: var(--text); }
.pill.active { border-color: var(--pink); color: var(--pink); background: var(--pink-dim); }

/* ── Main ── */

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

/* ── Cards ── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

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

.card-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Group headers ── */

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  margin-top: 20px;
}
.group-header:first-child { margin-top: 0; }

.group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Site cards ── */

.site-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.site-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.site-card:hover {
  border-color: var(--pink);
  transform: translateY(-1px);
}

.site-card h3 {
  font-size: 1rem;
  margin-bottom: 2px;
  color: var(--pink);
}

.site-domain {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-family: var(--mono);
}

.site-card .stats-row {
  display: flex;
  gap: 24px;
}

.site-card .stat {
  display: flex;
  flex-direction: column;
}

.site-card .stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.site-card .stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── Chart ── */

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.chart-title {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 120px;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.chart-bar {
  width: 100%;
  max-width: 24px;
  background: var(--pink);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.chart-bar:hover { opacity: 1; }
.chart-bar.visitors {
  background: var(--blue);
  opacity: 0.6;
}

.chart-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
}

.chart-tooltip {
  position: absolute;
  bottom: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
  display: none;
  z-index: 10;
}
.chart-bar-group:hover .chart-tooltip { display: block; }

/* ── Tables ── */

.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.table-title {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding: 16px 16px 0;
  margin-bottom: 12px;
}

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

th {
  text-align: left;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

td.num {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.8rem;
}

td.path {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--cyan);
}

td.referrer {
  font-size: 0.8rem;
  color: var(--blue);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Live view ── */

.live-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.live-entry:last-child { border-bottom: none; }

.live-time {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 60px;
}

.live-site {
  font-weight: 600;
  color: var(--pink);
  min-width: 100px;
}

.live-path {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--cyan);
  flex: 1;
}

.live-referrer {
  font-size: 0.75rem;
  color: var(--text-dim);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Section headings ── */

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.back-link {
  font-size: 0.82rem;
  color: var(--pink);
  cursor: pointer;
  margin-bottom: 16px;
  display: inline-block;
}
.back-link:hover { text-decoration: underline; }

/* ── Loading / empty ── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px;
  color: var(--text-dim);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Footer ── */

footer {
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  text-align: center;
}

.footer-ext {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
}
.footer-ext:hover { color: var(--text-dim); }

/* ── Responsive ── */

@media (max-width: 640px) {
  header { padding: 10px 12px; gap: 8px; }
  main { padding: 12px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .site-cards { grid-template-columns: 1fr; }
  .nav-app-switch { display: none; }
  .chart { height: 80px; }
}
