/* ============================================================
   F2 UI — Marketing / website blocks
   Navbar · Hero · FeatureGrid · Pricing · Testimonial · CTASection ·
   LogoCloud · FAQ · Footer
   These are full-width composed blocks (use fill:true in stories).
   ============================================================ */
(function () {
  const { Icon, Button, Badge, MonoLabel, Card, WorkflowNode, FlowEdge, StatusDot, Avatar, Accordion } = window.F2;

  function Logo({ size = 10 }) {
    const cell = (a) => ({ width: size, height: size, borderRadius: size * 0.28, background: a ? 'var(--f2-accent)' : 'var(--f2-surface-card)', border: a ? 'none' : '1px solid var(--f2-border-strong)' });
    return (
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 10 }}>
        <span style={{ display: 'grid', gridTemplateColumns: `${size}px ${size}px`, gap: 3 }}><span style={cell()} /><span style={cell()} /><span style={cell()} /><span style={cell(true)} /></span>
        <span style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 17, letterSpacing: '-0.02em', color: 'var(--f2-text)' }}>F2 <span style={{ fontWeight: 500, color: 'var(--f2-text-muted)' }}>Tecnologia</span></span>
      </span>
    );
  }

  /* ====================== Navbar ====================== */
  function Navbar({ links = ['Product', 'Methodology', 'Work', 'Pricing'], cta = 'Start a project', style = {} }) {
    return (
      <header style={{ display: 'flex', alignItems: 'center', gap: 24, padding: '16px 28px', borderBottom: '1px solid var(--f2-border)', background: 'var(--f2-surface)', ...style }}>
        <Logo />
        <nav style={{ display: 'flex', gap: 4, flex: 1, justifyContent: 'center', flexWrap: 'wrap' }}>
          {links.map((l) => <a key={l} href="#" onClick={(e) => e.preventDefault()} style={{ padding: '8px 12px', fontSize: 14.5, color: 'var(--f2-text-secondary)', textDecoration: 'none', borderRadius: 8 }}>{l}</a>)}
        </nav>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <a href="#" onClick={(e) => e.preventDefault()} style={{ fontSize: 14.5, color: 'var(--f2-text-secondary)', textDecoration: 'none' }}>Sign in</a>
          <Button size="sm">{cta}</Button>
        </div>
      </header>
    );
  }

  /* ====================== Hero ====================== */
  function HeroDiagram() {
    return (
      <Card style={{ padding: 18, width: '100%', maxWidth: 380 }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 18 }}>
          <MonoLabel node>Invoice agent</MonoLabel>
          <Badge tone="active"><StatusDot tone="active" live size={6} /> Running</Badge>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', flexWrap: 'nowrap', gap: 0 }}>
          <WorkflowNode label="EMAIL" icon={<Icon name="Mail" size={15} />} />
          <FlowEdge length={16} />
          <WorkflowNode label="AGENT" active icon={<Icon name="Bot" size={15} />} />
          <FlowEdge final length={16} />
          <WorkflowNode label="ERP" icon={<Icon name="CheckCircle2" size={15} />} />
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 20, paddingTop: 16, borderTop: '1px solid var(--f2-border)' }}>
          <div><div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 22, color: 'var(--f2-text)' }}>20 min</div><div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginTop: 2 }}>was 3 days</div></div>
          <div><div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 22, color: 'var(--f2-text)' }}>1,284</div><div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginTop: 2 }}>today</div></div>
          <div><div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 22, color: 'var(--f2-text)' }}>0</div><div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 10, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginTop: 2 }}>errors</div></div>
        </div>
      </Card>
    );
  }
  function Hero({ eyebrow = 'AI automation studio', title = 'Automation, engineered to fit.', subtitle = 'For teams that have outgrown off-the-shelf tools. We engineer custom automation — the depth of a software team with the restraint of a design studio.', primaryCta = 'Start a project', secondaryCta = 'See the work', aside = 'diagram', style = {} }) {
    return (
      <section style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))', gap: 48, alignItems: 'center', padding: 'clamp(40px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 22 }}>
            <span style={{ width: 7, height: 7, borderRadius: 2, background: 'var(--f2-accent)' }} />
            <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-muted)' }}>{eyebrow}</span>
          </div>
          <h1 style={{ margin: 0, fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 'clamp(34px, 5vw, 56px)', lineHeight: 1.0, letterSpacing: '-0.035em', color: 'var(--f2-text)' }}>{title}</h1>
          <p style={{ margin: '22px 0 0', fontSize: 'clamp(16px, 2vw, 19px)', lineHeight: 1.6, color: 'var(--f2-text-secondary)', maxWidth: 520 }}>{subtitle}</p>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, marginTop: 30 }}>
            <Button size="lg" iconRight={<Icon name="ArrowRight" size={18} />}>{primaryCta}</Button>
            {secondaryCta && <Button size="lg" variant="secondary">{secondaryCta}</Button>}
          </div>
        </div>
        {aside && <div style={{ display: 'flex', justifyContent: 'center' }}>{aside === 'diagram' ? <HeroDiagram /> : aside}</div>}
      </section>
    );
  }

  /* ====================== FeatureGrid ====================== */
  function FeatureCard({ icon, title, body }) {
    return (
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, padding: 24, border: '1px solid var(--f2-border)', borderRadius: 'var(--f2-radius-md)', background: 'var(--f2-surface-card)' }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 40, height: 40, borderRadius: 'var(--f2-radius-control)', border: '1px solid var(--f2-border)', background: 'var(--f2-surface-raised)', color: 'var(--f2-accent-text)' }}><Icon name={icon} size={20} /></span>
        <div style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 17, color: 'var(--f2-text)' }}>{title}</div>
        <div style={{ fontSize: 14.5, lineHeight: 1.6, color: 'var(--f2-text-muted)' }}>{body}</div>
      </div>
    );
  }
  function FeatureGrid({ eyebrow = 'How we work', title = 'Engineering, not templates.', features, style = {} }) {
    const f = features || [
      { icon: 'Microscope', title: 'Scoped to your stack', body: 'We map your actual systems and data before writing a line — no generic flows bolted on.' },
      { icon: 'Boxes', title: 'Production-grade builds', body: 'Custom agents with real error handling, observability and rollback. Not a demo.' },
      { icon: 'GitBranch', title: 'Deploy where you run', body: 'Your cloud or ours, with the same logs and controls either way.' },
      { icon: 'LineChart', title: 'Proof ahead of promises', body: 'We ship a measurable result first, then scale what works.' },
      { icon: 'ShieldCheck', title: 'Data stays yours', body: 'In-region processing. We never train on your data.' },
      { icon: 'Workflow', title: 'Visible decisions', body: 'Every step the agent takes is inspectable — here is exactly how it decides.' },
    ];
    return (
      <section style={{ padding: 'clamp(48px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div style={{ maxWidth: 1100, margin: '0 auto' }}>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 16 }}>
            <span style={{ width: 7, height: 7, borderRadius: 2, background: 'var(--f2-accent)' }} />
            <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-muted)' }}>{eyebrow}</span>
          </div>
          <h2 style={{ margin: '0 0 36px', fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 'clamp(26px, 3.5vw, 38px)', letterSpacing: '-0.03em', color: 'var(--f2-text)', maxWidth: 600 }}>{title}</h2>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))', gap: 16 }}>
            {f.map((x, i) => <FeatureCard key={i} {...x} />)}
          </div>
        </div>
      </section>
    );
  }

  /* ====================== Pricing ====================== */
  function PricingCard({ name, price, period = '/mo', description, features = [], cta = 'Start', featured = false, style = {} }) {
    return (
      <div style={{ display: 'flex', flexDirection: 'column', padding: 28, borderRadius: 'var(--f2-radius-lg)', background: featured ? 'var(--f2-surface-card)' : 'var(--f2-surface)', border: `1px solid ${featured ? 'var(--f2-accent-border)' : 'var(--f2-border)'}`, position: 'relative', ...style }}>
        {featured && <span style={{ position: 'absolute', top: 20, right: 20 }}><Badge tone="active">Most picked</Badge></span>}
        <div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.14em', textTransform: 'uppercase', color: featured ? 'var(--f2-accent-text)' : 'var(--f2-text-muted)' }}>{name}</div>
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 16 }}>
          <span style={{ fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 40, letterSpacing: '-0.03em', color: 'var(--f2-text)' }}>{price}</span>
          {period && <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 13, color: 'var(--f2-text-faint)' }}>{period}</span>}
        </div>
        {description && <p style={{ margin: '10px 0 0', fontSize: 14, lineHeight: 1.5, color: 'var(--f2-text-muted)' }}>{description}</p>}
        <div style={{ height: 1, background: 'var(--f2-border)', margin: '22px 0' }} />
        <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 12, flex: 1 }}>
          {features.map((f, i) => <li key={i} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', fontSize: 14.5, color: 'var(--f2-text-secondary)', lineHeight: 1.45 }}><span style={{ color: 'var(--f2-accent-text)', marginTop: 1, flex: '0 0 auto' }}><Icon name="Check" size={16} stroke={2} /></span>{f}</li>)}
        </ul>
        <div style={{ marginTop: 26 }}><Button variant={featured ? 'primary' : 'secondary'} size="lg" style={{ width: '100%' }}>{cta}</Button></div>
      </div>
    );
  }
  function Pricing({ eyebrow = 'Pricing', title = 'Scoped up front. No per-seat surprises.', plans, style = {} }) {
    const p = plans || [
      { name: 'Pilot', price: 'R$ 18k', period: 'one-time', description: 'A single scoped automation, shipped in weeks.', features: ['1 production agent', 'Your stack integration', '30-day tuning', 'Run observability'], cta: 'Book a scope' },
      { name: 'Studio', price: 'R$ 9.8k', period: '/mo', description: 'An ongoing engineering retainer for your automation roadmap.', features: ['Unlimited agents', 'Priority builds', 'Dedicated engineer', 'SLA + on-call', 'Quarterly roadmap'], cta: 'Start a project', featured: true },
      { name: 'Enterprise', price: 'Custom', period: '', description: 'Self-hosted, compliance, and volume needs.', features: ['On-prem / VPC deploy', 'SSO + audit logs', 'Data residency', 'Security review'], cta: 'Talk to us' },
    ];
    return (
      <section style={{ padding: 'clamp(48px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div style={{ maxWidth: 1100, margin: '0 auto' }}>
          <div style={{ textAlign: 'center', marginBottom: 40 }}>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 14 }}><span style={{ width: 7, height: 7, borderRadius: 2, background: 'var(--f2-accent)' }} /><span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-muted)' }}>{eyebrow}</span></div>
            <h2 style={{ margin: 0, fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 'clamp(26px, 3.5vw, 38px)', letterSpacing: '-0.03em', color: 'var(--f2-text)' }}>{title}</h2>
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))', gap: 16, alignItems: 'stretch' }}>
            {p.map((x, i) => <PricingCard key={i} {...x} />)}
          </div>
        </div>
      </section>
    );
  }

  /* ====================== Testimonial ====================== */
  function Testimonial({ quote = 'They cut our invoice processing from 3 days to 20 minutes. No template — they engineered it around our ERP exactly.', name = 'Marina Alves', role = 'Head of Operations', company = 'Logística Andrade', style = {} }) {
    return (
      <section style={{ padding: 'clamp(48px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface-card)', borderTop: '1px solid var(--f2-border)', borderBottom: '1px solid var(--f2-border)', ...style }}>
        <figure style={{ maxWidth: 820, margin: '0 auto', textAlign: 'center' }}>
          <Icon name="Quote" size={28} color="var(--f2-accent-text)" />
          <blockquote style={{ margin: '20px 0 0', fontFamily: 'var(--f2-font-display)', fontWeight: 500, fontSize: 'clamp(22px, 3vw, 30px)', lineHeight: 1.35, letterSpacing: '-0.02em', color: 'var(--f2-text)' }}>“{quote}”</blockquote>
          <figcaption style={{ display: 'inline-flex', alignItems: 'center', gap: 12, marginTop: 28 }}>
            <Avatar name={name} size={40} />
            <span style={{ textAlign: 'left' }}>
              <span style={{ display: 'block', fontSize: 15, fontWeight: 600, color: 'var(--f2-text)' }}>{name}</span>
              <span style={{ display: 'block', fontFamily: 'var(--f2-font-mono)', fontSize: 12, color: 'var(--f2-text-muted)', marginTop: 2 }}>{role} · {company}</span>
            </span>
          </figcaption>
        </figure>
      </section>
    );
  }

  /* ====================== CTASection ====================== */
  function CTASection({ eyebrow = 'Ready when you are', title = "Let's find the workflow worth automating.", body = 'A 30-minute scope call. We will tell you honestly whether it is worth building.', cta = 'Start a project', style = {} }) {
    return (
      <section style={{ padding: 'clamp(48px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div style={{ maxWidth: 820, margin: '0 auto', textAlign: 'center', padding: 'clamp(36px, 5vw, 56px)', borderRadius: 'var(--f2-radius-lg)', border: '1px solid var(--f2-accent-border)', background: 'var(--f2-surface-accent)' }}>
          <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-accent-text)' }}>{eyebrow}</span>
          <h2 style={{ margin: '16px 0 0', fontFamily: 'var(--f2-font-display)', fontWeight: 700, fontSize: 'clamp(26px, 3.5vw, 40px)', letterSpacing: '-0.03em', color: 'var(--f2-text)' }}>{title}</h2>
          <p style={{ margin: '16px auto 0', maxWidth: 480, fontSize: 16.5, lineHeight: 1.6, color: 'var(--f2-text-secondary)' }}>{body}</p>
          <div style={{ marginTop: 28 }}><Button size="lg" iconRight={<Icon name="ArrowRight" size={18} />}>{cta}</Button></div>
        </div>
      </section>
    );
  }

  /* ====================== LogoCloud ====================== */
  function LogoCloud({ label = 'Trusted by teams that ship', logos = ['Andrade', 'Nuvio', 'Cortex', 'Praxis', 'Lumen', 'Vértice'], style = {} }) {
    return (
      <section style={{ padding: 'clamp(32px, 4vw, 48px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div style={{ maxWidth: 1000, margin: '0 auto', textAlign: 'center' }}>
          <div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 11, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginBottom: 24 }}>{label}</div>
          <div style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'center', gap: 'clamp(24px, 5vw, 56px)', alignItems: 'center' }}>
            {logos.map((l) => <span key={l} style={{ display: 'inline-flex', alignItems: 'center', gap: 8, color: 'var(--f2-text-muted)', fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 19, letterSpacing: '-0.01em' }}><span style={{ width: 8, height: 8, borderRadius: 2, background: 'var(--f2-text-faint)' }} />{l}</span>)}
          </div>
        </div>
      </section>
    );
  }

  /* ====================== FAQ ====================== */
  function FAQ({ eyebrow = 'FAQ', title = 'Questions, answered plainly.', items, style = {} }) {
    const f = items || [
      { title: 'How is F2 different from a no-code tool?', content: 'No-code tools template the 80% case. We engineer the 20% that actually matters for your business — the edge cases, the integrations, the error handling.' },
      { title: 'How long does a first automation take?', content: 'A scoped pilot typically ships in 2–4 weeks, with a measurable result before we scale.' },
      { title: 'Can it run on our own infrastructure?', content: 'Yes — agents deploy to your cloud or VPC with the same observability as our hosted option.' },
      { title: 'Do you train on our data?', content: 'Never. Data stays in your region and is processed in-region only.' },
    ];
    return (
      <section style={{ padding: 'clamp(48px, 6vw, 88px) clamp(24px, 5vw, 64px)', background: 'var(--f2-surface)', ...style }}>
        <div style={{ maxWidth: 760, margin: '0 auto' }}>
          <div style={{ textAlign: 'center', marginBottom: 32 }}>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 14 }}><span style={{ width: 7, height: 7, borderRadius: 2, background: 'var(--f2-accent)' }} /><span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--f2-text-muted)' }}>{eyebrow}</span></div>
            <h2 style={{ margin: 0, fontFamily: 'var(--f2-font-display)', fontWeight: 600, fontSize: 'clamp(26px, 3.5vw, 38px)', letterSpacing: '-0.03em', color: 'var(--f2-text)' }}>{title}</h2>
          </div>
          <Accordion items={f} defaultOpen={[0]} />
        </div>
      </section>
    );
  }

  /* ====================== Footer ====================== */
  function Footer({ style = {} }) {
    const cols = [
      { h: 'Product', links: ['Automations', 'Agents', 'Observability', 'Pricing'] },
      { h: 'Company', links: ['Methodology', 'Work', 'Careers', 'Contact'] },
      { h: 'Resources', links: ['Docs', 'Brand', 'Status', 'Security'] },
    ];
    return (
      <footer style={{ padding: 'clamp(40px, 5vw, 64px) clamp(24px, 5vw, 64px) 28px', background: 'var(--f2-surface-sunken)', borderTop: '1px solid var(--f2-border)', ...style }}>
        <div style={{ maxWidth: 1100, margin: '0 auto' }}>
          <div style={{ display: 'grid', gridTemplateColumns: 'minmax(220px, 1.4fr) repeat(3, minmax(120px, 1fr))', gap: 40 }}>
            <div>
              <Logo />
              <p style={{ margin: '16px 0 0', fontSize: 14, lineHeight: 1.6, color: 'var(--f2-text-muted)', maxWidth: 280 }}>Engineered intelligence, built to fit. AI automation for teams that have outgrown off-the-shelf tools.</p>
            </div>
            {cols.map((c) => (
              <div key={c.h}>
                <div style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 11, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--f2-text-faint)', marginBottom: 14 }}>{c.h}</div>
                <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 10 }}>
                  {c.links.map((l) => <li key={l}><a href="#" onClick={(e) => e.preventDefault()} style={{ fontSize: 14, color: 'var(--f2-text-secondary)', textDecoration: 'none' }}>{l}</a></li>)}
                </ul>
              </div>
            ))}
          </div>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, marginTop: 40, paddingTop: 22, borderTop: '1px solid var(--f2-border)' }}>
            <span style={{ fontFamily: 'var(--f2-font-mono)', fontSize: 12, color: 'var(--f2-text-faint)' }}>© 2026 F2 Tecnologia · São Paulo</span>
            <div style={{ display: 'flex', gap: 8 }}>
              {['Github', 'Linkedin', 'Twitter'].map((s) => <a key={s} href="#" onClick={(e) => e.preventDefault()} aria-label={s} style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 34, height: 34, borderRadius: 8, border: '1px solid var(--f2-border)', color: 'var(--f2-text-muted)' }}><Icon name={s} size={16} /></a>)}
            </div>
          </div>
        </div>
      </footer>
    );
  }

  Object.assign(window.F2, { Navbar, Hero, FeatureGrid, FeatureCard, PricingCard, Pricing, Testimonial, CTASection, LogoCloud, FAQ, Footer });
})();
