/* ===== Phone card tables (public/js/mobile-tables.js adds .m-cards + data-label) =====
   Every main-page data table becomes a stack of soft cards on phones: title on top,
   "LABEL  value" rows, and the action buttons in a row at the bottom. Desktop is untouched. */
@media (max-width: 767.98px) {
    body .table-responsive:has(> table.m-cards) { overflow: visible !important; border: 0 !important; box-shadow: none !important; background: transparent !important; }
    body table.m-cards.m-cards { min-width: 0 !important; width: 100% !important; border: 0 !important; background: transparent !important; margin: 0 !important; }
    body table.m-cards.m-cards thead { display: none !important; }
    body table.m-cards.m-cards, body table.m-cards.m-cards tbody { display: block !important; }

    body table.m-cards.m-cards tbody tr {
        display: block !important; position: relative; margin: 0 0 12px; padding: 12px 14px 10px;
        background: #fff !important; border: 1px solid #ece8f7 !important; border-radius: 18px;
        box-shadow: 0 12px 26px -22px rgba(49, 46, 129, .55);
    }

    /* value rows: label column + value column (several values stack neatly) */
    body table.m-cards.m-cards tbody td {
        display: grid !important; grid-template-columns: minmax(86px, 36%) minmax(0, 1fr); column-gap: 12px; row-gap: 4px;
        align-items: center; justify-items: end; text-align: right;
        padding: 8px 0 !important; border: 0 !important; border-bottom: 1px dashed #f0edf8 !important;
        white-space: normal !important; background: transparent !important; width: auto !important; min-width: 0; max-width: none !important;
    }
    body table.m-cards.m-cards tbody td:last-child { border-bottom: 0 !important; }
    body table.m-cards.m-cards tbody td::before {
        content: attr(data-label); grid-column: 1; grid-row: 1; align-self: center; justify-self: start; text-align: left;
        font-size: .68rem; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: #8a84a8;
    }
    body table.m-cards.m-cards tbody td > * { grid-column: 2; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
    body table.m-cards.m-cards tbody td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
    body table.m-cards.m-cards tbody td[data-label=""]::before { display: none; }
    body table.m-cards.m-cards tbody td[data-label=""] > * { grid-column: 1; }
    body table.m-cards.m-cards tbody td .text-truncate { white-space: normal !important; max-width: 100% !important; }
    body table.m-cards.m-cards tbody td .badge { white-space: normal; text-align: left; }
    body table.m-cards.m-cards tbody td .d-flex { flex-wrap: wrap; justify-content: flex-end; }

    /* first column = card title */
    body table.m-cards.m-cards tbody td:first-child:not(.mc-index):not(.mc-check),
    body table.m-cards.m-cards tbody td.mc-index + td:not(.mc-check),
    body table.m-cards.m-cards tbody td.mc-check + td {
        display: flex !important; flex-direction: column; align-items: flex-start; justify-content: flex-start;
        text-align: left; font-size: .95rem; padding: 2px 30px 10px 0 !important;
    }
    body table.m-cards.m-cards tbody td:first-child:not(.mc-index):not(.mc-check)::before,
    body table.m-cards.m-cards tbody td.mc-index + td:not(.mc-check)::before,
    body table.m-cards.m-cards tbody td.mc-check + td::before { display: none; }
    body table.m-cards.m-cards tbody td:first-child .d-flex,
    body table.m-cards.m-cards tbody td.mc-index + td .d-flex,
    body table.m-cards.m-cards tbody td.mc-check + td .d-flex { justify-content: flex-start; }

    body table.m-cards.m-cards tbody td.mc-index { display: none !important; }
    body table.m-cards.m-cards tbody td.mc-check { display: block !important; position: absolute; top: 10px; right: 12px; border: 0 !important; padding: 0 !important; }
    body table.m-cards.m-cards tbody td.mc-check::before { display: none; }
    body table.m-cards.m-cards tbody td.mc-check input { width: 22px; height: 22px; }

    /* action buttons row */
    body table.m-cards.m-cards tbody td.mc-actions {
        display: flex !important; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 6px;
        margin-top: 4px; padding: 10px 0 2px !important; border-top: 1px solid #f0edf8 !important; border-bottom: 0 !important; text-align: left;
    }
    body table.m-cards.m-cards tbody td.mc-actions::before { display: none; }
    body table.m-cards.m-cards tbody td.mc-actions > * { max-width: 100%; }
    body table.m-cards.m-cards tbody td.mc-actions .d-flex, body table.m-cards.m-cards tbody td.mc-actions .btn-group { flex-wrap: wrap; justify-content: flex-start; gap: 6px; }
    body table.m-cards.m-cards tbody td.mc-actions .btn, body table.m-cards.m-cards tbody td.mc-actions > a { min-height: 36px; }

    /* "no records" row */
    body table.m-cards.m-cards tbody tr.mc-empty td { display: block !important; text-align: center; }
    body table.m-cards.m-cards tbody tr.mc-empty td::before { display: none; }

    body table.m-cards.m-cards tfoot { display: block; }
    body table.m-cards.m-cards tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; background: #f8f7fd; border-radius: 14px; padding: 8px 12px; }
    body table.m-cards.m-cards tfoot td, body table.m-cards.m-cards tfoot th { border: 0 !important; padding: 4px !important; }
}
