:root {
    --submit-height: 15px;
    --container-padding: 5px;
    /* Dynamic viewport height variables for better mobile support */
    --vh: 1vh;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

/* Main layout and container styles */
.upload-container {
    position: relative;
    margin: 0 auto;
    padding-top: 5px;
    width: 95%;
    /* Fallback for older browsers */
    height: calc(100vh - 60px - var(--submit-height) - var(--safe-area-inset-bottom));
    /* Better support for dynamic viewport */
    height: calc(100dvh - 60px - var(--submit-height) - var(--safe-area-inset-bottom));
    /* iOS Safari fallback */
    height: calc(var(--vh, 1vh) * 100 - 60px - var(--submit-height) - var(--safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 5px;
    padding: var(--container-padding);
    box-sizing: border-box;
    transition: height .4s ease-in-out;
}

.upload {
    background-color: rgba(0, 0, 0, 0.25);
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    text-align: center;
    overflow: auto;
    height: 100%;  /* Changed to use full height since container handles submit height */
    max-height: none;
    min-height: 150px;
    overflow-y: auto;
    border-radius: 35px;
    transition: height .4s ease-in-out;
}

/* Add spacing specifically for the file upload button */
.file-container.upload label[for="fileInput"] {
    margin-top: 5px;
}

.submit-container {
    position: relative;
    height: var(--submit-height);
    margin: 0px auto;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: height .4s ease-in-out;
    overflow: hidden;
}

.preview-container, .file-container, .results-container {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
}

.results-container {
    opacity: 0;
    display: none;
    overflow-x: hidden;
    padding: 0 15px;
}

.preview-container, .file-container {
    opacity: 1;
    display: flex;
}

/* Media query for mobile devices - matches button breakpoint at 685px */
@media (max-width: 685px) {
    .upload-container {
        height: calc(100vh - 130px - var(--submit-height));
        /* Change grid to single column at same breakpoint as buttons shrink */
        grid-template-columns: 1fr;
    }

    #fileList > .sortable-item {
        margin-right: 50px;
        padding: 5px;
        height: auto;
        width: auto;
    }    .upload {
        padding-top: 1px;
        padding-bottom: 1px;
    }
}

/* Small-medium mobile - intermediate sizing */
@media (max-width: 480px) {
    .upload-container {
        height: calc(100vh - 125px - var(--submit-height));
    }

    #fileList > .sortable-item {
        margin-right: 45px;
        padding: 4px;
    }
    
    .upload {
        padding-top: 0px;
        padding-bottom: 0px;
    }
}

/* Extra small mobile - covers 350-450px range */
@media (max-width: 400px) {
    .upload-container {
        height: calc(100vh - 120px - var(--submit-height));
        height: calc(100dvh - 120px - var(--submit-height));
        height: calc(var(--vh, 1vh) * 100 - 120px - var(--submit-height));
    }

    #fileList > .sortable-item {
        margin-right: 40px;
        padding: 3px;
    }
    
    .upload {
        padding-top: 0px;
        padding-bottom: 0px;
    }
}

@media (max-height: 600px) {
    .upload-container {
        margin-bottom: 5px;
        height: calc(100vh - 65px - var(--submit-height));
        height: calc(100dvh - 65px - var(--submit-height));
        height: calc(var(--vh, 1vh) * 100 - 65px - var(--submit-height));
    }
}

/* Specific fixes for older iOS devices */
@media screen and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait) {
    .upload-container {
        /* Additional bottom padding for iOS Safari UI */
        height: calc(var(--vh, 1vh) * 100 - 80px - var(--submit-height) - var(--safe-area-inset-bottom));
        margin-bottom: 10px;
    }
}

/* iPhone 5/SE specific fixes */
@media only screen 
    and (device-width: 320px) 
    and (device-height: 568px) 
    and (-webkit-device-pixel-ratio: 2) {
    .upload-container {
        height: calc(var(--vh, 1vh) * 100 - 100px - var(--submit-height));
        padding-bottom: 20px;
    }
    
    .upload {
        min-height: 120px;
    }
}

/* iPhone 4/4S specific fixes */
@media only screen 
    and (device-width: 320px) 
    and (device-height: 480px) 
    and (-webkit-device-pixel-ratio: 2) {
    .upload-container {
        height: calc(var(--vh, 1vh) * 100 - 110px - var(--submit-height));
        padding-bottom: 25px;
    }
}