/* ── Design tokens ─────────────────────────────────────────────────
   Neutrals, type, radii and elevation come from the portfolio design system
   (Portfolio/portfolio/src/style.css → @theme and [data-theme="light"]).
   Data colours (--series, --event, …) are Blip's own, validated for charts.
   See docs/design-system.md before changing anything here.

   Surfaces step in three layers, as in the portfolio:
     --bg         page canvas
     --surface    cards
     --surface-2  something nested inside a card. In light mode it's *lighter*
                  than its card and separated by a hairline, never a darker fill. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #F6F7F8;
  --surface-2: #FBFBFC;
  --inner-line: rgba(0, 0, 0, 0.06);
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.12);
  --text: #111111;
  --text-2: rgba(0, 0, 0, 0.7);
  --text-3: rgba(0, 0, 0, 0.55);
  --btn: rgba(0, 0, 0, 0.06);
  --btn-hover: rgba(0, 0, 0, 0.1);
  --nav-bg: rgba(255, 255, 255, 0.85);
  --indicator: rgba(0, 0, 0, 0.06);
  --indicator-line: rgba(0, 0, 0, 0.08);
  --brand: #03C067;
  --input-bg: #ffffff;

  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --series: #2a78d6;
  --series-hover: #1f63b7;
  --track: rgba(0, 0, 0, 0.06);
  --link-in: #1a7f37;
  --isp: #c2410c;
  --exit: #3b3fb6;
  --event: #6250d6;
  --event-soft: rgba(98, 80, 214, 0.1);
  --danger: #c62828;
  --live: #03C067;

  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.06);
  --elevation-2: 0 2px 4px rgba(0, 0, 0, 0.04), 0 10px 28px rgba(0, 0, 0, 0.1);
  --elevation-3: 0 2px 6px rgba(0, 0, 0, 0.06), 0 14px 32px rgba(0, 0, 0, 0.14);
  --shadow: none;
  --radius: 16px;
  --radius-inner: 10px;
  --sans: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
/* Dark: the portfolio's default theme. Applied when chosen, or when following a dark OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000; --surface: #171717; --surface-2: #1c1c1c; --inner-line: rgba(255, 255, 255, 0.06);
    --line: rgba(255, 255, 255, 0.1); --line-strong: rgba(255, 255, 255, 0.15);
    --text: #ffffff; --text-2: rgba(255, 255, 255, 0.7); --text-3: rgba(255, 255, 255, 0.5);
    --btn: rgba(255, 255, 255, 0.1); --btn-hover: rgba(255, 255, 255, 0.2); --nav-bg: rgba(0, 0, 0, 0.8);
    --indicator: rgba(255, 255, 255, 0.1); --indicator-line: rgba(255, 255, 255, 0.15); --input-bg: #0d0d0d;
    --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.16); --series: #3987e5; --series-hover: #62a1ec;
    --track: rgba(255, 255, 255, 0.08); --link-in: #4cc46a; --isp: #f0864a; --exit: #9aa0ff;
    --event: #9085e9; --event-soft: rgba(144, 133, 233, 0.16); --danger: #ef6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000; --surface: #171717; --surface-2: #1c1c1c; --inner-line: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.1); --line-strong: rgba(255, 255, 255, 0.15);
  --text: #ffffff; --text-2: rgba(255, 255, 255, 0.7); --text-3: rgba(255, 255, 255, 0.5);
  --btn: rgba(255, 255, 255, 0.1); --btn-hover: rgba(255, 255, 255, 0.2); --nav-bg: rgba(0, 0, 0, 0.8);
  --indicator: rgba(255, 255, 255, 0.1); --indicator-line: rgba(255, 255, 255, 0.15); --input-bg: #0d0d0d;
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.16); --series: #3987e5; --series-hover: #62a1ec;
  --track: rgba(255, 255, 255, 0.08); --link-in: #4cc46a; --isp: #f0864a; --exit: #9aa0ff;
  --event: #9085e9; --event-soft: rgba(144, 133, 233, 0.16); --danger: #ef6b6b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Header */
.top { background: var(--nav-bg); -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; text-decoration: none; color: var(--text); letter-spacing: -.02em; }
.brand svg { color: var(--brand); }
.brand span { color: var(--text); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  text-decoration: none; color: var(--text-2); padding: 6px 10px; border-radius: 7px; white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}
.tabs a:hover { background: var(--btn); color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--indicator); box-shadow: inset 0 0 0 1px var(--indicator-line); font-weight: 600; }

/* Filters */
.filters { max-width: 1240px; margin: 0 auto; padding: 16px 16px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters.hidden { display: none; }
.spacer { flex: 1; }
.updated { color: var(--text-3); font-size: 12.5px; }
select, .btn, .seg button, input, textarea {
  border: 1px solid var(--line-strong); background: var(--input-bg); border-radius: var(--radius-inner);
}
select { height: 34px; padding: 0 30px 0 10px; appearance: none; cursor: pointer; min-width: 170px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; }
.seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-inner); background: var(--btn); }
.seg button { border: 0; border-radius: 8px; height: 28px; padding: 0 11px; cursor: pointer; color: var(--text-2); background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.seg button[aria-checked="true"] { background: var(--input-bg); color: var(--text); font-weight: 600; box-shadow: var(--elevation-1), inset 0 0 0 1px var(--indicator-line); }
.seg button:hover:not([aria-checked="true"]) { background: var(--btn); }
.btn { height: 34px; padding: 0 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; background: var(--btn); border-color: transparent; font-weight: 550; text-decoration: none; transition: background-color .15s ease, transform .1s ease; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--text); color: var(--bg); font-weight: 600; }
.btn.primary:hover { background: var(--text); opacity: .86; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--btn); }
.btn.danger { color: var(--danger); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout */
.view { max-width: 1240px; margin: 0 auto; padding: 16px 16px 64px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: none; letter-spacing: 0; }
.card-h .right { margin-left: auto; }
.stack { display: grid; gap: 16px; }
.grid-lists { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
@media (max-width: 400px) { .grid-lists { grid-template-columns: 1fr; } }
.muted { color: var(--text-3); }
.empty { padding: 28px 16px; color: var(--text-3); text-align: center; }
.loading { padding: 48px; text-align: center; color: var(--text-3); }
.error { padding: 16px; color: var(--danger); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { padding: 14px 16px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi .label { color: var(--text-3); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 620; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .kpi { border-right: 0; border-bottom: 1px solid var(--line); } }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 3px color-mix(in oklab, var(--live) 25%, transparent); }

/* Sites table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--text-3); font-size: 12.5px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table tbody tr.clickable { cursor: pointer; transition: background-color .12s ease; }
.table tbody tr.clickable:hover { background: var(--btn); }
.site-cell { display: flex; flex-direction: column; }
.site-cell strong { font-weight: 600; }
.site-cell small { color: var(--text-3); }
.scroll-x { overflow-x: auto; }
.hide-sm { }
@media (max-width: 720px) { .hide-sm { display: none; } }

/* Chart */
.chart { position: relative; padding: 4px 16px 12px; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series); transition: fill .1s ease; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.on .bar { fill: var(--series-hover); }
.spark { display: block; width: 120px; height: 28px; }
.spark path.l { fill: none; stroke: var(--series); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark path.a { fill: var(--series); opacity: .12; }

/* Bar lists */
.blist { list-style: none; margin: 0; padding: 4px 8px 10px; }
.blist li { position: relative; display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 6px; min-height: 30px; }
.blist li .fill { position: absolute; inset: 2px auto 2px 0; background: var(--accent-soft); border-radius: 5px; z-index: 0; }
.blist li > *:not(.fill) { position: relative; z-index: 1; }
.blist .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.blist .lbl a { text-decoration: none; }
.blist .lbl a:hover { text-decoration: underline; }
.blist .n { font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 40px; text-align: right; }
.blist .n2 { font-variant-numeric: tabular-nums; color: var(--text-3); min-width: 44px; text-align: right; font-size: 12.5px; }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--btn); color: var(--text-2); white-space: nowrap; flex: none; }
.tag.event { background: var(--event-soft); color: var(--event); border-color: transparent; }

/* Visitor log */
.log { overflow: hidden; }
.sess { border-bottom: 1px solid var(--line); }
.sess:last-child { border-bottom: 0; }
.sess-h { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--inner-line); }
.sess-h > * { min-width: 0; }
.sess-h .where { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto; overflow-wrap: anywhere; }
.flag { font-size: 18px; line-height: 1; }
.isp { color: var(--isp); }
.ip { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.sess-h .who { display: flex; align-items: center; gap: 6px; }
.sess-h .dev { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.icon-btn { border: 0; background: transparent; padding: 3px; border-radius: 5px; cursor: pointer; color: var(--accent); display: inline-flex; }
.icon-btn:hover { background: var(--accent-soft); }
.steps { display: grid; grid-template-columns: 70px 72px 1fr; padding: 4px 16px 8px; }
.steps > div { padding: 4px 0; border-bottom: 1px dashed var(--line); min-width: 0; }
.steps > div:nth-last-child(-n+3) { border-bottom: 0; }
.steps .d, .steps .t { color: var(--text-2); font-variant-numeric: tabular-nums; }
.steps .t small { color: var(--text-3); }
.steps .what { overflow-wrap: anywhere; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.steps .ref { color: var(--link-in); text-decoration: none; }
.steps .page { text-decoration: none; }
.steps .page:hover, .steps .ref:hover, .steps .exit:hover { text-decoration: underline; }
.steps .page .p { color: var(--text-3); font-size: 12.5px; }
.steps .exit { color: var(--exit); text-decoration: none; }
.steps .exit b { font-weight: 650; }
@media (max-width: 640px) {
  .steps { grid-template-columns: 70px 1fr; }
  .steps .d { display: none; }
  .sess-h .dev { margin-left: 0; flex-wrap: wrap; }
  .sess-h .where { flex-basis: 100%; }
  .seg { max-width: 100%; overflow-x: auto; }
  .filters .spacer { display: none; }
}
.more { padding: 14px; text-align: center; border-top: 1px solid var(--line); }
.notice { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--text); margin-bottom: 16px; }

/* Funnels */
.funnel { padding: 6px 16px 16px; display: grid; gap: 10px; }
.fstep { display: grid; grid-template-columns: minmax(120px, 220px) 1fr 110px; gap: 12px; align-items: center; }
.fstep .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fstep .name .i { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; display: grid; place-items: center; flex: none; font-variant-numeric: tabular-nums; }
.fstep .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fstep .trk { height: 26px; background: var(--track); border-radius: 4px; position: relative; overflow: hidden; }
.fstep .trk div { position: absolute; inset: 0 auto 0 0; background: var(--series); border-radius: 4px; }
.fstep .stat { text-align: right; font-variant-numeric: tabular-nums; }
.fstep .stat small { display: block; color: var(--text-3); font-size: 12px; }
.fdrop { color: var(--text-3); font-size: 12px; margin: -4px 0 -2px; padding-left: 28px; }
@media (max-width: 640px) { .fstep { grid-template-columns: 1fr 90px; } .fstep .trk { grid-column: 1 / -1; grid-row: 2; } }

/* Sites admin */
.site-admin { padding: 16px; display: grid; gap: 14px; }
.field { display: grid; gap: 5px; align-content: start; }
.field > span { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.field small { color: var(--text-3); }
.row { align-items: start; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
input, textarea { padding: 8px 10px; width: 100%; font-size: 16px; }
@media (min-width: 720px) { input, textarea { font-size: 14px; } }
textarea { font-family: var(--mono); font-size: 13px; min-height: 84px; resize: vertical; line-height: 1.5; }
.code { position: relative; font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 84px 10px 12px; overflow-x: auto; white-space: pre; }
.code .btn { position: absolute; top: 6px; right: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msg { font-size: 13px; color: var(--text-3); }
.msg.err { color: var(--danger); }
details.help { border-top: 1px solid var(--line); padding: 12px 16px; }
details.help summary { cursor: pointer; color: var(--text-2); }
details.help code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--input-bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-inner); padding: 8px 10px; font-size: 12.5px;
  box-shadow: var(--elevation-2); min-width: 120px;
}
.tooltip .tt-t { color: var(--text-3); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-size: 14px; font-variant-numeric: tabular-nums; }
.tooltip .key { width: 12px; height: 2px; background: var(--series); border-radius: 1px; }

/* Docs */
.docs { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.docs-toc { position: sticky; top: 68px; }
.docs-toc-in { display: grid; gap: 2px; }
.toc-label { font-size: 12px; color: var(--text-3); font-weight: 600; padding: 4px 10px 8px; }
.docs-toc a:not(.btn) { text-decoration: none; color: var(--text-2); padding: 5px 10px; border-radius: 6px; font-size: 13.5px; }
.docs-toc a:not(.btn):hover { background: var(--btn); color: var(--text); }
.docs-toc a[aria-current] { color: var(--accent); background: var(--accent-soft); }
.toc-actions { display: grid; gap: 6px; margin-top: 14px; padding: 0 4px; justify-items: start; }
.docs-body { padding: 28px 36px 40px; max-width: 820px; line-height: 1.65; font-size: 15px; }
.docs-body h1 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 8px; line-height: 1.2; }
.docs-body h2 { font-size: 20px; letter-spacing: -.01em; margin: 40px 0 10px; padding-top: 20px; border-top: 1px solid var(--line); scroll-margin-top: 72px; }
.docs-body h3 { font-size: 16px; margin: 26px 0 6px; scroll-margin-top: 72px; }
.docs-body p { margin: 10px 0; color: var(--text); text-wrap: pretty; }
.docs-body ul, .docs-body ol { padding-left: 22px; margin: 10px 0; }
.docs-body li { margin: 5px 0; }
.docs-body li > ul, .docs-body li > ol { margin: 4px 0; }
.docs-body a { color: var(--accent); text-underline-offset: 2px; }
.docs-body code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.docs-body .doc-code { white-space: normal; padding: 0; margin: 12px 0; }
.docs-body .doc-code pre { margin: 0; padding: 14px 84px 14px 14px; overflow-x: auto; }
.docs-body .doc-code code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.55; white-space: pre; overflow-wrap: normal; }
.docs-body .doc-table { margin: 12px 0; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; border-collapse: separate; border-spacing: 0; }
.docs-body .doc-table th, .docs-body .doc-table td { padding: 8px 12px; vertical-align: top; }
.docs-body .doc-table th { background: var(--surface-2); color: var(--text-2); }
@media (max-width: 860px) {
  .docs { grid-template-columns: minmax(0, 1fr); }
  .docs-toc { position: static; }
  .docs-toc-in { display: flex; flex-wrap: wrap; gap: 4px; }
  .toc-label { width: 100%; }
  .toc-actions { display: flex; margin-top: 4px; }
  .docs-body { padding: 20px 16px 28px; }
}

/* Theme switcher & account */
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.theme-seg button { width: 30px; padding: 0; }
.theme-seg svg { width: 15px; height: 15px; }
@media (max-width: 640px) {
  .top-inner { flex-wrap: wrap; height: auto; gap: 6px 12px; padding-top: 8px; padding-bottom: 6px; }
  .tabs { order: 3; width: 100%; }
  .logout-label { display: none; }
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; display: grid; gap: 18px; }
.login-card .brand { font-size: 18px; }
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login-card p { margin: -10px 0 0; color: var(--text-3); }
.login-card .btn { width: 100%; justify-content: center; height: 40px; }
.login-card input { height: 40px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: -8px; }

/* Copy buttons sit on top of scrolling code; give them a solid chip so text slides under cleanly. */
.code .btn { background: var(--input-bg); box-shadow: var(--elevation-1), inset 0 0 0 1px var(--line); }
::placeholder { color: var(--text-3); opacity: .6; }
