/* ═══════════════════════════════════════
   LAYOUT PRINCIPAL - app.css
══════════════════════════════════════ */

:root {
    color-scheme: light;
    --sidebar-width: 260px;
    --navbar-height: 60px;

    --app-bg: #f1f5f9;
    --app-surface: #ffffff;
    --app-surface-rgb: 255, 255, 255;
    --app-surface-soft: #f8fafc;
    --app-surface-elevated: #ffffff;
    --app-text: #0f172a;
    --app-muted: #64748b;
    --app-border: #e2e8f0;
    --app-border-strong: #cbd5e1;
    --app-primary: #2563eb;
    --app-primary-soft: #dbeafe;
    --app-link: #2563eb;
    --app-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    --app-focus-ring: rgba(37, 99, 235, 0.22);

    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #94a3b8;
    --table-header-bg: var(--sidebar-bg);
    --table-header-border: var(--sidebar-hover);
    --table-striped-bg: #f8fafc;
    --table-selection-bg: #dbeafe;
    --table-selection-color: #0f172a;
}

[data-bs-theme="dark"] {
    color-scheme: dark;
    --bs-body-bg: #0b1120;
    --bs-body-color: #e5e7eb;
    --bs-emphasis-color: #f8fafc;
    --bs-secondary-color: #94a3b8;
    --bs-tertiary-bg: #111827;
    --bs-border-color: #243044;
    --bs-link-color: #93c5fd;
    --bs-link-hover-color: #bfdbfe;

    --app-bg: #0b1120;
    --app-surface: #111827;
    --app-surface-rgb: 17, 24, 39;
    --app-surface-soft: #162033;
    --app-surface-elevated: #172033;
    --app-text: #f1f5f9;
    --app-muted: #b6c2d2;
    --app-border: #243044;
    --app-border-strong: #334155;
    --app-primary: #60a5fa;
    --app-primary-soft: rgba(96, 165, 250, 0.16);
    --app-link: #93c5fd;
    --app-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 18px 50px rgba(0, 0, 0, 0.34), 0 0 28px rgba(255, 255, 255, 0.045);
    --app-focus-ring: rgba(96, 165, 250, 0.28);

    --sidebar-bg: #020617;
    --sidebar-hover: #111827;
    --sidebar-active: #2563eb;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #94a3b8;
    --table-header-bg: #111827;
    --table-header-border: #334155;
    --table-striped-bg: rgba(148, 163, 184, 0.06);
    --table-selection-bg: rgba(96, 165, 250, 0.18);
    --table-selection-color: #e5e7eb;
}

body {
    background-color: var(--app-bg);
    color: var(--app-text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Global tables: sidebar-colored headers + subtle striped rows. */
.table:not(.table-borderless) > thead,
.table:not(.table-borderless) > thead.table-light,
.table:not(.table-borderless) > thead.table-dark,
.table:not(.table-borderless) > thead > tr,
.table:not(.table-borderless) > thead > tr > th,
.table:not(.table-borderless) > thead > tr > td {
    --bs-table-bg: var(--table-header-bg);
    --bs-table-color: #fff;
    background-color: var(--table-header-bg) !important;
    border-color: var(--table-header-border) !important;
    color: #fff !important;
}

.table:not(.table-borderless) > thead > tr > th a,
.table:not(.table-borderless) > thead > tr > td a {
    color: #fff !important;
}

.table:not(.table-borderless) > tbody > tr:nth-of-type(odd) > * {
    --bs-table-bg-type: var(--table-striped-bg);
}


.table > tbody > tr.table-primary,
.table > tbody > tr.table-active,
.table > tbody > tr.selected {
    --bs-table-bg: var(--table-selection-bg) !important;
    --bs-table-striped-bg: var(--table-selection-bg) !important;
    --bs-table-active-bg: var(--table-selection-bg) !important;
    --bs-table-hover-bg: var(--table-selection-bg) !important;
    --bs-table-color: var(--table-selection-color) !important;
    --bs-table-striped-color: var(--table-selection-color) !important;
    --bs-table-active-color: var(--table-selection-color) !important;
    --bs-table-hover-color: var(--table-selection-color) !important;
}

.table > tbody > tr.table-primary > *,
.table > tbody > tr.table-active > *,
.table > tbody > tr.selected > *,
.table.table-hover > tbody > tr.table-primary:hover > *,
.table.table-hover > tbody > tr.table-active:hover > *,
.table.table-hover > tbody > tr.selected:hover > * {
    --bs-table-color-state: var(--table-selection-color) !important;
    --bs-table-color-type: var(--table-selection-color) !important;
    --bs-table-bg-state: var(--table-selection-bg) !important;
    --bs-table-bg-type: var(--table-selection-bg) !important;
    --bs-table-accent-bg: var(--table-selection-bg) !important;
    color: var(--table-selection-color) !important;
    background-color: var(--table-selection-bg) !important;
    box-shadow: inset 0 0 0 9999px var(--table-selection-bg) !important;
}


/* --- Sidebar --- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1000;
    overflow-y: auto;
    /* Ocultar scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#sidebar::-webkit-scrollbar {
    display: none;
}
 
.sidebar-nav {
    padding: 1rem 0;
}

.sidebar-brand {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--sidebar-hover);
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
}

.sidebar-brand i {
    font-size: 1.4rem;
    color: var(--sidebar-active);
    margin-right: 10px;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.sidebar-nav .nav-section {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-muted);
    white-space: nowrap;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    color: var(--sidebar-text);
    border-radius: 0;
    white-space: nowrap;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 24px;
    flex-shrink: 0;
    margin-right: 10px;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: white;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: white;
}

/* ── Navbar ── */
#navbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--navbar-height);
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 999;
    transition: left 0.3s;
}

/* ── Main content ── */
#main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: 1.5rem;
    min-height: calc(100vh - var(--navbar-height));
    transition: margin-left 0.3s;
}

/* --- Responsive mobile menu button --- */
.mobile-menu-btn { display: none; }

/* Navbar responsive */
@media (max-width: 768px) {
    .mobile-menu-btn { display: block !important; }

    #navbar {
        padding: 0.5rem 1rem !important;
    }

    #navbar .badge {
        font-size: 0.65rem !important;
        padding: 0.2rem 0.4rem !important;
    }

    #navbar .btn-sm {
        font-size: 0.75rem !important;
        padding: 0.25rem 0.5rem !important;
    }

    #sidebar { 
        width: 0; 
        z-index: 9999;
    }
    #sidebar.open { 
        width: var(--sidebar-width); 
        height: 100vh;
    }
    
    #navbar  { left: 0; }
    #main-content { margin-left: 0; }
    
    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
    }

    #navbar > button {
        display: block !important;
    }
}
}


/* AJAX search/autocomplete results */
.cliente-results {
    background-color: var(--app-surface) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text);
}
.cliente-results .cliente-option {
    color: var(--app-text);
    transition: background-color .12s ease, color .12s ease;
}
.cliente-results .cliente-option:hover,
.cliente-results .cliente-option:focus,
.cliente-results .cliente-option.active {
    background-color: rgba(13, 110, 253, .10);
    color: var(--app-text);
}
[data-bs-theme="dark"] .cliente-results {
    background-color: var(--app-surface) !important;
    border-color: var(--app-border-strong) !important;
    box-shadow: 0 16px 36px rgba(0,0,0,.38) !important;
}
[data-bs-theme="dark"] .cliente-results .cliente-option {
    color: var(--app-text);
    border-color: var(--app-border) !important;
}
[data-bs-theme="dark"] .cliente-results .cliente-option:hover,
[data-bs-theme="dark"] .cliente-results .cliente-option:focus,
[data-bs-theme="dark"] .cliente-results .cliente-option.active {
    background-color: var(--app-surface-soft) !important;
    color: #f8fafc !important;
}

/* ── Select2 overrides ── */
.select2-container--bootstrap5 {
    width: 100% !important;
}
.select2-container--bootstrap5 .select2-selection {
    min-height: calc(1.5em + 0.75rem + 2px);
    padding: 0.375rem 2.25rem 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.375rem;
    border: 1px solid #dee2e6;
    display: flex;
    align-items: center;
}
.select2-container--bootstrap5 .select2-selection__rendered {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.select2-container--bootstrap5.select2-container--focus .select2-selection {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* ── Context menu ── */
.ctx-item {
    display: block;
    width: 100%;
    padding: 0.25rem 1rem;
    clear: both;
    font-weight: 400;
    color: #212529;
    text-align: inherit;
    text-decoration: none;
    white-space: nowrap;
    background-color: transparent;
    border: 0;
    cursor: pointer;
}
.ctx-item:hover, .ctx-item:focus {
    color: #1e2128;
    background-color: #e9ecef;
}

/* ── Collapse icon ── */
.collapse-icon { transition: transform 0.2s ease; }
.collapse-icon.collapsed { transform: rotate(-90deg); }

/* ── Card clickable ── */
.card-clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.card-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important; }


/* ── DataTables responsive polish ── */
.table.dataTable {
    width: 100% !important;
    table-layout: fixed;
}

.table.dataTable > tbody > tr > td,
.table.dataTable > thead > tr > th {
    vertical-align: middle;
}

.table.dataTable td.dt-cell-compact,
.table.dataTable th.dt-cell-compact {
    max-width: 240px;
}

.table.dataTable td.dt-cell-compact,
.table.dataTable th.dt-cell-compact {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table.dataTable td.dtr-control,
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    cursor: pointer;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    background-color: #2563eb;
    border: 0;
    box-shadow: none;
    line-height: 1.05rem;
    height: 1.05rem;
    width: 1.05rem;
    margin-top: -0.55rem;
}

table.dataTable > tbody > tr.child ul.dtr-details {
    width: 100%;
}

.dt-child-table td {
    white-space: normal !important;
    word-break: break-word;
}

.dt-child-table .dt-child-value {
    color: #334155;
}

@media (max-width: 1200px) {
    .table.dataTable td.dt-cell-compact,
    .table.dataTable th.dt-cell-compact {
        max-width: 190px;
    }
}

@media (max-width: 768px) {
    .dataTables_wrapper .row {
        row-gap: 0.5rem;
    }

    .table.dataTable td.dt-cell-compact,
    .table.dataTable th.dt-cell-compact {
        max-width: 150px;
    }

    .table.dataTable .btn-group,
    .table.dataTable .d-flex {
        flex-wrap: nowrap;
    }
}


.table-responsive:has(table.dataTable.dtr-inline) {
    overflow-x: visible;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    padding-left: 2rem !important;
}


/* DataTables expand/collapse button: separate visual affordance from row checkbox. */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    content: "+" !important;
    display: inline-grid;
    place-items: center;
    background: #0ea5e9 !important;
    color: #fff;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.85rem;
}

table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th.dtr-control:before {
    content: "−" !important;
    background: #f97316 !important;
}

table.dataTable td.dt-responsive-control-cell {
    cursor: pointer;
}

table.dataTable td:first-child:has(.check-fila),
table.dataTable th:first-child:has(#checkTodos) {
    width: 42px !important;
    max-width: 42px !important;
    text-align: center;
}


/* Final DataTables detail trigger: only this button expands/collapses rows. */
.dt-row-details-toggle {
    width: 1.35rem;
    height: 1.35rem;
    border: 0;
    border-radius: 999px;
    background: #0ea5e9;
    color: #fff;
    display: inline-grid;
    place-items: center;
    font-weight: 900;
    line-height: 1;
    margin-right: 0.45rem;
    vertical-align: middle;
    cursor: pointer;
}

.dt-row-details-toggle::before {
    content: "+";
}

tr.parent .dt-row-details-toggle {
    background: #f97316;
}

tr.parent .dt-row-details-toggle::before {
    content: "−";
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    display: none !important;
    content: none !important;
}

table.dataTable td.dt-responsive-control-cell {
    cursor: default;
}

table.dataTable td.dt-responsive-control-cell .dt-row-details-toggle + * {
    vertical-align: middle;
}


/* Disable DataTables Responsive automatic row/cell toggles; NetFlow uses manual button only. */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before,
table.dataTable > tbody > tr > td.dtr-control:before,
table.dataTable > tbody > tr > th.dtr-control:before {
    display: none !important;
    content: none !important;
}

table.dataTable td.dtr-control,
table.dataTable th.dtr-control {
    cursor: default !important;
}


/* Mobile DataTables: avoid one-letter-per-line headers. */
@media (max-width: 576px) {
    .table.dataTable {
        table-layout: fixed;
        font-size: 0.82rem;
    }

    .table.dataTable > thead > tr > th,
    .table.dataTable > tbody > tr > td {
        padding: 0.45rem 0.4rem;
    }

    .table.dataTable th.dt-cell-compact,
    .table.dataTable td.dt-cell-compact {
        max-width: 105px;
        min-width: 0;
    }

    .table.dataTable th {
        white-space: nowrap !important;
        word-break: normal !important;
        overflow-wrap: normal !important;
    }

    .dt-row-details-toggle {
        width: 1.25rem;
        height: 1.25rem;
        margin-right: 0.25rem;
    }

    table.dataTable td:first-child:has(.check-fila),
    table.dataTable th:first-child:has(#checkTodos) {
        width: 34px !important;
        max-width: 34px !important;
    }
}


/* Phone layout: DataTables as compact list cards, not squeezed spreadsheet. */
@media (max-width: 576px) {
    .dataTables_wrapper table.dataTable,
    .dataTables_wrapper table.dataTable tbody,
    .dataTables_wrapper table.dataTable tr,
    .dataTables_wrapper table.dataTable td {
        display: block;
        width: 100% !important;
    }

    .dataTables_wrapper table.dataTable tbody tr {
        position: relative;
        background: var(--app-surface);
        border: 1px solid var(--app-border);
        border-radius: 0.85rem;
        margin-bottom: 0.75rem;
        padding: 0.55rem 0.65rem 0.65rem 2.5rem;
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
    }

    .dataTables_wrapper table.dataTable tbody tr.child {
        margin-top: -0.65rem;
        padding: 0.25rem 0.65rem 0.65rem 0.65rem;
        border-top: 0;
        box-shadow: none;
    }

    .dataTables_wrapper table.dataTable tbody td {
        border: 0;
        padding: 0.16rem 0;
        max-width: none !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .dataTables_wrapper table.dataTable tbody td:first-child:has(.check-fila) {
        position: absolute;
        left: 0.65rem;
        top: 0.75rem;
        width: auto !important;
        max-width: none !important;
        padding: 0;
    }


    .dataTables_wrapper table.dataTable tbody tr:not(.child) > td.dt-mobile-visible {
        text-align: left !important;
    }

    .dataTables_wrapper table.dataTable tbody td.dt-responsive-control-cell {
        font-weight: 700;
        color: #0f172a;
        padding-right: 0.25rem;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child {
        margin-top: 0.4rem;
        padding-top: 0.45rem;
        border-top: 1px dashed #e2e8f0;
        white-space: normal;
        overflow: visible;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child .btn,
    .dataTables_wrapper table.dataTable tbody td:last-child .dropdown,
    .dataTables_wrapper table.dataTable tbody td:last-child .btn-group {
        margin-top: 0.15rem;
    }

    .dt-child-table td {
        display: table-cell !important;
        width: auto !important;
        padding: 0.18rem 0.25rem !important;
        white-space: normal !important;
    }
}


/* Mobile table overflow + action buttons containment. */
@media (max-width: 576px) {
    html, body {
        max-width: 100%;
        overflow-x: hidden;
    }

    #main-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-bottom: calc(7rem + env(safe-area-inset-bottom, 0px));
        overflow-x: hidden;
    }

    .card,
    .card-body,
    .table-responsive,
    .dataTables_wrapper {
        max-width: 100%;
        overflow-x: hidden !important;
    }

    .dataTables_wrapper table.dataTable tbody tr {
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 0.35rem;
        max-width: 100% !important;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child .btn-group,
    .dataTables_wrapper table.dataTable tbody td:last-child .dropdown,
    .dataTables_wrapper table.dataTable tbody td:last-child .d-flex {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.3rem;
        max-width: 100%;
        min-width: 0;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child .btn,
    .dataTables_wrapper table.dataTable tbody td:last-child .dropdown-toggle,
    .dataTables_wrapper table.dataTable tbody td:last-child a.btn,
    .dataTables_wrapper table.dataTable tbody td:last-child button.btn {
        max-width: 100%;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .dataTables_wrapper table.dataTable tbody td:last-child .dropdown-menu {
        max-width: calc(100vw - 2rem);
    }
}


@media (max-width: 576px) {
    .dataTables_wrapper table.dataTable tbody td:last-child .dropdown-menu {
        z-index: 1060;
    }
}


/* Mobile expanded details must read like normal key/value content, not squeezed table columns. */
@media (max-width: 576px) {
    .dataTables_wrapper table.dataTable tbody tr.child {
        padding-left: 0.65rem;
        padding-right: 0.65rem;
        overflow: visible;
    }

    .dataTables_wrapper table.dataTable tbody tr.child > td {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
    }

    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table,
    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table tbody,
    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table tr,
    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table td {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: normal !important;
        overflow-wrap: anywhere !important;
    }

    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table tr {
        border: 0;
        box-shadow: none;
        margin: 0 0 0.45rem 0;
        padding: 0;
        background: transparent;
    }

    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table td:first-child {
        position: static !important;
        color: var(--sidebar-muted);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        font-weight: 800;
        padding: 0 !important;
    }

    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table .dt-child-value {
        color: #0f172a;
        font-size: 0.9rem;
        line-height: 1.35;
        padding: 0.08rem 0 0 0 !important;
    }

    .dataTables_wrapper table.dataTable tbody tr.child .dt-child-table .dt-child-value * {
        max-width: 100%;
        white-space: normal !important;
        word-break: normal !important;
        overflow-wrap: anywhere !important;
    }
}


/* Detail rows as readable list blocks, avoiding nested-table mobile compression. */
.dt-child-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.65rem 1rem;
    width: 100%;
    max-width: 100%;
}

.dt-child-item {
    min-width: 0;
    padding: 0.55rem 0.65rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.65rem;
    background: #f8fafc;
}

.dt-child-label {
    display: block;
    color: var(--sidebar-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 800;
    margin-bottom: 0.2rem;
}

.dt-child-value {
    display: block;
    color: #0f172a;
    font-size: 0.92rem;
    line-height: 1.35;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
}

.dt-child-value * {
    max-width: 100%;
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
}

@media (max-width: 576px) {
    .dt-child-list {
        display: block;
    }

    .dt-child-item {
        display: block;
        width: 100%;
        margin-bottom: 0.55rem;
        padding: 0.55rem 0.65rem;
    }

    .dataTables_wrapper table.dataTable tbody tr.child,
    .dataTables_wrapper table.dataTable tbody tr.child > td {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        white-space: normal !important;
    }
}


/* Responsive static tables used in show pages. */
@media (max-width: 576px) {
    .table-info-mobile,
    .table-info-mobile tbody,
    .table-info-mobile tr,
    .table-info-mobile td {
        display: block;
        width: 100% !important;
    }

    .table-info-mobile tr {
        padding: 0.55rem 0;
        border-bottom: 1px solid #e2e8f0;
    }

    .table-info-mobile tr:last-child {
        border-bottom: 0;
    }

    .table-info-mobile td {
        border: 0 !important;
        padding: 0.08rem 0 !important;
        text-align: left !important;
        white-space: normal !important;
        word-break: normal !important;
        overflow-wrap: break-word !important;
    }

    .table-info-mobile td:first-child {
        color: #64748b !important;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        font-weight: 800;
    }

    .table-info-mobile td:last-child {
        color: #0f172a;
        line-height: 1.35;
    }

    .table-info-mobile td:last-child .btn,
    .table-info-mobile td:last-child a,
    .table-info-mobile td:last-child code,
    .table-info-mobile td:last-child .badge {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: break-word;
    }

    .table-stack-mobile,
    .table-stack-mobile tbody,
    .table-stack-mobile tr,
    .table-stack-mobile td {
        display: block;
        width: 100% !important;
    }

    .table-stack-mobile tr {
        border: 1px solid #e2e8f0;
        border-radius: 0.75rem;
        padding: 0.65rem;
        margin-bottom: 0.65rem;
        background: #fff;
    }

    .table-stack-mobile td {
        border: 0 !important;
        padding: 0.18rem 0 !important;
        text-align: left !important;
        white-space: normal !important;
        overflow-wrap: break-word !important;
    }

    .table-stack-mobile td[colspan] {
        text-align: center !important;
    }
}


/* Mobile labels for card-style rows. */
@media (max-width: 576px) {
    .dataTables_wrapper table.dataTable tbody tr:not(.child) > td[data-label]::before,
    .table-stack-mobile tbody tr > td[data-label]::before {
        content: attr(data-label);
        display: block;
        color: var(--sidebar-muted);
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        font-weight: 800;
        margin-bottom: 0.08rem;
    }

    .dataTables_wrapper table.dataTable tbody tr:not(.child) > td:first-child:has(.check-fila)::before {
        display: none;
        content: none;
    }

    .table-stack-mobile tbody tr > td[data-label] {
        padding-top: 0.35rem !important;
        padding-bottom: 0.35rem !important;
    }
}


/* Responsive bulk action bars used by index/catalog tables. */
#barraAccionesMasivas .card-body {
    flex-wrap: wrap;
}

#barraAccionesMasivas .dropdown-menu {
    max-width: min(22rem, calc(100vw - 2rem));
    white-space: normal;
}

#barraAccionesMasivas .dropdown-item,
#contextMenuMasivas .dropdown-item,
#contextMenuMasivas .ctx-item {
    white-space: normal;
}

@media (max-width: 576px) {
    #barraAccionesMasivas .card-body {
        align-items: stretch !important;
        gap: 0.65rem !important;
        padding: 0.85rem !important;
    }

    #barraAccionesMasivas .fw-semibold {
        width: 100%;
        line-height: 1.25;
    }

    #barraAccionesMasivas .dropdown,
    #barraAccionesMasivas .dropdown > .btn,
    #barraAccionesMasivas #btnDeseleccionarTodo {
        width: 100%;
    }

    #barraAccionesMasivas #btnDeseleccionarTodo {
        margin-left: 0 !important;
    }

    #barraAccionesMasivas .dropdown-menu {
        width: 100%;
        min-width: 100%;
    }
}







/* DataTables readable cells: visible content should not be cut with ellipsis.
   If there is not enough room, the global responsive wrapper hides columns and
   moves them to the + details instead of clipping the text. */
.table.dataTable td.dt-cell-compact,
.table.dataTable td.dt-client-name-cell,
.table.dataTable td.dt-client-email-cell,
.table.dataTable td.dt-invoice-client-cell,
.table.dataTable td.dt-contract-number-cell {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
}

#tablaFacturas.dataTable td.dt-invoice-client-cell a {
    display: inline;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
}

/* /clientes: compact DataTable columns, aligned with /contratos and /facturas. */
#tablaClientes.dataTable > tbody > tr > td {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    line-height: 1.2;
}

#tablaClientes.dataTable td.dt-client-id-cell,
#tablaClientes.dataTable th.dt-client-id-cell {
    width: 9.5rem;
    min-width: 9.5rem;
    white-space: nowrap !important;
}

#tablaClientes.dataTable td.dt-client-city-cell,
#tablaClientes.dataTable th.dt-client-city-cell {
    width: 8rem;
    min-width: 8rem;
    white-space: nowrap !important;
}

#tablaClientes.dataTable td.dt-client-phone-cell,
#tablaClientes.dataTable th.dt-client-phone-cell {
    width: 7.75rem;
    min-width: 7.75rem;
    white-space: nowrap !important;
}

#tablaClientes.dataTable td.dt-client-status-cell,
#tablaClientes.dataTable th.dt-client-status-cell {
    width: 6.75rem;
    min-width: 6.75rem;
    white-space: nowrap !important;
}

#tablaClientes.dataTable td.dt-client-id-cell,
#tablaClientes.dataTable td.dt-client-city-cell,
#tablaClientes.dataTable td.dt-client-phone-cell,
#tablaClientes.dataTable td.dt-client-status-cell {
    padding-top: 0.22rem;
    padding-bottom: 0.22rem;
}

#tablaClientes.dataTable td.dt-client-status-cell .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.3rem;
    line-height: 1;
    padding: 0.26rem 0.48rem;
    font-size: 0.74rem;
}

#tablaClientes.dataTable td.dt-client-name-cell,
#tablaClientes.dataTable td.dt-client-email-cell {
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 769px) {
    #tablaClientes.dataTable td.dt-client-actions-cell,
    #tablaClientes.dataTable th.dt-client-actions-cell {
        white-space: nowrap !important;
        width: 8.5rem;
        min-width: 8.5rem;
    }

    #tablaClientes.dataTable td.dt-client-actions-cell .d-flex {
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
    }

    #tablaClientes.dataTable td.dt-client-actions-cell form {
        display: inline-flex !important;
        margin: 0;
    }

    #tablaClientes.dataTable td.dt-client-actions-cell .btn {
        width: 1.85rem;
        height: 1.85rem;
        padding: 0;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* /facturas: compact DataTable columns.
   Mirrors /contratos: each visible column gets a scoped class so small badges,
   dates and icon actions do not inherit excessive generic table spacing. */
#tablaFacturas.dataTable > tbody > tr > td {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    line-height: 1.2;
}

#tablaFacturas.dataTable td.dt-invoice-number-cell,
#tablaFacturas.dataTable th.dt-invoice-number-cell {
    width: 9rem;
    min-width: 9rem;
    white-space: nowrap !important;
}

#tablaFacturas.dataTable td.dt-invoice-date-cell,
#tablaFacturas.dataTable th.dt-invoice-date-cell {
    width: 7.25rem;
    min-width: 7.25rem;
    white-space: nowrap !important;
}

#tablaFacturas.dataTable td.dt-invoice-total-cell,
#tablaFacturas.dataTable th.dt-invoice-total-cell {
    width: 7.5rem;
    min-width: 7.5rem;
    white-space: nowrap !important;
}

#tablaFacturas.dataTable td.dt-invoice-status-cell,
#tablaFacturas.dataTable th.dt-invoice-status-cell {
    width: 6.75rem;
    min-width: 6.75rem;
    white-space: nowrap !important;
}

#tablaFacturas.dataTable td.dt-invoice-number-cell,
#tablaFacturas.dataTable td.dt-invoice-date-cell,
#tablaFacturas.dataTable td.dt-invoice-total-cell,
#tablaFacturas.dataTable td.dt-invoice-status-cell {
    padding-top: 0.22rem;
    padding-bottom: 0.22rem;
}

#tablaFacturas.dataTable td.dt-invoice-number-cell .fw-semibold,
#tablaFacturas.dataTable td.dt-invoice-status-cell .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.3rem;
    line-height: 1;
}

#tablaFacturas.dataTable td.dt-invoice-status-cell .badge {
    padding: 0.26rem 0.48rem;
    font-size: 0.74rem;
}

#tablaFacturas.dataTable td.dt-invoice-client-cell {
    overflow: hidden;
    text-overflow: ellipsis;
}

#tablaFacturas.dataTable td.dt-invoice-client-cell a {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

@media (min-width: 769px) {
    #tablaFacturas.dataTable td.dt-invoice-actions-cell,
    #tablaFacturas.dataTable th.dt-invoice-actions-cell {
        white-space: nowrap !important;
        width: 17rem;
        min-width: 17rem;
    }

    #tablaFacturas.dataTable td.dt-invoice-actions-cell .d-flex {
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
    }

    #tablaFacturas.dataTable td.dt-invoice-actions-cell form {
        display: inline-flex !important;
        margin: 0;
    }

    #tablaFacturas.dataTable td.dt-invoice-actions-cell .btn {
        width: 1.85rem;
        height: 1.85rem;
        padding: 0;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}


/* /contratos: compact desktop rows.
   The actions cell can contain 5-7 icon buttons/forms. The global DataTables
   action rule allowed flex-wrap, so those buttons broke into two lines and
   forced the whole row to become taller than the small badges/text content. */
#tablaContratos.dataTable > tbody > tr > td {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    line-height: 1.2;
}

#tablaContratos.dataTable td.dt-contract-number-cell,
#tablaContratos.dataTable th.dt-contract-number-cell {
    width: 8.5rem;
    min-width: 8.5rem;
    white-space: nowrap !important;
}

#tablaContratos.dataTable td.dt-contract-number-cell {
    padding-top: 0.22rem;
    padding-bottom: 0.22rem;
}

#tablaContratos.dataTable td.dt-contract-number-cell .fw-semibold {
    display: inline-flex;
    align-items: center;
    min-height: 1.3rem;
    line-height: 1;
}

#tablaContratos.dataTable td.dt-status-cell,
#tablaContratos.dataTable th.dt-status-cell {
    width: 6.25rem;
    min-width: 6.25rem;
    white-space: nowrap !important;
    text-align: center;
}

#tablaContratos.dataTable td.dt-status-cell {
    padding-top: 0.22rem;
    padding-bottom: 0.22rem;
}

#tablaContratos.dataTable td.dt-status-cell .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.3rem;
    line-height: 1;
    padding: 0.26rem 0.48rem;
    font-size: 0.74rem;
}

@media (min-width: 769px) {
    #tablaContratos.dataTable td.dt-actions-cell,
    #tablaContratos.dataTable th.dt-actions-cell {
        white-space: nowrap !important;
        width: 15.75rem;
        min-width: 15.75rem;
    }

    #tablaContratos.dataTable td.dt-actions-cell .d-flex {
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
    }

    #tablaContratos.dataTable td.dt-actions-cell form {
        display: inline-flex !important;
        margin: 0;
    }

    #tablaContratos.dataTable td.dt-actions-cell .btn {
        width: 1.85rem;
        height: 1.85rem;
        padding: 0;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Responsive Actions column: keep buttons usable without horizontal overflow. */
table.dataTable td.dt-actions-cell,
table.dataTable th.dt-actions-cell,
table.dataTable th:last-child,
table.dataTable td:last-child {
    white-space: normal !important;
}

table.dataTable td.dt-actions-cell .btn,
table.dataTable td:last-child .btn,
.table-stack-mobile td[data-label="Acciones"] .btn {
    flex: 0 0 auto;
}

table.dataTable td.dt-actions-cell .btn-group,
table.dataTable td.dt-actions-cell .d-flex,
table.dataTable td:last-child .btn-group,
table.dataTable td:last-child .d-flex,
.table-stack-mobile td[data-label="Acciones"] .btn-group,
.table-stack-mobile td[data-label="Acciones"] .d-flex {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem !important;
    max-width: 100%;
}

table.dataTable td.dt-actions-cell .dropdown-menu,
table.dataTable td:last-child .dropdown-menu,
.table-stack-mobile td[data-label="Acciones"] .dropdown-menu {
    max-width: min(18rem, calc(100vw - 2rem));
    white-space: normal;
}

@media (max-width: 768px) {
    table.dataTable th:last-child,
    table.dataTable td.dt-actions-cell,
    table.dataTable td:last-child {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    table.dataTable td.dt-actions-cell,
    table.dataTable td:last-child,
    .table-stack-mobile td[data-label="Acciones"] {
        overflow: visible !important;
        text-align: left !important;
    }

    table.dataTable td.dt-actions-cell .btn,
    table.dataTable td:last-child .btn,
    .table-stack-mobile td[data-label="Acciones"] .btn {
        min-width: 2.15rem;
        min-height: 2.15rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin: 0.12rem;
    }

    table.dataTable td.dt-actions-cell .btn-group,
    table.dataTable td:last-child .btn-group,
    .table-stack-mobile td[data-label="Acciones"] .btn-group {
        display: flex !important;
        width: 100%;
    }
}

@media (max-width: 576px) {
    .dataTables_wrapper table.dataTable tbody tr:not(.child) > td.dt-actions-cell,
    .dataTables_wrapper table.dataTable tbody tr:not(.child) > td:last-child,
    .table-stack-mobile td[data-label="Acciones"] {
        padding-top: 0.45rem !important;
        border-top: 1px dashed #e2e8f0 !important;
    }
}

/* Final readable overrides for tables with table-specific compact CSS.
   These must stay after /clientes and /facturas rules so visible text is not clipped. */
#tablaClientes.dataTable td.dt-client-name-cell,
#tablaClientes.dataTable td.dt-client-email-cell,
#tablaFacturas.dataTable td.dt-invoice-client-cell,
#tablaFacturas.dataTable td.dt-invoice-client-cell a {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
}

/* /clientes: prevent Municipio/Celular/Email from visually overlapping.
   Keep each value inside its own cell; the responsive wrapper will move Celular
   and Email to + details when space is tight. */
#tablaClientes.dataTable {
    table-layout: fixed !important;
}

#tablaClientes.dataTable td.dt-client-city-cell,
#tablaClientes.dataTable th.dt-client-city-cell,
#tablaClientes.dataTable td.dt-client-phone-cell,
#tablaClientes.dataTable th.dt-client-phone-cell,
#tablaClientes.dataTable td.dt-client-email-cell,
#tablaClientes.dataTable th.dt-client-email-cell {
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
}

#tablaClientes.dataTable td.dt-client-city-cell,
#tablaClientes.dataTable th.dt-client-city-cell {
    width: 8.5rem !important;
}

#tablaClientes.dataTable td.dt-client-phone-cell,
#tablaClientes.dataTable th.dt-client-phone-cell {
    width: 7.75rem !important;
}

#tablaClientes.dataTable td.dt-client-email-cell,
#tablaClientes.dataTable th.dt-client-email-cell {
    width: 12rem !important;
}

@media (max-width: 1200px) {
    #tablaClientes.dataTable td.dt-client-city-cell,
    #tablaClientes.dataTable td.dt-client-phone-cell,
    #tablaClientes.dataTable td.dt-client-email-cell {
        width: auto !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
    }
}

/* /clientes: Municipio is a primary field, so keep its text readable.
   Celular/Email are secondary and collapse first when the table gets tight. */
#tablaClientes.dataTable td.dt-client-city-cell,
#tablaClientes.dataTable th.dt-client-city-cell {
    width: auto !important;
    min-width: 9rem !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
}


/* Cliente show: nested contract/invoice tables are much narrower than /contratos.
   Keep them inside the card at high browser zoom and let NetFlow details (+)
   carry secondary columns instead of creating horizontal scroll. */
.table-client-detail-contracts.dataTable,
.table-client-detail-invoices.dataTable {
    width: 100% !important;
    table-layout: auto;
}

.table-client-detail-contracts.dataTable th,
.table-client-detail-contracts.dataTable td,
.table-client-detail-invoices.dataTable th,
.table-client-detail-invoices.dataTable td {
    max-width: none;
}

.table-client-detail-contracts.dataTable td.dt-client-contract-number-cell,
.table-client-detail-contracts.dataTable th.dt-client-contract-number-cell {
    min-width: 6.5rem;
    width: auto;
    white-space: nowrap !important;
}

.table-client-detail-contracts.dataTable td.dt-client-contract-plan-cell,
.table-client-detail-contracts.dataTable td.dt-client-contract-date-cell {
    white-space: normal !important;
    word-break: break-word;
}

@media (min-width: 769px) {
    .table-client-detail-contracts.dataTable td.dt-actions-cell,
    .table-client-detail-contracts.dataTable th.dt-actions-cell,
    .table-client-detail-invoices.dataTable td.dt-actions-cell,
    .table-client-detail-invoices.dataTable th.dt-actions-cell {
        width: auto !important;
        min-width: 0 !important;
        max-width: 8rem;
        white-space: normal !important;
    }

    .table-client-detail-contracts.dataTable td.dt-actions-cell .d-flex,
    .table-client-detail-invoices.dataTable td.dt-actions-cell .d-flex {
        flex-wrap: wrap !important;
        justify-content: center;
    }
}


.quick-action-card {
    transition: transform .15s ease, box-shadow .15s ease;
}

.quick-action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1rem rgba(15, 23, 42, .08);
}


/* ═══════════════════════════════════════
   THEME SYSTEM - Bootstrap 5.3 + app tokens
═══════════════════════════════════════ */
#preloader {
    position: fixed;
    inset: 0;
    background: var(--app-bg);
    color: var(--app-text);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    transition: opacity 0.25s ease;
}

#main-content,
#navbar,
.card,
.dropdown-menu,
.modal-content,
.offcanvas,
.list-group-item,
.table,
.form-control,
.form-select,
.input-group-text,
.page-link {
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.card,
.dropdown-menu,
.modal-content,
.offcanvas {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

.card.border-0,
.card.shadow-sm,
.card.shadow {
    box-shadow: var(--app-shadow) !important;
}

.card-header,
.card-footer {
    background-color: var(--app-surface-soft);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .card-header.bg-white,
[data-bs-theme="dark"] .card-footer.bg-white,
[data-bs-theme="dark"] .tab-content.bg-white,
[data-bs-theme="dark"] .position-fixed.bg-white {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
}

[data-bs-theme="dark"] .bg-light:not(.badge),
[data-bs-theme="dark"] .table-light {
    background-color: var(--app-surface-soft) !important;
    color: var(--app-text) !important;
    --bs-table-bg: var(--app-surface-soft) !important;
    --bs-table-bg-state: var(--app-surface-soft) !important;
    --bs-table-color-state: var(--app-text) !important;
}
[data-bs-theme="dark"] .table-light > :not(caption) > * > * {
    background-color: var(--app-surface-soft) !important;
    color: var(--app-text) !important;
}

[data-bs-theme="dark"] #main-content .text-dark:not(.badge):not(.btn),
[data-bs-theme="dark"] .card .text-dark:not(.badge):not(.btn),
[data-bs-theme="dark"] .dropdown-menu .text-dark:not(.badge):not(.btn) {
    color: var(--app-text) !important;
}

[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-secondary {
    color: var(--app-muted) !important;
}

[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-end,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-start {
    border-color: var(--app-border) !important;
}

[data-bs-theme="dark"] .btn-light,
[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--app-text);
    --bs-btn-bg: var(--app-surface-soft);
    --bs-btn-border-color: var(--app-border-strong);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #1f2937;
    --bs-btn-hover-border-color: #475569;
    --bs-btn-active-bg: #243044;
    --bs-btn-active-border-color: #475569;
}

.theme-dropdown .dropdown-item .theme-check {
    opacity: 0;
}
.theme-dropdown .dropdown-item.active .theme-check {
    opacity: 1;
}
.theme-dropdown .dropdown-item.active {
    background-color: var(--app-primary-soft);
    color: var(--app-text);
}
#themeToggleButton {
    border-color: var(--app-border);
}

.form-control,
.form-select,
.input-group-text {
    background-color: var(--app-surface);
    border-color: var(--app-border-strong);
    color: var(--app-text);
}
.form-control:focus,
.form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 0.25rem var(--app-focus-ring);
}
.form-control::placeholder {
    color: var(--app-muted);
}

.table {
    --bs-table-color: var(--app-text);
    --bs-table-bg: var(--app-surface);
    --bs-table-border-color: var(--app-border);
    --bs-table-striped-bg: var(--table-striped-bg);
    --bs-table-hover-bg: var(--app-surface-soft);
}

[data-bs-theme="dark"] .table > tbody > tr > * {
    color: var(--app-text);
    border-color: var(--app-border);
}

[data-bs-theme="dark"] .table-responsive,
[data-bs-theme="dark"] .dataTables_wrapper,
[data-bs-theme="dark"] .dt-container {
    color: var(--app-text);
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_processing,
[data-bs-theme="dark"] .dt-container .dt-length,
[data-bs-theme="dark"] .dt-container .dt-search,
[data-bs-theme="dark"] .dt-container .dt-info,
[data-bs-theme="dark"] .dt-container .dt-processing {
    color: var(--app-muted) !important;
}

[data-bs-theme="dark"] .page-link {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-link);
}
[data-bs-theme="dark"] .active > .page-link,
[data-bs-theme="dark"] .page-link.active {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
    color: #fff;
}

[data-bs-theme="dark"] .select2-container--bootstrap5 .select2-selection,
[data-bs-theme="dark"] .select2-dropdown {
    background-color: var(--app-surface);
    border-color: var(--app-border-strong);
    color: var(--app-text);
}
[data-bs-theme="dark"] .select2-container--bootstrap5 .select2-selection__rendered,
[data-bs-theme="dark"] .select2-results__option {
    color: var(--app-text);
}
[data-bs-theme="dark"] .select2-results__option--highlighted {
    background-color: var(--app-primary) !important;
    color: #fff !important;
}
[data-bs-theme="dark"] .select2-search__field {
    background-color: var(--app-surface-soft) !important;
    border-color: var(--app-border-strong) !important;
    color: var(--app-text) !important;
}

[data-bs-theme="dark"] .ctx-item {
    color: var(--app-text);
}
[data-bs-theme="dark"] .ctx-item:hover,
[data-bs-theme="dark"] .ctx-item:focus {
    color: #fff;
    background-color: var(--app-surface-soft);
}
[data-bs-theme="dark"] .dt-child-table .dt-child-value {
    color: var(--app-text);
}
[data-bs-theme="dark"] .swal2-popup {
    background: var(--app-surface) !important;
    color: var(--app-text) !important;
    border: 1px solid var(--app-border);
}
[data-bs-theme="dark"] .swal2-title {
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .swal2-html-container {
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .swal2-icon:not(.swal2-success):not(.swal2-error):not(.swal2-warning):not(.swal2-info):not(.swal2-question) {
    border-color: var(--app-border);
}
[data-bs-theme="dark"] .swal2-timer-progress-bar {
    background: var(--app-border);
}
[data-bs-theme="dark"] .swal2-cancel {
    color: var(--app-text) !important;
}
[data-bs-theme="dark"] .swal2-validation-message {
    background: var(--app-surface-soft);
    color: var(--app-text);
}

[data-bs-theme="dark"] ::selection {
    background: rgba(96, 165, 250, 0.35);
    color: #fff;
}


/* Dark dashboard polish: clearer metric text + subtle light elevation */
[data-bs-theme="dark"] #main-content .card {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012)),
        var(--app-surface);
    border: 1px solid rgba(255, 255, 255, 0.075) !important;
}

[data-bs-theme="dark"] #main-content .card.shadow-sm,
[data-bs-theme="dark"] #main-content .card.shadow,
[data-bs-theme="dark"] #main-content .card.border-0 {
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.055),
        0 16px 42px rgba(0, 0, 0, 0.32),
        0 0 24px rgba(255, 255, 255, 0.04) !important;
}

[data-bs-theme="dark"] #main-content .card-clickable:hover,
[data-bs-theme="dark"] #main-content .quick-action-card:hover {
    box-shadow:
        0 0 0 1px rgba(96, 165, 250, 0.28),
        0 18px 48px rgba(0, 0, 0, 0.38),
        0 0 30px rgba(96, 165, 250, 0.12) !important;
}

[data-bs-theme="dark"] #main-content .card .fw-bold,
[data-bs-theme="dark"] #main-content .card .fw-semibold,
[data-bs-theme="dark"] #main-content .card h1,
[data-bs-theme="dark"] #main-content .card h2,
[data-bs-theme="dark"] #main-content .card h3,
[data-bs-theme="dark"] #main-content .card h4,
[data-bs-theme="dark"] #main-content .card h5,
[data-bs-theme="dark"] #main-content .card h6,
[data-bs-theme="dark"] #main-content .card .text-dark:not(.badge):not(.btn) {
    color: #f8fafc !important;
}

[data-bs-theme="dark"] #main-content .card .text-muted,
[data-bs-theme="dark"] #main-content .card small.text-muted,
[data-bs-theme="dark"] #main-content .card .small.text-muted {
    color: #b6c2d2 !important;
}

[data-bs-theme="dark"] #main-content .quick-action-card.bg-light-subtle {
    background:
        linear-gradient(180deg, rgba(96, 165, 250, 0.06), rgba(255, 255, 255, 0.018)),
        var(--app-surface-soft) !important;
}

/* Grupo facturación panel */
.billing-panel__month { width: 130px; }
.billing-panel__year { width: 95px; }
.billing-panel .card-header {
    background: var(--app-surface, #fff);
    border-bottom-color: var(--app-border, rgba(0, 0, 0, .08));
}
.billing-panel__tile {
    background: #f8f9fa;
    color: var(--app-text, #212529);
    border: 1px solid var(--app-border, rgba(0, 0, 0, .08));
}
[data-bs-theme="dark"] .billing-panel .card,
[data-bs-theme="dark"] .billing-panel .card-body,
[data-bs-theme="dark"] .billing-panel .card-header {
    background-color: var(--app-surface, #111827) !important;
    color: var(--app-text, #f1f5f9) !important;
    border-color: var(--app-border, rgba(148, 163, 184, .18)) !important;
}
[data-bs-theme="dark"] .billing-panel__tile {
    background:
        linear-gradient(180deg, rgba(96, 165, 250, .075), rgba(255, 255, 255, .018)),
        var(--app-surface-soft, #1f2937) !important;
    color: var(--app-text, #f1f5f9) !important;
    border-color: var(--app-border, rgba(148, 163, 184, .20)) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}
[data-bs-theme="dark"] .billing-panel__tile small {
    color: var(--app-muted, #b6c2d2) !important;
}
[data-bs-theme="dark"] .billing-panel hr {
    border-color: var(--app-border, rgba(148, 163, 184, .18));
    opacity: 1;
}
[data-bs-theme="dark"] .billing-panel .table-light,
[data-bs-theme="dark"] .billing-panel .table-light > tr,
[data-bs-theme="dark"] .billing-panel .table-light > tr > th,
[data-bs-theme="dark"] .billing-panel .table-light > th,
[data-bs-theme="dark"] .billing-panel .table-light > td {
    --bs-table-bg: rgba(148, 163, 184, .10);
    --bs-table-color: var(--app-text, #f1f5f9);
    --bs-table-border-color: var(--app-border, rgba(148, 163, 184, .18));
    background-color: rgba(148, 163, 184, .10) !important;
    color: var(--app-text, #f1f5f9) !important;
    border-color: var(--app-border, rgba(148, 163, 184, .18)) !important;
}
[data-bs-theme="dark"] .billing-panel .modal-content {
    background: var(--app-surface, #111827);
    color: var(--app-text, #f1f5f9);
    border-color: var(--app-border, rgba(148, 163, 184, .18));
}
