<!DOCTYPE html>
<html lang="pt-BR">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
  <!-- iPad/iOS PWA — Add to Home Screen -->
  <meta name="mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
  <meta name="apple-mobile-web-app-title" content="" />
  <link rel="apple-touch-icon" sizes="180x180" id="apple-touch-icon" href="" />
  <title></title>
  <meta name="description" content="" />
  <link id="favicon" rel="icon" type="image/png" href="" />
  <!-- Preconnect for Core Web Vitals -->
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet" />
  <link rel="preconnect" href="https://iefppahyskbnsaogvzem.supabase.co" />
  <link rel="dns-prefetch" href="https://iefppahyskbnsaogvzem.supabase.co" />
  <link rel="dns-prefetch" href="https://www.googletagmanager.com" />
  <link rel="dns-prefetch" href="https://www.google-analytics.com" />
  <!-- AI Discoverability -->
  <link rel="manifest" href="/.well-known/ai-plugin.json" />
  <link rel="author" href="/llms.txt" type="text/plain" />
  
  <script>
    // Set title, description & favicon BEFORE React boots to prevent flash.
    // Registry mirrors SITE_REGISTRY in src/utils/resolvePortalIdentity.ts.
    // To add a new portal: add ONE entry here AND in resolvePortalIdentity.ts.
    (function () {
      var h = location.hostname;
      var p = location.pathname;
      var isLocal = h === 'localhost' || h === '127.0.0.1' || h.indexOf('192.168.') === 0;

      // Registry: [domainMatch[], localPaths[], title, description, favicon, shortName]
      var sites = [
        [['cattive.com','cattive.me'], ['/cattive','/login'], 'Cattive', 'Plataforma AI-First para Portais de Notícias', '/images/logos/cattive-favicon.png', 'Cattive'],
        [['publicidade.legal','publicidadelegalbrasil'], ['/publicidade-legal'], 'Publicidade.Legal', 'Homologação Oficial de Publicidade Legal e Atos Societários.', '/images/logos/cattive-favicon.png', 'Pub. Legal'],
        [['jornaldebarueri'], ['/jb'], 'Jornal de Barueri', 'Portal de Notícias de Barueri e região.', '/images/logos/jb-icon.png', 'JB'],
        [['allphaville'], ['/alphaville'], 'Allphaville', 'Portal de Notícias de Alphaville e região.', '/images/logos/cattive-favicon.png', 'Allphaville'],
        [['nossasp'], ['/sp'], 'Nossa SP', 'Portal de Notícias de São Paulo e região.', '/favicon-sp.ico', 'Nossa SP'],
        [['vivaamericana'], ['/americana'], 'Viva Americana', 'Portal de Notícias de Americana e região.', '/images/logos/cattive-favicon.png', 'Americana'],
        [['cbnamazonia'], ['/cbn-amazonia'], 'CBN Amazônia', 'CBN Amazônia - Seu portal regional de notícias com credibilidade.', '/images/logos/cattive-favicon.png', 'CBN Amazônia'],
        [['portalamazonia'], ['/portal-amazonia'], 'Portal Amazônia', 'Portal de Notícias da Amazônia.', '/images/logos/cattive-favicon.png', 'P. Amazônia'],
        [['amanha.com'], ['/grupo-amanha'], 'Grupo Amanhã', 'Portal do Grupo Amanhã.', '/images/logos/cattive-favicon.png', 'Amanhã'],
      ];

      // System routes (admin, console) — use Cattive branding
      var systemPaths = ['/admin', '/console'];

      var matched = null;

      // 1. Production: match by domain
      if (!isLocal) {
        for (var i = 0; i < sites.length; i++) {
          for (var d = 0; d < sites[i][0].length; d++) {
            if (h.indexOf(sites[i][0][d]) !== -1) { matched = sites[i]; break; }
          }
          if (matched) break;
        }
      } else {
        // 2. Localhost: match by path prefix
        for (var i = 0; i < sites.length; i++) {
          for (var lp = 0; lp < sites[i][1].length; lp++) {
            if (p === sites[i][1][lp] || p.indexOf(sites[i][1][lp] + '/') === 0) { matched = sites[i]; break; }
          }
          if (matched) break;
        }
        // 3. Localhost system routes → Cattive branding
        if (!matched) {
          for (var s = 0; s < systemPaths.length; s++) {
            if (p.indexOf(systemPaths[s]) === 0) {
              matched = [[], [], 'Cattive Platform', 'Cattive Platform', '/images/logos/cattive-favicon.png', 'Cattive'];
              break;
            }
          }
        }
      }

      // 4. Fallback: localhost root → Cattive Platform, production unknown → JB
      if (!matched) {
        matched = isLocal
          ? [[], [], 'Cattive Platform', 'Cattive Platform — Ambiente de Desenvolvimento Local', '/images/logos/cattive-favicon.png', 'Cattive']
          : [[], [], 'Jornal de Barueri', 'Portal de Notícias', '/images/logos/jb-icon.png', 'JB'];
      }

      // Apply
      var appleTitle = document.querySelector('meta[name="apple-mobile-web-app-title"]');
      var appleTouchIcon = document.getElementById('apple-touch-icon');
      document.title = matched[2];
      document.querySelector('meta[name="description"]').content = matched[3];
      document.getElementById('favicon').href = matched[4];
      if (appleTitle) appleTitle.content = matched[5];
      if (appleTouchIcon) appleTouchIcon.href = matched[4];

      // ── Google Analytics Boot (with Consent Mode v2) ──
      // GA loads synchronously for Google's verification bot to detect.
      // Consent Mode v2 ensures NO data is collected until user accepts cookies.
      // Multi-tenant: Each portal can have its own GA measurement ID.
      // Admin/console subdomains are always excluded.
      (function() {
        var gaRegistry = {
          'jornaldebarueri': 'G-CCYGRP3XJ3'
          // Add other portals here: 'cbnamazonia': 'G-XXXXXXXXXX'
        };

        // Skip admin/console/auth subdomains
        var sub = h.split('.')[0];
        if (sub === 'admin' || sub === 'console' || sub === 'auth' || sub === 'myaccount') return;

        // Skip localhost
        if (isLocal) return;

        // Find matching GA ID by domain
        var gaId = null;
        for (var key in gaRegistry) {
          if (h.indexOf(key) !== -1) { gaId = gaRegistry[key]; break; }
        }
        if (!gaId) return;

        // Initialize gtag
        window.dataLayer = window.dataLayer || [];
        window.gtag = function() { window.dataLayer.push(arguments); };

        // ── Consent Mode v2 ──
        // Check if user already gave consent (stored by PortalCookieBanner)
        var priorConsent = null;
        try { priorConsent = localStorage.getItem('portal_cookie_consent'); } catch(e) {}
        var analyticsGranted = priorConsent === 'all';

        // Set consent defaults BEFORE config (required by Google)
        window.gtag('consent', 'default', {
          analytics_storage: analyticsGranted ? 'granted' : 'denied',
          ad_storage: 'denied',
          ad_user_data: analyticsGranted ? 'granted' : 'denied',
          ad_personalization: 'denied',
          wait_for_update: 500
        });

        window.gtag('js', new Date());
        window.gtag('config', gaId, { send_page_view: analyticsGranted });

        // Mark as injected for the React hook to detect
        window.__GA_MEASUREMENT_ID = gaId;
        window.__GA_CONSENT_GRANTED = analyticsGranted;

        var s = document.createElement('script');
        s.async = true;
        s.src = 'https://www.googletagmanager.com/gtag/js?id=' + gaId;
        document.head.appendChild(s);
      })();

      // Generate dynamic Web Manifest for PWA
      var isAdminPage = location.hostname.startsWith('admin.') || location.hostname.startsWith('console.') || location.pathname.startsWith('/admin') || location.pathname.startsWith('/console');
      var logoSrc = document.getElementById('favicon').href;
      var manifest = {
        name: document.title,
        short_name: appleTitle ? appleTitle.content : document.title,
        description: document.querySelector('meta[name="description"]').content,
        start_url: isAdminPage ? "/admin" : "/",
        display: "standalone",
        background_color: "#ffffff",
        theme_color: (matched[2] === 'Cattive' || matched[2] === 'Cattive Platform') ? "#0f172a" : matched[2] === 'Publicidade.Legal' ? "#1e293b" : "#2563eb",
        icons: [
          {
            src: logoSrc,
            sizes: "192x192",
            type: "image/png",
            purpose: "any maskable"
          },
          {
            src: logoSrc,
            sizes: "512x512",
            type: "image/png",
            purpose: "any maskable"
          }
        ]
      };

      // Web Share Target API for Admin
      if (isAdminPage) {
        manifest.shortcuts = [
          { name: "Novo Artigo", short_name: "Artigo", url: "/admin/posts/new", icons: [{ src: logoSrc, sizes: "192x192" }] },
          { name: "Nova Imagem (DAM)", short_name: "Mídia", url: "/admin/media", icons: [{ src: logoSrc, sizes: "192x192" }] }
        ];

        manifest.share_target = {
          action: "/admin/media",
          method: "POST",
          enctype: "multipart/form-data",
          params: {
            title: "title",
            text: "text",
            url: "url",
            files: [
              {
                name: "file",
                accept: ["image/jpeg", "image/png", "image/webp", "video/mp4"]
              }
            ]
          }
        };
      }

      // Encode manifest as Data URI to avoid CORS and Blob destruction issues
      var manifestJson = encodeURIComponent(JSON.stringify(manifest));
      var link = document.createElement('link');
      link.rel = 'manifest';
      link.href = 'data:application/manifest+json;charset=utf-8,' + manifestJson;
      document.head.appendChild(link);
    })();
  </script>
  <script type="module" crossorigin src="/assets/index-CLUIECCT.js"></script>
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-CBRBZKdN.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-ui-DJbIYrdX.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-supabase-UBwEW4nm.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-charts-B3X4mxW5.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-editor-BOGfFXm4.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-sonner-DVkgLA0Q.js">
  <link rel="modulepreload" crossorigin href="/assets/vendor-helmet-mWFK-ZiZ.js">
  <link rel="stylesheet" crossorigin href="/assets/index-NEX_cbqK.css">
</head>

<body class="bg-slate-50 text-slate-900 antialiased selection:bg-blue-100 selection:text-blue-900">
  <!-- #A11 — Skip Navigation Link -->
  <a href="#main-content" style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-[9999] focus:bg-blue-600 focus:text-white focus:px-4 focus:py-2 focus:rounded-lg focus:text-sm focus:font-medium focus:shadow-lg">Pular para o conteúdo</a>
  <div id="global-admin-preloader-container"></div>
  <div id="root"></div>
  <script>
    (function() {
      var h = location.hostname;
      var p = location.pathname;
      var isAdminPage = h.startsWith('admin.') || h.startsWith('console.') || p.startsWith('/admin') || p.startsWith('/console');
      if (isAdminPage) {
        var preloaderContainer = document.getElementById('global-admin-preloader-container');
        if (preloaderContainer) {
          preloaderContainer.innerHTML = '<style>.uni-loader{position:fixed;top:0;left:0;width:100%;height:100%;z-index:99999;background:#fafafa;transition:opacity .4s ease}.uni-loader-bar{position:absolute;top:0;left:0;width:100%;height:2px;overflow:hidden}.uni-loader-bar::after{content:"";position:absolute;top:0;left:-40%;width:40%;height:100%;background:linear-gradient(90deg,transparent,rgba(0,0,0,.12),transparent);animation:uni-shimmer 1.4s ease-in-out infinite}@keyframes uni-shimmer{0%{left:-40%}100%{left:100%}}@media(prefers-color-scheme:dark){.uni-loader{background:#0a0a0a}.uni-loader-bar::after{background:linear-gradient(90deg,transparent,rgba(255,255,255,.08),transparent)}}</style><div id="global-admin-preloader" class="uni-loader"><div class="uni-loader-bar"></div></div>';
        }
      }
    })();
  </script>
</body>

</html>