// =============================================================
// page-markets.jsx — public market data showcase at /#/markets
//
// The /#/account dashboard has rich fuel + refinery + oil panels
// gated behind sign-in. fuel_signals, refinery_signals, refineries
// are all anon-readable, so this page surfaces the same intelligence
// publicly — proof of the data layer behind the platform.
// =============================================================

const {
  useState: useStateMK,
  useEffect: useEffectMK,
} = React;

function MarketsPage({ onNav }) {
  const [fuel, setFuel] = useStateMK([]);
  const [refSignals, setRefSignals] = useStateMK([]);
  const [refineries, setRefineries] = useStateMK([]);
  const [fred, setFred] = useStateMK([]);
  const [loading, setLoading] = useStateMK(true);

  useEffectMK(() => {
    let alive = true;
    if (!window.SI_DB || !window.SI_DB.raw) { setLoading(false); return; }
    (async () => {
      try {
        const [f, rs, rf, fi] = await Promise.all([
          window.SI_DB.raw.select("fuel_signals", "select=*&order=period.desc&limit=400"),
          window.SI_DB.raw.select("refinery_signals", "select=*&order=period.desc&limit=200"),
          window.SI_DB.raw.select("refineries", "select=name,operator,capacity_kbpd,padd,city,state&order=capacity_kbpd.desc&limit=30"),
          window.SI_DB.raw.select(
            "freight_indices",
            "select=series,value_num,period,source,notes&source=like.fred:*&order=period.desc&limit=400"
          ).catch(() => []),
        ]);
        if (!alive) return;
        setFuel(Array.isArray(f) ? f : []);
        setRefSignals(Array.isArray(rs) ? rs : []);
        setRefineries(Array.isArray(rf) ? rf : []);
        setFred(Array.isArray(fi) ? fi : []);
      } catch {} finally { if (alive) setLoading(false); }
    })();
    return () => { alive = false; };
  }, []);

  // Group freight_indices rows by series → sorted observations (newest first)
  const fredBySeries = React.useMemo(() => {
    const out = {};
    for (const r of fred) {
      const s = r.series;
      if (!s) continue;
      (out[s] = out[s] || []).push(r);
    }
    for (const k of Object.keys(out)) {
      out[k].sort((a, b) => (b.period || "").localeCompare(a.period || ""));
    }
    return out;
  }, [fred]);

  // Compute latest value + 4-period delta % for a series (4-period roughly =
  // 1 month for weekly series, 4 months for monthly series — close enough for
  // a "is this accelerating or decelerating?" signal).
  const fredCard = (seriesName, label, unit, fmt = "num") => {
    const obs = fredBySeries[seriesName];
    if (!obs || obs.length === 0) return null;
    const latest = parseFloat(obs[0].value_num);
    const ref = obs.length >= 5 ? parseFloat(obs[4].value_num) : null;
    const pct = (ref && ref !== 0) ? ((latest - ref) / ref) * 100 : null;
    const formatted = fmt === "thousand" ? `${latest.toLocaleString(undefined, { maximumFractionDigits: 0 })}`
                    : fmt === "percent"  ? `${latest.toFixed(1)}%`
                    : fmt === "money"    ? `$${latest.toLocaleString(undefined, { maximumFractionDigits: 0 })}`
                    : latest.toLocaleString(undefined, { maximumFractionDigits: 1 });
    return { label, unit, formatted, period: obs[0].period, pct };
  };

  const latest = (s) => fuel.find(f => f.series === s && f.region !== "futures-month-ago");
  const monthAgo = (s) => fuel.find(f => f.series === s && f.region === "futures-month-ago");

  function MoMTag({ series }) {
    const cur = latest(series);
    const old = monthAgo(series);
    if (!cur || !old) return null;
    const a = parseFloat(cur.value_num);
    const b = parseFloat(old.value_num);
    if (!a || !b) return null;
    const pct = ((a - b) / b) * 100;
    const dir = pct > 0.5 ? "up" : pct < -0.5 ? "down" : "flat";
    const arrow = dir === "up" ? "▲" : dir === "down" ? "▼" : "—";
    const color = dir === "up" ? "oklch(0.55 0.18 25)" : dir === "down" ? "oklch(0.50 0.14 145)" : "var(--ink-soft)";
    return (
      <span style={{
        display: "inline-block", padding: "2px 8px", borderRadius: 4,
        background: dir === "up" ? "oklch(0.96 0.04 25)" : dir === "down" ? "oklch(0.96 0.04 145)" : "var(--paper-2)",
        color, fontSize: 11, fontFamily: "var(--font-mono)", fontWeight: 600,
        marginTop: 8,
      }} title={`Month-ago: $${b.toFixed(2)}`}>
        {arrow} {Math.abs(pct).toFixed(1)}% MoM
      </span>
    );
  }

  const wti = latest("wti_crude_futures");
  const brent = latest("brent_crude_futures");
  const ulsd = latest("ulsd_diesel_futures");
  const rbob = latest("rbob_gas_futures");
  const retailUS = latest("diesel_retail_us");

  const regions = [
    ["west", "West Coast"], ["east", "East Coast"], ["gulf", "Gulf Coast"],
    ["midwest", "Midwest"], ["rocky", "Rocky Mtn"]
  ].map(([r, name]) => ({ ...latest(`diesel_retail_${r}`), name }));

  // Implied retail diesel from ULSD futures: rough rule of thumb
  // retail = futures wholesale + ~$1.10/gal (taxes + dist + retail margin)
  const implied = ulsd ? parseFloat(ulsd.value_num) + 1.10 : null;
  const actualUS = retailUS ? parseFloat(retailUS.value_num) : null;
  const gap = (implied != null && actualUS != null) ? actualUS - implied : null;

  // Refinery utilization — find the most recent reading per scope
  const utilByScope = {};
  refSignals.filter(r => r.signal_type === "utilization_pct").forEach(r => {
    if (!utilByScope[r.scope] || r.period > utilByScope[r.scope].period) {
      utilByScope[r.scope] = r;
    }
  });
  const utilizationCards = ["us", "padd-1", "padd-2", "padd-3", "padd-4", "padd-5"]
    .map(s => ({ scope: s, signal: utilByScope[s] }))
    .filter(x => x.signal);

  return (
    <div className="page-markets">
      <style>{`
        .pm-hero { max-width: 1280px; margin: 0 auto; padding: 56px 24px 24px; }
        .pm-eyebrow {
          font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.32em;
          text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px;
          display: inline-flex; align-items: center; gap: 10px;
        }
        .pm-eyebrow .dot { width: 8px; height: 8px; border-radius: 50%;
          background: oklch(0.55 0.18 145); animation: pm-pulse 1.6s infinite; }
        @keyframes pm-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
        .pm-h1 {
          font-family: var(--font-serif); font-size: 48px; line-height: 1.05;
          letter-spacing: -0.025em; margin: 0 0 16px; font-weight: 600;
          max-width: 880px;
        }
        @media (max-width: 700px) { .pm-h1 { font-size: 32px; } }
        .pm-dek {
          font-size: 17px; line-height: 1.55; color: var(--ink-soft);
          max-width: 760px; margin: 0;
        }

        .pm-section {
          max-width: 1280px; margin: 36px auto; padding: 0 24px;
        }
        .pm-section-h {
          font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.22em;
          text-transform: uppercase; color: var(--ink-soft);
          padding-bottom: 12px; border-bottom: 1px solid var(--rule); margin-bottom: 16px;
          display: flex; justify-content: space-between; align-items: baseline;
        }
        .pm-section-h .h-sub { font-size: 10px; letter-spacing: 0.16em; color: var(--ink-soft); }

        .pm-grid {
          display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
        }
        @media (max-width: 1100px) { .pm-grid { grid-template-columns: repeat(3, 1fr); } }
        @media (max-width: 800px)  { .pm-grid { grid-template-columns: repeat(2, 1fr); } }
        @media (max-width: 480px)  { .pm-grid { grid-template-columns: 1fr; } }

        .pm-card {
          background: #fff; border: 1px solid var(--rule); border-radius: 8px;
          padding: 18px;
        }
        .pm-card.gap {
          background: oklch(0.97 0.04 60);
          border-color: oklch(0.85 0.10 60);
        }
        .pm-card-label {
          font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em;
          text-transform: uppercase; color: var(--ink-soft); margin-bottom: 8px;
        }
        .pm-card-num {
          font-family: var(--font-serif); font-size: 30px; line-height: 1;
          letter-spacing: -0.02em; color: var(--ink); font-weight: 600;
          margin: 4px 0;
        }
        .pm-card-unit {
          font-family: var(--font-mono); font-size: 11px;
          color: var(--ink-soft); margin-top: 4px;
        }

        .pm-regions {
          padding: 16px 18px; background: var(--paper-2, #f5f1e8);
          border: 1px solid var(--rule); border-radius: 8px;
          display: flex; flex-wrap: wrap; gap: 28px; align-items: center;
        }
        .pm-regions-label {
          font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em;
          text-transform: uppercase; color: var(--ink-soft);
        }
        .pm-region {
          display: flex; flex-direction: column; gap: 2px;
        }
        .pm-region-name {
          font-family: var(--font-mono); font-size: 10px; color: var(--ink-soft);
          letter-spacing: 0.08em; text-transform: uppercase;
        }
        .pm-region-num {
          font-family: var(--font-serif); font-size: 18px;
          color: var(--ink); font-weight: 600;
        }

        .pm-util-grid {
          display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
        }
        @media (max-width: 900px) { .pm-util-grid { grid-template-columns: repeat(3, 1fr); } }
        @media (max-width: 480px) { .pm-util-grid { grid-template-columns: repeat(2, 1fr); } }
        .pm-util-cell {
          padding: 14px; background: #fff; border: 1px solid var(--rule); border-radius: 6px;
        }
        .pm-util-scope {
          font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em;
          text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px;
        }
        .pm-util-num {
          font-family: var(--font-serif); font-size: 24px; line-height: 1;
          letter-spacing: -0.02em; font-weight: 600;
        }
        .pm-util-bar {
          height: 4px; background: var(--rule); border-radius: 2px;
          margin-top: 8px; overflow: hidden;
        }
        .pm-util-bar-fill {
          height: 100%; background: oklch(0.55 0.16 145);
          transition: width 0.6s ease;
        }

        .pm-refinery-list {
          display: grid; grid-template-columns: repeat(2, 1fr); gap: 0;
        }
        @media (max-width: 700px) { .pm-refinery-list { grid-template-columns: 1fr; } }
        .pm-refinery {
          display: grid; grid-template-columns: 1fr 100px 60px;
          gap: 12px; padding: 11px 14px;
          border-bottom: 1px solid var(--rule);
          align-items: baseline;
        }
        .pm-refinery .name {
          font-family: var(--font-serif); font-size: 15px; color: var(--ink);
        }
        .pm-refinery .op {
          font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft);
          text-align: right;
        }
        .pm-refinery .cap {
          font-family: var(--font-mono); font-size: 13px; color: var(--ink); font-weight: 600;
          text-align: right;
        }
      `}</style>

      <section className="pm-hero">
        <div className="pm-eyebrow"><span className="dot" /> Live market data · refreshed daily</div>
        <h1 className="pm-h1">The freight market, <em>priced in real time.</em></h1>
        <p className="pm-dek">
          Crude futures, diesel retail, the futures-vs-pump gap, refinery
          utilization across all five PADDs, and the 30 highest-capacity US
          refineries — pulled from federal regulatory feeds and refreshed
          daily. The numbers shippers, carriers, and brokers use to price
          freight and predict fuel-surcharge moves.
        </p>
      </section>

      {/* Fuel + oil futures */}
      <section className="pm-section">
        <div className="pm-section-h">
          <span>Fuel & oil markets</span>
          <span className="h-sub">Futures vs pump · the gap predicts fuel-surcharge moves</span>
        </div>
        {loading ? (
          <div style={{ padding: 32, color: "var(--ink-soft)", textAlign: "center" }}>Loading market data…</div>
        ) : (
          <div className="pm-grid">
            {wti && (
              <div className="pm-card">
                <div className="pm-card-label">WTI crude · futures</div>
                <div className="pm-card-num">${parseFloat(wti.value_num).toFixed(2)}</div>
                <div className="pm-card-unit">/ barrel · CL=F</div>
                <MoMTag series="wti_crude_futures" />
              </div>
            )}
            {brent && (
              <div className="pm-card">
                <div className="pm-card-label">Brent crude · futures</div>
                <div className="pm-card-num">${parseFloat(brent.value_num).toFixed(2)}</div>
                <div className="pm-card-unit">/ barrel · East-Coast benchmark</div>
                <MoMTag series="brent_crude_futures" />
              </div>
            )}
            {wti && brent && (
              <div className="pm-card">
                <div className="pm-card-label">Brent–WTI spread</div>
                <div className="pm-card-num"
                     style={{ color: (parseFloat(brent.value_num) - parseFloat(wti.value_num)) > 5 ? "oklch(0.55 0.18 25)" : "var(--ink)" }}>
                  ${(parseFloat(brent.value_num) - parseFloat(wti.value_num)).toFixed(2)}
                </div>
                <div className="pm-card-unit">
                  {(parseFloat(brent.value_num) - parseFloat(wti.value_num)) > 5
                    ? "wide — East Coast refining cost rising"
                    : "tight — domestic crude advantage"}
                </div>
              </div>
            )}
            {ulsd && (
              <div className="pm-card">
                <div className="pm-card-label">ULSD diesel · futures</div>
                <div className="pm-card-num">${parseFloat(ulsd.value_num).toFixed(3)}</div>
                <div className="pm-card-unit">/ gallon · HO=F</div>
                <MoMTag series="ulsd_diesel_futures" />
              </div>
            )}
            {rbob && (
              <div className="pm-card">
                <div className="pm-card-label">RBOB gasoline · futures</div>
                <div className="pm-card-num">${parseFloat(rbob.value_num).toFixed(3)}</div>
                <div className="pm-card-unit">/ gallon · RB=F</div>
                <MoMTag series="rbob_gas_futures" />
              </div>
            )}
            {retailUS && (
              <div className="pm-card">
                <div className="pm-card-label">Diesel retail · US average</div>
                <div className="pm-card-num">${parseFloat(retailUS.value_num).toFixed(3)}</div>
                <div className="pm-card-unit">/ gallon · DOE weekly · {retailUS.period}</div>
              </div>
            )}
            {gap != null && (
              <div className="pm-card gap">
                <div className="pm-card-label">Futures-to-pump gap</div>
                <div className="pm-card-num"
                     style={{ color: Math.abs(gap) > 0.30 ? "oklch(0.55 0.18 25)" : "oklch(0.50 0.14 145)" }}>
                  {gap > 0 ? "+" : ""}${gap.toFixed(2)}
                </div>
                <div className="pm-card-unit">
                  actual vs implied · {gap > 0.20 ? "pump above expectation" : gap < -0.20 ? "pump below expectation" : "in line"}
                </div>
              </div>
            )}
          </div>
        )}
      </section>

      {/* Regional retail diesel */}
      {regions.some(r => r.value_num) && (
        <section className="pm-section">
          <div className="pm-section-h">
            <span>Regional retail diesel · DOE weekly</span>
          </div>
          <div className="pm-regions">
            <span className="pm-regions-label">$/gallon by PADD region:</span>
            {regions.filter(r => r.value_num).map(r => (
              <div key={r.name} className="pm-region">
                <span className="pm-region-name">{r.name}</span>
                <span className="pm-region-num">${parseFloat(r.value_num).toFixed(3)}</span>
              </div>
            ))}
          </div>
        </section>
      )}

      {/* Refinery utilization across PADDs */}
      {utilizationCards.length > 0 && (
        <section className="pm-section">
          <div className="pm-section-h">
            <span>US refinery utilization · weekly EIA</span>
            <span className="h-sub">% of nameplate capacity in operation</span>
          </div>
          <div className="pm-util-grid">
            {utilizationCards.map(({ scope, signal }) => {
              const v = parseFloat(signal.value_num);
              const label = scope === "us" ? "US Total"
                : scope === "padd-1" ? "PADD 1 · East"
                : scope === "padd-2" ? "PADD 2 · Midwest"
                : scope === "padd-3" ? "PADD 3 · Gulf"
                : scope === "padd-4" ? "PADD 4 · Rockies"
                : scope === "padd-5" ? "PADD 5 · West"
                : scope;
              const accent = v >= 92 ? "oklch(0.55 0.18 50)"
                : v >= 85 ? "oklch(0.55 0.16 145)"
                : "oklch(0.55 0.18 25)";
              return (
                <div key={scope} className="pm-util-cell">
                  <div className="pm-util-scope">{label}</div>
                  <div className="pm-util-num" style={{ color: accent }}>{v.toFixed(1)}%</div>
                  <div className="pm-util-bar">
                    <div className="pm-util-bar-fill" style={{ width: `${v}%`, background: accent }} />
                  </div>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, color: "var(--ink-soft)", marginTop: 6 }}>
                    Period {signal.period}
                  </div>
                </div>
              );
            })}
          </div>
        </section>
      )}

      {/* Top 30 US refineries */}
      {refineries.length > 0 && (
        <section className="pm-section">
          <div className="pm-section-h">
            <span>Top US refineries by capacity</span>
            <span className="h-sub">{refineries.length} largest · kbpd nameplate</span>
          </div>
          <div className="pm-refinery-list">
            {refineries.map((r, i) => (
              <div key={i} className="pm-refinery">
                <span className="name">{r.name}</span>
                <span className="op">{r.operator || "—"}</span>
                <span className="cap">{r.capacity_kbpd ? r.capacity_kbpd.toLocaleString() : "—"}</span>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 12, fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--ink-soft)" }}>
            kbpd = thousand barrels per day · nameplate capacity from federal regulatory filings
          </div>
        </section>
      )}

      {/* Macro freight indicators (FRED) — rail, truck, labor */}
      {(() => {
        const groups = [
          {
            heading: "Rail volume",
            sub: "AAR Class I weekly carloads + intermodal",
            cards: [
              fredCard("rail_carloads_weekly",   "Carloads",         "k carloads/week", "thousand"),
              fredCard("rail_intermodal_weekly", "Intermodal units", "k units/week",    "thousand"),
            ].filter(Boolean),
          },
          {
            heading: "Truck activity",
            sub: "ATA tonnage · PPI · industrial production",
            cards: [
              fredCard("ata_truck_tonnage",         "ATA Truck Tonnage Index",     "2015=100"),
              fredCard("ppi_long_distance_truck",   "PPI Long-Distance Trucking",  "Dec-2003=100"),
              fredCard("ppi_general_freight_truck", "PPI General Freight",         "1984=100"),
              fredCard("ind_prod_truck_transport",  "Ind. Production: Trucking",   "2017=100"),
              fredCard("ind_prod_auto_assembly",    "Auto Assembly (auto-pull)",   "2017=100"),
            ].filter(Boolean),
          },
          {
            heading: "Driver labor market",
            sub: "JOLTS · CES — transportation + warehousing sector",
            cards: [
              fredCard("jolts_jobopenings_transp", "Job openings rate",       "%", "percent"),
              fredCard("jolts_quits_transp",       "Quits rate",              "%", "percent"),
              fredCard("jolts_layoffs_transp",     "Layoffs rate",            "%", "percent"),
              fredCard("jolts_hires_transp",       "Hires rate",              "%", "percent"),
              fredCard("ces_payrolls_truck_transport",  "Trucking payrolls",  "thousands", "thousand"),
              fredCard("ces_payrolls_warehouse_storage","Warehouse payrolls", "thousands", "thousand"),
            ].filter(Boolean),
          },
          {
            heading: "Demand proxies",
            sub: "Real retail · e-commerce · unemployment · prices",
            cards: [
              fredCard("real_retail_sales",     "Real retail + food",  "$M"),
              fredCard("ecommerce_retail_sales","E-commerce retail",   "$M"),
              fredCard("unemployment_rate",     "Unemployment rate",   "%", "percent"),
              fredCard("pce_price_index",       "PCE Price Index",     "2017=100"),
            ].filter(Boolean),
          },
        ].filter(g => g.cards.length > 0);
        if (groups.length === 0) return null;
        return (
          <section className="pm-section">
            <div className="pm-section-h">
              <span>Macro freight indicators · FRED</span>
              <span className="h-sub">Rail · truck · labor · demand</span>
            </div>
            <p style={{ margin: "0 0 24px", color: "var(--ink-soft)", fontSize: 14, lineHeight: 1.5, maxWidth: 820 }}>
              Federal Reserve macro series scoped to freight-relevant categories.
              Each card shows the latest published value plus the 4-period %
              change — JOLTS quits trending up means driver wage pressure;
              ATA tonnage diverging from rail carloads is a mode-shift signal.
            </p>
            {groups.map(g => (
              <div key={g.heading} style={{ marginBottom: 24 }}>
                <div style={{ display: "flex", alignItems: "baseline", gap: 12, marginBottom: 12 }}>
                  <h3 style={{ margin: 0, fontFamily: "var(--font-serif)", fontSize: 18, color: "var(--ink)", fontWeight: 600 }}>
                    {g.heading}
                  </h3>
                  <span style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--ink-soft)" }}>
                    {g.sub}
                  </span>
                </div>
                <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: 12 }}>
                  {g.cards.map((c, i) => {
                    const dir = c.pct == null ? null : (c.pct > 0.5 ? "up" : c.pct < -0.5 ? "down" : "flat");
                    const arrow = dir === "up" ? "▲" : dir === "down" ? "▼" : dir === "flat" ? "—" : null;
                    const color = dir === "up" ? "oklch(0.50 0.14 145)" : dir === "down" ? "oklch(0.55 0.18 25)" : "var(--ink-soft)";
                    return (
                      <div key={i} style={{ background: "#fff", border: "1px solid var(--rule)", borderRadius: 6, padding: 14 }}>
                        <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-soft)", marginBottom: 6 }}>
                          {c.label}
                        </div>
                        <div style={{ fontFamily: "var(--font-serif)", fontSize: 26, color: "var(--ink)", lineHeight: 1.1, fontWeight: 600 }}>
                          {c.formatted}
                        </div>
                        <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, color: "var(--ink-soft)", marginTop: 4 }}>
                          {c.unit} · {c.period}
                        </div>
                        {arrow && (
                          <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, color, marginTop: 8, fontWeight: 600 }}>
                            {arrow} {Math.abs(c.pct).toFixed(1)}% / 4-period
                          </div>
                        )}
                      </div>
                    );
                  })}
                </div>
              </div>
            ))}
            <p style={{ margin: "8px 0 0", color: "var(--ink-soft)", fontSize: 11, lineHeight: 1.5, fontStyle: "italic" }}>
              Source: Federal Reserve Economic Data (FRED), api.stlouisfed.org. Refreshed daily.
            </p>
          </section>
        );
      })()}

      {/* Cross-links — push visitors into other surfaces */}
      <section className="pm-section">
        <div className="pm-section-h">
          <span>Connected surfaces</span>
          <span className="h-sub">Markets · into the rest of the graph</span>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))", gap: 12 }}>
          <a href="#/clarity" onClick={(e) => { e.preventDefault(); onNav("clarity"); }}
             style={{ textDecoration: "none", color: "inherit", padding: 16, border: "1px solid var(--rule)", borderRadius: 6, background: "#fff", display: "block" }}>
            <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-soft)", marginBottom: 6 }}>Clarity Dashboard →</div>
            <div style={{ fontFamily: "var(--font-serif)", fontSize: 17, color: "var(--ink)", lineHeight: 1.3 }}>
              The Bloomberg-style data wall: live signal ticker, hot lanes, enterprise shippers, flagged carriers.
            </div>
          </a>
          <a href="#/rates" onClick={(e) => { e.preventDefault(); onNav("rates"); }}
             style={{ textDecoration: "none", color: "inherit", padding: 16, border: "1px solid var(--rule)", borderRadius: 6, background: "#fff", display: "block" }}>
            <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-soft)", marginBottom: 6 }}>Lane Rates →</div>
            <div style={{ fontFamily: "var(--font-serif)", fontSize: 17, color: "var(--ink)", lineHeight: 1.3 }}>
              $/mi heat bands and headhaul-vs-backhaul asymmetry — the math that decides what a load pays.
            </div>
          </a>
          <a href="#/account" onClick={(e) => { e.preventDefault(); onNav("account"); }}
             style={{ textDecoration: "none", color: "inherit", padding: 16, border: "1px solid var(--ink)", borderRadius: 6, background: "var(--ink)", color: "var(--paper)", display: "block" }}>
            <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "color-mix(in srgb, var(--paper) 70%, transparent)", marginBottom: 6 }}>Full operations dashboard →</div>
            <div style={{ fontFamily: "var(--font-serif)", fontSize: 17, color: "var(--paper)", lineHeight: 1.3 }}>
              Sign in for the live operator-network feed, weather strip, port pulse, gravity map, and per-metro signals.
            </div>
          </a>
        </div>
      </section>

      <div style={{ height: 96 }} />
    </div>
  );
}

window.MarketsPage = MarketsPage;
