/* PWA-specific styles */

/* iOS install prompt */
#ios-install-prompt {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #f8f9fa;
    color: #212529;
    padding: 15px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* iOS PWA Standalone Mode - Aggressive full height enforcement */
body.ios-pwa-standalone {
    height: 100vh !important;
    height: -webkit-fill-available !important;
    height: var(--full-height, 100vh) !important;
    min-height: 100vh !important;
    min-height: -webkit-fill-available !important;
    min-height: var(--full-height, 100vh) !important;
    max-height: 100vh !important;
    max-height: -webkit-fill-available !important;
    max-height: var(--full-height, 100vh) !important;
    overflow: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
}

body.ios-pwa-standalone .page {
    height: 100vh !important;
    height: -webkit-fill-available !important;
    height: var(--full-height, 100vh) !important;
    min-height: 100vh !important;
    min-height: -webkit-fill-available !important;
    min-height: var(--full-height, 100vh) !important;
    max-height: 100vh !important;
    max-height: -webkit-fill-available !important;
    max-height: var(--full-height, 100vh) !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
}

body.ios-pwa-standalone main {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

body.ios-pwa-standalone .content {
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    box-sizing: border-box !important;
}

body.ios-pwa-standalone .top-row {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
}

/* Mobile specific for iOS PWA standalone */
@media (max-width: 767.98px) {
    body.ios-pwa-standalone .content {
        height: calc(100% - 3.5rem) !important;
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
    }
    
    body.ios-pwa-standalone .sidebar {
        height: 100vh !important;
        height: -webkit-fill-available !important;
        height: var(--full-height, 100vh) !important;
    }
}

#ios-install-prompt .content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 960px;
    margin: 0 auto;
}

#ios-install-prompt .message {
    flex: 1;
    padding-right: 15px;
}

#ios-install-prompt h3 {
    margin: 0 0 5px 0;
    font-size: 16px;
    font-weight: 600;
}

#ios-install-prompt p {
    margin: 0;
    font-size: 14px;
}

#ios-install-prompt .icon {
    display: flex;
    align-items: center;
    margin-right: 15px;
}

#ios-install-prompt .icon svg {
    width: 24px;
    height: 24px;
    fill: #007aff;
}

#ios-install-prompt .close-button {
    background: none;
    border: none;
    font-size: 20px;
    color: #6c757d;
    cursor: pointer;
    padding: 0 10px;
}

/* Add to home screen button */
#add-to-home {
    display: none;
    background-color: #007aff;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    margin: 10px 0;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #ios-install-prompt {
        background-color: #2c2c2e;
        color: #f5f5f5;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    }
    
    #ios-install-prompt .close-button {
        color: #a0a0a0;
    }
    
    #add-to-home {
        background-color: #0a84ff;
    }
}

/* Safe area insets for iOS devices with notches */
@supports (padding: max(0px)) {
    #ios-install-prompt {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
    
    /* Ensure content respects safe areas */
    .page {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    /* Ensure scrollable content has proper padding */
    .content {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Standalone mode (when app is installed) */
@media all and (display-mode: standalone) {
    #ios-install-prompt, #add-to-home {
        display: none !important;
    }
    
    /* Full screen in standalone mode */
    html {
        height: 100%;
        height: -webkit-fill-available;
        width: 100%;
        margin: 0;
        padding: 0;
    }
    
    body {
        margin: 0;
        padding: 0;
        height: 100%;
        height: -webkit-fill-available;
        width: 100%;
        overflow: hidden;
        position: relative;
    }
    
    .page {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        /* Handle notches and home indicator */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        box-sizing: border-box;
    }
    
    main {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
        height: 100%;
    }
    
    /* Ensure content is scrollable and uses remaining space */
    .content {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
        height: 100%;
        padding-bottom: 1rem;
        box-sizing: border-box;
    }
    
    /* Top row should not flex */
    .top-row {
        flex: 0 0 auto;
        flex-shrink: 0;
    }
    
    /* Sidebar adjustments for standalone mode */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        height: -webkit-fill-available;
        z-index: 1040;
    }
    
    /* Mobile Portrait adjustments for standalone mode */
    @media (max-width: 767.98px) and (orientation: portrait) {
        .page {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            height: 100%;
            width: 100%;
        }
        
        .sidebar {
            height: 100%;
            height: -webkit-fill-available;
            width: 280px;
        }
        
        main {
            height: 100%;
        }
        
        /* Ensure content uses full available space */
        .content {
            height: calc(100% - 3.5rem); /* Subtract top row height */
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }

    /* Mobile Landscape adjustments for standalone mode - iPhone and small tablets */
    @media (max-width: 1023px) and (orientation: landscape) {
        .page {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            height: 100%;
            width: 100%;
            flex-direction: column;
        }
        
        .sidebar {
            height: 100%;
            height: -webkit-fill-available;
            width: 320px;
            position: fixed;
            top: 0;
            left: -320px;
            z-index: 1040;
            transition: left 0.3s ease-out;
        }

        .sidebar.show {
            left: 0;
        }
        
        main {
            height: 100%;
            width: 100%;
        }
        
        .top-row {
            height: 3rem;
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
        }
        
        /* Ensure content uses full available space in landscape */
        .content {
            height: calc(100% - 3rem); /* Subtract smaller top row height */
            min-height: calc(100% - 3rem);
            max-height: calc(100% - 3rem);
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
            padding-left: max(1rem, env(safe-area-inset-left));
            padding-right: max(1rem, env(safe-area-inset-right));
            box-sizing: border-box;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
    }

    /* Tablet Portrait adjustments for standalone mode */
    @media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
        .page {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            height: 100%;
            width: 100%;
        }
        
        .sidebar {
            height: 100%;
            height: -webkit-fill-available;
            width: 300px;
        }
        
        main {
            height: 100%;
        }
        
        /* Ensure content uses full available space */
        .content {
            height: calc(100% - 3.5rem); /* Subtract top row height */
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }
    
    /* Desktop and Large Tablet Landscape adjustments for standalone mode */
    @media (min-width: 1024px) {
        .page {
            flex-direction: row;
        }
        
        .sidebar {
            position: relative;
            width: 250px;
            height: 100%;
        }
        
        main {
            flex: 1;
            height: 100%;
        }
    }
}
