/**
 * Pluggerzz marketplace modal layering — mobile-safe overlays above footer/tabbar.
 * Used with public/js/pluggerzz-modal-layer.js and .pluggerzz-modal-mobile-safe modals.
 */

body.pluggerzz-modal-open,
body.plgz-offer-modal-open {
    overflow: hidden !important;
    touch-action: none;
    overscroll-behavior: none;
}

body.pluggerzz-modal-open footer.footer,
body.pluggerzz-modal-open .footer,
body.pluggerzz-modal-open .plgz-tabbar,
body.pluggerzz-modal-open .tabbar,
body.pluggerzz-modal-open .iq-navbar-header,
body.pluggerzz-modal-open .whatsapp-float,
body.pluggerzz-modal-open .wa-chat-btn,
body.pluggerzz-modal-open #back-to-top,
body.pluggerzz-modal-open .back-to-top,
body.plgz-offer-modal-open footer.footer,
body.plgz-offer-modal-open .footer,
body.plgz-offer-modal-open .plgz-tabbar,
body.plgz-offer-modal-open .tabbar {
    visibility: hidden !important;
    pointer-events: none !important;
}

body.pluggerzz-modal-open .modal-backdrop,
body.plgz-offer-modal-open .modal-backdrop {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1055 !important;
    background-color: rgba(0, 0, 0, 0.55);
}

body.pluggerzz-modal-open .modal-backdrop.show,
body.plgz-offer-modal-open .modal-backdrop.show {
    opacity: 1;
}

.pluggerzz-modal-mobile-safe,
.plgz-offer-modal-mobile-safe {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1060 !important;
    overflow: hidden !important;
    padding: 0 !important;
}

.pluggerzz-modal-mobile-safe.show,
.plgz-offer-modal-mobile-safe.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.pluggerzz-modal-mobile-safe .pluggerzz-modal-dialog,
.pluggerzz-modal-mobile-safe .plgz-offer-modal-dialog,
.plgz-offer-modal-mobile-safe .pluggerzz-modal-dialog,
.plgz-offer-modal-mobile-safe .plgz-offer-modal-dialog {
    margin: 0.5rem auto;
    max-width: 500px;
    width: calc(100% - 1rem);
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    display: flex;
    align-items: stretch;
}

.pluggerzz-modal-mobile-safe .pluggerzz-modal-content,
.pluggerzz-modal-mobile-safe .plgz-offer-modal-content,
.plgz-offer-modal-mobile-safe .pluggerzz-modal-content,
.plgz-offer-modal-mobile-safe .plgz-offer-modal-content,
.pluggerzz-modal-mobile-safe .modal-content:not(.pluggerzz-modal-content):not(.plgz-offer-modal-content) {
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px;
}

.pluggerzz-modal-mobile-safe .modal-header,
.plgz-offer-modal-mobile-safe .modal-header {
    flex-shrink: 0;
}

.pluggerzz-modal-mobile-safe .pluggerzz-modal-form,
.pluggerzz-modal-mobile-safe .plgz-offer-modal-form,
.plgz-offer-modal-mobile-safe .pluggerzz-modal-form,
.plgz-offer-modal-mobile-safe .plgz-offer-modal-form {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pluggerzz-modal-mobile-safe .pluggerzz-modal-body,
.pluggerzz-modal-mobile-safe .plgz-offer-modal-body,
.plgz-offer-modal-mobile-safe .pluggerzz-modal-body,
.plgz-offer-modal-mobile-safe .plgz-offer-modal-body,
.pluggerzz-modal-mobile-safe .modal-body:not(.pluggerzz-modal-body):not(.plgz-offer-modal-body) {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.pluggerzz-modal-mobile-safe .pluggerzz-modal-footer,
.pluggerzz-modal-mobile-safe .plgz-offer-modal-footer,
.plgz-offer-modal-mobile-safe .pluggerzz-modal-footer,
.plgz-offer-modal-mobile-safe .plgz-offer-modal-footer,
.pluggerzz-modal-mobile-safe .modal-footer:not(.pluggerzz-modal-footer):not(.plgz-offer-modal-footer) {
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    background: #fff;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

@media (max-width: 767.98px) {
    .pluggerzz-modal-mobile-safe .pluggerzz-modal-dialog,
    .pluggerzz-modal-mobile-safe .plgz-offer-modal-dialog,
    .plgz-offer-modal-mobile-safe .pluggerzz-modal-dialog,
    .plgz-offer-modal-mobile-safe .plgz-offer-modal-dialog {
        width: calc(100% - 1rem);
        max-width: none;
        margin: 0.5rem auto;
    }
}

/*
 * Logged-in mobile tabbar stacking — stay above site footers during normal scroll.
 * Hidden while modals are open (rules above). Tabbar sits below modal backdrop (1055).
 */
body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open):not(.plgz-chat-page) {
    padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important;
}

body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) .plgz-tabbar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1040 !important;
    padding-bottom: env(safe-area-inset-bottom);
}

body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) footer.footer,
body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) .footer,
body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) .iq-footer {
    position: relative !important;
    z-index: 1 !important;
}

@media (max-width: 991.98px) {
    body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) footer.footer,
    body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) .footer,
    body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) .iq-footer {
        margin-bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

/*
 * Job details panel (marketplace mobile offcanvas / desktop section) sits below tabbar.
 */
body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) #jobDetailsOffcanvas {
    z-index: 1030 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    height: auto !important;
    max-height: none !important;
}

body.plgz-has-tabbar:not(.pluggerzz-modal-open):not(.plgz-offer-modal-open) #jobDetailsSection {
    z-index: 1030 !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    max-height: calc(100dvh - 72px - env(safe-area-inset-bottom)) !important;
}

/* Full-screen chat pages manage their own layout; never show the workflow tabbar. */
body.plgz-chat-page .plgz-tabbar {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
