.ds-dropdown {
  margin-bottom: 0;
  margin-top: 0;
  .control-label {
    font-size: inherit;
  }

  .dropdown {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    width: 100%;
    padding: 0px !important;
    font-size: 1rem;
    height: 55px;
    border: none;
    line-height: 1.6;
    box-shadow: none;
    position: relative;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding: 8px 12px;
    background: $gris_background;

    &.opened {
      background: $gris_light;

      ~ .control-label,
      ~ .dsicon-chevron-haut {
        color: $bleu_texte;
      }
    }

    .options {
      display: none;
      position: absolute;
      background: $blanc;
      border-radius: 5px;
      width: 100%;
      z-index: 99;
      top: 50px;
      padding: 8px 0px 8px 0px;
      max-height: 310px;
      overflow: auto;

      .option {
        position: relative;
        padding: 16px;

        p {
          color: $gris_dark;
        }

        &:hover {
          background-color: $gris_background;
          cursor: pointer;
          p {
            color: $noir
          }
        }
  
        &.active {
          p {
            color: $vert_positif;
          }
  
          .dsicon-check {
            display: inline;
          }
        }
  
        .dsicon-check {
          display: none;
        }
  
        &:not(:last-child) .sub-libelle {
          ~ .line {
            display: inherit;
          }
        }
  
        .line {
          display: none;
          position: absolute;
          bottom: 0;
          left: 15px;
          right: 15px;
          height: 1px;
          background-color: $gris_light;
        }
      }
    }

    ~ .message-aide {
      display: inherit;
      color: $gris_dark;
      font-size: 0.75rem;
      margin-left: 8px;
      margin-top: 4px;
      position: absolute;
      display: inherit;
    }
    ~ .message-erreur {
      position: absolute;
      display: none;
      color: $rouge_negatif;
      font-size: 0.75rem;
      margin-left: 8px;
    }
    &.erreur {
      ~ .bar {
        position: relative;
        border-bottom: 2px solid $rouge_negatif;
        display: block;
      }
      ~ .message-erreur {
        color: $rouge_negatif;
        font-size: 0.75rem;
        margin-left: 8px;
        margin-top: 4px;
        position: absolute;
        display: inherit;
      }
      ~ .message-aide {
        display: none;
      }
    }
    &.valide {
      ~ .bar {
        position: relative;
        border-bottom: 2px solid $vert_positif;
        display: block;
      }
      ~ .message-erreur {
        display: none;
      }
      ~ .message-aide {
        display: none;
      }
    }
    &:focus {
      ~ i.dsicon-chevron-bas {
        display: none;
      }
      ~ i.dsicon-chevron-haut {
        display: inline;
      }
      outline: none;
      ~ .bar::before {
        width: 100%;
        left: 0;
      }
    }
  }
  .dropdown-text {
    width: auto;
    padding: 0;
    font-size: inherit;
    border-bottom: 1px dashed $noir;
    box-shadow: none;
    position: relative;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    margin-left: 5px;

    .dsicon-fleche-dropdown-texte {
      margin-left: 4px;
    }

    &.erreur {
      border-bottom: 1px dashed $rouge_negatif;

      label,
      .dsicon-fleche-dropdown-texte {
        color: $rouge_negatif;
      }
    }

    &.disabled {
      border-bottom: 1px dashed $gris_dark;

      label,
      .dsicon-fleche-dropdown-texte {
        color: $gris_dark;
      }
    }

    .options {
      display: none;
      position: absolute;
      background: $blanc;
      border-radius: 5px;
      width: 300px;
      z-index: 99;
      padding: 8px 0px 8px 0px;
      max-height: 310px;
      overflow: auto;

      &.top-left,
      &.top-right {
        bottom: -10px;
      }

      &.top-left {
        right: 0;
      }

      &.top-right {
        left: 0;
      }

      &.bottom-left,
      &.bottom-right {
        top: 0;
      }

      &.bottom-left {
        right: 0;
      }

      &.bottom-right {
        left: 0;
      }

      .option {
        position: relative;
        padding: 16px;

        &:hover {
          background-color: $gris_background;
          cursor: pointer;
          p {
            color: $noir
          }
        }
        
        &.active {
          p {
            color: $vert_positif;
          }
  
          .dsicon-check {
            display: inline;
          }
        }

        p {
          color: $gris_dark;
        }  
  
        .dsicon-check {
          display: none;
        }
  
        .sub-libelle {  
          ~ .line {
            display: inherit;
          }
        }
      }
    }
  }
  .message-erreur {
    color: $rouge_negatif;
    font-size: 0.75rem;
    margin-left: 8px;
  }
  .sub-libelle {
    color: $gris_dark;
  }
  .control-label {
    width: calc(100% - 3.5rem);
    left: 1rem !important;
    padding-left: 0 !important;
    color: $noir;

    &.ds-placeholder {
      color: $gris_dark;
    }
  }
  .control-value {
    position: absolute;
    bottom: 0.625rem;
    right: 2.5rem;
    left: 1rem;

    ~ .control-label {
      font-size: 0.75rem;
      color: $bleu_texte;
      top: 0.5rem;
      left: 0rem;
    }
  }
  .disabled {
    pointer-events: none;
    background-color: rgba(246, 246, 246, 0.3) !important;
    opacity: 0.3;
  }

  &__menu {
    min-width: 200px;
    margin-top: 1px;
    background-color: $blanc;
    position: relative;
    z-index: 1000;
    
    // Supprimer la limite de hauteur et le scroll
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    
    // Ajouter une ombre et des coins arrondis
    box-shadow: 0 3px 6px 0 rgba(34, 34, 34, 0.3);
    border-radius: 4px;
    
    // Supprimer les scrollbars pour tous les navigateurs
    &::-webkit-scrollbar {
      display: none;
    }
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  &__item {
    outline: none;
    cursor: pointer;
    color: #636363;

    &:hover {
      background-color: rgba(0, 0, 0, 0.05);
    }

    &--selected {
      font-style: normal;
      color: $vert_positif;
    }
  
    &-content {
      padding: 1rem;
      white-space: normal;

      &:has(.sub-libelle) {
        .dsicon-check {
          align-self: center; // Vertically center the icon
        }
      }
    }

    &-separator {
      margin: 0 1rem;
      border-bottom: 1px solid $gris_light;
    }
  }

  .ds-placeholder {
    color: $gris_dark;

    &.valide {
      color: $vert_positif;
    }

    &.opened {
      color: $bleu_texte;
    }
  }

  .ds-input-form__disabled {
    .ds-placeholder,
    .dsicon-fleche-dropdown-texte {
      opacity: 0.3;
    }
  }

  .dropdown,
  .dropdown-text {
    .options {
      max-height: none !important;
      overflow: visible !important;
    }
  }
}

.ds-dropdown-linear {
  @extend .ds-dropdown;
  margin: 0;

  // Reset and override ALL bar styles from ds-dropdown
  .bar,
  .dropdown-linear ~ .bar {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 1px !important;
    border: none !important;
    border-bottom: none !important;
    background-color: $gris_dark !important;
    transition: all 0.2s ease !important;
    display: block !important;

    &::before {
      content: '';
      position: absolute !important;
      bottom: 0 !important;
      left: 50% !important;
      width: 0 !important;
      height: 1px !important;
      background-color: $bleu_texte !important;
      transition: all 0.2s ease !important;
    }
  }

  // Override specific states
  .dropdown-linear {
    &.opened ~ .bar {
      background-color: transparent !important;
      
      &::before {
        width: 100% !important;
        left: 0 !important;
        background-color: $bleu_texte !important;
        height: 1px !important;
      }
    }

    &.erreur ~ .bar {
      background-color: $rouge_negatif !important;
      height: 1px !important;
      border: none !important;
    }

    &.valide ~ .bar {
      background-color: $vert_positif !important;
      height: 1px !important;
      border: none !important;
    }

    &:focus ~ .bar {
      &::before {
        width: 100% !important;
        left: 0 !important;
        height: 1px !important;
      }
    }
  }

  .ds-placeholder {
    color: $rouge_negatif;
  }

  .text-truncate{
    margin-bottom: -6px;
    font-size: 16px;
  }

  .dropdown-linear {
    background: transparent;
    height: 48px;
    padding: 0 !important;
    border: none;
    position: relative;
    
    &.opened {
      background: transparent;
      
      ~ .control-label {
        color: $bleu_texte;
      }

      ~ .bar {
        position: relative;
        border-bottom: none;
        display: block;

        &::before {
          width: 100%;
          left: 0;
          background: $bleu_texte;
        }
      }
    }

    &.erreur {
      ~ .bar {
        position: relative;
        border-bottom: 1px solid $rouge_negatif !important;
        display: block;
        
      }
      ~ .message-erreur {
        color: $rouge_negatif;
        font-size: 0.75rem;
        margin-left: 0; // Différent du default form
        margin-top: 4px;
        position: absolute;
        display: inherit;
      }
      ~ .message-aide {
        display: none;
      }
    }

    &.valide {
      ~ .bar {
        position: relative;
        border-bottom: 1px solid $vert_positif;
        display: block;
      }
    }

    &:focus {
      ~ .bar::before {
        width: 100%;
        left: 0;
      }
    }
  }

  .control-label.ds-placeholder {
    top: 35%;
  }

  .control-value {
    left: 0;
    right: 2.5rem;
    bottom: 0.5rem;

    ~ .control-label {
      font-size: 0.75rem;
      top: 0.25rem;
      left: 0;
      padding-bottom: 4px;

      &.erreur {
        color: $rouge_negatif;
      }
    }
  }

  .control-label {
    left: 0 !important;
    padding-left: 0 !important;
  }

  i.dsicon-chevron-bas,
  i.dsicon-chevron-haut {
    position: absolute;
    right: 0;
    top: 60%;
    transform: translateY(-50%);
  }

  .bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: $gris_light;
    transition: all 0.2s ease;

    &::before {
      content: '';
      height: 100%; // Changed from 1px to 100%
      width: 0;
      left: 50%;
      bottom: 0; // Changed from -1px to 0
      position: absolute;
      background: $bleu_texte;
      transition: all 0.2s ease;
    }
  }

  .message-erreur {
    position: absolute;
    display: none;
    margin-left: 0; // Différent du default form
  }

  .message-aide {
    margin-left: 0;
  }

  .dropdown-linear {
    &.opened ~ .bar {
      background-color: transparent; // Hide the default gray bar when opened
      
      &::before {
        width: 100%;
        left: 0;
        background: $bleu_texte;
      }
    }

    &.erreur ~ .bar {
      background-color: $rouge_negatif; // Change the bar color directly
      border-bottom: none !important; // Remove the border
    }

    &.valide ~ .bar {
      background-color: $vert_positif; // Change the bar color directly
      border-bottom: none; // Remove the border
    }

    &:focus ~ .bar::before {
      width: 100%;
      left: 0;
    }
  }
}
