:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,0.10); --wash: #f0efec;
  --good-text: #006300; --critical: #d03b3b;
  --approved: #1baf7a; --pending: #eda100; --pending-reversed: #e8702a; --reversed: #d03b3b;
  --c-clicks: #4E79A7; --c-started: #ED8535; --c-completed: #59A14F; --c-purchased: #51528D; --c-payout: #FBE499;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10); --wash: #262624;
    --good-text: #0ca30c; --approved: #199e70; --pending: #c98500; --pending-reversed: #e27a3a; --reversed: #e05252;
    --c-clicks: #6b97c9; --c-purchased: #8d8ee0; --c-payout: #8a7a3c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10); --wash: #262624;
  --good-text: #0ca30c; --approved: #199e70; --pending: #c98500; --pending-reversed: #e27a3a; --reversed: #e05252;
  --c-clicks: #6b97c9; --c-purchased: #8d8ee0; --c-payout: #8a7a3c;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; padding: 0 16px 48px; }
.wrap { max-width: 1180px; margin: 0 auto; }
.mock-banner { background: var(--wash); color: var(--ink-2); font-size: 12px; padding: 6px 12px; border-radius: 0 0 8px 8px; margin-bottom: 14px; }
header.top { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 2px; font-weight: 650; }
.sub { color: var(--ink-2); font-size: 12.5px; margin: 0 0 12px; }
.meta { display: flex; gap: 14px; align-items: center; color: var(--ink-2); font-size: 12.5px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--approved); display: inline-block; margin-right: 6px; }
.user { background: var(--surface); border: 1px solid var(--ring); border-radius: 999px; padding: 4px 12px; color: var(--ink); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 14px; }
.tab { padding: 6px 14px; border-radius: 8px; color: var(--ink-2); border: 1px solid transparent; font-size: 13px; cursor: pointer; background: none; font: inherit; }
.tab.on { background: var(--surface); color: var(--ink); border-color: var(--ring); font-weight: 600; }
.filters { position: sticky; top: 0; z-index: 5; background: var(--page); display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0; margin: 8px 0 14px; border-bottom: 1px solid var(--grid); }
.chip { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 5px 10px; font-size: 13px; color: var(--ink); }
.chip span { color: var(--muted); margin-right: 4px; }
.chip.toggle::before { content: "✓ "; color: var(--good-text); font-weight: 700; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 16px; min-width: 0; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.g-2 { grid-template-columns: 3fr 2fr; }
@media (max-width: 860px) { .g-2 { grid-template-columns: 1fr; } }
.section-label { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 860px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 520px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile .lbl { color: var(--ink-2); font-size: 12.5px; }
.tile .v { font-size: 22px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.delta { font-size: 12px; font-weight: 600; } .delta.good { color: var(--good-text); } .delta.bad { color: var(--critical); }
.delta small { color: var(--muted); font-weight: 400; }
.search { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 12px; }
.search input { flex: 1 1 260px; min-width: 0; background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; }
.search select { padding: 6px 10px; }
.scount { color: var(--muted); font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tnote { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin: 4px 0 8px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.ln { height: 3px; border-radius: 2px; width: 14px; }
svg text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg text.val { fill: var(--ink-2); font-weight: 600; font-size: 10.5px; }
/* payment status */
.stack { display: flex; gap: 2px; height: 26px; border-radius: 6px; overflow: hidden; margin: 10px 0 14px; }
.stack div { height: 100%; }
.ps-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 18px; font-size: 13px; align-items: center; padding: 7px 0; border-top: 1px solid var(--grid); }
.ps-row .n, .ps-row .m { font-variant-numeric: tabular-nums; text-align: right; }
.ps-row .m { font-weight: 600; min-width: 72px; }
.ps-row small { color: var(--muted); display: block; font-size: 11.5px; }
/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { color: var(--ink-2); font-weight: 600; font-size: 11.5px; vertical-align: bottom; position: sticky; top: 0; background: var(--surface); }
th.grp { text-align: center; border-bottom: 1px solid var(--axis); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
tr.src td { font-weight: 600; }
tr.src td:first-child { cursor: pointer; }
tr.src td:first-child::before { content: "▾ "; color: var(--muted); }
tr.src.closed td:first-child::before { content: "▸ "; }
tr.subsrc td:first-child { padding-left: 28px; color: var(--ink-2); }
tr.total td { font-weight: 700; border-top: 2px solid var(--axis); border-bottom: none; }
td .pay { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.btn { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 5px 12px; font: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.btns { display: flex; gap: 6px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.ACCEPTED { color: var(--approved); background: color-mix(in srgb, var(--approved) 14%, transparent); }
.pill.PENDING { color: var(--pending); background: color-mix(in srgb, var(--pending) 16%, transparent); }
.pill.PENDING_REVERSED { color: var(--pending-reversed); background: color-mix(in srgb, var(--pending-reversed) 15%, transparent); }
.pill.REVERSED { color: var(--reversed); background: color-mix(in srgb, var(--reversed) 14%, transparent); }
.leads td { text-align: left; } .leads td.num { text-align: right; }
.pager { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 10px; flex-wrap: wrap; gap: 6px; }
.notes { color: var(--ink-2); font-size: 12.5px; }
.notes ul { margin: 6px 0 0; padding-left: 18px; } .notes li { margin: 3px 0; }
.new { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: var(--c-clicks); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 2px; }
/* ---- app additions ---- */
.loading { opacity: .55; transition: opacity .2s; }
.err { color: var(--critical); font-size: 13px; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.chart { width: 100%; height: 340px; }
.leads th { text-align: left; }
/* Pivots and leads report: own scroll area so the header rows stay visible (frozen) while scrolling down. */
.pivot-wrap, .leads-wrap { max-height: 70vh; overflow: auto; }
.pivot-wrap thead th, .leads-wrap thead th { position: sticky; top: 0; z-index: 2; }
.pivot-wrap thead th:first-child, .leads-wrap thead th:first-child { left: 0; z-index: 3; }
/* Leads report filters: one row per filter. */
.lead-filters { display: grid; gap: 8px; margin: 4px 0 8px; }
.lf-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lf-row .lf-value { display: contents; }
.lf-row select, .lf-row input.lf-text { background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; }
.lf-row input.lf-text { flex: 1 1 260px; min-width: 0; }
.lf-and { color: var(--muted); font-size: 12px; width: 32px; text-align: right; }
.lf-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.ms { position: relative; flex: 1 1 260px; min-width: 0; }
.ms summary { list-style: none; cursor: pointer; background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms summary::-webkit-details-marker { display: none; }
.ms summary::after { content: " ▾"; color: var(--muted); }
.ms .ms-list { position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 260px; overflow: auto; background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.ms label { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 6px; font-size: 13px; white-space: nowrap; cursor: pointer; }
.ms label:hover { background: var(--wash); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sortable::after { content: " ↕"; color: var(--axis); font-weight: 400; }
th.sorted-desc::after { content: " ▼"; color: var(--ink); }
th.sorted-asc::after { content: " ▲"; color: var(--ink); }
.filters label.chip { display: inline-flex; align-items: center; gap: 4px; }
.filters select, .filters input { background: transparent; border: 0; color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; min-width: 0; }
.filters input[name=source], .filters input[name=subsource] { width: 130px; }
.filters input[type=date] { width: 130px; }
.meta form { display: inline; }
.pager { align-items: center; }
.pager button:disabled { opacity: .4; cursor: default; }
.export-msg { color: var(--critical); font-size: 12px; }
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 12px; }
.login label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--ink-2); }
.login input { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--ring); background: var(--surface); color: var(--ink); font: inherit; }
.login .btn { margin-top: 16px; width: 100%; padding: 8px; }
.publist a { display: block; padding: 10px 0; border-bottom: 1px solid var(--grid); color: var(--ink); text-decoration: none; }
.publist small { color: var(--muted); }
