/*
 * Mobile and tablet adjustments, loaded after main.css / ermsf.css.
 * Breakpoints follow Bootstrap 4: phone < 576, small tablet < 768, tablet < 992.
 */

/* ---------- Header ---------- */
@media (max-width: 991px) {
    /* The template squeezes the logo cell to 55-130px, which the 140px logo overflows onto the menu button */
    #header-fix .logo-bar,
    .compact-menu:not(.horizontal-menu) #header-fix .logo-bar {
        width: auto !important;
        padding: 0 10px 0 12px;
        display: flex;
        align-items: center;
        border-right: none;
    }

    #header-fix .logo-bar .horizontal-logo img {
        height: 30px;
        width: auto;
    }

    #header-fix .collapse-menu-bar {
        width: 46px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-left: 1px solid var(--bordercolor);
    }

    #header-fix .collapse-menu-bar .sidebarCollapse {
        display: block;
        padding: 12px;
        line-height: 1;
    }

    /* Dropdowns from the header should never be wider than the screen */
    #header-fix .dropdown-menu {
        max-width: calc(100vw - 16px);
    }
}

@media (max-width: 400px) {
    #header-fix .logo-bar .horizontal-logo img {
        height: 24px;
    }

    #header-fix .top-icon > li {
        padding: 18px 4px;
    }
}

/* ---------- Off-canvas sidebar ---------- */
.sidebar-backdrop {
    display: none;
}

/*
 * Landscape tablets (992-1199px) get the same off-canvas menu as phones instead of the
 * template's 80px icon rail, which only expands on mouse hover and is awkward on touch screens.
 */
@media (min-width: 992px) and (max-width: 1199px) {
    body:not(.horizontal-menu) main,
    body:not(.horizontal-menu) .site-footer {
        margin-left: 0 !important;
        width: 100% !important;
    }

    body:not(.horizontal-menu) .sidebar,
    .compact-menu:not(.horizontal-menu) .sidebar:not(:hover) {
        position: fixed;
        top: 65px;
        bottom: 0;
        height: auto;
        width: 250px;
        -webkit-transform: translateX(-250px);
        transform: translateX(-250px);
    }

    body:not(.horizontal-menu) .sidebar.active {
        -webkit-transform: translateX(0);
        transform: translateX(0);
    }
}

@media (max-width: 1199px) {
    .sidebar.active {
        z-index: 1040;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 65px;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1035;
        background: rgba(0, 0, 0, 0.45);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    body.sidebar-open {
        overflow: hidden;
    }
}

/* ---------- Page layout ---------- */
@media (max-width: 767px) {
    main .card-body {
        padding: 0.9rem;
    }

    main .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Page titles and breadcrumbs stack instead of fighting for one line */
    main .sub-header {
        flex-direction: column;
        align-items: flex-start !important;
    }

    main .breadcrumb {
        flex-wrap: wrap;
        padding-left: 0;
    }

    /* Button groups in toolbars wrap onto a new line */
    main .card-header .btn,
    main .card-header .btn-group {
        margin-top: 0.25rem;
    }

    /* Inputs below 16px make iOS Safari zoom the page on focus */
    main input.form-control,
    main select.form-control,
    main textarea.form-control,
    main .dataTables_wrapper input,
    main .dataTables_wrapper select {
        font-size: 16px;
    }

    /* Modals use almost the full width on phones */
    .modal-dialog {
        margin: 0.5rem;
        max-width: none;
    }
}

/* Dashboard cards: fixed 300px height only matters when cards sit side by side */
@media (max-width: 991px) {
    .home-cards {
        height: auto;
        max-height: 300px;
        overflow: auto;
    }
}

/* ---------- Tables ---------- */
/* Tables scroll inside their card instead of being squeezed or cut off */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
    main .table th,
    main .table td {
        min-width: 7rem;
    }

    main .table th:has(> input[type=checkbox]),
    main .table td:has(> input[type=checkbox]),
    main .table th:empty,
    main .table td:empty {
        min-width: 0;
    }

    main .table td.cell-long {
        min-width: 15rem;
    }

    main .table th {
        white-space: nowrap;
    }

    .dataTables_wrapper .dataTables_length select {
        width: auto !important;
        display: inline-block;
        margin: 0 0.25rem;
    }

    /* DataTables: stack the length / search / info / paging controls */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        display: block;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        flex-wrap: wrap;
        justify-content: flex-start !important;
    }

    /* Tabulator grids scroll horizontally instead of truncating columns */
    .tabulator {
        overflow-x: auto;
    }
}

/* ---------- Overview parameter menu ---------- */
.parameter-menu .nav-link.active {
    color: #fff;
}

@media (max-width: 991px) {
    .parameter-menu {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .parameter-menu::-webkit-scrollbar {
        display: none;
    }

    .parameter-menu .nav-link {
        white-space: nowrap;
    }
}

/* ---------- Touch targets ---------- */
@media (hover: none) and (pointer: coarse) {
    .sidebar .sidebar-menu li a,
    .document-menu .nav-link,
    .dropdown-item {
        min-height: 40px;
        display: flex;
        align-items: center;
    }
}
