/**
 * REBANHO — Componentes compartilhados (Jobick)
 * Cards, tabelas, modais, filtros, loading, estados vazios
 */

/* Aliases da regra → implementação vigente */
.rebanho-stat-card {
  border: 1px solid var(--rebanho-border);
  border-top: 4px solid var(--rebanho-primary);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  background: var(--rebanho-card-bg);
}

.rebanho-stat-card .card-body {
  padding: 1rem 1.1rem;
}

/* Home — alias documentado na regra */
.rebanho-home-stat-card {
  border: 1px solid var(--rebanho-border);
  border-radius: 14px;
  background: var(--rebanho-card-bg);
}

.rebanho-card,
.rebanho-page-header {
  border: 1px solid var(--rebanho-border);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.rebanho-card-link {
  color: var(--rebanho-primary);
  font-weight: 600;
  text-decoration: none;
}

.rebanho-card-link:hover {
  text-decoration: underline;
}

/* Summary cards — variantes de cor no topo */
.rebanho-summary-card--warning {
  border-top-color: var(--rebanho-warning) !important;
}

.rebanho-summary-card--purple {
  border-top-color: #6f42c1 !important;
}

.rebanho-summary-card--danger {
  border-top-color: var(--rebanho-danger) !important;
}

.rebanho-summary-card--success {
  border-top-color: var(--rebanho-success) !important;
}

.rebanho-summary-card--info {
  border-top-color: var(--rebanho-info) !important;
}

/* Tabelas — alias rebanho-table */
.rebanho-table,
table.painel-lista-table {
  margin-bottom: 0;
}

.rebanho-table thead th,
table.painel-lista-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--rebanho-muted);
  border-bottom-width: 1px;
  white-space: nowrap;
}

.rebanho-table tbody td,
table.painel-lista-table tbody td {
  vertical-align: middle;
}

.rebanho-dt-icon-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.rebanho-dt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-end;
}

/* Modais padronizados */
.rebanho-modal .modal-header.rebanho-home-modal-header,
.rebanho-home-modal .modal-header.rebanho-home-modal-header {
  background: #fff !important;
  border-bottom: 1px solid #eef1f6;
  color: #212529;
}

.rebanho-home-modal .modal-header.bg-primary,
.rebanho-admin-scope .modal .modal-header.bg-primary,
.painel-modulo-interno .modal .modal-header.bg-primary {
  background: #fff !important;
  border-bottom: 1px solid #eef1f6;
  color: #212529;
}

.rebanho-home-modal .modal-header.bg-primary .modal-title,
.rebanho-admin-scope .modal .modal-header.bg-primary .modal-title {
  color: #212529 !important;
}

.rebanho-home-modal .modal-header .btn-close,
.rebanho-admin-scope .modal .modal-header .btn-close {
  filter: none;
  opacity: 0.55;
}

.rebanho-home-modal .btn-primary,
.rebanho-modal .btn-primary {
  background-color: var(--rebanho-primary);
  border-color: var(--rebanho-primary);
}

/* Filtros — pills */
.rebanho-filter-pills .nav-link.rebanho-filt-pill {
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  color: var(--rebanho-muted);
  border: 1px solid var(--rebanho-border);
  background: #fff;
}

.rebanho-filter-pills .nav-link.rebanho-filt-pill.active {
  background: var(--rebanho-primary);
  border-color: var(--rebanho-primary);
  color: #fff;
}

/* Loading global */
.rebanho-loading {
  position: fixed;
  inset: 0;
  background: rgba(245, 247, 251, 0.72);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rebanho-loading-box {
  background: #fff;
  border: 1px solid var(--rebanho-border);
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  text-align: center;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}

.rebanho-loading-box .spinner-border,
.rebanho-inline-loading .spinner-border,
.rebanho-preloader-inner .spinner-border {
  color: var(--rebanho-primary) !important;
  width: 2.5rem;
  height: 2.5rem;
}

/* Preloader inicial (substitui lds-ripple) */
#preloader.rebanho-preloader {
  background: var(--rebanho-bg, #f5f7fb);
}

#preloader.rebanho-preloader .rebanho-preloader-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* Estados vazios */
.rebanho-empty-state {
  border: 1px dashed #e0e6ed;
  border-radius: 0.5rem;
  background: #fafbfd;
  padding: 1.25rem 1rem;
  text-align: center;
}

.rebanho-empty-state .fa,
.rebanho-empty-state .fas {
  color: var(--rebanho-muted);
}

/* Logs — tabela com quebra de linha */
#tabela-logs td {
  white-space: normal;
  word-wrap: break-word;
  vertical-align: middle;
}

.rebanho-logs-filters .dataTables_wrapper .row {
  margin-bottom: 10px;
  align-items: center;
}

/* Acompanhamento — selects solid, filtros, formulário e editor */
.acomp-modulo-shell #form_acompanhamento select.form-select.solid,
.acomp-modulo-shell #listar .acomp-filtros-bar select.form-select.solid,
.acomp-modulo-shell #listar .acomp-filtros-bar input.form-control.solid {
  background-color: var(--light, #f5f7fb);
  border: 1px solid var(--light, #edf0f5);
  color: var(--text-dark, #212529);
  min-height: 2.85rem;
  height: 2.85rem;
  padding: 0.3125rem 2.25rem 0.3125rem 1.25rem;
  border-radius: 0.5rem;
  font-size: inherit;
  line-height: 1.5;
  box-shadow: none;
}

.acomp-modulo-shell #listar .acomp-filtros-bar input.form-control.solid {
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

@media only screen and (max-width: 1480px) {
  .acomp-modulo-shell #form_acompanhamento select.form-select.solid,
  .acomp-modulo-shell #listar .acomp-filtros-bar select.form-select.solid,
  .acomp-modulo-shell #listar .acomp-filtros-bar input.form-control.solid {
    height: 2.8rem;
    min-height: 2.8rem;
  }
}

.acomp-modulo-shell #form_acompanhamento select.form-select.solid:focus,
.acomp-modulo-shell #listar .acomp-filtros-bar select.form-select.solid:focus,
.acomp-modulo-shell #listar .acomp-filtros-bar input.form-control.solid:focus {
  border-color: var(--rgba-primary-5, rgba(72, 133, 237, 0.35));
  box-shadow: none;
  background-color: var(--light, #f5f7fb);
  color: var(--text-dark, #212529);
}

.acomp-modulo-shell #form_acompanhamento select.form-select.solid:hover,
.acomp-modulo-shell #listar .acomp-filtros-bar select.form-select.solid:hover,
.acomp-modulo-shell #listar .acomp-filtros-bar input.form-control.solid:hover {
  background-color: var(--light, #f5f7fb);
}

.acomp-modulo-shell #form_acompanhamento .btn-popover-info:focus {
  box-shadow: none;
}

.acomp-modulo-shell #form_acompanhamento .input-hasicon .icon {
  pointer-events: none;
}

/* Switch privado — toggle REBANHO (knob contido no trilho) */
.acomp-modulo-shell #form_acompanhamento .form-switch-acomp {
  min-height: 2.85rem;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-ui {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 2.875rem;
  height: 1.625rem;
  border-radius: 999px;
  background-color: #ced4da;
  transition: background-color 0.2s ease;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-ui::after {
  content: "";
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
  transition: transform 0.2s ease;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-input:checked + .rebanho-toggle-ui {
  background-color: var(--rebanho-primary);
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-input:checked + .rebanho-toggle-ui::after {
  transform: translateX(1.25rem);
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-input:focus-visible + .rebanho-toggle-ui {
  outline: 2px solid rgba(72, 133, 237, 0.45);
  outline-offset: 2px;
}

.acomp-modulo-shell #form_acompanhamento .rebanho-toggle-text {
  display: inline-flex;
  align-items: center;
  height: 1.625rem;
  line-height: 1;
  margin: 0;
  font-size: 0.9375rem;
}

@media only screen and (max-width: 1480px) {
  .acomp-modulo-shell #form_acompanhamento .form-switch-acomp {
    min-height: 2.8rem;
  }
}

.acomp-modulo-shell .ck.ck-editor__label,
.acomp-modulo-shell .ck-editor__label {
  display: none !important;
}

.acomp-modulo-shell .ck.ck-editor__editable_inline,
.acomp-modulo-shell .ck.ck-editor__editable {
  min-height: 260px;
  font-size: 1.05rem;
  line-height: 1.6;
}

/* Retiro evento — stat cards */
.retiro-evt-stat-icon {
  width: 3.25rem;
  height: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 1.2rem;
}

.retiro-evt-summary-card {
  padding: 1rem 1.1rem;
}

.retiro-evt-summary-card .retiro-evt-summary-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

.retiro-evt-summary-card .retiro-evt-summary-detail {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--rebanho-primary-soft, #eaf2ff);
  font-size: 0.8125rem;
}

.retiro-evt-summary-card .retiro-evt-summary-footnote {
  font-size: 0.8125rem;
  color: var(--rebanho-muted);
  border-top: 1px solid var(--rebanho-border);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
  margin-bottom: 0;
}

/* Retiro — tabela do extrato */
.retiro-extrato-tbl {
  --retiro-extrato-debito-bg: rgba(247, 43, 80, 0.04);
  --retiro-extrato-credito-bg: rgba(72, 133, 237, 0.04);
  --retiro-extrato-estorno-bg: rgba(126, 130, 153, 0.06);
}

.retiro-extrato-tbl thead th {
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.retiro-extrato-tbl tbody td {
  vertical-align: middle;
  font-size: 0.875rem;
}

.retiro-extrato-row--debito {
  background-color: var(--retiro-extrato-debito-bg);
  box-shadow: inset 3px 0 0 var(--rebanho-danger, #f72b50);
}

.retiro-extrato-row--credito {
  background-color: var(--retiro-extrato-credito-bg);
  box-shadow: inset 3px 0 0 var(--rebanho-primary, #4885ed);
}

.retiro-extrato-row--estorno {
  background-color: var(--retiro-extrato-estorno-bg);
  color: var(--rebanho-muted, #7e8299);
}

.retiro-extrato-row--estorno td:not(.retiro-extrato-valor) {
  font-style: italic;
}

.retiro-extrato-valor {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.retiro-extrato-valor--debito {
  color: var(--rebanho-danger, #f72b50) !important;
}

.retiro-extrato-valor--credito {
  color: var(--rebanho-primary, #4885ed) !important;
}

.retiro-extrato-valor--entrada {
  color: var(--rebanho-success, #2bc155) !important;
}

.retiro-extrato-acoes {
  white-space: nowrap;
}

.retiro-extrato-acoes .rebanho-dt-icon-btn + .rebanho-dt-icon-btn {
  margin-left: 0.25rem;
}

/* Retiro evento — gerar links de acompanhamento (select + botão alinhados) */
.retiro-acomp-gerar-links {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.retiro-acomp-link-block--grupo {
  padding-top: 0.75rem;
  border-top: 1px solid var(--rebanho-border, #edf0f5);
}

.retiro-acomp-link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
}

.retiro-acomp-link-field {
  flex: 1 1 12rem;
  min-width: 0;
}

.retiro-acomp-link-action {
  flex: 0 0 11.75rem;
  display: flex;
  align-items: stretch;
}

.retiro-acomp-link-action .btn {
  width: 100%;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.retiro-acomp-link-field .select2-container {
  width: 100% !important;
}

.retiro-acomp-link-field .select2-container--default .select2-selection--multiple {
  min-height: calc(1.5em + 0.75rem + 2px);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
  background-color: #fff;
  padding: 0.25rem 0.375rem;
  display: flex;
  align-items: center;
}

.retiro-acomp-link-field .select2-container--default.select2-container--focus .select2-selection--multiple,
.retiro-acomp-link-field .select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: var(--rebanho-primary, #4885ed);
  box-shadow: 0 0 0 0.2rem rgba(72, 133, 237, 0.15);
}

.retiro-acomp-link-field .select2-container--default .select2-selection--multiple .select2-selection__rendered {
  margin: 0;
  padding: 0;
  width: 100%;
}

.retiro-acomp-link-field .select2-container--default .select2-search--inline .select2-search__field {
  margin-top: 0;
  height: 1.5rem;
}

@media (max-width: 767.98px) {
  .retiro-acomp-link-action {
    flex: 1 1 100%;
  }
}

/* Pequenos grupos — modais e organização */
#modalOrganizar .modal-organizar-pg-body {
  overflow: hidden;
}

#modalOrganizar #modalOrganizarPgContent {
  max-width: min(96vw, 1200px);
}

#modalOrganizar .modal-organizar-pg-layout {
  max-height: min(72vh, 720px);
  min-height: 280px;
}

@media (max-width: 991.98px) {
  #modalOrganizar .modal-organizar-pg-layout {
    max-height: min(82vh, 820px);
  }
}

#modalOrganizar .modal-organizar-pg-grupos {
  min-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 991.98px) {
  #modalOrganizar .modal-organizar-pg-grupos {
    max-height: min(40vh, 420px);
  }
}

#modalOrganizar .modal-organizar-pg-pool-card .card-body {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#modalOrganizar .modal-organizar-pg-pool {
  min-height: 200px;
}

@media (min-width: 992px) {
  #modalOrganizar .modal-organizar-pg-pool {
    width: 360px;
    max-width: min(360px, 38vw);
    flex-shrink: 0 !important;
  }
}

#modalOrganizar #rebanho-disponivel.lista-drag {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: calc(min(72vh, 720px) - 7rem);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 991.98px) {
  #modalOrganizar #rebanho-disponivel.lista-drag {
    max-height: min(38vh, 380px);
  }
}

#modalOrganizar .pg-organizar-drop-zone {
  min-height: 72px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #fff !important;
}

#modalOrganizar .sortable-fallback {
  opacity: 0.95 !important;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2) !important;
  z-index: 9999 !important;
}

#modalOrganizar .pg-organizar-membro {
  cursor: grab;
}

#modalOrganizar .pg-organizar-membro--com-aptidoes {
  align-items: flex-start;
}

#modalOrganizar .pg-organizar-membro-icon {
  line-height: 1.35;
  margin-top: 0.05rem;
}

#modalOrganizar .pg-organizar-membro-body {
  min-width: 0;
}

#modalOrganizar .pg-organizar-membro-nome {
  line-height: 1.35;
}

#modalOrganizar .pg-organizar-membro-meta {
  align-self: center;
}

#modalOrganizar .pg-organizar-membro--com-aptidoes .pg-organizar-membro-meta {
  align-self: flex-start;
  margin-top: 0.05rem;
}

#modalOrganizar .pg-organizar-aptidoes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
  margin-top: 0.2rem;
  max-width: 100%;
}

#modalOrganizar .pg-organizar-apt-chip {
  display: inline-block;
  max-width: 6.25rem;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

#modalOrganizar .pg-organizar-apt-chip--more {
  background-color: var(--rebanho-border, #edf0f5);
  color: var(--rebanho-muted, #7e8299);
  max-width: none;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

#modalOrganizar .pg-organizar-membro:active {
  cursor: grabbing;
}

.rebanho-secretaria-scope .pg-organizar-card .card-header.bg-primary {
  background-color: var(--rebanho-primary, #4885ed) !important;
}

#modalOrganizar .modal-footer .btn-rebanho-primary {
  background-color: var(--rebanho-primary, #4885ed);
  border-color: var(--rebanho-primary, #4885ed);
  color: #fff;
}

#modalOrganizar .modal-footer .btn-rebanho-primary:hover {
  filter: brightness(0.94);
  color: #fff;
}

#modalForm select.form-select.solid {
  background-color: var(--light);
  border: 1px solid var(--light);
  color: var(--text-dark);
  min-height: 2.85rem;
  height: 2.85rem;
  padding: 0.3125rem 2.25rem 0.3125rem 1.25rem;
  border-radius: 0.5rem;
  font-size: inherit;
  line-height: 1.5;
  box-shadow: none;
}

@media only screen and (max-width: 1480px) {
  #modalForm select.form-select.solid {
    height: 2.8rem;
    min-height: 2.8rem;
  }
}

#modalForm select.form-select.solid:focus {
  border-color: var(--rgba-primary-5);
  box-shadow: none;
  background-color: var(--light);
  color: var(--text-dark);
}

#modalForm select.form-select.solid:hover {
  background-color: var(--light);
}
