//
// Suffix
//

$asset_suffix: if($variant == dark, '-dark', '');


//
// Background sizing
//

$icon_size: 16px;
$widget_size: 37.3px;
$attention: 6px 6px;
$separator_narrow: 1px 1px;
$separator_wide: 1px 1px, 1px 1px;
$titlebutton_small: if($ref_weight < 1.0, 20px, 28px);


//
// transitions
//

%transition {
  // do not include sizing factors and text colors/shadows
  transition-property: opacity,
                       border-color,
                       border-image,
                       background-color,
                       background-image,
                       box-shadow,
                       icon-shadow;
  transition-timing-function: $slope_medium;
  transition-duration: 0.2s;
}


// /*****************
//  * Common States *
//  *****************/

* {
  @extend %transition; // global transition setting

  padding: 0;
  background-clip: padding-box;

  // We use the outline properties to signal the focus properties
  // to the adwaita engine: using real CSS properties is faster,
  // and we don't use any outlines for now.

  outline-style: solid;
  outline-width: 2px;
  outline-color: $outline_track_color;
  outline-offset: rem(-4px);
  -gtk-outline-radius: 2px;

  -gtk-secondary-caret-color: $selected_bg_color;

  // disable drop-shadows as default
  text-shadow: none;
  -gtk-icon-shadow: none;
}


// /***************
//  * Base States *
//  ***************/

.background {
  background-color: $bg_color;
  color: $fg_color;
}

// These wildcard seems unavoidable, need to investigate.
// Wildcards are bad and troublesome, use them with care,
// or better, just don't.
// Everytime a wildcard is used a kitten dies, painfully.

*:disabled { -gtk-icon-effect: dim; }

// for backdrop, tone down element surfaces with transparentize
%fade_effect {
  &:backdrop > * { opacity: 0.4; }
}

.gtkstyle-fallback {
  background-color: $bg_color;
  color: $secondary_fg_color;
  &:hover {
    background-color: mix($fg_color, $bg_color, 12%);
    color: $fg_color;
  }
  &:active {
    background-color: mix($fg_color, $bg_color, 25%);
    color: $fg_color;
  }
  &:disabled {
    background-color: $bg_color;
    color: $insensitive_fg_color;
  }
  &:selected {
    background-color: $selected_bg_color;
    color: $selected_fg_color;
  }
}

%view,
.view {
  @extend %activatable_row;
  background-color: $base_color;
  color: $fg_color;
  &:hover,
  &:active,
  &:selected {
    border-radius: 2px;
    -gtk-outline-radius: 2px;
  }
  &:disabled { color: $insensitive_fg_color; }
  &:backdrop {
  }
  &:selected,
  &:selected:focus { @extend %selected_items; }
}

.view,
textview {
  text {
    background-color: $base_color;
    color: $fg_color;
    &:disabled { color: $insensitive_fg_color; }

    selection {
      &, &:focus { @extend %selected_items; }
    }
  }
}

textview {
  outline-width: 0;

  &,
  &.view,
  text,
  text selection { // remove images and transitions
    background-image: none;
    transition: none;
  }

  border { background-color: $bg_color; }
}

iconview { @extend %view; }

.rubberband,
rubberband {
  border: 1px solid $selected_bg_color;
  background-color: gtkopacity($selected_bg_color, 0.2);
}

flowbox {
  rubberband { @extend rubberband; }

  flowboxchild {
    padding: rem(4px, $sw: 1.0);
    border-radius: 0;
    -gtk-outline-radius: 2px;
    &:selected {
      @extend %selected_items;
      outline-offset: -2px;
    }
  }
}

// tiled flowbox-child in 3.23 or higher
frame.content-view flowbox > flowboxchild.tile {
  margin: if($ref_weight < 1.0, 6px, 8px);
  padding: if($ref_weight < 1.0, 6px, 8px);
  border-radius: 2px;
  background-color: $base_color;
  color: $secondary_fg_color;
  box-shadow: $z-depth-1,
              inset 0 1px $highlight_color;
  transition-timing-function: $slope_slow;
  &:hover { // not implemented yet
    // background-color: $track_color;
    // color: $fg_color;
    // box-shadow: $z-depth-2,
    //             inset 0 1px $highlight_color;
  }
  &:active { // not implemented yet
    // background-color: $track_color;
    // color: $fg_color;
    // transition: all 0.2s $slope_slow, background-image 0;
    // animation: flat_ripple_effect 0.3s $slope_slow forwards;
    // box-shadow: $z-depth-2,
    //             inset 0 1px $highlight_color;
  }
  &:selected {
    background-color: gtkopacity($selected_bg_color, 0.2);
    color: $fg_color;
    box-shadow: $z-depth-2,
                inset 0 1px $highlight_color;
    transition-timing-function: $slope_slow;
  }
  &:disabled {
    background-color: $track_color;
    color: $insensitive_secondary_fg_color;
    box-shadow: none;
  }
}

label {
  caret-color: currentColor; // this shouldn't be needed.

  &.separator { color: $tertiary_fg_color; }

  &:selected,
  row:selected & { // no need to set backgrounds
    color: $selected_fg_color;
    &:disabled { color: $insensitive_selected_fg_color; }
  }

  selection,
  selection:focus { @extend %selected_items; }

  &:disabled {
    color: $insensitive_fg_color;

    selection { color: $insensitive_selected_fg_color; }
  }

  // always use dark foreground in Gnome-Software
  &.kudo-label {
    color: $fixed_fg_color;
  }
}

%dim_label,
.dim-label { opacity: 0.55; }

%osd, .osd { opacity: 0.9; }


// /*************
//  * Assistant *
//  *************/

assistant { // sidebar styling
  .sidebar {
    padding: rem(6.7px, $sw: 1.0) 0;
    background-color: $secondary_dark_color;
    &:dir(ltr) { border-right: 1px solid $borders_color; }
    &:dir(rtl) { border-left: 1px solid $borders_color; }

    label {
      padding: rem(5.3px, $sw: 1.0) rem(8px, $sw: 1.0) rem(6.7px, $sw: 1.0);
      color: $secondary_fg_color;
      font-weight: 500;
      &.highlight { color: $selected_bg_color; }
    }
  }

  &.csd .sidebar { border-top-style: none; }
}


// /*********************
//  * Spinner Animation *
//  *********************/

@keyframes spinner {
  to { -gtk-icon-transform: rotate(1turn); }
}

spinner {
  background: none;
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');
  color: $accent_label_color;
  opacity: 0; // non spinning spinner makes no sense
  &:checked {
    opacity: 1.0;
    animation: spinner 1s linear infinite;
    &:backdrop { opacity: 1.0; }
  }
  &:disabled { color: gtkopacity($accent_label_color, 0.4); }
  &:backdrop { opacity: 0; }

  .osd &,
  .floating-bar &,
  .app-notification &,
  headerbar &,
  messagedialog & {
    color: $inverted_accent_label_color;
    &:disabled { color: gtkopacity($inverted_accent_label_color, 0.4); }
  }
}


// /****************
//  * Text Entries *
//  ****************/

%entry_fallback {
  &, &.flat {
    @extend %entry_fallback_normal;
    border-radius: 2px;
    &:focus { @extend %entry_fallback_focus; }
    &:disabled { @extend %entry_fallback_insensitive; }
  }
}

%entry_native {
  .background & {
    @include entry(normal);
    border-radius: 0;
    background-color: transparent;
    &:focus {
      @include entry(focus);
      background-color: transparent;
    }
    &:disabled {
      @include entry(insensitive);
      background-color: transparent;
    }
  }

  .background &.flat {
    @include entry(flat-normal);
    border-radius: 0;
    background-color: transparent;
    &:focus {
      @include entry(flat-focus);
      background-color: transparent;
    }
    &:disabled {
      @include entry(flat-insensitive);
      background-color: transparent;
    }
  }
}

entry {
  min-height: rem(13.3px);
  min-width: rem(33.3px);
  padding: rem(9.3px) rem(8px) rem(10.7px);

  // fallback entries for non-native apps
  @extend %entry_fallback;

  // standard entries for native Gtk+ apps
  @extend %entry_native;

  selection {
    &, &:focus { @extend %selected_items; }
  }

  image { // icons inside the entry
    &.left { margin-right: rem(8px); }
    &.right { margin-left: rem(8px); }
  }

  progress { @extend %entry_progressbar; }

  // fallback linked-entries for non-native apps
  .linked > &, &.flat,
  .linked.vertical > &, &.flat {
    @extend %entry_fallback_normal;
    border-radius: 2px;
    &:focus { @extend %entry_fallback_focus; }
    &:disabled { @extend %entry_fallback_insensitive; }
  }

  // standard linked-entries for native Gtk+ apps
  .background .linked > &, &.flat,
  .background .linked.vertical > &, &.flat {
    @include entry(flat-normal);
    border-radius: 0;
    -gtk-outline-radius: 0;
    background-color: transparent;
    &:focus {
      @include entry(flat-focus);
      background-color: transparent;
    }
    &:disabled {
      @include entry(flat-insensitive);
      background-color: transparent;
    }
  }

  // entry error, warning and missing style
  @each $e_type, $e_color in (error, $error_color),
                             (warning, $warning_color),
                             (search-missing, $error_color) {
    &.#{$e_type} {
      @include entry(normal, $e_color);
      &:focus { @include entry(focus, $e_color); }
      &:disabled { @include entry(insensitive, $e_color); }
      &.flat {
        @include entry(flat-normal, $e_color);
        &:focus { @include entry(flat-focus, $e_color); }
        &:disabled { @include entry(flat-insensitive, $e_color); }
      }
    }
  }

  image { // entry icons colors
    &:not(:hover):not(:active) { color: gtkalpha(currentColor, 0.87); }
    &:active { color: $selected_bg_color; }
    &:disabled { color: gtkalpha(currentColor, 0.54); }
  }

  &:drop(active) {
    &, &:focus {
      border-color: $drop_target_color;
      box-shadow: inset 0 0 0 1px $drop_target_color;
    }
  }

  treeview & { // reset styling inside tree-view
    &, &.flat {
      &, &:focus {
        margin-bottom: -1px;
        padding: 1px 1px 2px; // add extra 1px padding at bottom
        border-radius: 0;
        border-image: none;
        border: 1px solid $base_color;
        background-image: image($base_color);
        color: $fg_color;
        box-shadow: none;
        transition: none;
      }
    }
  }

  grid & { // special case
    padding-top: rem(9.3px - 2.7px);
    padding-bottom: rem(10.7px - 2.7px);

    > progress { margin: rem(-9.3px + 2.7px) 0 rem(-10.7px + 2.7px); }
  }

  .osd & {
  }

  &.entry-tag { // for libgd apps
    margin: rem(2.7px);
    padding: rem(9.3px - 2.7px) rem(6.7px) rem(10.7px - 2.7px);
    border-radius: 100px;
    border: none;
    background-image: image($suggested_color);
    box-shadow: none;
    &:not(:hover):not(:active) { color: $secondary_selected_fg_color; }
    &:hover,
    &:active { color: $selected_fg_color; }

    &:dir(ltr) { margin: rem(2.7px) rem(-4px) rem(2.7px) rem(8px); }
    &:dir(rtl) { margin: rem(2.7px) rem(8px) rem(2.7px) rem(-4px); }

    &.button {
      &,
      &:hover,
      &:active { // unset styling
        background-color: transparent;
        background-image: none;
        border-image: none;
        border: none;
        box-shadow: none;
        animation: none;
      }
      &:not(:hover):not(:active) { color: $secondary_selected_fg_color; }
      &:hover,
      &:active { color: $selected_fg_color; }
    }
  }

  > window.background:not(.csd) { // 'candidate' pop-down window
    border-radius: 0;
    background-color: $base_color;

    // non-CSD decoration
    decoration { box-shadow: $z-depth-1; }

    frame > border { border: none; }

    treeview.view {
      &:selected { // fallback to standard hovering
        background-color: $track_color;
        color: $fg_color;
      }
    }
  }
}


// /***********
//  * Buttons *
//  ***********/

// stuff for .needs-attention
@keyframes needs_attention {
  from { background-size: 0 0; }
  to { background-size: $attention; }
}

button {
  min-height: rem(13.3px);
  min-width: rem(33.3px);
  padding: rem(9.3px) rem(13.3px) rem(10.7px);
  border-radius: 2px;
  -gtk-outline-radius: 2px;
  background-repeat: no-repeat;
  background-position: center, center;
  font-weight: 500;

  // fallback buttons for non-native apps
  @extend %button_fallback_normal;
  &:hover { @extend %button_fallback_hover; }
  &:active,
  &:checked { @extend %button_fallback_active; }
  &:disabled { @extend %button_fallback_insensitive; }
  &:checked:disabled {
    @extend %button_fallback_checked_insensitive;
  }

  // raised buttons for native Gtk+ apps
  .background & {
    @include button(normal);
    border: none; // unset all borders
    &:hover { @include button(hover); }
    &:active { @include button(active); }
    &:disabled { @include button(insensitive); }
    &:checked { @include button(checked); }
    &:checked:disabled { @include button(checked-insensitive); }
  }

  &.flat {
    @include button(flat-normal);
    &:hover { @include button(flat-hover); }
    &:active { @include button(flat-active); }
    &:disabled { @include button(flat-insensitive); }
    &:checked { @include button(flat-checked); }
    &:checked:disabled { @include button(flat-checked-insensitive); }
    .linked > & {
      border-radius: 2px;
      -gtk-outline-radius: 2px;
      &.image-button {
        border-radius: 100px;
        -gtk-outline-radius: 100px;
      }
    }
  }

  // big standalone buttons like in Documents pager
  &.osd {
    &.image-button {
      @extend %button_flat_normal;
      @extend %image_button;
      padding: rem(17.3px);
      background-color: gtkopacity($inverted_dark_color, 0.9);
      &:not(:active):not(:disabled):not(hover) {
        color: $inverted_secondary_accent_label_color;
      }
      &:hover {
        @extend %button_flat_hover;
        color: $inverted_accent_label_color;
        background-image: image($track_color);
      }
      &:active {
        @extend %button_flat_active;
        color: $inverted_accent_label_color;
      }
    }
    &:disabled { opacity: 0; }

    .linked > & { // 'rotate CW/CCW' linked-buttons
      &.image-button {
        &:not(:disabled) {
          border: none;
          background-color: gtkopacity($inverted_dark_color, 0.9);
        }
        &:first-child {
          &:dir(ltr) { border-radius: 2px 0 0 2px; }
          &:dir(rtl) { border-radius: 0 2px 2px 0; }
        }
        &:last-child {
          &:dir(ltr) { border-radius: 0 2px 2px 0; }
          &:dir(rtl) { border-radius: 2px 0 0 2px; }
        }

        image { padding: 0 rem(8px); }
      }
    }
  }

  // overlay / OSD style
  .osd & {
  }

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color in (suggested-action, $suggested_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} {
      background-color: $b_color;
      color: $secondary_selected_fg_color;
      &:hover {
        @extend %button_hover;
        background-color: $b_color;
        color: $selected_fg_color;
      }
      &:active {
        @extend %button_active;
        background-color: $selected_bg_color;
        color: $selected_fg_color;
      }
      &:checked { background-color: mix($selected_fg_color, $b_color, 20%); }
      &:disabled {
        @include button(insensitive, $b_color,
                                     $insensitive_selected_fg_color);
      }
      &.flat {
        background-color: transparent;
        color: $b_color;
        &:hover { @include button(flat-hover, $track_color, $b_color); }
        &:active {
          @extend %button_flat_active;
          background-color: $track_color;
          color: $selected_bg_color;
        }
        &:checked {
          @include button(flat-checked, $b_color, $selected_fg_color);
        }
        &:disabled {
          @include button(flat-insensitive, $b_color,
                                            $insensitive_selected_fg_color);
        }
      }
    }
  }

  &.image-button {
    @extend %image_button;
    min-width: $icon_size;
    min-height: $icon_size;
  }

  &.text-button {
    padding: rem(9.3px) rem(13.3px) rem(10.7px);
    border-radius: 2px;
    -gtk-outline-radius: 2px;
    font-weight: 700;
  }

  &.lock {
    padding-top: rem(9.3px);
    padding-bottom: rem(10.7px);
  }

  &.text-button.image-button {
    // those buttons needs uneven horizontal padding, we want the icon side
    // to have the image-button padding, while the text side the text-button
    // one, so we're adding the missing padding to the label depending on
    // its position inside the button
    padding: rem(9.3px) rem(13.3px) rem(10.7px);
    border-radius: 2px;
    -gtk-outline-radius: 2px;

    label {
      padding-left: rem(4px);
      padding-right: rem(4px);
    }

    image {
      padding-left: rem(4px);
      padding-right: rem(4px);
    }
  }

  %button_drop_target,
  &:drop(active) {
    color: $drop_target_color;
    background-color: $drop_target_fill_color;
  }

  &.circular {
    &,
    &-button.image-button,
    &.radio.text-button {
      min-height: $icon_size * 1.5;
      min-width: $icon_size * 1.5;
      padding: if($ref_weight < 1.0,
               rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
               rem(($widget_size - $icon_size * 1.5) / 2));
      border-radius: 9999px;
      -gtk-outline-radius: 9999px;

      label { padding: 0; }
    }
  }

  separator { // remove vertical separator
    @extend separator.wide;
    min-height: 0;
    min-width: 0;
    border-color: transparent;
    background-color: transparent;
    color: transparent;
  }

  stackswitcher & { // do not shrink buton width
    &.text-button {
      min-height: rem(17.3px);
      min-width: rem(112px);
    }
  }

  .stack-switcher > & {
    // to position the needs attention dot, padding is added to the button
    // child, a label needs just lateral padding while an icon needs vertical
    // padding added too.

    outline-offset: rem(-2.6px); // needs to be set or it gets overriden
                                 // by GtkRadioButton outline-offset

    > label {
      padding-left: rem(8px);  // label padding
      padding-right: rem(8px); //
    }

    > image {
      padding-left: rem(8px);     // image padding
      padding-right: rem(8px);    //
      padding-top: rem(2.7px);    //
      padding-bottom: rem(2.7px); //
    }

    &.text-button {
      // compensate text-button paddings
      padding-left: rem(13.3px);
      padding-right: rem(13.3px);
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }

    &.image-button {
      // we want image buttons to have a 1:1 aspect ratio, so compensation
      // of the padding added to the image is needed
      padding-left: rem(8px);
      padding-right: rem(8px);
    }

    &.needs-attention {
      > label,
      > image { @extend %needs_attention; }

      &:active,
      &:checked {
        > label,
        > image {
          animation: none;
          background-image: none;
        }
      }
    }
  }

  // mimic tab-switcher-like button array
  // horizontal array
  .linked > & {
    @extend %button_array;
    min-width: rem(13.3px);
    padding: rem(9.3px) rem(5.3px) rem(10.7px);
    border-radius: 0;

    label {
      padding-left: rem(4px);
      padding-right: rem(4px);
    }

    image {
      padding-left: rem(4px);
      padding-right: rem(4px);
    }
  }

  // vertical array
  .linked.vertical > & {
    @extend %button_vertical_array;
    min-height: rem(13.3px);
    min-width: rem(22.6px);
    padding: rem(10px) rem(6.7px) rem(10px);
    border-radius: 0;
  }

  // generic switcher image buttons
  .linked > &.image-button,
  .linked.vertical > &.image-button {
    &, &.radio {
      min-width: $icon_size;
      min-height: $icon_size;
      padding: rem(10.7px);
      border-radius: 0;
      -gtk-outline-radius: 0;

      image { padding: 0; }
    }
  }

  // inline-toolbar and action-bar buttons
  .inline-toolbar &,
  actionbar & {
    &,
    &.image-button,
    &.text-button {
      @include button(flat-normal);
      &:hover { @include button(flat-hover); }
      &:active { @include button(flat-active); }
      &:disabled { @include button(flat-insensitive); }
      &:checked { @include button(flat-checked); }
      &:checked:disabled { @include button(flat-checked-insensitive); }
    }

    &,
    &:not(.text-button).image-button,
    &.circular {
      min-width: $icon_size;
      min-height: $icon_size;
      padding: rem(6.7px);
      border-radius: 100px;
      -gtk-outline-radius: 100px;
    }

    &.text-button,
    &.color {
      min-width: $icon_size;
      min-height: $icon_size;
      padding: rem(5.3px) rem(8px);
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }

    &.image-button.toggle {
      // hide unneeded background
      &:checked { background-color: transparent; }
    }

    @each $_type, $_color in (suggested, $suggested_color),
                             (destructive, $destructive_color) {
      &.#{$_type}-action {
        &,
        &.image-button,
        &.text-button {
          @extend %button_normal;
          background-color: #{$_color};
          color: $secondary_selected_fg_color;
          box-shadow: $z-depth-1;
          &:hover {
            @extend %button_hover;
            color: $selected_fg_color;
            box-shadow: $z-depth-2;
          }
          &:active {
            @extend %button_active;
            color: $selected_fg_color;
            background-color: $selected_bg_color;
            box-shadow: $z-depth-2;
          }
          &:checked {
            @extend %button_checked;
            background-color: #{$_color};
            color: $inverted_fg_color;
            box-shadow: $z-depth-1;
          }
          &:disabled { @include button(insensitive); }
        }
      }
    }
  }

  .inline-toolbar .linked > &,
  actionbar .linked > & {
    &,
    &:not(.text-button).image-button,
    &.circular {
      min-width: $icon_size;
      min-height: $icon_size;
      padding: rem(6.7px);
      border-radius: 100px;
      -gtk-outline-radius: 100px;

      image { padding: 0; } // reset padding
    }

    &.image-button.toggle {
      min-width: $icon_size;
      min-height: $icon_size;
      padding: rem(6.7px);
      border-radius: 100px;
      -gtk-outline-radius: 100px;

      image { padding: 0; }
    }

    &.text-button {
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }
  }

  // tango icons don't need shadows
  .primary-toolbar & { -gtk-icon-shadow: none; }
}

%button_array {
  @extend %button_flat_normal;
  border-radius: 0;
  -gtk-outline-radius: 0;
  color: $secondary_fg_color;
  background-color: transparent;
  border-image: -gtk-gradient(radial,
                              center bottom, 0,
                              center bottom, 0.5,
                              to($outline_track_color),
                              to(transparent))
                              0 0 1 / 0 0 1px;
  &:hover {
    @extend %button_flat_hover;
    border-radius: 0;
    color: $fg_color;
    background-color: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($outline_track_color),
                                to(transparent))
                                0 0 2 / 0 0 2px;
  }
  &:active {
    @extend %button_flat_active;
    color: $fg_color;
    background-color: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($selected_bg_color),
                                to(transparent))
                                0 0 2 / 0 0 2px;
  }
  &:checked {
    @extend %button_flat_checked;
    color: $fg_color;
    background-color: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($selected_bg_color),
                                to(transparent))
                                0 0 2 / 0 0 2px;
    &:disabled {
      color: $insensitive_fg_color;
      background-color: transparent;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to(gtkopacity($selected_bg_color, 0.2)),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;

      > label { color: inherit; }
    }
  }
  &:disabled {
    color: $insensitive_fg_color;
    background-color: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($outline_track_color),
                                to(transparent))
                                0 0 1 / 0 0 1px;
  }
}

%button_vertical_array {
  @extend %button_flat_normal;
  border-image: none;
  border-width: 0;
  -gtk-outline-radius: 0;
  background-color: transparent;
  color: $secondary_fg_color;
  &:dir(ltr) { box-shadow: inset 1px 0 $outline_track_color; }
  &:dir(rtl) { box-shadow: inset -1px 0 $outline_track_color; }
  &:hover {
    @extend %button_flat_hover;
    color: $fg_color;
    &:dir(ltr) { box-shadow: inset 2px 0 $outline_track_color; }
    &:dir(rtl) { box-shadow: inset -2px 0 $outline_track_color; }
  }
  &:active {
    @extend %button_flat_active;
    color: $fg_color;
    background-color: transparent;
    &:dir(ltr) { box-shadow: inset 2px 0 $selected_bg_color; }
    &:dir(rtl) { box-shadow: inset -2px 0 $selected_bg_color; }
  }
  &:checked {
    @extend %button_flat_checked;
    color: $fg_color;
    background-color: transparent;
    &:dir(ltr) { box-shadow: inset 2px 0 $selected_bg_color; }
    &:dir(rtl) { box-shadow: inset -2px 0 $selected_bg_color; }
    &:disabled {
      color: $insensitive_fg_color;
      background-color: transparent;
      &:dir(ltr) {
        box-shadow: inset 2px 0 gtkopacity($selected_bg_color, 0.2);
      }
      &:dir(rtl) {
        box-shadow: inset -2px 0 gtkopacity($selected_bg_color, 0.2);
      }

      > label { color: inherit; }
    }
  }
  &:disabled {
    color: $insensitive_fg_color;
    background-color: transparent;
    &:dir(ltr) { box-shadow: inset 1px 0 $outline_track_color; }
    &:dir(rtl) { box-shadow: inset -1px 0 $outline_track_color; }
  }
}

%image_button {
  padding: rem(($widget_size - $icon_size) / 2);
  border-radius: 100px;
  -gtk-outline-radius: 100px;
}

%needs_attention {
  background-repeat: no-repeat;
  background-position: right top;
  background-size: $attention;
  background-image: -gtk-scaled(url("assets/needs-attention.png"),
                                url("assets/needs-attention@2.png"));
  animation: needs_attention 0.3s $slope_slow forwards;
  &:dir(rtl) { background-position: left top; }
}

// menu buttons on GtkPopover
modelbutton.flat,
menuitem button.flat {
  @extend %button_flat_normal;
  min-height: rem(26.6px);
  padding: rem(5.3px) rem(8px) rem(6.7px);
  outline-offset: rem(-1px);
  background-color: transparent;
  color: $secondary_fg_color;
  transition: none;
  &:hover {
    @extend %button_flat_hover;
    background-color: transparent;
    color: $fg_color;
  }
  &:active {
    @extend %button_flat_active;
    background-color: transparent;
    color: $fg_color;
  }
  &:checked {
    @extend %button_flat_checked;
    background-color: transparent;
    color: $fg_color;
  }
  &:checked:disabled {
    @extend %button_flat_checked_disabled;
    background-color: transparent;
    color: $insensitive_fg_color;
  }
  &:disabled {
    @include button(flat-insensitive);
    background-color: transparent;
    color: $insensitive_secondary_fg_color;
  }

  check,
  radio {
    &:first-child { margin-right: rem(13.3px); }
    &:last-child { margin-left: rem(13.3px); }
  }
}

modelbutton.flat arrow {
  background: none;
  &:hover { background: none; }
  &.left { -gtk-icon-source: -gtk-icontheme("pan-start-symbolic"); }
  &.right { -gtk-icon-source: -gtk-icontheme("pan-end-symbolic"); }
}

button.color {
  min-width: rem(33.3px);
  min-height: rem(20px);
  // Uniform padding on the GtkColorButton
  padding: rem(6.7px) rem(8px) rem(6.7px);

  > colorswatch:first-child:last-child { // :first-child:last-child for
                                         // a specificity bump, it gets
                                         // overridden by the colorpicker style
    &, overlay {
      border-radius: 0;
      -gtk-outline-radius: 0;
    }

    box-shadow: $z-depth-1;
  }

  &,
  colorswatch {
    &:disabled {
      box-shadow: none;
      opacity: 0.4;
    }
  }
}

// toolpalette buttons
toolpalette {
  toolitemgroup {
    > button {
      border-top: 1px solid $borders_color;
      border-radius: 0;
    }

    arrow {
      min-width: $icon_size - 4px;
      min-height: $icon_size - 4px;
    }
  }

  toolbutton {
    > button.toggle { // use square buttons
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }
  }
}

// button box is always shown with flat-buttons
buttonbox {
  &, &.dialog-action-area {
    &:not(.linked) button { @extend %action-area-button; }
  }

  dialog.background & {
    &.dialog-action-area.linked button {
      @extend %action-area-button;
      border: 0 none transparent;
    }
  }
}

%action-area-button {
  @extend %button_flat_normal;
  background-color: transparent;
  color: $secondary_accent_label_color;
  font-weight: 700;
  &:hover {
    @extend %button_flat_hover;
    background-color: transparent;
    color: $accent_label_color;
  }
  &:active {
    @extend %button_flat_active;
    background-color: transparent;
    color: $accent_label_color;
  }
  &:disabled {
    @extend %button_flat_disabled;
    background-color: transparent;
    color: $insensitive_fg_color;
  }
  &:checked {
    @extend %button_flat_checked;
    background-color: transparent;
    color: $accent_label_color;
    &:disabled {
      @extend %button_flat_checked_disabled;
      background-color: transparent;
      color: gtkopacity($accent_label_color, 0.4);
    }
  }
}


// /*********
//  * Links *
//  *********/

%link,
*:link {
  @at-root %normal_link,
  & {
    color: $link_label_color;
    &:hover,
    &:active { color: $link_label_color; }

    *:selected & { color: $secondary_selected_fg_color; }
  }

  @at-root %visited_link,
  &:visited {
    color: $link_visited_label_color;
    &:hover,
    &:active { color: $link_visited_label_color; }

    *:selected & { color: $tertiary_selected_fg_color; }
  }

  @at-root %selected_link,
  &:selected {  color: $secondary_selected_fg_color; }

  &:disabled { opacity: 0.4; }
}

link {
  &:link { @extend %normal_link; }
  &:visited { @extend %visited_link; }
}

button.flat.link { // specificity bump with .flat class
  @extend %link;

  > label {
    color: inherit;
    text-decoration-line: underline;
  }
}


// /*****************
//  * GtkSpinButton *
//  *****************/

@keyframes spin_hover {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.01,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($track_color),
                                    to(transparent));
  }
}

@keyframes spin_active {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0.25)),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.01,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent));
  }
}

spinbutton {
  &:not(.vertical),
  &.vertical {
    &,
    grid &,
    row.activatable & { padding: 0; }  // specificity bump
  }

  &:not(.vertical) {
    // in this horizontal configuration, the whole spinbutton
    // behaves as the entry, so we extend the entry styling
    // and nuke the style on the internal entry
    @extend %entry_fallback;
    @extend %entry_native;

    // FIXME: this should not be set at all, but otherwise it gets the wrong
    // color
    &:disabled { color: $insensitive_fg_color; }

    entry {
      &, // unset all of fallback mode
      &:focus,
      &:disabled {
        margin: 0;
        background: none;
        border: none;
        border-image: none;
        box-shadow: none;
      }

      padding-top: rem(9.3px - 2.7px);
      padding-bottom: rem(10.7px - 2.7px);

      > progress { margin: rem(-9.3px + 2.7px) 0 rem(-10.7px + 2.7px); }
    }

    button {
      @extend %button_flat_normal;
      min-width: rem($icon_size);
      min-height: rem($icon_size);
      padding: rem(($widget_size - 4px - 13.3px) / 2);
      border-radius: 100px;
      -gtk-outline-radius: 100px;
      background: none;
      background-size: contain;
      background-color: transparent;
      color: $secondary_fg_color;
      transition-property: opacity,
                           color,
                           background-color,
                           background-image,
                           box-shadow;

      &.down { // '-' button
        &:hover {
          @extend %button_flat_hover;
          background: none;
          color: $error_color;
          animation: spin_hover 0.2s $slope_medium forwards;
        }
        &:active {
          @extend %button_flat_active;
          background: none;
          color: $error_color;
          animation: spin_active 0.2s $slope_quick forwards;
          transition-duration: 0.2s;
        }
        &:disabled {
          @extend %button_flat_disabled;
          background: none;
          color: $insensitive_fg_color;
        }
      }

      &.up { // '+' button
        &:hover {
          @extend %button_flat_hover;
          background: none;
          color: $success_color;
          animation: spin_hover 0.2s $slope_medium forwards;
        }
        &:active {
          @extend %button_flat_active;
          background: none;
          color: $success_color;
          animation: spin_active 0.2s $slope_quick forwards;
          transition-duration: 0.2s;
        }
        &:disabled {
          @extend %button_flat_disabled;
          background: none;
          color: $insensitive_fg_color;
        }
      }
    }
  }

  .osd & {
    &:not(.vertical),
    &.vertical { // specificity bump
      // set default foregrounds in top node
      &, &:focus {
        color: $inverted_fg_color;
        caret-color: $inverted_fg_color;
      }

      entry {
        &, &:focus {
          color: $inverted_fg_color;
          caret-color: $inverted_fg_color;
        }
        &:disabled { color: $insensitive_inverted_fg_color; }
      }

      button {
        color: $inverted_secondary_fg_color;
        &:disabled { color: $insensitive_inverted_fg_color; }

        &.down {
          &:hover,
          &:active { color: $error_color; }
        }

        &.up {
          &:hover,
          &:active { color: $success_color; }
        }
      }
    }
  }

  &.vertical { // FIXME: try using linking templates for
               // vertically linked stuff

    // FIXME: this should not be set at all, but otherwise it gets the wrong
    // color
    &:disabled { color: $insensitive_fg_color; }

    entry {
      min-width: rem(33.3px);
      min-height: rem(33.3px);
      padding: 0;
      border-radius: 0;
    }

    button {
      min-width: rem($widget_size - 9.3px, $sw: 1.0);
      min-height: rem($widget_size - 9.3px, $sw: 1.0);
      margin: rem(2.7px, $sw: 1.0);
      padding: 0;
      border-radius: 2px;
      -gtk-outline-radius: 2px;
      background: none;
      background-size: contain;
      color: $secondary_fg_color;
      box-shadow: none;
      transition-property: opacity,
                           color,
                           background-color,
                           background-image,
                           box-shadow;

      &.up { // '+' button
        &:hover {
          @extend %button_flat_hover;
          background-color: $track_color;
          color: $success_color;
        }
        &:active {
          @extend %button_flat_active;
          background-color: $track_color;
          color: $success_color;
        }
        &:disabled {
          @extend %button_flat_disabled;
          background: none;
          color: $insensitive_fg_color;
        }
      }

      &.down { // '-' button
        &:hover {
          @extend %button_flat_hover;
          background-color: $track_color;
          color: $error_color;
        }
        &:active {
          @extend %button_flat_active;
          background-color: $track_color;
          color: $error_color;
        }
        &:disabled {
          @extend %button_flat_disabled;
          background: none;
          color: $insensitive_fg_color;
        }
      }
    }
  }

  // Misc
  treeview & {
    entry:focus {
      padding: 1px;
      border-radius: 0;
      border-width: 0;
      background-color: $base_color;
      color: $fg_color;
      box-shadow: none;
      &:selected { @extend %selected_items; }
    }
  }
}


// /**************
//  * ComboBoxes *
//  **************/

combobox {
  arrow {
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    min-height: rem($icon_size);
    min-width: rem($icon_size);
  }

  &:drop(active) {
    button.combo { @extend %button_drop_target; }
  }

  > window.popup { // context-menu popup
    decoration { transition: none; } // do not set transitions

    > menu {
      padding: rem(3.3px) 0;
      transition: none; // do not set transitions

      menuitem { padding: rem(4.7px) rem(5.3px) rem(6px); }
    }
  }

  // fallback combo node for non-native apps
  @extend %entry_fallback_normal;
  border-radius: 2px;

  .background & { // unset all properties in combobox node
    border: unset;
    border-image: unset;
    border-radius: unset;
    background-color: unset;
    color: unset;
    box-shadow: unset;
  }

  // fallback combo-entries for non-native apps
  entry.combo {
    @extend %entry_fallback_normal;
    border-radius: 2px;
    &:focus { @extend %entry_fallback_focus; }
    &:disabled { @extend %entry_fallback_insensitive; }
  }

  // standard combo-entries for native Gtk+ apps
  .background & entry.combo {
    @include entry(normal);
    border-radius: 0;
    background-color: transparent;
    &:focus {
      @include entry(focus);
      background-color: transparent;
    }
    &:disabled {
      @include entry(insensitive);
      background-color: transparent;
    }

    selection {
      &, &:focus { @extend %selected_items; }
    }
  }

  button.combo { // button spacing
    min-height: rem(13.3px);
    min-width: rem(17.3px);
    padding: rem(8px) rem(5.3px) rem(8.7px);

    arrow { padding: 0 rem(4px) 0; }

    label {
      padding-left: rem(4px);
      padding-right: rem(4px);
    }

    image {
      min-height: rem($icon_size);
      min-width: rem($icon_size);
      padding-left: rem(4px);
      padding-right: rem(4px);
    }

    grid & { // set limit
      padding-top: rem(8px - 2.7px);
      padding-bottom: rem(8.7px - 2.7px);
    }
  }

  // fallback combo-buttons for non-native apps
  button.combo {
    @extend %button_fallback_normal;
    border-radius: 2px;
    &:hover { @extend %button_fallback_hover; }
    &:active,
    &:checked { @extend %button_fallback_active; }
    &:disabled { @extend %button_fallback_insensitive; }
    &:checked:disabled {
      @extend %button_fallback_checked_insensitive;
    }
  }

  // standard combo-buttons for native Gtk+ apps
  .background & button.combo {
    @extend %button_flat_normal;
    border-radius: 0;
    border: none; // unset borders
    color: $secondary_fg_color;
    background: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($outline_track_color),
                                to(transparent))
                                0 0 1 / 0 0 1px;
    &:hover,
    &:active,
    &:checked {
      @extend %button_flat_hover;
      border-radius: 0;
      color: $fg_color;
      background: transparent;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($selected_bg_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
    }
    &:disabled,
    &:checked:disabled {
      @extend %button_flat_disabled;
      color: $insensitive_fg_color;
      background: transparent;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($outline_track_color),
                                  to(transparent))
                                  0 0 1 / 0 0 1px;
    }
    &:checked { transition: none; } // do not set transitions
  }
}

// workaround for LibreOffice with fallback-mode liked-buttons
@each $order, $radius, $edge in (first-child, 2px 0 0 2px, right),
                                (last-child, 0 2px 2px 0, left) {
  .linked:not(combobox) > button.combo:#{$order} {
    border-radius: #{$radius};
    border-#{$edge}-width: 0;

    &:only-child {
      border-radius: 2px;
      border-width: 1px;
    }
  }
}


// /************
//  * Toolbars *
//  ************/

%toolitem_size {
  min-width: rem(30px / 2, $sw: 1.0);
  min-height: rem(30px, $sw: 1.0);
  padding: 0 rem(30px / 4, $sw: 1.0);
}

toolbar {
  -GtkWidget-window-dragging: true;

  padding: rem(5.3px);
  background-color: $bg_color;
  color: $secondary_fg_color;

  window > &,
  window box &,
  window grid & { // special case to draw fake-shadows
    box-shadow: if($variant == light, $toolbar-shadow-light,
                                      $toolbar-shadow-dark);
  }

  &.vertical,
  .inline-toolbar &,
  paned &,
  paned &.primary-toolbar,
  grid &.primary-toolbar,
  notebook > stack box & { // stop drawing fake-shadows
    box-shadow: none;
  }

  // on OSD
  .osd & { background-color: transparent; }

  @at-root %osd_toolbar,
  .osd &,
  &.osd {
    padding: 3px;
    border-style: solid;
    border-width: 11px;
    @if $variant == light {
      border-image: -gtk-scaled(url("assets/osd-shadow.png"),
                                url("assets/osd-shadow@2.png"))
                    11 / 11px stretch;
    }
    @else {
      border-image: -gtk-scaled(url("assets/osd-shadow-dark.png"),
                                url("assets/osd-shadow-dark@2.png"))
                    11 / 11px stretch;
    }
    box-shadow: none;
    color: $inverted_fg_color;
    background-color: $inverted_dark_color;

    button {
      @extend %button_flat_normal;
      background-color: transparent;
      &:not(:active):not(:disabled):not(hover) {
        background-color: transparent;
        color: $inverted_secondary_accent_label_color;
      }
      &:hover {
        @extend %button_flat_hover;
        background-color: transparent;
        color: $inverted_accent_label_color;
      }
      &:active {
        @extend %button_flat_active;
        border-image: none;
        background-color: transparent;
        color: $inverted_accent_label_color;
        box-shadow: none;
      }
      &:checked {
        @extend %button_flat_checked;
        border-image: none;
        background-color: transparent;
        color: $inverted_accent_label_color;
        box-shadow: none;
      }
      &:disabled {
        @extend %button_flat_disabled;
        background-color: transparent;
        color: gtkopacity($inverted_fg_color, 0.4);
      }

      &.image-button {
        min-width: rem($widget_size, $sw: 1.0);
        min-height: rem($widget_size, $sw: 1.0);
        padding: 0;
        border-radius: 100px;
        -gtk-outline-radius: 100px;
      }

      &.text-button {
        border-radius: 2px;
        -gtk-outline-radius: 2px;
      }

      label { margin: rem(-2px, $sw: 1.0) 0; }
    }

    .linked > button {
      &, &.image-button {
        border-image: none;
        box-shadow: none;
        &:hover { background-color: transparent; }
        &:not(:checked) {
          border-radius: 100px;
          -gtk-outline-radius: 100px;
        }
      }

      &.image-button {
        min-width: rem($widget_size, $sw: 1.0);
        min-height: rem($widget_size, $sw: 1.0);
        padding: 0;
        border-radius: 100px;
        -gtk-outline-radius: 100px;
      }
    }

    label { padding: 0 1em; }
  }

  .background & button { // use flat-buttons
    @extend %button_flat_normal;
    background-color: transparent;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($outline_track_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    color: $secondary_fg_color;
    &:hover {
      @extend %button_flat_hover;
      border-image: none;
      background-color: transparent;
      color: $fg_color;
    }
    &:active {
      @extend %button_flat_active;
      border-image: none;
      background-color: transparent;
      color: $fg_color;
    }
    &:checked {
      @extend %button_flat_checked;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($selected_bg_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $fg_color;
      &:disabled {
        @extend %button_flat_checked_disabled;
        border-image: none;
        background-color: transparent;
        color: $insensitive_fg_color;
      }
    }
    &:disabled {
      @extend %button_flat_disabled;
      border-image: none;
      background-color: transparent;
      color: $insensitive_secondary_fg_color;
    }

    &.toggle,
    &.popup.toggle { // remove double-background
      &,
      &:hover,
      &:active,
      &:checked {
        background-color: transparent;
        box-shadow: none;
      }
    }
  }

  .linked > button:not(.combo):not(.text-button) {
    // remove double-background and underlines
    &, &.image-button {
      border-image: none;
      box-shadow: none;
      &:hover {
        @extend %button_flat_hover;
        border-image: none;
        background-color: transparent;
        box-shadow: none;
      }
      &:active {
        @extend %button_flat_active;
        border-image: none;
        background-color: transparent;
        box-shadow: none;
      }

      &.raised.toggle,
      &.toggle { // revive underlines
        &:checked {
          border-image: -gtk-gradient(radial,
                                      center bottom, 0,
                                      center bottom, 0.5,
                                      to($selected_bg_color),
                                      to(transparent))
                                      0 0 2 / 0 0 2px;
        }
      }
    }
  }

  .linked > button.text-button:not(.image-button) { // revive underlines
    @extend %button_array;
  }

  // sizing
  .background & button,
  .background & .linked > button {
    &,
    &.text-button,
    &.image-button {
      @extend %toolitem_size;
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }
  }

  combobox {
    button.combo,
    .linked > button.combo { @extend %toolitem_size; }
  }

  .background & entry {
    &, &.combo {
      @extend %toolitem_size;

      progress { margin: 0; } // unset default margins
    }
  }

  // toolbar separators
  separator {
    color: transparent;
    background: none;
  }

  &.horizontal {
    separator { margin: 0 rem(6px); }
  }

  &.vertical {
    separator { margin: rem(6px) 0; }
  }
}

// searchbar, location-bar, inline-toolbar & actionbar
.inline-toolbar {
  padding: rem(5.3px);
  border-style: solid;
  border-width: 0 1px 1px;
  border-color: $borders_color;
  background-color: $secondary_dark_color;
  box-shadow: if($variant == light, $inline-shadow-light,
                                    $inline-shadow-dark);
}

searchbar,
.location-bar {
  padding: rem(5.3px);
  border-style: solid;
  border-width: 0 0 1px;
  border-color: $borders_color;
  background-color: $secondary_dark_color;

  .linked > button.image-button {
    min-width: $icon_size;
    min-height: $icon_size;
    padding: rem(10.7px);
    -gtk-outline-radius: 2px;
  }

  button.close {
    min-width: $icon_size;
    min-height: $icon_size;
    margin: 1px 0; // concern other linked widgets
    padding: rem(10.7px);
    border-radius: 100px;
    -gtk-outline-radius: 100px;
  }
}

actionbar {
  background-color: $secondary_dark_color;
  box-shadow: if($variant == light, $inline-shadow-light,
                                    $inline-shadow-dark);

  // actual padding
  > revealer > box { padding: rem(5.3px); }

  box:not(.linked) > button.toggle,
  .linked > button.image-button {
    @extend %button_flat_normal;
    border-radius: 100px;
    -gtk-outline-radius: 100px;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($outline_track_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    background-color: transparent;
    color: $secondary_fg_color;
    &:hover {
      @extend %button_flat_hover;
      border-image: none;
      background-color: transparent;
      color: $fg_color;
    }
    &:checked {
      @extend %button_flat_checked;
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($selected_bg_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $fg_color;
      &:disabled {
        @extend %button_flat_checked_disabled;
        border-image: none;
        background-color: transparent;
        color: $insensitive_fg_color;
      }
    }
    &:disabled {
      @extend %button_flat_disabled;
      border-image: none;
      background-color: transparent;
      color: $insensitive_secondary_fg_color;
    }

    &.text-button { // revert to square
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }
  }

  // override circular outlines
  .linked > button.popup.toggle { -gtk-outline-radius: 2px; }
}


// /***************
//  * Header bars *
//  ***************/

.titlebar,
headerbar {
  background-color: $inverted_dark_color;
  background-clip: border-box;

  // hide all outlines
  * {
    outline-style: none;
    outline-width: 0;
    outline-color: transparent;
  }

  // text colours
  color: $inverted_secondary_fg_color;

  label,
  image {
    &:checked {
      &:disabled { color: $insensitive_inverted_fg_color; }
    }

    button:disabled > &,
    .linked > button:disabled > &,
    &:disabled { color: $insensitive_inverted_secondary_fg_color; }
  }

  // titles
  .title {
    padding: 0 rem(13.3px);
    color: $inverted_fg_color;
    font-weight: 700;
  }

  .subtitle {
    @extend %dim_label;
    padding: 0 rem(13.3px);
    color: $inverted_secondary_fg_color;
    font-size: if($ref_weight < 1.0, 80%, 90%);
  }

  // separators
  separator.vertical,
  > box > separator.vertical,
  > box > box > separator.vertical {
    border: 0 none transparent;
    color: transparent;
    background-color: transparent;
  }

  // button styling
  button:not(.suggested-action):not(.destructive-action) {
    @include button(flat-normal);
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($selected_bg_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    color: $inverted_secondary_fg_color;
    &:hover {
      @include button(flat-hover);
      color: $inverted_fg_color;
    }
    &:active { @include button(flat-active); }
    &:checked {
      @include button(flat-checked);
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($selected_bg_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $inverted_fg_color;
      &:disabled {
        @include button(flat-checked-insensitive);
        background-color: transparent;
        color: $insensitive_inverted_fg_color;

        > label { color: inherit; }
      }
    }
    &:disabled {
      @include button(flat-insensitive);
      color: $insensitive_inverted_fg_color;

      > label { color: inherit; }
    }
  }

  // force to draw circle flat buttons as default
  button:not(.suggested-action):not(.destructive-action) {
    border-radius: 100px;
    -gtk-outline-radius: 100px;

    &.text-button {
      border-radius: 2px;
      -gtk-outline-radius: 2px;

      &.image-button {
        border-radius: 2px;
        -gtk-outline-radius: 2px;
      }
    }

    &.lock {
      border-radius: 2px;
      -gtk-outline-radius: 2px;
      font-weight: 700;
    }
  }

  // adjust spacing for finer aspect-ratio
  button.text-button {
    &,
    &.toggle {
      min-height: $icon_size;
      padding-top: rem(($widget_size - $icon_size - 4px) / 2);
      padding-bottom: rem(($widget_size - $icon_size - 1.3px) / 2);

      // prepare for tall and dense fonts
      label { margin: rem(-2px) 0; }

      dialog.background & { // modal-dialogs
        min-height: $icon_size * 1.5;
        padding-top: if($ref_weight < 1.0,
                     rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                     rem(($widget_size - $icon_size * 1.5) / 2));
        padding-bottom: if($ref_weight < 1.0,
                        rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                        rem(($widget_size - $icon_size * 1.5) / 2));
      }
    }

    &.suggested-action:not(.image-button),
    &.destructive-action:not(.image-button) {
      min-height: $icon_size * 1.5;
      padding-top: if($ref_weight < 1.0,
                   rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                   rem(($widget_size - $icon_size * 1.5) / 2));
      padding-bottom: if($ref_weight < 1.0,
                      rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                      rem(($widget_size - $icon_size * 1.5) / 2));
    }

    &.lock {
      min-height: $icon_size;
      padding-top: rem(($widget_size - $icon_size - 2.7px) / 2);
      padding-bottom: rem(($widget_size - $icon_size - 2.7px) / 2);

      label { margin: rem(-2px) 0; }
    }
  }

  button.text-button.image-button {
    min-height: $icon_size;
    padding-top: rem(($widget_size - $icon_size - 2.7px) / 2);
    padding-bottom: rem(($widget_size - $icon_size - 2.7px) / 2);

    label { margin: rem(-2px) 0; }
  }

  button:not(.image-button):not(.text-button):not(.title-button):not(.titlebutton):not(.slider-button),
  button.image-button:not(.text-button),
  button.title-button:not(.text-button) {
    min-width: $icon_size * 1.5;
    min-height: $icon_size * 1.5;
    padding: if($ref_weight < 1.0,
             rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
             rem(($widget_size - $icon_size * 1.5) / 2));
  }

  .linked > button {
    &.image-button:not(.text-button) {
      min-width: $icon_size * 1.5;
      min-height: $icon_size * 1.5;
      padding: if($ref_weight < 1.0,
               rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
               rem(($widget_size - $icon_size * 1.5) / 2));
    }
  }

  button.toggle:not(.text-button),
  button.toggle.title-button {
    min-width: $icon_size * 1.5;
    min-height: $icon_size * 1.5;
    padding: if($ref_weight < 1.0,
             rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
             rem(($widget_size - $icon_size * 1.5) / 2));
  }

  stackswitcher button:not(.image-button),
  .stack-switcher > button:not(.image-button) {
    min-height: $icon_size;
    padding-top: rem(($widget_size - $icon_size - 5.3px) / 2);
    padding-bottom: rem(($widget_size - $icon_size - 2.7px) / 2);

    label { margin: rem(-2px) 0; }

    > radio { // FIXME: for gnome-clocks
      margin: unset;
      padding: unset;
    }
  }

  button,
  .linked > button {
    &, label.text-button {
      color: $inverted_secondary_fg_color;
      &:hover { color: $inverted_fg_color; }
      &:checked {
        color: $inverted_fg_color;
        &:disabled { color: $insensitive_inverted_fg_color; }
      }
      &:disabled { color: $insensitive_inverted_secondary_fg_color; }
    }

    label.text-button { // workaround for Gnome-Software
      padding: 0;
      border-image: none;
      box-shadow: none;

      &:dir(ltr) { padding-right: rem(4px); }
      &:dir(rtl) { padding-left: rem(4px); }
    }

    &.suggested-action,
    &.destructive-action { // high-contrast foregrounds
      &, &.default {
        color: $secondary_selected_fg_color;
        &:hover,
        &:active,
        &:checked { color: $selected_fg_color; }
        &:disabled { color: $insensitive_selected_fg_color; }
      }
    }
  }

  // entry styling
  entry,
  .linked > entry,
  .linked.raised > entry {
    min-height: $icon_size;
    padding-top: rem(($widget_size - $icon_size - 5px) / 2);
    padding-bottom: rem(($widget_size - $icon_size - 2.3px) / 2);
  }

  .background & { // bump with .background class to override
    entry,
    .linked > entry,
    combobox > entry.combo {
      color: $inverted_secondary_fg_color;
      caret-color: $inverted_secondary_fg_color;
      &:focus {
        color: $inverted_fg_color;
        caret-color: $inverted_fg_color;
      }
      &:disabled { color: $insensitive_inverted_secondary_fg_color; }
    }
  }

  // combobox styling
  combobox,
  .linked > combobox {
    > entry.combo {
      min-height: $icon_size;
      padding-top: rem(($widget_size - $icon_size - 5px) / 2);
      padding-bottom: rem(($widget_size - $icon_size - 2.3px) / 2);
    }

    > button.combo {
      min-height: $icon_size;
      padding-top: rem(($widget_size - $icon_size - 5px) / 2);
      padding-bottom: rem(($widget_size - $icon_size - 2.3px) / 2);
      color: $inverted_secondary_fg_color;
      &:hover { color: $inverted_fg_color; }
      &:checked {
        color: $inverted_fg_color;
        &:disabled { color: $insensitive_inverted_fg_color; }
      }
      &:disabled { color: $insensitive_inverted_secondary_fg_color; }
    }
  }

  // menu styling
  menu menuitem { // reset text colour
    color: $secondary_fg_color;
    &:hover { color: $fg_color; }

    label {
      &:disabled { color: $insensitive_fg_color; }
    }

    accelerator { color: gtkalpha(currentColor, 0.54); }

    separator { color: $borders_color; }
  }

  // pop-over styling
  popover button.flat {
    color: $secondary_fg_color;
    &:hover { color: $fg_color; }

    label {
      &:hover { color: $fg_color; }
      &:disabled { color: $insensitive_fg_color; }
    }
  }

  // check and radio styling
  radio,
  check {
    min-width: rem($icon_size, $sw: 1.0);
    min-height: rem($icon_size, $sw: 1.0);
    margin: rem(-6.7px, $sw: 1.0) rem(-3.3px, $sw: 1.0);
    padding: rem(6.7px, $sw: 1.0);
  }

  checkbutton.text-button,
  radiobutton.text-button {
    min-height: $icon_size * 1.5;
    padding-top: if($ref_weight < 1.0,
                 rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                 rem(($widget_size - $icon_size * 1.5) / 2));
    padding-bottom: if($ref_weight < 1.0,
                    rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
                    rem(($widget_size - $icon_size * 1.5) / 2));
    color: $inverted_secondary_fg_color;
    &:hover,
    &:active,
    &:checked { color: $inverted_fg_color; }
    &:disabled,
    &:disabled:active,
    &:disabled:indeterminate {
      color: $insensitive_inverted_fg_color;
    }
  }

  // switch styling
  // use pixmap based switches instead for some apps
  switch {
    // 'indeterminate' is the synthetic wildcard
    &:not(:indeterminate) {
      @extend %reset_switch;
      min-width: 50px;
      min-height: 30px;

      slider:not(:indeterminate) { @extend %reset_switch; }
    }
    &:disabled { // specificity bump
      &, &:checked {
        @extend %reset_switch;
        min-width: 50px;
        min-height: 30px;
      }
    }

    &:not(:indeterminate) {@extend %pixmap_headerbar_switch; }
  }

  // spinbutton spacing
  spinbutton button {
    min-width: rem($widget_size - 4px);
    min-height: rem($widget_size - 4px);
    padding: 0;
    border: 0 none transparent;
  }
}

.titlebar {
  &.default-decoration {
    padding: 0 3px; // override scaling-unit
    border-radius: 2px 2px 0 0;
    border-width: 1px 0 0;
    border-top-color: $top_edge_borders_color;
    box-shadow: none;

    .title { // fade_effect doesn't work
      color: $inverted_fg_color;
      &:backdrop { color: $unfocused_inverted_fg_color; }
    }

    .titlebutton {
      min-width: $titlebutton_small;
      min-height: $titlebutton_small;
      margin: 3px 0 2px; // concern top-edge border
      padding: 0;
      border-radius: 100px;
      -gtk-outline-radius: 100px;
      color: $inverted_secondary_fg_color;
      &:hover,
      &:active { color: $inverted_fg_color; }
      &:backdrop { color: $unfocused_inverted_fg_color; }
    }
  }

  .tiled &,
  .tiled-top &,
  .tiled-bottom &,
  .tiled-left &,
  .tiled-right &,
  .maximized &,
  .fullscreen & {
    border-top-color: $inverted_dark_color;
    border-radius: 0;
  }
}

headerbar {
  .solid-csd & {
    &:dir(rtl), &:dir(ltr) { // specificity bump
      &, &:not(:only-child):last-child {
        margin: -1px -1px 0 -1px; // hide inset border-frame in decoration node
        border-radius: 0;
        border-top: 0 none transparent; // unset top-edge
        box-shadow: none;
      }
    }
  }

  .solid-csd box &:not(:only-child):last-child { // revive separators
    &:dir(ltr) { border-left: 1px solid $borders_color; }
    &:dir(rtl) { border-right: 1px solid $borders_color; }
  }

  &.selection-mode { // selection-mode styling
    border-width: 1px 0 1px 0; // remove side borders
    border-top-color: $highlight_color;
    border-bottom-color: transparent;
    background-color: mix($selected_bg_color, $inverted_dark_color, 87%);
    color: $selected_fg_color;
    &:backdrop > * { opacity: 1.0; } // unset fade_effect

    box & { // Remove unneeded side shadows with dirty hacks
      &:not(:only-child):last-child {
        &:dir(ltr) {
          box-shadow: if($variant == light, $selected-header-shadow-light-ltr,
                                            $selected-header-shadow-dark-ltr);
        }
        &:dir(rtl) {
          box-shadow: if($variant == light, $selected-header-shadow-light-rtl,
                                            $selected-header-shadow-dark-rtl);
        }
      }
    }

    .tiled &,
    .tiled-top &,
    .tiled-bottom &,
    .tiled-left &,
    .tiled-right &,
    .maximized & {
      border-top-color: mix($selected_bg_color, $inverted_dark_color, 87%);
    }

    label {
      &.title { color: $fixed_fg_color; } // turn to dark label

      &.subtitle {
        color: $secondary_fixed_fg_color;

        &:link { @extend %selected_link;  }
      }
    }

    button,
    button.image-button {
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.001,
                                  to($selected_fg_color),
                                  to(transparent))
                                  0 0 0 / 0 0 0px;
      color: $secondary_selected_fg_color;
      &:hover,
      &:active,
      &:checked { color: $selected_fg_color; }
      &:disabled { color: $insensitive_inverted_secondary_fg_color; }
      &:checked {
        border-image: -gtk-gradient(radial,
                                    center bottom, 0,
                                    center bottom, 0.5,
                                    to($selected_fg_color),
                                    to(transparent))
                                    0 0 2 / 0 0 2px;
        color: $selected_fg_color;
        background-color: transparent;
        &:disabled {
          color: $insensitive_selected_fg_color;

          > label { color: inherit; }
        }
      }

      &.suggested-action {
        // NOTE: do not use @extend button;
        @include button(normal);
        &:hover { @include button(hover); }
        &:active { @include button(active); }
        &:disabled { @include button(insensitive); }
      }

      // text-button foreground colors
      &.text-button,
      &.suggested-action {
        color: $secondary_selected_fg_color;
        &:hover,
        &:active,
        &:checked { color: $selected_fg_color; }
        &:disabled { color: $insensitive_selected_fg_color; }
      }
    }

    button:not(.suggested-action):not(.destructive-action) {
      border-radius: 100px;
      -gtk-outline-radius: 100px;
      color: $secondary_selected_fg_color;
      &:hover,
      &:active,
      &:checked { color: $selected_fg_color; }
      &:disabled { color: $insensitive_selected_fg_color; }

      &.text-button,
      &.flat.selection-menu,
      &.selection-menu.toggle.popup {
        min-height: $icon_size;
        padding-top: rem(($widget_size - $icon_size - 2.7px) / 2);
        padding-bottom: rem(($widget_size - $icon_size - 2.7px) / 2);
        border-radius: 2px;
        -gtk-outline-radius: 2px;

        label { margin: rem(-2px) 0; }

        &.image-button {
          border-radius: 100px;
          -gtk-outline-radius: 100px;
        }
      }
    }

    entry {
      color: $inverted_secondary_fg_color;
      &:focus { color: $inverted_fg_color; }
      &:disabled { color: $insensitive_inverted_secondary_fg_color; }
    }

    .selection-menu {
      padding-left: rem(16px);
      padding-right: rem(16px);

      &, &.popup {
        color: $secondary_selected_fg_color;
        &:hover,
        &:active,
        &:checked { color: $selected_fg_color; }
        &:disabled { color: $insensitive_inverted_secondary_fg_color; }
        &:checked {
          border-image: -gtk-gradient(radial,
                                      center bottom, 0,
                                      center bottom, 0.5,
                                      to($selected_fg_color),
                                      to(transparent))
                                      0 0 2 / 0 0 2px;
          background-color: transparent;
          &:disabled {
            color: $insensitive_selected_fg_color;

            > label { color: inherit; }
          }
        }
      }

      arrow {
        -GtkArrow-arrow-scaling: 1.0;
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        color: $secondary_selected_fg_color;
      }
    }
  }
}

headerbar {
  @extend %fade_effect; // add fade_effect

  // draw borders
  border-width: 1px 0 1px;
  border-style: solid;
  // do not use transparentize
  border-top-color: $top_edge_borders_color;
  border-bottom-color: $borders_color;

  .tiled &,
  .tiled-top &,
  .tiled-bottom &,
  .tiled-left &,
  .tiled-right &,
  .maximized &,
  .fullscreen & {
    border-top-color: $inverted_dark_color;
    border-radius: 0;
  }

  // reduce hidden gap reserved for separators
  > box.horizontal {
    &.left { margin-right: -6px; }
    &.right { margin-left: -6px; }
  }

  // To avoid double-padding, set it only for titlebar in case it
  // is placed on the header-bar.
  &.titlebar,
  .csd &,
  .solid-csd &,
  box &:only-child {
    @extend %headerbar_child_margins;
    padding: 0 rem(5.3px); // only add lateral spacer
    // draw hilight and shadows
    box-shadow: if($variant == light, $header-shadow-light,
                                      $header-shadow-dark);
  }

  // override unwanted side-borders
  box &:not(:only-child):first-child,
  box &:not(:only-child):last-child {
    border-left-color: $inverted_dark_color;
    border-right-color: $inverted_dark_color;
  }

  box & { // Remove unneeded side shadows with dirty hacks
    &:not(:only-child):last-child {
      &:dir(ltr) {
        box-shadow: if($variant == light, $sub-header-shadow-light-ltr,
                                          $sub-header-shadow-dark-ltr);
      }
      &:dir(rtl) {
        box-shadow: if($variant == light, $sub-header-shadow-light-rtl,
                                          $sub-header-shadow-dark-rtl);
      }
    }
  }
}

%headerbar_child_margins {
  button, // set spacer with vertical margin
  entry,
  spinbutton,
  scale { margin: rem(5.3px) 0; }

  // pixmap based switch does not need margins
  switch { margin: 0; }

  .title { margin-bottom: rem(5.3px - 1.3px); }

  > box.vertical {
    > .title { margin: 0; }

    > .subtitle { margin: rem(-2.7px) 0; }
  }
}

.background:not(.maximized):not(.fullscreen):not(.tiled):not(.solid-csd) {
  &:not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right) {
    headerbar,
    .titlebar { // set rounded corners
      border-top-left-radius: 2px;
      border-top-right-radius: 2px;
    }

    box.horizontal headerbar {
      &:not(:last-child) {
        &:dir(ltr) {
          border-top-left-radius: 2px;
          border-top-right-radius: 0;
        }
        &:dir(rtl) {
          border-top-left-radius: 0;
          border-top-right-radius: 2px;
        }
      }

      &:last-child {
        &:dir(ltr) { border-top-left-radius: 0; }
        &:dir(rtl) { border-top-right-radius: 0; }
      }
    }

    box.vertical headerbar:not(.titlebar) { // inline-mode
      &:not(:last-child) {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
      }
    }
  }
}

// force using rounded corners in case of paned titlebars
window:not(.maximized):not(.fullscreen):not(.tiled):not(.solid-csd) {
  &:not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right) {
    paned.titlebar,
    grid.titlebar {
      border-top-left-radius: 2px;
      border-top-right-radius: 2px;

      separator:first-child + headerbar { // only-child case
        border-top-left-radius: 2px;
      }

      headerbar:first-child {
        border-top-left-radius: 2px;
        border-top-right-radius: 0;
      }

      headerbar:last-child {
        border-top-left-radius: 0;
        border-top-right-radius: 2px;
      }
    }
  }
}

// workaround for inline-mode headerbars
.background:not(.csd):not(.ssd):not(.solid-csd) {
  box headerbar,
  headerbar {
    &, &:not(:last-child) {
      @extend %headerbar_child_margins;
      padding: 0 rem(5.3px); // only add lateral spacer
      border-radius: 0;
      border-top: 0 none transparent;
      box-shadow: none;

      // unset fade-effect
      &:backdrop > * { opacity: 1.0; }
    }
  }

  &.tiled,
  &.tiled-top,
  &.tiled-bottom,
  &.tiled-left,
  &.tiled-right,
  &.maximized,
  &.fullscreen {
    box headerbar,
    headerbar {
      &, &:not(:last-child) {
        border-top: 0 none transparent;
        background-color: $inverted_dark_color;
        box-shadow: none;
      }
    }
  }
}

dialog.background.csd > headerbar.titlebar {
  // enforce square shape in 'Cancel' and 'Open' button
  > button:not(.image-button):not(.text-button):not(.toggle):not(.popup) {
    border-radius: 2px;
    -gtk-outline-radius: 2px;
  }
}


// /************
//  * Pathbars *
//  ************/

.linked.path-bar,
.path-bar {
  button {
    &.text-button:not(.image-button) {
      padding: 0 rem(2.7px, $sw: 1.0) 0;
      -gtk-outline-radius: 2px;

      label {
        margin-left: rem(5.3px);
        margin-right: rem(5.3px);
        padding: 0 0 rem(1.3px);
      }
    }

    &.image-button {
      padding: 0 rem(2.7px, $sw: 1.0) 0;
      border-radius: 2px;
      -gtk-outline-radius: 2px;

      image {
        margin: 0 rem(5.3px) 0;
        padding: 0;
      }
    }

    &.text-button.image-button {
      &, &.toggle {
        padding: 0 rem(2.7px, $sw: 1.0) 0;
        -gtk-outline-radius: 2px;

        label {
          padding: 0 0 rem(1.3px);
          &:dir(ltr) {
            margin-left: 0;
            margin-right: rem(5.3px);
          }
          &:dir(rtl) {
            margin-left: rem(5.3px);
            margin-right: 0;
          }
        }

        image {
          &:dir(ltr) {
            margin-left: rem(1.3px);
            margin-right: rem(5.3px);
          }
          &:dir(ltr) {
            margin-left: rem(5.3px);
            margin-right: rem(1.3px);
          }
        }
      }
    }

    &.slider-button {
      min-height: $icon_size;
      padding: 0 rem(2.7px, $sw: 1.0) 0;
      border-radius: 2px;
      -gtk-outline-radius: 2px;

      image { margin: 0 rem(5.3px) 0; }
    }
  }
}


// /**************
//  * Tree Views *
//  **************/

treeview.view {
  @at-root * {
    -GtkTreeView-horizontal-separator: 4;
    -GtkTreeView-grid-line-width: 0;
    -GtkTreeView-grid-line-pattern: '';
    -GtkTreeView-tree-line-width: 1;
    -GtkTreeView-tree-line-pattern: '';
    -GtkTreeView-expander-size: 16;
  }

  // this is actually the tree lines color,
  // while this is the grid lines color, better then nothing to avoid borders
  // being overridden by the previously set props
  border-left-color: $outline_track_color;
  border-top-color: $borders_color;

  border-radius: 0; // rest border radius in lists

  rubberband { @extend rubberband; }

  // clear backgrounds
  background-color: transparent;
  background-image: none;
  box-shadow: none;

  &:hover,
  &:active { border-radius: 0; }
  &:selected {
    border-radius: 0;
    @extend %selected_items;
  }

  // override foreground colours
  &, entry,
  entry > label {
    color: $secondary_fg_color;
    &:hover,
    &:active,
    &:focus { color: $fg_color; }
    &:selected { color: $selected_fg_color; }
    &:disabled {
      color: $insensitive_fg_color;
      &:selected { color: $insensitive_selected_fg_color; }
    }
  }

  &.separator {
    min-height: if($ref_weight < 1.0, 1px + 2px,
                                      1px + (2px * 2));
    color: $solid_light_borders_color;
  }

  &.sidebar { // for lollypop
    background-color: $secondary_dark_color;
    font-weight: 500;
  }

  &:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $drop_target_color;

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

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

  &.expander {
    min-width: $icon_size;
    min-height: $icon_size;
    &:dir(ltr) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic'); }
    &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }

    &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
    &:selected {
      color: $secondary_selected_fg_color;
      &:hover,
      &:active { color: $selected_fg_color; }
    }
  }

  &.progressbar { // progressbar bit in treeviews
    box-shadow: inset 0 -4px $accent_color;
    &:selected { box-shadow: inset 0 -4px $selected_fg_color; }
  }

  &.trough { // progressbar trough in treeviews
    box-shadow: inset 0 -4px gtkopacity($accent_color, 0.2);
    &:selected {
      box-shadow: inset 0 -4px gtkopacity($selected_fg_color, 0.2);
    }
  }

  &, paned & { // redraw some stuff for RhythmBox
    background-color: $base_color;
    &:hover,
    row:hover { color: $fg_color; }
    &:selected,
    row:selected { @extend %selected_items; }
  }

  header {
    button {
      @extend %column_header_button;
      background-color: $bg_color;
      color: $tertiary_fg_color;
      &:hover {
        @extend %column_header_button;
        background-color: $track_color;
        color: $secondary_fg_color;
      }
      &:active {
        background-color: $track_color;
        color: $fg_color;
      }
      &:disabled {
        @extend %column_header_button;
        background-color: $bg_color;
        color: $insensitive_fg_color;
      }
    }
  }

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    &,
    &:hover,
    &:active,
    &:selected {
      min-height: rem(20px);
      padding: 0 rem(6.7px) 0;
      border: 1px solid $borders_color;
      border-radius: 0;
      background-color: $selected_bg_color;
      color: $selected_fg_color;
      box-shadow: none;
      font-weight: 400;
      transition: none;
    }
  }

  header button:last-child,
  &:last-child button { // treeview-like derived widgets in Banshee
                        // and Evolution
    border-right-style: none;
  }

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

%column_header_button {
  min-height: rem(20px);
  padding: 0 rem(6.7px) 0;
  border-style: none solid solid none;
  border-width: 1px;
  border-color: $borders_color;
  border-radius: 0;
  box-shadow: none;
  font-weight: 400;
}


// /*********
//  * Menus *
//  *********/

.menubar,
menubar {
  -GtkWidget-window-dragging: true;
  padding: 0;
  background-color: $inverted_dark_color;

  > menuitem {
    padding: rem(5.3px, $sw: 1.0) rem(8px, $sw: 1.0) rem(6.7px, $sw: 1.0);
    background-color: transparent;
    color: $inverted_secondary_fg_color;
    &:hover { // Seems like it :hover even with keyboard focus
      color: $inverted_fg_color;
      box-shadow: inset 0 -2px $selected_bg_color;
    }
    &:disabled {
      color: $insensitive_inverted_fg_color;
      box-shadow: none;
    }
  }
}

.menu,
.context-menu,
menu {
  &,
  .solid-csd.popup & {
    padding: rem(4px) 1px;
    border-radius: 0;
    border-width: 1px; // adds borders in a non composited env
    border-style: solid;
    border-color: $solid_light_borders_color;
    background-color: $secondary_base_color;
  }

  .csd.popup & { // axes borders in a composited env
    margin: rem(4px) 0;
    padding: rem(4px) 0;
    border-radius: 2px;
    border-width: 1px 0 0;
    border-style: solid none none;
    border-color: $menu_highlight_color transparent transparent;
  }

  font: initial; // decouple the font of context-menus from parent nodes

  menuitem {
    min-height: rem(20px);
    min-width: rem(40px);
    padding: rem(5.3px) rem(8px) rem(6.7px);
    color: $secondary_fg_color;
    font: initial;
    text-shadow: none;
    transition: none;
    &:hover {
      background-color: $track_color;
      color: $fg_color;
      transition: none;
    }
    &:disabled { color: $insensitive_fg_color; }

    // submenu indicators
    arrow {
      min-height: rem($icon_size);
      min-width: rem($icon_size);
      &:dir(ltr) {
        -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
        margin-left: rem(10.7px);
      }
      &:dir(rtl) {
        -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl');
        margin-right: rem(10.7px);
      }
    }

    // avoids labels color being overridden, see
    // https://bugzilla.gnome.org/show_bug.cgi?id=767058
    label,
    arrow {
      &:dir(rtl),
      &:dir(ltr) { color: inherit; }
    }
  }

  > arrow { // overflow buttons
    @extend %button_flat_normal;
    min-height: rem($icon_size);
    min-width: rem($icon_size);
    padding: rem(4px);
    border-style: none;
    border-radius: 0;
    color: $secondary_fg_color;
    background-color: $secondary_base_color;
    &:hover {
      @extend %button_flat_hover;
      color: $fg_color;
      background-color: $secondary_dark_color;
    }
    &:active { @include button(flat-active); }
    &:checked { @include button(flat-checked); }
    &:checked:disabled { @include button(flat-checked-insensitive); }
    &:disabled {
      border-color: transparent ;
      color: transparent;
      background-color: transparent;
    }

    &.top {
      margin-top: rem(-5.3px);
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
      border-bottom: 1px solid $borders_color;
    }
    &.bottom {
      margin-bottom: rem(-5.3px);
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
      border-top: 1px solid $borders_color;
    }
  }

  > separator { // asymmetrical separators with gaps
                // same as check/radio width and its paddings
    margin-top: rem(4px);
    margin-bottom: rem(4px);
    &:dir(ltr) { margin-left: rem($icon_size, $sw: 1.0) + rem(8px); }
    &:dir(rtl) { margin-right: rem($icon_size, $sw: 1.0) + rem(8px); }
  }
}

menuitem {
  accelerator { color: gtkalpha(currentColor, 0.54); }

  separator {
    margin-top: rem(4px);
    margin-bottom: rem(4px);
    border-top: 1px solid $borders_color;
    color: transparent;
    background: none;
    &:dir(ltr) { margin-left: rem($icon_size, $sw: 1.0) + rem(8px); }
    &:dir(rtl) { margin-right: rem($icon_size, $sw: 1.0) + rem(8px); }
  }

  box.horizontal separator { // special case for nm-applet
    min-height: 1px;
    border: none;
    background-color: $borders_color;

    &:dir(ltr),
    &:dir(rtl) {
      margin: rem(13.3px - 0.5px, $sw: 1.0) 0;
    }
  }
}

window.popup {
  &, &.solid-csd { border-radius: 0; }

  &.csd { // round corners for CSD menus
    border-radius: 2px;
  }
}

#IBus { // ibus-candidate popups
  &Candidate {
    border: 1px solid $borders_color;
    background-color: $secondary_base_color;
    box-shadow: inset 0 1px $menu_highlight_color;

    > box > label { color: $tertiary_fg_color; }

    widget label {
      color: $secondary_fg_color;
      font-size: 110%;
      -gtk-secondary-caret-color: $suggested_color; // =< 1.5.14
      &:selected { color: $selected_fg_color; }
    }

    button.flat.image-button { margin: rem(4px); }
  }

  &Handle { // a grip inside the ibus-candidate popups
    // override ugly grey backgrounds
    background-image: image($secondary_base_color);
  }

  &Emojier {
    &WhiteLabel,
    &GoldLabel,
    &SelectedLabel { padding: rem(5.3px, $sw: 1.0); }
  }
}


// /************
//  * Popovers *
//  ************/

%popover,
popover.background {
  padding: 0;
  background-color: $secondary_base_color;
  box-shadow:  $z-depth-3;

  &:backdrop { box-shadow: $z-depth-1; }

  &.menu { // reset standard menu spacing
    margin: 0;
    padding: 0;

    // compensate outer margins
    // subtract top-edge border width
    > stack { margin: -(6px - 2px) -6px -6px; }

    separator.horizontal {
      margin-top: rem(4px);
      margin-bottom: rem(4px);
    }
  }

  .csd &,
  & {
    border-width: 1px;
    border-style: solid;
    border-radius: 0;
    border-color: if($variant == light, gtkopacity($borders_color, 0.75),
                                        gtkopacity($borders_color, 0.5))
                  $secondary_base_color $secondary_base_color;
    border-image: linear-gradient(to bottom,
                                  $menu_highlight_color 1px,
                                  $secondary_base_color,
                                  $secondary_base_color 1px) 1 / 1px stretch;
  }

  > list,
  > .view,
  > toolbar,
  &.osd > toolbar {
    border-style: none;
    border-image: none;
    background-color: transparent;
  }

  &, list {
    separator { margin: 0; } // unset outer margins
  }

  list {
    > row,
    > .activatable { // limited transitions by default
      padding: 0; // unset padding
      transition-property: opacity,
                           background-image;
    }
  }

  button {
    menuitem.flat,
    &.flat {
      padding: 0 rem(13.3px) 0;
      background-color: transparent;
      color: $secondary_fg_color;
      font-weight: 400;
      font-size: 100%;
      transition-duration: 0s; // better than 'none'
      &:hover {
        background-color: transparent; // remove double-bg
        color: $fg_color;
      }
      // enforce insensitive foregrounds
      &:disabled { color: $insensitive_secondary_fg_color; }

      // FIXME: label padding is ugly
      // vertical padding of GtkMenuItem
      label { padding: rem(5.3px) 0 rem(6.7px); }
    }

    &.image-button { padding: rem(6.7px); }

    &.model.image-button { min-height: rem(26.7px); }
  }

  .linked > button {
    @extend %button_flat_normal;
    @extend %button_array;
    background-color: transparent;
    color: $secondary_fg_color;
    &:hover {
      @extend %button_flat_hover;
      background-color: transparent;
      color: $fg_color;
    }
    &:active {
      @extend %button_flat_active;
      background-color: transparent;
      color: $fg_color;
    }
    &:checked {
      @extend %button_flat_checked;
      background-color: transparent;
      color: $fg_color;
    }
    &:checked:disabled { @include button(flat-checked-insensitive); }
    &:disabled { @include button(flat-insensitive); }
  }
}

popover.background {
  &.osd { @extend %osd; }

  &.touch-selection, // do not use OSD-style
  &.magnifier {
    button.image-button {
      @extend %action-area-button;
      padding: rem(10px);
    }
  }
}


// /*************
//  * Notebooks *
//  *************/

notebook {
  padding: 0;

  &.frame {
    border: 1px solid $solid_light_borders_color;
    transition: none;

    // remove madness borders around header
    > header {
      &, &.frame { border-style: none; }
      @each $_header, $_margin in (top, -1px -1px 0 -1px),
                                  (bottom, 0 -1px -1px -1px),
                                  (left, -1px 0 -1px -1px),
                                  (right, -1px -1px -1px 0) {
        &.#{$_header} { margin: #{$_margin}; }
      }
    }
  }

  > stack {
    transition: none;
    &:only-child {
      border: none;
      background-color: transparent;
      box-shadow: none;
    }

    // the :not(:only-child) is for "hidden" notebooks
    &:not(:only-child),
    &:not(:first-child),
    &:not(:last-child) {
      border: none;
      background-color: $base_color;
      box-shadow: inset 0 0 0 1px $base_color;
    }
  }

  > header {
    $tab_indicator_size: 2px;
    // tab sizing
    $vpadding: rem(5.3px);
    $hpadding: rem(5.3px);

    background-color: $bg_color;
    tabs { background-color: transparent; }

    @each $_header, $_border in (top, 0 1px),
                                (bottom, 0 -1px),
                                (left, 1px 0),
                                (right, -1px 0) {
      &.#{$_header} {
        // FIXME: outset borders
        box-shadow: #{$_border} $borders_color;
      }
    }

    &.top {
      > tabs {
        margin: 0 rem(6px) -1px rem(6px);
        > tab {
          margin: 0 -1px 0 -1px; // 1px horizontal overlap
          padding: $vpadding $hpadding;
          border-bottom-width: $tab_indicator_size;
          box-shadow: none;
          &.reorderable-page {
            border-left-width: 1px;
            border-right-width: 1px;
          }
        }
      }
    }
    &.bottom {
      > tabs {
        margin: -1px rem(6px) 0 rem(6px);
        > tab {
          margin: 0 -1px 0 -1px;
          padding: $vpadding $hpadding;
          border-top-width: $tab_indicator_size;
          box-shadow: none;
          &.reorderable-page {
            border-left-width: 1px;
            border-right-width: 1px;
          }
        }
      }
    }
    &.left {
      > tabs {
        margin: rem(6px) -1px rem(6px) 0;
        > tab {
          margin: -1px 0 -1px 0; // 1px vertical overlap
          padding: $vpadding $hpadding;
          border-right-width: $tab_indicator_size;
          box-shadow: none;
          &.reorderable-page {
            border-bottom-width: 1px;
            border-top-width: 1px;
          }
        }
      }
    }
    &.right {
      > tabs {
        margin: rem(6px) 0 rem(6px) -1px;
        > tab {
          margin: -1px 0 -1px 0;
          padding: $vpadding $hpadding;
          border-left-width: $tab_indicator_size;
          box-shadow: none;
          &.reorderable-page {
            border-bottom-width: 1px;
            border-top-width: 1px;
          }
        }
      }
    }

    // Reorderable-page
    @each $_tab, $_border in (top, bottom),
                             (bottom, top),
                             (left, right),
                             (right, left) {
      &.#{$_tab} tab.reorderable-page {
        border-#{$_border}-width: 2px;
        border-#{$_border}-color: transparent;
        &:hover {
          border-color: $borders_color;
          border-#{$_border}-width: 2px;
          border-#{$_border}-color: $outline_track_color;
          background-color: $base_color;
          box-shadow: none;
        }
        &:checked {
          border-color: $borders_color;
          border-#{$_border}-width: 2px;
          border-#{$_border}-color: $selected_bg_color;
          background-color: $base_color;
          box-shadow: if($variant == light, $tab-shadow-light,
                                            $tab-shadow-dark);
        }
      }
    }

    // Arrow buttons
    > tabs > arrow {
      color: $tertiary_fg_color;
      transition: none;
      &:hover,
      &:active { color: $fg_color; }
      &:disabled { color: transparent; }
    }
  }

  tab {
    border-width: 0;
    border-style: solid;
    border-color: transparent;
    background-color: transparent;
    background-image: radial-gradient(circle farthest-side at center,
                                      gtkalpha(currentColor, 0.3) 12.5%,
                                      transparent 0%);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 0% 0%; // hide ripples in normal state
    transition: border-color 0.2s $slope_medium,
                border-image 0.2s $slope_medium,
                background-size 0s,
                background-image 0s,
                box-shadow 0.2s $slope_medium;

    // here's the interesting stuff
    &:hover { border-color: $outline_track_color; }
    &:checked { // draw ripples via transitions
      border-color: $selected_bg_color;
      background-image: radial-gradient(circle farthest-side at center,
                                        transparent 12.5%,
                                        transparent 0%);
      background-size: 100% * 8 100% * 8;
      transition: border-color 0.2s $slope_medium,
                  border-image 0.2s $slope_medium,
                  background-size 0.3s $slope_slow,
                  background-image 0.3s $slope_slow,
                  box-shadow 0.2s $slope_medium;
    }

    color: $tertiary_fg_color;
    &:hover,
    &:checked {
      color: $fg_color;

      label { // hover/active tab text
        color: $fg_color;
      }
    }

    button.flat { color: $tertiary_fg_color; }
    &:hover button.flat,
    &:checked button.flat {
      color: $secondary_fg_color;
      &:hover,
      &:active { color: $fg_color; }
    }
    &:disabled button.flat { color: $insensitive_fg_color; }
  }

  tab { // outline styling
    outline-offset: rem(-6px);
    outline-color: transparent;
  }

  &:focus tab { // actual outlines
    outline-color: $outline_track_color;
  }

  &:not(.reorderable-page) > entry {
    // do not pull 'fallback mode' entries
    @include entry(normal);
    border-radius: 0;
    background-color: transparent;
    &:focus {
      @include entry(focus);
      background-color: transparent;
    }
    &:disabled {
      @include entry(insensitive);
      background-color: transparent;
    }
  }

  header {
    &.top, &.bottom,
    &.left, &.right {
      tab label,
      tab.reorderable-page label { // label spacing
        min-height: $icon_size * 1.25;
        padding: 0 rem(5.3px);
        font-weight: 500;
      }

      tabs > arrow { // arrow spacing
        min-height: $icon_size;
        min-width: $icon_size;
        margin: 0 rem(5.3px);
        padding: 0;
        border-radius: 0;
        -gtk-outline-radius: 0;
      }

      button { // button spacing
        min-height: $icon_size;
        min-width: $icon_size;
        padding: 0;

        image { padding: rem(5.3px + 1.3px); }
      }

      button { // buttons outside tabs
        &.image-button { // revert to square
          border-radius: 2px;
          -gtk-outline-radius: 2px;
        }

        &.toggle:checked { // draw underlines
          background-color: transparent;
          border-image: -gtk-gradient(radial,
                                      center bottom, 0,
                                      center bottom, 0.5,
                                      to($selected_bg_color),
                                      to(transparent))
                                      0 0 2 / 0 0 2px;
        }
      }

      tab button { // tab close button
        &,
        &.image-button,
        &.small-button {
          border-radius: 100px;
          -gtk-outline-radius: 100px;
        }
      }
    }
  }
}


// /**************
//  * Scrollbars *
//  **************/

$slider_min_width: if($ref_weight < 1.0, rem(8px, $sw: 1.0),
                                         rem(12px, $sw: 1.0));
$slider_min_length: if($ref_weight < 1.0, rem(24px, $sw: 1.0),
                                          rem(32px, $sw: 1.0));

@keyframes slow_down_vert {
  from {min-width: $slider_min_width / 2; }
  to { min-width: $slider_min_width; }
}

@keyframes slow_down_horz {
  from {min-height: $slider_min_width / 2; }
  to { min-height: $slider_min_width; }
}

scrollbar {
  // disable steppers
  @at-root * {
    -GtkScrollbar-has-backward-stepper: false;
    -GtkScrollbar-has-forward-stepper: false;
  }

  background-color: gtkopacity($base_color, 0.55);
  transition-duration: 0.2s;

  // scrollbar border
  @each $_side,$_margin in ('top', '0 0 -2px 0'),
                           ('bottom', '-2px 0 0 0'),
                           ('left', '0 -2px 0 0'),
                           ('right', '0 0 0 -2px') {
    &.#{$_side} {
      border: none;

      .background scrolledwindow > &:not(.overlay-indicator) {
        // Negative margins can reduce the unwanted gap
        // since we don't have any outer borders and
        // Gtk+ seems to allocate 1px borders always when
        // overlay-indicator was disabled.
        margin: #{$_margin};
      }
    }
  }

  // slider colouring
  slider {
    background-color: gtkopacity($tertiary_fg_color, 0.55);
    &:hover { background-color: gtkopacity($secondary_fg_color, 0.55); }
    &:active { background-color: $fg_color; }
    &:disabled { opacity: 0.4; }
  }

  // slider sizing
  @each $_position,$_min_w,$_min_l in
  ('vertical', $slider_min_width, $slider_min_length),
  ('horizontal', $slider_min_length, $slider_min_width) {
    &.#{$_position} {
      &, &.fine-tune {
        slider {
          min-width: #{$_min_w};
          min-height: #{$_min_l};
          margin: 0;
          border-radius: 0;
          border: 0 none transparent;
        }
      }
    }
  }

  &.overlay-indicator {
    &:not(.dragging):not(.hovering) { // Overlay scrolling indicator
      border-color: transparent;
      background-color: transparent;

      slider {
        margin: 0;
        border: 0 none transparent;
        // FIXME: for WebKitGtk2
        background-color: gtkopacity(
                          mix($fixed_fg_color, $fixed_base_color, 50%),
                          0.55);

        .background & { // standard colour
          background-color: gtkopacity($tertiary_fg_color, 0.55);
        }
      }

      button {
        min-width: $slider_min_width;
        min-height: $slider_min_width;
        border-radius: 0;
        border: none;
        background-color: gtkopacity($tertiary_fg_color, 0.55);
        -gtk-icon-source: none;
      }

      // slider and button sizing
      @each $_position,$_min_w,$_min_l,$_button_s in
      ('vertical', $slider_min_width / 2, $slider_min_length, 'min-width'),
      ('horizontal', $slider_min_length, $slider_min_width / 2, 'min-height') {
        &.#{$_position} {
          slider {
            min-width: #{$_min_w};
            min-height: #{$_min_l};
            margin: 0;
          }

          button {
            #{$_button_s}: #{$_min_w};
            margin: 0;
          }
        }
      }
    }

    &.dragging,
    &.hovering { opacity: 0.8; }

    &.hovering { // slow-down when deforming
      &.vertical slider { animation: slow_down_vert 0.2s linear forwards; }

      &.horizontal slider { animation: slow_down_horz 0.2s linear forwards; }
    }
  }
}


// /**********
//  * Switch *
//  **********/

switch {
  min-width: $icon_size * 2;
  // similar to the scale
  border: rem(10px) solid transparent;
  border-radius: 100px;
  -gtk-outline-radius: 100px;
  background-color: $tertiary_fg_color;
  font-size: 0;
  outline-offset: rem(-4px);
  &:checked {
    background-color: gtkopacity($selected_bg_color, 0.54);
    &:disabled {
      background-color: gtkopacity($selected_bg_color, 0.54 * 0.28);
    }
  }
  &:disabled { background-color: gtkopacity($tertiary_fg_color, 0.28); }

  // slider styling
  // switch slider doesn't respond to its own states
  // but relies on the switch ones
  slider {
    min-width: $icon_size;
    min-height: $icon_size;
    margin: -2px 0;
    padding: 0;
    border-radius: 100px;
    -gtk-outline-radius: 100px;
    background-color: if($variant == light, $light_color,
                                            mix($fg_color, $bg_color, 87%));
    box-shadow: $z-depth-1;
    transition-timing-function: $slope_slow;
    transition-duration: 0.2s;
  }

  &:hover slider {
    background-image: image(if($variant == light,
                            gtkopacity($fixed_fg_color, 0.12),
                            $fg_color));
    box-shadow: $z-depth-1,
                0 0 0 7px $outline_track_color;
  }

  &:checked slider {
    background-color: $selected_bg_color;
    background-image: none;
    box-shadow: $z-depth-1;
  }

  &:checked:hover slider {
    background-image: image(gtkopacity($selected_fg_color, 0.12));
    box-shadow: $z-depth-1,
                0 0 0 7px gtkopacity($selected_bg_color, 0.2);
  }

  &:disabled {
    slider,
    &:checked slider {
      // do not use any transparentize
      background-color: mix($fg_color, $bg_color, 54% * 0.28);
      background-image: none;
      box-shadow: none;
    }
  }

  row:selected > & { // return to monochrome
    background-color: mix($selected_fg_color, $selected_bg_color, 54%);
    &:checked { background-color: $selected_fg_color; }

    slider { background-color: $selected_fg_color; }

    &:hover slider {
      background-image: image(gtkopacity($fixed_fg_color, 0.12));
      box-shadow: $z-depth-1,
                  0 0 0 7px gtkopacity($selected_fg_color, 0.2);
    }

    &:checked slider { background-color: $selected_fg_color; }

    &:checked:hover slider {
      box-shadow: $z-depth-1,
                  0 0 0 7px gtkopacity($selected_fg_color, 0.2);
    }
  }
}

%reset_switch {
  margin: 0;
  padding: 0;
  border: unset;
  color: transparent;
  background: unset;
  background-image: unset;
  background-size: 50px 30px;
  background-repeat: no-repeat;
  background-position: right center;
  box-shadow: none;
  font-size: 0;
  outline-color: transparent;

  &:dir(rtl) { background-position: left center; }
}

%pixmap_switch {
  // use ugly pixmaps
  background-image: -gtk-scaled(
                    url("assets/toggle-off#{$asset_suffix}.png"),
                    url("assets/toggle-off#{$asset_suffix}@2.png"));
  &:hover {
    background-image: -gtk-scaled(
                      url("assets/toggle-off-hover#{$asset_suffix}.png"),
                      url("assets/toggle-off-hover#{$asset_suffix}@2.png"));
  }
  &:checked {
    background-image: -gtk-scaled(
                      url("assets/toggle-on#{$asset_suffix}.png"),
                      url("assets/toggle-on#{$asset_suffix}@2.png"));
    &:hover {
      background-image: -gtk-scaled(
                        url("assets/toggle-on-hover#{$asset_suffix}.png"),
                        url("assets/toggle-on-hover#{$asset_suffix}@2.png"));
    }
    &:disabled,
    &:disabled:hover {
      background-image:
        -gtk-scaled(
          url("assets/toggle-on-insensitive#{$asset_suffix}.png"),
          url("assets/toggle-on-insensitive#{$asset_suffix}@2.png"));
    }
  }
  &:disabled,
  &:disabled:hover {
    background-image:
      -gtk-scaled(
        url("assets/toggle-off-insensitive#{$asset_suffix}.png"),
        url("assets/toggle-off-insensitive#{$asset_suffix}@2.png"));
  }
}

%pixmap_selected_row_switch {
  background-image: -gtk-scaled(
                    url("assets/toggle-off-selected-row.png"),
                    url("assets/toggle-off-selected-row@2.png"));
  &:hover {
    background-image: -gtk-scaled(
                      url("assets/toggle-off-selected-row-hover.png"),
                      url("assets/toggle-off-selected-row-hover@2.png"));
  }
  &:checked {
    background-image: -gtk-scaled(
                      url("assets/toggle-on-selected-row.png"),
                      url("assets/toggle-on-selected-row@2.png"));
    &:hover {
      background-image: -gtk-scaled(
                        url("assets/toggle-on-selected-row-hover.png"),
                        url("assets/toggle-on-selected-row-hover@2.png"));
    }
  }
}

%pixmap_headerbar_switch {
  background-image: -gtk-scaled(
                    url("assets/toggle-off-dark.png"),
                    url("assets/toggle-off-dark@2.png"));
  &:hover {
    background-image: -gtk-scaled(
                      url("assets/toggle-off-hover-dark.png"),
                      url("assets/toggle-off-hover-dark@2.png"));
  }
  &:checked {
    background-image: -gtk-scaled(
                      url("assets/toggle-on-dark.png"),
                      url("assets/toggle-on-dark@2.png"));
    &:hover {
      background-image: -gtk-scaled(
                        url("assets/toggle-on-hover-dark.png"),
                        url("assets/toggle-on-hover-dark@2.png"));
    }
    &:disabled,
    &:disabled:hover {
      background-image: -gtk-scaled(
                        url("assets/toggle-on-insensitive-dark.png"),
                        url("assets/toggle-on-insensitive-dark@2.png"));
    }
  }
  &:disabled,
  &:disabled:hover {
    background-image: -gtk-scaled(
                      url("assets/toggle-off-insensitive-dark.png"),
                      url("assets/toggle-off-insensitive-dark@2.png"));
  }
}

switch {
  // special case inside the grid and row container,
  // need to protect geometry by using pixmaps images...
  // FIXME: wild-card should be dropped
  row * &,
  row:selected * &,
  grid & {
    // reset all of default troughs
    // 'indeterminate' is the synthetic wildcard
    &:not(:indeterminate) {
      @extend %reset_switch;
      min-width: 50px;
      min-height: 30px;

      // reset all of default sliders
      slider:not(:indeterminate) { @extend %reset_switch; }
    }
    &:disabled { // specificity bump
      &, &:checked {
        @extend %reset_switch;
        min-width: 50px;
        min-height: 30px;
      }
    }
  }

  row * &:not(:indeterminate),
  grid &:not(:indeterminate) { @extend %pixmap_switch; }

  row:selected * &:not(:indeterminate) {
    @extend %pixmap_selected_row_switch;
  }
}


// /*************************
//  * Check and Radio items *
//  *************************/

@keyframes check_radio_hover {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to($track_color),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($track_color),
                                    to(transparent));
  }
}

@keyframes check_radio_active {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkopacity($selected_bg_color, 0.12)),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkopacity($selected_bg_color, 0.12)),
                                    to(transparent));
  }
}

@keyframes check_radio_active_reverse {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkopacity($selected_bg_color, 0.25)),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkopacity($selected_bg_color, 0)),
                                    to(transparent));
  }
}

// draw regular check and radio items using our PNG assets
// all assets are rendered from assets.svg. never add pngs directly

@each $w,$a in ('check', 'checkbox'),
               ('radio','radio') {

  // workaround for WebKitGtk, FirefoxQuantum and LibreOffice
  @each $s,$as in ('','-unchecked-solid'),
                  (':hover', '-unchecked-solid'),
                  (':active', '-unchecked-solid'),
                  (':disabled','-unchecked-solid-insensitive'),
                  (':indeterminate', '-mixed-solid'),
                  (':indeterminate:hover', '-mixed-solid'),
                  (':indeterminate:active', '-mixed-solid'),
                  (':indeterminate:disabled', '-mixed-solid-insensitive'),
                  (':checked', '-checked-solid'),
                  (':checked:hover', '-checked-solid'),
                  (':checked:active', '-checked-solid'),
                  (':checked:disabled','-checked-solid-insensitive') {
    #{$w}#{$s} {
      -gtk-icon-source:
        -gtk-scaled(url("assets/#{$a}#{$as}#{$asset_suffix}.png"),
                    url("assets/#{$a}#{$as}#{$asset_suffix}@2.png"));
      -gtk-icon-shadow: none;
    }
  }

  // standard checks and radios
  @each $s,$as in ('','-unchecked'),
                  (':hover', '-unchecked-active'),
                  (':active', '-unchecked-active'),
                  (':disabled','-unchecked-insensitive'),
                  (':indeterminate', '-mixed'),
                  (':indeterminate:hover', '-mixed-active'),
                  (':indeterminate:active', '-mixed-active'),
                  (':indeterminate:disabled', '-mixed-insensitive'),
                  (':checked', '-checked'),
                  (':checked:hover', '-checked-active'),
                  (':checked:active', '-checked-active'),
                  (':checked:disabled','-checked-insensitive') {
    // FIXME: exclude damned FirefoxQuantum
    .background:not(#MozillaGtkWidget) #{$w}#{$s} {
      -gtk-icon-source:
        -gtk-scaled(url("assets/#{$a}#{$as}#{$asset_suffix}.png"),
                    url("assets/#{$a}#{$as}#{$asset_suffix}@2.png"));
      -gtk-icon-shadow: none;
    }

    // dark-variant-only mode
    .background:not(#MozillaGtkWidget) headerbar #{$w}#{$s},
    messagedialog.background:not(#MozillaGtkWidget) #{$w}#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}-dark.png"),
                                    url("assets/#{$a}#{$as}-dark@2.png"));
      -gtk-icon-shadow: none;
    }
  }
}

.background:not(#MozillaGtkWidget) {
  // check/radio inside treeview
  treeview.view check,
  treeview.view radio {
    &, &:only-child {
      padding: 0; // FIXME: negative margin doesn't work.
    }
  }
}

// check/radio inside selected-rows
@each $w,$a in ('check', 'checkbox'),
               ('radio','radio') {

  // standard checks and radios
  @each $s,$as in ('','-unchecked'),
                  (':active', '-unchecked'),
                  (':indeterminate', '-mixed'),
                  (':indeterminate:active', '-mixed'),
                  (':checked', '-checked'),
                  (':checked:active', '-checked') {
    .background:not(#MozillaGtkWidget) {
      treeview.view,
      row {
        #{$w}:selected#{$s},
        #{$w}:selected:focus#{$s} {
          -gtk-icon-source:
            -gtk-scaled(url("assets/#{$a}#{$as}-selected.png"),
                        url("assets/#{$a}#{$as}-selected@2.png"));
          -gtk-icon-shadow: none;
        }
        // use dark variant for insensitive states
        #{$w}:selected:disabled,
        #{$w}:selected:focus:disabled {
          -gtk-icon-source:
            -gtk-scaled(url("assets/#{$a}-unchecked-insensitive-dark.png"),
                        url("assets/#{$a}-unchecked-insensitive-dark@2.png"));
        }
        #{$w}:selected:indeterminate:disabled,
        #{$w}:selected:focus:indeterminate:disabled {
          -gtk-icon-source:
            -gtk-scaled(url("assets/#{$a}-mixed-insensitive-dark.png"),
                        url("assets/#{$a}-mixed-insensitive-dark@2.png"));
        }
        #{$w}:selected:checked:disabled,
        #{$w}:selected:focus:checked:disabled {
          -gtk-icon-source:
            -gtk-scaled(url("assets/#{$a}-checked-insensitive-dark.png"),
                        url("assets/#{$a}-checked-insensitive-dark@2.png"));
        }
      }
    }
  }
}

// selection-mode
@each $s,$as in ('','-selectionmode'),
                (':hover', '-active-selectionmode'),
                (':active', '-active-selectionmode'),
                (':disabled', '-insensitive-selectionmode'),
                (':checked', '-checked-selectionmode'),
                (':checked:hover', '-checked-active-selectionmode'),
                (':checked:active', '-checked-active-selectionmode'),
                (':disabled:checked', '-checked-insensitive-selectionmode') {
  .background:not(#MozillaGtkWidget) .view.content-view.check#{$s}:not(list) {
    -gtk-icon-source:
      -gtk-scaled(url("assets/checkbox#{$as}#{$asset_suffix}.png"),
                  url("assets/checkbox#{$as}#{$asset_suffix}@2.png"));
    background-color: transparent;
  }

  .background:not(#MozillaGtkWidget) {
    flowbox > flowboxchild overlay checkbutton.bottom > check#{$s} {
      -gtk-icon-source:
      -gtk-scaled(url("assets/checkbox#{$as}#{$asset_suffix}.png"),
                  url("assets/checkbox#{$as}#{$asset_suffix}@2.png"));
      background-color: transparent;
    }
  }
}

checkbutton.text-button,
radiobutton.text-button {
  // FIXME: exclude damned FirefoxQuantum
  .background:not(#MozillaGtkWidget) & {
    // this is for a nice focus on check and radios text
    padding: rem(2.7px, $sw: 1.0) rem(6.7px, $sw: 1.0);
    outline-offset: 0;
  }

  color: $secondary_fg_color;
  &:hover,
  &:active,
  &:checked { color: $fg_color; }
  &:disabled,
  &:disabled:active,
  &:disabled:indeterminate {
    // set insensitive color, which is overriden otherwise
    // color: $insensitive_fg_color;
  }
}

radio,
check {
  min-width: rem($icon_size, $sw: 1.0);
  min-height: rem($icon_size, $sw: 1.0);

  // FIXME: exclude damned FirefoxQuantum as well
  .background:not(#MozillaGtkWidget) & {
    margin: rem(-10px, $sw: 1.0) rem(-3.3px, $sw: 1.0);
    padding: rem(10px, $sw: 1.0);
  }

  &:hover {
    animation: check_radio_hover 0.2s $slope_quick forwards;
  }
  &:active {
    transition-duration: 0.2s;
    animation: check_radio_active_reverse 0.2s $slope_quick forwards;
  }
  &:hover:checked,
  &:hover:indeterminate {
    animation: check_radio_active 0.2s $slope_quick forwards;
  }

  .background:not(#MozillaGtkWidget) menuitem & {
    min-width: rem($icon_size, $sw: 1.0);
    min-height: rem($icon_size, $sw: 1.0);
    margin: 0;
    padding: 0;
    &:dir(ltr) { margin-right: rem(8px); }
    &:dir(rtl) { margin-left: rem(8px); }
    &:not(:backdrop) { // FIXME: use button reset mixin
      color: inherit;
      -gtk-icon-transform: unset;
      transition: none;
      animation: none;
    }
  }
}

// special 'customed' selection-mode in 3.23.x
flowbox > flowboxchild overlay checkbutton.bottom {
  > check {
    &,
    &:hover,
    &:active,
    &:checked,
    &:disabled {
      min-height: $icon_size * 2.5;
      min-width: $icon_size * 2.5;
      margin: 0; // remove unneeded spacing for animations
      padding: 0;
      outline-width: 0; // hide unneeded outlines
      animation: none; // stop hover/active animations
    }
  }
}

// icon transformations
radio:not(:indeterminate):not(:checked):active:not(:backdrop) {
  -gtk-icon-transform: scale(0);
}

check:not(:indeterminate):not(:checked):active:not(:backdrop) {
  -gtk-icon-transform: translate(6px, -3px)
                       rotate(-45deg)
                       scaleY(0.2)
                       rotate(45deg)
                       scaleX(0);
}

radio,
check {
  &:not(:active):not(:checked):not(:backdrop),
  &:not(:active):not(:indeterminate):not(:backdrop) { // ease-out
    -gtk-icon-transform: unset;
    transition: 0.2s;
  }
  &:active { -gtk-icon-transform: scale(0, 1); }
  &:checked:not(:backdrop),
  &:indeterminate:not(:backdrop) { // ease-in
    -gtk-icon-transform: unset;
    transition: 0.2s;
  }
}


// /************
//  * GtkScale *
//  ************/

$scale: 80%;
$scale_slider_size: 20px;
$scale_trough_size: 2px;
$_marks_length: rem(6px, $sw: 1.0);
$_marks_distance: rem(6px, $sw: 1.0);

@keyframes scale_enlarge {
  from { background-size: $scale; }
  to { background-size: 100%; }
}

@keyframes scale_color_enlarge {
  from { background-size: $scale; }
  to { background-size: 90%; }
}

%scale_trough {
  border: 1px solid transparent;
  border-radius: 0;
  background-color: $outline_track_color;
  box-shadow: none;
  &:disabled {
    color: $insensitive_fg_color;
    background-color: $outline_track_color;
  }

  &:backdrop {
  }

  // OSD
  .osd & {
  }
}

%scale_highlight {
  border: 1px solid transparent;
  border-radius: 0;
  background-color: $accent_color;
  &:disabled {
    color: $insensitive_fg_color;
    background-color: $outline_track_color;
  }

  &:backdrop {
  }

  // OSD
  .osd & {
  }
}

scale {
  // remove ugly outlines
  &,
  & trough,
  & trough highlight {
    outline-style: none;
    outline-offset: 0;
    outline-width: 0;
  }

  min-height: $scale_slider_size / 2;
  min-width: $scale_slider_size / 2;
  padding: ($scale_slider_size / 2) - $scale_trough_size;

  &.fine-tune {
    // remove ugly outlines
    outline-offset: 0;
    outline-width: 0;
    &.horizontal {
      min-height: $scale_slider_size / 2;
      padding-top: ($scale_slider_size / 2) - $scale_trough_size;
      padding-bottom: ($scale_slider_size / 2) - $scale_trough_size;
    }

    &.vertical {
      min-width: $scale_slider_size / 2;
      padding-left: ($scale_slider_size / 2) - $scale_trough_size;
      padding-right: ($scale_slider_size / 2) - $scale_trough_size;
    }

    highlight,
    fill,
    trough {
    }
  }

  slider,
  &.fine-tune slider {
    min-height: $scale_slider_size;
    min-width: $scale_slider_size;
    margin: -(($scale_slider_size - $scale_trough_size) / 2);

    &:not(:hover):not(:active) {
      background-size: $scale;
      transition: 0.2s;
    }

    @each $s,$as in ('',''),
                    // (':hover','-hover'),
                    (':active','-active'),
                    (':disabled','-insensitive') {
      &#{$s} {
        $_url: 'assets/slider#{$as}#{$asset_suffix}';
        border-style: none;
        border-radius: 0;
        background-color: transparent;
        background-image: -gtk-scaled(url('#{$_url}.png'),
                                      url('#{$_url}@2.png'));
        background-repeat: no-repeat;
        background-position: center;
        box-shadow: none;
      }
    }
    &:hover {
      animation: scale_enlarge 0.2s $slope_medium forwards;
    }
    &:disabled {
    }
    // OSD sliders
    .osd & {
    }
  }

  // the backing bit sizing
  trough {
    min-height: $scale_trough_size;
    min-width: $scale_trough_size;
    border-radius: 0;
    border-width: 0;
  }

  fill,
  highlight {
    min-height: 0;
    min-width: 0;
    border-radius: 0;
    border-width: 0;
  }

  // the backing bit styling
  trough { @extend %scale_trough; }

  // the colored part of the backing bit
  highlight { @extend %scale_highlight; }

  // switch to orange tracking bit
  &.fine-tune highlight { background-color: $warning_color; }

  // this is another differently styled part of the backing bit,
  // the most relevant use case is for example in media player
  // to indicate how much video stream as been cached
  fill {
    @extend %scale_trough;

    background-color: $accent_fill_color;

    &:disabled {
      border-color: transparent;
      background-color: transparent;
    }
  }

  // same opacity value with dim-label
  value { color: gtkalpha(currentColor, 0.55); }

  separator {
    color: transparent;
    background-color: $outline_track_color;
  }

  // scales on selected list rows
  row:selected & {
  }
}

scale { // marks color
  marks {
    color: gtkalpha(currentColor, 0.55);
    @each $marks_class, $marks_pos, $marks_margin in (top, top, bottom),
                                                     (bottom, bottom, top),
                                                     (top, left, right),
                                                     (bottom, right, left) {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_length);
      }
    }
  }

  &.horizontal {
    indicator {
      min-height: $_marks_length;
      min-width: 1px;
    }
  }

  &.vertical {
    indicator {
      min-height: 1px;
      min-width: $_marks_length;
    }
  }
}

// scale with marks
@each $d,$dn in ('horizontal', 'horz'),
                ('vertical', 'vert') {
  @each $ws,$w,$we in  (':last-child:not(:only-child)',
                        'scale-has-marks-above', 'scale_marks_above'),
                       (':first-child:not(:only-child)',
                        'scale-has-marks-below', 'scale_marks_below') {
    scale.#{$d} {
      %#{$w}-#{$dn},
      contents#{$ws} > trough > slider {
        @each $s,$as in ('',''),
                        // (':hover','-hover'),
                        (':active','-active'),
                        (':disabled','-insensitive') {
          &#{$s} {
            @extend %#{$we}_#{$dn}; // negative margin makes trough shrinking
            $_url: 'assets/slider-#{$dn}-#{$w}#{$as}#{$asset_suffix}';
            border-style: none;
            border-radius: 0;
            background-color: transparent;
            background-image: -gtk-scaled(url('#{$_url}.png'),
                                          url('#{$_url}@2.png'));
            background-repeat: no-repeat;
            background-position: center;
            box-shadow: none;
          }
        }
      }
    }
  }
}

scale { // scales for colour
  &.color,
  &.fine-tune.color {
    min-height: 0;
    min-width: 0;

    // not actual trough colour
    trough {
      min-width: 4px;
      min-height: 4px;
      border-radius: 0;
      background-color: transparent;
    }

    slider {
      min-height: 20px;
      min-width: 20px;
      margin: -8px;
      // FIXME: horizontal slider bit seems to be truncated with 100%
      &:hover { animation: scale_color_enlarge 0.2s $slope_medium forwards; }
    }

    &.horizontal {
      margin: 0 -10px 10px;

      slider {
        &,
        &:hover,
        &:active,
        &:disabled { @extend %scale-has-marks-above-horz; }
      }
    }

    &.vertical {
      &:dir(ltr) {
        margin: -10px 0 -10px 10px;

        slider {
          &,
          &:hover,
          &:active,
          &:disabled { @extend %scale-has-marks-below-vert; }
        }
      }

      &:dir(rtl) {
        margin: -10px 10px -10px 0;

        slider {
          &,
          &:hover,
          &:active,
          &:disabled { @extend %scale-has-marks-above-vert; }
        }
      }
    }
  }
}

%scale_marks_above_horz { margin: -15px -10px -10px -10px; }

%scale_marks_below_horz { margin: -10px -10px -15px -10px; }

%scale_marks_above_vert { margin: -10px -10px -10px -15px; }

%scale_marks_below_vert { margin: -10px -15px -10px -10px; }


// /*****************
//  * Progress bars *
//  *****************/

progressbar {
  // sizing
  &.horizontal {
    trough,
    progress {
      min-width: 0;
      min-height: 4px;
      border-style: none;
    }
  }

  &.vertical {
    trough,
    progress {
      min-width: 4px;
      min-height: 0;
      border-style: none;
    }
  }

  // FIXME: insensitive state missing and some other state
  // should be set probably
  font-size: 90%;
  color: $tertiary_fg_color;

  trough {
    box-shadow: none;
    border-radius: 0;
    background-color: gtkopacity($accent_color, 0.2);
  }

  progress {
    box-shadow: none;
    border-radius: 0;
    background-color: $accent_color;
    &.left {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
    &.right {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
    &.top {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
    &.bottom {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  &.osd {
    &.horizontal {
      min-width: 0;
      min-height: 4px;
    }
    &.vertical {
      min-width: 4px;
      min-height: 0;
    }

    trough {
      border-style: none;
      box-shadow: none;
      background-color: gtkopacity($accent_color, 0.2);
    }

    progress {
      background-image: none;
      background-color: $accent_color;
      border-style: none;
      border-radius: 0;
    }
  }
}

%entry_progressbar { // progress inside entry
  margin: rem(-9.3px) 0 rem(-10.7px); // same values with entry node padding
  padding: 0;
  border: none;
  border-radius: 0;
  background-color: gtkopacity($selected_bg_color, 0.2);
  background-image: none;
}


// /*************
//  * Level Bar *
//  *************/

levelbar {
  box-shadow: $z-depth-1; // needs to be set here to avoid clipping

  block {
    min-width: 36px;
    min-height: 4px;
  }

  &.vertical block {
    min-width: 4px;
    min-height: 36px;
  }

  trough {
    padding: 2px;
    border-radius: 2px;
    box-shadow: $z-depth-1;
    &:disabled { box-shadow: none; }

    &.horizontal { padding: 2px 1px; }
    &.vertical { padding: 1px 2px; }
  }

  &.horizontal.discrete block { margin: 0 1px; }
  &.vertical.discrete block { margin: 1px 0; }

  block {
    border-radius: 0;
    border: none;
    box-shadow: none;

    &.low { background-color: $warning_color; }

    &:not(.empty),
    &.high { background-color: $accent_color; }

    &.full { background-color: $success_color; }

    &.empty { background-color: $outline_track_color; }
  }
}


// /****************
//  * Print dialog *
// *****************/

printdialog {
  paper {
    padding: 0;
    color: $fg_color;
    border: 1px solid $borders_color;
    background-color: $dark_color;
  }

  .dialog-action-box { margin: rem(12px); }
}


// /**********
//  * Frames *
//  **********/

frame > border,
.frame {
  margin: 0;
  padding: 0;
  border-radius: 0;
  border: 1px solid $borders_color;
  box-shadow: none;

  &.flat { border-style: none; }
}

actionbar {
  > frame > border { border-width: 1px 0 0; }

  > revealer > box { border-top: 1px solid $borders_color; }
}

%scrolledwindow,
scrolledwindow {
  viewport.frame { // avoid double borders when viewport inside
                   // scrolled window
    border-style: none;
  }

  // This is used by GtkScrolledWindow,
  // when content is touch-dragged past boundaries.
  // This draws a box on top of the content, the size changes programmatically.
  overshoot {
    &.top { @include overshoot(top); }
    &.bottom { @include overshoot(bottom); }
    &.left { @include overshoot(left); }
    &.right { @include overshoot(right); }
  }

  junction { // the small square between two scrollbars
    border-color: transparent;
    // the border image is used to add the missing dot 
    // between the borders, details, details, details...
    border-image: linear-gradient(to bottom,
                                  $borders_color 1px,
                                  transparent 1px) 0 0 0 1 / 0 1px stretch;
    background-color: $base_color;

    &:dir(rtl) { border-image-slice: 0 1 0 0; }
  }
}

// vbox and hbox separators
separator {
  min-height: 1px;
  min-width: 1px;
  color: transparent;
  background-color: $borders_color;
}


// /*********
//  * Lists *
//  *********/

list {
  border-color: $borders_color;
  background-color: $base_color;
}

row { padding: 2px; }

%activatable_row,
row.activatable {
  // let's take care of background colors
  background-image: radial-gradient(circle farthest-corner at center,
                                    gtkalpha(currentColor, 0) 100%,
                                    transparent 0%),
                    image(gtkalpha(currentColor, 0));
  background-repeat: no-repeat;
  background-position: center, center;
  transition-timing-function: $slope_slow;
  &.has-open-popup, // this is for indicating which sidebar row
                    // generated a popover
  &:hover {         // see https://bugzilla.gnome.org/show_bug.cgi?id=754411
    background-image: radial-gradient(circle farthest-corner at center,
                                      gtkalpha(currentColor, 0) 100%,
                                      transparent 0%),
                      image($track_color);
    transition-timing-function: $slope_slow;
    transition-duration: 0.1s;
  }
  &:active {
    transition: opacity 0.2s $slope_slow,
                border-color 0.2s $slope_slow,
                border-image 0.2s $slope_slow,
                background-color 0s $slope_slow,
                background-image 0s $slope_slow,
                box-shadow 0.2s $slope_slow;
    animation: flat_ripple_effect 0.3s $slope_slow forwards;
  }
  &:selected {
    transition: opacity 0.2s $slope_slow,
                border-color 0.2s $slope_slow,
                border-image 0.2s $slope_slow,
                background-color 0.2s $slope_slow,
                background-image 0.2s $slope_slow,
                box-shadow 0.2s $slope_slow;
  }
}

// button and entry spacing
row {
  // .round-button is used in some other places
  button.image-button:not(.text-button):not(.round-button),
  button.circular {
    min-width: $icon_size;
    min-height: $icon_size;
    // prevent drop-shadow truncation
    margin: rem(2.7px, $sw: 1.0) rem(4px, $sw: 1.0);
    padding: rem(8px);

    // reset spacing for 'eject' button
    placessidebar & {
      margin: 0;
      padding: rem(4px); // Same as of image.sidebar-icon
    }
  }

  entry {
    &, &.flat {
      min-height: rem(13.3px);
      padding: rem(6.7px) rem(8px) rem(8px);
    }
  }
}

row:selected { // buttons inside the selected-row
  @extend %selected_items;

  button {
    color: $secondary_fg_color;
    &:hover,
    &:active,
    &:checked { color: $fg_color; }
    &:disabled { color: $insensitive_secondary_selected_fg_color; }

    &.flat {
      color: $secondary_selected_fg_color;
      &:hover,
      &:active,
      &:checked { color: $selected_fg_color; }
      &:disabled { color: $insensitive_secondary_selected_fg_color; }
    }
  }
}

row:selected { // special case to use raised GtkEntry
  entry,
  entry.flat {
    min-width: rem(33.3px);
    min-height: rem(13.3px);
    padding: rem(8px);
    border-radius: 2px;
    -gtk-outline-radius: 2px;
    border-style: none;
    border-image: none;
    background-color: $base_color;
    color: $secondary_fg_color;
    caret-color: $secondary_fg_color;
    box-shadow: $z-depth-1;
    &:focus {
      border-style: none;
      border-image: none;
      background-color: $base_color;
      color: $fg_color;
      caret-color: $fg_color;
      box-shadow: $z-depth-2;
      transition: none;
    }
    &:disabled {
      border-style: none;
      border-image: none;
      background-color: $track_color;
      color: $insensitive_fg_color;
      box-shadow: none;
    }

    selection {
      &, &:focus { @extend %selected_items; }
    }
  }
}


// /*********************
//  * App Notifications *
//  *********************/

.app-notification {
  &, &.frame {
    @extend %osd;
    @extend %osd_toolbar;
    color: $inverted_fg_color;
    background-color: $inverted_dark_color;
    box-shadow: none;

    box.vertical {
      > label {
        &#summary {
          color: $inverted_fg_color;
          font-weight: 700;
        }

        &#body { color: $inverted_secondary_fg_color; }
      }
    }

    button {
      &:not(hover):not(:active):not(:checked):not(:disabled) {
        background-color: transparent;
        color: $inverted_secondary_accent_label_color;
      }
      &:hover {
        background-color: transparent;
        color: $inverted_accent_label_color;
      }
      &:active {
        border-image: none;
        background-color: transparent;
        color: $inverted_accent_label_color;
        box-shadow: none;
      }
      &:checked {
        border-image: none;
        background-color: transparent;
        color: $inverted_accent_label_color;
        box-shadow: none;
      }
      &:disabled {
        background-color: transparent;
        color: gtkopacity($inverted_accent_label_color, 0.4);
      }
    }

    border { border: none; }
  }
}


// /*************
//  * Expanders *
//  *************/

expander {
  label {
    color: $secondary_fg_color;
    &:hover,
    &:active { color: $fg_color; }
    &:selected { color: $selected_fg_color; }
    &:disabled { color: $insensitive_fg_color; }
  }

  title {
    padding: rem(2.7px) rem(4px) rem(3.3px);

    > arrow {
      -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
      min-width: $icon_size;
      min-height: $icon_size;
      &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }
      &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
      &:not(:hover):not(:active) { color: gtkalpha(currentColor, 0.87); }
      &:selected { color: $selected_fg_color; }
      &:disabled { color: $insensitive_fg_color; }
    }

    > label {
      // spacer between arrow and label
      &:dir(ltr) { padding-left: rem(4px, $sw: 1.0); }
      &:dir(rtl) { padding-right: rem(4px, $sw: 1.0); }
    }
  }
}


// /************
//  * Calendar *
//  ***********/

calendar {
  margin: rem(8px) 0;
  padding: rem(4px, $sw: 1.0) rem(1.3px, $sw: 1.0);
  border: 1px solid $borders_color;
  color: $fg_color;
  font-weight: 500;
  &:selected {
    border: none;
    background: none;
    color: $selected_bg_color;
  }

  &.header {
    border: 1px solid transparent;
    border-bottom-color: $borders_color;
  }

  &.button,
  &.header.button {
    @extend %button_flat_normal;
    color: $tertiary_fg_color;
    background-color: transparent;
    &:hover {
      @extend %button_flat_hover;
      color: $secondary_fg_color;
      background-color: $track_color;
    }
    &:active {
      @extend %button_flat_active;
      color: $secondary_fg_color;
    }
    &:disabled { @include button(flat-insensitive); }
  }

  &:indeterminate { color: gtkopacity($tertiary_fg_color, 0.55); }

  &.highlight { color: $tertiary_fg_color; }
}


// /***********
//  * Dialogs *
//  ***********/

messagedialog {
  &.background {
    color: $inverted_fg_color;
    background-color: gtkopacity($inverted_dark_color, 0.9);

    &.csd {
      // rounded bottom border styling for csd version
      border-bottom-left-radius: 2px;
      border-bottom-right-radius: 2px;

      .titlebar {
        min-height: unset; // reset unneeded min-height
        background-color: gtkopacity($inverted_dark_color, 0.9);
      }
    }

    &.solid-csd { background-color: $inverted_dark_color; } // use opaque
  }

  .dialog-action-box {
    margin: 0;
    padding: 0;
    border-width: 0;

    buttonbox.dialog-action-area { margin: -6px; }
  }

  .titlebar {
    min-height: $titlebutton_small + 3px + 2px;
    border-style: none;
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
    color: $inverted_secondary_fg_color;
    background-color: $inverted_dark_color;
  }

  &.background {
    entry {
      &, &.combo {
        &,
        &:focus {
          color: $inverted_fg_color;
          caret-color: $inverted_fg_color;
        }
        &:disabled { color: $insensitive_inverted_fg_color; }
      }
    }

    button { // set foregrounds for fallback-mode
      color: $inverted_secondary_accent_label_color;
      &:hover,
      &:active,
      &:checked { color: $inverted_accent_label_color; }
      &:disabled { color: $insensitive_inverted_fg_color; }

      &.combo {
        color: $inverted_secondary_fg_color;
        &:hover,
        &:active,
        &:checked { color: $inverted_fg_color; }
        &:disabled { color: $insensitive_inverted_fg_color; }
      }
    }
  }

  .linked > button {
    border: 2px solid transparent;
    border-radius: 2px;
    -gtk-outline-radius: 2px;
    border-image: none;
    box-shadow: none;
  }

  checkbutton.text-button,
  radiobutton.text-button {
    color: $inverted_secondary_fg_color;
    &:hover,
    &:active,
    &:checked { color: $inverted_fg_color; }
    &:disabled,
    &:disabled:active,
    &:disabled:indeterminate { color: $insensitive_inverted_fg_color; }
  }

  expander {
    label { color: $inverted_fg_color; }

    title {
      label,
      arrow {
        color: $inverted_secondary_fg_color;
        &:hover,
        &:active { color: $inverted_fg_color; }
        &:disabled { color: $insensitive_inverted_fg_color; }
      }
    }

    textview.view { // scrolled text-views
      &, > text {
        background-color: $base_color;
        color: $fg_color;
        caret-color: $fg_color;
      }
    }
  }

  &.background,
  &.csd.background {
    .dialog-action-area {
      button,
      .linked > button {
        border: 2px solid transparent;
        border-radius: 0;
        color: $inverted_secondary_accent_label_color;
        font-size: initial;
        &:hover,
        &:active,
        &:checked { color: $inverted_accent_label_color; }
        &:disabled {
          color: gtkopacity($inverted_fg_color, 0.4);
          &:checked {
            color: gtkopacity($inverted_accent_label_color, 0.4);
          }
        }

        &:first-child {
          border-radius: 0 0 0 2px;
          border-right-width: 0;
        }
        &:last-child {
          border-radius: 0 0 2px 0;
          border-left-width: 0;
        }
      }
    }
  }
}

filechooser {
  .dialog-action-box { border-top: 1px solid $borders_color; }

  #pathbarbox {
    border-bottom: 0 none transparent;
    background-color: $bg_color;
  }

  // override defaults to prevent to be bold
  box > paned.horizontal > separator {
    background-image: image($solid_light_borders_color);
  }
}

filechooserbutton:drop(active) {
  box-shadow: none;
  border-color: transparent;
}


// /***********
//  * Sidebar *
//  ***********/

%sidebar_template {
  background-color: $secondary_dark_color;
  &:dir(ltr) {
    box-shadow: if($variant == light, $sidebar-light-ltr,
                                      $sidebar-dark-ltr);
  }
  &:dir(rtl) {
    box-shadow: if($variant == light, $sidebar-light-rtl,
                                      $sidebar-dark-rtl);
  }
}

%sidebar_treeview {
  background-color: transparent;
  box-shadow: none;
  font-weight: 500;
  &:selected {
    &, &:focus {
      background-color: transparent;
      color: $selected_bg_color;
    }
  }
}

// FIXME: exclude treeview node for lollypop's sidebar
.sidebar:not(treeview) {
  border: none;
  color: $secondary_fg_color;

  &, list { // draw shadows
    &:dir(ltr) {
      box-shadow: if($variant == light, $sidebar-light-ltr,
                                        $sidebar-dark-ltr);
    }
    &:dir(rtl) {
      box-shadow: if($variant == light, $sidebar-light-rtl,
                                        $sidebar-dark-rtl);
    }
  }

  // remove background from child-elements
  .frame,
  list { background-color: transparent; }

  treeview.view { @extend %sidebar_treeview; }

  // fill actual background
  background-color: $secondary_dark_color;

  .frame list { box-shadow: none; }

  list,
  row {
    color: $secondary_fg_color;
    background-color: transparent;
    font-weight: 500;
    &:hover { color: $fg_color; }
    &:selected {
      color: $selected_bg_color;
      background-color: transparent;

      label { color: $selected_bg_color; }
    }
  }

  // disable shadows on overshoot/undershoot area
  // of gtk3-demo's sidebar
  overshoot,
  undershoot { box-shadow: none; }
}

stacksidebar {
  row {
    padding: rem(5.3px) rem(8px) rem(6.7px);

    > label {
      padding-left: rem(5.3px);
      padding-right: rem(5.3px);
    }

    color: $secondary_fg_color;
    background-color: transparent;
    font-weight: 500;
    &:hover { color: $fg_color; }
    &:selected {
      color: $selected_bg_color;
      background-color: transparent;

      label { color: $selected_bg_color; }
    }
    &:backdrop { opacity: 1.0; }

    &.needs-attention > label { @extend %needs_attention; }
  }

  .frame list { @extend %sidebar_template; } // draw shadows

  // remove unwanted separator
  separator,
  .separator {
    @extend separator.wide;
    min-height: 0;
    border-color: transparent;
    background-color: transparent;
  }
}


// /****************
//  * File chooser *
//  ****************/

placessidebar {
  @extend %scrolledwindow; // needs for overshoot / undershoot

  list,
  row {
    // Background color for Nautilus and FileChooser sidebar
    background-color: $secondary_dark_color;
  }

  row {
    // Needs overriding of the GtkListBoxRow padding
    // Actual padding is embedded into child elements
    padding: 0;

    // Using margins/padding directly in the row
    // will make the animation of the new bookmark row jump
    > revealer { padding: rem(4px) rem(14px) rem(4px) rem(12px); }

    image.sidebar-icon {
      padding: rem(4px) 0;
      opacity: 0.87; // dim the device icons
      &:dir(ltr) { padding-right: rem(5.3px); }
      &:dir(rtl) { padding-left: rem(5.3px); }
    }

    label.sidebar-label {
      padding: rem(2.7px) 0 rem(4px);
      &:dir(ltr) { padding-right: rem(2px); }
      &:dir(rtl) { padding-left: rem(2px); }
    }

    button.image-button { // Eject button for removable storages
      @include button(flat-normal);
      margin: 0; // unset outer margins
      padding: rem(4px); // Same as of image.sidebar-icon
      &:hover { @include button(flat-hover); }
      &:active { @include button(flat-active); }
      &:disabled { @include button(flat-insensitive); }
      &:checked { @include button(flat-checked); }
      &:checked:disabled { @include button(flat-checked-insensitive); }
    }

    &:selected {
      color: $selected_bg_color;

      label { color: $selected_bg_color; }

      button.image-button {
        color: $selected_bg_color;
        &:hover, // use opaque and brighter colour
        &:active { color: mix($selected_bg_color, $selected_fg_color, 75%); }
      }
    }

    // looks like the label doesn't get all the states so work around
    &:selected:disabled label { color: $insensitive_selected_fg_color; }

    &.sidebar-placeholder-row { border: solid 1px $selected_bg_color; }

    &.sidebar-new-bookmark-row { color: $selected_bg_color; }

    &:drop(active):not(:disabled) {
      color: $drop_target_color;
      background-color: $drop_target_fill_color;
      // draw vertical indicators
      &:dir(ltr) { box-shadow: inset 4px 0 $drop_target_color; }
      &:dir(rtl) { box-shadow: inset -4px 0 $drop_target_color; }

      &:selected {
        background-color: $drop_target_color;

        &,
        .sidebar-label,
        .sidebar-icon { color: $selected_fg_color; }
      }
    }
  }
}

placesview {
  .server-list-button > image {
  }

  .server-list-button:checked > image {
  }

  row.activatable:hover { background-color: transparent; }

  // this selects the "connect to server" label
  > actionbar > revealer > box > label {
    padding-left: rem(8px);
    padding-right: rem(8px);
  }
}


// /*********
//  * Paned *
//  *********/

paned {
  > separator {
    min-width: 1px;
    min-height: 1px;
    border-style: none;
    background-color: transparent;
    -gtk-icon-source: none; // defeats the ugly default handle decoration
    // using background instead of a border
    // since the border will get rendered twice (?)
    background-image: image($borders_color);
    background-size: $separator_narrow;
    transition: none;

    &:backdrop,
    &:selected { // FIXME: is this needed?
      background-image: image($solid_light_borders_color);
      transition: none;
    }

    window & {
      // do not across over GtkHeaderBar with solid border
      &,
      &:backdrop,
      &:selected {
        // FIXME: still happaned double-border though
        background-image: image($paned_borders_color);
        transition: none;
      }
    }

    window > grid.vertical & { // do not use transparentize
      &,
      &:backdrop,
      &:selected {
        background-image: image($solid_light_borders_color);
        transition: none;
      }
    }

    &.wide {
      min-width: rem(6px);
      min-height: rem(6px);
      margin: 0;
      padding: 0;
      // FIXME: use opaque borders to avoid double-border
      background-color: $bg_color;
      background-image: image($solid_light_borders_color),
                        image($solid_light_borders_color);
      background-size: $separator_wide;

      &:backdrop,
      &:selected { // FIXME: is this needed?
        background-image: image($solid_light_borders_color),
                          image($solid_light_borders_color);
      }
    }
  }

  &.horizontal > separator {
    background-repeat: repeat-y;

    &:dir(ltr) {
      margin: 0 rem(-8px) 0 0;
      padding: 0 rem(8px) 0 0;
      background-position: left;
    }
    &:dir(rtl) {
      margin: 0 0 0 rem(-8px);
      padding: 0 0 0 rem(8px);
      background-position: right;
    }

    &.wide {
      background-repeat: repeat-y, repeat-y;
      background-position: left, right;

      &:dir(ltr),
      &:dir(rtl) { // reset spacing
        margin: 0;
        padding: 0;
      }
    }
  }

  &.vertical > separator {
    margin: 0 0 rem(-8px) 0;
    padding: 0 0 rem(8px) 0;
    background-repeat: repeat-x;
    background-position: top;

    &.wide {
      margin: 0; // reset spacing
      padding: 0;
      background-repeat: repeat-x, repeat-x;
      background-position: bottom, top;
    }
  }
}


// /**************
//  * GtkInfoBar *
//  **************/

infobar {
  padding: rem(5.3px);
  border-width: 0 0 1px;
  border-style: solid;
  // do not use transparentize
  border-color: $solid_light_borders_color;
  background-color: $secondary_dark_color;

  &.info,
  &.question,
  &.warning,
  &.error {
    selection { background-color: darken($selected_bg_color, 10%); }

    *:link { color: mix($selected_fg_color, $selected_bg_color, 80%); }

    progressbar { // use 'white' bit and trough
      trough { background-color: gtkopacity($selected_fg_color, 0.2); }

      progress { background-color: $selected_fg_color; }
    }
  }

  &.info,
  &.question,
  &.warning { // always use dark forefground
    color: if($variant == light, $secondary_fg_color,
                                 $secondary_fixed_fg_color);
  }

  &.error { // use white text for this
    color: $selected_fg_color;
  }

  &.info,
  &.question,
  &.warning,
  &.error {
    button:not(.destructive-action):not(.suggested-action) {
      @extend %button_flat_normal;
      background-color: transparent;
      color: $secondary_fixed_fg_color;
      &:hover {
        @extend %button_flat_hover;
        background-color: transparent;
        color: $fixed_fg_color;
      }
      &:active {
        @extend %button_flat_active;
        background-color: transparent;
        color: $fixed_fg_color;
      }
      &:checked {
        @extend %button_flat_checked;
        background-color: transparent;
        color: $fixed_fg_color;
      }
      &:disabled { color: $insensitive_fixed_fg_color; }
    }
  }

  button {
    &,
    &.text-button,
    &.image-button,
    &.toggle,
    &.combo,
    &.close {
      min-height: $icon_size;
      min-width: $icon_size;
      padding: rem(6.7px);
      border-radius: 2px;
      -gtk-outline-radius: 2px;
    }
  }
}

@each $_type, $_color in (info, $info_bg_color),
                         (question, $question_bg_color),
                         (warning, $warning_bg_color),
                         (error, $error_bg_color) {
  .#{$_type} {
    background-color: if($variant == dark, mix($_color, $bg_color, 75%),
                                           $_color);
  }
}


// /************
//  * Tooltips *
//  ************/

tooltip {
  &.background {
    // FIXME: Eclipse specific tooltip widgets needs non-inverted backgrounds
    // even if alpha-value was 0.1%, so real backgrounds are drawin with
    // background-image property instead.
    background-color: gtkopacity($base_color, 0.001);
    background-image: image(gtkopacity($inverted_dark_color, 0.901));
  }

  &.csd { // asset-based drop-shadows
    border-style: solid;
    border-width: 11px;
    // no need to specify the light-variant specific shadows
    border-image: -gtk-scaled(url("assets/osd-shadow-dark.png"),
                              url("assets/osd-shadow-dark@2.png"))
                  11 / 11px stretch;

    // add inner padding (use non-scalable unit instead)
    > box {
      padding: 10px - 1px; // use symmetrical padding for border-images

      label { padding: if($ref_weight < 1.0, 0px 1px 1px, 1px 2px 2px); }
    }
  }

  label,
  image { color: $inverted_fg_color; } // default foregrounds
}

.tooltip:not(tooltip) {
  // FIXME: This should be purged! Only for ancient Marco.
  background-color: gtkopacity($inverted_dark_color, 0.9);

  > label { // for Marco
    color: $inverted_fg_color;
  }

  // protect the child widget foregrounds for damned Eclipse's debug tooltips
  > * > label { color: $fg_color; }
}


// /*****************
//  * Color Chooser *
//  *****************/

colorswatch {
  // This widget is made of two boxes one on top of the other,
  // the lower box is colorswatch {} the other one is
  // colorswatch > .overlay {}, colorswatch has the programmatically set
  // background, so most of the style is applied to the overlay box.

  box-shadow: $z-depth-1;

  // we need to re-set the shadow here since it get axed by the previous bit
  &:selected {
  }

  // do not use roundness
  &.top,
  &.bottom,
  &.left,
  &.right,
  &:only-child {
    &, .overlay { border-radius: 0; }
  }

  // hover effect
  &:hover { box-shadow: $z-depth-2; }

  // no hover effect for the colorswatch in the color editor
  GtkColorEditor & {
    border-radius: 0; // same radius as the entry
    &:hover { box-shadow: $z-depth-1; }
  }

  // indicator and keynav outline colors
  &.color-dark { color: white; }

  &.color-light { color: gtkopacity(black, 0.8); }

  // border color
  &.overlay,
  &.overlay:selected {
  }

  // make the add color button looks like, well, a button
  &#add-color-button {
    background-image: linear-gradient(to right,
                                      $error_bg_color 25%,
                                      $warning_bg_color 25%,
                                      $warning_bg_color 50%,
                                      $info_bg_color 50%,
                                      $info_bg_color 75%,
                                      $question_bg_color 75%);
    color: white;
  }
}

// colorscale popup
colorchooser .popover.osd {
  padding: 3px;
  border-style: solid;
  border-width: 11px;
  @if $variant == light {
    border-image: -gtk-scaled(url("assets/osd-shadow.png"),
                              url("assets/osd-shadow@2.png"))
                  11 / 11px stretch;
  }
  @else {
    border-image: -gtk-scaled(url("assets/osd-shadow-dark.png"),
                              url("assets/osd-shadow-dark@2.png"))
                  11 / 11px stretch;
  }
  box-shadow: none;
  color: $inverted_fg_color;
  background-color: $inverted_dark_color;

  label {
    color: $inverted_accent_label_color;
    font-weight: 700;
  }
}


// /********
//  * Misc *
//  ********/

// content view (grid/list)
.content-view {
  background-color: $bg_color;

  rubberband { @extend rubberband; }
}

@keyframes volume_hover {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($track_color),
                                    to(transparent));
  }
}

.scale-popup {
  .osd & { @extend %osd; }

  .osd & button.flat { // FIXME: quick hack, redo properly
  }

  .osd & .vertical button,
  .vertical button { // +/- buttons on GtkVolumeButton popup
    border-radius: 100px;
    -gtk-outline-radius: 100px;
    background-color: transparent;
    color: $secondary_fg_color;

    &:first-child { // '+' button
      &:hover {
        @extend %button_flat_hover;
        background: none;
        color: $success_color;
        animation: volume_hover 0.2s linear forwards;
      }
      &:disabled {
        @extend %button_flat_disabled;
        background: none;
        color: gtkopacity($success_color, 0.4);
      }
    }
    &:last-child { // '-' button
      &:hover {
        @extend %button_flat_hover;
        background: none;
        color: $error_color;
        animation: volume_hover 0.2s linear forwards;
      }
      &:disabled {
        @extend %button_flat_disabled;
        background: none;
        color: gtkopacity($error_color, 0.4);
      }
    }
  }

  .osd & button,
  button {
    border-radius: 100px;
    -gtk-outline-radius: 100px;
    background-color: transparent;
    color: $secondary_fg_color;

    &:first-child { // '-' button
      &:hover {
        @extend %button_flat_hover;
        background: none;
        color: $error_color;
        animation: spin_hover 0.2s linear forwards;
      }
      &:disabled {
        @extend %button_flat_disabled;
        background: none;
        color: gtkopacity($error_color, 0.4);
      }
    }
    &:last-child { // '+' button
      &:hover {
        @extend %button_flat_hover;
        background: none;
        color: $success_color;
        animation: spin_hover 0.2s linear forwards;
      }
      &:disabled {
        @extend %button_flat_disabled;
        background: none;
        color: gtkopacity($success_color, 0.4);
      }
    }
  }
}

button.flat.scale { // standalone Speaker/Mic buttons
  // I assume both are image-button *by default*
  // with the image-button/text-button classes automagically applied
  // depending on the button child these selectors can be deleted.
  // @extend %image_button;
  min-width: $icon_size;
  min-height: $icon_size;
  padding: rem(10.7px);
  border-radius: 100px;
  -gtk-outline-radius: 100px;
}

%fb_child_spacing {
  min-height: rem($icon_size * 1.75);
  min-width: rem($icon_size * 1.75);
  margin: 0;
  padding: 0;
}

.floating-bar {
  @extend %osd;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0;
  color: $inverted_secondary_fg_color;
  background-color: $inverted_dark_color;
  font-size: 90%;
  transition: none;

  label { min-height: rem($icon_size * 1.75); }

  button {
    @extend %fb_child_spacing;
    color: $inverted_secondary_accent_label_color;
    &:hover,
    &:active,
    &:checked { color: $inverted_accent_label_color; }
    &:disabled { color: gtkopacity($inverted_accent_label_color, 0.4); }
  }

  // axes left border and border radius
  &.bottom.left {
    border-width: 1px 1px 0 0;
    border-radius: 0 2px + 1px 0 0;
  }

  // axes right border and border radius
  &.bottom.right {
    border-width: 1px 0 0 1px;
    border-radius: 2px + 1px 0 0 0;
  }
}


// /**********************
//  * Window Decorations *
//  *********************/

decoration {
  margin: 10px; // this is used for the resize cursor area
  border-radius: 2px 2px 0 0;
  border-width: 0;
  background-color: transparent;
  box-shadow: $z-depth-4;
  transition-property: box-shadow;
  transition-timing-function: $slope_slow;
  transition-duration: 0.2s;

  &:backdrop {
    // the transparent shadow here is to enforce that the shadow extents don't
    // change when we go to backdrop, to prevent jumping windows.
    // The biggest shadow should be in the same order then in the active state
    // or the jumping will happen during the transition.
    box-shadow: $z-depth-2-backdrop;
  }

  .fullscreen &,
  .maximized & {
    &, &:backdrop { border-radius: 0; }
  }

  @each $_constraint,
        $_shadow in ('', $z-depth-2-backdrop-tiled),
                    ('-top', $z-depth-2-backdrop-tiled-top),
                    ('-bottom', $z-depth-2-backdrop-tiled-bottom),
                    ('-left', $z-depth-2-backdrop-tiled-left),
                    ('-right' $z-depth-2-backdrop-tiled-right) {
    // draw empty shadows + window edges when tiled
    // FIXME: window node was not needed semantically, but Solus build seems
    // to draw tiled-edges in GtkDialogs. Mystery...
    window.tiled#{$_constraint} & {
      border-radius: 0;
      box-shadow: #{$_shadow};
    }
  }

  // server-side decorations as used by mutter
  .ssd & { box-shadow: $z-depth-2; }

  // 'tiled' state in X11-SSD mode
  @each $_constraint,
        $_shadow in ('', $z-depth-2-tiled),
                    ('-top', $z-depth-2-tiled-top),
                    ('-bottom', $z-depth-2-tiled-bottom),
                    ('-left', $z-depth-2-tiled-left),
                    ('-right' $z-depth-2-tiled-right) {
    // draw empty shadows + window edges when tiled
    window.ssd.tiled#{$_constraint} & { box-shadow: #{$_shadow}; }
  }

  .popup & { box-shadow: none; }

  .csd.popup & {
    border-radius: 2px;
    box-shadow: $z-depth-3;
  }

  tooltip.csd & {
    // FIXME: drop-shadows via box-shadow property sometimes causes
    // flickering on its reserved shadow-region, so unset all properties
    // here and embed actual shadows onto tooltip node directly instead...
    all: unset;
  }

  messagedialog.csd & {
    border-radius: 2px;
    box-shadow: $z-depth-4;
    &:backdrop { box-shadow: $z-depth-2-backdrop; }
  }

  .solid-csd & {
    margin: 0;
    padding: 2px + 1px; // actual outset borders + inset border-frame
    border-radius: 0;
    border: none;
    background-color: $solid_light_borders_color;
    box-shadow: inset 0 0 0 2px $inverted_dark_color,
                inset 0 1px $top_edge_borders_color;
  }
}

// Window manager buttons
.csd headerbar:not(.default-decoration),
.solid-csd headerbar:not(.default-decoration) {
  > box.horizontal { // enforce 'gapless' titlebutton placements
    &.left {
      @each $class, $_left, $_right in ('.close', 0, -3px),
                                       ('.maximize', -3px, -3px),
                                       ('.minimize', -3px, -3px),
                                       ('.appmenu', 0, -3px),
                                       ('.icon', 0, -3px) {
        > button.titlebutton#{$class} {
          margin-left: #{$_left};
          margin-right: #{$_right};
        }
      }
    }

    &.right {
      @each $class, $_left, $_right in ('.close', -3px, 0),
                                       ('.maximize', -3px, -3px),
                                       ('.minimize', -3px, -3px),
                                       ('.appmenu', -3px, 0),
                                       ('.icon', -3px, 0) {
        > button.titlebutton#{$class} {
          margin-left: #{$_left};
          margin-right: #{$_right};
        }
      }
    }
  }

  button.titlebutton {
    @extend %fade_effect;
    min-width: $icon_size * 1.5;
    min-height: $icon_size * 1.5;
    padding: if($ref_weight < 1.0,
             rem(($widget_size - $icon_size * 1.5 - 2px) / 2),
             rem(($widget_size - $icon_size * 1.5) / 2));
    border-radius: 100px;
    -gtk-outline-radius: 100px;

    &.icon,
    &.appmenu { // appmenu buttons
      &:checked { // reset fill-area
        background-color: transparent;
        background-image: none;
      }
    }

    // 'indeterminate' is the synthetic wildcard
    &:not(.appmenu):not(.icon):not(:indeterminate) {
      background-image: none;

      > image {
        min-height: $icon_size;
        min-width: $icon_size;
        color: transparent;
        background-size: $icon_size $icon_size;
        background-repeat: no-repeat;
        background-position: center;
      }
    }
    &:backdrop {
      image { opacity: 1.0; }
    }

    // raised 'Close' button
    &.close {
      > image {
        background-image:
          -gtk-scaled(url("assets/window-close.png"),
                      url("assets/window-close@2.png"));
      }

      &:hover {
        @extend %button_hover;
        color: $selected_fg_color;
        background-color: $destructive_color;

        > image {
          background-image:
            -gtk-scaled(url("assets/window-close-active.png"),
                        url("assets/window-close-active@2.png"));
        }
      }
      &:active {
        @extend %button_active;
        color: $selected_fg_color;
        background-color: $selected_bg_color;

        > image {
          background-image:
            -gtk-scaled(url("assets/window-close-active.png"),
                        url("assets/window-close-active@2.png"));
        }
      }
    }

    &.minimize {
      > image {
        background-image:
          -gtk-scaled(url("assets/window-minimize.png"),
                      url("assets/window-minimize@2.png"));
      }

      &:hover,
      &:active {
        color: $inverted_fg_color;
        background-color: $track_color;

        > image {
          background-image:
            -gtk-scaled(url("assets/window-minimize-active.png"),
                        url("assets/window-minimize-active@2.png"));
        }
      }
    }

    &.maximize {
      > image {
        background-image:
          -gtk-scaled(url("assets/window-maximize.png"),
                      url("assets/window-maximize@2.png"));
      }

      &:hover,
      &:active {
        color: $inverted_fg_color;
        background-color: $track_color;

        > image {
          background-image:
            -gtk-scaled(url("assets/window-maximize-active.png"),
                        url("assets/window-maximize-active@2.png"));
        }
      }
    }
  }
}

.csd.maximized headerbar:not(.default-decoration),
.solid-csd.maximized headerbar:not(.default-decoration) {
  button.titlebutton {
    &.maximize {
      > image {
        background-image:
          -gtk-scaled(url("assets/window-unmaximize.png"),
                      url("assets/window-unmaximize@2.png"));
      }

      &:hover,
      &:active {
        > image {
          background-image:
            -gtk-scaled(url("assets/window-unmaximize-active.png"),
                        url("assets/window-unmaximize-active@2.png"));
        }
      }
    }
  }
}

// specific button styling for Mutter's SSDs
.ssd .titlebar {
  .titlebutton {
    image {
      background-size: $titlebutton_small $titlebutton_small;
      background-repeat: no-repeat;
      background-position: center;
    }

    &.close,
    &.minimize,
    &.maximize {
      color: transparent;
      background: none;
      box-shadow: none;
    }

    // tiny 2px padding causes truncation of shadows,
    // so elevate down to depth-1 at hover/active.
    @each $_class,
          $_state,
          $_shadow in ('', '', none),
                      (':hover', '-hover', $z-depth-1),
                      (':active', '-active', $z-depth-1),
                      (':backdrop', '-backdrop', none),
                      (':backdrop:hover', '-backdrop-hover', $z-depth-1),
                      (':backdrop:active', '-backdrop-active', $z-depth-1) {
      &.close#{$_class} {
        box-shadow: #{$_shadow};

        > image {
          @if $ref_weight < 1.0 {
            background-image:
              -gtk-scaled(url("assets/window-close-ssd-eta#{$_state}.png"),
                          url("assets/window-close-ssd-eta#{$_state}@2.png"));
          }
          @else {
            background-image:
              -gtk-scaled(url("assets/window-close-ssd#{$_state}.png"),
                          url("assets/window-close-ssd#{$_state}@2.png"));
          }
        }
      }
    }

    @each $_class, $_state in ('', ''),
                              (':hover', '-hover'),
                              (':active', '-active'),
                              (':backdrop', '-backdrop'),
                              (':backdrop:hover', '-backdrop-hover'),
                              (':backdrop:active', '-backdrop-active') {
      &.minimize#{$_class} > image {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(url("assets/window-minimize-ssd-eta#{$_state}.png"),
                        url("assets/window-minimize-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-minimize-ssd#{$_state}.png"),
                        url("assets/window-minimize-ssd#{$_state}@2.png"));
        }
      }

      &.maximize#{$_class} > image {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(url("assets/window-maximize-ssd-eta#{$_state}.png"),
                        url("assets/window-maximize-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-maximize-ssd#{$_state}.png"),
                        url("assets/window-maximize-ssd#{$_state}@2.png"));
        }
      }
    }
  }
}

.maximized.ssd .titlebar {
  .titlebutton {
    @each $_class, $_state in ('', ''),
                              (':hover', '-hover'),
                              (':active', '-active'),
                              (':backdrop', '-backdrop'),
                              (':backdrop:hover', '-backdrop-hover'),
                              (':backdrop:active', '-backdrop-active') {
      &.maximize#{$_class} > image {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(
              url("assets/window-unmaximize-ssd-eta#{$_state}.png"),
              url("assets/window-unmaximize-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-unmaximize-ssd#{$_state}.png"),
                        url("assets/window-unmaximize-ssd#{$_state}@2.png"));
        }
      }
    }
  }
}

// specific button styling for Metacity's CSDs and XWayland
headerbar.titlebar.default-decoration {
  &:backdrop > * {
    opacity: 1.0; // unset fade_effect
  }

  button.titlebutton {
    @extend %fade_effect;
    background-size: $titlebutton_small $titlebutton_small;
    background-repeat: no-repeat;
    background-position: center;

    &.close,
    &.minimize,
    &.maximize {
      color: transparent;
      background: none;
      box-shadow: none;
      animation: none; // FIXME: XWayland hides :active buttons
    }
  }

  button.titlebutton {
    @each $_class,
          $_state,
          $_shadow in ('', '', none),
                      (':hover', '-hover', $z-depth-1),
                      (':active', '-active', $z-depth-1),
                      (':backdrop', '-backdrop', none),
                      (':backdrop:hover', '-backdrop-hover', $z-depth-1),
                      (':backdrop:active', '-backdrop-active', $z-depth-1) {
      &.close#{$_class} {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(url("assets/window-close-ssd-eta#{$_state}.png"),
                        url("assets/window-close-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-close-ssd#{$_state}.png"),
                        url("assets/window-close-ssd#{$_state}@2.png"));
        }

        box-shadow: #{$_shadow};
      }
    }

    @each $_class, $_state in ('', ''),
                              (':hover', '-hover'),
                              (':active', '-active'),
                              (':backdrop', '-backdrop'),
                              (':backdrop:hover', '-backdrop-hover'),
                              (':backdrop:active', '-backdrop-active') {
      &.minimize#{$_class} {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(
              url("assets/window-minimize-ssd-eta#{$_state}.png"),
              url("assets/window-minimize-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-minimize-ssd#{$_state}.png"),
                        url("assets/window-minimize-ssd#{$_state}@2.png"));
        }
      }

      &.maximize#{$_class} {
        @if $ref_weight < 1.0 {
          background-image:
            -gtk-scaled(
              url("assets/window-maximize-ssd-eta#{$_state}.png"),
              url("assets/window-maximize-ssd-eta#{$_state}@2.png"));
        }
        @else {
          background-image:
            -gtk-scaled(url("assets/window-maximize-ssd#{$_state}.png"),
                        url("assets/window-maximize-ssd#{$_state}@2.png"));
        }
      }
    }
  }

  .maximized & {
    button.titlebutton {
      @each $_class, $_state in ('', ''),
                                (':hover', '-hover'),
                                (':active', '-active'),
                                (':backdrop', '-backdrop'),
                                (':backdrop:hover', '-backdrop-hover'),
                                (':backdrop:active', '-backdrop-active') {
        &.maximize#{$_class} {
          @if $ref_weight < 1.0 {
            background-image:
              -gtk-scaled(
                url("assets/window-unmaximize-ssd-eta#{$_state}.png"),
                url("assets/window-unmaximize-ssd-eta#{$_state}@2.png"));
          }
          @else {
            background-image:
              -gtk-scaled(url("assets/window-unmaximize-ssd#{$_state}.png"),
                          url("assets/window-unmaximize-ssd#{$_state}@2.png"));
          }
        }
      }
    }
  }
}


// /***********************
//  * catch all extend :) *
//  ***********************/

%selected_items {
  background-color: $selected_bg_color;
  color: $selected_fg_color;
  &:disabled {
    &, &:backdrop { color: $insensitive_selected_fg_color; }
  }
}

.monospace { font-family: Monospace; }


// /**********************
//  * Touch Copy & Paste *
//  *********************/

// touch selection handlebars for the Popover.osd above
%handle {
  -gtk-icon-source:
    -gtk-scaled(
      url('assets/slider-horz-scale-has-marks-above#{$asset_suffix}.png'),
      url('assets/slider-horz-scale-has-marks-above#{$asset_suffix}@2.png'));
}

cursor-handle {
  min-width: 20px;
  min-height: 25px;
  padding: 0 10px;
  border: none;
  background: none;
  box-shadow: none;

  &.top,
  &.bottom {
    &:dir(ltr),
    &:dir(rtl) {
      @extend %handle;
      -gtk-icon-shadow: $z-depth-2;
    }
  }

  &.top:dir(ltr),
  &.bottom:dir(rtl) {
    -gtk-icon-transform: rotate(45deg)
                         scale(0.9);
    &:hover,
    &:active {
      -gtk-icon-transform: rotate(45deg)
                           scale(1.0);
    }
  }

  &.top:dir(rtl),
  &.bottom:dir(ltr) {
    -gtk-icon-transform: rotate(-45deg)
                         scale(0.9);
    &:hover,
    &:active {
      -gtk-icon-transform: rotate(-45deg)
                           scale(1.0);
    }
  }

  &.insertion-cursor {
    &:dir(ltr),
    &:dir(rtl) {
      @extend %handle;
      -gtk-icon-transform: scale(0.9);
      -gtk-icon-shadow: $z-depth-2;
      &:hover,
      &:active { -gtk-icon-transform: scale(1.0); }
    }
  }
}

// Decouple the font of context menus from their entry/textview
.context-menu {
  font-weight: 400;
  font-size: 100%;
}


// /*******************
//  * Shortcut Window *
//  *******************/

.keycap {
  min-width: rem(20px, $sw: 1.0);
  min-height: rem(20px, $sw: 1.0);
  padding: rem((20px - 13.3px + 1.3px) / 2, $sw: 1.0)
           rem((20px - 13.3px) / 2, $sw: 1.0)
           rem((20px - 13.3px - 1.3px) / 2, $sw: 1.0);
  border: none;
  border-radius: 2px;
  color: $inverted_fg_color;
  background-color: if($variant == light, $inverted_base_color,
                                          $inverted_dark_color);
  box-shadow: $z-depth-1,
              inset 0 1px $highlight_color;
  font-weight: 700;

  // shortcut keycaps for Gnome-builder
  tooltip.background & {
    background-color: $suggested_color;
    color: $selected_fg_color;
  }
}

// FIXME: needs to be done widget by widget,
// this wildcard should really die
*:not(decoration):not(window):drop(active) {
  &, &:focus {
    border-color: $drop_target_color;
    box-shadow: inset 0 0 0 1px $drop_target_color;
    caret-color: $drop_target_color;
  }
}


// /****************
//  * Emoji Picker *
//  ****************/

popover.emoji {
  &-picker scrolledwindow.view {
    margin-top: 2px;
    border: 1px solid $borders_color;
    background-image: none;
  }

  &-completion {
    arrow {
      border: none;
      background: none;
    }

    contents row box { padding: 2px 10px; } // NEEDS_REVIEW
  }
}

flowboxchild.emoji { // emoji tiled view
  padding: 0;
  border-radius: 2px;
  font-weight: 400;

  label {
    padding: 4px;
    font-size: $icon_size; // use fixed label size
    color: $secondary_fg_color;
  }

  widget:hover label { // no active/checked states
    background-color: $track_color;
    color: $fg_color;
  }
}

popover.emoji-picker button.emoji-section.flat {
  min-height: rem($widget_size - 4px, $sw: 1.0);
  min-width: rem($widget_size - 4px, $sw: 1.0);
  margin: 2px 0 0;
  padding: 0;
  border-radius: 100px;
  -gtk-outline-radius: 100px;

  label {
    padding: 0; // unset padding
    font-size: $icon_size * 1.5; // use fixed label size
  }

  &:checked {
    &, &:hover { color: $selected_bg_color; }
  }
}

