/* ==========================================================
   Mobile card view for all Index list pages (table#DT_load)
   - Desktop (>= 768px): unchanged, normal DataTable
   - Mobile  (<  768px): each row becomes a card
   Data labels / title / action classes are added by
   /js/Export/ExportExcel.js
   ========================================================== */

@media (max-width: 767.98px) {

    /* Page container */
    .backgroundWhite {
        padding: 12px !important;
        border-radius: 8px;
        margin-bottom: 16px;
    }

    .backgroundWhite h2 {
        font-size: 1.25rem;
        word-break: break-word;
    }

    /* Title + "Create New" buttons: stack and go full width */
    .backgroundWhite > .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
        text-align: left !important;
        margin-bottom: 8px;
    }

    .backgroundWhite > .row > [class*="col-"] .btn {
        margin: 0 6px 6px 0;
    }

    /* Duplicate navbar that some pages render inside <main> */
    main > nav.navbar {
        display: none !important;
    }

    /* ---------- DataTables controls ---------- */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        width: 100%;
        margin: 6px 0;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin: 4px 0 0 0 !important;
        min-height: 38px;
        box-sizing: border-box;
    }

    .dataTables_wrapper .dt-buttons {
        float: none !important;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin: 6px 0;
    }

    .dataTables_wrapper .dt-buttons .dt-button {
        flex: 1 1 auto;
        margin: 0 !important;
    }

    .dataTables_wrapper .dataTables_paginate {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* ---------- Table -> cards ---------- */
    .dataTables_wrapper,
    .dataTables_wrapper .dataTables_scroll {
        overflow: visible !important;
    }

    table#DT_load,
    table#DT_load tbody,
    table#DT_load tfoot,
    table#DT_load tr,
    table#DT_load td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important; /* DataTables css uses content-box */
        white-space: normal !important;
    }

    table#DT_load {
        border: 0 !important;
        background: transparent;
        overflow: visible !important;
        margin: 0 !important;
    }

    table#DT_load thead {
        display: none !important;
    }

    table#DT_load tbody tr,
    table#DT_load tfoot tr {
        display: flex;
        flex-direction: column;
        background: #fff !important;
        border: 1px solid #dee2e6;
        border-radius: 10px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
        margin: 0 0 12px 0;
        overflow: hidden;
    }

    /* Same look as the Details page: label (dt) on top, value (dd) below */
    table#DT_load td {
        padding: 8px 14px !important;
        border: 0 !important;
        border-bottom: 1px solid #f0f0f0 !important;
        text-align: left !important;
        word-break: break-word;
        background: transparent !important;
    }

    table#DT_load td::before {
        content: attr(data-label);
        display: block;
        font-weight: 700;
        font-size: .85rem;
        color: #212529;
        margin-bottom: 2px;
    }

    /* Long text (Description, Remark ...) is clipped to 3 lines; tap to expand */
    table#DT_load td .dt-val {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        color: #495057;
    }

    table#DT_load td.dt-expanded .dt-val {
        -webkit-line-clamp: unset;
        display: block;
    }

    /* Card title = first data column */
    table#DT_load td.dt-card-title {
        order: -1;
        background: #e7f1ff !important;
        color: #0d6efd;
        border-bottom: 1px solid #cfe2ff !important;
    }

    table#DT_load td.dt-card-title::before {
        color: #0d6efd;
    }

    table#DT_load td.dt-card-title .dt-val {
        color: #0d6efd;
        font-weight: 700;
        font-size: 1.05rem;
    }

    /* Empty values are hidden to keep cards short */
    table#DT_load td.dt-empty {
        display: none;
    }

    /* Action buttons (Edit / Details ...) at the bottom of the card */
    table#DT_load td.dt-card-actions {
        order: 99;
        display: flex;
        gap: 8px;
        padding: 10px 14px !important;
        border-bottom: 0 !important;
        background: #f8f9fa !important;
    }

    table#DT_load td.dt-card-actions::before {
        display: none;
    }

    table#DT_load td.dt-card-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        margin: 0 !important;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Totals row (tfoot) */
    table#DT_load tfoot tr {
        border-color: #0d6efd;
    }

    /* "No data" row */
    table#DT_load td.dataTables_empty {
        text-align: center !important;
    }

    table#DT_load td.dataTables_empty::before {
        display: none;
    }

}

/* ==========================================================
   Menu pages (Module / SubModule / Control / SubControl index)
   ========================================================== */
@media (max-width: 767.98px) {

    /* Footer was position:absolute and covered the last row of icons */
    .footer {
        position: static !important;
        width: 100%;
        margin-top: 16px;
        line-height: 1.5 !important;
        padding: 12px 0;
        white-space: normal !important;
    }

    body {
        margin-bottom: 0 !important;
    }

    /* Titles above the icons: less empty space on a phone */
    main h1[style*="margin-top"],
    main h2[style*="margin-top"],
    main h3[style*="margin-top"],
    main h4[style*="margin-top"] {
        margin-top: 8px !important;
        padding: 0 8px;
    }

    main h1[style*="margin-top"] {
        margin-top: 24px !important;
        font-size: 1.6rem;
    }

    main h2[style*="margin-top"] { font-size: 1.3rem; }
    main h3[style*="margin-top"] { font-size: 1.15rem; }
    main h4[style*="margin-top"] { font-size: 1.05rem; }

    /* Icon grid: 3 per row, each icon as a tappable tile */
    .menu-grid {
        margin: 0 !important;
        padding: 8px 6px 24px;
        --bs-gutter-x: 8px;
    }

    .menu-grid .menu-item {
        margin-top: 8px !important;
        margin-bottom: 4px;
        padding: 0 4px;
    }

    .menu-grid .menu-item > a {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 12px 4px 8px;
        border-radius: 12px 12px 0 0;
        background: rgba(255, 255, 255, .10);
    }

    .menu-grid .menu-item > a img {
        max-width: 100%;
        width: 50px;
        height: 50px;
    }

    .menu-grid .menu-item > p {
        margin: 0 !important;
        padding: 4px 4px 10px;
        min-height: 54px;
        border-radius: 0 0 12px 12px;
        background: rgba(255, 255, 255, .10);
        font-size: .78rem;
        line-height: 1.25;
        word-break: break-word;
    }
}

/* Tablet / desktop with narrower table: allow horizontal scroll */
@media (min-width: 768px) {
    .dataTables_wrapper {
        overflow-x: auto;
    }
}
