/*
 * Ajustes de celular (telas até 767px), carregados no fim do base.html para valer
 * por cima dos estilos de cada tela. Regras genéricas: cabeçalhos que quebram linha,
 * grupos de botões que não vazam, tabelas que viram cartões (ver mobile.js) e campos
 * com 16px (o iPhone dá zoom sozinho em campos menores).
 *
 * Para uma tabela continuar como tabela no celular, use a classe "no-mobile-cards".
 */

html, body { max-width: 100%; }

@media (max-width: 767.98px) {
    body { overflow-x: hidden; }

    /* Nada de mídia mais larga que a tela */
    img, video, iframe, canvas, svg:not(.bi) { max-width: 100%; }
    img, video { height: auto; }
    /* ...exceto avatar e logos do menu, que têm tamanho fixo e não podem encolher */
    .navbar img, img.user-avatar { max-width: none; flex-shrink: 0; }
    input[type=file] { max-width: 100%; }

    /* Textos longos (e-mails, links) quebram em vez de empurrar a página */
    td, th, p, li, dd, .card-text, .card-title, h1, h2, h3, h4, h5, h6 { overflow-wrap: anywhere; }

    /* Campos com 16px: evita o zoom automático do iOS ao tocar */
    input.form-control, select.form-select, select.form-control, textarea.form-control,
    .form-control, .form-select { font-size: 16px; }

    /* Cabeçalho de tela: título + botões lado a lado quebram para baixo */
    .d-flex.justify-content-between:has(> h1, > h2, > h3, > div > h1, > div > h2, > div > h3) {
        flex-wrap: wrap;
        row-gap: .75rem;
    }

    .btn-nowrap { white-space: normal !important; }
    .btn-lg { padding: .55rem 1rem; font-size: 1rem; }

    /* Modais ocupam a largura útil */
    .modal-dialog:not(.modal-sm) { margin: .5rem; max-width: calc(100% - 1rem); }
    .modal-footer { flex-wrap: wrap; gap: .5rem; }

    /* Rolagem horizontal com dedo (quando a tabela continua tabela) */
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* ===== Tabelas em cartões (classe aplicada pelo mobile.js) ===== */
    .table-responsive:has(> table.m-cards) { overflow: visible; border: 0; }
    table.m-cards { border: 0 !important; background: transparent !important; min-width: 0 !important; width: 100% !important; }
    table.m-cards > thead { display: none; }
    table.m-cards > tbody, table.m-cards > tfoot { display: block; width: 100%; }
    table.m-cards > tbody > tr, table.m-cards > tfoot > tr {
        display: block;
        background: #fff;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px;
        margin-bottom: .75rem;
        padding: .35rem 0;
        box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    }
    table.m-cards > tbody > tr > td, table.m-cards > tfoot > tr > td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: .75rem;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        border: 0 !important;
        padding: .4rem .9rem !important;
        text-align: right !important;
        background: transparent !important;
        box-shadow: none !important;
        white-space: normal !important;
    }
    table.m-cards > tbody > tr > td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        max-width: 38%;
        text-align: left;
        font-weight: 600;
        font-size: .8rem;
        color: #6c757d;
        text-transform: none;
    }
    table.m-cards > tbody > tr > td > * { min-width: 0; }
    /* Célula sem título (checkbox, ações, mensagem de "vazio"): ocupa a linha toda */
    table.m-cards > tbody > tr > td:not([data-label])::before,
    table.m-cards > tbody > tr > td[data-label=""]::before { display: none; }
    table.m-cards > tbody > tr > td:not([data-label]),
    table.m-cards > tbody > tr > td[data-label=""] { justify-content: flex-start; text-align: left !important; }
    table.m-cards > tbody > tr > td[colspan] { justify-content: center; text-align: center !important; }
    table.m-cards > tbody > tr > td[colspan]::before { display: none; }
    /* Primeira coluna vira o título do cartão */
    table.m-cards > tbody > tr > td.m-card-title {
        font-weight: 600;
        font-size: 1rem;
        text-align: left !important;
        justify-content: flex-start;
        border-bottom: 1px solid #f1f3f5 !important;
        padding-bottom: .55rem !important;
        margin-bottom: .2rem;
    }
    table.m-cards > tbody > tr > td.m-card-title::before { display: none; }
    /* Coluna de ações: botões em linha, alinhados à esquerda, com área de toque boa */
    table.m-cards > tbody > tr > td.m-card-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
        text-align: left !important;
        border-top: 1px solid #f1f3f5 !important;
        margin-top: .2rem;
        padding-top: .6rem !important;
    }
    table.m-cards > tbody > tr > td.m-card-actions::before { display: none; }
    table.m-cards > tbody > tr > td.m-card-actions > * { flex: 0 0 auto; }
    table.m-cards > tbody > tr > td.m-card-actions .btn,
    table.m-cards > tbody > tr > td.m-card-actions a { min-height: 36px; }
    table.m-cards > tbody > tr > td.m-card-actions .d-flex,
    table.m-cards > tbody > tr > td.m-card-actions .btn-group { flex-wrap: wrap; gap: .4rem; }
    /* Linhas escondidas por filtro continuam escondidas */
    table.m-cards > tbody > tr[style*="display: none"], table.m-cards > tbody > tr.d-none { display: none !important; }

    /* ===== Ajustes por tela ===== */
    /* Completar cadastro: seletor de idioma sai de cima do título */
    .complete_page .language-selector {
        position: relative; top: auto; right: auto;
        width: fit-content; margin: 0 0 .75rem auto;
    }
}

/* Tablet e celular (até 991px) */
@media (max-width: 991.98px) {
    /* Grupos de botões quebram linha em vez de sair pela lateral */
    .d-flex:has(> .btn + .btn),
    .d-flex:has(> a.btn + a.btn),
    .d-flex:has(> form + .btn), .d-flex:has(> .btn + form) {
        flex-wrap: wrap;
    }
    /* Botões do topo de "Meus Assessments" quebram linha */
    .header-actions .d-flex { flex-wrap: wrap; justify-content: flex-end; }
    .header-actions .btn-nowrap { white-space: normal !important; }
    /* Menu "Acessos" (aparece abaixo de 992px) abre para a esquerda e não passa da borda */
    .quick-links-dropdown-navbar { left: auto; right: 0; }
}
@media (max-width: 767.98px) {
    .header-actions .d-flex > .btn { flex: 1 1 100%; justify-content: center; }
}

/* Notebook pequeno / tablet deitado (992–1199px): a barra do topo mostra os atalhos do desktop
   e não cabia junto com o nome do usuário; esconde o nome (fica o avatar) e afina os atalhos */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .user-dropdown .user-info { display: none !important; }
    .navbar-access-desktop .navbar-pill-btn { min-width: 0; padding-left: .6rem; padding-right: .6rem; }
    /* Botões do topo de "Meus Assessments" (Como usar, Assinatura, Criar) quebram linha em vez de cobrir o título */
    .header-actions .d-flex { flex-wrap: wrap; justify-content: flex-end; }
}
