/* ============================================================
   DigiNGO PWA — Mobile App Experience
   ============================================================ */

:root {
    --pwa-header-h: 56px;
    --pwa-bottom-nav-h: 64px;
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-transition: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Standalone / installed app mode ---- */
@media (display-mode: standalone), (display-mode: fullscreen) {
    body.pwa-mobile {
        padding-top: var(--pwa-safe-top);
    }
    body.pwa-mobile .top-bar,
    body.pwa-mobile .top-bar-mobile {
        display: none !important;
    }
    body.pwa-mobile #mainNavbar {
        display: none !important;
    }
    body.pwa-mobile .footer-main,
    body.pwa-mobile .footer-bottom {
        padding-bottom: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom) + 16px);
    }
}

body.pwa-mobile {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
    touch-action: manipulation;
}

body.pwa-mobile main {
    padding-bottom: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom) + 8px);
    transition: opacity var(--pwa-transition), transform var(--pwa-transition);
}

body.pwa-page-leaving main {
    opacity: 0.6;
    transform: translateY(6px);
}

/* ---- App header (mobile) ---- */
.pwa-app-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 1040;
    height: calc(var(--pwa-header-h) + var(--pwa-safe-top));
    padding-top: var(--pwa-safe-top);
    background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 100%);
    color: #fff;
    box-shadow: 0 4px 20px rgba(27, 94, 32, 0.25);
}

@media (max-width: 991.98px) {
    body.pwa-mobile .pwa-app-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: 12px;
        padding-right: 12px;
    }
    body.pwa-mobile .top-bar-mobile,
    body.pwa-mobile #mainNavbar {
        display: none !important;
    }
}

.pwa-app-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.pwa-app-header-brand img {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: cover;
    background: rgba(255,255,255,0.15);
}

.pwa-app-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.15);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.pwa-app-header-text {
    min-width: 0;
}

.pwa-app-header-text .title {
    display: block;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-app-header-text .subtitle {
    display: block;
    font-size: 0.72rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-app-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.pwa-header-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(255,255,255,0.12);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--pwa-transition);
}

.pwa-header-btn:active {
    background: rgba(255,255,255,0.25);
    transform: scale(0.95);
}

/* ---- Bottom navigation ---- */
.pwa-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    height: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom));
    padding-bottom: var(--pwa-safe-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(46, 125, 50, 0.12);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.08);
}

@media (max-width: 991.98px) {
    body.pwa-mobile .pwa-bottom-nav {
        display: flex;
        align-items: stretch;
        justify-content: space-around;
    }
}

.pwa-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #5a6e5b;
    font-size: 0.65rem;
    font-weight: 600;
    text-decoration: none;
    padding: 6px 4px;
    transition: color var(--pwa-transition), transform 0.15s ease;
    position: relative;
    min-height: 48px;
}

.pwa-bottom-nav-item i {
    font-size: 1.25rem;
    transition: transform 0.2s ease;
}

.pwa-bottom-nav-item.active {
    color: #2e7d32;
}

.pwa-bottom-nav-item.active i {
    transform: scale(1.1);
}

.pwa-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: #2e7d32;
    border-radius: 0 0 4px 4px;
}

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

.pwa-bottom-nav-item.donate-btn {
    color: #e65100;
}

.pwa-bottom-nav-item.donate-btn.active {
    color: #e65100;
}

.pwa-bottom-nav-item.donate-btn.active::before {
    background: #ff8f00;
}

/* ---- Mobile drawer ---- */
.pwa-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1060;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--pwa-transition), visibility var(--pwa-transition);
}

.pwa-drawer-overlay.open {
    opacity: 1;
    visibility: visible;
}

.pwa-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 88vw);
    height: 100%;
    background: #fff;
    z-index: 1070;
    transform: translateX(100%);
    transition: transform var(--pwa-transition);
    display: flex;
    flex-direction: column;
    padding-top: var(--pwa-safe-top);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.15);
}

.pwa-drawer.open {
    transform: translateX(0);
}

.pwa-drawer-head {
    padding: 20px 18px 16px;
    background: linear-gradient(135deg, #1b5e20, #2e7d32);
    color: #fff;
}

.pwa-drawer-head h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: #fff;
}

.pwa-drawer-head p {
    margin: 0;
    font-size: 0.8rem;
    opacity: 0.9;
}

.pwa-drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.pwa-drawer-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    color: #1a2e1b;
    font-weight: 500;
    font-size: 0.92rem;
    text-decoration: none;
    transition: background 0.2s ease;
}

.pwa-drawer-link i {
    width: 22px;
    color: #2e7d32;
    text-align: center;
}

.pwa-drawer-link:active,
.pwa-drawer-link.active {
    background: #f1f8f4;
    color: #2e7d32;
}

.pwa-drawer-footer {
    padding: 16px;
    border-top: 1px solid #e8f5e9;
}

/* ---- Install popup ---- */
.pwa-install-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1080;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    padding-bottom: calc(16px + var(--pwa-safe-bottom));
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.pwa-install-overlay.show {
    opacity: 1;
    visibility: visible;
}

.pwa-install-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 24px 24px 20px 20px;
    padding: 28px 24px 24px;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.2);
}

.pwa-install-overlay.show .pwa-install-card {
    transform: translateY(0);
}

.pwa-install-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, #2e7d32, #4caf50);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 16px;
    box-shadow: 0 8px 24px rgba(46, 125, 50, 0.35);
}

.pwa-install-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: #1a2e1b;
}

.pwa-install-card p {
    color: #5a6e5b;
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.pwa-install-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pwa-install-actions .btn-install {
    background: linear-gradient(135deg, #2e7d32, #388e3c);
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 14px 20px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 6px 20px rgba(46, 125, 50, 0.35);
    transition: transform 0.15s ease;
}

.pwa-install-actions .btn-install:active {
    transform: scale(0.98);
}

.pwa-install-actions .btn-later {
    background: transparent;
    color: #5a6e5b;
    border: none;
    padding: 12px;
    font-weight: 600;
    cursor: pointer;
}

/* ---- Floating action buttons ---- */
.pwa-fab-group {
    position: fixed;
    right: 16px;
    bottom: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom) + 16px);
    z-index: 1035;
    display: flex;
    flex-direction: column-reverse;
    gap: 12px;
    align-items: flex-end;
}

@media (min-width: 992px) {
    .pwa-fab-group {
        bottom: 24px;
    }
}

.pwa-fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    color: #fff;
    font-size: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
}

.pwa-fab:active {
    transform: scale(0.9);
}

.pwa-fab-whatsapp {
    background: linear-gradient(135deg, #25d366, #128c7e);
}

.pwa-fab-donate {
    background: linear-gradient(135deg, #ff8f00, #f57c00);
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
}

.pwa-fab-push {
    background: linear-gradient(135deg, #1565c0, #0d47a1);
    font-size: 1.1rem;
}

/* ---- Skeleton loading ---- */
.pwa-skeleton-overlay {
    position: fixed;
    inset: 0;
    background: #f1f8f4;
    z-index: 99998;
    display: none;
    flex-direction: column;
    padding: 20px;
    gap: 16px;
}

.pwa-skeleton-overlay.active {
    display: flex;
}

.pwa-skeleton-bar {
    height: 16px;
    border-radius: 8px;
    background: linear-gradient(90deg, #e8f5e9 25%, #c8e6c9 50%, #e8f5e9 75%);
    background-size: 200% 100%;
    animation: pwaShimmer 1.2s infinite;
}

.pwa-skeleton-bar.w60 { width: 60%; }
.pwa-skeleton-bar.w80 { width: 80%; }
.pwa-skeleton-bar.w40 { width: 40%; }
.pwa-skeleton-card {
    height: 120px;
    border-radius: 16px;
    background: linear-gradient(90deg, #e8f5e9 25%, #c8e6c9 50%, #e8f5e9 75%);
    background-size: 200% 100%;
    animation: pwaShimmer 1.2s infinite;
}

@keyframes pwaShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---- Swipe-friendly cards ---- */
@media (max-width: 991.98px) {
    body.pwa-mobile .card,
    body.pwa-mobile .activity-card,
    body.pwa-mobile .event-card,
    body.pwa-mobile .campaign-card,
    body.pwa-mobile .gallery-item,
    body.pwa-mobile .testimonial-card {
        scroll-snap-align: start;
        -webkit-overflow-scrolling: touch;
    }

    body.pwa-mobile .row-scroll,
    body.pwa-mobile .quick-actions-row {
        scroll-snap-type: x mandatory;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
    }

    body.pwa-mobile .row-scroll::-webkit-scrollbar,
    body.pwa-mobile .quick-actions-row::-webkit-scrollbar {
        display: none;
    }
}

/* ---- Offline banner ---- */
.pwa-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1090;
    background: #c62828;
    color: #fff;
    text-align: center;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    padding-top: calc(8px + var(--pwa-safe-top));
}

.pwa-offline-banner.show {
    transform: translateY(0);
}

/* ---- Enhanced page loader for PWA ---- */
body.pwa-mobile #page-loader .loader-leaf {
    width: 56px;
    height: 56px;
    border-width: 5px;
}

body.pwa-mobile #page-loader::after {
    content: 'Loading...';
    position: absolute;
    margin-top: 90px;
    font-size: 0.85rem;
    color: #2e7d32;
    font-weight: 600;
}

/* ---- Hide duplicate back-to-top on mobile PWA ---- */
@media (max-width: 991.98px) {
    body.pwa-mobile #backToTop {
        bottom: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom) + 80px) !important;
        right: 16px !important;
    }
}

/* ---- Touch-friendly buttons ---- */
@media (max-width: 991.98px) {
    body.pwa-mobile .btn,
    body.pwa-mobile .nav-link,
    body.pwa-mobile button {
        min-height: 44px;
    }
}

/* ---- Attendance badge on events ---- */
.pwa-attendance-btn {
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 16px;
    border: none;
    background: #e8f5e9;
    color: #2e7d32;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pwa-attendance-btn.marked {
    background: #2e7d32;
    color: #fff;
}

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

/* ---- Splash screen (iOS) ---- */
link[rel="apple-touch-startup-image"] {
    display: none;
}
