:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --mobile-nav-height: 0px;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

.app-shell,
.login-body,
.login-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.app-side {
    padding-top: max(14px, var(--safe-top));
    padding-left: max(10px, var(--safe-left));
}

.app-top.app-top-enterprise {
    min-height: calc(50px + var(--safe-top));
    padding-top: var(--safe-top) !important;
    padding-right: max(12px, var(--safe-right)) !important;
    padding-left: max(12px, var(--safe-left)) !important;
}

.app-content {
    padding-right: max(var(--mainPadX), var(--safe-right));
    padding-bottom: max(var(--mainPadB), var(--safe-bottom));
    padding-left: max(var(--mainPadL), var(--safe-left));
}

.ios-install-help {
    position: fixed;
    z-index: 390000;
    right: max(14px, var(--safe-right));
    bottom: max(14px, var(--safe-bottom));
    left: max(14px, var(--safe-left));
    width: min(440px, calc(100% - 28px - var(--safe-left) - var(--safe-right)));
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 12px 12px 16px;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 16px;
    background: rgba(8, 20, 38, .96);
    color: #fff;
    box-shadow: 0 18px 44px rgba(0, 0, 0, .28);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.ios-install-help[hidden] {
    display: none !important;
}

.ios-install-help__text {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    line-height: 1.4;
}

.ios-install-help__text strong {
    color: #ffd24a;
}

.ios-install-help__close {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

@media (hover: none) and (pointer: coarse) {
    .side-link:hover,
    .top-icon-trigger:hover,
    .top-bell:hover {
        transform: none;
    }
}

@media (max-width: 640px) {
    :root {
        --mobile-nav-height: 62px;
    }

    .app-shell {
        display: block;
        min-height: 100dvh;
        padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom));
    }

    .app-shell .app-side,
    .app-shell .app-side.is-collapsed,
    body.leftbar-collapsed .app-shell .app-side {
        position: fixed;
        z-index: 350000;
        inset: auto 0 0 0;
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: calc(var(--mobile-nav-height) + var(--safe-bottom));
        padding: 4px max(4px, var(--safe-right)) var(--safe-bottom) max(4px, var(--safe-left)) !important;
        border-top: 1px solid rgba(255, 255, 255, .16);
        border-right: 0;
        overflow: hidden;
    }

    .app-side .side-brand,
    .app-side .side-foot {
        display: none !important;
    }

    .app-side .side-nav {
        height: var(--mobile-nav-height);
        margin: 0;
        display: flex;
        flex-direction: row;
        align-items: stretch;
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .app-side .side-nav::-webkit-scrollbar {
        display: none;
    }

    .app-side .side-nav .side-link,
    .app-side.is-collapsed .side-nav .side-link {
        flex: 1 0 62px;
        min-width: 62px;
        min-height: 54px;
        padding: 5px 3px !important;
        gap: 2px;
        border-radius: 10px;
    }

    .app-side .side-nav .ico-img,
    .app-side.is-collapsed .side-nav .ico-img {
        width: 26px;
        height: 26px;
        margin: 0;
    }

    .app-side .side-nav .side-link .txt {
        display: block !important;
        font-size: 9px;
        line-height: 1;
    }

    .app-main {
        width: 100%;
        min-width: 0;
    }

    .app-top.app-top-enterprise {
        min-height: calc(52px + var(--safe-top));
        margin-bottom: 6px;
        border-radius: 0 0 8px 8px;
        gap: 6px;
    }

    .top-left {
        gap: 6px;
    }

    .top-title {
        max-width: 110px;
        font-size: 12px;
    }

    .top-title-full {
        display: none;
    }

    .top-title-short {
        display: inline;
    }

    .top-right {
        gap: 3px;
    }

    .top-icon-trigger,
    .top-bell {
        min-width: 44px;
        min-height: 44px;
    }

    .top-bell {
        display: inline-grid;
        place-items: center;
        padding: 0;
        border: 0;
        background: transparent;
    }

    .top-user-dropdown,
    .top-tools-dropdown {
        position: fixed;
        top: calc(58px + var(--safe-top));
        right: max(8px, var(--safe-right));
        left: max(8px, var(--safe-left));
        width: auto;
        min-width: 0;
        max-height: calc(100dvh - 136px - var(--safe-top) - var(--safe-bottom));
        overflow-y: auto;
    }

    .app-content {
        padding-right: max(6px, var(--safe-right));
        padding-bottom: 6px;
        padding-left: max(6px, var(--safe-left));
        overflow-x: hidden;
    }

    .app-content table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    input,
    select,
    textarea,
    .login-input,
    .moni input,
    .moni select,
    .moni textarea {
        font-size: 16px !important;
    }

    button,
    [role="button"],
    .btn,
    .top-user-item {
        min-height: 44px;
    }

    .login-center {
        min-height: 100dvh;
        padding:
            max(20px, var(--safe-top))
            max(16px, var(--safe-right))
            max(20px, var(--safe-bottom))
            max(16px, var(--safe-left));
    }

    .login-card {
        max-width: 360px;
        padding: 22px 18px;
        border-radius: 22px;
    }

    .login-logo-img {
        max-width: 120px;
        max-height: 120px;
    }

    .ios-install-help {
        bottom: calc(var(--mobile-nav-height) + max(10px, var(--safe-bottom)));
        width: auto;
        margin: 0;
    }

    .login-body .ios-install-help {
        bottom: max(14px, var(--safe-bottom));
    }

    .moni {
        height: calc(100dvh - 124px - var(--safe-top) - var(--safe-bottom)) !important;
        min-height: 320px;
    }

    .moni .monitor-tabs {
        height: 44px;
        min-height: 44px;
        flex-basis: 44px;
    }

    .moni .tab-item {
        font-size: 12px;
        touch-action: manipulation;
    }

    .moni .monitor-wrap {
        position: relative;
        display: block !important;
        width: 100%;
        height: 100%;
    }

    .moni .monitor-map {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100% !important;
    }

    .moni .monitor-side {
        position: absolute;
        z-index: 5000;
        inset: 0 auto 0 0;
        width: min(86vw, 300px) !important;
        min-width: 0 !important;
        max-width: 300px !important;
        height: 100% !important;
        border-right: 1px solid rgba(15, 23, 42, .12);
        border-bottom: 0;
        box-shadow: 12px 0 28px rgba(15, 23, 42, .18);
    }

    .moni .monitor-wrap.slider-collapsed .monitor-side {
        width: 0 !important;
        max-width: 0 !important;
        box-shadow: none;
    }

    .moni .monitor-wrap.slider-collapsed .monitor-map {
        grid-column: auto;
    }

    .moni .moni-float-toggle {
        width: 44px;
        height: 44px;
    }

    .moni .leaflet-top.leaflet-right {
        top: 8px !important;
        right: max(8px, var(--safe-right)) !important;
    }

    .moni .leaflet-control-zoom a,
    .moni .leaflet-control-layers-toggle,
    .moni .traccar-btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    .moni .trk-popup-full .leaflet-popup-content,
    .moni .trk-popup-mini .leaflet-popup-content {
        min-width: 0 !important;
        width: min(280px, calc(100vw - 64px)) !important;
        max-width: calc(100vw - 64px) !important;
        margin: 14px !important;
    }

    .moni .history-dock {
        right: max(6px, var(--safe-right));
        bottom: max(6px, var(--safe-bottom));
        left: max(6px, var(--safe-left));
        max-height: 68%;
        overflow-y: auto;
    }

    .moni .live-info-dock,
    .moni #liveInfoDock {
        right: max(6px, var(--safe-right));
        bottom: max(6px, var(--safe-bottom));
        left: max(6px, var(--safe-left));
        width: auto;
        max-height: 58%;
        overflow-y: auto;
        flex-direction: column;
    }

    .moni .live-info-card,
    .moni #liveInfoDock .live-info-card {
        width: 100%;
        min-width: 0;
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .moni .float-win,
    .moni #editWindow,
    .moni .command-win {
        right: max(8px, var(--safe-right)) !important;
        left: max(8px, var(--safe-left)) !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100% - 16px) !important;
    }
}

@media (max-width: 380px) {
    .top-title {
        max-width: 90px;
        font-size: 11px;
    }

    .top-logo,
    .top-logo-fallback {
        width: 26px;
        height: 26px;
    }
}

/* En tablets, el panel de dispositivos debe ocupar toda la altura disponible.
   Evita la fila fija de 420 px que recortaba la lista dentro del mapa. */
@media (min-width: 641px) and (max-width: 1100px) {
    .moni .monitor-wrap {
        position: relative;
        display: block !important;
        width: 100%;
        height: 100%;
    }

    .moni .monitor-map {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100% !important;
    }

    .moni .monitor-side {
        position: absolute;
        z-index: 5000;
        inset: 0 auto 0 0;
        width: min(42vw, var(--mon-sideW)) !important;
        min-width: 280px !important;
        max-width: var(--mon-sideW) !important;
        height: 100% !important;
        min-height: 0;
        border-right: 1px solid rgba(15, 23, 42, .12);
        border-bottom: 0;
        box-shadow: 12px 0 28px rgba(15, 23, 42, .18);
    }

    .moni .monitor-wrap.slider-collapsed .monitor-side {
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        box-shadow: none;
    }

    .moni .monitor-wrap.slider-collapsed .monitor-map {
        grid-column: auto;
    }

    .moni #panelDevices,
    .moni #treeList {
        min-height: 0;
    }

    .moni #treeList {
        flex: 1 1 0;
        height: 0;
        overflow-y: auto;
    }
}
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --mobile-nav-height: 54px;
    }

    .app-side .side-nav {
        height: 54px;
    }

    .app-side .side-nav .side-link {
        min-height: 48px;
        flex-direction: row;
    }

    .moni {
        min-height: 220px;
    }
}
