/**
 * Camada responsiva global (celular, iPad e PC).
 * Objetivos: nenhuma rolagem lateral, tabelas viram cartões em telas
 * estreitas e colunas/linhas de botões ficam no INÍCIO (ver js/responsive.js).
 * Carregada por último (admin_menu.php, site_header.php, mobile_head.php).
 */

/* ---------- Sem rolagem lateral ---------- */
html { max-width: 100%; overflow-x: hidden; }
body { max-width: 100%; overflow-x: hidden; overflow-wrap: break-word; }
@supports (overflow: clip) {
    html, body { overflow-x: clip; }
}

img, video, canvas, iframe, embed, object { max-width: 100%; }
img, video { height: auto; }
pre, code, kbd, samp { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }

.main-content, .container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl,
.card, .card-body, .content-card, .modal-dialog, .modal-content, .row > *, .d-flex > *, .form-control,
.form-select, .input-group { min-width: 0; }
.main-content, .container, .container-fluid, .card, .content-card, .modal-content { max-width: 100%; }
.form-control, .form-select, textarea, select, input:not([type=checkbox]):not([type=radio]):not([type=range]) { max-width: 100%; }

td, th { overflow-wrap: anywhere; }

/* Rolagem horizontal de tabela deixa de existir: o conteúdo quebra linha ou vira cartão */
.table-responsive { overflow-x: visible !important; width: 100%; }
.table-responsive > table,
.table-responsive > .table { min-width: 0 !important; width: 100% !important; }
table, .table { max-width: 100%; }

/* Tabelas processadas pelo js/responsive.js: células quebram em vez de forçar largura */
table.rt, table.rt thead, table.rt tbody, table.rt tr { white-space: normal !important; }
@media (max-width: 1024px) {
    table.rt { display: table !important; overflow: visible !important; width: 100% !important; }
    table.rt thead { display: table-header-group !important; }
    table.rt tbody { display: table-row-group !important; }
    table.rt tr { display: table-row !important; width: auto !important; }
    table.rt th, table.rt td { white-space: normal !important; }
}

/* Coluna / grupo de botões sempre no início */
td.rt-actions, th.rt-actions { white-space: nowrap; width: 1%; }
td.rt-actions .btn, td.rt-actions a.btn, td.rt-actions button { margin: 0 2px 2px 0; }
.btn-first { order: -1 !important; margin-left: 0 !important; margin-right: auto !important; }
.btn-first + * { margin-left: 0; }

/* ---------- Tabela vira cartão ---------- */
@media (max-width: 767.98px) {
    table.rt.rt-cards-ok { --rt-cards: 1; }
}
@media (max-width: 767.98px) {
    table.rt.rt-cards-ok,
    table.rt.rt-cards-ok > tbody,
    table.rt.rt-cards-ok > tbody > tr,
    table.rt.rt-cards-ok > tbody > tr > td { display: block !important; width: 100% !important; }
}
@media (max-width: 1199.98px) {
    table.rt.rt-wide.rt-cards-ok,
    table.rt.rt-wide.rt-cards-ok > tbody,
    table.rt.rt-wide.rt-cards-ok > tbody > tr,
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td { display: block !important; width: 100% !important; }
}

/* cabeçalho some visualmente (continua acessível) quando em cartão */
@media (max-width: 767.98px) {
    table.rt.rt-cards-ok > thead {
        position: absolute !important; width: 1px !important; height: 1px !important;
        overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important;
        display: block !important;
    }
}
@media (max-width: 1199.98px) {
    table.rt.rt-wide.rt-cards-ok > thead {
        position: absolute !important; width: 1px !important; height: 1px !important;
        overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important;
        display: block !important;
    }
}

@media (max-width: 767.98px) {
    table.rt.rt-cards-ok > tbody > tr {
        display: flex !important; flex-wrap: wrap; align-items: flex-start; gap: .2rem .9rem;
        padding: .6rem .7rem; margin: 0 0 .6rem; border: 1px solid rgba(128,128,128,.28) !important;
        border-radius: 10px;
    }
    table.rt.rt-cards-ok > tbody > tr > td {
        display: block !important; flex: 1 1 44%; width: auto !important; min-width: 0;
        border: 0 !important; padding: .15rem 0 !important; text-align: left !important;
    }
    table.rt.rt-cards-ok > tbody > tr > td[data-label]::before {
        content: attr(data-label); display: block; font-size: .68rem; line-height: 1.2;
        text-transform: uppercase; letter-spacing: .03em; opacity: .65; margin-bottom: 1px;
    }
    table.rt.rt-cards-ok > tbody > tr > td.rt-actions {
        order: -1; flex: 1 1 100%; display: flex !important; flex-wrap: wrap; gap: .35rem;
        padding-bottom: .4rem !important; margin-bottom: .2rem; border-bottom: 1px dashed rgba(128,128,128,.28) !important;
    }
    table.rt.rt-cards-ok > tbody > tr > td.rt-actions::before { display: none; }
    table.rt.rt-cards-ok > tbody > tr > td[colspan] { flex: 1 1 100%; }
}
@media (max-width: 1199.98px) {
    table.rt.rt-wide.rt-cards-ok > tbody > tr {
        display: flex !important; flex-wrap: wrap; align-items: flex-start; gap: .2rem .9rem;
        padding: .6rem .7rem; margin: 0 0 .6rem; border: 1px solid rgba(128,128,128,.28) !important;
        border-radius: 10px;
    }
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td {
        display: block !important; flex: 1 1 22%; width: auto !important; min-width: 0;
        border: 0 !important; padding: .15rem 0 !important; text-align: left !important;
    }
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td[data-label]::before {
        content: attr(data-label); display: block; font-size: .68rem; line-height: 1.2;
        text-transform: uppercase; letter-spacing: .03em; opacity: .65; margin-bottom: 1px;
    }
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td.rt-actions {
        order: -1; flex: 1 1 100%; display: flex !important; flex-wrap: wrap; gap: .35rem;
        padding-bottom: .4rem !important; margin-bottom: .2rem; border-bottom: 1px dashed rgba(128,128,128,.28) !important;
    }
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td.rt-actions::before { display: none; }
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td[colspan] { flex: 1 1 100%; }
}
@media (min-width: 768px) and (max-width: 1199.98px) {
    table.rt.rt-wide.rt-cards-ok > tbody > tr > td { flex-basis: 30%; }
}

/* ---------- Tablet / celular em geral ---------- */
@media (max-width: 1024px) {
    .d-flex, .btn-group, .btn-toolbar, .input-group { flex-wrap: wrap; }
    .modal-dialog { max-width: calc(100% - 16px); margin-left: auto; margin-right: auto; }
    [style*="min-width"] { min-width: 0 !important; }
    [style*="width:"][style*="px"]:not(img):not(svg):not(canvas):not(i):not(.progress-bar) { max-width: 100% !important; }
    .btn { white-space: normal; }
}
@media (max-width: 575.98px) {
    .row > [class*="col-"]:not([class*="col-6"]):not([class*="col-12"]) { flex: 0 0 100%; max-width: 100%; }
    .btn-group > .btn, .btn-toolbar > .btn { flex: 1 1 auto; }
}

@media print {
    table.rt, table.rt * { display: revert !important; }
}
