@import '../../styles/breakpoints/index';

:root {
  --CustomSearchBox-inputHeight: 48px;

  @media (orientation: portrait) {
    --CustomSearchBox-inputHeight: 48px;
  }

  @media (orientation: portrait) and ($sm) {
    --CustomSearchBox-inputHeight: 64px;
    --CustomSearchBox-inputPaddingTop: 8px;
  }

  @media (orientation: landscape) {
    --CustomSearchBox-inputHeight: 44px;
  }

  @media (orientation: landscape) and ($md) {
    --CustomSearchBox-inputPaddingTop: 8px;
    --CustomSearchBox-inputHeight: 48px;
  }

  @media (orientation: landscape) and ($lg) {
    --CustomSearchBox-inputPaddingTop: 8px;
    --CustomSearchBox-inputHeight: 54px;
  }

  @media (orientation: landscape) and ($xl) {
    --CustomSearchBox-inputPaddingTop: 24px;
    --CustomSearchBox-inputHeight: 78px;
  }
}

.form {
  display: grid;
  align-items: center;
  position: relative;
  --iconWidth: 16px;
  width: 100%;
  background-color: var(--color-background);
  overflow: hidden;
  justify-self: flex-end;
  transition: width 0.5s var(--animation-bezier);

  @media (orientation: portrait) {
    width: 40px;
    grid-column: 1 / span 12;
    grid-row: 1 / span 1;
  }

  @media (orientation: portrait) and ($sm) {
    width: 100%;
    grid-column: 5 / span 6;
  }

  @media (orientation: landscape) {
    grid-column: 5 / span 6;
  }

  @media ($lg) {
    --iconWidth: 20px;
  }
}

.form.hasScrolled,
.form:focus-within {

  @media (orientation: portrait) {
    width: 100%;
  }
}

.observer {

  @media (orientation: portrait) and ($sm) {
    display: none;
  }

  @media (orientation: landscape) {
    display: none;
  }
}

.inputWrapper {
  display: grid;
  grid-template-columns: min-content 1fr;
  align-items: baseline;
  grid-column-gap: 6px;
  width: 100%;
  outline: none;

  @media (orientation: portrait) {
    grid-template-columns: 40px 1fr;
  }

  @media (orientation: portrait) and ($sm) {
    grid-template-columns: min-content 1fr;
  }
}

.form.hasScrolled .inputWrapper,
.form:focus-within .inputWrapper {
  grid-template-columns: min-content 1fr;
}

.inputWrapper::after {
  content: '';
  position: relative;
  height: 2px;
  display: block;
  width: 100%;
  box-shadow: inset 0 -2px 0 0 var(--color-black-10);
  grid-column: span 2;
}

.inputWrapper:hover::after {
  box-shadow: inset 0 -2px 0 0 var(--color-black-50);
}

.inputWrapper:focus-within::after {
  box-shadow: inset 0 -2px 0 0 var(--color-black);
}

.input {
  height: var(--CustomSearchBox-inputHeight);
  outline: none;
  appearance: none;
  background-color: transparent;
  border: 0;
  font-weight: lighter;
  letter-spacing: var(--letter-spacing-large-1);
  outline: none;
  display: grid;
  align-items: center;
  width: 100%;
  border-radius: 0;
  grid-row: 1 / 2;
  padding-top: var(--CustomSearchBox-inputPaddingTop);;

  @media (orientation: portrait) {
    font-size: var(--size-3);
    grid-column: 1 / 2;
  }

  @media (orientation: portrait) and ($sm) {
    font-size: var(--size-4);
    grid-column: 2 / 3;
  }

  @media (orientation: landscape) {
    font-size: var(--size-2);
  }

  @media ($md) {
    font-size: var(--size-3);
  }

  @media ($xl) {
    font-size: var(--size-4);
  }

  &::placeholder {
    color: var(--color-placeholder);
    font-weight: 400;
    transition: opacity 0.25s var(--animation-bezier);

    @media (orientation: portrait) {
      opacity: 0;
    }

    @media (orientation: portrait) and ($sm) {
      opacity: 1;
    }
  }
}

.input.hasScrolled,
.form:focus-within .input {
  grid-column: 2 / 3;
}

.input.hasScrolled::placeholder,
.form:focus-within .input::placeholder {
  opacity: 1;
}

.input:not([value='']) {
  font-weight: 500;
}

.searchIcon {
  width: var(--iconWidth);
  height: var(--iconWidth);
  align-self: baseline;
  justify-self: center;
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  pointer-events: none;
  transform: translateY(2px);
}

.loadingIcon {
  width: 14px;
  height: 14px;
}

.loading {
  position: absolute;
  top: var(--CustomSearchBox-inputHeight);
  display: grid;
  align-items: center;
  justify-content: flex-end;
  grid-auto-flow: column;
  grid-column-gap: 6px;
  padding-top: 12px;
  right: 1px;
  opacity: 0;
  transition: opacity 0.25s var(--animation-bezier);
  transition-delay: 0s;
  pointer-events: none;

  @media (orientation: portrait) {
    right: calc(var(--pageMargin) + 1px);
    top: calc(var(--CustomSearchBox-inputHeight) / 2);
    transform: translateY(-50%);
  }
}

.loading.active {
  opacity: 1;
  pointer-events: all;
  transition-delay: 1s;
}

.loadingText {

  @media (orientation: portrait) {
    display: none;
  }
}

.sticky {
  position: sticky;
  top: 0;
}
