// ═══════════════════════════════════════════════════════════
// Leftshifted - Homepage
// ═══════════════════════════════════════════════════════════

const serviceItems = [
  { title: 'Strategy', desc: 'Expert commercial to technical translation - the clarity, the priorities, and how to move forward.' },
  { title: 'Data', desc: 'The end-to-end technical expertise you need on the ground, built to last.' },
  { title: 'AI', desc: 'Get models and agents into production, and keep them there.' },
  { title: 'Cloud', desc: 'The infrastructure and rigour you need to keep everything running.' },
];

const ServiceAccordion = () => {
  const [active, setActive] = useState(0);
  return (
    <div className="service-accordion">
      {serviceItems.map((item, i) => {
        const isActive = active === i;
        return (
          <div
            key={i}
            className={`service-accordion__item ${isActive ? 'is-active' : ''}`}
            onClick={() => setActive(isActive ? -1 : i)}
          >
            <div className="service-accordion__head">
              <span style={{ font: '600 18px/1 var(--font-display)', letterSpacing: '-0.02em' }}>{item.title}</span>
              <span style={{ font: '400 20px/1 var(--font-display)', opacity: 0.6 }}>{isActive ? '×' : '+'}</span>
            </div>
            {isActive && (
              <p style={{ font: 'var(--type-body-sm)', color: 'var(--fg-muted)', marginTop: 12 }}>{item.desc}</p>
            )}
          </div>
        );
      })}
    </div>
  );
};

const HomeFAQ = () => {
  const [openIdx, setOpenIdx] = useState(0);
  return (
    <div className="home-faq-list">
      {defaultFaqItems.map((item, i) => {
        const isOpen = openIdx === i;
        return (
          <div
            key={i}
            className={`home-faq-item ${isOpen ? 'is-open' : ''}`}
            onClick={() => setOpenIdx(isOpen ? -1 : i)}
          >
            <div className="home-faq-item__head">
              <img
                src={isOpen ? res('assets/brand/icon-close.png') : res('assets/brand/icon-plus.png')}
                alt="" style={{ width: 28, height: 28, flexShrink: 0 }}
              />
              <span>{item.q}</span>
            </div>
            {isOpen && (
              <p className="home-faq-item__answer" style={{ whiteSpace: 'pre-line' }}>{item.a}</p>
            )}
          </div>
        );
      })}
    </div>
  );
};

const whyCardItems = [
  { title: 'Spend', desc: 'A bad senior data hire can cost £150-300k before you\'ve realised it isn\'t working.\n\nYou need to oversee a team of contractors and can easily run £250k with no guaranteed ROI.\n\nBig firms cost even more and juniors learn on your time to take longer and deliver less.' },
  { title: 'Time', desc: 'Six months into a platform build and the business still can\'t answer basic questions.' },
  { title: 'Opportunity', desc: 'The commercial value sitting in your data compounds every month you leave it untapped.' },
  { title: 'Competition', desc: 'Your competitors are already leveraging AI while you debate architecture.' },
];

const WhyGrid = () => (
  <div className="why-grid">
    {whyCardItems.map((card, i) => (
      <div key={i} className={`why-grid-item ${i === 0 ? 'why-grid-item--lg' : ''}`}>
        {i === 0 && (
          <div style={{
            position: 'absolute', right: 0, top: 0, bottom: 0, width: '55%',
            backgroundImage: `url("${res('assets/brand/why-card-graphic.png')}")`,
            backgroundSize: 'cover', backgroundPosition: 'center',
            borderRadius: '0 20px 20px 0', opacity: 0.5,
          }}></div>
        )}
        <div style={{ position: 'relative', zIndex: 1 }}>
          <h4 style={{
            font: i === 0 ? '600 28px/1.1 var(--font-display)' : 'var(--type-h3)',
            letterSpacing: 'var(--tracking-h)',
            color: i === 0 ? '#fff' : 'var(--fg-default)',
          }}>{card.title}</h4>
          <p style={{
            font: 'var(--type-body-sm)', marginTop: i === 0 ? 16 : 10,
            color: i === 0 ? 'rgba(255,255,255,.85)' : 'var(--fg-muted)',
            maxWidth: 'none', whiteSpace: 'pre-line',
          }}>{card.desc}</p>
        </div>
      </div>
    ))}
  </div>
);

const HomePage = () => {
  const [activeTab, setActiveTab] = useState(0);
  const [isMobile, setIsMobile] = useState(() => window.matchMedia('(max-width: 900px)').matches);
  useEffect(() => {
    const mq = window.matchMedia('(max-width: 900px)');
    const on = (e) => setIsMobile(e.matches);
    mq.addEventListener('change', on);
    return () => mq.removeEventListener('change', on);
  }, []);

  const industries = [
    { name: 'PR & Comms', desc: 'Measure what matters, prove what works.', detail: 'PR firms are sitting on more data than they know what to do with.\n\nBut analyst work doesn\'t scale. Clients ask for more insight, faster, with more granularity than manual work allows.\n\nThe firms that are set up to make sense of and adapt to their clients needs at pace, will lead the market - on what they can offer clients, on margin, on competitive position.\n\nWe understand the commercial model, we know the workflow, and we\'ve loved delivering award-winning products to prove it.', items: ['Media impact measurement', 'Audience intelligence', 'Campaign attribution', 'Competitive benchmarking'], img: res('assets/imagery/pr-comms-pipeline-crop.png'), stat: '£10M+ in incr. ARR' },
  ];

  const insights = [
    { date: '06 May 2026', read: '4 min read', title: 'How to choose your first AI use-case without setting fire to a budget.', bg: 'var(--ls-ultramarine-blue)' },
    { date: '21 Apr 2026', read: '6 min read', title: '"Durable" data: what we mean, and why it matters more than your stack.', bg: 'var(--ls-midnight-navy)' },
    { date: '02 Apr 2026', read: '3 min read', title: 'An honest assessment of your data, in two weeks.', bg: 'var(--ls-blue-10)' },
  ];

  const ind = industries[activeTab];

  return (
    <PageShell current="/">
      {/* ── HERO ───────────────────────────────── */}
      <div className="home-hero">
        <img src={res("assets/brand/hero-pattern.png")} alt="" style={{
          position: 'absolute', top: 0, left: 0, width: '100%', height: '100%',
          objectFit: 'cover', pointerEvents: 'none', opacity: 0.6,
        }} />
        <div className="page-wrap home-hero__grid">
          <div className="home-hero__content">
            <Eyebrow variant="dark">Data and AI that actually delivers commercial value.</Eyebrow>
            <h1 className="home-hero__h1" style={{ marginTop: 16 }}>
              The data and AI team<br className="m-br" /> that delivers <span style={{ color: 'var(--ls-lime)' }}>5x ROI</span>.
            </h1>
            <p className="home-hero__sub">
              From commercial vision to working data and AI, end to end.
            </p>
            <div style={{ display: 'flex', gap: 12, marginTop: 48 }}>
              <Btn variant="primary" href="/services">What we do</Btn>
            </div>
          </div>
          <div className="home-hero__graphic">
            <img src={res("assets/brand/hero-graphic.png")} alt="" />
          </div>
        </div>
      </div>

      {/* ── INDUSTRY CHALLENGE ─────────────────── */}
      <div className="industry-challenge">
        <img className="challenge-squares" src={res("assets/brand/challenge-squares.svg")} alt="" style={{
          position: 'absolute', inset: 0, width: '100%', height: '100%',
          objectFit: 'contain', pointerEvents: 'none',
        }} />
        <div className="page-wrap" style={{ position: 'relative', zIndex: 1, textAlign: 'center', padding: '60px 0', width: '100%' }}>
          <Eyebrow variant="dark">The data and AI challenge</Eyebrow>
          <h2 style={{
            font: '700 48px/1.35 var(--font-display)', letterSpacing: 'var(--tracking-display)',
            marginTop: 24, maxWidth: 800, marginLeft: 'auto', marginRight: 'auto',
          }}>
            Contractors can only take you so far.<br />
            Big firms send juniors.<br />
            A first hire is a gamble.
          </h2>
          <p style={{
            font: 'var(--type-body-lg)', color: 'rgba(255,255,255,.85)',
            marginTop: 24, maxWidth: 560, marginLeft: 'auto', marginRight: 'auto',
          }}>
            There's a gap between where you are and where you need to be - and the market can't fill it fast enough.
          </p>
        </div>
      </div>

      {/* ── WHY LEFTSHIFTED ────────────────────── */}
      <Section style={{ paddingTop: 100, paddingBottom: 100, minHeight: '100vh', display: 'flex', alignItems: 'center' }}>
        <div className="why-section">
          <div className="why-section__left">
            <Eyebrow>Why solve it?</Eyebrow>
            <div className="why-section__photo">
              <img src={res("assets/imagery/stock-working.png")} alt="Team working" />
            </div>
          </div>
          <div className="why-section__right">
            <h2 style={{
              font: 'var(--type-display-3)', letterSpacing: 'var(--tracking-display)',
              textWrap: 'balance',
            }}>
              The cost of getting it wrong
            </h2>
            <WhyGrid />
          </div>
        </div>
      </Section>

      {/* ── WHY LEFTSHIFTED ─────────────────────── */}
      <Section className="why-leftshifted" style={{ paddingTop: 80, paddingBottom: 80 }}>
        <div style={{ textAlign: 'center', marginBottom: 40, width: '100%' }}>
          <Eyebrow>Why Leftshifted?</Eyebrow>
          <h2 style={{
            font: 'var(--type-display-3)', letterSpacing: 'var(--tracking-display)',
            marginTop: 20, maxWidth: 800, marginLeft: 'auto', marginRight: 'auto', textWrap: 'balance',
          }}>
            Leftshifted was built differently
          </h2>
          <p style={{
            font: 'var(--type-body-lg)', color: 'var(--fg-muted)',
            marginTop: 16, maxWidth: 640, marginLeft: 'auto', marginRight: 'auto',
          }}>
            Outcome based, expert led, designed to offboard to your team. Because the typical engagement takes too long, costs too much, and delivers nothing but dependency.
          </p>
        </div>
        <WhyThemes />
      </Section>

      {/* ── SOLUTIONS ──────────────────────────── */}
      <div className="home-services">
        <div className="page-wrap home-services__grid">
          <div className="home-services__img">
            <div style={{ background: 'var(--ls-ultramarine-blue)', borderRadius: 24, padding: 32, display: 'grid', placeItems: 'center', aspectRatio: '1', position: 'relative', overflow: 'hidden' }}>
              <img src={res("assets/brand/union-services.svg")} alt="" style={{
                position: 'absolute', top: 0, right: 0, height: '100%', width: 'auto', pointerEvents: 'none',
              }} />
              <img src={res("assets/brand/services-graphic-v3.svg")} alt="" style={{ maxWidth: '85%', maxHeight: '85%', width: 'auto', height: 'auto', borderRadius: 0, display: 'block', position: 'relative' }} />
            </div>
          </div>
          <div className="home-services__content">
            <Eyebrow variant="dark">Our service</Eyebrow>
            <h2 style={{
              font: '700 48px/1.05 var(--font-display)', letterSpacing: '-0.03em',
              color: '#fff', marginTop: 20, textWrap: 'balance',
            }}>
              Everything you need, end-to-end, to <span style={{ color: 'var(--ls-lime)' }}>drive commercial value</span> with data and AI.
            </h2>
            <ServiceAccordion />
            <div style={{ marginTop: 32 }}>
              <Btn variant="primary" href="/services">Tell me more</Btn>
            </div>
          </div>
        </div>
        <div className="page-wrap" style={{ paddingTop: 48, marginTop: 64 }}>
          <LogoBar />
        </div>
      </div>

      {/* ── CASE STUDIES & INDUSTRIES ──────────── */}
      <Section style={{ paddingTop: 120, paddingBottom: 120 }}>
        <div style={{ textAlign: 'center', marginBottom: 48 }}>
          <Eyebrow>PR & Comms focus</Eyebrow>
          <h2 style={{
            font: 'var(--type-display-3)', letterSpacing: 'var(--tracking-display)',
            marginTop: 16, textWrap: 'balance',
          }}>
            We know exactly what it takes to turn scattered monitoring data into commercial assets your clients will pay for.
          </h2>
        </div>
        <div className="m-grid-4 m-pr-cards" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 32 }}>
          {[
            { icon: 'database', text: 'PR firms are sitting on more data than they know what to do with.' },
            { icon: 'gauge', text: "Analyst work doesn't scale. Clients ask for more insight, faster, with more granularity than manual work allows." },
            { icon: 'trending-up', text: 'The firms that adapt to their clients needs at pace will lead the market.' },
            { icon: 'check-circle', text: 'We understand the commercial model, know the workflow, and have delivered award-winning work.' },
          ].map((item, i) => (
            <div key={i}>
              <div style={{ width: 40, height: 40, borderRadius: 10, background: 'var(--ls-ultramarine-blue)', color: '#fff', display: 'grid', placeItems: 'center', marginBottom: 16 }}>
                <i data-lucide={item.icon} style={{ width: 20, height: 20 }}></i>
              </div>
              <p style={{ font: 'var(--type-body)', color: 'var(--fg-muted)' }}>{item.text}</p>
            </div>
          ))}
        </div>
        <div className="m-pr-anim" style={{ margin: '48px 0', display: 'flex', justifyContent: 'center' }}>
          {ind.img ? (
            <iframe
              loading="lazy"
              src={res(isMobile ? "assets/animations/pr-comms-pipeline-lofi.html" : "assets/pr-comms-animation.html")}
              title={ind.name}
              frameBorder="0"
              scrolling="no"
              style={{ width: '100%', maxWidth: '100%', aspectRatio: '1920 / 1080', border: 'none', display: isMobile ? 'none' : 'block', background: 'var(--bg-default)' }}
              onLoad={(e) => {
                const doc = e.target.contentDocument;
                if (!doc) return;
                const style = doc.createElement('style');
                style.textContent = '[data-omelette-chrome]{display:none!important}svg{box-shadow:none!important}';
                doc.head.appendChild(style);
                // The animation's stage briefly renders a near-black letterbox div while it
                // unpacks async; neutralize it to match the page background once it appears.
                let tries = 0;
                const neutralizeLetterbox = () => {
                  doc.querySelectorAll('div').forEach((el) => {
                    if (el.style.backgroundColor === 'rgb(10, 10, 10)' || el.style.backgroundColor === 'rgb(0, 0, 0)') {
                      el.style.setProperty('background', '#F9F8F5', 'important');
                    }
                  });
                  if (++tries < 30) setTimeout(neutralizeLetterbox, 150);
                };
                neutralizeLetterbox();
              }}
            />
          ) : (
            <div style={{
              position: 'relative', borderRadius: 24, overflow: 'hidden', minHeight: 300,
              background: 'linear-gradient(135deg, var(--ls-ultramarine-blue) 0%, var(--ls-midnight-navy) 100%)',
            }}>
              <UnionOverlay opacity={0.08} />
            </div>
          )}
        </div>
        <div style={{ textAlign: 'center' }}>
          <div style={{ marginTop: 8 }}>
            <Btn href="/pr-comms">View PR & Comms</Btn>
          </div>
        </div>
      </Section>

      {/* ── ABOUT / MEET JACK ──────────────────── */}
      <div className="home-about">
        <div className="page-wrap home-about__grid">
          <div className="home-about__portrait">
            <img src={res("assets/brand/founder-squares.png")} alt="" style={{
              position: 'absolute', top: -20, left: -30, width: '60%', height: 'calc(100% + 40px)',
              objectFit: 'contain', objectPosition: 'left', pointerEvents: 'none', zIndex: 2,
            }} />
            <img src={res("assets/imagery/founder-portrait-2-web.jpg")} alt="Jack, Founder & CEO" style={{
              width: '100%', height: '100%', objectFit: 'cover', borderRadius: 24,
              position: 'relative', zIndex: 1,
            }} />
          </div>
          <div className="home-about__content">
            <Eyebrow variant="dark">About Leftshifted</Eyebrow>
            <h2 style={{
              font: 'var(--type-display-2)', letterSpacing: 'var(--tracking-display)',
              color: '#fff', marginTop: 20,
            }}>
              Meet Jack,<br />Founder &amp; CEO
            </h2>
            <p style={{
              font: '600 20px/1.4 var(--font-display)', letterSpacing: '-0.02em',
              color: '#fff', marginTop: 24,
            }}>
              I'm Jack, data specialist and dog dad to Benny the spaniel.
            </p>
            <p style={{
              font: 'var(--type-body)', color: 'rgba(255,255,255,.8)',
              marginTop: 20, maxWidth: 580,
            }}>
              I founded Leftshifted because I saw too many senior leaders getting stuck navigating the complexity of data and AI projects that never delivered real value. I've helped unlock £231M+ in commercial results by doing things differently. Our end-to-end approach is tailored to you, and built for your long-term success (with or without us). We start with your commercial goals and a clear, honest assessment of your current data and AI capabilities.
            </p>
            <div style={{ marginTop: 32 }}>
              <Btn variant="primary" href="/about">About Us</Btn>
            </div>
          </div>
        </div>
      </div>



    </PageShell>
  );
};

Object.assign(window, { HomePage });
