/* Rising Stats — dashboard styles. Palette: validated dataviz reference palette (dark + light). */
:root {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2a2a27;
  --line: #2e2e2b;
  --line-soft: #252523;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e84;
  --accent: #3987e5;
  --accent-ink: #0b0b0b;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --seq-0: #184f95; --seq-1: #1c5cab; --seq-2: #256abf; --seq-3: #3987e5; --seq-4: #5598e7; --seq-5: #86b6ef;
  --rail: 232px;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,.02) inset;
  --font: ui-sans-serif, "Segoe UI Variable Text", "SF Pro Text", "Helvetica Neue", Roboto, system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:where(:not([data-theme="dark"])) { color-scheme: light; --bg:#f4f3ef; --surface-1:#fcfcfb; --surface-2:#f3f2ee; --surface-3:#e9e7e1; --line:#e1dfd8; --line-soft:#ecebe5; --text:#0b0b0b; --text-2:#3d3c39; --muted:#6c6b64; --accent:#2a78d6; --accent-ink:#fff; --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --s5:#e87ba4; --s6:#008300; --s7:#6250d6; --s8:#e34948; --seq-0:#cde2fb; --seq-1:#b7d3f6; --seq-2:#9ec5f4; --seq-3:#6da7ec; --seq-4:#3987e5; --seq-5:#256abf; --shadow: 0 1px 2px rgba(20,20,10,.04); }
}
:root[data-theme="light"] { color-scheme: light; --bg:#f4f3ef; --surface-1:#fcfcfb; --surface-2:#f3f2ee; --surface-3:#e9e7e1; --line:#e1dfd8; --line-soft:#ecebe5; --text:#0b0b0b; --text-2:#3d3c39; --muted:#6c6b64; --accent:#2a78d6; --accent-ink:#fff; --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --s5:#e87ba4; --s6:#008300; --s7:#6250d6; --s8:#e34948; --seq-0:#cde2fb; --seq-1:#b7d3f6; --seq-2:#9ec5f4; --seq-3:#6da7ec; --seq-4:#3987e5; --seq-5:#256abf; --shadow: 0 1px 2px rgba(20,20,10,.04); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login { width: min(380px, 100%); background: var(--surface-1); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; display: grid; gap: 14px; }
.login .logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 20px; }
.login h1 { font-size: 22px; }
.login label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.login input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.alert { background: color-mix(in srgb, var(--crit) 18%, transparent); border: 1px solid color-mix(in srgb, var(--crit) 55%, transparent); padding: 9px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- buttons / inputs ---------- */
.btn { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 550; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: color-mix(in srgb, var(--crit) 60%, var(--line)); color: var(--serious); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
input.f, select.f { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input.f:hover, select.f:hover { border-color: var(--muted); }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto; background: var(--surface-1); border-right: 1px solid var(--line); padding: 18px 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand svg { width: 26px; height: 26px; flex: none; }
.navgrp { margin: 14px 0 4px; padding: 0 10px; font-size: 11.5px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.nav { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 8px; color: var(--text-2); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav:hover { background: var(--surface-2); text-decoration: none; }
.nav[aria-current="page"] { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.nav svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.rail-foot { margin-top: 18px; padding: 0 8px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.topbar .sp { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { background: none; border: 0; padding: 7px 11px; cursor: pointer; color: var(--text-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.page { padding: 22px 24px 60px; max-width: 1480px; }
.page-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 3px 0 0; color: var(--muted); max-width: 70ch; }
.menu-btn { display: none; }

/* ---------- grid / cards ---------- */
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 14.5px; margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.card .note { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.card.flat { padding: 0; overflow: hidden; }
.card.flat > h2, .card.flat > .sub { padding: 16px 18px 0; }
.card.flat > .sub { padding-bottom: 10px; }

.kpi { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi .l { color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: 6px; }
.kpi .v { font-size: 26px; font-weight: 680; letter-spacing: -.02em; margin: 4px 0 2px; line-height: 1.15; }
.kpi .d { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta.up { color: var(--good); } .delta.down { color: var(--serious); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); }
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }
.badge.mid { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.badge.bad { color: var(--serious); border-color: color-mix(in srgb, var(--serious) 55%, var(--line)); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: right; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface-1); }
table.t td { text-align: right; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t td.l, table.t th.l { text-align: left; }
tr.hl td { background: color-mix(in srgb, var(--serious) 12%, transparent); }
.clickable { cursor: pointer; }
.bar-cell { display: grid; grid-template-columns: minmax(40px, 1fr) auto; gap: 8px; align-items: center; }
.bar-cell i { display: block; height: 6px; border-radius: 3px; background: var(--s1); min-width: 2px; }

/* cohort heat table */
table.coh td, table.coh th { padding: 5px 4px; text-align: center; font-size: 12px; }
table.coh td:first-child, table.coh th:first-child { text-align: left; padding-left: 10px; white-space: nowrap; }
table.coh td.c { min-width: 46px; border-radius: 3px; border: 2px solid var(--surface-1); color: #fff; }
table.coh td.e { color: var(--muted); }
table.coh tr.avg td { font-weight: 700; border-top: 1px solid var(--line); }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--line-soft); }
.chart .axis { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 8px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
#tip { position: fixed; z-index: 100; pointer-events: none; background: var(--surface-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0,0,0,.35); opacity: 0; transition: opacity .08s; max-width: 280px; }
#tip b { display: block; margin-bottom: 3px; }
#tip .r { display: flex; justify-content: space-between; gap: 18px; }
#tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.hrow { display: grid; grid-template-columns: minmax(70px, 150px) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.hrow .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hrow .b { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hrow .b i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.hrow .v { color: var(--text); min-width: 48px; text-align: right; }

.funnel .step { display: grid; grid-template-columns: 110px 1fr 120px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.funnel .bar { height: 26px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.funnel .bar i { display: block; height: 100%; }
.funnel .meta { text-align: right; color: var(--muted); }
.funnel .meta b { color: var(--text); }

.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10.5px; color: var(--muted); }
.heat .c { aspect-ratio: 1.3; border-radius: 3px; }
.heat .lb { display: flex; align-items: center; }
.heat .hx { text-align: center; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); margin: 0 auto 10px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.err { background: color-mix(in srgb, var(--crit) 14%, transparent); border: 1px solid color-mix(in srgb, var(--crit) 50%, var(--line)); padding: 14px; border-radius: 10px; }

.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-x: auto; white-space: pre; }
.copy { cursor: pointer; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }
.tag { display: inline-block; padding: 0 7px; border-radius: 5px; background: var(--surface-3); font-size: 12px; }
.ev-name { font-weight: 600; }

/* ---------- publisher report ---------- */
.pub { max-width: 1100px; }
.pub-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 2px solid var(--text); margin-bottom: 18px; }
.pub-head h1 { font-size: 30px; letter-spacing: -.02em; }
.pub-tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--surface-1); }
.pub-tile .l { color: var(--muted); font-size: 12.5px; }
.pub-tile .v { font-size: 34px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; margin: 4px 0 6px; }
.pub-tile .rng { position: relative; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--serious) 0 33%, var(--warn) 33% 66%, var(--good) 66% 100%); opacity: .85; margin: 8px 0 4px; }
.pub-tile .rng u { position: absolute; top: -4px; width: 4px; height: 14px; background: var(--text); border-radius: 2px; transform: translateX(-2px); text-decoration: none; }
.pub-tile .rl { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.calc label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g21, .g12 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .18s; }
  .rail.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .menu-btn { display: inline-flex; }
  .page { padding: 16px 14px 60px; }
  .topbar { padding: 8px 14px; }
  .g2, .g3, .g4, .g5 { grid-template-columns: minmax(0, 1fr); }
  .kpi .v { font-size: 22px; }
  .funnel .step { grid-template-columns: 80px 1fr 90px; }
}
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }

/* ---------- print (publisher report) ---------- */
@media print {
  :root, :root[data-theme] { color-scheme: light; --bg:#fff; --surface-1:#fff; --surface-2:#f4f3ef; --surface-3:#e9e7e1; --line:#d9d7d0; --line-soft:#e9e7e1; --text:#0b0b0b; --text-2:#333; --muted:#666; --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --seq-3:#6da7ec; }
  body { background: #fff; }
  .rail, .topbar, .noprint { display: none !important; }
  .app { display: block; }
  .page { padding: 0; max-width: none; }
  .card, .pub-tile, .kpi { break-inside: avoid; box-shadow: none; }
}
