/* Tabelas — estilo ACERO adaptado para dados densos.
   Requer tokens-acero.css carregado antes. */

/* ---------- Container ---------- */
.tbl-wrap {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Cabeçalho do bloco: título + ações */
.tbl-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
}
.tbl-head h2 { font-size: var(--fs-h2); margin: 0; }
.tbl-head .count { font-size: var(--fs-label); color: var(--text-muted); margin-left: var(--sp-2); font-weight: 400; }

/* Barra de filtros */
.tbl-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: 0 var(--sp-6) var(--sp-4);
}
.tbl-filters select,
.tbl-filters input[type="search"] {
  font-family: var(--font);
  font-size: var(--fs-label);
  color: var(--text-body);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  height: 36px;
}
.tbl-filters input[type="search"] { min-width: 240px; }
.tbl-filters select:hover,
.tbl-filters input[type="search"]:hover { border-color: var(--navy-200); }

/* Chip de filtro aplicado */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--coral-50);
  color: var(--coral-700);
  font-size: var(--fs-caption);
  padding: 6px 10px 6px 12px;
  border-radius: var(--radius-pill);
}
.chip button { background: none; border: none; color: inherit; cursor: pointer; line-height: 1; padding: 0; font-size: 14px; }

/* ---------- Tabela ---------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-label);
}

.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: var(--fs-caption);
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--navy-50);
  padding: 10px var(--sp-4);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl thead th:first-child { padding-left: var(--sp-6); }
.tbl thead th:last-child  { padding-right: var(--sp-6); }

/* Coluna ordenável */
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text-body); }
.tbl th.sortable::after { content: "↕"; margin-left: 6px; opacity: 0.35; font-size: 11px; }
.tbl th[aria-sort="ascending"]::after  { content: "↑"; opacity: 1; color: var(--coral-500); }
.tbl th[aria-sort="descending"]::after { content: "↓"; opacity: 1; color: var(--coral-500); }

.tbl tbody td {
  padding: 12px var(--sp-4);
  border-top: 1px solid var(--border);
  color: var(--text-body);
  vertical-align: middle;
}
.tbl tbody td:first-child { padding-left: var(--sp-6); }
.tbl tbody td:last-child  { padding-right: var(--sp-6); }

.tbl tbody tr:hover { background: var(--navy-50); }
.tbl tbody tr[aria-selected="true"] { background: var(--coral-50); }

/* Célula de identificação: avatar + nome + subtítulo */
.cell-person { display: flex; align-items: center; gap: var(--sp-3); }
.cell-person .avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: var(--radius-pill);
  background: var(--coral-100);
  color: var(--coral-700);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-caption); font-weight: 500;
}
.cell-person .name { color: var(--text-strong); font-weight: 500; }
.cell-person .sub  { color: var(--text-muted); font-size: var(--fs-caption); }

/* Alinhamentos utilitários */
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .center { text-align: center; }
.tbl .nowrap { white-space: nowrap; }

/* Coluna de ações fixa à direita */
.tbl .col-actions { width: 1%; white-space: nowrap; }
.tbl .icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm);
  line-height: 1;
}
.tbl .icon-btn:hover { background: var(--navy-50); color: var(--text-strong); }

/* ---------- Estados ---------- */
.tbl-empty {
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
}
.tbl-empty h3 { font-size: var(--fs-h2); margin: 0 0 var(--sp-2); }
.tbl-empty p  { color: var(--text-muted); margin: 0 0 var(--sp-5); font-size: var(--fs-label); }

.tbl-skeleton td > span {
  display: block; height: 12px; border-radius: var(--radius-sm);
  background: var(--navy-50);
  animation: tbl-pulse 1.2s ease-in-out infinite;
}
@keyframes tbl-pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.45 } }

/* ---------- Rodapé / paginação ---------- */
.tbl-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  font-size: var(--fs-caption);
  color: var(--text-muted);
}
.pager { display: flex; gap: 4px; }
.pager button {
  min-width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: var(--fs-caption);
  color: var(--text-body); cursor: pointer;
}
.pager button:hover:not(:disabled) { border-color: var(--navy-200); }
.pager button[aria-current="page"] {
  background: var(--coral-400);
  border-color: var(--coral-400);
  color: var(--text-on-coral);
  font-weight: 500;
}
.pager button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Barra de seleção em lote ---------- */
.tbl-bulk {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-6);
  background: var(--coral-50);
  color: var(--coral-700);
  font-size: var(--fs-label);
}

/* ---------- Grade editável (diário do professor) ---------- */
.tbl-grid td.editable { padding: 0; }
.tbl-grid td.editable input {
  width: 100%; height: 100%;
  border: none; background: transparent;
  padding: 12px var(--sp-4);
  font-family: var(--font); font-size: var(--fs-label);
  color: var(--text-strong);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tbl-grid td.editable input:focus {
  outline: none;
  background: var(--white);
  box-shadow: inset 0 0 0 2px var(--coral-400);
}
.tbl-grid td.editable input:invalid { box-shadow: inset 0 0 0 2px var(--danger); }
.tbl-grid td.saved { position: relative; }
.tbl-grid td.saved::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success);
}

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl { min-width: 720px; }
}

/* Modo cartão no celular: aplique .tbl-cards e preencha data-label nos td */
@media (max-width: 620px) {
  .tbl-cards thead { display: none; }
  .tbl-cards, .tbl-cards tbody, .tbl-cards tr, .tbl-cards td { display: block; width: 100%; }
  .tbl-cards tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin: 0 var(--sp-4) var(--sp-3);
    background: var(--white);
  }
  .tbl-cards td {
    border: none;
    display: flex; justify-content: space-between; gap: var(--sp-4);
    padding: 10px var(--sp-4);
  }
  .tbl-cards td + td { border-top: 1px solid var(--border); }
  .tbl-cards td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: var(--fs-caption);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tbl-skeleton td > span { animation: none; }
}
