/* SIREPA-i: comportamiento de app en celulares (se carga después de los estilos de la plantilla) */

[hidden] { display: none !important; }

/* ---------- Barra de navegación inferior (solo celular) ---------- */
.bottom-nav { display: none; }

@media (max-width: 767.98px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1040;
        background: #fff;
        border-top: 1px solid #e3e8ef;
        box-shadow: 0 -4px 16px rgba(15, 40, 80, 0.08);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bottom-nav a,
    .bottom-nav button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 58px;
        padding: 6px 2px;
        border: 0;
        background: none;
        color: #6b7785;
        font-size: 11px;
        font-weight: 600;
        text-decoration: none;
        position: relative;
    }

    .bottom-nav i { font-size: 22px; line-height: 1; }
    .bottom-nav .activo { color: #1363D0; }
    .bottom-nav .activo::before {
        content: '';
        position: absolute;
        top: 0;
        left: 28%;
        right: 28%;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: #1363D0;
    }

    /* Botón «Nueva» elevado sobre la barra, con su texto siempre visible */
    .bottom-nav .nueva i {
        color: #fff;
        background: #1363D0;
        border-radius: 50%;
        width: 48px;
        height: 48px;
        margin-top: -22px;
        border: 4px solid #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        box-shadow: 0 4px 10px rgba(19, 99, 208, 0.35);
    }

    .bottom-nav .contador {
        position: absolute;
        top: 5px;
        left: calc(50% + 7px);
        min-width: 17px;
        height: 17px;
        padding: 0 5px;
        border-radius: 9px;
        background: #e11d48;
        color: #fff;
        font-size: 10.5px;
        font-weight: 700;
        line-height: 17px;
        text-align: center;
        /* Anillo blanco: separa el número de la campana y del borde para que se lea completo */
        box-shadow: 0 0 0 2px #fff;
        z-index: 3;
    }

    /* Espacio para que la barra no tape el contenido */
    body.fix-header .page-wrapper { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
    body.fix-header .footer { display: none; }
}

/* ---------- Menú lateral: fondo que lo cierra ---------- */
.sidebar-fondo-movil { display: none; }

@media (max-width: 767.98px) {
    body.show-sidebar .sidebar-fondo-movil {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 49;
        background: rgba(15, 25, 40, 0.45);
    }
    body.show-sidebar .left-sidebar { z-index: 50; }
}

/* ---------- App instalada: respetar la muesca y la barra de estado ---------- */
@media (display-mode: standalone) {
    body.fix-header .topbar { padding-top: env(safe-area-inset-top); }
}

/* ---------- Formularios y botones táctiles ---------- */
@media (max-width: 767.98px) {
    /* 16px evita el zoom automático de iOS al tocar un campo */
    input.form-control,
    select.form-control,
    select.form-select,
    textarea.form-control,
    .swal2-input,
    .swal2-textarea { font-size: 16px !important; }

    .page-wrapper .btn:not(.btn-sm):not(.btn-xs) { min-height: 44px; }

    .page-wrapper .container-fluid { padding-left: 10px; padding-right: 10px; }
    /* Ningún adorno (anillos animados, sombras) debe ensanchar la página */
    html, body { overflow-x: clip; }
    /* Las filas de la plantilla tienen margen de -15px: se igualan al relleno de 10px para no desbordar */
    .page-wrapper .container-fluid .row { margin-left: -10px; margin-right: -10px; }
    .page-wrapper .container-fluid .row > [class*="col"] { padding-left: 10px; padding-right: 10px; }
    .card .card-body { padding: 14px; }

    /* Modales a pantalla completa, con los botones siempre visibles */
    .modal-dialog,
    .modal-dialog.custom-modal-width {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        min-height: 100vh;
        min-height: 100dvh;
    }
    .modal-content {
        border-radius: 0 !important;
        min-height: 100vh;
        min-height: 100dvh;
        border: 0;
    }
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 2;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    /* Calendario de papeletas */
    .fc-toolbar { flex-wrap: wrap; gap: 6px; }
    .fc-toolbar h2 { font-size: 17px !important; }
    .fc-toolbar .fc-button { min-height: 40px; padding: 0 12px; }
    .fc-day-number { font-size: 13px; }
    .fc-event { font-size: 11px; }
}

/* ---------- Tablas → tarjetas (lo prepara js/sirepai-mobile.js) ---------- */
@media (max-width: 767.98px) {
    table.tabla-movil { border: 0 !important; width: 100% !important; min-width: 0 !important; }
    table.tabla-movil thead { display: none; }

    /* Tablas con filtros en la cabecera: los filtros quedan como un bloque arriba */
    table.tabla-movil.tabla-movil-con-filtros thead { display: block; }
    table.tabla-movil.tabla-movil-con-filtros thead tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        margin-bottom: 12px;
    }
    table.tabla-movil.tabla-movil-con-filtros thead th {
        display: block;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto !important;
        position: static !important;
        background: transparent !important;
        color: #4b5563 !important;
        border: 0 !important;
        padding: 0 !important;
        font-size: 12px;
        text-align: left !important;
        white-space: normal !important;
        word-break: normal !important;
    }
    table.tabla-movil.tabla-movil-con-filtros thead th br { display: none; }
    table.tabla-movil.tabla-movil-con-filtros thead th input,
    table.tabla-movil.tabla-movil-con-filtros thead th select {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 40px;
        margin-top: 2px;
    }

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

    table.tabla-movil tbody tr {
        background: #fff;
        border: 1px solid #e3e8ef !important;
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 6px 12px;
        box-shadow: 0 2px 8px rgba(15, 40, 80, 0.05);
    }

    table.tabla-movil tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border: 0 !important;
        border-bottom: 1px dashed #edf0f4 !important;
        padding: 8px 0 !important;
        text-align: right;
        white-space: normal !important;
        word-break: break-word;
    }
    table.tabla-movil tbody td:last-child { border-bottom: 0 !important; }
    /* Algunas vistas fijan max-width y fondo en línea en cada celda: en la tarjeta ocupa todo el ancho */
    table.tabla-movil tbody td { max-width: none !important; background: transparent !important; box-shadow: none !important; }

    table.tabla-movil tbody td[data-label]::before {
        content: attr(data-label);
        flex-shrink: 0;
        max-width: 45%;
        text-align: left;
        font-weight: 600;
        font-size: 12px;
        color: #6b7785;
    }
    table.tabla-movil tbody td[data-label=""]::before { content: none; }

    /* Fila de «sin resultados» con colspan */
    table.tabla-movil tbody td[colspan] { justify-content: center; text-align: center; }
    table.tabla-movil tbody td[colspan]::before { content: none; }

    .table-responsive:has(> table.tabla-movil),
    .table-wrapper-v2:has(> table.tabla-movil) { overflow-x: visible !important; }
}

@media (max-width: 767.98px) {
    table.tabla-movil.tabla-movil-con-filtros thead,
    table.tabla-movil.tabla-movil-con-filtros thead tr { background: transparent !important; }
    table.tabla-movil tbody td[data-label]::before { flex: 0 0 40%; max-width: 40%; }
    table.tabla-movil tbody td > * { min-width: 0; max-width: 60%; }
    table.tabla-movil tbody td.text-truncate { overflow: visible !important; text-overflow: clip !important; }
    table.tabla-movil tbody td .label,
    table.tabla-movil tbody td .badge { display: inline-block; white-space: nowrap; }
}

/* Algunas vistas fuerzan «display: table-cell !important» en columnas (.keep-mobile, .keep-xxs) */
@media (max-width: 767.98px) {
    table.tabla-movil tbody tr { display: block !important; }
    table.tabla-movil tbody td,
    table.tabla-movil tbody td.keep-mobile,
    table.tabla-movil tbody td.keep-xxs { display: flex !important; }
}

/* ---------- Tarjetas de resumen: dos columnas compactas en el celular ---------- */
@media (max-width: 767.98px) {
    /* Panel del supervisor */
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
    .summary-card { padding: 12px !important; gap: 10px !important; align-items: flex-start !important; flex-wrap: wrap; }
    .summary-card .summary-icon { width: 36px !important; height: 36px !important; font-size: 1rem !important; }
    .summary-card .summary-content { min-width: 0; }
    .summary-card .summary-value { font-size: 1.35rem !important; line-height: 1.1; }
    .summary-card .summary-label { font-size: 0.68rem !important; letter-spacing: 0.02em; white-space: normal; }
    .summary-grid > .summary-card:first-child:nth-last-child(odd) { grid-column: 1 / -1; }

    /* Listado de papeletas del revisor */
    .stats-container { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
    .stats-container .stat-card-modern { padding: 12px !important; min-height: 0 !important; margin: 0 !important; gap: 10px !important; }
    .stats-container .stat-card-modern:first-child { grid-column: 1 / -1; }
    .stats-container .stat-icon-modern { width: 38px !important; height: 38px !important; min-width: 38px !important; }
    .stats-container .stat-icon-modern .material-icons { font-size: 20px !important; }
    .stats-container .stat-value-modern { font-size: 1.4rem !important; line-height: 1.1; }
    .stats-container .stat-label-modern { font-size: 0.7rem !important; }
}

/* ---------- Elementos que en el celular ya cubre la barra inferior ---------- */
@media (max-width: 767.98px) {
    .solo-escritorio { display: none !important; }
}

/* ---------- Panel «Avisos en este celular» (notificaciones push) ---------- */
.push-panel {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 0 0 14px;
    padding: 14px;
    border: 1px solid #d6e4fa;
    border-radius: 14px;
    background: #f4f8fd;
}
.push-panel[hidden] { display: none !important; }
.push-panel-icono {
    flex: 0 0 40px;
    height: 40px;
    border-radius: 50%;
    background: #1363D0;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.push-panel-activo { background: #eefaf2; border-color: #c4ebd1; }
.push-panel-activo .push-panel-icono { background: #198754; }
.push-panel-texto { flex: 1; min-width: 0; }
.push-panel-titulo { font-weight: 700; color: #10294d; font-size: 15px; }
.push-panel-texto p { margin: 2px 0 10px; font-size: 13.5px; line-height: 1.45; color: #3d4a5c; }
.push-panel-acciones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.push-panel-texto .push-panel-ayuda { display: flex; gap: 6px; margin: 10px 0 0; font-size: 12.5px; color: #3d4a5c; }
.push-panel-texto .push-panel-ayuda[hidden] { display: none; }
.push-panel-ayuda i { color: #1363D0; margin-top: 3px; }
.push-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 10px;
    border: 0;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.push-btn[hidden] { display: none !important; }
.push-btn-activar { background: #1363D0; color: #fff; }
.push-btn-activar:hover { background: #0d4a9e; color: #fff; }
.push-btn-secundario { background: #fff; color: #1363D0; border: 1px solid #b9cff2; }
.push-btn-enlace { background: none; color: #6b7785; text-decoration: underline; padding: 0 6px; }
.push-btn:disabled { opacity: 0.6; cursor: wait; }

/* ---------- Menú lateral en el celular: submenús siempre abiertos (las opciones se ven sin toques extra) ---------- */
@media (max-width: 767.98px) {
    .left-sidebar #sidebarnav ul.collapse.first-level { display: block !important; height: auto !important; max-height: none !important; overflow: visible !important; visibility: visible !important; opacity: 1 !important; }
    .left-sidebar #sidebarnav .sidebar-link.has-arrow::after { display: none !important; }
    .left-sidebar #sidebarnav .sidebar-link.has-arrow { pointer-events: none; font-weight: 700; }
    .left-sidebar #sidebarnav ul.first-level .sidebar-link { min-height: 44px; display: flex; align-items: center; }
    /* Que la barra inferior no tape las últimas opciones */
    .left-sidebar #sidebarnav { padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important; }
}

/* ---------- Cabecera en el celular: logo blanco sobre el azul de la cabecera ---------- */
@media (max-width: 767.98px) {
    .topbar .top-navbar .navbar-header,
    .topbar .navbar-header {
        background: transparent !important;
        box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.12);
    }
    .topbar .navbar-header .navbar-brand img {
        filter: brightness(0) invert(1);
    }
}

/* ---------- Invitación a activar avisos (Inicio) ---------- */
.push-invitacion {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, #eaf2fd 0%, #f4f8fd 100%);
    border: 1px solid #cfe0f8;
}
.push-invitacion[hidden] { display: none !important; }
.push-invitacion-icono {
    flex: 0 0 38px;
    height: 38px;
    border-radius: 50%;
    background: #1363D0;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: push-campana 2.4s ease-in-out 1s 2;
}
.push-invitacion-texto { flex: 1; min-width: 0; line-height: 1.35; }
.push-invitacion-texto strong { display: block; color: #10294d; font-size: 14.5px; }
.push-invitacion-texto span { display: block; color: #4b5869; font-size: 13px; }
.push-invitacion .push-btn-activar { flex: 0 0 auto; }
.push-invitacion-cerrar {
    flex: 0 0 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #6b7785;
    font-size: 20px;
    line-height: 32px;
    cursor: pointer;
}
.push-invitacion-cerrar:hover { background: rgba(0, 0, 0, 0.06); }
.push-invitacion-lista { background: #eefaf2; border-color: #c4ebd1; }
.push-invitacion-lista .push-invitacion-icono { background: #198754; animation: none; }
@keyframes push-campana {
    0%, 100% { transform: rotate(0); }
    10%, 30% { transform: rotate(-14deg); }
    20%, 40% { transform: rotate(14deg); }
    50% { transform: rotate(0); }
}
@media (max-width: 575.98px) {
    .push-invitacion { flex-wrap: wrap; }
    .push-invitacion-texto { flex: 1 1 calc(100% - 100px); }
    .push-invitacion .push-btn-activar { order: 3; flex: 1 1 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
    .push-invitacion-icono { animation: none; }
}

/* Con el menú lateral abierto, el recordatorio flotante no debe taparlo */
@media (max-width: 767.98px) {
    body.show-sidebar .alert-banner-v2 { display: none !important; }
}
