// Cash Flow & Insights — fabricated, internally-consistent data for Atlas Bakery LLC.
//
// THREE SCENARIOS — keyed by `window.RBI_STATE.get()`. The Home overview's tweak
// switches the active scenario; Cash Flow and Industry Insights both read the
// active scenario so the story stays in sync.
//
//   declined   — today, 12d after decline; tight runway, 5 NSFs, fees high
//   improving  — 67d post-decline; rebuilding momentum, zero NSFs in 47 days
//   reeligible — 142d post-decline; Mercury switch, would be approved today
//
// Cohort for peer benchmarks (same in all scenarios): 247 NYC commercial
// bakeries, NAICS 311812, $500K–$2M revenue.

// ────────────────────────────────────────────────────────────────────────────
// Deterministic PRNG so dev refreshes don't reshuffle charts
function mulberry32(seed) {
  return function () {
    seed |= 0; seed = (seed + 0x6D2B79F5) | 0;
    let t = seed;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

// ────────────────────────────────────────────────────────────────────────────
// 90-day daily balance generator. Parametric so each scenario gets a distinct
// trajectory while sharing the same operational shape (daily deposits, weekly
// wholesale checks, biweekly payroll, monthly rent + utilities).
function buildBalance(opts) {
  const { seed, startBal, slopePerDay, overdraftDays, dailyInBoost, weeklyARBoost, payrollSize, rentSize, pullAheadDay, pullAheadAmt } = opts;
  const rng = mulberry32(seed);
  const days = 90;
  const series = [];
  const od = new Set(overdraftDays || []);
  let v = startBal;
  for (let i = 0; i < days; i++) {
    let delta = slopePerDay + (rng() - 0.5) * 1400;
    delta += 2300 + dailyInBoost + (rng() - 0.5) * 800;          // Square daily
    delta += 800 + (rng() - 0.5) * 350;                          // Stripe daily
    delta -= 1700 + rng() * 700;                                 // food costs
    delta -= 250 + rng() * 250;                                  // small ops
    if (i % 7 === 4) delta += 4200 + weeklyARBoost + rng() * 3500; // weekly AR
    if (i % 14 === 10) delta -= payrollSize - rng() * 600;         // payroll
    if (i === 8 || i === 38 || i === 68) delta -= rentSize;        // rent
    if (i === 22 || i === 52 || i === 82) delta -= 1430;           // utilities
    if (pullAheadDay != null && i === pullAheadDay) delta -= pullAheadAmt;
    if (i === 25) delta -= 1280;                                   // equipment service

    v += delta;
    if (od.has(i)) v = -90 - rng() * 110; // NSF day
    series.push(Math.round(v));
  }
  return series;
}

// ────────────────────────────────────────────────────────────────────────────
// Weekly inflow/outflow builder
function buildWeekly(inflows, outflows) {
  return inflows.map((inflow, i) => ({
    label: "W" + (i + 1),
    inflow,
    outflow: outflows[i],
    net: inflow - outflows[i],
  }));
}

// ────────────────────────────────────────────────────────────────────────────
// Spending categories: shared shape, scenario varies the amounts. Color +
// peer share stay consistent so cross-scenario comparisons are clean.
function buildSpending(amounts) {
  const CATS = [
    { key: "supplies",  label: "Supplies & ingredients", color: "#0040BA", peerShare: 24 },
    { key: "payroll",   label: "Payroll & contractors",  color: "#04C49E", peerShare: 31 },
    { key: "rent",      label: "Rent & utilities",       color: "#A4C3FF", peerShare: 12 },
    { key: "fees",      label: "Bank & processing fees", color: "#E07B39", peerShare:  2 },
    { key: "equipment", label: "Equipment & repairs",    color: "#7790F6", peerShare:  6 },
    { key: "marketing", label: "Marketing & software",   color: "#5DD8B6", peerShare:  4 },
    { key: "other",     label: "Insurance, fuel, other", color: "#C0C8D8", peerShare: 21 },
  ];
  const out = CATS.map((c) => ({ ...c, amount: amounts[c.key] }));
  const total = out.reduce((s, x) => s + x.amount, 0);
  out.forEach((x) => { x.share = Math.round((x.amount / total) * 1000) / 10; });
  out.total = total;
  return out;
}

// ────────────────────────────────────────────────────────────────────────────
// Peer benchmarks. Distributions (bins) and percentile cut-points are shared
// across scenarios — only Atlas's "you" value, percentile, and tone shift.
const PEER_BINS = {
  revenue: [4, 11, 19, 31, 42, 38, 31, 27, 21, 14, 7, 3],
  margin:  [9, 18, 28, 38, 45, 36, 28, 19, 12, 7, 4, 3],
  fees:    [42, 68, 51, 32, 24, 15, 9, 5, 1],
  buffer:  [22, 39, 41, 38, 31, 26, 18, 14, 9, 5, 3, 1],
};
const PEER_PCT = {
  revenue: { p25: 68200, p50: 82400, p75: 104500, p90: 138900 },
  margin:  { p25:   5.4, p50:   8.7, p75:   12.4, p90:   17.1 },
  fees:    { p25:   410, p50:   920, p75:  1680, p90:  2900 },
  buffer:  { p25:    31, p50:    54, p75:    88, p90:   132 },
};

function buildPeers(snapshot) {
  return {
    cohort: "247 NYC commercial bakeries",
    cohortSpec: "NAICS 311812 · annual revenue $500K–$2M · 12-mo trailing",
    metrics: [
      {
        key: "revenue", label: "Monthly revenue", unit: "$",
        you: snapshot.revenue.you, youPctile: snapshot.revenue.pct,
        tone: snapshot.revenue.tone, blurb: snapshot.revenue.blurb,
        ...PEER_PCT.revenue, peerP25: PEER_PCT.revenue.p25, peerP50: PEER_PCT.revenue.p50, peerP75: PEER_PCT.revenue.p75, peerP90: PEER_PCT.revenue.p90,
        bins: PEER_BINS.revenue,
      },
      {
        key: "margin", label: "Net margin", unit: "%",
        you: snapshot.margin.you, youPctile: snapshot.margin.pct,
        tone: snapshot.margin.tone, blurb: snapshot.margin.blurb,
        peerP25: PEER_PCT.margin.p25, peerP50: PEER_PCT.margin.p50, peerP75: PEER_PCT.margin.p75, peerP90: PEER_PCT.margin.p90,
        bins: PEER_BINS.margin,
      },
      {
        key: "fees", label: "Bank & card fees", unit: "$/mo",
        you: snapshot.fees.you, youPctile: snapshot.fees.pct,
        tone: snapshot.fees.tone, blurb: snapshot.fees.blurb,
        peerP25: PEER_PCT.fees.p25, peerP50: PEER_PCT.fees.p50, peerP75: PEER_PCT.fees.p75, peerP90: PEER_PCT.fees.p90,
        bins: PEER_BINS.fees,
      },
      {
        key: "buffer", label: "Cash buffer (days)", unit: "d",
        you: snapshot.buffer.you, youPctile: snapshot.buffer.pct,
        tone: snapshot.buffer.tone, blurb: snapshot.buffer.blurb,
        peerP25: PEER_PCT.buffer.p25, peerP50: PEER_PCT.buffer.p50, peerP75: PEER_PCT.buffer.p75, peerP90: PEER_PCT.buffer.p90,
        bins: PEER_BINS.buffer,
      },
    ],
  };
}

// ────────────────────────────────────────────────────────────────────────────
// Helper to annotate a transactions array with running balance.
function annotateRunning(transactions, startBal) {
  const ordered = transactions.slice().reverse();
  let bal = startBal;
  ordered.forEach((t) => { bal += t.amount; t.running = Math.round(bal); });
  return transactions;
}

// ────────────────────────────────────────────────────────────────────────────
// ── DECLINED — today, 12d after decline. Tight runway. ──────────────────────
const DECLINED = {
  todayLabel: "May 22, 2026",
  windowLabel: "Feb 21 – May 22, 2026",
  bank: "Chase Business ····4391",
  balance90: buildBalance({
    seed: 7341, startBal: 44200, slopePerDay: -180,
    overdraftDays: [66, 71, 76, 82, 86],
    dailyInBoost: 0, weeklyARBoost: 0,
    payrollSize: 11800, rentSize: 6800,
    pullAheadDay: 60, pullAheadAmt: 4800,
  }),
  overdraftDays: [66, 71, 76, 82, 86],
  weekly: buildWeekly(
    [22100, 24800, 21900, 23400, 22200, 21600, 20800, 19900, 20400, 19100, 20700, 19400],
    [19200, 18400, 20100, 19800, 21300, 20700, 22600, 21800, 23100, 22400, 24800, 23200]
  ),
  spending30d: buildSpending({
    supplies: 21400, payroll: 23800, rent: 8230, fees: 3850,
    equipment: 6100, marketing: 3200, other: 12600,
  }),
  transactions: annotateRunning([
    { date: "May 22", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  2840.10 },
    { date: "May 22", memo: "Restaurant Depot · Bushwick",            cat: "supplies",  amount: -1284.40 },
    { date: "May 22", memo: "Stripe Payouts · merchant settle",       cat: "deposit",   amount:   742.85 },
    { date: "May 21", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2210.55 },
    { date: "May 21", memo: "Con Edison · acct 8421**",               cat: "rent",      amount:  -612.00 },
    { date: "May 21", memo: "ADP Payroll · bi-weekly",                cat: "payroll",   amount:-11820.00,  flag: "Payroll · 11 staff" },
    { date: "May 20", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2410.00 },
    { date: "May 20", memo: "Stripe · proc fees · 3.1% effective",    cat: "fees",      amount:  -298.60,  flag: "Above peer median (2.6%)" },
    { date: "May 19", memo: "NSF / Insufficient funds fee",           cat: "fees",      amount:   -34.00,  flag: "5th NSF in 30 days" },
    { date: "May 19", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2280.95 },
    { date: "May 19", memo: "Pichardo Wholesale · flour 50ct",        cat: "supplies",  amount: -2840.00 },
    { date: "May 18", memo: "Greenpoint Hotels · Inv #2104 (LATE)",   cat: "ar",        amount: 11800.00,  flag: "Paid 14 days late · biggest buyer" },
    { date: "May 18", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2622.30 },
    { date: "May 17", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  3140.45 },
    { date: "May 17", memo: "Mary's Dairy · weekly delivery",         cat: "supplies",  amount:  -812.50 },
    { date: "May 16", memo: "Square Inc · Daily deposit · weekend",   cat: "deposit",   amount:  3870.10 },
    { date: "May 15", memo: "NSF / Insufficient funds fee",           cat: "fees",      amount:   -34.00,  flag: "Recurring fee event" },
    { date: "May 15", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2410.65 },
    { date: "May 15", memo: "Royal Wholesale Bakery · Inv #1102",     cat: "ar",        amount:  4280.00 },
    { date: "May 14", memo: "AMEX Business · payment",                cat: "fees",      amount: -2880.00 },
    { date: "May 13", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2380.00 },
    { date: "May 13", memo: "Cintas · linen service",                 cat: "supplies",  amount:  -184.20 },
    { date: "May 12", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2580.00 },
    { date: "May 11", memo: "NSF / Insufficient funds fee",           cat: "fees",      amount:   -34.00 },
    { date: "May 10", memo: "Williamsburg Café · Inv #1098",          cat: "ar",        amount:  3640.00 },
    { date: "May 10", memo: "Square Inc · Daily deposit · weekend",   cat: "deposit",   amount:  4120.00 },
    { date: "May  8", memo: "Hobart service · proofer repair",        cat: "equipment", amount: -1280.00 },
    { date: "May  7", memo: "ADP Payroll · bi-weekly",                cat: "payroll",   amount:-11760.00 },
    { date: "May  6", memo: "Pichardo Wholesale · sugar + butter",    cat: "supplies",  amount: -1920.00 },
    { date: "May  5", memo: "NSF / Insufficient funds fee",           cat: "fees",      amount:   -34.00 },
    { date: "May  4", memo: "Stripe Payouts · merchant settle",       cat: "deposit",   amount:   685.10 },
    { date: "May  1", memo: "Rent · 1124 Manhattan Ave LLC",          cat: "rent",      amount: -6800.00,  flag: "Monthly rent" },
    { date: "Apr 30", memo: "Square Inc · Daily deposit",             cat: "deposit",   amount:  2510.00 },
    { date: "Apr 29", memo: "Restaurant Depot · pull-ahead flour",    cat: "supplies",  amount: -4820.00,  flag: "Bulk order · drove spending +6%" },
    { date: "Apr 28", memo: "Stripe · proc fees · 3.1%",              cat: "fees",      amount:  -312.40,  flag: "Above peer median (2.6%)" },
    { date: "Apr 26", memo: "Mary's Dairy · weekly delivery",         cat: "supplies",  amount:  -784.50 },
    { date: "Apr 24", memo: "NSF / Insufficient funds fee",           cat: "fees",      amount:   -34.00 },
    { date: "Apr 23", memo: "ADP Payroll · bi-weekly",                cat: "payroll",   amount:-11900.00 },
  ], 12300),
  peers: buildPeers({
    revenue: { you: 84200, pct: 52, tone: "neutral",
      blurb: "Right around the median. Atlas's revenue is on par with peer bakeries — the issue isn't the top line." },
    margin: { you: 5.9, pct: 24, tone: "warn",
      blurb: "Bottom quartile. Margin compression is real — peer median runs 8.7%; you're at 5.9%." },
    fees: { you: 3850, pct: 92, tone: "bad",
      blurb: "92nd percentile — you're paying more in fees than 92% of peers. Stripe at 3.1% and 5 NSF events are the two biggest drivers." },
    buffer: { you: 26, pct: 18, tone: "bad",
      blurb: "18th percentile. Most peers carry 50+ days of buffer. Climbing back above 45 unlocks substantially better funding offers." },
  }),
  peerCallouts: [
    { icon: "dollar",         metric: "Bank fees", headline: "4.2× the peer median",
      body: "You spend $3,850/mo on bank + processing fees. Peer bakeries spend $920. Two specific drivers: 5 NSF events in 30 days and Stripe at 3.1% effective vs. 2.6% peer median.",
      tone: "bad" },
    { icon: "trending-down",  metric: "Net margin", headline: "2.8 points below peers",
      body: "Bottom quartile by margin. Spending grew 6% MoM (pull-ahead flour order) while revenue stayed flat. Margin gap closes if supplies normalize next month.",
      tone: "warn" },
    { icon: "calendar-clock", metric: "AR aging", headline: "Greenpoint paid 14d late",
      body: "Your largest wholesale buyer (Greenpoint Hotels, $11.8K) settled invoice #2104 14 days past terms. Their peer-cohort average is on-time. Worth flagging on the next renewal.",
      tone: "warn" },
    { icon: "trending-up",    metric: "Revenue", headline: "On par with peers",
      body: "At $84.2K/mo, Atlas sits right at the cohort median. The growth opportunity is wholesale: peers in your top quartile run 38% wholesale vs. your 22%.",
      tone: "good" },
  ],
  copy: {
    pageTitleAccent: "actually did",
    pageSub: "Reconciled from Plaid every 6 hours. Compared to 247 NYC commercial bakeries your size.",
    balanceTitle: "Tight runway. Five overdrafts in the last 30.",
    flowTitle: "Spending crept past revenue",
    flowSub: "Outflows have run above inflows for 4 of the last 6 weeks.",
    spendTitle: "Fees and supplies are the off-pattern lines",
    spendSub: "Comparing your category share to the peer median.",
    txTitle: "38 transactions · 5 flagged",
    txSub: "Anything we noticed gets a yellow tag. Click a chip to filter.",
    insightsHeadline: "stands in its cohort.",
    insightsHero: "At a glance: Atlas is on par for revenue, off-pattern on fees and buffer.",
  },
};

// ── IMPROVING — 67d post-decline, climbing. ────────────────────────────────
const IMPROVING = {
  todayLabel: "Jul 16, 2026",
  windowLabel: "Apr 17 – Jul 16, 2026",
  bank: "Chase Business ····4391",
  balance90: buildBalance({
    seed: 2207, startBal: 22500, slopePerDay: 290,
    overdraftDays: [12, 18, 25],  // earlier in window only, none recent
    dailyInBoost: 380, weeklyARBoost: 1200,
    payrollSize: 11900, rentSize: 6800,
  }),
  overdraftDays: [12, 18, 25],
  weekly: buildWeekly(
    [19200, 19800, 20100, 21400, 21800, 22600, 23100, 23800, 24400, 25100, 25800, 26900],
    [19400, 18900, 19200, 19100, 19800, 19600, 20400, 20100, 21300, 20800, 21800, 21600]
  ),
  spending30d: buildSpending({
    supplies: 19800, payroll: 23600, rent: 8230, fees: 1240,
    equipment: 2100, marketing: 3400, other: 15730,
  }),
  transactions: annotateRunning([
    { date: "Jul 16", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3210.40 },
    { date: "Jul 16", memo: "Williamsburg Café · Inv #1144",         cat: "ar",        amount:  4880.00,  flag: "Paid 4 days early" },
    { date: "Jul 15", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3084.50 },
    { date: "Jul 15", memo: "ADP Payroll · bi-weekly",               cat: "payroll",   amount:-11890.00 },
    { date: "Jul 14", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3422.10 },
    { date: "Jul 14", memo: "Stripe · proc fees · 3.1% effective",   cat: "fees",      amount:  -334.20,  flag: "Above peer median (2.6%) · still" },
    { date: "Jul 13", memo: "Square Inc · Daily deposit · weekend",  cat: "deposit",   amount:  4180.65 },
    { date: "Jul 12", memo: "Square Inc · Daily deposit · weekend",  cat: "deposit",   amount:  4012.30 },
    { date: "Jul 11", memo: "Greenpoint Hotels · Inv #2118",         cat: "ar",        amount: 12400.00,  flag: "On time · renewed at +5%" },
    { date: "Jul 11", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3140.85 },
    { date: "Jul 10", memo: "Pichardo Wholesale · flour 50ct",       cat: "supplies",  amount: -2740.00 },
    { date: "Jul 10", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3088.20 },
    { date: "Jul  9", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3210.50 },
    { date: "Jul  9", memo: "Mary's Dairy · weekly delivery",        cat: "supplies",  amount:  -842.50 },
    { date: "Jul  8", memo: "Newtown Wholesale (NEW) · Inv #0012",   cat: "ar",        amount:  6240.00,  flag: "New wholesale account · 4th this quarter" },
    { date: "Jul  8", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3055.00 },
    { date: "Jul  7", memo: "Stripe Payouts · merchant settle",      cat: "deposit",   amount:   985.10 },
    { date: "Jul  6", memo: "Square Inc · Daily deposit · weekend",  cat: "deposit",   amount:  3940.80 },
    { date: "Jul  5", memo: "Square Inc · Daily deposit · weekend",  cat: "deposit",   amount:  4220.10 },
    { date: "Jul  4", memo: "Square Inc · Daily deposit · holiday",  cat: "deposit",   amount:  4880.00 },
    { date: "Jul  3", memo: "Royal Wholesale Bakery · Inv #1118",    cat: "ar",        amount:  4520.00 },
    { date: "Jul  2", memo: "AMEX Business · payment",               cat: "fees",      amount: -2440.00 },
    { date: "Jul  1", memo: "ADP Payroll · bi-weekly",               cat: "payroll",   amount:-11820.00 },
    { date: "Jul  1", memo: "Rent · 1124 Manhattan Ave LLC",         cat: "rent",      amount: -6800.00,  flag: "Monthly rent" },
    { date: "Jun 30", memo: "Square Inc · Daily deposit",            cat: "deposit",   amount:  3180.00 },
    { date: "Jun 28", memo: "Restaurant Depot · standard order",     cat: "supplies",  amount: -2210.00 },
    { date: "Jun 26", memo: "Mary's Dairy · weekly delivery",        cat: "supplies",  amount:  -812.30 },
    { date: "Jun 24", memo: "Con Edison · acct 8421**",              cat: "rent",      amount:  -628.00 },
    { date: "Jun 22", memo: "Stripe · proc fees · 3.1%",             cat: "fees",      amount:  -342.10 },
    { date: "Jun 20", memo: "Williamsburg Café · Inv #1131",         cat: "ar",        amount:  4720.00 },
    { date: "Jun 18", memo: "ADP Payroll · bi-weekly",               cat: "payroll",   amount:-11750.00 },
  ], 28200),
  peers: buildPeers({
    revenue: { you: 98400, pct: 64, tone: "good",
      blurb: "Top tier. Up from p52 sixty days ago — the Williamsburg account and the new Newtown wholesaler did the work." },
    margin: { you: 12.8, pct: 56, tone: "neutral",
      blurb: "Right above the peer median. Margin recovery is real: supplies normalized after the April pull-ahead, and labor stayed flat." },
    fees: { you: 1240, pct: 58, tone: "warn",
      blurb: "Just above median. NSFs are gone (zero in 47 days). The lingering issue is Stripe at 3.1% — your one persistent fee lever." },
    buffer: { you: 47, pct: 43, tone: "neutral",
      blurb: "Climbing — from 26 days to 47 over the quarter. Another 30 days at this rate puts you in the top tier and re-opens Revenued." },
  }),
  peerCallouts: [
    { icon: "trending-up",    metric: "Revenue", headline: "Best month since opening",
      body: "$98.4K — up 11% MoM and 17% vs. 6-mo avg. Wholesale did the heavy lifting: the new Williamsburg account plus Greenpoint renewing at +5% combined for $22K of the lift.",
      tone: "good" },
    { icon: "trending-up",    metric: "Margin", headline: "Recovered to peer median",
      body: "Net margin moved from 5.9% (bottom quartile) to 12.8% (just above peer p50) in 60 days. The April flour pull-ahead is fully digested.",
      tone: "good" },
    { icon: "dollar",         metric: "Stripe fees", headline: "Still the one lever",
      body: "You're at 3.1% effective. Peer median is 2.6%. With $1.1M annual card volume you have the leverage — Stripe will negotiate interchange-plus above $1M.",
      tone: "warn" },
    { icon: "calendar-clock", metric: "NSF streak", headline: "47 days clean",
      body: "Zero overdrafts since April 5. Every funder on Revenued's platform weighs this. Another 13 days and you cross the 60-day window most underwriters require.",
      tone: "good" },
  ],
  copy: {
    pageTitleAccent: "is moving",
    pageSub: "Reconciled from Plaid every 6 hours. Sixty days of clean operating data — the trajectory is real.",
    balanceTitle: "Rebuilt. Buffer up 16 days in a quarter.",
    flowTitle: "Inflows pulled away from outflows",
    flowSub: "Wholesale receivables have grown three months straight.",
    spendTitle: "Fees are the one lever still open",
    spendSub: "Supplies normalized. Stripe is the persistent outlier.",
    txTitle: "31 transactions · 1 flagged",
    txSub: "Stripe processing rate is the only persistent anomaly in the last 30 days.",
    insightsHeadline: "is climbing the cohort.",
    insightsHero: "At a glance: above median on revenue and margin, near median on fees and buffer.",
  },
};

// ── REELIGIBLE — 142d post-decline, Mercury switch, would be approved. ─────
const REELIGIBLE = {
  todayLabel: "Sep 29, 2026",
  windowLabel: "Jul 1 – Sep 29, 2026",
  bank: "Mercury Business ····2210",
  balance90: buildBalance({
    seed: 9842, startBal: 38400, slopePerDay: 380,
    overdraftDays: [],  // zero NSFs all 90 days
    dailyInBoost: 720, weeklyARBoost: 2400,
    payrollSize: 11900, rentSize: 6800,
  }),
  overdraftDays: [],
  weekly: buildWeekly(
    [24800, 25400, 26100, 26900, 27800, 28200, 28900, 29400, 30100, 30800, 31400, 32100],
    [20200, 19800, 20400, 20100, 20800, 20400, 21200, 20900, 21600, 21100, 21800, 21400]
  ),
  spending30d: buildSpending({
    supplies: 22100, payroll: 24200, rent: 8230, fees: 28,
    equipment: 4200, marketing: 4400, other: 14842,
  }),
  transactions: annotateRunning([
    { date: "Sep 29", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3940.80 },
    { date: "Sep 29", memo: "Williamsburg Café · monthly recurring",     cat: "ar",        amount: 14000.00,  flag: "36-mo agreement · auto-paid" },
    { date: "Sep 28", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3820.10 },
    { date: "Sep 28", memo: "Mercury · monthly account fee",             cat: "fees",      amount:    -0.00,  flag: "$0 — Mercury fee structure" },
    { date: "Sep 28", memo: "Pichardo Wholesale · flour 50ct",           cat: "supplies",  amount: -2620.00 },
    { date: "Sep 27", memo: "Square Inc · Daily deposit · weekend",      cat: "deposit",   amount:  4420.30 },
    { date: "Sep 26", memo: "Square Inc · Daily deposit · weekend",      cat: "deposit",   amount:  4310.85 },
    { date: "Sep 25", memo: "Brooklyn Café Co · Inv #2204 (NEW)",        cat: "ar",        amount:  6240.00,  flag: "New wholesale account" },
    { date: "Sep 25", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3680.20 },
    { date: "Sep 24", memo: "Stripe · proc fees · 2.6% (renegotiated)",  cat: "fees",      amount:  -284.10,  flag: "Lowered from 3.1% in Aug" },
    { date: "Sep 24", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3540.50 },
    { date: "Sep 23", memo: "Greenpoint Hotels · Inv #2130",             cat: "ar",        amount: 13420.00 },
    { date: "Sep 23", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3680.00 },
    { date: "Sep 22", memo: "Mary's Dairy · weekly delivery",            cat: "supplies",  amount:  -922.40 },
    { date: "Sep 22", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3520.10 },
    { date: "Sep 20", memo: "Square Inc · Daily deposit · weekend",      cat: "deposit",   amount:  4480.00 },
    { date: "Sep 19", memo: "Hobart · annual service contract",          cat: "equipment", amount: -2480.00,  flag: "Annual paid up-front" },
    { date: "Sep 18", memo: "Royal Wholesale Bakery · Inv #1140",        cat: "ar",        amount:  4820.00 },
    { date: "Sep 18", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3620.00 },
    { date: "Sep 17", memo: "ADP Payroll · bi-weekly",                   cat: "payroll",   amount:-11920.00 },
    { date: "Sep 15", memo: "Toast POS · subscription",                  cat: "marketing", amount:  -169.00 },
    { date: "Sep 14", memo: "Square Inc · Daily deposit",                cat: "deposit",   amount:  3540.00 },
    { date: "Sep 12", memo: "Pichardo Wholesale · sugar + butter",       cat: "supplies",  amount: -1980.00 },
    { date: "Sep 10", memo: "Stripe Payouts · merchant settle",          cat: "deposit",   amount:  1180.20 },
    { date: "Sep  8", memo: "Mary's Dairy · weekly delivery",            cat: "supplies",  amount:  -908.10 },
    { date: "Sep  5", memo: "AMEX Business · payment",                   cat: "fees",      amount: -2680.00 },
    { date: "Sep  3", memo: "ADP Payroll · bi-weekly",                   cat: "payroll",   amount:-11880.00 },
    { date: "Sep  1", memo: "Rent · 1124 Manhattan Ave LLC",             cat: "rent",      amount: -6800.00,  flag: "Monthly rent" },
    { date: "Aug 31", memo: "Williamsburg Café · monthly recurring",     cat: "ar",        amount: 14000.00 },
  ], 52200),
  peers: buildPeers({
    revenue: { you: 112500, pct: 72, tone: "good",
      blurb: "Top quartile. Up from p52 in May. Three wholesale wins (Williamsburg recurring, new Brooklyn Café Co, Greenpoint renewal) put Atlas in the upper tier." },
    margin: { you: 13.6, pct: 72, tone: "good",
      blurb: "Top quartile by margin. Bank fee elimination (Mercury switch) and renegotiated Stripe together added ~3 points to net margin year-over-year." },
    fees: { you: 28, pct: 7, tone: "good",
      blurb: "7th percentile — Atlas now pays less in bank + processing fees than 93% of peers. Mercury at $0 and renegotiated Stripe (2.6%) are the two specific moves." },
    buffer: { you: 62, pct: 62, tone: "good",
      blurb: "Top third. Five consecutive months without an overdraft, buffer above 60 days. This is the threshold Revenued underwriters look for on flex-line increase." },
  }),
  peerCallouts: [
    { icon: "trending-up",   metric: "Revenue", headline: "Top quartile",
      body: "$112.5K — up 33% from the May baseline. Three wholesale wins (Williamsburg recurring, Brooklyn Café Co, Greenpoint renewal) compounded.",
      tone: "good" },
    { icon: "dollar",        metric: "Bank fees", headline: "From 92nd to 7th percentile",
      body: "Now $28/mo vs. $3,850/mo in May. Mercury at $0 monthly + Stripe renegotiated to 2.6%. The single biggest balance-sheet improvement of the quarter — ~$3,700/yr saved.",
      tone: "good" },
    { icon: "calendar-clock", metric: "NSF streak", headline: "5 months clean",
      body: "Zero overdrafts since April. Mercury's account structure makes this almost automatic — overdraft attempts simply decline instead of incurring fees.",
      tone: "good" },
    { icon: "trending-up",   metric: "Reapproval", headline: "Revenued would fund today",
      body: "The flex line we declined in January would auto-approve against our current credit policy. Same product, factor 1.24 (better terms than the original 1.32).",
      tone: "good" },
  ],
  copy: {
    pageTitleAccent: "is running clean",
    pageSub: "Reconciled from Plaid every 6 hours. Five months of clean operating data. You'd be approved today.",
    balanceTitle: "Strong runway. No overdrafts in 90 days.",
    flowTitle: "Inflows compounded",
    flowSub: "Twelve straight weeks of net positive flow — the Mercury switch did its work.",
    spendTitle: "Fees off the table",
    spendSub: "Mercury at $0/mo plus renegotiated Stripe — peer-bottom quartile now.",
    txTitle: "29 transactions · 0 NSF",
    txSub: "Every flag this month is contextual, not a problem.",
    insightsHeadline: "is in the top tier.",
    insightsHero: "At a glance: top quartile on revenue, margin, and fees. Strong buffer. Reapproval available.",
  },
};

window.RBI_CASHFLOW = {
  declined:   DECLINED,
  improving:  IMPROVING,
  reeligible: REELIGIBLE,
};
