import { lazy, Suspense } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Navigate, 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 { ProtectedRoute } from "@/components/ProtectedRoute";
import { GlobalAudioUnlock } from "@/components/GlobalAudioUnlock";
import { DeferredGlobals } from "@/components/DeferredGlobals";
import { NyMusicPlayerProvider } from "@/contexts/NyMusicPlayerContext";
import { NyVideoPlayerProvider } from "@/contexts/NyVideoPlayerContext";
import { NyMusicMiniPlayer } from "@/components/ny-music/NyMusicMiniPlayer";
import { NyVideoMiniPlayer } from "@/components/ny-music/NyVideoMiniPlayer";
import { AppErrorBoundary } from "@/components/AppErrorBoundary";
import { TrialGate } from "@/components/TrialGate";
import { Loader2 } from "lucide-react";

// Eager-loaded: rotas críticas iniciais
import LoginPage from "./pages/LoginPage";
import NotFound from "./pages/NotFound";

// Lazy: páginas pesadas (carregadas sob demanda)
const ShukkinPage = lazy(() => import("./pages/ShukkinPage"));
const NippoKakuninPage = lazy(() => import("./pages/NippoKakuninPage"));
const TimecardPage = lazy(() => import("./pages/TimecardPage"));
const Dashboard = lazy(() => import("./pages/Dashboard"));

// Lazy-loaded: demais rotas (carregadas sob demanda)
const GenbaList = lazy(() => import("./pages/GenbaList"));
const GenbaDetail = lazy(() => import("./pages/GenbaDetail"));
const SeikyuList = lazy(() => import("./pages/SeikyuList"));
const SeikyuDetail = lazy(() => import("./pages/SeikyuDetail"));
const ChumonList = lazy(() => import("./pages/ChumonList"));
const ChumonDetail = lazy(() => import("./pages/ChumonDetail"));
const ShiharaiList = lazy(() => import("./pages/ShiharaiList"));
const ShiharaiDetail = lazy(() => import("./pages/ShiharaiDetail"));
const ShainList = lazy(() => import("./pages/ShainList"));
const TorihikiList = lazy(() => import("./pages/TorihikiList"));
const ShouhinList = lazy(() => import("./pages/ShouhinList"));
const SharyoList = lazy(() => import("./pages/SharyoList"));
const KyujitsuPage = lazy(() => import("./pages/KyujitsuPage"));
const KouguList = lazy(() => import("./pages/KouguList"));
const KouguScanPage = lazy(() => import("./pages/KouguScanPage"));
const NenshouDoui = lazy(() => import("./pages/NenshouDoui"));
const ZaishokuShoumei = lazy(() => import("./pages/ZaishokuShoumei"));
const SagyouinMeibo = lazy(() => import("./pages/SagyouinMeibo"));
const GenbaSchedule = lazy(() => import("./pages/GenbaSchedule"));
const NinkuMonitor = lazy(() => import("./pages/NinkuMonitor"));
const TelegramPage = lazy(() => import("./pages/TelegramPage"));
const ManualPage = lazy(() => import("./pages/ManualPage"));
const MyProfilePage = lazy(() => import("./pages/MyProfilePage"));
const CredentialsPage = lazy(() => import("./pages/CredentialsPage"));
const MaekarikiniIraisho = lazy(() => import("./pages/MaekarikiniIraisho"));
const MaegariRireki = lazy(() => import("./pages/MaegariRireki"));
const YuukyuuTodoke = lazy(() => import("./pages/YuukyuuTodoke"));
const JitsumuKeikenPage = lazy(() => import("./pages/JitsumuKeikenPage"));
const MitsumoriHikaku = lazy(() => import("./pages/MitsumoriHikaku"));
const EtcRoutesPage = lazy(() => import("./pages/EtcRoutesPage"));
const FeatureVisibilityPage = lazy(() => import("./pages/FeatureVisibilityPage"));
const AppVersionsPage = lazy(() => import("./pages/AppVersionsPage"));
const AuditLogPage = lazy(() => import("./pages/AuditLogPage"));
const TrashPage = lazy(() => import("./pages/TrashPage"));
const SettingsPage = lazy(() => import("./pages/SettingsPage"));
const CardList = lazy(() => import("./pages/CardList"));
const CardPurchasesPage = lazy(() => import("./pages/CardPurchasesPage"));
const WorkSchedulePage = lazy(() => import("./pages/WorkSchedulePage"));
const EvaluationPage = lazy(() => import("./pages/EvaluationPage"));
const EpiPage = lazy(() => import("./pages/EpiPage"));
const KyRecordPage = lazy(() => import("./pages/KyRecordPage"));
const SafetyDocumentsPage = lazy(() => import("./pages/SafetyDocumentsPage"));
const QualificationPage = lazy(() => import("./pages/QualificationPage"));
const InspectionPage = lazy(() => import("./pages/InspectionPage"));
const DrawingsPage = lazy(() => import("./pages/DrawingsPage"));
const ExpenseClaimPage = lazy(() => import("./pages/ExpenseClaimPage"));
const MonthlyNinkuPage = lazy(() => import("./pages/MonthlyNinkuPage"));
const KouguMaintenancePage = lazy(() => import("./pages/KouguMaintenancePage"));
const MyKouguPage = lazy(() => import("./pages/MyKouguPage"));
const GenbaTrainingPage = lazy(() => import("./pages/GenbaTrainingPage"));
const GenbaMaterialsPage = lazy(() => import("./pages/GenbaMaterialsPage"));
const GenbaCostPanel = lazy(() => import("./pages/GenbaCostPanel"));
const MonthlyZairyoPage = lazy(() => import("./pages/MonthlyZairyoPage"));
const InspectionCalendarPage = lazy(() => import("./pages/InspectionCalendarPage"));
const TranslatePage = lazy(() => import("./pages/TranslatePage"));
const ShikudaiAdminPage = lazy(() => import("./pages/ShikudaiAdminPage"));
const EventPage = lazy(() => import("./pages/EventPage"));
const LazyZaikoPage = lazy(() => import("./pages/PlaceholderPages").then(m => ({ default: m.ZaikoPage })));
const ZaikoRirekiPage = lazy(() => import("./pages/ZaikoRirekiPage"));
const SupplierCategoryPage = lazy(() => import("./pages/SupplierCategoryPage"));
const YoteihyouCalendarPage = lazy(() => import("./pages/yoteihyou/YoteihyouCalendarPage"));
const YoteihyouUploadPage = lazy(() => import("./pages/yoteihyou/YoteihyouUploadPage"));
const YoteihyouSimulatorPage = lazy(() => import("./pages/yoteihyou/YoteihyouSimulatorPage"));
const YoteihyouProductivityPage = lazy(() => import("./pages/yoteihyou/YoteihyouProductivityPage"));
const YoteihyouGenbaDetailPage = lazy(() => import("./pages/yoteihyou/YoteihyouGenbaDetailPage"));
const NyMitsumoriList = lazy(() => import("./pages/ny-mitsumori/NyMitsumoriList"));
const NyMitsumoriEditor = lazy(() => import("./pages/ny-mitsumori/NyMitsumoriEditor"));
const NyMitsumoriSettings = lazy(() => import("./pages/ny-mitsumori/NyMitsumoriSettings"));
const CableScrapPage = lazy(() => import("./pages/CableScrapPage"));
const GenkinKanriPage = lazy(() => import("./pages/GenkinKanriPage"));
const TelegramRecipientsPage = lazy(() => import("./pages/TelegramRecipientsPage"));
const TelegramGroupsPage = lazy(() => import("./pages/TelegramGroupsPage"));
const KojoKanriPage = lazy(() => import("./pages/KojoKanriPage"));
const MyKojoPage = lazy(() => import("./pages/MyKojoPage"));
const NyMusicPage = lazy(() => import("./pages/NyMusicPage"));
const R2MigrationPage = lazy(() => import("./pages/R2MigrationPage"));
const SagyoufukuPage = lazy(() => import("./pages/SagyoufukuPage"));
const BingoPage = lazy(() => import("./pages/BingoPage"));
const BingoAdminPage = lazy(() => import("./pages/BingoAdminPage"));
const BingoGuestPage = lazy(() => import("./pages/BingoGuestPage"));
const BingoTvPage = lazy(() => import("./pages/BingoTvPage"));
const AmidakujiAdminPage = lazy(() => import("./pages/AmidakujiAdminPage"));
const AmidakujiGuestPage = lazy(() => import("./pages/AmidakujiGuestPage"));
const ShashinQuizAdminPage = lazy(() => import("./pages/ShashinQuizAdminPage"));
const ShashinQuizGuestPage = lazy(() => import("./pages/ShashinQuizGuestPage"));
const HayaoshiAdminPage = lazy(() => import("./pages/HayaoshiAdminPage"));
const HayaoshiGuestPage = lazy(() => import("./pages/HayaoshiGuestPage"));
const MeishiPage = lazy(() => import("./pages/MeishiPage"));
const GenbaChatGuestPage = lazy(() => import("./pages/GenbaChatGuestPage"));
const MeetingsPage = lazy(() => import("./pages/MeetingsPage"));
const MeetingRoomPage = lazy(() => import("./pages/MeetingRoomPage"));
const MeetingJoinPage = lazy(() => import("./pages/MeetingJoinPage"));
// シフト管理 (新モジュール - テスト中)
const ShiftDailyPage = lazy(() => import("./pages/shift/ShiftDailyPage"));
const ShiftAssignmentPage = lazy(() => import("./pages/shift/ShiftAssignmentPage"));
const ShiftGanttPage = lazy(() => import("./pages/shift/ShiftGanttPage"));
const ShiftMonitorPage = lazy(() => import("./pages/shift/ShiftMonitorPage"));
const ShiftTeamsPage = lazy(() => import("./pages/shift/ShiftTeamsPage"));
const ShiftMonitorConfigPage = lazy(() => import("./pages/shift/ShiftMonitorConfigPage"));
// シフト管理 v2 (work-map-light style)
const ShiftBoardPage = lazy(() => import("./pages/shift/ShiftBoardPage"));
const ShiftDayPage = lazy(() => import("./pages/shift/ShiftDayPage"));
const ShiftExtraJobsPage = lazy(() => import("./pages/shift/ShiftExtraJobsPage"));
const ShiftPlaceholderPagesMod = lazy(() => import("./pages/shift/ShiftPlaceholderPages").then(m => ({ default: m.ShiftKoteihyouPage })));
const ShiftHanGenbaPage = lazy(() => import("./pages/shift/ShiftPlaceholderPages").then(m => ({ default: m.ShiftHanGenbaPage })));
const ShiftMasterPage = lazy(() => import("./pages/shift/ShiftPlaceholderPages").then(m => ({ default: m.ShiftMasterPage })));
const ShiftMonitorViewPage = lazy(() => import("./pages/shift/ShiftPlaceholderPages").then(m => ({ default: m.ShiftMonitorViewPage })));

// シフト管理 v2 (protótipo paralelo /shift2/*)
const Shift2Index = lazy(() => import("./pages/shift2/Shift2Index"));
const ShiftBoardV2 = lazy(() => import("./pages/shift2/ShiftBoardV2"));
const ShiftDayV2 = lazy(() => import("./pages/shift2/ShiftDayV2"));
const ExtraJobsV2 = lazy(() => import("./pages/shift2/ExtraJobsV2"));
const ProjectScheduleV2 = lazy(() => import("./pages/shift2/ProjectScheduleV2"));
const MastersV2 = lazy(() => import("./pages/shift2/MastersV2"));
const CrewSitesV2 = lazy(() => import("./pages/shift2/CrewSitesV2"));
const ShiftMonitorV2 = lazy(() => import("./pages/shift2/ShiftMonitorV2"));
const ShiftMonitorPublic = lazy(() => import("./pages/shift2/ShiftMonitorPublic"));

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 10 * 60 * 1000,
      gcTime: 30 * 60 * 1000,
      refetchOnWindowFocus: false,
      refetchOnReconnect: true,
      refetchOnMount: true,
      retry: 1,
      networkMode: "offlineFirst",
    },
  },
});

const PageFallback = () => (
  <div className="flex items-center justify-center min-h-screen">
    <Loader2 className="h-6 w-6 animate-spin text-primary" />
  </div>
);

const App = () => (
  <QueryClientProvider client={queryClient}>
    <AppErrorBoundary>
      <TooltipProvider>
        <Toaster />
        <Sonner />
        <BrowserRouter>
          <TrialGate>
          <AuthProvider>
            <GlobalAudioUnlock />
            <DeferredGlobals />
            <NyMusicPlayerProvider>
              <NyVideoPlayerProvider>
                <Suspense fallback={<PageFallback />}>
              <Routes>
              <Route path="/login" element={<LoginPage />} />
              <Route path="/" element={<ProtectedRoute><Dashboard /></ProtectedRoute>} />
              <Route path="/genba" element={<ProtectedRoute><GenbaList /></ProtectedRoute>} />
              <Route path="/genba/:id" element={<ProtectedRoute><GenbaDetail /></ProtectedRoute>} />
              <Route path="/seikyu" element={<ProtectedRoute><SeikyuList /></ProtectedRoute>} />
              <Route path="/seikyu/:id" element={<ProtectedRoute><SeikyuDetail /></ProtectedRoute>} />
              <Route path="/chumon" element={<ProtectedRoute><ChumonList /></ProtectedRoute>} />
              <Route path="/chumon/:id" element={<ProtectedRoute><ChumonDetail /></ProtectedRoute>} />
              <Route path="/shiharai" element={<ProtectedRoute><ShiharaiList /></ProtectedRoute>} />
              <Route path="/shiharai/:id" element={<ProtectedRoute><ShiharaiDetail /></ProtectedRoute>} />
              <Route path="/shain" element={<ProtectedRoute><ShainList /></ProtectedRoute>} />
              <Route path="/torihiki" element={<ProtectedRoute><TorihikiList /></ProtectedRoute>} />
              <Route path="/timecard" element={<ProtectedRoute><TimecardPage /></ProtectedRoute>} />
              <Route path="/shukkin" element={<ProtectedRoute><ShukkinPage /></ProtectedRoute>} />
              <Route path="/nippo" element={<ProtectedRoute><NippoKakuninPage /></ProtectedRoute>} />
              <Route path="/kyujitsu" element={<ProtectedRoute><KyujitsuPage /></ProtectedRoute>} />
              <Route path="/shouhin" element={<ProtectedRoute><ShouhinList /></ProtectedRoute>} />
              <Route path="/meishi" element={<ProtectedRoute><MeishiPage /></ProtectedRoute>} />
              <Route path="/kougu" element={<ProtectedRoute><KouguList /></ProtectedRoute>} />
              <Route path="/kougu/scan" element={<ProtectedRoute><KouguScanPage /></ProtectedRoute>} />
              <Route path="/zaiko" element={<ProtectedRoute><LazyZaikoPage /></ProtectedRoute>} />
              <Route path="/zaiko-rireki" element={<ProtectedRoute><ZaikoRirekiPage /></ProtectedRoute>} />
              <Route path="/supplier-category" element={<ProtectedRoute><SupplierCategoryPage /></ProtectedRoute>} />
              <Route path="/sharyo" element={<ProtectedRoute><SharyoList /></ProtectedRoute>} />
              <Route path="/nenshou-doui" element={<ProtectedRoute><NenshouDoui /></ProtectedRoute>} />
              <Route path="/zaishoku-shoumei" element={<ProtectedRoute><ZaishokuShoumei /></ProtectedRoute>} />
              <Route path="/sagyouin-meibo" element={<ProtectedRoute><SagyouinMeibo /></ProtectedRoute>} />
              <Route path="/genba-schedule" element={<ProtectedRoute><GenbaSchedule /></ProtectedRoute>} />
              <Route path="/ninku-monitor" element={<ProtectedRoute><NinkuMonitor /></ProtectedRoute>} />
              <Route path="/telegram" element={<ProtectedRoute><TelegramPage /></ProtectedRoute>} />
              <Route path="/manual" element={<ProtectedRoute><ManualPage /></ProtectedRoute>} />
              <Route path="/my-profile" element={<ProtectedRoute><MyProfilePage /></ProtectedRoute>} />
              <Route path="/credentials" element={<ProtectedRoute><CredentialsPage /></ProtectedRoute>} />
              <Route path="/maekarikini" element={<ProtectedRoute><MaekarikiniIraisho /></ProtectedRoute>} />
              <Route path="/maegari-rireki" element={<ProtectedRoute><MaegariRireki /></ProtectedRoute>} />
              <Route path="/yuukyuu" element={<ProtectedRoute><YuukyuuTodoke /></ProtectedRoute>} />
              <Route path="/jitsumu-keiken" element={<ProtectedRoute><JitsumuKeikenPage /></ProtectedRoute>} />
              <Route path="/mitsumori-hikaku" element={<ProtectedRoute><MitsumoriHikaku /></ProtectedRoute>} />
              <Route path="/etc-routes" element={<ProtectedRoute><EtcRoutesPage /></ProtectedRoute>} />
              <Route path="/feature-visibility" element={<ProtectedRoute adminOnly><FeatureVisibilityPage /></ProtectedRoute>} />
              <Route path="/audit-log" element={<ProtectedRoute adminOnly><AuditLogPage /></ProtectedRoute>} />
              <Route path="/app-versions" element={<ProtectedRoute adminOnly><AppVersionsPage /></ProtectedRoute>} />
              <Route path="/trash" element={<ProtectedRoute adminOnly><TrashPage /></ProtectedRoute>} />
              <Route path="/settings" element={<ProtectedRoute><SettingsPage /></ProtectedRoute>} />
              <Route path="/cards" element={<ProtectedRoute><CardList /></ProtectedRoute>} />
              <Route path="/card-purchases" element={<ProtectedRoute><CardPurchasesPage /></ProtectedRoute>} />
              <Route path="/work-schedule" element={<ProtectedRoute><WorkSchedulePage /></ProtectedRoute>} />
              <Route path="/evaluation" element={<ProtectedRoute><EvaluationPage /></ProtectedRoute>} />
              <Route path="/epi" element={<ProtectedRoute><EpiPage /></ProtectedRoute>} />
              <Route path="/ky-record" element={<ProtectedRoute><KyRecordPage /></ProtectedRoute>} />
              <Route path="/safety-documents" element={<ProtectedRoute><SafetyDocumentsPage /></ProtectedRoute>} />
              <Route path="/qualifications" element={<ProtectedRoute><QualificationPage /></ProtectedRoute>} />
              <Route path="/inspections" element={<ProtectedRoute><InspectionPage /></ProtectedRoute>} />
              <Route path="/drawings" element={<ProtectedRoute><DrawingsPage /></ProtectedRoute>} />
              <Route path="/expense-claims" element={<ProtectedRoute><ExpenseClaimPage /></ProtectedRoute>} />
              <Route path="/monthly-ninku" element={<ProtectedRoute><MonthlyNinkuPage /></ProtectedRoute>} />
              <Route path="/kougu-maintenance" element={<ProtectedRoute><KouguMaintenancePage /></ProtectedRoute>} />
              <Route path="/my-kougu" element={<ProtectedRoute><MyKouguPage /></ProtectedRoute>} />
              <Route path="/genba-training" element={<ProtectedRoute><GenbaTrainingPage /></ProtectedRoute>} />
              <Route path="/genba-materials" element={<ProtectedRoute><GenbaMaterialsPage /></ProtectedRoute>} />
              <Route path="/genba-cost" element={<ProtectedRoute><GenbaCostPanel /></ProtectedRoute>} />
              <Route path="/monthly-zairyo" element={<ProtectedRoute adminOnly><MonthlyZairyoPage /></ProtectedRoute>} />
              <Route path="/inspection-calendar" element={<ProtectedRoute><InspectionCalendarPage /></ProtectedRoute>} />
              <Route path="/translate" element={<ProtectedRoute><TranslatePage /></ProtectedRoute>} />
              <Route path="/shikudai-admin" element={<ProtectedRoute adminOnly><ShikudaiAdminPage /></ProtectedRoute>} />
              <Route path="/events" element={<ProtectedRoute><EventPage /></ProtectedRoute>} />
              <Route path="/yoteihyou" element={<ProtectedRoute><YoteihyouCalendarPage /></ProtectedRoute>} />
              <Route path="/yoteihyou/upload" element={<ProtectedRoute><YoteihyouUploadPage /></ProtectedRoute>} />
              <Route path="/yoteihyou/simulator" element={<ProtectedRoute><YoteihyouSimulatorPage /></ProtectedRoute>} />
              <Route path="/yoteihyou/productivity" element={<ProtectedRoute><YoteihyouProductivityPage /></ProtectedRoute>} />
              <Route path="/yoteihyou/genba/:projectName" element={<ProtectedRoute><YoteihyouGenbaDetailPage /></ProtectedRoute>} />
              <Route path="/ny-mitsumori" element={<ProtectedRoute><NyMitsumoriList /></ProtectedRoute>} />
              <Route path="/ny-mitsumori/settings" element={<ProtectedRoute><NyMitsumoriSettings /></ProtectedRoute>} />
              <Route path="/ny-mitsumori/new" element={<ProtectedRoute><NyMitsumoriEditor /></ProtectedRoute>} />
              <Route path="/ny-mitsumori/:id" element={<ProtectedRoute><NyMitsumoriEditor /></ProtectedRoute>} />
              <Route path="/cable-scrap" element={<ProtectedRoute adminOnly><CableScrapPage /></ProtectedRoute>} />
              <Route path="/genkin-kanri" element={<ProtectedRoute adminOnly><GenkinKanriPage /></ProtectedRoute>} />
              <Route path="/telegram-recipients" element={<ProtectedRoute adminOnly><TelegramRecipientsPage /></ProtectedRoute>} />
              <Route path="/telegram-groups" element={<ProtectedRoute adminOnly><TelegramGroupsPage /></ProtectedRoute>} />
              <Route path="/kojo-kanri" element={<ProtectedRoute adminOnly><KojoKanriPage /></ProtectedRoute>} />
              <Route path="/my-kojo" element={<ProtectedRoute><MyKojoPage /></ProtectedRoute>} />
              <Route path="/ny-music" element={<ProtectedRoute><NyMusicPage /></ProtectedRoute>} />
              <Route path="/r2-migration" element={<ProtectedRoute adminOnly><R2MigrationPage /></ProtectedRoute>} />
              <Route path="/sagyoufuku" element={<ProtectedRoute><SagyoufukuPage /></ProtectedRoute>} />
              <Route path="/bingo" element={<ProtectedRoute><BingoPage /></ProtectedRoute>} />
              <Route path="/bingo-admin" element={<ProtectedRoute><BingoAdminPage /></ProtectedRoute>} />
              <Route path="/bingo-guest/:sessionId" element={<BingoGuestPage />} />
              <Route path="/bingo-tv" element={<BingoTvPage />} />
              <Route path="/amidakuji-admin" element={<ProtectedRoute><AmidakujiAdminPage /></ProtectedRoute>} />
              <Route path="/amidakuji-guest/:sessionId" element={<AmidakujiGuestPage />} />
              <Route path="/shashin-quiz-admin" element={<ProtectedRoute><ShashinQuizAdminPage /></ProtectedRoute>} />
              <Route path="/shashin-quiz-guest/:sessionId" element={<ShashinQuizGuestPage />} />
              <Route path="/hayaoshi-admin" element={<ProtectedRoute><HayaoshiAdminPage /></ProtectedRoute>} />
              <Route path="/hayaoshi-guest/:sessionId" element={<HayaoshiGuestPage />} />
              <Route path="/genba-chat-guest/:token" element={<GenbaChatGuestPage />} />
              <Route path="/meeting-join/:roomName" element={<MeetingJoinPage />} />
              <Route path="/meetings" element={<ProtectedRoute><MeetingsPage /></ProtectedRoute>} />
              <Route path="/meetings/:roomName" element={<MeetingRoomPage />} />
              {/* シフト管理 - 新モジュール (テスト中, admin+manager) */}
              <Route path="/shift/daily" element={<ProtectedRoute><ShiftDailyPage /></ProtectedRoute>} />
              <Route path="/shift/assignment" element={<ProtectedRoute><ShiftAssignmentPage /></ProtectedRoute>} />
              <Route path="/shift/gantt" element={<ProtectedRoute><ShiftGanttPage /></ProtectedRoute>} />
              <Route path="/shift/teams" element={<ProtectedRoute><ShiftTeamsPage /></ProtectedRoute>} />
              <Route path="/shift/monitor-config" element={<ProtectedRoute><ShiftMonitorConfigPage /></ProtectedRoute>} />
              {/* モニター表示 - トークン認証で公開 (ログイン不要) */}
              <Route path="/shift/monitor/:token" element={<ShiftMonitorPage />} />
              {/* シフト管理 v2 (work-map-light style) */}
              <Route path="/shift-board" element={<Navigate to="/shift2/board" replace />} />
              <Route path="/shift-board-v1" element={<ProtectedRoute><ShiftBoardPage /></ProtectedRoute>} />
              <Route path="/shift-day" element={<ProtectedRoute><ShiftDayPage /></ProtectedRoute>} />
              <Route path="/extra-jobs" element={<ProtectedRoute><ShiftExtraJobsPage /></ProtectedRoute>} />
              <Route path="/shift-extra-jobs" element={<ProtectedRoute><ShiftExtraJobsPage /></ProtectedRoute>} />
              <Route path="/shift-koteihyou" element={<ProtectedRoute><ProjectScheduleV2 /></ProtectedRoute>} />
              <Route path="/shift-han-genba" element={<ProtectedRoute><ShiftHanGenbaPage /></ProtectedRoute>} />
              <Route path="/shift-master" element={<ProtectedRoute><ShiftMasterPage /></ProtectedRoute>} />
              <Route path="/shift-monitor-view" element={<ProtectedRoute><ShiftMonitorViewPage /></ProtectedRoute>} />

              {/* シフト管理 v2 - protótipo paralelo */}
              <Route path="/shift2" element={<ProtectedRoute><Shift2Index /></ProtectedRoute>} />
              <Route path="/shift2/board" element={<ProtectedRoute><ShiftBoardV2 /></ProtectedRoute>} />
              <Route path="/shift2/day" element={<ProtectedRoute><ShiftDayV2 /></ProtectedRoute>} />
              <Route path="/shift2/extra-jobs" element={<ProtectedRoute><ExtraJobsV2 /></ProtectedRoute>} />
              <Route path="/shift2/projects" element={<ProtectedRoute><ProjectScheduleV2 /></ProtectedRoute>} />
              <Route path="/shift2/masters" element={<ProtectedRoute><MastersV2 /></ProtectedRoute>} />
              <Route path="/shift2/crew-sites" element={<ProtectedRoute><CrewSitesV2 /></ProtectedRoute>} />
              <Route path="/shift2/monitor" element={<ProtectedRoute><ShiftMonitorV2 /></ProtectedRoute>} />
              {/* モニター公開リンク (ログイン不要・トークン認証) */}
              <Route path="/shift2/monitor/public/:token" element={<ShiftMonitorPublic />} />

              <Route path="*" element={<NotFound />} />
              </Routes>
            </Suspense>
            <NyMusicMiniPlayer />
            <NyVideoMiniPlayer />
            </NyVideoPlayerProvider>
            </NyMusicPlayerProvider>
          </AuthProvider>
          </TrialGate>
        </BrowserRouter>
      </TooltipProvider>
    </AppErrorBoundary>
  </QueryClientProvider>
);

export default App;
