/* ====================================================
   MeControlei — camada de app (PWA / Android / iOS)
   Carregado em todas as páginas por includes/pwa_head.php
   ==================================================== */

/* ----------------------------------------------------
   Área segura (notch / barra de status)
   Só entra em ação quando rodando como app instalado.

   CUIDADO AO MEXER AQUI: responsive.css define
       body { padding-top: 48px }
   para o conteúdo não ficar embaixo da navbar fixa. As regras abaixo
   precisam SOMAR a área segura a esses 48px — nunca substituí-los.
   Substituir zera o padding no Android (onde o inset é 0, porque o
   StatusBar está com overlaysWebView: false) e a navbar passa a cobrir
   o topo do conteúdo.

   Com inset = 0, tudo aqui se reduz exatamente aos valores originais.
   ---------------------------------------------------- */
@supports (padding-top: env(safe-area-inset-top)) {
    html.mc-app body {
        padding-top: calc(48px + env(safe-area-inset-top));
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* O !important e obrigatorio: a navbar carrega a classe p-0 do
       Bootstrap, que aplica padding:0 !important e venceria esta regra.
       Sem ele, o fundo sobe ate o topo mas o logo fica sob o relogio. */
    html.mc-app #mainNavbar {
        padding-top: env(safe-area-inset-top) !important;
    }

    html.mc-app .sidebar {
        top: calc(48px + env(safe-area-inset-top)) !important;
        height: calc(100vh - 48px - env(safe-area-inset-top)) !important;
    }
}

/* ----------------------------------------------------
   Rodapé: a barra de navegação inferior (.bottom-nav) é
   position:fixed, então padding no body NÃO a desloca — ela
   precisa do próprio recuo, senão fica atrás da barra do
   Android e os toques vão para os botões do sistema.

   O responsive.css já reserva 64px no body para ela; aqui
   somamos a área segura aos dois, sem substituir nada.
   ---------------------------------------------------- */
@media (max-width: 767.98px) {
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        html.mc-app body {
            padding-bottom: calc(64px + env(safe-area-inset-bottom));
        }

        /* A barra cresce e o padding empurra os ícones para cima:
           o fundo branco continua cobrindo a área do sistema. */
        html.mc-app .bottom-nav {
            height: calc(60px + env(safe-area-inset-bottom));
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* No app instalado não faz sentido oferecer "instalar" */
html.mc-app #mcInstalarApp { display: none !important; }

html.mc-native body {
    -webkit-tap-highlight-color: transparent;
}

/* ----------------------------------------------------
   Sino de notificações
   ---------------------------------------------------- */
.mc-sino-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#mcSino {
    position: relative;
    color: #fff;
    padding: .5rem .75rem;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    border-radius: 5px;
    transition: background-color .2s;
}

#mcSino:hover { background-color: rgba(255, 255, 255, .1); }

#mcSinoBadge {
    display: none;
    position: absolute;
    top: 2px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: #e74c3c;
    color: #fff;
    border-radius: 9px;
    font-size: .65rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#mcSinoPainel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 340px;
    max-width: calc(100vw - 24px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
    z-index: 99999;
    overflow: hidden;
}

.mc-sino-cabecalho {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: .9rem;
    color: #2c3e50;
}

.mc-sino-cabecalho a {
    font-size: .75rem;
    font-weight: 500;
    color: #3498db;
    text-decoration: none;
}

#mcSinoLista {
    max-height: 380px;
    overflow-y: auto;
}

.mc-notif-item {
    display: block;
    padding: .8rem 1rem;
    border-bottom: 1px solid #f1f3f5;
    text-decoration: none;
    color: #2c3e50;
    transition: background-color .15s;
}

.mc-notif-item:hover { background: #f8f9fa; color: #2c3e50; }
.mc-notif-item.nao-lida { background: #f0f7fd; }
.mc-notif-item.nao-lida .mc-notif-titulo::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #3498db;
    margin-right: 6px;
    vertical-align: middle;
}

.mc-notif-titulo { font-weight: 600; font-size: .85rem; margin-bottom: 2px; }
.mc-notif-corpo  { font-size: .8rem; color: #6c757d; line-height: 1.35; }
.mc-notif-data   { font-size: .7rem; color: #adb5bd; margin-top: 4px; }

.mc-notif-vazio {
    padding: 2rem 1rem;
    text-align: center;
    color: #adb5bd;
    font-size: .85rem;
}

/* ----------------------------------------------------
   Convite para ativar notificações (navegador)
   ---------------------------------------------------- */
.mc-convite {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: 460px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    z-index: 99998;
    transform: translateY(140%);
    transition: transform .35s cubic-bezier(.2, .8, .2, 1);
}

.mc-convite.visivel { transform: translateY(0); }

.mc-convite-icone {
    font-size: 1.4rem;
    color: #3498db;
    margin-top: 2px;
    flex-shrink: 0;
}

.mc-convite-texto { flex: 1; min-width: 0; }
.mc-convite-texto strong { display: block; font-size: .9rem; color: #2c3e50; }
.mc-convite-texto span   { display: block; font-size: .8rem; color: #6c757d; line-height: 1.35; margin-top: 2px; }

.mc-convite-acoes {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.mc-convite-acoes button {
    border: 0;
    border-radius: 6px;
    padding: 7px 14px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.mc-btn-ativar { background: #3498db; color: #fff; }
.mc-btn-ativar:active { background: #2c81ba; }
.mc-btn-depois { background: transparent; color: #adb5bd; }

/* O convite flutua acima da bottom-nav e da barra do sistema */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    html.mc-app .mc-convite {
        bottom: calc(16px + 60px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 420px) {
    .mc-convite { flex-wrap: wrap; }
    .mc-convite-acoes { flex-direction: row; width: 100%; justify-content: flex-end; }
}

/* ----------------------------------------------------
   Toast de push recebido com o app aberto
   ---------------------------------------------------- */
.mc-toast {
    position: fixed;
    top: 12px;
    left: 16px;
    right: 16px;
    max-width: 400px;
    margin: 0 auto;
    background: #2c3e50;
    color: #fff;
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
    z-index: 99999;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity .3s, transform .3s;
}

.mc-toast.visivel { opacity: 1; transform: translateY(0); }
.mc-toast i { color: #f39c12; margin-top: 2px; }
.mc-toast strong { display: block; font-size: .85rem; }
.mc-toast span   { display: block; font-size: .78rem; opacity: .85; line-height: 1.35; margin-top: 2px; }

@supports (padding-top: env(safe-area-inset-top)) {
    html.mc-app .mc-toast { top: calc(12px + env(safe-area-inset-top)); }
}

/* ----------------------------------------------------
   Botão "Instalar app"
   ---------------------------------------------------- */
#mcInstalarApp {
    display: none;
    align-items: center;
    gap: 6px;
    background: #27ae60;
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}

#mcInstalarApp:hover { background: #219653; }

/* ----------------------------------------------------
   Conformidade com a Política de Pagamentos do Google Play
   ----------------------------------------------------
   Dentro do app não pode existir venda de conteúdo digital fora do
   Play Billing, nem direcionamento a pagamento externo. Marque com
   .mc-cobranca qualquer preço, botão de compra ou link de renovação.

   O CSS oculta imediatamente (sem piscar) e o PHP bloqueia as rotas —
   as duas camadas existem de propósito: se o JS falhar, o servidor
   ainda barra; se o cookie faltar, o CSS ainda esconde.
   ---------------------------------------------------- */
html.mc-native .mc-cobranca { display: none !important; }
