/**
 * Navegação mobile unificada (abaixo de 992px).
 * Cabeçalho compacto, gaveta lateral, busca em tela cheia e barra inferior.
 * Só é carregado quando a opção está ligada no admin.
 */

:root {
    --pnav-green: #1a5943;
    --pnav-green-2: #2d7a5f;
    --pnav-leaf: #4a8f4d;
    --pnav-fg: #1d2a24;
    --pnav-muted: #66756e;
    --pnav-line: #e3e9e6;
    --pnav-soft: #eef5f1;
    --pnav-red: #dc3545;
    --pnav-header-h: 56px;
    --pnav-tabbar-h: 62px;
    --pnav-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Desktop: nada da navegação mobile aparece */
.pnav-header,
.pnav-spacer,
.pnav-scrim,
.pnav-drawer,
.pnav-search,
.pnav-sheet,
.pnav-tabbar,
.pnav-toast,
.pnav-actions,
.pnav-filterbar,
.pnav-filter-sheet > .pnav-handle {
    display: none;
}

@media (max-width: 991.98px) {
    .pnav-actions {
        display: block;
    }
}

@media (max-width: 991.98px) {

    /* ---------- Esconder cabeçalhos antigos ---------- */
    body.pnav-on > header.main-header,
    body.pnav-on > nav.navbar-main,
    body.pnav-on > header.site-header > .header-top,
    body.pnav-on > header.site-header > nav.navbar-main,
    body.pnav-on #mobileAccountMenu {
        display: none !important;
    }
    /* Regra separada: navegador sem suporte a :has() descarta só esta */
    body.pnav-on > header.header:not(:has(> .right-buttons)) {
        display: none !important;
    }

    /* Páginas de post: o cabeçalho antigo vira só a faixa Curtir/Salvar/Compartilhar */
    body.pnav-on > header.header {
        background: #fff;
        padding: 8px 12px;
        gap: 0;
        border-bottom: 1px solid var(--pnav-line);
        flex-direction: row;
    }
    body.pnav-on > header.header > :not(.right-buttons) {
        display: none !important;
    }
    body.pnav-on > header.header > .right-buttons {
        order: 0;
        width: 100%;
        margin: 0;
        gap: 6px;
        justify-content: space-between;
    }
    body.pnav-on > header.header .action-btn {
        flex: 1;
        justify-content: center;
        min-height: 44px;
        padding: 8px 6px;
        font-size: 13.5px;
        background: transparent;
        border: 0;
        box-shadow: none;
        color: var(--pnav-fg);
    }
    body.pnav-on > header.header .action-btn:active {
        background: var(--pnav-soft);
    }
    body.pnav-on > header.header .share-wrapper {
        position: relative;
        flex: 1;
        display: flex;
    }
    body.pnav-on > header.header .share-dropdown {
        transform: none; /* post_page.css sobe 10px e cobria o cabeçalho novo */
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }

    /* peticoes_header: o restante (breadcrumb) deixa de ser fixo */
    body.pnav-on > header.site-header {
        position: static !important;
        box-shadow: none;
    }
    body.pnav-on > header.site-header:empty {
        display: none;
    }

    /* Compensações que as páginas faziam para o cabeçalho fixo antigo */
    body.pnav-on .container.my-5 {
        margin-top: 1.5rem !important;
    }

    /* ---------- Cabeçalho compacto ---------- */
    .pnav-header {
        display: flex;
        align-items: center;
        gap: 2px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1040;
        height: calc(var(--pnav-header-h) + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 6px 0;
        background: linear-gradient(135deg, var(--pnav-green) 0%, var(--pnav-green-2) 100%);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
        transition: transform 0.22s ease;
        will-change: transform;
    }
    .pnav-header.is-hidden {
        transform: translateY(-100%);
    }
    .pnav-spacer {
        display: block;
        height: calc(var(--pnav-header-h) + env(safe-area-inset-top, 0px));
    }

    .pnav-logo {
        flex: 1;
        display: flex;
        align-items: center;
        min-width: 0;
        padding-left: 2px;
    }
    .pnav-logo img {
        height: 30px;
        width: auto;
        display: block;
    }

    .pnav-ibtn {
        position: relative;
        width: 44px;
        height: 44px;
        flex: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 12px;
        background: transparent;
        color: #fff;
        font-size: 24px;
        line-height: 1;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .pnav-ibtn:hover,
    .pnav-ibtn:focus {
        color: #fff;
        text-decoration: none;
    }
    .pnav-ibtn:active {
        background: rgba(255, 255, 255, 0.15);
    }
    .pnav-ibtn:focus-visible {
        outline: 2px solid #fff;
        outline-offset: -3px;
    }

    .pnav-badge {
        position: absolute;
        top: 4px;
        right: 2px;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: var(--pnav-red);
        color: #fff;
        font: 700 11px/18px -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
        text-align: center;
        border: 2px solid var(--pnav-green);
        box-sizing: content-box;
    }
    .pnav-badge[hidden] {
        display: none;
    }
    .pnav-badge.is-pop {
        animation: pnav-pop 0.45s;
    }
    @keyframes pnav-pop {
        40% { transform: scale(1.35); }
    }

    /* ---------- Overlay ---------- */
    .pnav-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1050;
        background: rgba(8, 20, 14, 0.5);
        opacity: 0;
        transition: opacity 0.25s;
    }
    .pnav-scrim.is-open {
        opacity: 1;
    }
    .pnav-scrim[hidden] {
        display: none;
    }

    /* ---------- Gaveta ---------- */
    .pnav-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1060;
        width: 86%;
        max-width: 340px;
        background: #fff;
        color: var(--pnav-fg);
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.18);
        transform: translateX(-102%);
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
        padding-bottom: var(--pnav-safe-bottom);
        font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    }
    .pnav-drawer.is-open {
        transform: none;
    }
    .pnav-drawer.is-dragging {
        transition: none;
    }
    .pnav-drawer[hidden] {
        display: none;
    }

    .pnav-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: calc(8px + env(safe-area-inset-top, 0px)) 6px 8px 16px;
        background: linear-gradient(135deg, var(--pnav-green) 0%, var(--pnav-green-2) 100%);
    }
    .pnav-drawer-head img {
        height: 30px;
        width: auto;
    }

    .pnav-account {
        display: grid;
        gap: 10px;
        padding: 14px 16px;
        background: #f4f8f6;
        border-bottom: 1px solid var(--pnav-line);
    }
    .pnav-account p,
    .pnav-sheet p {
        margin: 0;
        font-size: 13.5px;
        color: var(--pnav-muted);
    }
    .pnav-account-btns {
        display: flex;
        gap: 8px;
    }
    .pnav-btn {
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: 44px;
        border-radius: 12px;
        font-weight: 700;
        font-size: 15px;
        text-decoration: none;
    }
    .pnav-btn-primary,
    .pnav-btn-primary:hover {
        background: var(--pnav-leaf);
        color: #fff;
        text-decoration: none;
    }
    .pnav-btn-outline,
    .pnav-btn-outline:hover {
        background: #fff;
        color: var(--pnav-green);
        border: 1.5px solid var(--pnav-green);
        text-decoration: none;
    }

    .pnav-who {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    .pnav-who strong {
        display: block;
        font-size: 15px;
    }
    .pnav-who small {
        display: block;
        font-size: 12px;
        color: var(--pnav-muted);
    }
    .pnav-avatar {
        width: 40px;
        height: 40px;
        flex: none;
        border-radius: 50%;
        background: var(--pnav-green);
        color: #fff;
        display: grid;
        place-items: center;
        font-weight: 800;
    }

    .pnav-drawer-body {
        flex: 1;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: 4px 0 16px;
    }
    .pnav-label {
        padding: 14px 18px 6px;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--pnav-muted);
    }
    .pnav-link {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        min-height: 48px;
        padding: 0 18px;
        border: 0;
        background: transparent;
        color: var(--pnav-fg);
        font-size: 15.5px;
        font-weight: 500;
        text-align: left;
        text-decoration: none;
        cursor: pointer;
    }
    .pnav-link:hover {
        color: var(--pnav-green);
        text-decoration: none;
    }
    .pnav-link:active,
    .pnav-link:focus-visible {
        background: var(--pnav-soft);
        outline: none;
    }
    .pnav-link > .bi:first-child {
        width: 22px;
        font-size: 20px;
        color: var(--pnav-green-2);
        text-align: center;
        flex: none;
    }
    .pnav-link.is-active {
        color: var(--pnav-green);
        font-weight: 700;
        background: var(--pnav-soft);
        box-shadow: inset 3px 0 0 var(--pnav-green);
    }
    .pnav-link-muted {
        color: var(--pnav-muted);
    }
    .pnav-chev {
        margin-left: auto;
        font-size: 14px;
        color: var(--pnav-muted);
        transition: transform 0.2s;
    }
    .pnav-link[aria-expanded="true"] .pnav-chev {
        transform: rotate(180deg);
    }

    .pnav-sub {
        display: grid;
        grid-template-rows: 0fr;
        transition: grid-template-rows 0.25s;
    }
    .pnav-sub.is-open {
        grid-template-rows: 1fr;
    }
    .pnav-sub > div {
        overflow: hidden;
    }
    .pnav-sub a {
        display: flex;
        align-items: center;
        min-height: 42px;
        padding: 0 18px 0 54px;
        color: var(--pnav-fg);
        font-size: 14.5px;
        text-decoration: none;
    }
    .pnav-sub a:active {
        background: var(--pnav-soft);
    }
    .pnav-sub a.pnav-sub-all {
        color: var(--pnav-green-2);
        font-weight: 600;
    }

    .pnav-drawer-foot {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 14px;
        padding: 12px 18px;
        border-top: 1px solid var(--pnav-line);
        font-size: 13px;
    }
    .pnav-drawer-foot a {
        color: var(--pnav-muted);
        padding: 6px 0;
    }

    /* ---------- Busca ---------- */
    .pnav-search {
        display: flex;
        flex-direction: column;
        position: fixed;
        inset: 0;
        z-index: 1070;
        background: #fff;
        color: var(--pnav-fg);
        opacity: 0;
        transform: translateY(12px);
        transition: opacity 0.2s, transform 0.2s;
        padding-top: env(safe-area-inset-top, 0px);
    }
    .pnav-search.is-open {
        opacity: 1;
        transform: none;
    }
    .pnav-search[hidden] {
        display: none;
    }
    .pnav-search-top {
        display: flex;
        align-items: center;
        gap: 4px;
        margin: 0;
        padding: 8px 6px 8px 4px;
        border-bottom: 1px solid var(--pnav-line);
    }
    .pnav-search-top .pnav-ibtn {
        color: var(--pnav-fg);
        font-size: 22px;
    }
    .pnav-search-top .pnav-search-go {
        background: var(--pnav-leaf);
        color: #fff;
        border-radius: 50%;
        font-size: 18px;
    }
    .pnav-search-top input {
        flex: 1;
        min-width: 0;
        height: 44px;
        padding: 0 16px;
        border: 0;
        border-radius: 22px;
        outline: 0;
        background: #f1f5f3;
        color: var(--pnav-fg);
        font-size: 16px; /* 16px evita o zoom automático do iOS */
        -webkit-appearance: none;
    }
    .pnav-search-top input:focus {
        box-shadow: 0 0 0 2px var(--pnav-leaf);
    }
    .pnav-seg {
        display: flex;
        gap: 6px;
        padding: 12px 16px 4px;
    }
    .pnav-chip {
        flex: none;
        display: inline-flex;
        align-items: center;
        height: 36px;
        padding: 0 14px;
        border: 1px solid var(--pnav-line);
        border-radius: 18px;
        background: #fff;
        color: var(--pnav-green);
        font-size: 14px;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        white-space: nowrap;
    }
    .pnav-chip[aria-pressed="true"] {
        background: var(--pnav-green);
        border-color: var(--pnav-green);
        color: #fff;
    }
    .pnav-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding: 4px 16px 8px;
    }
    .pnav-search-body {
        flex: 1;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 4px 0 calc(16px + var(--pnav-safe-bottom));
    }
    .pnav-result {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 52px;
        padding: 8px 16px;
        border-bottom: 1px solid #f0f3f1;
        color: var(--pnav-fg);
        font-size: 15px;
        line-height: 1.35;
        text-decoration: none;
    }
    .pnav-result:hover {
        color: var(--pnav-green);
        text-decoration: none;
    }
    .pnav-result:active {
        background: var(--pnav-soft);
    }
    .pnav-result > .bi {
        flex: none;
        color: var(--pnav-muted);
        font-size: 17px;
    }
    .pnav-result span {
        flex: 1;
        min-width: 0;
    }
    .pnav-result small {
        flex: none;
        color: var(--pnav-green);
        font-weight: 700;
        font-size: 13px;
    }
    .pnav-result mark {
        padding: 0 1px;
        border-radius: 3px;
        background: #dff0e6;
        color: inherit;
    }
    .pnav-result-all {
        justify-content: center;
        color: var(--pnav-green-2);
        font-weight: 700;
    }
    .pnav-empty {
        padding: 28px 20px;
        text-align: center;
        color: var(--pnav-muted);
        font-size: 14px;
    }

    /* ---------- Folha inferior (conta) ---------- */
    .pnav-sheet {
        display: grid;
        gap: 12px;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1060;
        max-height: 80vh;
        overflow-y: auto;
        padding: 8px 16px calc(20px + var(--pnav-safe-bottom));
        border-radius: 22px 22px 0 0;
        background: #fff;
        color: var(--pnav-fg);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
        transform: translateY(105%);
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    .pnav-sheet.is-open {
        transform: none;
    }
    .pnav-sheet[hidden] {
        display: none;
    }
    .pnav-handle {
        width: 44px;
        height: 5px;
        margin: 4px auto 2px;
        padding: 0;
        border: 0;
        border-radius: 3px;
        background: #cfd8d3;
        cursor: pointer;
    }
    .pnav-sheet-title {
        margin: 0;
        font-size: 18px;
        font-weight: 700;
    }
    .pnav-sheet-links .pnav-link {
        padding: 0 4px;
    }

    /* ---------- Barra inferior ---------- */
    body.pnav-has-tabbar {
        padding-bottom: calc(var(--pnav-tabbar-h) + var(--pnav-safe-bottom));
    }
    .pnav-tabbar {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1040;
        height: calc(var(--pnav-tabbar-h) + var(--pnav-safe-bottom));
        padding-bottom: var(--pnav-safe-bottom);
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid var(--pnav-line);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    }
    @supports (backdrop-filter: blur(8px)) {
        .pnav-tabbar {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(8px);
        }
    }
    .pnav-tab {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: 0;
        background: transparent;
        color: var(--pnav-muted);
        font-size: 11px;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .pnav-tab:hover {
        color: var(--pnav-green);
        text-decoration: none;
    }
    .pnav-tab .bi {
        font-size: 22px;
        line-height: 1;
    }
    .pnav-tab[aria-current="page"] {
        color: var(--pnav-green);
    }
    .pnav-tab[aria-current="page"]::before {
        content: "";
        position: absolute;
        top: 0;
        width: 28px;
        height: 3px;
        border-radius: 0 0 3px 3px;
        background: var(--pnav-green);
    }
    .pnav-tab .pnav-badge {
        top: 5px;
        right: calc(50% - 24px);
        border-color: #fff;
    }

    /* Elementos flutuantes do site sobem acima da barra inferior */
    body.pnav-has-tabbar .music-player,
    body.pnav-has-tabbar .expand-tab {
        bottom: calc(var(--pnav-tabbar-h) + var(--pnav-safe-bottom)) !important;
    }

    /* ---------- Toast ---------- */
    .pnav-toast {
        display: block;
        position: fixed;
        left: 16px;
        right: 16px;
        bottom: calc(16px + var(--pnav-safe-bottom));
        z-index: 1080;
        padding: 12px 14px;
        border-radius: 12px;
        background: #14261e;
        color: #fff;
        font-size: 14px;
        opacity: 0;
        transform: translateY(20px);
        transition: opacity 0.25s, transform 0.25s;
        pointer-events: none;
    }
    body.pnav-has-tabbar .pnav-toast {
        bottom: calc(var(--pnav-tabbar-h) + 12px + var(--pnav-safe-bottom));
    }
    .pnav-toast.is-on {
        opacity: 1;
        transform: none;
    }

    /* ---------- Breadcrumb em uma linha ---------- */
    body.pnav-on nav[aria-label="breadcrumb"].my-3 {
        margin-top: 10px !important;
        margin-bottom: 10px !important;
    }
    body.pnav-on .breadcrumb {
        flex-wrap: nowrap;
        align-items: center;
        margin-bottom: 0;
        overflow: hidden;
        font-size: 13px;
        white-space: nowrap;
    }
    body.pnav-on .breadcrumb-item {
        flex: none;
    }
    body.pnav-on .breadcrumb-item:last-child {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    body.pnav-on .breadcrumb-item:first-child a {
        padding: 6px 10px;
        gap: 6px;
        font-size: 13px;
    }
    body.pnav-on .breadcrumb-item:first-child a .bi-house-door {
        font-size: 15px;
    }

    /* ---------- Ações do artigo abaixo do título ---------- */
    .pnav-actions {
        margin: 12px 0 16px;
        border-top: 1px solid var(--pnav-line);
        border-bottom: 1px solid var(--pnav-line);
    }
    .pnav-actions .right-buttons {
        display: flex;
        width: 100%;
        margin: 0;
        padding: 4px 0;
        gap: 4px;
        justify-content: space-between;
    }
    .pnav-actions .action-btn {
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 44px;
        padding: 8px 4px;
        border: 0;
        border-radius: 10px;
        background: transparent;
        box-shadow: none;
        color: var(--pnav-fg);
        font-size: 14px;
        font-weight: 600;
    }
    .pnav-actions .action-btn:active {
        background: var(--pnav-soft);
    }
    .pnav-actions .share-wrapper {
        position: relative;
        flex: 1;
        display: flex;
    }
    .pnav-actions .share-dropdown {
        transform: none;
        max-height: calc(100vh - 140px);
        overflow-y: auto;
    }

    /* ---------- Filtros em folha inferior ---------- */
    .pnav-filterbar {
        display: flex;
        gap: 8px;
        margin: 16px 0;
    }
    .pnav-filterbtn {
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 46px;
        border: 1.5px solid var(--pnav-green);
        border-radius: 12px;
        background: #fff;
        color: var(--pnav-green);
        font-size: 15px;
        font-weight: 700;
    }
    .pnav-fcount {
        min-width: 20px;
        height: 20px;
        padding: 0 6px;
        border-radius: 10px;
        background: var(--pnav-green);
        color: #fff;
        font-size: 12px;
        line-height: 20px;
    }
    .pnav-fcount[hidden] {
        display: none;
    }
    body.pnav-on .filters-section.pnav-filter-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1060;
        max-height: 85vh;
        margin: 0;
        padding: 8px 16px calc(20px + var(--pnav-safe-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: 22px 22px 0 0;
        background: #fff;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
        transform: translateY(105%);
        visibility: hidden;
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
    }
    body.pnav-on .filters-section.pnav-filter-sheet.is-open {
        transform: none;
        visibility: visible;
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
    }
    .pnav-filter-sheet > .pnav-handle {
        display: block;
    }
    body.pnav-on .pnav-filter-sheet .filters-title {
        font-size: 17px;
        line-height: 1.25;
    }

    /* ---------- Listas roláveis e alvos de toque ---------- */
    body.pnav-on .tribunals-nav {
        scroll-snap-type: x proximity;
        -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
        mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
    }
    body.pnav-on .indicator-dot {
        position: relative;
    }
    body.pnav-on .indicator-dot::after {
        content: "";
        position: absolute;
        top: -17px;
        bottom: -17px;
        left: -4px;
        right: -4px;
    }
    body.pnav-on .type-card-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Rolagem travada enquanto um painel está aberto */
    html.pnav-locked,
    html.pnav-locked body {
        overflow: hidden !important;
    }
}

@media (max-width: 991.98px) and (prefers-reduced-motion: reduce) {
    .pnav-header,
    .pnav-scrim,
    .pnav-drawer,
    .pnav-search,
    .pnav-sheet,
    .pnav-sub,
    .pnav-toast {
        transition: none !important;
    }
    .pnav-badge.is-pop {
        animation: none;
    }
}
