:root {
  --bg: #0d0f1c;
  --panel: #151829;
  --panel-2: #1b1f33;
  --border: #262b45;
  --text: #e6e8f3;
  --muted: #8b91ad;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --green: #34d399;
  --red: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2 { margin: 0; font-weight: 700; }
h1 { font-size: 16px; letter-spacing: -0.01em; }
h2 { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: rgba(13, 15, 28, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title { display: flex; align-items: center; gap: 10px; margin-right: auto; }

.range-nav { display: flex; gap: 4px; padding: 3px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

select.site-sel {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b91ad' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 7px 30px 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  max-width: 260px;
  text-overflow: ellipsis;
}
select.site-sel:hover { border-color: #3a4167; }
select.site-sel:focus { outline: none; border-color: var(--accent); }
select.site-sel option { background: var(--panel); color: var(--text); }

.range-nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.range-nav button:hover { color: var(--text); }
.range-nav button.active { background: var(--accent); color: #fff; }

button.logout {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
}
button.logout:hover { color: var(--text); border-color: #3a4167; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 20px; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.card-value { margin-top: 6px; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.grid-charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-lists { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

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

.panel h2 { margin-bottom: 12px; }

canvas { width: 100%; display: block; }

.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut-wrap canvas { flex: 1 1 50%; max-width: 50%; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1 1 50%; display: flex; flex-direction: column; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text); }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .legend-value { color: var(--muted); font-variant-numeric: tabular-nums; }

.split-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

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

.mini-table th, .mini-table td { text-align: left; padding: 7px 8px; font-size: 12.5px; }
.mini-table th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.mini-table td { border-bottom: 1px solid #1e2338; }
.mini-table tr:last-child td { border-bottom: 0; }
.mini-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.mini-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

.table-scroll { overflow-x: auto; }
.recent-table { min-width: 900px; }
.recent-table th, .recent-table td { text-align: left; padding: 8px 10px; font-size: 12.5px; white-space: nowrap; }
.recent-table th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.recent-table td { border-bottom: 1px solid #1e2338; font-variant-numeric: tabular-nums; }
.recent-table tr:last-child td { border-bottom: 0; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.tag.direct { color: var(--accent-2); }
.tag.google { color: var(--green); }
.tag.linkedin, .tag.facebook { color: #7ea7ff; }

.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0 20px; }

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

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-card {
  width: min(380px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
}
.login-head { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 24px; text-align: center; }
.login-head p { color: var(--muted); font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { color: var(--muted); font-size: 12px; font-weight: 600; }
.login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.login-form button {
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.login-form button:hover { background: #5255e8; }
.login-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 4px; }

@media (max-width: 900px) {
  .grid-charts { grid-template-columns: 1fr; }
  .grid-lists { grid-template-columns: 1fr; }
  .split-bars { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px; }
}
