/* PWA Enhancements */

/* App Loading Screen */
.pwa-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #029db1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
    font-family: Arial, sans-serif;
}

.pwa-loading .logo {
    font-size: 48px;
    margin-bottom: 20px;
}

.pwa-loading .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    body {
        font-size: 16px;
        line-height: 1.4;
    }
    
    /* Touch-friendly buttons */
    button, .btn, input[type="submit"], input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        border-radius: 8px;
        border: none;
        cursor: pointer;
        font-size: 16px;
        touch-action: manipulation;
    }
    
    /* Improved form inputs for mobile */
    input, textarea, select {
        min-height: 44px;
        padding: 12px;
        border-radius: 8px;
        border: 1px solid #ddd;
        font-size: 16px; /* Prevents zoom on iOS */
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Better table display on mobile */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Improved navigation for mobile */
    .sidebar-menu {
        padding-bottom: 60px; /* Space for mobile nav */
    }
}

/* PWA Install Button */
.pwa-install-btn {
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.pwa-install-btn:hover {
    background: #027a8a !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2) !important;
}

/* Connection Status Bar */
.connection-status {
    animation: slideDown 0.3s ease;
}

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

/* Pull to Refresh */
.ptr-refresh {
    position: relative;
    overflow: hidden;
}

.ptr-content {
    transform: translateY(0px);
    transition: transform 0.3s ease;
}

.ptr-refresh.ptr-pulling .ptr-content {
    transform: translateY(80px);
}

.ptr-preloader {
    position: absolute;
    top: -80px;
    left: 50%;
    transform: translateX(-50%);
    height: 80px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    color: #029db1;
    font-size: 14px;
}

/* Offline Form Styling */
.offline-form {
    opacity: 0.7;
    pointer-events: none;
    position: relative;
}

.offline-form::before {
    content: "Hors ligne - Les données seront synchronisées";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: white;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    z-index: 10;
}

/* App-like appearance */
body.pwa-standalone {
    /* Remove default margins and scrollbars when installed as PWA */
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Safe area insets for devices with notches */
@supports (padding: max(0px)) {
    .main-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }
    
    .main-footer {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .sidebar {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .pwa-loading {
        background: #1a1a1a;
    }
    
    .offline-container {
        background: #2d2d2d;
        color: #ffffff;
    }
    
    .offline-container h1 {
        color: #ffffff;
    }
    
    .offline-container p {
        color: #cccccc;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
    }
    
    .pwa-install-btn {
        transition: none;
    }
    
    .connection-status {
        animation: none;
    }
}
