/* global React, Icon, Button, Eyebrow, Badge, Droplets, Container */

// Sub-brand tokens — Bienes Raíces (referenced from window)
const BRb = window.BR || {
  deep:   '#7C3A10',
  mid:    '#C4602A',
  glow:   '#F2A472',
  bg:     '#FEF3EA',
  bgDark: '#3A1808',
};

// ============================================================
// EL EMBUDO INMOBILIARIO
// ============================================================
function BrEmbudo() {
  const steps = [
    {
      n: '01', icon: 'megaphone',
      title: 'Anuncio donde busca tu comprador',
      body: 'Meta Ads, Google, Inmuebles24 y Lamudi — con Smart Ads AI optimizando puja y segmentación por zona, rango de precio e intent de compra en tiempo real.',
      tag: 'Meta · Google · Portales',
    },
    {
      n: '02', icon: 'message',
      title: 'Lead Engine capta y cualifica en automático',
      body: 'En menos de 3 minutos la IA inicia conversación por WhatsApp: presupuesto, plazo, zona, forma de pago. Sin que tu equipo levante un dedo.',
      tag: 'WhatsApp API · Lead Engine',
    },
    {
      n: '03', icon: 'sparkles',
      title: 'Score inmobiliario: A, B o C',
      body: 'Calificación basada en capacidad de pago real, plazo de decisión, zona de interés y señales de compra activas. Solo A y B llegan a tu asesor.',
      tag: 'BANT · Score IA',
    },
    {
      n: '04', icon: 'users',
      title: 'Asesor recibe contexto completo',
      body: 'No "un lead del portal". Sino: Gabriela, 38 años, busca depto 3 rec en Polanco, presupuesto $5–7M, plazo 3 meses, pre-aprobada hipotecaria.',
      tag: 'CRM · Contexto 360°',
    },
    {
      n: '05', icon: 'home',
      title: 'Cita en sala de ventas — o cierre virtual',
      body: 'Con NeuroCopy Lab redactando el seguimiento, la tasa de lead a cita mejora entre 1.5× y 2×. Tu asesor entra cuando el lead ya quiere comprar.',
      tag: 'NeuroCopy · Conversión',
    },
  ];

  return (
    <section id="embudo" style={{ background: '#fff' }}>
      <Container style={{ padding: '100px 32px' }}>
        <div style={{ maxWidth: 720, marginBottom: 52 }}>
          <Eyebrow color={BRb.mid}>EL EMBUDO INMOBILIARIO IA</Eyebrow>
          <h2 style={{
            fontFamily: 'var(--font-display)', fontWeight: 700,
            fontSize: 'clamp(28px, 3.6vw, 48px)',
            lineHeight: 1.05, letterSpacing: '-0.03em',
            margin: '14px 0 0', color: 'var(--fg1)',
          }}>
            Del anuncio a la firma.{' '}
            <span style={{ color: BRb.deep }}>Automatizado en cada paso.</span>
          </h2>
        </div>

        <div style={{ display: 'flex', flexDirection: 'column', gap: 14, maxWidth: 980 }}>
          {steps.map((s, i) => (
            <div key={s.n} style={{
              background: 'var(--ink-25)', border: '1px solid var(--border)',
              borderRadius: 22, padding: '22px 28px',
              display: 'grid', gridTemplateColumns: '68px 1fr auto',
              gap: 28, alignItems: 'center',
              transition: 'all var(--dur-base) var(--ease-out)',
            }}
              onMouseEnter={e => {
                e.currentTarget.style.borderColor = BRb.mid;
                e.currentTarget.style.boxShadow = 'var(--shadow-md)';
                e.currentTarget.style.background = '#fff';
              }}
              onMouseLeave={e => {
                e.currentTarget.style.borderColor = 'var(--border)';
                e.currentTarget.style.boxShadow = '';
                e.currentTarget.style.background = 'var(--ink-25)';
              }}>

              {/* Step number + icon */}
              <div style={{ textAlign: 'center' }}>
                <div style={{
                  fontFamily: 'var(--font-mono)', fontSize: 10.5, fontWeight: 600,
                  color: 'var(--fg3)', letterSpacing: '0.06em', marginBottom: 8,
                }}>{s.n}</div>
                <div style={{
                  width: 44, height: 44, borderRadius: 12,
                  background: i === steps.length - 1 ? BRb.deep : BRb.bg,
                  color: i === steps.length - 1 ? '#fff' : BRb.deep,
                  display: 'grid', placeItems: 'center', margin: '0 auto',
                }}>
                  <Icon name={s.icon} size={20} />
                </div>
              </div>

              {/* Content */}
              <div>
                <h3 style={{
                  fontFamily: 'var(--font-display)', fontSize: 19, fontWeight: 700,
                  letterSpacing: '-0.02em', margin: '0 0 7px', color: 'var(--fg1)',
                }}>{s.title}</h3>
                <p style={{ fontSize: 14.5, lineHeight: 1.55, color: 'var(--fg2)', margin: 0 }}>{s.body}</p>
              </div>

              {/* Tag */}
              <div style={{
                fontFamily: 'var(--font-mono)', fontSize: 11, padding: '5px 12px',
                background: '#fff', border: '1px solid var(--border)', borderRadius: 8,
                color: 'var(--fg3)', whiteSpace: 'nowrap', flexShrink: 0,
              }}>{s.tag}</div>
            </div>
          ))}
        </div>
      </Container>
    </section>
  );
}

// ============================================================
// RESULTADOS
// ============================================================
function BrResultados() {
  const stats = [
    { n: '+40%', l: 'más citas de ventas agendadas al mes',        src: 'Pilotos inmobiliarios MX' },
    { n: '−3h',  l: 'por asesor al día en seguimiento manual',     src: 'WhatsApp automatizado' },
    { n: '2×',   l: 'conversión de lead a cita con NeuroCopy',     src: 'A/B con neuromarketing' },
    { n: '−55%', l: 'leads fríos que consumen tiempo del equipo',  src: 'Calificación IA BANT' },
  ];

  return (
    <section style={{ background: 'var(--grad-deep)', color: '#fff', position: 'relative', overflow: 'hidden' }}>
      <div style={{
        position: 'absolute', right: -120, top: -100, width: 420, height: 420, borderRadius: 999,
        background: 'radial-gradient(circle, rgba(0,218,227,0.2), transparent 65%)',
      }} />
      <div style={{
        position: 'absolute', left: -140, bottom: -120, width: 460, height: 460, borderRadius: 999,
        background: `radial-gradient(circle, rgba(196,96,42,0.3), transparent 65%)`,
      }} />
      <Container style={{ padding: '100px 32px', position: 'relative' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 40, marginBottom: 60 }}>
          <div style={{ maxWidth: 680 }}>
            <Eyebrow dark>RESULTADOS · MERCADO INMOBILIARIO</Eyebrow>
            <h2 style={{
              fontFamily: 'var(--font-display)', fontSize: 'clamp(28px, 3.8vw, 50px)', fontWeight: 700,
              letterSpacing: '-0.03em', lineHeight: 1.05, margin: '16px 0 16px', color: '#fff',
            }}>
              Lo que cambia cuando dejas de perseguir leads y empiezas a recibirlos.
            </h2>
            <p style={{ fontSize: 16, color: 'rgba(255,255,255,0.7)', lineHeight: 1.55, margin: 0, maxWidth: 500 }}>
              Datos de pilotos con desarrolladoras e inmobiliarias en México. Sin promesas vacías.
            </p>
          </div>
          <Button variant="inverse" size="md" icon="arrow-right">Ver casos de éxito</Button>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 22 }}>
          {stats.map((s, i) => (
            <div key={i} style={{
              background: 'rgba(255,255,255,0.06)', border: '1px solid rgba(255,255,255,0.12)',
              borderRadius: 24, padding: '28px 24px', backdropFilter: 'blur(8px)',
            }}>
              <div style={{
                fontFamily: 'var(--font-display)', fontWeight: 700,
                fontSize: 'clamp(40px, 4vw, 56px)', letterSpacing: '-0.035em',
                lineHeight: 1, color: 'var(--cyan-300)', marginBottom: 14,
              }}>{s.n}</div>
              <div style={{ fontSize: 15, lineHeight: 1.5, color: '#fff', marginBottom: 12 }}>{s.l}</div>
              <div style={{
                fontSize: 10.5, fontWeight: 600, letterSpacing: '0.12em',
                textTransform: 'uppercase', color: 'rgba(255,255,255,0.5)',
              }}>{s.src}</div>
            </div>
          ))}
        </div>
      </Container>
    </section>
  );
}

// ============================================================
// CASO DESTACADO
// ============================================================
function BrCaso() {
  return (
    <section style={{ background: 'var(--ink-50)' }}>
      <Container style={{ padding: '100px 32px' }}>
        <Eyebrow color={BRb.mid}>CASO DESTACADO</Eyebrow>
        <div style={{
          marginTop: 28, background: '#fff', borderRadius: 32,
          border: '1px solid var(--border)', overflow: 'hidden',
          display: 'grid', gridTemplateColumns: '1fr 1fr',
        }}>

          {/* Left — quote */}
          <div style={{ padding: '52px 52px 52px', position: 'relative', overflow: 'hidden' }}>
            <Droplets style={{ left: -40, bottom: -30 }} color={BRb.glow} opacity={0.45} size={200} />
            <div style={{ position: 'relative' }}>
              <div style={{ marginBottom: 24 }}>
                <Icon name="quote" size={40} style={{ color: BRb.glow }} />
              </div>
              <blockquote style={{
                fontFamily: 'var(--font-display)', fontSize: 'clamp(19px, 2vw, 26px)',
                fontWeight: 700, lineHeight: 1.3, letterSpacing: '-0.02em',
                margin: '0 0 32px', color: 'var(--fg1)',
              }}>
                "Antes recibíamos 200 leads al mes y cerrábamos 3. Hoy con 150 leads cerramos 8. El cambio fue la calificación automática."
              </blockquote>
              <div>
                <div style={{ fontWeight: 700, fontSize: 16, color: 'var(--fg1)' }}>Director Comercial</div>
                <div style={{ fontSize: 13.5, color: 'var(--fg3)', marginTop: 4 }}>Desarrolladora boutique · Zona Valle, CDMX</div>
              </div>
              <div style={{ marginTop: 28 }}>
                <a style={{
                  display: 'inline-flex', alignItems: 'center', gap: 6,
                  fontSize: 14, fontWeight: 600, color: BRb.mid, cursor: 'pointer',
                }}>
                  Ver caso completo <Icon name="arrow-right" size={14} />
                </a>
              </div>
            </div>
          </div>

          {/* Right — metrics */}
          <div style={{
            background: `linear-gradient(160deg, ${BRb.bgDark} 0%, #1a0a04 100%)`,
            padding: '52px 48px', color: '#fff',
            position: 'relative', overflow: 'hidden',
          }}>
            <Droplets style={{ right: -40, top: -20 }} color={BRb.glow} opacity={0.22} size={180} />
            <div style={{ position: 'relative' }}>
              <div style={{
                fontSize: 10.5, fontWeight: 700, letterSpacing: '0.14em',
                textTransform: 'uppercase', color: BRb.glow, marginBottom: 32,
              }}>RESULTADOS · 90 DÍAS</div>

              <div style={{ display: 'flex', flexDirection: 'column', gap: 28 }}>
                {[
                  { label: 'Leads calificados A/B', before: '22%', after: '61%' },
                  { label: 'Tasa de cita agendada',  before: '8%',  after: '19%' },
                  { label: 'Cierres por mes',         before: '3',   after: '8' },
                ].map(m => (
                  <div key={m.label}>
                    <div style={{ fontSize: 12, color: 'rgba(255,255,255,0.55)', letterSpacing: '0.04em', marginBottom: 10 }}>{m.label}</div>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
                      <div style={{
                        fontFamily: 'var(--font-display)', fontWeight: 700,
                        fontSize: 30, color: 'rgba(255,255,255,0.38)',
                        letterSpacing: '-0.025em', lineHeight: 1,
                      }}>{m.before}</div>
                      <Icon name="arrow-right" size={18} style={{ color: 'rgba(255,255,255,0.28)' }} />
                      <div style={{
                        fontFamily: 'var(--font-display)', fontWeight: 700,
                        fontSize: 40, color: BRb.glow,
                        letterSpacing: '-0.03em', lineHeight: 1,
                      }}>{m.after}</div>
                    </div>
                  </div>
                ))}
              </div>
            </div>
          </div>
        </div>
      </Container>
    </section>
  );
}

// ============================================================
// CTA FINAL
// ============================================================
function BrCta({ onCta }) {
  return (
    <section style={{ background: BRb.bg, position: 'relative', overflow: 'hidden' }}>
      <Droplets style={{ right: -60, top: -40 }} color={BRb.glow} opacity={0.55} size={260} />
      <Droplets style={{ left: -80, bottom: -60 }} color={BRb.mid} opacity={0.16} size={300} />
      <Container style={{ padding: '100px 32px', position: 'relative' }}>
        <div style={{ maxWidth: 760, margin: '0 auto', textAlign: 'center' }}>

          <div style={{
            display: 'inline-flex', alignItems: 'center', gap: 8,
            background: '#fff', border: `1px solid ${BRb.glow}`,
            borderRadius: 999, padding: '5px 16px',
            fontSize: 11, fontWeight: 700, letterSpacing: '0.14em',
            textTransform: 'uppercase', color: BRb.deep, marginBottom: 28,
          }}>
            <Icon name="sparkles" size={12} />
            DIAGNÓSTICO INMOBILIARIO · GRATIS
          </div>

          <h2 style={{
            fontFamily: 'var(--font-display)', fontWeight: 700,
            fontSize: 'clamp(32px, 5vw, 62px)',
            lineHeight: 1.04, letterSpacing: '-0.035em',
            margin: '0 0 20px', color: 'var(--fg1)',
          }}>
            30 minutos para saber<br />
            <span style={{ color: BRb.deep, fontStyle: 'italic' }}>qué está fallando en tu embudo.</span>
          </h2>

          <p style={{ fontSize: 18, lineHeight: 1.6, color: 'var(--fg2)', maxWidth: 540, margin: '0 auto 36px' }}>
            Un estratega FRSKO con experiencia en bienes raíces revisa tu proceso actual y te dice — sin pitch — qué cambiaría primero.
          </p>

          <div style={{ display: 'flex', gap: 14, justifyContent: 'center', flexWrap: 'wrap', marginBottom: 28 }}>
            <Button variant="cta" size="lg" icon="arrow-right" onClick={onCta}>
              Agendar diagnóstico gratuito
            </Button>
            <Button variant="ghost" size="lg" icon="arrow-up-right">
              Ver casos de éxito
            </Button>
          </div>

          <div style={{ display: 'flex', gap: 24, justifyContent: 'center', flexWrap: 'wrap' }}>
            {[
              'Sin costo · Sin compromiso',
              'Respuesta en menos de 24h',
              'Estratega con experiencia inmobiliaria',
            ].map(t => (
              <div key={t} style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13, color: 'var(--fg3)' }}>
                <Icon name="check" size={13} stroke={2} style={{ color: BRb.deep }} />
                {t}
              </div>
            ))}
          </div>
        </div>
      </Container>
    </section>
  );
}

// ============================================================
// OTRAS INDUSTRIAS (cross-links)
// ============================================================
function BrOtrasIndustrias() {
  const other = [
    { icon: 'shopping',    label: 'Retail & E-commerce',   sub: 'Creatividades que no se queman. Retail Media + neuromarketing.' },
    { icon: 'credit-card', label: 'Fintech & Servicios',   sub: 'Leads pre-calificados. Nurturing regulado y medible.' },
    { icon: 'heart',       label: 'Salud',                  sub: 'Captación de pacientes con contenido educativo y medible.' },
    { icon: 'scale',       label: 'Legal',                  sub: 'Autoridad digital para despachos. SEO especializado.' },
  ];

  return (
    <section style={{ background: '#fff', borderTop: '1px solid var(--border)' }}>
      <Container style={{ padding: '80px 32px' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 36 }}>
          <div>
            <Eyebrow>OTRAS INDUSTRIAS</Eyebrow>
            <h3 style={{
              fontFamily: 'var(--font-display)', fontSize: 'clamp(22px, 2.8vw, 34px)', fontWeight: 700,
              letterSpacing: '-0.025em', margin: '10px 0 0', color: 'var(--fg1)',
            }}>Llegamos con playbooks ya probados en cada vertical.</h3>
          </div>
          <Button variant="ghost" size="md" icon="arrow-right">Ver todas las industrias</Button>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
          {other.map(v => (
            <div key={v.label} style={{
              background: 'var(--ink-25)', border: '1px solid var(--border)', borderRadius: 20,
              padding: '22px 22px 24px', display: 'flex', flexDirection: 'column', gap: 12,
              transition: 'all var(--dur-base) var(--ease-out)', cursor: 'pointer',
            }}
              onMouseEnter={e => { e.currentTarget.style.boxShadow = 'var(--shadow-sm)'; e.currentTarget.style.borderColor = 'var(--teal-200)'; e.currentTarget.style.transform = 'translateY(-2px)'; }}
              onMouseLeave={e => { e.currentTarget.style.boxShadow = ''; e.currentTarget.style.borderColor = 'var(--border)'; e.currentTarget.style.transform = ''; }}>
              <div style={{
                width: 40, height: 40, borderRadius: 12,
                background: 'var(--teal-50)', color: 'var(--brand)',
                display: 'grid', placeItems: 'center',
              }}>
                <Icon name={v.icon} size={18} />
              </div>
              <div>
                <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 16, color: 'var(--fg1)', marginBottom: 5 }}>{v.label}</div>
                <div style={{ fontSize: 13, lineHeight: 1.5, color: 'var(--fg3)' }}>{v.sub}</div>
              </div>
            </div>
          ))}
        </div>
      </Container>
    </section>
  );
}

Object.assign(window, { BrEmbudo, BrResultados, BrCaso, BrCta, BrOtrasIndustrias });
