@import "/src/assets/scss/modern-variables.scss";

.modern-list-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: $bg-primary;
}

// ===========================
// HEADER DE PAGE MODERNE
// ===========================

.page-header {
  background: $bg-secondary;
  border-bottom: 1px solid $border-light;
  box-shadow: $shadow-sm;
  
  .header-content {
    padding: $space-xl;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: $space-xl;
    
    @media (max-width: $tablet) {
      flex-direction: column;
      gap: $space-lg;
    }
    
    @media (max-width: $mobile) {
      padding: $space-lg;
    }
  }
}

.page-title-section {
  flex: 1;
  
  .page-title {
    display: flex;
    align-items: center;
    gap: $space-sm;
    font-size: $text-2xl;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 $space-xs 0;
    line-height: 1.2;
    
    .title-icon {
      font-size: 28px;
      width: 28px;
      height: 28px;
      color: $estair-blue;
    }
    
    @media (max-width: $mobile) {
      font-size: $text-xl;
      
      .title-icon {
        font-size: 24px;
        width: 24px;
        height: 24px;
      }
    }
  }
  
  .page-description {
    font-size: $text-base;
    color: $text-secondary;
    margin: 0;
    line-height: 1.4;
    
    @media (max-width: $mobile) {
      font-size: $text-sm;
    }
  }
}

// ===========================
// KPIs MODERNES
// ===========================

.kpi-section {
  flex-shrink: 0;
  
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: $space-md;
    
    @media (max-width: $tablet) {
      grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
      gap: $space-sm;
    }
  }
}

.kpi-card {
  background: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.2s ease;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  width: 250px;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }
  
  // Couleurs des icônes selon l'index (comme la maquette)
  &:nth-child(1) .kpi-icon {
    background: #3B82F6; // Bleu
  }
  
  &:nth-child(2) .kpi-icon {
    background: #10B981; // Vert
  }
  
  &:nth-child(3) .kpi-icon {
    background: #F59E0B; // Orange
  }
  
  &:nth-child(n+4) .kpi-icon {
    background: #8B5CF6; // Violet pour les suivants
  }
  
  .kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
    
    mat-icon {
      font-size: 24px;
      width: 24px;
      height: 24px;
    }
  }
  
  .kpi-content {
    flex: 1;
    min-width: 0;
    
    .kpi-value {
      font-size: 24px;
      font-weight: 600;
      color: #1F2937;
      line-height: 1;
      margin-bottom: 4px;
      
      .kpi-skeleton {
        width: 60px;
        height: 20px;
        background: #E5E7EB;
        border-radius: 4px;
        animation: pulse 1.5s ease-in-out infinite;
      }
    }
    
    .kpi-label {
      font-size: 14px;
      color: #6B7280;
      font-weight: 500;
      text-transform: none;
      letter-spacing: normal;
    }
  }
}

// ===========================
// TOOLBAR D'ACTIONS MODERNE
// ===========================

.actions-toolbar {
  background: $bg-secondary;
  border-bottom: 1px solid $border-light;
  padding: $space-lg $space-xl;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: $space-lg;
  
  @media (max-width: $tablet) {
    flex-direction: column;
    gap: $space-md;
    padding: $space-md $space-lg;
  }
  
  @media (max-width: $mobile) {
    padding: $space-md;
  }
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: $space-lg;
  flex: 1;
  
  @media (max-width: $tablet) {
    width: 100%;
    justify-content: space-between;
  }
}

.selection-info {
  .selection-badge {
    display: flex;
    align-items: center;
    gap: $space-xs;
    background: $estair-blue-light;
    color: $estair-blue;
    padding: $space-xs $space-sm;
    border-radius: $radius-xl;
    font-size: $text-sm;
    font-weight: 600;
    animation: slideInLeft $transition-normal ease-out;
    
    .clear-selection {
      background: none;
      border: none;
      color: inherit;
      cursor: pointer;
      padding: 2px;
      border-radius: $radius-sm;
      transition: all $transition-fast;
      
      &:hover {
        background: rgba(255, 255, 255, 0.2);
      }
      
      mat-icon {
        font-size: 16px;
        width: 16px;
        height: 16px;
      }
    }
  }
}

.view-controls {
  display: flex;
  align-items: center;
  gap: $space-sm;
  
  .view-mode-toggle {
    display: flex;
    background: $bg-tertiary;
    border-radius: $radius-md;
    padding: 2px;
    
    .view-btn {
      padding: $space-xs $space-sm;
      border: none;
      background: none;
      color: $text-muted;
      cursor: pointer;
      border-radius: $radius-sm;
      transition: all $transition-fast;
      
      &:hover {
        color: $text-primary;
      }
      
      &.active {
        background: $bg-secondary;
        color: $estair-blue;
        box-shadow: $shadow-sm;
      }
      
      mat-icon {
        font-size: 18px;
        width: 18px;
        height: 18px;
      }
    }
  }
  
  .filter-btn {
    display: flex;
    align-items: center;
    gap: $space-xs;
    padding: $space-xs $space-sm;
    border: 1px solid $border-light;
    background: $bg-secondary;
    color: $text-secondary;
    border-radius: $radius-md;
    cursor: pointer;
    font-size: $text-sm;
    font-weight: 500;
    transition: all $transition-normal;
    
    &:hover {
      border-color: $estair-blue;
      color: $estair-blue;
    }
    
    &.active {
      background: $estair-blue-light;
      border-color: $estair-blue;
      color: $estair-blue;
    }
    
    mat-icon {
      font-size: 16px;
      width: 16px;
      height: 16px;
    }
    
    .filter-label {
      @media (max-width: $mobile) {
        display: none;
      }
    }
  }
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: $space-md;
  
  @media (max-width: $tablet) {
    width: 100%;
    justify-content: space-between;
  }
}

.quick-search {
  position: relative;
  display: flex;
  align-items: center;
  
  .search-icon {
    position: absolute;
    left: $space-sm;
    color: $text-muted;
    font-size: 16px;
    z-index: 1;
  }
  
  .search-input {
    width: 200px;
    height: 36px;
    padding: 0 $space-sm 0 36px;
    border: 1px solid $border-light;
    border-radius: $radius-md;
    font-size: $text-sm;
    background: $bg-secondary;
    color: $text-primary;
    transition: all $transition-normal;
    
    @media (max-width: $mobile) {
      width: 150px;
    }
    
    &:focus {
      outline: none;
      border-color: $estair-blue;
      box-shadow: 0 0 0 3px rgba(74, 168, 220, 0.1);
    }
    
    &::placeholder {
      color: $text-muted;
    }
  }
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: $space-sm;
  
  .action-btn {
    display: flex;
    align-items: center;
    gap: $space-xs;
    padding: $space-sm $space-md;
    border-radius: $radius-md;
    font-size: $text-sm;
    font-weight: 500;
    cursor: pointer;
    transition: all $transition-normal;
    border: 1px solid transparent;
    white-space: nowrap;
    
    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
    
    mat-icon {
      font-size: 16px;
      width: 16px;
      height: 16px;
    }
    
    .btn-label {
      @media (max-width: $mobile) {
        display: none;
      }
    }
    
    // Styles par type d'action
    &.primary {
      background: $estair-blue;
      color: $text-inverse;
      border-color: $estair-blue;
      
      &:hover:not(:disabled) {
        background: $estair-blue-dark;
        transform: translateY(-1px);
        box-shadow: $shadow-md;
      }
    }
    
    &.secondary {
      background: $bg-secondary;
      color: $text-secondary;
      border-color: $border-light;
      
      &:hover:not(:disabled) {
        background: $bg-tertiary;
        color: $text-primary;
        border-color: $border-medium;
      }
    }
    
    &.danger {
      background: $status-error;
      color: $text-inverse;
      border-color: $status-error;
      
      &:hover:not(:disabled) {
        background: #DC2626;
        transform: translateY(-1px);
        box-shadow: $shadow-md;
      }
    }
    
    &.refresh {
      background: none;
      color: $text-muted;
      border: none;
      padding: $space-sm;
      
      &:hover:not(:disabled) {
        background: $bg-tertiary;
        color: $text-primary;
      }
    }
  }
}

// ===========================
// CONTAINER TABLEAU
// ===========================

.table-container {
  flex: 1;
  background: $bg-secondary;
  border-radius: $radius-xl $radius-xl 0 0;
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
  // margin: 0 $space-lg $space-lg;
  box-shadow: $shadow-md;

  @media (max-width: $mobile) {
    margin: 0 $space-md $space-md;
    border-radius: $radius-lg $radius-lg 0 0;
  }
}

// ===========================
// AG-GRID THEME ESTAIR
// ===========================

::ng-deep .ag-theme-estair {
  --ag-background-color: #{$bg-secondary};
  --ag-header-background-color: #{$bg-tertiary};
  --ag-odd-row-background-color: #{$bg-primary};
  --ag-row-hover-color: #{$estair-blue-light};
  --ag-selected-row-background-color: #{$estair-blue-light};
  --ag-border-color: #{$border-light};
  --ag-secondary-border-color: #{$border-light};
  --ag-foreground-color: #{$text-primary};
  --ag-secondary-foreground-color: #{$text-secondary};
  --ag-font-size: #{$text-sm};
  --ag-font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  
  .ag-header {
    border-bottom: 2px solid $border-light;
    
    .modern-header-cell {
      font-weight: 600;
      color: $text-secondary;
      font-size: $text-xs;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      padding: $space-sm $space-md;
    }
  }
  
  .ag-row {
    border-bottom: 1px solid $border-light;
    
    &:hover {
      background-color: $estair-blue-light !important;
    }
    
    &.ag-row-selected {
      background-color: $estair-blue-light !important;
      border-left: 3px solid $estair-blue !important;
    }
    
    .modern-cell {
      padding: $space-sm $space-md;
      font-size: $text-sm;
      line-height: 1.4;
      
      &.selection-cell {
        padding: $space-sm;
        justify-content: center;
      }
    }
  }
  
  // Styles pour les éléments personnalisés
  .modern-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: $radius-xl;
    font-size: $text-xs;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(0, 0, 0, 0.1);
  }
  
  .modern-reference {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: $estair-blue;
    text-decoration: none;
    font-weight: 500;

    &.reference-clickable {
      cursor: pointer;
      transition: color 0.2s ease, text-decoration 0.2s ease;

      &:hover {
        text-decoration: underline;
        opacity: 0.8;
      }
    }

    i {
      font-size: 14px;
    }
  }
  
  .modern-boolean {
    display: inline-flex;
    align-items: center;
    
    i {
      font-size: 18px;
    }
  }
  
  // Pagination moderne
  .ag-paging-panel {
    background: $bg-tertiary;
    border-top: 1px solid $border-light;
    padding: $space-md $space-lg;
    
    .ag-paging-page-summary-panel {
      color: $text-secondary;
      font-size: $text-sm;
      font-weight: 500;
    }
    
    .ag-paging-button {
      background: $bg-secondary;
      border: 1px solid $border-light;
      color: $text-secondary;
      border-radius: $radius-md;
      font-weight: 500;
      transition: all $transition-fast;
      
      &:hover:not(.ag-disabled) {
        background: $estair-blue-light;
        border-color: $estair-blue;
        color: $estair-blue;
      }
      
      &.ag-disabled {
        opacity: 0.4;
        cursor: not-allowed;
      }
    }
  }
}

// ===========================
// ÉTAT VIDE
// ===========================

.empty-state {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: $bg-secondary;
  
  .empty-content {
    text-align: center;
    max-width: 400px;
    padding: $space-xl;
    
    .empty-icon {
      font-size: 64px;
      width: 64px;
      height: 64px;
      color: $text-muted;
      margin-bottom: $space-lg;
      opacity: 0.5;
    }
    
    .empty-title {
      font-size: $text-lg;
      font-weight: 600;
      color: $text-primary;
      margin: 0 0 $space-sm 0;
    }
    
    .empty-description {
      font-size: $text-sm;
      color: $text-secondary;
      margin: 0 0 $space-lg 0;
      line-height: 1.5;
    }
    
    .empty-action {
      display: flex;
      align-items: center;
      gap: $space-xs;
      padding: $space-sm $space-lg;
      background: $estair-blue;
      color: $text-inverse;
      border: none;
      border-radius: $radius-md;
      font-size: $text-sm;
      font-weight: 500;
      cursor: pointer;
      transition: all $transition-normal;
      
      &:hover {
        background: $estair-blue-dark;
        transform: translateY(-1px);
        box-shadow: $shadow-md;
      }
      
      mat-icon {
        font-size: 16px;
        width: 16px;
        height: 16px;
      }
    }
  }
}

// ===========================
// ANIMATIONS
// ===========================

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

// ===========================
// RESPONSIVE
// ===========================

@media (max-width: $mobile) {
  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }
  
  .action-buttons {
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}