// industries/chrome.jsx — Shared chrome + section primitives for /industries pages.
// Exports to window: IndNav, IndFooter, IndHero, StatBand, ServiceGrid, HowWeWork,
//                    FeaturedEngagement, Insights, ClientStories, AdvisorStrip,
//                    ClosingCTA, IndustryPage.

const INDUSTRIES = [
  { slug: "energy",       name: "Energy",        desc: "Solar, wind, storage, geothermal.",       href: "energy"       },
  { slug: "data-centers", name: "Data centers",  desc: "Speed-to-power for AI infrastructure.",   href: "data-centers" },
  { slug: "real-estate",  name: "Commercial real estate",   desc: "Project services for owners and investors.", href: "real-estate"  },
];

/* ────────────────────────── HERO ────────────────────────── */
function IndHero({ eyebrow, title, lede, accent, sister }) {
  // sister: the two other industries to cross-link
  return (
    <section
      data-screen-label="01 Hero"
      style={{
        position: "relative",
        paddingTop: "26vh",
        paddingBottom: "10vh",
        overflow: "hidden",
        borderBottom: "1px solid var(--border)",
      }}>
      <div
        aria-hidden
        style={{
          position: "absolute", inset: 0, zIndex: 0, pointerEvents: "none",
          background:
            "radial-gradient(58% 50% at 92% 4%, rgba(229,162,105,0.16) 0%, transparent 55%)," +
            "radial-gradient(60% 50% at 0% 18%, rgba(40,60,100,0.32) 0%, transparent 55%)",
        }} />
      <div className="wrap" style={{ position: "relative", zIndex: 1 }}>
        <div style={{ display: "flex", gap: 14, alignItems: "center", marginBottom: 18, flexWrap: "wrap" }}>
          <span className="mono cap" style={{ color: "var(--accent)", letterSpacing: "0.14em", fontSize: 11 }}>
            Industries
          </span>
          <span className="mono" style={{ color: "var(--fg-3)" }}>/</span>
          <span className="eyebrow" style={{ color: "var(--fg-2)" }}>{eyebrow}</span>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "minmax(0, 1.55fr) minmax(0, 1fr)", gap: 80, alignItems: "end" }}>
          <h1 className="display" style={{
            fontSize: "clamp(48px, 6.4vw, 92px)",
            lineHeight: 1.02,
            letterSpacing: "-0.02em",
            margin: 0,
            maxWidth: 980,
          }}>
            {title}
          </h1>
          <div style={{ paddingBottom: 8 }}>
            <p className="lede" style={{ maxWidth: 460, fontSize: "clamp(16px, 1.15vw, 19px)" }}>
              {lede}
            </p>
            <div style={{ marginTop: 28 }}>
              <a href="../contact" className="btn">
                Let&rsquo;s talk
                <span className="arrow" aria-hidden>→</span>
              </a>
            </div>
          </div>
        </div>
        {/* Sister-industry pills */}
        {sister && sister.length > 0 && (
          <div style={{
            marginTop: 64, paddingTop: 22,
            borderTop: "1px solid var(--border)",
            display: "flex", gap: 16, alignItems: "center", flexWrap: "wrap",
          }}>
            <span className="mono cap" style={{ color: "var(--fg-3)" }}>Also in industries</span>
            {sister.map((s) => (
              <a key={s.href} href={s.href} className="mono"
                style={{
                  fontSize: 12, color: "var(--fg-2)", letterSpacing: "0.04em",
                  padding: "8px 14px",
                  border: "1px solid var(--border-2)", borderRadius: 999,
                  transition: "color .2s, border-color .2s, background .2s",
                  display: "inline-flex", alignItems: "center", gap: 8,
                }}
                onMouseEnter={(e) => {
                  e.currentTarget.style.color = "var(--fg)";
                  e.currentTarget.style.borderColor = "var(--border-strong)";
                  e.currentTarget.style.background = "rgba(229,162,105,0.05)";
                }}
                onMouseLeave={(e) => {
                  e.currentTarget.style.color = "var(--fg-2)";
                  e.currentTarget.style.borderColor = "var(--border-2)";
                  e.currentTarget.style.background = "transparent";
                }}>
                {s.name}
                <span aria-hidden style={{ color: "var(--accent)" }}>→</span>
              </a>
            ))}
          </div>
        )}
      </div>
    </section>
  );
}

/* ────────────────────────── STAT BAND ────────────────────────── */
function StatBand({ items, footnote }) {
  return (
    <section className="tight" data-screen-label="02 Stat band"
      style={{ borderBottom: "1px solid var(--border)", padding: "84px 0" }}>
      <div className="wrap">
        <div style={{
          display: "grid",
          gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))`,
        }}>
          {items.map(([n, label], i) => (
            <div key={i} style={{
              padding: "12px 32px 8px 0",
              borderRight: i < items.length - 1 ? "1px solid var(--border)" : "none",
              display: "flex", flexDirection: "column", gap: 22,
            }}>
              <div className="num-serif" style={{
                fontSize: "clamp(52px, 6.6vw, 108px)",
                color: "var(--fg)",
                lineHeight: 1.0,
                letterSpacing: "-0.025em",
                whiteSpace: "nowrap",
              }}>
                {n}
              </div>
              <div className="mono" style={{
                fontSize: 12, color: "var(--fg-2)",
                lineHeight: 1.5, maxWidth: 280,
                letterSpacing: "0.01em",
              }}>
                {label}
              </div>
            </div>
          ))}
        </div>
        {footnote && (
          <div className="mono" style={{
            marginTop: 36, fontSize: 11, color: "var(--fg-3)",
            letterSpacing: "0.03em", maxWidth: 760, lineHeight: 1.55,
          }}>
            {footnote}
          </div>
        )}
      </div>
    </section>
  );
}

/* ────────────────────────── SERVICE GRID (no-box) ────────────────────────── */
function ServiceCard({ n, title, body, href }) {
  const [hover, setHover] = React.useState(false);
  return (
    <a href={href}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        padding: "40px 36px 36px",
        borderRight: "1px solid var(--border)",
        borderBottom: "1px solid var(--border)",
        display: "flex", flexDirection: "column", gap: 18,
        minHeight: 360,
        position: "relative",
        background: hover ? "rgba(229,162,105,0.03)" : "transparent",
        transition: "background .25s ease",
        color: "var(--fg)",
      }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
        <span className="num-serif" style={{
          fontSize: 24, color: "var(--accent)", lineHeight: 1,
        }}>
          {n}
        </span>
        <span aria-hidden className="mono" style={{
          fontSize: 10, color: hover ? "var(--accent)" : "var(--fg-3)",
          letterSpacing: "0.14em",
          transition: "color .25s",
        }}>
          ⌁
        </span>
      </div>
      <div className="display" style={{
        fontSize: 24, letterSpacing: "-0.01em", lineHeight: 1.18,
      }}>
        {title}
      </div>
      <p style={{
        margin: 0, fontSize: 14.5, lineHeight: 1.6,
        color: "var(--fg-2)",
      }}>
        {body}
      </p>
      <div style={{ flex: 1 }} />
      <div style={{
        display: "inline-flex", alignItems: "center", gap: 8,
        fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: "0.12em",
        textTransform: "uppercase",
        color: hover ? "var(--accent)" : "var(--fg-2)",
        transition: "color .25s",
        marginTop: 4,
      }}>
        Read more
        <span aria-hidden style={{
          transform: hover ? "translateX(4px)" : "translateX(0)",
          transition: "transform .25s",
        }}>→</span>
      </div>
    </a>
  );
}

function ServiceGrid({ headline, intro, cards }) {
  return (
    <section data-screen-label="03 Services">
      <div className="wrap">
        <div style={{
          display: "grid", gridTemplateColumns: "minmax(0, 1.05fr) minmax(0, 1fr)",
          gap: 80, alignItems: "end", marginBottom: 64,
        }}>
          <h2 className="display display-2" style={{ maxWidth: 760 }}>
            {headline}
          </h2>
          <p className="muted" style={{ fontSize: 16, lineHeight: 1.6, maxWidth: 480, margin: 0 }}>
            {intro}
          </p>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: "repeat(3, minmax(0, 1fr))",
          borderTop: "1px solid var(--border)",
          borderLeft: "1px solid var(--border)",
        }}>
          {cards.map((c, i) => (
            <ServiceCard
              key={i}
              n={String(i + 1).padStart(2, "0")}
              title={c.title}
              body={c.body}
              href={c.href || "../contact"}
            />
          ))}
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── HOW WE WORK ────────────────────────── */
function HowWeWork({ items }) {
  return (
    <section data-screen-label="04 How we work" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <div style={{ marginBottom: 56, maxWidth: 720 }}>
          <span className="eyebrow">How we work</span>
          <h2 className="display display-2" style={{ marginTop: 18 }}>
            Where AI agents end and human judgment begins.
          </h2>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))`,
          gap: 0,
          borderTop: "1px solid var(--border-2)",
        }}>
          {items.map((it, i) => (
            <div key={i} style={{
              padding: "36px 32px 24px 0",
              borderRight: i < items.length - 1 ? "1px solid var(--border)" : "none",
              paddingLeft: i === 0 ? 0 : 32,
            }}>
              <div className="num-serif" style={{ fontSize: 28, color: "var(--accent)", marginBottom: 18 }}>
                {String(i + 1).padStart(2, "0")}
              </div>
              <div className="display" style={{
                fontSize: 22, letterSpacing: "-0.005em",
                marginBottom: 14, lineHeight: 1.22,
              }}>
                {it.title}
              </div>
              <p style={{
                margin: 0, fontSize: 14.5, lineHeight: 1.6,
                color: "var(--fg-2)", maxWidth: 380,
              }}>
                {it.body}
              </p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── FEATURED ENGAGEMENT (optional) ────────────────────────── */
function FeaturedEngagement({ eyebrow, title, body, meta }) {
  return (
    <section data-screen-label="05 Featured engagement">
      <div className="wrap">
        <div style={{
          padding: "56px 56px 52px",
          border: "1px solid var(--border-2)",
          borderRadius: 4,
          background: "linear-gradient(180deg, rgba(229,162,105,0.05) 0%, rgba(229,162,105,0) 100%)",
          position: "relative",
          overflow: "hidden",
        }}>
          <div aria-hidden style={{
            position: "absolute", inset: 0,
            background: "radial-gradient(60% 80% at 95% 50%, rgba(229,162,105,0.10) 0%, transparent 60%)",
            pointerEvents: "none",
          }} />
          <div style={{
            display: "grid", gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1.4fr)",
            gap: 64, alignItems: "start", position: "relative",
          }}>
            <div>
              <span className="eyebrow" style={{ color: "var(--accent)" }}>{eyebrow}</span>
              {meta && meta.length > 0 && (
                <div style={{ marginTop: 28, display: "flex", flexDirection: "column", gap: 14 }}>
                  {meta.map(([k, v], i) => (
                    <div key={i} style={{
                      display: "grid", gridTemplateColumns: "100px 1fr", gap: 16,
                      paddingTop: 12, borderTop: "1px solid var(--border)",
                    }}>
                      <span className="mono cap" style={{ color: "var(--fg-3)" }}>{k}</span>
                      <span style={{ fontSize: 14, color: "var(--fg)" }}>{v}</span>
                    </div>
                  ))}
                </div>
              )}
            </div>
            <div>
              <h2 className="display" style={{
                fontSize: "clamp(34px, 4vw, 52px)",
                lineHeight: 1.06, letterSpacing: "-0.015em",
                marginTop: 0, marginBottom: 24, maxWidth: 720,
              }}>
                {title}
              </h2>
              <p style={{
                fontSize: 17, lineHeight: 1.6, color: "var(--fg-2)",
                margin: 0, maxWidth: 620,
              }}>
                {body}
              </p>
              <div style={{ marginTop: 32 }}>
                <a href="../contact" className="btn">
                  Read more
                  <span className="arrow" aria-hidden>→</span>
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── INSIGHTS ────────────────────────── */
function Insights({ items }) {
  return (
    <section data-screen-label="06 Insights">
      <div className="wrap">
        <div style={{
          display: "flex", justifyContent: "space-between", alignItems: "end",
          marginBottom: 48, gap: 32, flexWrap: "wrap",
        }}>
          <div>
            <span className="eyebrow">Insights</span>
            <h2 className="display display-3" style={{ marginTop: 14, maxWidth: 640 }}>
              From the people doing the work.
            </h2>
          </div>
          <a href="../contact" className="mono cap" style={{
            color: "var(--fg-2)", letterSpacing: "0.12em",
            display: "inline-flex", alignItems: "center", gap: 8,
          }}>
            All insights <span aria-hidden style={{ color: "var(--accent)" }}>→</span>
          </a>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))`,
          borderTop: "1px solid var(--border)",
        }}>
          {items.map((it, i) => (
            <a key={i} href="../contact" style={{
              padding: "32px 28px 28px 0",
              borderRight: i < items.length - 1 ? "1px solid var(--border)" : "none",
              paddingLeft: i === 0 ? 0 : 28,
              display: "flex", flexDirection: "column", gap: 18,
              minHeight: 280,
              color: "var(--fg)",
            }}>
              <div className="mono cap" style={{ color: "var(--accent)", fontSize: 10.5 }}>
                {it.kicker || "Briefing"}
              </div>
              <div className="display" style={{
                fontSize: 22, letterSpacing: "-0.01em", lineHeight: 1.2,
              }}>
                {it.title}
              </div>
              <p style={{
                margin: 0, fontSize: 14.5, lineHeight: 1.55,
                color: "var(--fg-2)",
              }}>
                {it.body}
              </p>
              <div style={{ flex: 1 }} />
              <span className="mono cap" style={{
                color: "var(--fg-3)", fontSize: 10.5, letterSpacing: "0.12em",
                display: "inline-flex", alignItems: "center", gap: 8,
              }}>
                Read brief <span aria-hidden style={{ color: "var(--accent)" }}>→</span>
              </span>
            </a>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── CLIENT STORIES ────────────────────────── */
function ClientStories({ items, placeholder }) {
  if (placeholder) {
    return (
      <section data-screen-label="07 Client stories" style={{ background: "var(--bg-2)" }}>
        <div className="wrap">
          <div style={{ marginBottom: 36 }}>
            <span className="eyebrow">Client stories</span>
            <h2 className="display display-3" style={{ marginTop: 14, maxWidth: 720 }}>
              {placeholder.headline || "More stories in flight."}
            </h2>
          </div>
          <div style={{
            padding: "44px 40px",
            border: "1px dashed var(--border-2)",
            borderRadius: 4,
            display: "flex", justifyContent: "space-between", alignItems: "center",
            gap: 32, flexWrap: "wrap",
          }}>
            <p className="muted" style={{ margin: 0, fontSize: 15, maxWidth: 640, lineHeight: 1.55 }}>
              {placeholder.body || "We publish client stories once they\u2019re cleared for share. Want yours featured?"}
            </p>
            <a href="../contact" className="mono cap" style={{
              color: "var(--accent)", letterSpacing: "0.12em",
              display: "inline-flex", alignItems: "center", gap: 8, whiteSpace: "nowrap",
            }}>
              Talk to the team <span aria-hidden>→</span>
            </a>
          </div>
        </div>
      </section>
    );
  }
  return (
    <section data-screen-label="07 Client stories" style={{ background: "var(--bg-2)" }}>
      <div className="wrap">
        <div style={{ marginBottom: 56, maxWidth: 720 }}>
          <span className="eyebrow">Client stories</span>
          <h2 className="display display-2" style={{ marginTop: 18 }}>
            Projects we&rsquo;ve moved forward.
          </h2>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))`,
          borderTop: "1px solid var(--border-2)",
        }}>
          {items.map((it, i) => (
            <div key={i} style={{
              padding: "36px 32px 32px 0",
              paddingLeft: i === 0 ? 0 : 32,
              borderRight: i < items.length - 1 ? "1px solid var(--border)" : "none",
              display: "flex", flexDirection: "column", gap: 18,
              minHeight: 320,
            }}>
              <div className="mono cap" style={{ color: "var(--accent)", fontSize: 10.5 }}>
                {it.tag || "Featured"}
              </div>
              <div className="display" style={{ fontSize: 26, letterSpacing: "-0.01em", lineHeight: 1.15 }}>
                {it.client}
              </div>
              {it.quote && (
                <p style={{
                  margin: 0,
                  fontFamily: "var(--font-display)",
                  fontStyle: "italic",
                  fontSize: 17, lineHeight: 1.45, color: "var(--fg-2)",
                  letterSpacing: "-0.005em",
                }}>
                  &ldquo;{it.quote}&rdquo;
                </p>
              )}
              {!it.quote && it.body && (
                <p style={{ margin: 0, fontSize: 14.5, lineHeight: 1.6, color: "var(--fg-2)" }}>
                  {it.body}
                </p>
              )}
              <div style={{ flex: 1 }} />
              {it.attribution && (
                <div style={{
                  paddingTop: 16, borderTop: "1px solid var(--border)",
                  display: "flex", flexDirection: "column", gap: 4,
                }}>
                  <div className="display" style={{ fontSize: 14, letterSpacing: "-0.005em" }}>
                    {it.attribution.name}
                  </div>
                  <div className="mono cap" style={{ color: "var(--fg-3)", fontSize: 10.5 }}>
                    {[it.attribution.role, it.attribution.org].filter(Boolean).join(" \u00b7 ")}
                  </div>
                </div>
              )}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── ADVISOR STRIP ────────────────────────── */
function AdvisorStrip({ advisors }) {
  return (
    <section data-screen-label="08 Trusted by" style={{ paddingTop: 96, paddingBottom: 96 }}>
      <div className="wrap">
        <div style={{ marginBottom: 48 }}>
          <span className="eyebrow">Trusted by</span>
          <h2 className="display display-3" style={{ marginTop: 14, maxWidth: 760 }}>
            Endorsed by operators who&rsquo;ve built these projects before.
          </h2>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: `repeat(${advisors.length}, minmax(0, 1fr))`,
          gap: 0,
          borderTop: "1px solid var(--border)",
        }}>
          {advisors.map((a, i) => (
            <div key={i} style={{
              padding: "28px 22px 24px 0",
              paddingLeft: i === 0 ? 0 : 22,
              borderRight: i < advisors.length - 1 ? "1px solid var(--border)" : "none",
              display: "flex", flexDirection: "column", gap: 14,
            }}>
              <div style={{
                width: 64, height: 64, borderRadius: 999, overflow: "hidden",
                border: "1px solid var(--border-strong)",
                background: "var(--surface)",
              }}>
                {a.photo ? (
                  <img src={a.photo} alt={a.name}
                    style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
                ) : (
                  <div style={{
                    width: "100%", height: "100%",
                    display: "flex", alignItems: "center", justifyContent: "center",
                    fontFamily: "var(--font-display)", fontSize: 22, color: "var(--fg-3)",
                  }}>
                    {a.name.split(" ").map((s) => s[0]).slice(0, 2).join("")}
                  </div>
                )}
              </div>
              <div className="display" style={{
                fontSize: 16, letterSpacing: "-0.005em", lineHeight: 1.22,
              }}>
                {a.name}
              </div>
              <div className="mono" style={{
                fontSize: 11.5, color: "var(--fg-2)", lineHeight: 1.5,
                letterSpacing: "0.01em",
              }}>
                {a.role}
                {a.org && (
                  <>
                    <br />
                    <span style={{ color: "var(--fg-3)" }}>{a.org}</span>
                  </>
                )}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── CLOSING CTA ────────────────────────── */
function ClosingCTA({ headline, subhead }) {
  return (
    <section data-screen-label="09 Closing"
      style={{
        position: "relative", overflow: "hidden",
        borderTop: "1px solid var(--border)",
      }}>
      <div aria-hidden style={{
        position: "absolute", inset: 0, zIndex: 0, pointerEvents: "none",
        background:
          "radial-gradient(50% 60% at 80% 100%, rgba(229,162,105,0.16) 0%, transparent 60%)," +
          "radial-gradient(40% 50% at 0% 0%, rgba(40,60,100,0.30) 0%, transparent 55%)",
      }} />
      <div className="wrap" style={{ position: "relative", zIndex: 1 }}>
        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 1.2fr) minmax(0, 1fr)",
          gap: 64, alignItems: "end",
        }}>
          <h2 className="display" style={{
            fontSize: "clamp(40px, 5.6vw, 84px)",
            letterSpacing: "-0.02em", lineHeight: 1.04,
            margin: 0, maxWidth: 880,
          }}>
            {headline}
          </h2>
          <div style={{ paddingBottom: 8 }}>
            <p className="lede" style={{ maxWidth: 480 }}>
              {subhead}
            </p>
            <div style={{ marginTop: 28 }}>
              <a href="../contact" className="btn">
                Let&rsquo;s talk
                <span className="arrow" aria-hidden>→</span>
              </a>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ────────────────────────── FOOTER ────────────────────────── */
function IndFooter() {
  return <buildq-footer></buildq-footer>;
}

/* ────────────────────────── INDUSTRY PAGE COMPOSER ────────────────────────── */
function IndustryPage(props) {
  const {
    slug,
    eyebrow, title, lede,
    stats, statsFootnote,
    servicesHeadline, servicesIntro, services,
    howWeWork,
    featured,        // optional { eyebrow, title, body, meta }
    insights,
    clientStories,   // { items: [...] } or { placeholder: {...} }
    advisors,
    closingHeadline, closingSubhead,
  } = props;

  const sister = INDUSTRIES.filter((i) => i.slug !== slug);

  return (
    <>
      <main>
        <IndHero
          eyebrow={eyebrow}
          title={title}
          lede={lede}
          sister={sister}
        />
        <StatBand items={stats} footnote={statsFootnote} />
        <ServiceGrid
          headline={servicesHeadline}
          intro={servicesIntro}
          cards={services}
        />
        <HowWeWork items={howWeWork} />
        {featured && <FeaturedEngagement {...featured} />}
        <Insights items={insights} />
        <ClientStories {...clientStories} />
        <AdvisorStrip advisors={advisors} />
        <ClosingCTA headline={closingHeadline} subhead={closingSubhead} />
      </main>
      <IndFooter />
    </>
  );
}

Object.assign(window, {
  IndNav, IndFooter, IndHero,
  StatBand, ServiceGrid, ServiceCard, HowWeWork,
  FeaturedEngagement, Insights, ClientStories,
  AdvisorStrip, ClosingCTA, IndustryPage, INDUSTRIES,
});
