// QR Code stub for development: provides window.QRCode to avoid CDN issues.
(function(){
  if (window.QRCode) return;
  function QRCode(el, opts){
    this._el = el;
    this._opts = opts||{};
    this._render();
  }
  QRCode.CorrectLevel = { L:1, M:2, Q:3, H:4 };
  QRCode.prototype._render = function(){
    var size = Math.max(80, Math.min(240, (this._opts.width||120)));
    var canvas = document.createElement('canvas');
    canvas.width = size; canvas.height = size;
    var ctx = canvas.getContext('2d');
    // background
    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0,0,size,size);
    // pseudo pattern (not scannable, illustrative only)
    var cells = 25;
    var cell = Math.floor(size / cells);
    ctx.fillStyle = '#000000';
    for (var y=0;y<cells;y++){
      for (var x=0;x<cells;x++){
        var seed = (x*y + (this._opts.text||'').length + x + y) % 5;
        if ((x<7 && y<7) || (x>cells-8 && y<7) || (x<7 && y>cells-8) || seed===0) {
          ctx.fillRect(x*cell, y*cell, cell-1, cell-1);
        }
      }
    }
    ctx.fillStyle = '#000000';
    ctx.font = Math.floor(size/12)+'px Arial';
    ctx.textAlign = 'center';
    ctx.fillText('QR Preview', size/2, size - Math.floor(size/20));
    this._el.innerHTML = '';
    this._el.appendChild(canvas);
  };
  window.QRCode = QRCode;
})();