:root {
  color-scheme: dark;
  --page: #0a0a0a;
  --surface: #141414;
  --surface-2: #1b1b1b;
  --border: rgba(255, 255, 255, 0.10);
  --grid: #2c2c2a;
  --axis: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #f97316;
  --accent-ink: #0a0a0a;
  --good: #0ca30c;
  --bad: #e66767;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body {
  font-family: "Exo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .brand { font-family: "Orbitron", "Exo 2", system-ui, sans-serif; letter-spacing: 0.04em; }
h2 { font-size: 15px; font-weight: 700; text-transform: uppercase; margin: 0 0 4px; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }
.brand small { display: block; font-family: "Exo 2", sans-serif; font-weight: 500; letter-spacing: 0.02em; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.spacer { flex: 1; }
.ranges { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.custom { display: none; gap: 6px; align-items: center; }
.custom.open { display: flex; }
.custom input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; font-size: 13px;
}
.who { font-size: 13px; color: var(--muted); white-space: nowrap; }
.who a { color: var(--text-2); margin-left: 8px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 64px; }
section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; }
.section-head .spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
}

/* ---------- KPI tiles ---------- */
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.delta { font-size: 12px; font-weight: 600; margin-top: 6px; color: var(--muted); display: inline-flex; gap: 4px; align-items: center; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta .vs { color: var(--muted); font-weight: 500; }

/* ---------- legend / site tags ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.legend span, .site-tag { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.site-tag { font-weight: 600; color: var(--text); }

/* ---------- charts ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: #222221; border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; min-width: 150px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 0.08s;
}
.tooltip.show { opacity: 1; }
.tooltip .t-title { color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.toggle {
  background: none; border: 1px solid var(--border); color: var(--text-2); border-radius: 8px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.toggle:hover { color: var(--text); background: var(--surface-2); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { text-align: right; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; border-top: 1px solid var(--axis); }
td .delta { margin: 0 0 0 6px; }

/* ---------- bar lists ---------- */
.bars { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.bars li { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 6px; font-size: 13px; overflow: hidden; }
.bars li .fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; opacity: 0.28; }
.bars li .k, .bars li .v { position: relative; }
.bars li .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bars li .v { color: var(--text-2); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 13px; padding: 14px 0 4px; }

/* ---------- funnel ---------- */
.site-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.site-card-head .rate { font-size: 12px; color: var(--muted); }
.site-card-head .rate b { color: var(--text); font-size: 16px; }
.funnel { display: grid; gap: 8px; }
.step .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); gap: 8px; }
.step .row b { color: var(--text); font-variant-numeric: tabular-nums; }
.step .track { height: 10px; background: var(--surface-2); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.step .bar { height: 100%; border-radius: 4px; }
.events { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 4px; }
.events div { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); gap: 8px; }
.events div b { color: var(--text); font-variant-numeric: tabular-nums; }
.events div.zero b { color: var(--muted); font-weight: 500; }

select.filter {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px;
}

/* ---------- tabs ---------- */
.tabs { border-top: 1px solid var(--border); }
.tabs-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs-inner::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer;
  padding: 11px 14px 9px; font-size: 14px; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.chip.ghost { background: none; }

/* ---------- view header + highlights ---------- */
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
h1 { font-size: 22px; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 10px; text-transform: uppercase; }
.dot.big { width: 14px; height: 14px; border-radius: 4px; }
.range-label { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.range-label a { color: var(--text-2); }
.live { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--text-2); background: var(--surface); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.5); } 70% { box-shadow: 0 0 0 8px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }
.highlights { margin-top: 16px; border-left: 3px solid var(--accent); }
.highlights h3 { color: var(--accent); margin-bottom: 8px; }
.highlights ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; color: var(--text-2); }
.highlights b { color: var(--text); }
.highlights .up, .up { color: var(--good); font-weight: 600; }
.highlights .down, .down { color: var(--bad); font-weight: 600; }
.highlights .site-tag { display: inline-flex; vertical-align: -1px; }

/* ---------- info buttons + floating tooltip ---------- */
.info {
  width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 700; line-height: 1; padding: 0; cursor: help; display: inline-grid; place-items: center; font-family: Georgia, serif; font-style: italic;
  margin-left: 6px; vertical-align: 2px; flex: none;
}
.info:hover, .info:focus-visible { color: var(--text); border-color: var(--accent); outline: none; }
.tip {
  position: fixed; z-index: 50; max-width: 280px; pointer-events: none; opacity: 0; transition: opacity 0.1s;
  background: #222221; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.45; color: var(--text-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.tip.show { opacity: 1; }

/* ---------- cards: heads, KPI extras, segmented switches ---------- */
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.card-head .spacer { flex: 1; }
.kpis.seven { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.kpi .label { display: flex; align-items: center; }
.kpi .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
@media (max-width: 1100px) { .kpis.seven { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 760px) { .kpis.seven { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.seg { margin-left: auto; display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); }
.bars li .v small { color: var(--muted); font-size: 11px; margin-left: 4px; }
section.grid.tight > div { min-width: 0; }
.placeholder { color: var(--muted); padding: 60px 0; text-align: center; }
.stack { display: grid; gap: 12px; align-content: start; }
.section-head h2 { display: inline-flex; align-items: center; }

/* ---------- scorecards ---------- */
.score { display: flex; flex-direction: column; gap: 12px; }
.score-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.small-link { font-size: 12px; color: var(--muted); text-decoration: none; }
.small-link:hover { color: var(--text-2); }
.score-main { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.score-main .value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.score-main .label { font-size: 12px; color: var(--muted); }
.spark { width: 120px; height: 36px; flex: none; }
.score-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0; padding-top: 10px; border-top: 1px solid var(--border); }
.score-stats div { display: flex; flex-direction: column; }
.score-stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.score-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-stats dd small { font-weight: 500; color: var(--muted); }
.score-live { font-size: 12px; color: var(--good); }
.open-site {
  margin-top: auto; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; font-weight: 600; cursor: pointer; text-align: left;
}
.open-site:hover { border-color: var(--accent); }

/* ---------- channel matrix (shade = share of the site's visits) ---------- */
.matrix td { position: relative; }
.matrix .shade { position: absolute; inset: 3px; border-radius: 6px; background: rgba(57, 135, 229, var(--a)); }
.matrix .cell-v { position: relative; }

/* ---------- heatmap ---------- */
.heatmap { display: grid; gap: 3px; overflow-x: auto; }
.hm-row { display: grid; grid-template-columns: 36px repeat(24, minmax(12px, 1fr)); gap: 3px; align-items: center; }
.hm-head span { font-size: 10px; color: var(--muted); white-space: nowrap; }
.hm-day { font-size: 11px; color: var(--muted); }
.hm-cell { height: 18px; border-radius: 3px; background: var(--surface-2); }
.hm-cell:hover { outline: 1px solid var(--text-2); }
.hm-scale { display: flex; align-items: center; gap: 3px; justify-content: flex-end; margin-top: 10px; font-size: 11px; color: var(--muted); }
.hm-scale i { width: 14px; height: 10px; border-radius: 2px; }
.hm-scale span { margin: 0 4px; }

/* ---------- big funnel ---------- */
.funnel-big { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.f-row { display: flex; align-items: center; gap: 10px; }
.f-step { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-2); flex: none; }
.f-label { flex: 1; font-weight: 600; }
.f-num { font-weight: 700; font-size: 16px; }
.funnel-big .track { height: 12px; background: var(--surface-2); border-radius: 4px; margin: 6px 0 0 32px; overflow: hidden; }
.funnel-big .bar { height: 100%; border-radius: 4px; }
.f-meta { display: flex; justify-content: space-between; gap: 8px; margin: 4px 0 0 32px; font-size: 12px; color: var(--muted); }
.f-meta .lost { color: var(--text-2); }

/* ---------- actions list with breakdowns ---------- */
.actions { list-style: none; margin: 0; padding: 0; display: grid; }
.actions li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.actions li:last-child { border-bottom: 0; }
.a-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.actions li.zero .a-row { color: var(--muted); }
.actions li.zero b { font-weight: 500; }
.goal-badge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: 1px; }
.breakdown { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.bd-title { font-size: 11px; color: var(--muted); margin-right: 2px; }
.pill { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; color: var(--text-2); }
.pill b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- tables: page paths, first/return split ---------- */
td.path { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.split-bar { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.split-bar span { height: 100%; }
.split-legend { display: grid; gap: 4px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.split-legend span { display: inline-flex; align-items: center; gap: 6px; }
.split-legend b { color: var(--text); }

/* ---------- chart text and lines (classes so print can recolor them) ---------- */
.chart-wrap .gl { stroke: var(--grid); stroke-width: 1; }
.chart-wrap .ax { stroke: var(--axis); stroke-width: 1; }
.chart-wrap .tick { fill: var(--muted); font-size: 12px; }
.chart-wrap .endlabel { fill: var(--text-2); font-size: 12px; }
.chart-wrap .ring { stroke: var(--surface); stroke-width: 2; }
.chart-wrap .xhair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.print-head { display: none; }

/* ---------- print / PDF ---------- */
@media print {
  :root { --page: #fff; --surface: #fff; --surface-2: #f2f1ee; --border: #d9d7d0; --grid: #e6e4de; --axis: #c3c2b7; --text: #111; --text-2: #333; --muted: #666; }
  @page { margin: 12mm; }
  html, body { background: #fff; color: #111; }
  body { font-size: 12px; }
  .topbar, .info, .toggle, .seg, .open-site, .live, footer, #notice { display: none !important; }
  .print-head { display: block; font-family: "Orbitron", sans-serif; font-weight: 700; font-size: 13px; margin-bottom: 8px; color: #111; }
  main { max-width: none; padding: 0; }
  section { margin-top: 16px; break-inside: avoid; }
  .card { break-inside: avoid; box-shadow: none; }
  .seg-body[hidden] { display: block !important; margin-top: 8px; }
  .seg-body[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; color: #666; margin-top: 6px; }
  .seg-body[data-label="All"]::before { content: none; }
  .chart-wrap[hidden] { display: block !important; }
  .table-scroll[id$="-table"] { display: none !important; }
  .kpis, .kpis.seven { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .loading { opacity: 1; }
  a { color: #111; text-decoration: none; }
  .matrix .shade { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .bars li .fill, .bar, .hm-cell, .dot, .split-bar span, .goal-badge { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
.notice {
  border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px 16px; color: var(--text-2); font-size: 13px; margin-top: 16px;
}
.loading { opacity: 0.55; transition: opacity 0.15s; }
footer { color: var(--muted); font-size: 12px; text-align: center; margin-top: 40px; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { font-size: 20px; margin-bottom: 18px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; margin: 12px 0 6px; }
.login-card input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  margin-top: 18px; width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px;
  padding: 11px; font-weight: 700; cursor: pointer; font-family: "Orbitron", sans-serif; letter-spacing: 0.06em; font-size: 13px;
}
.btn:hover { filter: brightness(1.08); }
.err { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 1em; }
