/* === Sidebar Painel === */
#sidebar {
    transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1), width .25s ease, min-width .25s ease;
}
#sidebar.collapsed { 
    width: 4rem !important; 
    min-width: 4rem !important; 
}
#sidebar.collapsed .sidebar-label,
#sidebar.collapsed .sidebar-hide-collapsed { 
    display: none !important; 
    opacity: 0 !important; 
    width: 0 !important; 
    height: 0 !important;
    overflow: hidden !important; 
}
#sidebar.collapsed .sidebar-collapse-icon { 
    transform: rotate(180deg); 
}
#sidebar.collapsed ~ .flex-1 { 
    max-width: calc(100vw - 4rem); 
    min-width: 0;
}
@media (min-width: 768px) {
    #sidebar.collapsed > div:first-child > .flex.items-center {
        justify-content: center;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    #sidebar.collapsed nav {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    #sidebar.collapsed nav a,
    #sidebar.collapsed .menu-grupo-btn { 
        justify-content: center; 
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100%;
    }
    #sidebar.collapsed .menu-grupo-itens { 
        display: none !important; 
    }
    #sidebar.collapsed ~ .flex-1 .painel-content-area {
        max-width: calc(100vw - 4rem);
        min-width: 0;
    }
}

/* === Sidebar Mobile === */
@media (max-width: 767px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        transform: translateX(-100%);
        will-change: transform;
        overscroll-behavior: contain;
    }
    #sidebar.open { transform: translateX(0); }
    #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    #sidebarOverlay.open { display: block; opacity: 1; }
    .painel-content-area {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Evita que o navegador ajuste a rolagem sozinho ao restaurar/redimensionar */
        overflow-anchor: none;
    }
}

/* === Sidebar Tablet (768–1199): drawer com rótulos, sem rail === */
@media (min-width: 768px) and (max-width: 1199.98px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 280px !important;
        min-width: 280px !important;
        max-width: 85vw;
        z-index: 100;
        transform: translateX(-100%);
        will-change: transform;
        overscroll-behavior: contain;
    }
    #sidebar.open { transform: translateX(0); }

    #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    #sidebarOverlay.open { display: block !important; opacity: 1; }

    #sidebarCollapse { display: none !important; }
    #sidebarClose { display: grid !important; }

    /* Segurança: se a classe collapsed vier do desktop, o tablet mostra rótulos. */
    #sidebar.collapsed {
        width: 280px !important;
        min-width: 280px !important;
    }
    #sidebar.collapsed .sidebar-label,
    #sidebar.collapsed .sidebar-hide-collapsed {
        display: block !important;
        opacity: 1 !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
    }
    #sidebar.collapsed nav a,
    #sidebar.collapsed .menu-grupo-btn {
        justify-content: flex-start;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    #sidebar.collapsed .menu-grupo-itens { display: block !important; }
    #sidebar.collapsed ~ .flex-1,
    #sidebar.collapsed ~ .flex-1 .painel-content-area {
        max-width: none;
    }
}

/* No tablet retrato o menu inferior continua; o Menu abre o drawer. */
@media (min-width: 768px) and (max-width: 1199.98px) and (orientation: portrait) {
    .bottom-tab-bar {
        display: flex !important;
    }

    .painel-content-area > main,
    .painel-content-area > .resp-content {
        padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* O shell não usa ancoragem de rolagem; restaurações são tratadas pelo JS. */
html,
body {
    overflow-anchor: none;
}

/* === Swipe zone — área invisível para capturar gesture de swipe na borda esquerda === */
.swipe-zone {
    position: fixed;
    top: 0;
    left: 0;
    width: 16px;
    height: 100%;
    z-index: 50;
}

/* === Master Sidebar === */
#masterSidebar { transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1); }

#masterSidebar .ui-button-ghost {
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    font-weight: 400;
    font-size: 1rem;
    color: #fca5a5;
}

#masterSidebar .ui-button-ghost:hover {
    background-color: #b45309;
    color: #fecaca;
}

#masterSidebar .ui-button-ghost:focus-visible {
    outline-color: #fde68a;
    box-shadow: 0 0 0 3px rgba(253, 230, 138, 0.25);
}

@media (max-width: 767px) {
    #masterSidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        transform: translateX(-100%);
        will-change: transform;
    }
    #masterSidebar.open { transform: translateX(0); }
    #masterSidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    #masterSidebarOverlay.open { display: block; opacity: 1; }
}

/* === Page Transitions (App-Like) === */
@keyframes page-enter-from-right {
    from { transform: translateX(100%); opacity: 0.5; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes page-exit-to-left {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-30%); opacity: 0; }
}

.page-transition-enter {
    animation: page-enter-from-right 0.3s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}
.page-transition-exit {
    animation: page-exit-to-left 0.25s ease forwards;
}

/* === Slide-up (modais, sheets, toasts) === */
@keyframes slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.animate-slide-up { animation: slide-up 0.3s ease-out; }

/* === Slide-down (dropdowns, alerts) === */
@keyframes slide-down {
    from { transform: translateY(-8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.animate-slide-down { animation: slide-down 0.2s ease; }

/* === Marquee (banners rotativos com loop contínuo) === */
@keyframes marquee {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}
.animate-marquee { animation: marquee 25s linear infinite; }

/* Impedir rolagem dupla e interna no checkout */
main.resp-content.checkout-main {
    overflow: visible !important;
    height: auto !important;
    padding-bottom: 140px !important;
}
@media (min-width: 640px) {
    main.resp-content.checkout-main {
        padding-bottom: 24px !important;
    }
}

/* === Sticky Footer Universal e Eliminação de Áreas Inúteis === */
html {
    height: 100%;
}

body {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

main.resp-content,
main.flex-1 {
    flex: 1 0 auto;
    width: 100%;
}

/* Dentro do shell fixo do Master (.app-shell h-screen overflow-hidden), main precisa encolher para rolar */
.app-shell main.resp-content,
.app-shell main.flex-1 {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
}

footer.secao-carvao,
footer.mt-auto {
    margin-top: auto !important;
    width: 100%;
}

/* Mobile: o cartão principal preenche a área até a barra inferior (sem faixa vazia) */
@media (max-width: 639.98px) {
    /* Aplicado somente às páginas que declaram um cartão .ui-page-fill,
       sem alterar o fluxo de rolagem das demais telas. */
    .painel-content-area:has(.ui-page-fill) {
        display: flex;
        flex-direction: column;
    }

    .painel-content-area:has(.ui-page-fill) > main {
        display: flex;
        flex-direction: column;
        flex: 1 1 0%;
    }

    .painel-content-area:has(.ui-page-fill) > main > div:first-child {
        display: flex;
        flex-direction: column;
        flex: 1;
    }

    /* Cresce quando sobra espaço, mas nunca encolhe abaixo do conteúdo
       (evita cortar as linhas da lista). */
    .ui-page-fill {
        flex: 1 0 auto;
    }
}

/* Topbar fixa no mobile: garante que o cabeçalho não saia da tela
   em navegadores/WebView onde position: sticky falha dentro de flex. */
@media (max-width: 767.98px) {
    /* Especificidade acima das utilities (sticky/top-0/z-20/py) no mesmo elemento */
    header.painel-topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 40;
        padding-top: calc(0.625rem + env(safe-area-inset-top, 0px));
        /* Opaca: o conteúdo não pode aparecer por trás ao rolar */
        background: var(--card, #ffffff);
        backdrop-filter: none;
    }

    body .painel-content-area {
        padding-top: var(--painel-topbar-h, 65px);
        /* Evita o "elástico" que revela faixa vazia no fim da rolagem */
        overscroll-behavior-y: contain;
    }

    /* Altura da barra inferior + folga padrão de 16 px */
    body .painel-content-area > main {
        padding-bottom: calc(3.5625rem + 1rem + env(safe-area-inset-bottom, 0px)) !important;
    }
}
