const CACHE_NAME = 'collector-cache-v2';
const ASSETS = [
  '/mobile/', '/mobile/index.html', '/mobile/style.css', '/mobile/app.js', '/mobile/manifest.webmanifest',
  '/js/qrcode.min.js', '/js/qr_stub.js',
  '/assets/logo-light.png', '/assets/logo-dark.png'
];
self.addEventListener('install', (e)=>{
  e.waitUntil(caches.open(CACHE_NAME).then(c=> c.addAll(ASSETS)));
});
self.addEventListener('activate', (e)=>{
  e.waitUntil(caches.keys().then(keys=> Promise.all(keys.filter(k=>k!==CACHE_NAME).map(k=> caches.delete(k)))));
});
self.addEventListener('fetch', (e)=>{
  const req = e.request;
  e.respondWith(caches.match(req).then(cached=> cached || fetch(req).catch(()=> cached)));
});