// preview.jsx — Anteprima screens, payment sheet, success
const { useState: useStateP, useEffect: useEffectP, useRef: useRefP } = React;

// ─────────────────────────────────────────────────────────────
// 6. Preview grid (2x2)
// ─────────────────────────────────────────────────────────────
function PreviewGridScreen({ state, setState, back, openInvite, restart }) {
  return (
    <div className="app-shell fade-step">
      <div style={{ padding: '14px 20px 6px', display: 'flex', alignItems: 'center', gap: 12 }}>
        <button onClick={back} className="iconbtn" aria-label="indietro" style={{ width: 36, height: 36, background: '#fff' }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
            <path d="M15 18 L 9 12 L 15 6"/>
          </svg>
        </button>
        <div style={{ flex: 1, textAlign: 'center', fontSize: 14, fontWeight: 700, color: 'var(--ink-2)' }}>
          Le tue 4 anteprime
        </div>
        <button onClick={restart} className="iconbtn" aria-label="ricomincia" style={{ width: 36, height: 36, background: '#fff' }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
            <path d="M3 12 A 9 9 0 1 1 6 18.7 M 3 19 V 13 H 9"/>
          </svg>
        </button>
      </div>

      <div className="app-scroll" style={{ padding: '12px 20px 24px' }}>
        <div style={{
          padding: '14px 16px', background: '#fff', borderRadius: 16, border: '1px solid var(--line)',
          display: 'flex', alignItems: 'center', gap: 12, marginBottom: 18,
        }}>
          <div style={{
            width: 44, height: 44, borderRadius: 12,
            background: THEMES[state.tema].palette.primary, color: '#fff',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: 'DM Serif Display, serif', fontSize: 22,
          }}>{state.eta}</div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontSize: 16, fontWeight: 700, lineHeight: 1.2 }}>
              {state.nome} · {THEMES[state.tema].name}
            </div>
            <div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 2 }}>
              {formatDateLong(state.data)} · {state.ora}
            </div>
          </div>
          <button
            onClick={back}
            style={{
              fontSize: 12, fontWeight: 700, color: 'var(--ink)',
              padding: '6px 10px', borderRadius: 999, background: 'var(--bg-2)',
            }}
          >Modifica</button>
        </div>

        <div style={{ fontSize: 13, color: 'var(--ink-2)', marginBottom: 12, fontWeight: 500 }}>
          Tocca un invito per vederlo grande.
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
          {LAYOUTS.map((layout, i) => (
            <div key={layout.id} onClick={() => openInvite(layout.id)} className="invite-card">
              <Invitation themeId={state.tema} layoutId={layout.id} data={state} />
              <div className="watermark-layer" />
              <div style={{
                position: 'absolute', top: 8, left: 8,
                background: 'rgba(255,255,255,0.92)',
                color: 'var(--ink)', fontSize: 9, fontWeight: 700,
                padding: '4px 8px', borderRadius: 999,
                letterSpacing: '0.05em',
                textTransform: 'uppercase',
              }}>
                Stile {i + 1}
              </div>
              <div style={{
                position: 'absolute', bottom: 8, right: 8,
                background: 'var(--ink)', color: '#fff',
                fontSize: 11, fontWeight: 700,
                padding: '5px 10px', borderRadius: 999,
              }}>
                {layout.name}
              </div>
            </div>
          ))}
        </div>
      </div>

      <div style={{ padding: '12px 20px 20px', borderTop: '1px solid var(--line)', background: '#fff' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 12, color: 'var(--ink-3)' }}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
            <rect x="4" y="8" width="16" height="12" rx="2"/><path d="M8 8 V 6 a 4 4 0 0 1 8 0 V 8"/>
          </svg>
          <span>Le anteprime hanno il watermark. <b style={{ color: 'var(--ink)' }}>1€</b> per scaricarlo senza.</span>
        </div>
      </div>
    </div>
  );
}

function formatDateLong(iso) {
  if (!iso) return '—';
  const d = new Date(iso);
  if (isNaN(d)) return iso;
  const months = ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic'];
  return `${d.getDate()} ${months[d.getMonth()]} ${d.getFullYear()}`;
}

// ─────────────────────────────────────────────────────────────
// 7. Single invite fullscreen + CTA
// ─────────────────────────────────────────────────────────────
function InvitePreviewScreen({ state, layoutId, format = 'statico', back, onPay, onChangeLayout, onChangeFormat }) {
  return (
    <div className="app-shell fade-step" style={{ background: 'var(--bg)' }}>
      <div style={{ padding: '14px 20px 6px', display: 'flex', alignItems: 'center', gap: 12 }}>
        <button onClick={back} className="iconbtn" aria-label="indietro" style={{ width: 36, height: 36, background: '#fff' }}>
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
            <path d="M15 18 L 9 12 L 15 6"/>
          </svg>
        </button>
        <div style={{ flex: 1, textAlign: 'center', fontSize: 14, fontWeight: 700, color: 'var(--ink-2)' }}>
          Anteprima
        </div>
        <div style={{ width: 36 }} />
      </div>

      <div className="app-scroll" style={{ padding: '8px 22px 16px' }}>
        <div style={{ position: 'relative', boxShadow: 'var(--shadow-lg)', borderRadius: 14, overflow: 'hidden' }}>
          <div style={{ position: 'relative', aspectRatio: '3 / 4' }}>
            <FormattedInvite format={format} themeId={state.tema} layoutId={layoutId} data={state} />
            <div className="watermark-layer" />
            <div className="watermark-text">
              <div>
                {Array.from({ length: 24 }).map((_, i) => <span key={i}>Invitino</span>)}
              </div>
            </div>
          </div>
        </div>

        {/* FORMAT picker */}
        <div style={{ marginTop: 18 }}>
          <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--ink-2)', letterSpacing: '0.05em', marginBottom: 8 }}>
            FORMATO
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
            {FORMATS.map(f => {
              const sel = f.id === format;
              const isPremium = f.id !== 'statico';
              return (
                <button
                  key={f.id}
                  onClick={() => onChangeFormat(f.id)}
                  style={{
                    position: 'relative',
                    padding: '10px 4px 8px',
                    borderRadius: 12,
                    background: sel ? 'var(--ink)' : '#fff',
                    color: sel ? '#fff' : 'var(--ink)',
                    border: sel ? '2px solid var(--ink)' : '1.5px solid var(--line-2)',
                    display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
                    transition: 'all 0.15s',
                  }}
                >
                  <span style={{ fontSize: 18, lineHeight: 1 }}>{f.icon}</span>
                  <span style={{ fontSize: 11, fontWeight: 700 }}>{f.name}</span>
                  {isPremium && !sel && (
                    <span style={{
                      position: 'absolute', top: -5, right: -5,
                      background: 'var(--primary)', color: '#fff',
                      fontSize: 8, fontWeight: 800, letterSpacing: '0.05em',
                      padding: '2px 5px', borderRadius: 999,
                    }}>+1€</span>
                  )}
                </button>
              );
            })}
          </div>
          <div style={{ marginTop: 6, fontSize: 11, color: 'var(--ink-3)', textAlign: 'center' }}>
            {FORMATS.find(f => f.id === format)?.desc}
          </div>
        </div>

        {/* layout switcher */}
        <div style={{ marginTop: 18 }}>
          <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--ink-2)', letterSpacing: '0.05em', marginBottom: 8 }}>
            CAMBIA STILE
          </div>
          <div style={{ display: 'flex', gap: 8, overflowX: 'auto', paddingBottom: 4 }}>
            {LAYOUTS.map(l => {
              const sel = l.id === layoutId;
              return (
                <button
                  key={l.id}
                  onClick={() => onChangeLayout(l.id)}
                  style={{
                    flexShrink: 0, width: 64,
                    display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6,
                  }}
                >
                  <div style={{
                    position: 'relative', width: 60, aspectRatio: '3 / 4',
                    borderRadius: 8, overflow: 'hidden',
                    border: sel ? '2px solid var(--ink)' : '2px solid transparent',
                    boxShadow: 'var(--shadow-sm)',
                  }}>
                    <Invitation themeId={state.tema} layoutId={l.id} data={state} />
                  </div>
                  <span style={{ fontSize: 11, fontWeight: 600, color: sel ? 'var(--ink)' : 'var(--ink-3)' }}>{l.name}</span>
                </button>
              );
            })}
          </div>
        </div>
      </div>

      <div style={{ padding: '14px 20px 22px', borderTop: '1px solid var(--line)', background: '#fff' }}>
        <button className="btn-primary" style={{ width: '100%' }} onClick={onPay}>
          <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
            <path d="M17.04 13.36c-.03-2.92 2.39-4.32 2.5-4.39-1.36-1.99-3.48-2.27-4.24-2.3-1.81-.18-3.53 1.07-4.45 1.07-.92 0-2.34-1.04-3.84-1.01C5.07 6.76 3.3 7.88 2.34 9.6c-1.66 2.88-.42 7.13 1.18 9.47.78 1.14 1.7 2.43 2.93 2.39 1.18-.05 1.62-.76 3.04-.76 1.42 0 1.81.76 3.05.74 1.26-.02 2.06-1.16 2.83-2.31.9-1.32 1.27-2.61 1.29-2.68-.03-.01-2.47-.95-2.5-3.79zM14.7 4.6c.65-.79 1.09-1.89.97-2.97-.94.04-2.07.62-2.74 1.4-.6.7-1.13 1.81-.99 2.87 1.04.08 2.11-.52 2.76-1.3z"/>
          </svg>
          Scarica per {format === 'statico' ? '1,00' : '2,00'} €
        </button>
        <div style={{ marginTop: 10, fontSize: 11, color: 'var(--ink-3)', textAlign: 'center', display: 'flex', justifyContent: 'center', alignItems: 'center', gap: 6 }}>
          <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
            <rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10 V 7 a 4 4 0 0 1 8 0 V 10"/>
          </svg>
          Pagamento sicuro · Scarichi subito senza watermark
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// 8. Apple Pay-like sheet
// ─────────────────────────────────────────────────────────────
function PaySheet({ state, layoutId, onCancel, onSuccess }) {
  const [paying, setPaying] = useStateP(false);
  const [done, setDone] = useStateP(false);

  const handlePay = () => {
    setPaying(true);
    setTimeout(() => {
      setDone(true);
      setTimeout(onSuccess, 700);
    }, 1400);
  };

  return (
    <>
      <div className="sheet-backdrop" onClick={paying ? null : onCancel} />
      <div className="sheet">
        {/* grabber */}
        <div style={{ display: 'flex', justifyContent: 'center', padding: '8px 0' }}>
          <div style={{ width: 40, height: 5, borderRadius: 3, background: 'rgba(0,0,0,0.18)' }} />
        </div>

        <div style={{ padding: '8px 24px 0' }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 14, fontWeight: 700 }}>
              <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
                <path d="M17.04 13.36c-.03-2.92 2.39-4.32 2.5-4.39-1.36-1.99-3.48-2.27-4.24-2.3-1.81-.18-3.53 1.07-4.45 1.07-.92 0-2.34-1.04-3.84-1.01C5.07 6.76 3.3 7.88 2.34 9.6c-1.66 2.88-.42 7.13 1.18 9.47.78 1.14 1.7 2.43 2.93 2.39 1.18-.05 1.62-.76 3.04-.76 1.42 0 1.81.76 3.05.74 1.26-.02 2.06-1.16 2.83-2.31.9-1.32 1.27-2.61 1.29-2.68-.03-.01-2.47-.95-2.5-3.79zM14.7 4.6c.65-.79 1.09-1.89.97-2.97-.94.04-2.07.62-2.74 1.4-.6.7-1.13 1.81-.99 2.87 1.04.08 2.11-.52 2.76-1.3z"/>
              </svg>
              Pay
            </div>
            <button onClick={onCancel} disabled={paying} style={{ fontSize: 14, color: paying ? 'var(--ink-3)' : 'var(--primary)', fontWeight: 600 }}>Annulla</button>
          </div>

          <div style={{ marginTop: 18, fontSize: 13, color: 'var(--ink-3)', textTransform: 'uppercase', letterSpacing: '0.08em', fontWeight: 700 }}>
            Paga Invitino
          </div>

          {/* item row */}
          <div style={{
            marginTop: 12,
            display: 'flex', alignItems: 'center', gap: 12,
            padding: '10px 0', borderBottom: '1px solid var(--line)',
          }}>
            <div style={{
              width: 48, aspectRatio: '3 / 4', borderRadius: 6, overflow: 'hidden',
              boxShadow: 'var(--shadow-sm)', flexShrink: 0,
            }}>
              <Invitation themeId={state.tema} layoutId={layoutId} data={state} />
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontSize: 14, fontWeight: 700 }}>Invito {THEMES[state.tema].name}</div>
              <div style={{ fontSize: 12, color: 'var(--ink-3)' }}>PNG ad alta risoluzione · senza watermark</div>
            </div>
            <div style={{ fontSize: 16, fontWeight: 700 }}>1,00 €</div>
          </div>

          <div style={{
            display: 'flex', justifyContent: 'space-between', alignItems: 'center',
            padding: '14px 0', borderBottom: '1px solid var(--line)', fontSize: 14,
          }}>
            <span style={{ color: 'var(--ink-2)' }}>Totale</span>
            <span style={{ fontSize: 18, fontWeight: 800 }}>1,00 €</span>
          </div>

          {/* card row */}
          <div style={{
            marginTop: 14, padding: '14px',
            background: 'var(--bg-2)', borderRadius: 14,
            display: 'flex', alignItems: 'center', gap: 12,
          }}>
            <div style={{
              width: 44, height: 28, borderRadius: 4,
              background: 'linear-gradient(135deg, #1a1a2e 0%, #2d2d4a 100%)',
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              color: '#fff', fontWeight: 800, fontSize: 9, letterSpacing: '0.05em',
            }}>VISA</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 13, fontWeight: 700 }}>Visa ••••&nbsp;4242</div>
              <div style={{ fontSize: 11, color: 'var(--ink-3)' }}>Carta predefinita</div>
            </div>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" style={{ color: 'var(--ink-3)' }}>
              <path d="M9 6 L 15 12 L 9 18"/>
            </svg>
          </div>
        </div>

        {/* Pay button — slide to confirm style */}
        <div style={{ padding: '20px 24px 28px' }}>
          <button
            disabled={paying}
            onClick={handlePay}
            style={{
              width: '100%', height: 56, borderRadius: 16,
              background: done ? 'var(--green)' : '#000', color: '#fff',
              fontSize: 17, fontWeight: 700,
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
              transition: 'background 0.25s ease',
            }}
          >
            {done ? (
              <>
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
                  <path d="M5 12 L 10 17 L 19 7"/>
                </svg>
                Pagamento completato
              </>
            ) : paying ? (
              <>
                <span className="spinner" style={{
                  width: 18, height: 18, borderRadius: 999,
                  border: '2.5px solid rgba(255,255,255,0.3)',
                  borderTopColor: '#fff',
                  animation: 'spin 0.8s linear infinite',
                }}/>
                Conferma con Face ID...
              </>
            ) : (
              <>
                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                  <path d="M17.04 13.36c-.03-2.92 2.39-4.32 2.5-4.39-1.36-1.99-3.48-2.27-4.24-2.3-1.81-.18-3.53 1.07-4.45 1.07-.92 0-2.34-1.04-3.84-1.01C5.07 6.76 3.3 7.88 2.34 9.6c-1.66 2.88-.42 7.13 1.18 9.47.78 1.14 1.7 2.43 2.93 2.39 1.18-.05 1.62-.76 3.04-.76 1.42 0 1.81.76 3.05.74 1.26-.02 2.06-1.16 2.83-2.31.9-1.32 1.27-2.61 1.29-2.68-.03-.01-2.47-.95-2.5-3.79zM14.7 4.6c.65-.79 1.09-1.89.97-2.97-.94.04-2.07.62-2.74 1.4-.6.7-1.13 1.81-.99 2.87 1.04.08 2.11-.52 2.76-1.3z"/>
                </svg>
                Paga 1,00 €
              </>
            )}
          </button>
          <div style={{ marginTop: 10, textAlign: 'center', fontSize: 11, color: 'var(--ink-3)' }}>
            Doppio-clic sul tasto laterale per confermare
          </div>
        </div>
      </div>
    </>
  );
}

// ─────────────────────────────────────────────────────────────
// 9. Success
// ─────────────────────────────────────────────────────────────
function SuccessScreen({ state, layoutId, onShareWhatsApp, onSave, onOpenRsvp, onNew }) {
  const [showConfetti, setShowConfetti] = useStateP(true);
  const [reminder, setReminder] = useStateP(true);
  useEffectP(() => {
    const t = setTimeout(() => setShowConfetti(false), 3000);
    return () => clearTimeout(t);
  }, []);

  return (
    <div className="app-shell fade-step" style={{ background: 'var(--bg)' }}>
      {/* Confetti rain */}
      {showConfetti && (
        <div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', overflow: 'hidden', zIndex: 5 }}>
          {Array.from({ length: 26 }).map((_, i) => {
            const colors = ['#FF6B9D', '#8B7CF8', '#FFB84D', '#4FB890', '#FFB1CC'];
            return (
              <div key={i} style={{
                position: 'absolute',
                left: `${(i * 17 + 5) % 95}%`,
                top: -10,
                width: 8 + (i % 3) * 3,
                height: 14 + (i % 3) * 4,
                background: colors[i % colors.length],
                borderRadius: 2,
                animation: `confetti-fall ${2 + (i % 4) * 0.4}s ${(i % 6) * 0.15}s ease-in forwards`,
              }} />
            );
          })}
        </div>
      )}

      <div className="app-scroll" style={{ padding: '24px 24px 0', textAlign: 'center' }}>
        <div style={{
          width: 64, height: 64, borderRadius: 999,
          background: 'var(--green)', color: '#fff',
          display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
          marginTop: 14, marginBottom: 14,
          boxShadow: '0 8px 24px rgba(79, 184, 144, 0.4)',
        }}>
          <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
            <path d="M5 12 L 10 17 L 19 7"/>
          </svg>
        </div>
        <h2 className="h-display" style={{ fontSize: 32 }}>Tutto pronto! 🎉</h2>
        <p style={{ marginTop: 8, fontSize: 14, color: 'var(--ink-2)', maxWidth: 280, margin: '8px auto 0' }}>
          Il tuo invito è stato salvato in <b>Foto</b>. Mandalo a chi vuoi su WhatsApp.
        </p>

        <div style={{
          margin: '24px auto 0', maxWidth: 240,
          boxShadow: 'var(--shadow-lg)', borderRadius: 14, overflow: 'hidden',
          aspectRatio: '3 / 4',
          position: 'relative',
        }}>
          <Invitation themeId={state.tema} layoutId={layoutId} data={state} />
        </div>

        <div style={{ marginTop: 22, display: 'flex', flexDirection: 'column', gap: 10 }}>
          <button
            onClick={onShareWhatsApp}
            style={{
              width: '100%', height: 54,
              background: '#25D366', color: '#fff',
              border: 'none', borderRadius: 16,
              fontSize: 16, fontWeight: 700,
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
              boxShadow: '0 6px 18px rgba(37, 211, 102, 0.3)',
            }}
          >
            <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
              <path d="M20.52 3.48A12.07 12.07 0 0 0 12 0C5.5 0 .15 5.35.15 11.93c0 2.1.55 4.15 1.6 5.95L0 24l6.27-1.65a11.93 11.93 0 0 0 5.7 1.45h.01c6.6 0 11.97-5.36 11.97-11.95 0-3.2-1.24-6.2-3.5-8.45zM12 21.8h-.01a9.9 9.9 0 0 1-5.05-1.38l-.36-.21-3.74.98 1-3.65-.24-.37a9.92 9.92 0 0 1-1.5-5.24c0-5.5 4.46-9.95 9.92-9.95a9.93 9.93 0 0 1 9.92 9.95c0 5.5-4.46 9.87-9.92 9.87zm5.45-7.4c-.3-.15-1.77-.87-2.04-.97-.27-.1-.47-.15-.67.15-.2.3-.77.97-.95 1.17-.17.2-.34.22-.64.07-.3-.15-1.27-.47-2.42-1.5a9.07 9.07 0 0 1-1.67-2.07c-.17-.3-.02-.46.13-.61.13-.13.3-.34.45-.52.15-.17.2-.3.3-.5.1-.2.05-.37-.02-.52-.07-.15-.67-1.62-.92-2.22-.24-.58-.49-.5-.67-.51l-.57-.01c-.2 0-.52.07-.79.37-.27.3-1.04 1.02-1.04 2.5 0 1.47 1.07 2.89 1.22 3.09.15.2 2.1 3.2 5.07 4.49 2.35 1.02 2.83.82 3.34.77.5-.05 1.62-.66 1.84-1.3.23-.65.23-1.2.16-1.32-.07-.12-.27-.2-.57-.34z"/>
            </svg>
            Manda su WhatsApp con dettagli
          </button>

          <button
            onClick={onOpenRsvp}
            style={{
              width: '100%', height: 54,
              background: '#fff', color: 'var(--ink)',
              border: '1.5px solid var(--line-2)', borderRadius: 16,
              fontSize: 15, fontWeight: 700,
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
            }}
          >
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
              <path d="M9 11 L 12 14 L 22 4 M 21 12 V 19 A 2 2 0 0 1 19 21 H 5 A 2 2 0 0 1 3 19 V 5 A 2 2 0 0 1 5 3 H 16"/>
            </svg>
            Vedi chi ha confermato
          </button>

          <button
            onClick={onSave}
            style={{
              width: '100%', height: 48,
              background: 'transparent', color: 'var(--ink-2)',
              border: 'none',
              fontSize: 13, fontWeight: 600,
              display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8,
            }}
          >
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
              <path d="M12 3 V 16 M 6 11 L 12 17 L 18 11 M 4 21 H 20"/>
            </svg>
            Salva PNG in Foto
          </button>
        </div>

        {/* Reminder toggle */}
        <div style={{
          marginTop: 14, padding: '14px 16px',
          background: '#fff', border: '1px solid var(--line)', borderRadius: 14,
          display: 'flex', alignItems: 'center', gap: 12, textAlign: 'left',
        }}>
          <div style={{
            width: 36, height: 36, borderRadius: 10, background: 'var(--bg-2)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            color: 'var(--primary)', flexShrink: 0,
          }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
              <path d="M18 8 a 6 6 0 0 0 -12 0 c 0 7 -3 9 -3 9 h 18 s -3 -2 -3 -9 M 13.7 21 a 2 2 0 0 1 -3.4 0"/>
            </svg>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 13, fontWeight: 700 }}>Promemoria 24h prima</div>
            <div style={{ fontSize: 11, color: 'var(--ink-3)', marginTop: 1 }}>
              Ti ricordiamo di scrivere ai genitori che non hanno risposto.
            </div>
          </div>
          <button
            onClick={() => setReminder(r => !r)}
            style={{
              width: 44, height: 26, borderRadius: 999,
              background: reminder ? 'var(--green)' : 'var(--line-2)',
              position: 'relative', transition: 'background 0.2s',
              flexShrink: 0,
            }}
          >
            <span style={{
              position: 'absolute', top: 2, left: reminder ? 20 : 2,
              width: 22, height: 22, borderRadius: 999, background: '#fff',
              boxShadow: '0 1px 3px rgba(0,0,0,0.2)', transition: 'left 0.2s',
            }} />
          </button>
        </div>

        <button
          onClick={onNew}
          style={{
            marginTop: 16, fontSize: 13, fontWeight: 600,
            color: 'var(--ink-3)', padding: '8px 12px',
          }}
        >
          + Crea un altro invito
        </button>

        <div style={{ height: 24 }} />
      </div>

      <style>{`@keyframes spin { to { transform: rotate(360deg); } }`}</style>
    </div>
  );
}

Object.assign(window, { PreviewGridScreen, InvitePreviewScreen, PaySheet, SuccessScreen });
