import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import { AuthProvider } from "@/contexts/AuthContext";
import { ViewAsBanner } from "@/components/ViewAsBanner";
import { RequireAdmin } from "@/components/RequireAdmin";
import Index from "./pages/Index";
import Auth from "./pages/Auth";
import ResetPasswordPage from "./pages/ResetPasswordPage";
import NotFound from "./pages/NotFound";
import PublicFormSubmitPage from "./pages/PublicFormSubmitPage";
import VendorInsuranceSubmitPage from "./pages/VendorInsuranceSubmitPage";
import VendorProfileSubmitPage from "./pages/VendorProfileSubmitPage";
import TenantInfoSubmitPage from "./pages/TenantInfoSubmitPage";
import UnsubscribePage from "./pages/UnsubscribePage";
import RVRenterPortalPage from "./pages/rv-portal/RVRenterPortalPage";
import CodeRegistrationPage from "./pages/CodeRegistrationPage";
import SignupCodesPage from "./pages/SignupCodesPage";
import {
  AccountingLayout,
  AccountingDashboardPage,
  AccountingChartOfAccountsPage,
  AccountingJournalEntriesPage,
  AccountingInvoicesPage,
  AccountingBillsPage,
  AccountingCustomersPage,
  AccountingVendorsPage,
  AccountingDepositsPage,
  AccountingReceivePaymentsPage,
  AccountingBankingPage,
  AccountingReconciliationPage,
  AccountingBudgetsPage,
  AccountingAssessmentsPage,
  AccountingWorkOrdersPage,
  AccountingOpeningBalancesPage,
  AccountingExpensesPage,
  AccountingEstimatesPage,
  AccountingReconcileDetailPage,
  AccountingBudgetDetailPage,
  AccountingCustomerDetailPage,
  AccountingSettingsLayout,
  AccountingGeneralSettingsPage,
  AccountingCheckSetupPage,
  AccountingIntegrationsPage,
  AccountingReportsPage as PlatformAccountingReportsPage,
} from "./pages/accounting/AccountingIndex";

// Admin/Manager Layout & Pages
import DashboardLayout from "./layouts/DashboardLayout";
import Dashboard from "./pages/Dashboard";
import AssociationsPage from "./pages/AssociationsPage";
import UnitsPage from "./pages/UnitsPage";
import OwnersPage from "./pages/OwnersPage";
import BulkUpdatesPage from "./pages/BulkUpdatesPage";
import OwnerProfilePage from "./pages/OwnerProfilePage";
import ViolationsPage from "./pages/ViolationsPage";
import ARCApplicationsPage from "./pages/ARCApplicationsPage";
import ARCInboundEmailsPage from "./pages/ARCInboundEmailsPage";
import ReportGeneratorPage from "./pages/ReportGeneratorPage";
import AssociationDetailPage from "./pages/AssociationDetailPage";
import GeneralLedgerPage from "./pages/GeneralLedgerPage";
import BillableExpensesPage from "./pages/BillableExpensesPage";
import InvoiceClientsPage from "./pages/InvoiceClientsPage";
import BoardMembersPage from "./pages/BoardMembersPage";
import AnnouncementsPage from "./pages/AnnouncementsPage";
import RemindersPage from "./pages/RemindersPage";
import SettingsPage from "./pages/SettingsPage";
import UnitProfilePage from "./pages/UnitProfilePage";
import ProjectsPage from "./pages/ProjectsPage";
import ProjectDetailPage from "./pages/ProjectDetailPage";
import CalendarPage from "./pages/CalendarPage";
import CallLogPage from "./pages/CallLogPage";
import DocumentsPage from "./pages/DocumentsPage";
import FormsLettersPage from "./pages/FormsLettersPage";
import OwnerUpdatesPage from "./pages/OwnerUpdatesPage";
import StatusUpdatesPage from "./pages/StatusUpdatesPage";
import TasksPage from "./pages/TasksPage";
import InspectionsPage from "./pages/InspectionsPage";
import AIInvoiceParserPage from "./pages/AIInvoiceParserPage";
import BlockedDatesPage from "./pages/BlockedDatesPage";
import ChecklistsPage from "./pages/ChecklistsPage";
import InvoiceTrackingPage from "./pages/InvoiceTrackingPage";
import ClientInvoicesPage from "./pages/ClientInvoicesPage";
import PayablesPage from "./pages/PayablesPage";
import PaymentsPage from "./pages/PaymentsPage";
import UserManagementPage from "./pages/UserManagementPage";
import BidsQuotesPage from "./pages/BidsQuotesPage";
import BillApprovalsPage from "./pages/BillApprovalsPage";
import BillDetailPage from "./pages/BillDetailPage";
import BoardVotesPage from "./pages/BoardVotesPage";
import ElectionsPage from "./pages/ElectionsPage";

import ClientRequestsPage from "./pages/ClientRequestsPage";
import CollectionsPage from "./pages/CollectionsPage";
import EstoppelsPage from "./pages/EstoppelsPage";
import HomeownerRequestsPage from "./pages/HomeownerRequestsPage";
import LegalMattersPage from "./pages/LegalMattersPage";
import ParkingPage from "./pages/ParkingPage";
import PaymentPlansPage from "./pages/PaymentPlansPage";
import BudgetManagementPage from "./pages/BudgetManagementPage";
import BankAccountsPage from "./pages/BankAccountsPage";
import BankRegisterPage from "./pages/BankRegisterPage";

import ReconciliationsPage from "./pages/ReconciliationsPage";
import ImportTransactionsPage from "./pages/ImportTransactionsPage";
import WriteChecksPage from "./pages/WriteChecksPage";
import PrintChecksPage from "./pages/PrintChecksPage";
import CompanyBankAccountsPage from "./pages/CompanyBankAccountsPage";
import CompanyBankAccountsHubPage from "./pages/CompanyBankAccountsHubPage";
import CompanyBankRegisterPage from "./pages/CompanyBankRegisterPage";
import CompanyChecksPage from "./pages/CompanyChecksPage";
import AccountingReportsPage from "./pages/AccountingReportsPage";
import ComposeEmailPage from "./pages/ComposeEmailPage";
import EmailHistoryPage from "./pages/EmailHistoryPage";
import EmailRoutingPage from "./pages/EmailRoutingPage";
import EmailSendersPage from "./pages/EmailSendersPage";

import EmailTemplatesPage from "./pages/EmailTemplatesPage";
import NotifyBoardPage from "./pages/NotifyBoardPage";
import NotifyOwnersPage from "./pages/NotifyOwnersPage";
import MailchimpPage from "./pages/MailchimpPage";
import DataMigration from "./pages/DataMigration";
import MediaLibraryPage from "./pages/MediaLibraryPage";
import MigrationFieldsPage from "./pages/MigrationFieldsPage";
import TimeTrackingPage from "./pages/TimeTrackingPage";

// New financial pages
import VendorsPage from "./pages/VendorsPage";
import VendorDetailPage from "./pages/VendorDetailPage";
import BillsPage from "./pages/BillsPage";
import InboundBillsPage from "./pages/InboundBillsPage";
import DirectoryPage from "./pages/DirectoryPage";
import CommitteesPage from "./pages/CommitteesPage";
import BillApprovalsHubPage from "./pages/BillApprovalsHubPage";
import BankAccountsHubPage from "./pages/BankAccountsHubPage";
import ChartOfAccountsPage from "./pages/ChartOfAccountsPage";
import OwnerLedgerPage from "./pages/OwnerLedgerPage";
import RecordOwnerPaymentPage from "./pages/RecordOwnerPaymentPage";
import DepositBatchesPage from "./pages/DepositBatchesPage";
import TransfersPage from "./pages/TransfersPage";
import BrandingSettingsPage from "./pages/settings/BrandingSettingsPage";
import RolePermissionsPage from "./pages/settings/RolePermissionsPage";
import GeneralSettingsPage from "./pages/settings/GeneralSettingsPage";
import PortalFunctionVisibilityPage from "./pages/settings/PortalFunctionVisibilityPage";
import MyProfilePage from "./pages/MyProfilePage";
import AdminStripeAccountsPage from "./pages/AdminStripeAccountsPage";
import BuildiumSettingsPage from "./pages/settings/BuildiumSettingsPage";
import BuildiumImportReviewPage from "./pages/settings/BuildiumImportReviewPage";
import RecurringRulesPage from "./pages/settings/RecurringRulesPage";
import FinancialReportsPage from "./pages/FinancialReportsPage";
import FinancialOverviewPage from "./pages/FinancialOverviewPage";
import RecentLedgerUpdatesPage from "./pages/RecentLedgerUpdatesPage";
import OutstandingBalancesPage from "./pages/OutstandingBalancesPage";
import BulkChargesPage from "./pages/BulkChargesPage";
import LedgerChargesReportPage from "./pages/LedgerChargesReportPage";
import DocuSignEnvelopesPage from "./pages/DocuSignEnvelopesPage";
import AvriaSignEnvelopesPage from "./pages/AvriaSignEnvelopesPage";
import PublicSignPage from "./pages/PublicSignPage";
import CollaborativeDocumentsPageAdmin from "./components/collaborative/CollaborativeDocumentsPage";

import FormInboxPage from "./pages/FormInboxPage";
import ComplianceChecklistPage from "./pages/ComplianceChecklistPage";
import ComplianceChecklistsHubPage from "./pages/ComplianceChecklistsHubPage";

// Client Portal Layout & Pages
import ClientLayout from "./layouts/ClientLayout";
import ClientHomePage from "./pages/client/ClientHomePage";
import ClientDocumentsPage from "./pages/client/ClientDocumentsPage";
import ClientTasksPage from "./pages/client/ClientTasksPage";
import ClientViolationsPage from "./pages/client/ClientViolationsPage";
import ClientViolationReportsPage from "./pages/client/ClientViolationReportsPage";
import ClientCalendarPage from "./pages/client/ClientCalendarPage";
import ClientPersonalCalendarPage from "./pages/client/ClientPersonalCalendarPage";
import ClientProjectsPage from "./pages/client/ClientProjectsPage";
import ClientCollectionsPage from "./pages/client/ClientCollectionsPage";
import ClientEstoppelsPage from "./pages/client/ClientEstoppelsPage";
import ClientStatusUpdatesPage from "./pages/client/ClientStatusUpdatesPage";
import ClientOwnerUpdatesPage from "./pages/client/ClientOwnerUpdatesPage";
import ClientHomeownerRequestsPage from "./pages/client/ClientHomeownerRequestsPage";
import ClientParkingPage from "./pages/client/ClientParkingPage";
import ClientBoardVotesPage from "./pages/client/ClientBoardVotesPage";
import ClientPaymentPlansPage from "./pages/client/ClientPaymentPlansPage";
import ClientBidsQuotesPage from "./pages/client/ClientBidsQuotesPage";
import ClientCallLogsPage from "./pages/client/ClientCallLogsPage";
import ClientDirectoryPage from "./pages/client/ClientDirectoryPage";

// Homeowner Portal Layout & Pages
import HomeownerLayout from "./layouts/HomeownerLayout";
import HomeownerHomePage from "./pages/homeowner/HomeownerHomePage";
import HomeownerProfilePage from "./pages/homeowner/HomeownerProfilePage";
import HomeownerLedgerPage from "./pages/homeowner/HomeownerLedgerPage";
import HomeownerDocumentsPage from "./pages/homeowner/HomeownerDocumentsPage";
import HomeownerStatementsPage from "./pages/homeowner/HomeownerStatementsPage";
import HomeownerPaymentsPage from "./pages/homeowner/HomeownerPaymentsPage";
import HomeownerARCPage from "./pages/homeowner/HomeownerARCPage";
import HomeownerElectionsPage from "./pages/homeowner/HomeownerElectionsPage";
import HomeownerViolationsPage from "./pages/homeowner/HomeownerViolationsPage";
import HomeownerAmenityCalendarPage from "./pages/homeowner/HomeownerAmenityCalendarPage";
import HomeownerDirectoryPage from "./pages/homeowner/HomeownerDirectoryPage";
import HomeownerTicketsPage from "./pages/homeowner/HomeownerTicketsPage";

// Board Member Pages
import BoardProjectsPage from "./pages/board/BoardProjectsPage";
import BoardCalendarPage from "./pages/board/BoardCalendarPage";
import BoardDocumentsPage from "./pages/board/BoardDocumentsPage";
import BoardStatusUpdatesPage from "./pages/board/BoardStatusUpdatesPage";
import BoardTasksPage from "./pages/board/BoardTasksPage";
import BoardARCPage from "./pages/board/BoardARCPage";
import BoardBidsQuotesPage from "./pages/board/BoardBidsQuotesPage";
import BoardBillApprovalsPage from "./pages/board/BoardBillApprovalsPage";
import BoardSubmitInvoicePage from "./pages/board/BoardSubmitInvoicePage";
import BoardBoardVotesPage from "./pages/board/BoardBoardVotesPage";
import BoardClientRequestsPage from "./pages/board/BoardClientRequestsPage";
import BoardHomeownerRequestsPage from "./pages/board/BoardHomeownerRequestsPage";
import BoardParkingPage from "./pages/board/BoardParkingPage";
import BoardAnnouncementsPage from "./pages/board/BoardAnnouncementsPage";
import BoardViolationsPage from "./pages/board/BoardViolationsPage";
import BoardOwnerRosterPage from "./pages/board/BoardOwnerRosterPage";
import BoardBillDetailPage from "./pages/board/BoardBillDetailPage";
import BoardReportsPage from "./pages/board/BoardReportsPage";
import BoardFinancialReportsPage from "./pages/board/BoardFinancialReportsPage";
import BoardFinancialOverviewPage from "./pages/board/BoardFinancialOverviewPage";
import BoardMessagesPage from "./pages/board/BoardMessagesPage";
import BoardCollaborativeDocsPage from "./pages/board/BoardCollaborativeDocsPage";
import BoardElectionsPage from "./pages/board/BoardElectionsPage";
import BoardResourcesPage from "./pages/board/BoardResourcesPage";
import BoardEstoppelsPage from "./pages/board/BoardEstoppelsPage";
import ManageBoardResourcesPage from "./pages/ManageBoardResourcesPage";
import MessagesPage from "./pages/MessagesPage";
import HomeownerMessagesPage from "./pages/homeowner/HomeownerMessagesPage";

// Legal Portal
import LegalLayout from "./layouts/LegalLayout";
import LegalCasesPage from "./pages/legal/LegalCasesPage";
import LegalCaseDetailPage from "./pages/legal/LegalCaseDetailPage";

// ARC Committee Portal
import ArcLayout from "./layouts/ArcLayout";
import ArcCommitteePage from "./pages/arc/ArcCommitteePage";

// Master Board Portal
import MasterBoardLayout from "./layouts/MasterBoardLayout";
import MasterBoardDashboardPage from "./pages/master-board/MasterBoardDashboardPage";

// Public pages (no auth required)
import ViolationResponsePage from "./pages/ViolationResponsePage";
import SharedAccessPage from "./pages/SharedAccessPage";
import VerifyDocumentPage from "./pages/VerifyDocumentPage";
import PrivacyPolicyPage from "./pages/PrivacyPolicyPage";
import TermsOfServicePage from "./pages/TermsOfServicePage";
import CommunityPage from "./pages/CommunityPage";
import CommunityAmenityPage from "./pages/CommunityAmenityPage";
import RVBoatLotsPage from "./pages/RVBoatLotsPage";
import PublicRVBoatWaitlistPage from "./pages/PublicRVBoatWaitlistPage";
import BookingConfirmationPage from "./pages/BookingConfirmationPage";
import ElectionVotePage from "./pages/ElectionVotePage";
import BoardVotePublicPage from "./pages/BoardVotePublicPage";
import BillApprovePublicPage from "./pages/BillApprovePublicPage";
const queryClient = new QueryClient();

const App = () => (
  <QueryClientProvider client={queryClient}>
    <AuthProvider>
      <TooltipProvider>
        <Toaster />
        <Sonner />
        <BrowserRouter>
          <ViewAsBanner />
          <Routes>
            <Route path="/" element={<Index />} />
            <Route path="/auth" element={<Auth />} />
            <Route path="/reset-password" element={<ResetPasswordPage />} />
            <Route path="/violation/:id" element={<ViolationResponsePage />} />
            <Route path="/shared/:token" element={<SharedAccessPage />} />
            <Route path="/verify/:proofId" element={<VerifyDocumentPage />} />
            <Route path="/public-form/:slug" element={<PublicFormSubmitPage />} />
            <Route path="/privacy" element={<PrivacyPolicyPage />} />
            <Route path="/terms" element={<TermsOfServicePage />} />
            <Route path="/community/:slug" element={<CommunityPage />} />
            <Route path="/community/:slug/amenities/:amenityId" element={<CommunityAmenityPage />} />
            <Route path="/booking/:bookingId" element={<BookingConfirmationPage />} />
            <Route path="/vote/:electionId" element={<ElectionVotePage />} />
            <Route path="/board-vote/:voteId" element={<BoardVotePublicPage />} />
            <Route path="/bill-approve/:billId" element={<BillApprovePublicPage />} />
            <Route path="/sign/:token" element={<PublicSignPage />} />
             <Route path="/vendor-insurance/:token" element={<VendorInsuranceSubmitPage />} />
             <Route path="/vendor-profile/:token" element={<VendorProfileSubmitPage />} />
             <Route path="/tenant-info/:token" element={<TenantInfoSubmitPage />} />
             <Route path="/rv-boat-waitlist/:associationId" element={<PublicRVBoatWaitlistPage />} />
             <Route path="/rv-portal" element={<RVRenterPortalPage />} />
             <Route path="/register/:code" element={<CodeRegistrationPage />} />
             <Route path="/unsubscribe" element={<UnsubscribePage />} />

            {/* ─── Admin / Manager Portal ─── */}
            <Route path="/dashboard" element={<DashboardLayout />}>
              <Route index element={<Dashboard />} />
              <Route path="projects" element={<ProjectsPage />} />
              <Route path="projects/:id" element={<ProjectDetailPage />} />
              <Route path="billable-expenses" element={<BillableExpensesPage />} />
              <Route path="invoice-clients" element={<InvoiceClientsPage />} />
              <Route path="calendar" element={<CalendarPage />} />
              <Route path="call-log" element={<CallLogPage />} />
              <Route path="documents" element={<DocumentsPage />} />
              <Route path="forms-letters" element={<FormsLettersPage />} />
              <Route path="owner-updates" element={<OwnerUpdatesPage />} />
              <Route path="reminders" element={<RemindersPage />} />
              <Route path="status-updates" element={<StatusUpdatesPage />} />
              <Route path="tasks" element={<TasksPage />} />
              <Route path="inspections" element={<InspectionsPage />} />
              <Route path="ai-invoice-parser" element={<AIInvoiceParserPage />} />
              <Route path="blocked-dates" element={<BlockedDatesPage />} />
              <Route path="checklists" element={<ChecklistsPage />} />
              <Route path="invoice-tracking" element={<InvoiceTrackingPage />} />
              <Route path="client-invoices" element={<ClientInvoicesPage />} />
              <Route path="payables" element={<PayablesPage />} />
              <Route path="payments" element={<PaymentsPage />} />
              <Route path="user-management" element={<UserManagementPage />} />
              <Route path="signup-codes" element={<SignupCodesPage />} />
              <Route path="rv-boat-lots" element={<RVBoatLotsPage />} />
              <Route path="arc-applications" element={<ARCApplicationsPage />} />
              <Route path="arc-inbound" element={<ARCInboundEmailsPage />} />
              <Route path="associations" element={<AssociationsPage />} />
              <Route path="associations/:id" element={<AssociationDetailPage />} />
              <Route path="compliance-checklists" element={<ComplianceChecklistsHubPage />} />
              <Route path="associations/:id/compliance" element={<ComplianceChecklistPage />} />
              <Route path="bids-quotes" element={<BidsQuotesPage />} />
              <Route path="bill-approvals" element={<BillApprovalsHubPage />} />
              <Route path="bill-approvals-list" element={<BillApprovalsPage />} />
              <Route path="bill-approvals/:id" element={<BillDetailPage />} />
              <Route path="directory" element={<DirectoryPage />} />
              <Route path="committees" element={<CommitteesPage />} />
              <Route path="board-members" element={<BoardMembersPage />} />
              <Route path="board-resources" element={<ManageBoardResourcesPage />} />
              <Route path="board-votes" element={<BoardVotesPage />} />
              <Route path="elections" element={<ElectionsPage />} />
              
              <Route path="form-inbox" element={<FormInboxPage />} />
              
              <Route path="client-requests" element={<ClientRequestsPage />} />
              <Route path="collections" element={<CollectionsPage />} />
              <Route path="estoppels" element={<EstoppelsPage />} />
              <Route path="homeowner-requests" element={<HomeownerRequestsPage />} />
              <Route path="legal-matters" element={<LegalMattersPage />} />
              <Route path="bulk-updates" element={<BulkUpdatesPage />} />
              <Route path="bulk-owner-updates" element={<BulkUpdatesPage />} />
              <Route path="bulk-unit-updates" element={<BulkUpdatesPage />} />
              <Route path="owner-roster" element={<OwnersPage />} />
              <Route path="owner-roster/:id" element={<OwnerProfilePage />} />
              <Route path="parking" element={<ParkingPage />} />
              <Route path="payment-plans" element={<PaymentPlansPage />} />
              <Route path="reports" element={<ReportGeneratorPage />} />
              <Route path="unit-directory" element={<UnitsPage />} />
              <Route path="units/:id" element={<UnitProfilePage />} />
              <Route path="violations" element={<ViolationsPage />} />
              <Route path="announcements" element={<AnnouncementsPage />} />
              <Route path="media" element={<MediaLibraryPage />} />
              <Route path="budget-management" element={<BudgetManagementPage />} />
              <Route path="budget-management/:id" element={<AccountingBudgetDetailPage basePath="/dashboard/budget-management" />} />
              <Route path="bank-accounts" element={<BankAccountsHubPage />} />
              <Route path="bank-accounts-list" element={<BankAccountsPage />} />
              <Route path="bank-register" element={<BankRegisterPage />} />
              
              <Route path="reconciliations" element={<ReconciliationsPage />} />
              <Route path="general-ledger" element={<GeneralLedgerPage />} />
              <Route path="import-transactions" element={<ImportTransactionsPage />} />
              <Route path="write-checks" element={<WriteChecksPage />} />
              <Route path="print-checks" element={<PrintChecksPage />} />
              <Route path="company-bank-accounts" element={<CompanyBankAccountsHubPage />} />
              <Route path="company-bank-register" element={<CompanyBankRegisterPage />} />
              <Route path="company-checks" element={<CompanyChecksPage />} />
              <Route path="accounting-reports" element={<AccountingReportsPage />} />
              <Route path="financial-reports" element={<FinancialReportsPage />} />
              <Route path="financial-overview" element={<FinancialOverviewPage />} />
              <Route path="accounting" element={<RequireAdmin><AccountingLayout /></RequireAdmin>}>
                <Route index element={<AccountingDashboardPage />} />
                <Route path="chart-of-accounts" element={<AccountingChartOfAccountsPage />} />
                <Route path="journal-entries" element={<AccountingJournalEntriesPage />} />
                <Route path="invoices" element={<AccountingInvoicesPage />} />
                <Route path="bills" element={<AccountingBillsPage />} />
                <Route path="customers" element={<AccountingCustomersPage />} />
                <Route path="customers/:id" element={<AccountingCustomerDetailPage />} />
                <Route path="vendors" element={<AccountingVendorsPage />} />
                <Route path="expenses" element={<AccountingExpensesPage />} />
                <Route path="estimates" element={<AccountingEstimatesPage />} />
                <Route path="deposits" element={<AccountingDepositsPage />} />
                <Route path="receive-payments" element={<AccountingReceivePaymentsPage />} />
                <Route path="banking" element={<AccountingBankingPage />} />
                <Route path="reconciliation" element={<AccountingReconciliationPage />} />
                <Route path="reconciliation/:accountId" element={<AccountingReconcileDetailPage />} />
                <Route path="budgets" element={<AccountingBudgetsPage />} />
                <Route path="budgets/:id" element={<AccountingBudgetDetailPage />} />
                <Route path="assessments" element={<AccountingAssessmentsPage />} />
                <Route path="work-orders" element={<AccountingWorkOrdersPage />} />
                <Route path="opening-balances" element={<AccountingOpeningBalancesPage />} />
                <Route path="reports" element={<PlatformAccountingReportsPage />} />
                <Route path="settings" element={<AccountingSettingsLayout />}>
                  <Route index element={<AccountingGeneralSettingsPage />} />
                  <Route path="check-setup" element={<AccountingCheckSetupPage />} />
                  <Route path="integrations" element={<AccountingIntegrationsPage />} />
                </Route>
              </Route>
              <Route path="recent-ledger-updates" element={<RecentLedgerUpdatesPage />} />
              <Route path="outstanding-balances" element={<OutstandingBalancesPage />} />
              <Route path="bulk-charges" element={<BulkChargesPage />} />
              <Route path="ledger-charges-report" element={<LedgerChargesReportPage />} />
              <Route path="compose-email" element={<ComposeEmailPage />} />
              <Route path="email-history" element={<EmailHistoryPage />} />
              <Route path="email-routing" element={<EmailRoutingPage />} />
              <Route path="email-senders" element={<EmailSendersPage />} />
              
              <Route path="email-templates" element={<EmailTemplatesPage />} />
              <Route path="notify-board" element={<NotifyBoardPage />} />
              <Route path="notify-owners" element={<NotifyOwnersPage />} />
              <Route path="mailchimp" element={<MailchimpPage />} />
              <Route path="messages" element={<MessagesPage />} />
              {/* Financial module */}
              <Route path="vendors" element={<VendorsPage />} />
              <Route path="vendors/:id" element={<VendorDetailPage />} />
              <Route path="bills" element={<BillsPage />} />
              <Route path="inbound-bills" element={<InboundBillsPage />} />
              <Route path="chart-of-accounts" element={<ChartOfAccountsPage />} />
              <Route path="owner-ledger" element={<OwnerLedgerPage />} />
              <Route path="record-payment" element={<RecordOwnerPaymentPage />} />
              <Route path="deposit-batches" element={<DepositBatchesPage />} />
              <Route path="transfers" element={<TransfersPage />} />
              <Route path="data-migration" element={<DataMigration />} />
              <Route path="migration-fields" element={<MigrationFieldsPage />} />
              <Route path="time-tracking" element={<TimeTrackingPage />} />
              <Route path="docusign" element={<DocuSignEnvelopesPage />} />
              <Route path="avria-sign" element={<AvriaSignEnvelopesPage />} />
              <Route path="collaborative-docs" element={<CollaborativeDocumentsPageAdmin />} />
              <Route path="settings" element={<SettingsPage />}>
                <Route index element={<GeneralSettingsPage />} />
                <Route path="general" element={<GeneralSettingsPage />} />
                <Route path="branding" element={<BrandingSettingsPage />} />
                <Route path="stripe-accounts" element={<AdminStripeAccountsPage />} />
                <Route path="role-permissions" element={<RolePermissionsPage />} />
                <Route path="portal-visibility" element={<PortalFunctionVisibilityPage />} />
                <Route path="buildium" element={<BuildiumSettingsPage />} />
                <Route path="buildium/review" element={<BuildiumImportReviewPage />} />
                <Route path="recurring-rules" element={<RecurringRulesPage />} />
                <Route path="profile" element={<MyProfilePage />} />
                <Route path="*" element={<GeneralSettingsPage />} />
              </Route>
            </Route>

            {/* ─── Client Portal ─── */}
            <Route path="/client" element={<ClientLayout />}>
              <Route index element={<ClientHomePage />} />
              <Route path="documents" element={<ClientDocumentsPage />} />
              <Route path="tasks" element={<ClientTasksPage />} />
              <Route path="violations" element={<ClientViolationsPage />} />
              <Route path="violation-reports" element={<ClientViolationReportsPage />} />
              <Route path="calendar" element={<ClientCalendarPage />} />
              <Route path="personal-calendar" element={<ClientPersonalCalendarPage />} />
              <Route path="projects" element={<ClientProjectsPage />} />
              <Route path="projects/:id" element={<ProjectDetailPage />} />
              <Route path="collections" element={<ClientCollectionsPage />} />
              <Route path="estoppels" element={<ClientEstoppelsPage />} />
              <Route path="status-updates" element={<ClientStatusUpdatesPage />} />
              <Route path="owner-updates" element={<ClientOwnerUpdatesPage />} />
              <Route path="homeowner-requests" element={<ClientHomeownerRequestsPage />} />
              <Route path="directory" element={<ClientDirectoryPage />} />
              <Route path="parking" element={<ClientParkingPage />} />
              <Route path="board-votes" element={<ClientBoardVotesPage />} />
              <Route path="payment-plans" element={<ClientPaymentPlansPage />} />
              <Route path="bids-quotes" element={<ClientBidsQuotesPage />} />
              <Route path="call-logs" element={<ClientCallLogsPage />} />
            </Route>

            {/* ─── Homeowner Portal ─── */}
            <Route path="/homeowner" element={<HomeownerLayout />}>
              <Route index element={<HomeownerHomePage />} />
              <Route path="profile" element={<HomeownerProfilePage />} />
              <Route path="ledger" element={<HomeownerLedgerPage />} />
              <Route path="documents" element={<HomeownerDocumentsPage />} />
              <Route path="arc" element={<HomeownerARCPage />} />
              <Route path="statements" element={<HomeownerStatementsPage />} />
              <Route path="payments" element={<HomeownerPaymentsPage />} />
              <Route path="tickets" element={<HomeownerTicketsPage />} />
              <Route path="amenity-calendar" element={<HomeownerAmenityCalendarPage />} />
              <Route path="elections" element={<HomeownerElectionsPage />} />
              <Route path="violations" element={<HomeownerViolationsPage />} />
              <Route path="messages" element={<HomeownerMessagesPage />} />
              <Route path="directory" element={<HomeownerDirectoryPage />} />
              {/* Board Member Routes */}
              <Route path="board/projects" element={<BoardProjectsPage />} />
              <Route path="board/projects/:id" element={<ProjectDetailPage />} />
              <Route path="board/calendar" element={<BoardCalendarPage />} />
              <Route path="board/documents" element={<BoardDocumentsPage />} />
              <Route path="board/status-updates" element={<BoardStatusUpdatesPage />} />
              <Route path="board/tasks" element={<BoardTasksPage />} />
              <Route path="board/arc-applications" element={<BoardARCPage />} />
              <Route path="board/bids-quotes" element={<BoardBidsQuotesPage />} />
              <Route path="board/bill-approvals" element={<BoardBillApprovalsPage />} />
              <Route path="board/bill-approvals/:id" element={<BoardBillDetailPage />} />
              <Route path="board/submit-invoice" element={<BoardSubmitInvoicePage />} />
              <Route path="board/board-votes" element={<BoardBoardVotesPage />} />
              <Route path="board/elections" element={<BoardElectionsPage />} />
              <Route path="board/client-requests" element={<BoardClientRequestsPage />} />
              <Route path="board/homeowner-requests" element={<BoardHomeownerRequestsPage />} />
              <Route path="board/owner-roster" element={<BoardOwnerRosterPage />} />
              <Route path="board/parking" element={<BoardParkingPage />} />
              <Route path="board/violations" element={<BoardViolationsPage />} />
              <Route path="board/announcements" element={<BoardAnnouncementsPage />} />
              <Route path="board/reports" element={<BoardReportsPage />} />
              <Route path="board/financial-reports" element={<BoardFinancialReportsPage />} />
              <Route path="board/financial-overview" element={<BoardFinancialOverviewPage />} />
              <Route path="board/messages" element={<BoardMessagesPage />} />
              <Route path="board/collaborative-docs" element={<BoardCollaborativeDocsPage />} />
              <Route path="board/resources" element={<BoardResourcesPage />} />
              <Route path="board/estoppels" element={<BoardEstoppelsPage />} />
            </Route>

            {/* ─── Legal Portal ─── */}
            <Route path="/legal" element={<LegalLayout />}>
              <Route index element={<LegalCasesPage />} />
              <Route path="case/:id" element={<LegalCaseDetailPage />} />
            </Route>

            {/* ─── ARC Committee Portal ─── */}
            <Route path="/arc" element={<ArcLayout />}>
              <Route index element={<ArcCommitteePage />} />
            </Route>

            {/* ─── Master Board Portal ─── */}
            <Route path="/master-board" element={<MasterBoardLayout />}>
              <Route index element={<MasterBoardDashboardPage />} />
              <Route path="projects" element={<BoardProjectsPage />} />
              <Route path="projects/:id" element={<ProjectDetailPage />} />
              <Route path="calendar" element={<BoardCalendarPage />} />
              <Route path="documents" element={<BoardDocumentsPage />} />
              <Route path="status-updates" element={<BoardStatusUpdatesPage />} />
              <Route path="tasks" element={<BoardTasksPage />} />
              <Route path="arc-applications" element={<BoardARCPage />} />
              <Route path="bids-quotes" element={<BoardBidsQuotesPage />} />
              <Route path="bill-approvals" element={<BoardBillApprovalsPage />} />
              <Route path="bill-approvals/:id" element={<BoardBillDetailPage />} />
              <Route path="submit-invoice" element={<BoardSubmitInvoicePage />} />
              <Route path="board-votes" element={<BoardBoardVotesPage />} />
              <Route path="elections" element={<BoardElectionsPage />} />
              <Route path="client-requests" element={<BoardClientRequestsPage />} />
              <Route path="homeowner-requests" element={<BoardHomeownerRequestsPage />} />
              <Route path="owner-roster" element={<BoardOwnerRosterPage />} />
              <Route path="parking" element={<BoardParkingPage />} />
              <Route path="violations" element={<BoardViolationsPage />} />
              <Route path="announcements" element={<BoardAnnouncementsPage />} />
              <Route path="reports" element={<BoardReportsPage />} />
              <Route path="financial-reports" element={<BoardFinancialReportsPage />} />
              <Route path="financial-overview" element={<BoardFinancialOverviewPage />} />
              <Route path="messages" element={<BoardMessagesPage />} />
              <Route path="collaborative-docs" element={<BoardCollaborativeDocsPage />} />
              <Route path="resources" element={<BoardResourcesPage />} />
            </Route>

            <Route path="*" element={<NotFound />} />
          </Routes>
        </BrowserRouter>
      </TooltipProvider>
    </AuthProvider>
  </QueryClientProvider>
);

export default App;
