const CACHE = 'neolink-admin-v1';

self.addEventListener('install', e => {
  self.skipWaiting();
});

self.addEventListener('activate', e => {
  self.clients.claim();
});

self.addEventListener('fetch', e => {
  e.respondWith(
    fetch(e.request).catch(() => {
      return new Response(`
        <!DOCTYPE html>
        <html dir="rtl" lang="ar">
        <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>لا يوجد اتصال</title>
          <style>
            body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #1a56db; color: #fff; text-align: center; }
            h2 { font-size: 1.5rem; }
            p { color: rgba(255,255,255,0.7); }
          </style>
        </head>
        <body>
          <div>
            <h2>📡 لا يوجد اتصال</h2>
            <p>تحقق من اتصالك وحاول مجدداً</p>
          </div>
        </body>
        </html>
      `, { headers: { 'Content-Type': 'text/html; charset=utf-8' } });
    })
  );
});
