/*
 * Capa movil global.
 * Mantiene el escritorio sin cambios y convierte las vistas del sistema en
 * una experiencia tactil compacta cuando se abre desde un telefono.
 */
:root {
    --mobile-app-primary: #0d6efd;
    --mobile-app-ink: #172033;
    --mobile-app-muted: #64748b;
    --mobile-app-surface: #ffffff;
    --mobile-app-background: #f4f7fb;
    --mobile-app-border: #e3eaf3;
}

.mobile-data-cards {
    display: none;
}

.mobile-app-page-title {
    display: none;
}

@media (max-width: 767.98px) {
    html {
        background: var(--mobile-app-background);
        -webkit-tap-highlight-color: transparent;
    }

    body {
        background: var(--mobile-app-background);
        color: var(--mobile-app-ink);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #header.header {
        height: 68px;
        min-height: 68px;
        padding: env(safe-area-inset-top) 14px 0;
        background: #ffffff;
        box-shadow: 0 1px 0 rgba(15, 23, 42, 0.07), 0 3px 12px rgba(15, 23, 42, 0.06);
    }

    #header h4.logo {
        align-items: flex-start !important;
        color: var(--mobile-app-ink) !important;
        flex-direction: column;
        font-size: 0.95rem;
        gap: 0;
        line-height: 1.1;
        margin-bottom: 0;
    }

    #header .mobile-app-brand {
        color: var(--mobile-app-muted);
        font-size: 0.62rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    #header .mobile-app-page-title {
        color: var(--mobile-app-ink);
        display: block;
        font-family: "Nunito", sans-serif;
        font-size: 1.05rem;
        font-weight: 800;
        letter-spacing: 0;
        max-width: 220px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #header .toggle-sidebar-btn {
        color: #344054;
        font-size: 1.6rem;
        padding-left: 0.45rem;
    }

    #header .nav-profile img {
        max-height: 34px;
        border: 2px solid rgba(255, 255, 255, 0.45);
    }

    .sidebar {
        top: 68px;
        width: min(88vw, 340px);
        left: calc(min(88vw, 340px) * -1);
        padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
        border-radius: 0 28px 28px 0;
        box-shadow: 10px 0 34px rgba(15, 23, 42, 0.2);
    }

    .toggle-sidebar .sidebar {
        left: 0;
    }

    .sidebar-nav .nav-link,
    .sidebar-nav .nav-content a {
        min-height: 46px;
        border-radius: 12px;
        margin-bottom: 3px;
    }

    #main.main {
        margin-top: 68px;
        padding: 18px 12px calc(24px + env(safe-area-inset-bottom));
    }

    #footer.footer {
        display: none;
    }

    .pagetitle {
        margin: 0 4px 14px;
    }

    .pagetitle h1 {
        color: var(--mobile-app-ink);
        font-size: 1.22rem;
        font-weight: 800;
        line-height: 1.25;
    }

    .pagetitle nav {
        display: none;
    }

    .section {
        margin: 0;
    }

    .card {
        border: 0;
        border-radius: 24px;
        box-shadow: 0 3px 14px rgba(15, 23, 42, 0.055);
        overflow: hidden;
    }

    .card > .card-body:not(.p-0) {
        padding: 1rem;
    }

    .card-title {
        color: var(--mobile-app-ink);
        font-size: 1rem;
        font-weight: 800;
    }

    .row > .card {
        margin-left: 0;
        margin-right: 0;
    }

    .table-toolbar,
    [class$="-toolbar"] {
        align-items: stretch;
        gap: 0.75rem;
    }

    .table-toolbar .btn,
    [class$="-toolbar"] > .btn,
    [class$="-toolbar"] > a.btn {
        width: 100%;
    }

    .btn:not(.btn-sm) {
        min-height: 46px;
        border-radius: 16px;
        font-weight: 700;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn.btn-sm {
        min-height: 38px;
        border-radius: 12px;
        font-weight: 700;
    }

    .form-label {
        color: #475569;
        font-size: 0.74rem;
        font-weight: 800;
        letter-spacing: 0.025em;
        margin-bottom: 0.35rem !important;
        text-transform: uppercase;
    }

    .form-control,
    .form-select {
        min-height: 46px !important;
        background-color: #f7f9fc;
        border: 1px solid #cbd5e1;
        border-radius: 14px;
        font-size: 16px !important;
        padding: 0.55rem 0.75rem;
    }

    textarea.form-control {
        min-height: 100px !important;
    }

    .form-control:focus,
    .form-select:focus {
        background: #fff;
        border-color: var(--mobile-app-primary);
        box-shadow: 0 0 0 0.22rem rgba(13, 110, 253, 0.12);
    }

    .input-group > .input-group-text,
    .input-group > .btn {
        min-height: 46px;
        border-radius: 12px;
    }

    .form-check-input {
        width: 2.35em;
        height: 1.25em;
        margin-top: 0.15em;
    }

    .form-check-label {
        padding-left: 0.15rem;
        line-height: 1.5;
    }

    .select2-container .select2-selection--single {
        height: 46px !important;
        border-color: #d7e1ec !important;
        border-radius: 12px !important;
    }

    .select2-container .select2-selection--single .select2-selection__rendered {
        line-height: 44px !important;
        font-size: 16px;
        padding-left: 0.75rem;
    }

    .select2-container .select2-selection--single .select2-selection__arrow {
        height: 44px !important;
    }

    .nav-tabs {
        flex-wrap: nowrap;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 0 0.1rem 0.45rem;
        scrollbar-width: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-item {
        flex: 0 0 auto;
    }

    .nav-tabs .nav-link {
        border: 1px solid #dbe4ef;
        border-radius: 999px !important;
        color: #475569;
        min-height: 40px;
        padding: 0.48rem 0.85rem;
        white-space: nowrap;
    }

    .nav-tabs .nav-link.active {
        background: var(--mobile-app-primary);
        border-color: var(--mobile-app-primary);
        color: #fff;
    }

    .modal {
        padding-left: 0 !important;
    }

    .modal-dialog,
    .modal-dialog.modal-sm,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl,
    .modal-dialog.modal-fullscreen {
        height: 100%;
        margin: 0;
        max-width: 100%;
        width: 100%;
    }

    .modal-content {
        border: 0;
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .modal-header {
        align-items: center;
        background: #fff;
        border-bottom: 1px solid var(--mobile-app-border);
        padding: calc(0.8rem + env(safe-area-inset-top)) 1rem 0.8rem;
    }

    .modal-title {
        color: var(--mobile-app-ink);
        font-size: 1rem;
        font-weight: 800;
    }

    .modal-body {
        background: var(--mobile-app-background);
        padding: 1rem;
    }

    .modal-footer {
        background: #fff;
        border-top: 1px solid var(--mobile-app-border);
        display: grid;
        gap: 0.55rem;
        padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    }

    .modal-footer .btn {
        grid-column: 1;
        margin: 0;
        min-height: 46px;
        width: 100%;
    }

    .modal-footer .btn-primary,
    .modal-footer .btn-success,
    .modal-footer .btn-danger {
        grid-row: 1;
    }

    .modal-footer .btn-secondary,
    .modal-footer .btn-outline-secondary {
        grid-row: 2;
    }

    .modal-footer .btn:not(.btn-primary):not(.btn-success):not(.btn-danger):not(.btn-secondary):not(.btn-outline-secondary) {
        grid-row: 2;
    }

    .toast-container {
        bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        left: 10px;
        padding: 0 !important;
        right: 10px;
    }

    .toast-container .toast {
        width: 100%;
    }

    .back-to-top {
        bottom: calc(16px + env(safe-area-inset-bottom));
        border-radius: 50%;
        height: 48px;
        right: 16px;
        width: 48px;
    }

    /* La tabla fuente permanece para DataTables; la tarjeta es su vista movil. */
    .mobile-table-source {
        display: none !important;
    }

    .mobile-data-cards {
        display: grid;
        gap: 0.75rem;
        margin-top: 0.8rem;
    }

    .mobile-data-empty {
        border: 1px dashed #cbd5e1;
        border-radius: 14px;
        color: var(--mobile-app-muted);
        font-size: 0.9rem;
        padding: 1rem;
        text-align: center;
    }

    .mobile-data-card {
        background: var(--mobile-app-surface);
        border: 0;
        border-radius: 20px;
        box-shadow: 0 3px 14px rgba(15, 23, 42, 0.055);
        overflow: hidden;
        padding: 0.85rem;
    }

    .mobile-data-card__head {
        align-items: flex-start;
        display: flex;
        gap: 0.55rem;
        justify-content: space-between;
        margin-bottom: 0.72rem;
    }

    .mobile-data-card__title {
        color: var(--mobile-app-ink);
        font-size: 0.98rem;
        font-weight: 800;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }

    .mobile-data-card__number {
        background: #edf4ff;
        border-radius: 999px;
        color: #235db3;
        flex: 0 0 auto;
        font-size: 0.72rem;
        font-weight: 800;
        padding: 0.24rem 0.48rem;
    }

    .mobile-data-card__grid {
        display: grid;
        gap: 0.5rem;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mobile-data-card__field {
        background: #f3f6fb;
        border: 0;
        border-radius: 14px;
        min-width: 0;
        padding: 0.48rem 0.55rem;
    }

    .mobile-data-card__field--wide {
        grid-column: 1 / -1;
    }

    .mobile-data-card__label {
        color: var(--mobile-app-muted);
        font-size: 0.67rem;
        font-weight: 800;
        letter-spacing: 0.025em;
        margin-bottom: 0.12rem;
        text-transform: uppercase;
    }

    .mobile-data-card__value {
        color: var(--mobile-app-ink);
        font-size: 0.86rem;
        font-weight: 650;
        line-height: 1.35;
        overflow-wrap: anywhere;
    }

    .mobile-data-card__actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }

    .mobile-data-card__actions .btn {
        flex: 1 1 110px;
        min-height: 42px;
    }

}
