/******************************************* Variáveis **************************************************/
/* Ajuste de hover para ambos os temas */
html[data-bs-theme="dark"] .table {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.075) !important;
}

html[data-bs-theme="light"] .table {
    --bs-table-hover-bg: rgba(0, 0, 0, 0.075) !important;
}

/******************************************* Formatação de Texto ****************************************/
/* Desabilita text-transform do Bootstrap para permitir formatação JavaScript customizada
   que respeita regras do português (preposições em minúscula) */
input.text-capitalize,
textarea.text-capitalize {
    text-transform: none !important;
}

/************************************************* Base *************************************************/
html,
body {
    width: 100%;
    height: 100%;
    padding: 0px;
    margin: 0px;
}

a,
tr,
td,
li,
button,
i {
    cursor: pointer;
}

textarea {
    resize: none;
}

/************************************************ Styles ************************************************/
.principal {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow: hidden;
}

.window {
    padding: .25rem;
    width: 100%;
    max-height: -webkit-fill-available;
    height: -webkit-fill-available;
}

.janela {
    max-height: 100%;
    height: 100%;
    display: grid;
    gap: .25rem;
    align-content: stretch;
}

/************************************************ Tabelas ************************************************/
/* Cabeçalho de tabelas - usando cores do tema */
/* Hierarquia de z-index para sticky elements */
.table thead.sticky-top {
    z-index: 3;
    position: sticky;
}

.table thead th {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
    border-color: var(--bs-border-color);
    position: sticky;
    top: 0;
    z-index: 3;
}

.table tbody tr.group.sticky-top {
    z-index: 2;
}

.table tfoot.sticky-bottom {
    z-index: 3;
    position: sticky;
}

.table>thead>tr>th:has(i.bi-plus-lg) {
    border-left: 1px solid var(--bs-border-color);
    text-align: center;
}

/* Ordenação de colunas */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 2rem;
}

.table thead th.sortable:hover {
    background-color: var(--bs-tertiary-bg);
}

.table thead th.sortable::after {
    content: '⇅';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    font-size: 0.8em;
}

.table thead th.sortable:hover::after {
    opacity: 0.6;
}

.table thead th.sort-asc::after,
.table thead th.sort-desc::after {
    opacity: 1;
    color: var(--bs-primary);
}

.table thead th.sort-asc::after {
    content: '▲';
}

.table thead th.sort-desc::after {
    content: '▼';
}

/* Indicador de ordenação composta (múltiplas colunas) - Badge ao lado da seta */
.table thead th[data-sort-priority]::before {
    content: attr(data-sort-priority);
    position: absolute;
    right: 1.4rem;
    top: 50%;
    transform: translateY(-50%);
    background-color: var(--bs-primary);
    color: var(--bs-white);
    border-radius: 50%;
    width: 0.9rem;
    height: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55em;
    font-weight: bold;
    line-height: 1;
}

/* Para títulos alinhados à direita, ajusta posição */
.table thead th.text-end[data-sort-priority]::before {
    right: auto;
    left: 1.4rem;
}

.table thead th.text-end.sortable {
    padding-right: 0.5rem;
    padding-left: 2rem;
}

.table thead th.text-end.sortable::after {
    right: auto;
    left: 0.5rem;
}

/* Esconde badge quando é ordenação única (priority = 1) */
.table thead th[data-sort-priority="1"]::before {
    display: none;
}

/* Corpo das tabelas */
.table tbody td {
    border-color: var(--bs-border-color);
    border-width: 0 1px;
    padding: .25rem .5rem;
}

.table tbody tr.group-total>td {
    border: none;
    padding: .25rem .5rem;
}

.table tbody td:first-child {
    border-left-width: 0;
}

.table tbody td:last-child {
    border-right-width: 0;
}

/* Rodapé das tabelas */
.table tfoot td {
    padding: .25rem .5rem;
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-emphasis-color);
    border-color: var(--bs-border-color);
    font-weight: 500;
}

/* Classes de cor nas linhas */
.table tbody tr.secondary>td {
    color: var(--bs-secondary-color);
}

.table tbody tr.tertiary>td {
    color: var(--bs-tertiary-color);
}

.table tbody tr.danger>td {
    color: var(--bs-danger);
}

.table tbody tr.warning>td {
    color: var(--bs-warning);
}

.table tbody tr.info>td {
    color: var(--bs-info);
}

.table tbody tr.success>td {
    color: var(--bs-success);
}

/* Linha selecionada - agora usando variáveis Bootstrap */
.table .selecionado td {
    background-color: var(--bs-primary) !important;
    color: var(--bs-white) !important;
}

.table .selecionado td i {
    text-shadow: none;
    color: var(--bs-white);
}

td.text-truncate {
    max-width: 0;
}

/************************************************* Alterações *************************************************/
.card-header i,
.offcanvas-body i,
.navbar i,
.btn i:not(:only-child) {
    margin-right: .5rem;
}

.nav {
    z-index: 1021;
}

.offcanvas-body a {
    text-decoration: none;
    color: var(--bs-heading-color);
}

.janela>.card>.card-body {
    padding: 0px;
    overflow-y: auto;
    height: 100px;
}

ul.dropdown-menu {
    z-index: 2000;
}

/* Estilos para itens de tema no menu */
.dropdown-item.active {
    position: relative;
    background-color: var(--bs-primary-bg-subtle) !important;
    color: var(--bs-primary-text-emphasis) !important;
}

.dropdown-item.active::after {
    content: "✓";
    position: absolute;
    right: 10px;
    font-weight: bold;
    color: var(--bs-primary);
}

.dropdown-item i {
    margin-right: 8px;
    width: 16px;
    text-align: center;
}

.bootbox.secondary {
    z-index: 1056;
}

.bootbox.secondary+.modal-backdrop {
    z-index: 1055;
    opacity: 0.75 !important;
}

.bootbox.secondary .modal-content {
    --bs-bg-opacity: 1;
    background-color: rgba(var(--bs-secondary-bg-rgb), var(--bs-bg-opacity)) !important;
}

.bootbox.tertiary {
    z-index: 1057;
}

.bootbox.tertiary+.modal-backdrop {
    z-index: 1056;
    opacity: 0.85 !important;
}

.bootbox.tertiary .modal-content {
    --bs-bg-opacity: 1;
    background-color: rgba(var(--bs-tertiary-bg-rgb), var(--bs-bg-opacity)) !important;
}

.bootbox.tertiary {
    z-index: 1057;
}

.bootbox.tertiary+.modal-backdrop {
    z-index: 1056;
    opacity: 0.85 !important;
}

.bootbox.tertiary .modal-content {
    color: #000 !important;
    background-color: RGBA(255, 255, 255, var(--bs-bg-opacity, 1)) !important;
}

.bootbox.p-0 .modal-body {
    padding: 0px;
}

.bootbox.p-1 .modal-body {
    padding: .25rem;
}

.bootbox.p-2 .modal-body {
    padding: .5rem;
}

.bootbox.p-3 .modal-body {
    padding: .75rem;
}

.bootbox.p-4 .modal-body {
    padding: 1rem;
}

.bootbox.p-5 .modal-body {
    padding: 1.25rem;
}

.bootbox.pdf .modal-dialog {
    height: 80% !important;
}

.bootbox.pdf .modal-content {
    height: 100% !important;
}

.bootbox.pdf .modal-body {
    padding: 0px;
}

.bootbox.pdf .bootbox-body {
    height: 100% !important;
}

/************************************************* Diversos *************************************************/
.col-minima {
    width: 10px !important;
    white-space: nowrap;
}

.preSelect {
    flex-grow: 5 !important;
}

.preSelect+.form-control {
    flex-grow: 50 !important;
}

input.sem-seletor::-webkit-calendar-picker-indicator,
input.sem-seletor::-webkit-inner-spin-button {
    display: none;
}

input.sem-seletor {
    appearance: textfield;
    -moz-appearance: textfield;
}

.scroll {
    overflow-y: auto;
    white-space: nowrap;
}

/******************************************** Ajustes de largura **************************************************/
form>div:has(.parent-100) {
    width: 100% !important;
}

form>div:has(.parent-75) {
    width: calc(75% - 0.25rem) !important;
}

form>div:has(.parent-50) {
    width: calc(50% - 0.25rem) !important;
}

form>div:has(.parent-25) {
    width: calc(25% - 0.25rem) !important;
}

form>div:has(.d-none) {
    display: none;
}

/* Exceção: permitir exibição de containers com input[type="file"] oculto no formulário de perfil */
#formUser>div:has(input[type="file"].d-none) {
    display: block !important;
}

form>.row:last-of-type {
    margin-bottom: 0px;
}

/************************************************ DatePicker ************************************************/
.datepicker table tr td.range,
.datepicker table tr td.range:hover,
.datepicker table tr td.range.disabled,
.datepicker table tr td.range.disabled:hover,
.datepicker table tr td.day:hover,
.datepicker table tr td.day.focused,
.datepicker table tr td span:hover,
.datepicker table tr td span.focused,
.datepicker .datepicker-switch:hover,
.datepicker .prev:hover,
.datepicker .next:hover,
.datepicker tfoot tr th:hover,
.datepicker table tr td.highlighted {
    color: var(--bs-secondary-text-emphasis);
    background-color: var(--bs-border-color);
}

.datepicker table tr td.day.today {
    background: var(--bs-info) !important;
    color: var(--bs-black);
}

.datepicker table tr td.day.today.active {
    background: var(--bs-primary) !important;
}

.datepicker table tr td.active.highlighted.day {
    background: var(--bs-primary) !important;
    color: var(--bs-light);
}

.datepicker table tr td.day:hover {
    background: var(--bs-secondary) !important;
    color: var(--bs-light);
}

/********************* Estiliza o Flexdatalist com base nas variáveis CSS do Bootstrap **********************/
.flexdatalist-results {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    box-shadow: var(--bs-box-shadow-sm);
    list-style: none;
    padding: 0;
    margin-top: 0.25rem;
}

.flexdatalist-results li {
    padding: 0.5rem 1rem;
    color: var(--bs-body-color);
    cursor: pointer;
}

.flexdatalist-results li:hover,
.flexdatalist-results li.active {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

.flexdatalist-multiple {
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    color: var(--bs-body-color);
}

.flexdatalist-multiple li {
    background-color: var(--bs-primary);
    color: var(--bs-light);
    border-radius: 0.2rem;
    padding: 0.25rem 0.5rem;
    margin: 0.25rem;
}

/********************* Extensão do  **********************/
.h-0 {
    height: 0 !important;
}

.h-none {
    height: auto !important;
}

/******************************************** Ajustes de Tema usando variáveis Bootstrap **************************************************/
/* Usando variáveis CSS nativas do Bootstrap para dark/light mode */

/* Card Headers - usando cores do tema */
.card-header {
    background-color: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
    color: var(--bs-emphasis-color);
}

.card-header i {
    color: var(--bs-emphasis-color);
}

/* Modal Headers - usando cores do tema */
.modal-header {
    background-color: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
    color: var(--bs-emphasis-color);
}

.modal-header .modal-title {
    color: var(--bs-emphasis-color);
}

.modal-header .btn-close {
    opacity: 1;
}

.modal-header i {
    color: var(--bs-emphasis-color);
}

/* Bootbox específico */
.bootbox .modal-header {
    background-color: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
    color: var(--bs-emphasis-color);
}

.bootbox .modal-header h5,
.bootbox .modal-header h4 {
    color: var(--bs-emphasis-color) !important;
}

.bootbox .modal-header i {
    color: var(--bs-emphasis-color) !important;
}

/* Tabelas - linha selecionada */
.table .selecionado td {
    background-color: var(--bs-primary) !important;
    color: var(--bs-white) !important;
}

/* Select2 com variáveis Bootstrap */
.select2-container--bootstrap-5 .select2-selection {
    background-color: var(--bs-body-bg) !important;
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: var(--bs-body-color) !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    color: var(--bs-white) !important;
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

/* Botão de remover (X) nas tags - melhor visibilidade */
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove,
.select2-selection__choice__remove {
    position: relative !important;
    color: transparent !important;
    opacity: 1 !important;
    font-weight: 900 !important;
    font-size: 1.6em !important;
    margin-left: 8px !important;
    margin-right: 0 !important;
    transition: all 0.2s ease !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    visibility: visible !important;
    line-height: 1 !important;
    padding: 4px 6px !important;
    cursor: pointer !important;
    background: rgba(255, 255, 255, 0.15) !important;
    border-radius: 3px !important;
    width: auto !important;
    height: auto !important;
    min-width: 24px !important;
    min-height: 24px !important;
    order: 1 !important;
    flex-shrink: 0 !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove::before,
.select2-selection__choice__remove::before {
    content: '×' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    color: rgba(255, 255, 255, 0.95) !important;
    font-size: 1.5em !important;
    font-weight: 900 !important;
    line-height: 1 !important;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.9) !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice .select2-selection__choice__display,
.select2-selection__choice__display {
    order: 0 !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove:hover,
.select2-selection__choice__remove:hover {
    background-color: rgba(255, 0, 0, 0.4) !important;
    transform: scale(1.15) !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove:hover::before,
.select2-selection__choice__remove:hover::before {
    color: rgba(255, 255, 255, 1) !important;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 1) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered .select2-selection__placeholder {
    color: var(--bs-secondary-color) !important;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field {
    background-color: var(--bs-body-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color);
}

.select2-container--bootstrap-5 .select2-dropdown {
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
    background-color: var(--bs-body-bg);
}

.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option[role=group] .select2-results__group {
    color: var(--bs-secondary-color) !important;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option--highlighted {
    background-color: var(--bs-primary);
    color: var(--bs-white);
}

.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option--selected {
    background-color: var(--bs-secondary-bg);
}

/* Z-index para dropdown do Select2 em modais */
.select2-container--open .select2-dropdown {
    z-index: 9999 !important;
}

.select2-container {
    z-index: 2 !important;
}

/* Flexdatalist com variáveis Bootstrap */
.flexdatalist-results li:hover,
.flexdatalist-results li.active {
    background-color: var(--bs-primary);
    color: var(--bs-white);
}

.flexdatalist-multiple li {
    background-color: var(--bs-primary);
    color: var(--bs-white);
}

/* Form controls - ajustes finos */
.form-label {
    font-weight: 500;
}

/* DatePicker com variáveis Bootstrap */
.datepicker {
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

.datepicker table tr td.day.today {
    background: var(--bs-info) !important;
    color: var(--bs-emphasis-color);
}

.datepicker table tr td.day.today.active,
.datepicker table tr td.active.highlighted.day {
    background: var(--bs-primary) !important;
    color: var(--bs-white);
}

.datepicker table tr td.day:hover {
    background: var(--bs-secondary-bg) !important;
    color: var(--bs-body-color);
}