/* Giao diện điều hướng khi chạy dạng app (PWA) trên điện thoại.
   Mọi rule đều nằm dưới html.pwa-ios-nav: class này được gắn sớm trong PwaHead.ascx
   và trong pwa-nav.js, nên web thường (desktop/mobile) không bị ảnh hưởng. */

html.pwa-ios-nav {
    --pwa-brand: #066fd1;
    --pwa-tab-inactive: #8e8e93;
    --pwa-badge: #ff3b30;
    --pwa-sheet-bg: #f2f2f7;
    --pwa-separator: rgba(60, 60, 67, .18);
    --pwa-appbar-height: 52px;
    --pwa-top-nav-height: calc(var(--pwa-appbar-height) + env(safe-area-inset-top, 0px));
    --pwa-ios-nav-height: calc(50px + env(safe-area-inset-bottom, 0px));
}

html.pwa-ios-nav body {
    padding-bottom: var(--pwa-ios-nav-height);
    box-sizing: border-box;
}

html.pwa-ios-nav .page-wrapper {
    padding-top: var(--pwa-top-nav-height);
}

/* ---------- Top App Bar ---------- */

html.pwa-ios-nav .navbar.sticky-top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1030;
    min-height: 0;
    height: var(--pwa-top-nav-height);
    padding: env(safe-area-inset-top, 0px) 0 0;
    border: 0;
    box-shadow: none;
    transition: box-shadow .2s ease;
}

html.pwa-ios-nav.pwa-scrolled .navbar.sticky-top {
    box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 6px 18px rgba(16, 24, 40, .16);
}

html.pwa-ios-nav.pwa-vv-shifted .navbar.sticky-top {
    transform: translate3d(0, var(--pwa-vv-offset, 0px), 0);
}

html.pwa-ios-nav .navbar.sticky-top > .container-xl {
    position: relative;
    height: var(--pwa-appbar-height);
    flex-wrap: nowrap;
    align-items: center;
    padding: 0 10px 0 4px;
}

html.pwa-ios-nav .navbar.sticky-top .navbar-toggler {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s ease, transform .12s ease;
}

    html.pwa-ios-nav .navbar.sticky-top .navbar-toggler:active {
        background: rgba(255, 255, 255, .16);
        transform: scale(.92);
    }

.pwa-appbar-title {
    display: none;
}

html.pwa-ios-nav .pwa-appbar-title {
    display: block;
    position: absolute;
    top: 0;
    left: 96px;
    right: 96px;
    height: var(--pwa-appbar-height);
    line-height: var(--pwa-appbar-height);
    margin: 0;
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -.2px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* Các icon đã chuyển sang tab bar hoặc menu sheet */
html.pwa-ios-nav .pwa-top-home,
html.pwa-ios-nav .pwa-top-visitcard,
html.pwa-ios-nav .pwa-top-search,
html.pwa-ios-nav .eoffice-app-dropdown {
    display: none !important;
}

/* Giữ nút chat trong DOM để tab "Tin nhắn" mở dropdown, nhưng không hiển thị */
html.pwa-ios-nav .pwa-top-chat {
    width: 0;
    min-width: 0;
    margin: 0 !important;
    overflow: visible;
}

    html.pwa-ios-nav .pwa-top-chat > a {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: -1px !important;
        padding: 0 !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        border: 0 !important;
        pointer-events: none;
    }

html.pwa-ios-nav .navbar.sticky-top > .container-xl > .navbar-nav {
    margin-left: auto;
    align-items: center;
}

html.pwa-ios-nav #eoffice-notify {
    margin-right: 6px !important;
}

    html.pwa-ios-nav #eoffice-notify > .nav-link {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        font-size: 15px;
        -webkit-tap-highlight-color: transparent;
    }

        html.pwa-ios-nav #eoffice-notify > .nav-link:active {
            background: rgba(255, 255, 255, .16);
        }

html.pwa-ios-nav #notification-count-badge {
    position: absolute;
    top: 5px !important;
    right: 3px !important;
    min-width: 18px;
    height: 18px;
    padding: 0 5px !important;
    border-radius: 9px;
    background: var(--pwa-badge) !important;
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px #1f63b0;
}

html.pwa-ios-nav .navbar.sticky-top [aria-label="Open user menu"] .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .6);
}

/* Dropdown thông báo bám theo chiều cao App Bar mới */
html.pwa-ios-nav #eoffice-notify .dropdown-menu > .card {
    top: var(--pwa-top-nav-height) !important;
    border-radius: 0 0 16px 16px;
    overflow: hidden;
}

html.pwa-ios-nav #eoffice-notify .tab-content {
    max-height: calc(100dvh - var(--pwa-top-nav-height) - var(--pwa-ios-nav-height) - 130px) !important;
}

@media (max-width: 768px) {
    html.pwa-ios-nav .eoffice-chat-navbar-panel {
        inset: var(--pwa-top-nav-height) 0 auto 0 !important;
    }
}

/* ---------- Menu dạng bottom sheet ---------- */

.pwa-sheet-backdrop {
    display: none;
}

html.pwa-ios-nav .pwa-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1;
    background: rgba(0, 0, 0, .4);
    opacity: 0;
    pointer-events: none;
    touch-action: none;
    transition: opacity .3s ease;
}

html.pwa-sheet-open .pwa-sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
}

html.pwa-sheet-open .navbar.sticky-top {
    z-index: 2147483003;
    transform: none !important;
}

html.pwa-sheet-open body {
    overflow: hidden;
}

html.pwa-ios-nav #navbar-menu {
    display: block !important;
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    max-height: 88dvh;
    height: auto;
    margin: 0;
    padding: 0 0 calc(16px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: var(--pwa-sheet-bg);
    color: #1d1d1f;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .22);
    transform: translate3d(0, 105%, 0);
    visibility: hidden;
    transition: transform .34s cubic-bezier(.32, .72, 0, 1), visibility 0s linear .34s;
}

html.pwa-sheet-open #navbar-menu {
    transform: translate3d(0, 0, 0);
    visibility: visible;
    transition: transform .34s cubic-bezier(.32, .72, 0, 1), visibility 0s;
}

html.pwa-ios-nav #navbar-menu.is-dragging {
    transition: none;
}

.pwa-sheet-top,
.pwa-sheet-account,
.pwa-sheet-section,
.pwa-sheet-apps,
.pwa-sheet-list {
    display: none;
}

html.pwa-ios-nav .pwa-sheet-top {
    display: block;
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 6px 16px 4px;
    background: var(--pwa-sheet-bg);
}

html.pwa-ios-nav .pwa-sheet-grabber {
    width: 36px;
    height: 5px;
    margin: 0 auto 6px;
    border-radius: 3px;
    background: rgba(60, 60, 67, .3);
}

html.pwa-ios-nav .pwa-sheet-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
}

    html.pwa-ios-nav .pwa-sheet-titlebar strong {
        font-size: 20px;
        font-weight: 700;
        letter-spacing: -.3px;
    }

html.pwa-ios-nav .pwa-sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(118, 118, 128, .14);
    color: #636366;
    -webkit-tap-highlight-color: transparent;
}

html.pwa-ios-nav .pwa-sheet-account {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 16px 0;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fff;
    color: inherit;
    text-decoration: none;
}

    html.pwa-ios-nav .pwa-sheet-account img {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        object-fit: cover;
        flex-shrink: 0;
    }

    html.pwa-ios-nav .pwa-sheet-account-text {
        flex: 1;
        min-width: 0;
    }

        html.pwa-ios-nav .pwa-sheet-account-text b {
            display: block;
            font-size: 16px;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        html.pwa-ios-nav .pwa-sheet-account-text small {
            display: block;
            margin-top: 2px;
            color: #6e6e73;
            font-size: 13px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

html.pwa-ios-nav .pwa-sheet-section {
    display: block;
    margin: 18px 32px 6px;
    color: #6e6e73;
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .2px;
}

html.pwa-ios-nav .pwa-sheet-apps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin: 0 16px;
    padding: 12px 6px 8px;
    border-radius: 12px;
    background: #fff;
}

html.pwa-ios-nav .pwa-sheet-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 4px 2px 6px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #1d1d1f;
    font-family: inherit;
    text-align: center;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s ease, opacity .12s ease;
}

    html.pwa-ios-nav .pwa-sheet-app:active {
        transform: scale(.92);
        opacity: .7;
    }

html.pwa-ios-nav .pwa-sheet-app-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(160deg, #2f8cf0, #0a5fc2);
    color: #fff;
    font-size: 20px;
    box-shadow: 0 2px 6px rgba(6, 111, 209, .28);
}

    html.pwa-ios-nav .pwa-sheet-app-icon i {
        margin: 0 !important;
        font-size: 20px;
    }

html.pwa-ios-nav .pwa-sheet-app-label {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.25;
}

/* Danh sách chức năng: kiểu inset grouped list của iOS */
html.pwa-ios-nav #navbar-menu > .d-flex {
    display: block !important;
}

html.pwa-ios-nav #navbar-menu .navbar-nav,
html.pwa-ios-nav .pwa-sheet-list {
    display: block;
    margin: 0 16px;
    padding: 0;
    list-style: none;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

    html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item,
    html.pwa-ios-nav .pwa-sheet-list > li {
        position: relative;
        margin: 0;
    }

        html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item + .nav-item::before,
        html.pwa-ios-nav .pwa-sheet-list > li + li::before {
            content: "";
            position: absolute;
            top: 0;
            left: 58px;
            right: 0;
            border-top: .5px solid var(--pwa-separator);
        }

        html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item.pwa-sheet-hidden,
        html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item.hidden {
            display: none;
        }

        html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item > .nav-link,
        html.pwa-ios-nav .pwa-sheet-list > li > a {
            display: flex !important;
            align-items: center;
            justify-content: flex-start !important;
            gap: 0;
            min-height: 50px;
            padding: 0 16px 0 14px;
            color: #1d1d1f !important;
            font-size: 16px;
            font-weight: 500;
            text-decoration: none;
            -webkit-tap-highlight-color: transparent;
        }

            html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item > .nav-link:active,
            html.pwa-ios-nav .pwa-sheet-list > li > a:active {
                background: #e5e5ea;
            }

            html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item > .nav-link > span:first-child,
            html.pwa-ios-nav .pwa-sheet-list .pwa-sheet-list-icon {
                display: inline-flex !important;
                align-items: center;
                justify-content: center;
                flex-shrink: 0;
                width: 30px;
                height: 30px;
                margin-right: 14px;
                border-radius: 8px;
                background: var(--pwa-brand);
                color: #fff;
                font-size: 14px;
            }

                html.pwa-ios-nav #navbar-menu .navbar-nav > .nav-item > .nav-link > span:first-child i {
                    margin: 0 !important;
                }

            html.pwa-ios-nav #navbar-menu .navbar-nav .nav-link-title {
                flex: 1;
                min-width: 0;
                white-space: normal;
            }

html.pwa-ios-nav .pwa-sheet-list .pwa-sheet-list-icon.is-muted {
    background: #8e8e93;
}

html.pwa-ios-nav .pwa-sheet-list .pwa-sheet-list-icon.is-danger {
    background: var(--pwa-badge);
}

html.pwa-ios-nav .pwa-sheet-list > li > a.is-danger {
    color: var(--pwa-badge) !important;
}

/* Chevron kiểu iOS thay cho caret của Bootstrap */
html.pwa-ios-nav #navbar-menu .dropdown-toggle::after {
    content: "";
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin: 0 4px 0 auto;
    border: solid #c7c7cc;
    border-width: 0 2px 2px 0;
    transform: rotate(-45deg);
    transition: transform .2s ease;
}

html.pwa-ios-nav #navbar-menu .dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(45deg);
}

html.pwa-ios-nav #navbar-menu .dropdown-menu {
    position: static !important;
    float: none;
    min-width: 0;
    margin: 0 !important;
    padding: 2px 0 8px;
    border: 0;
    border-radius: 0;
    background: #f7f7fa;
    box-shadow: none;
    transform: none !important;
    inset: auto !important;
}

    html.pwa-ios-nav #navbar-menu .dropdown-menu .dropdown-menu {
        padding-left: 16px;
        background: #efeff4;
    }

html.pwa-ios-nav #navbar-menu .dropdown-menu-columns {
    display: block;
}

html.pwa-ios-nav #navbar-menu .dropdown-menu-column {
    min-width: 0;
}

html.pwa-ios-nav #navbar-menu .dropdown-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 8px 16px 8px 58px;
    color: #1d1d1f !important;
    font-size: 15px;
    white-space: normal;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}

    html.pwa-ios-nav #navbar-menu .dropdown-item:active,
    html.pwa-ios-nav #navbar-menu .dropdown-item:hover {
        background: #e5e5ea;
    }

    html.pwa-ios-nav #navbar-menu .dropdown-item > i:first-child {
        flex-shrink: 0;
        width: 20px;
        margin-right: 10px !important;
        color: var(--pwa-brand);
        text-align: center;
    }

html.pwa-ios-nav #navbar-menu .dropdown-divider {
    margin: 4px 16px 4px 58px;
    border-color: var(--pwa-separator);
}

/* ---------- Bottom tab bar kiểu iOS (kính mờ) ---------- */

.pwa-ios-nav-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2147483001;
    display: flex;
    align-items: stretch;
    height: var(--pwa-ios-nav-height);
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    background: rgba(249, 249, 251, .78);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: .5px solid rgba(60, 60, 67, .29);
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .pwa-ios-nav-bar {
        background: #f9f9fb;
    }
}

    .pwa-ios-nav-bar button {
        flex: 1;
        appearance: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 1px;
        min-width: 0;
        padding: 5px 2px 0;
        border: 0;
        background: transparent;
        color: var(--pwa-tab-inactive, #8e8e93);
        font-family: inherit;
        font-size: 10px;
        font-weight: 500;
        line-height: 1.2;
        letter-spacing: .1px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: opacity .12s ease, color .15s ease;
    }

        .pwa-ios-nav-bar button:active {
            opacity: .7;
        }

        .pwa-ios-nav-bar button.is-active {
            color: var(--pwa-brand, #066fd1);
        }

        .pwa-ios-nav-bar button.is-disabled {
            opacity: .4;
        }

    .pwa-ios-nav-bar .pwa-ios-nav-icon {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 28px;
        transition: transform .12s ease;
    }

    .pwa-ios-nav-bar button:active .pwa-ios-nav-icon {
        transform: scale(.88);
    }

    .pwa-ios-nav-bar svg {
        display: block;
        flex-shrink: 0;
    }

    .pwa-ios-nav-bar .pwa-tab-ico-on {
        display: none;
    }

    .pwa-ios-nav-bar button.is-active .pwa-tab-ico-on {
        display: block;
    }

    .pwa-ios-nav-bar button.is-active .pwa-tab-ico-off {
        display: none;
    }

.pwa-ios-nav-badge {
    display: none;
    position: absolute;
    top: -3px;
    left: 18px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--pwa-badge, #ff3b30);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px #f9f9fb;
}

/* ---------- Các thành phần khác bám theo thanh điều hướng ---------- */

html.pwa-ios-nav .eoffice-loader {
    bottom: var(--pwa-ios-nav-height);
    height: auto;
    min-height: 0;
}

html.pwa-ios-nav-keyboard .eoffice-loader {
    bottom: 0;
}

html.pwa-ios-nav .eoffice-messenger {
    bottom: calc(16px + var(--pwa-ios-nav-height));
    max-height: calc(100dvh - 80px - var(--pwa-ios-nav-height));
}

html.pwa-ios-nav .eoffice-chat-composer {
    padding-bottom: 0;
}

html.pwa-ios-nav body:has(#eoffice-chat-page) {
    padding-bottom: 0;
}

    html.pwa-ios-nav body:has(#eoffice-chat-page) .wrapper,
    html.pwa-ios-nav body:has(#eoffice-chat-page) #form1 {
        height: calc(100dvh - var(--pwa-ios-nav-height));
    }

html.pwa-ios-nav .toastify-bottom {
    bottom: calc(12px + var(--pwa-ios-nav-height)) !important;
}

html.pwa-ios-nav .air-datepicker,
html.pwa-ios-nav .air-datepicker-global-container {
    z-index: 2147483002 !important;
}

html.pwa-ios-nav-keyboard .pwa-ios-nav-bar {
    display: none;
}

html.pwa-ios-nav-keyboard body {
    padding-bottom: 0;
}

    html.pwa-ios-nav-keyboard body:has(#eoffice-chat-page) .wrapper,
    html.pwa-ios-nav-keyboard body:has(#eoffice-chat-page) #form1 {
        height: 100dvh;
    }

@media (max-width: 768px) {
    html.pwa-ios-nav .eoffice-messenger {
        bottom: var(--pwa-ios-nav-height);
        height: calc(100dvh - var(--pwa-ios-nav-height));
        max-height: calc(100dvh - var(--pwa-ios-nav-height));
    }

    html.pwa-ios-nav-keyboard .eoffice-messenger {
        bottom: 0;
        height: 100dvh;
        max-height: 100dvh;
    }
}

@media print {
    .pwa-ios-nav-bar,
    .pwa-sheet-backdrop {
        display: none !important;
    }

    html.pwa-ios-nav body {
        padding-bottom: 0;
    }
}
