/* Responsive Design */

/* Minimum supported width: 320px */
html, body {
    min-width: 320px;
}

/* Desktop (≥1024px) - sidebar + main content side by side */
@media (min-width: 1024px) {
    .row {
        display: flex;
    }

    .col-lg-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }

    .col-lg-9 {
        flex: 0 0 75%;
        max-width: 75%;
    }

    #modelListContainer {
        max-height: 600px;
        overflow-y: auto;
    }

    .card {
        margin-bottom: 1.5rem;
    }

    #graphContainer {
        height: 500px;
    }

    /* Hide mobile tab nav on desktop */
    .mobile-tab-nav {
        display: none;
    }
}

/* Tablet (768px - 1023px) - stacked layout with model list on top */
@media (min-width: 768px) and (max-width: 1023px) {
    .row {
        display: flex;
        flex-wrap: wrap;
    }

    .col-md-4 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }

    .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .col-md-8 {
        flex: 0 0 66.667%;
        max-width: 66.667%;
    }

    .col-12 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* On tablet, sidebar goes full width on top */
    .col-lg-3,
    .col-lg-9 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Sidebar toggle on tablet */
    .sidebar-hidden {
        width: 0 !important;
        max-width: 0 !important;
        flex: 0 0 0 !important;
        padding: 0 !important;
        opacity: 0;
        overflow: hidden;
        margin: 0 !important;
    }

    .sidebar-collapsed {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    #modelListContainer {
        max-height: 400px;
        overflow-y: auto;
        margin-bottom: 1.5rem;
    }

    .card {
        margin-bottom: 1rem;
    }

    #graphContainer {
        height: 400px;
    }

    /* Hide mobile tab nav on tablet */
    .mobile-tab-nav {
        display: none;
    }
}

/* Mobile (<768px) - fully stacked, tab-based navigation for panels */
@media (max-width: 767px) {
    body {
        padding: 0;
    }

    #app {
        padding: 0;
    }

    header {
        margin-bottom: 1rem;
    }

    header .navbar-brand {
        font-size: 1rem;
    }

    .navbar-nav {
        flex-direction: row;
        gap: 0.5rem;
    }

    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .row {
        display: flex;
        flex-direction: column;
    }

    .col-lg-3,
    .col-lg-9,
    .col-md-4,
    .col-md-6,
    .col-md-8,
    .col-12 {
        flex: 0 0 100%;
        max-width: 100%;
        padding: 0.5rem;
    }

    /* Sidebar toggle on mobile */
    .sidebar-hidden {
        width: 0 !important;
        max-width: 0 !important;
        flex: 0 0 0 !important;
        padding: 0 !important;
        opacity: 0;
        overflow: hidden;
        margin: 0 !important;
    }

    .sidebar-collapsed {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    #modelListContainer {
        max-height: 300px;
        overflow-y: auto;
        margin-bottom: 1rem;
    }

    .card {
        margin-bottom: 1rem;
        border-radius: 0.375rem;
    }

    .card-header {
        padding: 0.75rem;
    }

    .card-header h5 {
        font-size: 1rem;
    }

    .card-body {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    #graphContainer {
        height: 300px;
    }

    .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .list-group-item {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }

    /* Mobile tab navigation for detail panels */
    .mobile-tab-nav {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 2px solid #dee2e6;
        margin-bottom: 0.75rem;
        gap: 0;
        scrollbar-width: none;
    }

    .mobile-tab-nav::-webkit-scrollbar {
        display: none;
    }

    .mobile-tab-nav .tab-btn {
        flex: 0 0 auto;
        padding: 0.5rem 0.875rem;
        border: none;
        background: none;
        color: #6c757d;
        font-size: 0.85rem;
        white-space: nowrap;
        border-bottom: 2px solid transparent;
        margin-bottom: -2px;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-tab-nav .tab-btn:hover {
        color: #007bff;
    }

    .mobile-tab-nav .tab-btn.active {
        color: #007bff;
        border-bottom-color: #007bff;
        font-weight: 600;
    }

    /* Hide non-active panels on mobile */
    .mobile-panel {
        display: none;
    }

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

/* Extra Small Devices (320px - 480px) */
@media (max-width: 480px) {
    header .navbar-brand {
        font-size: 0.9rem;
    }

    .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }

    .card-header h5 {
        font-size: 0.95rem;
    }

    .card-body {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    #graphContainer {
        height: 250px;
    }

    #modelListContainer {
        max-height: 250px;
    }
}

/* Minimum supported width: 320px */
@media (max-width: 320px) {
    #app {
        min-width: 320px;
        overflow-x: auto;
    }

    .card-body {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    #graphContainer {
        height: 220px;
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 600px) {
    #modelListContainer {
        max-height: 300px;
    }

    #graphContainer {
        height: 300px;
    }

    .card {
        margin-bottom: 0.5rem;
    }
}

/* Print Styles */
@media print {
    header,
    .btn,
    #searchInput {
        display: none;
    }

    .card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
