.app-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10040;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

@media (max-width: 991.98px) {
    .app-shell {
        position: relative;
    }

    /* Evitar desbordamiento horizontal que desplaza el sidebar fijo */
    html,
    body {
        overflow-x: hidden;
        max-width: 100%;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10050;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        width: 260px !important;
    }

    .app-sidebar.sidebar-open {
        transform: translateX(0);
    }

    .app-sidebar-overlay.overlay-visible {
        display: block;
    }
}

#btn-sidebar-toggle {
    color: #1d1d1f;
    border-color: rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 0.6);
}

#btn-sidebar-toggle:hover {
    background: rgba(0, 122, 255, 0.1);
    border-color: #007aff;
    color: #007aff;
}

body.dark-mode #btn-sidebar-toggle {
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.07);
}

body.dark-mode #btn-sidebar-toggle:hover {
    background: rgba(10, 132, 255, 0.2);
    border-color: #0a84ff;
    color: #0a84ff;
}

/* ── Tablas compactas ─────────────────────────────────────────── */
/* Forzar con !important para ganar a Bootstrap vars y selectores hijo-directo de DT */
table.dataTable > thead > tr > th,
table.dataTable > thead > tr > td {
    padding: 0.45rem 0.65rem !important;
    font-size: 0.8rem !important;
}

table.dataTable > tbody > tr > td,
table.dataTable > tbody > tr > th {
    padding: 0.35rem 0.65rem !important;
    vertical-align: middle !important;
    font-size: 0.82rem !important;
    line-height: 1.3 !important;
}

/* Celda de acciones: nunca partir los botones en 2 líneas */
table.dataTable > tbody > tr > td:last-child {
    white-space: nowrap !important;
}

/* Botón expandir fila en modo responsive de DataTables */
table.dataTable tbody td.dtr-control::before {
    background-color: #007aff;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px #007aff;
}

body.dark-mode table.dataTable tbody td.dtr-control::before {
    background-color: #0a84ff;
    box-shadow: 0 0 0 2px #1c1c1e, 0 0 0 3px #0a84ff;
}

/* Subpanel de datos ocultos en responsive */
table.dataTable tbody tr.child ul.dtr-details {
    font-size: 0.82rem;
}

table.dataTable tbody tr.child ul.dtr-details li {
    border-bottom-color: rgba(0, 0, 0, 0.06);
    padding: 0.35rem 0;
}

body.dark-mode table.dataTable tbody tr.child ul.dtr-details li {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode table.dataTable tbody tr.child {
    background-color: rgba(10, 132, 255, 0.05) !important;
}

/* Botones de acción dentro de las tablas */
table.dataTable .btn-sm {
    padding: 0.2rem 0.45rem;
    font-size: 0.75rem;
}

/* DataTables wrapper: controles superiores e inferiores compactos */
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    font-size: 0.82rem;
}

.dataTables_wrapper .dataTables_length select {
    padding: 0.2rem 1.5rem 0.2rem 0.5rem;
    font-size: 0.82rem;
}

.dataTables_wrapper .dataTables_filter input {
    padding: 0.25rem 0.5rem;
    font-size: 0.82rem;
}

/* En móvil: alinear controles de tabla al centro y permitir scroll horizontal en tablas */
@media (max-width: 575.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        float: none !important;
    }

    .dataTables_wrapper .row > div {
        margin-bottom: 0.4rem;
    }
}

/* Scroll horizontal en tablas en TODOS los tamaños móviles,
   sin que el body desborde (lo que rompería el sidebar fijo) */
@media (max-width: 991.98px) {
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Las tarjetas que envuelven tablas también deben poder desbordar en X */
    .card {
        overflow: visible;
    }

    .card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

.select2-container--default .select2-selection--single {
    height: 38px;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    padding-left: 0.75rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

.select2-container--default .select2-selection--multiple {
    min-height: 38px;
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
}

.select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    background: linear-gradient(135deg, rgba(245, 247, 250, 0.7) 0%, rgba(232, 236, 241, 0.75) 50%, rgba(223, 228, 234, 0.8) 100%), url('/assets/images/camino2.jpg');
    background-size: 100% auto;
    background-position: center top;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

.app-sidebar {
    /* ancho un poco mayor para que los enlaces no queden tan comprimidos */
    width: 260px;
    background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    padding: 24px 18px; /* un pelín más de espacio horizontal */
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* ── Colapso del sidebar en escritorio ────────────────── */
@media (min-width: 992px) {
    .app-sidebar.sidebar-collapsed {
        width: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        border-right-width: 0;
    }
}

.app-logo {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-logo img {
    height: 48px;
    width: auto;
    display: block;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-menu-link {
    color: #e5e7eb;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 12px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    font-weight: 500;

    /* no se permite que el texto se divida en varias líneas, evita que el menú se deforme
       cuando aparece el scrollbar o se añade margen al body (p.ej. durante un Swal) */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-menu-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-menu-link.active {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.4);
}

.app-menu-group {
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 16px;
    padding: 8px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-menu-toggle {
    width: 100%;
    border: none;
    background: transparent;
    color: #e2e8f0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 6px;
    cursor: pointer;
}

.app-menu-toggle:hover {
    color: #fff;
}

.app-menu-caret {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-right: 2px solid #94a3b8;
    border-bottom: 2px solid #94a3b8;
    transform: rotate(-45deg);
    transition: transform 0.2s ease, border-color 0.2s ease;
    margin-left: 8px;
}

.app-menu-group.open .app-menu-caret {
    transform: rotate(45deg);
    border-color: #60a5fa;
}

.app-menu-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 0;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-4px);
    transition: max-height 0.28s ease, opacity 0.25s ease, transform 0.25s ease, margin-top 0.2s ease;
}

.app-menu-group.open .app-menu-items {
    max-height: 520px;
    opacity: 1;
    transform: translateY(0);
    margin-top: 6px;
}

.app-main {
    flex: 1;
    min-width: 0; /* evita que el flex-item empuje el ancho total más allá del viewport */
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    color: #1d1d1f;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 10010; /* above other elements like buttons or tooltips */
}

.app-topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: #1d1d1f;
}

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.app-topbar-actions .dropdown {
    flex-shrink: 0;
}

/* ensure dropdown menus in topbar sit above other elements */
.app-topbar-actions {
    position: relative; /* establish stacking context */
}

/* ensure dropdown wrapper sits above other buttons */
.app-topbar-actions .dropdown {
    position: relative;
    z-index: 4000; /* higher than any topbar button */
}

.app-topbar-actions .dropdown-menu {
    position: fixed !important; /* pop out of stacking contexts */
    z-index: 4001 !important; /* ensure menu itself overlays everything */
}

/* ensure all bootstrap modals float above the topbar; topbar z-index is 10010 */
.modal {
    z-index: 11000; /* container level */
}
.modal .modal-dialog {
    z-index: 11001; /* dialog itself */
}
/* specifically keep change-password modal rules in case it needs even higher priority */
#modal-cambiar-contrasena {
    z-index: 11000;
}
#modal-cambiar-contrasena .modal-dialog {
    z-index: 11001;
}
/* Select2 – el dropdown se adjunta a document.body pero debe superar
   el z-index del modal (11001) para ser visible sobre él */
.select2-container--open {
    z-index: 11500 !important;
}

.app-topbar-actions .btn {
    border-color: rgba(0, 0, 0, 0.1);
    color: #1d1d1f;
}

.app-topbar-actions .btn:hover {
    background: #007aff;
    border-color: #007aff;
    color: #ffffff;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0 !important;
    border-radius: 10px !important;
    color: #f8fafc;
}

.icon-sun,
.icon-moon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#btn-dark-mode .icon-moon {
    display: none;
}

body.dark-mode #btn-dark-mode {
    color: #facc15;
}

body.dark-mode #btn-dark-mode .icon-sun {
    display: none;
}

body.dark-mode #btn-dark-mode .icon-moon {
    display: inline-flex;
}

body.dark-mode {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.65) 0%, rgba(28, 28, 30, 0.7) 100%), url('/assets/images/camino2.jpg');
    background-size: 100% auto;
    background-position: center top;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

body.dark-mode .app-shell {
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.55) 0%, rgba(28, 28, 30, 0.65) 100%), url('/assets/images/camino2.jpg');
    background-size: 100% auto;
    background-position: center top;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

body.dark-mode .app-sidebar {
    background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
    border-right-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .app-topbar {
    background: rgba(28, 28, 30, 0.8);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-mode .app-topbar-title {
    color: #f5f5f7;
}

body.dark-mode .app-topbar-actions .btn {
    border-color: rgba(255, 255, 255, 0.15);
    color: #f5f5f7;
}

body.dark-mode .app-topbar-actions .btn:hover {
    background: #0a84ff;
    border-color: #0a84ff;
    color: #ffffff;
}

.login-logo {
    display: flex;
    justify-content: center;
}

.login-logo img {
    height: 96px;
    width: auto;
    display: block;
}

.login-page {
    background: url('/assets/images/camino1.jpg') no-repeat center center fixed;
    background-size: cover;
}

.login-page .card {
    backdrop-filter: blur(2px);
}

body.dark-mode .app-menu-group {
    background: rgba(30, 41, 59, 0.45);
    border-color: rgba(148, 163, 184, 0.2);
}

body.dark-mode .app-menu-link {
    color: #e2e8f0;
}

body.dark-mode .app-menu-link.active {
    background: linear-gradient(135deg, #0a84ff 0%, #0066cc 100%);
    box-shadow: 0 4px 16px rgba(10, 132, 255, 0.5);
}

body.dark-mode .card {
    background: #0f172a;
    border-color: rgba(148, 163, 184, 0.2);
}

body.dark-mode .table {
    color: #e2e8f0;
    --bs-table-bg: transparent;
    --bs-table-striped-bg: rgba(28, 28, 30, 0.5);
    --bs-table-hover-bg: rgba(10, 132, 255, 0.1);
}

body.dark-mode .table thead th {
    color: #f8fafc;
}

body.dark-mode .table tbody td {
    color: #e2e8f0;
    background-color: transparent;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6,
body.dark-mode .app-topbar-title {
    color: #f8fafc;
}

body.dark-mode .card-title,
body.dark-mode .card-header,
body.dark-mode .card-header h1,
body.dark-mode .card-header h2,
body.dark-mode .card-header h3,
body.dark-mode .card-header h4,
body.dark-mode .card-header h5,
body.dark-mode .card-header h6 {
    color: #f8fafc;
}

body.dark-mode .table thead th,
body.dark-mode .table thead td,
body.dark-mode .table thead tr {
    background-color: rgba(10, 132, 255, 0.12) !important;
    border-bottom-color: rgba(10, 132, 255, 0.25) !important;
}

body.dark-mode .form-control,
body.dark-mode .form-select {
    background: #0b1220;
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.3);
}

body.dark-mode .modal-content {
    background: rgba(44, 44, 46, 0.92);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

body.dark-mode .dataTables_wrapper .dataTables_length,
body.dark-mode .dataTables_wrapper .dataTables_filter,
body.dark-mode .dataTables_wrapper .dataTables_info,
body.dark-mode .dataTables_wrapper .dataTables_paginate {
    color: #cbd5f5;
}

body.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > * {
    color: #e2e8f0;
    background-color: rgba(28, 28, 30, 0.5) !important;
}

body.dark-mode .table-striped > tbody > tr:nth-of-type(even) > * {
    color: #e2e8f0;
    background-color: transparent !important;
}

body.dark-mode .table-bordered > :not(caption) > * {
    border-color: rgba(148, 163, 184, 0.2);
}

body.dark-mode .dataTables_wrapper .dataTables_paginate .page-link {
    color: #e2e8f0;
    background: rgba(28, 28, 30, 0.6);
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .dataTables_wrapper .dataTables_paginate .page-link:hover {
    background: rgba(28, 28, 30, 0.8);
    border-color: rgba(10, 132, 255, 0.4);
    color: #0a84ff;
}

body.dark-mode .dataTables_wrapper .dataTables_paginate .page-item.active .page-link {
    background: linear-gradient(135deg, #0a84ff 0%, #0066cc 100%);
    border-color: #0a84ff;
    color: #ffffff;
}

body.dark-mode .dataTables_wrapper .dataTables_paginate .page-item.disabled .page-link {
    color: #64748b;
    background: rgba(28, 28, 30, 0.3);
    border-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .select2-container--default .select2-selection--single,
body.dark-mode .select2-container--default .select2-selection--multiple {
    background: rgba(28, 28, 30, 0.8);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #e2e8f0;
}

body.dark-mode .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #94a3b8 transparent transparent transparent;
}

body.dark-mode .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: #1e293b;
    border-color: rgba(148, 163, 184, 0.35);
    color: #e2e8f0;
}

body.dark-mode .select2-dropdown {
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    border-color: rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
}

body.dark-mode .select2-results__option {
    color: #e2e8f0;
}

body.dark-mode .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: #0a84ff;
    color: #fff;
}

body.dark-mode .select2-container--default .select2-search--dropdown .select2-search__field {
    background: #0b1220;
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.35);
}

body.dark-mode .swal2-popup {
    background: #0f172a !important;
    color: #e2e8f0 !important;
}

body.dark-mode .swal2-title,
body.dark-mode .swal2-html-container {
    color: #e2e8f0 !important;
}

body.dark-mode .swal2-icon.swal2-warning {
    border-color: #fbbf24 !important;
    color: #fbbf24 !important;
}

body.dark-mode .swal2-icon.swal2-success {
    border-color: #34d399 !important;
    color: #34d399 !important;
}

body.dark-mode .swal2-icon.swal2-error {
    border-color: #f87171 !important;
    color: #f87171 !important;
}

/* put SweetAlert above modal windows */
.swal2-container {
    z-index: 20000 !important;
}

/* ── Formularios compactos y menos redondeados ─────────────────────────────── */
/* Sobreescribe las variables de Bootstrap para que todo el sistema sea coherente */
:root {
    --bs-border-radius:    0.25rem;   /* 4 px – era 0.375rem */
    --bs-border-radius-sm: 0.2rem;
    --bs-border-radius-lg: 0.3rem;
    --bs-border-radius-xl: 0.4rem;
}

/* Inputs, textareas y selects nativos */
.form-control,
.form-select {
    border-radius: 0.25rem !important;
    padding: 0.35rem 0.6rem !important;
    font-size: 0.875rem !important;
    min-height: unset !important;
}

.form-control-lg,
.form-select-lg {
    padding: 0.45rem 0.75rem !important;
    font-size: 0.925rem !important;
    border-radius: 0.3rem !important;
}

.form-control-sm,
.form-select-sm {
    padding: 0.2rem 0.45rem !important;
    font-size: 0.8rem !important;
    border-radius: 0.2rem !important;
}

/* Input groups */
.input-group > .form-control,
.input-group > .form-select,
.input-group-text {
    border-radius: 0.25rem !important;
}

.input-group > :not(:first-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

.input-group > :not(:last-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

/* Botones */
.btn:not(.btn-icon-only) {
    border-radius: 0.25rem !important;
    padding: 0.35rem 0.75rem !important;
    font-size: 0.875rem !important;
}

.btn-sm:not(.btn-icon-only) {
    padding: 0.2rem 0.5rem !important;
    font-size: 0.8rem !important;
    border-radius: 0.2rem !important;
}

.btn-lg:not(.btn-icon-only) {
    padding: 0.45rem 1rem !important;
    font-size: 0.925rem !important;
    border-radius: 0.3rem !important;
}

/* Modales: cabecera, cuerpo y pie más ajustados */
.modal-content {
    border-radius: 0.4rem !important;
}

.modal-header {
    padding: 0.75rem 1rem !important;
}

.modal-body {
    padding: 1rem !important;
}

.modal-footer {
    padding: 0.6rem 1rem !important;
}

/* Labels más compactos */
.form-label {
    margin-bottom: 0.2rem !important;
    font-size: 0.8rem !important;
    font-weight: 600 !important;
}

/* Separación entre grupos de campos */
.mb-3 {
    margin-bottom: 0.65rem !important;
}

/* Select2 – igualar con el resto de inputs */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    border-radius: 0.25rem !important;
    height: 32px !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 30px !important;
    padding-left: 0.6rem !important;
    font-size: 0.875rem !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 30px !important;
}

.select2-container--default .select2-selection--multiple {
    min-height: 32px !important;
}

.select2-dropdown {
    border-radius: 0.25rem !important;
}

/* Tarjetas */
.card {
    border-radius: 0.4rem !important;
}

.card-header {
    border-radius: 0.4rem 0.4rem 0 0 !important;
    padding: 0.6rem 1rem !important;
}

.card-body {
    padding: 0.85rem 1rem !important;
}

/* dark-mode: ajustes complementarios para los nuevos tamaños */
body.dark-mode .select2-container--default .select2-selection--single,
body.dark-mode .select2-container--default .select2-selection--multiple {
    border-radius: 0.25rem !important;
}

/* ── Fin formularios compactos ──────────────────────────────────────────────── */
