/* Padrao de TODOS os formularios internos (Usuario, Meu Perfil, cadastros, wizard, filtros, modais):
   label.form-label + form-control form-control-sm (demo forms-basic-inputs / Input Sizing / Small).
   Densidade oficial SGI (mais compacta que o .form-control-sm cru do Materialize 1.258rem):
   min-height calc(1.375em + 0.5rem + 2px), padding 0.25rem 0.5rem, font-size 0.8125rem.
   Nao usar form-floating: o Materialize forca height 3rem e o campo deixa de ser Small. */
.form-control-sm,
.form-select-sm,
select.form-control-sm,
.form-control.form-control-sm,
.form-select.form-select-sm {
  min-height: calc(1.375em + 0.5rem + 2px) !important;
  height: calc(1.375em + 0.5rem + 2px);
  padding: 0.25rem 0.5rem !important;
  font-size: 0.8125rem !important;
  border-radius: 0.375rem;
  line-height: 1.375;
}

/* O form-select desenha a seta no background: sem este recuo a seta cobre o texto. */
.form-select.form-select-sm:not([multiple]):not([size]) {
  padding-right: 1.75rem !important;
  background-position: right 0.5rem center;
}

.form-label {
  font-size: 0.8125rem;
  margin-bottom: 0.25rem;
}

/* jQuery Validator legado (help-block-error / has-error) no visual Materialize
   form-validation: borda e texto --bs-form-invalid-color (#ff4d49). */
.help-block.help-block-error,
span.help-block-error,
.has-error .help-block {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  margin-bottom: 0;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--bs-form-invalid-color, #ff4d49) !important;
}

.help-block.help-block-error.valid {
  display: none;
}

.has-error .form-control,
.has-error .form-select,
.has-error select.form-control,
.form-control.is-invalid,
select.form-control.is-invalid,
select.form-select.is-invalid,
.form-control:has(+ .help-block-error:not(.valid):not(:empty):not([style*="display: none"])),
select:has(+ .help-block-error:not(.valid):not(:empty):not([style*="display: none"])) {
  border-color: var(--bs-form-invalid-border-color, #ff4d49) !important;
}

.has-error .form-control:focus,
.form-control.is-invalid:focus,
select.form-control.is-invalid:focus {
  border-color: var(--bs-form-invalid-border-color, #ff4d49) !important;
  box-shadow: 0 0 0.25rem 0.05rem rgba(var(--bs-danger-rgb, 255, 77, 73), 0.1);
}

/* help-block dentro de input-group (select + botao) — evita caixa vermelha quebrando o flex */
.input-group > .help-block.help-block-error,
.input-group > span.help-block-error {
  flex: 0 0 100%;
  order: 99;
  width: 100%;
  margin-top: 0.25rem;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  padding-left: 0;
  padding-right: 0;
}

.input-group.has-error {
  border: 0 !important;
  box-shadow: none !important;
}

/* Textarea Small: mesma fonte/padding do input; altura minima de 2 linhas (rows no HTML pode aumentar). */
textarea.form-control-sm {
  height: auto !important;
  min-height: calc((1.375em * 2) + 0.5rem + 2px) !important;
  padding: 0.25rem 0.5rem !important;
}

/* btn-sm so quando a classe estiver no markup (Cadastrar, foto, login).
   Demais botoes fora da listagem usam o tamanho padrao da demo. Listagens = xs. */
.btn.btn-sm:not(.btn-close) {
  --bs-btn-padding-y: 0.4415rem;
  --bs-btn-padding-x: 0.969rem;
  --bs-btn-font-size: 0.8125rem;
  --bs-btn-border-radius: 0.375rem;
}

.btn-icon.btn-sm .icon-base {
  block-size: 0.8125rem;
  inline-size: 0.8125rem;
  font-size: 0.8125rem;
}

/* Remix e mask + currentColor. <a> sem href herda texto escuro do card
   via a:not([href]) { color: inherit } do Materialize — forcar a cor do botao. */
a.btn-primary:not([href]),
a.btn-primary:not([href]):hover,
a.btn-success:not([href]),
a.btn-success:not([href]):hover,
a.btn-danger:not([href]),
a.btn-danger:not([href]):hover,
a.btn-info:not([href]),
a.btn-info:not([href]):hover,
a.btn-secondary:not([href]),
a.btn-secondary:not([href]):hover {
  color: var(--bs-btn-color, #fff);
}

a.btn-primary:not([href]) span,
a.btn-success:not([href]) span,
a.btn-danger:not([href]) span,
a.btn-info:not([href]) span,
a.btn-secondary:not([href]) span {
  color: inherit;
}

.btn-primary .ri,
.btn-primary .icon-base,
.btn-success .ri,
.btn-success .icon-base,
.btn-danger .ri,
.btn-danger .icon-base,
.btn-info .ri,
.btn-info .icon-base,
.btn-secondary .ri,
.btn-secondary .icon-base {
  color: var(--bs-btn-color, #fff);
  background-color: var(--bs-btn-color, #fff);
}

.select2-container .select2-selection--single {
  min-height: calc(1.375em + 0.5rem + 2px) !important;
  height: calc(1.375em + 0.5rem + 2px) !important;
  padding: 0 !important;
  font-size: 0.8125rem;
  border-radius: 0.375rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: calc(1.375em + 0.5rem) !important;
  padding-left: 0.5rem !important;
  padding-right: 1.75rem !important;
  font-size: 0.8125rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: calc(1.375em + 0.5rem) !important;
  top: 1px !important;
  right: 0.25rem !important;
}

/* Listagens (select nativo + Select2): o popup herda texto claro do dark
   e o fundo branco do Windows/plugin — forcar cores do tema. */
[data-bs-theme=dark] select.form-control,
[data-bs-theme=dark] select.form-select,
[data-bs-theme=dark] .dataTables_wrapper .dataTables_length select {
  color-scheme: dark;
}

[data-bs-theme=dark] select option,
[data-bs-theme=dark] select optgroup {
  background-color: var(--bs-paper-bg, #30334e) !important;
  color: var(--bs-heading-color, var(--bs-body-color)) !important;
}

[data-bs-theme=dark] select option:checked {
  background-color: color-mix(in sRGB, var(--bs-primary) 28%, var(--bs-paper-bg, #30334e)) !important;
  color: var(--bs-heading-color, #fff) !important;
}

[data-bs-theme=dark] .select2-dropdown,
[data-bs-theme=dark] .select2-container--default .select2-selection--single,
[data-bs-theme=dark] .select2-container--default .select2-selection--multiple {
  background-color: var(--bs-paper-bg, #30334e);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

[data-bs-theme=dark] .select2-container--default .select2-selection--single .select2-selection__rendered,
[data-bs-theme=dark] .select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: var(--bs-body-color);
}

[data-bs-theme=dark] .select2-container--default .select2-results__option,
[data-bs-theme=dark] .select2-results__option {
  color: var(--bs-body-color);
}

[data-bs-theme=dark] .select2-container--default .select2-results__option--highlighted[aria-selected],
[data-bs-theme=dark] .select2-container--default .select2-results__option--highlighted,
[data-bs-theme=dark] .select2-results__option--highlighted {
  background-color: rgba(var(--bs-primary-rgb), 0.18) !important;
  color: var(--bs-heading-color, #fff) !important;
}

[data-bs-theme=dark] .select2-container--default .select2-results__option[aria-selected=true] {
  background-color: rgba(var(--bs-primary-rgb), 0.28);
  color: var(--bs-heading-color, #fff);
}

[data-bs-theme=dark] .select2-search--dropdown .select2-search__field {
  background-color: var(--bs-paper-bg, #30334e);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

.sgi-lang-flag {
  display: block;
  width: 22px;
  height: 16px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(67, 89, 113, 0.18);
}

/* Tema: o glifo do monitor/sol nao preenche a caixa de 22px e parece menor que a bandeira. */
.layout-navbar #nav-theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.375rem;
  height: 2.375rem;
  min-width: 2.375rem;
  padding: 0;
  line-height: 1;
}

.layout-navbar #nav-theme .theme-icon-active {
  display: block;
  width: 1.75rem !important;
  height: 1.75rem !important;
  font-size: 1.75rem !important;
  line-height: 1;
  flex: 0 0 auto;
}

/* Confirmacao / Bootbox 4 no padrao Materialize (ui-modals / Basic Modal).
   Titulo a esquerda, btn-close a direita — mesmas margens do core (.modal-header .btn-close). */
.bootbox .modal-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: var(--bs-modal-header-padding, 1.25rem 1.25rem);
}

.bootbox .modal-header .modal-title {
  order: 1;
  flex: 1 1 auto;
  margin: 0 !important;
  padding: 0;
  font-size: 1.125rem;
  font-weight: 500;
  line-height: var(--bs-modal-title-line-height, 1.375);
}

/* X alinhado ao titulo: padding + margin negativos iguais ao Materialize core.
   Nao usar width/height minúsculos — o margin-top negativo do core “puxa” o icone para cima. */
.bootbox .modal-header .close,
.bootbox .modal-header .bootbox-close-button,
.bootbox .modal-header .btn-close {
  order: 2;
  flex: 0 0 auto;
  align-self: center;
  position: static !important;
  top: auto !important;
  right: auto !important;
  float: none !important;
  box-sizing: content-box !important;
  width: 1rem !important;
  height: 1rem !important;
  padding: calc(var(--bs-modal-header-padding-y, 1.25rem) * 0.5)
    calc(var(--bs-modal-header-padding-x, 1.25rem) * 0.5) !important;
  margin-top: calc(-0.5 * var(--bs-modal-header-padding-y, 1.25rem)) !important;
  margin-right: calc(-0.5 * var(--bs-modal-header-padding-x, 1.25rem)) !important;
  margin-bottom: calc(-0.5 * var(--bs-modal-header-padding-y, 1.25rem)) !important;
  margin-left: auto !important;
  font-size: 0 !important;
  line-height: 0 !important;
  color: transparent !important;
  text-shadow: none !important;
  text-indent: 0 !important;
  background-color: transparent !important;
  background-image: var(--bs-btn-close-bg) !important;
  background-position: center !important;
  background-size: 1rem auto !important;
  background-repeat: no-repeat !important;
  border: 0 !important;
  border-radius: 0.375rem !important;
  opacity: var(--bs-btn-close-opacity, 0.75) !important;
  cursor: pointer;
}

.bootbox .modal-header .close:hover,
.bootbox .modal-header .bootbox-close-button:hover,
.bootbox .modal-header .btn-close:hover {
  opacity: var(--bs-btn-close-hover-opacity, 1) !important;
}

/* Esconde o &times; legado (texto/html) — o icone vem do background Materialize. */
.bootbox .modal-header .close > *,
.bootbox .modal-header .bootbox-close-button > * {
  display: none !important;
}

/* Demais modais BS5: garante X sem “subir” por overrides locais de tamanho. */
.modal:not(.bootbox) .modal-header .btn-close {
  align-self: center;
  position: static;
  float: none;
}

.bootbox .modal-body {
  color: var(--bs-body-color);
  font-size: 1rem;
  line-height: 1.5;
}

.bootbox .modal-body .note,
.bootbox .modal-body .alert {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
}

.bootbox .modal-body h1,
.bootbox .modal-body h2,
.bootbox .modal-body h3,
.bootbox .modal-body h4,
.bootbox .modal-body h5,
.bootbox .modal-body h6,
.bootbox .modal-body .note h4,
.bootbox .modal-body .note h4.block,
.bootbox .modal-body strong {
  font-size: 1rem !important;
  font-weight: 500 !important;
  line-height: 1.5 !important;
  margin: 0 !important;
}

.bootbox .modal-footer {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.bootbox .modal-footer .btn {
  --bs-btn-padding-y: 0.4415rem;
  --bs-btn-padding-x: 0.969rem;
  --bs-btn-font-size: 0.8125rem;
  --bs-btn-border-radius: 0.375rem;
  width: auto;
  flex: 0 1 auto;
  max-width: 100%;
  margin: 0;
  padding: 0.4415rem 0.969rem;
  font-size: 0.8125rem;
  line-height: 1.3;
  white-space: normal;
  text-align: center;
  /* Materialize .btn usa capitalize — sobrescreve para respeitar CamelCase i18n. */
  text-transform: none !important;
}

/* Confirmação Documento (Finalizar): mensagem sem note Metronic / UPPERCASE. */
.bootbox.sgi-doc-bootbox-confirm .sgi-doc-confirm-msg,
.bootbox.sgi-doc-bootbox-confirm .modal-title {
  text-transform: none;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--bs-heading-color, var(--bs-body-color));
}

.bootbox.sgi-doc-bootbox-confirm .modal-footer .btn .icon-base {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

/* Opções de revisão / aprovação (Materialize; sem portlet Metronic). */
.bootbox.sgi-doc-bootbox-opcoes .sgi-doc-confirm-msg,
.bootbox.sgi-doc-bootbox-opcoes .modal-title {
  text-transform: none;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--bs-heading-color, var(--bs-body-color));
}

.bootbox.sgi-doc-bootbox-opcoes .sgi-doc-opcoes-lista .list-group-item {
  font-size: 0.8125rem;
  padding: 0.5rem 0.75rem;
  background: color-mix(in srgb, var(--bs-paper-bg, var(--bs-body-bg)) 92%, var(--bs-primary) 8%);
  border-color: color-mix(in srgb, var(--bs-border-color) 80%, transparent);
  color: var(--bs-body-color);
}

.bootbox.sgi-doc-bootbox-opcoes .modal-footer {
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: stretch;
}

.bootbox.sgi-doc-bootbox-opcoes .modal-footer .btn {
  flex: 1 1 calc(33.333% - 0.5rem);
  min-width: min(100%, 9.5rem);
  text-transform: none !important;
  white-space: normal;
  line-height: 1.25;
}

.bootbox.sgi-doc-bootbox-aprovacao .modal-dialog {
  max-width: min(42rem, 96vw);
}

.bootbox.sgi-doc-bootbox-opcoes .modal-footer .btn .icon-base {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

/* 2 botões: tamanho padrão Materialize (nao esticar 50% em confirmações simples) */
.bootbox .modal-footer:has(> .btn:nth-child(2)) .btn {
  flex: 0 1 auto;
  min-width: 5.5rem;
}

/* Diálogo um pouco mais largo para rótulos longos (ex.: Alterar / Iniciar ACP) */
.bootbox .modal-dialog:has(.modal-footer > .btn:nth-child(2)) {
  max-width: min(36rem, 96vw);
}

@media (max-width: 420px) {
  .bootbox .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .bootbox .modal-footer .btn,
  .bootbox .modal-footer:has(> .btn:nth-child(2)) .btn {
    width: 100%;
    flex: 1 1 auto;
  }
}

/* Metronic: linha decorativa abaixo do input. No BS5 vira um segundo campo. */
.form-control-focus,
.form-control-sm-focus {
  display: none !important;
}

/* Flatpickr do Materialize (forms-pickers): calendario acima do menu e das modais. */
.flatpickr-calendar.open {
  z-index: 1090;
}

body:has(.modal.show) .flatpickr-calendar,
body:has(.modal.in) .flatpickr-calendar {
  z-index: 10080 !important;
}
