
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const rootElement = document.getElementById('root');
if (!rootElement) {
  throw new Error("Could not find root element to mount to");
}

try {
  const root = ReactDOM.createRoot(rootElement);
  root.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>
  );
} catch (err: any) {
  console.error("Erro fatal ao inicializar aplicação:", err);
  rootElement.innerHTML = `
    <div style="min-height: 100vh; display: flex; align-items: center; justify-content: center; background-color: #f8fafc; font-family: system-ui, sans-serif; padding: 24px;">
      <div style="max-width: 480px; width: 100%; background: white; border: 1px solid #e2e8f0; border-radius: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.06); padding: 32px; text-align: center;">
        <div style="width: 50px; height: 50px; background: #fee2e2; color: #dc2626; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; font-size: 24px; font-weight: bold; margin-bottom: 16px;">!</div>
        <h2 style="font-size: 1.25rem; font-weight: 700; color: #0f172a; margin: 0 0 8px 0;">Falha na Inicialização</h2>
        <p style="font-size: 0.875rem; color: #64748b; margin: 0 0 24px 0; line-height: 1.5;">Ocorreu uma instabilidade ao montar o sistema. Por favor, tente atualizar a página.</p>
        <button onclick="window.location.reload(true)" style="background: #2563eb; color: white; border: none; padding: 12px 24px; border-radius: 12px; font-weight: 600; cursor: pointer;">Atualizar Sistema</button>
      </div>
    </div>
  `;
}
