:root {
  color-scheme: light dark;
  /* Trample brand (brand/trample-tokens.css). Plum for text and strong controls on light surfaces, orchid for
     the chart series, rose and petal only as decoration. Dark-mode steps were contrast-checked separately. */
  --plum: #411950;
  --orchid: #8e4394;
  --rose: #c36ca8;
  --petal: #e7adcd;
  --paper: #f6f2f3;

  --surface-0: light-dark(var(--paper), #121211);
  --surface-1: light-dark(#fcfcfb, #1a1a19);
  --surface-2: light-dark(#efe8ec, #2a2230);
  --border: light-dark(#e6dde2, #2e2a30);
  --text-primary: light-dark(var(--plum), #f0efec);
  --text-secondary: light-dark(#5c4a62, #c3c2b7);
  --text-muted: light-dark(#6e5f73, #9a998f);
  --series-1: light-dark(var(--orchid), #b06ab6);
  --series-1-wash: light-dark(rgb(142 67 148 / 0.10), rgb(176 106 182 / 0.16));
  --bar: light-dark(#f3e4ee, #2e1f33);
  --link: light-dark(var(--orchid), #c58bcb);
  --primary-bg: light-dark(var(--plum), var(--petal));
  --primary-fg: light-dark(#ffffff, var(--plum));
  --good: light-dark(#006300, #0ca30c);
  --bad: light-dark(#b42f2f, #e66767);
  --accent: light-dark(var(--orchid), #c58bcb);
  --radius: 10px;
  accent-color: var(--accent);
  --display: "Rubik", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

/* Display face for headings and headline numbers; it echoes the heavy, rounded wordmark. Self-hosted (OFL,
   fonts/OFL.txt): an analytics tool that promises no tracking shouldn't fetch fonts from a third party. */
@font-face {
  font-family: "Rubik"; src: url("/fonts/rubik-latin-wght.woff2") format("woff2");
  font-weight: 300 900; font-display: swap;
}
h1, h2, .kpi .value { font-family: var(--display); }

* { box-sizing: border-box; }
body { margin: 0; background: var(--surface-0); color: var(--text-primary); }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

button, select, input {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px max(16px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--border);
  background: light-dark(var(--paper), var(--surface-1));
}
.brand { display: flex; align-items: center; text-decoration: none; }
/* Transparent lockup; <picture> swaps in the reversed artwork on dark surfaces. */
.brand img { display: block; height: 40px; width: auto; }
.topbar-site { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-site[hidden] { display: none; }
#site-select { font-weight: 600; max-width: 60vw; }
.live { color: var(--text-secondary); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }

main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }

/* ---- controls ---- */
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.controls .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--surface-1); border: 1px solid var(--border); font-size: 14px;
}
.chip b { font-weight: 600; }
.chip button { border: 0; padding: 0 6px; background: transparent; font-size: 16px; line-height: 1; color: var(--text-muted); }
.chip button:hover { color: var(--text-primary); }
.custom-range { display: inline-flex; gap: 6px; align-items: center; }

/* ---- cards ---- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-bottom: 1px solid var(--border); }
.kpi {
  text-align: left; border: 0; border-radius: 0; background: transparent; padding: 14px 18px;
  border-bottom: 3px solid transparent;
}
.kpi[aria-pressed="true"] { border-bottom-color: var(--series-1); }
.kpi:hover { background: var(--surface-2); }
.kpi:disabled { cursor: default; opacity: 1; }
.kpi:disabled:hover { background: transparent; }
.kpi .label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .delta { font-size: 13px; color: var(--text-muted); }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--bad); }

.chart-wrap { position: relative; padding: 16px 12px 8px 4px; }
.chart-wrap svg { display: block; width: 100%; height: 280px; overflow: visible; }
.chart-wrap .grid line { stroke: var(--border); stroke-width: 1; }
.chart-wrap .axis text { fill: var(--text-muted); font-size: 12px; }
.chart-wrap .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .area { fill: var(--series-1-wash); }
/* The bucket still in progress (today, this hour): dashed, so a partial count doesn't read as a drop. */
.chart-wrap .line.partial { stroke-dasharray: 4 4; }
.compare { margin: 0; padding: 8px 18px 0; font-size: 13px; color: var(--text-muted); }
.chart-wrap .crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-wrap .marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
  white-space: nowrap;
}
.tooltip .t-date { color: var(--text-secondary); }
.tooltip .t-val { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.tooltip .t-val::before { content: ""; width: 10px; height: 2px; background: var(--series-1); }
.chart-table { padding: 0 16px 12px; font-size: 14px; }
.chart-table summary { color: var(--text-secondary); cursor: pointer; width: fit-content; }
.chart-table table { margin-top: 8px; border-collapse: collapse; }
.chart-table td, .chart-table th { padding: 2px 16px 2px 0; text-align: left; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
.panel { padding: 14px 16px 12px; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; font-weight: 600; margin: 0; flex: 1; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 2px 8px; font-size: 13px; color: var(--text-secondary); border-radius: 6px; }
.tabs button[aria-selected="true"] { color: var(--text-primary); font-weight: 600; background: var(--surface-2); }
.list-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); font-weight: 500; padding: 0 6px 4px; }
.list-head span:last-child { display: flex; gap: 16px; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.row { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.row .bar-cell { position: relative; flex: 1; min-width: 0; }
.row .bar { position: absolute; inset: 0 auto 0 0; background: var(--bar); border-radius: 4px; }
.row .label {
  position: relative; display: block; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 4px 6px; border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .label:hover { text-decoration: underline; background: transparent; }
.row .metric { min-width: 48px; text-align: right; font-weight: 600; }
.row .metric.secondary { color: var(--text-muted); font-weight: 400; }
.empty { color: var(--text-muted); padding: 24px 6px; text-align: center; margin: auto 0; }

/* ---- sites page ---- */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; flex: 1; }
.site-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.site-card { padding: 16px; text-decoration: none; display: block; }
.site-card:hover { border-color: var(--series-1); }
.site-card h3 { margin: 0 0 4px; font-size: 16px; }
.site-card .meta { color: var(--text-muted); font-size: 13px; }
.site-card .figure { font-size: 22px; font-weight: 700; margin-top: 8px; }
.welcome { padding: 32px; text-align: center; }
.welcome p { color: var(--text-secondary); max-width: 52ch; margin: 8px auto 20px; }

.snippet { padding: 16px; margin-bottom: 16px; }
.snippet h2 { margin: 0 0 6px; font-size: 16px; }
.snippet p { margin: 0 0 10px; color: var(--text-secondary); font-size: 14px; }
.snippet pre {
  margin: 0; padding: 12px; background: var(--surface-2); border-radius: 8px;
  overflow-x: auto; font-size: 13px;
}
.snippet .snippet-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  background: var(--surface-1); color: var(--text-primary);
  width: min(440px, calc(100vw - 32px));
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--text-secondary); }
dialog input, dialog select { width: 100%; color: var(--text-primary); }
.form-error { color: var(--bad); font-size: 14px; min-height: 1.2em; margin: 0 0 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.error-banner { padding: 12px 16px; border-color: var(--bad); color: var(--bad); margin-bottom: 16px; }

@media (max-width: 600px) {
  .kpi .value { font-size: 21px; }
  .kpi { padding: 12px; }
}

/* ---- sign-in page ---- */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(400px, 100%); padding: 28px; }
.auth .brand { margin-bottom: 20px; }
.auth .brand img { height: 48px; }
.auth-foot { margin: 20px 0 0; font-size: 13px; color: var(--text-muted); text-align: center; }
.auth-foot a, .shared-foot a { color: var(--link); }
.shared-foot { margin-top: 24px; font-size: 13px; color: var(--text-muted); text-align: center; }
.auth h1 { font-size: 22px; margin: 0 0 6px; }
.auth .lead { color: var(--text-secondary); margin: 0 0 18px; }
.auth label { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }
.auth input { width: 100%; margin-bottom: 12px; }
.wide { width: 100%; padding: 9px 12px; }
.wide + .wide { margin-top: 8px; }
button.link, a.link { border: 0; background: transparent; color: var(--link); text-decoration: underline; padding: 6px; }
button.link:hover { background: transparent; }
.or { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.auth .form-error { margin: 12px 0 0; }
button:disabled { opacity: 0.6; cursor: progress; }

/* ---- signed-in chrome, account & settings ---- */
.user-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 14px; }
.user-nav[hidden] { display: none; }
.user-nav a { color: var(--text-secondary); text-decoration: none; padding: 6px; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-nav a:hover { color: var(--text-primary); text-decoration: underline; }
.settings { display: grid; gap: 16px; max-width: 760px; }
.settings section { padding: 18px; }
.settings h2 { font-size: 16px; margin: 0 0 4px; }
.settings .hint { color: var(--text-secondary); font-size: 14px; margin: 0 0 14px; }
.settings .inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.settings .inline input[type="email"] { flex: 1; min-width: 200px; }
.item-list { list-style: none; margin: 0 0 14px; padding: 0; border-top: 1px solid var(--border); }
.item-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.item-list .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-list .sub { color: var(--text-muted); font-size: 13px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); }
.danger { border-color: var(--bad); }
button.danger-btn { color: var(--bad); border-color: var(--bad); }
.status-line { font-size: 14px; color: var(--text-secondary); min-height: 1.3em; margin: 8px 0 0; }
.status-line.error { color: var(--bad); }
.back { display: inline-block; margin-bottom: 12px; color: var(--text-secondary); font-size: 14px; }
a.button-link {
  display: inline-block; text-decoration: none; border: 1px solid var(--border);
  background: var(--surface-1); border-radius: 8px; padding: 6px 10px;
}
a.button-link:hover { background: var(--surface-2); }

/* ---- billing ---- */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; flex-wrap: wrap; }
.banner .grow { flex: 1; min-width: 200px; }
.banner.bad { border-color: var(--bad); }
.banner.warn { border-color: light-dark(#c98500, #eda100); }
.banner a { color: var(--link); font-weight: 600; }
.meter { margin: 6px 0 16px; }
.meter-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-secondary); margin-bottom: 6px; }
.meter-label b { color: var(--text-primary); }
.meter-track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; background: var(--series-1); border-radius: 5px; }
.meter-fill.over { background: light-dark(#c98500, #eda100); }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.plan { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.plan.current { border-color: var(--series-1); }
.plan h3 { margin: 0; font-size: 16px; }
.plan .price { font-size: 26px; font-weight: 700; }
.plan .price span { font-size: 14px; font-weight: 400; color: var(--text-secondary); }
.plan .hint { flex: 1; margin: 0 0 8px; }
.settings.billing { max-width: 860px; }

/* ---- organizations, sign-in ---- */
.org-group { margin-bottom: 24px; }
.org-head { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 10px; }
.org-head h2 { margin: 0; font-size: 17px; }
.org-head a { color: var(--link); font-size: 14px; }
.subhead { font-size: 14px; margin: 18px 0 4px; }
.badge.ok { color: var(--good); }
.policy { display: grid; gap: 6px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.inline-label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--text-secondary); }
.rules { list-style: decimal; padding-left: 22px; margin: 0 0 12px; display: grid; gap: 8px; }
.rule { font-size: 14px; color: var(--text-secondary); }
.rule select, .rule input { margin: 0 4px; }
.rule input { width: 180px; }
fieldset.provider { border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; padding: 10px 14px; display: grid; gap: 8px; }
fieldset.provider legend { font-weight: 600; padding: 0 4px; }
fieldset.provider label:not(.check) { display: grid; gap: 4px; font-size: 14px; color: var(--text-secondary); }
code { overflow-wrap: anywhere; }
a.button.wide.sso { display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px; padding: 9px 12px; color: var(--text-primary); }
a.button.wide.sso:hover { background: var(--surface-2); }
a.button.wide.sso + a.button.wide.sso { margin-top: 8px; }
a.button.wide.sso svg { width: 18px; height: 18px; }
a.button.wide.sso[hidden], #sso-block[hidden], #email-form[hidden] { display: none; }
fieldset.provider p { margin: 0; }
