<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <title><?= e(APP_NAME) ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <meta name="theme-color" content="#1351b4">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="apple-mobile-web-app-title" content="Prefeitura Resolve">
    <link rel="manifest" href="<?= asset_url('/manifest.json') ?>">
    <link rel="apple-touch-icon" href="<?= asset_url('/assets/img/icon-192.png') ?>">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Raleway:wght@600;700;800&family=Rawline:wght@400;500;600;700&display=swap">
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
    <link rel="stylesheet" href="<?= asset_url('/assets/css/style.css') ?>">
    <link rel="stylesheet" href="<?= asset_url('/assets/css/public.css') ?>">
    <link rel="stylesheet" href="<?= asset_url('/assets/css/public-mobile.css') ?>?v=170">
</head>
<body class="public-body app-shell">
    <header class="topbar govbar app-header">
        <div class="container topbar-inner mobile-first">
            <a class="brand-wrap brand-link" href="<?= base_url('/') ?>">
                <div class="brand-mark">PR</div>
                <div>
                    <div class="eyebrow">Prefeitura Digital</div>
                    <h1>Prefeitura Resolve</h1>
                </div>
            </a>
            <button type="button" class="mobile-install-chip hidden" id="mobile-install-chip">Instalar</button>
            <nav class="main-nav desktop-nav">
                <a href="<?= base_url('/') ?>">Início</a>
                <a href="<?= base_url('/registrar') ?>">Registrar</a>
                <a href="<?= base_url('/consultar') ?>">Consultar</a>
                <a href="<?= base_url('/login') ?>">Admin</a>
            </nav>
        </div>
    </header>

    <main class="container page-content app-main">
        <?php require $viewFile; ?>
    </main>

    <nav class="mobile-bottom-nav" aria-label="Menu rápido">
        <?php $routeAtual = isset($_GET['route']) ? (string) $_GET['route'] : '/'; ?>
        <a href="<?= base_url('/') ?>" class="<?= ($routeAtual === '/' || $routeAtual === '') ? 'is-active' : '' ?>"><span>🏠</span><small>Início</small></a>
        <a href="<?= base_url('/registrar') ?>" class="<?= strpos($routeAtual, '/registrar') === 0 ? 'is-active' : '' ?>"><span>📍</span><small>Registrar</small></a>
        <a href="<?= base_url('/consultar') ?>" class="<?= strpos($routeAtual, '/consultar') === 0 ? 'is-active' : '' ?>"><span>🔎</span><small>Consultar</small></a>
    </nav>

    <div class="install-sheet" id="install-sheet" aria-live="polite">
        <h3>Instalar app</h3>
        <p>Adicione o Prefeitura Resolve à tela inicial do seu celular para abrir mais rápido, em tela cheia e com cara de aplicativo.</p>
        <div class="install-sheet-actions">
            <button type="button" class="btn" id="install-now-btn">Instalar</button>
            <button type="button" class="btn btn-outline" id="install-later-btn">Agora não</button>
        </div>
    </div>

    <script>
        window.PREFEITURA_RESOLVE = {
            baseUrl: <?= json_encode(app_base_path()) ?>,
            homeUrl: <?= json_encode(base_url('/')) ?>,
            registerUrl: <?= json_encode(base_url('/registrar')) ?>,
            manifestUrl: <?= json_encode(asset_url('/manifest.json')) ?>
        };
    </script>
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <script src="<?= asset_url('/assets/js/mapa.js') ?>?v=170"></script>
    <script src="<?= asset_url('/assets/js/public-mobile.js') ?>?v=170"></script>
</body>
</html>
