// home.jsx — Corporate-engineering homepage for Enginuity
// Hatch / DRA / EPCM aesthetic — full-bleed photo hero, image-led service cards,
// markets grid, difference, projects, insights, contact band.

const { useState: useState_h, useEffect: useEffect_h, useRef: useRef_h } = React;

// ── Data ───────────────────────────────────────────────────────────────────
const CAPABILITIES = [
  {
    id: 'ideation',
    label: 'Ideation',
    tag: 'Concept & R&D',
    headline: 'Turning complex problems into practical engineering.',
    blurb: 'From client challenge to validated concept. We bring deep R&D — including world-class microwave technology research from our St Gallen office — to bear on new processes, products and recovery routes.',
    services: [
      ['New product development', 'From client problem to functional prototype. FMEA, design-of-experiments, patentable concepts.'],
      ['Recycling & circular process', 'Material recovery flow-sheets. Beneficiation of secondary streams. Lab through pilot scale.'],
      ['Microwave technology',  'High-frequency heating for ore pre-treatment, drying and breakage reduction. Multiphysics simulation.'],
    ],
    tone: 'studio',
  },
  {
    id: 'design',
    label: 'Design',
    tag: 'Engineering',
    headline: 'Technically sound, best-practice engineering across disciplines.',
    blurb: 'Mechanical, MV electrical, civil, process and mining engineers working from the same project room. ANSYS FEA and CFD, Aspen, ETAP — we validate in software before steel is ordered.',
    services: [
      ['Mechanical engineering',       'Structural, rotating and materials handling. FEA, CFD, fatigue and vibration analysis.'],
      ['MV electrical engineering',    'Medium-voltage reticulation, protection coordination, MCCs, SCADA integration.'],
      ['Civil engineering',            'Earthworks, foundations, stormwater. RC and steel structures.'],
      ['Process & plant design',       'Mass and energy balances. PFDs, P&IDs, 3D plant models. Hazop-ready packages.'],
      ['Mining engineering',           'Mine planning, ventilation, hoist and material handling, geotechnical interface.'],
    ],
    tone: 'industrial',
  },
  {
    id: 'execution',
    label: 'Execution',
    tag: 'EPCM & Construction',
    headline: 'Project delivery with a single accountable team.',
    blurb: 'The engineers who design the plant stay on the project through procurement, construction and commissioning. NEC4, FIDIC and PMBOK frameworks. Cost, schedule and contract administration.',
    services: [
      ['EPCM',                          'Engineering, procurement and construction management — definition through handover.'],
      ['Project & programme management','NEC4, FIDIC and PMBOK frameworks. Cost, schedule and risk management.'],
      ['Construction supervision',      'Resident engineering, QA/QC, vendor inspection and commissioning support.'],
    ],
    tone: 'earth',
  },
  {
    id: 'monitoring',
    label: 'Monitoring',
    tag: 'Operations & Lifecycle',
    headline: 'Performance, risk and opportunity — after handover.',
    blurb: 'We instrument what we build and stay involved long after commissioning. Condition monitoring, predictive analytics and lifecycle integration feed the next design and protect the operating asset.',
    services: [
      ['Civil & structural',     'Settlement, strain and crack monitoring. Tailings dam integrity.'],
      ['Mechanical performance', 'Vibration, alignment, lubrication. Bearing and gearbox condition trending.'],
      ['Electrical & control',   'Power quality, thermography, partial-discharge surveys.'],
      ['Predictive & analytical','Failure-mode modelling, RCM frameworks, ML anomaly detection.'],
      ['Lifecycle integration',  'Asset management plans, ISO-55000 alignment, OPEX optimisation.'],
    ],
    tone: 'plant',
  },
];

const MARKETS = [
  { id: 'mining',     label: 'Mining',              blurb: 'Hard-rock, surface and underground operations across PGMs, base metals, gold, diamond and coal.', tone: 'earth' },
  { id: 'minerals',   label: 'Minerals & Metals',   blurb: 'Concentrators, smelters, refineries and recovery plants. Brownfield expansion and de-bottlenecking.', tone: 'industrial' },
  { id: 'energy',     label: 'Energy & Power',      blurb: 'Industrial power infrastructure, MV reticulation and energy-efficiency projects.', tone: 'sky' },
  { id: 'industrial', label: 'Industrial Plant',    blurb: 'Chemicals, water treatment and bulk materials handling. Project-specific process design.', tone: 'studio' },
  { id: 'research',   label: 'Technology & R&D',    blurb: 'Microwave heating, pre-treatment, novel beneficiation. From bench to pilot.', tone: 'plant' },
];

// Each client carries a logo slug. Drop logo files at uploads/logos/<slug>.png
// (or .svg) and they appear automatically; until then a clean wordmark shows.
const CLIENTS = [
  { name: 'Anglo American',         slug: 'anglo-american' },
  { name: 'Black Chrome Mine',      slug: 'bcm' },
  { name: 'Aurex Constructors',     slug: 'aurex' },
  { name: 'General Kinematics',     slug: 'general-kinematics' },
  { name: 'Iritron',                slug: 'iritron' },
  { name: 'R&R Quantity Surveyors', slug: 'rr-quantity-surveyors' },
];

const PROJECTS = [
  {
    id: 'p1',
    sector: 'Platinum · UG2',
    title: 'Concentrator de-bottlenecking',
    location: 'Limpopo, South Africa',
    year: '2024',
    metric: '+18% throughput',
    blurb: 'Hydrocyclone re-engineering and slurry distribution redesign. ANSYS CFD model validated against plant trial. Implemented with zero unplanned downtime.',
    discipline: ['Mechanical', 'Process', 'EPCM'],
    tone: 'industrial',
  },
  {
    id: 'p2',
    sector: 'Diamond · Kimberlite',
    title: 'Microwave pre-treatment pilot',
    location: 'Northern Cape, South Africa',
    year: '2024 — 2025',
    metric: '−22% mill energy',
    blurb: 'Pilot-scale 100 kW continuous microwave applicator for kimberlite pre-conditioning. Multiphysics design, fabrication oversight, performance monitoring.',
    discipline: ['R&D', 'Mechanical', 'Microwave'],
    tone: 'studio',
  },
  {
    id: 'p3',
    sector: 'Base metals · Smelter',
    title: 'MV reticulation upgrade',
    location: 'North West, South Africa',
    year: '2023',
    metric: '11 kV → 22 kV',
    blurb: 'Brownfield medium-voltage upgrade across an active smelter. Protection grading, harmonic study, phased switching plan, commissioning supervision.',
    discipline: ['MV Electrical', 'EPCM'],
    tone: 'industrial',
  },
  {
    id: 'p4',
    sector: 'PGM · Tailings',
    title: 'Re-mining flow-sheet',
    location: 'Rustenburg, South Africa',
    year: '2025',
    metric: '3.4 Mt/a feed',
    blurb: 'Front-end engineering and lab programme for a tailings re-treatment plant. Recovery model, mass balance, capex estimate to AACE Class 3.',
    discipline: ['Process', 'Ideation', 'EPCM'],
    tone: 'earth',
  },
];

const INSIGHTS = [
  {
    id: 'i1', kind: 'Insight',
    title: 'Why microwave pre-treatment is finally ready for mineral processing',
    date: 'March 2026',
    blurb: 'After two decades of academic interest, continuous microwave systems are at last viable at production scale. Here is what changed — and what still needs work.',
    tone: 'studio',
  },
  {
    id: 'i2', kind: 'Case study',
    title: 'How a 7 mm cyclone change added 18% throughput at a UG2 concentrator',
    date: 'February 2026',
    blurb: 'A study in why CFD-led detail matters more than capital. The change cost less than a single replacement pump and outperformed a far larger upgrade.',
    tone: 'industrial',
  },
  {
    id: 'i3', kind: 'News',
    title: 'Enginuity opens a research office in St Gallen, Switzerland',
    date: 'January 2026',
    blurb: 'Our R&D team now operates from both Centurion and St Gallen, deepening our work on microwave heating and circular-process design for the resource sector.',
    tone: 'sky',
  },
];

// ── Hero — full-bleed photo carousel ───────────────────────────────────────
const HERO_SLIDES = [
  {
    eyebrow: 'Enginuity · Technology development & EPCM partner',
    title: 'Engineering and project delivery for the mining and industrial sectors.',
    sub: 'Detailed engineers and on-site builders working as one team — across Africa and Europe.',
    cta: ['Explore our services', 'capabilities'],
    tone: 'industrial',
    img: 'assets/home-hero-mashup.jpg',
    caption: 'Concentrator floor — Limpopo, 2024',
  },
  {
    eyebrow: 'R&D in focus',
    title: 'Microwave pre-treatment, from concept to commissioned pilot.',
    sub: 'World-class research from our St Gallen office, integrated into the projects we deliver.',
    cta: ['See the R&D programme', 'capabilities/ideation'],
    tone: 'studio',
    img: 'assets/campus-stgallen.jpg',
    caption: '100 kW continuous applicator — pilot site, 2025',
  },
  {
    eyebrow: 'Operating across two continents',
    title: 'Two offices, one team — Centurion and St Gallen.',
    sub: 'Engineering, construction management and lifecycle support for the operators who keep industry moving.',
    cta: ['About Enginuity', 'about'],
    tone: 'earth',
    img: 'assets/headframe.jpg',
    caption: 'Site supervision — North West, 2023',
  },
];

function Hero({ layout, onNav }) {
  if (layout === 'split') return <HeroSplit onNav={onNav} />;
  if (layout === 'editorial') return <HeroEditorial onNav={onNav} />;
  return <HeroCarousel onNav={onNav} />;
}

function HeroCarousel({ onNav }) {
  const [i, setI] = useState_h(0);
  useEffect_h(() => {
    const t = setInterval(() => setI((n) => (n + 1) % HERO_SLIDES.length), 7500);
    return () => clearInterval(t);
  }, []);
  return (
    <section style={{
      position: 'relative', height: 'min(78vh, 680px)', minHeight: 560,
      background: '#0f1114', color: '#ffffff', overflow: 'hidden',
    }}>
      {HERO_SLIDES.map((s, idx) => (
        <div key={idx} style={{
          position: 'absolute', inset: 0,
          opacity: idx === i ? 1 : 0,
          transition: 'opacity 1.2s ease',
          pointerEvents: idx === i ? 'auto' : 'none',
        }}>
          <Photo aspect="auto" tone={s.tone} src={s.img} parallax={-25} style={{ height: '100%' }} caption={s.caption} />
          <div style={{
            position: 'absolute', inset: 0,
            background: 'linear-gradient(to right, rgba(15,17,20,0.78) 0%, rgba(15,17,20,0.45) 55%, rgba(15,17,20,0.1) 100%), linear-gradient(to bottom, rgba(15,17,20,0.15) 0%, rgba(15,17,20,0) 40%, rgba(15,17,20,0.7) 100%)',
          }} />
        </div>
      ))}
      <div style={{
        position: 'relative', height: '100%',
        maxWidth: 1320, margin: '0 auto', padding: '0 32px',
        display: 'flex', alignItems: 'flex-end', paddingTop: 132, paddingBottom: 56,
      }}>
        <div style={{ maxWidth: 880, width: '100%' }}>
          <div>
            <Eyebrow color="#ffffff">{HERO_SLIDES[i].eyebrow}</Eyebrow>
            <Headline size="xl" as="h1" style={{
              color: '#ffffff', marginTop: 24, maxWidth: '18ch',
            }}>{HERO_SLIDES[i].title}</Headline>
            <p style={{
              marginTop: 26, fontSize: 'clamp(17px, 1.4vw, 22px)', lineHeight: 1.5,
              color: 'rgba(255,255,255,0.88)', maxWidth: '52ch',
            }}>{HERO_SLIDES[i].sub}</p>
            <div style={{ marginTop: 36, display: 'flex', gap: 14, flexWrap: 'wrap' }}>
              <Button onClick={() => onNav(HERO_SLIDES[i].cta[1])} variant="solid" size="lg">
                {HERO_SLIDES[i].cta[0]}
              </Button>
              <Button onClick={() => onNav('contact')} variant="outline" size="lg"
                      style={{ borderColor: 'rgba(255,255,255,0.4)', color: '#fff', background: 'rgba(255,255,255,0.06)', backdropFilter: 'blur(8px)' }}>
                Get in touch
              </Button>
            </div>
          </div>
        </div>
      </div>
      {/* Slide dots */}
      <div style={{
        position: 'absolute', bottom: 36, right: 32, zIndex: 2,
        display: 'flex', gap: 10, alignItems: 'center',
      }}>
        {HERO_SLIDES.map((_, idx) => (
          <button key={idx} onClick={() => setI(idx)} aria-label={`Slide ${idx + 1}`} style={{
            appearance: 'none', border: 0, background: 'transparent', padding: 0, cursor: 'pointer',
            width: 36, height: 2,
          }}>
            <div style={{
              width: '100%', height: 2,
              background: idx === i ? '#ffffff' : 'rgba(255,255,255,0.35)',
              transition: 'background .3s',
            }} />
          </button>
        ))}
      </div>
    </section>
  );
}

function HeroSplit({ onNav }) {
  return (
    <section style={{
      position: 'relative', minHeight: 'min(62vh, 540px)',
      display: 'grid', gridTemplateColumns: '1fr 1fr',
      background: 'var(--bg)',
    }} className="enq-hero-split">
      <div style={{
        padding: '120px 56px 56px', display: 'flex', flexDirection: 'column',
        justifyContent: 'center', maxWidth: 740,
      }} className="enq-hero-split-content">
        <Eyebrow>Technology development & EPCM partner</Eyebrow>
        <Headline size="xl" as="h1" style={{ marginTop: 24, maxWidth: '18ch' }}>
          Engineering and project delivery for the mining and industrial sectors.
        </Headline>
        <p style={{
          marginTop: 26, fontSize: 'clamp(17px, 1.4vw, 22px)', lineHeight: 1.5,
          color: 'var(--fg2)', maxWidth: '50ch',
        }}>
          Detailed engineers and on-site builders working as one team — across Africa and Europe.
        </p>
        <div style={{ marginTop: 36, display: 'flex', gap: 14, flexWrap: 'wrap' }}>
          <Button onClick={() => onNav('capabilities')} variant="solid" size="lg">Explore our services</Button>
          <Button onClick={() => onNav('contact')} variant="outline" size="lg">Get in touch</Button>
        </div>
      </div>
      <div style={{ position: 'relative' }}>
        <Photo aspect="auto" tone="industrial" parallax={-30} style={{ height: '100%' }} caption="Concentrator floor — Limpopo, 2024" />
      </div>
    </section>
  );
}

function HeroEditorial({ onNav }) {
  return (
    <section style={{ paddingTop: 140, paddingBottom: 72 }}>
      <div style={{ maxWidth: 1320, margin: '0 auto', padding: '0 32px' }}>
        <div style={{
          display: 'grid', gridTemplateColumns: 'minmax(0, 0.4fr) minmax(0, 1fr)',
          gap: 56, alignItems: 'start',
        }} className="enq-2col">
          <Eyebrow>Enginuity</Eyebrow>
          <div>
            <Headline size="xxl" as="h1" style={{ maxWidth: '14ch' }}>
              Engineering and project delivery for the resource sector.
            </Headline>
            <div style={{
              marginTop: 56, display: 'grid', gridTemplateColumns: '1fr 1fr',
              gap: 56, alignItems: 'end',
            }} className="enq-2col">
              <p style={{ fontSize: 'clamp(17px, 1.3vw, 20px)', lineHeight: 1.55, color: 'var(--fg2)', margin: 0 }}>
                Enginuity is a multi-disciplinary engineering, project delivery and technology development
                partner. We work for mining, minerals and industrial clients across South Africa and Europe —
                from first-principles design through commissioning.
              </p>
              <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}>
                <Button onClick={() => onNav('capabilities')} variant="solid" size="lg">Explore our services</Button>
                <Button onClick={() => onNav('contact')} variant="outline" size="lg">Get in touch</Button>
              </div>
            </div>
          </div>
        </div>
        <div style={{ marginTop: 80 }}>
          <Photo aspect="21/9" tone="industrial" parallax={-30} caption="Concentrator floor — Limpopo, 2024" />
        </div>
      </div>
    </section>
  );
}

// ── Welcome — DRA-style intro paragraph ────────────────────────────────────
function Welcome({ onNav }) {
  return (
    <Section id="welcome">
      <div style={{
        display: 'grid', gridTemplateColumns: 'minmax(0, 0.6fr) minmax(0, 1fr)',
        gap: 56, alignItems: 'start',
      }} className="enq-2col">
        <div>
          <Eyebrow>Welcome</Eyebrow>
          <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '15ch' }}>
            A different kind of engineering firm.
          </Headline>
        </div>
        <div>
          <p style={{
            fontSize: 'clamp(18px, 1.4vw, 22px)', lineHeight: 1.55,
            color: 'var(--fg2)', margin: 0, maxWidth: '58ch',
          }}>
            Enginuity is a multi-disciplinary engineering, project delivery and operations
            partner — focused on the mining, minerals and industrial sectors. We bring together
            advanced research and turn-key EPCM delivery in a single team, so projects move from
            concept to commissioned asset without losing the engineers who started them.
          </p>
          <p style={{
            marginTop: 22, fontSize: 16, lineHeight: 1.65,
            color: 'var(--fg2)', margin: '22px 0 0', maxWidth: '58ch',
          }}>
            From our headquarters in Centurion, South Africa and our research office in
            St Gallen, Switzerland, we serve Anglo American, Black Chrome Mine, Aurex
            Constructors, General Kinematics, Iritron and R&amp;R Quantity Surveyors — among others.
          </p>
          <div style={{ marginTop: 32 }}>
            <ReadMore onClick={() => onNav('about')}>About Enginuity</ReadMore>
          </div>
        </div>
      </div>
    </Section>
  );
}

// ── Services — DRA-style image-led cards ───────────────────────────────────
function Services({ onNav }) {
  return (
    <Section id="services" style={{ background: 'var(--bg2)', paddingTop: 'var(--section-y)', paddingBottom: 'var(--section-y)' }}>
      <div style={{
        display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
        gap: 32, alignItems: 'end', marginBottom: 56,
      }} className="enq-2col">
        <div>
          <Eyebrow>What we do</Eyebrow>
          <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '16ch' }}>
            Four stages. One accountable team.
          </Headline>
        </div>
        <p style={{ fontSize: 'clamp(15px, 1.1vw, 17px)', lineHeight: 1.6, color: 'var(--fg2)', margin: 0, maxWidth: '46ch' }}>
          We cover the full lifecycle of an engineering project — from early-stage R&D and conceptual design through to long-term performance monitoring of operating assets.
        </p>
      </div>
      <div style={{
        display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))',
        gap: 28,
      }} className="enq-services-grid">
        {CAPABILITIES.map((c) => (
          <ServiceCard key={c.id} cap={c} onNav={onNav} />
        ))}
      </div>
      <div style={{ marginTop: 48, textAlign: 'center' }}>
        <Button onClick={() => onNav('capabilities')} variant="outline" size="lg">View all services</Button>
      </div>
    </Section>
  );
}

function ServiceCard({ cap, onNav }) {
  const [h, setH] = useState_h(false);
  return (
    <article onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)}
             onClick={() => onNav(`capabilities/${cap.id}`)}
             style={{
      background: 'var(--bg)', cursor: 'pointer',
      border: '1px solid var(--hair)',
      transition: 'box-shadow .25s, transform .25s',
      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)',
      display: 'flex', flexDirection: 'column',
    }}>
      <div style={{ position: 'relative', overflow: 'hidden' }}>
        <div style={{
          transform: h ? 'scale(1.03)' : 'scale(1)',
          transition: 'transform .8s ease',
        }}>
          <Photo aspect="16/9" tone={cap.tone} caption={`${cap.label} — Enginuity`} />
        </div>
        <div style={{
          position: 'absolute', top: 18, left: 18,
          padding: '6px 10px', background: 'rgba(255,255,255,0.92)',
          fontFamily: '"Source Sans 3", sans-serif', fontSize: 11, fontWeight: 700,
          letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--accent)',
          whiteSpace: 'nowrap',
        }}>{cap.tag}</div>
      </div>
      <div style={{ padding: '28px 30px 32px', display: 'flex', flexDirection: 'column', gap: 16 }}>
        <Headline size="md" as="h3" style={{ maxWidth: '18ch' }}>{cap.label}</Headline>
        <p style={{ margin: 0, fontSize: 15, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: '46ch' }}>
          {cap.blurb}
        </p>
        <div style={{ marginTop: 8 }}>
          <ReadMore color="var(--fg)" onClick={(e) => { e?.stopPropagation && e.stopPropagation(); onNav(`capabilities/${cap.id}`); }}>
            Read more
          </ReadMore>
        </div>
      </div>
    </article>
  );
}

// ── Markets — tile grid with photos ────────────────────────────────────────
function Markets({ onNav }) {
  return (
    <Section id="markets">
      <div style={{
        display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
        gap: 32, alignItems: 'end', marginBottom: 56,
      }} className="enq-2col">
        <div>
          <Eyebrow>Markets</Eyebrow>
          <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '14ch' }}>
            Sectors we serve.
          </Headline>
        </div>
        <p style={{ fontSize: 'clamp(15px, 1.1vw, 17px)', lineHeight: 1.6, color: 'var(--fg2)', margin: 0, maxWidth: '46ch' }}>
          Our work concentrates where simulation accuracy and on-site delivery must
          both be right — mining, minerals processing and the industrial plant that supports them.
        </p>
      </div>
      <div style={{
        display: 'grid',
        gridTemplateColumns: 'repeat(6, minmax(0, 1fr))',
        gap: 16,
      }} className="enq-markets-grid">
        {MARKETS.map((m, i) => {
          // First market spans 3, second spans 3, then 2-2-2
          const spans = [3, 3, 2, 2, 2];
          return <MarketTile key={m.id} market={m} span={spans[i] || 2} onNav={onNav} />;
        })}
      </div>
    </Section>
  );
}

function MarketTile({ market, span, onNav }) {
  const [h, setH] = useState_h(false);
  return (
    <button onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)}
            onClick={() => onNav('markets')} style={{
      gridColumn: `span ${span}`,
      appearance: 'none', border: 0, padding: 0,
      position: 'relative', overflow: 'hidden',
      cursor: 'pointer', textAlign: 'left',
      background: '#0f1114',
    }} className="enq-market-tile">
      <div style={{
        transform: h ? 'scale(1.04)' : 'scale(1)',
        transition: 'transform .9s ease',
      }}>
        <Photo aspect={span >= 3 ? '16/10' : '4/5'} tone={market.tone} caption={market.label} />
      </div>
      <div style={{
        position: 'absolute', inset: 0,
        background: `linear-gradient(to top, rgba(15,17,20,${h ? 0.85 : 0.7}) 0%, rgba(15,17,20,${h ? 0.3 : 0.15}) 60%, transparent 100%)`,
        transition: 'background .3s',
        padding: 28, display: 'flex', flexDirection: 'column', justifyContent: 'flex-end',
      }}>
        <Headline size="md" as="h3" style={{ color: '#ffffff', maxWidth: '14ch' }}>{market.label}</Headline>
        <div style={{
          maxHeight: h ? 80 : 0, overflow: 'hidden',
          transition: 'max-height .35s ease, opacity .35s',
          opacity: h ? 1 : 0,
        }}>
          <p style={{
            margin: '12px 0 0', fontSize: 14, lineHeight: 1.5,
            color: 'rgba(255,255,255,0.85)', maxWidth: '38ch',
          }}>{market.blurb}</p>
        </div>
      </div>
    </button>
  );
}

// ── Offices — two offices, one team ───────────────────────────────────────
function Difference({ onNav }) {
  return (
    <Section id="difference" style={{ background: 'var(--bg2)' }}>
      <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&amp;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>
  );
}

// ── Stats band ─────────────────────────────────────────────────────────────
function Stats() {
  return (
    <section style={{ background: 'var(--accent)', color: 'var(--on-accent)' }}>
      <div style={{
        maxWidth: 1320, margin: '0 auto', padding: '64px 32px',
        display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: 32,
      }} className="enq-stats">
        {[
          ['09', 'Years operating'],
          ['24', 'Projects delivered'],
          ['> R 1.4 bn', 'Combined project value'],
          ['02', 'Continents · ZA + CH'],
        ].map(([n, l], i) => (
          <div key={i}>
            <div style={{
              fontFamily: 'var(--ff-display)', fontWeight: 'var(--display-w)',
              letterSpacing: 'var(--display-track)',
              fontSize: 'clamp(42px, 5vw, 64px)', lineHeight: 1,
            }}>{n}</div>
            <div style={{
              marginTop: 12, fontSize: 14, fontWeight: 500,
              letterSpacing: '0.04em', opacity: 0.9,
            }}>{l}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// ── Featured projects ──────────────────────────────────────────────────────
function FeaturedWork({ onNav }) {
  return (
    <Section id="projects">
      <div style={{
        display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
        gap: 32, alignItems: 'end', marginBottom: 48,
      }} className="enq-2col">
        <div>
          <Eyebrow>Selected projects</Eyebrow>
          <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '14ch' }}>
            Built, commissioned, running.
          </Headline>
        </div>
        <div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 16 }}>
          <span style={{ fontSize: 14, color: 'var(--mid)' }}>04 of 24 featured</span>
          <Button onClick={() => onNav('work')} variant="outline" size="md">All projects</Button>
        </div>
      </div>
      <div style={{
        display: 'grid', gridTemplateColumns: 'repeat(2, minmax(0, 1fr))', gap: 32,
      }} className="enq-projects-grid">
        {PROJECTS.map((p) => (
          <ProjectCard key={p.id} project={p} onNav={onNav} />
        ))}
      </div>
    </Section>
  );
}

function ProjectCard({ project, onNav }) {
  const [h, setH] = useState_h(false);
  return (
    <article onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)}
             onClick={() => onNav('work')} style={{ cursor: 'pointer' }}>
      <div style={{ position: 'relative', overflow: 'hidden' }}>
        <div style={{ transform: h ? 'scale(1.03)' : 'scale(1)', transition: 'transform .8s ease' }}>
          <Photo aspect="4/3" tone={project.tone} caption={project.title} />
        </div>
      </div>
      <div style={{ marginTop: 20 }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 12 }}>
          <span style={{
            fontFamily: '"Source Sans 3", sans-serif', fontSize: 12, fontWeight: 700,
            letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--accent)',
          }}>{project.sector}</span>
          <span style={{ fontSize: 13, color: 'var(--mid)' }}>{project.year}</span>
        </div>
        <Headline size="md" as="h3" style={{ maxWidth: '20ch' }}>{project.title}</Headline>
        <p style={{ margin: '14px 0 16px', fontSize: 15, lineHeight: 1.55, color: 'var(--fg2)', maxWidth: '54ch' }}>
          {project.blurb}
        </p>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 14, flexWrap: 'wrap',
          paddingTop: 14, borderTop: '1px solid var(--hair)',
        }}>
          <span style={{
            fontSize: 14, fontWeight: 700, color: 'var(--accent)',
          }}>{project.metric}</span>
          <span style={{ color: 'var(--ash)' }}>·</span>
          <span style={{ fontSize: 13, color: 'var(--mid)' }}>{project.location}</span>
        </div>
      </div>
    </article>
  );
}

// ── Clients ────────────────────────────────────────────────────────────────
function Clients() {
  return (
    <Section id="clients" style={{ background: 'var(--bg2)' }}>
      <div style={{ textAlign: 'center', marginBottom: 48 }}>
        <Eyebrow style={{ display: 'inline-flex' }}>Trusted by</Eyebrow>
        <Headline size="md" as="h2" style={{ marginTop: 16 }}>
          Working with the operators who keep industry moving.
        </Headline>
      </div>
      <div style={{
        display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 0,
        border: '1px solid var(--hair)',
        background: 'var(--bg)',
      }} className="enq-clients-grid">
        {CLIENTS.map((c, i) => (
          <ClientLogo key={c.slug} client={c}
            borderRight={(i + 1) % 3 === 0 ? 'none' : '1px solid var(--hair)'}
            borderBottom={i < CLIENTS.length - (CLIENTS.length % 3 || 3) ? '1px solid var(--hair)' : 'none'} />
        ))}
      </div>
    </Section>
  );
}

// Renders a client's logo image, falling back to a clean wordmark if the
// image file hasn't been uploaded yet (uploads/logos/<slug>.png|svg).
function ClientLogo({ client, borderRight, borderBottom }) {
  const [mode, setMode] = useState_h('png'); // png → svg → wordmark
  const src = mode === 'png'
    ? `assets/logos/${client.slug}.png`
    : mode === 'svg'
      ? `assets/logos/${client.slug}.svg`
      : null;
  return (
    <div style={{
      padding: '36px 24px', display: 'flex', alignItems: 'center', justifyContent: 'center',
      borderRight, borderBottom,
      minHeight: 110, textAlign: 'center', color: 'var(--fg2)',
      transition: 'color .2s, background .2s',
    }}
    onMouseEnter={(e) => { e.currentTarget.style.color = 'var(--fg)'; e.currentTarget.style.background = 'var(--bg2)'; }}
    onMouseLeave={(e) => { e.currentTarget.style.color = 'var(--fg2)'; e.currentTarget.style.background = 'transparent'; }}
    >
      {src ? (
        <img src={src} alt={client.name} title={client.name}
             onError={() => setMode(mode === 'png' ? 'svg' : 'wordmark')}
             style={{
               maxHeight: 52, maxWidth: '80%', width: 'auto', objectFit: 'contain',
               opacity: 0.92, transition: 'opacity .2s, transform .2s',
             }}
             onMouseEnter={(e) => { e.currentTarget.style.opacity = '1'; e.currentTarget.style.transform = 'scale(1.03)'; }}
             onMouseLeave={(e) => { e.currentTarget.style.opacity = '0.92'; e.currentTarget.style.transform = 'scale(1)'; }}
        />
      ) : (
        <span style={{
          fontFamily: 'var(--ff-display)', fontWeight: 600,
          fontSize: 'clamp(15px, 1.2vw, 18px)', letterSpacing: '0.005em',
        }}>{client.name}</span>
      )}
    </div>
  );
}

// ── Insights ───────────────────────────────────────────────────────────────
function Insights({ onNav }) {
  const { items } = useInsights();
  return (
    <Section id="insights-home">
      <div style={{
        display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)',
        gap: 32, alignItems: 'end', marginBottom: 48,
      }} className="enq-2col">
        <div>
          <Eyebrow>Insights & news</Eyebrow>
          <Headline size="lg" as="h2" style={{ marginTop: 20, maxWidth: '15ch' }}>
            What we are working on, writing about and learning.
          </Headline>
        </div>
        <div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 16 }}>
          <Button onClick={() => onNav('insights')} variant="outline" size="md">All insights</Button>
        </div>
      </div>
      <div style={{
        display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 28,
      }} className="enq-3col">
        {items.slice(0, 3).map((it) => (
          <InsightCard key={it.id} it={it} onNav={onNav} />
        ))}
      </div>
    </Section>
  );
}

// ── Contact CTA ────────────────────────────────────────────────────────────
function ContactCTA({ onNav }) {
  return (
    <section style={{ position: 'relative', background: '#0f1114', color: '#ffffff', overflow: 'hidden' }}>
      <div style={{ position: 'absolute', inset: 0 }}>
        <Photo aspect="auto" tone="industrial" parallax={-20} style={{ height: '100%' }} caption="Site supervision — North West, 2023" />
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(135deg, rgba(15,17,20,0.92) 0%, rgba(15,17,20,0.7) 60%, rgba(15,17,20,0.5) 100%)' }} />
      </div>
      <div style={{
        position: 'relative', maxWidth: 1320, margin: '0 auto', padding: '110px 32px',
        display: 'grid', gridTemplateColumns: 'minmax(0, 1.2fr) minmax(0, 1fr)', gap: 64, alignItems: 'end',
      }} className="enq-2col">
        <div>
          <Eyebrow color="#ffffff" style={{ opacity: 0.9 }}>Need a solution?</Eyebrow>
          <Headline size="xl" as="h2" style={{ color: '#ffffff', marginTop: 24, maxWidth: '16ch' }}>
            Let's build it together.
          </Headline>
        </div>
        <div>
          <p style={{ fontSize: 'clamp(16px, 1.2vw, 19px)', lineHeight: 1.55, color: 'rgba(255,255,255,0.85)', margin: 0, maxWidth: '42ch' }}>
            Send us 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.
          </p>
          <div style={{ marginTop: 30, display: 'flex', gap: 14, flexWrap: 'wrap' }}>
            <Button onClick={() => onNav('contact')} variant="light" size="lg">Start a conversation</Button>
            <a href="mailto:karla.naude@engn.co.za" style={{
              display: 'inline-flex', alignItems: 'center', gap: 12,
              padding: '15px 26px', textDecoration: 'none',
              border: '1px solid rgba(255,255,255,0.3)', background: 'rgba(255,255,255,0.06)',
              color: '#ffffff', fontFamily: '"Source Sans 3", sans-serif', fontSize: 16, fontWeight: 600,
              backdropFilter: 'blur(8px)',
            }}>karla.naude@engn.co.za</a>
          </div>
        </div>
      </div>
    </section>
  );
}

// ── Home compose ───────────────────────────────────────────────────────────
function HomePage({ tweaks, onNav }) {
  return (
    <>
      <PlantExplorer embedded={true} />
      <Welcome onNav={onNav} />
      <Difference onNav={onNav} />
      <Stats />
      <Clients />
      <ContactCTA onNav={onNav} />
    </>
  );
}

Object.assign(window, {
  HomePage, CAPABILITIES, MARKETS, CLIENTS, PROJECTS, INSIGHTS,
  Hero, HeroCarousel, HeroSplit, HeroEditorial,
  Welcome, Services, ServiceCard, Markets, MarketTile,
  Difference, Stats, FeaturedWork, ProjectCard, Clients, Insights, ContactCTA,
});
