listview,
list {
  color: $text_color;
  background-color: $base_color;
  background-clip: padding-box;
  border-color: $borders_color;

  > row {
    padding: 2px;
    background-clip: padding-box;
  }

  > row.expander { padding: 0px; }
  > row.expander .row-header { padding: 2px; }

  &.horizontal row.separator,
  &.separators.horizontal > row:not(.separator) {
    border-left: 1px solid $borders_color;
  }

  &:not(.horizontal) row.separator,
  &.separators:not(.horizontal) > row:not(.separator) {
    border-bottom: 1px solid $borders_color;
  }
}

row {
  @include focus-ring();

  background-clip: padding-box;

  &.activatable {
    &.has-open-popup, // this is for indicathing which row generated a popover see https://bugzilla.gnome.org/show_bug.cgi?id=754411
    &:hover { background-color: $view_hover_color; }

    &:active { background-color: $view_active_color; }

    &:selected {
      &.has-open-popup,
      &:hover { background-color: $view_selected_hover_color; }

      &:active { background-color: $view_selected_active_color; }
    }
  }

  &:selected {
    background-color: $view_selected_color;
  }
}

/*******************************************************
 * Rich Lists                                          *
 * Large list usually containing lots of widgets       *
 * https://gitlab.gnome.org/GNOME/gtk/-/issues/3073    *
 *******************************************************/

.rich-list { /* rich lists usually containing other widgets than just labels/text */
  > row {
    padding: 8px 12px;
    min-height: 32px; /* should be tall even when only containing a label */

    > box {
      border-spacing: 12px;
    }
  }
}

/****************
 * AdwActionRow *
 ****************/

row {
  label.subtitle {
    font-size: smaller;
    @extend .dim-label;
  }

  > box.header {
    margin-left: 12px;
    margin-right: 12px;
    min-height: 50px;

    > .icon:disabled {
      filter: opacity(.5);
    }

    > box.title {
      margin-top: 8px;
      margin-bottom: 8px;
    }
  }
}

/***************
 * AdwComboRow *
 ***************/

popover.background.combo > contents {
  padding: 0px;

  list, listview {
    border-style: none;
    background-color: transparent;
    min-width: 200px;

    > row {
      padding: 0px 12px 0px 12px;
      min-height: 50px;
      border-bottom: 1px solid $borders_color;

      &:first-child {
        border-top-left-radius: $popover_radius - 2;
        border-top-right-radius: $popover_radius - 2;
      }

      &:last-child {
        border-bottom-left-radius: $popover_radius - 2;
        border-bottom-right-radius: $popover_radius - 2;
        border-bottom: none;
      }
    }
  }

  scrollbar.vertical {
    padding-top: 2px;
    padding-bottom: 2px;
  }
}

row.combo {
  image.dropdown-arrow:disabled {
    filter: opacity(.5);
  }

  listview.inline {
    background: none;
    border: none;
    box-shadow: none;
    color: inherit;

    &, &:disabled {
      background: none;
      color: inherit;
    }
  }
}

/******************
 * AdwExpanderRow *
 ******************/

@mixin margin-start($margin) {
  &:dir(ltr) {
    margin-left: $margin;
  }

  &:dir(rtl) {
    margin-right: $margin;
  }
}

%boxed_list_row {
  transition: 200ms $ease-out-quad;
  border-bottom: 1px solid $borders_color;

  &:not(:selected).activatable {
    &.has-open-popup,
    &:hover {
      background-color: gtkalpha(currentColor, .03);
    }

    &:active {
      background-color: gtkalpha(currentColor, .08);
    }
  }
}

row.expander {
  // Drop transparent background on expander rows to let nested rows handle it,
  // avoiding double highlights.
  background: none;
  padding: 0px;

  > box > list {
    background: none;
    color: inherit;
  }

  list.nested {
    background-color: gtkalpha(currentColor, .03);
    color: inherit;
  }

  list.nested > row {
    @extend %boxed_list_row;
  }

  // AdwExpanderRow arrow rotation

  image.expander-row-arrow {
    transition: 200ms $ease-out-quad;
    @include margin-start(6px);
  }

  &:checked image.expander-row-arrow {
    -gtk-icon-transform: rotate(0turn);
  }

  &:not(:checked) image.expander-row-arrow {
    @extend .dim-label;

    &:dir(ltr) {
      -gtk-icon-transform: rotate(-0.25turn);
    }

    &:dir(rtl) {
      -gtk-icon-transform: rotate(0.25turn);
    }
  }

  &:checked image.expander-row-arrow:not(:disabled) {
    color: $accent_color;
  }

  image.expander-row-arrow:disabled {
    filter: opacity(.5);
  }
}

/*****************
 * Content Lists *
 *****************/

list.content,
listview.content {
  background-color: $base_color;
  color: $text_color;
  border: 1px solid $borders_color;
  border-radius: 8px;

  > row {
    // Regular rows and expander header rows background
    &, &.expander row.header {
      @extend %boxed_list_row;
    }

    &.expander {
      border: none;
    }

    // Rounded top
    &:first-child {
      &, &.expander row.header {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
      }
    }

    // Rounded bottom
    &:last-child {
      &,
      &.expander:not(:checked),
      &.expander:not(:checked) row.header,
      &.expander:checked list.nested,
      &.expander:checked list.nested > row:last-child {
        border-bottom-left-radius: 8px;
        border-bottom-right-radius: 8px;
        border-bottom-width: 0;
      }
    }
  }
}
