:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f2f2f0;
  --border: #e6e6e3;
  --grid: #efefec;
  --text-primary: #111111;
  --text-secondary: #55554f;
  --text-muted: #85857d;
  --accent: #2a78d6;
  --accent-soft: #eaf2fc;
  --series-1: #2a78d6;
  --series-1-soft: #b7d3f6;
  --good: #0a8a0a;
  --critical: #c93434;
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5; --seq-550: #1c5cab; --seq-700: #0d366b;
  --radius: 12px;
  --font: "Inter Variable", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2c2c2a;
    --grid: #252523;
    --text-primary: #f5f5f3;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1b2738;
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --good: #2fb52f;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2c2c2a;
  --grid: #252523;
  --text-primary: #f5f5f3;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --accent-soft: #1b2738;
  --series-1: #3987e5;
  --series-1-soft: #184f95;
  --good: #2fb52f;
  --critical: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 26px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
button, select, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- layout */

.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; letter-spacing: -0.01em; padding: 0 8px; }
.brand svg { width: 18px; height: 18px; fill: var(--accent); stroke: none; }
.app-picker select { width: 100%; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button, .theme {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: 0; border-radius: 8px; padding: 8px 10px; color: var(--text-secondary); cursor: pointer;
}
.nav button svg, .theme svg { width: 18px; height: 18px; flex: none; }
.nav button:hover, .theme:hover { background: var(--surface-2); color: var(--text-primary); }
.nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.theme { margin-top: auto; }

.content { min-width: 0; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 32px 36px 20px; max-width: 1360px;
}
.sub { margin: 6px 0 0; color: var(--text-secondary); max-width: 720px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
main { padding: 0 36px 48px; max-width: 1360px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .app-picker { flex: 1; min-width: 160px; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  .nav button { width: auto; white-space: nowrap; }
  .theme { margin: 0; width: auto; }
  .theme span { display: none; }
  .page-head { padding: 20px 16px 14px; }
  main { padding: 0 16px 32px; }
}

/* ---------------------------------------------------------------- controls */

select, input[type="search"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; outline: none;
}
select { appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%2385857d' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 550; }
button.ghost { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: var(--text-secondary); }
button.ghost:hover { color: var(--text-primary); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { background: none; border: 0; border-radius: 7px; padding: 5px 12px; color: var(--text-secondary); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text-primary); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 0 0 1px var(--border); font-weight: 550; }

/* ---------------------------------------------------------------- blocks */

.notice { background: var(--accent-soft); color: var(--text-secondary); border-radius: 10px; padding: 10px 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 0; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.about { color: var(--text-muted); font-size: 12.5px; line-height: 1.45; margin: 3px 0 0; }
.card > .about { margin-bottom: 14px; }
.chart { position: relative; height: 210px; }
.empty { color: var(--text-muted); padding: 28px 0; text-align: center; margin: 0; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr)); gap: 16px; }
.grid-events { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .grid-events { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 15px; }
.tile .label { color: var(--text-secondary); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.025em; margin-top: 4px; line-height: 1.15; }
.tile .sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--critical); }

.table-wrap { overflow: auto; max-height: 640px; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--text-muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.table td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table tr.selected td { background: var(--accent-soft); }
.table code, .mono, code { font-family: var(--mono); font-size: 12px; }
.params { color: var(--text-muted); font-size: 12px; font-family: var(--mono); word-break: break-word; }
.tag { display: inline-block; font-size: 11px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; margin-left: 4px; }

.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; align-items: baseline; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { color: var(--text-secondary); font-size: 12.5px; text-align: right; white-space: nowrap; }
.bar-row .track { grid-column: 1 / -1; height: 5px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--series-1); border-radius: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chip { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); border-radius: 999px; padding: 3px 11px; font-size: 12.5px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.heat td.cell { text-align: right; min-width: 56px; border-bottom: 2px solid var(--surface); border-right: 2px solid var(--surface); border-radius: 4px; }
.funnel-form .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#funnel-steps { display: grid; gap: 8px; }
.step-row { display: flex; gap: 8px; align-items: center; }
.step-row select { flex: 1; min-width: 0; }
.step-row .num { color: var(--text-muted); width: 18px; text-align: right; }
#funnel-result { margin-top: 20px; }
.report { white-space: pre-wrap; font: 13px/1.55 var(--mono); margin: 0; color: var(--text-primary); background: var(--surface-2); border-radius: 8px; padding: 14px; }
.check { color: var(--text-secondary); font-size: 13px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }

.about-grid .card h2 { margin-bottom: 8px; }
.about-grid ul { margin: 0; padding-left: 18px; color: var(--text-secondary); }
.about-grid li { margin: 4px 0; }
.about-grid p { color: var(--text-secondary); margin: 0 0 8px; }
.accuracy { display: inline-block; font-size: 11.5px; font-weight: 550; border-radius: 6px; padding: 1px 7px; margin-left: 6px; vertical-align: 1px; }
.accuracy.exact { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.accuracy.approx { background: var(--surface-2); color: var(--text-secondary); }
