columnview.view,
treeview.view {
  border-left-color:  $treeview_borders_color; // this is actually the tree lines color,
  border-top-color: $treeview_borders_color;                         // while this is the grid lines color, better then nothing

  @include focus-ring();

  &:selected {
    &:focus, & {
      border-radius: 0;
      outline-color: $alt_focus_border_color;

      @extend %selected_items;
    }
  }

  &:disabled {
    color: $insensitive_fg_color;

    &:selected {
      color: mix($selected_fg_color, $selected_bg_color, 40%);
    }
  }

  &.separator {
    min-height: 2px;
    color: $treeview_borders_color;
  }

  &:drop(active) {
    box-shadow: none;
  }

  > dndtarget:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $selected_borders_color;

    &.after { border-top-style: none; }

    &.before { border-bottom-style: none; }
  }

  &.expander {
    // GtkTreeView uses the larger of the expander’s min-width and min-height
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');

    &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }

    color: mix($text_color, $base_color, 70%);

    &:hover { color: $text_color; }

    &:selected {
      color: mix($selected_fg_color, $selected_bg_color, 70%);

      &:hover { color: $selected_fg_color; }
    }

    &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }

    &:disabled { color: gtkalpha(currentColor, 0.5); }
  }

  &.progressbar { // progress bar in treeviews
    @if $variant == light { color: $base_color; }

    background-color: $selected_bg_color;
    background-image: image($selected_bg_color);
    box-shadow: none;

    &:selected {
      &:focus, & {

        @if $variant == 'light' {
          color: $selected_bg_color;
        }
        @else {
          box-shadow: inset 0 1px transparentize(white, 0.95);
        }

        background-image: image($base_color);
      }
    }
  }

  &.trough { // progress bar trough in treeviews
    background-color: transparentize($fg_color,0.9);

    &:selected {
      &:focus, & {
        background-color: if($variant == 'light',
                             transparentize($selected_fg_color, 0.7),
                             darken($selected_bg_color, 10%));
      }
    }
  }

  > header {
    > button {
      $_column_header_color: mix($fg_color, $base_color, 50%);

      @extend %column_header_button;

      color: $_column_header_color;
      background-color: $base_color;
      font-weight: bold;
      box-shadow: none;

      &:hover {
        @extend %column_header_button;

        color: mix($_column_header_color, $fg_color, 50%);
        box-shadow: none;
        transition: none; //I shouldn't need this
      }

      &:active {
        @extend %column_header_button;

        color: $fg_color;
        transition: none; //I shouldn't need this
      }
      sort-indicator {
        &.ascending {
          -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
        }
        &.descending {
          -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        }

        min-height: 16px;
        min-width: 16px;
      }
    }
  }

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    &:active, &:selected, &:hover, & {
      padding: 0 6px;
      color: $base_color;
      background-image: none;
      background-color: $selected_bg_color;
      border-style: none;
      border-radius: 0;
      box-shadow: inset 0 0 0 1px $base_color;
      transition: none;
    }
  }

  acceleditor > label { background-color: $selected_bg_color; } // see tests/testaccel to test
}

%column_header_button {
  padding: 0 6px;
  background-image: none;
  border-style: none none solid solid;
  border-color: $treeview_borders_color;
  border-radius: 0;

  &:disabled {
    border-color: $bg_color;
    background-image: none;
  }

  &:last-child { border-right-style: none; }
}

/********************************************************
 * Data Tables                                          *
 * treeview like tables with individual focusable cells *
 * https://gitlab.gnome.org/GNOME/gtk/-/issues/2929     *
 ********************************************************/

columnview {
  // move padding to child cells
  > listview > row {
    padding: 0;

    // align horizontal sizing with header buttons
    > cell {
      padding: 8px 6px;

      &:not(:first-child) {
        border-left: 1px solid transparent;
      }
    }
  }

  // make column separators visible when :show-column-separators is true
  &.column-separators > listview > row > cell {
    border-left-color: $treeview_borders_color;
  }

  // shrink vertically for .data-table
  &.data-table > listview > row > cell {
    padding-top: 2px;
    padding-bottom: 2px;
  }
}

columnview row:not(:selected) cell editablelabel:not(.editing):focus-within {
  outline: 2px solid $focus_border_color;
}

columnview row:not(:selected) cell editablelabel.editing:focus-within {
  outline: 2px solid $selected_bg_color;
}

columnview row:not(:selected) cell editablelabel.editing text selection {
  color: $selected_fg_color;
  background-color: $selected_bg_color;
}

treeexpander {
  border-spacing: 4px;
}
