:root {
  color-scheme: light;
  --page: #eef1f6;
  --surface: #ffffff;
  --text: #1a1a1e;
  --text-2: #5c5f66;
  --muted: #8a8f99;
  --grid: #e6e9ef;
  --axis: #cfd4dc;
  --border: rgba(20, 25, 40, 0.14);
  --hover: rgba(20, 25, 40, 0.05);
  --seg: #eceef2;
  --accent: #8955ee;
  --accent-soft: rgba(137, 85, 238, 0.1);
  --series-1: #8955ee;
  --series-prev: #b9bec8;
  /* Categorical chart palette, fixed order */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948;
  --good: #1a7f37;
  --bad: #d03b3b;
  --live: #0ca30c;
  --shadow: 0 1px 2px rgba(20, 25, 40, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #111114;
    --surface: #1c1c1f;
    --text: #ffffff;
    --text-2: #c5c7cc;
    --muted: #8a8f99;
    --grid: #2b2c31;
    --axis: #3a3b41;
    --border: rgba(255, 255, 255, 0.14);
    --hover: rgba(255, 255, 255, 0.07);
    --seg: #26272c;
    --accent: #9a6cf5;
    --accent-soft: rgba(154, 108, 245, 0.16);
    --series-1: #9a6cf5;
    --series-prev: #5d6068;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
    --good: #3fb950;
    --bad: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell: icon rail on the left, content on the right */
.shell { display: grid; grid-template-columns: 60px minmax(0, 1fr); min-height: 100vh; }
.shell.wide { grid-template-columns: 244px minmax(0, 1fr); }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; padding: 14px 12px; overflow-y: auto; }
.rail-brand { display: flex; align-items: center; gap: 10px; height: 36px; margin-bottom: 12px; padding-left: 3px; font-weight: 650; font-size: 15px; white-space: nowrap; }
.rail img { width: 30px; height: 30px; flex: none; }
.rail button { height: 36px; display: flex; align-items: center; gap: 10px; padding: 0 8px; border: 0; border-radius: 10px; background: none; color: var(--text-2); text-align: left; white-space: nowrap; overflow: hidden; }
.rail svg { flex: none; }
.shell:not(.wide) .rail span { display: none; }
.shell.wide .rail-toggle svg { transform: rotate(180deg); }
.rail button:hover { background: var(--hover); color: var(--text); }
.rail button[aria-current="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); font-weight: 550; }
.rail svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail .spacer { display: block !important; flex: 1; }
.content { padding: 0 16px 48px 4px; max-width: 1400px; }

/* Top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; }
.site { display: inline-flex; align-items: center; border-radius: 10px; background: var(--seg); }
.site select { border: 0; background-color: var(--surface); box-shadow: var(--shadow); font-weight: 550; max-width: 220px; }
.site span { padding: 0 12px; color: var(--text-2); white-space: nowrap; }
.site b { color: var(--text); font-weight: 550; }
.spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 7px; padding: 0 8px; color: var(--text-2); white-space: nowrap; }
.live b { color: var(--text); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--live); }

.btn, select, input[type="date"], input[type="text"], input[type="password"] {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 550; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }

/* Cards */
.card { background: var(--surface); border-radius: 20px; }
.card + .card, .card + .grid, .install { margin-top: 12px; }
.grid > .card { margin-top: 0; }
.loading { opacity: 0.55; transition: opacity 0.15s; }

/* Report header: title, period, filters */
.report { padding: 22px 28px 24px; margin-bottom: 12px; }
.report h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 18px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--seg); max-width: 100%; overflow-x: auto; }
.seg button { height: 30px; padding: 0 14px; border: 0; border-radius: 9px; background: none; color: var(--text); white-space: nowrap; }
.seg button:hover { background: var(--hover); }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 550; }
.custom { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 6px 0 14px; border: 1px solid var(--border); border-radius: 10px; max-width: 100%; }
.chip span { color: var(--text-2); }
.chip b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.chip button { width: 24px; height: 24px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 16px; line-height: 1; }
.chip button:hover { background: var(--hover); color: var(--text); }

/* Metric tiles */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); border-bottom: 1px solid var(--grid); }
.kpi { padding: 18px 20px 14px; border: 0; border-right: 1px solid var(--grid); background: none; text-align: left; position: relative; min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi:first-child { border-top-left-radius: 20px; }
.kpi:last-child { border-top-right-radius: 20px; }
.kpi:hover { background: var(--hover); }
.kpi[aria-pressed="true"]::after { content: ""; position: absolute; left: 20px; right: 20px; bottom: -1px; height: 2px; border-radius: 1px; background: var(--accent); }
.kpi[aria-pressed="true"] .kpi-label { color: var(--accent); }
.kpi-label { color: var(--text-2); font-size: 13px; }
.kpi-value { font-size: 26px; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; }
.delta { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

/* Chart */
.chart-head { display: flex; align-items: center; gap: 16px; padding: 14px 20px 0 28px; color: var(--text-2); font-size: 13px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--series-1); }
.chart { position: relative; padding: 8px 16px 14px; }
.chart svg { display: block; width: 100%; outline-offset: -2px; }
.chart text { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line.prev { stroke: var(--series-prev); stroke-width: 1.5; }
.area { fill: var(--series-1); opacity: 0.1; }
.cross { stroke: var(--axis); stroke-width: 1; }
.dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; top: 12px; pointer-events: none; z-index: 2;
  min-width: 150px; padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(20, 25, 40, 0.14); font-size: 12.5px;
}
.tip-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tip-row b { margin-left: auto; padding-left: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--text-2); }
.tip-title { color: var(--muted); margin-bottom: 2px; }

/* Donut: shares of a whole */
.donut-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 24px 48px; padding: 24px 28px; }
.donut { width: 200px; flex: none; }
.donut svg { display: block; width: 100%; }
.segment { stroke: var(--surface); stroke-width: 2; transition: opacity 0.12s; }
.focus .segment:not(.on) { opacity: 0.35; }
.donut-total { fill: var(--text); font-size: 28px; font-weight: 650; }
.donut-caption { fill: var(--muted); font-size: 12px; }
.donut-legend { display: grid; gap: 2px; min-width: 260px; flex: 0 1 380px; }
.donut-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 64px; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; }
.donut-row.on { background: var(--hover); }
.donut-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.donut-row small { color: var(--muted); text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.swatch { width: 12px; height: 12px; border-radius: 3px; }

/* Report tables */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.grid.single { grid-template-columns: 1fr; }
.grid.single .panel-head h2 { display: none; }
.grid.single .panel-head:has(.tabs:empty) { display: none; }
.grid.single .row, .grid.single .row-head { grid-template-columns: minmax(0, 1fr) 160px 140px; }
.rows.queries .row, .rows.queries .row-head { grid-template-columns: minmax(0, 1fr) 110px 110px 90px 90px; }
.hint { margin: 0 28px 14px; padding: 10px 14px; border-radius: 10px; background: var(--seg); color: var(--text-2); }
.note { padding: 24px 28px; max-width: 760px; }
.note p + p { margin-top: 10px; color: var(--text-2); }
.note .hint { margin: 0; padding: 0; background: none; }
.note + .grid { margin-top: 12px; }
.panel { overflow: hidden; scroll-margin-top: 12px; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 20px 20px 14px 28px; flex-wrap: wrap; }
.panel-head h2 { font-size: 18px; font-weight: 700; margin-right: auto; }
.tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--seg); }
.tabs:empty { display: none; }
.tabs button { height: 26px; padding: 0 10px; border: 0; border-radius: 8px; background: none; font-size: 13px; }
.tabs button:hover { background: var(--hover); }
.tabs button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); font-weight: 550; }
.rows.all { max-height: 560px; overflow-y: auto; }
.row, .row-head { display: grid; grid-template-columns: minmax(0, 1fr) 112px 104px; width: 100%; border: 0; border-top: 1px solid var(--grid); background: none; text-align: left; padding: 0; }
.row > *, .row-head > * { padding: 9px 16px; min-width: 0; }
.row > :first-child, .row-head > :first-child { padding-left: 28px; }
.row > :not(:first-child), .row-head > :not(:first-child) { border-left: 1px solid var(--grid); text-align: right; }
.row-head { color: var(--text-2); font-size: 13px; }
.row-head > :nth-child(2) { color: var(--text); }
.row.total { background: var(--hover); }
button.row:hover { background: var(--accent-soft); }
.row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; }
.row .num { font-variant-numeric: tabular-nums; }
.row.page:hover { background: var(--accent-soft); }
.row.page .label { display: flex; align-items: center; gap: 6px; overflow: visible; }
.page-name { min-width: 0; padding: 0; border: 0; background: none; text-align: left; }
.page-name span, .page-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-name small { color: var(--muted); font-size: 11.5px; }
.page-name:hover span { color: var(--accent); }
.ext { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: var(--muted); }
.ext:hover { background: var(--hover); color: var(--accent); }
.ext svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row .num small { display: block; color: var(--muted); font-size: 11.5px; }
.empty { padding: 28px 16px 40px; text-align: center; color: var(--muted); border-top: 1px solid var(--grid); }
.more { display: block; margin: 8px auto 12px; }

/* Data table for the chart */
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 7px 16px; text-align: right; border-top: 1px solid var(--grid); }
table.data th { color: var(--text-2); font-weight: 500; font-size: 13px; border-top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; padding-left: 12px; }
.table-scroll { max-height: 320px; overflow-y: auto; }

/* Forms: login, add site, install snippet */
.center { max-width: 400px; margin: 12vh auto 0; padding: 28px; }
.center h1 { font-size: 22px; margin-bottom: 4px; }
.center p { color: var(--text-2); margin-bottom: 16px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; color: var(--text-2); font-size: 13px; }
.form input, .form select { width: 100%; height: 40px; }
.error { color: var(--bad); min-height: 20px; }
.install { padding: 22px 28px; margin-bottom: 12px; }
.install h2 { font-size: 18px; margin-bottom: 4px; }
.install p { color: var(--text-2); }
pre { margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--seg); overflow-x: auto; font: 12.5px/1.5 ui-monospace, Menlo, monospace; }

@media (max-width: 900px) {
  .shell, .shell.wide { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; padding: 10px 12px 0; overflow-x: auto; }
  .rail-brand, .rail-toggle, .rail .spacer { display: none !important; }
  .rail button { flex: none; }
  .shell .rail button span, .shell:not(.wide) .rail button span { display: inline; }
  .grid.single .row, .grid.single .row-head { grid-template-columns: minmax(0, 1fr) 96px 80px; }
  .hint, .note { margin-left: 16px; margin-right: 16px; }
  .rows.queries { overflow-x: auto; }
  .rows.queries .row, .rows.queries .row-head { grid-template-columns: minmax(160px, 1fr) 80px 80px 70px 70px; min-width: 460px; }
  .note { margin: 0; padding: 18px 16px; }
  .content { padding: 0 12px 40px; }
  .grid { grid-template-columns: 1fr; }
  .report { padding: 18px 16px; }
  .report h1 { font-size: 22px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi { padding: 14px 16px 12px; border-bottom: 1px solid var(--grid); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-last-child(-n+2) { border-bottom: 0; }
  .kpi:first-child, .kpi:last-child { border-radius: 0; }
  .kpi[aria-pressed="true"]::after { left: 16px; right: 16px; }
  .rail button[aria-current="true"] { box-shadow: none; }
  .kpi-value { font-size: 22px; }
  .chart-head { padding-left: 16px; }
  .panel-head { padding: 16px; }
  .row > :first-child, .row-head > :first-child { padding-left: 16px; }
  .row, .row-head { grid-template-columns: minmax(0, 1fr) 96px 80px; }
  .row > *, .row-head > * { padding: 9px 10px; }
}
