// ============================================================
// PAGE — Contatti
// Hero + Form + Info + FAQ + Map placeholder
// ============================================================
const { useState: useStateCT, useRef: useRefCT } = React;
const motionCT = new Proxy({}, { get: (_, p) => window.FramerMotion.motion[p] });
const useInViewCT = (...a) => window.FramerMotion.useInView(...a);

// HERO
function ContattiHero() {
  const ref = useRefCT(null);
  const isInView = useInViewCT(ref, { once: true });
  return (
    <section ref={ref} style={{
      position: 'relative', overflow: 'hidden',
      padding: '160px 5% 60px',
      background: colors.bgPrimary,
    }}>
      {/* Bureau di corrispondenza — postmark, busta, ceralacca, pennino */}
      <div aria-hidden="true" style={{
        position: 'absolute', inset: 0, pointerEvents: 'none', overflow: 'hidden',
      }}>
        <div style={{
          position: 'absolute', inset: 0,
          background: `radial-gradient(ellipse 60% 40% at 50% 30%, rgba(201,168,76,0.1), transparent 70%)`,
        }} />
        <div style={{
          position: 'absolute', inset: 0, opacity: 0.16,
          backgroundImage: 'repeating-linear-gradient(0deg, rgba(255,236,170,0.7) 0 1px, transparent 1px 28px)',
          maskImage: 'radial-gradient(ellipse 70% 80% at 50% 50%, black 50%, transparent 92%)',
          WebkitMaskImage: 'radial-gradient(ellipse 70% 80% at 50% 50%, black 50%, transparent 92%)',
        }} />
        <svg viewBox="0 0 220 220" style={{
          position: 'absolute', top: 90, right: 60, width: 220, height: 220,
          opacity: 0.5, transform: 'rotate(-12deg)',
        }} className="ct-postmark">
          <defs>
            <path id="ct-arc-top" d="M 110 110 m -86 0 a 86 86 0 1 1 172 0" />
            <path id="ct-arc-bot" d="M 110 110 m 78 0 a 78 78 0 1 1 -156 0" />
          </defs>
          <circle cx="110" cy="110" r="98" fill="none" stroke="rgba(255,215,0,0.6)" strokeWidth="1.2" />
          <circle cx="110" cy="110" r="86" fill="none" stroke="rgba(255,215,0,0.4)" strokeWidth="0.7" strokeDasharray="2 4" />
          <text fill="rgba(255,215,0,0.78)" style={{ fontFamily: "'Cinzel', serif", fontSize: '12px', letterSpacing: '4px' }}>
            <textPath href="#ct-arc-top" startOffset="50%" textAnchor="middle">MODENA · ITALIA · LUMIKODE</textPath>
          </text>
          <text fill="rgba(255,215,0,0.55)" style={{ fontFamily: "'Courier Prime', monospace", fontSize: '9.5px', letterSpacing: '3px' }}>
            <textPath href="#ct-arc-bot" startOffset="50%" textAnchor="middle">BUREAU · DE · CORRESPONDANCE</textPath>
          </text>
          <g transform="translate(110 110)" textAnchor="middle">
            <line x1="-52" y1="-14" x2="52" y2="-14" stroke="rgba(255,215,0,0.55)" strokeWidth="0.8" />
            <line x1="-52" y1="16" x2="52" y2="16" stroke="rgba(255,215,0,0.55)" strokeWidth="0.8" />
            <text y="-24" fill="rgba(255,215,0,0.6)" style={{ fontFamily: "'Courier Prime', monospace", fontSize: '9px', letterSpacing: '2px' }}>POSTA · PRIORITARIA</text>
            <text y="6" fill="rgba(255,215,0,0.9)" style={{ fontFamily: "'Cinzel', serif", fontSize: '18px', letterSpacing: '5px', fontWeight: 600 }}>MMXXVI</text>
            <text y="30" fill="rgba(255,215,0,0.6)" style={{ fontFamily: "'Courier Prime', monospace", fontSize: '9px', letterSpacing: '2px' }}>IX · XI</text>
          </g>
        </svg>
        <svg viewBox="0 0 320 220" style={{
          position: 'absolute', top: 60, left: -60, width: 360, height: 240,
          opacity: 0.22, transform: 'rotate(-8deg)',
        }} className="ct-envelope">
          <rect x="20" y="20" width="280" height="180" rx="3" fill="rgba(247,240,222,0.02)" stroke="rgba(255,236,170,0.7)" strokeWidth="1.2" />
          <polyline points="20,20 160,130 300,20" fill="none" stroke="rgba(255,236,170,0.7)" strokeWidth="1.2" />
          {Array.from({ length: 30 }).map((_, i) => (
            <rect key={i} x={20 + i * 9.35} y="202" width="5.6" height="7"
              fill={i % 2 ? 'rgba(220,40,60,0.55)' : 'rgba(50,90,200,0.55)'} />
          ))}
          <g stroke="rgba(255,236,170,0.42)" strokeWidth="1">
            <line x1="180" y1="155" x2="280" y2="155" />
            <line x1="180" y1="170" x2="270" y2="170" />
            <line x1="180" y1="185" x2="258" y2="185" />
          </g>
        </svg>
        <div className="ct-seal" style={{
          position: 'absolute', bottom: 70, left: 60, width: 92, height: 92,
          borderRadius: '52% 48% 50% 50% / 48% 52% 50% 50%',
          background: 'radial-gradient(circle at 35% 30%, #f4c850, #b8862c 55%, #7a4f15)',
          boxShadow: '0 6px 18px rgba(0,0,0,0.5), inset 0 0 0 2px rgba(247,240,222,0.18), inset 0 -6px 12px rgba(0,0,0,0.25)',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          transform: 'rotate(-8deg)',
          opacity: 0.78,
        }}>
          <span style={{
            fontFamily: "'Cinzel', serif", fontSize: '2.4rem', fontWeight: 700,
            color: 'rgba(45,28,8,0.78)', lineHeight: 1,
            textShadow: '0 1px 0 rgba(255,236,170,0.35)',
          }}>L</span>
        </div>
        <svg viewBox="0 0 80 200" style={{
          position: 'absolute', bottom: '12%', right: '6%', width: 64, height: 170,
          opacity: 0.32, transform: 'rotate(18deg)',
        }} className="ct-nib">
          <path d="M 40 4 L 58 92 L 50 184 L 30 184 L 22 92 Z"
            fill="none" stroke="rgba(255,215,0,0.75)" strokeWidth="1.2" />
          <line x1="40" y1="22" x2="40" y2="174" stroke="rgba(255,215,0,0.55)" strokeWidth="0.8" />
          <circle cx="40" cy="108" r="3.2" fill="none" stroke="rgba(255,215,0,0.65)" strokeWidth="0.9" />
        </svg>
        <style>{`
          @media (max-width: 880px) {
            .ct-envelope, .ct-nib, .ct-seal { display: none; }
            .ct-postmark { width: 150px !important; height: 150px !important; opacity: 0.35 !important; top: 60px !important; right: 20px !important; }
          }
        `}</style>
      </div>
      <div style={{
        maxWidth: 920, margin: '0 auto', position: 'relative', zIndex: 1,
        textAlign: 'center',
      }}>
        <motionCT.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.brandGreen, boxShadow: `0 0 8px ${colors.brandGreen}`, animation: 'blink 1.6s ease-in-out infinite' }} />
          Iniziamo
        </motionCT.div>
        <motionCT.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,
          }}
        >
          Ogni progetto inizia<br />
          <span style={{ color: colors.brandGold, fontStyle: 'italic' }}>con una conversazione.</span>
        </motionCT.h1>
        <motionCT.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: 680, margin: '0 auto',
          }}
        >
          Raccontateci il vostro ecosistema IBM i. Vi richiamiamo entro 24 ore
          con una prima valutazione e un piano per i prossimi passi.
        </motionCT.p>
      </div>
    </section>
  );
}

// FORM + INFO
function ContattiBody() {
  const [formData, setFormData] = useStateCT({
    name: '', email: '', company: '', phone: '', topic: 'assessment', message: '',
  });
  const [submitted, setSubmitted] = useStateCT(false);
  const [sending, setSending] = useStateCT(false);
  const [sendError, setSendError] = useStateCT(null);

  const FORM_ENDPOINT = 'https://script.google.com/macros/s/AKfycbz04kMKLUaY6c-Vcwck-xOzrHjq3W6vTk9Z8ai2SH2g1oF1npZEEEqrIm3RSbEPNQj_/exec';

  const handleChange = e => setFormData({ ...formData, [e.target.name]: e.target.value });
  const handleSubmit = async e => {
    e.preventDefault();
    if (sending) return;
    setSending(true);
    setSendError(null);

    const topicLabels = {
      assessment: 'Assessment iniziale',
      aiko: 'Modernizzazione (AiKo)',
      kodari: 'API & Integration (Kodari)',
      lumiere: 'Frontend (Lumiere)',
      lestage: 'File Flow (Lestage)',
      altro: 'Altro / Non sicuro',
    };

    const payload = {
      name: formData.name,
      email: formData.email,
      company: formData.company,
      phone: formData.phone,
      topic: topicLabels[formData.topic] || formData.topic,
      message: formData.message,
    };

    try {
      // Apps Script web apps don't handle CORS preflights, so we use
      // text/plain to keep this a "simple" CORS request.
      const res = await fetch(FORM_ENDPOINT, {
        method: 'POST',
        headers: { 'Content-Type': 'text/plain;charset=utf-8' },
        body: JSON.stringify(payload),
      });
      const data = await res.json().catch(() => ({}));
      if (!res.ok || data.ok === false) {
        throw new Error(data.error || 'Errore di invio');
      }
      setSubmitted(true);
      setTimeout(() => {
        setSubmitted(false);
        setFormData({ name: '', email: '', company: '', phone: '', topic: 'assessment', message: '' });
      }, 6000);
    } catch (err) {
      setSendError('Non siamo riusciti a inviare il messaggio. Scriveteci direttamente a info@lumikode.io.');
      console.error('[contatti] invio fallito:', err);
    } finally {
      setSending(false);
    }
  };

  const inputStyle = {
    width: '100%',
    padding: '13px 16px',
    background: 'rgba(15,15,35,0.6)',
    border: '1px solid rgba(255,215,0,0.15)',
    borderRadius: 6,
    color: colors.textPrimary,
    fontFamily: "'DM Sans', sans-serif",
    fontSize: '0.92rem',
    transition: 'border-color 0.2s, box-shadow 0.2s',
    outline: 'none',
  };
  const labelStyle = {
    display: 'block',
    fontFamily: "'Courier Prime', monospace",
    fontSize: '0.68rem', color: colors.textGold,
    letterSpacing: 1.5, textTransform: 'uppercase',
    fontWeight: 600, marginBottom: 8,
  };

  const topics = [
    { v: 'assessment', l: 'Strategic Assessment' },
    { v: 'aiko', l: 'Modernizzazione (AiKo)' },
    { v: 'kodari', l: 'API & Integration (Kodari)' },
    { v: 'lumiere', l: 'Frontend (Lumiere)' },
    { v: 'lestage', l: 'File Flow (Lestage)' },
    { v: 'altro', l: 'Altro / Non sicuro' },
  ];

  return (
    <AnimatedSection style={{ padding: '60px 5% 100px', background: colors.bgPrimary }}>
      <div style={{
        maxWidth: 1100, margin: '0 auto',
        display: 'grid', gridTemplateColumns: '1.4fr 1fr',
        gap: 50,
      }} className="contact-grid">

        {/* FORM */}
        <div style={{
          padding: '40px 36px',
          background: 'rgba(255,255,255,0.02)',
          border: '1px solid rgba(255,215,0,0.15)',
          borderRadius: 12,
        }}>
          <div style={{
            fontFamily: "'Courier Prime', monospace",
            fontSize: '0.68rem', color: colors.textGold,
            letterSpacing: 2, textTransform: 'uppercase',
            fontWeight: 700, marginBottom: 8,
          }}>// Form</div>
          <h2 style={{
            fontFamily: "'DM Sans', sans-serif",
            fontSize: '1.5rem', fontWeight: 600,
            color: colors.textPrimary, marginBottom: 28,
          }}>Scriveteci</h2>

          {submitted ? (
            <div style={{
              padding: '40px 24px', textAlign: 'center',
              background: `linear-gradient(135deg, rgba(45,106,79,0.1), rgba(201,168,76,0.05))`,
              border: `1px solid ${colors.brandGreen}40`,
              borderRadius: 10,
            }}>
              <Icon name="check-circle-2" size={42} color={colors.brandGreen} style={{ marginBottom: 14 }} />
              <h3 style={{
                fontFamily: "'Cinzel', serif",
                fontSize: '1.4rem', color: colors.brandGreen,
                fontStyle: 'italic', marginBottom: 8,
              }}>Messaggio ricevuto</h3>
              <p style={{ fontSize: '0.9rem', color: colors.textMuted, lineHeight: 1.6 }}>
                Grazie. Vi richiamiamo entro 24 ore lavorative.
              </p>
            </div>
          ) : (
            <form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
              <div style={{
                display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16,
              }} className="form-row">
                <div>
                  <label style={labelStyle}>Nome*</label>
                  <input type="text" name="name" value={formData.name} onChange={handleChange} required
                    style={inputStyle}
                    onFocus={e => { e.target.style.borderColor = colors.brandGold; e.target.style.boxShadow = `0 0 0 3px ${colors.brandGold}15`; }}
                    onBlur={e => { e.target.style.borderColor = 'rgba(255,215,0,0.15)'; e.target.style.boxShadow = 'none'; }}
                  />
                </div>
                <div>
                  <label style={labelStyle}>Azienda</label>
                  <input type="text" name="company" value={formData.company} onChange={handleChange}
                    style={inputStyle}
                    onFocus={e => { e.target.style.borderColor = colors.brandGold; e.target.style.boxShadow = `0 0 0 3px ${colors.brandGold}15`; }}
                    onBlur={e => { e.target.style.borderColor = 'rgba(255,215,0,0.15)'; e.target.style.boxShadow = 'none'; }}
                  />
                </div>
              </div>
              <div style={{
                display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16,
              }} className="form-row">
                <div>
                  <label style={labelStyle}>Email*</label>
                  <input type="email" name="email" value={formData.email} onChange={handleChange} required
                    style={inputStyle}
                    onFocus={e => { e.target.style.borderColor = colors.brandGold; e.target.style.boxShadow = `0 0 0 3px ${colors.brandGold}15`; }}
                    onBlur={e => { e.target.style.borderColor = 'rgba(255,215,0,0.15)'; e.target.style.boxShadow = 'none'; }}
                  />
                </div>
                <div>
                  <label style={labelStyle}>Telefono</label>
                  <input type="tel" name="phone" value={formData.phone} onChange={handleChange}
                    style={inputStyle}
                    onFocus={e => { e.target.style.borderColor = colors.brandGold; e.target.style.boxShadow = `0 0 0 3px ${colors.brandGold}15`; }}
                    onBlur={e => { e.target.style.borderColor = 'rgba(255,215,0,0.15)'; e.target.style.boxShadow = 'none'; }}
                  />
                </div>
              </div>
              <div>
                <label style={labelStyle}>Argomento</label>
                <div style={{
                  display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)',
                  gap: 8,
                }} className="topic-grid">
                  {topics.map(t => (
                    <label key={t.v} style={{
                      cursor: 'pointer',
                      padding: '10px 12px',
                      background: formData.topic === t.v ? `${colors.brandGold}12` : 'rgba(15,15,35,0.4)',
                      border: `1px solid ${formData.topic === t.v ? colors.brandGold : 'rgba(255,215,0,0.12)'}`,
                      borderRadius: 6,
                      fontSize: '0.78rem',
                      color: formData.topic === t.v ? colors.brandGold : colors.textMuted,
                      fontWeight: formData.topic === t.v ? 600 : 400,
                      transition: 'all 0.15s',
                      textAlign: 'center',
                      display: 'flex', alignItems: 'center', justifyContent: 'center',
                    }}>
                      <input type="radio" name="topic" value={t.v} checked={formData.topic === t.v}
                        onChange={handleChange}
                        style={{ display: 'none' }}
                      />
                      {t.l}
                    </label>
                  ))}
                </div>
              </div>
              <div>
                <label style={labelStyle}>Messaggio*</label>
                <textarea name="message" value={formData.message} onChange={handleChange} required rows={5}
                  placeholder="Raccontateci il vostro contesto: che sistema IBM i avete, da quanti utenti è usato, cosa vorreste modernizzare per primo…"
                  style={{ ...inputStyle, resize: 'vertical', minHeight: 120, fontFamily: "'DM Sans', sans-serif" }}
                  onFocus={e => { e.target.style.borderColor = colors.brandGold; e.target.style.boxShadow = `0 0 0 3px ${colors.brandGold}15`; }}
                  onBlur={e => { e.target.style.borderColor = 'rgba(255,215,0,0.15)'; e.target.style.boxShadow = 'none'; }}
                />
              </div>
              <button type="submit" disabled={sending} style={{
                marginTop: 8,
                padding: '15px 28px',
                background: sending
                  ? `linear-gradient(135deg, ${colors.brandGoldMuted}, ${colors.brandGoldMuted})`
                  : `linear-gradient(135deg, ${colors.brandGold}, ${colors.brandGoldMuted})`,
                color: colors.bgPrimary,
                border: 'none', borderRadius: 6,
                cursor: sending ? 'wait' : 'pointer',
                opacity: sending ? 0.75 : 1,
                fontFamily: "'DM Sans', sans-serif",
                fontSize: '0.95rem', fontWeight: 600, letterSpacing: 0.5,
                boxShadow: `0 0 25px rgba(255,215,0,0.2)`,
                display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 10,
                transition: 'all 0.3s',
              }}
                onMouseEnter={e => { if (sending) return; e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 6px 35px rgba(255,215,0,0.3)'; }}
                onMouseLeave={e => { if (sending) return; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 0 25px rgba(255,215,0,0.2)'; }}
              >
                {sending ? 'Invio in corso…' : 'Invia messaggio'}
                {!sending && <Icon name="send" size={15} color={colors.bgPrimary} />}
              </button>
              {sendError && (
                <div style={{
                  padding: '12px 14px',
                  background: 'rgba(255,90,90,0.08)',
                  border: '1px solid rgba(255,90,90,0.35)',
                  borderRadius: 6,
                  fontSize: '0.82rem',
                  color: '#ffb4b4',
                  lineHeight: 1.5,
                }}>{sendError}</div>
              )}
              <p style={{
                fontSize: '0.72rem', color: colors.textDim,
                lineHeight: 1.5, marginTop: 4,
              }}>
                Trattiamo i vostri dati secondo il GDPR. Nessun newsletter automatica,
                nessun spam. Vi rispondiamo solo per rispondere.
              </p>
            </form>
          )}
        </div>

        {/* INFO */}
        <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
          <div style={{
            padding: '28px 26px',
            background: 'rgba(45,106,79,0.04)',
            border: `1px solid ${colors.brandGreen}30`,
            borderRadius: 10,
          }}>
            <Icon name="map-pin" size={22} color={colors.brandGreen} style={{ marginBottom: 12 }} />
            <h4 style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '1rem', fontWeight: 600,
              color: colors.textPrimary, marginBottom: 6,
            }}>Sede</h4>
            <p style={{ fontSize: '0.92rem', color: colors.textPrimary, marginBottom: 4, fontWeight: 500 }}>Sassuolo (MO)</p>
            <p style={{ fontSize: '0.85rem', color: colors.textMuted, lineHeight: 1.5, marginBottom: 14 }}>
              Via Circonvallazione Nord Est 229<br />
              41049 Sassuolo (MO), Italia
            </p>
            <div style={{
              position: 'relative',
              width: '100%', height: 220,
              borderRadius: 8, overflow: 'hidden',
              border: `1px solid ${colors.brandGreen}30`,
              marginBottom: 12,
              background: '#0a1110',
            }}>
              <iframe
                title="Mappa sede Lumikode"
                src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2843.2709886472253!2d10.7968467!3d44.550557399999995!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x477ffc96f1c50a4d%3A0xe3cdef4bca191ab9!2sVia%20Circonvallazione%20Nordest%2C%20229%2C%2041049%20Sassuolo%20MO!5e0!3m2!1sit!2sit!4v1778929300955!5m2!1sit!2sit"
                loading="lazy"
                allowFullScreen
                referrerPolicy="no-referrer-when-downgrade"
                style={{
                  width: '100%', height: '100%', border: 0, display: 'block',
                  filter: 'grayscale(0.35) contrast(0.95) brightness(0.9)',
                }}
              />
            </div>
            <a
              href="https://www.google.com/maps/search/?api=1&query=Via+Circonvallazione+Nord+Est+229,+41049+Sassuolo+MO"
              target="_blank"
              rel="noopener noreferrer"
              style={{
                display: 'inline-flex', alignItems: 'center', gap: 6,
                fontSize: '0.78rem', color: colors.brandGreen,
                textDecoration: 'none', fontWeight: 600,
                marginBottom: 8,
              }}
            >
              Apri in Google Maps <Icon name="arrow-up-right" size={12} color={colors.brandGreen} />
            </a>
            <p style={{ fontSize: '0.82rem', color: colors.textMuted, lineHeight: 1.5, marginTop: 4 }}>
              Servizio in tutta Italia. Trasferte e on-site su richiesta.
            </p>
          </div>

          <div style={{
            padding: '28px 26px',
            background: 'rgba(201,168,76,0.04)',
            border: `1px solid ${colors.brandGold}30`,
            borderRadius: 10,
          }}>
            <Icon name="mail" size={22} color={colors.brandGold} style={{ marginBottom: 12 }} />
            <h4 style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '1rem', fontWeight: 600,
              color: colors.textPrimary, marginBottom: 10,
            }}>Email</h4>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
              <a href="mailto:info@lumikode.io" style={{
                fontFamily: "'Courier Prime', monospace",
                fontSize: '0.86rem', color: colors.textGold,
                textDecoration: 'none',
              }}>info@lumikode.io</a>
            </div>
          </div>

          <div style={{
            padding: '28px 26px',
            background: 'rgba(255,255,255,0.02)',
            border: '1px solid rgba(255,255,255,0.08)',
            borderRadius: 10,
          }}>
            <Icon name="file-text" size={22} color={colors.textGold} style={{ marginBottom: 12 }} />
            <h4 style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '1rem', fontWeight: 600,
              color: colors.textPrimary, marginBottom: 10,
            }}>Dati societari</h4>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 8, fontSize: '0.82rem', color: colors.textMuted, lineHeight: 1.5 }}>
              <div>
                <span style={{ display: 'block', fontFamily: "'Courier Prime', monospace", fontSize: '0.7rem', color: colors.textGold, letterSpacing: 1, textTransform: 'uppercase', marginBottom: 2 }}>P. IVA / Cod. Fisc.</span>
                <span style={{ fontFamily: "'Courier Prime', monospace", color: colors.textPrimary }}>04223040363</span>
              </div>
              <div>
                <span style={{ display: 'block', fontFamily: "'Courier Prime', monospace", fontSize: '0.7rem', color: colors.textGold, letterSpacing: 1, textTransform: 'uppercase', marginBottom: 2 }}>Reg. Imprese Modena</span>
                <span style={{ fontFamily: "'Courier Prime', monospace", color: colors.textPrimary }}>04223040363</span>
              </div>
              <div>
                <span style={{ display: 'block', fontFamily: "'Courier Prime', monospace", fontSize: '0.7rem', color: colors.textGold, letterSpacing: 1, textTransform: 'uppercase', marginBottom: 2 }}>Codice SDI</span>
                <span style={{ fontFamily: "'Courier Prime', monospace", color: colors.textPrimary }}>SUBM70N</span>
              </div>
            </div>
          </div>

          <div style={{
            padding: '28px 26px',
            background: 'rgba(255,255,255,0.02)',
            border: '1px solid rgba(255,255,255,0.08)',
            borderRadius: 10,
          }}>
            <Icon name="clock" size={22} color={colors.brandCyan} style={{ marginBottom: 12 }} />
            <h4 style={{
              fontFamily: "'DM Sans', sans-serif",
              fontSize: '1rem', fontWeight: 600,
              color: colors.textPrimary, marginBottom: 6,
            }}>Tempi di risposta</h4>
            <p style={{ fontSize: '0.85rem', color: colors.textMuted, lineHeight: 1.6 }}>
              Lun–Ven, 9:00–18:00 CET<br />
              Risposta entro 24h lavorative.
            </p>
          </div>

          <div style={{
            padding: '24px 24px',
            background: `linear-gradient(135deg, rgba(201,168,76,0.06), rgba(45,106,79,0.04))`,
            border: `1px dashed ${colors.brandGold}40`,
            borderRadius: 10,
          }}>
            <div style={{
              fontFamily: "'Courier Prime', monospace",
              fontSize: '0.65rem', color: colors.brandGold,
              letterSpacing: 1.5, textTransform: 'uppercase',
              fontWeight: 700, marginBottom: 10,
            }}>// Demo gratuita</div>
            <p style={{
              fontSize: '0.85rem', color: colors.textPrimary,
              lineHeight: 1.6, fontWeight: 300,
            }}>
              Mandateci uno o due programmi RPG rappresentativi:
              vi mostriamo l'analisi a 5 dimensioni di AiKo Engine
              e una conversione di esempio.
            </p>
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 880px) {
          .contact-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
          .form-row { grid-template-columns: 1fr !important; }
          .topic-grid { grid-template-columns: 1fr 1fr !important; }
        }
      `}</style>
    </AnimatedSection>
  );
}

// FAQ
function ContattiFaq() {
  const faqs = [
    {
      q: 'Quanto costa una valutazione iniziale?',
      a: 'Niente. La prima conversazione (30–60 min) è gratuita e serve a capire se possiamo davvero aiutarvi. Se non è il nostro ambito, ve lo diciamo subito.',
    },
    {
      q: 'Lavorate solo con clienti grandi?',
      a: 'No. Lavoriamo con qualunque azienda abbia un patrimonio IBM i da modernizzare. La complessità varia, l\'approccio no.',
    },
    /* TODO ripristinare:
    {
      q: 'Possiamo ricevere il codice prodotto?',
      a: 'Sì, sempre. Tutto il codice (frontend, API, RPG) viene consegnato in un repository di vostra proprietà. Nessun runtime proprietario, nessun lock-in.',
    },
    */
    {
      q: 'Lavorate solo in Italia?',
      a: 'Principalmente sì, ma non esclusivamente. Possiamo lavorare anche all\'estero.',
    },
    {
      q: 'Quanto tempo serve per la prima conversione AiKo?',
      a: 'Una settimana per il setup e il primo programma di esempio. Da lì la pipeline scala in modo prevedibile, con review umana inclusa.',
    },
  ];
  const [open, setOpen] = useStateCT(0);

  return (
    <AnimatedSection style={{ padding: '90px 5%', background: colors.bgSecondary }}>
      <div style={{ maxWidth: 820, margin: '0 auto' }}>
        <SectionHeading
          eyebrow="// Domande frequenti"
          title="Le domande che ci fanno"
          sub="Le risposte oneste, senza marketing-speak."
        />
        <div style={{
          display: 'flex', flexDirection: 'column', gap: 8,
          marginTop: 50,
        }}>
          {faqs.map((f, i) => {
            const isOpen = open === i;
            return (
              <div key={i} style={{
                background: isOpen ? 'rgba(201,168,76,0.04)' : 'rgba(255,255,255,0.02)',
                border: `1px solid ${isOpen ? colors.brandGold + '30' : 'rgba(255,255,255,0.06)'}`,
                borderRadius: 8,
                transition: 'all 0.2s',
                overflow: 'hidden',
              }}>
                <button onClick={() => setOpen(isOpen ? -1 : i)} style={{
                  width: '100%',
                  padding: '20px 24px',
                  background: 'transparent', border: 'none',
                  cursor: 'pointer',
                  display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                  gap: 16, textAlign: 'left',
                  color: isOpen ? colors.brandGold : colors.textPrimary,
                  fontFamily: "'DM Sans', sans-serif",
                  fontSize: '0.98rem', fontWeight: 500,
                }}>
                  <span>{f.q}</span>
                  <Icon name={isOpen ? 'minus' : 'plus'} size={16} color={isOpen ? colors.brandGold : colors.textMuted} />
                </button>
                {isOpen && (
                  <div style={{
                    padding: '0 24px 22px',
                    fontSize: '0.9rem', color: colors.textMuted,
                    lineHeight: 1.7, fontWeight: 300,
                  }}>{f.a}</div>
                )}
              </div>
            );
          })}
        </div>
      </div>
    </AnimatedSection>
  );
}

// APP
function ContattiApp() {
  return (
    <React.Fragment>
      <SiteNav depth={0} current="contatti" />
      <main>
        <ContattiHero />
        <ContattiBody />
        <ContattiFaq />
      </main>
      <SiteFooter depth={0} />
    </React.Fragment>
  );
}

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

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

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