/*
 * SuperApp — layout app (scroll no main; chrome mobile fora do overflow)
 */

:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --app-mobile-header-h: 4.5rem;
    --app-tabbar-h: 4.25rem;
    --app-tabbar-total: calc(var(--app-tabbar-h) + var(--safe-bottom));
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

/* Shell: altura da tela; scroll APENAS em .superapp-main */
body.superapp-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    margin: 0;
}

.superapp-layout {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow: hidden;
}

.superapp-content-column {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.superapp-main {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* ── Mobile header fixo ── */
@media (max-width: 767px) {
    .app-mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 500;
        display: flex !important;
        padding-top: max(var(--safe-top), 0.5rem);
        padding-left: max(1rem, var(--safe-left));
        padding-right: max(1rem, var(--safe-right));
        padding-bottom: 0.875rem;
        background-color: var(--superapp-primary, #002766) !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
        border-radius: 0 0 1.5rem 1.5rem;
    }

    .app-mobile-header-spacer {
        flex-shrink: 0;
        height: var(--app-mobile-header-h);
        min-height: calc(3.75rem + var(--safe-top));
    }

    .superapp-main {
        padding-bottom: var(--app-tabbar-total) !important;
    }
}

@media (min-width: 768px) {
    .app-mobile-header,
    .app-mobile-header-spacer,
    #superapp-mobile-chrome {
        display: none !important;
    }
}

/* ── Chrome mobile (menu + tab bar) — filho do body, fora do overflow-hidden ── */
#superapp-mobile-chrome {
    display: block;
}

#superapp-mobile-chrome .app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    padding-bottom: max(var(--safe-bottom), 8px);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    background: #ffffff;
    border-top: 1px solid rgba(15, 23, 42, 0.1);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
}

.app-tabbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-around;
    min-height: var(--app-tabbar-h);
    max-width: 28rem;
    margin: 0 auto;
    padding: 0.25rem 0.5rem 0;
}

.app-tabbar-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.35rem 0.25rem;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 0.625rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.app-tabbar-btn.is-active,
.app-tabbar-menu-btn.is-open {
    color: var(--superapp-primary, #002766);
}

.app-tabbar-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.65rem;
}

.app-tabbar-btn.is-active .app-tabbar-icon,
.app-tabbar-menu-btn.is-open .app-tabbar-icon {
    background: rgba(0, 39, 102, 0.1);
}

#nav-mobile-wrapper.hidden {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden;
}

#nav-mobile-wrapper:not(.hidden) {
    display: flex !important;
    pointer-events: auto !important;
}

body.superapp-menu-open .superapp-main {
    overflow: hidden;
}

/* ── Overlays de tela cheia (drawers e modais das abas) ────────────────────
   O header e a tab bar do mobile são `position: fixed` com z-index 500. Um
   drawer em z-300 abria POR BAIXO dos dois: o botão de fechar ficava
   escondido atrás do header azul e a tab bar, mesmo clicável, navegava para
   uma aba que o drawer continuava cobrindo. Sem saída visível, o app parecia
   travado. A camada abaixo sobe o overlay acima do chrome (mas abaixo do
   menu mobile, z-600, que é quem dispara fecharOverlays() ao navegar). */
.superapp-overlay       { z-index: 550; }
.superapp-overlay-sheet { z-index: 551; }

/* Como o overlay agora cobre header e tab bar, ele assume o respiro que os
   dois davam: notch/ilha em cima, barra de gestos embaixo. */
.superapp-overlay-topo  { padding-top: max(2rem, calc(var(--safe-top) + 1rem)); }
.superapp-overlay-fundo { padding-bottom: max(1.5rem, calc(var(--safe-bottom) + 1.5rem)); }

/* Trava o scroll do app atrás do overlay — sem isto, rolar até o fim da
   lista do drawer continua rolando a aba embaixo. */
body.superapp-overlay-open .superapp-main {
    overflow: hidden;
}

/* ── Acessibilidade: contraste mínimo ──────────────────────────────────────
   slate-400 (#94a3b8) sobre branco dá ~3.0:1 — abaixo dos 4.5:1 exigidos pela
   WCAG 2.1 AA para texto pequeno. É a cor dos subtítulos e metadados em todo o
   app (234 ocorrências). Sobrescrever a utilitária de TEXTO corrige todas de
   uma vez, sem tocar em bordas/fundos que usam o mesmo tom.
   #64748b = slate-500 => ~4.6:1. O !important vence o <style> que o Tailwind
   CDN injeta em runtime depois desta folha. */
.text-slate-400 { color: #64748b !important; }

/* Foco visível: navegação por teclado precisa de indicação clara. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--superapp-primary, #002766);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Exceção: o campo de comentário do feed vive dentro de um container pill que
   já sinaliza o foco (focus-within: anel + borda primary + fundo branco). O
   outline retangular só duplicaria a indicação e ainda brigaria com o
   arredondamento, aparecendo como um contorno escuro em volta do campo. */
input[name="comentario"]:focus-visible {
    outline: none;
}

#toast-container {
    top: calc(var(--app-mobile-header-h) + var(--safe-top) + 0.5rem) !important;
}

@media (min-width: 768px) {
    #toast-container {
        top: 1.5rem !important;
    }
}
