/* global React */
const { useEffect: useEffCT, useState: useStateCT, useRef: useRefCT } = React;

/* ----------------------------------------------------------------- */
/*  ASPACE Contact — immersive editorial layer                       */
/*    Single scroll surface (the panel itself), ambient atmosphere,  */
/*    magnetic socials, glass inquiry pills, cinematic focus states. */
/* ----------------------------------------------------------------- */

function ContactPanel({ open, onClose }) {
  const tx = (window.useT && window.useT()) || ((k) => k);
  const [step, setStep] = useStateCT(0);
  const [hoverSubmit, setHoverSubmit] = useStateCT(false);
  const [magnet, setMagnet] = useStateCT({ x: 0, y: 0 });
  const submitRef = useRefCT(null);
  const scrollerRef = useRefCT(null);
  const [form, setForm] = useStateCT({
    name: '', email: '', topic: (tx('contact.inquiry.topics') || ['Private studio'])[0], message: '',
  });
  const [clock, setClock] = useStateCT(0);

  // Idle ambient breathing for the blue light pool
  useEffCT(() => {
    if (!open) return;
    let raf, t0 = performance.now();
    const tick = (n) => { setClock((n - t0) / 1000); raf = requestAnimationFrame(tick); };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [open]);

  // Body lock + Esc — overlay becomes the only scroll layer
  useEffCT(() => {
    if (!open) return;
    const onKey = (e) => { if (e.key === 'Escape') onClose(); };
    window.addEventListener('keydown', onKey);
    document.documentElement.style.overflow = 'hidden';
    document.body.style.overflow = 'hidden';
    // pause Lenis if present so the page underneath doesn't scroll
    if (window.lenis && typeof window.lenis.stop === 'function') window.lenis.stop();
    if (scrollerRef.current) scrollerRef.current.scrollTop = 0;
    return () => {
      window.removeEventListener('keydown', onKey);
      // Always reset to empty — never restore to a stale 'hidden' value
      // captured while another overlay was already open (chained-modal bug).
      // The CSS in styles.css reapplies overflow-x: clip / overflow-y: visible.
      document.documentElement.style.overflow = '';
      document.body.style.overflow = '';
      if (window.lenis && typeof window.lenis.start === 'function') window.lenis.start();
    };
  }, [open, onClose]);

  useEffCT(() => { if (!open) { setStep(0); setMagnet({ x: 0, y: 0 }); } }, [open]);

  const onMagnet = (e) => {
    if (!submitRef.current) return;
    const r = submitRef.current.getBoundingClientRect();
    setMagnet({
      x: (e.clientX - (r.left + r.width / 2)) * 0.18,
      y: (e.clientY - (r.top + r.height / 2)) * 0.18,
    });
  };
  const onMagnetLeave = () => setMagnet({ x: 0, y: 0 });

  const topics = tx('contact.inquiry.topics') || [];

  // Featured studios — directly bookable from inside the contact panel.
  // Each entry maps to a booking deep-link so clicking a card jumps the
  // user straight into the booking flow with the studio pre-selected.
  // Featured studios shown inside the contact panel. Each card gets a
  // real mockup image (the same three rotated across the rest of the
  // site) so the contact experience feels like a curated booking
  // showcase instead of a generic inquiry form.
  const STUDIO_META = [
    { priceFrom: 65,  img: '/site/uploads/mockup1.png' },
    { priceFrom: 145, img: '/site/uploads/mockup2.png' },
    { priceFrom: 55,  img: '/site/uploads/mockup3.png' },
    { priceFrom: 45,  img: '/site/uploads/mockup2.png' },
  ];
  const STUDIOS = (tx('contact.studios.items') || []).map((s, i) => ({ ...s, ...STUDIO_META[i] }));

  // Quick action pills — secondary entry-points sitting between the studios
  // grid and the (now optional) inquiry form.
  const QUICK_HREFS = [
    '/site/booking.html?intent=viewing',
    '/site/studios.html',
    '/site/booking.html?intent=availability',
    '#contact',
    '#contact',
  ];
  const QUICK_ACTIONS = (tx('contact.quickActions.items') || []).map((label, i) => ({ label, href: QUICK_HREFS[i] }));

  // Slowly drifting ambient gradient anchor
  const ax = 78 + Math.sin(clock * 0.18) * 5;
  const ay = 18 + Math.cos(clock * 0.22) * 4;
  const ap = 0.55 + (Math.sin(clock * 0.7) + 1) * 0.18;

  return (
    <React.Fragment>
      {/* Backdrop — strong scrim so the panel reads as a separate layer */}
      <div
        onClick={onClose}
        aria-hidden="true"
        data-lenis-prevent
        style={{
          position: 'fixed', inset: 0, zIndex: 9700,
          background: 'rgba(8,8,10,0.62)',
          backdropFilter: 'blur(22px) saturate(120%)',
          WebkitBackdropFilter: 'blur(22px) saturate(120%)',
          opacity: open ? 1 : 0,
          pointerEvents: open ? 'auto' : 'none',
          transition: 'opacity 720ms cubic-bezier(0.22, 1, 0.36, 1)',
          touchAction: 'none',
        }}
      />

      {/* Panel — slides up, single scroll surface inside */}
      <section
        aria-hidden={!open}
        id="contact-panel"
        data-lenis-prevent
        style={{
          position: 'fixed',
          left: 'clamp(8px, 1vw, 14px)',
          right: 'clamp(8px, 1vw, 14px)',
          bottom: 'clamp(8px, 1vw, 14px)',
          top: 'clamp(40px, 6vh, 72px)',
          zIndex: 9750,
          // warmer off-white with a subtle gradient — feels atmospheric, not flat
          background: `
            radial-gradient(900px 600px at ${ax}% ${ay}%, rgba(0,194,255,${0.10 + ap * 0.06}) 0%, transparent 60%),
            radial-gradient(700px 480px at 12% 92%, rgba(255,238,210,0.18) 0%, transparent 65%),
            linear-gradient(180deg, #F7F5EE 0%, #F2EFE7 100%)
          `,
          borderRadius: 'clamp(20px, 2.4vw, 32px)',
          boxShadow: `
            0 60px 140px -40px rgba(0,0,0,0.55),
            0 18px 40px -16px rgba(0,0,0,0.20),
            inset 0 1px 0 rgba(255,255,255,0.55),
            0 0 80px rgba(0,194,255,0.08)
          `,
          border: '1px solid rgba(255,255,255,0.55)',
          overflow: 'hidden',
          transform: open ? 'translateY(0)' : 'translateY(110vh)',
          transition: 'transform 880ms cubic-bezier(0.22, 1, 0.36, 1)',
          visibility: open ? 'visible' : 'hidden',
          willChange: 'transform',
          contain: 'layout paint',
          display: 'flex', flexDirection: 'column',
        }}
      >
        {/* Subtle grain overlay — restrained */}
        <div aria-hidden="true" style={{
          position: 'absolute', inset: 0,
          pointerEvents: 'none',
          opacity: 0.18, mixBlendMode: 'overlay',
          backgroundImage: "url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>\")",
        }}/>

        {/* Top bar — softer, less divider-y */}
        <div style={{
          position: 'relative', zIndex: 1,
          display: 'flex', alignItems: 'center', justifyContent: 'space-between',
          padding: 'clamp(18px, 2vw, 28px) clamp(20px, 3vw, 44px)',
          flexShrink: 0,
        }}>
          <div className="aspace-eyebrow" style={{ display: 'inline-flex', alignItems: 'center', gap: 12 }}>
            <span aria-hidden="true" style={{
              width: 6, height: 6, borderRadius: '50%',
              background: 'var(--aspace-blue)',
              boxShadow: '0 0 10px var(--aspace-blue)',
            }}/>
            {tx('contact.topEyebrow')}
          </div>
          <button onClick={onClose} aria-label={tx('contact.closeAria')}
            className="ct-close"
            style={{
              all: 'unset', cursor: 'pointer',
              display: 'inline-flex', alignItems: 'center', gap: 12,
              padding: '12px 18px',
              borderRadius: 99,
              border: '1px solid rgba(10,10,11,0.18)',
              fontSize: 12, letterSpacing: '0.18em', textTransform: 'uppercase',
              color: '#0A0A0B',
              transition: 'background 320ms ease, color 320ms ease, border-color 320ms ease, transform 480ms cubic-bezier(0.22,1.2,0.36,1)',
            }}>
            <span>{tx('contact.closeLabel')}</span>
            <span aria-hidden="true" style={{
              width: 22, height: 22, borderRadius: '50%',
              border: '1px solid currentColor',
              display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
              transition: 'transform 480ms cubic-bezier(0.22,1.2,0.36,1)',
            }}>
              <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M6 6l12 12M18 6L6 18"/></svg>
            </span>
          </button>
        </div>

        {/* Single scroll surface — ALL content scrolls inside this one container.
            data-lenis-prevent tells Lenis to ignore wheel/touch events here so
            native scroll runs cleanly on desktop, tablet, and mobile. */}
        <div ref={scrollerRef} className="ct-scroll" data-lenis-prevent style={{
          position: 'relative', zIndex: 1,
          flex: 1,
          overflowY: 'auto',
          overscrollBehavior: 'contain',
          WebkitOverflowScrolling: 'touch',
          touchAction: 'pan-y',
          // no smooth scroll-behavior — keeps wheel/touch feel native and snappy
        }}>
          <div style={{
            display: 'grid',
            gridTemplateColumns: 'minmax(240px, 0.85fr) minmax(0, 1.6fr)',
            gap: 'clamp(36px, 5vw, 88px)',
            padding: 'clamp(28px, 4vw, 56px) clamp(20px, 3vw, 44px) clamp(48px, 6vw, 80px)',
          }} className="contact-grid">

            {/* LEFT — editorial column */}
            <aside style={{
              display: 'flex', flexDirection: 'column',
              gap: 'clamp(40px, 5vw, 64px)',
            }}>
              <ContactRevealCol open={open} delay={120}>
                <div className="aspace-eyebrow ct-eyebrow">{tx('contact.visit.eyebrow')}</div>
                <div style={{
                  fontFamily: "'Inter Tight',sans-serif",
                  fontWeight: 500,
                  fontSize: 'clamp(18px,1.5vw,22px)',
                  letterSpacing: '-0.012em', lineHeight: 1.2,
                  marginTop: 16,
                }}>
                  {tx('contact.visit.name')}
                </div>
                <p style={{
                  margin: '10px 0 0',
                  color: 'rgba(10,10,11,0.58)',
                  fontFamily: "'Inter Tight',sans-serif",
                  fontWeight: 400,
                  fontSize: 13.5, lineHeight: 1.55,
                  letterSpacing: '-0.005em',
                }}>
                  {tx('contact.visit.addressLine1')}<br/>
                  <span style={{ color: 'rgba(10,10,11,0.42)' }}>{tx('contact.visit.postcode')}&nbsp;</span>{tx('contact.visit.city')}
                </p>
                <p style={{
                  margin: '14px 0 0',
                  color: 'var(--aspace-blue-deep, var(--aspace-blue))',
                  fontFamily: "'Inter Tight',sans-serif",
                  fontSize: 11.5, letterSpacing: '0.18em',
                  textTransform: 'uppercase',
                  display: 'inline-flex', alignItems: 'center', gap: 8,
                }}>
                  <span aria-hidden="true" style={{
                    width: 14, height: 1,
                    background: 'currentColor', opacity: 0.6,
                  }}/>
                  {tx('contact.visit.note')}
                </p>
              </ContactRevealCol>

              <ContactRevealCol open={open} delay={160}>
                <div className="aspace-eyebrow ct-eyebrow">{tx('contact.hours.eyebrow')}</div>
                <ul style={{
                  listStyle: 'none', margin: '14px 0 0', padding: 0,
                  display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '6px 14px',
                  fontFamily: "'Inter Tight', sans-serif", fontSize: 12.5,
                  color: 'rgba(10,10,11,0.62)',
                  fontVariantNumeric: 'tabular-nums',
                }}>
                  <li style={{ color: 'rgba(10,10,11,0.42)' }}>{(tx('contact.hours.monFri') || {}).label}</li><li>{(tx('contact.hours.monFri') || {}).value}</li>
                  <li style={{ color: 'rgba(10,10,11,0.42)' }}>{(tx('contact.hours.saturday') || {}).label}</li><li>{(tx('contact.hours.saturday') || {}).value}</li>
                  <li style={{ color: 'rgba(10,10,11,0.42)' }}>{(tx('contact.hours.sunday') || {}).label}</li><li>{(tx('contact.hours.sunday') || {}).value}</li>
                </ul>
              </ContactRevealCol>

              <ContactRevealCol open={open} delay={200}>
                <div className="aspace-eyebrow ct-eyebrow">{tx('contact.channels.eyebrow')}</div>
                <ul style={{
                  listStyle: 'none', padding: 0,
                  margin: '20px 0 0',
                  display: 'flex', flexDirection: 'column', gap: 4,
                }}>
                  {(() => {
                    const labels = tx('contact.channels.items') || [];
                    const hrefs  = ['#', '#', '#', 'mailto:hello@aspace.amsterdam'];
                    return labels.map((label, i) => (
                      <li key={label}>
                        <SocialLink label={label} href={hrefs[i] || '#'}/>
                      </li>
                    ));
                  })()}
                </ul>
              </ContactRevealCol>

              <ContactRevealCol open={open} delay={280}>
                <div className="aspace-eyebrow ct-eyebrow">{tx('contact.inquiry.eyebrow')}</div>
                <div style={{
                  display: 'flex', flexWrap: 'wrap', gap: 10,
                  marginTop: 18,
                }}>
                  {topics.map(topic => {
                    const active = form.topic === topic;
                    return (
                      <button
                        key={topic}
                        onClick={() => setForm(f => ({ ...f, topic }))}
                        className={'ct-pill' + (active ? ' is-active' : '')}
                      >
                        {active && (
                          <span aria-hidden="true" style={{
                            width: 5, height: 5, borderRadius: '50%',
                            background: 'var(--aspace-blue)',
                            boxShadow: '0 0 10px var(--aspace-blue)',
                            marginRight: 4,
                          }}/>
                        )}
                        {topic}
                      </button>
                    );
                  })}
                </div>
              </ContactRevealCol>
            </aside>

            {/* RIGHT — booking journey, not an inquiry form */}
            <div>
              {/* SECTION 1 — HERO STATEMENT */}
              <ContactRevealCol open={open} delay={140}>
                <div className="aspace-eyebrow ct-eyebrow">{tx('contact.journey.eyebrow')}</div>
                <h2 style={{
                  margin: '20px 0 clamp(36px, 4.5vw, 56px)',
                  fontFamily: "'Inter Tight', sans-serif",
                  fontWeight: 500,
                  fontSize: 'clamp(44px, 7vw, 124px)',
                  lineHeight: 0.92,
                  letterSpacing: '-0.038em',
                  textWrap: 'balance',
                  whiteSpace: 'pre-line',
                }}>
                  {tx('contact.journey.headlinePre')}<span className="blue-swipe">{tx('contact.journey.headlineHi')}</span>{tx('contact.journey.headlinePost')}
                </h2>
              </ContactRevealCol>

              {/* SECTION 2 — FEATURED STUDIOS */}
              <ContactRevealCol open={open} delay={220}>
                <div className="ct-studios-head" style={{
                  display: 'flex', alignItems: 'baseline', justifyContent: 'space-between',
                  gap: 16, flexWrap: 'wrap',
                  marginBottom: 'clamp(18px, 2vw, 24px)',
                }}>
                  <div className="aspace-eyebrow ct-eyebrow">{tx('contact.featured.eyebrow')}</div>
                  <a href="/site/studios.html" className="ct-studios-all">
                    {tx('contact.featured.allLink')}
                    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
                  </a>
                </div>
                <div className="ct-studios-grid">
                  {STUDIOS.map(s => <ContactStudioCard key={s.id} studio={s}/>)}
                </div>
              </ContactRevealCol>

              {/* SECTION 3 — QUICK ACTIONS */}
              <ContactRevealCol open={open} delay={300}>
                <div className="aspace-eyebrow ct-eyebrow" style={{ marginTop: 'clamp(40px, 5vw, 64px)' }}>{tx('contact.quickActions.eyebrow')}</div>
                <div className="ct-quick-actions" style={{
                  display: 'flex', flexWrap: 'wrap', gap: 10,
                  marginTop: 'clamp(14px, 1.6vw, 20px)',
                }}>
                  {QUICK_ACTIONS.map(a => (
                    <a key={a.label} href={a.href} className="ct-quick-pill">
                      {a.label}
                      <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
                    </a>
                  ))}
                </div>
              </ContactRevealCol>

              {/* SECTION 4 — COMPACT FORM (secondary entry-point) */}
              <ContactRevealCol open={open} delay={380}>
                <div className="ct-or-divider" style={{
                  display: 'flex', alignItems: 'center', gap: 16,
                  marginTop: 'clamp(48px, 6vw, 72px)',
                  marginBottom: 'clamp(24px, 3vw, 32px)',
                }}>
                  <span aria-hidden="true" style={{ flex: 1, height: 1, background: 'rgba(10,10,11,0.10)' }}/>
                  <span className="aspace-eyebrow ct-eyebrow" style={{ margin: 0 }}>{tx('contact.form.divider')}</span>
                  <span aria-hidden="true" style={{ flex: 1, height: 1, background: 'rgba(10,10,11,0.10)' }}/>
                </div>
              </ContactRevealCol>

              {step === 0 ? (
                <form onSubmit={(e) => { e.preventDefault(); setStep(1); }}
                      style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
                  {/* Name + email on one row from tablet up — the form is now
                      secondary, so we compact it instead of stretching it out. */}
                  <div className="ct-row-2">
                    <ContactField label={tx('contact.form.nameLabel')} delay={420} open={open}>
                      <input value={form.name} onChange={e => setForm(f => ({ ...f, name: e.target.value }))}
                        type="text" required placeholder={tx('contact.form.namePlaceholder')} autoComplete="name" />
                    </ContactField>
                    <ContactField label={tx('contact.form.emailLabel')} delay={460} open={open}>
                      <input value={form.email} onChange={e => setForm(f => ({ ...f, email: e.target.value }))}
                        type="email" required placeholder={tx('contact.form.emailPlaceholder')} autoComplete="email" />
                    </ContactField>
                  </div>
                  <ContactField label={tx('contact.form.messageLabel')} delay={520} open={open}>
                    <textarea value={form.message} onChange={e => setForm(f => ({ ...f, message: e.target.value }))}
                      rows={2} placeholder={tx('contact.form.messagePlaceholder')} />
                  </ContactField>

                  {/* Submit row */}
                  <div style={{
                    marginTop: 'clamp(28px, 3vw, 40px)',
                    display: 'flex', alignItems: 'center', justifyContent: 'space-between',
                    gap: 24, flexWrap: 'wrap',
                  }}>
                    <p style={{
                      color: 'rgba(10,10,11,0.5)',
                      fontFamily: "'Inter Tight',sans-serif",
                      fontSize: 12.5, lineHeight: 1.55,
                      margin: 0, maxWidth: 320,
                    }}>
                      {tx('contact.form.note')}
                    </p>
                    <button
                      ref={submitRef}
                      type="submit"
                      onMouseMove={onMagnet}
                      onMouseEnter={() => setHoverSubmit(true)}
                      onMouseLeave={() => { setHoverSubmit(false); onMagnetLeave(); }}
                      className="ct-submit"
                      style={{
                        all: 'unset', cursor: 'pointer',
                        position: 'relative',
                        display: 'inline-flex', alignItems: 'center', gap: 14,
                        padding: '16px 14px 16px 26px',
                        borderRadius: 99,
                        background: `linear-gradient(135deg, rgba(20,22,28,0.92) 0%, rgba(10,10,11,0.92) 100%)`,
                        color: '#fff',
                        fontFamily: "'Inter Tight',sans-serif",
                        fontSize: 'clamp(14px,1.05vw,16px)',
                        letterSpacing: '0.005em',
                        overflow: 'hidden',
                        transform: `translate(${magnet.x}px, ${magnet.y - (hoverSubmit ? 2 : 0)}px)`,
                        transition: 'transform 480ms cubic-bezier(0.22,1.2,0.36,1), box-shadow 520ms ease',
                        boxShadow: hoverSubmit
                          ? `0 22px 60px -22px rgba(0,0,0,0.55), 0 0 60px rgba(0,194,255,0.22), inset 0 1px 0 rgba(255,255,255,0.18)`
                          : `0 12px 32px -16px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.14)`,
                      }}>
                      <span aria-hidden="true" style={{
                        position: 'absolute', inset: 0, borderRadius: 99,
                        background: `radial-gradient(180px 90px at 50% 50%, rgba(0,194,255,${hoverSubmit ? 0.30 : 0.10}) 0%, transparent 70%)`,
                        mixBlendMode: 'screen',
                        opacity: 1,
                        transition: 'opacity 480ms ease',
                      }}/>
                      <span style={{ position: 'relative' }}>{tx('contact.form.submit')}</span>
                      <span aria-hidden="true" style={{
                        position: 'relative',
                        width: 36, height: 36, borderRadius: '50%',
                        background: 'radial-gradient(circle at 30% 30%, #1a1d24 0%, #0A0A0B 70%)',
                        display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
                        flexShrink: 0,
                        boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.16), inset 0 -1px 0 rgba(0,0,0,0.40)',
                        overflow: 'hidden',
                      }}>
                        <span style={{
                          position: 'absolute', inset: -3, borderRadius: '50%',
                          background: `radial-gradient(circle, rgba(0,194,255,${0.30 + (hoverSubmit ? 0.20 : 0)}) 0%, transparent 65%)`,
                          filter: 'blur(4px)',
                        }}/>
                        <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" style={{
                          position: 'relative',
                          transform: `translateX(${hoverSubmit ? 4 : 0}px) rotate(${hoverSubmit ? -10 : 0}deg)`,
                          transition: 'transform 480ms cubic-bezier(0.22,1.2,0.36,1)',
                        }}>
                          <path d="M5 12h14M13 6l6 6-6 6"/>
                        </svg>
                      </span>
                    </button>
                  </div>
                </form>
              ) : (
                <div style={{
                  padding: 'clamp(32px, 5vw, 56px) 0',
                  display: 'flex', flexDirection: 'column', gap: 18,
                }}>
                  <div className="aspace-eyebrow" style={{ color: 'var(--aspace-blue-deep)', display: 'inline-flex', alignItems: 'center', gap: 10 }}>
                    <span style={{
                      width: 7, height: 7, borderRadius: '50%',
                      background: 'var(--aspace-blue)',
                      boxShadow: '0 0 10px var(--aspace-blue)',
                    }}/>
                    {tx('contact.success.eyebrow')}
                  </div>
                  <h3 style={{
                    margin: 0,
                    fontFamily: "'Inter Tight',sans-serif",
                    fontWeight: 500,
                    fontSize: 'clamp(36px,5vw,72px)',
                    lineHeight: 1, letterSpacing: '-0.025em',
                    whiteSpace: 'pre-line',
                  }}>
                    {tx('contact.success.thanksPre')}{form.name || tx('contact.success.thanksFallback')}{tx('contact.success.thanksPost')}
                    <span className="blue-swipe">{tx('contact.success.thanksHi')}</span>
                  </h3>
                  <p style={{
                    color: 'rgba(10,10,11,0.6)',
                    fontFamily: "'Inter Tight',sans-serif",
                    fontSize: 16, lineHeight: 1.55, maxWidth: 520,
                  }}>
                    {tx('contact.success.copy')}
                  </p>
                  <div>
                    <button onClick={() => setStep(0)} className="aspace-pill ghost">{tx('contact.success.cta')}</button>
                  </div>
                </div>
              )}
            </div>
          </div>
        </div>

        <style>{`
          /* Hide the inner scrollbar entirely — the panel is the scroll layer */
          .ct-scroll { scrollbar-width: none; -ms-overflow-style: none; }
          .ct-scroll::-webkit-scrollbar { width: 0; height: 0; display: none; }

          /* Close button hover */
          .ct-close:hover { background: #0A0A0B; color: #fff; border-color: #0A0A0B; }
          .ct-close:hover span:last-child { transform: rotate(90deg) scale(1.05); }

          /* Eyebrow rhythm */
          .ct-eyebrow {
            display: inline-flex; align-items: center; gap: 10px;
            font-size: 11px; letter-spacing: 0.22em;
          }
          .ct-eyebrow::before {
            content: ''; width: 18px; height: 1px;
            background: rgba(10,10,11,0.28);
          }

          /* Inquiry pills — soft glass */
          .ct-pill {
            all: unset; cursor: pointer;
            display: inline-flex; align-items: center; gap: 8px;
            padding: 11px 18px;
            border-radius: 999px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 13px; letter-spacing: 0.005em;
            color: #0A0A0B;
            background: rgba(255,255,255,0.40);
            backdrop-filter: blur(10px) saturate(140%);
            -webkit-backdrop-filter: blur(10px) saturate(140%);
            border: 1px solid rgba(10,10,11,0.10);
            transition: transform 480ms cubic-bezier(0.22,1.2,0.36,1), background 320ms ease, border-color 320ms ease, box-shadow 480ms ease, color 320ms ease;
          }
          .ct-pill:hover {
            background: rgba(255,255,255,0.65);
            transform: translateY(-1px);
            border-color: rgba(10,10,11,0.18);
          }
          .ct-pill.is-active {
            background: linear-gradient(135deg, rgba(20,22,28,0.92) 0%, rgba(10,10,11,0.92) 100%);
            color: #fff;
            border-color: transparent;
            box-shadow: 0 14px 36px -16px rgba(0,0,0,0.45), 0 0 30px rgba(0,194,255,0.18), inset 0 1px 0 rgba(255,255,255,0.18);
          }

          /* Form inputs */
          #contact-panel input,
          #contact-panel textarea {
            all: unset; box-sizing: border-box;
            display: block; width: 100%;
            padding: 18px 0;
            font-family: 'Inter Tight', sans-serif;
            font-weight: 500;
            font-size: clamp(20px, 2.2vw, 28px);
            letter-spacing: -0.014em;
            color: #0A0A0B;
            background: transparent;
          }
          #contact-panel input::placeholder,
          #contact-panel textarea::placeholder {
            color: rgba(10,10,11,0.28);
            font-weight: 500;
          }
          #contact-panel textarea { resize: vertical; min-height: 60px; }

          /* Cinematic field — animated underline */
          .contact-field {
            position: relative;
            padding-top: 14px;
          }
          .contact-field::after {
            content: '';
            position: absolute; left: 0; right: 0; bottom: 0;
            height: 1px;
            background: rgba(10,10,11,0.16);
            transition: background 320ms ease;
          }
          .contact-field::before {
            content: '';
            position: absolute; left: 0; bottom: 0;
            height: 1px; width: 0%;
            background: linear-gradient(to right, var(--aspace-blue) 0%, rgba(0,194,255,0.4) 100%);
            box-shadow: 0 0 18px rgba(0,194,255,0.55);
            transition: width 720ms cubic-bezier(0.22,1,0.36,1);
            z-index: 1;
          }
          .contact-field:focus-within::before { width: 100%; }
          .contact-field-label {
            font-family: 'Inter Tight', sans-serif;
            font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
            color: rgba(10,10,11,0.5);
            font-weight: 500;
            transition: color 320ms ease, transform 480ms cubic-bezier(0.22,1.2,0.36,1);
          }
          .contact-field:focus-within .contact-field-label {
            color: var(--aspace-blue-deep, var(--aspace-blue));
            transform: translateX(2px);
          }

          /* Social link — magnetic-feel hover, drifting arrow */
          .ct-social {
            all: unset; cursor: pointer;
            display: flex; align-items: center; justify-content: space-between;
            padding: 16px 0 18px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 16px; letter-spacing: -0.005em;
            color: #0A0A0B;
            position: relative;
            transition: transform 520ms cubic-bezier(0.22,1.2,0.36,1), color 320ms ease;
          }
          .ct-social::after {
            content: '';
            position: absolute; left: 0; right: 0; bottom: 0;
            height: 1px;
            background: rgba(10,10,11,0.10);
          }
          .ct-social .ct-rule {
            position: absolute; left: 0; bottom: 0;
            height: 1px; width: 0%;
            background: var(--aspace-blue);
            box-shadow: 0 0 10px rgba(0,194,255,0.55);
            transition: width 640ms cubic-bezier(0.22,1,0.36,1);
          }
          .ct-social:hover { transform: translateX(6px); color: #0A0A0B; }
          .ct-social:hover .ct-rule { width: 100%; }
          .ct-social:hover .ct-arrow {
            transform: translate(8px, -8px) rotate(0deg);
            color: var(--aspace-blue-deep, var(--aspace-blue));
          }
          .ct-arrow {
            display: inline-flex; transition: transform 560ms cubic-bezier(0.22,1.2,0.36,1), color 320ms ease;
          }

          /* "See all studios" link */
          .ct-studios-all {
            all: unset; cursor: pointer;
            display: inline-flex; align-items: center; gap: 8px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 11.5px; letter-spacing: 0.18em; text-transform: uppercase;
            color: rgba(10,10,11,0.50);
            transition: color 320ms ease, transform 480ms cubic-bezier(0.22,1.2,0.36,1);
          }
          .ct-studios-all svg { transition: transform 480ms cubic-bezier(0.22,1.2,0.36,1); }
          .ct-studios-all:hover { color: var(--aspace-blue-deep, var(--aspace-blue)); }
          .ct-studios-all:hover svg { transform: translateX(3px); }

          /* ============================================================
             FEATURED STUDIOS — cinematic dark cards on a light surface,
             auto-fit grid: 4-up wide → 2-up tablet → 1-up phone.
             Hover lifts the card softly and parallaxes the image.
             ============================================================ */
          .ct-studios-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 14px;
          }
          .ct-studio-card {
            all: unset; cursor: pointer;
            display: flex; flex-direction: column;
            position: relative;
            border-radius: 18px;
            overflow: hidden;
            background: #0E1118;
            color: #fff;
            transition:
              transform 520ms cubic-bezier(0.22,1,0.36,1),
              box-shadow 520ms cubic-bezier(0.22,1,0.36,1);
            box-shadow:
              0 12px 32px -16px rgba(0,0,0,0.30),
              0 0 0 1px rgba(10,10,11,0.06);
          }
          .ct-studio-card:hover {
            transform: translateY(-3px);
            box-shadow:
              0 24px 60px -22px rgba(0,0,0,0.45),
              0 0 0 1px rgba(0,194,255,0.22),
              0 0 32px rgba(0,194,255,0.12);
          }
          .ct-studio-card:focus-visible {
            outline: 2px solid var(--aspace-blue, #00C2FF);
            outline-offset: 3px;
          }
          .ct-studio-image {
            position: relative;
            display: block;
            aspect-ratio: 4 / 3;
            overflow: hidden;
            transition: transform 720ms cubic-bezier(0.22,1,0.36,1);
          }
          .ct-studio-card:hover .ct-studio-image {
            transform: scale(1.04);
          }
          .ct-studio-pattern {
            position: absolute; inset: 0;
            background-image:
              radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 1.5px);
            background-size: 18px 18px;
            mix-blend-mode: screen;
            opacity: 0.7;
          }
          .ct-studio-tag {
            position: absolute; top: 12px; left: 12px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 9.5px; letter-spacing: 0.22em; text-transform: uppercase;
            color: rgba(255,255,255,0.65);
            padding: 5px 9px; border-radius: 999px;
            background: rgba(0,0,0,0.30);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(255,255,255,0.10);
          }
          .ct-studio-meta {
            display: flex; flex-direction: column; gap: 4px;
            padding: 14px 16px 16px;
            background: linear-gradient(180deg, rgba(20,22,28,0.94) 0%, rgba(10,10,11,0.96) 100%);
            transition: transform 520ms cubic-bezier(0.22,1,0.36,1);
          }
          .ct-studio-card:hover .ct-studio-meta { transform: translateY(-2px); }
          .ct-studio-name {
            font-family: 'Inter Tight', sans-serif;
            font-size: 16px; font-weight: 500; letter-spacing: -0.005em;
            color: rgba(255,255,255,0.96);
          }
          .ct-studio-stats {
            display: inline-flex; flex-wrap: wrap; gap: 6px;
            font-size: 11.5px; color: rgba(255,255,255,0.60);
            font-family: 'Inter Tight', sans-serif;
            letter-spacing: 0.005em;
          }
          .ct-studio-light {
            font-family: 'Inter Tight', sans-serif;
            font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
            color: rgba(255,255,255,0.40);
            margin-top: 2px;
          }
          .ct-studio-foot {
            display: flex; justify-content: space-between; align-items: baseline;
            gap: 12px;
            margin-top: 12px; padding-top: 12px;
            border-top: 1px solid rgba(255,255,255,0.10);
          }
          .ct-studio-price {
            display: inline-flex; align-items: baseline; gap: 4px;
            font-family: 'Inter Tight', sans-serif;
            color: rgba(255,255,255,0.94);
            font-variant-numeric: tabular-nums;
          }
          .ct-studio-price-from {
            font-size: 9.5px; letter-spacing: 0.18em; text-transform: uppercase;
            color: rgba(255,255,255,0.38); margin-right: 2px;
          }
          .ct-studio-price-value {
            font-size: 16px; font-weight: 500; letter-spacing: -0.005em;
          }
          .ct-studio-price-unit {
            font-size: 11px; color: rgba(255,255,255,0.50);
          }
          .ct-studio-cta {
            display: inline-flex; align-items: center; gap: 6px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
            color: var(--aspace-blue, #00C2FF);
            opacity: 0.55;
            transform: translateX(-4px);
            transition:
              opacity 480ms cubic-bezier(0.22,1,0.36,1),
              transform 520ms cubic-bezier(0.22,1.2,0.36,1);
          }
          .ct-studio-cta svg { transition: transform 520ms cubic-bezier(0.22,1.2,0.36,1); }
          .ct-studio-card:hover .ct-studio-cta {
            opacity: 1;
            transform: translateX(0);
          }
          .ct-studio-card:hover .ct-studio-cta svg { transform: translateX(3px); }

          /* ============================================================
             QUICK ACTIONS — editorial pill row that lives between the
             studio cards and the (now compact) form.
             ============================================================ */
          .ct-quick-pill {
            all: unset; cursor: pointer;
            display: inline-flex; align-items: center; gap: 8px;
            padding: 11px 18px;
            border-radius: 999px;
            font-family: 'Inter Tight', sans-serif;
            font-size: 13px; letter-spacing: 0.005em;
            color: rgba(10,10,11,0.85);
            background: rgba(255,255,255,0.45);
            backdrop-filter: blur(10px) saturate(140%);
            -webkit-backdrop-filter: blur(10px) saturate(140%);
            border: 1px solid rgba(10,10,11,0.10);
            transition:
              transform 480ms cubic-bezier(0.22,1.2,0.36,1),
              background 320ms ease,
              border-color 320ms ease,
              color 320ms ease,
              box-shadow 480ms ease;
          }
          .ct-quick-pill svg {
            opacity: 0.45;
            transition: transform 520ms cubic-bezier(0.22,1.2,0.36,1), opacity 320ms ease;
          }
          .ct-quick-pill:hover {
            background: rgba(255,255,255,0.75);
            color: #0A0A0B;
            border-color: rgba(0,194,255,0.40);
            transform: translateY(-1px);
            box-shadow: 0 0 0 1px rgba(0,194,255,0.18) inset, 0 12px 28px -16px rgba(0,194,255,0.30);
          }
          .ct-quick-pill:hover svg { opacity: 1; transform: translateX(3px); color: var(--aspace-blue-deep, var(--aspace-blue)); }

          /* Two-column form row — collapses to one column on small viewports */
          .ct-row-2 {
            display: grid;
            grid-template-columns: 1fr 1fr;
            column-gap: clamp(20px, 3vw, 36px);
          }

          @media (max-width: 800px) {
            .contact-grid { grid-template-columns: 1fr !important; }
            .ct-row-2 { grid-template-columns: 1fr; }
          }
          @media (max-width: 560px) {
            .ct-studios-grid { grid-template-columns: 1fr !important; }
            .ct-quick-pill { font-size: 12px; padding: 10px 14px; }
          }
        `}</style>
      </section>
    </React.Fragment>
  );
}

function ContactRevealCol({ open, delay = 0, children }) {
  return (
    <div style={{
      transform: open ? 'translateY(0)' : 'translateY(40px)',
      opacity: open ? 1 : 0,
      transition: `transform 900ms cubic-bezier(0.22,1,0.36,1) ${delay}ms, opacity 700ms ease ${delay}ms`,
    }}>
      {children}
    </div>
  );
}

function ContactField({ label, children, delay = 0, open }) {
  return (
    <div className="contact-field" style={{
      transform: open ? 'translateY(0)' : 'translateY(30px)',
      opacity: open ? 1 : 0,
      transition: `transform 800ms cubic-bezier(0.22,1,0.36,1) ${delay}ms, opacity 600ms ease ${delay}ms`,
    }}>
      <div className="contact-field-label">{label}</div>
      {children}
    </div>
  );
}

function SocialLink({ label, href }) {
  return (
    <a href={href} className="ct-social">
      <span className="ct-rule" aria-hidden="true"/>
      <span>{label}</span>
      <span aria-hidden="true" className="ct-arrow">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
          <path d="M7 17L17 7M9 7h8v8"/>
        </svg>
      </span>
    </a>
  );
}

/* Featured studio card — image, meta, price, dual CTAs.
   Whole card is clickable (jumps into booking with the studio pre-selected);
   the visible "Book now" + "View details" are visual reinforcements. */
function ContactStudioCard({ studio }) {
  const tx = (window.useT && window.useT()) || ((k) => k);
  const cta = tx('contact.featured.cta');
  return (
    <a href={'/site/booking.html?studio=' + studio.id}
       className="ct-studio-card"
       aria-label={cta + ' — ' + studio.name + ' · €' + studio.priceFrom + tx('contact.featured.priceUnit')}>
      <span className="ct-studio-image" aria-hidden="true" style={{
        // Real studio mockup as the card hero. Subtle dark gradient on
        // top so the white tag + name stay legible regardless of image.
        backgroundImage: 'linear-gradient(180deg, rgba(8,9,12,0.10) 0%, rgba(8,9,12,0.55) 100%), url(' + studio.img + ')',
        backgroundSize: 'cover',
        backgroundPosition: 'center',
      }}>
        <span className="ct-studio-pattern" aria-hidden="true"/>
        <span className="ct-studio-tag">{(tx('search.kinds') || {}).studio || 'Studio'} · {studio.id}</span>
      </span>
      <span className="ct-studio-meta">
        <span className="ct-studio-name">{studio.name}</span>
        <span className="ct-studio-stats">
          <span>{studio.size}</span>
          <span aria-hidden="true">·</span>
          <span>{studio.bestFor}</span>
        </span>
        <span className="ct-studio-light">{studio.light}</span>
        <span className="ct-studio-foot">
          <span className="ct-studio-price">
            <span className="ct-studio-price-from">{tx('contact.featured.priceFrom')}</span>
            <span className="ct-studio-price-value">€{studio.priceFrom}</span>
            <span className="ct-studio-price-unit">{tx('contact.featured.priceUnit')}</span>
          </span>
          <span className="ct-studio-cta">
            {cta}
            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
          </span>
        </span>
      </span>
    </a>
  );
}

window.ContactPanel = ContactPanel;
