/* Container principal */
.integration-container {
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 8px;
  min-height: 100vh;
}

/* ===== SEÇÃO DE FILTROS ===== */
.filters-section {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  align-items: flex-end;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
}

/* Campo de busca customizado */
.custom-field {
  position: relative;
  margin-bottom: 0;

  &:first-child {
    flex: 0 1 350px; /* Campo de busca */
  }

  &:last-child {
    flex: 0 1 250px; /* Select de status maior para não cortar o texto */
  }

  input, select {
    width: 100%;
    padding: 8px 36px 8px 12px;
    border: 1px solid var(--divider);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 10px;
    font-family: var(--font-primary);
    transition: all 0.2s ease;

    &:focus {
      outline: none;
      border-color: var(--primary);
      box-shadow: 0 0 0 2px rgba(241, 180, 13, 0.1);
    }

    &::placeholder {
      color: var(--text-secondary);
    }
  }

  select {
    appearance: none;
    cursor: pointer;
    padding-right: 30px; /* Reduzir padding direito para dar mais espaço ao texto */
    
    option {
      background: var(--surface);
      color: var(--text-primary);
      padding: 6px 10px;
      font-family: var(--font-primary);
      font-size: 10px;
    }
  }

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

  input:focus + label,
  input:not(:placeholder-shown) + label,
  select:focus + label,
  select:not([value=""]) + label {
    top: 0;
    font-size: 12px;
    color: var(--primary);
  }

  .field-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
    pointer-events: none;
  }
}

/* ===== TEMA ESCURO ESPECÍFICO ===== */
:host-context(.dark-theme) .custom-field {
  input, select {
    background: var(--surface);
    color: var(--text-primary);
    border-color: var(--divider);

    &:focus {
      border-color: #FFC82E;
      box-shadow: 0 0 0 2px rgba(255, 200, 46, 0.2);
    }

    &::placeholder {
      color: var(--text-secondary);
    }
  }

  select {
    option {
      background: var(--surface) !important;
      color: var(--text-primary) !important;
      
      &:hover {
        background: var(--hover-bg) !important;
      }
      
      &:checked,
      &[selected] {
        background: #FFC82E !important;
        color: #000000 !important;
        font-weight: 500 !important;
      }
    }
  }

  label {
    background-color: var(--surface);
    color: var(--text-secondary);
  }

  input:focus + label,
  input:not(:placeholder-shown) + label,
  select:focus + label,
  select:not([value=""]) + label {
    color: #FFC82E;
  }

  .field-icon {
    color: var(--text-secondary);
  }
}

.category-filters {
  margin-bottom: 2.5rem;

  .category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--surface);
    padding: 20px 24px;
    border-radius: 12px;
    border: 2px solid var(--divider);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
  }

  .category-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 6px;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    position: relative;

    &:hover {
      background-color: var(--hover-bg);
      border-radius: 12px;
      padding: 16px 20px;
    }

    &.active {
      background-color: var(--primary);
      color: var(--text-primary);
      font-weight: 600;
      box-shadow: 0 2px 4px rgba(241, 180, 13, 0.2);
      border-radius: 12px;
      padding: 16px 20px;
      
      .count {
        background: #f3f4f6;
        color: #000000;
      }
    }

    .count {
      font-weight: 500;
      font-size: 12px;
      color: #000000;
      background: #f3f4f6;
      padding: 8px 12px;
      border-radius: 12px;
      margin-left: 6px;
      min-width: 26px;
      text-align: center;
      line-height: 1.2;
      transition: all 0.2s ease;
    }
  }
}

/* ===== TEMA ESCURO PARA CATEGORIAS ===== */
:host-context(.dark-theme) .category-filters {
  .category-chips {
    background: var(--surface);
    border-color: var(--divider);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }

  .category-chip {
    color: var(--text-primary);

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

    &.active {
      background-color: #FFC82E;
      color: #000000;
      box-shadow: 0 2px 4px rgba(255, 200, 46, 0.3);
      
      .count {
        background: rgba(0, 0, 0, 0.1);
        color: #000000;
      }
    }

    .count {
      background: var(--hover-bg);
      color: var(--text-secondary);
    }
  }
}

// Estilos para status dropdown
.status-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;

    &.connected {
      background-color: #10b981; // Verde
    }

    &.error {
      background-color: #ef4444; // Vermelho
    }

    &.disconnected {
      background-color: #6b7280; // Cinza
    }
  }
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 2rem;
  margin-bottom: 2.5rem;
}

/* ===== RESPONSIVIDADE ===== */
@media (max-width: 768px) {
  .integration-container {
    padding: 1rem;
  }

  .filters-section {
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
    margin-top: 1rem;

    .custom-field {
      flex: 1 1 auto;
      max-width: none;
    }

    .custom-field {
      flex: 1 1 auto;
      max-width: none;
    }
  }

  .category-filters {
    margin-bottom: 1.5rem;
    margin-left: -1rem;
    margin-right: -1rem;
    position: relative;
    background: transparent;
    border-radius: 0;

    .category-chips {
      display: flex;
      flex-direction: row;
      overflow-x: auto;
      overflow-y: hidden;
      flex-wrap: nowrap;
      padding: 16px 1rem;
      gap: 0.75rem;
      background: var(--surface);
      border-radius: 0;
      border-left: none;
      border-right: none;
      border-top: 1px solid var(--divider);
      border-bottom: 1px solid var(--divider);
      box-shadow: 0 2px 8px rgba(0,0,0,0.05);
      
      /* Scroll suave */
      scroll-behavior: smooth;
      -webkit-overflow-scrolling: touch;
      
      /* Ocultar scrollbar completamente */
      scrollbar-width: none; /* Firefox */
      -ms-overflow-style: none; /* IE/Edge */
      
      &::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
      }
    }

    /* Gradiente mais forte para indicar scroll */
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      width: 15px;
      background: linear-gradient(
        to right,
        var(--surface) 0%,
        rgba(0, 0, 0, 0) 100%
      );
      pointer-events: none;
      z-index: 2;
    }

    &::after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      width: 15px;
      background: linear-gradient(
        to left,
        var(--surface) 0%,
        rgba(0, 0, 0, 0) 100%
      );
      pointer-events: none;
      z-index: 2;
    }

    .category-chip {
      flex-shrink: 0;
      white-space: nowrap;
      font-size: 14px;
      font-weight: 500;
      padding: 10px 16px;
      border-radius: 24px;
      border: none;
      min-width: auto;
      transition: all 0.2s ease;
      
      /* Mobile: estilo barra única */
      background: transparent;
      color: var(--text-primary);

      &:hover {
        background: var(--hover-bg);
        border-radius: 12px;
      }
      
      &.active {
        background: var(--primary);
        color: var(--text-primary);
        font-weight: 600;
        box-shadow: 0 2px 4px rgba(241, 180, 13, 0.2);
        border-radius: 12px;
        
        .count {
          background: #f3f4f6;
          color: #000000;
        }
      }

      .count {
        margin-left: 6px;
        font-weight: 500;
        font-size: 12px;
        color: #000000;
        background: #f3f4f6;
        padding: 4px 8px;
        border-radius: 12px;
        min-width: 22px;
        text-align: center;
        line-height: 1.2;
      }
    }
  }

  .cards-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .loading-container,
  .empty-state {
    padding: 2rem 1rem;

    .loading-icon,
    .empty-icon {
      font-size: 2.5rem;
    }

    h3 {
      font-size: 1.1rem;
    }

    p {
      font-size: 0.9rem;
    }
  }
}

// Mobile muito pequeno
@media (max-width: 480px) {
  .category-filters {
    .category-chips {
      padding: 0.625rem 1rem;
      gap: 0.5rem;
    }
    
    .category-chip {
      font-size: 13px;
      padding: 8px 14px;
      
      .count {
        font-size: 11px;
        margin-left: 4px;
        font-weight: 500;
        color: #000000;
        background: #f3f4f6;
        padding: 3px 7px;
        border-radius: 10px;
        min-width: 20px;
        text-align: center;
        line-height: 1.2;
      }
    }
  }

  /* ===== TEMA ESCURO MOBILE PEQUENO ===== */
  :host-context(.dark-theme) .category-filters {
    .category-chip {
      &.active {
        background: #FFC82E;
        color: #000000;
        
        .count {
          background: rgba(0, 0, 0, 0.1);
          color: #000000;
        }
      }

      .count {
        background: var(--hover-bg);
        color: var(--text-secondary);
      }
    }
  }

  .integration-container {
    padding: 0.75rem;
  }

  .filters-section {
    margin-top: 0.5rem;
    margin-bottom: 0.75rem;
  }
}

// Desktop - distribuir espaço sem quebrar linha
@media (min-width: 769px) {
  .category-filters {
    margin-left: 0;
    margin-right: 0;
    background: transparent;

    .category-chips {
      flex-wrap: nowrap;
      overflow: visible;
      padding: 20px 24px;
      background: var(--surface);
      border-radius: 8px;
      border: 1px solid var(--divider);
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      justify-content: flex-start;
      gap: 12px;
    }

    /* Remover gradientes no desktop */
    &::before,
    &::after {
      display: none;
    }

    .category-chip {
      /* Desktop: estilo padrão com bordas */
      background-color: transparent;
      border: none;
      color: var(--text-primary);
      flex: 0 0 auto;
      justify-content: center;
      min-width: auto;
      padding: 12px 18px;
      border-radius: 24px;

      &:hover {
        background-color: var(--hover-bg);
        border-radius: 12px;
      }

      &.active {
        background-color: var(--primary);
        color: var(--text-primary);
        box-shadow: 0 2px 4px rgba(241, 180, 13, 0.2);
        border-radius: 12px;
        
        .count {
          background: #f3f4f6;
          color: #000000;
        }
      }
      
      .count {
        font-weight: 500;
        font-size: 12px;
        color: #000000;
        background: #f3f4f6;
        padding: 4px 8px;
        border-radius: 12px;
        margin-left: 6px;
        min-width: 22px;
        text-align: center;
        line-height: 1.2;
      }
    }
  }

  /* ===== TEMA ESCURO DESKTOP ===== */
  :host-context(.dark-theme) .category-filters {
    .category-chips {
      background: var(--surface);
      border-color: var(--divider);
      box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }

    .category-chip {
      color: var(--text-primary);

      &:hover {
        background-color: var(--hover-bg);
        border-radius: 12px;
      }

      &.active {
        background-color: #FFC82E;
        color: #000000;
        box-shadow: 0 2px 4px rgba(255, 200, 46, 0.3);
        
        .count {
          background: rgba(0, 0, 0, 0.1);
          color: #000000;
        }
      }
      
      .count {
        background: var(--hover-bg);
        color: var(--text-secondary);
      }
    }
  }
}

// Tablet
@media (min-width: 769px) and (max-width: 1024px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
  }

  .page-header {
    .connected-count {
      .count-badge {
        font-size: 0.8rem;
        padding: 0.375rem 0.75rem;
      }
    }
  }
}

// Animações suaves
.cards-grid,
.category-filters,
.filters-section {
  transition: all 0.3s ease;
}

// Estados de hover e foco melhorados
.mat-mdc-form-field {
  &.mat-focused {
    .mat-mdc-form-field-outline {
      border-color: var(--idt-primary);
    }
  }

  .mat-mdc-text-field-wrapper {
    border-radius: 8px;
  }

  .mat-mdc-form-field-outline {
    border-radius: 8px;
  }
}

// Estilo personalizado para chips
::ng-deep .mat-mdc-chip {
  &.category-chip {
    --mdc-chip-container-height: 36px;
    --mdc-chip-label-text-size: 0.875rem;
    border-radius: 18px;
  }

  &.active {
    --mdc-chip-selected-container-color: var(--idt-primary);
    --mdc-chip-selected-label-text-color: #1a1a1a;
  }
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-secondary);

  .loading-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    animation: spin 1s linear infinite;
    color: var(--primary);
  }

  p {
    font-size: 1rem;
    margin: 0;
    color: var(--text-secondary);
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  text-align: center;
  color: var(--text-secondary);

  .empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    opacity: 0.6;
  }

  h3 {
    font-size: 1.25rem;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
  }

  p {
    font-size: 1rem;
    margin: 0;
    max-width: 400px;
    color: var(--text-secondary);
  }
}

/* ===== TEMA ESCURO LOADING/EMPTY ===== */
:host-context(.dark-theme) {
  .loading-container {
    color: var(--text-secondary);

    .loading-icon {
      color: #FFC82E;
    }

    p {
      color: var(--text-secondary);
    }
  }

  .empty-state {
    color: var(--text-secondary);

    .empty-icon {
      color: var(--text-secondary);
      opacity: 0.5;
    }

    h3 {
      color: var(--text-primary);
    }

    p {
      color: var(--text-secondary);
    }
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}



