/* RBS Oficina - camada responsiva compartilhada
   Mantem o layout desktop existente e melhora telas menores sem alterar a logica PHP. */

* { box-sizing: border-box; }
img { max-width: 100%; height: auto; }
textarea.form-control { min-height: 96px; resize: vertical; }

/* Pequenos refinamentos que tambem ajudam em tablets. */
.page-header .btn { margin-bottom: 6px; }
.table > thead > tr > th { vertical-align: middle; }
.table > tbody > tr > td { vertical-align: middle; }

@media (max-width: 767px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 0 28px !important;
        font-size: 14px;
        -webkit-text-size-adjust: 100%;
    }

    body::after,
    .fundo {
        background-attachment: scroll !important;
    }

    .wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 10px !important;
    }

    .container,
    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    [class*="col-xs-"],
    [class*="col-sm-"],
    [class*="col-md-"],
    [class*="col-lg-"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .page-header {
        margin: 10px 0 16px !important;
        padding-bottom: 10px !important;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: stretch;
    }

    .page-header h1,
    .page-header h2,
    .page-header h3 {
        width: 100%;
        float: none !important;
        margin: 0 0 4px !important;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .page-header h2 { font-size: 24px; }

    .page-header .pull-left,
    .page-header .pull-right {
        float: none !important;
    }

    .page-header > .btn,
    .page-header > a.btn {
        flex: 1 1 145px;
        margin: 0 !important;
        min-width: 0;
    }

    /* Botoes soltos no topo passam a se organizar melhor em linhas. */
    .wrapper > .btn,
    .container-fluid > .btn,
    .col-md-12 > .btn.pull-left,
    .col-md-12 > .btn.pull-right {
        float: none !important;
        margin: 0 6px 8px 0 !important;
    }

    .btn {
        min-height: 40px;
        padding: 9px 12px;
        border-radius: 7px;
        white-space: normal;
        touch-action: manipulation;
    }

    .btn-xs,
    .btn-sm {
        min-height: 34px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .form-group { margin-bottom: 14px; }

    label {
        margin-bottom: 6px;
        line-height: 1.3;
    }

    .form-control {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 42px;
        height: auto;
        padding: 9px 10px;
        font-size: 16px; /* evita zoom automatico no iPhone */
        border-radius: 7px;
    }

    input[type="file"].form-control {
        min-height: 46px;
        padding: 8px;
    }

    textarea.form-control { min-height: 105px; }

    .select2-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    .select2-container .select2-selection--single {
        min-height: 42px !important;
    }

    .alert {
        margin-bottom: 14px;
        padding: 12px;
        overflow-wrap: anywhere;
    }

    /* Tabelas transformadas em cards pelo mobile.js. */
    table.mobile-card-table {
        display: block !important;
        width: 100% !important;
        border: 0 !important;
        background: transparent !important;
    }

    table.mobile-card-table thead {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    table.mobile-card-table tbody,
    table.mobile-card-table tr,
    table.mobile-card-table td {
        display: block !important;
        width: 100% !important;
    }

    table.mobile-card-table tbody tr {
        margin: 0 0 12px !important;
        padding: 4px 11px !important;
        border: 1px solid rgba(0, 0, 0, .12) !important;
        border-radius: 10px !important;
        background: rgba(255, 255, 255, .96) !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, .07);
    }

    table.mobile-card-table tbody td {
        min-height: 38px;
        margin: 0 !important;
        padding: 9px 0 !important;
        border: 0 !important;
        border-bottom: 1px solid rgba(0, 0, 0, .08) !important;
        text-align: left !important;
        overflow-wrap: anywhere;
    }

    table.mobile-card-table tbody td:last-child {
        border-bottom: 0 !important;
    }

    table.mobile-card-table tbody td[data-label]:not([data-label=""]) {
        display: grid !important;
        grid-template-columns: minmax(108px, 38%) minmax(0, 1fr);
        gap: 10px;
        align-items: center;
    }

    table.mobile-card-table tbody td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        font-weight: 700;
        color: #444;
        line-height: 1.25;
    }

    table.mobile-card-table tbody td.mobile-actions-cell {
        display: block !important;
        padding-top: 10px !important;
    }

    table.mobile-card-table tbody td.mobile-actions-cell::before {
        display: block;
        margin-bottom: 8px;
    }

    table.mobile-card-table tbody td.mobile-actions-cell a,
    table.mobile-card-table tbody td.mobile-actions-cell button,
    table.mobile-card-table tbody td.mobile-actions-cell .btn,
    table.mobile-card-table tbody td.mobile-actions-cell form {
        margin: 2px 5px 2px 0 !important;
    }

    table.mobile-card-table tbody td.mobile-actions-cell form {
        display: inline-block !important;
    }

    /* Quando uma tabela nao puder virar card, ela continua utilizavel com rolagem. */
    .table-responsive {
        width: 100%;
        margin-bottom: 15px;
        border: 0;
        -webkit-overflow-scrolling: touch;
    }

    table.mobile-scroll-table {
        min-width: 620px;
    }

    .thumbnail,
    .img-thumbnail {
        max-width: 100%;
        height: auto;
    }

    pre, code {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

    /* Calendario lateral do desktop nao deve reservar espaco no celular. */
    .calendario { display: none !important; }

    /* Selects, caixas e paineis antigos com largura inline deixam de estourar. */
    [style*="width: 500px"],
    [style*="width:500px"],
    [style*="width: 650px"],
    [style*="width:650px"] {
        max-width: 100% !important;
    }
}

@media (max-width: 420px) {
    .wrapper { padding: 8px !important; }
    .page-header h2 { font-size: 22px; }

    .page-header > .btn,
    .page-header > a.btn {
        flex-basis: 100%;
    }

    table.mobile-card-table tbody td[data-label]:not([data-label=""]) {
        grid-template-columns: 1fr;
        gap: 3px;
    }
}

@media print {
    /* A camada mobile nao interfere na impressao/PDF. */
    table.mobile-card-table { display: table !important; }
    table.mobile-card-table thead { position: static !important; width: auto !important; height: auto !important; overflow: visible !important; clip: auto !important; }
    table.mobile-card-table tbody { display: table-row-group !important; }
    table.mobile-card-table tr { display: table-row !important; }
    table.mobile-card-table td { display: table-cell !important; }
    table.mobile-card-table td::before { display: none !important; content: none !important; }
}
