// ============================================================
// PAGE — Servizi
// Hero + 7 servizi dettagliati + processo + CTA
// ============================================================
const { useState: useStateSV, useRef: useRefSV } = React;
const motionSV = new Proxy({}, { get: (_, p) => window.FramerMotion.motion[p] });
const useInViewSV = (...a) => window.FramerMotion.useInView(...a);

// ============================================================
// SERVIZI ATMOSPHERE — universo caldo, calmo, editoriale
// Metafora: "7 servizi = costellazione". Starfield + costellazione +
// nebulosa calda. Editoriale, low-impact, palette scura del sito.
// ============================================================
function ServiziStarfield() {
  const canvasRef = useRefSV(null);
  const wrapRef = useRefSV(null);
  const animRef = useRefSV(null);
  const mouseRef = useRefSV({ x: 0, y: 0, target: { x: 0, y: 0 } });
  const tRef = useRefSV(0);
  const starsRef = useRefSV([]);

  React.useEffect(() => {
    const canvas = canvasRef.current;
    const wrap = wrapRef.current;
    if (!canvas || !wrap) return;
    const ctx = canvas.getContext('2d');
    const dpr = Math.min(window.devicePixelRatio || 1, 2);
    let w = 0, h = 0;

    const buildStars = () => {
      const stars = [];
      // 3 layers — depth via size, brightness, parallax factor
      const counts = [180, 90, 35];
      const layers = [
        { p: 0.15, sz: [0.4, 0.9],  br: [0.3, 0.55], warm: 0.15 },
        { p: 0.30, sz: [0.7, 1.5],  br: [0.45, 0.75], warm: 0.35 },
        { p: 0.55, sz: [1.2, 2.4],  br: [0.65, 0.95], warm: 0.55 },
      ];
      layers.forEach((L, li) => {
        for (let i = 0; i < counts[li]; i++) {
          stars.push({
            x: Math.random() * w,
            y: Math.random() * h,
            r: L.sz[0] + Math.random() * (L.sz[1] - L.sz[0]),
            br: L.br[0] + Math.random() * (L.br[1] - L.br[0]),
            tw: 0.5 + Math.random() * 2.5,         // twinkle speed
            ph: Math.random() * Math.PI * 2,        // phase
            par: L.p,
            warm: Math.random() < L.warm,           // some stars are warm gold
          });
        }
      });
      starsRef.current = stars;
    };

    const resize = () => {
      const rect = wrap.getBoundingClientRect();
      w = rect.width; h = rect.height;
      canvas.width = w * dpr; canvas.height = h * dpr;
      canvas.style.width = w + 'px'; canvas.style.height = h + 'px';
      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
      buildStars();
    };

    const onMouse = (e) => {
      const rect = wrap.getBoundingClientRect();
      mouseRef.current.target = {
        x: ((e.clientX - rect.left) / rect.width  - 0.5) * 2,
        y: ((e.clientY - rect.top)  / rect.height - 0.5) * 2,
      };
    };
    const onLeave = () => { mouseRef.current.target = { x: 0, y: 0 }; };

    const draw = () => {
      tRef.current += 0.01;
      const t = tRef.current;
      mouseRef.current.x += (mouseRef.current.target.x - mouseRef.current.x) * 0.05;
      mouseRef.current.y += (mouseRef.current.target.y - mouseRef.current.y) * 0.05;
      const mx = mouseRef.current.x;
      const my = mouseRef.current.y;

      ctx.clearRect(0, 0, w, h);

      // very slow horizontal drift (sky rotation feel)
      const drift = t * 4;

      starsRef.current.forEach(s => {
        const tw = 0.6 + 0.4 * Math.sin(t * s.tw + s.ph);
        const px = ((s.x + drift * s.par) % (w + 20)) - mx * 18 * s.par;
        const py = s.y - my * 14 * s.par;
        const a = s.br * tw;

        if (s.warm) {
          // warm halo
          const grad = ctx.createRadialGradient(px, py, 0, px, py, s.r * 4);
          grad.addColorStop(0, `rgba(255,215,0,${a})`);
          grad.addColorStop(0.4, `rgba(201,168,76,${a * 0.4})`);
          grad.addColorStop(1, 'rgba(201,168,76,0)');
          ctx.fillStyle = grad;
          ctx.beginPath(); ctx.arc(px, py, s.r * 4, 0, Math.PI * 2); ctx.fill();
          ctx.fillStyle = `rgba(255,236,170,${a})`;
          ctx.beginPath(); ctx.arc(px, py, s.r, 0, Math.PI * 2); ctx.fill();
        } else {
          ctx.fillStyle = `rgba(230,235,255,${a})`;
          ctx.beginPath(); ctx.arc(px, py, s.r, 0, Math.PI * 2); ctx.fill();
        }
      });

      animRef.current = requestAnimationFrame(draw);
    };

    resize();
    window.addEventListener('resize', resize);
    wrap.addEventListener('mousemove', onMouse);
    wrap.addEventListener('mouseleave', onLeave);
    animRef.current = requestAnimationFrame(draw);

    return () => {
      cancelAnimationFrame(animRef.current);
      window.removeEventListener('resize', resize);
      wrap.removeEventListener('mousemove', onMouse);
      wrap.removeEventListener('mouseleave', onLeave);
    };
  }, []);

  return (
    <div ref={wrapRef} style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>
      <canvas ref={canvasRef} style={{ position: 'absolute', inset: 0 }} />
    </div>
  );
}

function ServiziAtmosphere() {
  return (
    <div aria-hidden="true" style={{
      position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none',
    }}>
      {/* base warm wash */}
      <div style={{
        position: 'absolute', inset: 0,
        background: `
          radial-gradient(ellipse 70% 55% at 22% 30%, rgba(201,168,76,0.14), transparent 65%),
          radial-gradient(ellipse 55% 50% at 82% 72%, rgba(244,208,63,0.07), transparent 70%),
          radial-gradient(ellipse 90% 60% at 50% 100%, rgba(45,106,79,0.10), transparent 75%)
        `,
      }} />

      {/* deep-space starfield (canvas, parallax) */}
      <ServiziStarfield />

      {/* warm nebula glows — drifting */}
      <div className="serv-glow" style={{
        position: 'absolute',
        top: '15%', left: '6%',
        width: '45%', height: '70%',
        background: 'radial-gradient(circle, rgba(255,215,0,0.10), transparent 60%)',
        filter: 'blur(50px)',
      }} />
      <div className="serv-glow-2" style={{
        position: 'absolute',
        top: '40%', right: '8%',
        width: '40%', height: '60%',
        background: 'radial-gradient(circle, rgba(201,168,76,0.08), transparent 65%)',
        filter: 'blur(60px)',
      }} />

      {/* editorial horizontal rules — like a magazine grid */}
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: `repeating-linear-gradient(
          to bottom,
          transparent 0px,
          transparent 119px,
          rgba(255,255,255,0.025) 119px,
          rgba(255,255,255,0.025) 120px
        )`,
      }} />

      {/* COSTELLAZIONE — 5 stelle = 5 servizi. Pentagono morbido in alto a destra,
          fuori dal flusso del testo principale. Forma evocativa, non zodiacale. */}
      <svg
        viewBox="0 0 1000 600"
        preserveAspectRatio="xMidYMid slice"
        style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
      >
        <defs>
          <radialGradient id="serv-star-glow">
            <stop offset="0%"  stopColor="rgba(255,236,170,0.95)" />
            <stop offset="30%" stopColor="rgba(255,215,0,0.55)" />
            <stop offset="100%" stopColor="rgba(201,168,76,0)" />
          </radialGradient>
        </defs>

        {/* connecting lines — gentle pentagon outline + 1 interior tracer */}
        <g fill="none" stroke="rgba(255,215,0,0.32)" strokeWidth="0.8"
           strokeLinecap="round" strokeDasharray="1.6 5">
          {/* outline 1→2→3→4→5→1 */}
          <line x1="790" y1="95"  x2="935" y2="190" />
          <line x1="935" y1="190" x2="880" y2="360" />
          <line x1="880" y1="360" x2="700" y2="360" />
          <line x1="700" y1="360" x2="645" y2="190" />
          <line x1="645" y1="190" x2="790" y2="95" />
          {/* interior tracers through center — subtle pentagram */}
          <line x1="790" y1="95"  x2="880" y2="360" />
          <line x1="645" y1="190" x2="880" y2="360" />
          <line x1="935" y1="190" x2="700" y2="360" />
        </g>

        {/* the 5 stars — labelled */}
        {[
          { x: 790, y: 95,  r: 5.0, n: '01' },
          { x: 935, y: 190, r: 4.5, n: '02' },
          { x: 880, y: 360, r: 4.0, n: '03' },
          { x: 700, y: 360, r: 5.5, n: '04' },
          { x: 645, y: 190, r: 4.0, n: '05' },
        ].map((s, i) => (
          <g key={i}>
            <circle cx={s.x} cy={s.y} r={s.r * 5}
              fill="url(#serv-star-glow)" opacity="0.85" />
            <circle cx={s.x} cy={s.y} r={s.r * 0.55}
              fill="rgba(255,243,200,1)" />
            <circle cx={s.x} cy={s.y} r={s.r}
              fill="none" stroke="rgba(255,215,0,0.55)" strokeWidth="0.7" />
            {/* tiny ordinal label, monospaced */}
            <text x={s.x + s.r + 8} y={s.y + 3.5}
              fill="rgba(201,168,76,0.65)"
              style={{ font: "600 7.5px 'Courier Prime', monospace", letterSpacing: 1.5 }}>
              {s.n}
            </text>
          </g>
        ))}

        {/* constellation caption (italic serif) */}
        <text x="695" y="435"
          fill="rgba(201,168,76,0.55)"
          style={{ font: "italic 11px 'Cinzel', serif", letterSpacing: 2 }}>
          — Costellazione di servizi —
        </text>
      </svg>

      {/* small editorial mark — top-left "section signature" */}
      <div style={{
        position: 'absolute',
        top: 96, left: '8%',
        display: 'flex', alignItems: 'center', gap: 14,
        opacity: 0.55,
      }}>
        <div style={{
          width: 36, height: 1, background: 'rgba(201,168,76,0.6)',
        }} />
        <span style={{
          fontFamily: "'Courier Prime', monospace",
          fontSize: '0.62rem', letterSpacing: 2.5,
          color: 'rgba(201,168,76,0.85)',
          textTransform: 'uppercase', fontWeight: 700,
        }}>§ Servizi · MMXXVI</span>
      </div>

      {/* mirrored editorial mark — bottom-right */}
      <div style={{
        position: 'absolute',
        bottom: 56, right: '8%',
        display: 'flex', alignItems: 'center', gap: 14,
        opacity: 0.45,
      }}>
        <span style={{
          fontFamily: "'Cinzel', serif",
          fontSize: '0.78rem', letterSpacing: 4,
          color: 'rgba(255,255,255,0.45)',
          fontStyle: 'italic',
        }}>Capire · Costruire · Consegnare</span>
        <div style={{
          width: 36, height: 1, background: 'rgba(255,255,255,0.25)',
        }} />
      </div>

      {/* a single warm hairline diagonal — gestural */}
      <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
           preserveAspectRatio="none" viewBox="0 0 100 100">
        <path d="M -2 78 Q 30 70, 55 74 T 102 68"
              fill="none" stroke="rgba(201,168,76,0.18)"
              strokeWidth="0.12" vectorEffect="non-scaling-stroke" />
        <path d="M -2 84 Q 35 80, 62 82 T 102 78"
              fill="none" stroke="rgba(201,168,76,0.10)"
              strokeWidth="0.08" vectorEffect="non-scaling-stroke" />
      </svg>

      {/* paper grain — fractal noise */}
      <svg style={{
        position: 'absolute', inset: 0, width: '100%', height: '100%',
        opacity: 0.18, mixBlendMode: 'overlay',
      }}>
        <filter id="serv-grain">
          <feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" seed="7" />
          <feColorMatrix values="0 0 0 0 0.9
                                 0 0 0 0 0.85
                                 0 0 0 0 0.65
                                 0 0 0 0.55 0" />
        </filter>
        <rect width="100%" height="100%" filter="url(#serv-grain)" />
      </svg>

      <style>{`
        @keyframes serv-drift {
          0%,100% { transform: translate(0,0); }
          50% { transform: translate(40px, -20px); }
        }
        @keyframes serv-drift-2 {
          0%,100% { transform: translate(0,0); }
          50% { transform: translate(-30px, 25px); }
        }
        .serv-glow   { animation: serv-drift   26s ease-in-out infinite; }
        .serv-glow-2 { animation: serv-drift-2 32s ease-in-out infinite; }
      `}</style>
    </div>
  );
}

// HERO
function ServiziHero() {
  const ref = useRefSV(null);
  const isInView = useInViewSV(ref, { once: true });
  return (
    <section ref={ref} style={{
      position: 'relative', overflow: 'hidden',
      padding: '160px 5% 80px',
      background: colors.bgPrimary,
    }}>
      <ServiziAtmosphere />
      <div style={{
        position: 'absolute', inset: 0,
        background: `radial-gradient(ellipse 60% 40% at 50% 30%, rgba(201,168,76,0.08), transparent 70%)`,
        pointerEvents: 'none',
      }} />
      <div style={{
        maxWidth: 920, margin: '0 auto', position: 'relative', zIndex: 1,
        textAlign: 'center',
      }}>
        <motionSV.div
          initial={{ opacity: 0, y: -10 }}
          animate={isInView ? { opacity: 1, y: 0 } : {}}
          transition={{ duration: 0.6 }}
          style={{
            display: 'inline-flex', alignItems: 'center', gap: 10,
            padding: '6px 14px', marginBottom: 28,
            border: `1px solid rgba(201,168,76,0.3)`,
            borderRadius: 999, background: 'rgba(15,15,35,0.6)',
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.7rem', color: colors.textGold,
            letterSpacing: 2, textTransform: 'uppercase', fontWeight: 600,
          }}
        >
          <span style={{ width: 6, height: 6, borderRadius: '50%', background: colors.brandGold, boxShadow: `0 0 8px ${colors.brandGold}` }} />
          Cosa facciamo
        </motionSV.div>
        <motionSV.h1
          initial={{ opacity: 0, y: 20 }}
          animate={isInView ? { opacity: 1, y: 0 } : {}}
          transition={{ duration: 0.7, delay: 0.1 }}
          style={{
            fontFamily: "'Cinzel', serif",
            fontSize: 'clamp(2.6rem, 5.5vw, 4rem)',
            fontWeight: 500, color: colors.textPrimary,
            lineHeight: 1.1, marginBottom: 22, letterSpacing: -0.5,
          }}
        >
          Cinque servizi.<br />
          <span style={{ color: colors.brandGold, fontStyle: 'italic' }}>Un solo obiettivo.</span>
        </motionSV.h1>
        <motionSV.p
          initial={{ opacity: 0 }}
          animate={isInView ? { opacity: 1 } : {}}
          transition={{ duration: 0.7, delay: 0.3 }}
          style={{
            fontSize: '1.15rem', color: colors.textMuted,
            lineHeight: 1.7, fontWeight: 300, maxWidth: 720, margin: '0 auto',
          }}
        >
          Modernizzare il vostro patrimonio IBM i senza fermare la produzione,
          senza buttare via 30 anni di business logic, senza vendor lock-in.
        </motionSV.p>
      </div>
    </section>
  );
}

// SERVIZI — lista dettagliata
function ServiziList() {
  const services = [
    {
      n: '01', icon: 'search', title: 'Strategic Assessment & Legacy Analysis',
      accent: colors.brandGold,
      tagline: 'Capire prima di trasformare.',
      desc: 'Analisi completa dell\'ecosistema IBM i esistente: codice sorgente, dipendenze, business logic, integrazioni, performance. Identifichiamo i punti critici e le opportunità di modernizzazione.',
      deliverables: [
        'Audit codice + mappa dipendenze',
        'Architettura target (to-be) documentata',
        'Roadmap incrementale con milestone',
        'Stima effort e ROI per fase',
      ],
    },
    {
      n: '02', icon: 'book-open', title: 'Documentazione & Knowledge Base',
      accent: colors.brandGoldMuted,
      tagline: 'Conoscenza che resta in azienda.',
      desc: 'Ricostruzione e mantenimento della documentazione tecnica e funzionale del patrimonio IBM i: codice RPG, flussi business, integrazioni, dipendenze. La conoscenza tribale diventa artefatto consultabile, versionato e mantenibile dal vostro team.',
      deliverables: [
        'Mappa codice + grafo dipendenze',
        'Documentazione funzionale per modulo',
        'Diagrammi architetturali e flussi dati',
        'Knowledge base versionata in Git',
      ],
    },
    {
      n: '03', icon: 'workflow', title: 'Consulenza sui Processi Aziendali',
      accent: colors.brandGreen,
      tagline: 'Ripensare il modo in cui l\'azienda lavora.',
      desc: 'Affianchiamo la direzione e i process owner nell\'analisi e nel ridisegno dei processi di business: ordini, fatturazione, supply chain, magazzino, qualità, customer service. Mappiamo i flussi reali, identifichiamo colli di bottiglia e opportunità di automazione, governiamo il cambiamento accanto alle persone.',
      deliverables: [
        'Process map AS-IS dei flussi critici',
        'TO-BE con KPI e punti di automazione',
        'Workshop con process owner e operativi',
        'Roadmap di rollout e change management',
      ],
    },
    {
      n: '04', icon: 'layout-dashboard', title: 'Sviluppo web',
      accent: colors.brandGold,
      tagline: 'Costruiamo il frontend insieme.',
      desc: 'Sviluppo di applicazioni web sopra il vostro core IBM i: architetture moderne, microfrontend, design system condiviso. I primi moduli li costruiamo fianco a fianco con il vostro team, poi vi lasciamo le redini per portare avanti il resto in autonomia.',
      deliverables: [
        'Architettura frontend (microfrontend, design system)',
        'Componenti e SDK riusabili',
        'Moduli in produzione integrati con IBM i',
        'Handoff e mentoring sul team interno',
      ],
      featured: true,
    },
    {
      n: '05', icon: 'graduation-cap', title: 'Formazione & Coaching',
      accent: colors.brandAmber,
      tagline: 'Autonomia, non dipendenza.',
      desc: 'Percorsi formativi su misura per i vostri team: RPG ILE moderno, React e architetture frontend, IBM i contemporaneo, governance del codice. Workshop hands-on, pair programming, mentoring continuo. Trasferiamo competenza dove serve.',
      deliverables: [
        'Percorsi formativi su misura',
        'Workshop hands-on (RPG ILE, React, IBM i)',
        'Pair programming e code review guidata',
        'Materiali e roadmap individuale',
      ],
    },
  ];

  return (
    <AnimatedSection style={{ padding: '100px 5%', background: colors.bgSecondary }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHeading
          eyebrow="// L'offerta"
          title="Servizi"
          sub="Ogni esigenza di modernizzazione ha una risposta dedicata. Ogni servizio è connesso agli altri da un'unica filosofia: zero disruption, totale controllo."
        />

        <div style={{
          display: 'flex', flexDirection: 'column', gap: 28,
          marginTop: 60,
        }}>
          {services.map((svc, i) => (
            <motionSV.div
              key={i}
              initial={{ opacity: 0, y: 20 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ duration: 0.5, delay: i * 0.05 }}
              style={{
                position: 'relative',
                padding: svc.featured ? '36px 36px 36px 56px' : '32px 32px 32px 52px',
                background: svc.featured
                  ? `linear-gradient(135deg, rgba(201,168,76,0.06), rgba(45,106,79,0.03))`
                  : 'rgba(255,255,255,0.02)',
                border: `1px solid ${svc.featured ? svc.accent + '40' : 'rgba(255,255,255,0.06)'}`,
                borderLeft: `3px solid ${svc.accent}`,
                borderRadius: 10,
                transition: 'all 0.3s',
              }}
              onMouseEnter={e => {
                e.currentTarget.style.borderColor = svc.accent + '60';
                e.currentTarget.style.boxShadow = `0 0 30px ${svc.accent}15`;
              }}
              onMouseLeave={e => {
                e.currentTarget.style.borderColor = svc.featured ? svc.accent + '40' : 'rgba(255,255,255,0.06)';
                e.currentTarget.style.boxShadow = 'none';
              }}
            >
              {/* Number tag */}
              <div style={{
                position: 'absolute', top: 28, left: 18,
                fontFamily: "'Courier Prime', monospace",
                fontSize: '0.7rem', color: svc.accent,
                fontWeight: 700, letterSpacing: 1,
                writingMode: 'vertical-rl', transform: 'rotate(180deg)',
              }}>{svc.n}</div>

              <div>
                <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 14 }}>
                  <Icon name={svc.icon} size={26} color={svc.accent} />
                </div>
                <h3 style={{
                  fontFamily: "'DM Sans', sans-serif",
                  fontSize: svc.featured ? '1.55rem' : '1.3rem',
                  fontWeight: 600, color: colors.textPrimary,
                  lineHeight: 1.25, marginBottom: 10,
                }}>{svc.title}</h3>
                <div style={{
                  fontFamily: "'Cinzel', serif",
                  fontSize: '0.95rem', color: svc.accent,
                  fontStyle: 'italic', marginBottom: 18,
                }}>{svc.tagline}</div>
                <p style={{
                  fontSize: '0.96rem', color: colors.textMuted,
                  lineHeight: 1.7, fontWeight: 300, marginBottom: 22,
                  maxWidth: 720,
                }}>{svc.desc}</p>

                {/* Deliverables */}
                <div style={{
                  fontFamily: "'Courier Prime', monospace",
                  fontSize: '0.65rem', color: colors.textGold,
                  letterSpacing: 1.5, textTransform: 'uppercase',
                  fontWeight: 600, marginBottom: 12,
                }}>Deliverables</div>
                <ul style={{
                  listStyle: 'none', padding: 0, margin: 0,
                  display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))',
                  gap: '8px 24px',
                }}>
                  {svc.deliverables.map((d, di) => (
                    <li key={di} style={{
                      fontSize: '0.85rem', color: colors.textPrimary,
                      display: 'flex', alignItems: 'flex-start', gap: 10,
                      lineHeight: 1.5,
                    }}>
                      <Icon name="check" size={14} color={svc.accent} style={{ marginTop: 4, flexShrink: 0 }} />
                      <span>{d}</span>
                    </li>
                  ))}
                </ul>
              </div>
            </motionSV.div>
          ))}
        </div>
      </div>

      <style>{`
        @media (max-width: 768px) {
          .svc-row { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// PROCESSO — Come lavoriamo
function ServiziProcess() {
  const phases = [
    { n: '01', title: 'Discovery', desc: 'Workshop iniziale, mappa stakeholder, comprensione business e tecnologia.', dur: '1–2 settimane' },
    { n: '02', title: 'Assessment', desc: 'Analisi profonda del codice e dell\'ecosistema, identificazione rischi e opportunità.', dur: '2–4 settimane' },
    { n: '03', title: 'Roadmap', desc: 'Piano incrementale con milestone misurabili. Nessun big bang: ogni fase rilascia valore.', dur: '1 settimana' },
    { n: '04', title: 'Esecuzione', desc: 'Implementazione fianco a fianco. Trasferiamo know-how mentre realizziamo.', dur: 'iterativa' },
    { n: '05', title: 'Handoff', desc: 'Documentazione, training, autonomia operativa. Restiamo disponibili per il supporto.', dur: '2 settimane' },
  ];

  return (
    <AnimatedSection style={{ padding: '100px 5%', background: colors.bgPrimary }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHeading
          eyebrow="// Metodo"
          title="Come lavoriamo"
          sub="Cinque fasi, una sola filosofia: trasferiamo competenza, non creiamo dipendenza."
        />

        <div style={{
          marginTop: 60,
          display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)',
          gap: 0, position: 'relative',
        }} className="process-grid">
          {/* connector line */}
          <div style={{
            position: 'absolute', top: 26, left: '10%', right: '10%', height: 1,
            background: `linear-gradient(90deg, ${colors.brandGold}40, ${colors.brandGreen}40)`,
            zIndex: 0,
          }} className="process-line" />

          {phases.map((p, i) => (
            <motionSV.div
              key={i}
              initial={{ opacity: 0, y: 20 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true }}
              transition={{ duration: 0.4, delay: i * 0.1 }}
              style={{
                position: 'relative', zIndex: 1,
                padding: '0 16px', textAlign: 'center',
              }}
            >
              <div style={{
                width: 52, height: 52, margin: '0 auto 18px',
                borderRadius: '50%',
                background: colors.bgPrimary,
                border: `2px solid ${colors.brandGold}`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontFamily: "'Courier Prime', monospace",
                fontSize: '0.9rem', color: colors.brandGold,
                fontWeight: 700,
                boxShadow: `0 0 20px ${colors.brandGold}25`,
              }}>{p.n}</div>
              <h4 style={{
                fontFamily: "'DM Sans', sans-serif",
                fontSize: '1.05rem', fontWeight: 600,
                color: colors.textPrimary, marginBottom: 8,
              }}>{p.title}</h4>
              <p style={{
                fontSize: '0.82rem', color: colors.textMuted,
                lineHeight: 1.6, fontWeight: 300, marginBottom: 10,
              }}>{p.desc}</p>
              <div style={{
                fontFamily: "'Courier Prime', monospace",
                fontSize: '0.68rem', color: colors.textGold,
                letterSpacing: 1, textTransform: 'uppercase',
              }}>{p.dur}</div>
            </motionSV.div>
          ))}
        </div>
      </div>

      <style>{`
        @media (max-width: 900px) {
          .process-grid { grid-template-columns: 1fr 1fr !important; gap: 36px 16px !important; }
          .process-line { display: none; }
        }
        @media (max-width: 540px) {
          .process-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// CTA
function ServiziCta() {
  return (
    <AnimatedSection style={{
      padding: '100px 5%',
      background: `linear-gradient(135deg, ${colors.bgSecondary}, #1a1a3a)`,
      borderTop: `1px solid rgba(255,215,0,0.12)`,
      textAlign: 'center',
    }}>
      <div style={{ maxWidth: 720, margin: '0 auto' }}>
        <h2 style={{
          fontFamily: "'Cinzel', serif",
          fontSize: 'clamp(2rem, 4vw, 2.8rem)',
          fontWeight: 500, color: colors.textPrimary,
          marginBottom: 18, lineHeight: 1.2,
        }}>Quale servizio fa al caso vostro?</h2>
        <p style={{
          fontSize: '1.05rem', color: colors.textMuted,
          lineHeight: 1.7, fontWeight: 300,
          maxWidth: 560, margin: '0 auto 36px',
        }}>
          Una conversazione di 30 minuti basta per capirlo. Raccontateci il vostro
          contesto IBM i: vi diciamo dove possiamo aiutare e dove no.
        </p>
        <div style={{ display: 'inline-flex', gap: 14, flexWrap: 'wrap', justifyContent: 'center' }}>
          <a href="contatti.html" style={{
            fontFamily: "'DM Sans', sans-serif",
            fontSize: '0.95rem', fontWeight: 600,
            padding: '15px 32px',
            background: `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
            color: colors.bgPrimary, borderRadius: 6, textDecoration: 'none',
            letterSpacing: 0.5,
            boxShadow: `0 0 30px rgba(255,215,0,0.25)`,
            display: 'inline-flex', alignItems: 'center', gap: 10,
            transition: 'all 0.3s',
          }}
            onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; }}
            onMouseLeave={e => { e.currentTarget.style.transform = 'translateY(0)'; }}
          >Iniziamo a parlarne <Icon name="arrow-right" size={16} color={colors.bgPrimary} /></a>
          <a href="tecnologia.html" style={{
            fontFamily: "'DM Sans', sans-serif",
            fontSize: '0.95rem', fontWeight: 500,
            padding: '15px 28px',
            background: 'transparent',
            color: colors.textPrimary, borderRadius: 6, textDecoration: 'none',
            border: `1px solid rgba(255,255,255,0.15)`,
            letterSpacing: 0.5,
            display: 'inline-flex', alignItems: 'center', gap: 8,
            transition: 'all 0.3s',
          }}
            onMouseEnter={e => { e.currentTarget.style.borderColor = colors.brandGold; e.currentTarget.style.color = colors.brandGold; }}
            onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255,255,255,0.15)'; e.currentTarget.style.color = colors.textPrimary; }}
          >Vedi la tecnologia</a>
        </div>
      </div>
    </AnimatedSection>
  );
}

// APP
function ServiziApp() {
  return (
    <React.Fragment>
      <SiteNav depth={0} current="servizi" />
      <main>
        <ServiziHero />
        <ServiziList />
        <ServiziProcess />
        <ServiziCta />
      </main>
      <SiteFooter depth={0} />
    </React.Fragment>
  );
}

function mountServizi() {
  const ready =
    typeof colors !== 'undefined' &&
    typeof CompassLogo !== 'undefined' &&
    typeof SiteNav !== 'undefined' &&
    window.FramerMotion &&
    window.lucide;
  if (!ready) return setTimeout(mountServizi, 50);

  const root = ReactDOM.createRoot(document.getElementById('app'));
  root.render(<ServiziApp />);

  if (window.lucide) {
    const observer = new MutationObserver(() => window.lucide.createIcons());
    observer.observe(document.body, { childList: true, subtree: true });
    window.lucide.createIcons();
  }
}
mountServizi();
