/**
 * CBMS Custom Styles
 * Conforms to PROJECT_RULES.md (Section 23 - Responsive table-to-card)
 */

/* Responsive table-to-card on mobile screens (< 768px) */
@media (max-width: 767.98px) {
    .table-responsive-card thead,
    .table-responsive > .table:not(.table-keep) thead {
        display: none;
    }
    .table-responsive-card, 
    .table-responsive-card tbody, 
    .table-responsive-card tr, 
    .table-responsive-card td,
    .table-responsive > .table:not(.table-keep),
    .table-responsive > .table:not(.table-keep) tbody,
    .table-responsive > .table:not(.table-keep) tr,
    .table-responsive > .table:not(.table-keep) td {
        display: block;
        width: 100%;
    }
    .table-responsive-card tr,
    .table-responsive > .table:not(.table-keep) tr {
        margin-bottom: 0.85rem;
        background-color: #fff;
        border: 1px solid rgba(0,0,0,.125);
        border-radius: .35rem;
        padding: .5rem .75rem;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }
    .table-responsive-card td,
    .table-responsive > .table:not(.table-keep) td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: .4rem 0;
        border-top: 1px solid #f0f0f0;
        text-align: right;
    }
    .table-responsive-card td:first-child,
    .table-responsive > .table:not(.table-keep) td:first-child {
        border-top: none;
    }
    .table-responsive-card td::before,
    .table-responsive > .table:not(.table-keep) td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        text-align: left;
        margin-right: 1rem;
        white-space: nowrap;
    }
}

/* Loading state and spinner */
.cbms-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    z-index: 1050;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: inherit;
}

/* Empty state container */
.cbms-empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    color: #6c757d;
}
.cbms-empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #adb5bd;
}

/* Status badges */
.badge-status-active { background-color: #28a745; color: #fff; }
.badge-status-inactive { background-color: #6c757d; color: #fff; }
.badge-status-unpaid { background-color: #dc3545; color: #fff; }
.badge-status-partial { background-color: #ffc107; color: #212529; }
.badge-status-paid { background-color: #28a745; color: #fff; }
.badge-status-void { background-color: #343a40; color: #fff; }

/* Financial number alignment */
.text-money {
    font-family: 'SFMono-Regular', Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-weight: 600;
}

/* Sidebar navigation integrity */
.main-sidebar .brand-link {
    display: flex !important;
    align-items: center;
    color: rgba(255, 255, 255, 0.85) !important;
    text-decoration: none !important;
}
.main-sidebar .brand-link:hover {
    color: #fff !important;
}
.main-sidebar .user-panel a {
    color: rgba(255, 255, 255, 0.9) !important;
    text-decoration: none !important;
}
.main-sidebar .nav-sidebar .nav-link {
    text-decoration: none !important;
}

/* Sidebar Sub-menu Hierarchy & Indentation (Jangan Sejajar dengan Menu Utama) */
.main-sidebar .nav-sidebar .nav-treeview {
    display: none;
    list-style: none;
    padding: 4px 0 4px 0.75rem !important;
    margin: 3px 0 6px 0.5rem !important;
    background-color: rgba(0, 0, 0, 0.22) !important;
    border-radius: 0.35rem;
    border-left: 2px solid rgba(255, 255, 255, 0.15) !important;
}

.main-sidebar .nav-sidebar .menu-open > .nav-treeview {
    display: block !important;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-item {
    margin-bottom: 2px;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-link {
    padding-left: 0.75rem !important;
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
    font-size: 0.84rem;
    border-radius: 0.25rem;
    color: #c2c7d0;
    transition: all 0.15s ease-in-out;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    padding-left: 0.9rem !important;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-link.active {
    background-color: #f8f9fa !important;
    color: #1f2d3d !important;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    padding-left: 0.85rem !important;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-link .nav-icon {
    font-size: 0.75rem !important;
    width: 1.25rem !important;
    margin-right: 0.45rem !important;
    opacity: 0.8;
}

.main-sidebar .nav-sidebar .nav-treeview .nav-link.active .nav-icon {
    opacity: 1;
    color: #007bff !important;
}

.sidebar-collapse .main-sidebar .nav-sidebar .nav-treeview {
    border-left: none !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* Smart Centang & Row Selection (Menu Tagihan / Invoices) */
.invoice-row {
    transition: background-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    cursor: pointer;
}
.invoice-row:hover {
    background-color: rgba(0, 123, 255, 0.04) !important;
}
.invoice-row.table-row-selected {
    background-color: #e8f4fd !important;
    box-shadow: inset 4px 0 0 #007bff;
}
.invoice-row.table-row-selected td {
    background-color: transparent !important;
}

/* Responsive Table-to-Card on Mobile (< 768px) */
@media (max-width: 767.98px) {
    #table-invoices {
        border: none !important;
        background: transparent !important;
    }
    #table-invoices thead {
        display: none !important;
    }
    #table-invoices,
    #table-invoices tbody,
    #table-invoices tbody tr,
    #table-invoices tbody td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    #table-invoices tbody tr.invoice-row {
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 10px !important;
        margin-bottom: 14px !important;
        padding: 12px 14px !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05) !important;
        position: relative !important;
        transition: all 0.2s ease-in-out !important;
    }
    #table-invoices tbody tr.invoice-row.table-row-selected {
        background-color: #f0f7ff !important;
        border-color: #3b82f6 !important;
        box-shadow: 0 0 0 1px #3b82f6, 0 4px 6px rgba(59, 130, 246, 0.1) !important;
    }
    #table-invoices tbody td {
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        padding: 8px 0 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        text-align: right !important;
        min-height: 34px !important;
    }
    #table-invoices tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.78rem;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        text-align: left !important;
        margin-right: 12px;
        flex-shrink: 0;
    }
    #table-invoices tbody td.td-check {
        border-bottom: 1px dashed #cbd5e1 !important;
        padding-bottom: 10px !important;
        margin-bottom: 4px !important;
        justify-content: flex-start !important;
    }
    #table-invoices tbody td.td-check input[type="checkbox"] {
        width: 18px;
        height: 18px;
        margin-right: 8px;
        cursor: pointer;
    }
    #table-invoices tbody td.td-balance {
        font-size: 1.05rem !important;
    }
    #table-invoices tbody td.td-actions {
        border-bottom: none !important;
        padding-top: 10px !important;
        margin-top: 6px !important;
        border-top: 1px solid #e2e8f0 !important;
        justify-content: flex-end !important;
    }
    #table-invoices tbody td.td-actions .btn-group {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
        gap: 4px !important;
    }
    #table-invoices tbody td.td-actions .btn {
        padding: 0.35rem 0.65rem !important;
        font-size: 0.85rem !important;
    }
}

/* Bulletproof Table Customers Action Column */
#table-customers th:last-child,
#table-customers td:last-child {
    width: 185px !important;
    min-width: 185px !important;
    white-space: nowrap !important;
    text-align: center !important;
}

#table-customers td:last-child .d-inline-flex {
    display: inline-flex !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
}

#table-customers td:last-child .btn {
    flex-shrink: 0 !important;
}

/* Bulletproof Users Table Action Column */
#usersTable th:last-child,
#usersTable td:last-child {
    width: 150px !important;
    min-width: 150px !important;
    white-space: nowrap !important;
    text-align: center !important;
}

#usersTable td:last-child .d-inline-flex {
    display: inline-flex !important;
    flex-wrap: nowrap !important;
    white-space: nowrap !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
}

#usersTable td:last-child .btn {
    flex-shrink: 0 !important;
}

/* ==========================================================================
   GLOBAL SELECT2 BOOTSTRAP 4 THEME ENHANCEMENTS
   Conforms Select2 to standard Bootstrap 4 / AdminLTE form controls globally.
   ========================================================================== */

.select2-container--bootstrap4 .select2-selection--single,
.select2-container--default .select2-selection--single,
.select2-container .select2-selection--single {
    display: block !important;
    height: calc(2.25rem + 2px) !important;
    padding: .375rem .75rem !important;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff !important;
    border: 1px solid #ced4da !important;
    border-radius: .25rem !important;
    box-sizing: border-box !important;
    position: relative;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

.text-sm .select2-container--bootstrap4 .select2-selection--single,
.text-sm .select2-container--default .select2-selection--single,
.text-sm .select2-container .select2-selection--single {
    height: calc(1.8125rem + 2px) !important;
    padding: .25rem .5rem !important;
    font-size: .875rem !important;
    line-height: 1.5;
}

.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered,
.select2-container--default .select2-selection--single .select2-selection__rendered,
.select2-container .select2-selection--single .select2-selection__rendered {
    padding-left: 0 !important;
    padding-right: 20px !important;
    line-height: 1.5 !important;
    color: #495057 !important;
}

.select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder,
.select2-container--default .select2-selection--single .select2-selection__placeholder,
.select2-container .select2-selection--single .select2-selection__placeholder {
    color: #6c757d !important;
    line-height: 1.5 !important;
}

.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow,
.select2-container--default .select2-selection--single .select2-selection__arrow,
.select2-container .select2-selection--single .select2-selection__arrow {
    position: absolute !important;
    top: 50% !important;
    right: 8px !important;
    transform: translateY(-50%);
    width: 20px !important;
    height: 20px !important;
}

.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow b,
.select2-container--default .select2-selection--single .select2-selection__arrow b,
.select2-container .select2-selection--single .select2-selection__arrow b {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    margin-top: -2px !important;
    margin-left: -4px !important;
    border-color: #6c757d transparent transparent transparent !important;
    border-style: solid !important;
    border-width: 5px 4px 0 !important;
    width: 0 !important;
    height: 0 !important;
}

.select2-container--bootstrap4.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container.select2-container--focus .select2-selection--single {
    border-color: #80bdff !important;
    box-shadow: 0 0 0 .2rem rgba(0, 123, 255, .25) !important;
}

.select2-container--bootstrap4.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container.select2-container--disabled .select2-selection--single {
    background-color: #e9ecef !important;
    cursor: not-allowed;
    opacity: 1;
}

/* Invalid State for Select2 */
.select2-container.is-invalid .select2-selection,
select.is-invalid + .select2-container .select2-selection,
.is-invalid + .select2-container--bootstrap4 .select2-selection {
    border-color: #dc3545 !important;
    padding-right: 2.25rem !important;
}

.select2-container.is-invalid.select2-container--focus .select2-selection,
select.is-invalid + .select2-container.select2-container--focus .select2-selection {
    box-shadow: 0 0 0 .2rem rgba(220, 53, 69, .25) !important;
}

/* Select2 Dropdown Styling */
.select2-container--bootstrap4 .select2-dropdown,
.select2-container--default .select2-dropdown {
    border-color: #80bdff !important;
    border-radius: .25rem !important;
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
    z-index: 1060 !important; /* Ensure dropdown appears above Bootstrap modals */
}

.select2-container--bootstrap4 .select2-results__option,
.select2-container--default .select2-results__option {
    padding: .375rem .75rem !important;
    font-size: .875rem;
}

.select2-container--bootstrap4 .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #007bff !important;
    color: #fff !important;
}




