// pages.jsx — Inner pages for Enginuity (corporate engineering consultancy style)
// About, Capabilities (index + detail), Markets, Projects, Insights, Contact, 404

const { useState: useState_p, useEffect: useEffect_p } = React;

// ── EPCM disciplines — full service lists ───────────────────────────────────
// Mechanical / Electrical / Civil / Bulk reuse the detailed Plant Explorer lists;
// Process & Mining are the client-supplied lists.
const EPCM_DISCIPLINES = [
  {
    id: 'mechanical', label: 'Mechanical', tag: 'Design · FEA · Equipment', tone: 'industrial',
    blurb: 'Mechanical equipment and systems design — from equipment selection and materials engineering through FEA verification, piping layout and design reviews that keep every package buildable and compliant.',
    services: [
      'Mechanical equipment design & specification',
      'Static & rotating equipment selection',
      'Materials selection & corrosion assessment',
      'Piping design support & layout development',
      'Pressure vessel & tank design support',
      'Structural & mechanical interface definition',
      'Design for manufacture & assembly (DFMA)',
      'Finite element analysis (FEA) & structural verification',
      'Fatigue, vibration & thermal stress assessments',
      'Mechanical design reviews & compliance checks',
    ],
  },
  {
    id: 'electrical', label: 'Electrical & Control', tag: 'MV · LV · I&C', tone: 'sky',
    blurb: 'Medium-voltage reticulation, protection coordination, MCCs, drive packages and SCADA integration — for greenfield builds and live brownfield upgrades.',
    services: [
      'Medium-voltage reticulation (11 / 22 / 33 kV)',
      'Protection coordination & arc-flash studies',
      'Motor control centres & VSD packages',
      'Cable routing, racking & containment',
      'Substation & transformer design',
      'SCADA, PLC & instrumentation',
      'Power-quality & harmonic studies',
      'Earthing & lightning protection',
    ],
  },
  {
    id: 'process', label: 'Process', tag: 'Flowsheets · PFDs · P&IDs', tone: 'studio',
    blurb: 'Flowsheet development, mass and energy balances, equipment sizing and the diagrams that turn a concept into a buildable, operable plant — fully integrated with every other discipline.',
    services: [
      'Geological & geotechnical studies',
      'Process flow diagrams (PFD) development',
      'Piping & instrumentation diagrams (P&IDs)',
      'Mass & energy balances',
      'Equipment sizing & specifications',
      'Process simulation & performance modelling',
      'Control philosophy & instrumentation definition',
      'Utility & off-site system definition',
      'Hazard identification & operability studies (HAZOP)',
      'Process design criteria & bases of design',
      'Integration with mechanical, electrical & civil disciplines',
    ],
  },
  {
    id: 'civil', label: 'Civil & Structural', tag: 'Foundations · Steel · Concrete', tone: 'earth',
    blurb: 'Earthworks through to the steel and concrete that carries the plant. Heavy industrial structures designed to category-4 standards.',
    services: [
      'Earthworks, bulk & detail',
      'Reinforced-concrete foundations',
      'Heavy industrial steel structures',
      'Mill, crusher & tank foundations',
      'Conveyor gantries & support trestles',
      'Buildings, control rooms & substations',
      'Stormwater & containment',
      'Geotechnical interface design',
    ],
  },
  {
    id: 'mining', label: 'Mining', tag: 'Open pit · Underground · Planning', tone: 'plant',
    blurb: 'Open-pit and underground mine design, planning and optimisation — from concept studies through to fleet productivity and operational improvement.',
    services: [
      'Open-pit & underground mine design',
      'Mine planning, scheduling & production optimisation',
      'Drill & blast design and optimisation',
      'Geotechnical & ground-control support',
      'Haulage, materials handling & mine infrastructure layout',
      'Equipment selection & fleet-productivity assessment',
      'Mining studies (concept, pre-feasibility, feasibility)',
      'Operational improvement & cost-reduction studies',
      'Integration with processing plants & surface infrastructure',
    ],
  },
  {
    id: 'bulk', label: 'Bulk Material Handling', tag: 'Conveyors · Crushing · Equipment', tone: 'industrial',
    blurb: 'Materials handling and processing equipment from ROM tip through to product stockpile — conveying, crushing and screening, mills, pumps, tanks and the reclaim and dust systems around them.',
    services: [
      'Conveyor design (CEMA / DIN 22101)',
      'Transfer chute engineering (DEM analysis)',
      'Crushing — primary, secondary, tertiary',
      'Screening & classification',
      'Cyclone clusters & classification',
      'Mill packages (SAG, ball, regrind)',
      'Feeders, hoppers & surge bins',
      'Static equipment — tanks, vessels, hoppers',
      'Slurry & process pump systems',
      'Thickeners & clarifiers',
      'Leach & CIL / CIP adsorption circuits',
      'Elution & electrowinning circuits',
      'Stockpile geometry & reclaim systems',
      'Stackers & boom conveyors',
      'Piping, valves, FEA & CFD',
      'Dust management & enclosure',
    ],
  },
];

// ── R&D programmes ──────────────────────────────────────────────────────────
const RD_AREAS = [
  {
    id: 'microwave', label: 'High-power microwave technology', tag: '915 MHz · 100–800 kW', tone: 'studio', img: 'assets/rd-microwave.jpg',
    summary: 'Over more than eight years we have designed, built and field-deployed some of the highest-power industrial microwave systems in operation — multi-hundred-kilowatt 915 MHz plants that heat mineral-rich rock volumetrically to induce thermal cracking ahead of mechanical excavation.',
    detail: 'The same physics, hardware and safe-operation discipline now anchor our space and recycling research: volumetric dielectric heating, articulated waveguide applicators, Faraday shielding and closed-loop thermal control.',
    points: [
      ['100 kW → 800 kW', 'Installed microwave power, modular solid-state to in-situ rigs'],
      ['≈ 280–300 mm', 'Effective in-situ treatment depth on hard rock'],
      ['> 100% gain', 'Penetration / cutting-rate improvement from volumetric heating'],
      ['HFSS + MATLAB', 'Field-distribution modelling validated against field results'],
    ],
  },
  {
    id: 'lunar', label: 'Lunar surface construction', tag: 'In-situ ISRU · Patent pending', tone: 'industrial', img: 'assets/rd-lunar.png',
    summary: 'A microwave method for converting loose lunar regolith into solid, load-bearing surfaces directly on the Moon — using only in-situ material, with no binders, water or aggregate shipped from Earth.',
    detail: 'Regolith\u2019s iron- and titanium-bearing minerals couple strongly to microwave fields, so energy is deposited throughout the volume and the material sinters and melts into a coherent solid without contact — tolerant of hard vacuum and abrasive, charged dust. Our first trial achieved coalescence to 280 mm in a single three-minute 915 MHz exposure.',
    points: [
      ['Landing & ascent pads', 'Thick load-bearing slabs that suppress descent-plume ejecta'],
      ['Roads & rover traverses', 'Stable, dust-controlled routes between sites'],
      ['Foundation pads', 'Level bearing surfaces for habitats and equipment'],
      ['Dust-mitigation zones', 'Stabilised crusts protecting seals, optics and suits'],
    ],
  },
  {
    id: 'testing', label: 'Space-environment simulation & testing', tag: 'Vacuum · Thermal · Radiation', tone: 'sky', img: 'assets/rd-testing.png',
    summary: 'A deep-shaft environmental chamber that reproduces the conditions space hardware must survive — hard vacuum, extreme thermal cycling, altered gravity and radiation — so products can be qualified against representative lunar and orbital conditions in-house.',
    detail: 'Operating our own test facility closes the develop–test–iterate loop before any flight commitment, and lets us qualify both our own systems and partners\u2019 hardware. Separately patent pending.',
    points: [
      ['Hard vacuum', 'Representative lunar and orbital pressure regimes'],
      ['Thermal extremes', 'Hundreds of degrees of diurnal cycling'],
      ['Altered gravity', 'Deep-shaft architecture for reduced-g regimes'],
      ['Radiation', 'Environmental exposure for materials and electronics'],
    ],
  },
  {
    id: 'recycling', label: 'Recycling & circular-process systems', tag: 'Material recovery · Beneficiation', tone: 'plant', img: 'assets/rd-recycling.jpeg',
    summary: 'Flow-sheets for recovering value from secondary and waste streams — beneficiation of complex feeds, developed from laboratory through pilot scale and into full circular-process design for the resource sector.',
    detail: 'The same microwave, process and simulation tools we apply to ore and regolith carry directly into closing material loops: drying, separation, breakage reduction and recovery of secondary streams.',
    points: [
      ['Material recovery', 'Flow-sheets for secondary & waste streams'],
      ['Beneficiation', 'Upgrading of complex and low-grade feeds'],
      ['Lab → pilot', 'De-risked scale-up before commitment'],
      ['Circular design', 'Closing loops across the process'],
    ],
  },
];

// ── About ──────────────────────────────────────────────────────────────────
function AboutPage({ onNav }) {
  return (
    <>
      <PageHero
        eyebrow="About Enginuity"
        title="A firm built by engineers, for engineering problems."
        sub="Multi-disciplinary engineering, project delivery and technology development for the mining, minerals and industrial sectors."
        tone="industrial"
        img="assets/home-hero-mashup.jpg"
      />

      <Section id="story">
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.5fr) minmax(0, 1fr)',
          gap: 56, alignItems: 'start',
        }} className="enq-2col">
          <div>
            <Eyebrow>Our story</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '14ch' }}>
              Built to close the gap between design and delivery.
            </Headline>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 22 }}>
            <p style={{ fontSize: 'clamp(17px, 1.3vw, 20px)', lineHeight: 1.55, color: 'var(--fg)', margin: 0, maxWidth: '58ch' }}>
              Enginuity was founded in 2017 by engineers who had grown frustrated with the gap
              between conceptual design and the realities of execution. Plans that looked good
              on paper failed in the field — and the firms that designed them weren't there to
              fix it.
            </p>
            <p style={{ fontSize: 16, lineHeight: 1.65, color: 'var(--fg2)', margin: 0, maxWidth: '60ch' }}>
              We do it differently. The same engineers who do the simulation work also walk the
              site during commissioning. Our R&D programme — including world-class microwave
              technology research conducted from our St Gallen office — feeds directly into the
              EPCM projects we deliver across Africa.
            </p>
            <p style={{ fontSize: 16, lineHeight: 1.65, color: 'var(--fg2)', margin: 0, maxWidth: '60ch' }}>
              Today the team operates from Centurion, South Africa, with a research office in
              St Gallen, Switzerland. We work with clients and partners including
              Anglo American, Black Chrome Mine, Aurex Constructors, General Kinematics,
              Iritron and R&R Quantity Surveyors.
            </p>
          </div>
        </div>
      </Section>

      <Stats />

      <Section id="offices">
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
          gap: 32, alignItems: 'end', marginBottom: 48,
        }} className="enq-2col">
          <div>
            <Eyebrow>Offices</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '14ch' }}>
              Two offices, one team.
            </Headline>
          </div>
          <p style={{ fontSize: 16, lineHeight: 1.6, color: 'var(--fg2)', margin: 0, maxWidth: '46ch' }}>
            Headquartered in South Africa with a research arm in Switzerland —
            so the R&D bench and the EPCM delivery floor stay connected.
          </p>
        </div>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 28,
        }} className="enq-2col">
          {[
            { tag: 'South Africa', city: 'Centurion', role: 'Engineering & EPCM headquarters', detail: ['Limeroc Business Park', 'Mini Factory Unit 27, Magner Street', 'Knoppieslaagte 385-JR, Centurion 0157'], img: 'assets/office-centurion.jpeg', pos: 'center', tone: 'earth' },
            { tag: 'Switzerland',  city: 'St Gallen', role: 'Research & technology development',  detail: ['Lerchenfeldstrasse 3', '9014 St Gallen', 'Switzerland'], img: 'assets/office-stgallen.jpeg', pos: 'center 40%', tone: 'sky' },
          ].map((o, i) => (
            <article key={i} style={{ background: 'var(--bg)', border: '1px solid var(--hair)' }}>
              <Photo aspect="16/9" src={o.img} objectPosition={o.pos} tone={o.tone} caption={`${o.city} office — Enginuity`} />
              <div style={{ padding: '28px 32px 32px' }}>
                <span style={{
                  fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
                  letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)',
                }}>{o.tag}</span>
                <Headline size="md" as="h3" style={{ marginTop: 12 }}>{o.city}</Headline>
                <p style={{ margin: '8px 0 24px', fontSize: 15, color: 'var(--fg2)' }}>{o.role}</p>
                <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 6 }}>
                  {o.detail.map((line, j) => (
                    <li key={j} style={{ fontSize: 15, color: 'var(--fg2)', lineHeight: 1.5 }}>{line}</li>
                  ))}
                </ul>
              </div>
            </article>
          ))}
        </div>
      </Section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Capabilities index ─────────────────────────────────────────────────────
function CapabilitiesIndex({ onNav }) {
  return (
    <>
      <PageHero
        eyebrow="Services"
        title="Engineering across the project lifecycle."
        sub="From early-stage research through long-term performance monitoring — covered by a single multi-disciplinary team."
        tone="industrial"
      />
      <Section>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 28 }} className="enq-2col">
          {CAPABILITIES.map((c) => (
            <ServiceCard key={c.id} cap={c} onNav={onNav} />
          ))}
        </div>
      </Section>
      <Difference onNav={onNav} />
      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Capability detail ──────────────────────────────────────────────────────
function CapabilityDetail({ id, onNav }) {
  const cap = CAPABILITIES.find((c) => c.id === id);
  if (!cap) return <NotFound onNav={onNav} />;
  const others = CAPABILITIES.filter((c) => c.id !== id);
  return (
    <>
      <PageHero
        eyebrow={cap.tag}
        title={cap.headline}
        sub={cap.blurb}
        tone={cap.tone}
      />

      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.4fr) minmax(0, 1fr)',
          gap: 48, alignItems: 'start',
        }} className="enq-2col">
          <Eyebrow>What we deliver</Eyebrow>
          <div>
            <Headline size="lg" as="h2" style={{ maxWidth: '14ch' }}>
              {cap.label}.
            </Headline>
            <p style={{ marginTop: 22, fontSize: 17, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '52ch' }}>
              {cap.blurb}
            </p>
          </div>
        </div>
        <div style={{
          marginTop: 56,
          display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))', gap: 0,
          border: '1px solid var(--hair)',
        }}>
          {cap.services.map(([label, detail], i) => (
            <div key={label} style={{
              padding: '28px 28px 32px',
              borderRight: '1px solid var(--hair)',
              borderBottom: '1px solid var(--hair)',
              background: 'var(--bg)',
              transition: 'background .2s',
            }}
            onMouseEnter={(e) => { e.currentTarget.style.background = 'var(--bg2)'; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = 'var(--bg)'; }}
            >
              <span style={{
                fontFamily: '"Source Sans 3", sans-serif', fontSize: 13, fontWeight: 700,
                letterSpacing: '0.1em', color: 'var(--accent)',
              }}>{String(i + 1).padStart(2, '0')}</span>
              <Headline size="sm" as="h3" style={{ marginTop: 14, maxWidth: '16ch' }}>{label}</Headline>
              <p style={{ margin: '12px 0 0', fontSize: 14, lineHeight: 1.6, color: 'var(--fg2)' }}>{detail}</p>
            </div>
          ))}
        </div>
      </Section>

      <section style={{ background: 'var(--bg2)' }}>
        <Section>
          <div style={{ marginBottom: 48 }}>
            <Eyebrow>Continue exploring</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20 }}>Other services</Headline>
          </div>
          <div style={{
            display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 24,
          }} className="enq-3col">
            {others.map((c) => (
              <ServiceCard key={c.id} cap={c} onNav={onNav} />
            ))}
          </div>
        </Section>
      </section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Markets index ──────────────────────────────────────────────────────────
function MarketsPage({ onNav }) {
  return (
    <>
      <PageHero
        eyebrow="Markets"
        title="Where we work."
        sub="Our engineering and project delivery concentrates in the mining, minerals and industrial sectors — and the energy and infrastructure assets that support them."
        tone="earth"
      />
      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(6, minmax(0, 1fr))', gap: 16,
        }} className="enq-markets-grid">
          {MARKETS.map((m, i) => {
            const spans = [3, 3, 2, 2, 2];
            return <MarketTile key={m.id} market={m} span={spans[i] || 2} onNav={onNav} />;
          })}
        </div>
      </Section>
      <FeaturedWork onNav={onNav} />
      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Projects ───────────────────────────────────────────────────────────────
function WorkPage({ onNav }) {
  const [filter, setFilter] = useState_p('all');
  const FILTERS = [
    { id: 'all', label: 'All' },
    { id: 'Mechanical', label: 'Mechanical' },
    { id: 'Process', label: 'Process' },
    { id: 'MV Electrical', label: 'Electrical' },
    { id: 'R&D', label: 'R&D' },
    { id: 'EPCM', label: 'EPCM' },
  ];
  const visible = filter === 'all'
    ? PROJECTS
    : PROJECTS.filter((p) => p.discipline.some((d) => d === filter));

  return (
    <>
      <PageHero
        eyebrow="Projects"
        title="Selected work from across the resource sector."
        sub="From front-end studies to commissioned plants. A representative sample of recent projects across mining, minerals processing and industrial assets."
        tone="industrial"
      />

      <section style={{ borderBottom: '1px solid var(--hair)', background: 'var(--bg)' }}>
        <div style={{
          maxWidth: 1320, margin: '0 auto', padding: '22px 32px',
          display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap',
        }}>
          <span style={{ fontSize: 14, color: 'var(--mid)', fontWeight: 500, marginRight: 12 }}>Filter by discipline</span>
          {FILTERS.map((f) => (
            <button key={f.id} onClick={() => setFilter(f.id)} style={{
              appearance: 'none',
              border: `1px solid ${filter === f.id ? 'var(--fg)' : 'var(--hair)'}`,
              background: filter === f.id ? 'var(--fg)' : 'transparent',
              color: filter === f.id ? 'var(--bg)' : 'var(--fg)',
              padding: '8px 16px', cursor: 'pointer',
              fontFamily: '"Source Sans 3", sans-serif', fontSize: 14, fontWeight: 500,
              transition: 'all .2s',
            }}>{f.label}</button>
          ))}
        </div>
      </section>

      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 32,
        }} className="enq-projects-grid">
          {visible.map((p) => <ProjectCard key={p.id} project={p} onNav={onNav} />)}
        </div>
      </Section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Insights index ─────────────────────────────────────────────────────────
function InsightsPage({ onNav }) {
  const { items } = useInsights();
  const feat = items.find((i) => i.featured) || items[0] || null;
  return (
    <>
      <PageHero
        eyebrow="Insights"
        title="What we are working on, writing about and learning."
        sub="Engineering perspectives, project case studies and updates from our work across the mining and industrial sectors."
        tone="studio"
      />

      <Section>
        {/* Featured */}
        {feat && (
          <article style={{
            display: 'grid', gridTemplateColumns: 'minmax(0, 1.1fr) minmax(0, 1fr)',
            gap: 48, alignItems: 'center', marginBottom: 72,
          }} className="enq-2col">
            <Photo aspect="4/3" tone={feat.tone} src={feat.image} caption={(feat.title || '').slice(0, 30)} />
            <div>
              <span style={{
                fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
                letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)',
              }}>Featured · {feat.kind}</span>
              <Headline size="lg" as="h2" style={{ marginTop: 18 }}>
                {feat.title}
              </Headline>
              <p style={{ marginTop: 18, fontSize: 16, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '52ch' }}>
                {feat.featuredBlurb || feat.blurb}
              </p>
              {feat.href && (
                <div style={{ marginTop: 26 }}>
                  <ReadMore onClick={() => window.open(feat.href, '_blank', 'noopener')}>Read the full article</ReadMore>
                </div>
              )}
            </div>
          </article>
        )}

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 28,
        }} className="enq-3col">
          {items.map((it) => (
            <InsightCard key={it.id} it={it} onNav={onNav} />
          ))}
        </div>
      </Section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── Contact ────────────────────────────────────────────────────────────────
function ContactPage({ onNav }) {
  const [form, setForm] = useState_p({ name: '', org: '', email: '', stage: 'Design', message: '' });
  const [sent, setSent] = useState_p(false);
  const submit = async (e) => {
    e.preventDefault();
    setSent(true);
    await sendEnginuityForm({
      subject: `Project enquiry — ${form.name || 'Website'}`,
      fields: {
        Name: form.name,
        Organisation: form.org,
        Email: form.email,
        'Project stage': form.stage,
        Brief: form.message,
      },
    });
  };

  return (
    <>
      <PageHero
        eyebrow="Contact"
        title="Tell us about your project."
        sub="Send a brief — even a rough sketch — and we will come back with how we would approach it, who would lead it, and what a first phase might look like."
        tone="industrial"
      />

      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.7fr) minmax(0, 1fr)',
          gap: 56, alignItems: 'start',
        }} className="enq-2col">
          {/* Direct contact column */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 32 }}>
            <div>
              <Eyebrow>Get in touch</Eyebrow>
              <Headline size="md" as="h2" style={{ marginTop: 16 }}>Speak with an engineer.</Headline>
              <p style={{ marginTop: 14, fontSize: 15, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '40ch' }}>
                Expect a response from an engineer — not a sales rep — within two business days.
              </p>
            </div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
              {[
                ['Email',    'karla.naude@engn.co.za'],
                ['Phone',    '+27 (12) 030 3843'],
                ['LinkedIn', '@engnza'],
              ].map(([k, v]) => (
                <div key={k} style={{
                  padding: '18px 0', borderBottom: '1px solid var(--hair)',
                  display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
                }}>
                  <span style={{ fontSize: 14, color: 'var(--mid)', fontWeight: 500 }}>{k}</span>
                  <span style={{ fontSize: 16, color: 'var(--fg)', fontWeight: 500 }}>{v}</span>
                </div>
              ))}
            </div>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
              {[
                { tag: 'ZA · South Africa', city: 'Centurion', addr: ['Limeroc Business Park', 'Unit 27, Magner Street', 'Knoppieslaagte 385-JR'] },
                { tag: 'CH · Switzerland', city: 'St Gallen', addr: ['Lerchenfeldstrasse 3', '9014 St Gallen', 'Switzerland'] },
              ].map((o) => (
                <div key={o.tag} style={{
                  padding: '22px 22px', background: 'var(--bg2)', border: '1px solid var(--hair)',
                }}>
                  <span style={{
                    fontFamily: '"Source Sans 3", sans-serif', fontSize: 11, fontWeight: 700,
                    letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)',
                  }}>{o.tag}</span>
                  <Headline size="sm" as="h3" style={{ marginTop: 8 }}>{o.city}</Headline>
                  <ul style={{ listStyle: 'none', padding: 0, margin: '12px 0 0', display: 'flex', flexDirection: 'column', gap: 4 }}>
                    {o.addr.map((line, j) => (
                      <li key={j} style={{ fontSize: 14, color: 'var(--fg2)', lineHeight: 1.5 }}>{line}</li>
                    ))}
                  </ul>
                </div>
              ))}
            </div>
          </div>

          {/* Form column */}
          {!sent ? (
            <form onSubmit={submit} style={{
              background: 'var(--bg2)', border: '1px solid var(--hair)',
              padding: '40px 40px 44px',
            }}>
              <Eyebrow>Send a brief</Eyebrow>
              <Headline size="md" as="h2" style={{ marginTop: 14, marginBottom: 28 }}>Tell us what you're building.</Headline>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 18 }}>
                <Field label="Your name" value={form.name} onChange={(v) => setForm((f) => ({ ...f, name: v }))} />
                <Field label="Organisation" value={form.org} onChange={(v) => setForm((f) => ({ ...f, org: v }))} />
              </div>
              <div style={{ marginTop: 18 }}>
                <Field label="Email" value={form.email} onChange={(v) => setForm((f) => ({ ...f, email: v }))} type="email" />
              </div>
              <div style={{ marginTop: 22 }}>
                <span style={{ fontSize: 13, color: 'var(--mid)', fontWeight: 600 }}>Project stage</span>
                <div style={{ marginTop: 10, display: 'flex', flexWrap: 'wrap', gap: 8 }}>
                  {['Ideation', 'Design', 'Execution', 'Monitoring'].map((s) => (
                    <button key={s} type="button" onClick={() => setForm((f) => ({ ...f, stage: s }))} style={{
                      appearance: 'none', border: `1px solid ${form.stage === s ? 'var(--fg)' : 'var(--hair-s)'}`,
                      background: form.stage === s ? 'var(--fg)' : 'transparent',
                      color: form.stage === s ? 'var(--bg)' : 'var(--fg)',
                      padding: '9px 16px', cursor: 'pointer',
                      fontFamily: '"Source Sans 3", sans-serif', fontSize: 14, fontWeight: 500,
                      transition: 'all .2s',
                    }}>{s}</button>
                  ))}
                </div>
              </div>
              <div style={{ marginTop: 22 }}>
                <Field label="Brief" value={form.message} onChange={(v) => setForm((f) => ({ ...f, message: v }))} multiline />
              </div>
              <div style={{ marginTop: 32, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, flexWrap: 'wrap' }}>
                <span style={{ fontSize: 13, color: 'var(--mid)' }}>Response within 2 business days</span>
                <Button onClick={submit} variant="solid" size="lg">Submit brief</Button>
              </div>
            </form>
          ) : (
            <div style={{
              background: 'var(--bg2)', border: '1px solid var(--accent)',
              padding: '56px 40px',
            }}>
              <Eyebrow>Brief received</Eyebrow>
              <Headline size="md" as="h2" style={{ marginTop: 16 }}>
                Thanks{form.name ? `, ${form.name.split(' ')[0]}` : ''}. We will be in touch.
              </Headline>
              <p style={{ marginTop: 16, fontSize: 16, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '44ch' }}>
                Your brief has been received. Expect a response from an engineer within two business days.
              </p>
              <div style={{ marginTop: 28 }}>
                <Button onClick={() => setSent(false)} variant="outline">Send another</Button>
              </div>
            </div>
          )}
        </div>
      </Section>
    </>
  );
}

function Field({ label, value, onChange, type = 'text', multiline = false }) {
  const [focus, setFocus] = useState_p(false);
  const Tag = multiline ? 'textarea' : 'input';
  return (
    <label style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
      <span style={{ fontSize: 13, color: 'var(--mid)', fontWeight: 600 }}>{label}</span>
      <Tag
        type={type}
        value={value}
        onChange={(e) => onChange(e.target.value)}
        onFocus={() => setFocus(true)}
        onBlur={() => setFocus(false)}
        rows={multiline ? 5 : undefined}
        style={{
          appearance: 'none',
          border: `1px solid ${focus ? 'var(--accent)' : 'var(--hair-s)'}`,
          background: 'var(--bg)', color: 'var(--fg)',
          fontFamily: '"Source Sans 3", sans-serif',
          fontSize: 15, padding: '12px 14px',
          outline: 'none',
          resize: multiline ? 'vertical' : 'none',
          transition: 'border-color .2s',
        }}
      />
    </label>
  );
}

// ── Services landing — choose EPCM or R&D ───────────────────────────────────
function ServicesLanding({ onNav, tweaks }) {
  const style = (tweaks && tweaks.servicesLanding) || 'split';
  const choices = [
    {
      id: 'epcm', target: 'capabilities/epcm', tone: 'industrial',
      eyebrow: 'Delivery', title: 'EPCM',
      line: 'Engineering, procurement and construction management — every discipline under one accountable team.',
      meta: 'Mechanical · Electrical · Process · Civil · Mining · Bulk', img: 'assets/epcm-hero.jpeg',
    },
    {
      id: 'rd', target: 'capabilities/rd', tone: 'studio',
      eyebrow: 'Innovation', title: 'R&D',
      line: 'Frontier research — high-power microwave, lunar surface construction, space-environment testing and circular-process systems.',
      meta: 'Microwave · Space · Recycling', img: 'assets/rd-hero.jpeg',
    },
  ];

  if (style === 'split') {
    return (
      <>
        <SplitChoice choices={choices} onNav={onNav} />
        <ContactCTA onNav={onNav} />
      </>
    );
  }

  // 'cards' and 'editorial' share the PageHero then differ below
  return (
    <>
      <PageHero
        eyebrow="Services"
        title="Two ways we work."
        sub="A single multi-disciplinary team that both delivers EPCM projects and runs the research programme behind them. Choose a path."
        tone="industrial"
      />
      <Section>
        {style === 'editorial' ? (
          <div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
            {choices.map((c, i) => <EditorialChoice key={c.id} c={c} n={i + 1} onNav={onNav} />)}
          </div>
        ) : (
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 28 }} className="enq-2col">
            {choices.map((c) => <ChoiceCard key={c.id} c={c} onNav={onNav} />)}
          </div>
        )}
      </Section>
      <ContactCTA onNav={onNav} />
    </>
  );
}

function SplitChoice({ choices, onNav }) {
  const [hover, setHover] = useState_p(null);
  return (
    <section className="enq-split-choice" style={{
      display: 'flex', minHeight: 'min(86vh, 820px)', background: '#0f1114',
    }}>
      {choices.map((c) => {
        const active = hover === c.id;
        const dim = hover && hover !== c.id;
        return (
          <button key={c.id} onClick={() => onNav(c.target)}
            onMouseEnter={() => setHover(c.id)} onMouseLeave={() => setHover(null)}
            style={{
              position: 'relative', flex: active ? 1.25 : (dim ? 0.85 : 1),
              border: 0, padding: 0, cursor: 'pointer', overflow: 'hidden',
              color: '#fff', textAlign: 'left', transition: 'flex .55s cubic-bezier(.4,0,.2,1)',
              fontFamily: 'inherit', minWidth: 0,
            }}>
            <div style={{ position: 'absolute', inset: 0, transform: active ? 'scale(1.05)' : 'scale(1)', transition: 'transform .8s ease' }}>
              <Photo aspect="auto" tone={c.tone} src={c.img} caption={`${c.title} — Enginuity`} style={{ height: '100%' }} />
            </div>
            <div style={{
              position: 'absolute', inset: 0,
              background: `linear-gradient(to top, rgba(15,17,20,0.92) 0%, rgba(15,17,20,0.55) 45%, rgba(15,17,20,0.35) 100%)`,
              transition: 'opacity .5s', opacity: dim ? 0.85 : 1,
            }} />
            <div style={{
              position: 'relative', height: '100%', display: 'flex', flexDirection: 'column',
              justifyContent: 'flex-end', padding: 'clamp(32px, 5vw, 72px)', gap: 18, maxWidth: 620,
            }}>
              <Eyebrow color="#fff" style={{ opacity: 0.9 }}>{c.eyebrow}</Eyebrow>
              <div style={{
                fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)', letterSpacing: 'var(--display-track)',
                fontSize: 'clamp(56px, 8vw, 116px)', lineHeight: 0.95,
              }}>{c.title}</div>
              <p style={{ margin: 0, fontSize: 'clamp(16px, 1.3vw, 20px)', lineHeight: 1.5, color: 'rgba(255,255,255,0.88)', maxWidth: '40ch' }}>{c.line}</p>
              <div style={{
                fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
                letterSpacing: '0.12em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.6)',
                maxHeight: active ? 40 : 40, transition: 'opacity .4s', opacity: 1,
              }}>{c.meta}</div>
              <span style={{
                display: 'inline-flex', alignItems: 'center', gap: 10, marginTop: 6,
                fontSize: 15, fontWeight: 600, color: '#fff',
                transform: active ? 'translateX(6px)' : 'translateX(0)', transition: 'transform .4s',
              }}>Explore <span style={{ fontSize: 18 }}>→</span></span>
            </div>
          </button>
        );
      })}
    </section>
  );
}

function ChoiceCard({ c, onNav }) {
  const [h, setH] = useState_p(false);
  return (
    <article onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)}
      onClick={() => onNav(c.target)}
      style={{
        background: 'var(--bg)', cursor: 'pointer', border: '1px solid var(--hair)',
        transition: 'box-shadow .25s, transform .25s', display: 'flex', flexDirection: 'column',
        boxShadow: h ? '0 12px 32px rgba(0,0,0,0.08)' : '0 1px 0 rgba(0,0,0,0.02)',
        transform: h ? 'translateY(-2px)' : 'translateY(0)',
      }}>
      <div style={{ position: 'relative', overflow: 'hidden' }}>
        <div style={{ transform: h ? 'scale(1.03)' : 'scale(1)', transition: 'transform .8s ease' }}>
          <Photo aspect="16/9" tone={c.tone} src={c.img} caption={`${c.title} — Enginuity`} />
        </div>
        <div style={{
          position: 'absolute', left: 28, bottom: 22,
          fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)', letterSpacing: 'var(--display-track)',
          fontSize: 'clamp(40px, 5vw, 64px)', lineHeight: 1, color: '#fff',
          textShadow: '0 2px 24px rgba(0,0,0,0.5)',
        }}>{c.title}</div>
      </div>
      <div style={{ padding: '28px 32px 34px', display: 'flex', flexDirection: 'column', gap: 16 }}>
        <Eyebrow>{c.eyebrow}</Eyebrow>
        <p style={{ margin: 0, fontSize: 16, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '46ch' }}>{c.line}</p>
        <span style={{ fontSize: 13, fontWeight: 600, letterSpacing: '0.04em', color: 'var(--mid)' }}>{c.meta}</span>
        <div style={{ marginTop: 4 }}>
          <ReadMore color="var(--fg)" onClick={(e) => { e?.stopPropagation && e.stopPropagation(); onNav(c.target); }}>Explore {c.title}</ReadMore>
        </div>
      </div>
    </article>
  );
}

function EditorialChoice({ c, n, onNav }) {
  return (
    <div onClick={() => onNav(c.target)} style={{
      display: 'grid', gridTemplateColumns: 'auto minmax(0, 1fr) auto', gap: 'clamp(24px, 4vw, 64px)',
      alignItems: 'center', padding: '40px 0', borderTop: '1px solid var(--hair)', cursor: 'pointer',
    }} className="enq-edch">
      <div style={{
        fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)', letterSpacing: 'var(--display-track)',
        fontSize: 'clamp(40px, 5vw, 72px)', lineHeight: 1, color: 'var(--accent)',
      }}>{c.title}</div>
      <div>
        <Eyebrow>{c.eyebrow}</Eyebrow>
        <p style={{ margin: '12px 0 0', fontSize: 'clamp(16px, 1.4vw, 20px)', lineHeight: 1.5, color: 'var(--fg2)', maxWidth: '60ch' }}>{c.line}</p>
        <span style={{ display: 'block', marginTop: 10, fontSize: 13, fontWeight: 600, letterSpacing: '0.04em', color: 'var(--mid)' }}>{c.meta}</span>
      </div>
      <span style={{ fontSize: 28, color: 'var(--fg)' }}>→</span>
    </div>
  );
}

// ── EPCM page — all disciplines, one team ───────────────────────────────────
function EPCMPage({ onNav }) {
  return (
    <>
      <PageHero
        eyebrow="EPCM"
        title="Every discipline. One accountable team."
        sub="Engineering, procurement and construction management for the resource sector — delivered by mechanical, electrical, process, civil, mining and materials-handling engineers working from the same project room."
        tone="industrial"
        img="assets/epcm-hero.jpeg"
      />

      {/* Intro — how the disciplines combine */}
      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.9fr) minmax(0, 1fr)',
          gap: 'clamp(32px, 5vw, 72px)', alignItems: 'start',
        }} className="enq-2col">
          <div>
            <Eyebrow>The EPCM difference</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '15ch' }}>
              Good EPCM is disciplines that don't hand off.
            </Headline>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
            <p style={{ margin: 0, fontSize: 17, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '60ch' }}>
              A plant is not a stack of separate engineering packages — it is one system where the
              process flowsheet sets the mechanical duty, the mechanical layout sets the civil loads,
              and the electrical reticulation has to reach all of it. When those disciplines are split
              across firms, the gaps between them become the project's risk.
            </p>
            <p style={{ margin: 0, fontSize: 17, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '60ch' }}>
              We hold all of them in-house. Mechanical, electrical, process, civil, mining and bulk
              materials-handling engineers sit together — co-location, not coordination meetings — and
              the same team carries the project through procurement, construction management and
              commissioning. We validate in software before steel is ordered, and stay on site through
              ramp-up.
            </p>
          </div>
        </div>

        <div style={{
          marginTop: 56, display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 1,
          background: 'var(--hair)', border: '1px solid var(--hair)',
        }} className="enq-3col">
          {[
            ['One team', 'A single accountable team from study through handover — no interfaces lost between vendors.'],
            ['Simulation-first', 'ANSYS, SolidWorks, Nastran, Aspen and ETAP. Every discipline validated digitally before procurement.'],
            ['On the ground', 'The engineers who design the plant stay through construction and commissioning.'],
          ].map(([t, d]) => (
            <div key={t} style={{ background: 'var(--bg)', padding: '26px 26px 30px' }}>
              <Headline size="sm" as="h3">{t}</Headline>
              <p style={{ margin: '10px 0 0', fontSize: 14, lineHeight: 1.6, color: 'var(--fg2)' }}>{d}</p>
            </div>
          ))}
        </div>
      </Section>

      {/* LiDAR workflow */}
      <LiDARFlow />

      {/* Disciplines flow */}
      <section style={{ background: 'var(--bg2)' }}>
        <Section>
          <div style={{ marginBottom: 8 }}>
            <Eyebrow>Disciplines</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '18ch' }}>
              What each discipline delivers.
            </Headline>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column' }}>
            {EPCM_DISCIPLINES.map((d, i) => (
              <DisciplineBlock key={d.id} d={d} n={i + 1} />
            ))}
          </div>
        </Section>
      </section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

// ── LiDAR → 3D workflow ─────────────────────────────────────────────────────
// A reality-capture pipeline: scan the live site, register the point cloud,
// rebuild the plant in 3D, then engineer directly on the as-built model.
const LIDAR_STEPS = [
  {
    tag: 'Capture',
    tool: 'Terrestrial + drone',
    title: 'Scan the live site',
    body: 'We survey the working asset — mines, plants and processing facilities — with both tripod-mounted (terrestrial) and drone-borne LiDAR, capturing millions of points to millimetre accuracy.',
    tone: 'industrial',
    img: 'assets/lidar-capture.jpeg',
    caption: 'Drone LiDAR survey over plant',
  },
  {
    tag: 'Register',
    tool: 'Autodesk ReCap Pro',
    title: 'Build the point cloud',
    body: 'Individual scans are imported into Autodesk ReCap Pro and registered into a single, measurable point cloud — cleaned, aligned and ready for analysis.',
    tone: 'studio',
    img: 'assets/lidar-register.png',
    caption: 'Registered point cloud in ReCap',
  },
  {
    tag: 'Model',
    tool: 'AutoCAD Plant 3D',
    title: 'Replicate in 3D',
    body: 'The point cloud is rebuilt as a true-to-life model in Plant 3D (or equivalent) — every pipe, structure and equipment item recreated as intelligent, as-built geometry.',
    tone: 'sky',
    img: 'assets/lidar-model.png',
    caption: 'As-built model over point cloud',
  },
  {
    tag: 'Engineer',
    tool: 'Autodesk Inventor',
    title: 'Design against reality',
    body: 'Our engineers design directly on the as-built 3D model. Brownfield tie-ins, modifications and new works fit first time — because they are built against the real plant, not assumptions.',
    tone: 'earth',
    img: 'assets/lidar-engineer.jpg',
    caption: 'Engineering design on 3D model',
  },
];

function LiDARFlow() {
  return (
    <Section style={{ paddingTop: 0 }}>
      <div style={{ maxWidth: '64ch' }}>
        <Eyebrow>Reality capture</Eyebrow>
        <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '20ch' }}>
          From live site to a 3D model you can engineer on.
        </Headline>
        <p style={{ margin: '20px 0 0', fontSize: 17, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '60ch' }}>
          For brownfield work we don't guess at the as-built condition — we measure it. LiDAR scanning
          turns a working plant into a dimensionally-accurate 3D model, so design happens against reality
          from the first line.
        </p>
      </div>

      <div className="enq-lidar-flow" style={{
        marginTop: 56, display: 'grid',
        gridTemplateColumns: 'repeat(4, minmax(0, 1fr))',
        gap: 'clamp(28px, 3.4vw, 52px)',
      }}>
        {LIDAR_STEPS.map((s, i) => (
          <div key={s.tag} className="enq-lidar-step" style={{
            minWidth: 0, display: 'flex', flexDirection: 'column',
          }}>
            <div style={{ position: 'relative' }}>
              <Photo aspect="4/3" tone={s.tone} src={s.img} caption={s.caption} />
              {i < LIDAR_STEPS.length - 1 && (
                <span className="enq-lidar-arrow" aria-hidden style={{
                  position: 'absolute', top: '50%', left: '100%',
                  transform: 'translate(-50%, -50%)',
                  fontSize: 22, lineHeight: 1, color: 'var(--accent)',
                  fontFamily: '"Source Sans 3", sans-serif',
                }}>→</span>
              )}
            </div>
            <div style={{ padding: '20px 0 0', display: 'flex', flexDirection: 'column', flex: '1 1 auto' }}>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12 }}>
                <span style={{
                  fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)',
                  letterSpacing: 'var(--display-track)',
                  fontSize: 28, lineHeight: 1, color: 'var(--accent)',
                }}>{String(i + 1).padStart(2, '0')}</span>
                <span style={{
                  fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
                  letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--mid)',
                }}>{s.tag}</span>
              </div>
              <Headline size="sm" as="h3" style={{ marginTop: 14 }}>{s.title}</Headline>
              <div style={{
                marginTop: 10, alignSelf: 'flex-start', whiteSpace: 'nowrap',
                fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 600,
                letterSpacing: '0.02em', color: 'var(--fg)',
                padding: '4px 10px', border: '1px solid var(--hair-s)',
              }}>{s.tool}</div>
              <p style={{ margin: '14px 0 0', fontSize: 14.5, lineHeight: 1.6, color: 'var(--fg2)' }}>{s.body}</p>
            </div>
          </div>
        ))}
      </div>
    </Section>
  );
}

function DisciplineBlock({ d, n }) {
  return (
    <div style={{
      display: 'grid', gridTemplateColumns: 'minmax(0, 0.5fr) minmax(0, 1fr)',
      gap: 'clamp(24px, 4vw, 64px)', padding: '48px 0', borderTop: '1px solid var(--hair)',
      alignItems: 'start',
    }} className="enq-disc-block">
      <div>
        <div style={{
          display: 'flex', alignItems: 'baseline', gap: 14,
        }}>
          <span style={{
            fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)', letterSpacing: 'var(--display-track)',
            fontSize: 'clamp(34px, 4vw, 52px)', lineHeight: 1, color: 'var(--accent)',
          }}>{String(n).padStart(2, '0')}</span>
          <span style={{
            fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
            letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--mid)',
          }}>{d.tag}</span>
        </div>
        <Headline size="md" as="h3" style={{ marginTop: 16, maxWidth: '14ch' }}>{d.label}</Headline>
        <p style={{ margin: '14px 0 0', fontSize: 15, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '42ch' }}>{d.blurb}</p>
      </div>
      <ul style={{
        listStyle: 'none', padding: 0, margin: 0,
        display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: '0 32px',
      }} className="enq-disc-list">
        {d.services.map((s, i) => (
          <li key={i} style={{
            display: 'flex', gap: 12, alignItems: 'flex-start',
            padding: '13px 0', borderBottom: '1px solid var(--hair)',
            fontSize: 15, lineHeight: 1.45, color: 'var(--fg)',
          }}>
            <span style={{
              flex: '0 0 auto', width: 6, height: 6, marginTop: 7, borderRadius: '50%',
              background: 'var(--accent)',
            }} />
            <span>{s}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}

// ── R&D page ────────────────────────────────────────────────────────────────
function RDPage({ onNav }) {
  return (
    <>
      <PageHero
        eyebrow="R&amp;D"
        title="Research at the frontier of energy and materials."
        sub="A dedicated research programme — led from our St Gallen centre — in high-power microwave technology, in-situ construction for the lunar surface, space-environment testing and circular-process systems."
        tone="studio"
        img="assets/rd-hero.jpeg"
      />

      <Section>
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.9fr) minmax(0, 1fr)',
          gap: 'clamp(32px, 5vw, 72px)', alignItems: 'start',
        }} className="enq-2col">
          <div>
            <Eyebrow>Why we research</Eyebrow>
            <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '16ch' }}>
              The same physics, pushed further.
            </Headline>
          </div>
          <p style={{ margin: 0, fontSize: 17, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '60ch' }}>
            Our R&amp;D is not separate from our engineering — it is the same volumetric-microwave,
            process and simulation capability, applied to problems no one has solved yet. What we
            prove in the lab feeds directly into the plants we deliver, and the discipline of building
            high-power, safety-critical hardware for mining carries straight into our space work.
          </p>
        </div>
      </Section>

      <section style={{ background: 'var(--bg2)' }}>
        <Section>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
            {RD_AREAS.map((a, i) => (
              <RDBlock key={a.id} a={a} n={i + 1} flip={i % 2 === 1} />
            ))}
          </div>
        </Section>
      </section>

      <ContactCTA onNav={onNav} />
    </>
  );
}

function RDBlock({ a, n, flip }) {
  const media = (
    <div style={{ minWidth: 0 }}>
      <Photo aspect="4/3" tone={a.tone} src={a.img} caption={`${a.label} — Enginuity R&D`} />
    </div>
  );
  const body = (
    <div style={{ minWidth: 0 }}>
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 14 }}>
        <span style={{
          fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)', letterSpacing: 'var(--display-track)',
          fontSize: 'clamp(30px, 3.4vw, 44px)', lineHeight: 1, color: 'var(--accent)',
        }}>{String(n).padStart(2, '0')}</span>
        <span style={{
          fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
          letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--mid)',
        }}>{a.tag}</span>
      </div>
      <Headline size="md" as="h3" style={{ marginTop: 14, maxWidth: '16ch' }}>{a.label}</Headline>
      <p style={{ margin: '16px 0 0', fontSize: 16, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '52ch' }}>{a.summary}</p>
      <p style={{ margin: '14px 0 0', fontSize: 15, lineHeight: 1.65, color: 'var(--fg2)', maxWidth: '52ch' }}>{a.detail}</p>
      <div style={{
        marginTop: 24, display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 1,
        background: 'var(--hair)', border: '1px solid var(--hair)',
      }}>
        {a.points.map(([k, v], i) => (
          <div key={i} style={{ background: 'var(--bg)', padding: '16px 18px' }}>
            <div style={{ fontFamily: '"Source Sans 3", sans-serif', fontSize: 15, fontWeight: 700, color: 'var(--fg)' }}>{k}</div>
            <div style={{ marginTop: 5, fontSize: 13, lineHeight: 1.5, color: 'var(--fg2)' }}>{v}</div>
          </div>
        ))}
      </div>
    </div>
  );
  return (
    <div style={{
      display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
      gap: 'clamp(28px, 4vw, 64px)', alignItems: 'center',
      padding: '52px 0', borderTop: n === 1 ? 'none' : '1px solid var(--hair)',
    }} className="enq-rd-block">
      {flip ? <>{body}{media}</> : <>{media}{body}</>}
    </div>
  );
}

// ── 404 ────────────────────────────────────────────────────────────────────
function NotFound({ onNav }) {
  return (
    <section style={{ paddingTop: 200, paddingBottom: 200, textAlign: 'center' }}>
      <div style={{ maxWidth: 600, margin: '0 auto', padding: '0 32px' }}>
        <Eyebrow style={{ display: 'inline-flex' }}>404</Eyebrow>
        <Headline size="xl" as="h1" style={{ margin: '20px 0' }}>Page not found.</Headline>
        <p style={{ fontSize: 16, color: 'var(--fg2)', margin: '0 0 32px', lineHeight: 1.6 }}>
          We couldn't find that page. Let's get you back to something we built on purpose.
        </p>
        <Button onClick={() => onNav('home')} variant="solid" size="lg">Return home</Button>
      </div>
    </section>
  );
}

Object.assign(window, {
  AboutPage, CapabilitiesIndex, CapabilityDetail, MarketsPage,
  WorkPage, InsightsPage, ContactPage, NotFound, Field,
  ServicesLanding, EPCMPage, RDPage,
  EPCM_DISCIPLINES, RD_AREAS,
});
