:root {
	color-scheme: light;
	--bg: #f6f4fa;
	--surface: #ffffff;
	--surface-2: #f2eff8;
	--border: #e6e1ef;
	--grid: #ece8f3;
	--text: #1e1e1e;
	--text-2: #55516a;
	--muted: #858198;
	--accent: #532ebc;
	--accent-ink: #ffffff;
	--accent-hover: #4423a3;
	--wash: rgba(83, 46, 188, 0.09);
	--wash-strong: rgba(83, 46, 188, 0.16);
	--prev: #a9a4b8;
	--good: #11804a;
	--bad: #c0392b;
	--lime: #bced09;
	--shadow: 0 1px 2px rgba(30, 20, 60, 0.05), 0 4px 16px rgba(30, 20, 60, 0.04);
	--radius: 14px;
	--font: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--brand-font: 'Comfortaa', 'Poppins', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme='light']) {
		color-scheme: dark;
		--bg: #110f15;
		--surface: #1a1720;
		--surface-2: #221e2a;
		--border: #2e2938;
		--grid: #27232f;
		--text: #f1eff5;
		--text-2: #bdb8c9;
		--muted: #8d889c;
		--accent: #a08af3;
		--accent-ink: #140e26;
		--accent-hover: #b6a5f6;
		--wash: rgba(160, 138, 243, 0.12);
		--wash-strong: rgba(160, 138, 243, 0.22);
		--prev: #625d73;
		--good: #4cc38a;
		--bad: #f07a6a;
		--shadow: none;
	}
}
:root[data-theme='dark'] {
	color-scheme: dark;
	--bg: #110f15;
	--surface: #1a1720;
	--surface-2: #221e2a;
	--border: #2e2938;
	--grid: #27232f;
	--text: #f1eff5;
	--text-2: #bdb8c9;
	--muted: #8d889c;
	--accent: #a08af3;
	--accent-ink: #140e26;
	--accent-hover: #b6a5f6;
	--wash: rgba(160, 138, 243, 0.12);
	--wash-strong: rgba(160, 138, 243, 0.22);
	--prev: #625d73;
	--good: #4cc38a;
	--bad: #f07a6a;
	--shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
	background: var(--bg);
	color: var(--text);
	font: 400 14px/1.5 var(--font);
	-webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.5em; margin: 6px 0; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---- brand */
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font: 600 19px/1 var(--brand-font); letter-spacing: -0.01em; }
.brand small { font: 500 12px var(--font); color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.brand-lg { font-size: 28px; }
.eye {
	width: 22px; height: 22px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
	background: var(--accent); position: relative; flex: none;
}
.eye::after { content: ''; position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--lime); left: 6.5px; top: 6.5px; }
.brand-lg .eye { width: 30px; height: 30px; }
.brand-lg .eye::after { width: 12px; height: 12px; left: 9px; top: 9px; }

/* ---- buttons & inputs */
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn-danger { color: var(--bad); }
input, select, textarea {
	background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label, .lbl { font-size: 13px; color: var(--text-2); font-weight: 500; }
.step-edit .fld .lbl { font-size: 11.5px; }

/* ---- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow); display: grid; gap: 6px; }
.login-card p.muted { margin: 0 0 14px; }
.login-card .btn { margin-top: 6px; padding: 10px; }

/* ---- header */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.top-row { max-width: 1240px; margin: 0 auto; padding: 12px 16px 6px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.custom-range { display: inline-flex; align-items: center; gap: 4px; }
.custom-range input { padding: 5px 8px; }
.live-pill { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.live-pill b { color: var(--text); font-weight: 600; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.tabs { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { text-decoration: none; padding: 8px 12px 10px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current='page'] { color: var(--text); border-bottom-color: var(--accent); }

/* ---- layout */
.wrap { max-width: 1240px; margin: 0 auto; padding: 16px 16px 64px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.filters:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--wash); border: 1px solid var(--wash-strong); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px; }
.chip b { font-weight: 600; }
.chip button { border: 0; background: transparent; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; color: var(--text-2); line-height: 1; }
.chip button:hover { background: var(--wash-strong); color: var(--text); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
.grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.empty { color: var(--muted); padding: 24px 4px; text-align: center; font-size: 13px; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 24px 0 0; flex-wrap: wrap; }
.section-title h1 { font-size: 20px; }

/* ---- KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; text-align: left; cursor: default; display: grid; gap: 2px; box-shadow: var(--shadow); }
.tile.pick { cursor: pointer; }
.tile.pick:hover { border-color: var(--wash-strong); }
.tile[aria-pressed='true'] { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.tile .label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.delta { font-size: 12px; font-weight: 500; color: var(--muted); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---- chart */
.chart { position: relative; width: 100%; height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cur { stroke: var(--accent); }
.chart .prev { stroke: var(--prev); }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14); padding: 8px 10px; font-size: 12.5px; min-width: 140px; }
.tooltip .t-head { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.tooltip .t-row span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tooltip .t-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- bar lists */
.list { display: grid; gap: 2px; }
.list-head, .row { display: grid; grid-template-columns: minmax(0, 1fr) 72px 64px; gap: 8px; align-items: center; }
.list-head { font-size: 11.5px; color: var(--muted); padding: 0 8px 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.list-head span:not(:first-child), .row .v { text-align: right; }
.row { position: relative; border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; text-align: left; width: 100%; cursor: pointer; z-index: 0; }
.row::before { content: ''; position: absolute; inset: 1px auto 1px 0; width: var(--w, 0%); background: var(--wash); border-radius: 6px; z-index: -1; }
.row:hover::before { background: var(--wash-strong); }
.row .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .k small { color: var(--muted); margin-left: 6px; }
.row .v { font-variant-numeric: tabular-nums; font-weight: 500; }
.row .v2 { color: var(--text-2); font-weight: 400; }
.more { margin-top: 8px; font-size: 12.5px; }
.more a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ---- tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { font-size: 11.5px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; white-space: normal; vertical-align: bottom; min-width: 64px; }
th:first-child, td:first-child { text-align: left; }
td:first-child { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover td { background: var(--surface-2); }
td .link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--text); text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
td .link:hover { color: var(--accent); text-decoration: underline; }
td.zero { color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; font-weight: 500; }
.tag.test { background: color-mix(in srgb, var(--lime) 40%, transparent); color: var(--text); }

/* ---- funnels */
.funnel-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.pill { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 500; }
.pill[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.funnel { display: grid; gap: 0; margin-top: 4px; }
.fstep { display: grid; grid-template-columns: minmax(160px, 260px) minmax(0, 1fr) 110px; gap: 16px; align-items: center; padding: 10px 0; }
.fstep .fl { display: grid; gap: 2px; min-width: 0; }
.fstep .fl b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fstep .fl small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fstep .n { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 0.05em; }
.ftrack { height: 24px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.fbar { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.fbar.zero { min-width: 0; }
.fval { text-align: right; display: grid; }
.fval b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fval small { color: var(--muted); font-size: 12px; }
.fdrop { display: grid; grid-template-columns: minmax(160px, 260px) minmax(0, 1fr); gap: 16px; color: var(--muted); font-size: 12.5px; }
.fdrop span:last-child { padding-left: 2px; }
.fdrop b { color: var(--text-2); font-weight: 600; }
@media (max-width: 700px) {
	.fstep { grid-template-columns: minmax(0, 1fr) 90px; }
	.fstep .ftrack { grid-column: 1 / -1; grid-row: 2; }
	.fdrop { grid-template-columns: 1fr; }
	.fdrop span:first-child { display: none; }
}
.conv-cell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.mini { width: 60px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; display: inline-block; }
.mini i { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }

/* ---- editor / dialog */
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(15, 10, 30, 0.45); }
.dlg { padding: 20px; display: grid; gap: 14px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg > .fld { display: grid; gap: 3px; max-width: 420px; }
.steps-edit { display: grid; gap: 10px; }
.step-edit { display: grid; grid-template-columns: 26px minmax(0, 1.3fr) 120px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; padding: 10px; background: var(--surface-2); border-radius: 12px; }
.step-edit .idx { font-weight: 600; color: var(--muted); padding-bottom: 8px; }
.step-edit .fld { display: grid; gap: 3px; min-width: 0; }
.step-edit .fld label { font-size: 11.5px; }
.step-edit .acts { display: flex; gap: 2px; }
.step-edit .acts button { width: 30px; height: 34px; padding: 0; }
@media (max-width: 700px) {
	.step-edit { grid-template-columns: 26px minmax(0, 1fr) minmax(0, 1fr); }
	.step-edit .acts { grid-column: 2 / -1; }
}
.dlg-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.help { font-size: 12.5px; color: var(--muted); margin: 0; }
.help code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; color: var(--text-2); }

/* ---- links */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.form-grid .fld { display: grid; gap: 3px; }
.form-grid .wide { grid-column: 1 / -1; }
.out { display: flex; gap: 8px; margin-top: 12px; align-items: stretch; flex-wrap: wrap; }
.out input { flex: 1 1 320px; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 12.5px; }

/* ---- live */
.hero { font-size: 56px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.feed td:first-child { color: var(--muted); }
