/* =====================================================================
   x-zap — celular (site, área do cliente e painel do dono)

   Carregado por último em todas as páginas. Só age em telas estreitas.
   Regras de ouro: nada rola para o lado; alvo de toque ≥ 44px; texto
   ≥ 13px; campo com fonte 16px (abaixo disso o iPhone dá zoom);
   tabela vira cartão.
   ===================================================================== */

@media (max-width: 760px) {
    html { -webkit-text-size-adjust: 100%; }
    body { overflow-x: hidden; }
    img, svg, video { max-width: 100%; }

    /* Campos: 16px para o iPhone não dar zoom ao tocar */
    input:not([type=checkbox]):not([type=radio]), select, textarea {
        font-size: 16px !important;
        min-height: 46px;
    }
    textarea { min-height: 110px; }
    input[type=checkbox], input[type=radio] { width: 22px !important; height: 22px; flex-shrink: 0; }

    /* Toque: botões com 44px no mínimo */
    .btn, button:not(.ver-senha):not(.menu-botao), .sair, select { min-height: 44px; }
    .btn.pequeno { min-height: 44px; padding: 0 14px; }
    .ver-senha { min-height: 40px; min-width: 52px; font-size: 14px !important; }

    /* Texto: nada abaixo de 13px */
    small, .dica, .rotulo, .selo, .tique, .linha-pe, .contato-meta, .balao-pe, .balao-pe .tique,
    .marca-texto small, .lateral-grupo, .sair, .saude, code, .mono, td.mono, .dados .mono,
    .tabela-larga .mono, .tipo-ajuda, .adm-marca em, .form-link, .metrica .rotulo,
    th, label, .sub { font-size: max(13px, 1em); }
    .dica, .rotulo, .selo, .tique, .linha-pe, .contato-meta, .balao-pe, .lateral-grupo, .saude,
    .tipo-ajuda, .marca-texto small, .adm-marca em, small { font-size: 13px !important; }
    code { font-size: 13px !important; word-break: break-word; }

    /* Código: rola por dentro, a página não */
    pre { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: 13px !important; }
    pre code { word-break: normal; white-space: pre; }

    /* ---------- Tabelas viram cartões (mobile.js põe os rótulos) ---------- */
    table.cartoes, table.cartoes tbody, table.cartoes tr, table.cartoes td { display: block; width: 100%; }
    table.cartoes thead { display: none; }
    table.cartoes tr {
        border: 1px solid var(--borda, var(--linha, #DCE0E4));
        border-radius: 16px;
        padding: 6px 14px;
        margin: 0 0 10px;
        background: #fff;
    }
    table.cartoes tr:last-child { margin-bottom: 0; }
    table.cartoes td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 9px 0 !important; border-bottom: 1px solid #EEF0F2 !important;
        text-align: right; white-space: normal !important; min-height: 0;
    }
    table.cartoes td:last-child { border-bottom: 0 !important; }
    table.cartoes td::before {
        content: attr(data-label);
        font-size: 13px; color: #5B636B; font-weight: 500; text-align: left; flex-shrink: 0;
        max-width: 42%;
    }
    table.cartoes td[data-label=""]::before, table.cartoes td:not([data-label])::before { content: none; }
    table.cartoes td[data-label=""], table.cartoes td:not([data-label]) { justify-content: flex-start; text-align: left; }
    /* Primeira coluna = título do cartão */
    table.cartoes td:first-child { display: block; text-align: left; font-size: 16px; }
    table.cartoes td:first-child::before { content: none; }
    /* Coluna de ações: botões lado a lado, largura toda */
    table.cartoes td.acoes-cel, table.cartoes td:last-child:has(form, .btn) {
        display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 8px; text-align: left;
    }
    table.cartoes td:last-child:has(form, .btn)::before { content: none; }
    table.cartoes td form { margin: 0 !important; }
    table.cartoes td .btn { flex: 1 1 auto; }
    table.cartoes td > *:not(form) { max-width: 100%; overflow-wrap: anywhere; }
    .painel:has(> table.cartoes), .painel:has(> .rolagem > table.cartoes) {
        background: transparent; border: 0; box-shadow: none; padding: 0 !important; overflow: visible !important;
    }

    /* Grades com colunas fixas no meio do HTML: uma coluna */
    [style*="grid-template-columns"]:not(.metricas):not(.manter-grade) { grid-template-columns: 1fr !important; }
    .grade { grid-template-columns: 1fr !important; }

    /* Avisos e cartões: respiro menor */
    .aviso { font-size: 15px; }
}

/* Telas bem estreitas (360) */
@media (max-width: 380px) {
    .metricas { grid-template-columns: 1fr 1fr !important; }
    h1 { font-size: 24px !important; }
}

/* =====================================================================
   PAINEL DO DONO (layout com .lateral)
   ===================================================================== */
.topo-movel { display: none; }

@media (max-width: 980px) {
    /* Barra de topo fixa: menu, marca e o nome da tela */
    .topo-movel {
        display: flex; align-items: center; gap: 12px;
        position: fixed; top: 0; left: 0; right: 0; z-index: 50;
        height: calc(58px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 14px 0 calc(10px + env(safe-area-inset-left));
        background: rgba(230, 233, 236, .92);
        -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
        border-bottom: 1px solid #D6DBE0;
    }
    .topo-movel .menu-botao {
        position: static; display: flex; width: 44px; height: 44px; flex-shrink: 0;
        background: #14171A; border-radius: 12px; padding: 14px 12px;
    }
    .topo-movel .tm-marca { display: flex; align-items: center; gap: 8px; color: #14171A; text-decoration: none; font-weight: 600; letter-spacing: -.04em; font-size: 18px; }
    .topo-movel .tm-marca b { color: #00874A; font-weight: 600; }
    .topo-movel .tm-titulo { margin-left: auto; font-size: 14px; color: #4A5259; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
    body > .menu-botao, .app > .menu-botao { display: none !important; }

    .pagina { padding: calc(78px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom)) !important; }
    .lateral { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); width: min(300px, 86vw); }
    .lateral-item { min-height: 46px; font-size: 16px; }
    .lateral-grupo { margin-top: 14px; }

    /* Cabeçalho da tela: título em cima, ação principal embaixo com largura toda */
    .cabecalho-secao { flex-direction: column; align-items: stretch; gap: 14px; }
    .cabecalho-secao > .btn, .cabecalho-secao > a.btn, .cabecalho-secao > button,
    .cabecalho-secao > form, .cabecalho-secao > .selo { align-self: stretch; }
    .cabecalho-secao > .selo { align-self: flex-start; }
    .cabecalho-secao .btn { width: 100%; }
    h1 { font-size: 26px; }

    .painel { padding: 18px; border-radius: 20px; }
    .acoes { gap: 8px; }
    .acoes > .btn, .acoes > form, .acoes > a.btn { flex: 1 1 calc(50% - 8px); }
    .acoes > form .btn, .acoes > form button { width: 100%; }

    /* Cartões de instância compactos */
    .grade { gap: 12px; }
    .linha-card { padding: 16px; }
    .linha-card .linha-fone.vazio { margin-top: 6px; }
    .linha-card > div:empty { display: none; }

    /* Filtros recolhidos atrás de "Filtrar" (mobile.js) */
    .filtros { grid-template-columns: 1fr !important; }

    /* Pareamento: QR do tamanho da tela */
    .pareamento { grid-template-columns: 1fr !important; }
    .qr-palco { width: 100% !important; height: auto !important; aspect-ratio: 1; max-width: 360px; margin: 0 auto; }
    .qr-tempo { width: 100%; }

    /* Documentação e socorro: uma coluna, código rola por dentro */
    .docs { grid-template-columns: 1fr !important; gap: 0; }
    .docs-corpo { min-width: 0; max-width: 100%; }
    .docs-corpo table { display: block; overflow-x: auto; }

    /* Detalhes de instância (tabela de 2 colunas): empilha */
    .instancia-detalhes th, .instancia-detalhes td { display: block; width: 100% !important; padding: 2px 0 !important; border: 0 !important; }
    .instancia-detalhes tr { display: block; padding: 10px 0; border-bottom: 1px solid #EEF0F2; }
}

/* Conversas no celular: lista OU conversa, como no WhatsApp */
@media (max-width: 760px) {
    .conv-grade { grid-template-columns: 1fr !important; }
    .conv-grade.tem-contato > .conv-lista { display: none; }
    .conv-grade:not(.tem-contato) > .conv-thread { display: none; }
    .conv-voltar { display: inline-flex !important; }
    .lista-contatos { max-height: none !important; }
    .contato { min-height: 52px; padding: 10px 12px; }
    .thread { padding: 12px 8px; }
    .balao { max-width: 90% !important; font-size: 15px; }
}
.conv-voltar { display: none; }

/* =====================================================================
   ÁREA DO CLIENTE (.app-menu) — barra de abas embaixo
   ===================================================================== */
.abas-cel { display: none; }

@media (max-width: 760px) {
    .app { display: block; }
    .app-menu {
        position: sticky; top: 0; z-index: 40;
        flex-direction: row; align-items: center; justify-content: space-between;
        padding: calc(10px + env(safe-area-inset-top)) 16px 10px; gap: 12px;
        background: rgba(230, 233, 236, .92);
        -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
        border-bottom: 1px solid #D6DBE0;
    }
    .app-menu > nav, .app-menu > .card { display: none !important; }
    .app-menu .sair-cel { display: block !important; }
    .app-main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)) !important; gap: 14px; }
    .app .card { padding: 18px; border-radius: 20px; }
    .app .card.topo { flex-direction: column; align-items: stretch; }
    .app .card.topo > .btn, .app .card.topo > form, .app .card.topo > a.btn { width: 100%; }
    .app .card.topo form .btn, .app .card.topo form button { width: 100%; }
    .grade { grid-template-columns: 1fr !important; }
    .app .metrica .valor { font-size: 28px; }

    .abas-cel {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .96);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
        border-top: 1px solid #D6DBE0;
    }
    .abas-cel a {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        min-height: 52px; border-radius: 12px; text-decoration: none;
        color: #4A5259; font-size: 13px; font-weight: 500;
    }
    .abas-cel a svg { width: 22px; height: 22px; }
    .abas-cel a.ativo { color: #14171A; background: #EAF8F0; }
    .abas-cel a.ativo svg { stroke: #00874A; }

    /* Campo + botão Copiar: botão com largura toda embaixo */
    .copiar-linha { flex-direction: column; }
    .copiar-linha > .btn { width: 100%; }
}
.sair-cel { display: none; }

/* Telas de entrada (login, cadastro) */
@media (max-width: 760px) {
    .entrada { padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); align-items: flex-start; }
    .entrada .card, .entrada-form { padding: 22px !important; border-radius: 20px; }
    .adm-entrada .entrada-caixa { padding: 24px 16px; }
    .adm-marca { flex-wrap: wrap; }
}

/* Ajustes finos (estilos escritos direto no HTML e botões de código) */
@media (max-width: 760px) {
    .btn, a.btn, button.btn { min-height: 44px !important; }
    .ver-senha { min-height: 44px !important; }
    [style*="font-size: 10"], [style*="font-size:10"], [style*="font-size: 11"], [style*="font-size:11"],
    [style*="font-size: 12"], [style*="font-size:12"] { font-size: 13px !important; }
    .codigo button, .segredo button {
        opacity: 1 !important; font-size: 13px !important; min-height: 36px; padding: 6px 12px;
    }
    .codigo pre { padding-top: 48px; }
    .docs-corpo code, .dg-caixa span, .thread-dia, .balao-midia .mono, .tique { font-size: 13px !important; }
}
@media (max-width: 760px) {
    table.cartoes td { overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
    .topo-movel { overflow: hidden; }
}
@media (max-width: 760px) {
    .grade.metricas-cel.manter-grade { grid-template-columns: 1fr 1fr !important; }
    .grade.metricas-cel .metrica { padding: 14px 16px; }
    .campo-nome-numero { width: 100% !important; }
}
@media (max-width: 980px) {
    .linha-topo > div:first-child { flex: 1; }
    .linha-card { min-height: 0 !important; height: auto !important; }
}
@media (max-width: 760px) {
    table.cartoes td::before { font-family: var(--corpo, Geist, system-ui, sans-serif) !important; letter-spacing: 0; }
    table.cartoes td form[style*="display:flex"], table.cartoes td form[style*="display: flex"] { flex-wrap: wrap; width: 100%; }
    table.cartoes td form select { min-width: 0 !important; width: 100% !important; flex: 1 1 100%; }
    table.cartoes td form .btn { flex: 1 1 100%; }
    .conv-thread .rotulo { white-space: nowrap; }
    .pagina:has(.conv-grade.tem-contato) .painel:has(> .conv-busca) { display: none; }
}

/* Seções que abrem e fecham (página da instância no celular) */
@media (max-width: 980px) {
    .painel.recolhivel > h2 { cursor: pointer; display: flex; justify-content: space-between; align-items: center; margin: 0; min-height: 30px; }
    .painel.recolhivel > h2::after { content: '+'; font-size: 24px; font-weight: 400; color: #5B636B; line-height: 1; }
    .painel.recolhivel.aberto > h2 { margin-bottom: 14px; }
    .painel.recolhivel.aberto > h2::after { content: '−'; }
    .painel.recolhivel:not(.aberto) > *:not(h2) { display: none !important; }
}
@media (max-width: 760px) {
    [style*="grid-column"] { grid-column: auto !important; }
}
@media (max-width: 980px) {
    .filtros.recolhido { display: none !important; }
}

/* =====================================================================
   SITE PÚBLICO
   ===================================================================== */
.site-menu-btn { display: none; }
@media (max-width: 760px) {
    header:has(> .site-nav) { padding: calc(10px + env(safe-area-inset-top)) 12px 0 !important; position: sticky; top: 0; z-index: 30; }
    .site-nav { padding: 8px 8px 8px 14px !important; gap: 8px !important; justify-content: space-between; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
    .site-nav > a[href="#topo"] { min-height: 44px; }
    .site-menu-btn {
        display: flex; flex-direction: column; justify-content: space-between; order: 3;
        width: 44px; height: 44px; padding: 14px 12px; border: 0; border-radius: 12px; background: #14171A; cursor: pointer;
    }
    .site-menu-btn span { display: block; height: 2px; background: #fff; border-radius: 2px; }
    .site-nav .site-links, .site-nav .site-acoes { display: none !important; }
    .site-nav.aberto .site-links, .site-nav.aberto .site-acoes { display: flex !important; flex: 1 1 100% !important; order: 4; }
    .site-nav.aberto .site-links { flex-direction: column; gap: 0 !important; padding: 6px 0; border-top: 1px solid #DCE0E4; }
    .site-nav.aberto .site-links a { min-height: 48px; display: flex; align-items: center; font-size: 17px !important; }
    .site-nav.aberto .site-acoes { padding-bottom: 6px; }
    .site-nav.aberto .site-acoes a { flex: 1; justify-content: center; }

    #topo > div { padding: 36px 16px 48px !important; gap: 32px !important; }
    #topo .xz-pontos { padding: 22px 14px !important; }
    #topo h1 { font-size: 44px !important; }
    #recursos > div, #como > div, #precos > div, #duvidas > div { padding: 56px 16px !important; }
    #api > div { padding-top: 40px !important; padding-bottom: 40px !important; }
    section[aria-label="Para quem é"] > div { padding-left: 16px !important; padding-right: 16px !important; }
    #recursos article, #precos article, #como li { padding: 22px !important; }
    #recursos h2, #como h2, #precos h2, #api h2, #duvidas h2 { font-size: 32px !important; }
    .plano-destaque { order: -1; }
    .site-rodape a, footer a { min-height: 44px; display: inline-flex; align-items: center; }
    #topo a[href="#precos"], #topo a[href="/docs"], #topo a[href="#api"] { width: 100%; justify-content: center; box-sizing: border-box; }
    #api a, #precos a, section a[href^="/conta"] { min-height: 44px; display: inline-flex; align-items: center; }
}
