/* Style Pack: base layer. Colours are tokens; dark mode is its own set. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --line-strong: #c9c8c1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-1: #cde2fb; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab; --seq-5: #0d366b;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --good-ink: #006300; --warn-ink: #8a5a00; --crit-ink: #a32424;
  --good-wash: #e7f5e7; --warn-wash: #fdf3dc; --crit-wash: #fbe7e7;
  --shadow: 0 1px 0 rgba(0,0,0,.04);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-strong: #44443f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #6da7ec; --seq-5: #b7d3f6;
    --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f08080;
    --good-wash: #13261a; --warn-wash: #2b2410; --crit-wash: #2d1616;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-strong: #44443f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #6da7ec; --seq-5: #b7d3f6;
  --good-ink: #5fd35f; --warn-ink: #fab219; --crit-ink: #f08080;
  --good-wash: #13261a; --warn-wash: #2b2410; --crit-wash: #2d1616;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top__row { max-width: 1440px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 15px; }
.brand span { color: var(--text-3); font-weight: 500; }
.fresh { display: flex; gap: 6px; flex-wrap: wrap; margin-right: auto; }
.src { font-size: 12px; color: var(--text-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; display: inline-flex; gap: 6px; align-items: center; }
.src::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.src--error::before { background: var(--crit); }
.src--stale::before { background: var(--warn); }
.btn { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn--ghost { border-color: transparent; }
.tabs { max-width: 1440px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .badge { margin-left: 6px; }

main { max-width: 1440px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.is-active { display: block; }
.loading { opacity: .55; transition: opacity .2s; }

/* layout */
.grid { display: grid; gap: 12px; }
.grid--1 { grid-template-columns: minmax(0, 1fr); }
.grid--kpi { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2, .card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.card h2 small, .card h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-3); margin-left: 6px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 22px 0 8px; font-weight: 600; }
.section-title:first-child { margin-top: 0; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* KPI tile */
.kpi { position: relative; padding: 12px 14px 10px; }
.kpi__label { font-size: 12px; color: var(--text-2); display: flex; gap: 6px; align-items: center; }
.kpi__value { font: 600 24px/1.15 var(--mono); margin: 4px 0 2px; letter-spacing: -.02em; }
.kpi__sub { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; }
.kpi__spark { margin-top: 6px; height: 34px; }
.kpi--good { box-shadow: inset 3px 0 0 var(--good); }
.kpi--hero { box-shadow: inset 3px 0 0 var(--s3); }
.kpi--hero .kpi__value { font-size: 30px; }
.kpi--bad { box-shadow: inset 3px 0 0 var(--warn); background: linear-gradient(90deg, var(--warn-wash), var(--surface) 60%); }
.kpi--drop { box-shadow: inset 3px 0 0 var(--crit); background: linear-gradient(90deg, var(--crit-wash), var(--surface) 60%); }

/* status chips */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 7px; white-space: nowrap; border: 1px solid transparent; }
.chip--good { color: var(--good-ink); background: var(--good-wash); }
.chip--bad { color: var(--warn-ink); background: var(--warn-wash); }
.chip--drop { color: var(--crit-ink); background: var(--crit-wash); }
.chip--flat, .chip--low, .chip--nobase, .chip--mix, .chip--nodata { color: var(--text-3); border-color: var(--line); }
.delta { font-family: var(--mono); font-size: 12px; }
.delta--good { color: var(--good-ink); }
.delta--bad, .delta--drop { color: var(--crit-ink); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center; background: var(--crit); color: #fff; font-weight: 700; }
.badge--amber { background: var(--warn); color: #3a2a00; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 10px; border: 1px solid var(--line); color: var(--text-2); max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
.pill::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.pill--ok { color: var(--good-ink); background: var(--good-wash); border-color: transparent; }
.pill--ok::before { background: var(--good); }
.pill--amber { color: var(--warn-ink); background: var(--warn-wash); border-color: transparent; }
.pill--amber::before { background: var(--warn); }
.pill--red { color: var(--crit-ink); background: var(--crit-wash); border-color: var(--crit); }
.pill--red::before { background: var(--crit); }
.wh-alert { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.wh-alert--red { background: var(--crit-wash); border: 1px solid var(--crit); }
.wh-alert--amber { background: var(--warn-wash); border: 1px solid var(--warn); }

/* focus list */
.focus { display: grid; gap: 8px; }
.fi { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.fi--red { border-left: 3px solid var(--crit); }
.fi--amber { border-left: 3px solid var(--warn); }
.fi--green { border-left: 3px solid var(--good); }
.fi__icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.fi--red .fi__icon { background: var(--crit-wash); color: var(--crit-ink); }
.fi--amber .fi__icon { background: var(--warn-wash); color: var(--warn-ink); }
.fi--green .fi__icon { background: var(--good-wash); color: var(--good-ink); }
.fi__title { font-weight: 600; }
.fi__detail { color: var(--text-2); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.fi__action { font-size: 12px; margin-top: 4px; color: var(--text-2); }
.fi__action b { color: var(--text); font-weight: 600; }
.fi__impact { text-align: right; font: 600 13px var(--mono); white-space: nowrap; }
.fi__impact small { display: block; max-width: 22ch; margin-left: auto; font: 400 11px var(--sans); color: var(--text-3); white-space: normal; }

/* rung */
.rung__bar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.rung__fill { height: 100%; background: var(--accent); border-radius: 6px; }
.rung__fill--off { background: var(--serious); }

/* funnel */
.funnel { display: grid; gap: 6px; }
.fstage { display: grid; grid-template-columns: minmax(130px, 200px) 1fr 90px; gap: 10px; align-items: center; }
.fstage__bar { height: 26px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.fstage__fill { height: 100%; background: var(--seq-3); border-radius: 6px; min-width: 2px; }
.fstep { margin: 0 0 0 20px; padding: 3px 0 3px 12px; border-left: 2px dashed var(--line-strong); font-size: 12px; color: var(--text-2); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fstep b { font-family: var(--mono); color: var(--text); }

/* tables */
.tbl-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.tbl-tools input[type="search"] { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 6px 10px; min-width: 220px; flex: 1; max-width: 360px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 10px; cursor: pointer; font-size: 12px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--surface); }
.tbl-wrap { overflow: auto; max-height: 640px; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; max-width: 420px; overflow-wrap: anywhere; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-2); cursor: pointer; user-select: none; z-index: 1; }
th.n, td.n { text-align: right; }
th[aria-sort="ascending"]::after { content: ' ▲'; font-size: 9px; }
th[aria-sort="descending"]::after { content: ' ▼'; font-size: 9px; }
tbody tr:hover td { background: var(--surface-2); }
tr.r-drop td { background: var(--crit-wash); }
tr.r-bad td { background: var(--warn-wash); }
tr.r-good td:first-child { box-shadow: inset 3px 0 0 var(--good); }
tr.r-drop td:first-child { box-shadow: inset 3px 0 0 var(--crit); }
tr.r-bad td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filter { display: inline-flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-3); min-width: 0; }
.filter select { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 5px 8px; font-size: 13px; max-width: 180px; }
.ledger-sum { margin-bottom: 8px; }
.section-row { margin: 22px 0 8px; justify-content: space-between; }
.section-row .section-title { margin: 0; }
.tbl-foot { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* cohorts and journeys */
.seg--wrap { flex-wrap: wrap; }
tr.r-grey td { color: var(--text-3); }
.rate small { display: block; font-size: 10px; color: var(--text-3); }
.rate--above { color: var(--good-ink); font-weight: 600; }
.rate--below { color: var(--crit-ink); font-weight: 600; }
.rate--grey { color: var(--text-3); }
.tl { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 2px solid var(--line-strong); display: grid; gap: 4px; font-size: 13px; }
.tl__ev { overflow-wrap: anywhere; }
.tl__journey { margin-top: 4px; }
.tl__ev--click_out { color: var(--text); font-weight: 500; }
.tl__ev--partner { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); font-weight: 600; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font: 11px var(--mono); }
.chart .partial { fill: var(--surface-2); }
.chart .xhair { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.box { height: 10px; width: 10px; border-radius: 3px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 9px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 5; min-width: 140px; display: none; }
.tip__date { color: var(--text-3); margin-bottom: 4px; font-family: var(--mono); }
.tip__row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tip__row b { font-family: var(--mono); }
.tip__row span { color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.tip__row span i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

.empty { padding: 24px; text-align: center; color: var(--text-3); }
.note { font-size: 12px; color: var(--text-3); margin-top: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
.error-box { border: 1px solid var(--crit); background: var(--crit-wash); color: var(--crit-ink); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }

@media (max-width: 640px) {
  .fstage { grid-template-columns: 110px 1fr 70px; }
  .kpi__value { font-size: 20px; }
  .fi { grid-template-columns: 22px 1fr; }
  .fi__impact { grid-column: 2; text-align: left; }
  .fi__impact small { max-width: none; margin-left: 0; }
  .tbl-tools input[type="search"] { min-width: 0; }
  .filter { flex: 1 1 calc(50% - 8px); }
  .filter select { max-width: none; width: 100%; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0 14px; }
  .kv dd { margin-bottom: 6px; }
}
@media (forced-colors: active) { .chip, .badge, .src::before { border: 1px solid CanvasText; } }
.view > .section-row:first-child { margin-top: 0; }
.kpi__value--text { font-size: 15px; line-height: 1.35; margin: 6px 0 4px; overflow-wrap: anywhere; }
td .pill { white-space: nowrap; overflow-wrap: normal; max-width: none; }
.chart .suspect { fill: var(--warn-wash); }
.seg button:disabled { cursor: default; opacity: .45; }

/* attention */
.section-title__sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.att-counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; }
.att-count { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.att-count__value { font: 600 24px/1.15 var(--mono); letter-spacing: -.02em; }
.att-count__label { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.att-count--red { box-shadow: inset 3px 0 0 var(--crit); }
.att-count--amber { box-shadow: inset 3px 0 0 var(--warn); }
.att-count--green { box-shadow: inset 3px 0 0 var(--good); }

/* customer flow */
.legend-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; }
.jr-lead { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; margin-bottom: 12px; }
.sk-host { position: relative; overflow-x: auto; }
.sk-host svg { display: block; max-width: none; }
.sk-col { fill: var(--text-3); font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: .05em; }
.sk-band { opacity: .42; transition: opacity .12s; cursor: default; }
.sk-band--drop { opacity: .22; }
.sk-band:hover { opacity: .75; }
.sk-name, .sk-value { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.sk-name { fill: var(--text-2); font: 500 11px var(--sans); }
.sk-name--drop { fill: var(--text-3); }
.sk-value { fill: var(--text); font: 600 13px var(--mono); }
.sk-value--drop { fill: var(--text-2); font-weight: 400; }
.jr-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; margin-top: 12px; }
.jr-step { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.jr-step--leak { box-shadow: inset 3px 0 0 var(--serious); }
.jr-step__rate { font: 600 24px/1.15 var(--mono); letter-spacing: -.02em; }
.jr-step__name { font-size: 13px; margin-top: 2px; }
.jr-step__sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.jr-step__flag { font-size: 12px; color: var(--crit-ink); font-weight: 600; margin-top: 2px; }
.jr-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 12px; }
.jr-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.jr-card__head { display: flex; gap: 10px; font-size: 12px; color: var(--text-3); margin-bottom: 8px; flex-wrap: wrap; }
.jr-path { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 18px; font-size: 13px; }
.jr-path__step { position: relative; min-width: 0; }
.jr-path__step:not(:last-child)::after { content: '→'; position: absolute; right: -14px; top: 14px; color: var(--text-3); }
.jr-path__kind { font-size: 11px; color: var(--text-3); }
.jr-path__title { font-weight: 600; overflow-wrap: anywhere; }
.jr-path__detail { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.jr-path__amount { font: 600 15px var(--mono); color: var(--good-ink); }
.jr-path__amount small { font: 400 11px var(--sans); color: var(--text-3); }
.jr-log { margin-top: 10px; }
.jr-log summary { cursor: pointer; color: var(--text-2); font-size: 12px; margin-bottom: 8px; }

@media (max-width: 760px) {
  .jr-path { grid-auto-flow: row; gap: 8px; }
  .jr-path__step:not(:last-child)::after { content: none; }
}
