/* Services, Pricing, About, Partners, Contact pages */

const { useState, useEffect } = React;
const { navigate } = window;

/* ──────── Services ──────── */
const ServicesPage = () => {
  const disciplines = [
  {
    id: "web",
    title: "Web Development",
    lead: "Sites that load fast, rank well, and convert.",
    body: "From a single-page lead magnet to a multi-page corporate platform with a CMS your team can actually use — we build it, test it on Core Web Vitals, and hand it over with a playbook.",
    points: [
    "Marketing sites, landing pages, and product sites",
    "Headless CMS integrations (Sanity, Payload, Strapi)",
    "E-commerce builds on Shopify or custom stacks",
    "Progressive Web Apps for offline-capable experiences"],

    stack: ["Next.js", "Astro", "Tailwind", "Sanity", "Vercel"],
    icon: "web"
  },
  {
    id: "app",
    title: "App Development",
    lead: "Mobile apps that feel native on day one.",
    body: "Cross-platform builds with Flutter when velocity matters; fully-native when the experience demands it. Authentication, payments, push, offline sync — we've shipped them all.",
    points: [
    "iOS & Android, one codebase, zero compromises",
    "Auth, payments, push notifications & in-app purchase",
    "Offline-first architectures for real-world usage",
    "App Store & Play Store submission and review support"],

    stack: ["Flutter", "Supabase", "RevenueCat", "Resend", "Paystack"],
    icon: "app"
  },
  {
    id: "game",
    title: "Game Development",
    lead: "From prototype to playable release.",
    body: "2D and 3D games for mobile, web, and desktop. We work with clients from napkin-sketch to alpha, handle the engine heavy-lifting, and stay on through launch and LiveOps.",
    points: [
    "Unity and Godot for 2D & 3D experiences",
    "Gameplay systems, economies, and progression design",
    "Multiplayer & backend (matchmaking, leaderboards)",
    "LiveOps, events, and post-launch content pipelines"],

    stack: ["Unity", "Godot", "C#", "GDScript", "PlayFab"],
    icon: "game"
  }];



  return (
    <>
      <section style={{ padding: "140px 0 60px" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ Services</div>
          <h1 className="display" style={{ fontSize: "clamp(56px, 10vw, 160px)", margin: 0, lineHeight: 0.92, letterSpacing: "-0.025em", maxWidth: "14ch", fontFamily: "Roboto" }}>
            Everything you need to <em style={{ fontStyle: "italic", fontWeight: 400 }}>launch</em>.
          </h1>
          <p style={{ fontSize: 19, color: "var(--muted)", maxWidth: "60ch", marginTop: 32 }}>
            Three disciplines, one team. We stay tight on scope, ship weekly, and stick around after launch. Everything below has a fixed price and a fixed timeline — no surprises.
          </p>
        </div>
      </section>

      {disciplines.map((d, i) =>
      <section key={d.id} id={d.id} className="reveal" style={{
        padding: "80px 0",
        background: i % 2 ? "var(--paper-2)" : "var(--paper)",
        borderTop: "1px solid var(--line)"
      }}>
          <div className="wrap">
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1.4fr", gap: 80, alignItems: "start" }} className="disc-grid">
              <div style={{ position: "sticky", top: 100 }} className="disc-left">
                <div style={{ marginBottom: 24 }}><ServiceIcon kind={d.icon} height={56} /></div>
                <div className="mono" style={{ fontSize: 12, letterSpacing: "0.14em", color: "var(--muted)", marginBottom: 10 }}>0{i + 1} / 03</div>
                <h2 className="display" style={{ fontSize: "clamp(48px, 6vw, 84px)", margin: "0 0 20px", lineHeight: 0.95, fontFamily: "Roboto" }}>{d.title}</h2>
                <p style={{ fontSize: 20, color: "var(--ink-2)", margin: 0 }}>{d.lead}</p>
              </div>
              <div>
                <p style={{ fontSize: 17, lineHeight: 1.6, marginTop: 0 }}>{d.body}</p>
                <div className="eyebrow" style={{ margin: "32px 0 14px" }}>What we ship</div>
                <ul style={{ listStyle: "none", padding: 0, margin: 0, borderTop: "1px solid var(--line)" }}>
                  {d.points.map((p, j) =>
                <li key={j} style={{ padding: "16px 0", borderBottom: "1px solid var(--line)", display: "flex", gap: 16, alignItems: "start", fontSize: 16 }}>
                      <span className="mono" style={{ fontSize: 11, color: "var(--muted)", paddingTop: 4 }}>/ {String(j + 1).padStart(2, "0")}</span>
                      {p}
                    </li>
                )}
                </ul>
                <div className="eyebrow" style={{ margin: "32px 0 14px" }}>Typical stack</div>
                <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
                  {d.stack.map((s) =>
                <span key={s} className="mono" style={{ fontSize: 12, padding: "8px 14px", borderRadius: 999, border: "1px solid var(--ink)", background: "transparent" }}>{s}</span>
                )}
                </div>
              </div>
            </div>
          </div>
          <style>{`
            @media (max-width: 900px) {
              .disc-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
              .disc-left { position: static !important; }
            }
          `}</style>
        </section>
      )}

      <section style={{ padding: "120px 0", background: "var(--ink)", color: "var(--paper)" }}>
        <div className="wrap" style={{ textAlign: "center" }}>
          <h2 className="display" style={{ fontSize: "clamp(40px, 6vw, 80px)", margin: "0 0 20px", lineHeight: 1, fontFamily: "Roboto" }}>
            Need something else?
          </h2>
          <p style={{ color: "rgba(246,244,239,0.7)", fontSize: 18, maxWidth: "54ch", margin: "0 auto 32px" }}>
            Internal tools, dashboards, integrations, Chrome extensions, AI-assisted workflows — if it runs on code, we can probably build it. Tell us the problem.
          </p>
          <a href="#/contact" onClick={(e) => {e.preventDefault();navigate("contact");}} className="btn btn-accent">
            Get a quote →
          </a>
        </div>
      </section>
    </>);

};

/* ──────── Pricing ──────── */
const PRICING = [
{
  tier: "The Lead Magnet",
  sub: "Landing Page",
  price: "€500",
  days: "5 working days",
  outcome: "A high-conversion, single-page \"sales machine\".",
  perfect: "Product launches, campaigns, startups needing an immediate digital presence.",
  features: [
  "1 custom-designed content page",
  "Mobile-first responsive design",
  "Form with smart lead validation",
  "Basic SEO + Google Analytics",
  "1 round of revisions"]

},
{
  tier: "The Growth Hub",
  sub: "SMB Website",
  price: "€750",
  days: "10 working days",
  outcome: "A 3–5 page ecosystem that builds trust 24/7.",
  perfect: "Established small-to-medium businesses automating authority and lead gen.",
  features: [
  "3 – 5 custom content pages",
  "Mobile-first responsive design",
  "Contact forms with validation",
  "Advanced on-page SEO",
  "Google Analytics setup",
  "2 rounds of revisions",
  "1 week post-launch support"],

  featured: true
},
{
  tier: "Authority Suite",
  sub: "Corporate Website",
  price: "€1,500",
  days: "15 working days",
  outcome: "A robust 5–10 page platform built for long-term dominance.",
  perfect: "Businesses that need scale, content control, and maximum visibility.",
  features: [
  "5 – 10 custom content pages",
  "Integrated CMS to manage content",
  "Authority blog setup",
  "Advanced on-page SEO",
  "Contact forms with validation",
  "Google Analytics setup",
  "3 rounds of revisions",
  "1 month post-launch support"]

}];


const KPIS = [
{ n: "01", t: "Speed-to-Market", d: "Most agencies take 6–8 weeks. We launch in 15 days or less — without cutting corners." },
{ n: "02", t: "Performance Guarantee", d: "Every site is audited for Core Web Vitals. Fast sites rank better and convert better." },
{ n: "03", t: "Clean Code Policy", d: "Lightweight, responsive, semantic. Google loves it and your users feel the difference." }];


const PricingPage = () => {
  return (
    <>
      <section style={{ padding: "140px 0 40px" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ Digital Solutions Suite</div>
          <h1 className="display" style={{ fontSize: "clamp(56px, 10vw, 160px)", margin: 0, lineHeight: 0.92, letterSpacing: "-0.025em", fontFamily: "Roboto" }}>
            Fixed price.<br />Fixed timeline.<br /><em style={{ fontStyle: "italic", fontWeight: 400 }}>Zero surprises.</em>
          </h1>
          <p style={{ fontSize: 19, color: "var(--muted)", maxWidth: "58ch", marginTop: 32 }}>
            High-performance web development for scalable growth. Every package includes custom design — no generic templates — and every timeline is a commitment, not an estimate.
          </p>
        </div>
      </section>

      <section style={{ padding: "40px 0 80px" }}>
        <div className="wrap">
          <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }} className="price-grid">
            {PRICING.map((p, i) =>
            <article key={p.tier} className="reveal" style={{
              border: "1px solid var(--ink)",
              borderRadius: 20,
              padding: 32,
              background: p.featured ? "var(--ink)" : "var(--paper)",
              color: p.featured ? "var(--paper)" : "var(--ink)",
              display: "flex",
              flexDirection: "column",
              gap: 24,
              position: "relative",
              transitionDelay: `${i * 80}ms`
            }}>
                {p.featured &&
              <span style={{ position: "absolute", top: -13, left: 32, background: "var(--accent)", color: "var(--ink)", border: "1px solid var(--ink)", padding: "4px 12px", borderRadius: 999, fontFamily: "var(--f-mono)", fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase" }}>
                    Most Popular
                  </span>
              }
                <div>
                  <div className="mono" style={{ fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase", opacity: 0.6, marginBottom: 8 }}>{p.sub}</div>
                  <h3 className="display" style={{ fontSize: 36, margin: 0, lineHeight: 1, fontFamily: "Roboto" }}>{p.tier}</h3>
                </div>
                <div>
                  <div className="display" style={{ fontSize: 64, lineHeight: 1, letterSpacing: "-0.02em", fontFamily: "Roboto" }}>{p.price}</div>
                  <div className="mono" style={{ fontSize: 12, opacity: 0.6, letterSpacing: "0.1em", textTransform: "uppercase", marginTop: 4 }}>{p.days}</div>
                </div>
                <p style={{ fontSize: 15, margin: 0, opacity: 0.85 }}>{p.outcome}</p>
                <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10, borderTop: "1px solid", borderColor: p.featured ? "rgba(246,244,239,0.2)" : "var(--line)", paddingTop: 20 }}>
                  {p.features.map((f, j) =>
                <li key={j} style={{ display: "flex", gap: 12, fontSize: 14, alignItems: "start" }}>
                      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" strokeWidth="3" style={{ marginTop: 3, flexShrink: 0 }}><path d="M20 6 9 17l-5-5" /></svg>
                      {f}
                    </li>
                )}
                </ul>
                <div style={{ marginTop: "auto", display: "flex", flexDirection: "column", gap: 12 }}>
                  <div style={{ fontSize: 12, opacity: 0.6 }}>
                    <strong style={{ fontWeight: 600, opacity: 1 }}>Perfect for:</strong> {p.perfect}
                  </div>
                  <a href="#/contact" onClick={(e) => {e.preventDefault();navigate("contact");}} className={p.featured ? "btn btn-accent" : "btn btn-primary"} style={{ justifyContent: "center" }}>
                    Start this project →
                  </a>
                </div>
              </article>
            )}
          </div>
        </div>
        <style>{`
          @media (max-width: 980px) { .price-grid { grid-template-columns: 1fr !important; } }
        `}</style>
      </section>

      <section style={{ padding: "80px 0", background: "var(--paper-2)", borderTop: "1px solid var(--line)", borderBottom: "1px solid var(--line)" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ Why choose us</div>
          <h2 className="display" style={{ fontSize: "clamp(40px, 6vw, 72px)", margin: "0 0 48px", lineHeight: 0.95, fontFamily: "Roboto" }}>Unique KPIs you can hold us to.</h2>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 0, borderTop: "1px solid var(--ink)" }} className="kpi-grid">
            {KPIS.map((k, i) =>
            <div key={k.n} style={{ padding: "32px 28px 32px 0", borderRight: i < 2 ? "1px solid var(--line)" : "none", paddingLeft: i > 0 ? 28 : 0 }}>
                <div className="mono" style={{ color: "var(--accent)", fontSize: 12, letterSpacing: "0.14em", marginBottom: 20, background: "var(--ink)", display: "inline-block", padding: "6px 10px", borderRadius: 4 }}>{k.n}</div>
                <h3 className="display" style={{ fontSize: 32, margin: "0 0 12px", lineHeight: 1, fontFamily: "Roboto" }}>{k.t}</h3>
                <p style={{ color: "var(--muted)", fontSize: 15, margin: 0 }}>{k.d}</p>
              </div>
            )}
          </div>
        </div>
        <style>{`
          @media (max-width: 820px) {
            .kpi-grid { grid-template-columns: 1fr !important; }
            .kpi-grid > * { border-right: none !important; padding-left: 0 !important; border-bottom: 1px solid var(--line); }
            .kpi-grid > *:last-child { border-bottom: none; }
          }
        `}</style>
      </section>

      <section style={{ padding: "80px 0" }}>
        <div className="wrap">
          <div style={{ background: "var(--ink)", color: "var(--paper)", borderRadius: 24, padding: "56px 48px", display: "grid", gridTemplateColumns: "1.6fr 1fr", gap: 32, alignItems: "center" }} className="oop-cta">
            <div>
              <div className="eyebrow" style={{ color: "rgba(246,244,239,0.5)", marginBottom: 14 }}>▸ Out of scope?</div>
              <h3 className="display" style={{ fontSize: "clamp(32px, 4.5vw, 56px)", margin: "0 0 16px", lineHeight: 0.95, fontFamily: "Roboto" }}>
                Apps, games, or something bigger than a website?
              </h3>
              <p style={{ color: "rgba(246,244,239,0.7)", fontSize: 17, margin: 0, maxWidth: "56ch" }}>
                Mobile apps, games, custom platforms and integrations are priced per project. Tell us what you're building and we'll come back with a quote within 48 hours.
              </p>
            </div>
            <a href="#/contact" onClick={(e) => {e.preventDefault();navigate("contact");}} className="btn btn-accent" style={{ justifySelf: "end" }}>
              Contact us for a quote →
            </a>
          </div>
        </div>
        <style>{`
          @media (max-width: 820px) { .oop-cta { grid-template-columns: 1fr !important; } .oop-cta > a { justify-self: start !important; } }
        `}</style>
      </section>
    </>);

};

/* ──────── About ──────── */
const AboutPage = () => {
  const values = [
  { t: "Fixed scope, fixed price", d: "You get a number and a timeline — not a time-and-materials black hole." },
  { t: "Ship weekly, show weekly", d: "We demo every week. You always know what's built and what's next." },
  { t: "Stay on after launch", d: "One week to one month of hand-holding is built into every package." },
  { t: "No generic templates", d: "Every site is custom-designed. Every line of code earns its place." }];

  return (
    <>
      <section style={{ padding: "140px 0 60px" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ About M2 Tech</div>
          <h1 className="display" style={{ fontSize: "clamp(56px, 10vw, 160px)", margin: 0, lineHeight: 0.92, letterSpacing: "-0.025em", maxWidth: "12ch", fontFamily: "Roboto" }}>
            A small studio<br />that ships <em style={{ fontStyle: "italic", fontWeight: 400 }}>a lot</em>.
          </h1>
        </div>
      </section>

      <section style={{ padding: "40px 0 80px" }}>
        <div className="wrap">


            <div>
              <p style={{ fontSize: 22, lineHeight: 1.5, margin: "0 0 20px", color: "var(--ink-2)" }}>
                M2 Tech is a compact studio of engineers and designers. We build apps, websites and games for founders, agencies and operators who need it done right — and done quickly.
              </p>
              <p style={{ fontSize: 17, lineHeight: 1.6, color: "var(--muted)", margin: 0 }}>
                We started because the industry has a trust problem. Too many agencies promise the moon, charge like it, and deliver a template. We wanted to build the opposite: small scopes, fixed prices, weekly demos, and a real human on the other side of the conversation. So far so good.
              </p>
            </div>

        </div>
        <style>{`
          @media (max-width: 900px) { .about-grid { grid-template-columns: 1fr !important; gap: 32px !important; } }
        `}</style>
      </section>

      <section style={{ padding: "80px 0", background: "var(--paper-2)", borderTop: "1px solid var(--line)" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ What we stand for</div>
          <h2 className="display" style={{ fontSize: "clamp(40px, 6vw, 72px)", margin: "0 0 48px", lineHeight: 0.95, fontFamily: "Roboto" }}>Four rules we don't break.</h2>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 0, borderTop: "1px solid var(--ink)" }} className="val-grid">
            {values.map((v, i) =>
            <div key={i} style={{ padding: "32px 40px 32px 0", paddingLeft: i % 2 ? 40 : 0, borderRight: i % 2 === 0 ? "1px solid var(--line)" : "none", borderBottom: i < 2 ? "1px solid var(--line)" : "none" }}>
                <div className="mono" style={{ fontSize: 12, letterSpacing: "0.14em", color: "var(--muted)", marginBottom: 14 }}>0{i + 1}</div>
                <h3 className="display" style={{ fontSize: 32, margin: "0 0 10px", lineHeight: 1, fontFamily: "Roboto" }}>{v.t}</h3>
                <p style={{ color: "var(--muted)", fontSize: 15, margin: 0 }}>{v.d}</p>
              </div>
            )}
          </div>
        </div>
        <style>{`
          @media (max-width: 720px) {
            .val-grid { grid-template-columns: 1fr !important; }
            .val-grid > * { border-right: none !important; padding-left: 0 !important; border-bottom: 1px solid var(--line) !important; }
            .val-grid > *:last-child { border-bottom: none !important; }
          }
        `}</style>
      </section>

      <window.CtaBlock />
    </>);

};

/* ──────── Partners ──────── */
/*
  Drop a partner logo into  assets/partners/  and set `logo` to its path
  (transparent PNG/SVG works best). Leave `logo` empty to use the
  generated monogram tile instead.
*/
const PARTNERS = [
{
  name: "Digital Productions Marketing House",
  short: "Digital Productions",
  role: "Marketing & Brand",
  url: "https://dpmh.co.za/",
  logo: "", // e.g. "assets/partners/dpmh.png"
  accent: "#9AAFFF",
  blurb:
  "A full-service digital marketing studio. They handle strategy, SEO, social, and graphic & web design — the growth engine that gets the products we build in front of the right audience."
},];


const Monogram = ({ p }) => {
  const initials = p.short.split(" ").map((w) => w[0]).join("").slice(0, 2).toUpperCase();
  return (
    <div style={{
      width: 72, height: 72, borderRadius: 16, flexShrink: 0,
      background: p.accent, color: "var(--ink)",
      display: "inline-flex", alignItems: "center", justifyContent: "center",
      fontFamily: "var(--f-display)", fontWeight: 700, fontSize: 28,
      border: "1px solid var(--ink)"
    }}>
      {initials}
    </div>);

};

const PartnersPage = () => {
  return (
    <>
      <section style={{ padding: "140px 0 60px" }}>
        <div className="wrap">
          <div className="eyebrow" style={{ marginBottom: 20 }}>▸ Partners</div>
          <h1 className="display" style={{ fontSize: "clamp(56px, 10vw, 160px)", margin: 0, lineHeight: 0.92, letterSpacing: "-0.025em", maxWidth: "13ch", fontFamily: "Roboto" }}>
            Better together, <em style={{ fontStyle: "italic", fontWeight: 400 }}>by design</em>.
          </h1>
          <p style={{ fontSize: 19, color: "var(--muted)", maxWidth: "60ch", marginTop: 32 }}>
            We don't try to be everything. We partner with specialists we trust — so clients get the right team for marketing, sport, and beyond, all under one roof.
          </p>
        </div>
      </section>

      <section style={{ padding: "20px 0 80px" }}>
        <div className="wrap">
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 24 }} className="partner-grid">
            {PARTNERS.map((p, i) =>
            <a
              key={p.name}
              href={p.url}
              target="_blank"
              rel="noreferrer"
              className="reveal partner-card"
              style={{
                position: "relative",
                display: "flex",
                flexDirection: "column",
                gap: 24,
                background: "var(--paper-2)",
                border: "1px solid var(--line)",
                borderRadius: 22,
                padding: 36,
                minHeight: 320,
                overflow: "hidden",
                transition: "transform 0.3s var(--ease), border-color 0.3s var(--ease)",
                transitionDelay: `${i * 90}ms`,
                color: "var(--ink)"
              }}
              onMouseEnter={(e) => {e.currentTarget.style.transform = "translateY(-4px)";e.currentTarget.style.borderColor = "var(--ink)";}}
              onMouseLeave={(e) => {e.currentTarget.style.transform = "";e.currentTarget.style.borderColor = "var(--line)";}}>

                {/* accent wash */}
                <div aria-hidden="true" style={{
                position: "absolute", top: -80, right: -80, width: 220, height: 220, borderRadius: "50%",
                background: p.accent, opacity: 0.18, filter: "blur(8px)", pointerEvents: "none"
              }} />

                <div style={{ position: "relative", display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16 }}>
                  {p.logo ?
                <div style={{ width: 72, height: 72, borderRadius: 16, background: "var(--paper)", border: "1px solid var(--line)", display: "inline-flex", alignItems: "center", justifyContent: "center", overflow: "hidden", flexShrink: 0 }}>
                      <img src={p.logo} alt={p.name} style={{ width: "78%", height: "78%", objectFit: "contain" }} />
                    </div> :

                <Monogram p={p} />
                }
                  <span className="mono" style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", padding: "6px 12px", borderRadius: 999, border: "1px solid var(--line)", color: "var(--muted)" }}>
                    {p.role}
                  </span>
                </div>

                <div style={{ position: "relative" }}>
                  <h2 className="display" style={{ fontSize: "clamp(28px, 3.4vw, 40px)", margin: "0 0 12px", lineHeight: 1, fontFamily: "Roboto" }}>{p.short}</h2>
                  <p style={{ fontSize: 16, lineHeight: 1.55, color: "var(--ink-2)", margin: 0, maxWidth: "46ch" }}>{p.blurb}</p>
                </div>

                <span style={{ position: "relative", marginTop: "auto", display: "inline-flex", alignItems: "center", gap: 10, fontWeight: 600, fontSize: 14 }}>
                  Visit {p.short}
                  <span style={{ width: 34, height: 34, borderRadius: 999, background: "var(--accent)", color: "var(--ink)", display: "inline-flex", alignItems: "center", justifyContent: "center" }}>
                    <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M7 17L17 7M7 7h10v10" /></svg>
                  </span>
                </span>
              </a>
            )}
          </div>
        </div>
        <style>{`
          @media (max-width: 820px) { .partner-grid { grid-template-columns: 1fr !important; } }
        `}</style>
      </section>

      {/* become a partner */}
      <section style={{ padding: "20px 0 100px" }}>
        <div className="wrap">
          <div style={{ background: "var(--ink)", color: "var(--paper)", borderRadius: 24, padding: "56px 48px", display: "grid", gridTemplateColumns: "1.6fr 1fr", gap: 32, alignItems: "center" }} className="partner-cta">
            <div>
              <div className="eyebrow" style={{ color: "rgba(246,244,239,0.5)", marginBottom: 14 }}>▸ Work with us</div>
              <h3 className="display" style={{ fontSize: "clamp(32px, 4.5vw, 60px)", margin: "0 0 16px", lineHeight: 0.95, fontFamily: "Roboto" }}>
                Want to partner<br />with M2 Tech?
              </h3>
              <p style={{ color: "rgba(246,244,239,0.7)", fontSize: 17, margin: 0, maxWidth: "54ch" }}>
                Agencies, studios and brands that need engineering muscle behind their ideas — let's talk about building something together.
              </p>
            </div>
            <a href="#/contact" onClick={(e) => {e.preventDefault();navigate("contact");}} className="btn btn-accent" style={{ justifySelf: "end" }}>
              Become a partner →
            </a>
          </div>
        </div>
        <style>{`
          @media (max-width: 820px) { .partner-cta { grid-template-columns: 1fr !important; } .partner-cta > a { justify-self: start !important; } }
        `}</style>
      </section>
    </>);

};

/* ──────── Contact ──────── */
/*
  Submits to the Supabase Edge Function `contact`, which emails the team
  inbox via Resend. Point CONTACT_ENDPOINT at your deployed function:
    https://<your-project-ref>.supabase.co/functions/v1/contact
  (function code: supabase/functions/contact/index.ts · setup: SETUP-resend.md)
*/
const CONTACT_ENDPOINT = "https://fgqbcsnahaigvycybfkt.supabase.co/functions/v1/contact";

const SERVICES = [
{ value: "website", label: "Website Development" },
{ value: "app", label: "App Development" },
{ value: "game", label: "Game Development" },
{ value: "other", label: "Other Services" }];


const ContactPage = () => {
  const empty = { name: "", email: "", phone: "", service: "", budget: "", message: "", consent: false, hp_field: "" };
  const [form, setForm] = useState(empty);
  const [errors, setErrors] = useState({});
  const [status, setStatus] = useState("idle"); // idle | sending | sent

  const set = (k) => (e) => {
    const v = e.target.type === "checkbox" ? e.target.checked : e.target.value;
    setForm((f) => ({ ...f, [k]: v }));
    setErrors((er) => ({ ...er, [k]: undefined }));
  };

  const validate = () => {
    const er = {};
    if (!form.name.trim()) er.name = "This field is required";
    if (!form.email.trim()) er.email = "This field is required";
    else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email)) er.email = "Please enter a valid email address";
    if (!form.service) er.service = "Please choose a service";
    if (!form.message.trim()) er.message = "This field is required";
    if (!form.consent) er.consent = "Please accept the privacy policy";
    return er;
  };

  const submit = async (e) => {
    e.preventDefault();
    const er = validate();
    setErrors(er);
    if (Object.keys(er).length) return;

    setStatus("sending");
    try {
      const res = await fetch(CONTACT_ENDPOINT, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(form)
      });

      if (res.status === 422) {
        // server-side validation — surface the same errors on the fields
        const body = await res.json().catch(() => ({}));
        setStatus("idle");
        setErrors(body.errors || { form: "Please check the highlighted fields." });
        return;
      }
      if (!res.ok) throw new Error("Request failed with status " + res.status);

      setStatus("sent");
      setForm(empty);
    } catch (err) {
      setStatus("idle");
      setErrors({ form: "Something went wrong sending your message. Please try again, or email support@m2-tech.co.za directly." });
    }
  };

  const Err = ({ name }) =>
  errors[name] ?
  <span style={{ color: "#E5484D", fontSize: 12, marginTop: 2 }}>{errors[name]}</span> :
  null;

  return (
    <section style={{ padding: "140px 0 80px" }}>
      <div className="wrap">
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1.1fr", gap: 80 }} className="contact-grid">
          {/* left — info */}
          <div>
            <div className="eyebrow" style={{ marginBottom: 20 }}>▸ Contact</div>
            <h1 className="display" style={{ fontSize: "clamp(48px, 8vw, 120px)", margin: "0 0 24px", lineHeight: 0.92, letterSpacing: "-0.025em", fontFamily: "Roboto" }}>
              Get in touch.
            </h1>
            <p style={{ fontSize: 19, color: "var(--muted)", margin: "0 0 40px", maxWidth: "44ch" }}>
              Ready to start your project? Send us a brief and we'll get back to you within 24 hours with next steps.
            </p>

            <div style={{ display: "flex", flexDirection: "column", gap: 20, borderTop: "1px solid var(--line)", paddingTop: 32 }}>
              <div>
                <div className="eyebrow" style={{ marginBottom: 6 }}>Email</div>
                <a href="mailto:support@m2-tech.co.za" className="display" style={{ fontSize: 24, color: "var(--ink)", textDecoration: "underline", textDecorationColor: "var(--accent)", textDecorationThickness: 4, textUnderlineOffset: 6, fontFamily: "Roboto" }}>
                  support@m2-tech.co.za
                </a>
              </div>
              <div>
                <div className="eyebrow" style={{ marginBottom: 6 }}>Website</div>
                <a href="https://m2-tech.co.za" target="_blank" rel="noreferrer" style={{ fontSize: 17, color: "var(--ink)" }}>m2-tech.co.za ↗</a>
              </div>
              <div>
                <div className="eyebrow" style={{ marginBottom: 6 }}>Response time</div>
                <div style={{ fontSize: 17 }}>Within 24 working hours. Usually faster.</div>
              </div>
            </div>

            <div style={{ marginTop: 32, borderTop: "1px solid var(--line)", paddingTop: 32 }}>
              <div className="eyebrow" style={{ marginBottom: 14 }}>Business hours</div>
              <div style={{ display: "flex", flexDirection: "column", gap: 8, fontSize: 15 }}>
                <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--muted)" }}>Monday – Friday</span><span style={{ fontWeight: 600 }}>9:00 – 18:00</span></div>
                <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--muted)" }}>Saturday</span><span style={{ fontWeight: 600 }}>10:00 – 16:00</span></div>
                <div style={{ display: "flex", justifyContent: "space-between" }}><span style={{ color: "var(--muted)" }}>Sunday</span><span style={{ fontWeight: 600 }}>Closed</span></div>
              </div>
            </div>
          </div>

          {/* right — form */}
          <div style={{ background: "var(--paper-2)", border: "1px solid var(--line)", borderRadius: 20, padding: 32 }}>
            {status === "sent" ?
            <div style={{ textAlign: "center", padding: "60px 20px" }}>
                <div style={{ width: 72, height: 72, borderRadius: 999, background: "var(--accent)", margin: "0 auto 24px", display: "inline-flex", alignItems: "center", justifyContent: "center" }}>
                  <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="var(--ink)" strokeWidth="3"><path d="M20 6 9 17l-5-5" /></svg>
                </div>
                <h3 className="display" style={{ fontSize: 36, margin: "0 0 12px", fontFamily: "Roboto" }}>Message sent!</h3>
                <p style={{ color: "var(--muted)", maxWidth: "36ch", margin: "0 auto" }}>
                  Thank you for reaching out. We'll get back to you within 24 hours.
                </p>
                <button onClick={() => setStatus("idle")} className="btn btn-ghost" style={{ marginTop: 24 }}>
                  Send another →
                </button>
              </div> :

            <form onSubmit={submit} noValidate style={{ display: "flex", flexDirection: "column", gap: 18 }}>
                <h3 className="display" style={{ fontSize: 28, margin: "0 0 4px", fontFamily: "Roboto" }}>Send us a message</h3>

                {/* honeypot — hidden from people AND autofill; only bots fill it.
                    No label + display:none + neutral name keeps password managers away. */}
                <div aria-hidden="true" style={{ display: "none" }}>
                  <input
                    type="text"
                    name="hp_field"
                    tabIndex={-1}
                    autoComplete="off"
                    value={form.hp_field}
                    onChange={set("hp_field")}
                  />
                </div>

                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }} className="cf-row">
                  <div className="field">
                    <label>Your name *</label>
                    <input value={form.name} onChange={set("name")} placeholder="Your name" style={errors.name ? { borderColor: "#E5484D" } : undefined} />
                    <Err name="name" />
                  </div>
                  <div className="field">
                    <label>Email address *</label>
                    <input type="email" value={form.email} onChange={set("email")} placeholder="you@company.com" style={errors.email ? { borderColor: "#E5484D" } : undefined} />
                    <Err name="email" />
                  </div>
                </div>

                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }} className="cf-row">
                  <div className="field">
                    <label>Phone (optional)</label>
                    <input type="tel" value={form.phone} onChange={set("phone")} placeholder="+27 …" />
                  </div>
                  <div className="field">
                    <label>Service interested in *</label>
                    <select value={form.service} onChange={set("service")} style={errors.service ? { borderColor: "#E5484D", color: form.service ? "var(--ink)" : "var(--muted)" } : { color: form.service ? "var(--ink)" : "var(--muted)" }}>
                      <option value="" disabled>Choose a service…</option>
                      {SERVICES.map((s) => <option key={s.value} value={s.value} style={{ color: "var(--ink)" }}>{s.label}</option>)}
                    </select>
                    <Err name="service" />
                  </div>
                </div>

                <div className="field">
                  <label>Project budget (optional)</label>
                  <input value={form.budget} onChange={set("budget")} placeholder="e.g. €750, or not sure yet" />
                </div>

                <div className="field">
                  <label>Your message *</label>
                  <textarea value={form.message} onChange={set("message")} placeholder="Tell us what you're building, who it's for, and when you'd like it live." style={errors.message ? { borderColor: "#E5484D" } : undefined} />
                  <Err name="message" />
                </div>

                <label style={{ display: "flex", gap: 12, alignItems: "flex-start", fontSize: 13, color: "var(--muted)", cursor: "pointer" }}>
                  <input type="checkbox" checked={form.consent} onChange={set("consent")} style={{ width: 18, height: 18, marginTop: 2, accentColor: "var(--ink)", flexShrink: 0 }} />
                  <span>I agree to the processing of my personal data so M2 Tech can contact me about my project.</span>
                </label>
                <Err name="consent" />

                {errors.form && <span style={{ color: "#E5484D", fontSize: 13 }}>{errors.form}</span>}

                <button type="submit" disabled={status === "sending"} className="btn btn-primary" style={{ justifyContent: "center", opacity: status === "sending" ? 0.85 : 1 }}>
                  {status === "sending" ?
                <span style={{ display: "inline-flex", alignItems: "center", gap: 10 }}>
                      <span className="cf-spinner" /> Sending…
                    </span> :

                <span style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>Send message →</span>
                }
                </button>
              </form>
            }
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) {
          .contact-grid { grid-template-columns: 1fr !important; gap: 48px !important; }
        }
        @media (max-width: 480px) {
          .cf-row { grid-template-columns: 1fr !important; }
        }
        .cf-spinner {
          width: 16px; height: 16px; border-radius: 999px;
          border: 2px solid rgba(246,244,239,0.35); border-top-color: var(--paper);
          display: inline-block; animation: cf-spin 0.7s linear infinite;
        }
        @keyframes cf-spin { to { transform: rotate(360deg); } }
      `}</style>
    </section>);

};

Object.assign(window, { ServicesPage, PricingPage, AboutPage, PartnersPage, ContactPage });