/* ==========================================================================
   Perfex CRM PWA - Immersive Mobile App Shell & Design System
   Auteur : Ir. Roland MANTAMA
   ========================================================================== */

:root {
    --pwa-primary: #3B82F6;
    --pwa-primary-hover: #2563EB;
    --pwa-primary-glow: rgba(59, 130, 246, 0.35);
    --pwa-dock-bg: rgba(15, 23, 42, 0.88);
    --pwa-dock-border: rgba(255, 255, 255, 0.1);
    --pwa-text-active: #38BDF8;
    --pwa-text-idle: #94A3B8;
    --pwa-badge-bg: #EF4444;
}

/* Prise en compte de la Safe Area sur les terminaux avec encoche (iPhone / Android) */
@supports (padding: max(0px)) {
    body.pwa-has-bottom-bar {
        padding-bottom: calc(64px + max(10px, env(safe-area-inset-bottom))) !important;
    }
}

/* ==========================================================================
   1. Bottom Navigation Bar Flottante (Mobile Dock)
   ========================================================================== */
#pwa-bottom-bar,
.pwa-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: 58px;
    padding: 6px 12px max(8px, env(safe-area-inset-bottom)) 12px;
    background: var(--pwa-dock-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--pwa-dock-border);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: space-around;
    /* Native Bootstrap fixed layer, below modal/backdrop (1040/1050). */
    --pwa-z-dock: 1030;
    z-index: var(--pwa-z-dock);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.32s ease;
    user-select: none;
    -webkit-user-select: none;
}

/* Masquage intelligent au défilement vers le bas */
/* Synchronous lock, independent of scroll direction and animation timing. */
body.modal-open #pwa-bottom-bar,
body.modal-open .pwa-bottom-bar {
    visibility: hidden;
    pointer-events: none;
}

.pwa-bottom-bar.pwa-bar-hidden {
    transform: translateY(115%);
    opacity: 0;
    pointer-events: none;
}

/* Onglets de la Bottom Bar */
.pwa-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 48px;
    text-decoration: none !important;
    color: var(--pwa-text-idle) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

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

.pwa-nav-item.active {
    color: var(--pwa-text-active) !important;
}

.pwa-nav-icon {
    position: relative;
    width: 22px;
    height: 22px;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.pwa-nav-item.active .pwa-nav-icon {
    transform: translateY(-2px);
}

.pwa-nav-item.active .pwa-nav-icon svg {
    stroke: var(--pwa-text-active);
    filter: drop-shadow(0 2px 8px var(--pwa-primary-glow));
}

.pwa-nav-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
}

/* Pastille numérique de notifications */
.pwa-badge {
    position: absolute;
    top: -2px;
    right: -7px;
    background: var(--pwa-badge-bg);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 700;
    height: 16px;
    min-width: 16px;
    padding: 0 4px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    border: 1.5px solid var(--pwa-dock-bg);
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ==========================================================================
   2. Pull to Refresh Gesture Indicator
   ========================================================================== */
.pwa-pull-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--pwa-dock-bg);
    border: 1px solid var(--pwa-dock-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pwa-primary);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    z-index: 100000;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

.pwa-pull-indicator.visible {
    opacity: 1;
}

.pwa-pull-indicator.refreshing svg {
    animation: pwaSpin 0.8s linear infinite;
}

@keyframes pwaSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   3. Bannière d'Installation Intelligente A2HS
   ========================================================================== */
.pwa-install-banner {
    position: fixed;
    bottom: calc(72px + max(12px, env(safe-area-inset-bottom)));
    left: 16px;
    right: 16px;
    max-width: 460px;
    margin: 0 auto;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 18px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
    z-index: 99998;
    animation: slideUpBanner 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex-shrink: 0;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pwa-banner-content {
    flex: 1;
    min-width: 0;
}

.pwa-banner-title {
    font-size: 14px;
    font-weight: 700;
    color: #F8FAFC;
    margin-bottom: 2px;
}

.pwa-banner-desc {
    font-size: 12px;
    color: #94A3B8;
    line-height: 1.3;
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-btn-install {
    padding: 8px 14px;
    background: linear-gradient(135deg, #3B82F6, #2563EB);
    color: #FFFFFF;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.pwa-btn-dismiss {
    background: transparent;
    border: none;
    color: #64748B;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes slideUpBanner {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Masquer la Bottom Bar sur Desktop (> 768px) */
@media (min-width: 769px) {
    #pwa-bottom-bar,
    .pwa-bottom-bar,
    .pwa-pull-indicator {
        display: none !important;
    }
}
