/* ============================================================
   CUSTOM PAGES — Brief · Order Confirmed · Invoice
   Fully integrated into Belle & Bloom routing system
   ============================================================ */

/* ── Shared helpers ─────────────────────────────────────── */
function CustomPageHero({ eyebrow, title, sub }) {
  return (
    <section style={{ background: 'linear-gradient(160deg, var(--cream-deep), var(--blush-soft))', padding: 'clamp(48px,7vw,90px) var(--gutter)' }}>
      <div className="container" style={{ maxWidth: 760 }}>
        <p className="eyebrow">{eyebrow}</p>
        <h1 style={{ fontSize: 'clamp(38px,6vw,72px)', margin: '14px 0 14px' }}>{title}</h1>
        {sub && <p style={{ fontSize: 'clamp(15px,1.8vw,19px)', color: 'var(--ink-soft)', lineHeight: 1.65, maxWidth: 540 }}>{sub}</p>}
      </div>
    </section>
  );
}

function StepBar({ current, total }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', marginBottom: 40 }}>
      {Array.from({ length: total }, (_, i) => {
        const n = i + 1, done = n < current, active = n === current;
        return (
          <React.Fragment key={n}>
            <div style={{
              width: 36, height: 36, borderRadius: '100%', flexShrink: 0,
              display: 'grid', placeItems: 'center',
              fontFamily: 'var(--sans)', fontSize: 13, fontWeight: 500,
              background: done ? 'var(--gold)' : active ? 'var(--ink)' : 'var(--cream-deep)',
              color: (done || active) ? '#fff' : 'var(--ink-faint)',
              border: `1.5px solid ${done ? 'var(--gold)' : active ? 'var(--ink)' : 'var(--line)'}`,
              boxShadow: active ? '0 4px 14px rgba(42,17,51,.2)' : 'none',
              transition: 'all .35s',
            }}>
              {done
                ? <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="m5 13 4 4 10-11" strokeLinecap="round"/></svg>
                : n}
            </div>
            {n < total && <div style={{ flex: 1, height: 1, background: done ? 'var(--gold)' : 'var(--line)', margin: '0 4px', transition: 'background .35s' }} />}
          </React.Fragment>
        );
      })}
    </div>
  );
}

function BriefField({ label, required, children }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
      <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500 }}>
        {label}{required && <span style={{ color: 'var(--blush)', marginLeft: 2 }}>*</span>}
      </label>
      {children}
    </div>
  );
}

const briefInputSx = {
  background: 'var(--cream)', border: '1.5px solid var(--line)',
  borderRadius: 'var(--r-sm)', padding: '13px 16px', color: 'var(--ink)',
  width: '100%', fontFamily: 'var(--sans)', fontSize: 14, transition: 'border .25s, box-shadow .25s',
};
const iFocus = e => { e.target.style.borderColor = 'var(--gold)'; e.target.style.boxShadow = '0 0 0 4px rgba(138,24,192,.10)'; e.target.style.outline = 'none'; };
const iBlur  = e => { e.target.style.borderColor = 'var(--line)'; e.target.style.boxShadow = ''; };

const cardSx = { background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', padding: 'clamp(24px,4vw,44px)', marginBottom: 20 };

/* ─────────────────────────────────────────────────────────
   1. BRIEF PAGE
───────────────────────────────────────────────────────── */
function BriefPage() {
  const { nav, toast } = useStore();
  const [step, setStep] = React.useState(1);

  // Step 1
  const [eventType, setEventType] = React.useState('');
  const [eventDate, setEventDate] = React.useState('');
  const [guestCount, setGuestCount] = React.useState('');
  const [briefText, setBriefText] = React.useState('');
  const [budget, setBudget] = React.useState('');

  // Step 2 — links
  const [links, setLinks] = React.useState(['']);
  // Step 2 — files
  const [files, setFiles] = React.useState([]);
  const [fileTab, setFileTab] = React.useState('image');
  const [dragging, setDragging] = React.useState(false);
  // Step 2 — voice recorder
  const [recState, setRecState] = React.useState('idle');
  const [recTime, setRecTime] = React.useState(0);
  const [audioURL, setAudioURL] = React.useState('');
  const mrRef = React.useRef(null);
  const riRef = React.useRef(null);
  const chunksRef = React.useRef([]);

  // Step 3
  const [consult, setConsult] = React.useState(false);
  // Booking widget state
  const [bookStep, setBookStep] = React.useState(1); // 1=bundle+date, 2=time, 3=summary
  const [bookBundle, setBookBundle] = React.useState('');
  const [bookDate, setBookDate] = React.useState('');
  const [bookTime, setBookTime] = React.useState('');
  const [bookMonth, setBookMonth] = React.useState(() => { const d = new Date(); return { y: d.getFullYear(), m: d.getMonth() }; });
  const [showLogin, setShowLogin] = React.useState(false);
  const [loginEmail, setLoginEmail] = React.useState('');
  const [loginPass, setLoginPass] = React.useState('');
  const [bookConfirmed, setBookConfirmed] = React.useState(false);

  const BUNDLES = [
    'No preference — any available designer',
    'Party Favour Bundle',
    'Full Party Bundle (Favours + Props)',
    'Balloon Garland & Décor',
    'Invitation Suite',
    'Custom / Bespoke Commission',
  ];

  const SLOTS = ['9:00 AM','9:30 AM','10:00 AM','10:30 AM','11:00 AM','11:30 AM','2:00 PM','2:30 PM','3:00 PM','3:30 PM','4:00 PM','4:30 PM','5:00 PM','5:30 PM'];
  const UNAVAILABLE = ['9:30 AM','11:00 AM','3:00 PM'];

  function getDaysInMonth(y, m) { return new Date(y, m + 1, 0).getDate(); }
  function getFirstDay(y, m) { return new Date(y, m, 1).getDay(); }
  function isPast(y, m, d) { const t = new Date(); t.setHours(0,0,0,0); return new Date(y, m, d) < t; }
  function fmtDate(str) { if (!str) return ''; const [y,m,d] = str.split('-'); return new Date(y,m-1,d).toLocaleDateString('en-GB',{weekday:'long',day:'numeric',month:'long',year:'numeric'}); }

  function prevMonth() { setBookMonth(p => p.m === 0 ? {y:p.y-1,m:11} : {y:p.y,m:p.m-1}); }
  function nextMonth() { setBookMonth(p => p.m === 11 ? {y:p.y+1,m:0} : {y:p.y,m:p.m+1}); }

  const MONTH_NAMES = ['January','February','March','April','May','June','July','August','September','October','November','December'];

  const bookWidgetSx = { background: 'var(--cream)', border: '1.5px solid var(--line)', borderRadius: 'var(--r-lg)', overflow: 'hidden', marginBottom: 24, animation: 'bkExpand .4s cubic-bezier(.2,.8,.2,1)' };
  const bkTabSx = active => ({ flex: 1, padding: '10px 4px', fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.1em', textTransform: 'uppercase', fontWeight: 500, border: 'none', cursor: 'pointer', background: active ? 'var(--ink)' : 'transparent', color: active ? 'var(--cream)' : 'var(--ink-faint)', transition: 'all .3s', borderRadius: 0 });

  const [clientName, setClientName] = React.useState('');
  const [clientEmail, setClientEmail] = React.useState('');
  const [clientWA, setClientWA] = React.useState('');

  const FILE_LIMITS = { image: 20, video: 80, audio: 25 };
  const FILE_ACCEPT = { image: 'image/*', video: 'video/*', audio: 'audio/*' };
  const FILE_ICONS  = { image: '🖼', video: '🎬', audio: '🎵' };
  const today = new Date().toISOString().split('T')[0];

  function goStep(n) { setStep(n); window.scrollTo({ top: 0, behavior: 'smooth' }); }

  function addFiles(list) {
    setFiles(prev => [...prev, ...Array.from(list).map(f => {
      const type = f.type.startsWith('image') ? 'image' : f.type.startsWith('video') ? 'video' : f.type.startsWith('audio') ? 'audio' : 'other';
      const sizeMB = f.size / 1024 / 1024;
      return { f, type, sizeMB: sizeMB.toFixed(1), error: sizeMB > (FILE_LIMITS[type] || 20) ? `Exceeds ${FILE_LIMITS[type] || 20} MB limit` : null, id: Math.random() };
    })]);
  }

  async function startRec() {
    try {
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
      chunksRef.current = [];
      const mr = new MediaRecorder(stream);
      mr.ondataavailable = e => chunksRef.current.push(e.data);
      mr.onstop = () => { setAudioURL(URL.createObjectURL(new Blob(chunksRef.current, { type: 'audio/webm' }))); stream.getTracks().forEach(t => t.stop()); };
      mr.start(); mrRef.current = mr;
      setRecTime(0); setRecState('recording');
      riRef.current = setInterval(() => setRecTime(t => { if (t >= 119) { stopRec(); return t; } return t + 1; }), 1000);
    } catch { toast('Microphone access needed for voice notes', 'info'); }
  }
  function stopRec() { mrRef.current?.state !== 'inactive' && mrRef.current.stop(); clearInterval(riRef.current); setRecState('done'); }
  function deleteRec() { setAudioURL(''); setRecTime(0); setRecState('idle'); }
  function fmtTime(s) { return `${Math.floor(s/60)}:${String(s%60).padStart(2,'0')}`; }

  function submitBrief() {
    if (!clientName || !clientEmail) { toast('Please fill in your name and email', 'error'); return; }
    const ref = 'BB-' + Date.now().toString(36).toUpperCase().slice(-6);
    localStorage.setItem('bb_brief_ref', ref);
    localStorage.setItem('bb_brief_name', clientName);
    nav('order-confirmed', { ref });
  }

  return (
    <>
      <CustomPageHero
        eyebrow="Custom order request"
        title={<>Tell us about your <em style={{ fontStyle: 'italic' }}>vision</em></>}
        sub="Share as much as you like. Every detail helps us create something truly yours."
      />
      <section style={{ background: 'var(--cream)', padding: 'clamp(40px,7vw,80px) var(--gutter)' }}>
        <div style={{ maxWidth: 760, margin: '0 auto' }}>
          <StepBar current={step} total={3} />

          {/* STEP 1 */}
          {step === 1 && (
            <div style={cardSx}>
              <p className="eyebrow" style={{ marginBottom: 8 }}>Step 1 of 3</p>
              <h2 style={{ fontFamily: 'var(--serif)', fontSize: 'clamp(22px,3vw,30px)', marginBottom: 8 }}>The brief</h2>
              <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 28, lineHeight: 1.65 }}>Describe your event, theme, colours, and any must-have elements.</p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
                <BriefField label="Type of event" required>
                  <select style={briefInputSx} value={eventType} onChange={e => setEventType(e.target.value)} onFocus={iFocus} onBlur={iBlur}>
                    <option value="" disabled>Select event type</option>
                    {['Birthday party (child)','Birthday party (adult)','Baby shower','Naming ceremony','Gender reveal','Wedding / engagement','Corporate event','Other'].map(o => <option key={o}>{o}</option>)}
                  </select>
                </BriefField>
                <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
                  <BriefField label="Event date" required>
                    <input type="date" style={briefInputSx} value={eventDate} min={today} onChange={e => setEventDate(e.target.value)} onFocus={iFocus} onBlur={iBlur} />
                  </BriefField>
                  <BriefField label="Guest count">
                    <select style={briefInputSx} value={guestCount} onChange={e => setGuestCount(e.target.value)} onFocus={iFocus} onBlur={iBlur}>
                      <option value="" disabled>Select range</option>
                      {['Under 20','20 – 50','50 – 100','100 – 200','200+'].map(o => <option key={o}>{o}</option>)}
                    </select>
                  </BriefField>
                </div>
                <BriefField label="Project brief" required>
                  <textarea style={{ ...briefInputSx, minHeight: 120, resize: 'vertical' }} value={briefText} onChange={e => setBriefText(e.target.value.slice(0,1500))} placeholder="Describe your vision — theme, colours, mood, specific items, who the celebration is for…" onFocus={iFocus} onBlur={iBlur} />
                  <span style={{ fontSize: 11, color: 'var(--ink-faint)', textAlign: 'right' }}>{briefText.length}/1500</span>
                </BriefField>
                <BriefField label="Approximate budget">
                  <select style={briefInputSx} value={budget} onChange={e => setBudget(e.target.value)} onFocus={iFocus} onBlur={iBlur}>
                    <option value="" disabled>Select a range</option>
                    {['Under ₦100,000 / $65','₦100k – ₦250k / $65–$160','₦250k – ₦500k / $160–$315','₦500k – ₦1m / $315–$625','Over ₦1m / $625+'].map(o => <option key={o}>{o}</option>)}
                  </select>
                </BriefField>
              </div>
              <div style={{ textAlign: 'right', marginTop: 28 }}>
                <button className="btn btn-primary" onClick={() => { if (!eventType || !eventDate) { toast('Please fill in event type and date', 'error'); return; } goStep(2); }}>
                  Continue <I.arrow width={15} height={15} />
                </button>
              </div>
            </div>
          )}

          {/* STEP 2 */}
          {step === 2 && (
            <div style={cardSx}>
              <p className="eyebrow" style={{ marginBottom: 8 }}>Step 2 of 3</p>
              <h2 style={{ fontFamily: 'var(--serif)', fontSize: 'clamp(22px,3vw,30px)', marginBottom: 8 }}>Inspiration &amp; references</h2>
              <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 28, lineHeight: 1.65 }}>Share links, images, videos, or a quick voice note — whatever helps us see your vision.</p>

              {/* Inspiration links */}
              <BriefField label="Inspiration links">
                <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 4 }}>
                  {links.map((l, i) => (
                    <div key={i} style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
                      <input type="url" style={{ ...briefInputSx, flex: 1 }} value={l} onChange={e => setLinks(p => p.map((v,j) => j===i ? e.target.value : v))} placeholder="https://pinterest.com/pin/…" onFocus={iFocus} onBlur={iBlur} />
                      {links.length > 1 && (
                        <button onClick={() => setLinks(p => p.filter((_,j) => j!==i))} style={{ width: 34, height: 34, borderRadius: '100%', background: 'var(--cream-deep)', color: 'var(--ink-soft)', display: 'grid', placeItems: 'center', flexShrink: 0, border: 'none', cursor: 'pointer' }}>
                          <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M18 6 6 18M6 6l12 12" strokeLinecap="round"/></svg>
                        </button>
                      )}
                    </div>
                  ))}
                  <button onClick={() => setLinks(p => [...p, ''])} style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontSize: 12, letterSpacing: '.1em', textTransform: 'uppercase', color: 'var(--gold-deep)', fontWeight: 500, padding: '8px 0', background: 'none', border: 'none', cursor: 'pointer' }}>
                    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M12 5v14M5 12h14" strokeLinecap="round"/></svg>
                    Add another link
                  </button>
                </div>
              </BriefField>

              {/* File uploader */}
              <div style={{ marginTop: 24 }}>
                <BriefField label="Upload files">
                  <div style={{ display: 'none' }}>
                    {['image','video','audio'].map(t => (
                      <button key={t} onClick={() => { setFileTab(t); document.getElementById('briefFileInp').accept = FILE_ACCEPT[t]; }} style={{ padding: '9px 18px', borderRadius: 100, fontSize: 12, letterSpacing: '.08em', textTransform: 'uppercase', fontWeight: 500, border: `1.5px solid ${fileTab===t ? 'var(--ink)' : 'var(--line)'}`, background: fileTab===t ? 'var(--ink)' : 'var(--cream)', color: fileTab===t ? 'var(--cream)' : 'var(--ink-soft)', cursor: 'pointer', transition: 'all .25s' }}>
                        {t==='image' ? '🖼 Images' : t==='video' ? '🎬 Video' : '🎵 Audio'}
                      </button>
                    ))}
                  </div>
                  <div
                    onClick={() => document.getElementById('briefFileInp').click()}
                    onDragOver={e => { e.preventDefault(); setDragging(true); }}
                    onDragLeave={() => setDragging(false)}
                    onDrop={e => { e.preventDefault(); setDragging(false); addFiles(e.dataTransfer.files); }}
                    style={{ border: `2px dashed ${dragging ? 'var(--gold)' : 'var(--line)'}`, borderRadius: 'var(--r-lg)', padding: '32px 20px', textAlign: 'center', cursor: 'pointer', background: dragging ? 'var(--gold-soft)' : 'var(--cream)', transition: 'all .25s' }}>
                    <div style={{ width: 52, height: 52, borderRadius: '100%', background: 'var(--gold-soft)', display: 'grid', placeItems: 'center', color: 'var(--gold-deep)', margin: '0 auto 14px' }}>
                      <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
                    </div>
                    <p style={{ fontFamily: 'var(--serif)', fontSize: 20, marginBottom: 6 }}>Drop files here or <span style={{ color: 'var(--gold-deep)' }}>browse</span></p>
                    <div style={{ display: 'flex', gap: 8, justifyContent: 'center', flexWrap: 'wrap', marginTop: 12 }}>
                      <span style={{ fontSize: 11, padding: '5px 12px', borderRadius: 100, background: 'var(--gold-soft)', color: 'var(--gold-deep)', fontWeight: 500 }}>Images up to 20 MB</span>
                      <span style={{ fontSize: 11, padding: '5px 12px', borderRadius: 100, background: 'var(--blush-soft)', color: 'var(--blush-deep)', fontWeight: 500 }}>Videos up to 80 MB</span>
                      <span style={{ fontSize: 11, padding: '5px 12px', borderRadius: 100, background: 'var(--sage-soft)', color: 'var(--sage)', fontWeight: 500 }}>Audio up to 25 MB</span>
                    </div>
                    <input id="briefFileInp" type="file" multiple accept="image/*" style={{ display: 'none' }} onChange={e => { addFiles(e.target.files); e.target.value = ''; }} />
                  </div>
                  {files.length > 0 && (
                    <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 14 }}>
                      {files.map(f => (
                        <div key={f.id} style={{ display: 'flex', alignItems: 'center', gap: 12, background: f.error ? 'var(--blush-soft)' : 'var(--cream)', border: `1px solid ${f.error ? 'var(--blush)' : 'var(--line)'}`, borderRadius: 'var(--r-md)', padding: '12px 16px' }}>
                          <span style={{ fontSize: 20, flexShrink: 0 }}>{FILE_ICONS[f.type] || '📎'}</span>
                          <div style={{ flex: 1, minWidth: 0 }}>
                            <div style={{ fontSize: 13.5, fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{f.f.name}</div>
                            <div style={{ fontSize: 11, color: 'var(--ink-faint)', marginTop: 2 }}>{f.sizeMB} MB</div>
                            {f.error && <div style={{ fontSize: 11, color: 'var(--blush-deep)', fontWeight: 500, marginTop: 3 }}>⚠ {f.error} — please reduce file size</div>}
                          </div>
                          <button onClick={() => setFiles(p => p.filter(x => x.id!==f.id))} style={{ width: 28, height: 28, borderRadius: '100%', background: 'var(--line)', display: 'grid', placeItems: 'center', color: 'var(--ink-soft)', border: 'none', cursor: 'pointer' }}>
                            <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M18 6 6 18M6 6l12 12" strokeLinecap="round"/></svg>
                          </button>
                        </div>
                      ))}
                    </div>
                  )}
                </BriefField>
              </div>

              {/* Voice recorder */}
              <div style={{ marginTop: 24 }}>
                <p style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500, marginBottom: 10 }}>Voice note</p>
                <div style={{ background: 'var(--cream)', border: '1.5px solid var(--line)', borderRadius: 'var(--r-md)', padding: '16px 20px', display: 'flex', alignItems: 'center', gap: 16, flexWrap: 'wrap' }}>
                  {recState === 'idle' && <>
                    <button onClick={startRec} aria-label="Start recording" style={{ width: 44, height: 44, borderRadius: '100%', background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', color: '#fff', display: 'grid', placeItems: 'center', flexShrink: 0, boxShadow: '0 4px 14px rgba(138,24,192,.28)', border: 'none', cursor: 'pointer' }}>
                      <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="8"/></svg>
                    </button>
                    <div>
                      <p style={{ fontSize: 13.5, color: 'var(--ink)', fontWeight: 500 }}>Record a voice note</p>
                      <p style={{ fontSize: 12, color: 'var(--ink-faint)', marginTop: 2 }}>Up to 2 minutes</p>
                    </div>
                  </>}
                  {recState === 'recording' && <>
                    <button onClick={stopRec} aria-label="Stop recording" style={{ width: 44, height: 44, borderRadius: '100%', background: 'linear-gradient(135deg,var(--blush-deep),var(--blush))', color: '#fff', display: 'grid', placeItems: 'center', flexShrink: 0, boxShadow: '0 4px 14px rgba(240,32,127,.28)', border: 'none', cursor: 'pointer' }}>
                      <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><rect x="4" y="4" width="16" height="16" rx="2"/></svg>
                    </button>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 10, flex: 1 }}>
                      <span style={{ width: 8, height: 8, borderRadius: '100%', background: 'var(--blush)', animation: 'bBlink 1.2s ease-in-out infinite', display: 'inline-block', flexShrink: 0 }}></span>
                      <span style={{ fontFamily: 'var(--serif)', fontSize: 24 }}>{fmtTime(recTime)}</span>
                      <div style={{ display: 'flex', gap: 2, alignItems: 'center', height: 28 }}>
                        {[0,.1,.2,.3,.15,.05,.25].map((d,i) => <div key={i} style={{ width: 3, borderRadius: 100, background: 'var(--gold)', animation: `bWave 1.3s ease-in-out ${d}s infinite` }}></div>)}
                      </div>
                    </div>
                  </>}
                  {recState === 'done' && <>
                    <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 8 }}>
                      <p style={{ fontSize: 13, color: 'var(--ink-soft)' }}>Voice note recorded ✓</p>
                      <audio src={audioURL} controls style={{ width: '100%', borderRadius: 'var(--r-sm)' }}></audio>
                    </div>
                    <div style={{ display: 'flex', gap: 8, flexShrink: 0 }}>
                      <button onClick={deleteRec} style={{ padding: '7px 12px', borderRadius: 100, background: 'var(--blush-soft)', color: 'var(--blush-deep)', fontSize: 11, letterSpacing: '.08em', textTransform: 'uppercase', fontWeight: 500, border: 'none', cursor: 'pointer' }}>Delete</button>
                      <button onClick={() => { setRecState('idle'); setAudioURL(''); }} style={{ padding: '7px 12px', borderRadius: 100, background: 'var(--gold-soft)', color: 'var(--gold-deep)', fontSize: 11, letterSpacing: '.08em', textTransform: 'uppercase', fontWeight: 500, border: 'none', cursor: 'pointer' }}>Re-record</button>
                    </div>
                  </>}
                </div>
              </div>

              <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 28, flexWrap: 'wrap', gap: 12 }}>
                <button className="btn btn-outline" onClick={() => goStep(1)}>← Back</button>
                <button className="btn btn-primary" onClick={() => goStep(3)}>Continue <I.arrow width={15} height={15} /></button>
              </div>
            </div>
          )}

          {/* STEP 3 */}
          {step === 3 && (
            <div style={cardSx}>
              <p className="eyebrow" style={{ marginBottom: 8 }}>Step 3 of 3</p>
              <h2 style={{ fontFamily: 'var(--serif)', fontSize: 'clamp(22px,3vw,30px)', marginBottom: 8 }}>How would you like to proceed?</h2>
              <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 28, lineHeight: 1.65 }}>Choose how our team reviews your brief and sends your proposal.</p>

              {/* Consultation toggle */}
              <div style={{ display: 'flex', gap: 16, alignItems: 'flex-start', marginBottom: 20 }}>
                <label style={{ position: 'relative', width: 52, height: 28, flexShrink: 0, marginTop: 3, cursor: 'pointer', display: 'block' }}>
                  <input type="checkbox" checked={consult} onChange={e => setConsult(e.target.checked)} style={{ opacity: 0, width: 0, height: 0, position: 'absolute' }} />
                  <span style={{ position: 'absolute', inset: 0, borderRadius: 100, background: consult ? 'var(--gold)' : 'var(--line)', transition: 'background .35s' }}>
                    <span style={{ position: 'absolute', left: consult ? 26 : 3, top: 3, width: 22, height: 22, borderRadius: '100%', background: '#fff', boxShadow: '0 2px 6px rgba(0,0,0,.15)', transition: 'left .35s' }}></span>
                  </span>
                </label>
                <div>
                  <h4 style={{ fontFamily: 'var(--serif)', fontSize: 18, marginBottom: 4 }}>Book a consultation call</h4>
                  <p style={{ fontSize: 14, color: 'var(--ink-soft)', lineHeight: 1.6 }}>Toggle on to schedule a live 30-minute call with our designer before we begin.</p>
                </div>
              </div>

              {consult ? (
                <div style={bookWidgetSx}>
                  {/* Widget header */}
                  <div style={{ background: 'linear-gradient(135deg,var(--ink),#4A1E5E)', padding: '18px 24px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                    <div>
                      <p style={{ fontFamily: 'var(--sans)', fontSize: 10, letterSpacing: '.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,.5)', marginBottom: 4 }}>Free consultation</p>
                      <p style={{ fontFamily: 'var(--serif)', fontSize: 18, color: '#fff' }}>Book a 30-minute call</p>
                    </div>
                    <div style={{ display: 'flex', background: 'rgba(255,255,255,.08)', borderRadius: 100, padding: 3, gap: 2 }}>
                      {['Details','Time','Summary'].map((l,i) => (
                        <button key={l} style={{ ...bkTabSx(bookStep===i+1), borderRadius: 100, padding: '8px 14px', fontSize: 10 }} onClick={() => { if (i+1 < bookStep || (i===1 && bookDate)) setBookStep(i+1); }}>{l}</button>
                      ))}
                    </div>
                  </div>

                  {/* STEP 1: Bundle + Calendar */}
                  {bookStep === 1 && (
                    <div style={{ padding: 'clamp(18px,3vw,32px)' }}>
                      {/* Bundle picker */}
                      <div style={{ marginBottom: 22 }}>
                        <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500, display: 'block', marginBottom: 8 }}>Party bundle <span style={{ color: 'var(--ink-faint)', fontWeight: 400 }}>(optional)</span></label>
                        <select style={{ ...briefInputSx, background: 'var(--ivory)' }} value={bookBundle} onChange={e => setBookBundle(e.target.value)} onFocus={iFocus} onBlur={iBlur}>
                          <option value="">Select a bundle (or leave blank)</option>
                          {BUNDLES.map(b => <option key={b}>{b}</option>)}
                        </select>
                      </div>
                      {/* Calendar */}
                      <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500, display: 'block', marginBottom: 12 }}>Select a date <span style={{ color: 'var(--blush)' }}>*</span></label>
                      <div style={{ background: 'var(--ivory)', borderRadius: 'var(--r-md)', border: '1px solid var(--line)', overflow: 'hidden' }}>
                        {/* Month nav */}
                        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '14px 18px', borderBottom: '1px solid var(--line)' }}>
                          <button onClick={prevMonth} style={{ width: 32, height: 32, borderRadius: '100%', background: 'var(--cream-deep)', border: 'none', cursor: 'pointer', display: 'grid', placeItems: 'center', color: 'var(--ink-soft)' }}>
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M15 18l-6-6 6-6"/></svg>
                          </button>
                          <span style={{ fontFamily: 'var(--serif)', fontSize: 18 }}>{MONTH_NAMES[bookMonth.m]} {bookMonth.y}</span>
                          <button onClick={nextMonth} style={{ width: 32, height: 32, borderRadius: '100%', background: 'var(--cream-deep)', border: 'none', cursor: 'pointer', display: 'grid', placeItems: 'center', color: 'var(--ink-soft)' }}>
                            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M9 18l6-6-6-6"/></svg>
                          </button>
                        </div>
                        {/* Day labels */}
                        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', padding: '10px 12px 4px' }}>
                          {['Su','Mo','Tu','We','Th','Fr','Sa'].map(d => (
                            <div key={d} style={{ textAlign: 'center', fontSize: 11, letterSpacing: '.08em', color: 'var(--ink-faint)', fontWeight: 500, padding: '4px 0' }}>{d}</div>
                          ))}
                        </div>
                        {/* Days grid */}
                        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(7,1fr)', padding: '0 12px 14px', gap: 2 }}>
                          {Array.from({ length: getFirstDay(bookMonth.y, bookMonth.m) }, (_, i) => <div key={'e'+i} />)}
                          {Array.from({ length: getDaysInMonth(bookMonth.y, bookMonth.m) }, (_, i) => {
                            const d = i + 1;
                            const dateStr = `${bookMonth.y}-${String(bookMonth.m+1).padStart(2,'0')}-${String(d).padStart(2,'0')}`;
                            const past = isPast(bookMonth.y, bookMonth.m, d);
                            const isSun = new Date(bookMonth.y, bookMonth.m, d).getDay() === 0;
                            const sel = bookDate === dateStr;
                            return (
                              <button key={d} disabled={past || isSun} onClick={() => setBookDate(dateStr)} style={{
                                height: 36, borderRadius: 8, border: 'none', cursor: past||isSun ? 'not-allowed' : 'pointer',
                                fontFamily: 'var(--sans)', fontSize: 13, fontWeight: sel ? 600 : 400,
                                background: sel ? 'var(--gold)' : 'transparent',
                                color: sel ? '#fff' : past||isSun ? 'var(--line)' : 'var(--ink)',
                                transition: 'all .2s',
                                boxShadow: sel ? '0 4px 14px rgba(138,24,192,.25)' : 'none',
                              }} onMouseEnter={e => { if (!past && !isSun && !sel) e.currentTarget.style.background = 'var(--gold-soft)'; }}
                              onMouseLeave={e => { if (!sel) e.currentTarget.style.background = 'transparent'; }}>
                                {d}
                              </button>
                            );
                          })}
                        </div>
                      </div>
                      <div style={{ marginTop: 20, textAlign: 'right' }}>
                        <button className="btn btn-primary" disabled={!bookDate} onClick={() => bookDate && setBookStep(2)} style={{ opacity: bookDate ? 1 : .4 }}>
                          Choose a time <I.arrow width={14} height={14} />
                        </button>
                      </div>
                    </div>
                  )}

                  {/* STEP 2: Time slots */}
                  {bookStep === 2 && (
                    <div style={{ padding: 'clamp(18px,3vw,32px)' }}>
                      <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 20, padding: '12px 16px', background: 'var(--gold-soft)', borderRadius: 'var(--r-md)' }}>
                        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="var(--gold-deep)" strokeWidth="1.5"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>
                        <span style={{ fontSize: 13.5, color: 'var(--gold-deep)', fontWeight: 500 }}>{fmtDate(bookDate)}</span>
                        <button onClick={() => setBookStep(1)} style={{ marginLeft: 'auto', fontSize: 11, color: 'var(--gold-deep)', background: 'none', border: 'none', cursor: 'pointer', letterSpacing: '.08em', textTransform: 'uppercase', textDecoration: 'underline' }}>Change</button>
                      </div>
                      <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500, display: 'block', marginBottom: 14 }}>Available times (WAT · Lagos) <span style={{ color: 'var(--blush)' }}>*</span></label>
                      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill,minmax(108px,1fr))', gap: 8 }}>
                        {SLOTS.map(s => {
                          const unavail = UNAVAILABLE.includes(s);
                          const sel = bookTime === s;
                          return (
                            <button key={s} disabled={unavail} onClick={() => setBookTime(s)} style={{
                              padding: '11px 8px', borderRadius: 100, fontSize: 13, fontFamily: 'var(--sans)', fontWeight: 500,
                              border: `1.5px solid ${sel ? 'var(--gold)' : unavail ? 'var(--line)' : 'var(--line)'}`,
                              background: sel ? 'var(--gold)' : 'var(--ivory)',
                              color: sel ? '#fff' : unavail ? 'var(--ink-faint)' : 'var(--ink)',
                              cursor: unavail ? 'not-allowed' : 'pointer',
                              textDecoration: unavail ? 'line-through' : 'none',
                              opacity: unavail ? .45 : 1,
                              transition: 'all .2s',
                              boxShadow: sel ? '0 4px 14px rgba(138,24,192,.22)' : 'none',
                            }}>{s}</button>
                          );
                        })}
                      </div>
                      <p style={{ fontSize: 12, color: 'var(--ink-faint)', marginTop: 12 }}>Crossed-out slots are unavailable. All times are West Africa Time (GMT+1).</p>
                      <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 20 }}>
                        <button className="btn btn-outline" onClick={() => setBookStep(1)}>← Back</button>
                        <button className="btn btn-primary" disabled={!bookTime} onClick={() => bookTime && setBookStep(3)} style={{ opacity: bookTime ? 1 : .4 }}>
                          Review booking <I.arrow width={14} height={14} />
                        </button>
                      </div>
                    </div>
                  )}

                  {/* STEP 3: Summary */}
                  {bookStep === 3 && (
                    <div style={{ padding: 'clamp(18px,3vw,32px)' }}>
                      <p style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--ink-faint)', fontWeight: 500, marginBottom: 16 }}>Booking summary</p>
                      <div style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-md)', overflow: 'hidden', marginBottom: 20 }}>
                        {[
                          ['Service', 'Free 30-min design consultation'],
                          ['Bundle interest', bookBundle || 'No preference'],
                          ['Date', fmtDate(bookDate)],
                          ['Time', bookTime + ' WAT (Lagos)'],
                          ['Duration', '30 minutes'],
                          ['Format', 'WhatsApp video or voice call'],
                        ].map(([l,v], i, arr) => (
                          <div key={l} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 16, padding: '13px 18px', borderBottom: i < arr.length-1 ? '1px solid var(--cream-deep)' : 'none' }}>
                            <span style={{ fontSize: 12, color: 'var(--ink-faint)', letterSpacing: '.06em', textTransform: 'uppercase', flexShrink: 0 }}>{l}</span>
                            <span style={{ fontSize: 14, fontWeight: 500, textAlign: 'right' }}>{v}</span>
                          </div>
                        ))}
                      </div>
                      {/* Price breakdown */}
                      <div style={{ background: 'linear-gradient(135deg,var(--gold-soft),var(--cream))', border: '1px solid var(--line)', borderRadius: 'var(--r-md)', padding: '16px 18px', marginBottom: 20 }}>
                        <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 14, marginBottom: 8 }}><span style={{ color: 'var(--ink-soft)' }}>Consultation fee</span><span style={{ fontWeight: 500 }}>₦5,000</span></div>
                        <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 13, marginBottom: 8 }}><span style={{ color: 'var(--ink-faint)' }}>VAT (7.5%)</span><span style={{ color: 'var(--ink-faint)' }}>₦375</span></div>
                        <div style={{ height: 1, background: 'var(--line)', margin: '10px 0' }}></div>
                        <div style={{ display: 'flex', justifyContent: 'space-between' }}><span style={{ fontFamily: 'var(--serif)', fontSize: 18 }}>Total due today</span><span style={{ fontFamily: 'var(--serif)', fontSize: 22, color: 'var(--gold-deep)' }}>₦5,375</span></div>
                      </div>
                      <div style={{ background: 'var(--sage-soft)', border: '1px solid var(--sage)', borderRadius: 'var(--r-sm)', padding: '12px 16px', display: 'flex', gap: 10, alignItems: 'flex-start', marginBottom: 24 }}>
                        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="var(--sage)" strokeWidth="1.5" style={{ flexShrink:0, marginTop:1 }}><circle cx="12" cy="12" r="9"/><path d="M12 8v4M12 16h.01"/></svg>
                        <p style={{ fontSize: 13, color: 'var(--ink-soft)', lineHeight: 1.6 }}>By confirming, you’ll be directed to payment. Once paid, we’ll send a WhatsApp confirmation within a few hours. The fee is deducted from your final order.</p>
                      </div>
                      <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
                        <button className="btn btn-outline" onClick={() => setBookStep(2)} style={{ flexShrink: 0 }}>← Back</button>
                        <button className="btn btn-gold" onClick={() => setShowLogin(true)} style={{ flex: 1, justifyContent: 'center' }}>
                          <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>
                          Confirm appointment
                        </button>
                      </div>
                    </div>
                  )}

                  {/* Confirmed state */}
                  {bookConfirmed && (
                    <div style={{ padding: 'clamp(18px,3vw,32px)', textAlign: 'center' }}>
                      <div style={{ width: 60, height: 60, borderRadius: '100%', background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', display: 'grid', placeItems: 'center', color: '#fff', margin: '0 auto 16px', boxShadow: '0 8px 24px rgba(138,24,192,.28)' }}>
                        <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="m5 13 4 4 10-11" strokeLinecap="round"/></svg>
                      </div>
                      <h4 style={{ fontFamily: 'var(--serif)', fontSize: 24, marginBottom: 8 }}>Slot reserved!</h4>
                      <p style={{ fontSize: 14, color: 'var(--ink-soft)', lineHeight: 1.65, maxWidth: 360, margin: '0 auto' }}>Your consultation is booked for <strong>{fmtDate(bookDate)}</strong> at <strong>{bookTime}</strong>. We’ll confirm via WhatsApp shortly.</p>
                    </div>
                  )}

                </div>
              ) : (
                <div style={{ background: 'var(--sage-soft)', border: '1px solid var(--sage)', borderRadius: 'var(--r-md)', padding: '16px 20px', display: 'flex', gap: 12, alignItems: 'flex-start', marginBottom: 24 }}>
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="var(--sage)" strokeWidth="1.5" style={{ flexShrink: 0, marginTop: 2 }}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 3"/></svg>
                  <p style={{ fontSize: 14, color: 'var(--ink-soft)', lineHeight: 1.65 }}>Our team will review your brief asynchronously and get back to you <strong>within 48 hours</strong> via WhatsApp with a personalised proposal.</p>
                </div>
              )}

              <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
                <BriefField label="Your name" required>
                  <input type="text" style={briefInputSx} value={clientName} onChange={e => setClientName(e.target.value)} placeholder="e.g. Adaeze Okafor" autoComplete="name" onFocus={iFocus} onBlur={iBlur} />
                </BriefField>
                <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
                  <BriefField label="Email address" required>
                    <input type="email" style={briefInputSx} value={clientEmail} onChange={e => setClientEmail(e.target.value)} placeholder="you@example.com" autoComplete="email" onFocus={iFocus} onBlur={iBlur} />
                  </BriefField>
                  <BriefField label="WhatsApp">
                    <input type="tel" style={briefInputSx} value={clientWA} onChange={e => setClientWA(e.target.value)} placeholder="+234 800 000 0000" autoComplete="tel" onFocus={iFocus} onBlur={iBlur} />
                  </BriefField>
                </div>
              </div>

              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 14, marginTop: 28 }}>
                <button className="btn btn-outline" onClick={() => goStep(2)}>← Back</button>
                <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 8 }}>
                  <button className="btn btn-gold btn-lg" onClick={submitBrief}>
                    Submit my brief
                    <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M22 2 11 13M22 2 15 22 11 13 2 9l20-7z"/></svg>
                  </button>
                  <span style={{ fontSize: 12, color: 'var(--ink-faint)', display: 'flex', alignItems: 'center', gap: 6 }}>
                    <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
                    Secure · Private · No obligation
                  </span>
                </div>
              </div>
            </div>
          )}
        </div>
      </section>

      <style>{`
        @keyframes bBlink { 0%,100%{opacity:1}50%{opacity:0} }
        @keyframes bWave  { 0%,100%{height:6px;opacity:.4}50%{height:28px;opacity:1} }
        @keyframes bkExpand { from{opacity:0;transform:translateY(-8px)} to{opacity:1;transform:none} }
      `}</style>

      {/* Login modal */}
      {showLogin && (
        <div onClick={e => { if (e.target === e.currentTarget) setShowLogin(false); }} role="dialog" aria-modal="true" style={{ position: 'fixed', inset: 0, zIndex: 9999, background: 'rgba(18,6,26,.72)', backdropFilter: 'blur(7px)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20, animation: 'ttnIn .4s forwards' }}>
          <div style={{ background: 'var(--ivory)', borderRadius: 24, maxWidth: 420, width: '100%', padding: 'clamp(28px,5vw,48px)', boxShadow: '0 32px 80px rgba(42,17,51,.35)', border: '1px solid var(--line)', position: 'relative', animation: 'ttnCardIn .45s forwards' }}>
            <button onClick={() => setShowLogin(false)} aria-label="Close" style={{ position: 'absolute', top: 18, right: 18, width: 34, height: 34, borderRadius: '100%', background: 'var(--cream-deep)', border: 'none', cursor: 'pointer', display: 'grid', placeItems: 'center', color: 'var(--ink-soft)' }} onMouseEnter={e => { e.currentTarget.style.background='var(--ink)'; e.currentTarget.style.color='#fff'; }} onMouseLeave={e => { e.currentTarget.style.background='var(--cream-deep)'; e.currentTarget.style.color='var(--ink-soft)'; }}>
              <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M18 6 6 18M6 6l12 12" strokeLinecap="round"/></svg>
            </button>
            <p className="eyebrow" style={{ marginBottom: 10 }}>One last step</p>
            <h3 style={{ fontFamily: 'var(--serif)', fontSize: 28, marginBottom: 6, lineHeight: 1.05 }}>Sign in to confirm</h3>
            <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 24, lineHeight: 1.6 }}>Create a free account or sign in to lock in your consultation slot.</p>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
                <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500 }}>Email address</label>
                <input type="email" style={{ ...briefInputSx, background: 'var(--cream)' }} value={loginEmail} onChange={e => setLoginEmail(e.target.value)} placeholder="you@example.com" onFocus={iFocus} onBlur={iBlur} autoComplete="email" />
              </div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
                <label style={{ fontFamily: 'var(--sans)', fontSize: 11, letterSpacing: '.12em', textTransform: 'uppercase', color: 'var(--ink-soft)', fontWeight: 500 }}>Password</label>
                <input type="password" style={{ ...briefInputSx, background: 'var(--cream)' }} value={loginPass} onChange={e => setLoginPass(e.target.value)} placeholder="••••••••" onFocus={iFocus} onBlur={iBlur} autoComplete="current-password" />
              </div>
            </div>
            <button className="btn btn-gold" onClick={() => { setShowLogin(false); setBookConfirmed(true); setBookStep(99); }} style={{ width: '100%', justifyContent: 'center', marginTop: 20 }}>
              Confirm my appointment
            </button>
            <div style={{ display: 'flex', alignItems: 'center', gap: 12, margin: '18px 0' }}>
              <div style={{ flex: 1, height: 1, background: 'var(--line)' }}></div>
              <span style={{ fontSize: 12, color: 'var(--ink-faint)' }}>or</span>
              <div style={{ flex: 1, height: 1, background: 'var(--line)' }}></div>
            </div>
            <button className="btn btn-outline" style={{ width: '100%', justifyContent: 'center' }} onClick={() => { setShowLogin(false); setBookConfirmed(true); setBookStep(99); }}>
              Continue as guest
            </button>
            <p style={{ fontSize: 12, color: 'var(--ink-faint)', textAlign: 'center', marginTop: 16 }}>
              No account? <span style={{ color: 'var(--gold-deep)', cursor: 'pointer', textDecoration: 'underline' }}>Create one free</span>
            </p>
          </div>
        </div>
      )}
    </>
  );
}

/* ─────────────────────────────────────────────────────────
   2. ORDER CONFIRMED PAGE
───────────────────────────────────────────────────────── */
function OrderConfirmedPage({ params }) {
  const { nav } = useStore();
  const ref  = (params && params.ref)  || localStorage.getItem('bb_brief_ref')  || 'BB-XXXXXX';
  const name = localStorage.getItem('bb_brief_name') || 'there';
  const now  = new Date().toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' });
  const [copied, setCopied] = React.useState(false);

  function copyRef() {
    navigator.clipboard.writeText(ref).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); });
  }

  const tlItem = (state, icon, title, desc, eta) => (
    <div style={{ display: 'flex', gap: 18 }}>
      <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
        <div style={{ width: 38, height: 38, borderRadius: '100%', flexShrink: 0, display: 'grid', placeItems: 'center', zIndex: 1,
          background: state==='done' ? 'linear-gradient(135deg,var(--gold-deep),var(--gold))' : state==='active' ? 'var(--ivory)' : 'var(--cream-deep)',
          border: `2px solid ${state==='done' ? 'var(--gold)' : state==='active' ? 'var(--gold)' : 'var(--line)'}`,
          color: state==='done' ? '#fff' : state==='active' ? 'var(--gold)' : 'var(--ink-faint)',
          boxShadow: state==='done' ? '0 4px 14px rgba(138,24,192,.25)' : 'none',
        }}>{icon}</div>
        {eta && <div style={{ flex: 1, width: 2, background: 'var(--line)', margin: '4px 0' }}></div>}
      </div>
      <div style={{ paddingTop: 6, paddingBottom: eta ? 28 : 0 }}>
        <h4 style={{ fontFamily: 'var(--serif)', fontSize: 18, marginBottom: 4 }}>{title}</h4>
        <p style={{ fontSize: 13.5, color: 'var(--ink-soft)', lineHeight: 1.6 }}>{desc}</p>
        {eta && <p style={{ fontSize: 11, letterSpacing: '.1em', textTransform: 'uppercase', color: 'var(--gold-deep)', fontWeight: 500, marginTop: 6 }}>{eta}</p>}
      </div>
    </div>
  );

  return (
    <>
      <section style={{ background: 'linear-gradient(160deg,var(--cream-deep),var(--gold-soft))', padding: 'clamp(56px,9vw,100px) var(--gutter)', textAlign: 'center' }}>
        <div style={{ maxWidth: 640, margin: '0 auto' }}>
          <div style={{ width: 96, height: 96, borderRadius: '100%', background: 'linear-gradient(135deg,var(--gold-deep),var(--gold),var(--blush))', display: 'grid', placeItems: 'center', color: '#fff', margin: '0 auto 28px', boxShadow: '0 16px 48px rgba(138,24,192,.30)', animation: 'ocPop .7s cubic-bezier(.2,.8,.2,1) both' }}>
            <svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="m5 13 4 4 10-11" strokeLinecap="round" strokeLinejoin="round"/></svg>
          </div>
          <p className="eyebrow" style={{ marginBottom: 12 }}>Brief received</p>
          <h1 style={{ fontSize: 'clamp(36px,5.5vw,62px)', marginBottom: 14 }}>Your brief is <em style={{ fontStyle: 'italic' }}>blooming</em> 🌸</h1>
          <p style={{ fontSize: 16, color: 'var(--ink-soft)', lineHeight: 1.7 }}>We've received your project brief and our team is already looking forward to bringing your vision to life.</p>
        </div>
      </section>

      <section style={{ background: 'var(--cream)', padding: 'clamp(40px,7vw,80px) var(--gutter)' }}>
        <div style={{ maxWidth: 760, margin: '0 auto' }}>

          {/* Draft card */}
          <div style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', overflow: 'hidden', marginBottom: 24, boxShadow: '0 2px 12px rgba(42,17,51,.07)', animation: 'ocRise .7s .15s cubic-bezier(.2,.8,.2,1) both' }}>
            <div style={{ background: 'linear-gradient(135deg,var(--ink),#4A1E5E)', padding: 'clamp(24px,4vw,36px)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 16 }}>
              <div>
                <h2 style={{ fontFamily: 'var(--serif)', fontSize: 22, color: '#fff', marginBottom: 4 }}>Your draft order</h2>
                <p style={{ fontSize: 13, color: 'rgba(255,255,255,.55)', letterSpacing: '.06em' }}>Saved · Awaiting review</p>
              </div>
              <div style={{ background: 'rgba(255,255,255,.12)', border: '1px solid rgba(255,255,255,.2)', borderRadius: 100, padding: '8px 20px', display: 'flex', alignItems: 'center', gap: 8, fontSize: 12, fontWeight: 500, letterSpacing: '.12em', textTransform: 'uppercase', color: 'rgba(255,255,255,.8)' }}>
                <span style={{ width: 8, height: 8, borderRadius: '100%', background: '#F0C040', animation: 'ocPulse 2s ease-in-out infinite', display: 'inline-block' }}></span>Draft
              </div>
            </div>
            <div style={{ padding: 'clamp(20px,4vw,36px)' }}>
              {/* Ref */}
              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: 'var(--cream-deep)', border: '1px solid var(--line)', borderRadius: 'var(--r-md)', padding: '16px 20px', marginBottom: 28 }}>
                <div>
                  <div style={{ fontSize: 11, letterSpacing: '.16em', textTransform: 'uppercase', color: 'var(--ink-faint)', marginBottom: 4 }}>Reference number</div>
                  <div style={{ fontFamily: 'var(--serif)', fontSize: 28, color: 'var(--ink)', letterSpacing: '.04em' }}>{ref}</div>
                </div>
                <button onClick={copyRef} style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '8px 14px', borderRadius: 100, background: copied ? 'var(--gold-soft)' : 'var(--gold-soft)', color: 'var(--gold-deep)', fontSize: 12, letterSpacing: '.08em', textTransform: 'uppercase', fontWeight: 500, border: 'none', cursor: 'pointer' }}>
                  {copied ? '✓ Copied' : <><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg> Copy ref</>}
                </button>
              </div>
              {/* Details */}
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20, marginBottom: 28 }}>
                {[['Submitted', now], ['Status', '🟡 Under review'], ['Expected response', 'Within 48 hours'], ['Contact method', 'WhatsApp']].map(([l,v]) => (
                  <div key={l}>
                    <div style={{ fontSize: 11, color: 'var(--ink-faint)', letterSpacing: '.1em', textTransform: 'uppercase', marginBottom: 4 }}>{l}</div>
                    <div style={{ fontSize: 14.5, fontWeight: 500 }}>{v}</div>
                  </div>
                ))}
              </div>
              {/* Video processing */}
              <div style={{ background: 'var(--sage-soft)', border: '1px solid var(--sage)', borderRadius: 'var(--r-md)', padding: '18px 20px', display: 'flex', gap: 14, alignItems: 'flex-start', marginBottom: 28 }}>
                <div style={{ width: 40, height: 40, borderRadius: '100%', background: 'rgba(169,143,216,.2)', display: 'grid', placeItems: 'center', color: 'var(--sage)', flexShrink: 0 }}>
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M15 10l4.553-2.277A1 1 0 0 1 21 8.62v6.76a1 1 0 0 1-1.447.9L15 14M3 8a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8Z"/></svg>
                </div>
                <div style={{ flex: 1 }}>
                  <h4 style={{ fontFamily: 'var(--serif)', fontSize: 17, marginBottom: 4 }}>Your video is processing…</h4>
                  <p style={{ fontSize: 13, color: 'var(--ink-soft)', lineHeight: 1.6, marginBottom: 10 }}>We're optimising your uploaded video. This usually takes a few minutes. You'll receive a WhatsApp message once it's ready for review.</p>
                  <div style={{ height: 6, background: 'rgba(255,255,255,.6)', borderRadius: 100, overflow: 'hidden' }}>
                    <div style={{ height: '100%', background: 'linear-gradient(90deg,var(--sage),var(--gold))', borderRadius: 100, animation: 'ocProg 4s ease-out forwards' }}></div>
                  </div>
                </div>
              </div>
              {/* Timeline */}
              <p style={{ fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: 'var(--ink-faint)', fontWeight: 500, marginBottom: 20 }}>What happens next</p>
              {(() => {
                const tlIc1 = <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="m5 13 4 4 10-11" strokeLinecap="round"/></svg>;
                const tlIc2 = <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 3"/></svg>;
                const tlIc3 = <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6l8-3Z"/></svg>;
                const tlIc4 = <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>;
                return (<>
                  {tlItem('done',    tlIc1, 'Brief submitted',      'Your project brief, inspiration links, and attachments have been received.', 'Completed just now')}
                  {tlItem('active',  tlIc2, 'Team review',          'Our design team will review your brief and any inspiration you shared.', 'In progress · up to 48 hours')}
                  {tlItem('pending', tlIc3, 'Custom proposal',      'You will receive a personalised proposal via WhatsApp with itemised pricing and mood board.', '2–3 business days')}
                  {tlItem('pending', tlIc4, 'Approval & production','Approve the proposal and pay a 50% deposit - then our artisans begin crafting your pieces.', null)}
                </>);
              })()}
            </div>
          </div>

          {/* Quote */}
          <div style={{ background: 'linear-gradient(135deg,var(--gold-soft),var(--blush-soft))', borderRadius: 'var(--r-xl)', padding: '32px 36px', textAlign: 'center', marginBottom: 40, borderLeft: '4px solid var(--gold)' }}>
            <p style={{ fontFamily: 'var(--serif)', fontStyle: 'italic', fontSize: 'clamp(17px,2.5vw,23px)', color: 'var(--ink)', lineHeight: 1.45 }}>"With us, your ideas don't just come to life — they bloom into something unforgettable."</p>
            <p style={{ fontSize: 12, letterSpacing: '.14em', textTransform: 'uppercase', color: 'var(--ink-faint)', marginTop: 12 }}>— Belle &amp; Bloom Designs</p>
          </div>

          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', justifyContent: 'center' }}>
            <button className="btn btn-outline" onClick={() => nav('brief')}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>
              Edit my brief
            </button>
            <button className="btn btn-gold btn-lg" onClick={() => nav('shop')}>
              Continue shopping <I.arrow width={15} height={15} />
            </button>
          </div>

        </div>
      </section>

      <style>{`
        @keyframes ocPop  { from{opacity:0;transform:scale(.6)} to{opacity:1;transform:scale(1)} }
        @keyframes ocRise { from{opacity:0;transform:translateY(22px)} to{opacity:1;transform:none} }
        @keyframes ocPulse{ 0%,100%{opacity:1}50%{opacity:.4} }
        @keyframes ocProg { 0%{width:0}60%{width:68%}80%{width:82%}100%{width:90%} }
      `}</style>
    </>
  );
}

/* ─────────────────────────────────────────────────────────
   3. INVOICE PAGE
───────────────────────────────────────────────────────── */
function InvoicePage({ params }) {
  const { nav } = useStore();
  const [view, setView] = React.useState('custom');
  const [selectedPkg, setSelectedPkg] = React.useState(null);
  const [paid, setPaid] = React.useState(false);
  const [expSecs, setExpSecs] = React.useReducer(s => Math.max(0, s - 1), 48 * 3600 - 108);

  React.useEffect(() => {
    const t = setInterval(() => setExpSecs(), 1000);
    return () => clearInterval(t);
  }, []);

  function fmtExp(s) { const h = Math.floor(s/3600), m = Math.floor((s%3600)/60), sc = s%60; return `${h}:${String(m).padStart(2,'0')}:${String(sc).padStart(2,'0')}`; }

  const lineItems = [
    { name: 'Custom Favour Boxes — Bluey Theme', desc: 'Handcrafted gable boxes with custom labels, tissue paper, and ribbon. Each personalised.', qty: '60 units', price: '₦180,000' },
    { name: 'Custom Chivita Juice Box Labels', desc: 'Mini Chivita juice boxes with custom Bluey-themed labels. Minimum order 12 units.', qty: '60 units (5 × dozen)', price: '₦72,000' },
    { name: 'Balloon Garland — Pastel Blue & Cream', desc: '3-metre organic balloon garland with pastel blues, teals, creams, and character cutout.', qty: '1 garland', price: '₦65,000' },
    { name: 'Design & Customisation', desc: 'Bespoke artwork creation, digital proofing, and 2 rounds of revisions.', qty: 'Flat fee', price: '₦25,000' },
    { name: 'Lagos Delivery', desc: 'Tracked courier within Lagos. 2–3 business days after production.', qty: '—', price: '₦8,500' },
  ];

  const packages = [
    { name: 'Starter Bloom', sub: 'Intimate celebrations · up to 20 guests', price: '₦85,000', usd: '≈ $54', featured: false, features: ['20 custom favour boxes (any theme)', '1 × custom banner (60×30cm)', 'Digital proof · 1 revision', 'Lagos delivery included', 'No balloon garland'] },
    { name: 'Signature Bloom', sub: 'Our most-loved bundle · 20–60 guests', price: '₦220,000', usd: '≈ $138', featured: true, features: ['60 custom favour boxes', '60 custom juice box labels', '1 × balloon garland (2 metres)', 'Custom banner + 4 table cards', '2 revisions · WhatsApp proofing', 'Lagos delivery included'] },
    { name: 'Luxury Bloom', sub: 'Full-service bespoke · 60–150 guests', price: '₦480,000', usd: '≈ $300', featured: false, features: ['120 premium custom favour boxes', 'Juice labels, cookies & cupcake toppers', '3-metre balloon garland + arch', 'Full décor suite: backdrop, props, runner', 'Unlimited revisions · 1-to-1 consultation', 'International shipping included'] },
  ];

  if (paid) return (
    <section style={{ minHeight: '80vh', display: 'grid', placeItems: 'center', background: 'var(--cream)', padding: 'clamp(48px,8vw,96px) var(--gutter)', textAlign: 'center' }}>
      <div style={{ maxWidth: 480 }}>
        <div style={{ width: 80, height: 80, borderRadius: '100%', background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', display: 'grid', placeItems: 'center', color: '#fff', margin: '0 auto 24px', boxShadow: '0 12px 36px rgba(138,24,192,.30)', animation: 'ocPop .7s cubic-bezier(.2,.8,.2,1) both' }}>
          <svg width="34" height="34" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="m5 13 4 4 10-11" strokeLinecap="round"/></svg>
        </div>
        <p className="eyebrow" style={{ marginBottom: 12 }}>Payment received</p>
        <h1 style={{ fontSize: 'clamp(32px,5vw,52px)', marginBottom: 14 }}>You're all set! 🌸</h1>
        <p style={{ fontSize: 16, color: 'var(--ink-soft)', lineHeight: 1.7, marginBottom: 32 }}>Your deposit has been received and production is now confirmed. Expect a WhatsApp message from our team within 24 hours with your production timeline.</p>
        <button className="btn btn-gold btn-lg" onClick={() => nav('home')}>Back to store <I.arrow width={15} height={15} /></button>
      </div>
      <style>{`@keyframes ocPop{from{opacity:0;transform:scale(.6)}to{opacity:1;transform:scale(1)}}`}</style>
    </section>
  );

  const paymentSidebar = (amount, deposit, subLabel) => (
    <div style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', padding: 'clamp(20px,3vw,36px)', position: 'sticky', top: 90 }}>
      <h3 style={{ fontFamily: 'var(--serif)', fontSize: 26, marginBottom: 6 }}>Pay your deposit</h3>
      <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 20 }}>50% to confirm production</p>
      {/* Expiry */}
      <div style={{ background: 'var(--blush-soft)', border: '1px solid var(--blush)', borderRadius: 'var(--r-md)', padding: '12px 16px', display: 'flex', gap: 10, alignItems: 'flex-start', marginBottom: 18 }}>
        <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="var(--blush-deep)" strokeWidth="2" style={{ flexShrink: 0, marginTop: 1 }}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 3"/></svg>
        <p style={{ fontSize: 12.5, color: 'var(--blush-deep)', lineHeight: 1.55 }}>Invoice expires in <strong>{fmtExp(expSecs)}</strong>. Pay now to lock in your slot.</p>
      </div>
      {/* Amount */}
      <div style={{ background: 'linear-gradient(135deg,var(--cream-deep),var(--gold-soft))', borderRadius: 'var(--r-md)', padding: '22px 20px', textAlign: 'center', marginBottom: 20 }}>
        <div style={{ fontSize: 11, letterSpacing: '.16em', textTransform: 'uppercase', color: 'var(--gold-deep)', marginBottom: 6 }}>{subLabel || 'Deposit due today'}</div>
        <div style={{ fontFamily: 'var(--serif)', fontSize: 40, color: 'var(--ink)', lineHeight: 1 }}>{deposit}</div>
        <div style={{ fontSize: 13, color: 'var(--ink-soft)', marginTop: 6 }}>Full total: {amount}</div>
      </div>
      {/* Pay btn */}
      <button onClick={() => setPaid(true)} style={{ width: '100%', padding: '19px', borderRadius: 100, background: 'linear-gradient(120deg,var(--gold-deep),var(--gold),var(--blush))', color: '#fff', fontFamily: 'var(--sans)', fontSize: 14, fontWeight: 500, letterSpacing: '.14em', textTransform: 'uppercase', border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, boxShadow: '0 8px 28px rgba(138,24,192,.30)', marginBottom: 14, transition: 'transform .3s, box-shadow .3s' }} onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 18px 48px rgba(138,24,192,.42)'; }} onMouseLeave={e => { e.currentTarget.style.transform = ''; e.currentTarget.style.boxShadow = '0 8px 28px rgba(138,24,192,.30)'; }}>
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="1" y="4" width="22" height="16" rx="2"/><path d="M1 10h22"/></svg>
        Pay Now — {deposit}
      </button>
      {/* Trust */}
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {[['256-bit SSL encrypted', <svg key="s" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6l8-3Z"/></svg>], ['Production begins within 24 hrs', <svg key="p" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="12" cy="12" r="9"/><path d="m9 12 2 2 4-4"/></svg>], ['WhatsApp progress updates', <svg key="w" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 12"/></svg>]].map(([t, ic]) => (
          <div key={t} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12, color: 'var(--ink-faint)' }}>{ic}{t}</div>
        ))}
      </div>
    </div>
  );

  return (
    <>
      <section style={{ background: 'var(--cream)', padding: 'clamp(40px,6vw,72px) var(--gutter)' }}>
        <div style={{ maxWidth: 1280, margin: '0 auto' }}>
          {/* Page heading */}
          <div style={{ marginBottom: 32 }}>
            <p className="eyebrow" style={{ marginBottom: 10 }}>Invoice · BB-2026-0042</p>
            <h1 style={{ fontFamily: 'var(--serif)', fontSize: 'clamp(30px,4.5vw,52px)', marginBottom: 8 }}>Your custom <em style={{ fontStyle: 'italic' }}>proposal</em></h1>
            <p style={{ fontSize: 15, color: 'var(--ink-soft)' }}>Review your bespoke order details and pay when you're ready. Expires in <strong>{fmtExp(expSecs)}</strong>.</p>
          </div>

          {/* View toggle */}
          <div style={{ display: 'flex', background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 100, padding: 4, gap: 4, width: 'fit-content', marginBottom: 44 }}>
            {[['custom','Custom Order'],['packages','Fixed Packages']].map(([v,l]) => (
              <button key={v} onClick={() => setView(v)} style={{ padding: '10px 24px', borderRadius: 100, fontSize: 12, letterSpacing: '.1em', textTransform: 'uppercase', fontWeight: 500, cursor: 'pointer', border: 'none', background: view===v ? 'var(--ink)' : 'transparent', color: view===v ? 'var(--cream)' : 'var(--ink-soft)', boxShadow: view===v ? '0 4px 12px rgba(42,17,51,.18)' : 'none', transition: 'all .3s' }}>{l}</button>
            ))}
          </div>

          {/* CUSTOM ORDER VIEW */}
          {view === 'custom' && (
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 400px', gap: 'clamp(28px,4vw,60px)', alignItems: 'start' }}>
              <div>
                <div style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', overflow: 'hidden' }}>
                  {/* Invoice header */}
                  <div style={{ background: 'linear-gradient(135deg,var(--ink),#4A1E5E)', padding: 'clamp(24px,4vw,40px)' }}>
                    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', flexWrap: 'wrap', gap: 20, marginBottom: 28 }}>
                      <div style={{ fontFamily: 'var(--serif)', fontSize: 24, color: '#fff' }}>Belle &amp; <em style={{ fontStyle: 'italic', background: 'linear-gradient(100deg,rgba(192,96,240,1),rgba(240,32,127,1))', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', backgroundClip: 'text' }}>Bloom</em></div>
                      <div style={{ textAlign: 'right' }}>
                        <div style={{ fontFamily: 'var(--serif)', fontSize: 20, color: '#fff', marginBottom: 4 }}>INV-2026-0042</div>
                        <div style={{ fontSize: 13, color: 'rgba(255,255,255,.55)' }}>Issued: 20 June 2026</div>
                        <div style={{ fontSize: 13, color: 'rgba(255,255,255,.55)' }}>Due: 4 July 2026</div>
                      </div>
                    </div>
                    <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
                      {[['Billed to', 'Adaeze Okafor', 'adaeze@example.com', '+234 802 000 1234'], ['From', 'Belle & Bloom Designs', 'Lagos, Nigeria', 'belleandbloomdesigns.com']].map(([lbl, name, d1, d2]) => (
                        <div key={lbl}>
                          <div style={{ fontSize: 10, letterSpacing: '.2em', textTransform: 'uppercase', color: 'rgba(255,255,255,.4)', marginBottom: 6 }}>{lbl}</div>
                          <div style={{ fontFamily: 'var(--serif)', fontSize: 18, color: '#fff', marginBottom: 2 }}>{name}</div>
                          <div style={{ fontSize: 13, color: 'rgba(255,255,255,.6)' }}>{d1}</div>
                          <div style={{ fontSize: 13, color: 'rgba(255,255,255,.6)' }}>{d2}</div>
                        </div>
                      ))}
                    </div>
                  </div>
                  {/* Specs */}
                  <div style={{ padding: 'clamp(20px,3vw,36px)', borderBottom: '1px solid var(--line)' }}>
                    <div style={{ fontSize: 10, letterSpacing: '.2em', textTransform: 'uppercase', color: 'var(--ink-faint)', marginBottom: 16, fontWeight: 500 }}>Project specifications</div>
                    <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14, marginBottom: 16 }}>
                      {[['Event type','Birthday party (child)'],['Event date','12 July 2026'],['Guest count','50–100 guests'],['Processing time','5–14 days']].map(([l,v]) => (
                        <div key={l}><div style={{ fontSize: 11, color: 'var(--ink-faint)', letterSpacing: '.08em', marginBottom: 3 }}>{l}</div><div style={{ fontSize: 14, fontWeight: 500 }}>{v}</div></div>
                      ))}
                    </div>
                    <div style={{ background: 'var(--cream-deep)', borderRadius: 'var(--r-md)', padding: '14px 18px' }}>
                      <div style={{ fontSize: 11, color: 'var(--ink-faint)', letterSpacing: '.08em', marginBottom: 5 }}>Theme brief</div>
                      <p style={{ fontSize: 14, color: 'var(--ink-soft)', lineHeight: 1.65 }}>Bluey-themed party for Teni's 3rd birthday — pastel blues, teals, and creams. Custom favour boxes, balloon garland, and personalised juice box labels for 60 guests.</p>
                    </div>
                  </div>
                  {/* Line items */}
                  <div style={{ padding: 'clamp(20px,3vw,36px)', borderBottom: '1px solid var(--line)' }}>
                    <div style={{ fontSize: 10, letterSpacing: '.2em', textTransform: 'uppercase', color: 'var(--ink-faint)', marginBottom: 16, fontWeight: 500 }}>Order details</div>
                    {lineItems.map((item, i) => (
                      <div key={i} style={{ display: 'flex', justifyContent: 'space-between', gap: 16, padding: '14px 0', borderBottom: i < lineItems.length - 1 ? '1px solid var(--cream-deep)' : 'none' }}>
                        <div style={{ flex: 1 }}>
                          <div style={{ fontSize: 15, fontWeight: 500, marginBottom: 2 }}>{item.name}</div>
                          <div style={{ fontSize: 12.5, color: 'var(--ink-soft)', lineHeight: 1.5 }}>{item.desc}</div>
                          <div style={{ fontSize: 11, color: 'var(--ink-faint)', marginTop: 4 }}>Qty: {item.qty}</div>
                        </div>
                        <div style={{ fontFamily: 'var(--serif)', fontSize: 20, whiteSpace: 'nowrap', fontWeight: 500 }}>{item.price}</div>
                      </div>
                    ))}
                  </div>
                  {/* Totals */}
                  <div style={{ padding: 'clamp(20px,3vw,36px)' }}>
                    {[['Subtotal','₦350,500'],['Returning client discount (5%)','− ₦17,550']].map(([l,v]) => (
                      <div key={l} style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0', fontSize: 14 }}>
                        <span style={{ color: 'var(--ink-soft)' }}>{l}</span>
                        <span style={{ fontWeight: 500, color: l.includes('discount') ? 'var(--blush-deep)' : undefined }}>{v}</span>
                      </div>
                    ))}
                    <div style={{ display: 'flex', justifyContent: 'space-between', padding: '14px 0 8px', borderTop: '1px solid var(--line)', marginTop: 6 }}>
                      <span style={{ fontFamily: 'var(--serif)', fontSize: 18 }}>Total</span>
                      <span style={{ fontFamily: 'var(--serif)', fontSize: 26, background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', backgroundClip: 'text' }}>₦332,950</span>
                    </div>
                    <div style={{ display: 'flex', justifyContent: 'space-between', padding: '8px 0 0', fontSize: 14 }}>
                      <span style={{ color: 'var(--ink-faint)' }}>50% deposit due now</span>
                      <span style={{ fontWeight: 500, fontSize: 17 }}>₦166,475</span>
                    </div>
                    <p style={{ fontSize: 12, color: 'var(--ink-faint)', textAlign: 'right', marginTop: 4 }}>Remaining balance due before dispatch.</p>
                  </div>
                </div>
              </div>
              {paymentSidebar('₦332,950', '₦166,475', 'Deposit due today')}
            </div>
          )}

          {/* PACKAGES VIEW */}
          {view === 'packages' && (
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 400px', gap: 'clamp(28px,4vw,60px)', alignItems: 'start' }}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
                {packages.map(pkg => (
                  <div key={pkg.name} onClick={() => setSelectedPkg(pkg)} style={{ background: 'var(--ivory)', border: `2px solid ${selectedPkg?.name===pkg.name ? 'var(--gold)' : pkg.featured ? 'var(--gold)' : 'var(--line)'}`, borderRadius: 'var(--r-xl)', overflow: 'hidden', cursor: 'pointer', position: 'relative', transition: 'border-color .3s, transform .35s, box-shadow .35s', transform: selectedPkg?.name===pkg.name ? 'translateY(-4px)' : 'none', boxShadow: selectedPkg?.name===pkg.name ? '0 12px 40px rgba(138,24,192,.13)' : 'none' }}>
                    {pkg.featured && <div style={{ position: 'absolute', top: 20, right: 20, background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', color: '#fff', fontSize: 10, letterSpacing: '.14em', textTransform: 'uppercase', fontWeight: 600, padding: '5px 12px', borderRadius: 100 }}>Most popular</div>}
                    <div style={{ padding: '28px 28px 20px' }}>
                      <h3 style={{ fontFamily: 'var(--serif)', fontSize: 26, marginBottom: 6 }}>{pkg.name}</h3>
                      <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 14 }}>{pkg.sub}</p>
                      <div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
                        <span style={{ fontFamily: 'var(--serif)', fontSize: 36, fontWeight: 500, background: 'linear-gradient(135deg,var(--gold-deep),var(--gold))', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', backgroundClip: 'text' }}>{pkg.price}</span>
                        <span style={{ fontSize: 14, color: 'var(--ink-faint)' }}>{pkg.usd}</span>
                      </div>
                    </div>
                    <div style={{ padding: '0 28px 28px' }}>
                      <div style={{ height: 1, background: 'var(--line)', marginBottom: 20 }}></div>
                      <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
                        {pkg.features.map((f, i) => (
                          <div key={i} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', fontSize: 14, color: i < pkg.features.length - (pkg.name==='Starter Bloom' ? 2 : 0) ? 'var(--ink-soft)' : 'var(--ink-faint)' }}>
                            <div style={{ width: 18, height: 18, borderRadius: '100%', background: i < pkg.features.length - (pkg.name==='Starter Bloom' ? 2 : 0) ? 'var(--gold-soft)' : 'var(--line)', display: 'grid', placeItems: 'center', color: 'var(--gold-deep)', flexShrink: 0, marginTop: 1 }}>
                              {i < pkg.features.length - (pkg.name==='Starter Bloom' ? 2 : 0)
                                ? <svg width="9" height="9" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3"><path d="m5 13 4 4 10-11" strokeLinecap="round"/></svg>
                                : '–'}
                            </div>
                            {f}
                          </div>
                        ))}
                      </div>
                      <button onClick={e => { e.stopPropagation(); setSelectedPkg(pkg); }} style={{ width: '100%', padding: '14px', borderRadius: 'var(--r-md)', marginTop: 20, fontFamily: 'var(--sans)', fontSize: 12, letterSpacing: '.12em', textTransform: 'uppercase', fontWeight: 500, cursor: 'pointer', border: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, transition: 'all .3s', background: pkg.featured ? 'linear-gradient(120deg,var(--gold-deep),var(--gold),var(--blush))' : 'var(--cream-deep)', color: pkg.featured ? '#fff' : 'var(--ink)', boxShadow: pkg.featured ? '0 6px 22px rgba(138,24,192,.24)' : 'none' }}>
                        {selectedPkg?.name===pkg.name ? '✓ Selected' : 'Select this package'}
                        {pkg.featured && <I.arrow width={14} height={14} />}
                      </button>
                    </div>
                  </div>
                ))}
              </div>

              {/* Package payment sidebar */}
              <div style={{ background: 'var(--ivory)', border: '1px solid var(--line)', borderRadius: 'var(--r-xl)', padding: 'clamp(20px,3vw,36px)', position: 'sticky', top: 90 }}>
                {!selectedPkg ? (
                  <>
                    <h3 style={{ fontFamily: 'var(--serif)', fontSize: 24, marginBottom: 6 }}>No package selected</h3>
                    <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 28 }}>Choose a package on the left to see pricing and pay.</p>
                    <div style={{ height: 120, display: 'grid', placeItems: 'center', color: 'var(--ink-faint)' }}>
                      <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1"><circle cx="12" cy="12" r="9"/><path d="m9 12 2 2 4-4"/></svg>
                    </div>
                    <p style={{ fontSize: 13, color: 'var(--ink-faint)', textAlign: 'center', marginTop: 14 }}>All packages are fully customisable to your theme.</p>
                  </>
                ) : (
                  <>
                    <h3 style={{ fontFamily: 'var(--serif)', fontSize: 24, marginBottom: 6 }}>{selectedPkg.name}</h3>
                    <p style={{ fontSize: 14, color: 'var(--ink-soft)', marginBottom: 20 }}>Selected package</p>
                    <div style={{ background: 'linear-gradient(135deg,var(--cream-deep),var(--gold-soft))', borderRadius: 'var(--r-md)', padding: '22px 20px', textAlign: 'center', marginBottom: 20 }}>
                      <div style={{ fontSize: 11, letterSpacing: '.16em', textTransform: 'uppercase', color: 'var(--gold-deep)', marginBottom: 6 }}>Package total</div>
                      <div style={{ fontFamily: 'var(--serif)', fontSize: 40, lineHeight: 1 }}>{selectedPkg.price}</div>
                      <div style={{ fontSize: 13, color: 'var(--ink-soft)', marginTop: 6 }}>50% deposit confirms your slot</div>
                    </div>
                    <button onClick={() => setPaid(true)} style={{ width: '100%', padding: '19px', borderRadius: 100, background: 'linear-gradient(120deg,var(--gold-deep),var(--gold),var(--blush))', color: '#fff', fontFamily: 'var(--sans)', fontSize: 14, fontWeight: 500, letterSpacing: '.14em', textTransform: 'uppercase', border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, boxShadow: '0 8px 28px rgba(138,24,192,.30)', marginBottom: 16 }}>
                      Pay 50% Deposit <I.arrow width={14} height={14} />
                    </button>
                    <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
                      <div style={{ display: 'flex', gap: 8, fontSize: 12, color: 'var(--ink-faint)', alignItems: 'center' }}><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6l8-3Z"/></svg>All packages include digital proofing</div>
                      <div style={{ display: 'flex', gap: 8, fontSize: 12, color: 'var(--ink-faint)', alignItems: 'center' }}><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5"><circle cx="12" cy="12" r="9"/><path d="m9 12 2 2 4-4"/></svg>Fully customisable to your theme</div>
                    </div>
                  </>
                )}
              </div>
            </div>
          )}

        </div>
      </section>
    </>
  );
}

Object.assign(window, { BriefPage, OrderConfirmedPage, InvoicePage });
