/* Jolly Stats — single stylesheet, light + dark */
:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e4e2dd;
  --line-strong: #d3d1ca;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8882;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6effb;
  --good: #0c7a0c;
  --bad: #c03030;
  --warn: #a36800;
  --bar: #e6effb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948; --s0: #a3a19a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 15, .04), 0 2px 8px rgba(20, 20, 15, .04);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2c2c2a; --line-strong: #3a3a37;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8b8a83;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2a3d;
    --good: #3fbf3f; --bad: #ec6b6b; --warn: #fab219; --bar: #1d2c40;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s0: #6b6a64;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2c2c2a; --line-strong: #3a3a37;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8b8a83;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2a3d;
  --good: #3fbf3f; --bad: #ec6b6b; --warn: #fab219; --bar: #1d2c40;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s0: #6b6a64;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--font); font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
h2 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 22px 0 6px; }
.muted { color: var(--muted); font-weight: 400; }
.warn { color: var(--warn); }

/* Top bar */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15.5px; color: var(--text); letter-spacing: -.02em; white-space: nowrap; }
.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 24 24'%3E%3Cpath d='M5 16l4-4.5 3 2.2 6-7' stroke='white' stroke-width='2.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; flex: none; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 8px 12px; border-radius: 9px; color: var(--text-2); font-weight: 550; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.on { background: var(--accent-soft); color: var(--accent-ink); }
.top-right { display: flex; gap: 4px; }
.icon-btn { width: 34px; height: 34px; min-height: 34px; padding: 0; display: grid; place-items: center; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }

/* Filters row */
.filters { max-width: 1280px; margin: 0 auto; padding: 16px 16px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.select select, .form input, .form select, .fb-row select, .fb-row input, .custom-pop input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 7px 30px 7px 11px; min-height: 36px;
}
.select select { appearance: none; font-weight: 600; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8882' stroke-width='1.6' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; max-width: 230px; }
.pills { display: flex; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 2px; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.pills::-webkit-scrollbar { display: none; }
.pills a { padding: 6px 10px; border-radius: 8px; color: var(--text-2); white-space: nowrap; font-weight: 500; }
.pills a:hover { text-decoration: none; background: var(--surface-2); }
.pills a.on { background: var(--text); color: var(--surface); }
.custom { position: relative; }
.custom summary { list-style: none; cursor: pointer; padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text-2); font-weight: 500; }
.custom summary::-webkit-details-marker { display: none; }
.custom.on summary { background: var(--text); color: var(--surface); border-color: var(--text); }
.custom-pop { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); width: max-content; max-width: calc(100vw - 32px); }
.custom-pop input { padding-right: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; }
.chip:hover { text-decoration: none; filter: brightness(.97); }
.chip span { font-size: 15px; line-height: 1; opacity: .7; }

/* Layout */
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span2 { grid-column: span 2; }
@media (max-width: 860px) { .grid2 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 28px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpis.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis, .kpis.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-2); font-size: 12.5px; font-weight: 550; }
.kpi-val { font-size: 26px; font-weight: 700; letter-spacing: -.03em; margin: 2px 0 1px; }
.kpi-delta { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .kpi { padding: 12px; } .kpi-val { font-size: 22px; } }
.delta { font-weight: 650; color: var(--muted); }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.seg button { font: inherit; font-weight: 550; font-size: 13px; border: 0; background: transparent; color: var(--text-2); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Charts */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
@media (max-width: 560px) { .chart-box, .chart-box.tall { height: 220px; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend button { font: inherit; color: inherit; background: none; border: 0; padding: 2px 0; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.legend button.off { opacity: .35; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: 0; flex: none; }
.legend .dot { margin: 0; }
.dot.s0 { background: var(--s0); } .dot.s1 { background: var(--s1); } .dot.s2 { background: var(--s2); } .dot.s3 { background: var(--s3); } .dot.s4 { background: var(--s4); }
.dot.s5 { background: var(--s5); } .dot.s6 { background: var(--s6); } .dot.s7 { background: var(--s7); } .dot.s8 { background: var(--s8); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 550; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .n { text-align: right; white-space: nowrap; }
.tbl tr.link { cursor: pointer; }
.tbl tr.link:hover td { background: var(--surface-2); }
.tbl td.label { position: relative; isolation: isolate; max-width: 0; width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbl td.label > * { position: relative; }
.tbl .bar { position: absolute !important; left: 0; top: 4px; bottom: 4px; border-radius: 0 6px 6px 0; background: var(--bar); z-index: -1; }
.tbl .site-tag { color: var(--muted); font-size: 12px; margin-left: 6px; }
.tbl .path { font-family: var(--mono); font-size: 12.5px; }
.tbl td.path { word-break: break-all; }
.tbl .empty { color: var(--muted); text-align: center; padding: 24px 8px; white-space: normal; }
@media (max-width: 560px) { .hide-sm { display: none; } .tbl td, .tbl th { padding-left: 6px; padding-right: 6px; } }

/* Journeys */
.trail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.crumb { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); padding: 2px 7px; border-radius: 6px; }
.crumb.aff { background: color-mix(in srgb, var(--s3) 16%, transparent); border-color: color-mix(in srgb, var(--s3) 40%, transparent); font-family: var(--font); font-weight: 600; }
.arr { color: var(--muted); }

/* Funnel */
.funnel { display: flex; flex-direction: column; gap: 14px; }
.f-step { display: grid; grid-template-columns: minmax(150px, 260px) 1fr minmax(120px, 210px); gap: 14px; align-items: center; }
@media (max-width: 700px) { .f-step { grid-template-columns: 1fr; gap: 4px; } }
.f-label { font-weight: 600; display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; }
.f-num { width: 22px; height: 22px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.f-track { height: 26px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.f-bar { height: 100%; background: var(--s1); border-radius: 0 7px 7px 0; transition: width .4s; }
.f-step:nth-child(2) .f-bar { background: #3987e5; } .f-step:nth-child(3) .f-bar { background: #5598e7; }
.f-step:nth-child(4) .f-bar { background: #6da7ec; } .f-step:nth-child(n+5) .f-bar { background: #86b6ef; }
.f-stats { display: flex; flex-direction: column; font-size: 12.5px; }
.f-stats b { font-size: 16px; }
.builder { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.builder summary { cursor: pointer; font-weight: 600; color: var(--accent-ink); }
.fb-rows { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.fb-row { display: flex; gap: 8px; align-items: center; }
.fb-row select { padding-right: 11px; }
.fb-row input { flex: 1; min-width: 0; padding-right: 11px; }
.fb-actions { display: flex; gap: 8px; }

/* Horizontal bars */
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: 28px 1fr 100px; gap: 10px; align-items: center; }
.hbar-k { color: var(--text-2); font-weight: 600; text-align: right; }
.hbar-track { height: 18px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar { display: block; height: 100%; background: var(--s1); border-radius: 0 5px 5px 0; }
.hbar-v { text-align: right; font-size: 13px; }

/* Forms & buttons */
button, .btn { font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 8px 14px; background: var(--accent); color: #fff; cursor: pointer; min-height: 36px; }
.btn { display: inline-flex; align-items: center; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
button.ghost { background: var(--surface-2); color: var(--text); }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.form label small { color: var(--muted); font-weight: 400; }
.form input { padding-right: 11px; }
.form.inline { display: flex; flex-wrap: wrap; gap: 8px; }
.form.inline input { flex: 1; min-width: 160px; }
.alert { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 12%, var(--surface)); color: var(--bad); font-weight: 550; }
.alert.ok { background: color-mix(in srgb, var(--good) 12%, var(--surface)); color: var(--good); }
.snippet { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 10px; padding: 10px; }
.snippet code { flex: 1; background: none; word-break: break-all; }
ul.plain { list-style: none; padding: 0; margin: 0 0 12px; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login .brand { font-size: 18px; margin-bottom: 4px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.login input { font: inherit; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--text); }

/* Chart tooltip */
.tip { position: absolute; pointer-events: none; z-index: 40; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 9px 11px; font-size: 12.5px; min-width: 150px; opacity: 0; transition: opacity .1s; }
.tip .t-day { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.tip .t-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tip .t-row b { color: var(--text); }
.tip .t-total { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 5px; }

/* SVG charts */
svg.chart { display: block; width: 100%; height: 100%; overflow: visible; touch-action: pan-y; }
svg.chart .tick { fill: var(--muted); font-size: 11.5px; }
svg.chart .gl { stroke: var(--line); stroke-width: 1; }
svg.chart .base { stroke: var(--line-strong); stroke-width: 1; }
svg.chart .ln.partial { stroke-dasharray: 4 4; }
svg.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .area { stroke: none; opacity: .12; }
svg.chart .area.stack { opacity: .85; stroke: var(--surface); stroke-width: 1; }
svg.chart .cross { stroke: var(--line-strong); stroke-width: 1; }
svg.chart .pt { stroke: var(--surface); stroke-width: 2; }
svg.chart .s0 { stroke: var(--s0); fill: var(--s0); } svg.chart .s1 { stroke: var(--s1); fill: var(--s1); }
svg.chart .s2 { stroke: var(--s2); fill: var(--s2); } svg.chart .s3 { stroke: var(--s3); fill: var(--s3); }
svg.chart .s4 { stroke: var(--s4); fill: var(--s4); } svg.chart .s5 { stroke: var(--s5); fill: var(--s5); }
svg.chart .s6 { stroke: var(--s6); fill: var(--s6); } svg.chart .s7 { stroke: var(--s7); fill: var(--s7); }
svg.chart .s8 { stroke: var(--s8); fill: var(--s8); }
svg.chart .ln.s0, svg.chart .ln.s1, svg.chart .ln.s2, svg.chart .ln.s3, svg.chart .ln.s4,
svg.chart .ln.s5, svg.chart .ln.s6, svg.chart .ln.s7, svg.chart .ln.s8 { fill: none; }
svg.chart .area.stack.s0, svg.chart .area.stack.s1, svg.chart .area.stack.s2, svg.chart .area.stack.s3,
svg.chart .area.stack.s4, svg.chart .area.stack.s5, svg.chart .area.stack.s6, svg.chart .area.stack.s7,
svg.chart .area.stack.s8 { stroke: var(--surface); }

@media (max-width: 560px) { .brand-text { display: none; } .top-inner { gap: 10px; } .tabs a { padding: 8px 9px; } }

.hist-note { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 10px; padding: 8px 12px; }

/* OAuth consent */
.consent { max-width: 440px; }
.consent h2 { font-size: 17px; line-height: 1.35; }
.consent-list { margin: 0; padding-left: 18px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.consent-actions { display: flex; gap: 8px; justify-content: flex-end; }
