/* ================= FINANCIAL TABLE MOBILE VIEW ================= */

@media (max-width: 768px) {

    .financial-table tbody tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid #ddd;
        border-radius: 6px;
        overflow: hidden;
    }

    .financial-table tbody td {
        display: block;
        width: 100%;
        text-align: left;
        padding: 8px 12px;
        border: none;
    }

        .financial-table tbody td:first-child {
            background: #f8f9fa;
            font-weight: bold;
            border-bottom: 1px solid #eee;
        }
}


/* ================= TABLE RESPONSIVE CONTROL ================= */

@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        overflow-y: hidden;
    }
}

@media (min-width: 769px) {
    .table-responsive {
        overflow-x: visible;
    }
}


/* ================= RESPONSIVE IMAGES ================= */

@media (max-width: 768px) {
    .responsive-img {
        max-width: 80px;
        max-height: 80px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .responsive-img {
        max-width: 100px;
        max-height: 100px;
    }
}

@media (min-width: 1025px) {
    .responsive-img {
        max-width: 150px;
        max-height: 150px;
    }

    #loginsection {
        margin-right: 200px;
        padding-left: 0px;
    }
}


/* ================= ERP TABLE LAYOUT ================= */

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

    /* headers */
    table th {
        border: 1px solid #dee2e6;
        padding: 4px 6px;
        
        text-align: center;
        font-weight: 600;
        width: 1%;
    }

    /* cells */
    table td {
        border: 1px solid #dee2e6;
        padding: 4px 6px;
        white-space: normal;
        word-break: break-word;
    }

/* smaller tables */
.table {
    margin-bottom: 5px;
}


/* ================= MOBILE TABLE OPTIMIZATION ================= */

@media (max-width:768px) {

    table th,
    table td {
        padding: 3px 4px;
        font-size: 12px;
    }

        table td img {
            max-width: 40px;
        }

    .table .btn {
        padding: 2px 5px;
        font-size: 11px;
    }
}


 /* ================= TABLE TEXT CLAMP (OPT-IN) ================= */
.clamped {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* limit to 2 lines */
    line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4em;
    max-height: 2.8em;
    cursor: pointer;
}

.clamped.expanded {
    -webkit-line-clamp: unset;
    line-clamp: unset;
    max-height: none;
}

/* ================= MOBILE DENSITY OVERRIDES ================= */
@media (max-width: 768px) {
    /* Extreme padding reduction to use every possible pixel */
    #main,
    .section,
    .pagetitle,
    header {
        padding: 0px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .card {
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
    }

    .card-body {
        padding: 4px 0px !important;
    }

    .card-title {
        padding: 5px 4px !important;
        font-size: 15px !important;
    }

    /* Ultra-tight tables for mobile */
    .table-sm th,
    .table-sm td {
        padding: 2px 3px !important;
        font-size: 12px !important;
        white-space: normal;
    }

    /* Force the '#' column (first child) to be as narrow as the content */
    table th:first-child,
    table td:first-child {
        width: 1% !important;
        white-space: nowrap !important;
        padding-left: 2px !important;
        padding-right: 2px !important;
        text-align: center;
    }

    /* Table layout auto helps keep columns tight */
    table {
        table-layout: auto !important;
    }

    /* Wrap headers to keep them narrow */
    table th {
        white-space: normal !important;
        line-height: 1.1;
        vertical-align: middle;
    }

    /* Safer Clamping: Target an inner wrapper to protect table structure */
    table td .cell-content,
    table th .cell-content {
        display: -webkit-box;
        -webkit-line-clamp: 2; /* limit to 2 lines */
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        max-height: 2.8em;
        line-height: 1.4em;
    }

    /* Expanded State for the wrapper */
    table td.expanded .cell-content,
    table th.expanded .cell-content {
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
        max-height: none !important;
        overflow: visible !important;
        display: block !important;
    }

    /* Ensure td/th itself stays relative and clickable */
    table td, table th {
        cursor: pointer;
        position: relative;
    }

    /* ================= RESPONSIVE CARD TABLE ================= */
    /* Use this class for tables that still scroll horizontally after tightening */
    .responsive-card-table tbody tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid #dee2e6;
        border-radius: 4px;
        background: #fff;
    }

    .responsive-card-table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 8px 10px !important;
        border: none;
        border-bottom: 1px solid #f6f9ff;
    }

    .responsive-card-table tbody td:last-child {
        border-bottom: none;
    }

    /* Injection of header labels */
    .responsive-card-table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        margin-right: 15px;
        color: #4154f1;
        text-align: left;
    }

    .responsive-card-table thead {
        display: none;
    }
}


#table-id th:first-child,
#table-id td:first-child {
    width: 1%;
    white-space: nowrap;
    text-align: center;
}