/*
 * Accounting Responsive Tables Fix
 * Version 1.0.0
 */

/* ---------- Global container protection ---------- */
.accounting-card,
.accounting-section,
.payroll-section,
.employees-section,
.accounting-dashboard,
.accounting-container,
.accounting-plugin,
[class*="accounting"] {
    box-sizing: border-box;
    max-width: 100%;
}

.accounting-card *,
.accounting-section *,
.payroll-section *,
.employees-section *,
.accounting-dashboard *,
.accounting-container *,
.accounting-plugin *,
[class*="accounting"] * {
    box-sizing: border-box;
}

/* Do not allow normal words/headings to break into individual letters */
.artf-responsive-table th,
.artf-responsive-table td {
    word-break: normal !important;
    overflow-wrap: normal !important;
    hyphens: none !important;
}

/* Keep numeric/accounting values readable */
.artf-responsive-table .artf-money,
.artf-responsive-table [data-label="Basic"],
.artf-responsive-table [data-label="Allowances"],
.artf-responsive-table [data-label="Gross"],
.artf-responsive-table [data-label="SSNIT"],
.artf-responsive-table [data-label="PAYE"],
.artf-responsive-table [data-label="Net"] {
    white-space: nowrap !important;
}

/* ---------- Desktop ---------- */
.artf-responsive-table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse !important;
    table-layout: auto !important;
}

.artf-responsive-table th,
.artf-responsive-table td {
    padding: 12px 10px !important;
    vertical-align: middle !important;
    text-align: left !important;
    line-height: 1.35 !important;
}

.artf-responsive-table th {
    font-weight: 700 !important;
    white-space: normal !important;
}

.artf-responsive-table .artf-actions {
    white-space: nowrap !important;
}

.artf-responsive-table .artf-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.artf-responsive-table .artf-action-buttons button,
.artf-responsive-table .artf-action-buttons a {
    width: 100%;
    min-width: 90px;
}

/* If a table genuinely needs more room on desktop/tablet, scroll the wrapper,
   rather than letting the table escape the main card. */
.artf-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
    .artf-responsive-table th,
    .artf-responsive-table td {
        padding: 10px 8px !important;
        font-size: 14px !important;
    }

    .artf-responsive-table {
        table-layout: auto !important;
    }

    .artf-responsive-table th,
    .artf-responsive-table td {
        min-width: 70px;
    }

    .artf-responsive-table th:first-child,
    .artf-responsive-table td:first-child {
        min-width: 120px;
    }

    .artf-responsive-table th:last-child,
    .artf-responsive-table td:last-child {
        min-width: 100px;
    }
}

/* ---------- Mobile card layout ---------- */
@media (max-width: 767px) {
    .artf-table-wrap {
        overflow-x: visible !important;
    }

    .artf-responsive-table,
    .artf-responsive-table thead,
    .artf-responsive-table tbody,
    .artf-responsive-table tr {
        display: block !important;
        width: 100% !important;
    }

    .artf-responsive-table thead {
        display: none !important;
    }

    .artf-responsive-table tbody tr {
        margin: 0 0 15px 0 !important;
        padding: 13px 14px !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px !important;
        background: #fff !important;
        box-shadow: 0 2px 8px rgba(0,0,0,.04) !important;
    }

    .artf-responsive-table tbody td {
        display: flex !important;
        align-items: flex-start !important;
        justify-content: space-between !important;
        gap: 14px !important;
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 8px 0 !important;
        border: 0 !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
        text-align: right !important;
        word-break: normal !important;
        overflow-wrap: anywhere !important;
    }

    .artf-responsive-table tbody td::before {
        content: attr(data-label);
        flex: 0 0 40%;
        max-width: 40%;
        font-weight: 700;
        color: #374151;
        text-align: left;
        white-space: normal;
        word-break: normal !important;
        overflow-wrap: normal !important;
    }

    .artf-responsive-table tbody td > * {
        min-width: 0;
        max-width: 60%;
    }

    /* Employee name gets a card title treatment */
    .artf-responsive-table tbody td.artf-employee-name {
        display: block !important;
        padding: 0 0 11px 0 !important;
        margin-bottom: 3px !important;
        border-bottom: 1px solid #eeeeee !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        text-align: left !important;
    }

    .artf-responsive-table tbody td.artf-employee-name::before {
        display: none !important;
    }

    /* Actions get their own bottom row */
    .artf-responsive-table tbody td.artf-actions {
        display: block !important;
        padding-top: 12px !important;
        margin-top: 4px !important;
        border-top: 1px solid #eeeeee !important;
        text-align: left !important;
    }

    .artf-responsive-table tbody td.artf-actions::before {
        display: none !important;
    }

    .artf-responsive-table .artf-action-buttons {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        gap: 8px !important;
    }

    .artf-responsive-table .artf-action-buttons button,
    .artf-responsive-table .artf-action-buttons a {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        width: auto !important;
        white-space: normal !important;
        text-align: center !important;
    }

    /* Payroll dates remain compact */
    .artf-responsive-table tbody td.artf-period {
        white-space: nowrap !important;
    }

    /* Status should not split character-by-character */
    .artf-responsive-table tbody td.artf-status {
        white-space: nowrap !important;
    }
}

/* ---------- Very small phones ---------- */
@media (max-width: 400px) {
    .artf-responsive-table tbody tr {
        padding: 11px 12px !important;
    }

    .artf-responsive-table tbody td {
        font-size: 13px !important;
        gap: 9px !important;
    }

    .artf-responsive-table tbody td::before {
        flex-basis: 42%;
        max-width: 42%;
    }

    .artf-responsive-table tbody td > * {
        max-width: 58%;
    }

    .artf-responsive-table .artf-action-buttons button,
    .artf-responsive-table .artf-action-buttons a {
        font-size: 12px !important;
        padding: 9px 5px !important;
    }
}

/* ---------- Protection against common parent overflow ---------- */
@media (max-width: 767px) {
    .accounting-card,
    .accounting-section,
    .payroll-section,
    .employees-section,
    .accounting-dashboard,
    .accounting-container,
    .accounting-plugin,
    [class*="accounting"] {
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }
}
