/* PWA Mobile Optimization CSS */
/* Ensures perfect display when app is added as shortcut on phones */

/* iOS Safari Standalone Mode Optimizations */
.ios-standalone {
    /* Account for iOS status bar */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Android Chrome Standalone Mode Optimizations */
.android-standalone {
    /* Optimize for Android display cutouts */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* PWA Status Bar Styling - Fix header color and prevent content scrolling behind status bar */
@supports (padding-top: env(safe-area-inset-top)) {
    /* Keep original header colors for PWA mode - RESTORE WHITE/YELLOW THEME */
    body.ios-standalone .navbar,
    body.android-standalone .navbar {
        padding-top: calc(1rem + env(safe-area-inset-top));
        background: linear-gradient(135deg, #ffffff 0%, #fffacd 100%) !important;
        border-bottom: 3px solid #ffc107 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1050 !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    }
    
    /* Fix navbar brand colors for PWA */
    body.ios-standalone .navbar-brand,
    body.android-standalone .navbar-brand {
        color: #000 !important;
    }
    
    body.ios-standalone .navbar-brand .lottery-logo,
    body.android-standalone .navbar-brand .lottery-logo {
        color: #000 !important;
    }
    
    body.ios-standalone .navbar-brand .fas,
    body.android-standalone .navbar-brand .fas {
        color: #ffc107 !important;
    }
    
    /* Add top padding to body content to prevent scrolling behind header */
    body.ios-standalone,
    body.android-standalone {
        padding-top: calc(90px + env(safe-area-inset-top)) !important;
        background: #f8f9fa !important;
    }
    
    /* Ensure main content starts below fixed header */
    body.ios-standalone .container-fluid,
    body.android-standalone .container-fluid {
        margin-top: 0 !important;
        padding-top: 10px !important;
        position: relative !important;
        z-index: 1 !important;
    }
}

/* PWA Install Button Styling */
#pwa-install-btn {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 9999;
    background: linear-gradient(135deg, #1a472a 0%, #0f2c18 100%);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 12px 20px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(26, 71, 42, 0.3);
    transition: all 0.3s ease;
    font-size: 14px;
    min-width: 120px;
}

#pwa-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(26, 71, 42, 0.4);
    background: linear-gradient(135deg, #0f2c18 0%, #1a472a 100%);
}

#pwa-install-btn i {
    margin-right: 8px;
}

/* Full-screen mobile optimizations */
@media (max-width: 768px) {
    /* Optimize viewport for mobile PWA */
    body.ios-standalone,
    body.android-standalone {
        margin: 0;
        padding: 0;
        overflow-x: hidden;
    }
    
    /* Ensure full-width containers */
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    /* Optimize cards for mobile PWA */
    .card {
        border-radius: 12px;
        margin-bottom: 15px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    }
    
    /* Optimize lottery balls for mobile PWA */
    .lottery-number, .lottery-ball {
        min-width: 35px;
        height: 35px;
        line-height: 35px;
        font-size: 14px;
        margin: 2px;
    }
    
    /* Optimize data analytics for mobile PWA */
    .hot-number-item, .cold-number-item, .absent-number-item {
        width: 35px !important;
        height: 35px !important;
        line-height: 35px !important;
        font-size: 12px !important;
        margin: 2px !important;
    }
    
    /* Optimize mobile navigation for PWA */
    body.ios-standalone #mobile-nav,
    body.android-standalone #mobile-nav {
        bottom: env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        border-top: 1px solid rgba(0,0,0,0.1);
    }
    
    /* PWA-specific bottom padding adjustments */
    body.ios-standalone,
    body.android-standalone {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
    
    /* Fix for the yellow header issue - override theme color in PWA mode */
    body.ios-standalone .navbar-brand,
    body.android-standalone .navbar-brand {
        color: #000 !important;
    }
    
    /* Prevent scrolling content from going behind status bar */
    body.ios-standalone .container,
    body.android-standalone .container,
    body.ios-standalone .container-fluid,
    body.android-standalone .container-fluid {
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* Ensure cards don't scroll behind header */
    body.ios-standalone .card,
    body.android-standalone .card {
        position: relative !important;
        z-index: 1 !important;
    }
}

/* Landscape mode optimizations for mobile PWA */
@media (max-width: 768px) and (orientation: landscape) {
    body.ios-standalone,
    body.android-standalone {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
    
    .card {
        margin-bottom: 10px;
    }
    
    .lottery-number, .lottery-ball {
        min-width: 30px;
        height: 30px;
        line-height: 30px;
        font-size: 12px;
    }
}

/* Dark mode support for PWA */
@media (prefers-color-scheme: dark) {
    body.ios-standalone,
    body.android-standalone {
        background-color: #121212;
        color: #ffffff;
    }
    
    body.ios-standalone .card,
    body.android-standalone .card {
        background-color: #1e1e1e;
        border-color: #333;
        color: #ffffff;
    }
    
    body.ios-standalone #mobile-nav,
    body.android-standalone #mobile-nav {
        background: rgba(30, 30, 30, 0.98);
        border-top-color: rgba(255,255,255,0.1);
    }
}

/* Splash screen fade out animation */
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; visibility: hidden; }
}

/* PWA Loading States */
.pwa-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a472a 0%, #0f2c18 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 99999;
    animation: fadeOut 0.5s ease 2s forwards;
}

.pwa-loading .logo {
    width: 80px;
    height: 80px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #1a472a;
    margin-bottom: 20px;
}

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

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

/* Prevent text selection on PWA interactive elements */
body.ios-standalone .lottery-number,
body.android-standalone .lottery-number,
body.ios-standalone .lottery-ball,
body.android-standalone .lottery-ball,
body.ios-standalone .hot-number-item,
body.android-standalone .hot-number-item,
body.ios-standalone .cold-number-item,
body.android-standalone .cold-number-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Smooth scrolling for PWA */
body.ios-standalone,
body.android-standalone {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Hide browser UI elements in PWA mode */
body.ios-standalone *:focus,
body.android-standalone *:focus {
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

/* PWA-specific button animations */
body.ios-standalone .btn,
body.android-standalone .btn {
    transition: all 0.2s ease;
    transform: translateZ(0); /* Hardware acceleration */
}

body.ios-standalone .btn:active,
body.android-standalone .btn:active {
    transform: scale(0.98);
}

/* Optimize font rendering for PWA */
body.ios-standalone,
body.android-standalone {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}