<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <!-- Clear any previous tenant icon until Firestore resolves branding. -->
    <link
      rel="icon"
      href="/blank-favicon.svg"
    />
    <link
      rel="shortcut icon"
      href="/blank-favicon.svg"
    />
    <link
      rel="apple-touch-icon"
      href="/blank-favicon.svg"
    />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
    />
    <title>Private Pay</title>

    <!-- Pre-establish connections to external origins used at runtime so
         TCP+TLS handshakes are already done when JS requests them. -->
    <link
      rel="preconnect"
      href="https://fonts.googleapis.com"
    />
    <link
      rel="preconnect"
      href="https://fonts.gstatic.com"
      crossorigin
    />
    <link
      rel="preconnect"
      href="https://firestore.googleapis.com"
    />
    <link
      rel="preconnect"
      href="https://identitytoolkit.googleapis.com"
    />
    <link
      rel="preconnect"
      href="https://securetoken.googleapis.com"
    />

    <!-- Load Inter directly from the HTML <head> so the browser fetches it at
         parse time rather than after JS executes (eliminates the webfontloader
         JS waterfall — saves one full JS-execution round-trip). -->
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700&display=swap"
    />

    <link
      rel="stylesheet"
      type="text/css"
      href="/loader.css"
    />
    <script type="module" crossorigin src="/assets/index-DauUxa8D.js"></script>
    <link rel="modulepreload" crossorigin href="/assets/vendor-firebase-Heqn5NRL.js">
    <link rel="modulepreload" crossorigin href="/assets/vendor-vuetify-6gj6Ucxg.js">
    <link rel="modulepreload" crossorigin href="/assets/vendor-search-BEOrI6a0.js">
    <link rel="modulepreload" crossorigin href="/assets/vendor-sentry-DeszqKTo.js">
    <link rel="stylesheet" crossorigin href="/assets/vendor-vuetify-Cc1oqx5c.css">
    <link rel="stylesheet" crossorigin href="/assets/index-DORxcdwt.css">
  </head>

  <body>
    <div id="app">
      <div class="loading-logo">
        <div class="loading">
          <div class="effect-1 effects"></div>
          <div class="effect-2 effects"></div>
          <div class="effect-3 effects"></div>
        </div>
      </div>
      <template id="tygapay-dashboard-loader">
        <picture>
          <source media="(prefers-reduced-motion: reduce)" srcset="/tenant-assets/logo-dark.png" />
          <img src="/tygapay-dashboard-loader.svg" width="112" height="112" alt="" />
        </picture>
      </template>
      <template id="tenant-foil-loader">
        <span class="tenant-foil-logo" aria-hidden="true"></span>
      </template>
    </div>
    <script src="/tenant-runtime.js"></script>
    <script>
      // Restore theme colors for the CSS spinner before Vue initialises
      const appTitle = document.title
      const runtime = window.__TYGABANK_TENANT_RUNTIME__
      const isTygaPay = ['tyga-pay-0ehna', 'tyga-pay-sandbox-00pgi'].includes(runtime?.tenantId)
      if (isTygaPay) document.documentElement.classList.add('tygapay-ui')
      // The root route redirects to the dashboard. OTC also has a direct entry.
      const path = window.location.pathname
      const isOtc = /^\/otc\/?$/i.test(path)
      function stored(key) {
        try { return localStorage.getItem(key) } catch { return null }
      }
      const legacyPrefix = 'materio'
      const storedTheme =
        stored(`${appTitle}-theme`) || stored(`${legacyPrefix}-theme`) || (isTygaPay ? 'dark' : 'system')
      const isDarkMode =
        storedTheme === 'dark' ||
        (storedTheme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)
      const loaderColor = isTygaPay ? (isDarkMode ? '#0F1729' : '#F4F7FA') :
        stored(`${appTitle}-initial-loader-bg`) ||
        stored(`${legacyPrefix}-initial-loader-bg`) ||
        (isDarkMode ? '#181d26' : '#FFFFFF')
      const primaryColor = isTygaPay ? '#F8C630' :
        stored(`${appTitle}-initial-loader-color`) ||
        stored(`${legacyPrefix}-initial-loader-color`) ||
        (isDarkMode ? '#FFFFFF' : '#000000')

      if (loaderColor) {
        document.documentElement.style.setProperty('--initial-loader-bg', loaderColor)
      }

      if (primaryColor) {
        document.documentElement.style.setProperty('--initial-loader-color', primaryColor)
      }

      const hasTenantAssets = runtime?.tenantId && /^\/(?:[\w-]+\/)*[\w-]+\/?$/.test(runtime.assetBasePath)
      if ((isTygaPay || hasTenantAssets) && (path === '/' || /^\/my\/dashboard\/?$/i.test(path) || isOtc)) {
        const splash = document.querySelector('.loading-logo')
        const template = document.getElementById(isTygaPay ? 'tygapay-dashboard-loader' : 'tenant-foil-loader')
        const content = template.content.cloneNode(true)
        if (!isTygaPay) {
          const bundled = runtime.assetBasePath.replace(/\/$/, '') + (isDarkMode ? '/logo-light.png' : '/logo-dark.png')
          let cached
          try { cached = JSON.parse(stored(`${runtime.tenantId}-loader-logo`)) } catch { /* Use the bundled logo. */ }
          const preferred = isDarkMode ? cached?.primaryLight : cached?.primaryDark
          const mark = content.querySelector('.tenant-foil-logo')
          const image = new Image()
          const highlight = new Image()
          image.alt = highlight.alt = ''
          highlight.className = 'tenant-foil-highlight'
          function showLogo(url) {
            image.src = url
            highlight.src = url
          }
          image.onerror = () => {
            if (image.getAttribute('src') !== bundled) showLogo(bundled)
            else {
              mark.className = 'tenant-loading-name'
              mark.textContent = runtime.name || ''
            }
          }
          showLogo(typeof preferred === 'string' && preferred ? preferred : bundled)
          mark.append(image, highlight)
        }
        splash.classList.add('branded-startup-loader')
        // Vue clears #app on mount, before the initial route and its async layout are ready.
        document.getElementById('app').before(splash)
        if (!isDarkMode) splash.style.setProperty('--loader-caption', '#4a596e')
        splash.setAttribute('role', 'status')
        splash.setAttribute('aria-label', isOtc ? 'Opening OTC' : 'Opening your dashboard')
        splash.replaceChildren(content)
      }
    </script>
  </body>
</html>
