/* ================================================================
   consultancy.jsx — Capital Economics Consultancy page.
   One job: produce a qualified consultancy enquiry.
   Order: hero (compressed) → capability selector (tabs/accordion) →
   proof band → case studies (dark) → engagement timeline → team
   (dark) → enquiry section. Sticky enquiry bar after the hero.
   Chrome/tokens come from shared.jsx via window.
   Capability body copy is VERBATIM and fixed (section 6 of the brief).
================================================================ */
const { Icon, MAX, NS, SERIF, Eyebrow, SectionHead, SiteHeader, SiteFooter } = window;
const { Button, Input, Select, Checkbox } = window.CapitalEconomicsDesignSystem_f2a5b2;

const CONSULTANCY_EMAIL = "consultancy@capitaleconomics.com";
const emailHref = (a) => "mailto:" + a;

/* ---- extra line icons (Lucide) ---- */
const CI = {
  mail: <><rect width="20" height="16" x="2" y="4" rx="2" /><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" /></>,
  "arrow-right": <><path d="M5 12h14" /><path d="m12 5 7 7-7 7" /></>,
  "arrow-left": <><path d="M19 12H5" /><path d="m12 19-7-7 7-7" /></>,
  "chevron-right": <path d="m9 18 6-6-6-6" />,
  "chevron-down": <path d="m6 9 6 6 6-6" />,
  "external": <><path d="M15 3h6v6" /><path d="M10 14 21 3" /><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /></>,
  "check-circle": <><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" /><path d="m9 11 3 3L22 4" /></>,
  target: <><circle cx="12" cy="12" r="10" /><circle cx="12" cy="12" r="6" /><circle cx="12" cy="12" r="2" /></>,
  layers: <><path d="m12 2 9 5-9 5-9-5 9-5z" /><path d="m3 12 9 5 9-5" /><path d="m3 17 9 5 9-5" /></>,
  "file-text": <><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" /><path d="M14 2v6h6" /><path d="M16 13H8M16 17H8M10 9H8" /></>,
  presentation: <><path d="M2 3h20" /><path d="M21 3v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V3" /><path d="m7 21 5-5 5 5" /></>,
  "map-pin": <><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z" /><circle cx="12" cy="10" r="3" /></>,
};
function CIcon({ name, size = 20, stroke = 2, style }) {
  return (
    <svg style={style} width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      {CI[name]}
    </svg>
  );
}

/* Placeholder marker — copy CE must review before launch. */
function Ph({ children }) {
  return <span title="Placeholder — for Capital Economics to confirm before launch" style={{ borderBottom: "1px dashed var(--text-muted)", color: "inherit", cursor: "help" }}>{children}</span>;
}

/* ================================================================
   Data
================================================================ */
const CAPABILITIES = [
  { slug: "custom-scenarios", kicker: "Preparing for tomorrow's uncertainties", heading: "Custom macro scenarios and stress testing",
    body: "Developing economic forecasts and scenarios (e.g., inflation spikes, policy shifts, geopolitical risks) tailored to your portfolio or market. Stress test financial portfolios, optimise investment strategies, and build more resilient business plans.", related: null },
  { slug: "business-planning", kicker: "Independent insights into corporate strategy", heading: "Business planning and strategic forecasting",
    body: "Developing forecasts and scenarios to anchor your corporate strategy and resource allocation in robust, independent, and defensible economic reality. Anchor strategic goals, corporate planning, and resource allocation in robust, independent, and defensible economic reality.", related: 2 },
  { slug: "due-diligence", kicker: "De-risking growth with data-driven decisions", heading: "Due diligence for market entry and investment strategy",
    body: "In-depth economic and political risk analysis for specific target countries, cities, or sectors for due diligence and to inform investment decisions. Prioritise markets for expansion, inform investment decisions, and build a robust rationale for internal stakeholders.", related: 0 },
  { slug: "impact-assessment", kicker: "Quantifying your value to stakeholders", heading: "Economic impact assessments",
    body: "Estimating direct, indirect, and induced impacts on GDP, jobs, tax revenues, and investment. Engage policymakers, regulators, or the public with credible, evidence-based figures to support your narrative.", related: 1 },
  { slug: "policy-appraisal", kicker: "Measuring the economic ripple effect of policy", heading: "Policy appraisal and advocacy",
    body: "Assessing the impact of proposed or actual policies/regulations on a specific industry, region, or market. Influence policy and support, lobbying efforts with clear, numerical outputs and a compelling report for non-technical audiences.", related: null },
  { slug: "thought-leadership", kicker: "Designing and producing bespoke reports", heading: "Thought leadership white label & co-branded reports",
    body: "Integrate our independent analysis into your communications strategy for investor relations, thought leadership, or capital raising. Elevate thought leadership and investor credibility by leveraging third-party, independent economic validation to strengthen external communications and support capital raising or client engagement efforts.", related: null },
];

const CASE_STUDIES = [
  { title: "Global private equity due diligence", tag: "Due diligence", blurb: "Country and sector risk analysis to inform a cross-border investment decision." },
  { title: "Quantifying iwoca's Impact on SME Growth", tag: "Economic impact", blurb: "Direct, indirect and induced impact figures to support an external narrative." },
  { title: "PepsiCo: Strategic Supply Chain Planning Amid Macroeconomic Uncertainty", tag: "Business planning", blurb: "Scenario-based forecasting to anchor supply-chain and resource decisions." },
];

const TEAM = [
  { name: "Grant Colquhoun", role: "Chief Consultancy Economist", photo: "assets/people/Grant-Colquhoun.png", spec: "Grant leads CE Consultancy, with more than twenty years in applied macro across industry, commodities and China. Previously at Oxford Economics and CRU." },
  { name: "Andrew Evans", role: "Deputy Chief Consultancy Economist", photo: "assets/people/Andrew-Evans.jpg", spec: "Andrew has over ten years building evidence-based economic cases for investors, private equity firms and businesses, across due diligence, policy appraisal and strategic planning." },
  { name: "Alexandra Dreisin", role: "Head of Modelling", photo: "assets/people/Alexandra-Dreisin.jpg", spec: "Alexandra heads CE's modelling work, building the scenario and stress-testing frameworks behind consultancy engagements. Previously at SLJ Macro Partners and the US Bureau of Labor Statistics." },
  { name: "Paul Ashworth", role: "Chief Data & Modelling Economist", photo: "assets/people/Paul-Ashworth.png", spec: "Paul leads CE's Data and Modelling team and has run the Toronto office since 2007. Joined CE in 2001 from NIESR. Named WSJ Forecaster of the Year." },
];

const HOW_WE_WORK = [
  ["Tailored", "An extension of your team, with recommendations tailored to your objectives and timelines."],
  ["Deep sector expertise", "Bespoke insight from regional and sector specialists, built on an existing research base."],
  ["Objective", "Complex economic data translated into clear reports designed to shape strategic decisions."],
  ["Actionable", "Deliverables that turn economic information into immediate, impactful action."],
];

const INSTITUTION_TYPES = ["Corporate", "Financial institution", "Trade body", "Government / public body", "Private equity", "Other"];

/* ================================================================
   Page CSS. Mobile rules authored once with "@@" → media query.
================================================================ */
let cssInjected = false;
function injectCSS() {
  if (cssInjected || typeof document === "undefined") return;
  cssInjected = true;
  const base = `
  .ce-plain-mail { font-family: var(--font-ui); font-weight: 700; color: var(--brand); text-decoration: none; }
  .ce-plain-mail:hover { text-decoration: underline; color: var(--brand-hover); }

  /* Capability selector: two-column tabs on desktop, accordion on mobile.
     One DOM, all six panels present. .ce-cap-item uses display:contents so
     kickers land in col1 and panels in col2; a trailing 1fr row soaks up
     slack so the kicker list stays tight at the top. */
  .ce-cap { display: grid; grid-template-columns: 384px 1fr; grid-template-rows: repeat(6, auto) 1fr; column-gap: 48px; border-top: 1px solid var(--border-default); }
  .ce-cap-item { display: contents; }
  .ce-cap-kicker { grid-column: 1; align-self: start; display: flex; align-items: flex-start; gap: 14px; width: 100%; text-align: left; appearance: none; background: transparent; border: 0; border-bottom: 1px solid var(--border-subtle); padding: 22px 8px 22px 0; cursor: pointer; font: inherit; color: var(--text-secondary); transition: color 140ms cubic-bezier(0.2,0,0,1); }
  .ce-cap-kicker:hover { color: var(--text-primary); }
  .ce-cap-kicker:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
  .ce-cap-num { font-family: var(--font-ui); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-muted); flex: 0 0 auto; padding-top: 2px; }
  .ce-cap-ktext { font-family: var(--font-ui); font-weight: 700; font-size: 17px; line-height: 1.3; letter-spacing: -0.005em; }
  .ce-cap-kicker[aria-selected="true"] { color: var(--brand); }
  .ce-cap-kicker[aria-selected="true"] .ce-cap-num { color: var(--brand); }
  .ce-cap-kicker[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--brand); padding-left: 16px; }
  .ce-cap-chev { margin-left: auto; flex: 0 0 auto; color: var(--text-muted); display: none; }
  .ce-cap-panel { grid-column: 2; grid-row: 1 / -1; align-self: start; display: none; padding: 24px 0 8px; }
  .ce-cap-panel.is-active { display: block; }

  /* Case study carousel */
  .ce-cs-track { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(340px, 1fr); gap: 22px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; scrollbar-width: thin; }
  .ce-cs-track::-webkit-scrollbar { height: 8px; }
  .ce-cs-track::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 999px; }
  .ce-cs-card { scroll-snap-align: start; display: flex; flex-direction: column; text-align: left; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.14); border-radius: var(--radius-lg); padding: 26px 26px 24px; cursor: pointer; transition: border-color 150ms cubic-bezier(0.2,0,0,1), background 150ms cubic-bezier(0.2,0,0,1), transform 150ms cubic-bezier(0.2,0,0,1); appearance: none; font: inherit; color: inherit; }
  .ce-cs-card:hover { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.3); }
  .ce-cs-card:focus-visible { outline: 3px solid var(--ce-blue-light); outline-offset: 2px; }

  /* Engagement timeline */
  .ce-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 26px; position: relative; }
  .ce-step-line { position: absolute; top: 24px; left: 12%; right: 12%; height: 2px; background: var(--border-default); z-index: 0; }
  .ce-how-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }

  /* Team */
  .ce-team-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 30px; }
  .ce-team-photo { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: 50% 18%; border-radius: 8px; display: block; }

  /* Enquiry */
  .ce-enq-grid { display: grid; grid-template-columns: 0.82fr 1.18fr; gap: 48px; align-items: start; }
  .ce-form-card { background: var(--surface-card); border: 1px solid var(--border-default); border-radius: var(--radius-lg); padding: 32px 34px; box-shadow: var(--shadow-sm); }
  .ce-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

  /* Sticky enquiry bar */
  .ce-sticky { position: fixed; z-index: 45; transition: opacity 200ms cubic-bezier(0.2,0,0,1), transform 200ms cubic-bezier(0.2,0,0,1); }
  .ce-sticky.hide { opacity: 0; transform: translateY(14px); pointer-events: none; }
  .ce-sticky-desk { right: 24px; bottom: 24px; display: flex; align-items: center; gap: 14px; background: #1d233f; border: 1px solid rgba(255,255,255,0.16); border-radius: 999px; padding: 9px 10px 9px 22px; box-shadow: 0 14px 40px rgba(20,30,60,0.32); }
  .ce-sticky-mob { display: none; }

  @keyframes ceFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .ce-fade { animation: ceFade 200ms cubic-bezier(0.2,0,0,1) both; }
  @media (prefers-reduced-motion: reduce) { .ce-fade { animation: none; } }
  `;
  const mobile = `
  @@.ce-cap { grid-template-columns: 1fr; grid-template-rows: none; column-gap: 0; }
  @@.ce-cap-item { display: block; border-bottom: 1px solid var(--border-subtle); }
  @@.ce-cap-kicker { border-bottom: 0; padding: 20px 4px; }
  @@.ce-cap-kicker[aria-selected="true"] { box-shadow: none; padding-left: 4px; }
  @@.ce-cap-chev { display: block; }
  @@.ce-cap-panel { grid-column: auto; grid-row: auto; padding: 0 4px 24px; }
  @@.ce-steps { grid-template-columns: 1fr; gap: 22px; }
  @@.ce-step-line { display: none; }
  @@.ce-how-strip { grid-template-columns: 1fr 1fr; gap: 18px; }
  @@.ce-team-grid { grid-template-columns: 1fr 1fr; gap: 26px; }
  @@.ce-enq-grid { grid-template-columns: 1fr; gap: 30px; }
  @@.ce-form-card { padding: 24px 20px; }
  @@.ce-field-row { grid-template-columns: 1fr; gap: 0; }
  @@.ce-hero-h1 { font-size: 34px !important; }
  @@.ce-sticky-desk { display: none; }
  @@.ce-sticky-mob { display: flex; left: 0; right: 0; bottom: 0; background: #1d233f; border-top: 1px solid rgba(255,255,255,0.16); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); gap: 12px; align-items: center; }
  @@.ce-sticky { right: 0; bottom: 0; }
  `;
  const media = mobile.replace(/@@/g, "");
  const el = document.createElement("style");
  el.setAttribute("data-ce", "consultancy-page");
  el.textContent = base + "\n@media (max-width: 860px){" + media + "}";
  document.head.appendChild(el);
}
injectCSS();

/* ================================================================
   Hero — compressed navy band. Names the offer + outputs, proof
   strip, primary CTA to the form, plain visible email.
================================================================ */
const H1_LIVE = "Bespoke economic analysis, from the economists who produce the research";
const H1_OPTIONS = [
  "Macroeconomic analysis built for one decision: yours",
  "The answer to your specific economic question",
  "Strategic partnership for confident decision making (incumbent — fallback only)",
];

function Hero({ onEnquire }) {
  const proof = ["200+ client engagements", "15 years", "London, Toronto, Singapore"];
  return (
    <section id="cons-hero" style={{ position: "relative", background: "linear-gradient(180deg, rgba(20,26,46,0.86) 0%, rgba(20,26,46,0.94) 100%), url('assets/start-now-bg.jpg') center/cover no-repeat", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "72px 32px 40px", minHeight: "48vh", display: "flex", flexDirection: "column", justifyContent: "center", position: "relative", zIndex: 1 }}>
        <div style={{ maxWidth: 760 }}>
          <Eyebrow style={{ marginBottom: 16, color: "var(--ce-blue-light)" }}>Consultancy</Eyebrow>
          <h1 className="ce-hero-h1" style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 48, lineHeight: 1.08, letterSpacing: "-0.02em", color: "#fff", margin: 0, maxWidth: 740 }}>
            {H1_LIVE}
          </h1>
          <p style={{ fontFamily: NS, fontSize: 19, lineHeight: 1.5, color: "var(--text-on-navy)", margin: "20px 0 28px", maxWidth: 620 }}>
            Forecasts, scenarios, models, impact assessments and reports, scoped to your question.
          </p>
          <div style={{ display: "flex", flexWrap: "wrap", alignItems: "center", gap: "14px 22px" }}>
            <Button variant="inverse" size="lg" onClick={onEnquire} iconEnd={<CIcon name="arrow-right" size={18} />}>Start a conversation</Button>
            <span style={{ fontFamily: NS, fontSize: 15.5, color: "rgba(255,255,255,0.82)" }}>
              Or email <a href={emailHref(CONSULTANCY_EMAIL)} className="ce-plain-mail" style={{ color: "#fff" }}>{CONSULTANCY_EMAIL}</a>
            </span>
          </div>
        </div>

        {/* Proof strip — readable size, not caption */}
        <div style={{ marginTop: 40, paddingTop: 22, borderTop: "1px solid rgba(255,255,255,0.16)", display: "flex", flexWrap: "wrap", alignItems: "center", gap: "10px 26px" }}>
          {proof.map((p, i) => (
            <React.Fragment key={p}>
              {i > 0 && <span aria-hidden="true" style={{ color: "rgba(255,255,255,0.3)" }}>·</span>}
              <span style={{ fontFamily: NS, fontWeight: 700, fontSize: 16, color: "#fff" }}>{p}</span>
            </React.Fragment>
          ))}
        </div>
      </div>
    </section>
  );
}

/* Headline options for sign-off — subordinate review annotation. */
function HeadlineNote() {
  return (
    <section style={{ background: "var(--surface-sunken)", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "12px 32px", display: "flex", flexWrap: "wrap", alignItems: "center", gap: "6px 12px" }}>
        <span style={{ fontFamily: NS, fontSize: 12, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--text-muted)", flex: "0 0 auto" }}>Headline options for CE sign-off</span>
        <span style={{ fontFamily: NS, fontSize: 13, color: "var(--text-secondary)" }}>
          Live: “{H1_LIVE}”. Alternatives: {H1_OPTIONS.slice(0, 2).map((o) => "“" + o + "”").join("; ")}. Incumbent kept as fallback only.
        </span>
      </div>
    </section>
  );
}

/* ================================================================
   Capability selector — ARIA tabs (desktop) / accordion (mobile).
   All six panels in the DOM; inactive hidden with CSS.
================================================================ */
function CapabilitySection({ active, setActive, onDiscuss }) {
  const onKeyNav = (e) => {
    const n = CAPABILITIES.length;
    if (e.key === "ArrowDown" || e.key === "ArrowRight") { e.preventDefault(); setActive((active + 1) % n); }
    else if (e.key === "ArrowUp" || e.key === "ArrowLeft") { e.preventDefault(); setActive((active - 1 + n) % n); }
    else if (e.key === "Home") { e.preventDefault(); setActive(0); }
    else if (e.key === "End") { e.preventDefault(); setActive(n - 1); }
  };
  return (
    <section id="capabilities" style={{ background: "var(--surface-card)", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "60px 32px" }}>
        <SectionHead eyebrow="What you can commission" title="Six ways we work with clients."
          intro="Pick the problem that sounds like yours. Each opens what we produce, and takes that context straight into your enquiry." maxTitle={640} />
        <div className="ce-cap" role="tablist" aria-label="Consultancy capabilities" aria-orientation="vertical" onKeyDown={onKeyNav}>
          {CAPABILITIES.map((cap, i) => (
            <div className="ce-cap-item" key={cap.slug}>
              <button className="ce-cap-kicker" id={"cap-tab-" + cap.slug} role="tab" aria-selected={active === i} aria-controls={"cap-panel-" + cap.slug}
                tabIndex={active === i ? 0 : -1} onClick={() => setActive(i)}>
                <span className="ce-cap-num">{String(i + 1).padStart(2, "0")}</span>
                <span className="ce-cap-ktext">{cap.kicker}</span>
                <span className="ce-cap-chev"><CIcon name="chevron-down" size={20} style={{ transform: active === i ? "rotate(180deg)" : "none", transition: "transform 160ms cubic-bezier(0.2,0,0,1)" }} /></span>
              </button>
              <div className={"ce-cap-panel" + (active === i ? " is-active" : "")} id={"cap-panel-" + cap.slug} role="tabpanel" aria-labelledby={"cap-tab-" + cap.slug} tabIndex={0}>
                <div className="ce-fade" key={active === i ? "on" : "off"}>
                    <div style={{ fontFamily: NS, fontWeight: 700, fontSize: 12, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--brand)", marginBottom: 14 }}>{cap.kicker}</div>
                    <h3 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 30, lineHeight: 1.16, letterSpacing: "-0.015em", color: "var(--text-primary)", margin: 0, maxWidth: 620 }}>{cap.heading}</h3>
                    <p style={{ fontFamily: NS, fontSize: 17, lineHeight: 1.62, color: "var(--text-secondary)", margin: "18px 0 0", maxWidth: 620 }}>{cap.body}</p>
                    {cap.related != null && (() => { const cs = CASE_STUDIES[cap.related]; return (
                      <a href="#case-studies" style={{ display: "flex", alignItems: "center", gap: 14, marginTop: 26, padding: "16px 18px", background: "var(--surface-sunken)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-lg)", textDecoration: "none", maxWidth: 560 }}>
                        <span style={{ width: 38, height: 38, borderRadius: 8, background: "var(--brand-subtle)", color: "var(--brand)", display: "inline-flex", alignItems: "center", justifyContent: "center", flex: "0 0 auto" }}><CIcon name="file-text" size={18} /></span>
                        <span style={{ minWidth: 0 }}>
                          <span style={{ display: "block", fontFamily: NS, fontSize: 11.5, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--text-muted)" }}>Related work</span>
                          <span style={{ display: "block", fontFamily: NS, fontSize: 15.5, fontWeight: 700, color: "var(--text-primary)", marginTop: 2 }}>{cs.title}</span>
                        </span>
                        <span style={{ marginLeft: "auto", color: "var(--brand)", flex: "0 0 auto" }}><CIcon name="chevron-right" size={18} /></span>
                      </a>
                    ); })()}
                    <div style={{ marginTop: 28 }}>
                      <Button variant="primary" size="lg" onClick={() => onDiscuss(cap.slug)} iconEnd={<CIcon name="arrow-right" size={18} />}>Discuss this with our team</Button>
                    </div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ================================================================
   Proof band + Case studies (dark) — read as one continuous argument.
================================================================ */
function ProofAndCases({ onDiscuss }) {
  const trackRef = React.useRef();
  const nudge = (dir) => { const el = trackRef.current; if (el) el.scrollBy({ left: dir * (el.clientWidth * 0.8), behavior: "smooth" }); };
  const clients = [["Goldman Sachs", "Goldman-Sachs.svg"], ["Investec", "Investec.svg"], ["Bank of Ireland", "Bank-of-Ireland.svg"], ["EDF", "EDF.svg"]];
  return (
    <>
      {/* Proof band — light, sits directly above the dark case studies */}
      <section style={{ background: "var(--surface-page)", borderBottom: "1px solid var(--border-subtle)" }}>
        <div style={{ maxWidth: MAX, margin: "0 auto", padding: "40px 32px 44px", textAlign: "center" }}>
          <div style={{ fontFamily: NS, fontWeight: 700, fontSize: 13, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--text-muted)", marginBottom: 26 }}>
            Trusted by corporates, financial institutions and public bodies worldwide
          </div>
          <div style={{ display: "flex", flexWrap: "wrap", justifyContent: "center", alignItems: "center", gap: "24px 56px" }}>
            {clients.map(([name, file]) => (
              <img key={name} src={"assets/logos/" + file} alt={name} style={{ height: 38, width: "auto", maxWidth: 170, objectFit: "contain", opacity: 0.8, display: "block" }} />
            ))}
          </div>
        </div>
      </section>

      {/* Case studies — dark contrast band */}
      <section id="case-studies" style={{ background: "#1d233f" }}>
        <div style={{ maxWidth: MAX, margin: "0 auto", padding: "64px 32px" }}>
          <div style={{ marginBottom: 34 }}>
            <Eyebrow style={{ marginBottom: 16, color: "var(--ce-blue-light)" }}>Selected work</Eyebrow>
            <h2 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 36, lineHeight: 1.13, letterSpacing: "-0.015em", color: "#fff", margin: 0, maxWidth: 620 }}>
              Comparable engagements, by capability.
            </h2>
          </div>

          <div className="ce-cs-track" ref={trackRef}>
            {CASE_STUDIES.map((cs) => (
              <a key={cs.title} href="#case-studies" className="ce-cs-card">
                <span style={{ alignSelf: "flex-start", fontFamily: NS, fontWeight: 700, fontSize: 11.5, letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--ce-blue-light)", border: "1px solid rgba(165,181,222,0.4)", borderRadius: 999, padding: "5px 11px", marginBottom: 20 }}>{cs.tag}</span>
                <h3 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 22, lineHeight: 1.24, letterSpacing: "-0.01em", color: "#fff", margin: "0 0 12px" }}>{cs.title}</h3>
                <p style={{ fontFamily: NS, fontSize: 15, lineHeight: 1.55, color: "rgba(255,255,255,0.72)", margin: "0 0 22px" }}>{cs.blurb}</p>
                <span style={{ marginTop: "auto", display: "inline-flex", alignItems: "center", gap: 6, fontFamily: NS, fontWeight: 700, fontSize: 14.5, color: "#fff" }}>Read case study<CIcon name="arrow-right" size={15} /></span>
              </a>
            ))}
          </div>

          <div style={{ marginTop: 30 }}>
            <a href="#case-studies" className="ce-textlink ce-textlink-light">View all case studies<CIcon name="arrow-right" size={15} /></a>
          </div>
        </div>
      </section>
    </>
  );
}

/* ================================================================
   Engagement process — horizontal 4-step timeline + reduced
   "how we work" strip. Step copy is placeholder for CE review.
================================================================ */
function EngagementSection() {
  const steps = [
    { icon: "target", h: "Scope", b: "An initial call with a lead economist to define the question, the outputs and the timeline." },
    { icon: "layers", h: "Analyse", b: "Modelling and analysis by sector and regional specialists, drawing on CE's existing research base." },
    { icon: "file-text", h: "Deliver", b: "A report, model or dataset built for the audience who needs to act on it." },
    { icon: "presentation", h: "Present", b: "A walkthrough with your team or stakeholders, with the analysts who did the work." },
  ];
  return (
    <section style={{ background: "var(--surface-card)", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "64px 32px" }}>
        <SectionHead eyebrow="How an engagement works" title="From first call to final walkthrough."
          intro="A scoped, quoted process, not a subscription. Step detail is placeholder copy for the consultancy team to confirm before launch." maxTitle={680} />

        <div className="ce-steps">
          {steps.map((s) => (
            <div key={s.h} style={{ position: "relative", zIndex: 1 }}>
              <div style={{ marginBottom: 18 }}>
                <span style={{ width: 56, height: 56, borderRadius: 14, background: "var(--brand-subtle)", border: "1px solid #cdd8f0", color: "var(--brand)", display: "inline-flex", alignItems: "center", justifyContent: "center", boxShadow: "0 6px 16px rgba(22,65,148,0.12)" }}><CIcon name={s.icon} size={24} /></span>
              </div>
              <h3 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 22, letterSpacing: "-0.01em", color: "var(--text-primary)", margin: "0 0 8px" }}>{s.h}</h3>
              <p style={{ fontFamily: NS, fontSize: 15, lineHeight: 1.55, color: "var(--text-secondary)", margin: 0 }} title="Placeholder — for Capital Economics to confirm before launch">{s.b}</p>
            </div>
          ))}
        </div>

        {/* Reduced "how we work" claims — one-line captions */}
        <div className="ce-how-strip" style={{ marginTop: 52, paddingTop: 34, borderTop: "1px solid var(--border-subtle)" }}>
          {HOW_WE_WORK.map(([h, b]) => (
            <div key={h}>
              <div style={{ fontFamily: NS, fontWeight: 700, fontSize: 15, color: "var(--text-primary)", marginBottom: 6 }}>{h}</div>
              <p style={{ fontFamily: NS, fontSize: 14, lineHeight: 1.5, color: "var(--text-secondary)", margin: 0 }}>{b}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ================================================================
   Team (dark) — About Us bio treatment, with a specialism line.
================================================================ */
function TeamMember({ m }) {
  return (
    <div>
      {m.photo ? (
        <img className="ce-team-photo" src={m.photo} alt={m.name} />
      ) : (
        <div className="ce-team-photo" title="Headshot to be supplied by CE" style={{ background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.14)", display: "flex", alignItems: "center", justifyContent: "center" }}>
          <span style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 34, color: "rgba(255,255,255,0.5)" }}>{m.name.split(" ").map((w) => w[0]).join("")}</span>
        </div>
      )}
      <h3 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 21, letterSpacing: "-0.01em", color: "#fff", margin: "16px 0 0" }}>{m.name}</h3>
      <div style={{ fontFamily: NS, fontWeight: 700, fontSize: 11, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--ce-blue-light)", margin: "8px 0 10px" }}>{m.role}</div>
      <p style={{ fontFamily: NS, fontSize: 14, lineHeight: 1.55, color: "rgba(255,255,255,0.72)", margin: 0 }}>{m.spec}</p>
      <a href="#team" className="ce-textlink ce-textlink-light" style={{ marginTop: 12, fontSize: 14 }}>View profile<CIcon name="arrow-right" size={14} /></a>
    </div>
  );
}
function TeamSection() {
  return (
    <section id="team" style={{ background: "#1d233f", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "64px 32px" }}>
        <div style={{ maxWidth: 640, marginBottom: 40 }}>
          <Eyebrow style={{ marginBottom: 16, color: "var(--ce-blue-light)" }}>Who you work with</Eyebrow>
          <h2 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 36, lineHeight: 1.13, letterSpacing: "-0.015em", color: "#fff", margin: 0 }}>
            You work directly with the economists who do the analysis, not an account team.
          </h2>
        </div>
        <div className="ce-team-grid">
          {TEAM.map((m) => <TeamMember key={m.name} m={m} />)}
        </div>
      </div>
    </section>
  );
}

/* ================================================================
   Enquiry section — the conversion point. Two columns.
================================================================ */
const CAP_LABELS = CAPABILITIES.map((c) => c.heading);
const slugToHeading = (slug) => { const c = CAPABILITIES.find((x) => x.slug === slug); return c ? c.heading : ""; };

function EnquiryForm({ capability }) {
  const [v, setV] = React.useState({ email: "", first: "", last: "", company: "", institution: "", country: "", phone: "", capability: "", message: "" });
  const [sent, setSent] = React.useState(false);
  const set = (k) => (e) => setV((s) => ({ ...s, [k]: e.target.value }));

  React.useEffect(() => { if (capability) setV((s) => ({ ...s, capability: slugToHeading(capability) })); }, [capability]);

  if (sent) {
    return (
      <div className="ce-form-card ce-fade" role="status" aria-live="polite">
        <div style={{ width: 52, height: 52, borderRadius: "50%", background: "var(--positive-100)", color: "var(--positive)", display: "inline-flex", alignItems: "center", justifyContent: "center", marginBottom: 20 }}><CIcon name="check-circle" size={28} /></div>
        <h3 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 26, letterSpacing: "-0.015em", color: "var(--text-primary)", margin: "0 0 12px" }}>Thanks. Your enquiry is with the consultancy team.</h3>
        <p style={{ fontFamily: NS, fontSize: 16.5, lineHeight: 1.6, color: "var(--text-secondary)", margin: "0 0 24px", maxWidth: 520 }}>
          We'll read it, route it to the right economist and come back within <Ph>one working day</Ph>. If it's urgent, email <a href={emailHref(CONSULTANCY_EMAIL)} className="ce-plain-mail">{CONSULTANCY_EMAIL}</a>.
        </p>
        <Button variant="secondary" size="lg" onClick={() => { setV({ email: "", first: "", last: "", company: "", institution: "", country: "", phone: "", capability: "", message: "" }); setSent(false); }}>Send another enquiry</Button>
      </div>
    );
  }

  return (
    <form className="ce-form-card" onSubmit={(e) => { e.preventDefault(); setSent(true); }} noValidate>
      <div style={{ display: "flex", flexDirection: "column", gap: 18 }}>
        <Input label="Work email" required type="email" value={v.email} onChange={set("email")} autoComplete="email" />
        <div className="ce-field-row">
          <Input label="First name" required value={v.first} onChange={set("first")} autoComplete="given-name" />
          <Input label="Last name" required value={v.last} onChange={set("last")} autoComplete="family-name" />
        </div>
        <Input label="Company name" required value={v.company} onChange={set("company")} autoComplete="organization" />
        <div className="ce-field-row">
          <Select label="Institution type" hint="Optional" value={v.institution} onChange={set("institution")}
            options={[{ value: "", label: "Select…" }, ...INSTITUTION_TYPES.map((t) => ({ value: t, label: t }))]} />
          <Input label="Country" hint="Optional" value={v.country} onChange={set("country")} autoComplete="country-name" />
        </div>
        <div className="ce-field-row">
          <Input label="Telephone" hint="Optional" type="tel" value={v.phone} onChange={set("phone")} autoComplete="tel" />
          <Select label="Capability of interest" hint="Optional" value={v.capability} onChange={set("capability")}
            options={[{ value: "", label: "Select…" }, ...CAP_LABELS.map((t) => ({ value: t, label: t }))]} />
        </div>
        <div>
          <label htmlFor="enq-msg" style={{ display: "block", fontFamily: NS, fontWeight: 600, fontSize: 14, color: "var(--text-primary)", marginBottom: 7 }}>Message <span style={{ color: "var(--negative)" }}>*</span></label>
          <textarea id="enq-msg" required value={v.message} onChange={set("message")} rows={4} placeholder="What question are you trying to answer, and by when?"
            style={{ width: "100%", boxSizing: "border-box", fontFamily: NS, fontSize: 15.5, lineHeight: 1.5, color: "var(--text-primary)", padding: "11px 13px", borderRadius: "var(--radius-md, 5px)", border: "1px solid var(--border-default)", outline: "none", resize: "vertical", background: "var(--surface-card)" }} />
        </div>
        <div style={{ marginTop: 2 }}>
          <Button type="submit" variant="primary" size="lg" iconEnd={<CIcon name="arrow-right" size={17} />}>Send enquiry</Button>
        </div>
        <p style={{ fontFamily: NS, fontSize: 13, lineHeight: 1.55, color: "var(--text-muted)", margin: 0 }}>
          We use your details only to respond to your enquiry. See our <a href="#privacy">privacy policy</a>.
        </p>
        <p style={{ fontFamily: NS, fontSize: 12.5, lineHeight: 1.5, color: "var(--text-muted)", margin: 0, paddingTop: 12, borderTop: "1px dashed var(--border-default)" }}>
          <Ph>Field requirements are a recommendation for CE to approve</Ph>: only email, name, company and message are required; telephone, country and institution type are optional to lift completion.
        </p>
      </div>
    </form>
  );
}

function EnquirySection({ capability, formRef }) {
  const steps = [
    "We read your enquiry and route it to the right economist",
    "We come back within one working day",
    "A scoping call to agree the question, outputs and timeline, with no obligation",
  ];
  return (
    <section id="enquire" ref={formRef} style={{ background: "linear-gradient(180deg, #F4F6FC 0%, #E6ECF7 100%)", borderBottom: "1px solid var(--border-subtle)", scrollMarginTop: 80 }}>
      <div style={{ maxWidth: MAX, margin: "0 auto", padding: "64px 32px" }}>
        <div className="ce-enq-grid">
          {/* Reassurance panel */}
          <div>
            <Eyebrow style={{ marginBottom: 16 }}>Enquire</Eyebrow>
            <h2 style={{ fontFamily: SERIF, fontWeight: 600, fontSize: 34, lineHeight: 1.13, letterSpacing: "-0.015em", color: "var(--text-primary)", margin: 0 }}>Tell us what you need.</h2>

            <div style={{ marginTop: 30, fontFamily: NS, fontWeight: 700, fontSize: 12, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--text-muted)", marginBottom: 14 }}>What happens next</div>
            <ol style={{ listStyle: "none", counterReset: "s", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 16 }}>
              {steps.map((s, i) => (
                <li key={i} style={{ display: "flex", gap: 14 }}>
                  <span style={{ width: 28, height: 28, borderRadius: "50%", background: "var(--brand)", color: "#fff", fontFamily: NS, fontWeight: 700, fontSize: 14, display: "inline-flex", alignItems: "center", justifyContent: "center", flex: "0 0 auto" }}>{i + 1}</span>
                  <span style={{ fontFamily: NS, fontSize: 16, lineHeight: 1.5, color: "var(--text-secondary)", paddingTop: 3 }}>{i === 1 ? <><Ph>We come back within one working day</Ph></> : s}</span>
                </li>
              ))}
            </ol>

            <div style={{ marginTop: 30, paddingTop: 24, borderTop: "1px solid var(--border-subtle)" }}>
              <div style={{ fontFamily: NS, fontSize: 15, color: "var(--text-secondary)", marginBottom: 4 }}>Or email us directly at</div>
              <a href={emailHref(CONSULTANCY_EMAIL)} className="ce-plain-mail" style={{ fontSize: 18 }}>{CONSULTANCY_EMAIL}</a>
            </div>
          </div>

          {/* Form */}
          <EnquiryForm capability={capability} />
        </div>
      </div>
    </section>
  );
}

/* ================================================================
   Sticky enquiry bar — appears after the hero leaves the viewport.
================================================================ */
function StickyBar({ onEnquire }) {
  const [show, setShow] = React.useState(false);
  React.useEffect(() => {
    const hero = document.getElementById("cons-hero");
    if (!hero || !("IntersectionObserver" in window)) return;
    const io = new IntersectionObserver(([e]) => setShow(!e.isIntersecting), { threshold: 0, rootMargin: "-80px 0px 0px 0px" });
    io.observe(hero);
    return () => io.disconnect();
  }, []);
  return (
    <div className={"ce-sticky" + (show ? "" : " hide")}>
      <div className="ce-sticky-desk">
        <span style={{ fontFamily: NS, fontSize: 14.5, fontWeight: 600, color: "#fff" }}>Ready to scope a question?</span>
        <a href={emailHref(CONSULTANCY_EMAIL)} aria-label={"Email " + CONSULTANCY_EMAIL} style={{ width: 40, height: 40, borderRadius: 999, border: "1px solid rgba(255,255,255,0.24)", color: "#fff", display: "inline-flex", alignItems: "center", justifyContent: "center" }}><CIcon name="mail" size={18} /></a>
        <Button variant="inverse" size="md" onClick={onEnquire} iconEnd={<CIcon name="arrow-right" size={16} />}>Enquire</Button>
      </div>
      <div className="ce-sticky-mob">
        <a href={emailHref(CONSULTANCY_EMAIL)} aria-label={"Email " + CONSULTANCY_EMAIL} style={{ width: 46, height: 46, borderRadius: 12, border: "1px solid rgba(255,255,255,0.24)", color: "#fff", display: "inline-flex", alignItems: "center", justifyContent: "center", flex: "0 0 auto" }}><CIcon name="mail" size={20} /></a>
        <Button variant="inverse" size="lg" block onClick={onEnquire} iconEnd={<CIcon name="arrow-right" size={18} />}>Enquire</Button>
      </div>
    </div>
  );
}

/* ================================================================
   App
================================================================ */
function App() {
  const [active, setActive] = React.useState(0);
  const [capability, setCapability] = React.useState("");
  const formRef = React.useRef();

  // Deep-link: ?capability=slug preselects the form.
  React.useEffect(() => {
    const p = new URLSearchParams(location.search).get("capability");
    if (p && CAPABILITIES.some((c) => c.slug === p)) setCapability(p + "|" + Date.now());
  }, []);

  const scrollToForm = () => { if (formRef.current) { const r = formRef.current.getBoundingClientRect(); window.scrollTo({ top: window.scrollY + r.top - 76, behavior: "smooth" }); } };
  const onEnquire = () => scrollToForm();
  const onDiscuss = (slug) => { setCapability(slug + "|" + Date.now()); scrollToForm(); };
  const cleanCap = capability ? capability.split("|")[0] : "";

  return (
    <div style={{ minHeight: "100vh", background: "var(--surface-page)" }}>
      <SiteHeader />
      <Hero onEnquire={onEnquire} />
      <CapabilitySection active={active} setActive={setActive} onDiscuss={onDiscuss} />
      <ProofAndCases onDiscuss={onDiscuss} />
      <EngagementSection />
      <TeamSection />
      <EnquirySection capability={cleanCap} formRef={formRef} />
      <SiteFooter />
      <StickyBar onEnquire={onEnquire} />
    </div>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
