@use '../../theme/styles' as theme;

.wr-command-palette {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6rem 1rem 1rem;
  pointer-events: none;
  font-family: var(--wr-font-family-base);

  &__backdrop {
    position: absolute;
    inset: 0;
    background: var(--wr-color-overlay);
    backdrop-filter: blur(4px);
    pointer-events: auto;
    animation: wr-cmd-fade var(--wr-duration-base) var(--wr-ease-out);
  }

  &__panel {
    position: relative;
    width: 100%;
    max-width: 36rem;
    background: var(--wr-color-white);
    border: 1px solid var(--wr-color-light);
    @include theme.smooth-br(var(--wr-border-radius-base));
    box-shadow: var(--wr-shadow-modal);
    overflow: hidden;
    pointer-events: auto;
    animation: wr-cmd-pop var(--wr-duration-base) var(--wr-ease-out);
  }

  &__search {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--wr-color-light);
    color: var(--wr-color-medium);

    input {
      flex: 1 1 auto;
      min-width: 0;
      appearance: none;
      background: transparent;
      border: 0;
      outline: 0;
      padding: 0;
      color: var(--wr-color-dark);
      font-family: inherit;
      font-size: var(--wr-text-base);

      &::placeholder {
        color: var(--wr-color-medium);
      }
    }
  }

  &__hint {
    padding: 0.0625rem 0.375rem;
    border: 1px solid var(--wr-color-light);
    border-radius: var(--wr-border-radius-sm);
    color: var(--wr-color-medium);
    font-family: inherit;
    font-size: var(--wr-text-xs);
    font-weight: var(--wr-font-weight-medium);
    text-transform: uppercase;
    letter-spacing: var(--wr-tracking-wide);
  }

  &__body {
    max-height: 24rem;
    overflow-y: auto;
    padding: 0.375rem;
  }

  &__group {
    padding: 0.25rem 0;

    &:first-child {
      padding-top: 0;
    }
  }

  &__group-title {
    padding: 0.375rem 0.625rem 0.25rem;
    color: var(--wr-color-medium);
    font-size: var(--wr-text-xs);
    font-weight: var(--wr-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--wr-tracking-wide);
  }

  &__option {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--wr-border-radius-sm);
    cursor: pointer;
    color: var(--wr-color-dark);
    font-size: var(--wr-text-sm);
    line-height: var(--wr-leading-tight);
    user-select: none;

    &--active {
      background: var(--wr-color-primary-soft);
      color: var(--wr-color-primary);
    }
  }

  &__option-icon {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    color: var(--wr-color-medium);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  &__option--active &__option-icon {
    color: var(--wr-color-primary);
  }

  &__option-body {
    flex: 1 1 auto;
    min-width: 0;
  }

  &__option-label {
    font-weight: var(--wr-font-weight-medium);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &__option-description {
    margin-top: 0.0625rem;
    color: var(--wr-color-medium);
    font-size: var(--wr-text-xs);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &__option-shortcut {
    flex: 0 0 auto;
    padding: 0.0625rem 0.375rem;
    border: 1px solid var(--wr-color-light);
    border-radius: var(--wr-border-radius-sm);
    background: var(--wr-color-hover);
    color: var(--wr-color-medium);
    font-family: inherit;
    font-size: var(--wr-text-xs);
    font-weight: var(--wr-font-weight-medium);
  }

  &__empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--wr-color-medium);
    font-size: var(--wr-text-sm);
  }
}

// Full-screen presentation on small viewports — opt in per-instance with
// `responsive` or app-wide via `provideWrResponsiveOverlays()`. The palette
// auto-focuses its input, so it fills the screen from the top edge rather than
// docking to the bottom (a bottom-sheet would sit under the on-screen
// keyboard). The list flexes to fill the remaining height.
.wr-command-palette--sheet {
  padding: 0;

  .wr-command-palette__panel {
    max-width: none;
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    border: 0;
    border-radius: 0;
    // Top-docked full-screen: clear the notch at the top (search bar) and the
    // home indicator at the bottom. The panel background still fills both edges.
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .wr-command-palette__body {
    flex: 1 1 auto;
    max-height: none;
  }
}

@keyframes wr-cmd-fade {
  from {
    opacity: 0;
  }
}

@keyframes wr-cmd-pop {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(-0.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .wr-command-palette__backdrop,
  .wr-command-palette__panel {
    animation: none;
  }
}
