/* ==========================================================================
   Mobile Responsive Styles for iViewer
   Applied on narrow viewports (tablets and phones).
   Desktop layout (sidebar fixed on the left + image on the right) is
   preserved above 900px.
   ========================================================================== */

@media screen and (max-width: 900px) {

    /* Allow the page to scroll on mobile. */
    html, body {
        overflow: auto !important;
        overflow-x: hidden !important;
        width: 100%;
    }

    .page {
        margin: 0 !important;
    }

    /* Turn the two-column layout into a stacked column layout. */
    .wrapper {
        display: flex !important;
        flex-direction: column !important;
        min-height: 0 !important;
        padding: 0 !important;
    }

    /* Sidebar first (user selects experiments/solutions),
       image container below (visual result). */
    .sidebar {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        order: 1;
        padding: 10px 0 !important;
        box-sizing: border-box !important;
    }

    .content-wrapper {
        float: none !important;
        width: 100% !important;
        order: 2;
    }

    .content {
        margin-left: 0 !important;
        padding: 0 !important;
        height: auto !important;
    }

    /* Top and bottom bars: full width, no offscreen overflow. */
    .filling-bar {
        width: 100% !important;
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .w3-teal,
    .w3-teal-inf {
        width: 100% !important;
        margin-left: 0 !important;
        box-sizing: border-box !important;
    }

    .w3-teal {
        height: auto !important;
        padding: 6px 8px !important;
    }

    .w3-teal h1 {
        font-size: 22px;
        margin: 4px 0 !important;
        padding: 0 !important;
    }

    /* Image container: fit the mobile viewport. */
    .image-container {
        width: 100% !important;
        margin-left: 0 !important;
        height: 60vh !important;
        min-height: 260px;
        max-height: 75vh;
    }

    .bin-image {
        max-width: 100% !important;
        max-height: 100% !important;
        width: auto !important;
        height: auto !important;
    }

    /* Tables: use the full mobile width, let columns shrink. */
    .tableFixHead,
    .tableFixHeadSmall {
        width: calc(100% - 8px) !important;
        max-width: calc(100% - 8px) !important;
        box-sizing: border-box !important;
    }

    .tableFixHead table,
    .tableFixHeadSmall table {
        width: 100% !important;
        table-layout: auto !important;
    }

    .tableFixHead th,
    .tableFixHead td,
    .tableFixHeadSmall th,
    .tableFixHeadSmall td {
        width: auto !important;
        min-width: 0 !important;
        padding: 4px 5px !important;
        font-size: 12px;
        word-break: break-word;
        white-space: normal !important;
    }

    .tableFixHead tbody,
    .tableFixHeadSmall tbody {
        max-height: 180px;
    }

    #table_experiments th:nth-child(1),
    #table_experiments td:nth-child(1),
    #table_experiments th:nth-child(2),
    #table_experiments td:nth-child(2) {
        white-space: nowrap !important;
    }

    #table_instance th:nth-child(1),
    #table_instance td:nth-child(1) {
        min-width: 0 !important;
        width: auto !important;
    }

    /* Button bar: wrap buttons, smaller text. */
    .w3-teal-inf {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        padding: 6px 4px !important;
        height: auto !important;
        margin-top: 0 !important;
    }

    .big {
        width: auto !important;
        min-width: 0 !important;
        flex: 1 1 45%;
        max-width: 48%;
        padding: 8px 6px !important;
        font-size: 12px !important;
        height: auto !important;
        display: inline-block !important;
        white-space: normal;
        line-height: 1.2;
    }

    /* Loading overlay stays centered and visible even while scrolling. */
    .loading-overlay {
        position: fixed !important;
        margin-left: 0 !important;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
        font-size: 15px !important;
        padding: 12px 18px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }

    /* Logo scales down. */
    .navbar-brand {
        padding-top: 6px !important;
    }
    .navbar-brand img {
        max-width: 80%;
        height: auto;
    }

    /* Sidebar headings */
    .sidebar h3 {
        font-size: 15px;
        padding: 0 8px;
        margin: 10px 0 4px;
    }

    /* Search box fills the row. */
    .floating.specific-search {
        padding: 0 8px;
        gap: 8px;
    }
    .floating.specific-search label {
        font-size: 13px;
    }
    .floating.specific-search input {
        flex: 1 1 150px;
        min-width: 0;
    }

    /* Slider container */
    .slider-container {
        padding: 0 10px;
        box-sizing: border-box;
    }
    .slider-container label {
        font-size: 13px;
    }
    #iteration-slider,
    #time-slider {
        width: 90% !important;
    }

    /* Instance table variant */
    .tableFixHeadSmall tbody {
        max-height: 140px;
    }
}

/* Smaller phones (portrait, <=480px) */
@media screen and (max-width: 480px) {
    .w3-teal h1 {
        font-size: 18px;
    }

    .big {
        font-size: 11px !important;
        padding: 7px 4px !important;
        max-width: 100%;
        flex: 1 1 100%;
    }

    .image-container {
        height: 55vh !important;
        min-height: 230px;
    }

    .tableFixHead th,
    .tableFixHead td,
    .tableFixHeadSmall th,
    .tableFixHeadSmall td {
        font-size: 11px;
        padding: 3px 4px !important;
    }

    .navbar-brand img {
        max-width: 70%;
    }

    .sidebar h3 {
        font-size: 14px;
    }
}

/* Landscape phones: keep image visible */
@media screen and (max-width: 900px) and (orientation: landscape) {
    .image-container {
        height: 80vh !important;
    }
    .tableFixHead tbody,
    .tableFixHeadSmall tbody {
        max-height: 130px;
    }
}
