/**
 * CECWEB Core - Grid
 * Versão 0.2.1
 *
 * Estilos compartilhados para consultas, tabelas, toolbars,
 * paginação, seleção de colunas e impressão.
 */

:root {
    --cec-border: #dfe6ef;
    --cec-head: #eef3f8;
    --cec-hover: #eaf3ff;
    --cec-zebra: #f8fafc;
}

/* Estrutura geral das telas de consulta */
body {
    margin: 0;
    background: #f4f7fb;
    color: #253247;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.page-header {
    padding: 13px 18px;
    color: #fff;
    background: linear-gradient(135deg, #172b4d, #244b7a);
}

.page-header h1 {
    margin: 0;
    font-size: 18px;
}

.page-header small {
    opacity: .78;
}

.conteudo,
.cec-content {
    width: 100%;
    padding: 10px 12px 12px;
}

.card-cec,
.cec-card {
    width: 100%;
    background: #fff;
    border: 1px solid var(--cec-border);
    border-radius: 11px;
    box-shadow: 0 5px 18px rgba(31, 45, 61, .06);
}

/* Campos compactos */
.form-label {
    margin-bottom: 2px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: #667085;
}

.form-control-sm,
.form-select-sm,
.btn-sm {
    min-height: 29px;
    font-size: 11px;
}

/* Barra de pesquisa e ações */
.toolbar {
    padding: 11px;
    margin-bottom: 10px;
}

.toolbar-linha {
    display: flex;
    align-items: flex-end;
    width: 100%;
    gap: 10px;
}

.toolbar-busca {
    flex: 1 1 auto;
    min-width: 280px;
}

.toolbar-acoes {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
}

.toolbar-acoes .btn {
    height: 29px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

/* Grid genérica */
.cec-grid-wrap {
    overflow: auto;
    border: 1px solid var(--cec-border);
    border-radius: 8px;
}

.cec-grid {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    white-space: nowrap;
}

.cec-grid thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 7px 6px;
    border-bottom: 1px solid #cfd8e3;
    background: var(--cec-head);
    font-size: .72rem;
    text-transform: uppercase;
}

.cec-grid tbody td {
    padding: 6px;
    border-bottom: 1px solid #e8edf3;
}

.cec-grid tbody tr:nth-child(even) {
    background: var(--cec-zebra);
}

.cec-grid tbody tr:hover {
    background: var(--cec-hover);
}

.cec-grid-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 9px 11px;
    background: #fff;
    border: 1px solid var(--cec-border);
    border-top: 0;
}

/* Grid administrativa compacta */
.table-wrap {
    height: calc(100vh - 180px);
    min-height: 560px;
    overflow: auto;
}

.table-clientes {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 10.5px;
    white-space: nowrap;
}

.table-clientes thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 7px 6px;
    border-bottom: 1px solid #cfd8e3;
    background: var(--cec-head);
    color: #425466;
    font-size: 9.5px;
    text-transform: uppercase;
}

.table-clientes tbody td {
    padding: 5px 6px;
    border-bottom: 1px solid #e8edf3;
    vertical-align: middle;
}

.table-clientes tbody tr:nth-child(even) {
    background: var(--cec-zebra);
}

.table-clientes tbody tr:hover {
    background: var(--cec-hover);
}

/* Colunas e ações */
.col-acoes {
    position: sticky;
    left: 0;
    z-index: 2;
    width: 74px;
    min-width: 74px;
    text-align: center;
    background: inherit;
    border-right: 1px solid #d8e0e9;
}

.table-clientes thead .col-acoes,
.cec-grid thead .col-acoes {
    z-index: 5;
    background: var(--cec-head);
}

.btn-acao-grid {
    width: 27px;
    height: 25px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}

.col-numero {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.col-centro {
    text-align: center;
}

.nome-cliente {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Rodapé e paginação */
.footer-grid {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 9px 11px;
    border-top: 1px solid var(--cec-border);
}

/* Seletor e ordenação de colunas */
.coluna-opcao {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.item-coluna {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #dfe6ef;
    border-radius: 7px;
    background: #fff;
    cursor: grab;
    user-select: none;
}

.item-coluna:hover {
    background: #f6f9fc;
    border-color: #bfcbd9;
}

.item-coluna.arrastando {
    opacity: .45;
}

.item-coluna.destino-arraste {
    border-top: 3px solid #0d6efd;
}

.item-coluna .grip {
    color: #98a2b3;
    cursor: grab;
}

.item-coluna .nome-coluna {
    flex: 1;
    font-weight: 600;
    color: #344054;
}

.item-coluna .ordem-coluna {
    min-width: 23px;
    text-align: center;
    color: #98a2b3;
    font-size: 10px;
}

/* Listas e badges */
.lista-convenios {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    max-width: 360px;
}

.badge-convenio {
    display: inline-flex;
    align-items: center;
    padding: 3px 6px;
    border-radius: 999px;
    background: #e7f1ff;
    color: #0b5ed7;
    font-size: 9px;
    font-weight: 700;
}

.estado-vazio,
.cec-empty-state {
    padding: 32px;
    text-align: center;
    color: #667085;
}

/* Responsividade */
@media (max-width: 900px) {
    .toolbar-linha {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-acoes {
        justify-content: flex-start;
    }

    .toolbar-busca {
        min-width: 0;
        width: 100%;
    }

    .table-wrap {
        min-height: 420px;
    }
}

/* Impressão */
@media print {
    .no-print,
    .cec-no-print,
    .page-header {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .conteudo,
    .cec-content {
        padding: 0;
    }

    .card-cec,
    .cec-card {
        border: 0;
        box-shadow: none;
    }

    .table-wrap,
    .cec-grid-wrap {
        height: auto;
        min-height: 0;
        overflow: visible;
        border: 0;
    }

    .table-clientes,
    .cec-grid {
        font-size: 8px;
    }
}

/* ==========================================================================
 * Consulta de contratos em tela cheia
 * ========================================================================== */

.cec-grid-fullscreen {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.cec-grid-fullscreen .cec-page {
    height: 100%;
    overflow: hidden;
}

.cec-grid-fullscreen .conteudo,
.cec-grid-fullscreen .cec-content {
    display: flex;
    width: 100%;
    height: calc(100vh - 58px);
    min-height: 0;
    flex-direction: column;
    padding: 10px 12px 12px;
    overflow: hidden;
}

.card-grid {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    padding: 8px;
    overflow: hidden;
}

.card-grid .table-wrap {
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    height: auto;
    overflow: auto;
    border: 1px solid #edf1f5;
    border-radius: 7px 7px 0 0;
}

.table-contratos {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 10.5px;
    white-space: nowrap;
}

.table-contratos thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 7px 6px;
    color: #425466;
    background: var(--cec-head);
    border-bottom: 1px solid #cfd8e3;
    font-size: 9.5px;
    text-transform: uppercase;
}

.table-contratos tbody td {
    padding: 5px 6px;
    border-bottom: 1px solid #e8edf3;
    vertical-align: middle;
}

.table-contratos tbody tr:nth-child(even) {
    background: var(--cec-zebra);
}

.table-contratos tbody tr:hover {
    background: var(--cec-hover);
}

.table-contratos thead .col-acoes {
    z-index: 12;
    background: var(--cec-head);
}

.table-contratos .nome-cliente {
    max-width: 230px;
}

.card-grid .footer-grid {
    position: relative;
    z-index: 12;
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid #edf1f5;
    border-top: 0;
    border-radius: 0 0 7px 7px;
}

.badge-situacao {
    display: inline-flex;
    max-width: 170px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge-primary {
    color: #fff;
    background: #0d6efd;
}

.badge-red {
    color: #fff;
    background: #dc3545;
}

.badge-info {
    color: #073642;
    background: #0dcaf0;
}

.badge-warning {
    color: #3d3300;
    background: #ffc107;
}

.badge-success {
    color: #fff;
    background: #198754;
}

.badge-yellow {
    color: #4a4100;
    background: #ffea70;
}

.badge-green {
    color: #fff;
    background: #20a464;
}

.badge-default {
    color: #fff;
    background: #6c757d;
}

@media print {
    .cec-grid-fullscreen,
    .cec-grid-fullscreen .cec-page {
        height: auto;
        overflow: visible;
    }

    .cec-grid-fullscreen .conteudo,
    .cec-grid-fullscreen .cec-content {
        height: auto;
        overflow: visible;
        padding: 0;
    }

    .card-grid .table-wrap {
        overflow: visible;
    }

    .table-contratos {
        font-size: 8px;
    }
}

/* Alinhamento dos botões da coluna fixa de ações */
.col-acoes {
    vertical-align: middle;
}

.grid-acoes {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    min-height: 25px;
    white-space: nowrap;
}

.grid-acoes .btn-acao-grid {
    flex: 0 0 27px;
    margin: 0 !important;
    line-height: 1;
}

.grid-acoes .btn-acao-grid i {
    display: block;
    line-height: 1;
}

/* ==========================================================================
 * Correções de prioridade após Bootstrap
 * ========================================================================== */

.cec-card.toolbar {
    display: block;
    flex: 0 0 auto;
    padding: 11px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid var(--cec-border);
    border-radius: 11px;
    box-shadow: 0 5px 18px rgba(31, 45, 61, .06);
}

.cec-card.toolbar .toolbar-linha {
    display: flex;
    width: 100%;
    align-items: flex-end;
    gap: 10px;
}

.cec-card.toolbar .toolbar-busca {
    display: block;
    flex: 1 1 auto;
    min-width: 280px;
}

.cec-card.toolbar .toolbar-acoes {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
}

.cec-card.toolbar .cec-quicksearch-group {
    display: flex;
    width: 100%;
}

.cec-card.toolbar .cec-quicksearch-group .form-control {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
}

.cec-card.toolbar .cec-quicksearch-group .input-group-text,
.cec-card.toolbar .cec-quicksearch-group .form-control,
.cec-card.toolbar .cec-quicksearch-group .btn,
.cec-card.toolbar .toolbar-acoes .btn {
    min-height: 31px;
    font-size: 11px;
}

.cec-card.toolbar .toolbar-acoes .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

/* Coluna de ações da grid */
.table-contratos .col-acoes {
    width: 82px;
    min-width: 82px;
    padding: 4px !important;
    vertical-align: middle;
}

.table-contratos .grid-acoes {
    display: flex;
    width: 100%;
    min-height: 27px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

.table-contratos .grid-acoes .btn-acao-grid {
    display: inline-flex;
    width: 29px;
    height: 27px;
    min-width: 29px;
    min-height: 27px;
    flex: 0 0 29px;
    align-items: center;
    justify-content: center;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 5px;
    font-size: 11px;
    line-height: 1;
}

.table-contratos .grid-acoes .btn-acao-grid i {
    display: inline-block;
    width: auto;
    height: auto;
    margin: 0;
    line-height: 1;
}

@media (max-width: 900px) {
    .cec-card.toolbar .toolbar-linha {
        align-items: stretch;
        flex-direction: column;
    }

    .cec-card.toolbar .toolbar-busca {
        width: 100%;
        min-width: 0;
    }

    .cec-card.toolbar .toolbar-acoes {
        justify-content: flex-start;
    }
}
