:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7c7b76;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --bar-track: #eceae5;
  --danger: #c43b3a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --border: #2e2e2c;
    --grid: #262624;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --bar-track: #262624;
    --danger: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface-1: #1a1a19; --border: #2e2e2c; --grid: #262624;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --bar-track: #262624; --danger: #e66767;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 650; font-size: 15px; color: var(--text-primary); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 12px; border-radius: 6px; color: var(--text-secondary); }
.nav a.on { background: var(--bg); color: var(--text-primary); font-weight: 600; }
.nav a:hover { text-decoration: none; color: var(--text-primary); }
.topbar .right { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.topbar form { margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.sub { color: var(--text-secondary); margin: 4px 0 0; }

.ranges { display: flex; gap: 2px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.ranges a { padding: 4px 10px; border-radius: 6px; color: var(--text-secondary); font-size: 13px; }
.ranges a.on { background: var(--bg); color: var(--text-primary); font-weight: 600; }
.ranges a:hover { text-decoration: none; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .k { color: var(--text-secondary); font-size: 12px; }
.tile .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.n, th.n { text-align: right; white-space: nowrap; }
td.path { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--text-muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 12px; color: var(--text-secondary); }
.empty { color: var(--text-muted); padding: 16px 0; }

/* Inline bar inside a table cell: value shown as text, bar shows magnitude. */
.barcell { position: relative; min-width: 120px; }
.barcell .track { height: 8px; background: var(--bar-track); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.barcell .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

/* Line chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .s1 { stroke: var(--series-1); }
.chart .s2 { stroke: var(--series-2); }
.chart .dot1 { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .dot2 { fill: var(--series-2); stroke: var(--surface-1); stroke-width: 2; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; color: var(--text-secondary); font-size: 12px; margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); display: none; white-space: nowrap; z-index: 5; }
.tooltip b { display: block; margin-bottom: 2px; }

/* Journeys */
.steps { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.step { padding: 2px 8px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); font-size: 12px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arrow { color: var(--text-muted); font-size: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li { position: relative; padding: 4px 0 8px 16px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface-1); border: 2px solid var(--text-muted); }
.timeline li.pageview::before { border-color: var(--series-1); background: var(--series-1); }
.timeline li.click::before { border-color: var(--series-2); }
.timeline li.page_leave::before { border-color: var(--danger); }
.timeline .when { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 8px; }
.timeline .etype { font-weight: 600; margin-right: 6px; }
.session-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }

form.inline { display: flex; gap: 8px; }
input[type=text], input[type=password], input[type=search] { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-1); color: var(--text-primary); font: inherit; }
button, .btn { padding: 7px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1); color: var(--text-primary); font: inherit; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.linkbtn { background: none; border: none; padding: 0; color: var(--text-secondary); cursor: pointer; }

.login { max-width: 360px; margin: 12vh auto; }
.login label { display: block; font-size: 12px; color: var(--text-secondary); margin: 12px 0 4px; }
.login input { width: 100%; }
.login .err { color: var(--danger); margin-top: 8px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #1baf7a; margin-right: 6px; }
