// ════════════ WEBSITE cluster (deep) ════════════
const { Icon, Spark, Pex, Avatar, Card, Btn, Pill, Label, Num, Spark2, Toggle, Field, Select, TextArea, Tabs, money } = window;

window.SCREENS['website'] = function Website({ sub }) {
  const P = window.PX; const { go } = window.useApp();
  const [preview, setPreview] = React.useState(false);
  const seg = (sub || '').split('/');
  const active = seg[0] || 'overview';
  const nav = [
    { items: [
      { k: 'overview', icon: 'home', label: 'Overview' },
      { k: 'analytics', icon: 'barchart', label: 'Analytics' },
    ]},
    { label: 'Build', items: [
      { k: 'pages', icon: 'layout', label: 'Pages', badge: 7 },
      { k: 'editor', icon: 'penTool', label: 'Editor' },
      { k: 'blog', icon: 'fileText', label: 'Blog', badge: 7 },
      { k: 'store', icon: 'bag', label: 'Store', badge: 12 },
      { k: 'theme', icon: 'palette', label: 'Theme & brand' },
    ]},
    { label: 'Grow', items: [
      { k: 'seo', icon: 'search', label: 'SEO' },
      { k: 'forms', icon: 'inbox', label: 'Forms & leads', badge: 5, tone: 'spark' },
      { k: 'domains', icon: 'globe', label: 'Domains' },
    ]},
  ];
  const onNav = (k) => go('website' + (k === 'overview' ? '' : '/' + k));
  // The visual builder is a full-bleed workspace — it renders without the
  // module's secondary nav (it has its own back control + page selector).
  if (active === 'editor') return <window.WebBuilder/>;
  return (
    <>
    <window.SubLayout title="Website" nav={nav} active={active} onNav={onNav}
      foot={<div style={{ background: P.sageWash, border: `1px solid ${P.sageTint}`, borderRadius: 10, padding: 11 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}><span style={{ width: 8, height: 8, borderRadius: 8, background: P.sage }}/><span style={{ fontSize: 12, fontWeight: 600, color: P.ink }}>Published</span></div>
        <div style={{ fontSize: 11, color: P.ink3, marginTop: 4 }}>honestloaves.com · last edit 2h ago</div>
        <Btn kind="default" size="sm" full icon="ext" style={{ marginTop: 8 }} onClick={() => setPreview(true)}>Visit live site</Btn>
      </div>}>
      {active === 'overview' && <SiteOverview onPreview={() => setPreview(true)}/>}
      {active === 'analytics' && <SiteAnalytics/>}
      {active === 'pages' && <SitePages/>}
      {active === 'editor' && <window.WebBuilder/>}
      {active === 'blog' && <SiteBlog/>}
      {active === 'store' && <SiteStore/>}
      {active === 'theme' && <SiteTheme/>}
      {active === 'seo' && <SiteSEO/>}
      {active === 'forms' && <SiteForms/>}
      {active === 'domains' && <SiteDomains/>}
    </window.SubLayout>
    {preview && <SitePreviewModal onClose={() => setPreview(false)} onEdit={() => { setPreview(false); go('website/editor'); }}/>}
    </>
  );
};

function SiteOverview({ onPreview }) {
  const P = window.PX; const { go } = window.useApp();
  const attention = [
    ['About page has 2 stale facts', 'amber', 'website/editor'],
    ['Hero headline could convert +18%', 'sky', 'website/editor'],
    ['3 images missing alt text (SEO)', 'neutral', 'website/seo'],
  ];
  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>honestloaves.com</div><div style={{ fontSize: 12.5, color: P.ink3 }}>7 pages · 7 blog posts · 12 products · published 2h ago</div></div>
        <Btn kind="default" size="sm" icon="ext" onClick={onPreview}>Preview</Btn>
        <Btn kind="primary" size="sm" icon="pencil" onClick={() => go('website/editor')} style={{ marginLeft: 8 }}>Edit site</Btn>
      </div>

      {/* live preview + stats */}
      <div style={{ display: 'grid', gridTemplateColumns: '1.5fr 1fr', gap: 18 }}>
        <Card pad={0}>
          <div style={{ height: 28, background: P.sunk, display: 'flex', alignItems: 'center', gap: 6, padding: '0 12px', borderBottom: `1px solid ${P.line}` }}>
            <span style={{ width: 9, height: 9, borderRadius: 9, background: '#E88171' }}/><span style={{ width: 9, height: 9, borderRadius: 9, background: '#E8C27B' }}/><span style={{ width: 9, height: 9, borderRadius: 9, background: '#97B87A' }}/>
            <div style={{ flex: 1, textAlign: 'center', fontSize: 11, color: P.ink3 }}>honestloaves.com</div>
          </div>
          <div style={{ height: 300, overflow: 'hidden', background: '#F2E2C4' }}>
            <div style={{ padding: '14px 24px', display: 'flex', alignItems: 'center', borderBottom: '1px solid rgba(0,0,0,0.06)' }}>
              <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 18, color: '#3A2A1C', flex: 1 }}>Honest Loaves</div>
              <div style={{ fontSize: 10, color: '#3A2A1C' }}>Menu · Classes · Shop · Contact</div>
            </div>
            <div style={{ padding: '34px 24px', display: 'grid', gridTemplateColumns: '1.1fr 1fr', gap: 20, alignItems: 'center' }}>
              <div>
                <div style={{ fontSize: 9, color: '#8C4A2A', textTransform: 'uppercase', letterSpacing: 1.5, marginBottom: 8 }}>Brooklyn · since 2019</div>
                <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 36, color: '#3A2A1C', letterSpacing: -1, lineHeight: 1 }}>Stone-milled.<br/>Hand-shaped.</div>
                <div style={{ marginTop: 12, padding: '7px 13px', background: '#3A2A1C', color: '#F5D8A8', fontSize: 11, display: 'inline-block', borderRadius: 2 }}>Order for Saturday</div>
              </div>
              <div style={{ aspectRatio: '4/5', background: 'repeating-linear-gradient(45deg,#D9A84C 0 10px,#C99944 10px 20px)', borderRadius: 6 }}/>
            </div>
          </div>
        </Card>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
            {[['Visitors · 7d', '2,418', '+18%', 'sage'], ['Orders · 7d', '64', '+9%', 'sage'], ['Conversion', '2.6%', '+0.4pt', 'sage'], ['Avg order', '$34', '−$2', 'rose']].map((c, i) => (
              <Card key={i} pad={14}><Label>{c[0]}</Label><Num size={22} style={{ marginTop: 5 }}>{c[1]}</Num><div style={{ fontSize: 11, color: P[c[3]], marginTop: 3 }}>{c[2]}</div></Card>
            ))}
          </div>
          <Card pad={16}>
            <div style={{ fontSize: 13, fontWeight: 600, color: P.ink, marginBottom: 9 }}>Needs attention</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 7 }}>
              {attention.map((x, i) => (
                <div key={i} onClick={() => go(x[2])} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12.5, color: P.ink2, cursor: 'pointer', padding: '2px 4px', margin: '-2px -4px', borderRadius: 6 }}
                  onMouseEnter={e => e.currentTarget.style.background = P.hover} onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                  <span style={{ width: 6, height: 6, borderRadius: 6, background: x[1] === 'neutral' ? P.ink4 : P[x[1]] }}/>
                  <span style={{ flex: 1 }}>{x[0]}</span>
                  <Icon name="chevR" size={13} color={P.ink4}/>
                </div>
              ))}
            </div>
            <Btn kind="default" size="sm" full style={{ marginTop: 12 }} onClick={() => go('website/seo')}>Review all</Btn>
          </Card>
        </div>
      </div>
    </div>
  );
}

const ANALYTICS = {
  '24h': {
    kpis: [['Visitors', '312', [3,5,4,6,5,7,6], 'sage', '+6%'], ['Pageviews', '1,040', [4,5,6,5,7,6,8], 'sky', '+9%'], ['Avg. time', '1m 58s', [5,6,5,6,5,6,6], 'amber', '+3s'], ['Bounce', '41%', [6,5,6,5,5,4,5], 'sage', '−2pt']],
    lineSub: 'Hourly · last 24 hours',
    linePath: 'M0,150 L80,132 L160,140 L240,110 L320,120 L400,92 L480,70 L560,64',
    lineLabels: [['12a',0],['4a',80],['8a',160],['12p',240],['4p',320],['8p',400],['now',480]],
    sources: [['Instagram', 38, 'spark'], ['Google search', 30, 'sage'], ['Direct', 20, 'sky'], ['Referral', 8, 'amber'], ['Email', 4, 'plum']],
    topPages: [['/ (Home)', '540', '34%'], ['/shop', '210', '9%'], ['/classes', '160', '14%'], ['/about', '70', '48%'], ['/wholesale', '40', '20%']],
    devices: [['Mobile', 71, 'spark'], ['Desktop', 24, 'sky'], ['Tablet', 5, 'sage']],
    locations: [['Brooklyn, NY', 55], ['Manhattan, NY', 20], ['Queens, NY', 12], ['Other US', 13]],
  },
  '7d': {
    kpis: [['Visitors', '2,418', [4,5,4,6,7,6,8], 'sage', '+18%'], ['Pageviews', '8,210', [5,6,5,7,6,8,9], 'sky', '+12%'], ['Avg. time', '2m 14s', [6,5,6,5,7,6,7], 'amber', '+8s'], ['Bounce', '38%', [7,6,7,5,4,5,4], 'sage', '−4pt']],
    lineSub: 'Daily · last 7 days',
    linePath: 'M0,140 L80,120 L160,134 L240,96 L320,80 L400,104 L480,52 L560,40',
    lineLabels: [['Mon',0],['Tue',80],['Wed',160],['Thu',240],['Fri',320],['Sat',400],['Sun',480]],
    sources: [['Google search', 41, 'sage'], ['Instagram', 28, 'spark'], ['Direct', 22, 'sky'], ['Referral', 6, 'amber'], ['Email', 3, 'plum']],
    topPages: [['/ (Home)', '4,210', '38%'], ['/classes', '1,840', '12%'], ['/shop', '1,120', '8%'], ['/about', '640', '52%'], ['/wholesale', '380', '22%']],
    devices: [['Mobile', 64, 'spark'], ['Desktop', 31, 'sky'], ['Tablet', 5, 'sage']],
    locations: [['Brooklyn, NY', 52], ['Manhattan, NY', 21], ['Queens, NY', 11], ['Other US', 16]],
  },
  '30d': {
    kpis: [['Visitors', '9,860', [5,6,7,6,8,9,10], 'sage', '+22%'], ['Pageviews', '34,120', [6,7,8,7,9,10,11], 'sky', '+15%'], ['Avg. time', '2m 26s', [6,6,7,6,7,7,8], 'amber', '+11s'], ['Bounce', '36%', [7,6,6,5,5,4,4], 'sage', '−5pt']],
    lineSub: 'Weekly · last 30 days',
    linePath: 'M0,150 L140,118 L280,96 L420,66 L560,42',
    lineLabels: [['Wk1',0],['Wk2',130],['Wk3',270],['Wk4',420]],
    sources: [['Google search', 46, 'sage'], ['Instagram', 24, 'spark'], ['Direct', 18, 'sky'], ['Referral', 8, 'amber'], ['Email', 4, 'plum']],
    topPages: [['/ (Home)', '16,900', '36%'], ['/classes', '6,400', '13%'], ['/shop', '4,720', '9%'], ['/about', '2,410', '50%'], ['/wholesale', '1,560', '21%']],
    devices: [['Mobile', 62, 'spark'], ['Desktop', 33, 'sky'], ['Tablet', 5, 'sage']],
    locations: [['Brooklyn, NY', 49], ['Manhattan, NY', 22], ['Queens, NY', 13], ['Other US', 16]],
  },
  '12m': {
    kpis: [['Visitors', '112,400', [3,5,6,5,7,8,9], 'sage', '+64%'], ['Pageviews', '402,900', [4,6,7,6,8,9,11], 'sky', '+58%'], ['Avg. time', '2m 39s', [5,6,7,7,8,8,9], 'amber', '+22s'], ['Bounce', '34%', [8,7,6,6,5,4,4], 'sage', '−9pt']],
    lineSub: 'Monthly · last 12 months',
    linePath: 'M0,150 L51,140 L102,132 L153,120 L204,124 L255,104 L306,96 L357,80 L408,84 L459,60 L510,52 L560,38',
    lineLabels: [['J',0],['F',48],['M',96],['A',144],['M',192],['J',240],['J',288],['A',336],['S',384],['O',432],['N',480],['D',528]],
    sources: [['Google search', 48, 'sage'], ['Instagram', 22, 'spark'], ['Direct', 17, 'sky'], ['Referral', 9, 'amber'], ['Email', 4, 'plum']],
    topPages: [['/ (Home)', '198,000', '35%'], ['/classes', '72,400', '12%'], ['/shop', '58,900', '9%'], ['/about', '29,100', '49%'], ['/wholesale', '18,700', '20%']],
    devices: [['Mobile', 60, 'spark'], ['Desktop', 35, 'sky'], ['Tablet', 5, 'sage']],
    locations: [['Brooklyn, NY', 47], ['Manhattan, NY', 23], ['Queens, NY', 14], ['Other US', 16]],
  },
};

function SiteAnalytics() {
  const P = window.PX; const [range, setRange] = React.useState('7d');
  const d = ANALYTICS[range];
  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>Analytics</div><div style={{ fontSize: 12.5, color: P.ink3 }}>How people find and use your site</div></div>
        <div style={{ display: 'flex', gap: 4, background: P.sunk, padding: 3, borderRadius: 9 }}>
          {['24h', '7d', '30d', '12m'].map(r => <span key={r} onClick={() => setRange(r)} style={{ padding: '5px 12px', borderRadius: 7, fontSize: 12, fontWeight: 500, cursor: 'pointer', background: range === r ? P.card : 'transparent', color: range === r ? P.ink : P.ink3, boxShadow: range === r ? P.shSm : 'none' }}>{r}</span>)}
        </div>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 14, marginBottom: 18 }}>
        {d.kpis.map((c, i) => (
          <Card key={i} pad={16}>
            <Label>{c[0]}</Label>
            <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', marginTop: 6 }}>
              <Num size={24}>{c[1]}</Num><Spark2 data={c[2]} color={P[c[3]]} w={48} h={22} fill/>
            </div>
            <div style={{ fontSize: 11, color: P[c[3]], marginTop: 5 }}>{c[4]} vs prev</div>
          </Card>
        ))}
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1.6fr 1fr', gap: 18, marginBottom: 18 }}>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 4 }}>Visitors over time</div>
          <div style={{ fontSize: 12, color: P.ink3, marginBottom: 14 }}>{d.lineSub}</div>
          <svg width="100%" height="180" viewBox="0 0 560 180" preserveAspectRatio="none">
            {[0,1,2,3].map(i => <line key={i} x1="0" x2="560" y1={i*48+10} y2={i*48+10} stroke={P.line}/>)}
            <path d={d.linePath} fill="none" stroke={P.spark} strokeWidth="2.5"/>
            <path d={d.linePath + ' L560,180 L0,180 Z'} fill={P.spark} opacity="0.1"/>
            {d.lineLabels.map((l, i) => <text key={i} x={l[1]+6} y={175} fontSize="10" fill={P.ink3} fontFamily={P.sans}>{l[0]}</text>)}
          </svg>
        </Card>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 14 }}>Where visitors come from</div>
          {d.sources.map((s, i) => (
            <div key={i} style={{ marginBottom: 11 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12.5, color: P.ink2, marginBottom: 4 }}><span>{s[0]}</span><span>{s[1]}%</span></div>
              <div style={{ height: 6, background: P.sunk, borderRadius: 6, overflow: 'hidden' }}><div style={{ width: s[1] + '%', height: '100%', background: P[s[2]] }}/></div>
            </div>
          ))}
        </Card>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 18 }}>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 14 }}>Top pages</div>
          {d.topPages.map((r, i) => (
            <div key={i} style={{ display: 'grid', gridTemplateColumns: '1fr 80px 70px', gap: 10, padding: '9px 0', borderBottom: i < 4 ? `1px solid ${P.line}` : 'none', fontSize: 12.5, alignItems: 'center' }}>
              <span style={{ color: P.ink, fontFamily: P.mono, fontSize: 12 }}>{r[0]}</span>
              <span style={{ color: P.ink2, textAlign: 'right' }}>{r[1]} views</span>
              <span style={{ color: P.ink3, textAlign: 'right' }}>{r[2]} bounce</span>
            </div>
          ))}
        </Card>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 14 }}>Devices & top locations</div>
          <div style={{ display: 'flex', gap: 16, marginBottom: 16 }}>
            {d.devices.map((dv, i) => (
              <div key={i} style={{ flex: 1, textAlign: 'center' }}><Num size={22} color={P[dv[2]]}>{dv[1]}%</Num><div style={{ fontSize: 11, color: P.ink3 }}>{dv[0]}</div></div>
            ))}
          </div>
          {d.locations.map((l, i) => (
            <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '6px 0', fontSize: 12.5 }}><span style={{ flex: 1, color: P.ink }}>{l[0]}</span><span style={{ color: P.ink3 }}>{l[1]}%</span></div>
          ))}
        </Card>
      </div>
    </div>
  );
}

function SitePages() {
  const P = window.PX; const { go, toast } = window.useApp();
  const [pages, setPages] = React.useState([
    { id: window.pxid('pg'), name: 'Home', url: '/', status: 'Published', edited: '2h ago', views: 4210 },
    { id: window.pxid('pg'), name: 'Classes', url: '/classes', status: 'Published', edited: '3d ago', views: 1840 },
    { id: window.pxid('pg'), name: 'Shop', url: '/shop', status: 'Published', edited: '1w ago', views: 1120 },
    { id: window.pxid('pg'), name: 'About', url: '/about', status: 'Needs review', edited: '11mo ago', views: 640 },
    { id: window.pxid('pg'), name: 'Wholesale', url: '/wholesale', status: 'Published', edited: '2mo ago', views: 380 },
    { id: window.pxid('pg'), name: 'Contact', url: '/contact', status: 'Published', edited: '2mo ago', views: 290 },
    { id: window.pxid('pg'), name: 'FAQ', url: '/faq', status: 'Draft', edited: '—', views: 0 },
  ]);
  const [menuFor, setMenuFor] = React.useState(null);
  const [editing, setEditing] = React.useState(null); // null | 'new' | page object

  const published = pages.filter(p => p.status === 'Published').length;

  const savePage = (data) => {
    if (data.id) {
      setPages(ps => ps.map(p => p.id === data.id ? { ...p, name: data.name, url: data.url, status: data.status, edited: 'Just now' } : p));
      toast('Page updated.', { tone: 'sage', icon: 'check' });
    } else {
      setPages(ps => [...ps, { id: window.pxid('pg'), name: data.name, url: data.url, status: data.status, edited: 'Just now', views: 0 }]);
      toast(`"${data.name}" page created.`, { tone: 'sage', icon: 'check' });
    }
    setEditing(null);
  };
  const dup = (p) => {
    setPages(ps => { const i = ps.findIndex(x => x.id === p.id); const copy = { ...p, id: window.pxid('pg'), name: p.name + ' copy', url: p.url === '/' ? '/home-copy' : p.url + '-copy', status: 'Draft', edited: 'Just now', views: 0 }; return [...ps.slice(0, i + 1), copy, ...ps.slice(i + 1)]; });
    toast(`Duplicated "${p.name}".`, { tone: 'sage', icon: 'copy' }); setMenuFor(null);
  };
  const del = (p) => { setPages(ps => ps.filter(x => x.id !== p.id)); toast(`Deleted "${p.name}".`, { tone: 'neutral', icon: 'trash' }); setMenuFor(null); };

  const menuItems = (p) => [
    ['pencil', 'Rename / edit', () => { setEditing(p); setMenuFor(null); }],
    ['copy', 'Duplicate', () => dup(p)],
    ['trash', 'Delete', () => del(p)],
  ];

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>Pages</div><div style={{ fontSize: 12.5, color: P.ink3 }}>{pages.length} pages · {published} published</div></div>
        <Btn kind="primary" size="sm" icon="plus" onClick={() => setEditing('new')}>New page</Btn>
      </div>
      {menuFor && <div onClick={() => setMenuFor(null)} style={{ position: 'fixed', inset: 0, zIndex: 40 }}/>}
      <Card>
        <div style={{ display: 'grid', gridTemplateColumns: '2fr 1.5fr 1fr 90px 90px 30px', gap: 12, padding: '12px 18px', borderBottom: `1px solid ${P.line}` }}>
          {['Page', 'URL', 'Status', 'Edited', 'Views 7d', ''].map((h, i) => <Label key={i}>{h}</Label>)}
        </div>
        {pages.map((p, i) => (
          <div key={p.id} onClick={() => go('website/editor')} style={{ position: 'relative', zIndex: menuFor === p.id ? 42 : 'auto', display: 'grid', gridTemplateColumns: '2fr 1.5fr 1fr 90px 90px 30px', gap: 12, padding: '12px 18px', borderBottom: i < pages.length - 1 ? `1px solid ${P.line}` : 'none', alignItems: 'center', cursor: 'pointer' }}
            onMouseEnter={e => e.currentTarget.style.background = P.hover} onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
            <span style={{ fontSize: 13.5, color: P.ink, fontWeight: 500 }}>{p.name}</span>
            <span style={{ fontFamily: P.mono, fontSize: 12, color: P.ink3 }}>{p.url}</span>
            <Pill tone={p.status === 'Published' ? 'sage' : p.status === 'Draft' ? 'neutral' : 'amber'}>{p.status}</Pill>
            <span style={{ fontSize: 12, color: P.ink3 }}>{p.edited}</span>
            <span style={{ fontSize: 12.5, color: P.ink2, fontFamily: P.mono }}>{p.views || '—'}</span>
            <span onClick={(e) => { e.stopPropagation(); setMenuFor(menuFor === p.id ? null : p.id); }} style={{ cursor: 'pointer', display: 'inline-flex', padding: 3, borderRadius: 6, color: menuFor === p.id ? P.ink : P.ink4 }}><Icon name="dotsV" size={16}/></span>
            {menuFor === p.id && (
              <div onClick={e => e.stopPropagation()} style={{ position: 'absolute', top: 40, right: 12, zIndex: 41, background: P.card, border: `1px solid ${P.line}`, borderRadius: 10, boxShadow: P.shPop, padding: 5, width: 168 }}>
                {menuItems(p).map((m, mi) => (
                  <div key={mi} onClick={m[2]} style={{ display: 'flex', alignItems: 'center', gap: 9, padding: '8px 10px', borderRadius: 7, cursor: 'pointer', fontSize: 12.5, color: m[0] === 'trash' ? P.rose : P.ink2 }}
                    onMouseEnter={e => e.currentTarget.style.background = P.hover} onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                    <Icon name={m[0]} size={14}/>{m[1]}
                  </div>
                ))}
              </div>
            )}
          </div>
        ))}
      </Card>
      <div style={{ fontSize: 11, color: P.ink4, marginTop: 10 }}>Opening a page row loads it in the visual editor. (Prototype: the editor always loads the Home model regardless of row.)</div>
      {editing && <PageEditor page={editing === 'new' ? null : editing} onClose={() => setEditing(null)} onSave={savePage}/>}
    </div>
  );
}

function PageEditor({ page, onClose, onSave }) {
  const P = window.PX; const { toast } = window.useApp();
  const isNew = !page;
  const [name, setName] = React.useState(page ? page.name : '');
  const [url, setUrl] = React.useState(page ? page.url : '');
  const [status, setStatus] = React.useState(page ? page.status : 'Draft');
  const slugify = (s) => '/' + s.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
  const submit = () => {
    if (!name.trim()) { toast('Give the page a name.', { tone: 'rose', icon: 'alert' }); return; }
    onSave({ id: page ? page.id : undefined, name: name.trim(), url: (url.trim() || slugify(name)), status });
  };
  return (
    <window.Modal title={isNew ? 'New page' : 'Edit page'} w={480} onClose={onClose}
      foot={<><Btn kind="ghost" size="md" onClick={onClose}>Cancel</Btn><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon={isNew ? 'plus' : 'check'} onClick={submit}>{isNew ? 'Create page' : 'Save'}</Btn></>}>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
        <Field label="Page name" placeholder="Wholesale" value={name} onChange={(v) => { setName(v); if (isNew && (!url || url === slugify(name))) setUrl(slugify(v)); }}/>
        <Field label="URL path" placeholder="/wholesale" icon="link" mono value={url} onChange={setUrl}/>
        <Select label="Status" value={status} onChange={setStatus} options={['Draft', 'Published', 'Needs review']}/>
      </div>
    </window.Modal>
  );
}

function SiteBlog() {
  const P = window.PX; const { toast } = window.useApp();
  const [posts, setPosts] = React.useState([
    { id: 1, title: 'The case for stubborn bread', status: 'Published', date: 'Feb 28', reads: 840, tags: ['bread', 'philosophy'], body: "Some breads take three days. Ours does. Here's why patience beats speed at the counter.", image: '#D9A84C' },
    { id: 2, title: 'Why we mill our own flour', status: 'Published', date: 'Feb 12', reads: 1240, tags: ['flour', 'process'], body: 'Freshly milled flour tastes different — and it changes how the dough behaves, too.', image: '#8C4A2A' },
    { id: 3, title: 'A class for nervous bakers', status: 'Published', date: 'Jan 30', reads: 620, tags: ['classes'], body: 'Our beginner class exists for one reason: sourdough scares people more than it should.', image: '#3A2A1C' },
    { id: 4, title: 'Behind the Saturday line', status: 'Draft', date: '—', reads: 0, tags: [], body: '', image: '#C99944' },
  ]);
  const [editing, setEditing] = React.useState(null); // null | 'new' | post object

  const published = posts.filter(p => p.status === 'Published').length;
  const totalReads = posts.reduce((s, p) => s + p.reads, 0);

  const savePost = (data, publish) => {
    const status = publish ? 'Published' : 'Draft';
    if (data.id) {
      setPosts(ps => ps.map(p => p.id === data.id ? { ...p, ...data, status, date: publish && p.status !== 'Published' ? 'Just now' : p.date } : p));
    } else {
      const palette = ['#D9A84C', '#8C4A2A', '#3A2A1C', '#C99944', '#E0C080'];
      setPosts(ps => [{ ...data, id: Date.now(), status, date: publish ? 'Just now' : '—', reads: 0, image: data.image || palette[ps.length % palette.length] }, ...ps]);
    }
    toast(publish ? 'Post published to honestloaves.com.' : 'Draft saved.', { tone: publish ? 'sage' : 'neutral', icon: publish ? 'check' : 'fileText' });
    setEditing(null);
  };

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>Blog</div><div style={{ fontSize: 12.5, color: P.ink3 }}>{posts.length} posts · {published} published · {totalReads.toLocaleString()} reads this month</div></div>
        <Btn kind="primary" size="sm" icon="plus" onClick={() => setEditing('new')}>Write</Btn>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2,1fr)', gap: 14 }}>
        {posts.map((p) => (
          <Card key={p.id} pad={0} hover onClick={() => setEditing(p)}>
            <div style={{ height: 120, background: p.image }}/>
            <div style={{ padding: 16 }}>
              <div style={{ display: 'flex', gap: 8, marginBottom: 8 }}><Pill tone={p.status === 'Published' ? 'sage' : 'neutral'}>{p.status}</Pill><span style={{ fontSize: 11, color: P.ink3, alignSelf: 'center' }}>{p.date}</span></div>
              <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 19, color: P.ink, lineHeight: 1.2 }}>{p.title}</div>
              {p.reads > 0 && <div style={{ fontSize: 11.5, color: P.ink3, marginTop: 8 }}>{p.reads} reads · 4 min</div>}
            </div>
          </Card>
        ))}
      </div>
      {editing && <BlogComposer post={editing === 'new' ? null : editing} onClose={() => setEditing(null)} onSave={savePost}/>}
    </div>
  );
}

function BlogComposer({ post, onClose, onSave }) {
  const P = window.PX;
  const isNew = !post;
  const [title, setTitle] = React.useState(post ? post.title : '');
  const [body, setBody] = React.useState(post ? post.body : '');
  const [tagsStr, setTagsStr] = React.useState(post ? post.tags.join(', ') : '');
  const [publish, setPublish] = React.useState(post ? post.status === 'Published' : false);
  const [cover, setCover] = React.useState(post ? post.image : null);
  const tags = tagsStr.split(',').map(t => t.trim()).filter(Boolean);
  const inputStyle = { width: '100%', boxSizing: 'border-box', border: `1px solid ${P.lineStrong}`, borderRadius: P.rCtl, padding: '9px 11px', fontSize: 13.5, color: P.ink, fontFamily: P.sans, background: P.card, outline: 'none' };
  const COVER_COLORS = ['#D9A84C', '#8C4A2A', '#3A2A1C', '#C99944', '#E0C080', '#E8B860'];
  const uploadCover = () => setCover(COVER_COLORS[Math.floor(Math.random() * COVER_COLORS.length)]);

  const submit = () => onSave({ id: post ? post.id : undefined, title: title.trim() || 'Untitled post', body, tags, image: cover || undefined }, publish);

  return (
    <window.Drawer onClose={onClose} w={560}
      tag={<Pill tone={publish ? 'sage' : 'neutral'} dot>{publish ? 'Will publish' : 'Draft'}</Pill>}
      title={isNew ? 'New post' : 'Edit post'} sub={isNew ? 'Write something worth reading.' : `Editing "${post.title}"`}
      foot={<><Btn kind="ghost" size="md" onClick={onClose}>Cancel</Btn><div style={{ flex: 1 }}/><Btn kind={publish ? 'primary' : 'default'} size="md" icon={publish ? 'check' : 'fileText'} onClick={submit}>{publish ? 'Publish' : 'Save draft'}</Btn></>}>
      <div style={{ marginBottom: 14 }}>
        <div style={{ fontSize: 12, color: P.ink3, marginBottom: 5, fontWeight: 500 }}>Title</div>
        <input value={title} onChange={e => setTitle(e.target.value)} placeholder="Why we mill our own flour" style={{ ...inputStyle, fontSize: 16, fontFamily: P.serif, fontStyle: 'italic' }}/>
      </div>

      <div style={{ marginBottom: 14 }}>
        <Label style={{ marginBottom: 6 }}>Featured image</Label>
        {cover ? (
          <div style={{ height: 120, borderRadius: 10, background: cover, position: 'relative', display: 'flex', alignItems: 'flex-end', padding: 10, gap: 8 }}>
            <Btn kind="default" size="sm" icon="refresh" onClick={uploadCover}>Replace</Btn>
            <Btn kind="default" size="sm" icon="trash" onClick={() => setCover(null)}>Remove</Btn>
          </div>
        ) : (
          <div onClick={uploadCover} style={{ height: 120, borderRadius: 10, border: `1px dashed ${P.lineStrong}`, background: P.sunk, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 6, color: P.ink3, cursor: 'pointer' }}>
            <Icon name="image" size={22}/>
            <span style={{ fontSize: 12 }}>Click to upload a cover image</span>
          </div>
        )}
      </div>

      <div style={{ marginBottom: 14 }}>
        <div style={{ fontSize: 12, color: P.ink3, marginBottom: 5, fontWeight: 500 }}>Body</div>
        <textarea value={body} onChange={e => setBody(e.target.value)} placeholder="Start writing…" style={{ ...inputStyle, minHeight: 220, lineHeight: 1.6, resize: 'vertical' }}/>
      </div>

      <div style={{ marginBottom: 14 }}>
        <div style={{ fontSize: 12, color: P.ink3, marginBottom: 5, fontWeight: 500 }}>Tags</div>
        <input value={tagsStr} onChange={e => setTagsStr(e.target.value)} placeholder="bread, story, behind-the-scenes" style={inputStyle}/>
        {tags.length > 0 && <div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 8 }}>{tags.map((t, i) => <Pill key={i} tone="neutral">#{t}</Pill>)}</div>}
      </div>

      <label style={{ display: 'flex', alignItems: 'center', gap: 10, padding: 12, background: P.sunk, borderRadius: 10, cursor: 'pointer' }}>
        <Toggle on={publish} onClick={() => setPublish(v => !v)}/>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 13, fontWeight: 600, color: P.ink }}>{publish ? 'Publish live' : 'Keep as draft'}</div>
          <div style={{ fontSize: 11.5, color: P.ink3 }}>{publish ? 'Goes live on honestloaves.com when saved.' : "Won't be visible on your site yet."}</div>
        </div>
      </label>
    </window.Drawer>
  );
}

const PROD_COLORS = ['#D9A84C', '#C99944', '#E0C080', '#8C4A2A', '#E8B860', '#3A2A1C'];

function SiteStore() {
  const P = window.PX; const { go, toast } = window.useApp();
  const [prods, setProds] = React.useState([
    { id: window.pxid('pr'), name: 'Country bâtard', price: '$8', sold: 142, stock: true, color: '#D9A84C' },
    { id: window.pxid('pr'), name: 'Baguette', price: '$4.50', sold: 210, stock: true, color: '#C99944' },
    { id: window.pxid('pr'), name: 'Pain de mie', price: '$7', sold: 88, stock: true, color: '#E0C080' },
    { id: window.pxid('pr'), name: 'Rye & caraway', price: '$9', sold: 64, stock: true, color: '#8C4A2A' },
    { id: window.pxid('pr'), name: 'Croissant (6pk)', price: '$18', sold: 120, stock: true, color: '#E8B860' },
    { id: window.pxid('pr'), name: 'Sourdough class', price: '$80', sold: 18, stock: true, color: '#3A2A1C' },
  ]);
  const [editing, setEditing] = React.useState(null); // null | 'new' | product
  const totalSold = prods.reduce((s, p) => s + p.sold, 0);

  const saveProduct = (data) => {
    if (data.id) { setProds(ps => ps.map(p => p.id === data.id ? { ...p, ...data } : p)); toast('Product updated.', { tone: 'sage', icon: 'check' }); }
    else { setProds(ps => [...ps, { id: window.pxid('pr'), name: data.name, price: data.price, stock: data.stock, sold: 0, color: PROD_COLORS[ps.length % PROD_COLORS.length] }]); toast(`"${data.name}" added to your store.`, { tone: 'sage', icon: 'check' }); }
    setEditing(null);
  };
  const delProduct = (p) => { setProds(ps => ps.filter(x => x.id !== p.id)); toast(`Removed "${p.name}".`, { tone: 'neutral', icon: 'trash' }); };

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>Store</div><div style={{ fontSize: 12.5, color: P.ink3 }}>{prods.length} products · {totalSold} sold · synced with Money</div></div>
        <Btn kind="default" size="sm" icon="bag" onClick={() => go('orders')}>Orders</Btn>
        <Btn kind="primary" size="sm" icon="plus" style={{ marginLeft: 8 }} onClick={() => setEditing('new')}>Add product</Btn>
      </div>
      {prods.length === 0 && <Card pad={40} style={{ textAlign: 'center', color: P.ink3 }}>No products yet. Add your first one to start selling.</Card>}
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 14 }}>
        {prods.map((p) => (
          <Card key={p.id} pad={0} hover onClick={() => setEditing(p)}>
            <div style={{ height: 130, background: p.color, display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', padding: 12, position: 'relative' }}>
              <Pill tone="sage" style={{ background: 'rgba(255,255,255,0.85)', alignSelf: 'flex-end' }}>{p.sold} sold</Pill>
              <div style={{ display: 'flex', gap: 5 }}>
                <span onClick={(e) => { e.stopPropagation(); setEditing(p); }} title="Edit" style={{ width: 26, height: 26, borderRadius: 7, background: 'rgba(255,255,255,0.85)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><Icon name="pencil" size={13} color={P.ink2}/></span>
                <span onClick={(e) => { e.stopPropagation(); delProduct(p); }} title="Delete" style={{ width: 26, height: 26, borderRadius: 7, background: 'rgba(255,255,255,0.85)', display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer' }}><Icon name="trash" size={13} color={P.rose}/></span>
              </div>
            </div>
            <div style={{ padding: 14, display: 'flex', alignItems: 'center' }}>
              <div style={{ flex: 1 }}><div style={{ fontSize: 14, fontWeight: 600, color: P.ink }}>{p.name}</div><div style={{ fontSize: 11.5, color: p.stock ? P.ink3 : P.rose }}>{p.stock ? 'In stock' : 'Out of stock'}</div></div>
              <Num size={20}>{p.price}</Num>
            </div>
          </Card>
        ))}
      </div>
      {editing && <ProductEditor product={editing === 'new' ? null : editing} onClose={() => setEditing(null)} onSave={saveProduct}/>}
    </div>
  );
}

function ProductEditor({ product, onClose, onSave }) {
  const P = window.PX; const { toast } = window.useApp();
  const isNew = !product;
  const [name, setName] = React.useState(product ? product.name : '');
  const [price, setPrice] = React.useState(product ? product.price : '');
  const [stock, setStock] = React.useState(product ? product.stock : true);
  const submit = () => {
    if (!name.trim()) { toast('Name the product.', { tone: 'rose', icon: 'alert' }); return; }
    let pr = price.trim(); if (pr && !pr.startsWith('$')) pr = '$' + pr; if (!pr) pr = '$0';
    onSave({ id: product ? product.id : undefined, name: name.trim(), price: pr, stock });
  };
  return (
    <window.Modal title={isNew ? 'Add product' : 'Edit product'} w={480} onClose={onClose}
      foot={<><Btn kind="ghost" size="md" onClick={onClose}>Cancel</Btn><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon={isNew ? 'plus' : 'check'} onClick={submit}>{isNew ? 'Add product' : 'Save'}</Btn></>}>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
        <Field label="Product name" placeholder="Country bâtard" value={name} onChange={setName}/>
        <Field label="Price" placeholder="$8" icon="tag" value={price} onChange={setPrice}/>
        <label style={{ display: 'flex', alignItems: 'center', gap: 10, padding: 12, background: P.sunk, borderRadius: 10, cursor: 'pointer' }}>
          <Toggle on={stock} onClick={() => setStock(v => !v)}/>
          <div style={{ flex: 1 }}><div style={{ fontSize: 13, fontWeight: 600, color: P.ink }}>{stock ? 'In stock' : 'Out of stock'}</div><div style={{ fontSize: 11.5, color: P.ink3 }}>{stock ? 'Available to buy on your store.' : 'Hidden from the storefront.'}</div></div>
        </label>
      </div>
    </window.Modal>
  );
}

const THEME_PRESETS = [
  { name: 'Warm Bakery', palette: ['#3A2A1C', '#D9A84C', '#8C4A2A', '#F2E2C4'], heading: 'Cormorant Garamond', body: 'Inter' },
  { name: 'Modern Mono', palette: ['#1C1C1A', '#E4572E', '#F4A259', '#F7F3E9'], heading: 'Fraunces', body: 'Work Sans' },
  { name: 'Fresh Market', palette: ['#2E4E1E', '#8FB339', '#B5C99A', '#F5F7EE'], heading: 'Playfair Display', body: 'Nunito Sans' },
  { name: 'Coastal', palette: ['#1E3A4C', '#4C9BB5', '#E8B860', '#EEF4F6'], heading: 'Cormorant Garamond', body: 'Inter' },
];
const HEADING_FONTS = ['Cormorant Garamond', 'Playfair Display', 'Fraunces', 'Georgia'];
const BODY_FONTS = ['Inter', 'Work Sans', 'Nunito Sans', 'system-ui'];

function SiteTheme() {
  const P = window.PX; const { toast } = window.useApp();
  const [palette, setPalette] = React.useState([{ name: 'Crust', hex: '#3A2A1C' }, { name: 'Wheat', hex: '#D9A84C' }, { name: 'Bake', hex: '#8C4A2A' }, { name: 'Cream', hex: '#F2E2C4' }]);
  const [heading, setHeading] = React.useState('Cormorant Garamond');
  const [body, setBody] = React.useState('Inter');
  const [editColor, setEditColor] = React.useState(null); // index
  const [browsing, setBrowsing] = React.useState(false);

  const setHex = (i, hex) => setPalette(pl => pl.map((c, ci) => ci === i ? { ...c, hex } : c));
  const applyPreset = (t) => {
    setPalette(pl => pl.map((c, i) => ({ ...c, hex: t.palette[i] })));
    setHeading(t.heading); setBody(t.body); setBrowsing(false);
    toast(`Applied the "${t.name}" theme to your site.`, { tone: 'sage', icon: 'palette' });
  };

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink, marginBottom: 16 }}>Theme & brand</div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 18 }}>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 4 }}>Brand palette</div>
          <div style={{ fontSize: 11.5, color: P.ink3, marginBottom: 14 }}>Click a color to edit it</div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 10 }}>
            {palette.map((c, i) => (
              <div key={i} onClick={() => setEditColor(i)} style={{ cursor: 'pointer' }}>
                <div style={{ aspectRatio: '1', background: c.hex, borderRadius: 10, marginBottom: 6, border: `1px solid ${P.line}` }}/>
                <div style={{ fontSize: 11.5, color: P.ink, fontWeight: 500 }}>{c.name}</div>
                <div style={{ fontSize: 10, color: P.ink3, fontFamily: P.mono }}>{c.hex}</div>
              </div>
            ))}
          </div>
        </Card>
        <Card pad={18}>
          <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 14 }}>Typography</div>
          <div style={{ fontFamily: `'${heading}', Georgia, serif`, fontStyle: 'italic', fontSize: 34, color: P.ink, lineHeight: 1.1 }}>{heading.split(' ')[0]}</div>
          <div style={{ fontSize: 11.5, color: P.ink3, marginBottom: 12 }}>Display · headings</div>
          <div style={{ fontFamily: body, fontSize: 16, color: P.ink, marginBottom: 14 }}>{body} — body & UI</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
            <Select label="Headings" value={heading} onChange={setHeading} options={HEADING_FONTS}/>
            <Select label="Body" value={body} onChange={setBody} options={BODY_FONTS}/>
          </div>
        </Card>
        <Card pad={18} style={{ gridColumn: '1 / -1', display: 'flex', gap: 14, alignItems: 'center' }}>
          <div style={{ width: 44, height: 44, borderRadius: 11, background: P.sunk, color: P.ink2, display: 'flex', alignItems: 'center', justifyContent: 'center' }}><Icon name="palette" size={20}/></div>
          <div style={{ flex: 1 }}><div style={{ fontSize: 14, fontWeight: 600, color: P.ink }}>Want a fresh look?</div><div style={{ fontSize: 12.5, color: P.ink2 }}>Browse theme presets built from your brand — fonts, colors, and spacing, previewed live.</div></div>
          <Btn kind="default" size="md" onClick={() => setBrowsing(true)}>Browse themes</Btn>
        </Card>
      </div>

      {editColor != null && (
        <window.Modal title={`Edit "${palette[editColor].name}"`} w={380} onClose={() => setEditColor(null)}
          foot={<><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon="check" onClick={() => { setEditColor(null); toast('Color updated.', { tone: 'sage', icon: 'check' }); }}>Done</Btn></>}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
            <div style={{ width: 72, height: 72, borderRadius: 12, background: palette[editColor].hex, border: `1px solid ${P.line}`, flexShrink: 0 }}/>
            <div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 10 }}>
              <input type="color" value={palette[editColor].hex} onChange={e => setHex(editColor, e.target.value)} style={{ width: '100%', height: 40, border: `1px solid ${P.lineStrong}`, borderRadius: P.rCtl, background: P.card, cursor: 'pointer' }}/>
              <Field label="Hex" mono value={palette[editColor].hex} onChange={(v) => setHex(editColor, v)}/>
            </div>
          </div>
        </window.Modal>
      )}

      {browsing && (
        <window.Modal title="Browse themes" sub="Previewed with your brand colors and fonts." w={620} onClose={() => setBrowsing(false)}
          foot={<><div style={{ flex: 1 }}/><Btn kind="ghost" size="md" onClick={() => setBrowsing(false)}>Close</Btn></>}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
            {THEME_PRESETS.map((t) => (
              <Card key={t.name} pad={0} hover onClick={() => applyPreset(t)}>
                <div style={{ height: 74, display: 'flex' }}>{t.palette.map((c, i) => <div key={i} style={{ flex: 1, background: c }}/>)}</div>
                <div style={{ padding: 13 }}>
                  <div style={{ fontFamily: `'${t.heading}', Georgia, serif`, fontStyle: 'italic', fontSize: 20, color: P.ink }}>{t.name}</div>
                  <div style={{ fontSize: 11, color: P.ink3, marginTop: 2 }}>{t.heading} · {t.body}</div>
                  <Btn kind="default" size="sm" full style={{ marginTop: 10 }} onClick={(e) => { e.stopPropagation(); applyPreset(t); }}>Apply theme</Btn>
                </div>
              </Card>
            ))}
          </div>
        </window.Modal>
      )}
    </div>
  );
}

function SiteSEO() {
  const P = window.PX; const { sparks, setSparks, openOverlay, toast } = window.useApp();
  const [issues, setIssues] = React.useState([
    { id: 'i1', title: '3 images missing alt text', sub: 'On Home, About', tone: 'amber', bump: 4, resolved: false },
    { id: 'i2', title: 'About page meta description too short', sub: '92 chars · aim for 150', tone: 'amber', bump: 3, resolved: false },
    { id: 'i3', title: 'Missing schema markup for local business', sub: 'Helps you show in Maps', tone: 'sky', bump: 5, resolved: false },
  ]);
  const [score, setScore] = React.useState(82);
  const open = issues.filter(i => !i.resolved).length;

  const fix = (issue) => {
    const cost = 1;
    if (cost > sparks) { openOverlay('creditGate', { needed: cost, balance: sparks }); return; }
    setSparks(s => Math.max(0, s - cost));
    setIssues(is => is.map(i => i.id === issue.id ? { ...i, resolved: true } : i));
    setScore(s => Math.min(100, s + issue.bump));
    toast(`Fixed: ${issue.title}. SEO score +${issue.bump}.`, { tone: 'sage', icon: 'check' });
  };

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink, marginBottom: 16 }}>SEO</div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 14, marginBottom: 18 }}>
        {[['SEO score', String(score), '/100', 'sage'], ['Indexed pages', '7', 'of 7', 'sky'], ['Issues', String(open), open === 1 ? 'to fix' : 'to fix', open === 0 ? 'sage' : 'amber']].map((c, i) => (
          <Card key={i} pad={16}><Label>{c[0]}</Label><div style={{ display: 'flex', alignItems: 'baseline', gap: 4, marginTop: 6 }}><Num size={28} color={P[c[3]]}>{c[1]}</Num><span style={{ fontSize: 12, color: P.ink3 }}>{c[2]}</span></div></Card>
        ))}
      </div>
      <Card>
        <div style={{ padding: '14px 18px', borderBottom: `1px solid ${P.line}`, fontSize: 14, fontWeight: 600, color: P.ink }}>Issues to fix</div>
        {open === 0 && <div style={{ padding: '20px 18px', fontSize: 13, color: P.sage, display: 'flex', alignItems: 'center', gap: 8 }}><Icon name="check" size={16}/>All issues resolved — nice work.</div>}
        {issues.map((r, i) => (
          <div key={r.id} style={{ padding: '13px 18px', display: 'flex', alignItems: 'center', gap: 12, borderBottom: i < issues.length - 1 ? `1px solid ${P.line}` : 'none', opacity: r.resolved ? 0.55 : 1 }}>
            <span style={{ width: 8, height: 8, borderRadius: 8, background: r.resolved ? P.sage : P[r.tone] }}/>
            <div style={{ flex: 1 }}><div style={{ fontSize: 13.5, color: P.ink, fontWeight: 500, textDecoration: r.resolved ? 'line-through' : 'none' }}>{r.title}</div><div style={{ fontSize: 11.5, color: P.ink3 }}>{r.sub}</div></div>
            {r.resolved ? <Pill tone="sage" icon="check">Fixed</Pill> : <Btn kind="spark" size="sm" onClick={() => fix(r)}>Fix · 1 ⚡</Btn>}
          </div>
        ))}
      </Card>
      <Card pad={16} style={{ marginTop: 14 }}>
        <div style={{ fontSize: 14, fontWeight: 600, color: P.ink, marginBottom: 12 }}>Top keywords you rank for</div>
        {[['brooklyn sourdough', 3, 410], ['williamsburg bakery', 5, 280], ['sourdough class nyc', 2, 190], ['stone milled bread', 8, 90]].map((k, i) => (
          <div key={i} style={{ display: 'grid', gridTemplateColumns: '1fr 80px 90px', gap: 10, padding: '8px 0', borderBottom: i < 3 ? `1px solid ${P.line}` : 'none', fontSize: 12.5, alignItems: 'center' }}>
            <span style={{ color: P.ink }}>{k[0]}</span><span style={{ color: P.ink2, textAlign: 'right' }}>#{k[1]}</span><span style={{ color: P.ink3, textAlign: 'right' }}>{k[2]}/mo</span>
          </div>
        ))}
      </Card>
    </div>
  );
}

const FORM_STATUSES = [
  { k: 'new', label: 'New', tone: 'spark' },
  { k: 'contacted', label: 'Contacted', tone: 'sky' },
  { k: 'converted', label: 'Converted', tone: 'sage' },
  { k: 'archived', label: 'Archived', tone: 'neutral' },
];

function SiteForms() {
  const P = window.PX; const { toast, openOverlay } = window.useApp();
  const [subs, setSubs] = React.useState([
    { id: 1, name: 'Maria Hernandez', email: 'maria.h@gmail.com', message: 'Hi! Looking for a wedding cake for June 14th, about 80 guests. Do you do tastings?', form: 'Contact form', time: 'Today · 9:14am', status: 'new' },
    { id: 2, name: 'Corner Coffee Co.', email: 'owner@cornercoffee.co', message: 'Interested in wholesale pricing for a 12-loaf weekly order. Can we set up a call?', form: 'Wholesale inquiry', time: '2h ago', status: 'new' },
    { id: 3, name: 'Devon Price', email: 'devon@gmail.com', message: "Any chance there's a waitlist spot open for the March sourdough class?", form: 'Class waitlist', time: 'Yesterday', status: 'new' },
    { id: 4, name: 'Lila Events', email: 'events@lila.nyc', message: 'Quoting a corporate breakfast for 60 people — would love your catering menu.', form: 'Catering quote', time: '2d ago', status: 'contacted' },
    { id: 5, name: 'Priya Nair', email: 'priya.n@outlook.com', message: 'Loved the rye loaf! Do you sell it at any farmers markets nearby?', form: 'Contact form', time: '4d ago', status: 'contacted' },
    { id: 6, name: 'Alex Chen', email: 'curious@gmail.com', message: 'Do you ship nationally? Would love to order for my parents.', form: 'Contact form', time: '5d ago', status: 'converted' },
    { id: 7, name: 'Sam Ortiz', email: 'sam.o@gmail.com', message: 'Asking about allergen info for the croissants — not relevant to us anymore.', form: 'Contact form', time: '1w ago', status: 'archived' },
  ]);

  const move = (id, dir) => setSubs(ss => ss.map(s => {
    if (s.id !== id) return s;
    const idx = FORM_STATUSES.findIndex(st => st.k === s.status);
    const next = FORM_STATUSES[idx + dir];
    return next ? { ...s, status: next.k } : s;
  }));

  const [forms, setForms] = React.useState([
    { id: 'f1', name: 'Contact form', active: true, fields: ['Name', 'Email', 'Message'] },
    { id: 'f2', name: 'Wholesale inquiry', active: true, fields: ['Name', 'Business', 'Email', 'Volume'] },
    { id: 'f3', name: 'Class waitlist', active: true, fields: ['Name', 'Email', 'Class'] },
    { id: 'f4', name: 'Catering quote', active: false, fields: ['Name', 'Email', 'Guests', 'Date'] },
  ]);
  const [managing, setManaging] = React.useState(false);

  const addToPeople = (s) => {
    if (s.added) return;
    const looksCo = /\.|\bco\b|events|market|coffee|guild|hotel/i.test(s.name);
    const c = { id: window.pxid('c'), name: s.name, co: looksCo ? s.name : '—', role: 'Lead', tags: ['website', 'new'], deal: 0, last: 'Today', tone: 'sky', signal: `From ${s.form}`, email: s.email, phone: '', ltv: 0, rel: 50 };
    window.PXPeople.addContact(c);
    setSubs(ss => ss.map(x => x.id === s.id ? { ...x, added: true } : x));
    toast(`${s.name} added to People as a new lead.`, { tone: 'sage', icon: 'check' });
  };

  const newCount = subs.filter(s => s.status === 'new').length;

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 18 }}>
        <div style={{ flex: 1 }}><div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink }}>Forms & leads</div><div style={{ fontSize: 12.5, color: P.ink3 }}>{newCount} new submissions · auto-added to People</div></div>
        <Btn kind="default" size="sm" icon="settings" onClick={() => setManaging(true)}>Manage forms</Btn>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 14 }}>
        {FORM_STATUSES.map((col, ci) => {
          const items = subs.filter(s => s.status === col.k);
          return (
            <div key={col.k}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 }}>
                <Pill tone={col.tone} dot>{col.label}</Pill>
                <span style={{ fontSize: 11.5, color: P.ink3 }}>{items.length}</span>
              </div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
                {items.length === 0 && <div style={{ fontSize: 12, color: P.ink4, padding: '10px 0', textAlign: 'center' }}>—</div>}
                {items.map(s => (
                  <Card key={s.id} pad={13}>
                    <div style={{ display: 'flex', alignItems: 'flex-start', gap: 8, marginBottom: 6 }}>
                      <div style={{ flex: 1, minWidth: 0 }}>
                        <div style={{ fontSize: 13, fontWeight: 600, color: P.ink }}>{s.name}</div>
                        <div style={{ fontSize: 11, color: P.ink3, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{s.email}</div>
                      </div>
                    </div>
                    <div style={{ fontSize: 12, color: P.ink2, lineHeight: 1.5, marginBottom: 8 }}>{s.message}</div>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 10 }}>
                      <Pill tone="outline">{s.form}</Pill>
                      <span style={{ fontSize: 10.5, color: P.ink4 }}>{s.time}</span>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 8 }}>
                      <Btn kind="ghost" size="sm" icon="chevL" disabled={ci === 0} onClick={() => move(s.id, -1)} style={{ padding: '5px 7px' }}/>
                      <Btn kind="ghost" size="sm" icon="chevR" disabled={ci === FORM_STATUSES.length - 1} onClick={() => move(s.id, 1)} style={{ padding: '5px 7px' }}/>
                      <span style={{ flex: 1, fontSize: 10.5, color: P.ink4, textAlign: 'right' }}>move stage</span>
                    </div>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                      <Btn kind="default" size="sm" full onClick={() => openOverlay('compose', { to: s.email, subject: `Re: ${s.form}` })}>Reply</Btn>
                      <Btn kind={s.added ? 'ghost' : 'soft'} size="sm" full disabled={s.added} icon={s.added ? 'check' : undefined} onClick={() => addToPeople(s)}>{s.added ? 'Added' : 'Add to People'}</Btn>
                    </div>
                  </Card>
                ))}
              </div>
            </div>
          );
        })}
      </div>
      {managing && (
        <window.Modal title="Manage forms" sub="Toggle which forms are live on your site." w={520} onClose={() => setManaging(false)}
          foot={<><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon="check" onClick={() => { setManaging(false); toast('Form settings saved.', { tone: 'sage', icon: 'check' }); }}>Done</Btn></>}>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
            {forms.map((f) => {
              const count = subs.filter(s => s.form === f.name).length;
              return (
                <div key={f.id} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 14, border: `1px solid ${P.line}`, borderRadius: 11 }}>
                  <div style={{ flex: 1 }}>
                    <div style={{ fontSize: 13.5, fontWeight: 600, color: P.ink }}>{f.name}</div>
                    <div style={{ fontSize: 11.5, color: P.ink3 }}>{f.fields.join(' · ')} · {count} submission{count === 1 ? '' : 's'}</div>
                  </div>
                  <span style={{ fontSize: 11.5, color: f.active ? P.sage : P.ink4 }}>{f.active ? 'Live' : 'Off'}</span>
                  <Toggle on={f.active} onClick={() => setForms(fs => fs.map(x => x.id === f.id ? { ...x, active: !x.active } : x))}/>
                </div>
              );
            })}
          </div>
        </window.Modal>
      )}
    </div>
  );
}

function SiteDomains() {
  const P = window.PX; const { toast } = window.useApp();
  const [secondaries, setSecondaries] = React.useState([{ id: 'd1', name: 'honestloaves.nyc', price: '$18', redirect: true }]);
  const [buying, setBuying] = React.useState(false);
  const [managing, setManaging] = React.useState(null); // domain obj

  const buy = (name, price) => { setSecondaries(ds => [...ds, { id: window.pxid('dom'), name, price, redirect: true }]); setBuying(false); toast(`Registered ${name}. It now redirects to honestloaves.com.`, { tone: 'sage', icon: 'check' }); };
  const removeDomain = (d) => { setSecondaries(ds => ds.filter(x => x.id !== d.id)); setManaging(null); toast(`Removed ${d.name}.`, { tone: 'neutral', icon: 'trash' }); };
  const toggleRedirect = (d) => setSecondaries(ds => ds.map(x => x.id === d.id ? { ...x, redirect: !x.redirect } : x));

  return (
    <div style={{ fontFamily: P.sans, padding: 22 }}>
      <div style={{ fontFamily: P.serif, fontStyle: 'italic', fontSize: 26, color: P.ink, marginBottom: 16 }}>Domains</div>
      <Card pad={18} style={{ marginBottom: 14 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
          <div style={{ width: 44, height: 44, borderRadius: 11, background: P.sageTint, color: P.sage, display: 'flex', alignItems: 'center', justifyContent: 'center' }}><Icon name="globe" size={22}/></div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 15, fontWeight: 600, color: P.ink }}>honestloaves.com</div>
            <div style={{ fontSize: 12, color: P.ink3 }}>Primary · registered through Pexxie · renews Mar 2026</div>
          </div>
          <Pill tone="sage" dot>Active · SSL</Pill>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 12, marginTop: 16, paddingTop: 16, borderTop: `1px solid ${P.line}` }}>
          {[['DNS', 'Cloudflare'], ['SSL', 'Auto · valid'], ['Email', 'Google Workspace'], ['Renews', 'Mar 12, 2026']].map((d, i) => (
            <div key={i}><Label>{d[0]}</Label><div style={{ fontSize: 13, color: P.ink, marginTop: 3 }}>{d[1]}</div></div>
          ))}
        </div>
      </Card>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
        {secondaries.map((d) => (
          <Card key={d.id} pad={16} hover onClick={() => setManaging(d)}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <div style={{ flex: 1, fontSize: 13.5, fontWeight: 600, color: P.ink }}>{d.name}</div>
              <Icon name="settings" size={14} color={P.ink4}/>
            </div>
            <div style={{ fontSize: 12, color: P.ink3, marginTop: 4 }}>{d.redirect ? 'Redirects to .com' : 'Parked'} · {d.price}/yr</div>
          </Card>
        ))}
        <Card pad={16} onClick={() => setBuying(true)} style={{ borderStyle: 'dashed', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, color: P.spark, cursor: 'pointer' }}>
          <Icon name="plus" size={16}/><span style={{ fontSize: 13, fontWeight: 500 }}>Add or buy a domain</span>
        </Card>
      </div>

      {buying && <DomainBuyer onClose={() => setBuying(false)} onBuy={buy}/>}
      {managing && (
        <window.Modal title={managing.name} sub="Manage this domain." w={440} onClose={() => setManaging(null)}
          foot={<><Btn kind="danger" size="md" icon="trash" onClick={() => removeDomain(managing)}>Remove domain</Btn><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon="check" onClick={() => setManaging(null)}>Done</Btn></>}>
          <label style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 14, background: P.sunk, borderRadius: 11, cursor: 'pointer' }}>
            <Toggle on={managing.redirect} onClick={() => { toggleRedirect(managing); setManaging(m => ({ ...m, redirect: !m.redirect })); }}/>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 13, fontWeight: 600, color: P.ink }}>{managing.redirect ? 'Redirect to honestloaves.com' : 'Parked (no redirect)'}</div>
              <div style={{ fontSize: 11.5, color: P.ink3 }}>{managing.redirect ? 'Visitors land on your main site.' : 'Domain is reserved but shows nothing.'}</div>
            </div>
          </label>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, marginTop: 14 }}>
            <div><Label>Renews</Label><div style={{ fontSize: 13, color: P.ink, marginTop: 3 }}>{managing.price}/yr · Mar 2026</div></div>
            <div><Label>SSL</Label><div style={{ fontSize: 13, color: P.ink, marginTop: 3 }}>Auto · valid</div></div>
          </div>
        </window.Modal>
      )}
    </div>
  );
}

function DomainBuyer({ onClose, onBuy }) {
  const P = window.PX;
  const [q, setQ] = React.useState('honestloaves');
  const base = (q.trim() || 'yourbakery').toLowerCase().replace(/[^a-z0-9]/g, '');
  const suggestions = [[base + '.co', '$28'], [base + '.shop', '$32'], [base + 'brooklyn.com', '$14'], [base + '.bread', '$60']];
  return (
    <window.Modal title="Add or buy a domain" sub="Search available domains and connect them in one click." w={520} onClose={onClose}
      foot={<><div style={{ flex: 1 }}/><Btn kind="ghost" size="md" onClick={onClose}>Close</Btn></>}>
      <Field label="Search a name" icon="globe" placeholder="honestloaves" value={q} onChange={setQ}/>
      <div style={{ marginTop: 14, display: 'flex', flexDirection: 'column', gap: 8 }}>
        <Label>Available</Label>
        {suggestions.map((s, i) => (
          <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '11px 13px', border: `1px solid ${P.line}`, borderRadius: 10 }}>
            <Icon name="globe" size={15} color={P.sage}/>
            <span style={{ flex: 1, fontSize: 13.5, color: P.ink, fontFamily: P.mono }}>{s[0]}</span>
            <span style={{ fontSize: 12, color: P.ink3 }}>{s[1]}/yr</span>
            <Btn kind="primary" size="sm" onClick={() => onBuy(s[0], s[1])}>Buy</Btn>
          </div>
        ))}
      </div>
    </window.Modal>
  );
}

// ── Live site preview (used by Overview Preview + Visit-live) ──
function SitePreviewModal({ onClose, onEdit }) {
  const P = window.PX;
  const serif = "'Cormorant Garamond', Georgia, serif";
  const cream = '#F2E2C4', crust = '#3A2A1C', wheat = '#D9A84C', bake = '#8C4A2A', sub = '#6B563C';
  return (
    <window.Modal title="Live preview" sub="honestloaves.com · this is exactly what visitors see." w={900} onClose={onClose}
      foot={<><Btn kind="ghost" size="md" onClick={onClose}>Close</Btn><div style={{ flex: 1 }}/><Btn kind="primary" size="md" icon="pencil" onClick={onEdit}>Open in editor</Btn></>}>
      <div style={{ border: `1px solid ${P.line}`, borderRadius: 10, overflow: 'hidden' }}>
        <div style={{ height: 30, background: P.sunk, display: 'flex', alignItems: 'center', gap: 6, padding: '0 12px', borderBottom: `1px solid ${P.line}` }}>
          <span style={{ width: 9, height: 9, borderRadius: 9, background: '#E88171' }}/><span style={{ width: 9, height: 9, borderRadius: 9, background: '#E8C27B' }}/><span style={{ width: 9, height: 9, borderRadius: 9, background: '#97B87A' }}/>
          <div style={{ flex: 1, textAlign: 'center', fontSize: 11, color: P.ink3 }}>honestloaves.com</div>
        </div>
        <div style={{ background: '#fff', color: crust, fontFamily: 'Inter, system-ui, sans-serif' }}>
          <div style={{ padding: '16px 32px', display: 'flex', alignItems: 'center', borderBottom: '1px solid rgba(0,0,0,0.06)' }}>
            <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 22, flex: 1 }}>Honest Loaves</div>
            <div style={{ display: 'flex', gap: 20, fontSize: 12, color: sub }}><span>Menu</span><span>Classes</span><span>Shop</span><span>Contact</span></div>
          </div>
          <div style={{ background: cream, padding: '52px 32px', display: 'grid', gridTemplateColumns: '1.1fr 0.9fr', gap: 28, alignItems: 'center' }}>
            <div>
              <div style={{ fontSize: 11, color: bake, textTransform: 'uppercase', letterSpacing: 2, marginBottom: 12 }}>Brooklyn · since 2019</div>
              <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 52, lineHeight: 1.02, letterSpacing: -1.2 }}>Stone-milled. Hand-shaped. Stubborn.</div>
              <div style={{ fontSize: 15, color: sub, lineHeight: 1.6, marginTop: 16, maxWidth: 420 }}>A tiny bakery in Williamsburg. Open Thursday through Sunday.</div>
              <div style={{ marginTop: 22, display: 'inline-flex', padding: '11px 20px', background: crust, color: '#F5D8A8', fontSize: 13, fontWeight: 600, borderRadius: 3 }}>Order for Saturday</div>
            </div>
            <div style={{ aspectRatio: '4/5', background: `repeating-linear-gradient(45deg, ${wheat} 0 14px, #C99944 14px 28px)`, borderRadius: 8 }}/>
          </div>
          <div style={{ padding: '52px 32px' }}>
            <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 32, textAlign: 'center', marginBottom: 22 }}>This week's bakes</div>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 16 }}>
              {[['Country bâtard', '$8', wheat], ['Rye & caraway', '$9', bake], ['Pain de mie', '$7', '#E0C080']].map((it, i) => (
                <div key={i} style={{ textAlign: 'center' }}>
                  <div style={{ aspectRatio: '1', background: it[2], borderRadius: 8, marginBottom: 10 }}/>
                  <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 17 }}>{it[0]}</div>
                  <div style={{ fontSize: 13, color: sub, marginTop: 2 }}>{it[1]}</div>
                </div>
              ))}
            </div>
          </div>
          <div style={{ padding: '52px 32px', background: '#FBF3E0' }}>
            <div style={{ maxWidth: 620 }}>
              <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 32, marginBottom: 14 }}>Our story</div>
              <div style={{ fontSize: 16, lineHeight: 1.7, color: sub }}>Three generations of stubborn obsession with bread. We mill our own flour, ferment slow, and bake in a single Brooklyn oven — the same way since 2019.</div>
            </div>
          </div>
          <div style={{ padding: '52px 32px', background: crust, color: '#F5E9CE', textAlign: 'center' }}>
            <div style={{ fontFamily: serif, fontStyle: 'italic', fontSize: 38, letterSpacing: -0.8 }}>Order for this weekend</div>
            <div style={{ fontSize: 14, color: 'rgba(245,233,206,0.72)', marginTop: 10 }}>Pickup Thursday–Sunday. Wholesale welcome.</div>
            <div style={{ marginTop: 20, display: 'inline-flex', padding: '12px 24px', background: wheat, color: crust, fontSize: 14, fontWeight: 700, borderRadius: 3 }}>Start an order</div>
          </div>
        </div>
      </div>
    </window.Modal>
  );
}
