/* global React, Header, Hero, CollectionGrid, CollectionsIndex, ConfiguratorStrip, ProjectsGrid, ProjectsPage, EDM, Footer, COLLECTIONS, SpecificationSection, SpecifierDownloads, EnquiryBlock, ThreadBadge, THREADS, useViewport, FeatureCarousel, GatewayCarousel, EditorialCarousel, NowShowing, CollaboratorsStrip, MaterialsStory, TaglineSlab, About, DesignCapabilities, CircularEconomy, ProjectDetail, PolicyPage, ModularBuildUp, ModularAssemblies */
const { useState, useEffect } = React;

function Home({ setScreen }) {
  const goCollection = (slug) => setScreen(slug === "gateway" ? "gateway" : "collections");
  return (
    <>
      <FeatureCarousel />
      <TaglineSlab />
      <NowShowing onCollection={goCollection} />
      <CollectionGrid setScreen={setScreen} limit={3} />
      <ProjectsGrid setScreen={setScreen} />
      <MaterialsStory />
      <EDM />
    </>
  );
}

function GatewayDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      {/* Full-bleed carousel — page opens on image with its own caption */}
      <GatewayCarousel />

      {/* Title + intro, now below the carousel */}
      <PageIntro
        eyebrow="Gateway · Alexander Lotersztain, 2025"
        title="A modular public seating system redefining comfort in high-traffic environments."
        body="A comprehensive modular seating system designed for the demands of high-traffic public interiors — airports, transit hubs, healthcare, civic and corporate environments. Connectivity, ergonomic comfort and architectural clarity, set on Derlot's two long-standing pillars: modular furniture and systems thinking."
        compact
        noTopPad
      />

      {/* Editorial pair — image carousel + copy */}
      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto" }}>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 32 : 48 }}>
          <EditorialCarousel
            slides={[
              { src: "images/collections/gateway/pillars/01.jpg",         alt: "Gateway · S-shape configuration render",  caption: "01 · Configuration" },
              { src: "images/collections/gateway/pillars/02.jpg", alt: "Gateway · 4-seater assembly stages",      caption: "02 · Construction" },
              { src: "images/collections/gateway/pillars/03.jpg",   alt: "Gateway · airport lobby in situ render",  caption: "03 · In service" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>Endure · Configure</div>
            <h2 style={{ fontWeight: 500, fontSize: isMobile ? "clamp(22px, 5.5vw, 28px)" : "clamp(24px, 2.2vw, 32px)", lineHeight: 1.12, letterSpacing: "-0.01em", color: "#1a1917", margin: "0 0 16px 0", maxWidth: "22ch" }}>
              An organic, adaptable system for public passage.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Designed from the ground up around the contemporary user's need for on-demand connectivity within a clean, uncluttered environment. The result integrates connectivity, ergonomic comfort and architectural clarity to set a new standard for public seating across diverse, demanding environments.
            </p>
          </div>
        </div>
      </section>

      {/* Three features — what makes Gateway Gateway */}
      <section style={{ padding: isMobile ? "64px 20px" : "120px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto" }}>
        <div style={{ maxWidth: 720, marginBottom: isMobile ? 40 : 64 }}>
          <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>What Gateway does</div>
          <h2 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? "clamp(24px, 6vw, 30px)" : "clamp(26px, 2.6vw, 38px)", lineHeight: 1.12, letterSpacing: "-0.015em", color: "#1a1917", margin: 0, maxWidth: "26ch", textWrap: "balance" }}>
            Three pillars holding the system together.
          </h2>
        </div>

        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            {
              no: "01",
              kicker: "Modular",
              title: "Distinct seating zones for diverse user profiles.",
              body: "An organic, modular design tailored to a wide range of users — from solo travellers and waiting patients to families, groups and corporate users. Configurations can be reconfigured with ease as needs shift, supporting the dynamic nature of modern public environments.",
              image: "images/collections/gateway/feature/01.webp",
              alt: "Gateway configured as a linear beam",
            },
            {
              no: "02",
              kicker: "Connected",
              title: "Integrated power and wireless charging by OE Elsafe.",
              body: "Concealed cable management and on-demand power and USB access support the digital needs of contemporary users while preserving the calm aesthetic essential to public environments. Delivered in collaboration with OE Elsafe — global leaders in soft wiring and workspace technologies.",
              image: "images/collections/gateway/feature/02.jpg",
              alt: "Gateway · phone charging on the integrated armrest USB-C socket",
            },
            {
              no: "03",
              kicker: "Universal",
              title: "Accessibility designed in, not retrofitted.",
              body: "Wheelchair-accessible positions sit seamlessly within the seating layout, allowing companions and wheelchair users to sit alongside one another without separation or compromise. The detail is considered rather than retrofitted — accessibility is part of the system's core design language.",
              image: "images/collections/gateway/feature/03.jpg",
              alt: "Gateway · wheelchair zone integrated into the cluster",
            },
          ].map((f) => (
            <div key={f.no}>
              <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden", marginBottom: isMobile ? 18 : 24 }}>
                <img src={f.image} srcSet={window.IMG && window.IMG.srcsetFor(f.image)} sizes={window.IMG && window.IMG.sizes()} alt={f.alt} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
              </div>
              <div style={{ display: "flex", alignItems: "baseline", gap: 14, marginBottom: 12 }}>
                <div style={{ fontSize: 11, color: "#6c6862", fontWeight: 500, letterSpacing: "0.08em" }}>{f.no}</div>
                <div style={{ height: "0.5px", flex: 1, background: "rgba(26,25,23,0.25)" }} />
                <div style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500 }}>{f.kicker}</div>
              </div>
              <h3 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? 19 : 20, lineHeight: 1.22, letterSpacing: "-0.01em", color: "#1a1917", margin: "0 0 10px 0", maxWidth: "20ch" }}>
                {f.title}
              </h3>
              <p style={{ fontSize: 14, lineHeight: 1.6, color: "#6c6862", margin: 0, maxWidth: "38ch" }}>
                {f.body}
              </p>
            </div>
          ))}
        </div>
      </section>

      {/* The build-up — condensed sequence */}
      <ModularBuildUp
        eyebrow="How Gateway is built"
        title="Built from the frame up."
        concept="Choose a footprint, populate it, power it, finish it — or start from a configuration we've already drawn."
        steps={[
          { n: 1, layer: "Frame",       line: "Single or double, straight, curved or a full ring." },
          { n: 2, layer: "Seating",     line: "Populate the bays — standard, curved, accessible or backless." },
          { n: 3, layer: "Tables",      line: "Drop in surfaces where people dwell." },
          { n: 4, layer: "Armrests",    line: "Comfort — and the carrier for power." },
          { n: 5, layer: "Power",       line: "Charging integrated by OE Elsafe — wired or wireless." },
          { n: 6, layer: "Accessories", line: "Cup holders, cable trays and floor fixing as needed." },
          { n: 7, layer: "Finish",      line: "Upholstery, metalwork, timber tops and embroidery." },
        ]}
      />

      {/* The shortcut path — typical pre-drawn assemblies */}
      <ModularAssemblies
        eyebrow="Start from a drawn configuration"
        title="Five assemblies, drawn and ready."
        intro="Each is a real bundle a specifier can quote from — and an editable starting point in the configurator. Component counts are indicative; final bay splits are confirmed against the frame spec."
        assemblies={[
          { id: "gateway-4-linear",   kicker: "Linear",        name: "Gateway 4",      rows: [
            { label: "Frame",    value: "GTW-FRM-SNG-04" },
            { label: "Populate", value: "4× GTW-STM-700" },
            { label: "Power",    value: "1× GTW-ARM-PWR + GTW-CBL-150" },
          ] },
          { id: "gateway-6-table",    kicker: "Linear + table", name: "Gateway 6",     rows: [
            { label: "Frame",    value: "GTW-FRM-SNG-06" },
            { label: "Populate", value: "5× GTW-STM-700 + 1× GTW-TBM-SNG-700" },
            { label: "Power",    value: "2× GTW-ARM-PWR-WRL + trays" },
          ] },
          { id: "gateway-12-b2b",     kicker: "Back-to-back",  name: "Gateway 12",     rows: [
            { label: "Frame",    value: "GTW-FRM-DBL-12" },
            { label: "Populate", value: "12× GTW-STM-700" },
            { label: "Power",    value: "2× GTW-TBM-DBL-700 · 4× GTW-ARM-PWR + trays" },
          ] },
          { id: "gateway-island",     kicker: "Rounded pod",   name: "Gateway Island", rows: [
            { label: "Frame",    value: "GTW-FRM-DBL-RND-16" },
            { label: "Populate", value: "Straight + curved-end modules" },
            { label: "Showcase", value: "Central planter / table", plain: true },
          ] },
          { id: "gateway-ring",       kicker: "Full circle",   name: "Gateway Ring",   rows: [
            { label: "Frame",    value: "GTW-FRM-SNG-CRC-12-1100-1800" },
            { label: "Populate", value: "12× GTW-STM-CRV-30-1100" },
            { label: "Showcase", value: "Centre planting", plain: true },
          ] },
        ]}
        note="Swap any GTW-STM-700 for the priority module GTW-STM-PRM-700 to meet accessibility code."
        invitation="Build your own — then price it with us, or take it to your drawings. Every configuration exports as a CAD-ready DXF, direct from the platform."
      />

      <SpecificationSection
        headline="Fully customisable. The configurations below are a starting point — get in touch to tailor to your project."
        meta={[
          ["Design", "Alexander Lotersztain, 2025"],
          ["Sectors", "Aviation · Healthcare · Civic · Corporate · Hospitality"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Certifications", "GECA certified"],
          ["Manufactured", "Australia · Poland"],
          ["Connectivity", "OE Elsafe (OE Electrics Group)"],
        ]}
materials="Beam frame in heat-treated alloy steel, uncoated plain black finish, on a 700 mm modular grid. Seating and armrest substructures in powder-coated mild steel (Dulux Mannex Black standard). Dunlop Enduro® foam over MDF substrate, upholstered in Maharam Lariat / Compound / Willow / Route / Gust or COM/COL. Table surfaces in timber particleboard with Melamine, solid timber, or P3 Black Integral Skin Foam. Armrests with timber or foam top. Power and wireless charging by OE Elsafe (TUF-R AC PIP up to 25W standard / 72W fast-charge HP; ARC DOT wireless up to 15W). Global socket types — B, I, E, F, G, J, K, P30."
        groups={[
          {
            label: "Armrest modules",
            note: "All armrests share a common footprint — 400 × 120 × 175 mm.",
            items: [
              { sku: "GTW-ARM",         name: "Standard armrest" },
              { sku: "GTW-ARM-WRL",     name: "Standard armrest · wireless charging" },
              { sku: "GTW-ARM-PWR",     name: "Powered armrest · AC PIP" },
              { sku: "GTW-ARM-PWR-WRL", name: "Powered armrest · AC PIP + wireless charging" },
            ],
          },
          {
            label: "Seating modules",
            note: "Standard seat height 450 mm; 520 mm for premium raised. 800H total module.",
            items: [
              { sku: "GTW-STM-700",            name: "Standard seating module",                       dims: "700 × 700 × 800" },
              { sku: "GTW-STM-PRM-700",        name: "Premium seating module",                        dims: "700 × 700 × 800" },
              { sku: "GTW-STM-PRM-RSD-700",    name: "Premium raised seating module",                 dims: "700 × 700 × 870" },
              { sku: "GTW-STM-CRV-30-1100",    name: "30° curved seating module · small",             dims: "920 × 730 × 800" },
              { sku: "GTW-STM-CRV-30-1100-CNV",name: "30° curved seating module · small convertible", dims: "920 × 730 × 800" },
              { sku: "GTW-STM-CRV-30-2500-CNV",name: "30° curved seating module · large convertible", dims: "1280 × 750 × 800" },
              { sku: "GTW-STM-CRV-90",         name: "90° curved corner seating module",              dims: "700 × 700 × 800" },
            ],
          },
          {
            label: "Ottoman modules",
            note: "450 mm seat height across the family.",
            items: [
              { sku: "GTW-OTM-700",         name: "Standard ottoman module",                dims: "700 × 700 × 450" },
              { sku: "GTW-OTM-CRV-30-1100", name: "30° curved ottoman module · small",      dims: "920 × 730 × 450" },
              { sku: "GTW-OTM-CRV-30-2500", name: "30° curved ottoman module · large",      dims: "1280 × 730 × 450" },
              { sku: "GTW-OTM-CRV-90",      name: "90° curved corner ottoman module",       dims: "700 × 700 × 450" },
            ],
          },
          {
            label: "Table modules",
            note: "25 mm thickness across all table modules.",
            items: [
              { sku: "GTW-TBM-SNG-700", name: "Single row table module",     dims: "700 × 700 × 25" },
              { sku: "GTW-TBM-SNG-END", name: "Single row end table module", dims: "435 × 700 × 25" },
              { sku: "GTW-TBM-DBL-700", name: "Double row table module",     dims: "665 × 1365 × 25" },
              { sku: "GTW-TBM-DBL-END", name: "Double row end table module", dims: "395 × 1365 × 25" },
            ],
          },
          {
            label: "Linear single row frames",
            note: "700 mm depth · 3–12 positions · 700 mm modular grid. Custom lengths available.",
            items: [
              { sku: "GTW-FRM-SNG-03", name: "Linear single row · 3 positions",  dims: "2100 × 700" },
              { sku: "GTW-FRM-SNG-04", name: "Linear single row · 4 positions",  dims: "2800 × 700" },
              { sku: "GTW-FRM-SNG-05", name: "Linear single row · 5 positions",  dims: "3500 × 700" },
              { sku: "GTW-FRM-SNG-06", name: "Linear single row · 6 positions",  dims: "4200 × 700" },
              { sku: "GTW-FRM-SNG-07", name: "Linear single row · 7 positions",  dims: "4900 × 700" },
              { sku: "GTW-FRM-SNG-08", name: "Linear single row · 8 positions",  dims: "5600 × 700" },
              { sku: "GTW-FRM-SNG-09", name: "Linear single row · 9 positions",  dims: "6300 × 700" },
              { sku: "GTW-FRM-SNG-10", name: "Linear single row · 10 positions", dims: "7000 × 700" },
              { sku: "GTW-FRM-SNG-11", name: "Linear single row · 11 positions", dims: "7700 × 700" },
              { sku: "GTW-FRM-SNG-12", name: "Linear single row · 12 positions", dims: "8400 × 700" },
            ],
          },
          {
            label: "Linear double row frames",
            note: "1400 mm depth · 6–24 positions · back-to-back configuration. Custom lengths available.",
            items: [
              { sku: "GTW-FRM-DBL-06", name: "Linear double row · 6 positions",  dims: "2100 × 1400" },
              { sku: "GTW-FRM-DBL-08", name: "Linear double row · 8 positions",  dims: "2800 × 1400" },
              { sku: "GTW-FRM-DBL-10", name: "Linear double row · 10 positions", dims: "3500 × 1400" },
              { sku: "GTW-FRM-DBL-12", name: "Linear double row · 12 positions", dims: "4200 × 1400" },
              { sku: "GTW-FRM-DBL-14", name: "Linear double row · 14 positions", dims: "4900 × 1400" },
              { sku: "GTW-FRM-DBL-16", name: "Linear double row · 16 positions", dims: "5600 × 1400" },
              { sku: "GTW-FRM-DBL-18", name: "Linear double row · 18 positions", dims: "6300 × 1400" },
              { sku: "GTW-FRM-DBL-20", name: "Linear double row · 20 positions", dims: "7000 × 1400" },
              { sku: "GTW-FRM-DBL-22", name: "Linear double row · 22 positions", dims: "7700 × 1400" },
              { sku: "GTW-FRM-DBL-24", name: "Linear double row · 24 positions", dims: "8400 × 1400" },
            ],
          },
          {
            label: "Linear double row, rounded end",
            note: "1400 mm depth · 8–28 positions · rounded terminations for transit and lounge runs. Custom lengths available.",
            items: [
              { sku: "GTW-FRM-DBL-RND-08", name: "Double row rounded end · 8 positions",  dims: "2800 × 1400" },
              { sku: "GTW-FRM-DBL-RND-10", name: "Double row rounded end · 10 positions", dims: "3500 × 1400" },
              { sku: "GTW-FRM-DBL-RND-12", name: "Double row rounded end · 12 positions", dims: "4200 × 1400" },
              { sku: "GTW-FRM-DBL-RND-14", name: "Double row rounded end · 14 positions", dims: "4900 × 1400" },
              { sku: "GTW-FRM-DBL-RND-16", name: "Double row rounded end · 16 positions", dims: "5600 × 1400" },
              { sku: "GTW-FRM-DBL-RND-18", name: "Double row rounded end · 18 positions", dims: "6300 × 1400" },
              { sku: "GTW-FRM-DBL-RND-20", name: "Double row rounded end · 20 positions", dims: "7000 × 1400" },
              { sku: "GTW-FRM-DBL-RND-22", name: "Double row rounded end · 22 positions", dims: "7700 × 1400" },
              { sku: "GTW-FRM-DBL-RND-24", name: "Double row rounded end · 24 positions", dims: "8400 × 1400" },
              { sku: "GTW-FRM-DBL-RND-26", name: "Double row rounded end · 26 positions", dims: "9100 × 1400" },
              { sku: "GTW-FRM-DBL-RND-28", name: "Double row rounded end · 28 positions", dims: "9800 × 1400" },
            ],
          },
          {
            label: "Circular single row frames",
            note: "3600 mm standard diameter (1800 mm radius). Half, three-quarter and full circle starting points — custom diameters and arcs available.",
            items: [
              { sku: "GTW-FRM-SNG-CRC-06",            name: "Half circle · single row",          dims: "Ø 3600" },
              { sku: "GTW-FRM-SNG-CRC-09",            name: "Three-quarter circle · single row", dims: "Ø 3600" },
              { sku: "GTW-FRM-SNG-CRC-12-1100-1800",  name: "Full circle · single row · custom",   dims: "Ø 3600" },
            ],
          },
          {
            label: "Circular double row frames",
            note: "5000 mm standard overall diameter. Back-to-back closed-loop starting points — custom diameters available.",
            items: [
              { sku: "GTW-FRM-DBL-CRC-12",     name: "Double row circular",                 dims: "Ø 5000 · 3200 inner" },
              { sku: "GTW-FRM-DBL-RND-CRC-18", name: "Double row rounded circular",         dims: "Ø 5000 · 4700 config" },
            ],
          },
        ]}
        extras={[
          {
            label: "Power & charging · OE Elsafe",
            note: "Specified per armrest. Global socket compatibility for all major markets.",
            rows: [
              { text: "AC PIP · TUF-R · up to 25W standard charging" },
              { text: "AC PIP · TUF-R HP · up to 72W fast charging" },
              { text: "Wireless · ARC DOT · up to 15W" },
              { text: "Sockets · Type B, I, E, F, G, J, K, P30", muted: true },
            ],
          },
          {
            label: "Upholstery · Maharam range",
            note: "COM and COL also available.",
            rows: [
              { text: "Lariat · 51 colours · vinyl, 100% Non-Phthalate PVC" },
              { text: "Compound · 34 colours · vinyl, 100% Polyurethane" },
              { text: "Willow · 14 colours · fabric, Crypton finish" },
              { text: "Route · 11 colours · fabric, Crypton finish" },
              { text: "Gust · 16 colours · fabric, Crypton finish" },
              { text: "COM / COL · Customer's Own Material or Leather", muted: true },
            ],
          },
          {
            label: "Table tops",
            rows: [
              { text: "P3 · Black Integral Skin Foam" },
              { text: "T6 · American Oak" },
              { text: "T8 · American Walnut" },
            ],
          },
          {
            label: "Metalwork & options",
            rows: [
              { text: "Dulux Mannex Black · standard" },
              { text: "Custom powder coat · any colour available" },
              { text: "Embroidery · priority seating symbols and custom options", muted: true },
            ],
          },
        ]}
        finishHeadline="Frame, upholstery, table top and connectivity — specified independently."
      />

      <ConfiguratorStrip collection="Gateway" />

      {/* Specified in — projects using this collection */}
      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto", borderTop: "0.5px solid rgba(26,25,23,0.18)" }}>
        <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", marginBottom: isMobile ? 24 : 36, flexWrap: "wrap", gap: 12 }}>
          <div>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 12 }}>Specified in</div>
            <h2 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? "clamp(22px, 5.5vw, 28px)" : "clamp(24px, 2.2vw, 32px)", lineHeight: 1.12, letterSpacing: "-0.015em", color: "#1a1917", margin: 0, maxWidth: "22ch", textWrap: "balance" }}>
              Working in airports across three continents.
            </h2>
          </div>
          <a onClick={() => { window.location.href = "/projects"; }} style={{ fontSize: 12, color: "#1a1917", borderBottom: "0.5px solid rgba(26,25,23,0.35)", paddingBottom: 2, cursor: "pointer" }}>
            All projects with Gateway →
          </a>
        </div>

        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 28 : 24 }}>
          {[
            { name: "Dallas Fort Worth Airport", place: "Dallas, USA",   firm: "",                year: 2024, image: "assets/gateway/hero-dfw.webp",       slug: "dfw" },
            { name: "Adelaide Airport",          place: "Adelaide, AUS", firm: "Woods Bagot",      year: 2025, image: "images/_legacy/projects/adelaide-airport.jpg", slug: "adelaide" },
            { name: "Cairns Airport",            place: "Cairns, AUS",    firm: "Studio Spillane", year: 2025, image: "images/_legacy/projects/cairns/17-canoe-suspended.jpg",   slug: "cairns" },
          ].map((p) => (
            <a key={p.slug} style={{ display: "block", color: "inherit", cursor: "pointer" }}>
              <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden" }}>
                <img src={p.image} srcSet={window.IMG && window.IMG.srcsetFor(p.image)} sizes={window.IMG && window.IMG.sizes()} alt={p.name} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
              </div>
              <div style={{ height: "0.5px", background: "rgba(26,25,23,0.18)", marginTop: 14 }} />
              <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", marginTop: 12, gap: 12 }}>
                <div style={{ fontSize: 15, color: "#1a1917", lineHeight: 1.3 }}>{p.name}</div>
                <div style={{ fontSize: 11, letterSpacing: "0.12em", color: "#6c6862", fontWeight: 500, whiteSpace: "nowrap" }}>{p.year}</div>
              </div>
              <div style={{ fontSize: 12, color: "#6c6862", marginTop: 4 }}>{p.place}{p.firm ? " \u00b7 " + p.firm : ""}</div>
            </a>
          ))}
        </div>
      </section>

      <SpecifierDownloads collection="Gateway" />

      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto", borderTop: "0.5px solid rgba(26,25,23,0.18)" }}>
        <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 20 }}>Related collections</div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 32 : 32 }}>
          {(window.COLLECTIONS || []).filter(c => ["trio","platform","mochi"].includes(c.slug)).map((c) => (
            <div key={c.slug}>
              <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden" }}>
                {c.image && (
                  <img src={c.image} srcSet={window.IMG && window.IMG.srcsetFor(c.image)} sizes={window.IMG && window.IMG.sizes()} alt={c.name} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
                )}
              </div>
              <div style={{ height: "0.5px", background: "rgba(26,25,23,0.18)", marginTop: 14 }} />
              <div style={{ fontSize: 16, color: "#1a1917", marginTop: 12 }}>{c.name}</div>
              <div style={{ marginTop: 10, display: "flex", flexWrap: "wrap", rowGap: 6 }}>
                {c.threads.map(tk => <ThreadBadge key={tk} threadKey={tk} />)}
              </div>
            </div>
          ))}
        </div>
      </section>

      <EnquiryBlock collection="Gateway" />
    </>
  );
}

// Coerce retired screen ids back to home so a stale localStorage value or an old
// bookmarked deep link (e.g. the removed "client" portal) never lands on a blank
// page — the render block has no default fallback.
const RETIRED_SCREENS = { client: 1 };
function normalizeScreen(s) {
  return RETIRED_SCREENS[s] ? "home" : s;
}

// ---- URL <-> screen mapping ---------------------------------------------
// The app keeps a single internal `screen` id (e.g. "gateway", "project-dfw",
// "policy-privacy"). These two helpers translate that id to/from a real path so
// the address bar reads /collections/gateway instead of /?screen=gateway.
// Collection details nest under /collections/, projects under /projects/, and
// policies under /policy/; every other screen is a flat top-level path. The map
// is fully reversible, so pushState and the back button round-trip cleanly.
function isCollectionSlug(s) {
  return !!(window.COLLECTIONS || []).find((c) => c.slug === s);
}
function screenToPath(s) {
  if (!s || s === "home") return "/";
  if (s.indexOf("project-") === 0) return "/projects/" + s.slice("project-".length);
  if (s.indexOf("policy-") === 0)  return "/policy/" + s.slice("policy-".length);
  if (isCollectionSlug(s))         return "/collections/" + s;
  return "/" + s;
}
function pathToScreen(path) {
  const p = (path || "/").replace(/\/+$/, "");        // trim trailing slashes
  if (p === "") return "home";
  const parts = p.replace(/^\/+/, "").split("/").map((x) => { try { return decodeURIComponent(x); } catch (e) { return x; } });
  if (parts[0] === "collections" && parts[1]) return parts[1];
  if (parts[0] === "projects"    && parts[1]) return "project-" + parts[1];
  if (parts[0] === "policy"      && parts[1]) return "policy-" + parts[1];
  return parts[0] || "home";
}
// Exposed so the few detail components that navigate via a full page load
// (they have no setScreen prop) can build a real path instead of the old
// localStorage+reload hack, which path routing would otherwise override.
window.screenToPath = screenToPath;
window.pathToScreen = pathToScreen;

// Map a screen id → its document title + analytics label. Data-driven from the
// collection/project registries so EVERY page is tracked distinctly. Lead
// Forensics and GTM read document.title and the URL on each virtual pageview,
// so these must be unique per screen.
function screenMeta(screen) {
  const SITE = "Derlot";
  const STATIC = {
    home:                  ["Derlot — Designed for the spaces between.", "01 Home"],
    collections:           ["Collections — " + SITE,    "02 Collections"],
    downloads:             ["Downloads — " + SITE,       "04 Downloads"],
    projects:              ["Projects — " + SITE,        "05 Projects"],
    about:                 ["About — " + SITE,           "06 About"],
    "design-capabilities": ["Collaboration — " + SITE,   "07 Collaboration"],
    "circular-economy":    ["Circularity — " + SITE,     "08 Circularity"],
    distributors:          ["Distributors — " + SITE,    "10 Distributors"],
    moodboard:             ["Moodboard — " + SITE,        "Moodboard"],
  };
  if (STATIC[screen]) return { title: STATIC[screen][0], label: STATIC[screen][1] };
  if (screen && screen.indexOf("policy-") === 0) {
    const name = screen.replace("policy-", "").replace(/-/g, " ");
    const nice = name.replace(/\b\w/g, (c) => c.toUpperCase());
    return { title: nice + " — " + SITE, label: "Policy · " + name };
  }
  if (screen && screen.indexOf("project-") === 0) {
    const p = window.getProject && window.getProject(screen);
    const nm = (p && p.name) || screen.replace("project-", "");
    return { title: nm + " — Projects — " + SITE, label: "Project · " + nm };
  }
  const c = (window.COLLECTIONS || []).find((x) => x.slug === screen);
  if (c) return { title: c.name + " — Collections — " + SITE, label: c.name + " detail" };
  return { title: SITE, label: screen || "home" };
}

function App() {
  const [screen, setScreenState] = React.useState(() => {
    // URL is the source of truth. Prefer a real path (/collections/gateway),
    // then a legacy ?screen= deep link (old shared links still resolve), then
    // the persisted screen for a bare "/" visit, then home. We don't persist
    // the URL value so a deep-linked tab doesn't clobber other tabs.
    try {
      const q = new URLSearchParams(window.location.search).get("screen");
      if (q) return normalizeScreen(q);
      const fromPath = pathToScreen(window.location.pathname);
      if (fromPath && fromPath !== "home") return normalizeScreen(fromPath);
    } catch (e) { /* no-op */ }
    return normalizeScreen(localStorage.getItem("derlot-screen") || "home");
  });
  // SPA virtual pageview — fires on user navigation AND back/forward, with the
  // accurate title + path so Lead Forensics / GTM attribute each screen.
  const firePageview = (s) => {
    const m = screenMeta(s);
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({ event: "screen_view", screen: s, page_title: m.title, page_path: screenToPath(s) });
  };

  const setScreen = (s) => {
    setScreenState(s);
    localStorage.setItem("derlot-screen", s);
    // Reflect the screen as a real path so deep links, the address bar and
    // URL-based analytics all track the actual page (e.g. /collections/gateway).
    try {
      window.history.pushState({ screen: s }, "", screenToPath(s));
    } catch (e) { /* no-op */ }
    firePageview(s);
    window.scrollTo({ top: 0, behavior: "instant" });
  };

  // Keep the tab/document title + canonical URL in sync with the screen (covers
  // initial load too), so each route is titled and canonicalised distinctly.
  React.useEffect(() => {
    try {
      document.title = screenMeta(screen).title;
      const link = document.querySelector('link[rel="canonical"]');
      if (link) link.setAttribute("href", "https://www.derlot.com" + screenToPath(screen));
    } catch (e) { /* no-op */ }
  }, [screen]);

  // Back/forward: restore the screen from the URL without pushing a new entry.
  React.useEffect(() => {
    const onPop = () => {
      let s = "home";
      try {
        const q = new URLSearchParams(window.location.search).get("screen");
        s = q || pathToScreen(window.location.pathname);
      } catch (e) { /* no-op */ }
      s = normalizeScreen(s);
      setScreenState(s);
      localStorage.setItem("derlot-screen", s);
      firePageview(s);
      window.scrollTo({ top: 0, behavior: "instant" });
    };
    window.addEventListener("popstate", onPop);
    return () => window.removeEventListener("popstate", onPop);
  }, []);

  return (
    <div data-screen-label={screenMeta(screen).label}>
      <Header screen={screen} setScreen={setScreen} />
      {window.PDP_ROUTES && window.PDP_ROUTES.has(screen) && (
        <PdpNav slug={screen} setScreen={setScreen} />
      )}
      {window.PROJECT_PDP_ROUTES && window.PROJECT_PDP_ROUTES.has(screen) && (
        <ProjectPdpNav slug={screen} setScreen={setScreen} />
      )}
      <main>
      {screen === "home"                 && <Home setScreen={setScreen} />}
      {screen === "collections"          && <CollectionsIndex setScreen={setScreen} />}
      {screen === "gateway"              && <GatewayDetail />}
      {screen === "trio"                 && <TrioDetail />}
      {screen === "pipeline"             && <PipelineDetail />}
      {screen === "prisma"               && <PrismaDetail />}
      {screen === "caterpillar"          && <CaterpillarDetail />}
      {screen === "mochi"                && <MochiDetail />}
      {screen === "twig"                 && <TwigDetail />}
      {screen === "autobahn"             && <AutobahnDetail />}
      {screen === "cocoon"               && <CocoonDetail />}
      {screen === "volar"                && <VolarDetail />}
      {screen === "stump-r"              && <StumpRecycledDetail />}
      {screen === "s1"                   && <S1Detail />}
      {screen === "tonne"                && <TonneDetail />}
      {screen === "stump"                && <StumpRecycledDetail />}
      {screen === "cup"                  && <CupDetail />}
      {screen === "biggie"               && <BiggieDetail />}
      {screen === "platform"             && <PlatformDetail />}
      {screen === "strap"                && <StrapDetail />}
      {screen === "picket"               && <PicketDetail />}
      {screen === "pinto"                && <PintoDetail />}
      {screen === "hext"                 && <HextDetail />}
      {screen === "yeti"                 && <YetiDetail />}
      {screen === "rio"                  && <RioDetail />}
      {screen === "pillar"               && <PillarDetail />}
      {screen === "guell"                && <GuellDetail />}
      {screen === "fit"                  && <FitDetail />}
      {screen === "tetromino-s"          && <TetrominoSoftDetail />}
      {screen === "mass"                 && <MassDetail setScreen={setScreen} />}
      {screen === "seed"                 && <SeedDetail setScreen={setScreen} />}
      {screen === "ivi"                  && <IviDetail setScreen={setScreen} />}
      {screen === "homework"             && <HomeworkDetail setScreen={setScreen} />}
      {screen === "coral"                && <CoralDetail setScreen={setScreen} />}
      {screen === "wombat"               && <WombatDetail />}
      {screen === "flatliner"            && <FlatlinerWallDetail />}
      {screen === "kono"                 && <KonoDetail setScreen={setScreen} />}
      {screen === "bolet"                && <BoletDetail setScreen={setScreen} />}
      {screen === "kink"                 && <KinkDetail setScreen={setScreen} />}
      {screen === "pill"                 && <PillDetail setScreen={setScreen} />}
      {screen === "downloads"            && <Downloads />}
      {screen === "projects"             && <ProjectsPage setScreen={setScreen} />}
      {screen === "about"                && <About setScreen={setScreen} />}
      {screen === "design-capabilities"  && <DesignCapabilities setScreen={setScreen} />}
      {screen === "circular-economy"     && <CircularEconomy setScreen={setScreen} />}
      {screen === "distributors"         && <Distributors setScreen={setScreen} />}
      {screen.startsWith("policy-")      && <PolicyPage slug={screen.replace("policy-", "")} setScreen={setScreen} />}
      {screen === "moodboard"            && <Moodboard />}
      {screen.startsWith("project-") && window.getProject && window.getProject(screen) && <ProjectDetail slug={screen} setScreen={setScreen} />}
      </main>
      <Footer setScreen={setScreen} />
    </div>
  );
}

window.App = App;
