/**
 * Progressive Web App - Styles CSS
 * Bannières, modals et éléments PWA
 * Version: 1.0.0
 */

:root {
    --pwa-primary: #2563EB;
    --pwa-primary-dark: #1D4ED8;
    --pwa-dark: #0F172A;
    --pwa-light: #F1F5F9;
    --pwa-border: #E2E8F0;
}

/**
 * 1️⃣ Bannière Offline
 * Affichée en haut de la page quand pas de connexion
 */
.pwa-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #FEE2E2;
    border-bottom: 2px solid #DC2626;
    padding: 12px 16px;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: none;
}

.pwa-offline-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #DC2626;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    max-width: 1400px;
    margin: 0 auto;
}

.pwa-offline-icon {
    font-size: 18px;
    animation: pulse-offline 2s ease-in-out infinite;
}

@keyframes pulse-offline {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

.pwa-offline-text {
    flex: 1;
}

/* Ajuster le padding du body si offline */
body.pwa-offline-active {
    padding-top: 50px;
}

/**
 * 2️⃣ Message Premier Lancement
 * Bienvenue pour first-time users
 */
.pwa-first-launch-message {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9995;
    animation: slideDownMessage 0.5s ease-out;
    max-width: 500px;
    width: calc(100% - 32px);
}

@keyframes slideDownMessage {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.pwa-first-launch-content {
    background: white;
    border: 1px solid var(--pwa-border);
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.pwa-first-launch-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.pwa-first-launch-content h5 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--pwa-dark);
}

.pwa-first-launch-content p {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #64748B;
    line-height: 1.5;
}

.pwa-first-launch-content .btn {
    font-size: 12px;
    padding: 4px 12px;
}

/**
 * 3️⃣ Bannière Update
 * Notification de mise à jour disponible
 */
.pwa-update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #FEF3C7;
    border-bottom: 2px solid #FBBF24;
    padding: 12px 16px;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.pwa-update-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #92400E;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    max-width: 1400px;
    margin: 0 auto;
}

.pwa-update-icon {
    font-size: 18px;
}

.pwa-update-text {
    flex: 1;
}

.pwa-update-banner .btn {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
}

/**
 * 4️⃣ Instructions iPhone
 * Affichée sur Safari iOS
 */
.pwa-iphone-instructions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--pwa-border);
    z-index: 9999;
    animation: slideUpInstructions 0.4s ease-out;
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: 20px;
}

@keyframes slideUpInstructions {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.pwa-iphone-instructions-content {
    padding: 20px;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
}

.pwa-iphone-instructions-close {
    position: absolute;
    top: 10px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #64748B;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pwa-iphone-instructions h5 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--pwa-dark);
}

.pwa-iphone-instructions p {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #64748B;
    line-height: 1.6;
}

.pwa-iphone-instructions ol {
    margin: 12px 0;
    padding-left: 20px;
    color: #64748B;
    font-size: 13px;
    line-height: 1.8;
}

.pwa-iphone-instructions li {
    margin-bottom: 8px;
}

.pwa-iphone-instructions li strong {
    color: var(--pwa-primary);
    font-weight: 600;
}

.pwa-iphone-instructions .text-muted {
    color: #94A3B8;
    font-size: 12px;
}

/**
 * 5️⃣ Mode Standalone
 * Quand l'app est installée et en mode fullscreen
 */
body.pwa-standalone {
    /* Ajuster le padding pour tenir compte de la barre de statut iOS */
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
}

.pwa-standalone header {
    padding-top: max(0px, env(safe-area-inset-top, 0px));
}

.pwa-standalone footer {
    padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
}

/**
 * 6️⃣ Bouton Installation Global
 * Disponible partout
 */
#pwa-install-btn {
    background: white;
    color: var(--pwa-primary);
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

#pwa-install-btn:hover {
    background: #F1F5F9;
    transform: scale(1.05);
}

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

/**
 * 7️⃣ Touch Targets
 * Minimum 44x44px pour les cibles tactiles
 */
@media (max-width: 768px) {
    button,
    a,
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .pwa-offline-banner-content {
        padding: 8px 0;
    }

    .pwa-iphone-instructions-content {
        padding: 16px;
    }

    .pwa-iphone-instructions h5 {
        font-size: 16px;
    }
}

/**
 * 8️⃣ Responsive Design
 */
@media (max-width: 480px) {
    .pwa-offline-banner-content {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .pwa-first-launch-message {
        width: calc(100% - 16px);
        top: 60px;
    }

    .pwa-iphone-instructions {
        max-height: 80vh;
    }
}

/**
 * 9️⃣ Préférence Dark Mode
 * Support pour dark mode du système
 */
@media (prefers-color-scheme: dark) {
    .pwa-first-launch-content {
        background: #1E293B;
        border-color: #334155;
    }

    .pwa-first-launch-content h5 {
        color: white;
    }

    .pwa-first-launch-content p {
        color: #CBD5E1;
    }

    .pwa-iphone-instructions {
        background: #0F172A;
        border-top-color: #334155;
    }

    .pwa-iphone-instructions-close {
        color: #94A3B8;
    }

    .pwa-iphone-instructions h5 {
        color: white;
    }

    .pwa-iphone-instructions p,
    .pwa-iphone-instructions ol {
        color: #CBD5E1;
    }

    .pwa-iphone-instructions li strong {
        color: #3B82F6;
    }
}

/**
 * 🔟 Animations
 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Print Styles */
@media print {
    .pwa-offline-banner,
    .pwa-update-banner,
    .pwa-first-launch-message,
    .pwa-iphone-instructions,
    #pwa-install-btn,
    #pwa-install-button-fallback {
        display: none !important;
    }
}
