// ========================================
// 🎯 PANELS STYLES - Data Table
// Painéis modais, drag&drop e componentes avançados
// ========================================

// ========================================
// 🎯 CONTROLES DE COLUNAS E GROUPING
// ========================================

.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.columns-control, .grouping-control {
  position: relative;
}

.columns-toggle, .grouping-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 4px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    background: var(--hover-bg);
  }

  i {
    font-size: 0.875rem;
  }
}

.columns-menu, .grouping-menu {
  position: absolute;
  top: 100%;
  right: 0;
  width: 250px;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  margin-top: 0.5rem;
}

.grouping-menu {
  width: 300px;
}

.columns-menu-header, .grouping-menu-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--divider);

  h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.875rem;
  }
}

.columns-list, .grouping-list {
  max-height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
}

.grouping-list {
  padding: 1rem;
}

.column-option {
  display: flex;
  align-items: center;
  padding: 0.5rem;
  gap: 0.5rem;
  cursor: pointer;
  transition: background-color 0.2s ease;

  input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--divider);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;

    &:checked {
      accent-color: var(--primary);
      border-color: var(--primary);
    }

    &:hover:not(:checked) {
      border-color: var(--primary);
    }
  }

  &:hover {
    background: var(--hover-bg);
  }
}

.group-level {
  margin-bottom: 1rem;

  label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
  }

  .aggregates {
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--hover-bg);
    border-radius: 4px;

    h5 {
      margin: 0 0 0.75rem;
      font-size: 0.875rem;
      color: var(--text-secondary);
      font-weight: 500;
    }

    label {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin-bottom: 0.5rem;
      font-weight: normal;
    }
  }
}

.group-level + .group-level {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--divider);
}

// ========================================
// 🎯 MODAL E OVERLAY SYSTEM
// ========================================

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  
  @media (max-width: 768px) {
    padding: 0.75rem;
  }
  
  @media (max-width: 480px) {
    padding: 0.5rem;
  }
}

.floating-panel {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 400px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: panel-fade-in 0.2s ease;

  .panel-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
  }
  
  @media (max-width: 768px) {
    max-width: 95vw;
    max-height: 60vh;
    
    .panel-content {
      padding: 0.5rem;
    }
  }
  
  @media (max-width: 480px) {
    max-width: 95vw;
    max-height: 55vh;
    
    .panel-content {
      padding: 0.375rem;
    }
  }
}

@keyframes panel-fade-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.close-button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;

  &:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #FFC82E 0%, #FFD700 100%);
  color: #000;
  border-bottom: 1px solid rgba(255, 200, 46, 0.3);
  
  .header-content {
    display: flex;
    align-items: center;
    gap: 8px;
    
    .header-icon {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 24px;
      height: 24px;
      background: rgba(0, 0, 0, 0.1);
      border-radius: 6px;
      
      i {
        font-size: 12px;
        color: #000;
      }
    }
    
    .header-text {
      h4 {
        margin: 0;
        font-size: 0.9rem;
        font-weight: 600;
        color: #000;
      }
      
      .header-subtitle {
        font-size: 0.7rem;
        color: rgba(0, 0, 0, 0.7);
        margin-top: 2px;
      }
    }
  }
  
  .close-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 5px;
    color: #000;
    cursor: pointer;
    transition: all 0.2s ease;
    
    &:hover {
      background: rgba(0, 0, 0, 0.2);
    }
    
    i {
      font-size: 10px;
    }
  }
}

// ========================================
// ✅ BEAUTIFUL GROUPING PANEL STYLES
// ========================================

.grouping-panel {
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.15),
    0 8px 20px rgba(0, 0, 0, 0.1);
  animation: panel-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  
  @media (max-width: 768px) {
    max-width: 95vw;
    max-height: 80vh;
  }
  
  @media (max-width: 480px) {
    max-width: 95vw;
    max-height: 85vh;
  }
}

.panel-quick-actions {
  display: flex;
  gap: 4px;
  padding: 0.375rem 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid var(--divider);
  
  .quick-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    color: #666;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s ease;
    
    &:hover:not(:disabled) {
      background: #f5f5f5;
      border-color: #ccc;
    }
    
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
    
    i {
      font-size: 9px;
    }
  }
}

.grouping-levels {
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.grouping-level-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.2s ease;
  
  &.level-active {
    border-color: #FFC82E;
    box-shadow: 0 2px 8px rgba(255, 200, 46, 0.2);
  }
  
  &.level-disabled {
    opacity: 0.6;
    background: #f9f9f9;
  }
}

.level-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
  
  .level-info {
    display: flex;
    align-items: center;
    gap: 10px;
    
    i {
      font-size: 16px;
      color: #666;
    }
    
    .level-title {
      font-weight: 600;
      color: #333;
      font-size: 0.95rem;
    }
    
    .level-subtitle {
      font-size: 0.8rem;
      color: #888;
      background: #e9ecef;
      padding: 2px 8px;
      border-radius: 4px;
      margin-left: 8px;
    }
  }
  
  .level-status {
    .status-badge {
      padding: 4px 10px;
      border-radius: 4px;
      font-size: 0.75rem;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      
      &.active {
        background: #d4edda;
        color: #155724;
      }
      
      &.disabled {
        background: #f8d7da;
        color: #721c24;
      }
      
      &:not(.active):not(.disabled) {
        background: #e2e3e5;
        color: #6c757d;
      }
    }
  }
}

.level-content {
  padding: 1rem;
  
  .form-group {
    margin-bottom: 1rem;
    
    label {
      display: block;
      margin-bottom: 6px;
      font-weight: 500;
      color: #333;
      font-size: 0.875rem;
    }
    
    .form-select {
      width: 100%;
      padding: 8px 12px;
      border: 1px solid #ccc;
      border-radius: 6px;
      background: #fff;
      font-size: 0.875rem;
      color: #333;
      
      &:focus {
        outline: none;
        border-color: #FFC82E;
        box-shadow: 0 0 0 3px rgba(255, 200, 46, 0.1);
      }
      
      &:disabled {
        background: #f5f5f5;
        color: #999;
      }
    }
  }
}

.aggregates-section {
  margin-top: 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
}

.section-header {
  padding: 12px;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: background-color 0.2s ease;
  
  &:hover {
    background: #e9ecef;
  }
  
  &.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    .header-left {
      display: flex;
      align-items: center;
      gap: 8px;
      
      i {
        color: #666;
        font-size: 14px;
      }
      
      span {
        font-weight: 500;
        color: #333;
        font-size: 0.875rem;
      }
    }
    
    .header-right {
      display: flex;
      align-items: center;
      gap: 8px;
      
      .aggregate-count {
        font-size: 0.75rem;
        color: #666;
        background: #e9ecef;
        padding: 2px 6px;
        border-radius: 3px;
      }
      
      .toggle-icon {
        color: #666;
        font-size: 12px;
        transition: transform 0.2s ease;
        
        &.fa-chevron-up {
          transform: rotate(180deg);
        }
      }
    }
  }
}

.aggregates-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  
  &.expanded {
    max-height: 500px;
  }
}

.aggregates-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  
  @media (min-width: 500px) {
    grid-template-columns: repeat(2, 1fr);
  }
}

.aggregate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  
  .column-name {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    
    i {
      color: #666;
      font-size: 12px;
    }
    
    span {
      font-size: 0.8rem;
      color: #333;
    }
  }
  
  .aggregate-select {
    min-width: 80px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.75rem;
    background: #fff;
    
    &:focus {
      outline: none;
      border-color: #FFC82E;
    }
  }
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 1rem;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
  
  .grouping-stats {
    display: flex;
    gap: 8px;
    
    .stat-item {
      display: flex;
      align-items: center;
      gap: 4px;
      font-size: 0.7rem;
      color: #666;
      
      i {
        font-size: 10px;
        
        &.text-primary { color: #FFC82E !important; }
        &.text-info { color: #17a2b8 !important; }
        &.text-success { color: #28a745 !important; }
        &.text-muted { color: #6c757d !important; }
      }
    }
  }
  
  .panel-actions {
    display: flex;
    gap: 4px;
    
    .panel-btn {
      padding: 5px 10px;
      border-radius: 4px;
      font-size: 0.75rem;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      border: 1px solid transparent;
      
      &.secondary {
        background: #fff;
        color: #666;
        border-color: #ccc;
        
        &:hover {
          background: #f5f5f5;
        }
      }
      
      &.primary {
        background: #FFC82E;
        color: #000;
        border-color: #FFC82E;
        
        &:hover {
          background: #FFD700;
        }
        
        i {
          margin-right: 2px;
        }
      }
    }
  }
}

@keyframes panel-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

// ========================================
// ✅ BEAUTIFUL COLUMNS PANEL STYLES
// ========================================

.columns-panel {
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.15),
    0 8px 20px rgba(0, 0, 0, 0.1);
  animation: panel-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  
  @media (max-width: 768px) {
    max-width: 95vw;
    max-height: 60vh;
  }
  
  @media (max-width: 480px) {
    max-width: 95vw;
    max-height: 55vh;
  }
}

.columns-list-enhanced {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0.75rem;
  
  @media (max-width: 768px) {
    gap: 4px;
    padding: 0.5rem;
  }
  
  @media (max-width: 480px) {
    gap: 3px;
    padding: 0.375rem;
  }
}

.column-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  transition: all 0.3s ease;
  
  &.column-visible {
    border-color: #FFC82E;
    box-shadow: 0 2px 8px rgba(255, 200, 46, 0.1);
  }
  
  &.column-hidden {
    opacity: 0.7;
    background: #f9f9f9;
  }
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  /* ✅ ANIMAÇÃO ESPECIAL QUANDO SENDO MOVIDO */
  &.moving {
    transform: scale(1.02);
    z-index: 10;
    box-shadow: 0 8px 20px rgba(255, 200, 46, 0.2);
  }
  
  /* ✅ MOBILE: Ainda mais compacto */
  @media (max-width: 768px) {
    gap: 8px;
    padding: 6px;
    border-radius: 4px;
  }
  
  @media (max-width: 480px) {
    gap: 6px;
    padding: 4px;
    border-radius: 3px;
  }
}

.column-checkbox-wrapper {
  position: relative;
  
  .column-checkbox {
    opacity: 0;
    position: absolute;
    
    &:checked + .checkbox-custom {
      background: #FFC82E;
      border-color: #FFC82E;
      
      i {
        opacity: 1;
        transform: scale(1);
      }
    }
  }
  
  .checkbox-custom {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    
    i {
      font-size: 10px;
      color: #000;
      opacity: 0;
      transform: scale(0.5);
      transition: all 0.2s ease;
    }
    
    &:hover {
      border-color: #FFC82E;
    }
  }
}

.column-info {
  flex: 1;
  min-width: 0;
  
  .column-label {
    display: block;
    font-weight: 500;
    color: #333;
    font-size: 0.85rem;
    margin-bottom: 3px;
    cursor: pointer;
  }
  
  .column-details {
    display: flex;
    align-items: center;
    gap: 6px;
    
    .column-field {
      font-size: 0.7rem;
      color: #666;
      background: #f0f0f0;
      padding: 1px 4px;
      border-radius: 3px;
    }
    
    .column-type {
      display: flex;
      align-items: center;
      gap: 3px;
      font-size: 0.7rem;
      color: #888;
      
      i {
        font-size: 9px;
      }
    }
  }
}

.column-actions {
  display: flex;
  flex-direction: column;
  gap: 1px;
  
  .column-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    
    &:hover:not(:disabled) {
      background: #FFC82E;
      color: #000;
      border-color: #FFC82E;
      transform: translateY(-1px);
      box-shadow: 0 2px 4px rgba(255, 200, 46, 0.3);
    }
    
    &:active:not(:disabled) {
      transform: translateY(0);
      box-shadow: 0 1px 2px rgba(255, 200, 46, 0.3);
    }
    
    &:disabled {
      opacity: 0.3;
      cursor: not-allowed;
    }
    
    i {
      font-size: 8px;
      transition: transform 0.2s ease;
    }
    
    /* ✅ FEEDBACK ESPECÍFICO PARA CADA DIREÇÃO */
    &:hover:not(:disabled) i.fa-chevron-up {
      transform: translateY(-1px);
    }
    
    &:hover:not(:disabled) i.fa-chevron-down {
      transform: translateY(1px);
    }
  }
}

.column-stats {
  display: flex;
  gap: 8px;
  
  .stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #666;
    
    i {
      font-size: 10px;
      
      &.text-success { color: #28a745 !important; }
      &.text-muted { color: #6c757d !important; }
    }
  }
}

// ========================================
// 🎯 DRAG & DROP
// ========================================

.cdk-drag-preview {
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cdk-drag-placeholder {
  opacity: 0.3;
}

.cdk-drag-animating {
  transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}

// ========================================
// 🎯 OUTROS ELEMENTOS
// ========================================

.group-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
}

.group-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.group-aggregates {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
}

.data-row {
  &.child-of-group {
    background: var(--background);

    td:first-child {
      padding-left: 48px; // 24px * 2 para alinhar com o segundo nível
    }
  }

  &:hover {
    background: var(--hover-bg);
  }
}

.group-row {
  background: var(--surface-variant);
  font-weight: 500;
  border-bottom: 1px solid var(--divider);
}

.group-row.group-level-1 {
  background: var(--surface-variant-light);
}

// ========================================
// 🎯 FORM FIELDS CUSTOMIZADOS
// ========================================

.custom-field {
  position: relative;
  margin-bottom: 0.5rem;
}

.custom-field input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--divider);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-primary);
  transition: all 0.2s;
}

.custom-field label {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--surface);
  padding: 0 4px;
  color: var(--text-secondary);
  font-size: 14px;
  transition: all 0.2s;
  pointer-events: none;
}

.custom-field input:focus,
.custom-field input:not(:placeholder-shown) {
  border-color: var(--primary);
  outline: none;
}

.custom-field input:focus + label,
.custom-field input:not(:placeholder-shown) + label {
  top: 0;
  font-size: 12px;
  color: var(--primary);
}

.custom-field input:focus {
  box-shadow: 0 0 0 2px rgba(241, 180, 13, 0.1);
}

// ========================================
// 🎯 CONTAINER E RESIZE
// ========================================

.table-container {
  overflow-x: hidden;
  position: relative;
  width: 100%;
  max-width: 100%;
}

.resizable-column {
  position: relative;
  min-width: 100px;
  max-width: 100%;
}

.th-content {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Melhorias para células da tabela */
td {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Permitir quebra de texto em células específicas quando necessário */
.text-wrap {
  white-space: normal !important;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

// ========================================
// 🎯 REQUEST FILTERS CONTAINER
// ========================================

.request-filters-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 2rem 1rem 1rem 1rem;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1rem;
  flex-direction: column;

  .filter-field {
    flex: 1 1;
    max-width: 450px;
  }

  .custom-field {
    position: relative;
    margin-bottom: 1rem;

    input {
      width: 100%;
      padding: 0.5rem;
      border: 1px solid #ccc;
      border-radius: 4px;
      background-color: white;
    }

    label {
      position: absolute;
      top: -0.8rem;
      left: 0.5rem;
      background-color: white;
      padding: 0 0.5rem;
      font-size: 0.8rem;
      color: #666;
    }
  }
}

// Removendo os estilos do Material Design que não vamos mais usar
::ng-deep .mat-form-field,
::ng-deep .mat-form-field-wrapper,
::ng-deep .mat-form-field-outline,
::ng-deep .mat-form-field-label,
::ng-deep .mat-input-element,
::ng-deep .mat-form-field-appearance-outline {
  display: none;
} 