/* Hide mobile elements by default on all screen sizes */
.show-on-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    /* Project Vitrine: Edit button icon-only styling on mobile */
    #edit-button {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        border: 1px solid #dee2e6 !important;
        border-radius: 4px !important;
        box-shadow: none !important;
    }

    #edit-button i {
        font-size: 1.2rem !important;
        margin: 0 !important;
        color: #9a1818;
    }

    #edit-button .btn-text {
        display: none !important;
    }
    *, *::before, *::after { /* Add this for global box-sizing */
        box-sizing: border-box;
    }

    /* Hide elements that should not appear on mobile */
    .hide-on-mobile {
        display: none !important;
    }

    /* Show elements that should only appear on mobile */
    .show-on-mobile {
        display: flex !important;
    }

    /* Default display for show-on-mobile elements that should be block */
    .show-on-mobile.d-block {
        display: block !important;
    }

    /* Hide all dropdown-related elements on mobile */
    .selection-dropdown,
    .dropdown-toggle,
    .dropdown-menu,
    .custom-select-dropdown,
    .custom-select-option,
    .dropdown-toggle-icon {
        display: none !important;
    }

    .desktop-specific-view-options {
        display: none !important;
    }
}

/* Hide mobile menu button by default */
#mobile-menu-button {
    display: none;
}

@media (max-width: 768px) {
    /* Mobile menu button container */
    .mobile-menu-button-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 15px;
        margin-bottom: 10px;
        width: 100%;
    }

    /* Container for the menu button and label on the left */
    .mobile-menu-left {
        display: flex;
        align-items: center;
    }

    /* Mobile menu label */
    .mobile-menu-label {
        margin-left: 15px;
        font-size: 16px;
        font-weight: 500;
    }

    /* Mobile menu button */
    #mobile-menu-button {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background-color: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        cursor: pointer;
        position: relative;
        z-index: 100;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    /* Style for the menu button */
    #mobile-menu-button i {
        font-size: 1.2rem;
    }

    /* Mobile view toggle button */
    #mobile-view-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background-color: #f8f9fa;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        cursor: pointer;
        z-index: 100;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }

    #mobile-view-toggle i {
        font-size: 1.2rem;
        color: #333;
    }
}

/* Hide mobile folders container by default */
#mobile-folders-container {
    display: none;
}

/* Overlay for when mobile menu is open - GLOBAL STYLES */
#mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    display: none; /* Hidden by default globally */
}

#mobile-overlay.open {
    display: block; /* Visible when .open class is added */
}

@media (max-width: 768px) {
    /* Mobile folders tree container */
    #mobile-folders-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 75%;
        height: 100vh;
        background-color: white;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
        padding: 20px 15px 15px 15px;
        display: block !important;
    }

    /* Style the folders tree inside the mobile container */
    #mobile-folders-container .folders-tree,
    #mobile-folders-container .collections-tree {
        max-height: none;
        overflow-y: visible;
        padding-bottom: 20px;
    }

    #mobile-folders-container #project-folders-container {
        display: block !important;
        width: 100%;
        margin-bottom: 40px;
    }

    #mobile-folders-container .folders-section,
    #mobile-folders-container .collections-section {
        margin-bottom: 20px;
    }

    #mobile-folders-container .section-title {
        margin: 10px 0;
        font-weight: bold;
    }

    #mobile-folders-container ul {
        padding-left: 15px !important;
    }

    #mobile-folders-container .folder-item {
        padding: 8px 0;
    }

    /* Make sure virtual folders are visible */
    #mobile-folders-container .virtual {
        display: block !important;
    }

    #mobile-folders-container.open {
        transform: translateX(0);
    }
}

@media (max-width: 768px) {
    /* Main content container adjustments */
    #GROS {
        flex-direction: column;
        height: auto !important;
    }

    /* Mobile grid/list hybrid view */
    .mobile-item-container {
        width: 100%;
        padding: 10px;
        box-sizing: border-box;
    }

    .mobile-item {
        display: flex;
        flex-direction: column;
        width: calc(50% - 7px); /* Accommodate 10px gutter AND 1px item border with box-sizing */
        margin-bottom: 10px;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        overflow: hidden;
        background-color: white;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        box-sizing: border-box;
        transition: opacity 0.3s ease-in-out; /* Added for smooth reveal */
    }

    .mobile-item-image {
        width: 100%;
        height: auto; /* So it adapts to the image's proportional height */
        background-color: #f8f9fa;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden; /* Added for safety */
    }

    .mobile-item-image img {
        max-width: 100%;
        height: auto; /* This ensures aspect ratio is maintained based on width */
        display: block;
        object-fit: contain; /* Added here */
    }

    .mobile-item-content {
        padding: 10px;
        border-top: 1px solid #dee2e6;
        position: relative;
    }

    .mobile-item-title {
        font-weight: bold;
        margin-bottom: 5px;
        font-size: 1rem;
        word-break: break-word;
    }

    /* Metadata corner elements */
    .mobile-item-metadata {
        position: absolute;
        font-size: 0.75rem;
        color: #555;
        max-width: 45%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .metadata-top-left {
        top: 5px;
        left: 10px;
    }

    .metadata-top-right {
        top: 5px;
        right: 10px;
        text-align: right;
    }

    .metadata-bottom-left {
        bottom: 5px;
        left: 10px;
    }

    .metadata-bottom-right {
        bottom: 5px;
        right: 10px;
        text-align: right;
    }

    /* Adjust explore div for mobile */
    #explore-div {
        width: 100% !important;
        padding: 0 !important;
    }

    #explore-results {
        width: 100%;
    }

    /* Restore list view styles */
    .mobile-item-container.list-view .mobile-item {
        width: 100%;
        margin-bottom: 10px;
    }

    .mobile-item.needs-lazy-reveal {
        visibility: hidden;
        opacity: 0;
    }
}

@media (max-width: 768px) {
    /* VisionneuseVitrine Mobile Styles */
    .containerV .row.flex-nowrap {
        width: 100% !important;
        flex-direction: column !important;
    }

    .vitrine-leftcol,
    .vitrine-details {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        overflow-y: visible !important;
        position: static !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .vitrine-details {
        margin-top: 20px;
    }

    #column-resizer {
        display: none !important;
    }

    /* Style for the action buttons container */
    .vitrine-leftcol > .d-flex.justify-content-center {
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 8px !important;
        margin-top: 15px !important;
        margin-bottom: 15px !important;
    }

    /* Styling for individual action buttons */
    .btn-vitrine-primary,
    .btn-vitrine-secondary {
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        font-size: 1rem !important;
        line-height: 40px !important;
        text-align: center !important;
        flex-shrink: 0;
    }

    .btn-vitrine-primary .btn-text,
    .btn-vitrine-secondary .btn-text {
        display: none !important;
    }

    .btn-vitrine-primary i,
    .btn-vitrine-secondary i {
        margin: 0 !important;
    }

    /* Project title and info */
    #tabloid {
        text-align: center;
        padding: 15px;
        margin-bottom: 15px;
    }

    #tabloid h3 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }

    #mobile-folders-container {
        padding-top: 20px !important;
        margin-top: 20px !important;
    }

    /* Mobile infinite scroll loader */
    .mobile-loader {
        text-align: center;
        padding: 20px;
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: white;
        z-index: 1000;
    }

    .mobile-loader.active {
        display: block;
    }

    .mobile-loader-spinner {
        display: inline-block;
        width: 30px;
        height: 30px;
        border: 3px solid rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        border-top-color: #007bff;
        animation: spin 1s ease-in-out infinite;
    }

    @keyframes spin {
        to { transform: rotate(360deg); }
    }
}

/* Fullscreen Image Overlay for Mobile Vitrine */
#fullscreen-image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0s linear 0.3s;
}

#fullscreen-image-overlay.active {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease-in-out, visibility 0s linear 0s;
}

#fullscreen-image-overlay img#fullscreened-image-content {
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
    cursor: default;
    transform: scale(0.8);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease-in-out;
    transition-delay: 0.05s;
}

#fullscreen-image-overlay.active img#fullscreened-image-content {
    transform: scale(1);
    opacity: 1;
}

/* Landscape mode adjustments for fullscreen image */
@media (max-width: 768px) and (orientation: landscape) {
    #fullscreen-image-overlay.active {
        background-color: transparent !important;
    }

    #fullscreen-image-overlay.active img#fullscreened-image-content {
        width: 100vw;
        height: 100vh;
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.3s ease-in-out;
    }
}

@media (max-width: 768px) {
    .containerV .row.flex-nowrap {
        flex-direction: column !important;
    }

    .vitrine-leftcol,
    .vitrine-details {
        width: 100% !important;
        max-width: 100% !important;
    }

    #column-resizer {
        display: none !important;
    }
}
