/* AG Analytics design tokens
   Light-first, modern SaaS look: soft neutral background, white elevated
   cards with a gentle shadow, a single violet accent for interface elements,
   and a separate mint "live" color reserved only for the one number on the
   page that updates in real time (visitors online now).
   Type: Space Grotesk for headings/brand, Inter for interface text,
   IBM Plex Mono for every number, since precision-looking digits matter
   more than decoration in an analytics tool. */

:root {
  --bg: #f5f5f9;
  --surface: #ffffff;
  --surface-2: #f1f0f8;
  --border: #e6e4f0;
  --text: #17171f;
  --text-muted: #6e6e82;
  --accent: #6c5ce7;
  --accent-soft: #eeebfd;
  --accent-contrast: #ffffff;
  --live: #16a672;
  --live-soft: #dcf5ea;
  --negative: #e4572e;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(23, 23, 31, 0.05);
  --shadow-lg: 0 16px 32px -20px rgba(23, 23, 31, 0.28);
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

[data-theme="dark"] {
  --bg: #0e0e14;
  --surface: #17171f;
  --surface-2: #1e1e29;
  --border: #2a2a38;
  --text: #f2f2f7;
  --text-muted: #9391a8;
  --accent: #9c8cff;
  --accent-soft: rgba(156, 140, 255, 0.16);
  --accent-contrast: #0e0e14;
  --live: #34d399;
  --live-soft: rgba(52, 211, 153, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 40px -20px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Auth screens (setup / login) */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0 0 6px;
}

.muted { color: var(--text-muted); font-size: 14px; margin-top: 0; }

form label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}

form input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
}

form input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 9px;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

button:active { transform: scale(0.98); }

form > button[type="submit"] {
  width: 100%;
  margin-top: 20px;
  padding: 11px;
  background: var(--accent);
  color: var(--accent-contrast);
}

.form-error {
  color: var(--negative);
  font-size: 13px;
  min-height: 18px;
  margin-top: 10px;
}

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 10px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.btn-ghost.small { font-size: 12px; padding: 6px 10px; }

.btn-ghost.danger { color: var(--negative); }
.btn-ghost.danger:hover { color: var(--negative); border-color: var(--negative); background: rgba(228, 87, 46, 0.08); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost:disabled:hover { color: var(--text-muted); border-color: var(--border); background: var(--surface); }

/* App shell */
.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
}

.sidebar-section { margin-top: 28px; }
.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#site-select {
  width: 100%;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.site-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.site-actions button { width: 100%; }
.full-width { width: 100%; margin-top: 10px; }

.period-tabs { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.period-tabs button {
  text-align: left;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 8px;
}
.period-tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.content { padding: 32px 40px 56px; }

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

#site-name { font-size: 26px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.online-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
}

#online-count { color: var(--live); font-weight: 600; }

/* Signature element: a live pulsing dot, the one animated thing on the page,
   reserved for the single number that changes in real time. */
.pulse-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
}
.pulse-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.65; }
  100% { transform: scale(3.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse-dot::after { animation: none; }
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-label { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.card-value { font-family: var(--font-mono); font-size: 28px; font-weight: 600; }
.card-delta { font-family: var(--font-mono); font-size: 12px; margin-top: 6px; min-height: 15px; }
.card-delta.up { color: var(--live); }
.card-delta.down { color: var(--negative); }
.card-delta.flat { color: var(--text-muted); }

.chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 24px;
  position: relative;
}

#chart { width: 100%; height: 240px; display: block; cursor: crosshair; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 5;
}

.chart-tooltip strong { font-family: var(--font-display); font-size: 12px; }

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 14px;
  margin-bottom: 12px;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table td { padding: 7px 0; border-bottom: 1px solid var(--border); }
table tr:last-child td { border-bottom: none; }
td.label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
td.value { font-family: var(--font-mono); text-align: right; color: var(--text-muted); }
td.label a { color: inherit; text-decoration: none; }
td.label a:hover { color: var(--accent); text-decoration: underline; }
td.label .flag { margin-right: 7px; font-size: 14px; }
td.label img.favicon { width: 14px; height: 14px; margin-right: 7px; vertical-align: -2px; border-radius: 3px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  margin-top: 14px;
  cursor: pointer;
}
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.checkbox-row:first-of-type { margin-top: 18px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .breakdown-grid { grid-template-columns: 1fr; }
}
