/* Buy or Block — PWA: install button, notification bell, mobile tab bar, offline page.
   Uses the design tokens from app.css. Owned by apps/pwa. */

/* ---------- Install button ---------- */
.pwa-install[hidden], .pwa-standalone .pwa-install { display: none !important; }
.pwa-install { color: var(--primary); border-color: var(--primary-100); background: var(--primary-50); }
.pwa-install:hover { background: var(--primary-100); color: var(--primary-700); }

/* ---------- Notification bell ---------- */
.pwa-bell { position: relative; }
.pwa-bell-btn { color: var(--text-2); }
.pwa-bell.open .pwa-bell-btn { background: var(--primary-50); color: var(--primary); }
.pwa-bell-count {
  position: absolute; top: 1px; left: 21px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  border: 2px solid var(--surface); box-sizing: content-box; font-variant-numeric: tabular-nums;
}
.pwa-bell-count[hidden] { display: none; }
.pwa-bell-panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: 400px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: none; z-index: 60; overflow: hidden; flex-direction: column;
}
.pwa-bell.open .pwa-bell-panel { display: flex; animation: pwa-pop .14s ease-out; }
@keyframes pwa-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pwa-bell-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.pwa-bell-head strong { font-size: 15px; color: var(--text); }
.pwa-bell-new { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px; background: var(--primary-50); color: var(--primary-700); font-size: 12px; font-weight: 600; line-height: 20px; }
.pwa-bell-new[hidden] { display: none; }
.pwa-link { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0; font: inherit; font-size: 13px; font-weight: 600; color: var(--primary); cursor: pointer; }
.pwa-link:hover { color: var(--primary-700); }
.pwa-bell-perm { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--blue-50); color: var(--blue-700); font-size: 13px; border-bottom: 1px solid var(--border); }
.pwa-bell-perm[hidden] { display: none; }
.pwa-bell-perm span { flex: 1; }
.pwa-bell-list { max-height: min(440px, 60vh); overflow-y: auto; overscroll-behavior: contain; }
.pwa-bell-foot { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px; border-top: 1px solid var(--border); font-weight: 600; font-size: 13px; background: var(--surface-2); }

/* Notification rows (dropdown + full page) */
.pwa-notif { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; color: var(--text-2); border-bottom: 1px solid var(--border); position: relative; transition: background .12s; }
.pwa-notif:last-child { border-bottom: 0; }
.pwa-notif:hover { background: var(--gray-50); color: var(--text-2); }
.pwa-notif.is-unread { background: #F5F8FF; }
.pwa-notif.is-unread:hover { background: var(--primary-50); }
.pwa-notif-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: var(--gray-100); color: var(--gray-700); }
.pwa-notif-icon [data-lucide], .pwa-notif-icon svg { width: 18px; height: 18px; }
.pwa-notif-icon.red { background: var(--red-50); color: var(--red-700); }
.pwa-notif-icon.amber { background: var(--amber-50); color: var(--amber-700); }
.pwa-notif-icon.blue { background: var(--blue-50); color: var(--blue-700); }
.pwa-notif-icon.purple { background: var(--purple-50); color: var(--purple-700); }
.pwa-notif-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pwa-notif-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pwa-notif-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.pwa-notif-label.red { color: var(--red-700); }
.pwa-notif-label.amber { color: var(--amber-700); }
.pwa-notif-label.blue { color: var(--blue-700); }
.pwa-notif-label.purple { color: var(--purple-700); }
.pwa-notif-top time { font-size: 12px; color: var(--muted-2); white-space: nowrap; }
.pwa-notif-title { font-weight: 600; color: var(--text); line-height: 1.4; overflow-wrap: anywhere; }
.pwa-notif-body { font-size: 13px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.pwa-notif-body.is-clamped { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pwa-notif-contact { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 12px; font-weight: 600; color: var(--primary); }
.pwa-notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 6px; }
.pwa-notif-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 36px 24px; color: var(--muted); font-size: 13px; }
.pwa-notif-empty strong { color: var(--text); font-size: 14px; }
.pwa-notif-empty-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); margin-bottom: 8px; }
.pwa-notif-card { overflow: hidden; padding: 0; }
.pwa-notif-card .pwa-notif { padding: 16px 20px; }
.pwa-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); }

/* ---------- Mobile bottom tab bar (only rendered on app pages) ---------- */
.pwa-tabbar, .pwa-nav-backdrop { display: none; }
@media (max-width: 860px) {
  :root { --pwa-tabbar-h: 64px; }
  .pwa-tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--pwa-tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: rgba(255,255,255,.96); -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(16,24,40,.06);
  }
  .pwa-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
    color: var(--muted); font: inherit; font-size: 11px; font-weight: 600; background: none; border: 0; padding: 6px 2px;
    cursor: pointer; -webkit-tap-highlight-color: transparent; position: relative;
  }
  .pwa-tab:hover { color: var(--text-2); }
  .pwa-tab.active { color: var(--primary); }
  .pwa-tab-icon { position: relative; display: inline-grid; place-items: center; width: 44px; height: 28px; border-radius: 14px; transition: background .15s; }
  .pwa-tab.active .pwa-tab-icon { background: var(--primary-50); }
  .pwa-tab-icon [data-lucide], .pwa-tab-icon svg { width: 22px; height: 22px; }
  .pwa-tab-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .pwa-tab-badge {
    position: absolute; top: -5px; left: 27px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
    background: var(--red); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
    border: 2px solid #fff; box-sizing: content-box;
  }
  .pwa-tab-add { justify-content: center; }
  .pwa-fab {
    width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin-top: -22px;
    background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(21,94,239,.38), 0 0 0 4px #fff;
    transition: transform .12s, background .12s;
  }
  .pwa-fab [data-lucide], .pwa-fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
  .pwa-tab-add:active .pwa-fab { transform: scale(.94); background: var(--primary-700); }
  .pwa-tab-add.active .pwa-fab { background: var(--primary-700); }

  /* keep page content clear of the bar */
  body:has(.pwa-tabbar) .main { padding-bottom: calc(var(--pwa-tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  body.pwa-has-tabbar .main { padding-bottom: calc(var(--pwa-tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  body.nav-open .pwa-tabbar { z-index: 30; }

  /* sidebar ("More") gets a tap-to-close backdrop */
  .pwa-nav-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(16,24,40,.5); backdrop-filter: blur(2px); }
  body.nav-open .pwa-nav-backdrop { display: block; }

  /* the tab bar already has Queue + Add, so the topbar gets lighter on phones */
  .topbar-actions:has(.pwa-bell) > a.icon-btn[title="Overdue follow-ups"] { display: none; }
  .pwa-bell-panel { position: fixed; top: calc(var(--topbar-h) + 4px); left: 8px; right: 8px; width: auto; max-width: none; }
  .pwa-bell-list { max-height: calc(100vh - var(--topbar-h) - var(--pwa-tabbar-h) - 140px); }
}
@media (max-width: 600px) {
  body:has(.pwa-tabbar) .topbar-actions > a.btn-primary[href*="/contacts/new"] { display: none; }
  .pwa-install span { display: none; }
  .pwa-install { padding: 7px 9px; }
}

/* ---------- Standalone (installed) tweaks ---------- */
.pwa-standalone body { overscroll-behavior-y: none; }
.pwa-standalone .topbar { padding-top: env(safe-area-inset-top, 0px); height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); }

/* ---------- Offline page ---------- */
.pwa-offline { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 50% 0%, var(--primary-50), var(--bg) 60%); }
.pwa-offline-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 32px 24px; text-align: center; position: relative; }
.pwa-offline-card img { border-radius: 14px; }
.pwa-offline-icon { position: absolute; top: 20px; left: calc(50% + 14px); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--amber-50); color: var(--amber-700); border: 3px solid var(--surface); }
.pwa-offline-icon [data-lucide], .pwa-offline-icon svg { width: 15px; height: 15px; }
.pwa-offline h1 { margin: 20px 0 8px; font-size: 22px; }
.pwa-offline p { color: var(--muted); }
.pwa-offline-tip { font-size: 13px; background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; margin: 16px 0 20px; }
.pwa-offline-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
