@use '../abstracts' as *;

// --- Фильтр врачей ---
// Адаптив: мобильная версия — колонка, десктоп — строка
.doctors-filter {
  display: grid;
  gap: 20px;
  background: $color-bg-filter;
  border-radius: $radius-md;
  padding: 20px;
  margin-bottom: $gap;
  align-items: center;

  @include down-to($until-767) {
    grid-template-columns: minmax(0, 1fr);
  }

  // Планшет: три колонки полей + иконка
  @include between($bp-md, $until-991) {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 40px;
  }

  // Ноутбук: колонка кнопки до 120px
  @include between($bp-md2, $until-1439) {
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 120px);
  }

  // Десктоп: четыре равные колонки
  @include up($bp-lg) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  &__field {
    min-width: 0;
    position: relative;
  }

  // Поле поиска по имени — прежние размеры и бордер (как было у input/select 40px)
  &__field--search input[type='text'] {
    width: 100%;
    height: 40px;
    padding: 0 16px;
    padding-right: 44px;
    border: 1px solid $color-filter-input-border;
    border-radius: $radius-sm;
    font-family: $font-main;
    font-size: 14px;
    color: $color-text;
    background: $color-white;
    appearance: none;
    transition: border-color 0.2s;
    box-sizing: border-box;

    &:focus {
      outline: none;
      border-color: $color-blue;
    }

    &::placeholder {
      color: $color-text-secondary;
    }
  }

  &__field--search .btn-search {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: $color-text-secondary;

    // Figma node 22-771: значок поиска 20×20
    svg {
      display: block;
      width: 20px;
      height: 20px;
    }
  }

  // Выпадающий список чекбоксов — Figma 117:1067 (триггер), 123:1279 (панель)
  &__field--multi {
    align-self: stretch;
  }

  &__trigger {
    width: 100%;
    height: 40px;
    padding: 0 14px 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid $color-filter-input-border;
    border-radius: $radius-sm;
    background: $color-white;
    font-family: $font-main;
    font-size: 14px;
    font-weight: 400;
    line-height: normal;
    color: $color-text;
    cursor: pointer;
    box-sizing: border-box;
    text-align: left;
    transition: border-color 0.2s;

    &:hover {
      border-color: $color-text-secondary;
    }

    &:focus-visible {
      outline: none;
      border-color: $color-blue;
      box-shadow: 0 0 0 2px rgba($color-blue, 0.25);
    }
  }

  &__trigger-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  &__trigger-label {
    flex-shrink: 0;
    white-space: nowrap;
  }

  &__trigger-count {
    flex-shrink: 0;
    color: $color-blue;
    white-space: nowrap;
  }

  &__chevron {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    color: $color-text-secondary;

    svg {
      display: block;
      transition: transform 0.2s ease;
    }

    &.is-open svg {
      transform: rotate(180deg);
    }
  }

  &__panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: min(320px, 70vh);
    overflow-y: auto;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: $color-white;
    border: 1px solid $color-text-secondary;
    border-radius: $radius-md;
    box-shadow: 0 8px 24px rgba($color-text, 0.12);
    box-sizing: border-box;
  }

  &__option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    min-height: 16px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.3;
    color: $color-text;
    cursor: pointer;
    user-select: none;

    &:hover .doctors-filter__check {
      background-color: rgba($color-blue, 0.06);
    }
  }

  &__option-text {
    min-width: 0;
  }

  &__native-check {
    @include visually-hidden;

    &:focus-visible + .doctors-filter__check {
      outline: 2px solid $color-blue;
      outline-offset: 2px;
    }

    &:checked + .doctors-filter__check {
      border-color: $color-blue;
      background-color: $color-doctor-hero-bg;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='9' viewBox='0 0 12 9' fill='none'%3E%3Cpath d='M1%204.5%20L4.5%208%20L11%201' stroke='%234F6ECB' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: center;
      background-size: 10px 7px;
    }
  }

  &__check {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    box-sizing: border-box;
    border: 1.5px solid $color-blue;
    border-radius: 4px;
    background: $color-white;
    transition: border-color 0.15s ease, background-color 0.15s ease;
  }

  &__submit {
    min-width: 0;
    box-sizing: border-box;
    height: 40px;
    padding: 0 32px;
    gap: 0;
    width: 100%;

    @include up($bp-lg) {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 8px 16px;
    }

    &-icon {
      display: none;
      align-items: center;
      justify-content: center;
      line-height: 0;

      svg {
        display: block;
        width: 20px;
        height: 20px;
        color: $color-white;
      }
    }

    // Планшет: квадратная кнопка с иконкой
    @include between($bp-md, $until-991) {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 40px;
      min-width: 40px;
      padding: 0;
      box-sizing: border-box;

      .doctors-filter__submit-text {
        @include visually-hidden;
      }

      .doctors-filter__submit-icon {
        display: flex;
      }
    }

    // Ноутбук: текстовая кнопка
    @include between($bp-md2, $until-1439) {
      width: 100%;
      max-width: 120px;

      .doctors-filter__submit-text {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        padding: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
        border: 0;
      }

      .doctors-filter__submit-icon {
        display: none;
      }
    }

    @include down-to($until-767) {
      width: 100%;
      max-width: none;
      box-sizing: border-box;

      .doctors-filter__submit-text {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        padding: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
        border: 0;
      }

      .doctors-filter__submit-icon {
        display: none;
      }
    }

    @include sm {
      width: auto;
      justify-self: start;
      min-width: 120px;
    }
  }

  @include sm {
    margin-bottom: 20px;
  }
}
