/* ============================================================
   VISIBILIDAD MOVIL / TABLET
   Ajustes globales para telefonos y tablets (hasta 1024px).
   Escritorio amplio: min-width 1025px.
============================================================ */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: clip;
}

body {
    overflow-x: visible;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

@media (max-width: 1024px) {
    .app-sidebar {
        width: min(280px, calc(100vw - 28px));
        padding-top: max(16px, env(safe-area-inset-top, 0px));
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
        grid-template-rows: auto minmax(0, 1fr);
        min-height: 100dvh;
    }

    /* Salir ya está en el bloque del usuario */
    .app-sidebar > .app-sidebar__logout--footer,
    .app-sidebar__logout--footer {
        display: none !important;
    }

    .app-sidebar__user {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "name salir"
            "role salir";
        align-items: center;
        column-gap: 8px;
        row-gap: 2px;
        padding: 10px;
    }

    .app-sidebar__user > span {
        grid-area: name;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: .78rem;
    }

    .app-sidebar__user > strong {
        grid-area: role;
        min-width: 0;
        font-size: .9rem;
    }

    .app-sidebar__logout--user {
        display: block !important;
        grid-area: salir;
        justify-self: end;
        align-self: center;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .app-sidebar__logout--user button {
        width: auto;
        min-width: 0;
        min-height: 36px;
        padding: 6px 10px;
        gap: 4px;
        font-size: .78rem;
        white-space: nowrap;
    }

    .app-sidebar__logout--user button .bi {
        flex: 0 0 14px;
        font-size: .9rem;
    }

    /* Menú lateral: densidad táctil y etiquetas cortas legibles (TENS ambulancia / operativa) */
    .app-sidebar__nav {
        gap: 4px;
        padding-right: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .app-sidebar__section {
        margin: 10px 6px 2px;
        font-size: .68rem;
        letter-spacing: .04em;
    }

    .app-sidebar__section:first-child {
        margin-top: 4px;
    }

    .app-sidebar__link {
        min-height: 44px;
        padding: 10px 10px;
        gap: 8px;
        line-height: 1.2;
    }

    .app-sidebar__link-text {
        white-space: normal;
        overflow-wrap: break-word;
        font-size: .92rem;
    }

    .app-sidebar__badge {
        flex: 0 0 auto;
        min-width: 1.4rem;
        height: 1.4rem;
        padding: 0 .4rem;
        font-size: .7rem;
    }

    /* FAB menu: contraste alto (como FAB matrona), siempre visible abajo izquierda */
    .app-topbar__menu {
        position: fixed !important;
        top: auto !important;
        right: auto !important;
        bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px)) !important;
        left: max(14px, env(safe-area-inset-left, 0px)) !important;
        z-index: 1100 !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 56px !important;
        min-width: 56px !important;
        height: 56px !important;
        min-height: 56px !important;
        padding: 0 !important;
        gap: 0;
        border-radius: 999px !important;
        border: 0 !important;
        color: #fff !important;
        background: var(--corp-blue) !important;
        box-shadow: 0 10px 24px rgba(0, 67, 109, .38) !important;
    }

    /* Debe ir después del FAB: con sheet de filtros abierto, ocultar menú */
    body.is-sidebar-open .app-topbar__menu,
    body.custodia-filtros-open .app-topbar__menu,
    body.custodia-registro-open .app-topbar__menu,
    body.transport-registro-open .app-topbar__menu,
    body.tens-pickup-filtros-open .app-topbar__menu,
    body.recibidas-custodia-filtros-open .app-topbar__menu,
    body.no-recibidas-custodia-filtros-open .app-topbar__menu,
    body.matrona-tracking-filtros-open .app-topbar__menu,
    body.matrona-retiradas-filtros-open .app-topbar__menu,
    body.matrona-trazabilidad-filtros-open .app-topbar__menu {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    .app-topbar__menu > span {
        display: none !important;
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
        font-size: 0;
        visibility: hidden;
    }

    .app-topbar__menu .bi {
        flex: 0 0 auto;
        font-size: 1.45rem;
        line-height: 1;
        color: #fff !important;
    }

    .is-private-app {
        padding-bottom: max(72px, calc(env(safe-area-inset-bottom, 0px) + 64px));
    }

    .is-private-app .app-workspace {
        padding-top: max(10px, env(safe-area-inset-top, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    .role-dashboard {
        gap: 10px;
        padding-bottom: 12px;
    }

    /* Hero: [icono] | centro madre centrado | CitoFlow — sin hueco para el menu */
    .role-dashboard__hero {
        grid-template-columns: auto minmax(0, 1fr) auto !important;
        align-items: center;
        gap: 6px 6px;
        padding: 6px 10px;
        min-height: 0;
    }

    .role-dashboard__identity {
        min-height: 0;
    }

    .role-dashboard__identity--left {
        padding-left: 0;
        justify-self: start;
    }

    .role-dashboard__identity--right {
        justify-self: end;
    }

    .role-dashboard__logo--disam {
        display: none !important;
    }

    .role-dashboard__logo--disam-icon {
        display: block !important;
        width: 30px;
        height: 30px;
        max-width: none;
        object-fit: contain;
    }

    .role-dashboard__logo--citoflow {
        width: 74px;
        max-width: none;
    }

    .role-dashboard__heading {
        grid-column: auto !important;
        grid-row: auto !important;
        justify-items: center;
        text-align: center;
        gap: 0;
        padding: 0 2px;
        min-width: 0;
    }

    .role-dashboard__eyebrow {
        font-size: .98rem;
        line-height: 1.1;
    }

    .role-dashboard__territorio {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: center;
        gap: 4px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: .7rem;
        line-height: 1.15;
        text-transform: none;
        color: #16364e;
        font-weight: 800;
    }

    .role-dashboard__territorio > .bi {
        display: inline-flex;
        flex: 0 0 auto;
        color: #9a2029;
        font-size: .74rem;
        line-height: 1;
    }

    .app-workspace,
    .public-main,
    .auth-access,
    .role-dashboard,
    .centro-operativo-panel {
        max-width: 100%;
        min-width: 0;
    }

    .form-control,
    .form-select,
    textarea,
    input[type="text"],
    input[type="password"],
    input[type="search"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="date"] {
        font-size: 16px;
        max-width: 100%;
    }

    .btn,
    button,
    [role="button"] {
        min-height: 40px;
    }

    table {
        max-width: 100%;
    }

    .table-responsive,
    .matrona-historial,
    .matrona-trazabilidad__listado-wrap,
    .custodia-board,
    .transport-board {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .swal2-popup {
        width: min(92vw, 32em) !important;
        padding: 1.1rem !important;
    }

    .swal2-html-container {
        max-width: 100%;
        overflow-x: auto;
    }
}

@media (max-width: 575px) {
    .auth-access {
        min-height: calc(100dvh - 72px);
        padding: 12px;
        place-items: start center;
    }

    .auth-access__shell {
        width: 100%;
        padding: 18px 16px 20px;
        box-shadow: 0 10px 24px rgba(35, 54, 68, .08);
    }

    .auth-access__header {
        gap: 10px;
        min-height: 0;
        padding-bottom: 14px;
    }

    .auth-access__content {
        padding-top: 18px;
    }

    .auth-access__content h1 {
        font-size: 1.55rem;
    }

    .auth-access__content p,
    .auth-access__form {
        margin-top: 14px;
    }

    .centro-operativo-panel__header {
        padding: 12px;
    }

    .centro-operativo-panel__header-actions {
        justify-items: stretch;
    }

    .centro-operativo-panel__icon-btn {
        width: 42px;
        height: 42px;
    }
}
