// rbd-main.jsx — All page sections + App root
const { useState, useEffect, useRef } = React;

// ── Helpers ───────────────────────────────────────────────────────────────────
function Label({ children, light = false }) {
  return (
    <span style={{
      display: 'inline-block', fontFamily: 'Montserrat,sans-serif',
      fontWeight: 500, fontSize: '10px', letterSpacing: '0.32em',
      color: light ? 'var(--accent,rgba(255,255,255,0.45))' : 'rgba(0,0,0,0.35)',
      textTransform: 'uppercase', marginBottom: '20px'
    }}>{children}</span>);

}

function Btn({ children, onClick, variant = 'outlineLight', style = {} }) {
  const [hov, setHov] = useState(false);
  const variants = {
    outlineLight: { bg: hov ? '#fff' : 'transparent', color: hov ? '#000' : '#fff', border: '1px solid rgba(255,255,255,0.55)' },
    solidLight: { bg: hov ? 'transparent' : '#fff', color: hov ? '#fff' : '#000', border: '1px solid #fff' },
    outlineDark: { bg: hov ? '#000' : 'transparent', color: hov ? '#fff' : '#000', border: '1px solid rgba(0,0,0,0.7)' },
    solidDark: { bg: hov ? 'transparent' : '#000', color: hov ? '#000' : '#fff', border: '1px solid #000' },
    whatsapp: { bg: hov ? '#1da851' : '#25D366', color: '#fff', border: 'none' }
  };
  const v = variants[variant] || variants.outlineLight;
  return (
    <button onClick={onClick}
    onMouseEnter={() => setHov(true)} onMouseLeave={() => setHov(false)}
    style={{
      fontFamily: 'Montserrat,sans-serif', fontWeight: 600,
      fontSize: '11px', letterSpacing: '0.22em', textTransform: 'uppercase',
      padding: '17px 44px', cursor: 'pointer',
      background: v.bg, color: v.color, border: v.border,
      transition: 'all 0.32s cubic-bezier(0.22,1,0.36,1)',
      display: 'inline-flex', alignItems: 'center', gap: '10px',
      ...style
    }}>{children}</button>);

}

// ── HERO ──────────────────────────────────────────────────────────────────────
function HeroSection({ navigate }) {
  return (
    <section id="home" style={{
      position: 'relative', height: '100svh', minHeight: '560px', overflow: 'hidden',
    }}>
      {/* ── Foto de fundo — dessaturada e discreta ── */}
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: 'url(hero.jpg)',
        backgroundSize: 'cover', backgroundPosition: 'center 60%',
        filter: 'grayscale(80%) brightness(0.55)',
      }} />

      {/* Overlay escuro para focar no CTA */}
      <div style={{
        position: 'absolute', inset: 0,
        background: 'linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.5) 100%)',
      }} />

      {/* ── CTA centralizado ── */}
      <div style={{
        position: 'absolute', inset: 0, zIndex: 1,
        display: 'flex', flexDirection: 'column',
        alignItems: 'center', justifyContent: 'center',
        textAlign: 'center', padding: '0 24px',
      }}>
        {/* Tagline */}
        <p style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
          fontSize: '10px', letterSpacing: '0.42em',
          color: 'rgba(255,255,255,0.45)', textTransform: 'uppercase',
          margin: '0 0 24px',
        }}>RBD Arquitetura &amp; Interiores</p>

        <h2 style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 700,
          fontSize: 'clamp(24px, 3.2vw, 44px)', lineHeight: 1.3,
          letterSpacing: '-0.02em', color: '#fff',
          margin: '0 0 28px', maxWidth: '680px',
        }}>A boa <span style={{ fontSize: '1em' }}>ARQUITETURA</span> vai muito além da planta.</h2>

        <p style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
          fontSize: 'clamp(13px, 1.4vw, 17px)', letterSpacing: '0.04em',
          color: 'rgba(255,255,255,0.55)', margin: '0 0 52px', maxWidth: '480px', lineHeight: 1.7,
        }}>Integramos arquitetura, construção e interiores para que você viva todo o processo com mais segurança, organização e tranquilidade.</p>

        {/* WhatsApp CTA */}
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '10px', marginBottom: '36px' }}>
          <a href="https://wa.me/5542988708525?text=Olá,%20gostaria%20de%20conversar%20sobre%20um%20projeto."
            target="_blank" rel="noopener noreferrer"
            style={{
              display: 'inline-flex', alignItems: 'center', gap: '12px',
              background: '#25D366', color: '#fff',
              fontFamily: 'Montserrat,sans-serif', fontWeight: 700,
              fontSize: '12px', letterSpacing: '0.2em', textTransform: 'uppercase',
              padding: '20px 52px', textDecoration: 'none',
              transition: 'background 0.28s ease, transform 0.22s ease',
              boxShadow: '0 8px 32px rgba(37,211,102,0.28)',
            }}
            onMouseEnter={e => { e.currentTarget.style.background = '#1da851'; e.currentTarget.style.transform = 'translateY(-2px)'; }}
            onMouseLeave={e => { e.currentTarget.style.background = '#25D366'; e.currentTarget.style.transform = 'translateY(0)'; }}>
            <svg width="20" height="20" viewBox="0 0 22 22" fill="currentColor">
              <path d="M11 0C4.925 0 0 4.925 0 11c0 1.94.505 3.76 1.388 5.337L.05 21.5l5.313-1.318A10.94 10.94 0 0011 22c6.075 0 11-4.925 11-11S17.075 0 11 0zm5.46 15.54c-.23.644-1.344 1.232-1.847 1.27-.503.04-1.008.192-3.405-.713-2.86-1.09-4.68-4.02-4.82-4.208-.142-.19-1.148-1.527-1.148-2.912s.726-2.07.984-2.357c.258-.286.563-.358.75-.358.188 0 .375.002.54.01.173.008.405-.066.633.483.23.55.78 1.9.85 2.038.07.138.115.3.023.483-.09.183-.135.297-.27.457-.134.16-.282.357-.403.48-.134.133-.273.277-.117.544.155.267.69 1.138 1.48 1.843 1.017.907 1.875 1.188 2.14 1.32.264.134.418.112.57-.067.153-.18.656-.768.832-1.032.175-.264.35-.22.59-.132.238.088 1.516.715 1.775.845.26.13.432.196.496.305.065.11.065.635-.165 1.28z"/>
            </svg>
            Falar com a RBD
          </a>
          <p style={{
            fontFamily: 'Montserrat,sans-serif', fontWeight: 400,
            fontSize: '12px', letterSpacing: '0.18em',
            color: 'rgba(255,255,255,0.45)', margin: 0,
          }}>(42) 98870-8525</p>
        </div>

        {/* Email + Telefone */}
        <div className="hero-cta-btns" style={{ display: 'flex', gap: '40px', alignItems: 'flex-start', flexWrap: 'wrap', justifyContent: 'center' }}>
          {/* Email */}
          <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '8px' }}>
            <a href="mailto:contato@rbdarquitetura.com.br"
              style={{
                display: 'inline-flex', alignItems: 'center', gap: '9px',
                border: '1px solid rgba(255,255,255,0.3)', color: 'rgba(255,255,255,0.85)',
                fontFamily: 'Montserrat,sans-serif', fontWeight: 500,
                fontSize: '11px', letterSpacing: '0.18em', textTransform: 'uppercase',
                padding: '13px 28px', textDecoration: 'none',
                transition: 'border-color 0.25s, color 0.25s',
              }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = '#fff'; e.currentTarget.style.color = '#fff'; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255,255,255,0.3)'; e.currentTarget.style.color = 'rgba(255,255,255,0.85)'; }}>
              <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
                <rect x="2" y="4" width="20" height="16" rx="2"/><polyline points="2,4 12,13 22,4"/>
              </svg>
              Enviar e-mail
            </a>
            <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '10px', letterSpacing: '0.12em', color: 'rgba(255,255,255,0.35)', margin: 0 }}>contato@rbdarquitetura.com.br</p>
          </div>

          {/* Telefone */}
          <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '8px' }}>
            <a href="tel:+5542988708525"
              style={{
                display: 'inline-flex', alignItems: 'center', gap: '9px',
                border: '1px solid rgba(255,255,255,0.3)', color: 'rgba(255,255,255,0.85)',
                fontFamily: 'Montserrat,sans-serif', fontWeight: 500,
                fontSize: '11px', letterSpacing: '0.18em', textTransform: 'uppercase',
                padding: '13px 28px', textDecoration: 'none',
                transition: 'border-color 0.25s, color 0.25s',
              }}
              onMouseEnter={e => { e.currentTarget.style.borderColor = '#fff'; e.currentTarget.style.color = '#fff'; }}
              onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255,255,255,0.3)'; e.currentTarget.style.color = 'rgba(255,255,255,0.85)'; }}>
              <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
                <path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.5 19.5 0 013.09 12a19.79 19.79 0 01-3.07-8.67A2 2 0 012 1.14h3a2 2 0 012 1.72 12.84 12.84 0 00.7 2.81 2 2 0 01-.45 2.11L6.09 8.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7A2 2 0 0122 15.92z"/>
              </svg>
              Ligar agora
            </a>
            <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '10px', letterSpacing: '0.12em', color: 'rgba(255,255,255,0.35)', margin: 0 }}>+55 (42) 98870-8525</p>
          </div>
        </div>

        {/* Atendimento 24h */}
        <div style={{ marginTop: '32px', display: 'flex', alignItems: 'center', gap: '8px' }}>
          <div style={{ width: '6px', height: '6px', borderRadius: '50%', background: '#25D366', boxShadow: '0 0 8px rgba(37,211,102,0.7)', animation: 'pulse24h 2s infinite' }} />
          <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 400, fontSize: '10px', letterSpacing: '0.3em', color: 'rgba(255,255,255,0.4)', textTransform: 'uppercase', margin: 0 }}>Atendimento 24 horas</p>
        </div>
      </div>

      {/* ── Texto inferior esquerdo — discreto ── */}
      <div className="hero-bl" style={{
        position: 'absolute', bottom: '52px', left: '64px',
        display: 'flex', flexDirection: 'column', gap: '7px', zIndex: 1,
      }}>
        <p style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
          fontSize: '10px', letterSpacing: '0.42em',
          color: 'rgba(255,255,255,0.6)', textTransform: 'uppercase', margin: 0,
        }}>RBD Arquitetura &amp; Interiores</p>
        <p style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 200,
          fontSize: '10px', letterSpacing: '0.28em',
          color: 'rgba(255,255,255,0.35)', textTransform: 'uppercase', margin: 0,
        }}>Ponta Grossa — Paraná</p>
      </div>

      {/* ── Links inferior direito — mínimos ── */}
      <div className="hero-br" style={{
        position: 'absolute', bottom: '52px', right: '64px',
        display: 'flex', gap: '36px', alignItems: 'center', zIndex: 1,
      }}>
        {[['portfolio','Portfólio'], ['contato','Contato']].map(([id, label]) => (
          <button key={id} onClick={() => navigate(id)} style={{
            background: 'none', border: 'none', cursor: 'pointer',
            fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
            fontSize: '10px', letterSpacing: '0.32em',
            color: 'rgba(255,255,255,0.5)', textTransform: 'uppercase', padding: 0,
            transition: 'color 0.28s ease',
          }}
          onMouseEnter={e => e.currentTarget.style.color = '#fff'}
          onMouseLeave={e => e.currentTarget.style.color = 'rgba(255,255,255,0.5)'}
          >{label}</button>
        ))}
      </div>

      {/* ── Scroll cue — centro base ── */}
      <div style={{
        position: 'absolute', bottom: '28px', left: '50%',
        transform: 'translateX(-50%)', zIndex: 1,
        display: 'flex', flexDirection: 'column', alignItems: 'center',
      }}>
        <div className="scroll-line" style={{
          width: '1px', height: '44px',
          background: 'linear-gradient(to bottom, rgba(255,255,255,0.5), transparent)',
        }} />
      </div>
    </section>
  );
}

// ── ABOUT ─────────────────────────────────────────────────────────────────────
function AboutSection() {
  const diffs = [
  { n: '01', title: 'Excelência Técnica', desc: 'Mais de 25 anos de experiência e centenas de projetos entregues com qualidade superior.' },
  { n: '02', title: 'Visão Integrada', desc: 'Do conceito à execução, acompanhamos cada etapa com atenção irrestrita ao detalhe.' },
  { n: '03', title: 'Materiais Premium', desc: 'Parceiros selecionados e materiais de primeira linha para resultados extraordinários.' },
  { n: '04', title: 'Entrega Pontual', desc: 'Compromisso total com prazos e transparência em todas as fases do projeto.' }];

  return (
    <section id="sobre" style={{ background: '#fff', color: '#000', padding: '140px 80px' }}>
      <div style={{ maxWidth: '1200px', margin: '0 auto' }}>
        {/* Main grid */}
        <div className="about-grid" style={{ display: 'grid', gridTemplateColumns: '55% 1fr', gap: '80px', alignItems: 'center', marginBottom: '110px' }}>
          <div>
            <div className="reveal"><Label>SOBRE NÓS</Label></div>
            <h2 className="reveal reveal-d1" style={{
              fontFamily: 'Montserrat,sans-serif', fontWeight: 800,
              fontSize: 'clamp(30px,3.6vw,52px)', lineHeight: 1.1,
              letterSpacing: '-0.02em', color: '#000', margin: '0 0 36px'
            }}>
              Uma boa arquitetura<br />começa muito antes do projeto.
            </h2>
            <p className="reveal reveal-d2" style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '15px', lineHeight: 1.95, color: '#555', maxWidth: '480px', marginBottom: '20px' }}>
              Antes de pensar em formas, materiais ou acabamentos, buscamos compreender as pessoas, os objetivos e a forma como cada espaço será ocupado. É essa leitura que orienta todas as decisões ao longo da jornada.
            </p>
            <p className="reveal reveal-d2" style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '15px', lineHeight: 1.95, color: '#555', maxWidth: '480px', marginBottom: '20px' }}>
              Mais do que desenvolver projetos, conduzimos arquitetura, construção e interiores de forma integrada, trazendo clareza, organização e segurança em cada etapa.
            </p>
            <p className="reveal reveal-d2" style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '15px', lineHeight: 1.95, color: '#555', maxWidth: '480px' }}>
              Porque acreditamos que uma boa arquitetura não é apenas aquela que impressiona quando fica pronta. É aquela que continua fazendo sentido ao longo do tempo.
            </p>
          </div>
          <div className="reveal reveal-d3" style={{ height: '520px', overflow: 'hidden', borderRadius: '2px' }}>
            <img src="equipe.jpg" alt="Equipe RBD Arch" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
          </div>
        </div>

        {/* Differentials */}
        <div style={{ borderTop: '1px solid rgba(0,0,0,0.08)', paddingTop: '80px' }}>
          <div className="diffs-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: '48px' }}>
            {diffs.map(({ n, title, desc }, i) =>
            <div key={n} className={`reveal reveal-d${i}`}>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 200, fontSize: '40px', color: 'rgba(0,0,0,0.1)', lineHeight: 1, marginBottom: '20px' }}>{n}</p>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 700, fontSize: '13px', letterSpacing: '0.04em', marginBottom: '12px', color: '#000' }}>{title}</p>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '13px', lineHeight: 1.85, color: '#777' }}>{desc}</p>
              </div>
            )}
          </div>
        </div>
      </div>
    </section>);

}

// ── LIGHTBOX ─────────────────────────────────────────────────────────────────
const makeSlides = (proj) => {
  const { name, cat, images, captions } = proj;
  if (images && images.length) {
    return images.map((src, i) => ({ src, label: `${name.toUpperCase()}\n${(captions && captions[i]) || ''}`.trim() }));
  }
  const base = cat.split(' · ')[0];
  const map = {
    Residencial: ['FACHADA', 'SALA DE ESTAR', 'COZINHA GOURMET', 'SUÍTE MASTER', 'ÁREA EXTERNA'],
    Comercial: ['VISTA GERAL', 'RECEPÇÃO', 'ÁREA PRINCIPAL', 'DETALHE', 'TERRAÇO'],
    Interiores: ['COMPOSIÇÃO GERAL', 'PALETA DE MATERIAIS', 'ILUMINAÇÃO', 'DETALHE CONSTRUTIVO', 'ACABAMENTOS']
  };
  return (map[base] || map.Residencial).map((l) => ({ src: null, label: `${name.toUpperCase()}\n${l}` }));
};

function Lightbox({ project, onClose }) {
  const [idx, setIdx] = useState(0);
  const [fading, setFading] = useState(false);
  const [zoom, setZoom] = useState(1);
  const [pan, setPan] = useState({ x: 50, y: 50 });
  const [editingCap, setEditingCap] = useState(false);
  const [capOverrides, setCapOverrides] = useState(() => {
    try { return JSON.parse(localStorage.getItem('rbd-captions') || '{}'); } catch (e) { return {}; }
  });
  const touchX = useRef(null);
  const total = project.slides.length;

  // Reset zoom whenever the slide changes
  useEffect(() => { setZoom(1); setPan({ x: 50, y: 50 }); setEditingCap(false); }, [idx]);

  // Preload neighboring slides (and all slides once idle) so navigation feels instant
  useEffect(() => {
    const preload = (i) => {
      const src = project.slides[(i + total) % total].src;
      if (src) { const img = new Image(); img.src = src; }
    };
    preload(idx + 1);
    preload(idx - 1);
  }, [idx, total]);

  useEffect(() => {
    const id = setTimeout(() => {
      project.slides.forEach((s) => { if (s.src) { const img = new Image(); img.src = s.src; } });
    }, 300);
    return () => clearTimeout(id);
  }, []);

  const hasImg = !!project.slides[idx].src;
  const toggleZoom = (e) => {
    if (!hasImg) return;
    if (e) e.stopPropagation();
    setZoom((z) => z === 1 ? 2 : 1);
  };
  const onImgMove = (e) => {
    if (zoom === 1) return;
    const r = e.currentTarget.getBoundingClientRect();
    const x = ((e.clientX - r.left) / r.width) * 100;
    const y = ((e.clientY - r.top) / r.height) * 100;
    setPan({ x: Math.max(0, Math.min(100, x)), y: Math.max(0, Math.min(100, y)) });
  };

  useEffect(() => {
    const onKey = (e) => {
      if (e.key === 'Escape') onClose();
      if (editingCap) return;
      if (e.key === 'ArrowRight' && !fading) go(1);
      if (e.key === 'ArrowLeft' && !fading) go(-1);
    };
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, [idx, fading, editingCap]);

  useEffect(() => {
    const prev = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    return () => {document.body.style.overflow = prev || '';};
  }, []);

  const go = (dir) => {
    if (fading) return;
    setFading(true);
    setTimeout(() => {setIdx((i) => (i + dir + total) % total);setFading(false);}, 220);
  };

  const jumpTo = (i) => {
    if (i === idx || fading) return;
    setFading(true);
    setTimeout(() => {setIdx(i);setFading(false);}, 220);
  };

  const onTouchStart = (e) => {touchX.current = e.touches[0].clientX;};
  const onTouchEnd = (e) => {
    if (touchX.current === null) return;
    const diff = touchX.current - e.changedTouches[0].clientX;
    if (Math.abs(diff) > 50) go(diff > 0 ? 1 : -1);
    touchX.current = null;
  };

  const arrowBase = {
    position: 'absolute', top: '50%', transform: 'translateY(-50%)',
    zIndex: 10, border: '1px solid rgba(255,255,255,0.14)', color: '#fff',
    cursor: 'pointer', width: '56px', height: '56px',
    display: 'flex', alignItems: 'center', justifyContent: 'center',
    background: 'rgba(255,255,255,0.05)', transition: 'background 0.2s ease, border-color 0.2s ease'
  };

  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 2000, background: 'rgba(0,0,0,0.97)', display: 'flex', flexDirection: 'column' }}
    onClick={onClose}>

      {/* ── Top bar ── */}
      <div onClick={(e) => e.stopPropagation()} style={{
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        padding: '18px 32px', borderBottom: '1px solid rgba(255,255,255,0.06)',
        flexShrink: 0, position: 'relative'
      }}>
        <span style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 200, fontSize: '12px', letterSpacing: '0.4em', color: 'rgba(255,255,255,0.35)' }}>
          RBD<span style={{ fontWeight: 700 }}>ARCH</span>
        </span>

        {/* Counter — centrado */}
        <span style={{
          position: 'absolute', left: '50%', transform: 'translateX(-50%)',
          fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
          fontSize: '12px', letterSpacing: '0.4em', color: 'rgba(255,255,255,0.5)'
        }}>
          <span style={{ color: '#fff', fontWeight: 600 }}>{idx + 1}</span>
          <span style={{ color: 'rgba(255,255,255,0.25)', margin: '0 8px' }}>/</span>
          {total}
        </span>

        {/* Right controls: zoom + close */}
        <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
          {hasImg &&
          <div style={{ display: 'flex', border: '1px solid rgba(255,255,255,0.15)' }}>
            {[1, 2].map((z) =>
            <button key={z} onClick={(e) => { e.stopPropagation(); setZoom(z); if (z === 1) setPan({ x: 50, y: 50 }); }} style={{
              fontFamily: 'Montserrat,sans-serif', fontWeight: 600, fontSize: '11px', letterSpacing: '0.08em',
              padding: '0 14px', height: '44px', cursor: 'pointer',
              background: zoom === z ? '#fff' : 'transparent',
              color: zoom === z ? '#000' : 'rgba(255,255,255,0.55)',
              border: 'none', borderLeft: z === 2 ? '1px solid rgba(255,255,255,0.15)' : 'none',
              transition: 'all 0.2s ease'
            }}>{z}x</button>
            )}
          </div>}

          {/* Close */}
          <button onClick={onClose} style={{
            background: 'none', border: '1px solid rgba(255,255,255,0.15)',
            color: '#fff', cursor: 'pointer', width: '44px', height: '44px',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            transition: 'background 0.2s, border-color 0.2s'
          }}
          onMouseEnter={(e) => {e.currentTarget.style.background = 'rgba(255,255,255,0.09)';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.35)';}}
          onMouseLeave={(e) => {e.currentTarget.style.background = 'none';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.15)';}}>
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round">
              <path d="M2 2l12 12M14 2L2 14" />
            </svg>
          </button>
        </div>
      </div>

      {/* ── Image area ── */}
      <div style={{ flex: 1, position: 'relative', overflow: 'hidden' }}
      onClick={(e) => e.stopPropagation()}
      onTouchStart={onTouchStart}
      onTouchEnd={onTouchEnd}>

        {/* Left arrow */}
        <button onClick={() => go(-1)} style={{ ...arrowBase, left: '24px' }}
        onMouseEnter={(e) => {e.currentTarget.style.background = 'rgba(255,255,255,0.12)';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.3)';}}
        onMouseLeave={(e) => {e.currentTarget.style.background = 'rgba(255,255,255,0.05)';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.14)';}}>
          <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"><path d="M12 16l-6-6 6-6" /></svg>
        </button>

        {/* Slide */}
        <div style={{
          position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center',
          padding: '16px 100px',
          opacity: fading ? 0 : 1,
          transform: fading ? 'scale(0.97)' : 'scale(1)',
          transition: 'opacity 0.22s ease, transform 0.22s ease'
        }}>
          {project.slides[idx].src ?
          <img
            src={project.slides[idx].src}
            alt={project.slides[idx].label.replace(/\n/g, ' — ')}
            onClick={toggleZoom}
            onMouseMove={onImgMove}
            style={{
              maxWidth: '100%', maxHeight: '100%', width: 'auto', height: 'auto',
              objectFit: 'contain', display: 'block',
              cursor: zoom === 1 ? 'zoom-in' : 'zoom-out',
              transform: `scale(${zoom})`,
              transformOrigin: `${pan.x}% ${pan.y}%`,
              transition: 'transform 0.32s cubic-bezier(0.22,1,0.36,1)'
            }} /> :

          <div style={{ width: '100%', maxWidth: '1040px', aspectRatio: '16/10' }}>
            <PlaceholderImage label={project.slides[idx].label} style={{ width: '100%', height: '100%' }} />
          </div>}
        </div>

        {/* Right arrow */}
        <button onClick={() => go(1)} style={{ ...arrowBase, right: '24px' }}
        onMouseEnter={(e) => {e.currentTarget.style.background = 'rgba(255,255,255,0.12)';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.3)';}}
        onMouseLeave={(e) => {e.currentTarget.style.background = 'rgba(255,255,255,0.05)';e.currentTarget.style.borderColor = 'rgba(255,255,255,0.14)';}}>
          <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"><path d="M8 4l6 6-6 6" /></svg>
        </button>

        {/* Per-image caption — editável */}
        {(() => {
          const parts = (project.slides[idx].label || '').split('\n');
          const derived = parts.length > 1 ? parts.slice(1).join(' ').trim() : '';
          const key = `rbd-cap:${project.name}:${idx}`;
          const cap = (capOverrides[key] !== undefined ? capOverrides[key] : derived);
          return (
            <div style={{ position: 'absolute', bottom: '44px', left: '50%', transform: 'translateX(-50%)', maxWidth: '80%', textAlign: 'center' }}>
              <span
                contentEditable={editingCap}
                suppressContentEditableWarning
                spellCheck={false}
                onClick={(e) => { e.stopPropagation(); if (!editingCap) { setEditingCap(true); setTimeout(() => { const el = e.target; el.focus(); const r = document.createRange(); r.selectNodeContents(el); const s = getSelection(); s.removeAllRanges(); s.addRange(r); }, 0); } }}
                onBlur={(e) => { const v = e.currentTarget.textContent.trim(); setCapOverrides((o) => { const n = { ...o, [key]: v }; try { localStorage.setItem('rbd-captions', JSON.stringify(n)); } catch (err) {} return n; }); setEditingCap(false); }}
                onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); e.currentTarget.blur(); } if (e.key === 'Escape') { e.currentTarget.textContent = cap; e.currentTarget.blur(); } }}
                title={editingCap ? '' : 'Clique para editar a descrição'}
                style={{
                  display: 'inline-block', background: editingCap ? 'rgba(0,0,0,0.82)' : 'rgba(0,0,0,0.55)', backdropFilter: 'blur(6px)',
                  padding: '9px 22px', border: editingCap ? '1px solid var(--accent,rgba(255,255,255,0.55))' : '1px solid rgba(255,255,255,0.1)',
                  fontFamily: 'Montserrat,sans-serif', fontWeight: 500, fontSize: '12px',
                  letterSpacing: '0.14em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.92)',
                  outline: 'none', cursor: editingCap ? 'text' : 'pointer', minWidth: '40px',
                  opacity: fading ? 0 : 1, transition: 'opacity 0.22s ease, background 0.2s ease, border-color 0.2s ease'
                }}>{cap}</span>
              {!editingCap &&
              <span style={{ display: 'block', marginTop: '6px', fontFamily: 'Montserrat,sans-serif', fontSize: '8px', letterSpacing: '0.22em', color: 'rgba(255,255,255,0.35)', textTransform: 'uppercase', pointerEvents: 'none' }}>
                Clique para editar
              </span>}
            </div>
          );
        })()}

        {/* Dot indicators */}
        <div style={{ position: 'absolute', bottom: '20px', left: '50%', transform: 'translateX(-50%)', display: 'flex', gap: '8px', alignItems: 'center' }}>
          {project.slides.map((_, i) =>
          <button key={i} onClick={() => jumpTo(i)} style={{
            width: i === idx ? '28px' : '6px', height: '6px',
            background: i === idx ? 'var(--accent,#fff)' : 'rgba(255,255,255,0.22)',
            border: 'none', cursor: 'pointer', padding: 0,
            transition: 'all 0.35s cubic-bezier(0.22,1,0.36,1)'
          }} />
          )}
        </div>
      </div>

      {/* ── Footer info ── */}
      <div onClick={(e) => e.stopPropagation()} style={{
        padding: '24px 40px 28px', borderTop: '1px solid rgba(255,255,255,0.06)', flexShrink: 0
      }}>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '10px', letterSpacing: '0.3em', color: 'var(--accent,rgba(255,255,255,0.45))', textTransform: 'uppercase', marginBottom: '8px' }}>
          {project.cat}
        </p>
        <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', flexWrap: 'wrap', gap: '12px' }}>
          <h3 style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 700, fontSize: 'clamp(18px,2.5vw,28px)', letterSpacing: '-0.01em', color: '#fff', margin: 0 }}>
            {project.name}
          </h3>
          <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '13px', color: 'rgba(255,255,255,0.45)', lineHeight: 1.7, maxWidth: '520px', textAlign: 'right' }}>
            {project.desc}
          </p>
        </div>
      </div>
    </div>);

}

// ── PORTFOLIO ─────────────────────────────────────────────────────────────────
function PortfolioSection({ navigate }) {
  const [tab, setTab] = useState('Residencial');
  const [lightbox, setLightbox] = useState(null);
  const tabs = ['Residencial', 'Comercial', 'Interiores'];

  const projects = {
    Residencial: [
    { name: 'Casa KBR', cat: 'Residencial · Ponta Grossa-PR', desc: 'Residência térrea com cobertura inclinada em metal e forro de madeira, fachada em tijolo aparente, ripado vertical e iluminação linear embutida — carport integrado, área externa com deck, piscina e jardim tropical.',
      images: ['projects/casa-kbr/01-fachada-noite.jpg', 'projects/casa-kbr/02-fachada-lateral.jpg', 'projects/casa-kbr/03-area-externa.jpg', 'projects/casa-kbr/04-piscina-deck.jpg', 'projects/casa-kbr/05-fachada-real.jpg'],
      captions: ['FACHADA NOTURNA', 'FACHADA LATERAL', 'ÁREA EXTERNA & JARDIM', 'PISCINA & DECK', 'FACHADA PRINCIPAL'] },
    { name: 'Casa FB', cat: 'Residencial · Ponta Grossa-PR', desc: 'Residência contemporânea com fachada em pedra natural, ripado de madeira e jardins suspensos — volumes horizontais precisos, cobogós metálicos e iluminação cênica que valorizam a materialidade e a relação entre arquitetura e paisagismo.',
      images: ['projects/casa-fb/01-fachada-dia.jpg', 'projects/casa-fb/02-detalhe-jardim.jpg', 'projects/casa-fb/03-detalhe-pedra.jpg', 'projects/casa-fb/04-fachada-noite.jpg', 'projects/casa-fb/05-fachada-esquina.jpg'],
      captions: ['FACHADA PRINCIPAL', 'DETALHE — JARDIM SUSPENSO', 'DETALHE — PEDRA NATURAL', 'FACHADA NOTURNA', 'VISTA DA ESQUINA'] },
    { name: 'Casa L&F', cat: 'Residencial · Ponta Grossa-PR', desc: 'Residência contemporânea com cobertura inclinada em madeira, fachada em pedra natural e iluminação linear embutida — carport integrado à volumetria, jardim tropical e área externa com piscina e parede em pedra.',
      images: ['projects/casa-lf/01-fachada-render.jpg', 'projects/casa-lf/02-fachada-render2.jpg', 'projects/casa-lf/03-detalhe-entrada.jpg', 'projects/casa-lf/04-area-externa.jpg', 'projects/casa-lf/05-fachada-real.jpg'],
      captions: ['FACHADA PRINCIPAL', 'VISTA LATERAL', 'DETALHE — ENTRADA', 'ÁREA EXTERNA & PISCINA', 'FOTO REAL — FACHADA'] },
    { name: 'Casa TSS', cat: 'Residencial · Ponta Grossa-PR', desc: 'Sobrado contemporâneo de dois pavimentos com fachada em concreto aparente, ripado de madeira e jardim suspenso — iluminação linear embutida, piscina com deck e área gourmet integrada ao living.',
      images: ['projects/casa-tss/01-piscina-jardim.jpg', 'projects/casa-tss/02-fachada-lateral.jpg', 'projects/casa-tss/03-fachada-noite.jpg', 'projects/casa-tss/04-area-externa.jpg', 'projects/casa-tss/05-fachada-principal.jpg'],
      captions: ['PISCINA & JARDIM NOTURNO', 'FACHADA LATERAL', 'FACHADA NOTURNA', 'ÁREA EXTERNA & PISCINA', 'FACHADA PRINCIPAL'] },
    { name: 'Casa RNT', cat: 'Residencial · Ponta Grossa-PR', desc: 'Residência térrea de linguagem tropical contemporânea — cobertura em telha natural, pergolado em madeira maciça, piscina com deck e jardim com palmeiras imperiais. Integração total entre o living e as áreas externas.',
      images: ['projects/casa-rnt/01-fachada.jpg', 'projects/casa-rnt/02-piscina.jpg', 'projects/casa-rnt/03-jardim-fogueira.jpg', 'projects/casa-rnt/04-fachada-real.jpg', 'projects/casa-rnt/05-pergolado.jpg'],
      captions: ['FACHADA PRINCIPAL', 'PISCINA & DECK', 'JARDIM & FOGUEIRA', 'FACHADA — VISTA EXTERNA', 'PERGOLADO & VARANDA'] },
    ],

    Comercial: [
    { name: 'Loja Comercial PK2', cat: 'Comercial · Automotivo', desc: 'Showroom multimarcas Perfect K2 Imports com torre-totem em concreto e identidade visual integrada à arquitetura — fachadas em vidro, ACM grafite e tijolo aparente, iluminação cênica que transforma a vitrine de carros em cartão-postal urbano ao entardecer.',
      images: ['projects/pk2/01-torre-k2.jpg', 'projects/pk2/02-esquina.jpg', 'projects/pk2/03-fachada-rua.jpg'],
      captions: ['FACHADA SECUNDÁRIA', 'VISTA DA ESQUINA', 'FACHADA & SHOWROOM'] },
    { name: 'Estúdio de Fotografia', cat: 'Comercial · Curitiba', desc: 'Edifício comercial de três pavimentos com fachada em ripado de madeira natural, jardins verticais e esquadrias metálicas escuras — linguagem contemporânea que une leveza e sofisticação.',
      images: ['projects/estudio-foto/01-fachada.jpg', 'projects/estudio-foto/02-estacionamento.jpg', 'projects/estudio-foto/03-cobertura.jpg'],
      captions: ['FACHADA PRINCIPAL', 'ÁREA DE ESTACIONAMENTO', 'DETALHE DE COBERTURA'] },
    { name: 'Espaço Mall', cat: 'Comercial · Varejo', desc: 'Centro comercial com sete lojas de alto padrão — fachada em ACM grafite, ripado de madeira, tijolo aparente e piso de paralelepípedo. Identidade visual integrada à arquitetura com iluminação cênica ao entardecer.',
      images: ['projects/espaco-mall/01-fachada-noite.jpg', 'projects/espaco-mall/02-fachada-dia.jpg', 'projects/espaco-mall/03-estacionamento.jpg'],
      captions: ['FACHADA NOTURNA', 'VISTA GERAL', 'CORREDOR DE ACESSO'] },
    { name: 'Escritório de Advocacia', cat: 'Comercial · Jurídico', desc: 'Sede de escritório jurídico com fachada em mármore Calacatta, ripado de madeira e volumetria escultórica — linguagem sóbria e imponente que traduz autoridade e sofisticação.',
      images: ['projects/advocacia/01-entrada.jpg', 'projects/advocacia/02-fachada-noite.jpg', 'projects/advocacia/03-fachada-dia.jpg'],
      captions: ['DETALHE DA ENTRADA', 'FACHADA NOTURNA', 'FACHADA DIURNA'] },
    { name: 'Supermercado Vitor', cat: 'Comercial · Varejo', desc: 'Supermercado de grande porte com fachada esculpida em volumes curvos e revestimento cerâmico claro — ACM grafite, painéis amadeirados e iluminação linear contínua que valoriza a marca dia e noite.',
      images: ['projects/vitor/01-fachada.jpg', 'projects/vitor/02-volume-curvo.jpg', 'projects/vitor/03-entrada.jpg'],
      captions: ['FACHADA PRINCIPAL', 'VOLUME CURVO', 'ACESSO PRINCIPAL'] },
    ],

    Interiores: [
    { name: 'Espaço Gourmet · CL', cat: 'Interiores · Residencial', desc: 'Espaço gourmet integrado de cobertura com vista panorâmica da cidade — ilha em mármore com cooktop, bancada de madeira maciça em corte natural, marcenaria amadeirada, iluminação linear embutida e varanda com cortina de vidro que funde estar, jantar e cozinha ao horizonte ao entardecer.',
      images: ['projects/gourmet-cl/01-cozinha-ilha.jpg', 'projects/gourmet-cl/06-gourmet-entardecer.jpg', 'projects/gourmet-cl/05-varanda-jantar.jpg', 'projects/gourmet-cl/02-jantar-varanda.jpg', 'projects/gourmet-cl/03-living-vista.jpg', 'projects/gourmet-cl/04-home-tv.jpg'],
      captions: ['Espaço integrado — Cozinha/Living/Varanda', 'Espaço integrado — Varanda gourmet', 'VARANDA GOURMET', 'Espaço integrado — Varanda gourmet', 'Espaço integrado — Living', 'Espaço integrado — Living/Escritório'] },
    { name: 'Cond. Avant Garden', cat: 'Interiores · Áreas Comuns', desc: 'Áreas comuns de condomínio de alto padrão — salão de festas, cozinha gourmet em mármore Saint Laurent, academia equipada, sala de jogos com mural artístico, brinquedoteca lúdica e lounge com jardim vertical, unidos por uma linguagem de iluminação linear quente e madeira ripada.',
      images: ['projects/avant/01-salao.jpg', 'projects/avant/06-lounge.jpg', 'projects/avant/02-cozinha.jpg', 'projects/avant/03-academia.jpg', 'projects/avant/04-jogos.jpg', 'projects/avant/05-brinquedoteca.jpg', 'projects/avant/07-extra.jpg'],
      captions: ['Brinquedoteca', 'Estar — Salão de festas principal', 'Salão de festas principal', 'Churrasqueira — Salão de festas principal', 'Academia', 'Sala de jogos', 'Espaço Gourmet'] },
    { name: 'Cobertura · GN', cat: 'Interiores · Residencial', desc: 'Cobertura com spa coberto por pergolado de vidro e vista panorâmica da cidade — deck em madeira nobre, jardim vertical, painéis ripados, parede escultórica iluminada e estar integrado que dissolve o limite entre lazer e contemplação.',
      images: ['projects/cobertura-gn/01-spa-vista.jpg', 'projects/cobertura-gn/02-living-jardim.jpg', 'projects/cobertura-gn/03-img.jpg', 'projects/cobertura-gn/04-img.jpg', 'projects/cobertura-gn/05-img.jpg'],
      captions: ['SPA & VISTA PANORÂMICA', 'SPA', 'SPA & LIVING', 'SPA', 'LIVING INTEGRADO'] },
    { name: 'Suíte · GN', cat: 'Interiores · Residencial', desc: 'Suíte master integrada à banheira freestanding por um ripado de madeira vazado — mármore Calacatta na cabeceira, iluminação linear quente, poltrona bouclé e marcenaria sob medida que unem descanso e spa em um só ambiente.',
      images: ['projects/suite-gn/01-banheira-suite.jpg', 'projects/suite-gn/02-corredor.jpg', 'projects/suite-gn/03-poltrona.jpg', 'projects/suite-gn/04-cabeceira.jpg', 'projects/suite-gn/05-tv-frigobar.jpg'],
      captions: ['SUÍTE', 'BANHEIRA E SUÍTE', 'BANHEIRA & SUÍTE', 'SUÍTE', 'SUÍTE'] },
    { name: 'Espaço Integrado · GN', cat: 'Interiores · Residencial', desc: 'Integração total entre living, sala de jantar e cozinha gourmet — mármore Calacatta, ripado de madeira nobre, escada escultural e iluminação linear embutida que costura todos os ambientes em uma só atmosfera.',
      images: ['projects/gn/01-integrado.jpg', 'projects/gn/02-living.jpg', 'projects/gn/03-escada.jpg', 'projects/gn/04-cozinha.jpg', 'projects/gn/05-jantar.jpg'],
      captions: ['ESPAÇO INTEGRADO', 'LIVING & ESCADA', 'ESCADA ESCULTURAL', 'COZINHA', 'SALA DE JANTAR'] },
    ]

  };

  return (
    <section id="portfolio" style={{ background: '#000', padding: '140px 80px' }}>
      <div style={{ maxWidth: '1200px', margin: '0 auto' }}>
        <div className="reveal" style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', flexWrap: 'wrap', gap: '32px', marginBottom: '64px' }}>
          <div>
            <Label light>PORTFÓLIO</Label>
            <h2 style={{
              fontFamily: 'Montserrat,sans-serif', fontWeight: 800,
              fontSize: 'clamp(30px,3.6vw,52px)', lineHeight: 1.1,
              letterSpacing: '-0.02em', color: '#fff', margin: 0
            }}>Arquitetura feita para ser vivida.</h2>
            <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '14px', lineHeight: 1.8, color: 'rgba(255,255,255,0.5)', maxWidth: '480px', marginTop: '20px' }}>Cada projeto nasce de uma história diferente. Por isso, mais do que criar espaços bonitos, buscamos desenvolver ambientes que façam sentido para quem vai viver ali. Conheça alguns dos projetos que tivemos o privilégio de conduzir.</p>
          </div>
          {/* Tabs */}
          <div style={{ display: 'flex', gap: 0, border: '1px solid rgba(255,255,255,0.12)' }}>
            {tabs.map((t, i) =>
            <button key={t} onClick={() => setTab(t)} style={{
              fontFamily: 'Montserrat,sans-serif', fontWeight: 500,
              fontSize: '10px', letterSpacing: '0.2em',
              padding: '13px 28px', cursor: 'pointer',
              background: tab === t ? '#fff' : 'transparent',
              color: tab === t ? '#000' : 'rgba(255,255,255,0.45)',
              border: 'none',
              borderLeft: i > 0 ? '1px solid rgba(255,255,255,0.12)' : 'none',
              transition: 'all 0.28s ease'
            }}>{t.toUpperCase()}</button>
            )}
          </div>
        </div>

        {/* Grid */}
        <div className="portfolio-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(6,1fr)', gap: '3px' }}>
          {projects[tab].map((proj, i) =>
          <ProjectCard
            key={proj.name} name={proj.name} cat={proj.cat} idx={i} cover={proj.images && proj.images[0]}
            span={i < 3 ? 2 : 3}
            onOpen={() => setLightbox({ ...proj, slides: makeSlides(proj) })} />

          )}
        </div>

        <div className="reveal" style={{ textAlign: 'center', marginTop: '64px' }}>
          <Btn variant="outlineLight" onClick={() => navigate('contato')}>SOLICITAR ORÇAMENTO</Btn>
        </div>
      </div>

      {lightbox && <Lightbox project={lightbox} onClose={() => setLightbox(null)} />}
    </section>);

}

function ProjectCard({ name, cat, idx, onOpen, cover, span = 2 }) {
  const [hov, setHov] = useState(false);
  const aspectRatio = span === 3 ? '16/9' : '4/3';
  return (
    <div
      onMouseEnter={() => setHov(true)} onMouseLeave={() => setHov(false)}
      onClick={onOpen}
      style={{ position: 'relative', aspectRatio, overflow: 'hidden', cursor: 'pointer', gridColumn: `span ${span}` }}>
      
      <PlaceholderImage label={name.toUpperCase()} src={cover} style={{ position: 'absolute', inset: 0, minHeight: 'unset', width: '100%', height: '100%' }} />
      {/* Hover overlay */}
      <div style={{
        position: 'absolute', inset: 0,
        background: 'rgba(0,0,0,0.88)',
        display: 'flex', flexDirection: 'column', justifyContent: 'flex-end',
        padding: '32px',
        opacity: hov ? 1 : 0,
        transform: hov ? 'translateY(0)' : 'translateY(8px)',
        transition: 'all 0.38s cubic-bezier(0.22,1,0.36,1)'
      }}>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '10px', letterSpacing: '0.22em', color: 'var(--accent,rgba(255,255,255,0.5))', marginBottom: '10px', textTransform: 'uppercase' }}>{cat}</p>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 700, fontSize: '18px', color: '#fff', letterSpacing: '0.02em', lineHeight: 1.2 }}>{name}</p>
        <div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginTop: '16px' }}>
          <div style={{ width: '32px', height: '1px', background: 'var(--accent,rgba(255,255,255,0.4))' }} />
          <span style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 400, fontSize: '9px', letterSpacing: '0.22em', color: 'rgba(255,255,255,0.45)' }}>VER PROJETO</span>
        </div>
      </div>
    </div>);

}

// ── SERVICES ──────────────────────────────────────────────────────────────────
const ServiceIcon = ({ type }) => {
  const icons = {
    residencial:
    <svg width="36" height="36" viewBox="0 0 36 36" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round">
        <path d="M3 17L18 4L33 17" /><path d="M7 14V32H29V14" />
        <rect x="14" y="22" width="8" height="10" />
      </svg>,

    comercial:
    <svg width="36" height="36" viewBox="0 0 36 36" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round">
        <rect x="3" y="8" width="30" height="24" /><rect x="9" y="3" width="18" height="9" />
        <line x1="12" y1="8" x2="12" y2="32" /><line x1="24" y1="8" x2="24" y2="32" />
        <line x1="3" y1="18" x2="33" y2="18" />
      </svg>,

    interiores:
    <svg width="36" height="36" viewBox="0 0 36 36" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round">
        <rect x="2" y="12" width="32" height="14" rx="2" />
        <path d="M8 12V9" /><path d="M28 12V9" />
        <path d="M2 26H34" /><line x1="18" y1="26" x2="18" y2="32" />
        <line x1="12" y1="32" x2="24" y2="32" />
      </svg>,

    consultoria:
    <svg width="36" height="36" viewBox="0 0 36 36" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round">
        <rect x="4" y="4" width="28" height="28" />
        <line x1="4" y1="14" x2="32" y2="14" /><line x1="4" y1="22" x2="32" y2="22" />
        <line x1="14" y1="4" x2="14" y2="32" />
        <circle cx="9" cy="9" r="1" fill="currentColor" />
      </svg>

  };
  return icons[type] || null;
};

function ServicesSection({ navigate }) {
  const services = [
  { type: 'residencial', title: 'Arquitetura', desc: 'Onde a jornada começa.' },
  { type: 'comercial', title: 'Construção', desc: 'Onde o projeto ganha vida.' },
  { type: 'interiores', title: 'Interiores', desc: 'Onde cada espaço ganha identidade.' },
  { type: 'consultoria', title: 'Gestão Integrada', desc: 'Onde tudo se conecta.' }];

  return (
    <section id="servicos" style={{ background: '#fff', padding: '140px 80px' }}>
      <div style={{ maxWidth: '1200px', margin: '0 auto' }}>
        <div className="reveal" style={{ marginBottom: '80px' }}>
          <Label>SERVIÇOS</Label>
          <h2 style={{
            fontFamily: 'Montserrat,sans-serif', fontWeight: 800,
            fontSize: 'clamp(28px,3.2vw,46px)', lineHeight: 1.15,
            letterSpacing: '-0.02em', color: '#000', margin: 0
          }}>Soluções que acompanham cada momento da sua jornada.</h2>
        </div>

        <div className="services-grid" style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: '1px', background: 'rgba(0,0,0,0.08)' }}>
          {services.map(({ type, title, desc }, i) =>
          <ServiceCard key={type} type={type} title={title} desc={desc} idx={i} navigate={navigate} />
          )}
        </div>
      </div>
    </section>);

}

function ServiceCard({ type, title, desc, navigate }) {
  const [hov, setHov] = useState(false);
  return (
    <div
      onMouseEnter={() => setHov(true)} onMouseLeave={() => setHov(false)}
      style={{
        background: hov ? '#000' : '#fff',
        padding: '48px 36px', cursor: 'default',
        transition: 'background 0.38s cubic-bezier(0.22,1,0.36,1)'
      }}>
      
      <div style={{
        color: hov ? 'var(--accent,rgba(255,255,255,0.7))' : '#000',
        marginBottom: '28px',
        transition: 'color 0.38s ease'
      }}>
        <ServiceIcon type={type} />
      </div>
      <h3 style={{
        fontFamily: 'Montserrat,sans-serif', fontWeight: 700,
        fontSize: '15px', letterSpacing: '0.02em', lineHeight: 1.3,
        color: hov ? '#fff' : '#000', marginBottom: '16px',
        transition: 'color 0.38s ease'
      }}>{title}</h3>
      <p style={{
        fontFamily: 'Montserrat,sans-serif', fontWeight: 300,
        fontSize: '13px', lineHeight: 1.85,
        color: hov ? 'rgba(255,255,255,0.55)' : '#666',
        transition: 'color 0.38s ease'
      }}>{desc}</p>
      <div style={{
        marginTop: '32px', width: '28px', height: '1px',
        background: hov ? 'var(--accent,rgba(255,255,255,0.5))' : 'rgba(0,0,0,0.2)',
        transition: 'all 0.38s ease'
      }} />
    </div>);

}

// ── MUITO ALÉM DE UM PROJETO ────────────────────────────────────────────────
function IntegratedSection() {
  return (
    <section id="processo" style={{ background: '#0a0a0a', padding: '140px 80px' }}>
      <div style={{ maxWidth: '860px', margin: '0 auto', textAlign: 'center' }}>
        <h2 style={{
          fontFamily: 'Montserrat,sans-serif', fontWeight: 800,
          fontSize: 'clamp(26px,3vw,42px)', lineHeight: 1.2,
          letterSpacing: '-0.02em', color: '#fff', margin: '0 0 40px'
        }}>Muito além de um projeto.</h2>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '16px', lineHeight: 1.9, color: 'rgba(255,255,255,0.6)', marginBottom: '24px' }}>
          Contratar um arquiteto é importante. Mas conduzir todas as etapas com clareza faz toda a diferença.
        </p>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '16px', lineHeight: 1.9, color: 'rgba(255,255,255,0.6)', marginBottom: '24px' }}>
          Ao longo dessa jornada, existem dezenas de decisões, fornecedores, prazos e detalhes que precisam conversar entre si.
        </p>
        <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '16px', lineHeight: 1.9, color: 'rgba(255,255,255,0.6)' }}>
          Nosso papel é integrar esse processo para que você tenha mais segurança para decidir, mais tranquilidade durante a execução e a certeza de que cada etapa está sendo conduzida com o mesmo cuidado do início ao fim.
        </p>
      </div>
    </section>);

}

// ── CONTACT ───────────────────────────────────────────────────────────────────
function ContactSection() {
  const [form, setForm] = useState({ name: '', email: '', phone: '', message: '' });
  const [errors, setErrors] = useState({});
  const [sent, setSent] = useState(false);

  const validate = () => {
    const e = {};
    if (!form.name.trim()) e.name = 'Campo obrigatório';
    if (!form.email.trim() || !/\S+@\S+\.\S+/.test(form.email)) e.email = 'E-mail inválido';
    if (!form.message.trim()) e.message = 'Campo obrigatório';
    return e;
  };

  const handle = (e) => {
    e.preventDefault();
    const errs = validate();
    if (Object.keys(errs).length) {setErrors(errs);return;}
    setSent(true);
  };

  const field = (key, placeholder, type = 'text', multiline = false) => {
    const hasErr = !!errors[key];
    const baseStyle = {
      width: '100%', background: 'transparent',
      border: 'none', borderBottom: `1px solid ${hasErr ? '#e55' : 'rgba(255,255,255,0.2)'}`,
      color: '#fff', fontFamily: 'Montserrat,sans-serif',
      fontWeight: 300, fontSize: '14px', padding: '14px 0',
      outline: 'none', resize: 'none', transition: 'border-color 0.25s'
    };
    return (
      <div style={{ marginBottom: '32px' }}>
        {multiline ?
        <textarea rows={4} placeholder={placeholder} value={form[key]}
        onChange={(e2) => {setForm((f) => ({ ...f, [key]: e2.target.value }));setErrors((er) => ({ ...er, [key]: '' }));}}
        style={{ ...baseStyle, display: 'block' }} /> :
        <input type={type} placeholder={placeholder} value={form[key]}
        onChange={(e2) => {setForm((f) => ({ ...f, [key]: e2.target.value }));setErrors((er) => ({ ...er, [key]: '' }));}}
        style={{ ...baseStyle, display: 'block' }} />
        }
        {hasErr && <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '10px', color: '#e55', marginTop: '6px', letterSpacing: '0.1em' }}>{errors[key]}</p>}
      </div>);

  };

  return (
    <section id="contato" style={{ background: '#000', padding: '140px 80px' }}>
      <div style={{ maxWidth: '1200px', margin: '0 auto' }}>
        <div className="reveal" style={{ marginBottom: '80px' }}>
          <Label light>CONTATO</Label>
          <h2 style={{
            fontFamily: 'Montserrat,sans-serif', fontWeight: 800,
            fontSize: 'clamp(26px,3.2vw,46px)', lineHeight: 1.2,
            letterSpacing: '-0.02em', color: '#fff', margin: 0
          }}>Sua história merece um projeto à altura.<br />Da primeira conversa ao último detalhe.</h2>
        </div>

        <div className="contact-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '100px', alignItems: 'start' }}>
          {/* Form */}
          <div className="reveal">
            {sent ?
            <div style={{ padding: '60px 0' }}>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 200, fontSize: '13px', letterSpacing: '0.3em', color: 'var(--accent,rgba(255,255,255,0.5))', marginBottom: '20px', textTransform: 'uppercase' }}>MENSAGEM ENVIADA</p>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 700, fontSize: '28px', color: '#fff', marginBottom: '16px', lineHeight: 1.2 }}>Obrigado pelo contato!</p>
                <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '15px', color: 'rgba(255,255,255,0.5)', lineHeight: 1.8 }}>Nossa equipe entrará em contato em até 24 horas.</p>
              </div> :

            <form onSubmit={handle} noValidate>
                {field('name', 'Seu nome completo')}
                {field('email', 'Seu e-mail', 'email')}
                {field('phone', 'Telefone / WhatsApp', 'tel')}
                {field('message', 'Conte-nos sobre seu projeto...', 'text', true)}
                <Btn variant="solidLight" style={{ marginTop: '8px' }}>
                  ENVIAR MENSAGEM
                </Btn>
              </form>
            }
          </div>

          {/* Info panel */}
          <div className="reveal reveal-d2" style={{ display: 'flex', flexDirection: 'column', gap: '48px' }}>
            {/* WhatsApp */}
            <div>
              <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '9px', letterSpacing: '0.28em', color: 'rgba(255,255,255,0.3)', marginBottom: '16px', textTransform: 'uppercase' }}>ATENDIMENTO RÁPIDO</p>
              <a href="https://wa.me/5542988708525" target="_blank" rel="noopener noreferrer" onClick={e => { e.preventDefault(); window.open('https://wa.me/5542988708525', '_blank'); }} style={{ textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: '14px', background: '#25D366', color: '#fff', padding: '18px 32px', fontFamily: 'Montserrat,sans-serif', fontWeight: 600, fontSize: '13px', letterSpacing: '0.12em', transition: 'background 0.25s ease' }}
              onMouseEnter={(e) => e.currentTarget.style.background = '#1da851'}
              onMouseLeave={(e) => e.currentTarget.style.background = '#25D366'}>
                <svg width="22" height="22" viewBox="0 0 22 22" fill="currentColor">
                  <path d="M11 0C4.925 0 0 4.925 0 11c0 1.94.505 3.76 1.388 5.337L.05 21.5l5.313-1.318A10.94 10.94 0 0011 22c6.075 0 11-4.925 11-11S17.075 0 11 0zm5.46 15.54c-.23.644-1.344 1.232-1.847 1.27-.503.04-1.008.192-3.405-.713-2.86-1.09-4.68-4.02-4.82-4.208-.142-.19-1.148-1.527-1.148-2.912s.726-2.07.984-2.357c.258-.286.563-.358.75-.358.188 0 .375.002.54.01.173.008.405-.066.633.483.23.55.78 1.9.85 2.038.07.138.115.3.023.483-.09.183-.135.297-.27.457-.134.16-.282.357-.403.48-.134.133-.273.277-.117.544.155.267.69 1.138 1.48 1.843 1.017.907 1.875 1.188 2.14 1.32.264.134.418.112.57-.067.153-.18.656-.768.832-1.032.175-.264.35-.22.59-.132.238.088 1.516.715 1.775.845.26.13.432.196.496.305.065.11.065.635-.165 1.28z" />
                </svg>
                FALAR PELO WHATSAPP
              </a>
              <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '12px', letterSpacing: '0.08em', color: 'rgba(255,255,255,0.4)', marginTop: '14px' }}>Vamos conversar</p>
            </div>

            {/* Address */}
            <div>
              <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '9px', letterSpacing: '0.28em', color: 'rgba(255,255,255,0.3)', marginBottom: '16px', textTransform: 'uppercase' }}>ENDEREÇO</p>
              <p style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '14px', color: 'rgba(255,255,255,0.6)', lineHeight: 2 }}>
                Rua Jacob Holzmann, 233<br />
                Ed. Philadélphia, Sala 603<br />
                Centro — Ponta Grossa, PR<br />
                <span style={{ fontSize: '12px', color: 'rgba(255,255,255,0.35)' }}>Segunda a sexta, das 8h às 17:30h</span>
              </p>
            </div>

            {/* Contact info */}
            <div>
              <p style={{ fontFamily: 'Montserrat,sans-serif', fontSize: '9px', letterSpacing: '0.28em', color: 'rgba(255,255,255,0.3)', marginBottom: '16px', textTransform: 'uppercase' }}>E-MAIL & TELEFONE</p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}>
                {['contato@rbdarquitetura.com.br', '+55 (42) 98870-8525'].map((v) =>
                <p key={v} style={{ fontFamily: 'Montserrat,sans-serif', fontWeight: 300, fontSize: '14px', color: 'rgba(255,255,255,0.6)', lineHeight: 1.5 }}>{v}</p>
                )}
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>);

}

// ── APP ───────────────────────────────────────────────────────────────────────
function App() {
  const [tweaks, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [active, setActive] = useState('home');
  useScrollReveal();

  // Set CSS custom property for accent
  useEffect(() => {
    const map = { gold: '#C8A96E', steel: '#7EA8C0', none: 'rgba(255,255,255,0.45)' };
    document.documentElement.style.setProperty('--accent', map[tweaks.accent] || map.none);
  }, [tweaks.accent]);

  // Active section tracking
  useEffect(() => {
    const ids = ['home', 'sobre', 'portfolio', 'servicos', 'contato'];
    const observer = new IntersectionObserver(
      (entries) => {
        entries.forEach((e) => {if (e.isIntersecting) setActive(e.target.id);});
      },
      { threshold: 0.4 }
    );
    ids.forEach((id) => {const el = document.getElementById(id);if (el) observer.observe(el);});
    return () => observer.disconnect();
  }, []);

  const navigate = (id) => {
    const el = document.getElementById(id);
    if (!el) return;
    const top = el.getBoundingClientRect().top + window.scrollY - 70;
    window.scrollTo({ top, behavior: 'smooth' });
  };

  return (
    <div style={{ fontFamily: 'Montserrat,sans-serif', lineHeight: 1 }}>
      <Header active={active} navigate={navigate} />
      <main>
        <HeroSection navigate={navigate} />
        <AboutSection />
        <PortfolioSection navigate={navigate} />
        <ServicesSection navigate={navigate} />
        <IntegratedSection />
        <ContactSection />
      </main>
      <Footer navigate={navigate} />
      <TweaksPanel>
        <TweakSection label="Identidade" />
        <TweakRadio label="Detalhe" value={tweaks.accent}
        options={['none', 'gold', 'steel']}
        onChange={(v) => setTweak('accent', v)} />
        <TweakSection label="Estilo" />
        <TweakRadio label="Botões" value={tweaks.buttonRadius}
        options={['sharp', 'soft']}
        onChange={(v) => setTweak('buttonRadius', v)} />
        <TweakRadio label="Espaçamento" value={tweaks.sectionSpacing}
        options={['compact', 'generous']}
        onChange={(v) => setTweak('sectionSpacing', v)} />
      </TweaksPanel>
    </div>);

}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);