:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c2030;
  --border: #262a38;
  --text: #e6e8ee;
  --muted: #8a93a6;
  --accent: #7aa2f7;
  --accent-2: #bb9af7;
  --good: #9ece6a;
  --warn: #e0af68;
  --bad: #f7768e;
  --chart-visitors: #7aa2f7;
  --chart-sessions: #9ece6a;
  --chart-pageviews: #bb9af7;
  --shadow: 0 1px 0 rgba(255,255,255,.02), 0 8px 24px rgba(0,0,0,.25);
  --r: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fb;
    --panel: #ffffff;
    --panel-2: #f3f4f7;
    --border: #e6e8ee;
    --text: #1c2030;
    --muted: #6b7387;
    --shadow: 0 1px 0 rgba(0,0,0,.02), 0 8px 24px rgba(20,30,60,.06);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.4; }
h1, h2, h3 { font-weight: 600; margin: 0; }
button { font: inherit; cursor: pointer; }

.login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r); padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; margin-bottom: 4px; }
.login-sub { color: var(--muted); margin: 0 0 20px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  font: inherit;
}
.login-card button {
  width: 100%; padding: 10px; border: 0; border-radius: 8px;
  background: var(--accent); color: #0b1020; font-weight: 600;
}
.login-err { color: var(--bad); margin: 12px 0 0; font-size: 13px; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 20px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 8px;
}
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px rgba(158, 206, 106, .2); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.ranges { display: flex; gap: 2px; background: var(--panel-2); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.ranges button {
  background: transparent; border: 0; color: var(--muted);
  padding: 6px 10px; border-radius: 7px; font-size: 12px;
}
.ranges button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.grid {
  display: grid; gap: 16px; padding: 20px;
  grid-template-columns: repeat(12, 1fr);
}
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow); grid-column: span 6; min-width: 0;
}
.card.wide { grid-column: span 12; }
.chart-card { grid-column: span 12; }
.card > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.card h3 { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); }
.legend i.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.chart-card .canvas-wrap { position: relative; height: 280px; }
.donut-grid .canvas-wrap { position: relative; height: 180px; }
.canvas-wrap > canvas { max-width: 100%; }
.sw-visitors { background: var(--chart-visitors); }
.sw-sessions { background: var(--chart-sessions); }
.sw-pageviews { background: var(--chart-pageviews); }

.kpis {
  grid-column: span 12;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.kpi {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar {
  position: relative; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 6px; background: var(--panel-2); font-size: 12.5px;
  overflow: hidden;
}
.bar::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: var(--w, 0%);
  background: linear-gradient(90deg, rgba(122,162,247,.15), rgba(187,154,247,.10));
  z-index: 0;
}
.bar > * { position: relative; z-index: 1; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%; }
.bar-val { color: var(--muted); font-variant-numeric: tabular-nums; }

.geo-grid, .donut-grid { display: grid; gap: 16px; }
.geo-grid { grid-template-columns: 1fr 1fr; }
.donut-grid { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 880px) {
  .card { grid-column: span 12; }
  .geo-grid, .donut-grid { grid-template-columns: 1fr; }
}

.table-wrap { overflow-x: auto; }
.sessions-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.sessions-table th, .sessions-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.sessions-table th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.sessions-table tr { cursor: pointer; }
.sessions-table tr:hover { background: var(--panel-2); }
.sessions-table td { font-variant-numeric: tabular-nums; }
.flag { display: inline-block; margin-right: 4px; font-size: 14px; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); font-size: 11px; color: var(--muted); }
.filter input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 8px; font: inherit; min-width: 220px; }

.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 90vw);
  background: var(--panel); border-left: 1px solid var(--border);
  overflow: auto; padding: 20px;
}
.drawer-panel > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.drawer-panel h2 { font-size: 15px; }
.timeline { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.timeline-event {
  display: grid; grid-template-columns: 80px 1fr; gap: 10px;
  padding: 6px 10px; background: var(--panel-2); border-radius: 6px; font-size: 12.5px;
}
.timeline-event .ts { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline-event .ev-type { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 1px 5px; border-radius: 3px; background: var(--bg); color: var(--muted); margin-right: 6px; }
.summary-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.summary-list dt { color: var(--muted); }
.summary-list dd { margin: 0; }
