{
  "version": "0.4",
  "title": "Caisse Tactile POS - SmartPOS AI (Version Light Complète)",
  "type": "page",
  "content": [
    {
      "id": "sec_lmfb11p",
      "elType": "section",
      "isInner": false,
      "settings": {
        "layout": "full_width",
        "stretch_section": "section-stretched",
        "background_background": "classic",
        "background_color": "#f8fafc",
        "padding": {
          "unit": "px",
          "top": "0",
          "right": "0",
          "bottom": "0",
          "left": "0",
          "isLinked": true
        }
      },
      "elements": [
        {
          "id": "col_zz8f97h",
          "elType": "column",
          "isInner": false,
          "settings": {
            "_column_size": 100,
            "_inline_size": null,
            "padding": {
              "unit": "px",
              "top": "0",
              "right": "0",
              "bottom": "0",
              "left": "0",
              "isLinked": true
            }
          },
          "elements": [
            {
              "id": "wid_no08ka8",
              "elType": "widget",
              "isInner": false,
              "widgetType": "html",
              "settings": {
                "html": "<div id=\"smartpos-standalone-app\" style=\"font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: #0f172a; background: #f8fafc; border-radius: 20px; border: 1px solid #e2e8f0; padding: 24px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.05), 0 8px 10px -6px rgba(0,0,0,0.01); width: 100%; box-sizing: border-box;\">\n  <style>\n    #smartpos-standalone-app p:empty { display: none !important; margin: 0 !important; padding: 0 !important; }\n    #smartpos-standalone-app > p { display: none !important; margin: 0 !important; padding: 0 !important; }\n    #smartpos-standalone-app br { display: none !important; }\n    #smartpos-standalone-app * { box-sizing: border-box; }\n    \n    .sp-pos-layout {\n      display: flex !important;\n      flex-direction: row !important;\n      gap: 24px !important;\n      width: 100% !important;\n      align-items: flex-start !important;\n    }\n    @media (max-width: 991px) {\n      .sp-pos-layout { flex-direction: column !important; }\n      .sp-pos-cart-col { width: 100% !important; min-width: 100% !important; }\n    }\n    .sp-pos-catalog {\n      flex: 1 1 0% !important;\n      min-width: 0 !important;\n      width: 100% !important;\n    }\n    .sp-pos-cart-col {\n      width: 380px !important;\n      min-width: 320px !important;\n      flex-shrink: 0 !important;\n    }\n    .sp-products-grid {\n      display: grid !important;\n      grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;\n      gap: 14px !important;\n      width: 100% !important;\n    }\n    .sp-btn-touch {\n      cursor: pointer;\n      user-select: none;\n      transition: all 0.15s ease;\n    }\n    .sp-btn-touch:hover {\n      transform: translateY(-2px);\n      box-shadow: 0 6px 16px rgba(0,0,0,0.06);\n    }\n    .sp-btn-touch:active {\n      transform: scale(0.97);\n    }\n  </style>\n\n  <!-- POS HEADER BAR -->\n  <div style=\"display: flex; justify-content: space-between; align-items: center; background: #ffffff; border: 1px solid #e2e8f0; border-radius: 16px; padding: 14px 20px; margin-bottom: 20px; flex-wrap: wrap; gap: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);\">\n    <div style=\"display: flex; align-items: center; gap: 12px;\">\n      <div style=\"background: linear-gradient(135deg, #10b981, #059669); color: white; width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; box-shadow: 0 4px 10px rgba(16,185,129,0.25);\">⚡</div>\n      <div>\n        <div style=\"display: flex; align-items: center; gap: 8px;\">\n          <h2 style=\"margin: 0; font-size: 18px; font-weight: 800; color: #0f172a; letter-spacing: -0.02em;\">SmartPOS AI Pro</h2>\n          <span style=\"background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 9999px;\">NF525 CERTIFIÉ</span>\n        </div>\n        <p style=\"margin: 2px 0 0; font-size: 11px; color: #64748b;\">Caisse Tactile WooCommerce • Alex Dupont (Caisse 01)</p>\n      </div>\n    </div>\n    <div style=\"display: flex; align-items: center; gap: 10px;\">\n      <div style=\"background: #f1f5f9; padding: 6px 12px; border-radius: 10px; border: 1px solid #e2e8f0; font-size: 12px; font-weight: 600; color: #334155;\">\n        📍 Table 04 • Sur place\n      </div>\n      <div id=\"sp-live-clock\" style=\"background: #f8fafc; padding: 6px 12px; border-radius: 10px; border: 1px solid #e2e8f0; font-family: monospace; font-size: 12px; color: #059669; font-weight: 700;\">\n        12:00:00\n      </div>\n    </div>\n  </div>\n\n  <!-- MAIN WORKSPACE -->\n  <div class=\"sp-pos-layout\">\n    \n    <!-- LEFT: CATALOG -->\n    <div class=\"sp-pos-catalog\">\n      \n      <!-- Search and Scanner Simulation -->\n      <div style=\"background: #ffffff; padding: 10px 14px; border-radius: 14px; border: 1px solid #e2e8f0; margin-bottom: 14px; display: flex; align-items: center; gap: 10px;\">\n        <span style=\"font-size: 16px;\">🔍</span>\n        <input \n          type=\"text\" \n          id=\"sp-search-input\" \n          oninput=\"spFilterProducts()\" \n          placeholder=\"Rechercher un article, un code SKU, un plat...\" \n          style=\"width: 100%; border: none; outline: none; background: transparent; font-size: 13px; color: #0f172a;\"\n        />\n        <span style=\"font-size: 11px; background: #f1f5f9; color: #475569; padding: 3px 8px; border-radius: 6px; font-family: monospace; white-space: nowrap;\">SCAN READY</span>\n      </div>\n\n      <!-- Categories Pills -->\n      <div style=\"display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 16px;\">\n        <button onclick=\"spSetCategory('all', this)\" class=\"sp-cat-btn\" style=\"padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 700; border: none; cursor: pointer; background: #10b981; color: #ffffff; white-space: nowrap;\">Tous les Articles</button>\n        <button onclick=\"spSetCategory('cafe', this)\" class=\"sp-cat-btn\" style=\"padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid #e2e8f0; cursor: pointer; background: #ffffff; color: #475569; white-space: nowrap;\">☕ Cafés & Boissons</button>\n        <button onclick=\"spSetCategory('boulangerie', this)\" class=\"sp-cat-btn\" style=\"padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid #e2e8f0; cursor: pointer; background: #ffffff; color: #475569; white-space: nowrap;\">🥐 Boulangerie</button>\n        <button onclick=\"spSetCategory('restaurant', this)\" class=\"sp-cat-btn\" style=\"padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid #e2e8f0; cursor: pointer; background: #ffffff; color: #475569; white-space: nowrap;\">🍔 Plats & Salades</button>\n        <button onclick=\"spSetCategory('retail', this)\" class=\"sp-cat-btn\" style=\"padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 600; border: 1px solid #e2e8f0; cursor: pointer; background: #ffffff; color: #475569; white-space: nowrap;\">🛍️ Boutique & Retail</button>\n      </div>\n\n      <!-- Products Grid -->\n      <div id=\"sp-products-container\" class=\"sp-products-grid\">\n        <!-- Injected via JavaScript -->\n      </div>\n    </div>\n\n    <!-- RIGHT: TICKET DE CAISSE PRO -->\n    <div class=\"sp-pos-cart-col\">\n      <div style=\"background: #ffffff; border: 1px solid #e2e8f0; border-radius: 18px; padding: 18px; box-shadow: 0 4px 12px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 14px;\">\n        \n        <!-- Ticket Header -->\n        <div style=\"display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #f1f5f9; padding-bottom: 12px;\">\n          <div>\n            <div style=\"font-weight: 800; font-size: 14px; color: #0f172a;\">Ticket #TK-2026-0842</div>\n            <div style=\"font-size: 11px; color: #64748b;\">Table 04 • Client Comptoir</div>\n          </div>\n          <button onclick=\"spClearCart()\" style=\"background: transparent; border: none; color: #ef4444; font-size: 12px; font-weight: 600; cursor: pointer;\">Vider</button>\n        </div>\n\n        <!-- Cart Items Scroll -->\n        <div id=\"sp-cart-items\" style=\"max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px;\">\n          <!-- Injected via JavaScript -->\n        </div>\n\n        <!-- Discounts Buttons -->\n        <div style=\"background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 10px;\">\n          <div style=\"font-size: 11px; font-weight: 700; color: #475569; margin-bottom: 6px; display: flex; justify-content: space-between;\">\n            <span>Remise Commerciale :</span>\n            <span id=\"sp-discount-label\" style=\"color: #059669;\">0%</span>\n          </div>\n          <div style=\"display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;\">\n            <button onclick=\"spApplyDiscount(0, this)\" class=\"sp-disc-btn\" style=\"background: #10b981; color: white; border: none; border-radius: 6px; padding: 5px; font-size: 11px; font-weight: bold; cursor: pointer;\">0%</button>\n            <button onclick=\"spApplyDiscount(5, this)\" class=\"sp-disc-btn\" style=\"background: #ffffff; color: #334155; border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px; font-size: 11px; font-weight: bold; cursor: pointer;\">-5%</button>\n            <button onclick=\"spApplyDiscount(10, this)\" class=\"sp-disc-btn\" style=\"background: #ffffff; color: #334155; border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px; font-size: 11px; font-weight: bold; cursor: pointer;\">-10%</button>\n            <button onclick=\"spApplyDiscount(20, this)\" class=\"sp-disc-btn\" style=\"background: #ffffff; color: #334155; border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px; font-size: 11px; font-weight: bold; cursor: pointer;\">-20%</button>\n          </div>\n        </div>\n\n        <!-- Totals Card -->\n        <div style=\"background: #0f172a; color: #ffffff; border-radius: 14px; padding: 14px;\">\n          <div style=\"display: flex; justify-content: space-between; font-size: 12px; color: #94a3b8; margin-bottom: 4px;\">\n            <span>Sous-total Brut</span>\n            <span id=\"sp-subtotal-val\" style=\"font-family: monospace;\">0.00 €</span>\n          </div>\n          <div id=\"sp-discount-row\" style=\"display: none; justify-content: space-between; font-size: 12px; color: #34d399; margin-bottom: 4px;\">\n            <span>Remise déduite</span>\n            <span id=\"sp-discount-val\" style=\"font-family: monospace;\">-0.00 €</span>\n          </div>\n          <div style=\"display: flex; justify-content: space-between; font-size: 11px; color: #64748b; border-top: 1px solid #1e293b; padding-top: 6px; margin-top: 4px;\">\n            <span id=\"sp-ht-val\">Base HT: 0.00 €</span>\n            <span id=\"sp-tva-val\">TVA: 0.00 €</span>\n          </div>\n          <div style=\"display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid #1e293b; padding-top: 8px; margin-top: 8px;\">\n            <div>\n              <div style=\"font-size: 11px; text-transform: uppercase; color: #94a3b8; font-weight: bold;\">TOTAL TTC NET</div>\n              <div style=\"font-size: 9px; color: #34d399;\">Certifié NF525</div>\n            </div>\n            <div id=\"sp-total-val\" style=\"font-size: 24px; font-weight: 900; color: #34d399; font-family: monospace;\">0.00 €</div>\n          </div>\n        </div>\n\n        <!-- Payment Actions -->\n        <div style=\"display: grid; grid-template-columns: 1fr 1fr; gap: 8px;\">\n          <button onclick=\"spOpenPayment('Carte Bancaire (TPE)')\" style=\"background: #10b981; color: #ffffff; border: none; border-radius: 12px; padding: 12px; font-weight: 800; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 4px 10px rgba(16,185,129,0.2);\">\n            💳 Carte Bancaire\n          </button>\n          <button onclick=\"spOpenPayment('Espèces (Cash)')\" style=\"background: #1e293b; color: #ffffff; border: none; border-radius: 12px; padding: 12px; font-weight: 800; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;\">\n            💵 Espèces / Cash\n          </button>\n        </div>\n\n      </div>\n    </div>\n  </div>\n\n  <!-- RECEIPT MODAL (ESC/POS NF525) -->\n  <div id=\"sp-receipt-modal\" style=\"display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.75); backdrop-filter: blur(4px); z-index: 9999; align-items: center; justify-content: center; padding: 16px;\">\n    <div style=\"background: #ffffff; border-radius: 20px; max-width: 400px; width: 100%; padding: 24px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); text-align: left; position: relative;\">\n      <button onclick=\"spCloseModal()\" style=\"position: absolute; top: 16px; right: 16px; background: #f1f5f9; border: none; width: 30px; height: 30px; border-radius: 50%; font-weight: bold; cursor: pointer;\">✕</button>\n      \n      <div style=\"display: flex; align-items: center; gap: 8px; color: #059669; font-weight: 800; font-size: 14px; margin-bottom: 12px;\">\n        <span>✓</span> Encaissement Validé (NF525)\n      </div>\n\n      <!-- Thermal Receipt Visual Paper -->\n      <div style=\"background: #fffbeb; border: 1px solid #fef3c7; border-radius: 12px; padding: 16px; font-family: monospace; font-size: 11px; color: #1e293b; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);\">\n        <div style=\"text-align: center; border-bottom: 1px dashed #cbd5e1; padding-bottom: 8px; margin-bottom: 8px;\">\n          <div style=\"font-weight: 900; font-size: 14px;\">SMARTPOS AI PRO</div>\n          <div>BISTROT & COMMERCE PARIS</div>\n          <div style=\"font-size: 10px; color: #64748b;\">SIRET: 849 203 912 00014</div>\n          <div style=\"font-size: 10px; color: #64748b;\">CONFORME ART. 88 LOI FINANCES</div>\n        </div>\n\n        <div id=\"sp-modal-items-list\" style=\"margin-bottom: 8px; border-bottom: 1px dashed #cbd5e1; padding-bottom: 8px;\">\n          <!-- Dynamically populated -->\n        </div>\n\n        <div style=\"display: flex; justify-content: space-between; font-weight: bold; font-size: 13px; margin-bottom: 4px;\">\n          <span>TOTAL PAYÉ TTC</span>\n          <span id=\"sp-modal-total\">0.00 €</span>\n        </div>\n        <div id=\"sp-modal-method\" style=\"font-size: 10px; color: #059669; font-weight: bold; margin-bottom: 8px;\">\n          MODE: CARTE BANCAIRE\n        </div>\n\n        <div style=\"text-align: center; border-top: 1px dashed #cbd5e1; padding-top: 8px; font-size: 9px; color: #64748b;\">\n          <div>SIGNATURE CRYPTOGRAPHIQUE FISCALE :</div>\n          <div style=\"font-weight: bold; color: #0f172a; word-break: break-all;\">SHA256: 8F2B7E91C4A028E5-POS-FR</div>\n          <div style=\"margin-top: 4px;\">MERCI DE VOTRE VISITE !</div>\n        </div>\n      </div>\n\n      <div style=\"display: flex; gap: 8px; margin-top: 16px;\">\n        <button onclick=\"alert('Impression envoyée vers votre imprimante thermique ESC/POS 80mm.');\" style=\"flex: 1; background: #0f172a; color: white; border: none; padding: 10px; border-radius: 10px; font-size: 12px; font-weight: bold; cursor: pointer;\">\n          🖨️ Imprimer\n        </button>\n        <button onclick=\"spNewSale()\" style=\"flex: 1; background: #10b981; color: white; border: none; padding: 10px; border-radius: 10px; font-size: 12px; font-weight: bold; cursor: pointer;\">\n          + Nouvelle Vente\n        </button>\n      </div>\n    </div>\n  </div>\n\n  <script>\n    (function() {\n      var PRODUCTS = [\n        { id: '1', name: 'Café Espresso Bio', cat: 'cafe', price: 2.50, emoji: '☕', tva: 10, sku: 'BOV-ESP' },\n        { id: '2', name: 'Cappuccino Mousse Lait', cat: 'cafe', price: 4.20, emoji: '🍵', tva: 10, sku: 'BOV-CAP' },\n        { id: '3', name: 'Thé Vert Menthe Fraîche', cat: 'cafe', price: 3.80, emoji: '🫖', tva: 10, sku: 'BOV-THE' },\n        { id: '4', name: 'Jus Orange Pressé Minute', cat: 'cafe', price: 4.50, emoji: '🍊', tva: 10, sku: 'BOV-JUS' },\n        { id: '5', name: 'Croissant Beurre AOP', cat: 'boulangerie', price: 1.90, emoji: '🥐', tva: 10, sku: 'BAK-CRO' },\n        { id: '6', name: 'Pain Chocolat Pur Beurre', cat: 'boulangerie', price: 2.10, emoji: '🥖', tva: 10, sku: 'BAK-CHO' },\n        { id: '7', name: 'Tiramisu Artisanal Café', cat: 'boulangerie', price: 5.50, emoji: '🍰', tva: 10, sku: 'BAK-TIR' },\n        { id: '8', name: 'Tarte Citron Meringuée', cat: 'boulangerie', price: 4.90, emoji: '🍋', tva: 10, sku: 'BAK-CIT' },\n        { id: '9', name: 'Burger Gourmet & Frites', cat: 'restaurant', price: 16.50, emoji: '🍔', tva: 10, sku: 'RES-BUR' },\n        { id: '10', name: 'Pizza Margherita DOC', cat: 'restaurant', price: 13.90, emoji: '🍕', tva: 10, sku: 'RES-PIZ' },\n        { id: '11', name: 'Salade César Poulet', cat: 'restaurant', price: 12.50, emoji: '🥗', tva: 10, sku: 'RES-SAL' },\n        { id: '12', name: 'Pâtes Truffe & Parmesan', cat: 'restaurant', price: 17.80, emoji: '🍝', tva: 10, sku: 'RES-PAT' },\n        { id: '13', name: 'Frites Maison Port.', cat: 'restaurant', price: 4.50, emoji: '🍟', tva: 10, sku: 'RES-FRI' },\n        { id: '14', name: 'T-Shirt Coton Bio SmartPOS', cat: 'retail', price: 29.00, emoji: '👕', tva: 20, sku: 'RET-TSH' },\n        { id: '15', name: 'Totebag Toile Canvas', cat: 'retail', price: 14.00, emoji: '👜', tva: 20, sku: 'RET-TOT' },\n        { id: '16', name: 'Gourde Inox Isotherme', cat: 'retail', price: 22.00, emoji: '🍶', tva: 20, sku: 'RET-GOU' }\n      ];\n\n      var cart = [\n        { product: PRODUCTS[0], qty: 2 },\n        { product: PRODUCTS[4], qty: 2 },\n        { product: PRODUCTS[8], qty: 1 }\n      ];\n\n      var currentCat = 'all';\n      var discountPercent = 0;\n      var lastPaymentMethod = 'Carte Bancaire';\n\n      function updateClock() {\n        var clockEl = document.getElementById('sp-live-clock');\n        if (clockEl) {\n          var d = new Date();\n          clockEl.innerText = d.toLocaleTimeString('fr-FR');\n        }\n      }\n      setInterval(updateClock, 1000);\n      updateClock();\n\n      window.spSetCategory = function(cat, btn) {\n        currentCat = cat;\n        var buttons = document.querySelectorAll('.sp-cat-btn');\n        buttons.forEach(function(b) {\n          b.style.background = '#ffffff';\n          b.style.color = '#475569';\n          b.style.border = '1px solid #e2e8f0';\n        });\n        btn.style.background = '#10b981';\n        btn.style.color = '#ffffff';\n        btn.style.border = 'none';\n        window.spFilterProducts();\n      };\n\n      window.spFilterProducts = function() {\n        var query = (document.getElementById('sp-search-input').value || '').toLowerCase();\n        var container = document.getElementById('sp-products-container');\n        if (!container) return;\n\n        var html = '';\n        PRODUCTS.forEach(function(p) {\n          var matchCat = (currentCat === 'all' || p.cat === currentCat);\n          var matchQuery = p.name.toLowerCase().includes(query) || p.sku.toLowerCase().includes(query);\n          if (matchCat && matchQuery) {\n            var inCartItem = cart.find(function(i) { return i.product.id === p.id; });\n            var count = inCartItem ? inCartItem.qty : 0;\n\n            html += '<div onclick=\"spAddToCart(\\'' + p.id + '\\')\" class=\"sp-btn-touch\" style=\"background:#ffffff; border:' + (count > 0 ? '2px solid #10b981' : '1px solid #e2e8f0') + '; border-radius:14px; padding:12px; display:flex; flex-direction:column; justify-content:space-between; position:relative;\">';\n            if (count > 0) {\n              html += '<span style=\"position:absolute; top:8px; right:8px; background:#10b981; color:#fff; font-size:10px; font-weight:800; width:20px; height:20px; border-radius:50%; display:flex; align-items:center; justify-content:center;\">' + count + '</span>';\n            }\n            html += '<div>';\n            html += '<div style=\"font-size:26px; margin-bottom:6px;\">' + p.emoji + '</div>';\n            html += '<div style=\"font-weight:700; font-size:12px; color:#0f172a; line-height:1.2;\">' + p.name + '</div>';\n            html += '<div style=\"font-size:10px; color:#94a3b8; margin-top:2px;\">' + p.sku + ' • TVA ' + p.tva + '%</div>';\n            html += '</div>';\n            html += '<div style=\"display:flex; justify-content:space-between; align-items:center; border-top:1px solid #f1f5f9; padding-top:8px; margin-top:8px;\">';\n            html += '<span style=\"font-weight:800; font-size:13px; color:#0f172a;\">' + p.price.toFixed(2) + ' €</span>';\n            html += '<span style=\"background:#ecfdf5; color:#059669; font-weight:bold; width:22px; height:22px; border-radius:6px; display:flex; align-items:center; justify-content:center; font-size:13px;\">+</span>';\n            html += '</div>';\n            html += '</div>';\n          }\n        });\n        container.innerHTML = html;\n      };\n\n      window.spAddToCart = function(id) {\n        var p = PRODUCTS.find(function(item) { return item.id === id; });\n        if (!p) return;\n        var existing = cart.find(function(item) { return item.product.id === id; });\n        if (existing) {\n          existing.qty += 1;\n        } else {\n          cart.push({ product: p, qty: 1 });\n        }\n        window.spRenderCart();\n        window.spFilterProducts();\n      };\n\n      window.spChangeQty = function(id, delta) {\n        var item = cart.find(function(i) { return i.product.id === id; });\n        if (!item) return;\n        item.qty += delta;\n        if (item.qty <= 0) {\n          cart = cart.filter(function(i) { return i.product.id !== id; });\n        }\n        window.spRenderCart();\n        window.spFilterProducts();\n      };\n\n      window.spClearCart = function() {\n        cart = [];\n        discountPercent = 0;\n        window.spRenderCart();\n        window.spFilterProducts();\n      };\n\n      window.spApplyDiscount = function(pct, btn) {\n        discountPercent = pct;\n        document.querySelectorAll('.sp-disc-btn').forEach(function(b) {\n          b.style.background = '#ffffff';\n          b.style.color = '#334155';\n          b.style.border = '1px solid #cbd5e1';\n        });\n        btn.style.background = '#10b981';\n        btn.style.color = '#ffffff';\n        btn.style.border = 'none';\n        document.getElementById('sp-discount-label').innerText = pct > 0 ? '-' + pct + '%' : '0%';\n        window.spRenderCart();\n      };\n\n      window.spRenderCart = function() {\n        var cartContainer = document.getElementById('sp-cart-items');\n        if (!cartContainer) return;\n\n        if (cart.length === 0) {\n          cartContainer.innerHTML = '<div style=\"text-align:center; padding:30px 10px; color:#94a3b8; font-size:12px;\">Ticket vide.<br>Sélectionnez un article pour commencer.</div>';\n        } else {\n          var html = '';\n          cart.forEach(function(item) {\n            html += '<div style=\"display:flex; justify-content:space-between; align-items:center; background:#f8fafc; border:1px solid #e2e8f0; border-radius:10px; padding:8px 10px;\">';\n            html += '<div style=\"display:flex; align-items:center; gap:8px;\">';\n            html += '<span style=\"font-size:18px;\">' + item.product.emoji + '</span>';\n            html += '<div>';\n            html += '<div style=\"font-weight:700; font-size:11px; color:#0f172a;\">' + item.product.name + '</div>';\n            html += '<div style=\"font-size:10px; color:#64748b;\">' + item.product.price.toFixed(2) + ' € x ' + item.qty + ' = <strong style=\"color:#059669;\">' + (item.product.price * item.qty).toFixed(2) + ' €</strong></div>';\n            html += '</div>';\n            html += '</div>';\n            html += '<div style=\"display:flex; align-items:center; gap:4px;\">';\n            html += '<button onclick=\"spChangeQty(\\'' + item.product.id + '\\', -1)\" style=\"width:22px; height:22px; border-radius:6px; border:1px solid #cbd5e1; background:#ffffff; font-weight:bold; cursor:pointer;\">-</button>';\n            html += '<span style=\"width:18px; text-align:center; font-weight:bold; font-size:11px;\">' + item.qty + '</span>';\n            html += '<button onclick=\"spChangeQty(\\'' + item.product.id + '\\', 1)\" style=\"width:22px; height:22px; border-radius:6px; border:1px solid #cbd5e1; background:#ffffff; font-weight:bold; cursor:pointer;\">+</button>';\n            html += '</div>';\n            html += '</div>';\n          });\n          cartContainer.innerHTML = html;\n        }\n\n        // Calculations\n        var subtotal = cart.reduce(function(acc, i) { return acc + i.product.price * i.qty; }, 0);\n        var discAmount = (subtotal * discountPercent) / 100;\n        var netTotal = Math.max(0, subtotal - discAmount);\n\n        var tva10Items = cart.filter(function(i) { return i.product.tva === 10; }).reduce(function(acc, i) { return acc + i.product.price * i.qty; }, 0);\n        var tva20Items = cart.filter(function(i) { return i.product.tva === 20; }).reduce(function(acc, i) { return acc + i.product.price * i.qty; }, 0);\n\n        var tva10 = (tva10Items * (1 - discountPercent / 100) * 10) / 110;\n        var tva20 = (tva20Items * (1 - discountPercent / 100) * 20) / 120;\n        var baseHt = netTotal - tva10 - tva20;\n\n        document.getElementById('sp-subtotal-val').innerText = subtotal.toFixed(2) + ' €';\n        document.getElementById('sp-total-val').innerText = netTotal.toFixed(2) + ' €';\n        document.getElementById('sp-ht-val').innerText = 'Base HT: ' + baseHt.toFixed(2) + ' €';\n        document.getElementById('sp-tva-val').innerText = 'TVA: ' + (tva10 + tva20).toFixed(2) + ' €';\n\n        var discRow = document.getElementById('sp-discount-row');\n        if (discountPercent > 0) {\n          discRow.style.display = 'flex';\n          document.getElementById('sp-discount-val').innerText = '-' + discAmount.toFixed(2) + ' €';\n        } else {\n          discRow.style.display = 'none';\n        }\n      };\n\n      window.spOpenPayment = function(method) {\n        if (cart.length === 0) {\n          alert('Votre ticket est vide. Ajoutez des articles pour encaisser.');\n          return;\n        }\n        lastPaymentMethod = method;\n        var modal = document.getElementById('sp-receipt-modal');\n        var listContainer = document.getElementById('sp-modal-items-list');\n        var totalEl = document.getElementById('sp-modal-total');\n        var methodEl = document.getElementById('sp-modal-method');\n\n        var itemsHtml = '';\n        cart.forEach(function(i) {\n          itemsHtml += '<div style=\"display:flex; justify-content:space-between; margin-bottom:2px;\">';\n          itemsHtml += '<span>' + i.qty + 'x ' + i.product.name.substring(0, 18) + '</span>';\n          itemsHtml += '<span>' + (i.product.price * i.qty).toFixed(2) + ' €</span>';\n          itemsHtml += '</div>';\n        });\n\n        var subtotal = cart.reduce(function(acc, i) { return acc + i.product.price * i.qty; }, 0);\n        var discAmount = (subtotal * discountPercent) / 100;\n        var netTotal = Math.max(0, subtotal - discAmount);\n\n        listContainer.innerHTML = itemsHtml;\n        totalEl.innerText = netTotal.toFixed(2) + ' €';\n        methodEl.innerText = 'RÈGLEMENT : ' + method.toUpperCase();\n\n        modal.style.display = 'flex';\n      };\n\n      window.spCloseModal = function() {\n        document.getElementById('sp-receipt-modal').style.display = 'none';\n      };\n\n      window.spNewSale = function() {\n        window.spClearCart();\n        window.spCloseModal();\n      };\n\n      // Initial execution\n      window.spFilterProducts();\n      window.spRenderCart();\n    })();\n  </script>\n</div>"
              }
            }
          ]
        }
      ]
    }
  ]
}