.navbar {
  background-color: $white;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 100;
}

.navbar-logo {
  height: 70px;
  padding-top: 5px;
}

.fa-search {
  color: $navbar-dark-grey;
  font-size: 1.1rem;
  margin-right: 12px;
  vertical-align: middle;

  &:hover {
    color: $primary-green;
    cursor: pointer;
  }

  &.active {
    color: $secondary-green;
  }

  &:focus {
    outline: none;
  }
}

.navbar-simulator-text {
  border: 2px solid $primary-green;
  color: $navbar-dark-grey;
  font-weight: 500;
  transition: all 0.3s ease-in;
  border-radius: 4px;

  &:hover {
    background: $primary-green;
    color: $white;
  }
}

.rotate180::after {
  transform: rotate(180deg);
}

.dropdown-toggle.navbar-user-dropdown {
  cursor: pointer;

  &::after {
    margin-left: 0;
    padding-left: 0;
    vertical-align: 0.5em;
  }
}

.dropdown-item {
  &:hover {
    background-color: $primary-green;
    color: $white;
  }
}

.navbar-text {
  color: $navbar-dark-grey;
  font-weight: 500;
  font-size: 16px;

  &:hover {
    color: $primary-green;
  }

  &.active {
    color: $secondary-green;
  }

  &:focus {
    outline: none;
    text-decoration: underline;
  }
}

.navbar-search-active {
  background-color: $white;
  display: none;
  margin-top: 0;
  padding: 20px;
  position: sticky;
  top: 96px;
  width: 100%;
  z-index: 90;
}

#navbar-dropdown-1,
#navbar-dropdown-2,
#navbar-dropdown-3 {
  margin-inline-start: -10px;

  &:hover {
    color: $primary-green;
  }

  &[aria-expanded="true"] {
    color: $secondary-green;
  }

  &:focus {
    outline: none;
    text-decoration: underline;
  }
}

.navbar-username-truncate {
  display: inline-block;
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.affix {
  box-shadow: 0 8px 6px -6px $shadow-grey;
}

.search-bar-container {
  min-height: 40px;
  position: relative;
}

.search-bar-form {
  max-width: 1220px;
  margin: 0 auto;
}

.search-bar {
  width: 100%;
  height: 40px;
}

.sorting-container {
  position: relative;
  width: 192px;
}

.sorting-buttons {
  border: 1px solid $shadow-grey;
  border-radius: 8px;

  button {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 14px;
    min-width: 0;
    
    &:focus {
      outline: 1px solid $primary-green;
      border-radius: 8px;
    }
    
    &:first-child {
      border-right: 1px solid $shadow-grey;
      flex: 1;
    }
    
    span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-right: 8px;
    }
  }
}

.sorting-options {
  background-color: $white;
  position: absolute;
  border: 1px solid $shadow-grey;
  border-radius: 8px;
  top: 110%;
  width: 75%;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba($black, 0.1);
  max-height: 200px;
  overflow-y: auto;

  &.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.sorting-option {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  color: $navbar-dark-grey;
  font-size: 14px;
  list-style: none;

  &:hover {
    background-color: $project-card-grey;
  }

  &.active {
    background-color: $light-green-bg;
    color: $primary-green;
  }

  &:first-child {
    border-radius: 8px 8px 0 0;
  }

  &:last-child {
    border-radius: 0 0 8px 8px;
  }
}

.filters-container {
  height: 100%;
  position: relative;

  button {
    background: none; 
    border: 1px solid $shadow-grey;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 14px;
  }

  .filters-dropdown {
    position: absolute;
    top: 110%;
    right: 0%;
    background: $white;
    border: 1px solid $shadow-grey;
    border-radius: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: all 0.2s ease;
    z-index: 1000;
    min-width: 240px;
    padding: 0;

    &.show {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }
  }

  .filters-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .filter-label {
    font-size: 12px;
    color: $navbar-dark-grey;
    font-weight: 500;
  }

  .filter-input {
    border: 1px solid $shadow-grey;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    
    &:focus {
      outline: none;
      border-color: $primary-green;
    }
    
    &::placeholder {
      color: lighten($navbar-dark-grey, 20%);
    }
  }

  .tag-input-container {
    border: 1px solid $shadow-grey;
    border-radius: 6px;
    padding: 8px 10px;
    min-height: 38px;
    transition: border-color 0.2s ease;

    &:focus-within {
      border-color: $primary-green;
    }
  }

  .tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 0;
    margin-bottom: 8px;

    &:empty {
      margin-bottom: 0;
    }
  }

  .tag-item {
    display: inline-flex;
    align-items: center;
    background-color: $light-green-bg;
    color: $primary-green;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    gap: 6px;
    white-space: nowrap;
  }

  .tag-remove {
    background: none;
    border: none;
    color: $primary-green;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;

    &:hover {
      background-color: rgba($primary-green, 0.2);
    }

    &:focus {
      outline: none;
      background-color: rgba($primary-green, 0.3);
    }
  }

  .tag-input {
    border: none;
    outline: none;
    padding: 4px 0;
    font-size: 14px;
    flex: 1;
    min-width: 120px;

    &::placeholder {
      color: lighten($navbar-dark-grey, 20%);
    }
  }

  .filter-select-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;

    .filter-select-arrow {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      width: 12px;
      height: 12px;
      pointer-events: none;
    }
  }

  .filter-select {
    border: 1px solid $shadow-grey;
    border-radius: 6px;
    padding: 8px 30px 8px 10px;
    font-size: 14px;
    background-color: $white;
    transition: border-color 0.2s ease;
    appearance: none;
    width: 100%;
    cursor: pointer;
    
    &:focus {
      outline: none;
      border-color: $primary-green;
    }
    
    &:hover {
      border-color: darken($shadow-grey, 10%);
    }
  }


  .filter-actions {
    display: flex;
    gap: 8px;
  }

  .filter-clear-button {
    background-color: transparent;
    color: $navbar-dark-grey;
    border: 1px solid $shadow-grey;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    flex: 1;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
      background-color: $project-card-grey;
      border-color: darken($shadow-grey, 10%);
    }

    &:focus {
      outline: none;
      box-shadow: 0 0 0 2px rgba($shadow-grey, 0.4);
    }
  }

  .filter-apply-button {
    background-color: $primary-green;
    color: $white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    flex: 1;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
      background-color: darken($primary-green, 5%);
    }

    &:focus {
      outline: none;
      background-color: darken($primary-green, 5%);
      box-shadow: 0 0 0 2px rgba($primary-green, 0.3);
    }
  }
}

.search-bar-input {
  border: 1px solid $shadow-grey;
  border-radius: 0 !important;
  padding: 5px 10px;
  height: 100%;
  width: 100%;

  &:focus {
    outline: none;
  }
}

.search-bar-button {
  background-color: $primary-green;
  border: 1px solid $primary-green;
  border-radius: 0 8px 8px 0;
  color: $white;
  height: 100%;
  padding: 0 12px;

  &:hover {
    background-color: darken($primary-green, 5%);
  }
}

.select-wrapper {
  position: relative;
  width: 110px;
  height: 100%;
}

.select-button {
  background-color: $primary-green;
  border: 1px solid $primary-green;
  border-radius: 8px 0 0 8px;
  color: $white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  transition: all 0.2s ease;
  padding: 0 12px;
  width: 100%;
  height: 100%;

  &:focus {
    outline: none;
  }

  &:hover {
    background-color: darken($primary-green, 5%);
  }
}

.select-arrow {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.black-arrow {
  filter: brightness(0) invert(0) !important;
  color: #000 !important;
}

.sorting-container.open .select-arrow {
  transform: rotate(180deg);
}

.select-wrapper.open .select-arrow {
  transform: rotate(180deg);
}

.select-dropdown {
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  background: $white;
  border: 1px solid $shadow-grey;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba($black, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-5px);
  transition: all 0.2s ease;
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;

  &.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.select-option {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  color: $navbar-dark-grey;
  font-size: 14px;

  &:hover {
    background-color: $project-card-grey;
  }

  &.active {
    background-color: $light-green-bg;
    color: $primary-green;

    .select-check {
      opacity: 1;
    }
  }

  &:first-child {
    border-radius: 8px 8px 0 0;
  }

  &:last-child {
    border-radius: 0 0 8px 8px;
  }
}

.dropdown-menu {
  border: 0;
  box-shadow: 0 0 10px 1px $shadow-grey;
  top: 90%;
}

//breakpoints

// Ensure stacked search layout takes full width on extra-small screens
@media (max-width: 576px) {
  .search-bar {
    width: 100%;
  }

  .sorting-container {
    width: 100%;
  }

  .sorting-options {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .select-wrapper {
    width: 80px;
  }

  .select-button {
    padding: 0 10px;
    font-size: 14px;
  }

  .select-option {
    font-size: 14px;
    padding: 10px 14px;
  }

  .search-bar-input {
    font-size: 14px;
  }

  .filters-dropdown {
    left: 0;
  }
}

@media (max-width: 400px) {
 .navbar-logo {
    height: 60px;
    padding-top: 10px;
  }
}

@media (max-width: 300px) {
  .navbar {
    padding: 0.5rem;
  }
}

@media (max-width: 991px) {
  .auth-buttons-container {
    width: 100%;
  }
}

.margin-lg-0 {
  @media (max-width: 991px) {
    margin: 0 !important;
  }
}

.navbar-auth-buttons {
  .btn-login {
    background-color: $primary-green;
    border: none;
    color: white;
    font-size: 16px;
    transition: all 0.3s ease;

    &:hover {
      background-color: $secondary-green;
      color: white;
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba($primary-green, 0.3);
    }

    &:focus {
      outline: none;
      box-shadow: 0 0 0 3px rgba($primary-green, 0.25);
    }
  }

  .btn-signup {
    background-color: white;
    border: 1px solid $shadow-grey;
    color: black;
    font-size: 16px;
    transition: all 0.3s ease;

    &:hover {
      background-color: $card-grey;
      border-color: $shadow-grey;
      color: black;
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba($shadow-grey, 0.4);
    }

    &:focus {
      outline: none;
      box-shadow: 0 0 0 3px rgba($shadow-grey, 0.25);
    }
  }

  @media (max-width: 991px) {
    width: 100%;
  }
}

[dir="rtl"] {
  .main-nav-items {
    padding: 0 !important;
  }

  .search-bar-button {
    border: 1px solid $primary-green;
    border-radius: 8px 0 0 8px !important;
  }

  .select-button {
    border-radius: 0 8px 8px 0 !important;
  }
}

// Utility classes
.hidden {
  display: none !important;
}
