// Sellcore — Inversiones inmobiliarias · modelo FLIPPING (/inversiones/).
// Contenido PLACEHOLDER: reemplaza textos y oportunidades por los reales.
const { Ico } = window.SC_Site;

// Oportunidades desde el archivo compartido (inversiones-data.js).
const OPORTUNIDADES = (window.SC_INVERSIONES && window.SC_INVERSIONES.oportunidades) || [];

// Scroll horizontal por flecha. Instantáneo + acotado (robusto; evita el bug de
// scrollBy 'smooth' + scroll-snap mandatory que dejaba el slider sin moverse).
function scSlide(el, dx) {
  if (!el) return;
  const max = el.scrollWidth - el.clientWidth;
  el.scrollLeft = Math.max(0, Math.min(max, el.scrollLeft + dx));
}

// Observa si un slider tiene contenido que desborde (para mostrar/ocultar flechas).
function scWatch(ref, setScrollable) {
  const el = ref.current;
  if (!el) return undefined;
  const check = () => setScrollable(el.scrollWidth > el.clientWidth + 40);
  check();
  window.addEventListener('resize', check);
  return () => window.removeEventListener('resize', check);
}

// -------------------------------------------------- Barra de financiamiento
function Progreso({ valor, dark }) {
  const cerrado = valor >= 100;
  return (
    <div>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
        <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.05em', textTransform: 'uppercase', color: dark ? 'var(--text-on-dark-muted)' : 'var(--text-muted)' }}>
          {cerrado ? 'Financiado · cerrado' : 'Financiado · abierto'}
        </span>
        <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 14, color: dark ? 'var(--white)' : 'var(--ink-900)' }}>{valor}%</span>
      </div>
      <div style={{ height: 8, borderRadius: 99, background: dark ? 'rgba(255,255,255,0.14)' : 'var(--ink-100)', overflow: 'hidden' }}>
        <div style={{ height: '100%', width: valor + '%', borderRadius: 99, background: 'var(--brand-gradient)', transition: 'width .5s ease' }} />
      </div>
    </div>
  );
}

// -------------------------------------------------- Grilla de oportunidades
function OportunidadesSlider({ onOpen }) {
  return (
    <section style={{ background: 'var(--surface-app)', padding: '84px 28px', borderTop: '1px solid var(--border-default)' }}>
      <div style={{ maxWidth: 'var(--container-2xl)', margin: '0 auto' }}>
        <span className="sc-eyebrow">Oportunidades</span>
        <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'clamp(28px, 6.2vw, 40px)', letterSpacing: '-0.025em', margin: '14px 0 0', color: 'var(--ink-900)' }}>
          Oportunidades de flipping
        </h2>

        <div style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'center', gap: 24, marginTop: 32 }}>
          {OPORTUNIDADES.map((o) => (
            <window.SC.Card key={o.id} interactive elevation="flat" padding="none" onClick={() => onOpen(o)} style={{ overflow: 'hidden', cursor: 'pointer', flex: '1 1 340px', maxWidth: 500 }}>
              <div style={{ height: 170, background: 'linear-gradient(135deg, var(--ink-050), var(--ink-100))', display: 'grid', placeItems: 'center', color: 'var(--ink-300)', position: 'relative' }}>
                {o.foto
                  ? <img src={o.foto} alt={o.titulo} loading="lazy" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
                  : <Ico name={o.icono} size={54} stroke={1.4} />}
                <div style={{ position: 'absolute', top: 12, left: 12, fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase', color: '#fff', background: 'var(--brand-gradient)', padding: '4px 9px', borderRadius: 99 }}>Flipping</div>
              </div>
              <div style={{ padding: 22 }}>
                <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{o.tipo} · {o.superficie}</div>
                <h3 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 22, margin: '6px 0 6px', color: 'var(--ink-900)' }}>{o.titulo}</h3>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13, color: 'var(--text-body)', marginBottom: 18 }}>
                  <Ico name="MapPin" size={14} />{o.comuna}
                </div>
                <Progreso valor={o.progreso} />
                <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '14px 12px', margin: '20px 0 0', paddingTop: 16, borderTop: '1px solid var(--border-subtle)' }}>
                  <Stat label="Retorno estimado" value={o.retorno} accent />
                  <Stat label="Plazo estimado" value={o.plazo} />
                </div>
                <window.SC.Button variant="accent" size="sm" onClick={() => onOpen(o)} style={{ width: '100%', marginTop: 20 }} trailingIcon={<Ico name="ArrowRight" size={14} />}>Ver oportunidad e invertir</window.SC.Button>
              </div>
            </window.SC.Card>
          ))}
        </div>

        <p style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 22, maxWidth: 720 }}>
          * Oportunidades y cifras <strong>referenciales</strong>, con fines ilustrativos. No constituyen asesoría financiera ni una oferta de inversión.
          Edita la lista en <code>inversiones-data.js</code>.
        </p>
      </div>
    </section>
  );
}

function Stat({ label, value, accent }) {
  return (
    <div>
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{label}</div>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: accent ? 22 : 16, color: accent ? 'var(--brand-green)' : 'var(--ink-900)', marginTop: 3 }}>{value}</div>
    </div>
  );
}

// -------------------------------------------------- Detalle de la casa (modal)
function PropiedadModal({ opp, onClose }) {
  const [c, setC] = React.useState({});
  React.useEffect(() => { setC({}); }, [opp && opp.id]);
  if (!opp) return null;

  const EMAIL = (typeof window !== 'undefined' && window.SC_CART_CONTACT_EMAIL) || 'ventas@sellcore.cl';
  const field = (label, key, opts) => {
    opts = opts || {};
    return (
      <div style={{ marginBottom: 12 }}>
        <label style={{ display: 'block', fontSize: 12, fontWeight: 600, color: 'var(--ink-700)', marginBottom: 5 }}>{label}{opts.req ? ' *' : ''}</label>
        {opts.area
          ? <textarea rows={3} value={c[key] || ''} onChange={(e) => setC({ ...c, [key]: e.target.value })} placeholder={opts.ph || ''} style={inp} />
          : <input type={opts.type || 'text'} value={c[key] || ''} onChange={(e) => setC({ ...c, [key]: e.target.value })} placeholder={opts.ph || ''} style={inp} />}
      </div>
    );
  };
  const enviar = () => {
    if (!c.nombre || !c.email || !c.telefono) return toast('Completa nombre, email y teléfono.');
    if (!/.+@.+\..+/.test(c.email)) return toast('Ingresa un email válido.');
    const cuerpo =
      'Interés de inversión en: ' + opp.titulo + ' (' + opp.id + ')\n' + opp.comuna + ' · ' + opp.tipo + '\n\n' +
      'Nombre: ' + c.nombre + '\nEmail: ' + c.email + '\nTeléfono: ' + c.telefono + '\n' +
      'Monto a invertir: ' + (c.monto || '-') + '\n\nMensaje:\n' + (c.mensaje || '-') + '\n';
    window.location.href = 'mailto:' + EMAIL + '?subject=' + encodeURIComponent('Inversión — ' + opp.titulo + ' (Sellcore)') + '&body=' + encodeURIComponent(cuerpo);
    onClose();
    toast('Abrimos tu correo para enviar tu interés en ' + opp.titulo + '.');
  };

  return (
    <div onClick={onClose} style={{ position: 'fixed', inset: 0, zIndex: 200, background: 'rgba(11,18,32,0.55)', backdropFilter: 'blur(4px)', display: 'grid', placeItems: 'center', padding: 24 }}>
      <div onClick={(e) => e.stopPropagation()} style={{ background: 'var(--white)', borderRadius: 'var(--radius-2xl)', boxShadow: 'var(--shadow-xl)', width: 'min(760px, 100%)', maxHeight: '90vh', overflow: 'auto' }}>
        <div style={{ position: 'relative', height: 190, background: 'linear-gradient(135deg, var(--ink-050), var(--ink-100))', display: 'grid', placeItems: 'center', color: 'var(--ink-300)' }}>
          {opp.foto
            ? <img src={opp.foto} alt={opp.titulo} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
            : <Ico name={opp.icono} size={60} stroke={1.4} />}
          <div style={{ position: 'absolute', top: 14, left: 14, fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.1em', textTransform: 'uppercase', color: '#fff', background: 'var(--brand-gradient)', padding: '4px 9px', borderRadius: 99 }}>Flipping</div>
          <button onClick={onClose} aria-label="Cerrar" style={{ position: 'absolute', top: 14, right: 14, width: 36, height: 36, borderRadius: 10, border: 'none', background: 'rgba(255,255,255,0.9)', cursor: 'pointer', display: 'grid', placeItems: 'center', color: 'var(--ink-800)', boxShadow: 'var(--shadow-md)' }}><Ico name="X" size={18} /></button>
        </div>

        <div style={{ padding: 28 }}>
          <span style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--text-muted)' }}>{opp.tipo} · {opp.superficie} · {opp.comuna}</span>
          <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 30, letterSpacing: '-0.02em', margin: '8px 0 16px', color: 'var(--ink-900)' }}>{opp.titulo}</h2>

          <Progreso valor={opp.progreso} />

          {/* Desglose de la inversión */}
          <div className="sc-eyebrow" style={{ margin: '26px 0 12px' }}>Detalle de la inversión</div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: '14px 20px' }}>
            <Stat label="Valor de compra" value={opp.valorCompra} />
            <Stat label="Renovación" value={opp.valorRenovacion} />
            <Stat label="Venta estimada" value={opp.valorVentaEstimado} />
            <Stat label="Utilidad estimada" value={opp.utilidadEstimada} accent />
            <Stat label="Retorno estimado" value={opp.retorno} accent />
            <Stat label="Plazo" value={opp.plazo} />
            <Stat label="Inversión mínima" value={opp.inversionMinima} />
          </div>

          {/* Etapas */}
          <div className="sc-eyebrow" style={{ margin: '26px 0 12px' }}>Etapas del proyecto</div>
          <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
            {opp.etapas.map(([nombre, estado]) => {
              const done = estado === 'Completado', curso = estado === 'En curso';
              return (
                <div key={nombre} style={{ flex: '1 1 140px', border: '1px solid var(--border-default)', borderRadius: 'var(--radius-lg)', padding: '12px 14px' }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                    <Ico name={done ? 'CheckCircle2' : curso ? 'Loader' : 'Circle'} size={16} color={done ? 'var(--brand-green)' : curso ? 'var(--brand-cyan)' : 'var(--ink-300)'} />
                    <span style={{ fontWeight: 700, fontSize: 14, color: 'var(--ink-900)' }}>{nombre}</span>
                  </div>
                  <div style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 4 }}>{estado}</div>
                </div>
              );
            })}
          </div>

          {/* Resumen */}
          <p style={{ fontSize: 15, lineHeight: 1.6, color: 'var(--text-body)', margin: '24px 0 0' }}>{opp.resumen}</p>

          {/* Formulario de contacto */}
          <div style={{ marginTop: 28, borderTop: '1px solid var(--border-default)', paddingTop: 24 }}>
            <h3 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 22, margin: '0 0 4px', color: 'var(--ink-900)' }}>Habla con un asesor</h3>
            <p style={{ fontSize: 14, color: 'var(--text-muted)', margin: '0 0 18px' }}>Déjanos tus datos y te contactamos para invertir en esta propiedad.</p>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: '0 16px' }}>
              {field('Nombre', 'nombre', { req: true, ph: 'Tu nombre' })}
              {field('Email', 'email', { req: true, type: 'email', ph: 'correo@empresa.cl' })}
              {field('Teléfono', 'telefono', { req: true, type: 'tel', ph: '+56 9 ...' })}
              {field('Monto a invertir (opcional)', 'monto', { ph: '$' })}
            </div>
            {field('Mensaje', 'mensaje', { area: true, ph: 'Cuéntanos tu interés…' })}
            <div style={{ display: 'flex', gap: 12, marginTop: 8 }}>
              <window.SC.Button variant="accent" size="lg" onClick={enviar} trailingIcon={<Ico name="ArrowRight" size={16} />}>Enviar y contactar</window.SC.Button>
              <window.SC.Button variant="secondary" size="lg" onClick={onClose}>Cerrar</window.SC.Button>
            </div>
            <div style={{ fontSize: 11, color: 'var(--text-muted)', marginTop: 12 }}>Se enviará a {EMAIL}. Cifras referenciales; no constituyen asesoría ni oferta de inversión.</div>
          </div>
        </div>
      </div>
    </div>
  );
}

const inp = { width: '100%', boxSizing: 'border-box', padding: '10px 12px', borderRadius: 10, border: '1px solid var(--border-default)', fontFamily: 'var(--font-body)', fontSize: 14, color: 'var(--ink-900)', outline: 'none', background: 'var(--white)' };

// Toast simple para el formulario del modal.
function toast(msg) {
  if (typeof document === 'undefined') return;
  let el = document.getElementById('toast');
  if (!el) { el = document.createElement('div'); el.id = 'toast'; document.body.appendChild(el); }
  el.innerHTML = '';
  const card = document.createElement('div');
  card.style.cssText = 'background:var(--ink-900);color:#fff;padding:14px 20px;border-radius:14px;box-shadow:var(--shadow-xl);font-family:var(--font-body);font-weight:600;font-size:14px;display:flex;gap:10px;align-items:center';
  card.innerHTML = '<span style="width:8px;height:8px;border-radius:9px;background:var(--brand-green)"></span>' + msg;
  el.appendChild(card); el.classList.add('show');
  clearTimeout(window.__it); window.__it = setTimeout(() => el.classList.remove('show'), 2800);
}

// -------------------------------------------------- Comparativa + calculadora
const fmtCLP = (n) => '$' + Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
const fmtM = (n) => '$' + (n / 1e6).toFixed(1).replace('.', ',') + 'M';

// Retornos a 14 meses (referenciales) e índices mensuales (base 1).
const RET = { nosotros: 0.22, dap: 0.064, money: 0.055 };
const IDX = {
  nosotros: [1, 1.005, 1.01, 1.02, 1.03, 1.045, 1.06, 1.08, 1.105, 1.13, 1.155, 1.18, 1.20, 1.21, 1.22],
  dap: [1, 1.005, 1.009, 1.014, 1.018, 1.023, 1.027, 1.032, 1.037, 1.041, 1.046, 1.05, 1.055, 1.059, 1.064],
  money: [1, 1.004, 1.008, 1.012, 1.016, 1.02, 1.024, 1.028, 1.031, 1.035, 1.039, 1.043, 1.047, 1.051, 1.055],
};

function ComparativaChart({ monto }) {
  const meses = 14;
  const W = 1000, H = 210, pl = 14, pr = 18, pt = 22, pb = 26;
  const vmax = monto * 1.25, vmin = monto * 0.98;
  const X = (i) => pl + (i / meses) * (W - pl - pr);
  const Y = (v) => pt + (1 - (v - vmin) / (vmax - vmin)) * (H - pt - pb);
  const pts = (arr) => arr.map((r, i) => X(i) + ',' + Y(r * monto)).join(' ');
  const areaD = (arr) => 'M' + X(0) + ',' + Y(vmin) + ' L' + arr.map((r, i) => X(i) + ',' + Y(r * monto)).join(' L') + ' L' + X(meses) + ',' + Y(vmin) + ' Z';
  const series = [
    { label: 'Con Sellcore', color: '#00d454', width: 3.5, dash: null, idx: IDX.nosotros },
    { label: 'Depósito a plazo', color: '#8aa0b8', width: 2, dash: null, idx: IDX.dap },
    { label: 'Money market', color: '#66788f', width: 2, dash: '5 6', idx: IDX.money },
  ];
  const xTicks = [0, 7, 14];
  return (
    <div>
      <svg viewBox={'0 0 ' + W + ' ' + H} width="100%" style={{ display: 'block', overflow: 'visible' }} preserveAspectRatio="xMidYMid meet">
        <defs>
          <linearGradient id="areaG" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="#00d454" stopOpacity="0.28" />
            <stop offset="100%" stopColor="#00d454" stopOpacity="0" />
          </linearGradient>
        </defs>
        <line x1={pl} y1={Y(monto)} x2={W - pr} y2={Y(monto)} stroke="rgba(255,255,255,0.16)" strokeDasharray="4 5" strokeWidth="1" />
        <text x={pl} y={Y(monto) - 7} fill="rgba(255,255,255,0.55)" style={{ fontFamily: 'var(--font-mono)', fontSize: 11 }}>{fmtM(monto)} hoy</text>
        <path d={areaD(IDX.nosotros)} fill="url(#areaG)" />
        {series.map((s) => (
          <polyline key={s.label} points={pts(s.idx)} fill="none" stroke={s.color} strokeWidth={s.width} strokeDasharray={s.dash || undefined} strokeLinecap="round" strokeLinejoin="round" />
        ))}
        {series.map((s) => (
          <circle key={s.label + 'd'} cx={X(meses)} cy={Y(s.idx[meses] * monto)} r={s.width + 1} fill={s.color} />
        ))}
        <text x={X(meses)} y={Y(IDX.nosotros[meses] * monto) - 12} textAnchor="end" fill="#00d454" style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 15 }}>{fmtM(IDX.nosotros[meses] * monto)}</text>
        {xTicks.map((m) => (
          <text key={m} x={X(m)} y={H - pb + 20} textAnchor={m === 0 ? 'start' : m === meses ? 'end' : 'middle'} fill="rgba(255,255,255,0.5)" style={{ fontFamily: 'var(--font-mono)', fontSize: 11 }}>{m} meses</text>
        ))}
      </svg>
      <div style={{ display: 'flex', gap: 18, flexWrap: 'wrap', marginTop: 14 }}>
        {series.map((s) => (
          <div key={s.label} style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            <span style={{ width: 18, height: 4, borderRadius: 9, background: s.color, flex: 'none' }} />
            <span style={{ fontSize: 13, fontWeight: 600, color: 'var(--white)' }}>{s.label}</span>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: 12, fontWeight: 700, color: s.color === '#00d454' ? 'var(--brand-green)' : 'var(--text-on-dark-muted)' }}>+{((s.idx[meses] - 1) * 100).toFixed(1).replace('.', ',')}%</span>
          </div>
        ))}
      </div>
    </div>
  );
}

function Calculadora({ monto, setMonto }) {
  const util = monto * RET.nosotros;
  const total = monto + util;
  const vsDap = total - monto * (1 + RET.dap);
  return (
    <div>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
        <span className="sc-eyebrow" style={{ color: 'var(--brand-green)' }}>Calcula tu retorno</span>
        <span style={{ fontFamily: 'var(--font-mono)', fontSize: 12, color: 'var(--text-on-dark-muted)' }}>a 14 meses</span>
      </div>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'clamp(24px, 5.3vw, 34px)', color: 'var(--white)', margin: '6px 0 2px' }}>{fmtCLP(monto)}</div>
      <input type="range" min={1000000} max={100000000} step={1000000} value={monto} onChange={(e) => setMonto(+e.target.value)}
        style={{ width: '100%', accentColor: 'var(--brand-green)', margin: '10px 0 4px' }} />
      <div style={{ display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: 11, color: 'var(--text-on-dark-muted)' }}>
        <span>$1M</span><span>$100M</span>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, marginTop: 18 }}>
        <div style={{ border: '1px solid var(--border-inverse)', borderRadius: 'var(--radius-lg)', padding: '14px 16px' }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.06em', textTransform: 'uppercase', color: 'var(--text-on-dark-muted)' }}>Utilidad estimada (+22%)</div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 22, color: 'var(--brand-green)', marginTop: 3 }}>{fmtCLP(util)}</div>
        </div>
        <div style={{ border: '1px solid var(--border-inverse)', borderRadius: 'var(--radius-lg)', padding: '14px 16px' }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.06em', textTransform: 'uppercase', color: 'var(--text-on-dark-muted)' }}>Recibes al final</div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 22, color: 'var(--white)', marginTop: 3 }}>{fmtCLP(total)}</div>
        </div>
      </div>
      <div style={{ fontSize: 13, color: 'var(--text-on-dark-muted)', marginTop: 12 }}>
        Son <strong style={{ color: 'var(--white)' }}>{fmtCLP(vsDap)}</strong> más que en un depósito a plazo.
      </div>
    </div>
  );
}

// -------------------------------------------------- Sección "El modelo flipping"
function ModeloFlipping() {
  const [monto, setMonto] = React.useState(10000000);
  const etapas = [
    ['01', 'ShoppingBag', 'Compramos', 'Adquirimos propiedades bajo su valor de mercado, con potencial de revalorización.'],
    ['02', 'Hammer', 'Renovamos', 'Remodelación eficiente que maximiza el valor: terminaciones, distribución y eficiencia.'],
    ['03', 'TrendingUp', 'Vendemos', 'Comercializamos y distribuimos la utilidad entre los inversionistas.'],
  ];
  return (
    <section style={{ background: 'var(--ink-900)', color: 'var(--white)', padding: '84px 28px', borderTop: '1px solid var(--border-inverse)' }}>
      <div style={{ maxWidth: 'var(--container-2xl)', margin: '0 auto' }}>
        <span className="sc-eyebrow" style={{ color: 'var(--text-on-dark-muted)' }}>El modelo flipping</span>
        <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'clamp(28px, 6.2vw, 40px)', letterSpacing: '-0.025em', margin: '14px 0 0', color: 'var(--white)' }}>
          Cómo funciona y cuánto rinde.
        </h2>

        {/* Fila superior: proceso (izq) + calculadora (der) */}
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(340px, 1fr))', gap: 44, marginTop: 44, alignItems: 'stretch' }}>
          {/* Izquierda: cómo funciona (stepper vertical) */}
          <div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
            <div className="sc-eyebrow" style={{ marginBottom: 24 }}>Cómo funciona</div>
            {etapas.map(([n, icon, t, b], idx) => (
              <div key={n} style={{ display: 'flex', gap: 16, position: 'relative', paddingBottom: idx < 2 ? 28 : 0 }}>
                {idx < 2 && <div style={{ position: 'absolute', left: 26, top: 54, bottom: 0, width: 2, background: 'var(--border-inverse)' }} />}
                <div style={{ width: 52, height: 52, borderRadius: 14, background: 'rgba(255,255,255,0.08)', border: '1px solid var(--border-inverse)', display: 'grid', placeItems: 'center', color: 'var(--white)', flex: 'none', zIndex: 1 }}><Ico name={icon} size={22} /></div>
                <div>
                  <span style={{ fontFamily: 'var(--font-mono)', fontWeight: 700, fontSize: 13, color: 'var(--brand-cyan)' }}>{n}</span>
                  <h3 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 21, margin: '4px 0 6px', color: 'var(--white)' }}>{t}</h3>
                  <p style={{ fontSize: 14, lineHeight: 1.6, color: 'var(--text-on-dark-muted)', margin: 0, maxWidth: 380 }}>{b}</p>
                </div>
              </div>
            ))}
          </div>

          {/* Derecha: calculadora */}
          <div style={{ border: '1px solid var(--border-inverse)', borderRadius: 'var(--radius-2xl)', padding: 28, background: 'rgba(255,255,255,0.03)', display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
            <Calculadora monto={monto} setMonto={setMonto} />
          </div>
        </div>

        {/* Gráfico a lo ancho */}
        <div style={{ marginTop: 22, border: '1px solid var(--border-inverse)', borderRadius: 'var(--radius-2xl)', padding: 28, background: 'rgba(255,255,255,0.03)' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', flexWrap: 'wrap', gap: 8, marginBottom: 18 }}>
            <span className="sc-eyebrow" style={{ color: 'var(--text-on-dark-muted)' }}>Proyección a 14 meses</span>
            <span style={{ fontSize: 13, color: 'var(--text-on-dark-muted)' }}>Invertir con nosotros vs. instrumentos tradicionales</span>
          </div>
          <ComparativaChart monto={monto} />
        </div>

        <p style={{ fontSize: 12, color: 'var(--text-on-dark-muted)', marginTop: 18 }}>* Cifras y proyecciones referenciales, con fines ilustrativos. No constituyen asesoría ni oferta de inversión; rentabilidades pasadas o proyectadas no garantizan resultados futuros.</p>
      </div>
    </section>
  );
}

// -------------------------------------------------- Página
function InversionesPage({ onCta }) {
  const [sel, setSel] = React.useState(null);
  return (
    <React.Fragment>
      {/* Hero */}
      <section style={{ background: 'var(--ink-900)', color: 'var(--white)', position: 'relative', overflow: 'hidden' }}>
        <div style={{ position: 'absolute', top: -120, right: -80, width: 520, height: 520, background: 'radial-gradient(circle, rgba(62,123,240,0.28), transparent 62%)', filter: 'blur(20px)' }} />
        <div style={{ maxWidth: 'var(--container-2xl)', margin: '0 auto', padding: '84px 28px 76px', position: 'relative' }}>
          <span className="sc-eyebrow" style={{ color: 'var(--text-on-dark-muted)' }}>Inversiones inmobiliarias · Flipping</span>
          <h1 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'clamp(32px, 8.4vw, 54px)', letterSpacing: '-0.03em', lineHeight: 1.04, margin: '16px 0 0', color: 'var(--white)', maxWidth: 760 }}>
            Invierte en <span className="sc-gradient-text">flipping inmobiliario</span>.
          </h1>
          <p style={{ fontSize: 18, lineHeight: 1.55, color: 'var(--text-on-dark-muted)', margin: '20px 0 0', maxWidth: 620 }}>
            Compramos propiedades bajo su valor de mercado, las renovamos y las vendemos con plusvalía.
            Tú participas de la utilidad, con un modelo estructurado, plazos definidos y gestión profesional.
          </p>
          <div style={{ display: 'flex', gap: 12, marginTop: 32 }}>
            <window.SC.Button variant="accent" size="lg" onClick={onCta} trailingIcon={<Ico name="ArrowRight" size={17} />}>Quiero invertir</window.SC.Button>
          </div>
        </div>
      </section>

      {/* El modelo flipping: cómo funciona (izq) + calculadora y gráfico (der) */}
      <ModeloFlipping />

      {/* Oportunidades */}
      <OportunidadesSlider onOpen={setSel} />

      {/* CTA */}
      <section style={{ background: 'var(--white)', padding: '80px 28px', borderTop: '1px solid var(--border-default)' }}>
        <div style={{ maxWidth: 'var(--container-xl)', margin: '0 auto', borderRadius: 'var(--radius-2xl)', background: 'var(--brand-gradient)', padding: '2px', boxShadow: 'var(--shadow-lg)' }}>
          <div style={{ background: 'var(--ink-900)', borderRadius: 'calc(var(--radius-2xl) - 2px)', padding: '52px 52px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 32, flexWrap: 'wrap' }}>
            <div style={{ maxWidth: 560 }}>
              <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 'clamp(24px, 5.3vw, 34px)', letterSpacing: '-0.025em', lineHeight: 1.1, margin: 0, color: 'var(--white)' }}>
                Conversemos sobre tu inversión
              </h2>
              <p style={{ fontSize: 16, color: 'var(--text-on-dark-muted)', margin: '12px 0 0' }}>
                Déjanos tus datos y un asesor te presentará las oportunidades de flipping disponibles.
              </p>
            </div>
            <window.SC.Button variant="accent" size="lg" onClick={onCta} trailingIcon={<Ico name="ArrowRight" size={17} />}>Contactar a un asesor</window.SC.Button>
          </div>
        </div>
      </section>

      <PropiedadModal opp={sel} onClose={() => setSel(null)} />
    </React.Fragment>
  );
}

window.SC_InvPage = { InversionesPage };
