:root {
  --brand: #5b2d8e;
  --brand-dark: #44206d;
  --brand-soft: #f1eaf8;
  --brand-line: #d9c9ec;
  --bg: #faf9fc;
  --surface: #ffffff;
  --text: #231a30;
  --muted: #655c73;
  --line: #e4dfec;
  --ok: #1d7a46;
  --ok-bg: #e5f5ec;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --info: #1f55a3;
  --info-bg: #e6eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 26, 48, .06), 0 2px 8px rgba(35, 26, 48, .04);
  --focus: 0 0 0 3px #fff, 0 0 0 5px #7b49b5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; color: var(--text); }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-dark); }
code, .mono, textarea.mono, input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code { background: #f3eff8; padding: .08em .35em; border-radius: 4px; word-break: break-all; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--brand); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* layout */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .6rem 16px; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; }
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; letter-spacing: -.01em; }
.brand svg { flex: none; }
.brand:hover { color: #fff; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.nav a { color: #eadcf7; text-decoration: none; padding: .35rem .7rem; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.2); color: #fff; }
.topbar :focus-visible { box-shadow: 0 0 0 2px var(--brand), 0 0 0 4px #fff; }
.userbox { display: flex; align-items: center; gap: .6rem; font-size: .9rem; color: #eadcf7; }
.userbox .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.45); }
.userbox .btn:hover { background: rgba(255,255,255,.14); }
.userbox a { color: #eadcf7; text-decoration: none; border-bottom: 1px dotted rgba(234,220,247,.5); }
.userbox a:hover, .userbox a:focus-visible { color: #fff; border-bottom-color: #fff; }
.mockbar { background: #ffe9a8; color: #5c4300; text-align: center; font-size: .85rem; padding: .25rem 1rem; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.crumbs { font-size: .875rem; color: var(--muted); margin-bottom: .35rem; }
.crumbs a { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: .5rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.row.end { justify-content: flex-end; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card.flat { box-shadow: none; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.kpi .v { font-size: 1.6rem; font-weight: 700; color: var(--brand); line-height: 1.2; }
.kpi .l { font-size: .85rem; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-size: .95rem; font-weight: 600; min-height: 40px; padding: .4rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f6f2fa; border-color: var(--brand-line); color: var(--text); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn.danger { background: #fff; border-color: #e7b4ae; color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { min-height: 32px; padding: .2rem .6rem; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn[disabled]:hover { background: #fff; border-color: var(--line); }
.btn.primary[disabled]:hover { background: var(--brand); border-color: var(--brand); }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* forms */
label { font-weight: 600; font-size: .92rem; display: block; margin-bottom: .25rem; }
.field { margin-bottom: 1rem; }
.field .hint, .hint { font-size: .85rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }
.field .err, .err { font-size: .85rem; color: var(--bad); margin-top: .25rem; font-weight: 600; }
input[type=text], input[type=url], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 1rem; color: var(--text); background: #fff; border: 1px solid #c9bfd8; border-radius: 8px; padding: .5rem .65rem; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: #f3f1f6; color: #6e6679; cursor: not-allowed; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; accent-color: var(--brand); margin: 0; flex: none; }
.check { display: flex; align-items: flex-start; gap: .55rem; font-weight: 500; margin-bottom: .4rem; cursor: pointer; font-size: .95rem; }
.check input { margin-top: .22rem; }
.check .hint { display: block; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: .35rem; }
.inline-fields { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); align-items: start; }
.opt-cards { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.opt-card { border: 1.5px solid var(--line); border-radius: 10px; padding: .7rem .85rem; display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; background: #fff; font-weight: 500; margin: 0; }
.opt-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.opt-card:has(input:focus-visible) { box-shadow: var(--focus); }
.opt-card input { margin-top: .2rem; }
.opt-card strong { display: block; }
.opt-card .hint { margin-top: .1rem; }
.opt-card:has(input:disabled) { opacity: .65; cursor: not-allowed; }
.input-suffix { display: flex; align-items: center; gap: .4rem; }
.input-suffix input { max-width: 8rem; }

/* badges + alerts */
.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; font-weight: 700; padding: .12rem .55rem; border-radius: 999px; background: #eeebf2; color: #4b4358; white-space: nowrap; line-height: 1.4; }
.badge.success { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.muted { background: #f3f1f6; color: #6e6679; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; display: inline-block; }
.alert { border-radius: 10px; padding: .75rem 1rem; border: 1px solid; margin-bottom: 1rem; font-size: .95rem; }
.alert strong { display: block; }
.alert.error { background: var(--bad-bg); border-color: #f2b8b2; color: #7a1710; }
.alert.warn { background: var(--warn-bg); border-color: #f0d28a; color: #5c3d00; }
.alert.info { background: var(--info-bg); border-color: #b8cdef; color: #173f7a; }
.alert.success { background: var(--ok-bg); border-color: #aad8bd; color: #14562f; }
.alert ul { margin: .35rem 0 0 1.1rem; padding: 0; }
.alert .row { margin-top: .5rem; }
.empty { text-align: center; padding: 2.2rem 1rem; color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff; }
.empty h3 { color: var(--text); }
.empty p { max-width: 46ch; margin-left: auto; margin-right: auto; }
.spinner { width: 1.1rem; height: 1.1rem; border: 3px solid var(--brand-line); border-top-color: var(--brand); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { scroll-behavior: auto !important; } }
.loading { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1.25rem; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; border-radius: 6px 6px 0 0; }
.tabs a:hover { color: var(--brand); background: var(--brand-soft); }
.tabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .65rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: center; justify-content: space-between; }
.list > li:last-child { border-bottom: 0; }

/* overview */
.client-block { margin-bottom: 2rem; }
.client-block > h2 { display: flex; align-items: center; gap: .6rem; }
.site-card { margin-bottom: 1rem; padding: 0; overflow: hidden; }
.site-head { padding: .9rem 1.2rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between; align-items: center; background: #fdfcff; border-bottom: 1px solid var(--line); }
.site-head h3 { margin: 0; font-size: 1.1rem; }
.site-meta { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; font-size: .85rem; color: var(--muted); }
.site-body { padding: .25rem 1.2rem .6rem; }
.exp-row { display: grid; grid-template-columns: minmax(0, 2fr) auto minmax(0, 2fr); gap: .5rem 1rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.exp-row:last-child { border-bottom: 0; }
.exp-row .title { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
@media (max-width: 700px) { .exp-row { grid-template-columns: 1fr; } }

/* experiment editor */
.stepper { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.25rem; padding: 0; list-style: none; counter-reset: s; }
.stepper button { font: inherit; font-weight: 600; font-size: .92rem; border: 1.5px solid var(--line); background: #fff; color: var(--muted); border-radius: 999px; padding: .35rem .9rem .35rem .45rem; cursor: pointer; display: flex; align-items: center; gap: .45rem; min-height: 40px; }
.stepper button .n { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: #eeebf2; color: #4b4358; font-size: .8rem; }
.stepper button[aria-current="step"] { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.stepper button[aria-current="step"] .n { background: var(--brand); color: #fff; }
.stepper button.has-error .n { background: var(--bad); color: #fff; }
.rule-row { display: grid; grid-template-columns: minmax(120px, 170px) minmax(0, 1fr) auto auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.rule-row.cond { grid-template-columns: minmax(110px, 150px) minmax(80px, 140px) minmax(110px, 150px) minmax(0, 1fr) auto; }
@media (max-width: 700px) { .rule-row, .rule-row.cond { grid-template-columns: 1fr 1fr; } .rule-row > :nth-child(2), .rule-row.cond > :nth-child(4) { grid-column: 1 / -1; } }
.tester { background: var(--brand-soft); border: 1px solid var(--brand-line); border-radius: 10px; padding: .85rem 1rem; }
.tester-result { margin-top: .6rem; font-weight: 600; }
.tester-result.ok { color: var(--ok); }
.tester-result.no { color: var(--bad); }
.variant-card { border: 1.5px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; background: #fff; margin-bottom: 1rem; border-left: 6px solid var(--vc, var(--brand)); }
.variant-card > .vhead { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: .75rem; align-items: end; margin-bottom: .75rem; }
@media (max-width: 560px) { .variant-card > .vhead { grid-template-columns: 1fr; } }
.weightbar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: #eeebf2; margin: .4rem 0 .3rem; }
.weightbar span { display: block; height: 100%; }
details.change { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; background: #fdfcff; }
details.change > summary { cursor: pointer; padding: .55rem .8rem; font-weight: 600; font-size: .92rem; list-style: none; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
details.change > summary::-webkit-details-marker { display: none; }
details.change > summary::before { content: "▸"; color: var(--brand); margin-right: .45rem; }
details.change[open] > summary::before { content: "▾"; }
details.change > .body { padding: .25rem .8rem .8rem; }
details.change.invalid { border-color: #e7b4ae; }
.json-box { min-height: 160px; }
.calc { background: #fdfcff; border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.calc-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-top: .75rem; }
.calc-out .kpi { background: #fff; }
.wizard-nav { display: flex; justify-content: space-between; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }
.savebar { position: sticky; bottom: 0; background: rgba(250,249,252,.96); border-top: 1px solid var(--line); padding: .7rem 16px; margin: 1.5rem -16px -64px; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; z-index: 10; backdrop-filter: blur(4px); }

/* results */
.metric-card { margin-bottom: 1rem; }
.metric-card .mhead { display: flex; flex-wrap: wrap; gap: .5rem .8rem; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.metric-card h3 { margin: 0; }
.bar-wrap { background: #eeebf2; border-radius: 999px; height: 12px; overflow: hidden; }
.bar { background: var(--brand); height: 100%; border-radius: 999px; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .85rem; margin-top: .4rem; }
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: inherit; fill: #655c73; font-size: 11px; }
.advice { background: var(--brand-soft); border-left: 4px solid var(--brand); padding: .75rem 1rem; border-radius: 0 8px 8px 0; margin: .75rem 0; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg label { margin: 0; padding: .35rem .8rem; cursor: pointer; font-size: .88rem; font-weight: 600; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }
.seg label:has(input:focus-visible) { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5px #7b49b5; }

/* feed + dialog + toast */
.feed td, .feed th { padding: .35rem .6rem; font-size: .85rem; }
.feed-box { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.copybox { display: flex; gap: .5rem; align-items: stretch; }
.copybox textarea, .copybox input { flex: 1; min-width: 0; }
.steps-list { padding-left: 1.2rem; margin: .5rem 0; }
.steps-list li { margin-bottom: .4rem; }
dialog { border: 0; border-radius: 14px; padding: 0; max-width: min(520px, calc(100vw - 32px)); width: 100%; box-shadow: 0 20px 60px rgba(35,26,48,.35); color: var(--text); }
dialog::backdrop { background: rgba(35,26,48,.5); }
.dlg { padding: 1.3rem 1.4rem; }
.dlg h2 { margin-top: 0; }
.dlg .row { margin-top: 1rem; justify-content: flex-end; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: #2b2038; color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 420px; font-size: .93rem; }
.toast.error { background: var(--bad); }
.toast.success { background: #17613a; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #f1eaf8 0%, #faf9fc 60%); }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { color: var(--brand); margin-bottom: 1rem; font-size: 1.3rem; }
@media (max-width: 480px) { h1 { font-size: 1.35rem; } main { padding-top: 16px; } .card { padding: .95rem 1rem; } .site-head, .site-body { padding-left: 1rem; padding-right: 1rem; } }
.chips .badge { white-space: normal; }
.noscript { padding: 2rem; }
