/* ============================================================================
   PWA + Push Notifications UI
   - Bottone "Installa app" (mostrato quando beforeinstallprompt disponibile)
   - Bottone "Abilita notifiche" (mostrato quando SW pronto)
   - Floating pill mobile-friendly
   ============================================================================ */

/* ---- Floating pill (mobile first) ---- */
/* Nessun display:none su #pwa-floating-pill: un selettore ID (specificità 1-0-0)
   vincerebbe sulla classe .pwa-floating-pill (0-1-0) e la pill non comparirebbe
   mai su mobile. Su desktop la nasconde il media query min-width:900px più sotto. */
.pwa-floating-pill {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
    left: 16px;
    right: 16px;
    z-index: 998;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none; /* lascia passare click sotto */
}

.pwa-btn {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    text-decoration: none;
    color: white;
}

.pwa-btn:active {
    transform: scale(0.97);
}

.pwa-btn__icon {
    display: inline-flex;
    align-items: center;
}

.pwa-btn--install {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: white;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4);
}

.pwa-btn--install:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e3a8a);
}

.pwa-btn--notifications {
    background: rgba(255, 255, 255, 0.95);
    color: #1f2937;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.pwa-btn--notifications.pwa-btn--enabled {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.pwa-btn--notifications.pwa-btn--denied {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

.pwa-btn--notifications:not(.pwa-btn--enabled):not(.pwa-btn--denied):hover {
    background: white;
}

/* Dark mode */
[data-theme="dark"] .pwa-btn--notifications {
    background: rgba(30, 41, 59, 0.95);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .pwa-btn--notifications:not(.pwa-btn--enabled):not(.pwa-btn--denied):hover {
    background: rgba(51, 65, 85, 1);
}

[data-theme="dark"] .pwa-btn--notifications.pwa-btn--denied {
    background: #1e293b;
    color: #64748b;
}

/* ---- Su desktop: integra nella navbar ---- */
@media (min-width: 900px) {
    .pwa-floating-pill {
        display: none !important; /* desktop usa bottoni in navbar */
    }

    .pwa-navbar-buttons {
        display: flex !important;
        align-items: center;
        gap: 6px;
    }
}

@media (max-width: 899px) {
    .pwa-navbar-buttons {
        display: none !important;
    }
}

.pwa-navbar-buttons {
    display: none;
}

.pwa-nav-btn {
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: inherit;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    position: relative;
}

.pwa-nav-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.pwa-nav-btn:active {
    transform: scale(0.92);
}

.pwa-nav-btn--enabled {
    background: #10b981;
    color: white;
    border-color: transparent;
}

.pwa-nav-btn--enabled:hover {
    background: #059669;
}

.pwa-nav-btn--denied {
    opacity: 0.4;
    cursor: not-allowed;
}

[data-theme="dark"] .pwa-nav-btn {
    border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .pwa-nav-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ---- iOS: mostra istruzioni aggiuntive ---- */
.pwa-ios-hint {
    background: rgba(254, 243, 199, 0.95);
    border: 1px solid #fbbf24;
    color: #78350f;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.875rem;
    pointer-events: auto;
}

[data-theme="dark"] .pwa-ios-hint {
    background: rgba(120, 53, 15, 0.4);
    color: #fde68a;
    border-color: #b45309;
}

/* ---- Pulse animation per notifiche ---- */
@keyframes pwa-notif-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
}

.pwa-btn--enabled {
    animation: pwa-notif-pulse 2s ease-in-out infinite;
}

/* Hide su standalone + non mostrare il FAB notifiche se non supportato */
@supports not (backdrop-filter: blur(1px)) {
    .pwa-btn--notifications {
        background: white;
    }
}
