.category-list {
  border: none;
  display: grid;
  // Bug 1967304 - Large number (48px)
  gap: calc(var(--space-xlarge) * 2) var(--space-large);
  grid-auto-rows: 86px;
  grid-template-columns: 1fr 1fr 1fr;
  margin-block-end: var(--space-large);
  padding: 0;

  label {
    display: inline-block;
    font-size: var(--font-size-small);
    text-align: center;
    width: 100%;
  }
}

.category-header {
  display: flex;
  justify-content: space-between;

  .wallpapers-reset {
    margin: unset;
  }
}

.arrow-button {
  background: url('chrome://global/skin/icons/arrow-left.svg') no-repeat left center;

  &:dir(rtl) {
    background: url('chrome://global/skin/icons/arrow-right.svg') no-repeat right center;
  }

  border: none;
  cursor: pointer;
  margin-block-end: var(--space-xlarge);
  padding-inline-start: var(--space-xlarge);
  -moz-context-properties: fill;
  fill: currentColor;
  min-height: 1rem;
}

.wallpaper-input {
  appearance: none;
  background-clip: content-box;
  background-repeat: no-repeat;
  background-size: cover;
  border-radius: var(--border-radius-medium);
  border: none;
  box-shadow: $shadow-secondary;
  cursor: pointer;
  height: 86px;
  margin: 0;
  outline: 2px solid transparent;
  padding: 0;
  width: 100%;

  &:checked,
  &.selected {
    box-shadow: inset 0 0 0 3px var(--color-accent-primary);
  }

  &.theme-custom-wallpaper {
    border: 2px dashed var(--border-color-default, #CFCFD8);
    box-shadow: none;
    position: relative;

    &::after {
      content: '';
      -moz-context-properties: fill;
      fill: var(--icon-color);
      width: calc(var(--icon-size) * 1.25 ); // Custom size: ~20px;
      height: calc(var(--icon-size) * 1.25 ); // Custom size: ~20px;
      display: block;
      position: absolute;
      inset-block-start: 50%;
      inset-inline-start: 50%;
      transform: translate(-50%, -50%);
    }

    &:focus {
      outline-color: var(--focus-outline-color);
      outline-offset: var(--focus-outline-offset);
    }
  }

  &.theme-custom-wallpaper {
    &::after {
      background: url('chrome://global/skin/icons/plus-20.svg') center no-repeat;
    }
  }

  $wallpapers: dark-landscape, dark-color, dark-mountain, dark-panda, dark-sky, dark-beach, light-beach, light-color, light-landscape, light-mountain, light-panda, light-sky;

  @each $wallpaper in $wallpapers {
    &.#{$wallpaper} {
      background-image: url('chrome://newtab/content/data/content/assets/wallpapers/#{$wallpaper}.avif')
    }
  }

  &:focus-visible {
    outline-offset: var(--focus-outline-offset);
  }

  &:hover {
    filter: brightness(55%);
    outline-color: transparent;
  }
}

.theme-custom-color-picker {
  background-color: var(--newtab-background-color-secondary);
  background-clip: content-box;
  border-radius: var(--border-radius-medium);
  outline: 2px dashed var(--border-color-default, #CFCFD8);
  outline-offset: 2px;
  position: relative;

  .wallpaper-input {
    box-shadow: none;

    &:focus {
      outline-color: var(--focus-outline-color);
      outline-offset: 6px;
    }
  }

  // The color picker has a default state where the user has not picked a custom color
  // It will either be a custom color or the default background color.
  // Depending on this, we need to override the icon color to match the correct contrast.
  // The default-color-set and custom-color-dark classes are removed whenever
  //  a user interacts with the color picker, letting the current color dictate contrast.

  // When the user has no custom color set, we need to hide the color picker input entirely to
  // show the default panel color beneath
  &.default-color-set {
    #solid-color-picker {
      opacity: 0;
    }

    &::after {
      @media (prefers-color-scheme: dark) {
        color-scheme: dark;
      }
    }
  }

  &.custom-color-dark {
    &::after {
      color-scheme: dark;
    }
  }

  // Change the icon color based on the selected color
  &.is-dark::after {
    color-scheme: dark;

    @media (prefers-color-scheme: dark) {
      color: #FBFBFE; // var(--color-gray-05);
    }
  }

  // Color Picker Icon
  &::after {
    background: url('chrome://global/skin/icons/color-picker-20.svg') center no-repeat;
    content: '';
    -moz-context-properties: fill;
    fill: var(--icon-color);
    width: calc(var(--icon-size) * 1.25); // Custom size: ~20px;
    height: calc(var(--icon-size) * 1.25); // Custom size: ~20px;
    display: block;
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    cursor: pointer;
    color-scheme: light;
  }

  label {
    display: inline-block;
    font-size: var(--font-size-small);
    text-align: center;
    width: 100%;
  }

  ::-moz-color-swatch {
    border-color: transparent;
    border-radius: var(--border-radius-medium);
  }
}

.wallpaper-list {
  display: grid;
  gap: var(--space-large);
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 86px;
  margin: var(--space-large) 0;
  padding: 0;
  border: none;

  &.category {
    background-color: var(--newtab-background-color-secondary);
    color: var(--newtab-text-primary-color);
    display: unset;
    gap: unset;
    grid-auto-rows: unset;
    grid-template-columns: unset;
    height: 100%;
    // Can get rid of padding and replace height with
    // 'height: stretch' when bug 1789477 lands.
    padding-block-end: var(--space-xxlarge);
    inset-inline-start: var(--space-xlarge);
    position: absolute;
    inset-block-start: 0;
    width: 380px;
    z-index: 2;
    transform: translateX(100%);
    overflow-y: auto;

    &:dir(rtl) {
      transform: translateX(-100%);
    }

    fieldset {
      border: none;
      display: grid;
      gap: var(--space-large);
      grid-auto-rows: 86px;
      grid-template-columns: 1fr 1fr 1fr;
    }

    @media (prefers-reduced-motion: no-preference) {
      &.wallpaper-list-enter,
      &.wallpaper-list-exit,
      &.wallpaper-list-enter-done,
      &.wallpaper-list-exit-done {
        transition: transform 300ms;
      }
    }

    &.wallpaper-list-enter-done,
    &.wallpaper-list-enter-active {
      transform: translateX(0);
    }
  }

  &:not(.ignore-color-mode) .wallpaper-input,
  &:not(.ignore-color-mode) .sr-only {
    &.theme-light {
      display: inline-block;

      @include dark-theme-only {
        display: none;
      }
    }

    &.theme-dark {
      display: none;

      @include dark-theme-only {
        display: inline-block;
      }
    }
  }

  // visually hide label, but still read by screen readers
  .sr-only {
    opacity: 0;
    overflow: hidden;
    position: absolute;
    pointer-events: none;
  }
}

.wallpapers-reset {
  background: none;
  border: none;
  text-decoration: underline;
  margin-inline: auto;
  display: block;
  font-size: var(--font-size-small);
  color: var(--newtab-text-primary-color);
  cursor: pointer;

  &:hover {
    text-decoration: none;
  }

  &:focus-visible {
    outline-offset: -2px;
  }
}

// Bug 1947813 - Custom Upload Error Message
.custom-wallpaper-error {
  padding-block-start: var(--space-xlarge);
  font-size: var(--font-size-small);
  display: flex;
  gap: var(--space-small);
  align-items: center;

  .icon {
    width: var(--button-size-icon-small);
    height: var(--button-size-icon-small);
    fill: var(--icon-color-critical);
  }
}
