// ========================================
// 🎯 HEADERS STYLES - Data Table
// Headers sticky, sorting, resize handles
// ========================================

// 🔒 HEADER STICKY OTIMIZADO
thead {
  position: sticky;
  top: 0;
  z-index: 100;
  
  /* ✅ BACKGROUND: Sólido com variável de tema */
  background: var(--surface-variant);
  
  /* ✅ SOMBRA: Para destacar separação */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  
  tr {
    position: sticky;
    top: 0;
    z-index: 101;
    background: var(--surface-variant);
  }
}

// 🔒 TH STICKY OTIMIZADO - Header 25% maior
th {
  height: 3.2rem; /* Aumentado para 3.2rem */
  font-size: 1.25rem; /* Maior para acompanhar a altura */
  line-height: 3.2rem; /* Igual à altura para centralizar verticalmente */
  font-weight: 600;
  
  /* ✅ STICKY: Herda do thead */
  position: sticky;
  top: 0;
  z-index: 102; /* ✅ MAIOR: z-index maior que o thead */
  
  /* ✅ BACKGROUND: Variável de tema */
  background: var(--surface-variant);
  
  /* ✅ PROPRIEDADES: Padrão da tabela */
  display: table-cell;
  vertical-align: middle;
  text-align: left;
  color: var(--text-primary);
  border-bottom: 2px solid var(--divider);
}

th {
  background: linear-gradient(135deg, 
    var(--surface) 0%, 
    rgba(255, 200, 46, 0.02) 100%
  );
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  border-bottom: 1px solid var(--divider);
  border-right: 1px solid rgba(var(--divider), 0.3);
  position: relative;
  height: 2.25rem;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  box-shadow: none;
  
  &:first-child {
    border-left: none;
  }
  
  &:last-child {
    border-right: none;
  }
}

.th-content {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.5rem;
  font-size: 0.95rem;
  height: 100%;
  min-height: 2.25rem;
  width: 100%; // ✅ NOVO: Garantir largura total

  .header-text {
    flex: 1;
    transition: all 0.3s ease;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.015em;
    text-transform: uppercase;
    font-size: 0.75rem;
    min-width: 0; // ✅ NOVO: Permite encolher se necessário
  }

  .drag-handle {
    cursor: grab;
    opacity: 0.6;
    font-size: 0.75rem;
    padding: 0.25rem;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
    background: rgba(255, 200, 46, 0.05);
    
    &:hover {
      opacity: 1;
      color: var(--primary);
      transform: scale(1.05);
      background: rgba(255, 200, 46, 0.15);
      box-shadow: 0 2px 4px rgba(255, 200, 46, 0.2);
    }
    
    &:active {
      cursor: grabbing;
      opacity: 0.8;
      transform: scale(1.02);
    }
  }
  
  i:not(.drag-handle) {
    font-size: 0.875rem;
    margin-left: auto;
    transition: all 0.3s ease;
    color: var(--text-secondary);
    opacity: 0.7;
    
    &:hover {
      opacity: 1;
      transform: scale(1.05);
    }
  }
}

.sortable {
  cursor: pointer;
  user-select: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;

  &:hover {
    background: linear-gradient(135deg, 
      rgba(255, 200, 46, 0.04) 0%,
      rgba(255, 200, 46, 0.08) 100%
    );
    transform: none;
    box-shadow: none;
      
    .header-text {
      color: var(--text-primary);
      text-shadow: none;
    }
    
    i:not(.drag-handle) {
      color: var(--primary);
      opacity: 1;
      transform: scale(1.05);
    }
  }

  &.sorting {
    background: linear-gradient(135deg, 
      rgba(255, 200, 46, 0.08) 0%,
      rgba(255, 200, 46, 0.12) 100%
    );
    border-left: 2px solid #FFC82E;
    border-top: none;
    transform: none;
    box-shadow: none;

    .header-text {
      color: #000000;
      font-weight: 600;
      text-shadow: none;
      letter-spacing: 0.015em;
    }

    i:not(.drag-handle) {
      color: #000000;
      font-weight: 600;
      font-size: 0.9rem;
      filter: none;
      animation: none;
      transform: scale(1.05);
    }

    &::after {
      display: none;
    }
    
    &::before {
      display: none;
    }
  }
}

@keyframes shimmer {
  0%, 100% {
    opacity: 0.6;
    transform: translateX(-100%);
  }
  50% {
    opacity: 1;
    transform: translateX(100%);
  }
}

@keyframes sortIconPulse {
  0%, 100% {
    transform: scale(1.15);
    opacity: 1;
  }
  50% {
    transform: scale(1.25);
    opacity: 0.85;
  }
}

// ========================================
// 🎯 RESIZE HANDLE - ADAPTADO PARA HEADER MAIOR
// ========================================

.resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 6px; /* ✅ REDUZIDO: de 8px para 6px */
  cursor: col-resize;
  user-select: none;
  background: transparent;
  transition: all 0.3s ease;
  z-index: 10;

  &:hover {
    background: linear-gradient(180deg, 
      rgba(255, 200, 46, 0.15) 0%, /* ✅ REDUZIDO: de 0.2 para 0.15 */
      rgba(255, 200, 46, 0.25) 50%, /* ✅ REDUZIDO: de 0.4 para 0.25 */
      rgba(255, 200, 46, 0.15) 100% /* ✅ REDUZIDO: de 0.2 para 0.15 */
    );
    width: 8px; /* ✅ REDUZIDO: de 10px para 8px */
  }

  &::after {
    content: "";
    position: absolute;
    right: 2px; /* ✅ AJUSTADO: de 3px para 2px */
    top: 50%;
    transform: translateY(-50%);
    height: 16px; /* ✅ REDUZIDO: de 20px para 16px */
    width: 2px;
    background: var(--divider);
    opacity: 0;
    transition: all 0.3s ease;
    border-radius: 1px;
  }

  &:hover::after {
    opacity: 1;
    background: var(--primary);
    height: 20px; /* ✅ REDUZIDO: de 26px para 20px */
    box-shadow: 0 1px 3px rgba(255, 200, 46, 0.2); /* ✅ REDUZIDO: sombra menor */
  }
}

th:hover .resize-handle::after {
  opacity: 0.6; /* ✅ NOVO: Opacidade menor quando não está em hover direto */
}

/* ✅ NOVO: ESTILOS PARA RESIZE ATIVO */
th.resizing-active {
  background: rgba(255, 200, 46, 0.1) !important;
  border-right: 2px solid var(--primary) !important;
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--primary);
    box-shadow: 0 0 8px rgba(255, 200, 46, 0.4);
    z-index: 15;
  }
  
  .resize-handle {
    background: var(--primary) !important;
    width: 8px !important;
    
    &::after {
      opacity: 1 !important;
      background: white !important;
      height: 24px !important;
      box-shadow: 0 0 4px rgba(0, 0, 0, 0.3) !important;
    }
  }
}

/* ✅ NOVO: CURSOR PERSONALIZADO DURANTE RESIZE */
body[style*="cursor: col-resize"] {
  cursor: col-resize !important;
  
  * {
    cursor: col-resize !important;
  }
  
  .resize-handle {
    cursor: col-resize !important;
  }
}

// ========================================
// 📱 RESPONSIVIDADE MOBILE - HEADER
// ========================================

/* Mobile padrão (≤768px) */
@media (max-width: 768px) {
  th {
    height: 3rem; /* ✅ Altura reduzida para mobile */
    font-size: 0.9rem;
    border-bottom: 1px solid var(--divider); /* ✅ Borda mais fina */
  }
  
  .th-content {
    padding: 0.75rem 0.5rem; /* ✅ Padding reduzido */
    min-height: 3rem;
    gap: 0.375rem;
    
    .header-text {
      font-size: 0.8rem; /* ✅ Texto menor */
      font-weight: 600;
      letter-spacing: 0.015em;
    }
    
    .drag-handle {
      font-size: 0.8rem;
      padding: 0.25rem;
      
      &:hover {
        transform: scale(1.1); /* ✅ Escala menor para mobile */
      }
    }
    
    i:not(.drag-handle) {
      font-size: 0.9rem; /* ✅ Ícones menores */
    }
  }
  
  .sortable {
    &:hover {
      transform: translateY(-1px); /* ✅ Movimento menor */
      box-shadow: 0 2px 8px rgba(255, 200, 46, 0.15);
    }
    
    &.sorting {
      border-left: 3px solid #FFC82E; /* ✅ Borda menor */
      border-top: 1px solid rgba(255, 200, 46, 0.4);
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(255, 200, 46, 0.25);
      
      .header-text {
        font-weight: 600; /* ✅ Peso menor para mobile */
        letter-spacing: 0.02em;
      }
      
      i:not(.drag-handle) {
        font-size: 1rem;
        transform: scale(1.1); /* ✅ Escala menor */
      }
      
      &::after {
        height: 2px; /* ✅ Linha superior menor */
      }
      
      &::before {
        width: 4px; /* ✅ Barra lateral menor */
      }
    }
  }
  
  .resize-handle {
    width: 6px; /* ✅ Handle menor para mobile */
    
    &:hover {
      width: 8px;
    }
    
    &::after {
      height: 20px;
    }
    
    &:hover::after {
      height: 24px;
    }
  }
}

/* Mobile pequeno (≤480px) */
@media (max-width: 480px) {
  th {
    height: 2.5rem; /* ✅ Ainda menor para telas pequenas */
    font-size: 0.85rem;
  }
  
  .th-content {
    padding: 0.5rem 0.375rem;
    min-height: 2.5rem;
    gap: 0.25rem;
    
    .header-text {
      font-size: 0.75rem;
      letter-spacing: 0.01em;
      /* ✅ Remove uppercase em telas muito pequenas */
      text-transform: none;
    }
    
    .drag-handle {
      font-size: 0.7rem;
      padding: 0.2rem;
    }
    
    i:not(.drag-handle) {
      font-size: 0.85rem;
    }
  }
  
  .sortable {
    &.sorting {
      border-left: 2px solid #FFC82E; /* ✅ Borda ainda menor */
      
      .header-text {
        font-weight: 600;
        letter-spacing: 0.015em;
      }
      
      i:not(.drag-handle) {
        font-size: 0.9rem;
        transform: scale(1.05);
      }
      
      &::before {
        width: 3px; /* ✅ Barra lateral mínima */
      }
    }
  }
  
  .resize-handle {
    width: 4px; /* ✅ Handle mínimo */
    
    &:hover {
      width: 6px;
    }
    
    &::after {
      height: 16px;
    }
    
    &:hover::after {
      height: 20px;
    }
  }
}

/* Landscape mobile - altura reduzida */
@media (max-width: 768px) and (orientation: landscape) {
  th {
    height: 2.25rem; /* ✅ Altura mínima em landscape */
  }
  
  .th-content {
    padding: 0.4rem 0.5rem;
    min-height: 2.25rem;
    
    .header-text {
      font-size: 0.75rem;
    }
  }
}

// ========================================
// 🌙 TEMA DARK - HEADERS
// ========================================

/* Tema escuro - Header sticky */
:host-context(.dark-theme) thead {
  background: var(--surface-variant);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  
  tr {
    background: var(--surface-variant);
  }
}

:host-context(.dark-theme) th {
  background: var(--surface-variant);
  color: var(--text-primary);
  border-bottom-color: var(--divider);
}

:host-context(.dark-theme) {
  th {
    background: linear-gradient(135deg, 
      var(--surface) 0%, 
      rgba(255, 200, 46, 0.03) 100%
    );
    border-bottom-color: rgba(255, 200, 46, 0.3);
    box-shadow: inset 0 -1px 0 rgba(255, 200, 46, 0.15);
  }
  
  .th-content .header-text {
    color: var(--text-primary);
  }
  
  .sortable {
    &:hover {
      background: linear-gradient(135deg, 
        rgba(255, 200, 46, 0.1) 0%, 
        rgba(255, 200, 46, 0.18) 100%
      );
      box-shadow: 
        0 4px 12px rgba(255, 200, 46, 0.25),
        inset 0 1px 0 rgba(255, 200, 46, 0.1);
        
      .header-text {
        color: #FFD700;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
      }
    }

    &.sorting {
      background: linear-gradient(135deg, 
        rgba(255, 200, 46, 0.18) 0%, 
        rgba(255, 200, 46, 0.28) 100%
      );
      border-left-color: #FFD700;
      border-top-color: rgba(255, 215, 0, 0.6);
      box-shadow: 
        0 6px 16px rgba(255, 200, 46, 0.35),
        inset 0 1px 0 rgba(255, 200, 46, 0.15);

      .header-text {
        color: #FFD700;
        font-weight: 700;
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
      }

      i:not(.drag-handle) {
        color: #FFD700;
        filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
      }

      &::after {
        background: linear-gradient(90deg, 
          transparent 0%, 
          #FFD700 20%,
          #FFF700 50%, 
          #FFD700 80%,
          transparent 100%
        );
      }
      
      &::before {
        background: linear-gradient(180deg, 
          #FFF700 0%,
          #FFD700 50%,
          #FFC82E 100%
        );
      }
    }
  }
} 