/* =====================================================================
   VERSIÓN MÓVIL - SISTEMA JB
   Se carga después de theme.css y styles.css (inc/css.inc.php).
   Breakpoints: < 992px tablet/móvil (sin sidebar)  |  < 576px teléfono
   ===================================================================== */

:root {
    --m-topbar-h: 60px;
    --m-drawer-w: 290px;
    --m-brand: #1a6137;
    --m-accent: #4272d7;
    --m-text: #333;
    --m-border: #e6e6e6;
}

/* Drawer y overlay ocultos fuera de móvil */
.mobile-drawer,
.mobile-drawer__overlay {
    display: none;
}

/* ---------------------------------------------------------------------
   < 992px  — Estructura general
   --------------------------------------------------------------------- */
@media (max-width: 991.98px) {

    html, body {
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    /* Contenedor principal ocupa todo el ancho (theme.css lo deja en calc(100% - 300px)) */
    .page-wrapper {
        display: block;
    }

    .page-container,
    .page-container.desplegable {
        width: 100% !important;
        max-width: 100% !important;
        top: 0 !important;
        padding: var(--m-topbar-h) 0 0 0 !important;
        position: relative;
        min-height: 100vh;
    }

    /* El header de escritorio (frase + cuenta) se sustituye por la barra móvil */
    .header-desktop,
    .menu_desplegable {
        display: none !important;
    }

    .main-content {
        padding-top: 16px;
        padding-bottom: 24px;
        min-height: calc(100vh - var(--m-topbar-h));
    }

    .section__content--p30 {
        padding: 0;
    }

    .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* ----- Barra superior ----- */
    .header-mobile.mobile-topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--m-topbar-h);
        background: #f5f5f5;
        box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
        z-index: 1030;
    }

    .mobile-topbar__inner {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 12px;
        gap: 10px;
    }

    .mobile-topbar__toggle.hamburger {
        width: 42px;
        height: 42px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
        border-radius: 8px;
        border: 1px solid var(--m-border);
        flex: 0 0 auto;
    }

    .mobile-topbar__toggle .hamburger-box {
        width: 22px;
        height: 16px;
    }

    .mobile-topbar__toggle .hamburger-inner,
    .mobile-topbar__toggle .hamburger-inner::before,
    .mobile-topbar__toggle .hamburger-inner::after {
        width: 22px;
        height: 2px;
        border-radius: 2px;
    }

    .mobile-topbar__toggle .hamburger-inner::before { top: 7px; }
    .mobile-topbar__toggle .hamburger-inner::after { top: 14px; }

    .mobile-topbar__logo {
        flex: 1 1 auto;
        text-align: center;
        min-width: 0;
    }

    .mobile-topbar__logo img {
        max-height: 42px;
        max-width: 100%;
        width: auto;
    }

    .mobile-topbar__user {
        width: 42px;
        height: 42px;
        flex: 0 0 auto;
        border-radius: 50%;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
        border: 1px solid var(--m-border);
        color: #555;
        font-size: 18px;
    }

    .mobile-topbar__user img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* ----- Menú lateral deslizable ----- */
    .mobile-drawer__overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility .25s ease;
    }

    .mobile-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: var(--m-drawer-w);
        max-width: 85vw;
        background: #fff;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform .28s ease;
        box-shadow: 4px 0 16px rgba(0, 0, 0, .18);
    }

    body.mobile-nav-open {
        overflow: hidden;
    }

    body.mobile-nav-open .mobile-drawer {
        transform: translateX(0);
    }

    body.mobile-nav-open .mobile-drawer__overlay {
        opacity: 1;
        visibility: visible;
    }

    .mobile-drawer__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 16px 14px;
        background: var(--m-brand);
        color: #fff;
        flex: 0 0 auto;
    }

    .mobile-drawer__user {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
    }

    .mobile-drawer__avatar {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        overflow: hidden;
        background: rgba(255, 255, 255, .2);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        flex: 0 0 auto;
    }

    .mobile-drawer__avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .mobile-drawer__user-text {
        display: flex;
        flex-direction: column;
        min-width: 0;
        line-height: 1.25;
    }

    .mobile-drawer__user-text strong {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-drawer__user-text small {
        font-size: 12px;
        opacity: .8;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-drawer__close {
        width: 38px;
        height: 38px;
        border-radius: 50%;
        border: 0;
        background: rgba(255, 255, 255, .15);
        color: #fff;
        font-size: 20px;
        flex: 0 0 auto;
        cursor: pointer;
    }

    .mobile-drawer__nav.navbar-sidebar {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 0;
    }

    .mobile-drawer__nav .navbar__list > li > a {
        display: flex;
        align-items: center;
        padding: 12px 18px;
        font-size: 15px;
        color: var(--m-text);
        border-bottom: 1px solid #f1f1f1;
    }

    .mobile-drawer__nav .navbar__list > li > a img {
        width: 30px !important;
        height: 30px;
        object-fit: contain;
        padding: 0 !important;
        margin-right: 12px !important;
    }

    .mobile-drawer__nav .navbar__list > li.has-sub > a::after {
        content: '\f2f9';
        font-family: "Material-Design-Iconic-Font";
        margin-left: auto;
        font-size: 18px;
        transition: transform .2s ease;
    }

    .mobile-drawer__nav .navbar__list > li.has-sub > a.open::after {
        transform: rotate(180deg);
    }

    .mobile-drawer__nav .navbar__list li.active > a {
        color: var(--m-accent);
        font-weight: 500;
    }

    .mobile-drawer__nav .navbar__sub-list {
        display: none;
        background: #f8f8f8;
        padding: 4px 0;
    }

    .mobile-drawer__nav .navbar__sub-list li a {
        display: flex;
        align-items: center;
        padding: 10px 18px 10px 30px;
        font-size: 14px;
        color: #555;
    }

    .mobile-drawer__nav .navbar__sub-list li a i {
        width: 20px;
        margin-right: 12px;
        text-align: center;
        color: #888;
    }

    .mobile-drawer__nav .navbar__sub-list li.active > a,
    .mobile-drawer__nav .navbar__sub-list li.active > a i {
        color: var(--m-accent);
    }

    .mobile-drawer__foot {
        flex: 0 0 auto;
        border-top: 1px solid var(--m-border);
        display: flex;
    }

    .mobile-drawer__foot a {
        flex: 1 1 50%;
        text-align: center;
        padding: 14px 8px;
        color: var(--m-text);
        font-size: 14px;
    }

    .mobile-drawer__foot a + a {
        border-left: 1px solid var(--m-border);
        color: #d33;
    }

    /* ----- Títulos y barra de acciones de cada página ----- */
    .main-title {
        padding-bottom: 16px;
    }

    .overview-wrap {
        flex-direction: row !important;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
    }

    .overview-wrap h2,
    .overview-wrap .button {
        order: 0 !important;
    }

    .title-1 {
        font-size: 22px;
        line-height: 1.25;
    }

    .main-title .title-1[class*="col-"] {
        flex: 1 1 auto;
        max-width: 100%;
        padding: 0;
    }

    /* Filtros dentro del título (col-3 sin breakpoint en calendario, cobranza, etc.) */
    .main-title .row > [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 10px;
    }

    .main-title .row > .col-auto {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .main-title .d-flex {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* ----- Tarjetas y paneles ----- */
    .card-body {
        padding: 14px;
    }

    .au-card-title {
        padding: 22px 60px 22px 18px;
    }

    .au-card-title h3 {
        font-size: 18px;
    }

    .overview-item {
        padding: 18px;
        margin-bottom: 16px;
    }

    .overview-box .icon img {
        max-width: 52px;
    }

    .overview-box .text h2 {
        font-size: 28px;
    }

    .overview-box .text span {
        font-size: 14px;
    }

    .m-b-40 {
        margin-bottom: 20px !important;
    }

    /* ----- Tablas (DataTables con responsive: true) ----- */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    table.dataTable {
        width: 100% !important;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        margin-bottom: 8px;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_filter input {
        display: block;
        width: 100% !important;
        margin-left: 0 !important;
    }

    .dataTables_wrapper .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .dataTables_wrapper .dataTables_filter input {
        display: block;
        margin-top: 4px;
        height: 40px;
        padding: 6px 10px;
        border: 1px solid #ced4da;
        border-radius: 6px;
    }

    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
    }

    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 6px 10px !important;
        min-width: 36px;
    }

    /* Fila hija de DataTables Responsive (columnas ocultas) */
    table.dataTable > tbody > tr.child ul.dtr-details {
        display: block;
        width: 100%;
    }

    table.dataTable > tbody > tr.child ul.dtr-details > li {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 10px;
        padding: 8px 0;
        white-space: normal;
    }

    table.dataTable > tbody > tr.child span.dtr-title {
        min-width: 110px;
        font-weight: 600;
    }

    table.dataTable > tbody > tr.child span.dtr-data {
        flex: 1 1 140px;
        word-break: break-word;
    }

    .table-earning thead th {
        padding: 12px 10px;
        font-size: 13px;
    }

    .table-earning tbody td {
        padding: 10px;
        font-size: 14px;
    }

    /* ----- Formularios ----- */
    .form-control,
    .au-input,
    .select2-container .select2-selection--single {
        min-height: 42px;
        font-size: 16px; /* evita el zoom automático en iOS */
    }

    .select2-container {
        width: 100% !important;
    }

    .au-input--xl,
    .au-input--w435 {
        min-width: 0 !important;
        width: 100%;
    }

    /* ----- Modales ----- */
    .modal-dialog {
        margin: 10px auto;
        max-width: calc(100% - 20px);
    }

    #lgModal.pdf .modal-dialog.modal-lg {
        max-width: 100% !important;
        margin: 0;
    }

    /* Flechas fijas antiguas del calendario */
    .flecha_izquierda {
        left: 4px;
    }
}

/* ---------------------------------------------------------------------
   < 576px  — Teléfonos
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {

    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .title-1 {
        font-size: 20px;
    }

    /* Botón principal de cada listado ("Agregar ...") a todo el ancho */
    .overview-wrap > .au-btn,
    .overview-wrap > a.btn,
    .overview-wrap > button {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    .au-btn {
        line-height: 44px;
        padding: 0 16px;
    }

    .main-title .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .main-title .d-flex > .btn,
    .main-title .d-flex > .btn-excel {
        flex: 1 1 auto;
    }

    /* Tarjetas de estadísticas en dos columnas compactas */
    .row.m-t-25 > .col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
        padding-left: 6px;
        padding-right: 6px;
    }

    .row.m-t-25 {
        margin-left: -6px;
        margin-right: -6px;
        margin-top: 10px !important;
    }

    .overview-item {
        padding: 14px 12px;
        margin-bottom: 12px;
    }

    .overview-box {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .overview-box .icon {
        margin: 0 0 6px 0;
    }

    .overview-box .icon img {
        max-width: 38px;
    }

    .overview-box .text h2 {
        font-size: 24px;
    }

    .overview-box .text span {
        font-size: 12px;
    }

    .card-deck .card {
        margin-bottom: 12px;
    }

    /* Botones de acciones en formularios: apilados */
    .card-footer .btn,
    form .btn-lg {
        width: 100%;
        margin: 0 0 8px 0;
    }

    .au-card-title {
        padding: 18px 56px 18px 14px;
    }

    .au-card-title h3 {
        font-size: 16px;
    }

    .au-card-title + .collapse .au-task__item-inner,
    .au-message__item-inner {
        padding: 14px !important;
    }

    .au-message__item-inner {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .au-message__item-time {
        margin-top: 6px;
    }

    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
    }

    .swal2-popup {
        width: 92% !important;
        padding: 18px !important;
    }
}

/* ---------------------------------------------------------------------
   Calendario semanal / Cobranza (css/calendario.css)
   En móvil: cada día ocupa casi toda la pantalla y se desliza horizontalmente.
   --------------------------------------------------------------------- */
@media (max-width: 991.98px) {

    html body {
        overflow-y: auto;
    }

    .table-responsive.calendario {
        max-height: calc(100vh - var(--m-topbar-h) - 24px) !important;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        font-size: 13px !important;
        border-radius: 10px;
    }

    .calendario .contenedor_calendario {
        min-width: 0 !important;
        width: calc(5 * 88vw);
        padding-left: 0;
    }

    .calendario .col-20 {
        scroll-snap-align: start;
    }

    .calendario .mes {
        padding: 10px 14px !important;
    }

    .calendario .dias > .col-20 {
        padding: 8px 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }

    .calendario .dias > .col-20 .btn {
        flex: 0 0 auto;
        max-width: none;
        width: auto;
    }

    .dia-vehiculo, .dia-operador, .dia-ruta, .dia-configuracion, .dia-bitacora {
        padding: 4px 12px !important;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .calendario .contenedor_calendario {
        width: calc(5 * 46vw);
    }
}

/* ---------------------------------------------------------------------
   Login / recuperar contraseña
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
    .page-content--bge5 {
        min-height: 100vh;
        height: auto;
        padding: 0 6px 30px;
    }

    .login-wrap {
        padding-top: 6vh;
    }

    .login-logo img {
        max-width: 70%;
    }

    .login-content {
        padding: 22px 18px 14px;
        border-radius: 14px;
    }
}
