/**
 * =====================================================================
 * ESTILOS MELHORADOS PARA TABELAS – OWNFLEX v4.4
 * =====================================================================
 * 
 * Arquivo: table-styles-enhanced.css
 * Versão: 1.0
 * Data: 2026-04-12
 * 
 * Complementa styles.css com:
 * - Paginação visual
 * - Toolbar de filtro/busca
 * - Indicadores de sorting
 * - Card view para mobile
 * - Melhor acessibilidade
 * 
 */

/* ─────────────────────────────────────────────────────────────────
   TOOLBAR DE TABELA (Busca, Filtro, Exportar)
   ───────────────────────────────────────────────────────────────── */

.tbbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  align-items: center;
}

.tbbar input[type="text"],
.tbbar select {
  padding: 8px 12px;
  border: 1px solid var(--BD);
  border-radius: 6px;
  font-size: 13px;
  background: var(--C);
  color: var(--TX);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tbbar input[type="text"]:focus,
.tbbar select:focus {
  outline: none;
  border-color: var(--P);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.1);
}

.tbbar input[type="text"]::placeholder {
  color: var(--TM);
}

/* ─────────────────────────────────────────────────────────────────
   PAGINAÇÃO
   ───────────────────────────────────────────────────────────────── */

.pagination-bar {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  background: #f8fafc;
  border-radius: 8px;
}

.pagination-bar button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--BD);
  background: var(--C);
  color: var(--TX);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 600;
}

.pagination-bar button:hover:not(:disabled) {
  background: var(--BG);
  border-color: var(--P);
  color: var(--P);
}

.pagination-bar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-bar button:active:not(:disabled) {
  transform: scale(0.98);
}

.pagination-bar span {
  padding: 0 8px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--TX);
  font-weight: 600;
}

.pagination-bar span strong {
  color: var(--P);
}

/* ─────────────────────────────────────────────────────────────────
   TABELAS – MELHORIAS NO HEADER SORTÁVEL
   ───────────────────────────────────────────────────────────────── */

.tw table thead th {
  cursor: default;
  user-select: none;
  position: relative;
  transition: background-color 0.15s, color 0.15s;
}

/* Header com sortabilidade */
.tw table thead th[data-sort] {
  background-color: #f0f4f8;
  font-weight: 800;
  color: var(--P);
}

.tw table thead th:hover {
  background-color: #f5f7fc;
}

/* Indicador de sorting */
.tw table thead th[data-sort="asc"]::after {
  content: ' ↑';
  color: var(--P);
  font-weight: 800;
}

.tw table thead th[data-sort="desc"]::after {
  content: ' ↓';
  color: var(--P);
  font-weight: 800;
}

/* Hint visual para headers sortáveis */
.tw table thead th[onclick]::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  opacity: 0.3;
  transition: opacity 0.15s;
}

.tw table thead th[onclick]:hover::before {
  opacity: 0.6;
}

/* ─────────────────────────────────────────────────────────────────
   TABELAS – EFEITOS DE LINHA
   ───────────────────────────────────────────────────────────────── */

.tw tbody tr {
  transition: background-color 0.1s;
}

.tw tbody tr:nth-child(even) td {
  background: #fcfdff;
}

.tw tbody tr:hover td {
  background: #eef4ff;
}

.tw tbody tr.highlighted td {
  background: #fef3c7;
}

/* Row oculta em filtro */
.tw tbody tr[style*="display: none"] {
  display: none !important;
}

/* ─────────────────────────────────────────────────────────────────
   TABELAS – LINHAS VAZIAS / MENSAGENS
   ───────────────────────────────────────────────────────────────── */

.table-empty {
  pointer-events: none;
}

.table-empty td {
  text-align: center;
  padding: 32px 12px;
  color: var(--TM);
  font-style: italic;
  border-bottom: none;
}

/* ─────────────────────────────────────────────────────────────────
   CARD VIEW PARA MOBILE
   ───────────────────────────────────────────────────────────────── */

.card-view {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.card-view.active {
  display: flex;
}

.card-item {
  border: 1px solid var(--BD);
  border-radius: 8px;
  padding: 12px;
  background: var(--C);
  box-shadow: var(--SH2);
  transition: all 0.15s;
}

.card-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.card-item-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--BD);
  align-items: center;
}

.card-item-row:last-child {
  border-bottom: none;
}

.card-item-label {
  font-weight: 700;
  color: var(--TM);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-item-value {
  color: var(--TX);
  font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────
   COLUNAS COM DENSIDADE CONFIGURÁVEL
   ───────────────────────────────────────────────────────────────── */

.tw.dense table th,
.tw.dense table td {
  padding: 6px 10px;
  font-size: 12px;
}

.tw.spacious table th,
.tw.spacious table td {
  padding: 12px 16px;
  font-size: 14px;
}

/* ─────────────────────────────────────────────────────────────────
   COLAPSÍVEL DE DETALHES (expandir/colapsar linha)
   ───────────────────────────────────────────────────────────────── */

.tw tbody tr.expandable {
  cursor: pointer;
  user-select: none;
}

.tw tbody tr.expandable:hover td {
  background: #e8f0ff;
}

.tw tbody tr.expandable td:first-child::before {
  content: '▶ ';
  color: var(--P);
  font-weight: 700;
  transition: transform 0.2s;
}

.tw tbody tr.expandable.expanded td:first-child::before {
  transform: rotate(90deg);
}

.row-details {
  display: none;
}

.row-details.show {
  display: table-row;
}

.row-details td {
  background: #f8fafc;
  padding: 12px;
  border-top: 2px solid var(--BD);
}

.details-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--TM);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 13px;
  color: var(--TX);
  font-weight: 600;
}

/* ─────────────────────────────────────────────────────────────────
   BADGES EM TABELAS
   ───────────────────────────────────────────────────────────────── */

.table-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.table-badge.status-ok {
  background: #dcfce7;
  color: #15803d;
}

.table-badge.status-warning {
  background: #fef9c3;
  color: #b45309;
}

.table-badge.status-critical {
  background: #fee2e2;
  color: #b91c1c;
}

.table-badge.status-info {
  background: #dbeafe;
  color: #1d4ed8;
}

/* ─────────────────────────────────────────────────────────────────
   TABELAS RESPONSIVAS – MEDIA QUERIES
   ───────────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .tw {
    font-size: 12px;
  }
  
  .tw table th,
  .tw table td {
    padding: 8px 10px;
  }
  
  .tbbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .tbbar input,
  .tbbar select {
    width: 100%;
  }
  
  .pagination-bar {
    flex-direction: column;
    gap: 6px;
  }
  
  .pagination-bar button {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .tw {
    border-radius: 8px;
  }
  
  .tbbar {
    gap: 6px;
    padding: 8px;
  }
  
  .tbbar input[type="text"],
  .tbbar select {
    width: 100%;
  }
  
  /* Esconder tabela tradicional em favor de card view */
  .tw table {
    display: none !important;
  }
  
  .card-view.active {
    display: flex;
  }
  
  /* Alternativa: scroll horizontal com aviso */
  .tw table {
    display: table;
    min-width: 600px;
  }
  
  .tw table::after {
    content: '⟵ Scroll para mais colunas →';
    display: block;
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: var(--TM);
    background: var(--BG);
    border-radius: 0 0 8px 8px;
    margin-top: 8px;
  }
  
  .tw {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .tw table {
    font-size: 11px;
  }
  
  .tw table th,
  .tw table td {
    padding: 6px 8px;
  }
  
  .pagination-bar span {
    font-size: 11px;
  }
  
  .pagination-bar button {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  /* Em muito pequeno, card view é obrigatório */
  .tw.mobile-cards table {
    display: none !important;
  }
  
  .tw.mobile-cards .card-view {
    display: flex !important;
  }
  
  .card-item {
    padding: 8px;
  }
  
  .card-item-row {
    grid-template-columns: 80px 1fr;
    gap: 6px;
    padding: 6px 0;
  }
  
  .card-item-label {
    font-size: 10px;
  }
  
  .card-item-value {
    font-size: 12px;
  }
}

/* ─────────────────────────────────────────────────────────────────
   TABELAS COLORIDAS (POR CONTEXTO)
   ───────────────────────────────────────────────────────────────── */

/* Tabela de Risco */
.tw.table-risk tbody tr td:last-child {
  font-weight: 700;
}

.tw.table-risk tbody tr.risk-high td {
  border-left: 3px solid var(--ER);
}

.tw.table-risk tbody tr.risk-medium td {
  border-left: 3px solid var(--WN);
}

.tw.table-risk tbody tr.risk-low td {
  border-left: 3px solid var(--OK);
}

/* Tabela com Progresso */
.progress-cell {
  position: relative;
  padding: 6px !important;
  background: transparent;
}

.progress-bar {
  height: 20px;
  background: var(--BG);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--OK), var(--P));
  transition: width 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}

/* ─────────────────────────────────────────────────────────────────
   ACESSIBILIDADE
   ───────────────────────────────────────────────────────────────── */

/* Focus visible para navegação por keyboard */
.tw table th:focus-visible,
.tw table td:focus-visible,
.tbbar input:focus-visible,
.tbbar select:focus-visible,
.pagination-bar button:focus-visible {
  outline: 2px solid var(--P);
  outline-offset: 2px;
}

/* Melhorar contraste em inputs */
.tbbar input,
.tbbar select {
  color: var(--TX);
  background: var(--C);
}

/* ─────────────────────────────────────────────────────────────────
   UTILITÁRIOS DE PRINT
   ───────────────────────────────────────────────────────────────── */

@media print {
  .tbbar,
  .pagination-bar {
    display: none !important;
  }
  
  .tw {
    box-shadow: none;
    border: 1px solid #000;
  }
  
  .tw table {
    font-size: 11px;
  }
  
  .tw tbody tr {
    page-break-inside: avoid;
  }
  
  .card-view {
    display: flex !important;
  }
  
  .tw table {
    display: none !important;
  }
}

/* ─────────────────────────────────────────────────────────────────
   ANIMAÇÕES
   ───────────────────────────────────────────────────────────────── */

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.row-details.show {
  animation: slideDown 0.2s ease;
}

.card-view.active {
  animation: fadeIn 0.15s ease;
}

/* ─────────────────────────────────────────────────────────────────
   SCROLLBAR CUSTOMIZADO
   ───────────────────────────────────────────────────────────────── */

.tw::-webkit-scrollbar {
  height: 6px;
}

.tw::-webkit-scrollbar-track {
  background: #f0f2f7;
  border-radius: 3px;
}

.tw::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.tw::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

/* ─────────────────────────────────────────────────────────────────
   SUPORTE A TEMAS (OPCIONAL)
   ───────────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  .tbbar {
    background: var(--SH);
  }
  
  .tbbar input,
  .tbbar select {
    background: var(--SH);
    color: #fff;
    border-color: var(--BD);
  }
  
  .pagination-bar {
    background: var(--SH);
  }
  
  .pagination-bar span {
    color: #fff;
  }
  
  .card-item {
    background: var(--SH);
    border-color: var(--BD);
  }
  
  .card-item-label {
    color: #a0aec0;
  }
  
  .card-item-value {
    color: #fff;
  }
}
