// Viyu Partners — App shell + all page content (per build brief).
// Hash routing, navy editorial pages, copper accent, mono eyebrows.

const CWR = [
  { stage: "Crawl", body: "Audit your data sources, get them clean, standardized, and centralized so the foundation can support real decisions." },
  { stage: "Walk", body: "Build the reporting and operational visibility that proves the data is trustworthy and the workflows around it are stable." },
  { stage: "Run", body: "Deploy automation, agents, and machine learning on top of a foundation that can actually support them." },
];

// Full per-service copy (brief Section 07). `deliver` OR `special` (AI).
const SERVICE_DETAILS = {
  "workflow-automation": {
    line: "Service 01", title: "Workflow Automation",
    sub: "We rebuild the workflows that hold your business together so they run themselves.",
    whatItIs: "Workflow automation is the practice of taking the repeatable processes inside your business, the ones humans do today by hand, and rebuilding them so the system does them by default. Done well, it removes friction. Done badly, it adds new friction on top of the old.",
    deliver: "A documented process audit, a redesigned workflow architecture, integrations across the tools you already own, and a measurable reduction in operating friction, surfaced in time saved, errors eliminated, and revenue protected.",
  },
  "ai-agent-build": {
    line: "Service 02", title: "AI and Agent Build",
    sub: "Production AI agents built on a data foundation that can actually support them.",
    whatItIs: "AI and Agent Build is the practice of deploying autonomous systems inside your operating model. Not chatbots. Not demos. Agents that actually do work, on data that is actually ready for them.",
    special: {
      heading: "Where AI projects actually start",
      body: "Most AI projects fail because the data underneath them is not ready. Before we build agents or deploy models, we run applied research on your data sources and your workflows. We never start at run.",
      cards: CWR,
    },
  },
  "crm-implementation": {
    line: "Service 03", title: "CRM Implementation",
    sub: "CRM systems built around how your team actually sells, not how the vendor demos it.",
    whatItIs: "A CRM is only as useful as the operating model it reflects. Most CRMs fail because they get configured to match the vendor's demo, not the firm's selling motion. We configure them around the deal cycle, the qualification framework, and the reporting that actually matters.",
    deliver: "Platform selection, pipeline architecture, qualification fields and stages, reporting dashboards, integrations, and a rollout plan that gets the team to use it.",
  },
  "cybersecurity-api": {
    line: "Service 04", title: "Cybersecurity and API",
    sub: "Resilient infrastructure and clean integrations that scale without breaking.",
    whatItIs: "Two practices that sit next to each other, cybersecurity for the protection layer and API development for the integration layer. Both decide whether the rest of the operating system holds up under load and threat.",
    deliver: "Security audits, compliance posture work, API design and build, third party integrations, and the documentation to keep all of it maintainable.",
  },
  "managed-services-provider": {
    line: "Service 05", title: "Managed Services Provider",
    sub: "An outsourced IT function that runs the systems we built, every day.",
    whatItIs: "Managed Services is the ongoing operation of the systems that run your business. Endpoint management, identity, backup, monitoring, helpdesk. The function most SMBs cannot afford to staff internally.",
    deliver: "A defined service catalog, response and resolution SLAs, monthly reporting, and a single point of accountability across your stack.",
  },
  "development-partner": {
    line: "Service 06", title: "Development Partner",
    sub: "Embedded engineering and product talent that ships against your roadmap on a defined sprint cadence.",
    whatItIs: "A flexible engineering and product capability you can pull in when your internal team needs more throughput, or when you do not have an internal team yet. Embedded talent, sprint cadence, your roadmap.",
    deliver: "Senior engineers, product designers, and project leadership, embedded into your team, working against your backlog with the same discipline as your full time staff.",
  },
  "value-management-partnership": {
    line: "Service 07", title: "Value Management Partnership",
    sub: "An ongoing executive partnership that keeps Revenue, Cost, and Risk improving every quarter.",
    whatItIs: "The Value Management Partnership is the Drive phase, productized. A standing executive engagement where we stay close to the operating model after the build is done, and keep it improving against the metrics that matter.",
    deliver: "Quarterly business reviews, ongoing optimization work, an active backlog of revenue, cost, and risk initiatives, and a relationship that compounds over years instead of ending at handoff.",
  },
};
const SERVICE_ORDER = ["workflow-automation", "ai-agent-build", "crm-implementation", "cybersecurity-api", "managed-services-provider", "development-partner", "value-management-partnership"];

const MW = "var(--container-max)";
const arrow = (sz = 15) => <span style={{ display: "inline-flex" }} dangerouslySetInnerHTML={{ __html: lucide.createElement(lucide.ArrowRight, { width: sz, height: sz }).outerHTML }} />;
const mono = (s) => ({ fontFamily: "var(--font-mono)", letterSpacing: "0.16em", textTransform: "uppercase", ...s });

function PageHero({ eyebrow, title, sub, center = true }) {
  return (
    <div style={{ position: "relative", borderBottom: "1px solid var(--border-faint)", background: "var(--navy-900)" }}>
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "clamp(126px,13vw,168px) 24px clamp(72px,7vw,104px)", display: "flex", flexDirection: "column", alignItems: center ? "center" : "flex-start", textAlign: center ? "center" : "left" }}>
        <a href="#home" style={{ alignSelf: "flex-start", display: "inline-flex", alignItems: "center", gap: "8px", fontFamily: "var(--font-mono)", fontSize: "12px", letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--gray-400)", cursor: "pointer", marginBottom: "36px" }}
          onMouseEnter={(e) => (e.currentTarget.style.color = "#fff")} onMouseLeave={(e) => (e.currentTarget.style.color = "var(--gray-400)")}>
          <span style={{ display: "inline-flex" }} dangerouslySetInnerHTML={{ __html: lucide.createElement(lucide.ArrowLeft, { width: 14, height: 14 }).outerHTML }} />
          Back to Home
        </a>
        {eyebrow && <span style={mono({ fontSize: "13px", fontWeight: 500, color: "var(--copper-text)", marginBottom: "28px" })}>{eyebrow}</span>}
        <h1 style={{ fontSize: "clamp(38px, 6vw, 78px)", fontWeight: 700, letterSpacing: "var(--tracking-tighter)", lineHeight: 1.02, color: "#fff", maxWidth: "1000px", textWrap: "pretty" }}>{title}</h1>
        {sub && <p style={{ marginTop: "28px", fontSize: "clamp(18px,1.7vw,21px)", fontWeight: 300, color: "var(--gray-300)", maxWidth: "720px", lineHeight: 1.7 }}>{sub}</p>}
      </div>
    </div>
  );
}

// ---- Service detail -------------------------------------------------------
function ServiceDetailPage({ serviceKey, navigate }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  const active = serviceKey && SERVICE_DETAILS[serviceKey] ? serviceKey : SERVICE_ORDER[0];
  const svc = SERVICE_DETAILS[active];

  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow={svc.line} title={svc.title} sub={svc.sub} center={false} />
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "72px 24px 112px", display: "grid", gridTemplateColumns: "248px 1fr", gap: "56px", alignItems: "start" }} className="viyu-grid-collapse">
        {/* switcher */}
        <div style={{ display: "flex", flexDirection: "column", position: "sticky", top: "104px" }}>
          <div style={mono({ fontSize: "11px", color: "var(--gray-500)", marginBottom: "16px" })}>All services</div>
          {SERVICE_ORDER.map((k, i) => (
            <button key={k} onClick={() => navigate("service", k)} className="viyu-svc-link"
              style={{ textAlign: "left", padding: "12px 0", border: "none", borderTop: "1px solid var(--border-faint)", borderBottom: i === SERVICE_ORDER.length - 1 ? "1px solid var(--border-faint)" : "none", cursor: "pointer", background: "transparent", fontFamily: "var(--font-sans)", fontSize: "14px", lineHeight: 1.3, letterSpacing: "0.01em",
                color: k === active ? "#fff" : "var(--gray-400)", fontWeight: k === active ? 600 : 400, display: "flex", alignItems: "center", gap: "10px", transition: "color 0.2s var(--ease-out), padding-left 0.2s var(--ease-out)" }}>
              <span style={{ width: k === active ? "14px" : "0px", height: "1px", background: "var(--copper)", transition: "width 0.2s var(--ease-out)", flexShrink: 0 }}></span>
              {SERVICE_DETAILS[k].title}
            </button>
          ))}
        </div>

        <div style={{ maxWidth: "720px" }}>
          {/* What it is */}
          <div style={{ marginBottom: "56px" }}>
            <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "20px" })}>What it is</div>
            <p style={{ color: "var(--gray-200)", fontSize: "19px", fontWeight: 300, lineHeight: 1.7 }}>{svc.whatItIs}</p>
          </div>

          {/* What we deliver OR special (AI) */}
          {svc.deliver && (
            <div style={{ marginBottom: "56px" }}>
              <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "20px" })}>What we deliver</div>
              <p style={{ color: "var(--gray-300)", fontSize: "17px", fontWeight: 300, lineHeight: 1.7 }}>{svc.deliver}</p>
            </div>
          )}
          {svc.special && (
            <div style={{ marginBottom: "56px" }}>
              <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "20px" })}>{svc.special.heading}</div>
              <p style={{ color: "var(--gray-300)", fontSize: "17px", fontWeight: 300, lineHeight: 1.7, marginBottom: "28px" }}>{svc.special.body}</p>
              <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(180px,1fr))", gap: "1px", background: "var(--border-subtle)", border: "1px solid var(--border-subtle)" }}>
                {svc.special.cards.map((c) => (
                  <div key={c.stage} style={{ background: "var(--navy-850)", padding: "24px" }}>
                    <div style={{ fontWeight: 700, color: "#fff", fontSize: "17px", marginBottom: "10px" }}>{c.stage}</div>
                    <p style={{ color: "var(--gray-400)", fontSize: "13px", fontWeight: 300, lineHeight: 1.6 }}>{c.body}</p>
                  </div>
                ))}
              </div>
            </div>
          )}

          {/* How we engage */}
          <div style={{ marginBottom: "56px" }}>
            <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "20px" })}>How we engage</div>
            <p style={{ color: "var(--gray-300)", fontSize: "17px", fontWeight: 300, lineHeight: 1.7, marginBottom: "24px" }}>Every engagement runs through the Viyu approach. We diagnose before we design, design before we deploy, and stay in to drive the result.</p>
            <div style={{ display: "flex", flexWrap: "wrap", gap: "10px" }}>
              {window.PHASES.map((p) => (
                <span key={p.n} style={{ ...mono({ fontSize: "12px" }), color: "var(--gray-300)", border: "1px solid var(--border-strong)", borderRadius: "999px", padding: "8px 16px" }}>{p.n} {p.title}</span>
              ))}
            </div>
          </div>

          {/* CTA */}
          <div style={{ borderTop: "1px solid var(--border-subtle)", paddingTop: "48px" }}>
            <h2 style={{ color: "#fff", fontSize: "clamp(24px,3vw,34px)", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "24px" }}>Start with a Diagnose conversation.</h2>
            <Button variant="primary" icon={arrow()} onClick={() => navigate("book")}>Let's Connect, Book an Appointment</Button>
          </div>
        </div>
      </div>
    </div>
  );
}

// ---- Services overview ----------------------------------------------------
function ServicesOverviewPage({ navigate }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="Services" title="What we do." sub="Viyu Partners is a high conviction cross industry operating and technology partner for SMB and mid-market businesses. Seven service lines, one operating model." />
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "8px 24px 24px" }}>
        <div className="viyu-tilegrid" style={{ display: "grid", gridTemplateColumns: "repeat(4, minmax(0, 1fr))", gap: "1px", background: "var(--border-subtle)" }}>
          {window.SERVICES.map((s) => <window.ServiceTile key={s.key} s={s} navigate={navigate} />)}
          <button onClick={() => navigate("book")} style={{ textAlign: "left", cursor: "pointer", fontFamily: "var(--font-sans)", background: "var(--accent-soft)", border: "none", padding: "32px 28px", display: "flex", flexDirection: "column", justifyContent: "space-between", minHeight: "230px" }}>
            <span style={mono({ fontSize: "12px", fontWeight: 500, color: "var(--copper-text)" })}>08</span>
            <div>
              <h3 style={{ fontSize: "20px", fontWeight: 600, color: "#fff", marginBottom: "12px" }}>Not sure which fits.</h3>
              <span style={{ ...mono({ fontSize: "12px" }), color: "var(--copper-text)", display: "inline-flex", alignItems: "center", gap: "8px" }}>Start with Diagnose {arrow(13)}</span>
            </div>
          </button>
        </div>
      </div>
      <window.ApproachPreview navigate={navigate} full={true} />
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "96px 24px", textAlign: "center" }}>
        <h2 style={{ color: "#fff", fontSize: "clamp(26px,3.4vw,40px)", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "28px" }}>Not sure which service fits.</h2>
        <Button variant="primary" size="lg" icon={arrow(16)} onClick={() => navigate("book")}>Let's Connect, Book an Appointment</Button>
      </div>
    </div>
  );
}

// ---- About ----------------------------------------------------------------
const LEADERS = [
  { name: "Amit Rai", role: "Founder and CEO", focus: "Strategy, growth, and client value." },
  { name: "Sameet Rai", role: "Partner", focus: "Cybersecurity, compliance, and delivery oversight." },
  { name: "Anthony McCormick", role: "Partner", focus: "Solution architecture and technical standard." },
];
function Monogram({ name }) {
  const initials = name.split(" ").map((w) => w[0]).join("").slice(0, 2);
  return (
    <div style={{ width: "64px", height: "64px", borderRadius: "50%", border: "1px solid var(--border-copper)", background: "var(--accent-soft)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--copper-text)", fontFamily: "var(--font-mono)", fontSize: "18px", fontWeight: 500, letterSpacing: "0.04em" }}>{initials}</div>
  );
}

function AboutPage({ navigate }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  const sec = { maxWidth: MW, margin: "0 auto", padding: "0 24px" };
  const eyebrow = (t) => <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "20px" })}>{t}</div>;
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="About Viyu Partners" title="Built by an operator, run like an operator." sub="Viyu Partners is a Business Process Management firm and Managed Services Provider based in Jersey City, NJ, serving SMB and mid-market businesses across the Northeast. We install operating systems instead of selling projects, and we stay accountable to them long after the build is done." center={false} />

      {/* Founder bio */}
      <section style={{ padding: "96px 0", borderBottom: "1px solid var(--border-faint)" }}>
        <div style={{ ...sec, display: "grid", gridTemplateColumns: "minmax(0,0.8fr) minmax(0,1.2fr)", gap: "56px", alignItems: "start" }} className="viyu-grid-collapse">
          <div>{eyebrow("The founder")}<h2 style={{ color: "#fff", fontSize: "clamp(26px,3vw,38px)", fontWeight: 700, letterSpacing: "var(--tracking-tight)", lineHeight: 1.1 }}>Amit Rai</h2><p style={{ color: "var(--copper-text)", marginTop: "8px", fontFamily: "var(--font-mono)", fontSize: "13px", letterSpacing: "0.1em" }}>Founder and CEO</p></div>
          <div style={{ display: "flex", flexDirection: "column", gap: "20px" }}>
            <p style={{ color: "var(--gray-300)", fontSize: "18px", fontWeight: 300, lineHeight: 1.75 }}>
              Viyu Partners was founded by Amit Rai. Amit started his career at TEKsystems, first as a recruiter and then as an outside sales account manager, before moving into enterprise advisory and SaaS at Gartner, LinkedIn, Dataminr, and monday.com.
            </p>
            <p style={{ color: "var(--gray-300)", fontSize: "18px", fontWeight: 300, lineHeight: 1.75 }}>
              The firm is built on a simple premise: the best business operators are also the best business buyers. People who have sat on both sides of the table know exactly where projects break and where partnerships compound. That's why Viyu is built on relationships that get the job done.
            </p>
          </div>
        </div>
      </section>

      {/* How we operate: four phase methodology (per July 2026 handoff, Option A) */}
      <section style={{ padding: "96px 0", background: "var(--navy-850)" }}>
        <div style={sec}>
          {eyebrow("How we operate")}
          <div className="viyu-opergrid" style={{ display: "grid", gridTemplateColumns: "repeat(4, minmax(0, 1fr))", marginTop: "16px" }}>
            {[
              { phase: "Diagnose", body: "We start inside the work, not the org chart. We map how revenue moves, where cost hides, and where risk sits unmanaged, so every recommendation is grounded in what your operation actually does." },
              { phase: "Design", body: "We architect the fix before we build it. Workflows, systems, integrations, and controls are designed as one system, engineered around your team instead of forcing your team around a tool." },
              { phase: "Deploy", body: "We build and implement the work ourselves. No handoff to a vendor bench, no binder of recommendations left on your desk. The people who designed it are the people who ship it." },
              { phase: "Drive", body: "This is the phase most firms skip. We stay in the operation, running, measuring, and improving what we built, so the results compound instead of decaying after go-live." },
            ].map((p) => (
              <div key={p.phase} className="viyu-opercol">
                <h3 style={{ color: "#fff", fontSize: "22px", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "14px" }}>{p.phase}</h3>
                <p style={{ color: "var(--gray-300)", fontSize: "15px", fontWeight: 300, lineHeight: 1.7 }}>{p.body}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Advise, build, operate (addendum copy, verbatim) */}
      <section style={{ padding: "96px 0", borderBottom: "1px solid var(--border-faint)" }}>
        <div style={sec}>
          {eyebrow("One firm, one partnership")}
          <h2 style={{ color: "#fff", fontSize: "clamp(28px,3.4vw,44px)", fontWeight: 700, letterSpacing: "var(--tracking-tighter)", lineHeight: 1.08, maxWidth: "760px", marginBottom: "32px" }}>We advise, build, and operate, all under one roof.</h2>
          <div style={{ maxWidth: "760px", display: "flex", flexDirection: "column", gap: "20px", color: "var(--gray-300)", fontSize: "17px", fontWeight: 300, lineHeight: 1.75 }}>
            <p>We're a business process management firm, and what makes us different is that we're the only firm our clients will meet that advises, builds, and operates, all under one roof, and we're genuinely better at each piece because of where we come from.</p>
            <p>When we advise, you're not getting a junior analyst with a template. Our team spent years inside enterprise SaaS, consulting, and researching, advising, and selling into some of the most sophisticated operations in the world. We bring that enterprise discipline down to businesses that could never justify a Big Four invoice. So when we diagnose your business, we're asking the same questions a Fortune 500 gets asked, about your revenue, your costs, and your risk, and we put real numbers on the answers before we ever propose a thing.</p>
            <p>When we build, we don't hand the care of your business to just anyone. Every engagement gets senior specialists, people who've built APIs, security programs, and automation for enterprise environments, assembled specifically for your problem. You get the exact team your business needs.</p>
            <p>And when we operate, that's where we're truly alone. Almost every firm in our space is paid to finish, so they build, they hand off, and they disappear. We stay. We run what we build, we watch the numbers with you, and we keep tuning until the result shows up in your business, not just in a report.</p>
            <p>Why do we work this way? Because we came from the relationship side of this industry, not the transaction side. We've watched businesses get sold software they didn't need and strategies nobody stayed to execute. We built Viyu to be the opposite of that: one firm, one partnership, accountable for the outcome. Our clients aren't projects to us. The whole model only works if they win, and that's exactly how we want it.</p>
          </div>
        </div>
      </section>

      {/* Applied research deep */}
      <section style={{ padding: "96px 0" }}>
        <div style={sec}>
          {eyebrow("Applied research")}
          <h2 style={{ color: "#fff", fontSize: "clamp(28px,3.4vw,44px)", fontWeight: 700, letterSpacing: "var(--tracking-tighter)", lineHeight: 1.08, maxWidth: "760px", marginBottom: "28px" }}>How we think before we build.</h2>
          <p style={{ color: "var(--gray-300)", fontSize: "18px", fontWeight: 300, lineHeight: 1.75, maxWidth: "760px", marginBottom: "20px" }}>Every engagement starts with applied research. Applied research is the practice we run before we touch a workflow, a system, or an AI model. We start by mapping where your data actually lives, how clean it is, and what it can support today. That work runs across every service we offer and every industry we serve, because the underlying question is always the same, what is the business actually ready for.</p>
          <h3 style={{ color: "#fff", fontSize: "20px", fontWeight: 600, marginTop: "40px", marginBottom: "16px" }}>The crawl walk run model for AI.</h3>
          <p style={{ color: "var(--gray-300)", fontSize: "17px", fontWeight: 300, lineHeight: 1.75, maxWidth: "760px", marginBottom: "40px" }}>Most clients ask for AI before they have the data foundation to use it. We walk every AI conversation through three stages. Skipping crawl is the most common reason AI projects fail.</p>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(220px,1fr))", gap: "1px", background: "var(--border-subtle)", border: "1px solid var(--border-subtle)" }}>
            {CWR.map((c, i) => (
              <div key={c.stage} style={{ background: "var(--navy-850)", padding: "28px" }}>
                <div style={mono({ fontSize: "11px", color: "var(--copper-text)", marginBottom: "12px" })}>{"0" + (i + 1)}</div>
                <div style={{ fontWeight: 700, color: "#fff", fontSize: "19px", marginBottom: "10px" }}>{c.stage}</div>
                <p style={{ color: "var(--gray-400)", fontSize: "14px", fontWeight: 300, lineHeight: 1.6 }}>{c.body}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Why different + proof, relocated from the homepage (addendum S11) */}
      <window.WhyDifferentSection />
      <window.CaseStudiesSection />

      {/* Leadership */}
      <section style={{ padding: "96px 0", background: "var(--navy-850)" }}>
        <div style={sec}>
          {eyebrow("Leadership")}
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(260px,1fr))", gap: "24px" }}>
            {LEADERS.map((l) => (
              <div key={l.name} style={{ borderTop: "1px solid var(--border-strong)", paddingTop: "24px" }}>
                <Monogram name={l.name} />
                <h3 style={{ color: "#fff", fontSize: "20px", fontWeight: 600, marginTop: "20px" }}>{l.name}</h3>
                <p style={{ color: "var(--copper-text)", fontFamily: "var(--font-mono)", fontSize: "12px", letterSpacing: "0.08em", margin: "6px 0 12px" }}>{l.role}</p>
                <p style={{ color: "var(--gray-400)", fontSize: "15px", fontWeight: 300, lineHeight: 1.6 }}>{l.focus}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Closing */}
      <section style={{ padding: "112px 0", textAlign: "center" }}>
        <div style={sec}>
          <p style={mono({ fontSize: "13px", color: "var(--copper-text)", marginBottom: "24px" })}>Pathway from strategy to execution.</p>
          <Button variant="primary" size="lg" icon={arrow(16)} onClick={() => navigate("book")}>Let's Connect, Book an Appointment</Button>
        </div>
      </section>
    </div>
  );
}

// ---- Industries -----------------------------------------------------------
function IndustriesPage({ navigate }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="Industries Served" title="One firm. Every sector." sub="Viyu Partners is built to operate across industries because the underlying problems, revenue drag, cost leakage, operational friction, and unmanaged risk, look the same in every sector." center={false} />
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "8px 24px 24px" }}>
        <div style={{ borderLeft: "1px solid var(--border-subtle)", borderTop: "1px solid var(--border-subtle)" }}>
          {window.SECTORS.map((s, i) => (
            <div key={s.key} className="v-reveal" style={{ display: "grid", gridTemplateColumns: "300px 1fr", gap: "40px", padding: "40px 28px", borderBottom: "1px solid var(--border-subtle)", borderRight: "1px solid var(--border-subtle)", alignItems: "start" }}>
              <div style={{ display: "flex", alignItems: "baseline", gap: "16px" }}>
                <span style={mono({ fontSize: "12px", color: "var(--copper-text)" })}>{"0" + (i + 1)}</span>
                <h3 style={{ color: "#fff", fontSize: "23px", fontWeight: 700, letterSpacing: "var(--tracking-tight)", lineHeight: 1.15 }}>{s.title}</h3>
              </div>
              <p style={{ color: "var(--gray-300)", fontSize: "16px", fontWeight: 300, lineHeight: 1.7 }}>{s.body}</p>
            </div>
          ))}
        </div>
      </div>
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "80px 24px 112px", textAlign: "center" }}>
        <h2 style={{ color: "#fff", fontSize: "clamp(24px,3vw,36px)", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "28px" }}>Don't see your sector.</h2>
        <Button variant="primary" icon={arrow()} onClick={() => navigate("book")}>Let's Connect, Book an Appointment</Button>
      </div>
    </div>
  );
}

// ---- Insights -------------------------------------------------------------
const INSIGHT_CARDS = [
  "Inside Diagnose, Design, Deploy, Drive.",
  "How to audit your tech stack in 90 days.",
  "The case for one firm across every sector.",
];
function InsightsPage() {
  const { Button, Input } = window.ViyuPartnersDesignSystem_8838e3;
  const [sent, setSent] = React.useState(false);
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="Insights" title="Insights from the firm." sub="Field notes on revenue, cost, and risk for SMB and mid market operators. New writing, monthly." center={false} />
      {/* Email capture */}
      <section style={{ padding: "64px 0", borderBottom: "1px solid var(--border-faint)" }}>
        <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px" }}>
          <form onSubmit={(e) => { e.preventDefault(); setSent(true); }} style={{ display: "flex", gap: "12px", flexWrap: "wrap", maxWidth: "520px" }}>
            <div style={{ flex: "1 1 260px" }}><Input type="email" placeholder="Work email" aria-label="Work email" /></div>
            <Button variant="primary" onClick={(e) => { e.preventDefault(); setSent(true); }}>{sent ? "You're on the list" : "Notify me"}</Button>
          </form>
        </div>
      </section>
      {/* Placeholder cards */}
      <section style={{ padding: "72px 0 112px" }}>
        <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px", display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(300px,1fr))", gap: "1px", background: "var(--border-subtle)", border: "1px solid var(--border-subtle)" }}>
          {INSIGHT_CARDS.map((t) => (
            <div key={t} style={{ background: "var(--navy-900)", padding: "40px 32px", minHeight: "220px", display: "flex", flexDirection: "column" }}>
              <span style={{ ...mono({ fontSize: "11px" }), color: "var(--copper-text)", border: "1px solid var(--border-copper)", borderRadius: "999px", padding: "5px 12px", alignSelf: "flex-start", marginBottom: "28px" }}>Coming soon</span>
              <h3 style={{ color: "#fff", fontSize: "22px", fontWeight: 600, lineHeight: 1.3, letterSpacing: "var(--tracking-tight)", marginTop: "auto" }}>{t}</h3>
            </div>
          ))}
        </div>
      </section>
    </div>
  );
}

// ---- Contact --------------------------------------------------------------
// Submissions go to the lead-intake Lambda, which creates an item on the Monday
// board. The Monday token lives in that function, never in the browser.
// Source: github.com/arsrattan/viyu-lead-intake
const LEAD_INTAKE_ENDPOINT = "https://viyu-lead-intake.anmol-rattan.workers.dev";

// Success confirmation: modal shown once the Worker accepts the submission.
function SentDialog({ onClose }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  const panelRef = React.useRef(null);
  React.useEffect(() => {
    if (panelRef.current) panelRef.current.focus();
    const onKey = (e) => { if (e.key === "Escape") onClose(); };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [onClose]);
  return (
    <div onClick={onClose} style={{ position: "fixed", inset: 0, zIndex: 9000, background: "rgba(4,10,18,0.62)", backdropFilter: "blur(6px)", WebkitBackdropFilter: "blur(6px)", display: "flex", alignItems: "center", justifyContent: "center", padding: "24px" }}>
      <div ref={panelRef} tabIndex={-1} role="alertdialog" aria-modal="true" aria-labelledby="viyu-sent-title" aria-describedby="viyu-sent-body"
        onClick={(e) => e.stopPropagation()} className="viyu-fade-up"
        style={{ background: "var(--navy-850)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-lg)", padding: "clamp(32px,4.5vw,48px)", maxWidth: "440px", width: "100%", textAlign: "center", outline: "none", boxShadow: "var(--shadow-xl)" }}>
        <div style={{ width: "56px", height: "56px", margin: "0 auto 20px", borderRadius: "999px", border: "1px solid var(--border-copper)", display: "flex", alignItems: "center", justifyContent: "center" }}>
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" aria-hidden="true">
            <path d="M5 12.5l4.2 4.2L19 7" stroke="var(--copper)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
          </svg>
        </div>
        <h3 id="viyu-sent-title" style={{ color: "#fff", fontSize: "22px", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "10px" }}>Message sent.</h3>
        <p id="viyu-sent-body" style={{ color: "var(--gray-300)", fontSize: "15px", fontWeight: 300, lineHeight: 1.7, marginBottom: "28px" }}>We respond within one business day.</p>
        <Button variant="primary" onClick={onClose}>Done</Button>
      </div>
    </div>
  );
}

const EMPTY_FORM = { name: "", email: "", company: "", title: "", phone: "", link: "", message: "", hp_extra: "" };

// Dial codes for the phone field. A bare 10-digit US number submitted without
// +1 was parsed by Monday as +60 (Malaysia), so the country is now explicit.
const PHONE_COUNTRIES = [
  ["US", "+1"], ["CA", "+1"], ["MX", "+52"], ["GB", "+44"], ["IE", "+353"],
  ["DE", "+49"], ["FR", "+33"], ["ES", "+34"], ["IT", "+39"], ["NL", "+31"],
  ["AU", "+61"], ["NZ", "+64"], ["IN", "+91"], ["SG", "+65"], ["JP", "+81"],
  ["BR", "+55"], ["AE", "+971"], ["ZA", "+27"],
];
// Spinner shows at least this long, so a fast response still reads as "it did something".
const MIN_SENDING_MS = 2000;

function ContactForm({ source = "website" }) {
  const { Button, Input } = window.ViyuPartnersDesignSystem_8838e3;
  const [fields, setFields] = React.useState(EMPTY_FORM);
  const [phoneCountry, setPhoneCountry] = React.useState("US");
  // idle | sending | error
  const [status, setStatus] = React.useState("idle");
  const [error, setError] = React.useState("");
  const [sentOpen, setSentOpen] = React.useState(false);

  const set = (key) => (e) => setFields((prev) => ({ ...prev, [key]: e.target.value }));

  const submit = async (e) => {
    e.preventDefault();
    if (status === "sending") return;
    setStatus("sending");
    setError("");
    const started = Date.now();
    // Hold the spinner to MIN_SENDING_MS even when the network is faster.
    const settle = () => new Promise((r) => setTimeout(r, Math.max(0, MIN_SENDING_MS - (Date.now() - started))));
    // Make the dial code explicit unless the visitor already typed one.
    const dial = (PHONE_COUNTRIES.find(([iso]) => iso === phoneCountry) || ["US", "+1"])[1];
    const rawPhone = fields.phone.trim();
    const phone = rawPhone ? (rawPhone.startsWith("+") ? rawPhone : `${dial} ${rawPhone}`) : "";
    try {
      const res = await fetch(LEAD_INTAKE_ENDPOINT, {
        method: "POST",
        headers: { "content-type": "application/json" },
        body: JSON.stringify({ ...fields, phone, phone_country: phoneCountry, source }),
      });
      const body = await res.json().catch(() => ({}));
      if (!res.ok || !body.ok) throw new Error(body.error || "That did not go through. Please try again.");
      await settle();
      setFields(EMPTY_FORM);
      setStatus("idle");
      setSentOpen(true);
    } catch (err) {
      await settle();
      // A network failure lands here too, where err.message is unhelpful.
      setError(err instanceof TypeError ? "We could not reach the server. Please email hello@viyupartners.com." : err.message);
      setStatus("error");
    }
  };

  const sending = status === "sending";
  const spinner = (
    <svg width="15" height="15" viewBox="0 0 24 24" fill="none" aria-hidden="true" style={{ animation: "viyuLoaderSpin 0.8s linear infinite" }}>
      <circle cx="12" cy="12" r="9" stroke="currentColor" strokeOpacity="0.25" strokeWidth="2.5" />
      <path d="M12 3a9 9 0 0 1 9 9" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
    </svg>
  );

  return (
    <form onSubmit={submit} style={{ display: "flex", flexDirection: "column", gap: "16px" }}>
      <Input placeholder="Full name" aria-label="Full name" name="name" value={fields.name} onChange={set("name")} required disabled={sending} />
      <Input type="email" placeholder="Work email" aria-label="Work email" name="email" value={fields.email} onChange={set("email")} required disabled={sending} />
      <Input placeholder="Company" aria-label="Company" name="company" value={fields.company} onChange={set("company")} disabled={sending} />
      <Input placeholder="Title / role (optional)" aria-label="Title or role" name="title" value={fields.title} onChange={set("title")} disabled={sending} />
      <div style={{ display: "flex", gap: "12px" }}>
        <select aria-label="Country code" value={phoneCountry} onChange={(e) => setPhoneCountry(e.target.value)} disabled={sending}
          style={{ flex: "0 0 auto", padding: "16px 14px", background: "var(--surface-glass)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-lg)", color: "var(--white)", fontFamily: "var(--font-sans)", fontSize: "15px", outline: "none", cursor: "pointer" }}>
          {PHONE_COUNTRIES.map(([iso, dial]) => (
            <option key={iso} value={iso} style={{ background: "var(--navy-850)", color: "#fff" }}>{iso} {dial}</option>
          ))}
        </select>
        <div style={{ flex: 1 }}>
          <Input type="tel" placeholder="Phone (optional)" aria-label="Phone" name="phone" value={fields.phone} onChange={set("phone")} disabled={sending} />
        </div>
      </div>
      <Input placeholder="Website or LinkedIn (optional)" aria-label="Website or LinkedIn profile" name="link" value={fields.link} onChange={set("link")} disabled={sending} />
      <Input multiline rows={4} placeholder="How can we help" aria-label="How can we help" name="message" value={fields.message} onChange={set("message")} disabled={sending} />
      {/* Honeypot: hidden from people, tempting to bots that POST every field they find.
          Anything here is discarded server side. The name is deliberately meaningless —
          it was "website", which Chrome autofill and password managers fill for real
          humans (silently losing their lead). readOnly keeps autofill away entirely. */}
      <input type="text" name="hp_extra" tabIndex={-1} readOnly autoComplete="off" aria-hidden="true"
        data-lpignore="true" data-1p-ignore="true" data-bwignore="true" data-form-type="other"
        value={fields.hp_extra}
        style={{ position: "absolute", left: "-9999px", width: "1px", height: "1px", opacity: 0 }} />
      <Button variant="primary" fullWidth type="submit" disabled={sending} icon={sending ? spinner : undefined}>{sending ? "Sending…" : status === "error" ? "Try again" : "Send message"}</Button>
      <div role="status" aria-live="polite" style={{ minHeight: "20px", fontSize: "14px", lineHeight: 1.5, color: "var(--copper-text)" }}>
        {status === "error" ? error : ""}
      </div>
      {sentOpen && <SentDialog onClose={() => setSentOpen(false)} />}
    </form>
  );
}
function ContactInfo() {
  const row = (icon, text, href) => (
    <a href={href} style={{ display: "flex", alignItems: "center", gap: "12px", color: "var(--gray-200)", fontSize: "15px", cursor: href ? "pointer" : "default" }}>
      <span style={{ color: "var(--copper-text)", display: "inline-flex" }} dangerouslySetInnerHTML={{ __html: lucide.createElement(lucide[icon], { width: 18, height: 18 }).outerHTML }} />{text}
    </a>
  );
  return (
    <div style={{ background: "var(--navy-850)", border: "1px solid var(--border-subtle)", padding: "36px", display: "flex", flexDirection: "column", gap: "18px" }}>
      <div style={mono({ fontSize: "11px", color: "var(--gray-500)", marginBottom: "4px" })}>Direct</div>
      {row("Phone", "+1 (609) 977-0011", "tel:+16099770011")}
      {row("Mail", "hello@viyupartners.com", "mailto:hello@viyupartners.com")}
      {row("MapPin", "Jersey City, NJ", null)}
      {row("Linkedin", "LinkedIn", "#")}
    </div>
  );
}
function ContactPage({ navigate }) {
  const { Button } = window.ViyuPartnersDesignSystem_8838e3;
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="Contact" title="Let us talk." sub="Tell us where the friction is. We respond within one business day." center={false} />
      <section style={{ padding: "72px 0 96px" }}>
        <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px", display: "grid", gridTemplateColumns: "minmax(0,1.3fr) minmax(0,0.7fr)", gap: "48px", alignItems: "start" }} className="viyu-grid-collapse">
          <ContactForm source="contact-page" />
          <ContactInfo />
        </div>
      </section>
      <section style={{ padding: "80px 0 112px", borderTop: "1px solid var(--border-faint)", textAlign: "center" }}>
        <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px" }}>
          <h2 style={{ color: "#fff", fontSize: "clamp(24px,3vw,34px)", fontWeight: 700, letterSpacing: "var(--tracking-tight)", marginBottom: "28px" }}>Prefer to skip the form.</h2>
          <Button variant="primary" icon={arrow()} onClick={() => navigate("book")}>Let's Connect, Book an Appointment</Button>
        </div>
      </section>
    </div>
  );
}

// ---- Book -----------------------------------------------------------------
// Full booking section: final section of the homepage (addendum S9) and the body of the Book page.
function BookSection() {
  return (
    <section id="book" style={{ padding: "clamp(88px,10.5vw,164px) 0", background: "var(--navy-950)", borderTop: "1px solid var(--border-faint)" }}>
      <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px" }}>
        <div className="v-reveal" style={{ marginBottom: "clamp(40px,5vw,64px)", maxWidth: "760px" }}>
          <div style={mono({ fontSize: "12px", color: "var(--copper-text)", marginBottom: "24px" })}>Let's Connect</div>
          <h2 style={{ color: "#fff", fontSize: "clamp(30px,4.4vw,56px)", fontWeight: 700, letterSpacing: "var(--tracking-tighter)", lineHeight: 1.04, marginBottom: "20px" }}>Book an <em style={{ fontStyle: "italic", fontWeight: 400, color: "var(--copper-text)" }}>appointment.</em></h2>
          <p style={{ color: "var(--gray-300)", fontSize: "18px", fontWeight: 300, lineHeight: 1.7 }}>Most engagements begin with a Diagnose phase. A focused, scoped audit that tells you exactly where revenue, cost, and risk are sitting in your business today. We respond within one business day.</p>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "minmax(0,1.3fr) minmax(0,0.7fr)", gap: "48px", alignItems: "start" }} className="viyu-grid-collapse">
          <ContactForm source="home-book-section" />
          <ContactInfo />
        </div>
      </div>
    </section>
  );
}

function BookPage({ navigate }) {
  return (
    <div style={{ background: "var(--navy-900)", minHeight: "100vh" }}>
      <PageHero eyebrow="Let's Connect" title="Book an appointment." sub="A focused, scoped audit that tells you exactly where revenue, cost, and risk are sitting in your business today. We respond within one business day." center={false} />
      <section style={{ padding: "72px 0 112px" }}>
        <div style={{ maxWidth: MW, margin: "0 auto", padding: "0 24px", display: "grid", gridTemplateColumns: "minmax(0,1.3fr) minmax(0,0.7fr)", gap: "48px", alignItems: "start" }} className="viyu-grid-collapse">
          <ContactForm source="book-page" />
          <ContactInfo />
        </div>
      </section>
    </div>
  );
}

// ---- App ------------------------------------------------------------------
function routeFromHash() {
  var h = (window.location.hash || "").replace(/^#/, "");
  if (!h) return { page: "home", arg: null };
  if (h.indexOf("service-") === 0) return { page: "service", arg: h.slice(8) };
  return { page: h, arg: null };
}
function hashForRoute(page, arg) { return page === "service" ? "service-" + arg : page; }

const PAGE_TITLES = {
  home: "Viyu Partners | Business Process Management and Managed Services, Jersey City NJ",
  about: "About Viyu Partners | Built by an Operator",
  services: "Services | Viyu Partners",
  industries: "Industries Served | Viyu Partners",
  insights: "Insights | Viyu Partners",
  book: "Let's Connect, Book an Appointment | Viyu Partners",
  contact: "Contact | Viyu Partners",
};

function App() {
  const [route, setRoute] = React.useState(routeFromHash());
  const scrollRef = React.useRef(null);

  // Hash-driven routing: navigate() pushes a real history entry, so the
  // browser back/forward buttons work normally (addendum S10.3).
  React.useEffect(() => {
    const onHash = () => {
      setRoute(routeFromHash());
      if (scrollRef.current) scrollRef.current.scrollTo({ top: 0 });
    };
    window.addEventListener("hashchange", onHash);
    return () => window.removeEventListener("hashchange", onHash);
  }, []);

  React.useEffect(() => {
    document.title = PAGE_TITLES[route.page] || (route.page === "service" && SERVICE_DETAILS[route.arg] ? SERVICE_DETAILS[route.arg].title + " | Viyu Partners" : PAGE_TITLES.home);
  }, [route]);

  const navigate = (page, arg = null) => {
    const h = hashForRoute(page, arg);
    if ((window.location.hash || "#").replace(/^#/, "") === h) {
      if (scrollRef.current) scrollRef.current.scrollTo({ top: 0 });
    } else {
      window.location.hash = h;
    }
  };
  window.viyuGo = navigate;

  let content;
  if (route.page === "home") content = <React.Fragment><window.Hero navigate={navigate} /><window.HomeContent navigate={navigate} /><BookSection /></React.Fragment>;
  else if (route.page === "service") content = <ServiceDetailPage serviceKey={route.arg} navigate={navigate} />;
  else if (route.page === "services") content = <ServicesOverviewPage navigate={navigate} />;
  else if (route.page === "about") content = <AboutPage navigate={navigate} />;
  else if (route.page === "industries") content = <IndustriesPage navigate={navigate} />;
  else if (route.page === "insights") content = <InsightsPage navigate={navigate} />;
  else if (route.page === "book") content = <BookPage navigate={navigate} />;
  else content = <React.Fragment><window.Hero navigate={navigate} /><window.HomeContent navigate={navigate} /><BookSection /></React.Fragment>;

  return (
    <div id="viyu-scroll" ref={scrollRef} style={{ height: "100vh", overflowY: "auto", background: "var(--navy-900)", position: "relative" }}>
      <window.Navbar page={route.page} navigate={navigate} />
      {content}
      <window.Footer navigate={navigate} />
    </div>
  );
}

Object.assign(window, { App, ServiceDetailPage, ServicesOverviewPage, AboutPage, IndustriesPage, InsightsPage, BookPage, BookSection, PageHero, SERVICE_DETAILS, SERVICE_ORDER });
