/**
 * AsturMaker — tabelas e DataTables (visual moderno, sem alterar lógica)
 */

/* Loading overlay em tabelas */
.am-table-wrap {
  position: relative;
  min-height: 11rem;
}

.am-table-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(3px);
  border-radius: var(--am-radius);
  pointer-events: none;
}

.am-table-loading.is-hidden {
  display: none !important;
}

.am-table-loading__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--am-space-3);
  color: var(--am-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.am-table-loading__inner .fa-spin {
  font-size: 1.5rem;
  color: var(--am-primary);
}

.am-table-wrap--loading .dataTables_empty,
.am-table-wrap--loading td.dataTables_empty {
  visibility: hidden;
}

.am-table-wrap--loading .dataTables_processing {
  display: none !important;
}

/* Container da tabela */
.am-app .am-legacy-shell .table,
.am-app .am-panel .table {
  --am-table-border: var(--am-border);
  margin-bottom: 0;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--am-table-border);
  border-radius: var(--am-radius);
  overflow: hidden;
  background: var(--am-surface);
}

.am-app .am-legacy-shell .table thead th,
.am-app .am-panel .table thead th {
  background: #f1f5f9;
  color: var(--am-text-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--am-table-border);
  border-top: none;
  vertical-align: middle;
  white-space: nowrap;
}

.am-app .am-legacy-shell .table tbody td,
.am-app .am-panel .table tbody td {
  padding: 0.875rem 1rem;
  color: var(--am-text);
  font-size: 0.875rem;
  line-height: 1.45;
  vertical-align: middle;
  border-color: var(--am-table-border);
}

.am-app .am-legacy-shell .table.table-bordered > :not(caption) > * > *,
.am-app .am-panel .table.table-bordered > :not(caption) > * > * {
  border-color: var(--am-table-border);
}

.am-app .am-legacy-shell .table-striped > tbody > tr:nth-of-type(odd) > *,
.am-app .am-panel .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(248, 250, 252, 0.65);
}

.am-app .am-legacy-shell .table-hover > tbody > tr:hover > *,
.am-app .am-panel .table-hover > tbody > tr:hover > * {
  background-color: var(--am-primary-soft) !important;
}

.am-app .am-legacy-shell .table tbody tr:last-child td,
.am-app .am-panel .table tbody tr:last-child td {
  border-bottom: none;
}

/* Coluna de checkbox (DataTables Checkboxes / tabelas selecionáveis) */
.am-app table.dataTable thead th.dt-checkboxes-select-all,
.am-app table.dataTable tbody td.dt-checkboxes-cell,
.am-app table.js-table-checkable.dataTable thead th:first-child:has(input[type="checkbox"]),
.am-app table.js-table-checkable.dataTable tbody td:first-child:has(input[type="checkbox"]) {
  width: 2.75rem !important;
  min-width: 2.75rem !important;
  max-width: 2.75rem !important;
  padding: 0.75rem 0.375rem 0.75rem 0.75rem !important;
  text-align: left !important;
  vertical-align: middle;
  white-space: nowrap;
  box-sizing: border-box;
}

.am-app table.dataTable thead th.dt-checkboxes-select-all.sorting,
.am-app table.dataTable thead th.dt-checkboxes-select-all.sorting_asc,
.am-app table.dataTable thead th.dt-checkboxes-select-all.sorting_desc,
.am-app table.dataTable thead th.dt-checkboxes-select-all.sorting_disabled {
  padding-right: 0.375rem !important;
}

.am-app table.dataTable thead th.dt-checkboxes-select-all input[type="checkbox"],
.am-app table.dataTable tbody td.dt-checkboxes-cell input[type="checkbox"],
.am-app table.js-table-checkable.dataTable thead th:first-child input[type="checkbox"],
.am-app table.js-table-checkable.dataTable tbody td:first-child input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  vertical-align: middle;
}

/* ID/texto logo após a coluna de checkbox — menos espaço morto */
.am-app table.dataTable:has(td.dt-checkboxes-cell) thead th:nth-child(2),
.am-app table.dataTable:has(td.dt-checkboxes-cell) tbody td:nth-child(2),
.am-app table.js-table-checkable.dataTable:has(td:first-child input[type="checkbox"]) thead th:nth-child(2),
.am-app table.js-table-checkable.dataTable:has(td:first-child input[type="checkbox"]) tbody td:nth-child(2) {
  padding-left: 0.75rem;
}

/* Coluna de ações — à direita, largura para botões em linha */
.am-app table.table thead th.am-col-actions,
.am-app table.table tbody td.am-col-actions,
.am-app table.table tbody td:has(.am-table-actions),
.am-app table.table tbody td:has(.op-icons) {
  text-align: right !important;
  white-space: nowrap !important;
  width: 1% !important;
  min-width: 7.5rem !important;
  max-width: none !important;
  vertical-align: middle;
}

.am-app .am-table-actions {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  flex-shrink: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 0.375rem;
  width: auto;
  max-width: none;
}

/* Botões diretos na célula (sem wrapper) — sempre lado a lado */
.am-app table.table tbody td:has(.op-icons) > .btn.op-icons,
.am-app table.table tbody td:has(.op-icons) > a.btn {
  display: inline-flex !important;
  float: none !important;
  vertical-align: middle;
  flex-shrink: 0;
  margin: 0 !important;
}

.am-app table.table tbody td:has(.op-icons) > .btn.op-icons + .btn.op-icons,
.am-app table.table tbody td:has(.op-icons) > a.btn + a.btn {
  margin-left: 0.375rem !important;
}

/* Botões de ícone nas tabelas */
.am-app table.table .btn.op-icons,
.am-app .am-table-actions .btn,
.am-app .am-table-actions a.btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex !important;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: var(--am-radius-sm);
  font-size: 0.8125rem;
  line-height: 1;
  box-shadow: var(--am-shadow-sm);
  transition: transform var(--am-transition), box-shadow var(--am-transition);
}

.am-app table.table .btn.op-icons:hover,
.am-app .am-table-actions .btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--am-shadow);
}

.am-app table.table .btn-info.op-icons {
  background: var(--am-primary-soft);
  border-color: rgba(37, 99, 235, 0.25);
  color: var(--am-primary);
}

.am-app table.table .btn-info.op-icons:hover {
  background: var(--am-primary);
  border-color: var(--am-primary);
  color: #fff;
}

.am-app table.table .btn-danger.op-icons {
  background: var(--am-danger-soft);
  border-color: rgba(220, 38, 38, 0.2);
  color: var(--am-danger);
}

.am-app table.table .btn-danger.op-icons:hover {
  background: var(--am-danger);
  border-color: var(--am-danger);
  color: #fff;
}

.am-app table.table .btn-warning.op-icons {
  background: var(--am-warning-soft);
  border-color: rgba(217, 119, 6, 0.25);
  color: var(--am-warning);
}

/* Barras de progresso — layout unificado em todas as telas */
.am-app table .progress.push,
.am-app table .am-table-progress,
.am-app .am-legacy-shell table .progress.push {
  margin: 0 !important;
  width: 100%;
  min-width: 9.5rem;
  max-width: 14rem;
  height: 1.375rem;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}

.am-app table .progress.push .progress-bar,
.am-app table .am-table-progress .progress-bar,
.am-app .am-legacy-shell table .progress.push .progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  min-height: 100%;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.am-app table .progress.push .progress-bar .fs-sm,
.am-app table .am-table-progress .progress-bar .fs-sm {
  font-size: 0.6875rem !important;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

/* Coluna Progreso — largura consistente */
.am-app table thead th.am-col-progress,
.am-app table tbody td.am-col-progress {
  width: 14rem;
  min-width: 14rem;
  max-width: 14rem;
  vertical-align: middle;
}

/* Coluna Estatus — badge centralizado */
.am-app table thead th.am-col-status,
.am-app table tbody td.am-col-status {
  width: 10rem;
  min-width: 10rem;
  text-align: center !important;
  vertical-align: middle;
}

/* Badges de status */
.am-app table.table .badge,
.am-app table .badge {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.45em 0.9em;
  border-radius: 999px;
  letter-spacing: 0.02em;
  display: inline-block;
  min-width: 6.25rem;
  text-align: center;
  line-height: 1.2;
  vertical-align: middle;
}

.am-app table tbody td.am-col-status .badge,
.am-app table tbody td:has(> .badge:only-child) .badge {
  margin: 0 auto;
}

/* Última coluna Acciones nas tabelas DataTables */
.am-app table.js-dataTable-responsive thead th:last-child,
.am-app table.js-dataTable-responsive tbody td:last-child,
.am-app table.js-dataTable-responsive-productos thead th:last-child,
.am-app table.js-dataTable-responsive-productos tbody td:last-child {
  min-width: 7.5rem;
  white-space: nowrap !important;
}

.am-app table.js-dataTable-responsive tbody td:last-child .am-table-actions,
.am-app table.js-dataTable-responsive-productos tbody td:last-child .am-table-actions {
  flex-wrap: nowrap;
}

/* DataTables wrapper */
.am-app .dataTables_wrapper {
  padding: 0;
}

/* Barra superior: quantidade + pesquisa agrupados à direita */
.am-app .dataTables_wrapper > .row:has(.dataTables_filter),
.am-app .dataTables_wrapper > .row:has(.dataTables_length) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--am-space-3) var(--am-space-4);
  margin-bottom: var(--am-space-4) !important;
  margin-left: 0;
  margin-right: 0;
}

.am-app .dataTables_wrapper > .row:has(.dataTables_filter) > [class*="col-"],
.am-app .dataTables_wrapper > .row:has(.dataTables_length) > [class*="col-"] {
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  padding: 0;
  margin: 0;
}

.am-app .dataTables_wrapper .dataTables_length,
.am-app .dataTables_wrapper .dataTables_filter {
  margin: 0;
  padding: 0;
  text-align: right;
  float: none;
}

.am-app .dataTables_wrapper .dataTables_length {
  order: 1;
}

.am-app .dataTables_wrapper .dataTables_filter {
  order: 2;
}

.am-app .dataTables_wrapper .dataTables_length label,
.am-app .dataTables_wrapper .dataTables_filter label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: var(--am-space-2);
  margin: 0;
  font-size: 0.875rem;
  color: var(--am-text-muted);
  font-weight: 500;
  white-space: nowrap;
  text-align: right;
}

.am-app .dataTables_wrapper .dataTables_length select {
  width: auto;
  min-width: 4.25rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius-sm);
  font-size: 0.875rem;
  color: var(--am-text);
  background-color: var(--am-surface);
}

.am-app .dataTables_wrapper .dataTables_filter input {
  min-width: 12rem;
  width: 12rem;
  max-width: 100%;
  margin: 0 !important;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius-sm);
  font-size: 0.875rem;
  display: inline-block;
}

.am-app .dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--am-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

@media screen and (max-width: 767px) {
  .am-app .dataTables_wrapper > .row:has(.dataTables_filter),
  .am-app .dataTables_wrapper > .row:has(.dataTables_length) {
    justify-content: flex-end;
  }

  .am-app .dataTables_wrapper .dataTables_length,
  .am-app .dataTables_wrapper .dataTables_filter {
    text-align: right;
  }
}

.am-app .dataTables_wrapper .dataTables_info {
  font-size: 0.8125rem;
  color: var(--am-text-muted);
  padding-top: var(--am-space-3);
}

.am-app .dataTables_wrapper .dataTables_paginate {
  padding-top: var(--am-space-3);
}

.am-app .dataTables_wrapper .pagination {
  gap: 0.25rem;
}

.am-app .dataTables_wrapper .page-link {
  border-radius: var(--am-radius-sm) !important;
  border-color: var(--am-border);
  color: var(--am-text);
  font-size: 0.875rem;
  padding: 0.375rem 0.625rem;
}

.am-app .dataTables_wrapper .page-item.active .page-link {
  background: var(--am-primary);
  border-color: var(--am-primary);
}

.am-app table.dataTable {
  width: 100% !important;
}

.am-app table.dataTable thead th.sorting,
.am-app table.dataTable thead th.sorting_asc,
.am-app table.dataTable thead th.sorting_desc {
  padding-right: 1.75rem;
}

/* Tabs internas (biblioteca, etc.) */
.am-app .nav-tabs-alt {
  border-bottom: 1px solid var(--am-border);
  gap: 0.25rem;
  margin-bottom: var(--am-space-4);
}

.am-app .nav-tabs-alt .nav-link {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--am-radius-sm) var(--am-radius-sm) 0 0;
  color: var(--am-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.625rem 1rem;
  margin-bottom: -1px;
}

.am-app .nav-tabs-alt .nav-link:hover {
  color: var(--am-text);
  background: var(--am-surface-hover);
}

.am-app .nav-tabs-alt .nav-link.active {
  color: var(--am-primary);
  background: transparent;
  border-bottom-color: var(--am-primary);
}

/* Conteúdo interno das páginas legadas */
.am-app .am-legacy-shell .block-content {
  padding: 0;
}

.am-app .am-legacy-shell .block-content > .block.block-rounded {
  background: transparent;
  box-shadow: none;
}

.am-app .am-legacy-shell .block-content .block-header-default {
  background: transparent;
  border-bottom: 1px solid var(--am-border);
  padding: 0 0 var(--am-space-4);
  margin-bottom: var(--am-space-4);
}

.am-app .am-legacy-shell .block-content-full.p-2,
.am-app .am-legacy-shell .block-content-full.p-3 {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.am-app .am-legacy-shell .btn-alt-primary {
  background: var(--am-primary-soft);
  border-color: rgba(37, 99, 235, 0.25);
  color: var(--am-primary);
  font-weight: 600;
  border-radius: var(--am-radius-sm);
}

.am-app .am-legacy-shell .btn-alt-primary:hover {
  background: var(--am-primary);
  border-color: var(--am-primary);
  color: #fff;
}

/* Responsive DataTables — detalhe expandido */
.am-app table.dataTable > tbody > tr.child ul.dtr-details {
  width: 100%;
}

.am-app table.dataTable > tbody > tr.child ul.dtr-details > li {
  border-bottom: 1px solid var(--am-border);
  padding: 0.5rem 0;
}

.am-app table.dataTable > tbody > tr.child .dtr-title {
  font-weight: 600;
  color: var(--am-text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

/* Células só com texto de processo */
.am-app table.table tbody td:has(> span:only-child) {
  color: var(--am-text-muted);
  font-size: 0.8125rem;
  font-style: italic;
}

/*
  Correção de tema escuro no cabeçalho das tabelas.

  O thead vinha com fundo claro fixo (#f1f5f9) e texto cinzento: dentro de uma
  tabela escura ficava uma faixa clara com texto de baixo contraste. Passa a
  derivar dos tokens, como as linhas do corpo.
*/
.am-app table.table > thead th,
.am-app table.table > thead > tr > th {
  background-color: var(--am-surface-hover);
  color: var(--am-text-muted);
  border-bottom-color: var(--am-border);
}

.am-app table.table > tbody > tr > td {
  border-top-color: var(--am-border);
}
