@media (max-width: 768px) {
    .glass-header {
        padding: 0.75rem 1rem;
        flex-direction: column !important;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .logo {
        font-size: 1.25rem;
    }

    .search-container {
        margin-left: 0;
        max-width: 100%;
        width: 100%;
    }

    .search-box {
        padding: 0.5rem 1rem;
    }

    .search-toggles {
        display: none; /* Mobile space saving */
    }

    .container {
        padding: 1rem;
    }

    .results-header {
        flex-direction: column !important;
        align-items: flex-start;
        gap: 1rem;
    }

    /* Grid adjustment for mobile */
    .grid {
        grid-template-columns: 1fr !important;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95% !important;
        padding: 1.5rem !important;
        margin: 10px auto;
    }

    .tabs {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tab-btn {
        font-size: 0.85rem;
        padding: 0.4rem 0.75rem;
    }

    /* Gallery adjustment - CRITICAL for images not fitting */
    .gallery-grid {
        grid-template-columns: 1fr !important; /* Single column on mobile */
        gap: 1rem;
    }

    .gallery-item {
        width: 100%;
    }

    .gallery-item img {
        width: 100% !important;
        height: auto !important;
    }
}

/* --- Lightbox Overlay for Image Zoom --- */
#imageLightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    z-index: 2000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

#imageLightbox.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

#imageLightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border: 2px solid var(--glass-border);
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 2.5rem;
    cursor: pointer;
    z-index: 2001;
    opacity: 0.7;
}
.lightbox-close:hover { opacity: 1; }

/* --- Robust Mobile Optimization --- */
@media screen and (max-width: 600px) {
    /* 1. Detail Modal: Strict 100% width, no overflow */
    .modal-content {
        width: 100% !important;
        max-width: 100vw !important;
        height: 100vh !important; /* Full height */
        margin: 0 !important;
        padding: 12px 15px !important;
        border-radius: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        overflow-x: hidden !important; /* Prevent widening */
        overflow-y: auto !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Prevent any children from widening the parent */
    .modal-content * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 2. Title: Break within the fixed box */
    #modelDetailTitle {
        display: block !important;
        width: 100% !important;
        font-size: 1.1rem !important;
        white-space: normal !important;
        overflow-wrap: break-word !important;
        word-wrap: break-word !important;
        padding-right: 40px !important;
        line-height: 1.4 !important;
    }

    /* 3. Table Container: Internal scrolling for tables */
    .table-container {
        font-size: 0.75rem !important;
        overflow-x: auto !important; /* ONLY Table scrolls, not modal */
        margin: 10px 0 !important;
        width: 100% !important;
        background: transparent !important;
    }

    .gallery-grid {
        grid-template-columns: 1fr !important; /* Single column for clarity */
        gap: 15px !important;
    }
}
