/* Responsive overrides. Everything is inside max-width media queries,
   so the desktop layout (>= 992px) is not affected. */

/* ---------- Tablet & below ---------- */
@media (max-width: 991.98px) {
    html, body {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Navbar stays above the drawer so logo and toggle button remain reachable */
    .navbar {
        z-index: 400;
    }

    /* Navbar: allow wrapping of its items, keep it compact */
    .navbar .container-fluid {
        flex-wrap: wrap;
        gap: 6px;
        padding-left: 8px;
        padding-right: 8px;
    }

    .navbar .navbar-header {
        width: auto !important;
        flex: 0 0 auto;
        flex-wrap: nowrap;
        align-items: center;
    }

    .navbar .navbar-header > .col-6 {
        width: auto;
        flex: 0 0 auto;
    }

    .navbar .logo-dashboard {
        width: 90px;
        min-width: 70px;
        max-width: none;
        margin: 0 8px 0 0 !important;
    }

    .navbar .input-group.w-25 {
        width: auto !important;
        flex: 1 1 180px;
        min-width: 0;
    }

    .navbar .input-group .form-control {
        min-width: 60px;
    }

    .navbar .acc-btn {
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Sidebar becomes an off-canvas drawer. "active" = hidden (same as desktop). */
    #sidebar {
        top: 0;
        margin-left: 0 !important;
        transform: none;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.2);
        z-index: 300;
        padding-top: 0;
    }

    #sidebar .sidebar-component {
        margin-top: 70px;
    }

    #sidebar.active {
        margin-left: 0 !important;
        transform: translateX(-100%);
        box-shadow: none;
        visibility: hidden;
    }

    #content,
    #content[style] {
        margin-left: 0 !important;
        padding: 130px 8px 70px;
        width: 100%;
        overflow-x: hidden;
    }

    /* Keep the hamburger icon static (core.css mobile rules assumed inverted state) */
    #sidebarCollapse span,
    #sidebarCollapse.active span,
    #sidebarCollapse.active span:first-of-type,
    #sidebarCollapse.active span:nth-of-type(2),
    #sidebarCollapse.active span:last-of-type {
        transform: none;
        opacity: 1;
    }

    /* Wide content scrolls horizontally inside its own box instead of the page */
    .table-responsive,
    #content .card-body {
        max-width: 100%;
        overflow-x: auto;
    }

    #content table {
        max-width: none;
    }

    .dataTables_filter input {
        width: 100% !important;
    }

    /* DataTables 2.x: scroll the table area, keep header/pagination in view */
    div.dt-container {
        max-width: 100%;
    }

    div.dt-container div.dt-layout-table,
    div.dt-container div.dt-layout-table > div,
    div.dt-container div.dt-scroll-body {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    div.dt-container table.dataTable {
        min-width: 720px;
    }

    div.dt-container table.dataTable th,
    div.dt-container table.dataTable td {
        font-size: 0.85rem;
        padding: 6px 8px;
    }

    div.dt-container div.dt-layout-row {
        flex-wrap: wrap;
        gap: 6px;
    }

    div.dt-container div.dt-layout-cell {
        max-width: 100%;
    }

    div.dt-container div.dt-search input {
        width: 100% !important;
        margin-left: 0;
    }

    div.dt-container div.dt-paging ul.pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .dataTables_info {
        padding-left: 0;
    }

    /* Filters / page headers: let flex rows wrap and make inline-fixed widths fluid */
    #content .d-flex {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    #content .d-flex.justify-content-between {
        gap: 8px;
    }

    #content .d-flex > .form-select,
    #content .d-flex > .form-control,
    #content .d-flex > .input-group,
    #content .d-flex > .input-group.date {
        width: auto !important;
        flex: 1 1 140px;
        min-width: 0;
        max-width: 100%;
    }

    #content .d-flex > label.form-label {
        width: auto !important;
        flex: 0 0 auto;
        margin-top: 0 !important;
        align-self: center;
    }

    #content .d-flex > .me-3 {
        margin-right: 0.5rem !important;
    }

    #content .d-flex > [style*="width"]:not(.form-select):not(.form-control):not(.input-group):not(label) {
        max-width: 100%;
    }

    #content header.page-header,
    #content .page-header .d-flex {
        width: 100%;
    }

    #content .btn-group {
        flex-wrap: wrap;
    }

    /* Fixed-width widgets */
    .modal-dialog {
        width: auto !important;
        max-width: calc(100% - 1rem) !important;
        margin: 0.5rem auto;
    }

    .modal-dialog-confirm {
        width: auto !important;
    }

    #notification {
        width: 90%;
        left: 5%;
        margin-left: 0;
    }

    .container-center,
    .box-white {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    img, canvas {
        max-width: 100%;
    }

    .add-center-bottom-button {
        height: 56px;
        width: 56px;
        font-size: 2.2rem;
        right: 12px;
        bottom: 12px;
    }
}

/* ---------- Phones ---------- */
@media (max-width: 575.98px) {
    #content .d-flex > .form-select,
    #content .d-flex > .form-control,
    #content .d-flex > .input-group {
        flex-basis: 100%;
    }

    #content .d-flex > .input-group.date {
        flex-basis: 40%;
    }

    .navbar .logo-dashboard {
        width: 70px;
    }

    .navbar .acc-btn .text-thin-grey {
        display: none;
    }

    .navbar .input-group.w-25 {
        flex-basis: 100%;
        order: 5;
    }

    #content,
    #content[style] {
        padding-top: 120px;
    }

    #sidebar .sidebar-component {
        margin-top: 115px;
    }

    .btn {
        font-size: 0.9rem;
    }

    .selected-items-info {
        right: 8px;
        bottom: 8px;
        padding: 6px 12px;
    }

    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        float: none;
    }

    .dataTables_wrapper .row > div {
        text-align: center;
    }
}
