/* global React */
/* Customer Stories · full case studies (Yours Clothing, Kiko Cosmetics, DKNY) */

const stStyles = {
  section: {
    background: "var(--nb-cream-2)",
    padding: "140px 56px 160px",
    color: "var(--nb-ink)",
    borderTop: "1px solid var(--nb-line)",
    borderBottom: "1px solid var(--nb-line)",
  },
  inner: { maxWidth: 1320, margin: "0 auto" },

  head: { display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 80, alignItems: "end", marginBottom: 64 },
  eyebrow: { fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--nb-soft)", marginBottom: 28, fontWeight: 600 },
  title: { fontFamily: "var(--serif)", fontWeight: 400, fontSize: "clamp(36px, 4.5vw, 64px)", lineHeight: 1.1, letterSpacing: "-0.01em", margin: 0 },
  sub: { fontSize: 17, lineHeight: 1.65, color: "var(--nb-navy)", maxWidth: 500 },

  /* Case study card — alternating layout */
  caseStudy: {
    background: "var(--nb-bone)",
    border: "1px solid var(--nb-line)",
    borderRadius: 12, overflow: "hidden",
    marginBottom: 28,
    display: "grid",
    gridTemplateColumns: "1fr 1fr",
    alignItems: "stretch",
  },
  caseStudyReverse: { gridTemplateColumns: "1fr 1fr" },

  csLeft: {
    padding: "56px 56px 60px",
    display: "flex", flexDirection: "column", gap: 18,
    justifyContent: "center",
  },
  csTheme: { fontSize: 10, letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--nb-rust)", fontWeight: 700 },
  csBrand: { fontFamily: "var(--serif)", fontSize: 56, lineHeight: 1, fontWeight: 400, letterSpacing: "-0.02em", color: "var(--nb-ink)" },
  csHead: { fontFamily: "var(--serif)", fontSize: 24, lineHeight: 1.2, fontStyle: "italic", color: "var(--nb-rust)", margin: 0 },
  csBody: { fontSize: 14.5, lineHeight: 1.7, color: "var(--nb-navy)" },
  csBodyT: { fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--nb-soft)", fontWeight: 700, marginBottom: 8 },

  csOutcomes: { display: "flex", flexDirection: "column", gap: 10, marginTop: 4 },
  csOutcome: {
    display: "grid", gridTemplateColumns: "16px 1fr", gap: 12,
    fontSize: 13.5, lineHeight: 1.55, color: "var(--nb-navy)",
  },
  csOutcomeBullet: { width: 7, height: 7, borderRadius: 999, background: "var(--nb-rust)", marginTop: 7 },

  /* Right pane — quote + stat block */
  csRight: {
    background: "var(--nb-ink)",
    color: "var(--nb-cream)",
    padding: "56px 56px 60px",
    display: "flex", flexDirection: "column",
    justifyContent: "space-between",
    gap: 32,
    position: "relative",
    overflow: "hidden",
  },
  csRightAccent: (color) => ({
    position: "absolute", inset: 0,
    background: `linear-gradient(135deg, ${color}28 0%, transparent 60%)`,
    pointerEvents: "none",
  }),
  csStat: {
    fontFamily: "var(--serif)", fontSize: 120, lineHeight: 0.9,
    letterSpacing: "-0.03em", fontWeight: 400, color: "var(--nb-cream)",
    position: "relative", zIndex: 1,
  },
  csStatSub: { fontSize: 12, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--nb-rose)", fontWeight: 700, marginTop: 16, position: "relative", zIndex: 1 },

  csQuoteBlock: { position: "relative", zIndex: 1 },
  csQuoteMark: { fontFamily: "var(--serif)", fontSize: 64, lineHeight: 0.4, color: "var(--nb-rust)", marginBottom: 14 },
  csQuote: { fontFamily: "var(--serif)", fontStyle: "italic", fontSize: 22, lineHeight: 1.35, color: "var(--nb-cream)", margin: 0 },
  csAttr: { fontSize: 12, color: "var(--nb-rose)", marginTop: 16, letterSpacing: "0.04em" },

  csMeta: {
    position: "relative", zIndex: 1,
    paddingTop: 24, borderTop: "1px solid rgba(244,238,227,0.18)",
    display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 16,
  },
  csMetaCell: {},
  csMetaLab: { fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--nb-rose)", marginBottom: 6, fontWeight: 700 },
  csMetaVal: { fontFamily: "var(--serif)", fontSize: 15, color: "var(--nb-cream)", lineHeight: 1.35 },

  /* Closing band — what N Brown takes from these */
  takeaway: {
    background: "var(--nb-ink)",
    color: "var(--nb-cream)",
    borderRadius: 12,
    padding: "48px 56px 56px",
    marginTop: 28,
  },
  takeawayHead: { display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 64, alignItems: "end", marginBottom: 32 },
  takeawayEye: { fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--nb-rose)", marginBottom: 16, fontWeight: 700 },
  takeawayT: { fontFamily: "var(--serif)", fontSize: "clamp(28px, 3.2vw, 44px)", lineHeight: 1.15, margin: 0, fontWeight: 400, letterSpacing: "-0.01em" },
  takeawaySub: { fontSize: 14, lineHeight: 1.6, color: "var(--nb-rose)", maxWidth: 460 },
  takeawayGrid: { display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 16 },
  takeawayCard: {
    background: "rgba(255,253,247,0.04)",
    border: "1px solid rgba(255,253,247,0.1)",
    borderRadius: 8,
    padding: "22px 24px 26px",
  },
  takeawayLab: { fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--nb-rose)", fontWeight: 700 },
  takeawayCardT: { fontFamily: "var(--serif)", fontSize: 22, lineHeight: 1.2, margin: "10px 0", fontWeight: 400, color: "var(--nb-cream)" },
  takeawayCardB: { fontSize: 13, lineHeight: 1.55, color: "rgba(244,238,227,0.7)" },
};

const CASES = [
  {
    theme: "Revenue Growth · Modernising tech stack",
    brand: "Yours Clothing",
    head: "42% lower total cost of ownership.",
    bodyT: "The story",
    bodyHTML: "UK size-inclusive retailer with a legacy ESP that was costing more, doing less. They needed speed, flexibility, and a measurably lower run-rate &mdash; and they got all three when they moved to Klaviyo.",
    outcomes: [
      "Legacy incumbent removed in favour of a platform built for speed and flexibility.",
      "Klaviyo integrated cleanly with their existing legacy technology stack &mdash; no rip-and-replace.",
      "Reduced dependency on technical resource &mdash; marketers now self-serve campaign execution.",
      "Faster marketing execution and a lower total cost of ownership year-on-year.",
    ],
    stat: "42%",
    statSub: "Lower total cost of ownership",
    quote: "We replaced our legacy ESP and got speed, flexibility, and a measurably lower TCO in return.",
    attr: "Yours Clothing leadership team",
    accent: "#C8552F",
    meta: [
      { lab: "Sector",      val: "Size-inclusive UK fashion" },
      { lab: "Why it lands","val": "Direct N Brown peer · same size of subscriber base" },
      { lab: "Migration",   val: "No rip-and-replace · phased cutover" },
      { lab: "Time to value","val": "Marketers self-serving from day one" },
    ],
  },
  {
    theme: "Operational Speed · Modernising tech stack",
    brand: "Kiko Cosmetics",
    head: "Loyalty, ecommerce, and a Salesforce legacy left behind.",
    bodyT: "The story",
    bodyHTML: "Global beauty retailer running ecommerce email and SMS across markets &mdash; on a legacy Salesforce Commerce Cloud setup that couldn&rsquo;t support real-time loyalty triggers. Migrated to Klaviyo without disrupting BAU, with loyalty-linked flows live within weeks.",
    outcomes: [
      "Full ecommerce email and SMS programme rebuilt on Klaviyo across markets.",
      "Migrated from legacy Salesforce Commerce Cloud without disruption to BAU.",
      "Faster campaign build, unified customer data, and loyalty-linked flows live within weeks.",
      "Real-time loyalty events flowing into Klaviyo &mdash; triggered comms they previously couldn&rsquo;t run.",
    ],
    stat: "3.4×",
    statSub: "Faster campaign build",
    quote: "Real-time loyalty events flowing into Klaviyo unlocked triggered comms we simply couldn't run before.",
    attr: "Kiko Cosmetics · Global CRM",
    accent: "#9176D1",
    meta: [
      { lab: "Sector",       val: "Global beauty retail" },
      { lab: "Why it lands", val: "Loyalty integration N Brown wants for FS + Insider" },
      { lab: "Migration",    val: "Off Salesforce Commerce Cloud · BAU uninterrupted" },
      { lab: "Time to value","val": "Loyalty flows live within weeks" },
    ],
  },
  {
    theme: "CX + Personalisation · Send less, drive more",
    brand: "DKNY",
    head: "Send less. Drive more revenue.",
    bodyT: "The story",
    bodyHTML: "A massive subscriber list that wasn&rsquo;t showing up in engagement or revenue. DKNY was over-saturating subscribers with general, frequent campaigns. They leaned into Klaviyo&rsquo;s personalisation tools &mdash; flows, segmentation, AI-powered dynamic product recommendations &mdash; to send less and drive more.",
    outcomes: [
      "1.2M active subscribers re-engaged via flows + segmentation + AI personalisation.",
      "Dynamic product recommendation blocks powered by Klaviyo AI &mdash; relevant to every subscriber.",
      "Better message relevance, fewer sends, higher attributed revenue.",
      "Same audience, better engagement &mdash; without expanding the CRM team.",
    ],
    stat: "24%",
    statSub: "YoY reduction in total email sends",
    quote: "Personalisation, segmentation and AI-powered product blocks let us send less and impact more.",
    attr: "DKNY · 1.2M active subscribers",
    accent: "#16182C",
    meta: [
      { lab: "Sector",       val: "Global heritage fashion" },
      { lab: "Why it lands", val: "Mirrors the 350M-send throughput problem" },
      { lab: "Lever",        val: "Personalisation > volume" },
      { lab: "Time to value","val": "Engagement uplift within the first quarter" },
    ],
  },
];

const TAKEAWAYS = [
  { lab: "From Yours Clothing", t: "Lower TCO · proven on a UK peer.", b: "Same size, same sector, same ESP-replacement journey. The 42% TCO improvement is the headline N Brown can model against today&rsquo;s cost base." },
  { lab: "From Kiko",           t: "Loyalty triggers, live in weeks.", b: "Real-time loyalty events flowing in. The same architecture that lights up FS-account triggers, Insider tier moves, and Fashion Voucher events for N Brown." },
  { lab: "From DKNY",           t: "Send less, earn more.",            b: "The 350M-send-a-year throughput problem solved with personalisation, not volume. AI-powered product blocks, AI-driven segments, fewer sends." },
];

function CustomerStories() {
  return (
    <section id="stories" style={stStyles.section} data-screen-label="03 Customer stories">
      <div style={stStyles.inner}>
        <div style={stStyles.head}>
          <div>
            <div style={stStyles.eyebrow}>Customer stories · Retailers like N Brown</div>
            <h2 style={stStyles.title}>
              Three brands.<br/>
              Three different N Brown problems,<br/>
              <span className="serif-i" style={{color: "var(--nb-rust)"}}>already solved on Klaviyo</span>.
            </h2>
          </div>
          <p style={stStyles.sub}>
            Lower TCO. Faster loyalty triggers. Send-less, earn-more
            personalisation. Three case studies that map directly to the three
            commercial outcomes on the previous page — each from a retailer
            recognisable to N Brown&rsquo;s leadership.
          </p>
        </div>

        {CASES.map((c, i) => (
          <div key={c.brand} style={stStyles.caseStudy}>
            <div style={i % 2 === 1 ? {...stStyles.csRight, order: 0} : stStyles.csLeft}>
              {i % 2 === 1 ? null : (
                <React.Fragment>
                  <div style={stStyles.csTheme}>{c.theme}</div>
                  <div style={stStyles.csBrand}>{c.brand}</div>
                  <h3 style={stStyles.csHead}>{c.head}</h3>
                  <div>
                    <div style={stStyles.csBodyT}>{c.bodyT}</div>
                    <div style={stStyles.csBody} dangerouslySetInnerHTML={{__html: c.bodyHTML}}/>
                  </div>
                  <div style={stStyles.csOutcomes}>
                    {c.outcomes.map((o, j) => (
                      <div key={j} style={stStyles.csOutcome}>
                        <span style={stStyles.csOutcomeBullet}/>
                        <span dangerouslySetInnerHTML={{__html: o}}/>
                      </div>
                    ))}
                  </div>
                </React.Fragment>
              )}
              {i % 2 === 1 && (
                <React.Fragment>
                  <div style={stStyles.csRightAccent(c.accent)}/>
                  <div style={stStyles.csQuoteBlock}>
                    <div style={stStyles.csQuoteMark}>&ldquo;</div>
                    <p style={stStyles.csQuote}>{c.quote}</p>
                    <div style={stStyles.csAttr}>{c.attr}</div>
                  </div>
                  <div>
                    <div style={{...stStyles.csStat, color: "var(--nb-cream)"}}>{c.stat}</div>
                    <div style={stStyles.csStatSub}>{c.statSub}</div>
                  </div>
                  <div style={stStyles.csMeta}>
                    {c.meta.map(m => (
                      <div key={m.lab} style={stStyles.csMetaCell}>
                        <div style={stStyles.csMetaLab}>{m.lab}</div>
                        <div style={stStyles.csMetaVal}>{m.val}</div>
                      </div>
                    ))}
                  </div>
                </React.Fragment>
              )}
            </div>
            <div style={i % 2 === 1 ? stStyles.csLeft : stStyles.csRight}>
              {i % 2 === 1 ? (
                <React.Fragment>
                  <div style={stStyles.csTheme}>{c.theme}</div>
                  <div style={stStyles.csBrand}>{c.brand}</div>
                  <h3 style={stStyles.csHead}>{c.head}</h3>
                  <div>
                    <div style={stStyles.csBodyT}>{c.bodyT}</div>
                    <div style={stStyles.csBody} dangerouslySetInnerHTML={{__html: c.bodyHTML}}/>
                  </div>
                  <div style={stStyles.csOutcomes}>
                    {c.outcomes.map((o, j) => (
                      <div key={j} style={stStyles.csOutcome}>
                        <span style={stStyles.csOutcomeBullet}/>
                        <span dangerouslySetInnerHTML={{__html: o}}/>
                      </div>
                    ))}
                  </div>
                </React.Fragment>
              ) : (
                <React.Fragment>
                  <div style={stStyles.csRightAccent(c.accent)}/>
                  <div style={stStyles.csQuoteBlock}>
                    <div style={stStyles.csQuoteMark}>&ldquo;</div>
                    <p style={stStyles.csQuote}>{c.quote}</p>
                    <div style={stStyles.csAttr}>{c.attr}</div>
                  </div>
                  <div>
                    <div style={stStyles.csStat}>{c.stat}</div>
                    <div style={stStyles.csStatSub}>{c.statSub}</div>
                  </div>
                  <div style={stStyles.csMeta}>
                    {c.meta.map(m => (
                      <div key={m.lab} style={stStyles.csMetaCell}>
                        <div style={stStyles.csMetaLab}>{m.lab}</div>
                        <div style={stStyles.csMetaVal}>{m.val}</div>
                      </div>
                    ))}
                  </div>
                </React.Fragment>
              )}
            </div>
          </div>
        ))}

        {/* What N Brown takes from these */}
        <div style={stStyles.takeaway}>
          <div style={stStyles.takeawayHead}>
            <div>
              <div style={stStyles.takeawayEye}>What these mean for N Brown</div>
              <h3 style={stStyles.takeawayT}>
                Three case studies. Three N Brown levers.
              </h3>
            </div>
            <p style={stStyles.takeawaySub}>
              We&rsquo;re not picking these to admire. Each one demonstrates a
              specific Klaviyo capability lined up against a specific N Brown
              problem you raised in discovery.
            </p>
          </div>
          <div style={stStyles.takeawayGrid}>
            {TAKEAWAYS.map(t => (
              <div key={t.lab} style={stStyles.takeawayCard}>
                <div style={stStyles.takeawayLab}>{t.lab}</div>
                <div style={stStyles.takeawayCardT}>{t.t}</div>
                <div style={stStyles.takeawayCardB}>{t.b}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}
