:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #161b26;
  --ink-2: #4a5468;
  --ink-3: #7b8597;
  --line: #e3e7ee;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --bar: #e7e9fd;
  --good: #0f9d6b;
  --ni: #d98c0a;
  --poor: #d93838;
  --good-soft: #e3f5ee;
  --poor-soft: #fbe9e9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --surface: #161b24; --surface-2: #1d2430; --ink: #e8ebf1; --ink-2: #b2bac8; --ink-3: #7d8799;
    --line: #262e3b; --accent: #8b85ff; --accent-ink: #0e1117; --accent-soft: #23234a; --bar: #262a4d;
    --good: #34c88f; --ni: #f0b03c; --poor: #f06a6a; --good-soft: #143528; --poor-soft: #3a1c1c;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --surface: #161b24; --surface-2: #1d2430; --ink: #e8ebf1; --ink-2: #b2bac8; --ink-3: #7d8799;
  --line: #262e3b; --accent: #8b85ff; --accent-ink: #0e1117; --accent-soft: #23234a; --bar: #262a4d;
  --good: #34c88f; --ni: #f0b03c; --poor: #f06a6a; --good-soft: #143528; --poor-soft: #3a1c1c;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* layout */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); }
.brand:hover { text-decoration: none; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 22l5-7 4 4 7-10' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; display: inline-block; flex: none; }
.topnav { display: flex; gap: 4px; }
.topnav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; }
.topnav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-right form { margin: 0; }
.topbar-right .link-btn { white-space: nowrap; }
.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.container.wide { max-width: 1320px; }
.footer { text-align: center; color: var(--ink-3); font-size: 12px; padding: 16px; }
.footer a { color: var(--ink-3); text-decoration: underline; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--poor); color: #fff; border-color: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn.danger { color: var(--poor); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; color: var(--ink-2); cursor: pointer; font-size: 16px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 36px; width: 100%; }
textarea { padding: 8px 10px; height: auto; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin-top: 2px; }
.input-sm { width: 90px; display: inline-block; }
label { display: block; font-weight: 550; font-size: 13px; color: var(--ink-2); }
label > input, label > select, label > textarea { margin-top: 6px; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--ink); margin: 0 0 12px; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 8px 0 16px; font-weight: 400; color: var(--ink); }
label.inline input { margin: 0; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash-ok { background: var(--good-soft); border-color: transparent; color: var(--ink); }
.flash-error { background: var(--poor-soft); border-color: transparent; color: var(--ink); }
.flash-info { background: var(--accent-soft); border-color: transparent; color: var(--ink); font-size: 13px; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.alt { background: var(--surface-2); color: var(--ink-2); }
.empty { color: var(--ink-3); padding: 28px 8px; text-align: center; }
.empty-state { text-align: center; padding: 48px; }
.loading { color: var(--ink-3); padding: 24px 0; text-align: center; }

/* forms */
.form-card h2 { margin-bottom: 16px; }
.form-card.narrow { max-width: 460px; }
.form-card label, .auth-card label { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 14px; }
.form-row.align-end { align-items: end; }
.form-row.align-end label { margin: 0; }

/* auth */
.auth { display: flex; align-items: center; justify-content: center; flex: 1; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 16px; }

/* sites */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 24px; }
.site-card { display: block; color: var(--ink); margin: 0; transition: border-color .15s; }
.site-card:hover { text-decoration: none; border-color: var(--accent); }
.site-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.avatar { width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.site-name { font-weight: 600; }
.site-card-stat strong { font-size: 20px; }
.live-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--good); background: var(--good-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.live-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); animation: pulse 2s infinite; }
.live-pill.idle { color: var(--ink-3); background: var(--surface-2); }
.live-pill.idle .dot { background: var(--ink-3); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th.num { text-align: right; }
.table td form { margin: 0; display: inline; }
.table.hover tr.clickable { cursor: pointer; }
.table.hover tr.clickable:hover td { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }

/* dashboard header */
.dash-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.site-switch { display: flex; align-items: center; gap: 10px; }
.site-switch select { font-weight: 650; font-size: 16px; width: auto; border-color: transparent; background-color: transparent; padding-left: 4px; }
.site-switch .live-pill { margin-left: 0; }
.tabs { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; overflow-x: auto; max-width: 100%; }
.tabs a { padding: 5px 12px; border-radius: 6px; color: var(--ink-2); white-space: nowrap; cursor: pointer; font-weight: 500; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.on { background: var(--accent); color: var(--accent-ink); }
.range-picker { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.range-picker select { width: auto; }
.range-picker input { width: 140px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--ink); border-radius: 99px; padding: 3px 4px 3px 12px; font-size: 13px; }
.chip button { border: 0; background: var(--surface); color: var(--ink-2); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; line-height: 1; }

/* KPIs + chart */
.chart-card { padding: 0; overflow: hidden; }
.kpis { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.kpi { flex: 1 1 140px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 16px 20px; background: none; border: 0; border-right: 1px solid var(--line); border-bottom: 3px solid transparent; text-align: left; font: inherit; color: var(--ink); cursor: pointer; }
.kpi:last-child { border-right: 0; }
.kpi.static { cursor: default; }
.kpi:not(.static):hover { background: var(--surface-2); }
.kpi.on { border-bottom-color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--ink-3); font-weight: 550; }
.kpi-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.change { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.change.up { color: var(--good); }
.change.down { color: var(--poor); }
.chart { position: relative; padding: 16px 16px 8px; min-height: 276px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .09; }
.chart .hover-line { stroke: var(--ink-3); stroke-dasharray: 3 3; }
.chart .hover-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.tooltip .muted { color: var(--bg); opacity: .7; }

/* report cards */
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 16px; }
.report-grid .card { margin: 0; }
.report { padding: 16px 18px; }
.report-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.report-head select, .report-head input { width: auto; height: 30px; }
.mini-tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.mini-tabs button { background: none; border: 0; font: inherit; font-size: 12.5px; color: var(--ink-3); padding: 3px 8px; border-radius: 6px; cursor: pointer; font-weight: 550; }
.mini-tabs button:hover { color: var(--ink); }
.mini-tabs button.on { color: var(--accent); background: var(--accent-soft); }
.bar-list { display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-flow: column; grid-auto-columns: minmax(56px, auto); gap: 12px; align-items: center; min-height: 32px; font-size: 13px; }
.bar-head { color: var(--ink-3); font-size: 11.5px; font-weight: 600; min-height: 24px; text-transform: uppercase; letter-spacing: .03em; }
.bar-label { position: relative; display: block; padding: 6px 8px; border-radius: 5px; overflow: hidden; }
.bar { position: absolute; inset: 0 auto 0 0; background: var(--bar); border-radius: 5px; }
.bar-text { position: relative; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row.clickable { cursor: pointer; }
.bar-row.clickable:hover .bar-label { outline: 1px solid var(--accent); outline-offset: -1px; }
.drill-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.drill-head #drill-filter { margin-left: auto; }

/* realtime */
.rt-top { display: grid; grid-template-columns: 280px 1fr; gap: 16px; margin-bottom: 16px; }
.rt-top .card { margin: 0; }
.rt-num { font-size: 56px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; color: var(--good); }
.rt-bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; margin-top: 12px; }
.rt-bars span { flex: 1; background: var(--accent); opacity: .75; border-radius: 2px 2px 0 0; min-height: 2px; }
.feed { max-height: 420px; overflow-y: auto; }
.feed-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; align-items: baseline; }
.feed-what { overflow: hidden; text-overflow: ellipsis; }

/* funnels */
.funnel { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(130px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.funnel-bar-wrap { height: 180px; background: var(--surface-2); border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; }
.funnel-bar { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; }
.funnel-meta { padding-top: 8px; font-size: 13px; }
.funnel-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop { color: var(--poor); font-size: 12px; }
.funnel-def { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.funnel-def form { margin-left: auto; }
.funnel-form { margin-top: 16px; }
.step-row { grid-template-columns: 24px 160px 1fr; margin-bottom: 8px; align-items: center; }
.step-num { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

/* retention */
.cohort { border-collapse: separate; border-spacing: 3px; width: 100%; font-size: 13px; }
.cohort th { font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 4px 8px; text-align: left; }
.cohort td { padding: 7px 8px; white-space: nowrap; }
.cohort td.cell.hi { color: #fff; }
.cohort td.cell { background: color-mix(in srgb, var(--accent) calc(var(--a) * 85%), var(--surface-2)); border-radius: 4px; color: var(--ink); }

/* vitals */
.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 16px; }
.vitals .card { margin: 0; border-top: 3px solid var(--line); }
.vital.good { border-top-color: var(--good); }
.vital.ni { border-top-color: var(--ni); }
.vital.poor { border-top-color: var(--poor); }
.vital-value { font-size: 28px; font-weight: 650; margin: 4px 0 10px; letter-spacing: -.02em; }
.dist { display: flex; height: 6px; border-radius: 3px; overflow: hidden; gap: 2px; margin-bottom: 6px; }
.dist .good, .rate.good { background: var(--good); }
.dist .ni, .rate.ni { background: var(--ni); }
.dist .poor, .rate.poor { background: var(--poor); }
.rate { padding: 1px 6px; border-radius: 4px; color: #fff; }
.rate:not(.good):not(.ni):not(.poor) { color: var(--ink-3); }

/* errors */
.err { border-bottom: 1px solid var(--line); padding: 10px 0; }
.err summary { display: flex; justify-content: space-between; gap: 16px; cursor: pointer; list-style: none; }
.err summary::-webkit-details-marker { display: none; }
.err-msg { font-family: var(--mono); font-size: 12.5px; color: var(--poor); word-break: break-word; }
.err-detail { padding: 8px 0 0; }

/* profiles */
.profile-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; margin-top: 12px; align-items: start; }
.traits { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.traits dt { color: var(--ink-3); }
.traits dd { margin: 0; word-break: break-word; }
.tl-session { border-left: 2px solid var(--line); padding: 0 0 16px 16px; margin-left: 6px; position: relative; }
.tl-session::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tl-session ul { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.tl-session li { padding: 3px 0; }

/* settings */
.settings-layout { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; }
.settings-nav a:hover { background: var(--surface); text-decoration: none; }
.settings-body section, .settings-body form.card { scroll-margin-top: 76px; }
.code-wrap { position: relative; }
.code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; white-space: pre; margin: 8px 0 12px; }
.code-wrap .code { padding-right: 80px; }
.copy-btn { position: absolute; top: 8px; right: 8px; }
.verify { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin: 4px 0 8px; }
.verify-result { font-size: 13px; padding: 6px 0; }
.verify-result.ok { color: var(--good); }
.verify-result.bad { color: var(--poor); }
.docs { margin-top: 12px; }
.docs summary { cursor: pointer; font-weight: 600; }
.toggles { margin-bottom: 8px; }
.danger-zone { border-color: var(--poor); }

@media (max-width: 600px) {
  .brand-text { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar-right { gap: 8px; }
  .dash-head { gap: 10px; }
}
@media (max-width: 860px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .topnav a { padding: 6px; }
  .range-picker { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .range-picker select { flex: 1; }
  .rt-top, .profile-grid, .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .kpi { flex-basis: 50%; border-bottom-width: 3px; }
  .kpi-value { font-size: 20px; }
  .bar-row { grid-auto-columns: minmax(44px, auto); gap: 8px; }
  .step-row { grid-template-columns: 24px 1fr; }
  .step-row input { grid-column: 1 / -1; }
}

/* keep wide content scrolling inside its card instead of widening the page */
.report-body { overflow-x: auto; }
.settings-layout > *, .report-grid > *, .profile-grid > * { min-width: 0; }
