/*
 * Mobile shell (bottom nav + "Altro" sheet)
 * Attivo solo su viewport < 768px. Desktop invariato.
 */

#mobile-bottom-nav,
#mobile-nav-sheet {
    display: none;
}

@media (max-width: 767.98px) {
    /* Nasconde la sidebar desktop */
    #wrapper > nav.sidebar,
    #accordionSidebar {
        display: none !important;
    }

    /* Assicura spazio per la bottom nav */
    #content-wrapper,
    body {
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }

    /* === Bottom navigation === */
    #mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: calc(60px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--bs-body-bg, #ffffff);
        color: var(--bs-body-color, #171614);
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        z-index: 1040;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
    }

    [data-bs-theme="dark"] #mobile-bottom-nav {
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    #mobile-bottom-nav a,
    #mobile-bottom-nav button {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        font-size: 11px;
        font-weight: 500;
        text-decoration: none;
        color: inherit;
        background: transparent;
        border: 0;
        padding: 6px 2px;
        min-width: 0;
        cursor: pointer;
        opacity: 0.7;
        transition: opacity 0.15s, color 0.15s;
    }

    #mobile-bottom-nav a.active,
    #mobile-bottom-nav .active {
        color: var(--bs-primary, #8E09F9);
        opacity: 1;
    }

    #mobile-bottom-nav a:active,
    #mobile-bottom-nav button:active {
        opacity: 1;
    }

    #mobile-bottom-nav i {
        font-size: 18px;
        line-height: 1;
    }

    #mobile-bottom-nav span {
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    /* === "Altro" sheet === */
    #mobile-nav-sheet {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1060;
        pointer-events: none;
    }

    #mobile-nav-sheet .mns-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        transition: opacity 0.25s ease;
    }

    #mobile-nav-sheet .mns-content {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--bs-body-bg, #ffffff);
        color: var(--bs-body-color, #171614);
        border-radius: 20px 20px 0 0;
        padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
        transition: transform 0.3s ease;
        max-height: 75vh;
        overflow-y: auto;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    }

    #mobile-nav-sheet.open {
        pointer-events: auto;
    }

    #mobile-nav-sheet.open .mns-backdrop {
        opacity: 1;
    }

    #mobile-nav-sheet.open .mns-content {
        transform: translateY(0);
    }

    #mobile-nav-sheet .mns-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 16px;
    }

    #mobile-nav-sheet .mns-header h6 {
        margin: 0;
        font-weight: 700;
        font-size: 18px;
    }

    #mobile-nav-sheet .mns-close {
        border: 1px solid rgba(0, 0, 0, 0.1);
        background: transparent;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: inherit;
        cursor: pointer;
    }

    [data-bs-theme="dark"] #mobile-nav-sheet .mns-close {
        border-color: rgba(255, 255, 255, 0.15);
    }

    #mobile-nav-sheet .mns-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

    #mobile-nav-sheet .mns-grid a,
    #mobile-nav-sheet .mns-grid button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 16px 8px;
        border-radius: 12px;
        text-decoration: none;
        color: var(--bs-body-color, #171614);
        background: rgba(0, 0, 0, 0.03);
        border: 0;
        font-size: 12px;
        font-weight: 500;
        text-align: center;
        min-height: 92px;
        cursor: pointer;
        transition: background 0.15s;
    }

    [data-bs-theme="dark"] #mobile-nav-sheet .mns-grid a,
    [data-bs-theme="dark"] #mobile-nav-sheet .mns-grid button {
        background: rgba(255, 255, 255, 0.05);
    }

    #mobile-nav-sheet .mns-grid a:active,
    #mobile-nav-sheet .mns-grid button:active {
        background: rgba(var(--bs-primary-rgb, 142, 9, 249), 0.12);
    }

    #mobile-nav-sheet .mns-grid i {
        font-size: 22px;
        color: var(--bs-primary, #8E09F9);
    }

    #mobile-nav-sheet .mns-grid .mns-status-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #9ca3af;
        display: inline-block;
        margin-left: 4px;
    }

    #mobile-nav-sheet .mns-grid .mns-status-dot.on {
        background: #1cc88a;
    }

    /* Hide top navbar burger toggle (non serve più) */
    #sidebarToggleTop {
        display: none !important;
    }
}

/* === PWA install modal (works on all viewports) === */
.pwa-modal {
    border-radius: 16px;
    overflow: hidden;
    border: none;
}

.pwa-modal-header {
    background: linear-gradient(135deg, #8E09F9 0%, #5b009c 100%);
    color: #fff;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.pwa-modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 1.05rem;
}

.pwa-modal-logo {
    background: #fff;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.pwa-modal-body {
    padding: 0 !important;
    background: var(--bs-body-bg, #ffffff);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fallback se Bootstrap modal-dialog-scrollable non si applica */
@media (max-width: 767.98px) {
    .pwa-modal .modal-content {
        max-height: 92vh;
        display: flex;
        flex-direction: column;
    }
    .pwa-modal .pwa-modal-body {
        flex: 1 1 auto;
        min-height: 0;
    }
    .pwa-modal .pwa-modal-header,
    .pwa-modal .pwa-modal-footer {
        flex-shrink: 0;
    }
}

.pwa-intro {
    background: rgba(142, 9, 249, 0.06);
    border-bottom: 1px solid rgba(142, 9, 249, 0.14);
    padding: 16px 22px;
    color: #3a1057;
    line-height: 1.55;
}

[data-bs-theme="dark"] .pwa-intro {
    background: rgba(142, 9, 249, 0.14);
    color: #e6d4ff;
}

.pwa-now-wrap {
    padding: 18px 22px 0;
}

.pwa-now-btn {
    width: 100%;
    background: linear-gradient(135deg, #8E09F9 0%, #5b009c 100%);
    color: #fff;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 6px 16px rgba(142, 9, 249, 0.25);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.pwa-now-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(142, 9, 249, 0.25);
}

.pwa-now-hint {
    text-align: center;
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--bs-secondary-color, #6c757d);
}

.pwa-tabs {
    display: flex;
    gap: 6px;
    padding: 14px 22px 0;
    border: 0;
    flex-wrap: wrap;
}

.pwa-tabs .nav-link {
    background: rgba(142, 9, 249, 0.08);
    color: #5b009c;
    border: 1px solid rgba(142, 9, 249, 0.12);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

[data-bs-theme="dark"] .pwa-tabs .nav-link {
    background: rgba(142, 9, 249, 0.18);
    color: #e6d4ff;
    border-color: rgba(142, 9, 249, 0.3);
}

.pwa-tabs .nav-link.active {
    background: #8E09F9;
    color: #fff;
    border-color: #8E09F9;
}

.pwa-tab-content {
    display: none;
    padding: 8px 22px 0;
}

.pwa-tab-content.active {
    display: block;
}

.pwa-steps {
    position: relative;
    padding: 18px 0 8px;
}

.pwa-steps::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 32px;
    bottom: 32px;
    width: 2px;
    background: linear-gradient(180deg, #8E09F9 0%, rgba(142, 9, 249, 0.2) 100%);
}

.pwa-step {
    position: relative;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.pwa-step:last-child { margin-bottom: 0; }

.pwa-step-num {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #8E09F9;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 4px var(--bs-body-bg, #fff), 0 0 0 6px rgba(142, 9, 249, 0.14);
    font-size: 14px;
    z-index: 1;
    margin-left: 4px;
}

.pwa-step-body {
    flex: 1 1 auto;
    padding-top: 4px;
}

.pwa-step-title {
    font-weight: 600;
    color: var(--bs-body-color, #1f2d0f);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    margin-bottom: 4px;
}

.pwa-step-title i {
    color: #8E09F9;
    width: 18px;
    text-align: center;
}

.pwa-step-text {
    margin: 0;
    color: var(--bs-secondary-color, #495057);
    font-size: 13.5px;
    line-height: 1.55;
}

[data-bs-theme="dark"] .pwa-step-text {
    color: #adb5bd;
}

.pwa-tip {
    display: flex;
    gap: 12px;
    background: linear-gradient(135deg, rgba(142, 9, 249, 0.10) 0%, rgba(142, 9, 249, 0.03) 100%);
    border: 1px solid rgba(142, 9, 249, 0.18);
    border-radius: 12px;
    padding: 14px 16px;
    margin: 18px 22px 22px;
    color: #3a1057;
    font-size: 13.5px;
}

[data-bs-theme="dark"] .pwa-tip {
    color: #e6d4ff;
    border-color: rgba(142, 9, 249, 0.3);
}

.pwa-tip i {
    color: #8E09F9;
    font-size: 18px;
    margin-top: 2px;
    flex-shrink: 0;
}

.pwa-modal-footer {
    padding: 14px 22px 18px;
    background: rgba(142, 9, 249, 0.04);
    display: flex;
    justify-content: flex-end;
}

.pwa-close-btn {
    background: #8E09F9;
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 8px 20px;
    font-weight: 500;
    cursor: pointer;
}

.pwa-close-btn:hover { background: #7209d4; }
