/* App shell + simple router */
function App() {
  const routes = ['home', 'contact'];
  const initial = (location.hash || '').replace('#', '');
  const [route, setRoute] = React.useState(routes.includes(initial) ? initial : 'home');
  const appRef = React.useRef(null);

  const navigate = (r) => { setRoute(r); try { history.replaceState(null, '', '#' + r); } catch (e) {} if (appRef.current) appRef.current.scrollTop = 0; };

  React.useEffect(() => {
    const id = setTimeout(() => window.lucide && window.lucide.createIcons(), 20);
    return () => clearTimeout(id);
  });

  let screen;
  if (route === 'contact') screen = <ContactScreen onNavigate={navigate} />;
  else screen = <HomeScreen onNavigate={navigate} />;

  return (
    <div className="brs-app" ref={appRef}>
      <Header route={route} onNavigate={navigate} />
      {screen}
      <Footer onNavigate={navigate} />
    </div>
  );
}

let bursonMounted = false;
function mountBurson() {
  const NS = window.BursonLtdDesignSystem_53a781;
  const el = document.getElementById('root');
  if (bursonMounted) return;
  if (!el || !NS || !NS.Button || !window.Header || !window.Footer || !window.HomeScreen || !window.ContactScreen) { setTimeout(mountBurson, 40); return; }
  bursonMounted = true;
  ReactDOM.createRoot(el).render(<App />);
  setTimeout(() => window.lucide && window.lucide.createIcons(), 60);
}
if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', mountBurson);
} else {
  mountBurson();
}
