<!doctype html>
<html lang="fr">
<head>
  <% const appConfig = typeof app !== 'undefined' ? app : { appName: 'Lustra' }; %>
  <% const user = typeof currentUser !== 'undefined' ? currentUser : null; %>
  <% const company = typeof currentCompany !== 'undefined' ? currentCompany : null; %>
  <% const saasMarketing = typeof isSaasMarketing !== 'undefined' ? isSaasMarketing : false; %>
  <% const companyName = company && company.name ? company.name : (appConfig.appName || 'SaaS DEMO'); %>
  <% const companySlug = company && company.slug ? company.slug : 'saas-demo'; %>
  <% const layoutPublicSite = typeof publicSite !== 'undefined' ? publicSite : null; %>
  <% const tenantHomeUrl = layoutPublicSite?.homeUrl || (companySlug === 'saas-demo' ? '/demo/saas-demo' : `/site/${companySlug}`); %>
  <% const tenantPathBase = companySlug && companySlug !== 'saas-demo' ? `/site/${companySlug}` : ''; %>
  <% const publicServicesUrl = layoutPublicSite?.servicesUrl || (tenantPathBase ? `${tenantPathBase}/services` : '/services'); %>
  <% const publicGuidesUrl = layoutPublicSite?.guidesUrl || (tenantPathBase ? `${tenantPathBase}/infos-utiles` : '/infos-utiles'); %>
  <% const publicContactUrl = layoutPublicSite?.contactUrl || (tenantPathBase ? `${tenantPathBase}/contact` : '/contact'); %>
  <% const publicQuoteUrl = layoutPublicSite?.quoteUrl || (tenantPathBase ? `${tenantPathBase}/demander-un-devis` : '/demander-un-devis'); %>
  <% const publicTermsUrl = layoutPublicSite?.termsUrl || (tenantPathBase ? `${tenantPathBase}/conditions-generales` : '/conditions-generales'); %>
  <% const publicPrivacyUrl = layoutPublicSite?.privacyUrl || (tenantPathBase ? `${tenantPathBase}/confidentialite` : '/confidentialite'); %>
  <% const tenantAdminBaseUrl = typeof adminBaseUrl !== 'undefined' ? adminBaseUrl : (tenantPathBase ? `${tenantPathBase}/admin` : '/admin'); %>
  <% const tenantClientBaseUrl = typeof clientBaseUrl !== 'undefined' ? clientBaseUrl : (tenantPathBase ? `${tenantPathBase}/client` : '/client'); %>
  <% const tenantStaffBaseUrl = typeof staffBaseUrl !== 'undefined' ? staffBaseUrl : (tenantPathBase ? `${tenantPathBase}/agenda` : '/agenda'); %>
  <% const authLoginUrl = !saasMarketing && tenantPathBase ? `/auth/connexion?site=${companySlug}` : '/auth/connexion'; %>
  <% const saasBrandName = appConfig.appName || 'Lustra'; %>
  <% const saasBrandTagline = (appConfig.brandTagline) || 'Suite nettoyage'; %>
  <% const saasInitials = saasBrandName.split(/\s+/).filter(Boolean).slice(0, 2).map(part => part[0]).join('').toUpperCase() || 'LU'; %>
  <% const pageBrandName = saasMarketing ? saasBrandName : companyName; %>
  <% const tenantInitials = companyName.split(/\s+/).filter(Boolean).slice(0, 2).map(part => part[0]).join('').toUpperCase() || saasInitials; %>
  <% const tenantLogoPath = company && company.logo_path ? company.logo_path : ''; %>
  <% const token = typeof csrfToken !== 'undefined' ? csrfToken : ''; %>
  <% const flashMessage = typeof flash !== 'undefined' ? flash : null; %>
  <% const description = typeof metaDescription !== 'undefined' ? metaDescription : 'Lustra aide les entreprises de nettoyage à créer leur site vitrine, gérer clients, devis, factures, passages, employés, qualité terrain et messages.'; %>
  <% const canonicalUrl = typeof canonical !== 'undefined' ? canonical : ''; %>
  <% const schemas = typeof schemaJson !== 'undefined' ? schemaJson : []; %>
  <% const publicCta = typeof showPublicCta !== 'undefined' ? showPublicCta : false; %>
  <% const pathForRobots = typeof currentPath !== 'undefined' ? currentPath : ''; %>
  <% const robotsContent = typeof robotsMeta !== 'undefined' ? robotsMeta : (/^\/(auth|admin|client|agenda|fiduciaire|setup)/.test(pathForRobots) ? 'noindex,nofollow' : ''); %>
  <% const staticAssetVersion = typeof assetVersion !== 'undefined' ? assetVersion : '20260604b'; %>
  <% const tenantFiduciaryBaseUrl = typeof fiduciaryBaseUrl !== 'undefined' ? fiduciaryBaseUrl : (tenantPathBase ? `${tenantPathBase}/fiduciaire` : '/fiduciaire'); %>
  <% const userDashboardUrl = user ? (user.role === 'client' ? tenantClientBaseUrl : (user.role === 'employee' ? tenantStaffBaseUrl : (user.role === 'fiduciaire' ? tenantFiduciaryBaseUrl : tenantAdminBaseUrl))) : ''; %>
  <% const tenantIndustryLabelValue = layoutPublicSite && layoutPublicSite.industryLabel ? layoutPublicSite.industryLabel : (typeof tenantIndustryLabel !== 'undefined' ? tenantIndustryLabel : 'Nettoyage et entretien'); %>
  <% const tenantTemplateClass = !saasMarketing && layoutPublicSite?.builder?.template ? `tenant-template-${String(layoutPublicSite.builder.template).replace(/[^a-z0-9-]/gi, '')}` : ''; %>
  <% const studioWorkspace = /^\/admin\/studio/.test(pathForRobots) || /^\/site\/[^/]+\/admin\/studio/.test(pathForRobots); %>
  <% const mobilePublicBar = !saasMarketing && !user && !/^\/(auth|admin|client|agenda|fiduciaire|setup)/.test(pathForRobots); %>
  <% const mobileClientBar = user && user.role === 'client' && pathForRobots.startsWith('/client'); %>
  <% const mobileAdminBar = user && (user.role === 'admin' || user.is_responsible) && pathForRobots.startsWith('/admin'); %>
  <% const mobileStaffBar = user && (user.role === 'employee' || user.role === 'admin') && pathForRobots.startsWith('/agenda'); %>
  <% const hasMobileActionBar = mobilePublicBar || mobileClientBar || mobileAdminBar || mobileStaffBar; %>
  <% const adminWorkspace = user && (user.role === 'admin' || user.is_responsible) && /^\/admin/.test(pathForRobots || ''); %>
  <% const appWorkspace = user && /^\/(admin|client|agenda|fiduciaire|setup)/.test(pathForRobots || ''); %>
  <% const businessPhoneRaw = company && company.phone ? company.phone : (appConfig.business && appConfig.business.phone ? appConfig.business.phone : '079 000 00 00'); %>
  <% const businessPhoneHref = businessPhoneRaw.replace(/[^\d+]/g, '').replace(/^0/, '+41'); %>
  <% const whatsappPhone = businessPhoneHref.replace(/[^\d]/g, ''); %>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="csrf-token" content="<%= token %>">
  <title><%= title ? title + ' - ' : '' %><%= pageBrandName %></title>
  <meta name="description" content="<%= description %>">
  <% if (robotsContent) { %><meta name="robots" content="<%= robotsContent %>"><% } %>
  <% if (canonicalUrl) { %><link rel="canonical" href="<%= canonicalUrl %>"><% } %>
  <meta property="og:title" content="<%= title ? title + ' - ' : '' %><%= pageBrandName %>">
  <meta property="og:description" content="<%= description %>">
  <meta property="og:type" content="website">
  <meta name="theme-color" content="<%= company && company.primary_color ? company.primary_color : '#0b6f95' %>">
  <link rel="manifest" href="/public/manifest.webmanifest">
  <link rel="stylesheet" href="/public/css/styles.css?v=<%= staticAssetVersion %>">
  <link rel="stylesheet" href="/public/css/app.css?v=<%= staticAssetVersion %>">
  <link rel="stylesheet" href="/public/css/lustra.css?v=<%= staticAssetVersion %>">
  <% if (!saasMarketing && company) { %>
    <style>
      :root{--blue:<%= company.primary_color || '#0b6b88' %>;--teal:<%= company.secondary_color || '#20b86c' %>}
    </style>
  <% } %>
  <% schemas.forEach((schema) => { %>
    <script type="application/ld+json"><%- JSON.stringify(schema) %></script>
  <% }) %>
</head>
<body class="<%= hasMobileActionBar ? 'has-mobile-action-bar' : '' %> <%= user ? `app-body role-${user.role}` : 'public-body' %> <%= appWorkspace ? 'app-ui' : '' %> <%= saasMarketing ? 'saas-marketing-body' : '' %> <%= studioWorkspace ? 'studio-workspace-body' : '' %> <%= adminWorkspace ? 'admin-workspace-body' : '' %> <%= tenantTemplateClass %>">
  <% if (!adminWorkspace) { %>
    <header class="topbar">
      <a class="brand <%= saasMarketing ? 'saas-brand' : '' %>" href="<%= saasMarketing ? '/' : tenantHomeUrl %>">
        <% if (saasMarketing) { %>
          <span class="saas-brand-mark" aria-hidden="true"><%= saasInitials %></span>
          <span class="brand-text"><strong><%= saasBrandName %></strong><small><%= saasBrandTagline %></small></span>
        <% } else { %>
          <% if (tenantLogoPath) { %>
            <img class="brand-logo" src="<%= tenantLogoPath %>" alt="<%= companyName %>">
          <% } else { %>
            <span class="tenant-brand-mark" aria-hidden="true"><%= tenantInitials %></span>
          <% } %>
          <span class="brand-text"><strong><%= companyName %></strong><small><%= tenantIndustryLabelValue %></small></span>
        <% } %>
      </a>
      <button class="nav-toggle" type="button" data-nav-toggle>Menu</button>
      <nav class="nav" data-nav>
        <% if (!appWorkspace) { %>
          <% if (saasMarketing) { %>
            <a href="<%= pathForRobots === '/' ? '#fonctionnalites' : '/#fonctionnalites' %>">Fonctionnalités</a>
            <a href="/tarifs">Tarifs</a>
            <a href="/demo/saas-demo">Démo SaaS DEMO</a>
            <% if (typeof isSaasOwner !== 'undefined' && isSaasOwner) { %><a href="/saas-admin">Admin SaaS</a><% } %>
          <% } else { %>
            <a href="<%= tenantHomeUrl %>">Accueil</a>
            <a href="<%= publicServicesUrl %>">Services</a>
            <a href="<%= publicGuidesUrl %>">Infos utiles</a>
            <a href="<%= publicContactUrl %>">Contact</a>
          <% } %>
        <% } else { %>
          <a href="<%= tenantHomeUrl %>">Voir le site</a>
        <% } %>
        <% if (user) { %>
          <a href="<%= userDashboardUrl %>">Tableau de bord</a>
          <form method="post" action="/auth/deconnexion" class="inline-form"><input type="hidden" name="_csrf" value="<%= token %>"><button>Déconnexion</button></form>
        <% } else { %>
          <a href="<%= authLoginUrl %>">Connexion</a>
          <% if (saasMarketing) { %>
            <a class="button small quote-animated nav-quote-button" href="/auth/entreprise">Créer une entreprise</a>
          <% } else { %>
            <a class="button small quote-animated nav-quote-button" href="<%= publicQuoteUrl %>">Demander un devis</a>
          <% } %>
        <% } %>
      </nav>
    </header>
  <% } %>
  <% if (flashMessage) { %><div class="flash <%= flashMessage.type %>"><%= flashMessage.message %></div><% } %>
  <% if (adminWorkspace) { %>
    <%- partial('partials/admin-command') %>
  <% } %>
  <main>
    <%- body %>
  </main>
  <% if (!adminWorkspace) { %>
    <footer class="footer">
      <span>© <%= new Date().getFullYear() %> <%= saasMarketing ? saasBrandName : companyName %></span>
      <a href="<%= publicTermsUrl %>">Conditions générales</a>
      <a href="<%= publicPrivacyUrl %>">Confidentialité</a>
    </footer>
  <% } %>
  <% if (mobilePublicBar) { %>
    <nav class="mobile-action-bar" aria-label="Actions rapides">
      <a class="mobile-action mobile-action-call" href="tel:<%= businessPhoneHref %>">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1.9.3 1.7.6 2.5a2 2 0 0 1-.5 2.1L8 9.5a16 16 0 0 0 6.5 6.5l1.2-1.2a2 2 0 0 1 2.1-.5c.8.3 1.6.5 2.5.6A2 2 0 0 1 22 16.9z"/></svg>
        <span>Appeler</span>
      </a>
      <a class="mobile-action mobile-action-whatsapp" href="https://wa.me/<%= whatsappPhone %>?text=<%= encodeURIComponent(`Bonjour ${companyName}, je souhaite obtenir des informations pour une prestation.`) %>">
        <svg viewBox="0 0 32 32" aria-hidden="true"><path d="M26.7 5.3A14.5 14.5 0 0 0 4.1 22.5L2.5 29.5l7.1-1.7A14.5 14.5 0 0 0 26.7 5.3Z"/><path d="M11.5 9.5c-.4 0-.9.1-1.3.6-.5.5-1.6 1.6-1.6 3.8s1.7 4.4 1.9 4.7c.2.3 3.2 5.1 7.9 6.8 3.9 1.4 4.7.9 5.5.8.8-.1 2.6-1.1 3-2.1.4-1 .4-1.9.3-2.1-.1-.2-.4-.3-.9-.6l-2.8-1.4c-.4-.2-.8-.3-1.1.2-.3.5-1.2 1.5-1.5 1.8-.3.3-.6.3-1 .1-.5-.2-1.9-.7-3.5-2.2-1.3-1.2-2.2-2.7-2.5-3.1-.3-.5 0-.7.2-1 .2-.2.5-.6.7-.8.2-.3.3-.5.5-.9.2-.3.1-.6 0-.9L12 10c-.2-.4-.4-.5-.5-.5Z"/></svg>
        <span>WhatsApp</span>
      </a>
      <a class="mobile-action mobile-action-quote mobile-sticky-quote" href="<%= publicQuoteUrl %>">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>
        <span>Devis gratuit</span>
      </a>
    </nav>
  <% } %>
  <% if (mobileClientBar) { %>
    <nav class="mobile-action-bar mobile-app-bar" aria-label="Actions client">
      <a class="mobile-action <%= pathForRobots.startsWith('/client/devis') ? 'active' : '' %>" href="<%= tenantClientBaseUrl %>/devis">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 3h7l4 4v14H7z"/><path d="M14 3v5h5"/><path d="M10 12h6M10 16h6"/></svg>
        <span>Mes devis</span>
      </a>
      <a class="mobile-action <%= pathForRobots.startsWith('/client/factures') ? 'active' : '' %>" href="<%= tenantClientBaseUrl %>/factures">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 2h12v20l-3-2-3 2-3-2-3 2z"/><path d="M9 8h6M9 12h6M9 16h4"/></svg>
        <span>Factures</span>
      </a>
      <a class="mobile-action <%= pathForRobots.startsWith('/client/messages') ? 'active' : '' %>" href="<%= tenantClientBaseUrl %>/messages">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M21 15a4 4 0 0 1-4 4H8l-5 3V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4z"/></svg>
        <span>Messages</span>
      </a>
    </nav>
  <% } %>
  <% if (mobileAdminBar) { %>
    <nav class="mobile-action-bar mobile-app-bar" aria-label="Actions admin">
      <% if (user.role === 'admin') { %>
        <a class="mobile-action <%= pathForRobots.startsWith('/admin/demandes') ? 'active' : '' %>" href="<%= tenantAdminBaseUrl %>/demandes">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 6h13M8 12h13M8 18h13"/><path d="M3 6h.01M3 12h.01M3 18h.01"/></svg>
          <span>Demandes</span>
        </a>
        <a class="mobile-action <%= pathForRobots.startsWith('/admin/clients') ? 'active' : '' %>" href="<%= tenantAdminBaseUrl %>/clients">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M19 8v6M22 11h-6"/></svg>
          <span>Clients</span>
        </a>
      <% } else { %>
        <a class="mobile-action <%= pathForRobots.startsWith('/admin/clients') ? 'active' : '' %>" href="<%= tenantAdminBaseUrl %>/clients">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></svg>
          <span>Clients</span>
        </a>
      <% } %>
      <a class="mobile-action <%= pathForRobots.startsWith('/admin/interventions') ? 'active' : '' %>" href="<%= tenantAdminBaseUrl %>/interventions">
        <svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/><path d="M8 14h.01M12 14h.01M16 14h.01"/></svg>
        <span>Planning</span>
      </a>
      <% if (user.role !== 'admin') { %>
        <a class="mobile-action <%= pathForRobots.startsWith('/admin/photos') ? 'active' : '' %>" href="<%= tenantAdminBaseUrl %>/photos">
          <svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="M21 15l-3.5-3.5L10 19"/></svg>
          <span>Photos</span>
        </a>
      <% } %>
    </nav>
  <% } %>
  <% if (mobileStaffBar) { %>
    <nav class="mobile-action-bar mobile-app-bar" aria-label="Actions équipe">
      <a class="mobile-action active" href="<%= tenantStaffBaseUrl %>">
        <svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4M8 2v4M3 10h18"/></svg>
        <span>Agenda</span>
      </a>
      <a class="mobile-action" href="<%= tenantStaffBaseUrl %>?status=planifiee">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/></svg>
        <span>À faire</span>
      </a>
      <% if (user.role === 'admin' || user.is_responsible) { %>
        <a class="mobile-action" href="<%= tenantAdminBaseUrl %>/interventions">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 3v18h18"/><path d="M7 14l3-3 4 4 5-7"/></svg>
          <span>Gestion</span>
        </a>
      <% } else { %>
        <a class="mobile-action" href="<%= tenantStaffBaseUrl %>?status=terminee">
          <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>
          <span>Heures</span>
        </a>
      <% } %>
    </nav>
  <% } %>
  <script src="/public/js/app.js?v=<%= staticAssetVersion %>"></script>
  <script src="/public/js/pwa.js?v=<%= staticAssetVersion %>"></script>
</body>
</html>
