@keyframes grow {
  0%   {
    opacity: 0;
    width: 0;
    margin-left: 0;
    margin-right: 0;
  }
  100% {
    opacity: 1;
    width: 10rem;
    margin: 4px;
  }
}

@keyframes shrink {
  0% {
    opacity: 1;
    width: 10rem;
    margin: 4px;
  }
  100% {
    opacity: 0;
    width: 0;
    margin-left: 0;
    margin-right: 0;
    padding: 0;
  }
}

@keyframes fade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

form[name='search'] {
  margin-left: auto;
  margin-right: auto;
  max-width: calc(var(--max-content) * 2/3);
}

input {
  background: var(--background-1);
  color: var(--foreground-1);
  border: 1px solid var(--background-3);
  border-radius: 3px;
  padding: 8px;
  margin-bottom: 11px;
  font-size: 1em;
  line-height: 1.6;
}

select {
  appearance: none;
  all: unset;
  background: var(--background-1);
  color: var(--foreground-1);
  border: 1px solid var(--background-3);
  border-radius: 3px;
  padding: 8px;
  font-size: 1em;
  line-height: 1.6;
  cursor: pointer;
}

.search-controls {
  display: flex;
  align-items: center;
  margin-bottom: 11px;
  background: var(--background-1);
  border-radius: 3px;
  border: 1px solid var(--background-3);
  outline-color: transparent;
  transition: border .1s ease-in-out, outline .1s ease-in-out;
  overflow: hidden;

  * {
    box-sizing: border-box;
  }

  --animation-timing: .1s ease-in-out;

  &:has(input:focus) {
    border-color: var(--orange-1);
    outline: 1px solid var(--orange-1);
  }

  label {
    color: var(--foreground-3);
  }

  input {
    flex: 1;
    margin-bottom: 0;
    border: none;
    line-height: 28px;
    &:focus {
      outline: none;
    }
  }

  select {
    padding: 0;
    background: transparent;
    border: none;
  }

  .button {
    align-self: center;
    margin: 6px;
    padding: 0;
    gap: 0;
    outline-color: transparent;

    label,
    select {
      padding: 3px 8px;
    }

    &:has(select:focus) {
      outline: 2px solid var(--orange-1);
    }

    @media (max-width: 600px) {
      flex-direction: column;
      align-items: flex-start;

      label {
        font-size: 0.8em;
        line-height: 1;
        width: 100%;
        padding-bottom: 0;
      }
      select {
        padding-top: 0;
      }
    }
  }

  .sort-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.75rem 0 0.5rem;
    border-left: 1px solid var(--background-3);
    margin-left: 0.5rem;

    button {
      background: none;
      border: none;
      color: var(--foreground-3);
      font: inherit;
      padding: 0;
      cursor: pointer;
      transition: color .1s ease-in-out;

      &:hover {
        color: var(--foreground-2);
        text-decoration: none;
      }

      &:focus-visible {
        outline: 2px solid var(--orange-1);
        outline-offset: 2px;
      }

      &.is-active {
        color: var(--foreground-1);
        font-weight: 600;
      }
    }

    .sort-toggle-separator {
      color: var(--foreground-4);
      font-size: 0.9em;
    }
  }

  @media (max-width: 600px) {
    flex-wrap: wrap;

    input {
      width: 33vw;
    }
    .sort-toggle {
      gap: 0.5rem;
      font-size: 14px;
      padding: 0 0.5rem;
    }
  }
}


/* Compact header search: hide Sort By until focus, with animation */
form.compact {
  margin: 0;

  .search-controls {
    margin-bottom: 0;

    input {
      line-height: 1;
      width: 9em;
      transition: width var(--animation-timing);
    }

    .button {
      display: none;
      animation: var(--animation-timing) forwards grow;
      font-size: 13px;
      margin: 4px;

      label {
        padding-right: 0;
      }
    }
  }

  &[data-expanded="true"] {
    .search-controls {
      input {
        width: 12em;
      }

      .button {
        display: flex;
      }
    }
  }

  &.going-away .button {
    display: flex;
    animation: var(--animation-timing) forwards shrink;
  }

  padding: 0 var(--side-padding) 0 0;

  @media (max-width: 50rem) {
    display: none;

    &[data-expanded="true"],
    &.going-away {
      display: flex;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      padding: 8px var(--side-padding);
      background: var(--background-2);
      align-items: center;

      > * {
        flex: 1;
      }
    }

    &.going-away {
      animation: var(--animation-timing) forwards fade;
    }
  }
}

.timeline-break {
  margin: 0.6rem 0;
  font-weight: 600;
  color: var(--foreground-3);
  padding: 8px 2px;
}

.search-subcontrols {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.35rem;
  margin-right: 2px;
  font-size: 0.85em;
  color: var(--foreground-3);

  .usage-toggle {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    cursor: pointer;
    transition: color .1s ease-in-out;
    text-decoration: line-through;
    font-size: small;

    &:hover {
      color: var(--foreground-2);
    }

    &:focus-visible {
      outline: 2px solid var(--orange-1);
      outline-offset: 2px;
    }

    &.is-active {
      color: var(--foreground-1);
      font-weight: 500;
      text-decoration: none;
    }
  }
}
