﻿/* Auto-generated from mockups/04-case-study.html */
(function(){

const { useState, useEffect, useRef } = React;

    /* ── Icons ── */
    const Icon = ({ size = 16, children, style }) => (
      <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ flex:'none', ...style }}>{children}</svg>
    );
    const X = (p) => <Icon {...p}><path d="M18 6L6 18M6 6l12 12"/></Icon>;
    const Check = (p) => <Icon {...p}><path d="M20 6L9 17l-5-5"/></Icon>;
    const Arrow = (p) => <Icon {...p}><path d="M5 12h14M13 5l7 7-7 7"/></Icon>;
    const Sparkle = (p) => <Icon {...p}><path d="M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8"/></Icon>;

    /* ── Animation hooks ── */
    function useInView(threshold = 0.3) {
      const ref = useRef(null);
      const [inView, setInView] = useState(false);
      useEffect(() => {
        if (!ref.current) return;
        const r = ref.current.getBoundingClientRect();
        if (r.top < window.innerHeight && r.bottom > 0) { setInView(true); return; }
        const io = new IntersectionObserver(([e]) => e.isIntersecting && setInView(true), { threshold });
        io.observe(ref.current);
        return () => io.disconnect();
      }, [threshold]);
      return [ref, inView];
    }
    function useMetricPop({ active, delay = 0 } = {}) {
      const [popped, setPopped] = useState(false);
      useEffect(() => {
        if (!active) { setPopped(false); return; }
        const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches;
        if (reduce) { setPopped(true); return; }
        const id = setTimeout(() => setPopped(true), delay);
        return () => clearTimeout(id);
      }, [active, delay]);
      return {
        display: 'inline-block',
        opacity: popped ? 1 : 0,
        transform: popped ? 'scale(1)' : 'scale(0.9)',
        transition: 'opacity 600ms cubic-bezier(0.34, 1.56, 0.64, 1), transform 600ms cubic-bezier(0.34, 1.56, 0.64, 1)',
        transformOrigin: 'left center',
        willChange: 'transform, opacity',
      };
    }
    function Reveal({ children, delay = 0, style }) {
      const [ref, inView] = useInView(0.15);
      return (
        <div ref={ref} className={`reveal ${inView ? 'in' : ''}`}
          style={{ transitionDelay: `${delay}ms`, ...style }}>{children}</div>
      );
    }

    /* ── Headline number trio — CPL / Message cost / Lead volume ── */
    function MetricCallout({ label, before, after, unit, pct, vs, accent, delay = 0, active, format = 'num' }) {
      const popStyle = useMetricPop({ active, delay });
      const display = format === 'plus' ? `+${after}%` : after;
      return (
        <div style={{
          padding: '32px 28px', background: 'var(--bg-card)',
          border: '1px solid var(--border-subtle)', borderRadius: 16, position: 'relative', overflow: 'hidden',
        }}>
          {/* Accent stripe */}
          <div style={{ position:'absolute', top: 0, left: 0, right: 0, height: 2, background: accent }}/>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 13, color: 'var(--text-dim)',
            letterSpacing: '0.2em', textTransform: 'uppercase', marginBottom: 18 }}>{label}</div>

          <div style={{ display: 'flex', alignItems: 'baseline', gap: 14, flexWrap: 'wrap' }}>
            {format === 'num' && (
              <span style={{
                fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 30,
                color: 'var(--text-faint)', textDecoration: 'line-through',
                textDecorationColor: 'rgba(248,113,113,0.7)', textDecorationThickness: 2,
                letterSpacing: '-0.03em', fontVariantNumeric: 'tabular-nums',
              }}>
                <span style={{direction:'ltr',unicodeBidi:'isolate',display:'inline-block'}}>{before}</span>
              </span>
            )}
            <span style={{
              fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 64,
              color: accent, letterSpacing: '-0.045em', fontVariantNumeric: 'tabular-nums',
              lineHeight: 0.95, textShadow: `0 0 28px ${accent}55`,
            }}>
              <span style={popStyle}>
                <span style={{direction:'ltr',unicodeBidi:'isolate',display:'inline-block'}}>{display}</span>
              </span>
            </span>
            {unit && (
              <span style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 48,
                color: accent, letterSpacing: '-0.04em', lineHeight: 0.95,
                opacity: 0.85, marginLeft: -4 }}>{unit}</span>
            )}
          </div>

          <div style={{ marginTop: 14, display: 'flex', alignItems: 'center', gap: 8,
            fontFamily: 'var(--font-mono)', fontSize: 14, color: 'var(--text-faint)',
            letterSpacing: '0.12em' }}>
            <span style={{
              display: 'inline-flex', alignItems: 'center', gap: 4,
              padding: '3px 8px', borderRadius: 9999,
              background: accent === '#22c55e' ? 'rgba(34,197,94,0.12)' : 'rgba(0,71,255,0.12)',
              color: accent,
              fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 14,
              letterSpacing: '-0.005em',
            }}>{pct}</span>
            {vs}
          </div>
        </div>
      );
    }

    /* ── The 3-column story block ── */
    function StoryColumn({ eyebrow, eyebrowColor, title, items, tone = 'neutral' }) {
      const isCenter = tone === 'center';
      return (
        <div style={{
          padding: 32,
          background: isCenter ? 'rgba(0,71,255,0.055)' : 'var(--bg-card)',
          border: `1px solid ${isCenter ? 'rgba(0,71,255,0.3)' : 'var(--border-subtle)'}`,
          borderRadius: 16, height: '100%',
          display: 'flex', flexDirection: 'column',
          position: 'relative', overflow: 'hidden',
        }}>
          {isCenter && (
            <div style={{ position: 'absolute', top: 0, left: 0, right: 0, height: 2,
              background: 'linear-gradient(90deg, transparent, #0047ff, transparent)' }}/>
          )}
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 14, color: eyebrowColor,
            letterSpacing: '0.2em', textTransform: 'uppercase', marginBottom: 16 }}>{eyebrow}</div>
          <h3 style={{ fontFamily: 'var(--font-display)', fontSize: 22, fontWeight: 600,
            letterSpacing: '-0.015em', color: 'var(--text-primary)', margin: '0 0 20px', lineHeight: 1.2 }}>{title}</h3>
          <ul style={{ listStyle: 'none', padding: 0, margin: 0,
            display: 'flex', flexDirection: 'column', gap: 14, flex: 1 }}>
            {items.map((it, i) => <StoryItem key={i} item={it} tone={tone}/>)}
          </ul>
        </div>
      );
    }
    function StoryItem({ item, tone }) {
      const [Mark, markColor] = tone === 'before' ? [X, '#f87171']
        : tone === 'after' ? [Check, '#22c55e']
        : [Sparkle, '#0047ff'];
      if (tone === 'center') {
        return (
          <li style={{ display: 'flex', gap: 14 }}>
            <div style={{
              flex: 'none', width: 28, height: 28, borderRadius: 8,
              background: 'rgba(0,71,255,0.15)', color: '#0047ff',
              border: '1px solid rgba(0,71,255,0.3)',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              fontFamily: 'var(--font-display)', fontSize: 13, fontWeight: 600,
            }}>{item.n}</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontFamily: 'var(--font-display)', fontSize: 15, fontWeight: 600,
                color: 'var(--text-primary)', marginBottom: 4, lineHeight: 1.3 }}>{item.title}</div>
              <div style={{ fontFamily: 'var(--font-display)', fontSize: 13, color: 'var(--text-muted)',
                lineHeight: 1.5 }}>{item.body}</div>
              {item.tiers && (
                <div style={{ marginTop: 8, display: 'flex', gap: 6, flexWrap: 'wrap' }}>
                  {item.tiers.map((t, i) => (
                    <span key={i} style={{
                      padding: '3px 8px', borderRadius: 9999,
                      background: 'rgba(0,71,255,0.1)', border: '1px solid rgba(0,71,255,0.25)',
                      color: '#9fb8ff',
                      fontFamily: 'var(--font-mono)', fontSize: 13, fontWeight: 600,
                      letterSpacing: '0.1em', textTransform: 'uppercase',
                    }}>{t}</span>
                  ))}
                </div>
              )}
            </div>
          </li>
        );
      }
      const text = item.text || item;
      const parts = item.num ? [item.text, item.num, item.suffix || ''] : null;
      return (
        <li style={{ display: 'flex', gap: 12, alignItems: 'flex-start' }}>
          <Mark size={16} style={{ color: markColor, marginTop: 3 }}/>
          <span style={{ fontFamily: 'var(--font-display)', fontSize: 14, color: 'var(--text-secondary)', lineHeight: 1.5 }}>
            {parts ? (
              <>
                {parts[0]}
                <span style={{
                  fontFamily: 'var(--font-display)', fontWeight: 700,
                  color: tone === 'before' ? '#f87171' : '#0047ff',
                  fontVariantNumeric: 'tabular-nums',
                  padding: '0 2px',
                }}>{parts[1]}</span>
                {parts[2]}
              </>
            ) : text}
          </span>
        </li>
      );
    }

    /* ── Case Study Section ── */
    function CaseStudySection() {
      const [metricsRef, metricsIn] = useInView(0.35);
      const t = window.useCopy();

      const stepTiers = [['Tier 1'], ['Tier 1'], ['Tier 2'], ['Tier 1']];
      const interventionItems = t.sila.col2.steps.map((step, i) => ({
        n: String(i + 1),
        title: step.title,
        body: step.body,
        tiers: stepTiers[i],
      }));

      return (
        <section style={{
          position: 'relative', background: 'var(--bg-base)',
          padding: '120px 48px 120px',
        }}>
          {/* Soft blue horizon under the metric row */}
          <div style={{
            position: 'absolute', left: 0, right: 0, top: '72%', height: 200,
            pointerEvents: 'none',
            background: 'linear-gradient(180deg, transparent, rgba(0,71,255,0.05), transparent)',
          }}/>

          <div style={{ maxWidth: 1344, margin: '0 auto', position: 'relative' }}>
            {/* Header */}
            <Reveal>
              <div style={{
                display: 'inline-flex', alignItems: 'center', gap: 10,
                padding: '6px 12px 6px 10px', borderRadius: 9999,
                background: 'rgba(0,71,255,0.1)', border: '1px solid rgba(0,71,255,0.3)',
                fontFamily: 'var(--font-display)', fontSize: 16, fontWeight: 600,
                letterSpacing: '0.12em', textTransform: 'uppercase', color: '#9fb8ff',
              }}>
                <span style={{ width: 6, height: 6, borderRadius: 9999, background: '#0047ff',
                  boxShadow: '0 0 6px #0047ff' }}/>
                {t.sila.badge}
              </div>
            </Reveal>

            <Reveal delay={80}>
              <h2 style={{
                fontFamily: 'var(--font-display)', fontSize: 64, fontWeight: 600,
                lineHeight: 1.05, letterSpacing: '-0.035em',
                color: 'var(--text-primary)', margin: '24px 0 20px', maxWidth: 1040, textWrap: 'balance',
              }}>
                {t.sila.h1_pre}{' '}
                <span style={{ color: '#0047ff', fontVariantNumeric: 'tabular-nums',
                  textShadow: '0 0 32px rgba(0,71,255,0.4)' }}>
                  <span style={{direction:'ltr',unicodeBidi:'isolate',display:'inline-block'}}>{t.sila.h1_metric}</span>
                </span>{' '}
                {t.sila.h1_post}
              </h2>
            </Reveal>

            <Reveal delay={140}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 28, marginBottom: 56,
                fontFamily: 'var(--font-mono)', fontSize: 14, color: 'var(--text-dim)',
                letterSpacing: '0.12em', textTransform: 'uppercase' }}>
                <span>{t.sila.meta.client}</span>
                <span style={{ width: 4, height: 4, borderRadius: 9999, background: 'var(--border-subtle)' }}/>
                <span>{t.sila.meta.industry}</span>
                <span style={{ width: 4, height: 4, borderRadius: 9999, background: 'var(--border-subtle)' }}/>
                <span>{t.sila.meta.region}</span>
                <span style={{ width: 4, height: 4, borderRadius: 9999, background: 'var(--border-subtle)' }}/>
                <span>{t.sila.meta.engagement}</span>
              </div>
            </Reveal>

            {/* 3-column story */}
            <div className="sila-story-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1.1fr 1fr', gap: 20, marginBottom: 40 }}>
              <Reveal delay={100}>
                <StoryColumn
                  eyebrow={t.sila.col1.label}
                  eyebrowColor="#f87171"
                  title={t.sila.col1.h}
                  items={t.sila.col1.pains}
                  tone="before"
                />
              </Reveal>
              <Reveal delay={160}>
                <StoryColumn
                  eyebrow={t.sila.col2.label}
                  eyebrowColor="#9fb8ff"
                  title={t.sila.col2.h}
                  items={interventionItems}
                  tone="center"
                />
              </Reveal>
              <Reveal delay={220}>
                <StoryColumn
                  eyebrow={t.sila.col3.label}
                  eyebrowColor="#22c55e"
                  title={t.sila.col3.h}
                  items={t.sila.col3.wins}
                  tone="after"
                />
              </Reveal>
            </div>

            {/* Headline metric trio — animates on scroll-into-view */}
            <div ref={metricsRef} className="sila-metrics-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20 }}>
              <MetricCallout
                label={t.sila.metrics[0].label}
                before={120} after={17} unit="₪"
                pct={t.sila.metrics[0].baseline}
                vs={t.sila.metrics[0].vs}
                accent="#0047ff"
                delay={0} active={metricsIn}
              />
              <MetricCallout
                label={t.sila.metrics[1].label}
                before={55} after={8} unit="₪"
                pct={t.sila.metrics[1].baseline}
                vs={t.sila.metrics[1].vs}
                accent="#0047ff"
                delay={150} active={metricsIn}
              />
              <MetricCallout
                label={t.sila.metrics[2].label}
                before={0} after={400} unit="vs. baseline"
                pct={t.sila.metrics[2].baseline}
                vs={t.sila.metrics[2].vs}
                accent="#22c55e"
                delay={300} active={metricsIn} format="plus"
              />
            </div>
          </div>
        </section>
      );
    }

window.SilaSection = CaseStudySection;
})();
