
$ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$button_transition: all 200ms $ease-out-quad;
$backdrop_transition: 200ms ease-out;
$focus_transition: outline-width 200ms $ease-out-quad, outline-offset 200ms $ease-out-quad;
$asset_suffix: if($variant == 'dark', '-dark', ''); // use dark assets in dark variant
$header_asset_suffix: if($header == 'dark', '-dark', ''); // use dark assets in dark variant

//
// Base States
//
.background {
  &.csd {
    border-radius: 2px;
  }

  color: $fg_color;
  background-color: if($trans == 'true', rgba($bg_color, 1), $bg_color); // without this headerbar transparency doesn't seem to work

  &:backdrop {
    text-shadow: none;
    -gtk-icon-shadow: none;
  }
}

#desktopwindow.background {
  background-color: transparent;
  border: none;
}

dnd {
  color: $fg_color;
}

.normal-icons {
  -gtk-icon-size: 16px;
}

.large-icons {
  -gtk-icon-size: 32px;
}

spinner:disabled,
arrow:disabled,
scrollbar:disabled,
check:disabled,
radio:disabled,
treeview.expander:disabled { -gtk-icon-filter: opacity(0.5); }

.view, %view {
  color: rgba($text_color, 1);
  background-color: $base_color;
  &:hover { color: $fg_color; }

  &:selected {
    &:focus, & {
      @extend %normal_selected_items;

      border-radius: 2px;
    }

    &:hover { background-color: mix(black, $menu_selected_color, 10%); }
  }
}

textview {
  > text {
    @extend %view;

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

  &:drop(active) {
    caret-color: $drop_target_color;
  }
}

textview border { background-color: mix($bg_color, $base_color, 50%); }

iconview {
  @extend %view;
  @include focus-ring();
  &:hover, &:active, &:selected { border-radius: 2px; }

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

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

rubberband {
  border: 1px solid darken($selected_bg_color, 10%);
  background-color: rgba(darken($selected_bg_color, 10%), 0.2);
}

flowbox {
  > rubberband { @extend rubberband; }

  > flowboxchild {
    padding: 3px;
    border-radius: 2px;

    @include focus-ring();

    &:selected {
      @extend %selected_items;

      outline-color: $alt_focus_border_color;
    }
  }
}

gridview {
  > rubberband { @extend rubberband; }

  > child {
    padding: 3px;
    transition: $focus_transition;

    @include focus-ring();

    &:selected {
      outline-color: $alt_focus_border_color;

      @extend %selected_items;
    }

    box { //cells
      border-spacing: 8px; //label separation
      margin: 12px;
    }
  }
}

coverflow cover {
  color: $text_color;
  background-color: $base_color;
  border: 1px solid black;
}

label {
  @include focus-ring();

  &.separator {
    @extend .dim-label;
  }

  > selection {
    color: $selected_fg_color;
    background-color: $selected_bg_color;
  }

  &:disabled {
    color: $insensitive_fg_color;

    button &,
    entry &,
    row,
    headerbar { color: inherit; }

    selection { color: mix($selected_fg_color, $selected_bg_color, 50%); }
  }

  &.error {
    color: $error_color;
    &:disabled { color: transparentize($error_color,0.5); }
  }
}

.dim-label {
  opacity: 0.55;
  text-shadow: none;
}

window.assistant {
  .sidebar {
    padding: 3px;
    background-color: $base_color;
    border-top: 1px solid $borders_color;
  }

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

  .sidebar > label { padding: 6px 12px; }

  .sidebar > label.highlight {
    background-color: $selected_bg_color;
    color: $selected_fg_color;
    border-radius: 2px;
  }
}

window.aboutdialog image.large-icons {
  -gtk-icon-size: 128px;
}

%osd {
  color: $osd_fg_color;
  background-color: $osd_bg_color;
  border-radius: 3px;
}

.osd {
  @extend %osd;
  border: none;
  padding: 6px;
  margin: 6px;
  box-shadow: 0 3px 8px rgba(black, 0.15), 0 0 0 1px $borders_color;
  // -gtk-icon-shadow: 0 1px black;

  &.circular { border-radius: 100%; }
}

//
// Spinner Animations
//
@keyframes spin {
  to { transform: rotate(1turn); }
}

spinner {
  background: none;
  opacity: 0; // non spinning spinner makes no sense
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');

  &:checked {
    opacity: 1;
    animation: spin 1s linear infinite;

    &:disabled {
      opacity: 0.5;
    }
  }
}

//
// General Typography
//
.large-title {
  font-weight: 300;
  font-size: 24pt;
}

.title-1 {
  font-weight: 800;
  font-size: 20pt;
}

.title-2 {
  font-weight: 800;
  font-size: 15pt;
}

.title-3 {
  font-weight: 700;
  font-size: 15pt;
}

.title-4 {
   font-weight: 700;
   font-size: 13pt;
}

.heading {
  font-weight: 700;
  font-size: 11pt;
}

.body {
  font-weight: 400;
  font-size: 11pt;
}

.caption-heading {
  font-weight: 700;
  font-size: 9pt;
}

.caption {
  font-weight: 400;
  font-size: 9pt;
}

//
// Text Entries
//
%entry,
entry {
  min-height: 22px;
  border: 1px solid;
  padding: 2px 8px;
  caret-color: currentColor;
  border-radius: 3px;
  border-spacing: 3px;
  transition: $button_transition;
  background-clip: if($variant=='light', border-box, padding-box);

  &.search { border-radius: 1000px; }

  @include entry(normal);

  // @include focus-ring($focus-state: 'focus-within');

  > image { // icons inside the entry
    color: mix($fg_color,$base_color, 80%);

    &.left { margin-right: 6px; }
    &.right { margin-left: 6px; }
  }

  > text > placeholder {
    @extend .dim-label;
  }

  @at-root %flat_entry, &.flat {
    &:focus-within, &:backdrop, &:disabled, &:backdrop:disabled, & {
      min-height: 0;
      padding: 2px;
      background-image: none;
      border-color: transparent;
      border-radius: 0;
    }
  }

  &:focus-within {
    background-clip: if($variant == 'light', border-box, padding-box);
    @include entry(focus);

    > placeholder {
      opacity: 0; /* We hide placeholders on focus */
    }
  }

  &:disabled { @include entry(insensitive); }

  > text > selection { @extend %selected_items; }

  // error and warning style
  @each $e_type, $e_color, $e_fg_color in (warning, $warning_color, $warning_fg_color),
                                          (error, $error_color, $error_fg_color),
                                          (success, $success_color, $success_fg_color),
                                          // entry.search-missing for Gnome-Builder
                                          (search-missing, $error_color, $error_fg_color) {
    &.#{$e_type} {
      color: $e_fg_color;
      border-color: if($variant=='light', $e_color, $entry_border);
      background-color: mix($e_color, $base_color, 60%);
      @include focus-ring($focus-state: 'focus-within', $fc: transparentize($e_color, 0.5));

      > image {
        color: $e_fg_color;
      }

      &:focus-within {
        color: $e_fg_color;
        background-color: $e_color;
        box-shadow: none;
      }

      > selection {
        background-color: $e_fg_color;
        color: $e_color;
      }
    }
  }

  > image { // entry icons colors
    color: mix($fg_color, $base_color, 80%);

    &:hover { color: $fg_color; }

    &:active { color: $selected_bg_color; }
  }

  &.password image.caps-lock-indicator {
    color: mix($insensitive_fg_color, $base_color, 80%);
  }

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

  .osd & {
    @include entry(osd);
    &:focus-within { @include entry(osd-focus); }
    &:disabled { @include entry(osd-insensitive); }
  }

  > progress {
    margin-bottom: 2px;
  }

  progress > trough > progress {
    background-color: transparent;
    background-image: none;
    border-radius: 0;
    border-width: 0 0 2px;
    border-color: $progress_color;
    border-style: solid;
    box-shadow: none;
  }

   // linked entries
  .linked:not(.vertical) > & { @extend %linked; }

  .linked:not(.vertical) > &:drop(active) + &,
  .linked:not(.vertical) > &:drop(active) + button,
  .linked:not(.vertical) > &:drop(active) + menubutton > button,
  .linked:not(.vertical) > &:drop(active) + dropdown > button,
  .linked:not(.vertical) > &:drop(active) + colorbutton > button,
  .linked:not(.vertical) > &:drop(active) + fontbutton > button,
  .linked:not(.vertical) > &:drop(active) + filechooserbutton > button,
  .linked:not(.vertical) > &:drop(active) + filechooserbutton > combobox > box > button.combo,
  .linked:not(.vertical) > &:drop(active) + appchooserbutton > combobox > box > button.combo,
  .linked:not(.vertical) > &:drop(active) + combobox > box > button.combo { border-left-color: $drop_target_color; }

  // Vertically linked entries
  // FIXME: take care of "colored" entries
  .linked.vertical > & {
    @extend %linked_vertical;

    // brighter border between linked entries
    &:not(:disabled) + entry:not(:disabled),
    &:not(:disabled) + %entry:not(:disabled) {
      border-top-color: mix($borders_color, $base_color, 30%);
    }

    // brighter border between linked insensitive entries
    &:disabled + %entry:disabled,
    &:disabled + entry:disabled { border-top-color: mix($borders_color, $base_color, 30%); }

    + %entry:drop(active):not(:only-child),
    + entry:drop(active):not(:only-child) { border-top-color: $drop_target_color; }

    &:drop(active):not(:only-child) {
      + %entry,
      + entry,
      + button,
      + menubutton > button,
      + dropdown > button,
      + colorbutton > button,
      + fontbutton > button,
      + filechooserbutton > button,
      + filechooserbutton > combobox > box > button.combo,
      + appchooserbutton > combobox > box > button.combo,
      + combobox > box > button.combo { border-top-color: $drop_target_color; }
    }
  }
}

treeview entry {
  &:focus-within {
    &:dir(rtl), &:dir(ltr) { // specificity bump hack
      background-color: $base_color;
      transition-property: color, background;
    }
  }

  &.flat, & {
    border-radius: 0;
    background-image: none;
    background-color: $base_color;

    &:focus-within { border-color: $selected_bg_color; }
  }
}

// Editable Labels
editablelabel > stack > text {
  @include entry(normal);
}

//
// Buttons
//

// stuff for .needs-attention
$_dot_color: if($variant=='light', $selected_bg_color,
                                   lighten($selected_bg_color,15%));

@keyframes needs_attention {
  from { background-image: radial-gradient(farthest-side, $_dot_color 0%, transparentize($_dot_color, 1) 0%); }
  to { background-image: radial-gradient(farthest-side, $_dot_color 95%, transparentize($_dot_color, 1)); }
}

%button {
  border-width: 1px;
  border-style: solid;
  @include button(normal);

  &, &:hover, &:active, &:checked, &:disabled {
    background-clip: if($variant=='light', border-box, padding-box);
  }

  &:hover {
    @include button(hover);
  }

  &:active, &.keyboard-activating, &:checked {
    @include button(active);
  }

  &:disabled {
    @include button(insensitive);

    &:active, &:checked {
      @include button(insensitive-active);
    }
  }
}

%flat_button {
  border-width: 1px;
  border-style: solid;
  @include button(undecorated);

  &, &:hover, &:active, &:checked, &:disabled {
    background-clip: if($variant=='light', border-box, padding-box);
  }

  &:hover {
    @include button(hover);
  }

  &:active, &:checked {
    @include button(active);
  }

  &:disabled {
    @include button(insensitive);
    @include button(undecorated);
  }
}

button {
  min-height: 22px;
  min-width: 20px;
  transition: $button_transition;
  border-radius: 3px;
  padding: 2px 6px;
  @include focus-ring();
  @extend %button;

  &:hover {
    -gtk-icon-filter: brightness(1.2);
  }

  &:active, &:checked {
    transition-duration: 50ms;

    &:not(:disabled) label:disabled { color: inherit; opacity: 0.6; }
  }

  &.flat {
    transition: none;
    @extend %flat_button;

    &:hover,
    &:active,
    &:checked { transition: $button_transition; }

    &:hover {
      transition-duration: 350ms;
    }
  }

  &.image-button {
    min-width: 24px;
    padding-left: 5px;
    padding-right: 5px;
  }

  &.text-button {
    padding-left: 12px;
    padding-right: 12px;
  }

  &.text-button.image-button {
    padding-left: 5px;
    padding-right: 5px;

    label {
      &:first-child {
        padding-left: 8px;
        padding-right: 2px;
      }

      &:last-child {
        padding-right: 8px;
        padding-left: 2px;
      }

      &:only-child {
        padding-left: 8px;
        padding-right: 8px;
      }
    }

    &.popup { padding-right: 8px; padding-left: 8px; }
  }

  @at-root %button_basic_drop_active,
  &:drop(active) {
    color: $drop_target_color;
    border-color: $drop_target_color;
    box-shadow: inset 0 0 0 1px $drop_target_color;
  }

  // big standalone buttons like in Documents pager
  &.osd {
    color: $osd_fg_color;
    background-color: $osd_bg_color;
    border-color: darken($osd_bg_color, 8%);
    box-shadow: none;

    &.image-button {
      padding: 0;
      min-height: 36px;
      min-width: 36px;
    }

    &:hover { color: $selected_bg_color; }
    &:active, &:checked { @include button(osd-active); }
    &:disabled { @include button(osd-insensitive); }
  }

  //overlay / OSD style
  @at-root %osd_button,
  .osd & {
    @include button(osd);
    box-shadow: none;

    &:hover { @include button(osd-hover); }

    &:active, &:checked {
      background-clip: padding-box;
      @include button(osd-active);
    }

    &:disabled { @include button(osd-insensitive); }

    &.flat {
      @include button(undecorated);
      box-shadow: none;

      &:hover { @include button(osd-hover); }

      &:disabled {
        @include button(osd-insensitive);
        background-image: none;
      }

      &:active, &:checked { @include button(osd-active); }
    }
  }

  .osd .linked:not(.vertical):not(.path-bar) > &:hover:not(:checked):not(:active):not(:only-child),
  .osd .linked:not(.vertical):not(.path-bar) > &:hover:not(:checked):not(:active) + &:not(:checked):not(:active) { box-shadow: none; }

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color, $b_fg in (suggested-action, $suggested_color, $suggested_fg_color),
                                    (destructive-action, $destructive_color, $destructive_fg_color) {
    &.#{$b_type} {
      @include button(suggested_destructive, $b_color, $b_fg);

      &.flat {
        @include button(undecorated);
        color: $b_color;
      }

      &:hover {
        @include button(suggested_destructive, lighten($b_color, 5%), $b_fg);
      }

      &:active, &:checked {
        @include button(suggested_destructive, lighten($b_color, 10%), $b_fg);
      }

      &.flat:disabled {
        @include button(undecorated);
        color: $insensitive_fg_color;
      }

      &:disabled { @include button(insensitive); }
    }
  }

  stackswitcher > & {
    // 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: -3px; // needs to be set or it gets overridden by GtkRadioButton outline-offset

    > label {
      padding-left: 6px;  // label padding
      padding-right: 6px; //
    }

    > image {
      padding-left: 6px;
      padding-right: 6px;
      padding-top: 3px;
      padding-bottom: 3px;
    }

    &.text-button {
      padding-left: 10px;
      padding-right: 10px;
    }

    &.image-button {
      padding-left: 2px;
      padding-right: 2px;
    }

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

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

  // hide separators
  &.font,
  &.file {
    separator { background-color: transparent; }
    > box { border-spacing: 6px; }
    > box > box > label { font-weight: bold; }
  }

  .linked:not(.vertical) > & { @extend %linked; }
  .linked.vertical > & { @extend %linked_vertical; }
}

%circular_button,
button.circular {
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 1000px;

  label { padding: 0; }
}

%needs_attention {
  // the dot is drawn by using two radial gradient, the first one is the actual dot, the other
  // simulates the shadow labels and icons normally have in buttons.
  animation: needs_attention 150ms ease-in;

  background-image: radial-gradient(farthest-side, $_dot_color 96%, transparentize($_dot_color,1 ));
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;

  @if $variant == 'light' { background-position: right 3px, right 4px; }

  @else { background-position: right 3px, right 2px; }

  &:backdrop { background-size: 6px 6px, 0 0;}

  &:dir(rtl) {
    @if $variant == 'light' { background-position: left 3px, left 4px; }

    @else { background-position: left 3px, left 2px; }
  }
}

// Some crazy linking stuff
@mixin linking_rules($a:0.3, $var:$variant, $vert:'false', $entry_rules:'true', $button_rules:'true',
                     $e_border:$entry_border, $b_border:$button_border) {

  $_border: if($vert=='false', left, top);

  @if $entry_rules=='true' {
    > entry + entry {
      border-#{$_border}-color: rgba($e_border, $a);
      margin-left: 0;
    }

    > entry.error + entry,
    > entry + entry.error { border-#{$_border}-color: $error_color; }

    > entry.warning + entry,
    > entry + entry.warning { border-#{$_border}-color: $warning_color; }

    > entry.error + entry.warning,
    > entry.warning + entry.error { border-#{$_border}-color: mix($error_color, $warning_color, 50%);}

    @each $e_type, $e_color in (':focus-within',$selected_bg_color),
                               (':drop(active)', $drop_target_color),
                               ('.warning:focus-within', $warning_color),
                               ('.error:focus-within', $error_color) {

      > entry + entry#{$e_type}:not(:last-child),
      > entry + entry#{$e_type}:last-child { border-#{$_border}-color: $e_color; }

      > entry#{$e_type}:not(:only-child) {
        + entry,
        + button,
        + combobox > box > button.combo {
          border-#{$_border}-color: $e_color;
          margin-left: 0;
        }
      }
    }

    > button:active + entry,
    > button:checked + entry { border-#{$_border}-color: $selected_bg_color; }
  }

  @if $entry_rules=='false' {
    > entry + entry,
    > entry.error + entry,
    > entry + entry.error,
    > entry.warning + entry,
    > entry + entry.warning,
    > entry.error + entry.warning,
    > entry.warning + entry.error { border-#{$_border}-color: $e_border; }

    @each $e_type, $e_color in (':focus-within',$selected_bg_color),
                               (':drop(active)', $drop_target_color),
                               ('.warning:focus-within', $warning_color),
                               ('.error:focus-within', $error_color) {

      > entry + entry#{$e_type}:not(:last-child),
      > entry + entry#{$e_type}:last-child { border-#{$_border}-color: $e_color; }

      > entry#{$e_type}:not(:only-child) {
        + entry { border-#{$_border}-color: $e_border; }
      }

      > entry#{$e_type}:not(:only-child) {
        + button,
        + combobox > box > button.combo {
          &:not(:hover):not(:active):not(:checked) {
            border-#{$_border}-color: transparent;
          }
        }
      }

      > entry#{$e_type}:not(:only-child) {
        + button:hover,
        + combobox > box > button.combo:hover { border-#{$_border}-color: $e_border; }
      }
    }

    > button:active + entry,
    > button:checked + entry { border-#{$_border}-color: $e_border; }
  }

  @if $button_rules=='true' {
    $_uncolored_button: 'button:not(:checked):not(:active):not(.suggested-action):not(.destructive-action)';

    > button + button {
      border-#{$_border}-style: none;
      margin-left: 0;
    }

    > #{$_uncolored_button}:hover:not(:only-child),
    > #{$_uncolored_button}:hover + #{$_uncolored_button} { box-shadow: inset if($vert=='false', 1px 0, 0 1px) $b_border; }

    > #{$_uncolored_button}:disabled:not(:only-child),
    > #{$_uncolored_button}:disabled + #{$_uncolored_button}:not(:hover) { box-shadow: inset if($vert=='false', 1px 0, 0 1px) $b_border; }

    > button:active + #{$_uncolored_button}:hover,
    > button:checked + #{$_uncolored_button}:hover,
    > button.suggested-action + #{$_uncolored_button}:hover,
    > button.destructive-action + #{$_uncolored_button}:hover,
    > entry + #{$_uncolored_button}:hover:not(:only-child),
    > #{$_uncolored_button}:first-child:disabled,
    > #{$_uncolored_button}:disabled + #{$_uncolored_button}:disabled,
    > #{$_uncolored_button}:first-child:hover,
    > button:active + #{$_uncolored_button}:disabled,
    > button:checked + #{$_uncolored_button}:disabled,
    > button.suggested-action + #{$_uncolored_button}:disabled,
    > button.destructive-action + #{$_uncolored_button}:disabled,
    > entry + #{$_uncolored_button}:disabled:not(:only-child) { box-shadow: none; }
  }

  @if $button_rules=='false' {
    $_uncolored_button: 'button:not(:checked):not(:active):not(.suggested-action):not(.destructive-action)';

    > button + button { border-#{$_border}-style: solid; }

    > #{$_uncolored_button}:hover:not(:only-child),
    > #{$_uncolored_button}:hover + #{$_uncolored_button} { box-shadow: none; }

    > #{$_uncolored_button}:disabled:not(:only-child),
    > #{$_uncolored_button}:disabled + #{$_uncolored_button}:not(:hover) { box-shadow: none; }
  }
}

// Fix for libadwiata
@each $widget, $child in ("button",      ""),
                         ("menubutton",  "> button"),
                         ("dropdown",    "> button"),
                         ("colorbutton", "> button"),
                         ("fontbutton",  "> button"),
                         ("tabbutton",   "> button"),
                         ("entry",       "") {
  .linked:not(.vertical) > {
    #{$widget} {
      &:dir(ltr):not(:first-child) #{$child},
      &:dir(rtl):not(:last-child) #{$child} {
        margin-left: 0;
      }
    }
  }

  .linked.vertical {
    #{$widget} {
      &:not(:first-child) #{$child} {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        margin-top: 0;
      }
    }
  }
}

// special case, because path-bars are bugged
@mixin pathbar_linking_rules($sep_color:$disable_borders_color) {

  > button + button { border-left-style: none; }

  > button:hover:not(:checked):not(:active):not(:only-child) {

    // &:hover {
    //   box-shadow: none;
    // }

    &:first-child:hover { box-shadow: none; }
    &:last-child:hover { box-shadow: none; }
  }
}

// Apply the rules defined above
.linked:not(.vertical) {
  &:not(.path-bar) { @include linking_rules(); }
  &.path-bar { @include pathbar_linking_rules(); }
  .osd & { @include linking_rules($e_border:$osd_entry_border, $b_border:$osd_button_border); }
}

.linked.vertical { @include linking_rules($vert:'true'); }

headerbar, .titlebar {
  .linked:not(.vertical):not(.path-bar) {
    @include linking_rules($entry_rules:'false', $button_rules:'false', $e_border: $header_entry_border, $b_border: transparent);
  }
}

%linked_middle {
  border-radius: 0;
  border-right-style: none;
  background-clip: if($variant=='light', border-box, padding-box);
}

%linked {
  @extend %linked_middle;
  &:first-child {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
  }
  &:last-child {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    border-right-style: solid;
  }
  &:only-child {
    border-radius: 3px;
    border-style: solid;
  }
}

%linked-flat {
  @extend %linked_middle;
  &:first-child {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 0;
  }
  &:last-child {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 0;
    border-right-style: solid;
  }
  &:only-child {
    border-radius: 3px 3px 0 0;
    border-style: solid;
  }
}

%linked_vertical_middle {
  border-radius: 0;
  border-bottom-style: none;
}

%linked_vertical{
  @extend %linked_vertical_middle;
  &:first-child {
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
  }
  &:last-child {
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;
    border-bottom-style: solid;
  }
  &:only-child {
    border-radius: 3px;
    border-style: solid;
  }
}

%undecorated_button {
  border-color: transparent;
  background-color: transparent;
  background-image: none;
  box-shadow: none;
  text-shadow: none;
  -gtk-icon-shadow: none;
}

%linked_not_left {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

%linked_not_right {
  border-right-style: none;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

%linked_not_top {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

%linked_not_bottom {
  border-bottom-style: none;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.linked:not(.vertical) > menubutton,
.linked:not(.vertical) > dropdown,
.linked:not(.vertical) > colorbutton,
.linked:not(.vertical) > fontbutton,
.linked:not(.vertical) > filechooserbutton {
  &:dir(ltr) {
    &:not(:first-child) > button { @extend %linked_not_left; }
    &:not(:last-child) > button { @extend %linked_not_right; }
  }

  &:dir(rtl) {
    &:not(:first-child) > button { @extend %linked_not_right; }
    &:not(:last-child) > button { @extend %linked_not_left; }
  }
}

.linked.vertical > menubutton,
.linked.vertical > dropdown,
.linked.vertical > colorbutton,
.linked.vertical > fontbutton,
.linked.vertical > filechooserbutton {
  &:not(:first-child) > button { @extend %linked_not_top; }
  &:not(:last-child) > button { @extend %linked_not_bottom; }
}

// menu buttons
modelbutton.flat {
  min-height: 24px;
  padding-left: 6px;
  padding-right: 6px;
  outline-offset: -3px;
  border-radius: 2px;
  @extend %undecorated_button;

  &:hover {
    background-color: $menu_selected_color;
    color: $fg_color;
  }

  &:active {
    color: $fg_color;
    background-color: $menu_active_color;
  }

  &:selected { @extend %normal_selected_items; }

  &:disabled { color: $insensitive_fg_color; }
}

modelbutton.flat arrow {
  background: none;
  min-width: 16px;
  min-height: 16px;
  opacity: 0.3; //dim icon

  &:hover, &:selected, &:focus { background: none; }

  &.left { -gtk-icon-source: -gtk-icontheme("go-previous-symbolic"); }

  &.right { -gtk-icon-source: -gtk-icontheme("go-next-symbolic"); }
}

/* list buttons */
/* tone down as per new designs, see issue #1473 */
%list_button,
list > row button.image-button:not(.flat) {
  @extend %undecorated_button;
  border: 1px solid transparentize($borders_color, .5);
  &:hover { @include button(hover); }
  &:active,
  &:checked { @include button(active); }

  @each $b_type, $b_color in (suggested-action, $selected_bg_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} { // allow colored buttons in lists #3643
      @include button(suggested_destructive, $b_color, white);
      @include focus-ring($fc: $alt_focus_border_color);
    }
  }
}


//
// Links
//

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

link, %links {
  color: $link_color;
  text-decoration: underline;

  &:visited {
    color: $link_visited_color;
    *:selected & { color: mix($selected_fg_color, $selected_bg_color, 60%); }
  }

  &:hover {
    color: lighten($link_color, 10%);
    *:selected & { color: mix($selected_fg_color, $selected_bg_color, 90%); }
  }

  &:active {
    color: $link_color;
    *:selected & { color: mix($selected_fg_color, $selected_bg_color, 80%); }
  }

  &:selected,
  *:selected & { @extend %link_selected; }
}

link {
  @include focus-ring();
}

button.link {
  @extend %links;

  &,
  &:hover,
  &:active,
  &:checked {
    @extend %undecorated_button;

    text-shadow: none;
  }

  > label {
    text-decoration: underline;
  }
}

//
// Spinbuttons
//

%spinbutton_horz_entry {
  min-width: 28px;
  // reset all the other props since the spinbutton node is styled here
  background: none;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 6px;
  margin: 0;
}

spinbutton {
  &:not(.vertical) {
    @extend %entry;
    padding: 0;
    border-spacing: 0;
    outline: none;

    > text {
      @extend %spinbutton_horz_entry;
    }

    > button.image-button.up:not(.flat),
    > button.image-button.down:not(.flat) {
      min-height: 16px;
      margin: 0;
      padding-bottom: 0;
      padding-top: 0;
      color: mix($fg_color, $base_color, 90%);
      background-image: none;
      border-style: none none none solid;
      border-color: $borders_color;
      border-radius: 0;
      box-shadow: none;

      &:dir(rtl) { border-style: none solid none none; }

      &:hover {
        color: $fg_color;
        background-color: rgba($fg_color, 0.1);
      }

      &:disabled {
        color: transparentize($insensitive_fg_color, 0.7);
        background-color: transparent;
        border-color: $disable_borders_color;
      }

      &:active {
        background-color: rgba($fg_color, 0.2);
      }

      &:dir(ltr):last-child { border-radius: 0 2px 2px 0; }

      &:dir(rtl):first-child { border-radius: 2px 0 0 2px; }
    }
  }

  // OSD horizontal
  .osd &:not(.vertical) {
    > text {
      @extend %spinbutton_horz_entry;
    }

    > button.image-button.up:not(.flat),
    > button.image-button.down:not(.flat) {
      @include button(undecorated);

      color: $osd_fg_color;
      border-style: none none none solid;
      border-color: transparentize($osd_borders_color, 0.3);
      border-radius: 0;
      box-shadow: none;
      -gtk-icon-shadow: 0 1px black;

      &:dir(rtl) { border-style: none solid none none; }

      &:hover {
        @include button(undecorated);

        color: $osd_fg_color;
        border-color: transparentize(opacify($osd_borders_color, 1), 0.5);
        background-color: darken($osd_bg_color, 10%);
        -gtk-icon-shadow: 0 1px black;
        box-shadow: none;
      }

      &:disabled {
        @include button(undecorated);
        color: $osd_insensitive_fg_color;
        border-color: transparentize(opacify($osd_borders_color, 1), 0.5);
        -gtk-icon-shadow: none;
        box-shadow: none;
      }

      &:dir(ltr):last-child { border-radius: 0 2px 2px 0; }

      &:dir(rtl):first-child { border-radius: 2px 0 0 2px; }
    }
  }

  &.vertical {
    outline: none;

    &:disabled { color: $insensitive_fg_color; }

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

    > text {
      @extend %entry;

      min-height: 32px;
      min-width: 32px;
      padding: 0;
      border-radius: 0;

      > selection { @extend %selected_items; }

      > block-cursor {
        color: $base_color;
        background-color: $text_color;
      }
    }

    > button {
      min-height: 32px;
      min-width: 32px;
      padding: 0;

      &.up { @extend %top_button; }

      &.down { @extend %bottom_button; }
    }

    %top_button {
      border-bottom-style: none;
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }

    %bottom_button {
      border-top-style: none;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
  }

  // OSD vertical
  .osd &.vertical > button:first-child {
    @include button(osd);

    &:hover { @include button(osd-hover);}

    &:active { @include button(osd-active); }

    &:disabled { @include button(osd-insensitive); }
  }

  // Misc
  treeview &:not(.vertical) {
    min-height: 0;
    border-style: none;
    border-radius: 0;

    > text {
      min-height: 0;
      padding: 1px 2px;
    }
  }

  font-feature-settings: "tnum";
}

//
// Comboboxes
//
dropdown > popover.menu.background > contents { padding: 0; } //allow search entries with no margin

dropdown > button > box {
  border-spacing: 6px;
}

dropdown,
combobox {
  button.combo {
    min-width: 0;       // otherwise the arrow placement is unsymmetric
    padding-left: 8px;  //
    padding-right: 8px  //
  }

  arrow {
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    min-height: 16px;
    min-width: 16px;
  }

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    padding-left: 9px;
    padding-right: 9px;
  }

  &:drop(active) { // FIXME: untested
    box-shadow: none;

    button.combo { @extend %button_basic_drop_active; }
  }

  // newstyle
  popover {
    margin-top: 4px;
    padding: 0;

    listview {
      margin: 0;
      padding: 0;

      & > row {
        padding: 6px;
        border-radius: 2px;

        + row {
          margin-top: 2px;
        }
  
        &:selected {
          outline: none;
          color: $text_color;
          background-color: $menu_selected_color;
        }
      }
    }

    // drodowns with searchboxes on top
    .dropdown-searchbar {
      padding: 6px;
      border-bottom: 1px solid $borders_color;
    }
  }

  .linked:not(.vertical) > & > box > button.combo {
    // the combobox is a composite widget so the way we do button linking doesn't
    // work, special case needed.
    &:dir(ltr),
    &:dir(rtl) { @extend %linked_middle; } // specificity bump
  }

  .linked:not(.vertical) > &:first-child > box > button.combo {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px
  }
  .linked:not(.vertical) > &:last-child > box > button.combo {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    border-right-style: solid;
  }
  .linked:not(.vertical) > &:only-child > box > button.combo {
    border-radius: 3px;
    border-style: solid;
  }

  // .linked.vertical > & > box > button.combo { @extend %linked_vertical_middle; }
  .linked.vertical > &:first-child > box > button.combo {
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
  }
  .linked.vertical > &:last-child > box > button.combo {
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;
    border-bottom-style: solid;
  }
  .linked.vertical > &:only-child > box > button.combo {
    border-radius: 3px;
    border-style: solid;
  }
}

.linked:not(.vertical) > filechooserbutton > combobox,
.linked:not(.vertical) > appchooserbutton > combobox,
.linked:not(.vertical) > combobox {
  &:dir(ltr) {
    &:not(:first-child) > box > button.combo { @extend %linked_not_left; }
    &:not(:last-child) > box > button.combo { @extend %linked_not_right; }
  }

  &:dir(rtl) {
    &:not(:first-child) > box > button.combo { @extend %linked_not_right; }
    &:not(:last-child) > box > button.combo { @extend %linked_not_left; }
  }
}

.linked.vertical > filechooserbutton > combobox,
.linked.vertical > appchooserbutton > combobox,
.linked.vertical > combobox {
  &:not(:first-child) > box > button.combo { @extend %linked_not_top; }
  &:not(:last-child) > box > button.combo { @extend %linked_not_bottom; }
}

//
// Toolbars
//
%toolbar {
  padding: 6px;
  border-spacing: 6px;
  background-color: $bg_color;
  color: $text_color;
  border-radius: 3px;
}

toolbar {
  @extend %toolbar;

  separator { background: none; }
  &.horizontal separator { margin: 0 6px; }
  &.vertical separator { margin: 6px 0; }

  .osd & { background-color: transparent; }

  &.osd {
    padding: 8px;
    border: 1px solid $osd_borders_color;
    border-radius: 3px;
    background-color: rgba($osd_bg_color, 0.9);
    background-clip: padding-box;

    &.left,
    &.right,
    &.top,
    &.bottom { border-radius: 0; } // positional classes for `attached` osd toolbars

    &.top { border-width: 0 0 1px 0; }
    &.bottom { border-width: 1px 0 0 0; }
    &.left { border-width: 0 1px 0 0; }
    &.right { border-width: 0 0 0 1px; }
  }
}

// oldstyle toolbar buttons
%theme_flat_button {
  @extend %undecorated_button;

  &:hover { @include button('hover'); }
  &:active, &.keyboard-activating { @include button('active'); }
  &:checked { @include button('checked'); }
  &:disabled { @include button('insensitive'); }
}

//searchbar & location-bar
searchbar > revealer > box {
  padding: 6px;
  border-spacing: 6px;
  border-style: solid;
  border-color: $solid_borders_color;
  background-color: $bg_color;
  border-width: 0 0 1px;
  box-shadow: none;
  color: $text_color;
}

actionbar > revealer > box {
  padding: 6px;
  border-spacing: 6px;
  border-top: 1px solid $borders_color;
  background-color: darken($bg_color, 3%);
  box-shadow: none;
  color: $text_color;
}

//
// Headerbars
//

$_header_radius: if($variant=='light', 2px, 2px);

%viewswitcher_button {
  color: $header_fg;
  border-radius: 0;
  box-shadow: none;
  border: none;
  margin: 0 0 0 0;
  border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                $selected_bg_color 0%,
                                transparent 0%)
                                0 0 0 / 0 0 0;

  &:checked, &:active {
    color: $header_fg;
    background-color: rgba($header_fg, 0.15);
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $selected_bg_color 100%,
                                  transparent 0%)
                                  0 0 3 / 0 0 3px;
  }

  &:disabled {
    color: rgba($header_fg, 0.4);
  }

  &:checked:disabled {
    color: rgba($header_fg, 0.4);
    background-color: rgba($header_fg, 0.05);
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  rgba($selected_bg_color, 0.4) 100%,
                                  transparent 0%)
                                  0 0 3 / 0 0 3px;
  }
}

.titlebar { // headerbar border rounding
  border-top-left-radius: $_header_radius;
  border-top-right-radius: $_header_radius;

  &, & headerbar {
    box-shadow: inset 0 1px $highlight;

    @if $header == 'light' { box-shadow: inset 0 -1px $borders_color, inset 0 1px $highlight; }

    .tiled &,
    .maximized &,
    .fullscreen & { @if $header == 'dark' { box-shadow: none; } }
  }

  &.windowhandle {
    viewswitcher button:not(.titlebutton):not(.suggested-action):not(.destructive-action) {
      border-radius: 0;
      margin-top: 0;
      margin-bottom: 0;
      @extend %viewswitcher_button;
    }
  }
}

%header_entry {
  @include entry(header-normal);

  &:backdrop { opacity: 0.85; }

  &:focus-within {
    @include entry(header-focus);
    background-clip: if($variant=='light', border-box, padding-box);

    image { color: $selected_bg_color; }
  }

  &:disabled { @include entry(header-insensitive); }

  selection:focus-within {
    background-color: $selected_fg_color;
    color: $selected_bg_color;
  }
}

%header_button {
  @include button(header-normal);
  border-width: if($header == 'dark', 0, 1px);

  &:backdrop { opacity: 0.8; }

  &:hover { @include button(header-hover); }
  &:active, &:checked {
    transition: 200ms $ease-out-quad;
    @include button(header-active);
    background-clip: if($header == 'light', border-box, padding-box);
  }

  &:disabled { @include button(header-insensitive); }
  &:disabled:active, &:disabled:checked { @include button(header-insensitive-active); }

  // Disconnect linked buttons
  .linked.raised > &:not(:last-child):not(:only-child) {
    margin-left: 1px;
  }

  // Reset buttons
  .linked.raised > & {
    border-radius: 3px;
    border-style: solid;
    border-width: if($header == 'dark', 0, 1px);
    box-shadow: none;

    &:last-child {
      border-left-style: solid;
      border-left-width: if($header == 'dark', 0, 1px);
      border-color: transparent;

      &:hover, &:active { border-color: $borders_color; }
    }
  }
}

%reset_entry {
  @include entry(normal);

  &:focus-within {
    @include entry(focus);
  }

  &:disabled {
    @include entry(insensitive);
  }
}

%reset_button {
  @include button(normal);
  border-width: 1px;

  &:hover {
    @include button(hover);
  }

  &:active, &:checked {
    @include button(active);
  }

  &:disabled {
    @include button(insensitive);

    &:active, &:checked {
      @include button(insensitive-active);
    }
  }
}

headerbar {
  min-height: 42px;
  padding: 0;
  margin: 0;
  color: $header_fg;
  border: none;
  background-color: $header_bg;
  box-shadow: inset 0 -1px $borders_color, inset 0 1px $highlight;

  &:backdrop {
    transition: $backdrop_transition;
    color: rgba($header_fg, 0.7);
    background-color: $header_bg_backdrop;
  }

  > windowhandle > box {
    padding: 6px;

    &,
    > box.start,
    > box.end {
      border-spacing: 6px;
    }
  }

  .title {
    padding-left: 12px;
    padding-right: 12px;
    font-weight: bold;
  }

  .subtitle {
    font-size: smaller;
    padding-left: 12px;
    padding-right: 12px;

    @extend .dim-label;
  }

  &.flat {
    background-color: transparent;
    box-shadow: inset 0 1px $highlight;
  }

  separator.titlebutton { @extend %header_separator; }

  entry {
    @extend %header_entry;

    progress {
      border-color: $progress_color;
      background-image: none;
      background-color: transparent;
    }

    @each $e_type, $e_color, $e_fg_color in (warning, $warning_color, $warning_fg_color),
                                            (error, $error_color, $error_fg_color) {
      &.#{$e_type} {
        color: $e_fg_color;
        border-color: if($variant=='light', $e_color, $header_entry_border);
        background-color: mix($e_color, $header_bg, 60%);

        &:focus-within {
          color: $e_fg_color;
          background-color: $e_color;
        }

        selection, selection:focus {
          background-color: $e_fg_color;
          color: $e_color;
        }
      }
    }
  }

  button {
    @extend %header_button;
  }

  popover > contents {
    entry {
      @extend %reset_entry;
    }

    button {
      @extend %reset_button;
    }
  }

  &.selection-mode button {
    @include button(undecorated);
    color: $selection_mode_fg;
    background-color: rgba($selection_mode_fg, 0.0);

    &.flat {
      @include button(undecorated);
      color: $selection_mode_fg;
      background-color: rgba($selection_mode_fg, 0.0);
    }

    &:hover { background-color: gtkalpha($selection_mode_fg, 0.3); }

    &:active, &:checked {
      color: $selected_bg_color;
      background-color: $selected_fg_color;
      border-color: $selected_fg_color;
    }

    &:disabled {
      color: rgba($selected_fg_color, 0.42);
      label { color: rgba($selected_fg_color, 0.42); }
    }

    &:disabled:checked, &:disabled:active {
      color: $selected_bg_color;
      background-color: rgba($selected_fg_color, 0.5);
      border-color: rgba($selected_fg_color, 0.42);
    }

    &:backdrop { opacity: 0.7; background: none; }
  }

  // special case and stackswitcher
  buttonbox.linked > button,
  stackswitcher.linked > button {
    background-color: lighten($header_bg, 10%);
    color: $header_fg;
    border-width: if($header == 'dark', 0, 1px);
    border-color: $borders_color;

    &:hover { background-color: mix($header_fg, lighten($header_bg, 10%), 10%); }
    &:active, &:checked { @include button(header-active); }
    &:disabled { color: rgba($header_fg, 0.4); label { color: rgba($header_fg, 0.4); } }
  }

  stackswitcher.linked > button + button {
    border-left: none;
  }

  // use linking rules for entries only
  .linked:not(.vertical):not(.path-bar) {
    // Reset headerbar linked rules
    > entry {
      border-radius: 3px;
      border: 1px solid $header_entry_border;

      &:focus-within { border-color: $selected_bg_color; }
    }

    > entry + entry { border-left-color: $header_entry_border; }
    > entry.error + entry { border-left-color: $header_entry_border; }
    > entry + entry.error { border-left-color: $error_color; }
    > entry.warning + entry { border-left-color: $header_entry_border; }
    > entry + entry.warning { border-left-color: $warning_color; }
    > entry.error + entry.warning { border-left-color: $warning_color; }
    > entry.warning + entry.error { border-left-color: $error_color; }
  }

  // Headerbar Suggested and Destructive Action buttons
  @each $b_type, $b_color, $b_fg in (suggested-action, $suggested_color, $suggested_fg_color),
                                    (destructive-action, $destructive_color, $destructive_fg_color) {
    button.#{$b_type} {
      @include button(suggested_destructive, $b_color, $b_fg);

      &.flat {
        @include button(undecorated);
        color: $b_color;
      }

      &:hover {
        @include button(suggested_destructive, lighten($b_color, 5%), $b_fg);
      }

      &:active, &:checked {
        @include button(suggested_destructive, lighten($b_color, 10%), $b_fg);
      }

      &.flat:disabled,
      &:disabled { @include button(header-insensitive); }
    }

    button.#{$b_type}:backdrop,
    button.#{$b_type}:backdrop {
      opacity: 0.8;
    }
  }

  // Headerbar Spinbuttons
  spinbutton:not(.vertical) {
    &:focus-within {
      color: $selected_fg_color;
      caret-color: $selected_fg_color;
    }

    button {
      &,&:disabled { @include button(header-hover); }

      &:hover { background-color: lighten($header_button_bg, 15%); }
      &:active, &:checked { @include button(header-active); }
      &:disabled { color: rgba($header_fg, 0.42); }
    }

    > button + button { border-left-style: none; }

    > button:hover:not(:active),
    > button:hover + button { box-shadow: inset 1px 0 $header_button_border; }

    > button:disabled + button:not(:disabled):not(:active):not(:checked):not(:hover),
    > button:not(:disabled):not(:active):not(:checked):not(:hover) + button:disabled { box-shadow: inset 1px 0 $header_button_border; }

    > button:first-child:hover:not(:active),
    > entry + button:not(:active):hover { box-shadow: none; }

    > entry:focus-within + button { border-left-color: $selected_bg_color; }
  }

  // Headerbar ComboBoxes
  combobox {
    &:disabled { color: rgba($header_fg, 0.42); }

    > .linked > button.combo {
      @include entry(header-normal);

      &:hover { @include entry(header-focus); box-shadow: none; }
      &:disabled { @include entry(header-insensitive); }
    }

    > .linked > entry.combo {
      &:dir(ltr) {
        border-right-style: none;

        &:focus { box-shadow: 1px 0 $selected_bg_color; }
      }
      &:dir(rtl) {
        border-left-style: none;

        &:focus { box-shadow: -1px 0 $selected_bg_color; }
      }
    }

    > .linked > button.combo {
      &:dir(ltr) {
        &, &:hover, &:active, &:checked, &:disabled {
          border-top-left-radius: 0;
          border-bottom-left-radius: 0;
        }
      }

      &:dir(rtl) {
        &, &:hover, &:active, &:checked, &:disabled {
          border-top-right-radius: 0;
          border-bottom-right-radius: 0;
        }
      }
    }
  }

  // Headerbar Switches
  switch {
    &:backdrop { opacity: 0.75; }
  }

  progressbar {
    trough { background-color: if($variant=='light', darken($header_bg, 10%), $header_button_border); }

    &:backdrop { opacity: 0.75; }
  }

  // Headerbar Scale
  scale {
    $_trough_bg: if($variant=='light', darken($header_bg, 10%), $header_button_border);

    &:backdrop { opacity: 0.75; }

    slider {
      $_slider_border: if($variant=='light', opacify($header_button_border, 0.2), opacify($header_button_border, 0.3));
      $_slider_bg: if($variant=='light', opacify($header_button_bg,1), lighten(opacify($header_bg,1), 10%));

      background-color: $_slider_bg;
      border-color: $_slider_border;

      &:hover {
        background-color: lighten($_slider_bg, 5%);
        border-color: $_slider_border;
      }

      &:active {
        background-color: $selected_bg_color;
        border-color: $selected_bg_color;
      }

      &:disabled {
        background-color: mix($_slider_bg, $header_bg, 70%);
        border-color: $_slider_border;
      }
    }

    trough {
      background-color: $_trough_bg;

      &:disabled { background-color: if($variant=='light', rgba($_trough_bg, 0.95), rgba($_trough_bg, 0.9)); }
    }
  }

  &.titlebar headerbar:not(.titlebar) {
    background: none;
    box-shadow: none;
  }

  // Selectionmode
  &.selection-mode {
    color: $selection_mode_fg;
    background-color: $selection_mode_bg;
    border-color: darken($selection_mode_bg, 4%);
    box-shadow: none;

    &:backdrop {
      background-color: $selection_mode_bg;
      color: rgba($selection_mode_fg, 0.6);
    }

    .subtitle:link { @extend %link_selected;  }

    .selection-menu {
      box-shadow: none;
      padding-left: 10px;
      padding-right: 10px;

      .arrow {
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
      }
    }
    .maximized & { background-color: opacify($selection_mode_bg, 1); }
  }

  .maximized & {
    background-color: opacify($header_bg, 1);
    box-shadow: none;

    &:backdrop { background-color: opacify($header_bg_backdrop, 1); }
  }

  &.default-decoration {
    min-height: 28px;
    padding: 0;
    background-color: opacify($header_bg, 1);
    @if $header == 'light' { box-shadow: inset 0 1px $highlight; }

    .tiled &,
    .maximized &,
    .fullscreen & { box-shadow: none; }

    > windowhandle > box {
      padding: 0 6px;
    }
  }

  .solid-csd & {
    &:backdrop, & {
      &:dir(rtl), &:dir(ltr) { // specificity bump
        margin-left: -1px;
        margin-right: -1px;
        margin-top: -1px;
        border-radius: 0;
        box-shadow: none;
      }
    }
  }
}

// Fixes split headerbars too
.titlebar:not(headerbar) {
  window > &,
  window.csd > & {
    &, &:backdrop {
      padding: 0;
      background: none;
      border: none;
      // box-shadow: none;
    }
  }

  > separator {
    background-image: _solid($header_bg);
    box-shadow: inset 0 1px $highlight;

    &:backdrop {
      transition: $backdrop_transition;
      background-image: _solid($header_bg_backdrop);
      box-shadow: none;
    }
  }
}

%header_separator {
  min-width: 0;
  min-height: 0;
  background: none;
  border-width: 0 0;
  border-image: linear-gradient(to bottom,
                                rgba($header_fg, 0.0) 25%,
                                rgba($header_fg, 0.35) 25%,
                                rgba($header_fg, 0.35) 75%,
                                rgba($header_fg, 0.0) 75%) 0 1/0 0 stretch;

  &:backdrop { opacity: 0.6; }
}

window.devel {
  headerbar.titlebar {
    $c: darken($bg_color, 10%);
    $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
               linear-gradient(to right, transparent 65%, transparentize($selected_bg_color, 0.8)),
               linear-gradient(to top, darken($c, 3%), $c 3px, lighten($c, 6%));
    @if $variant == 'dark' {
      $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                 linear-gradient(to right, transparent 65%, transparentize($selected_bg_color, 0.9)),
                 linear-gradient(to top, lighten($c, 3%) 3px, lighten($c, 5%));
    }

    background: $bg_color $gradient;

    &:backdrop {
      background: $bg_color cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                  image($bg_color); /* background-color would flash */
    }
  }
}

//
// Pathbars
//
.path-bar > button {
  &:hover { background-color: rgba($fg_color, 0.06); }
  &:checked, &:active {
    background-color: $selected_bg_color;
    border-color: $selected_bg_color;

    &:hover{
      background-color: lighten($selected_bg_color, 5%);
      border-color: lighten($selected_bg_color, 5%);
    }
  }

  &.text-button, &.image-button, & {
    padding-left: 6px;
    padding-right: 6px;
  }

  &.text-button.image-button label { padding-left: 0; padding-right: 0; }

  &.text-button.image-button, & {
    label:last-child { padding-right: 10px; }
    label:first-child { padding-left: 10px; }
  }

  &.slider-button,
  &:not(.image-button):not(.text-button) {
    padding-left: 1px;
    padding-right: 1px;
  }

  image {
    padding-left: 4px;
    padding-right: 4px;
  }
}

//
// Tree Views
//
$_treeview_borders_color: if($variant=='light',mix($borders_color, $base_color,80%),mix($fg_color, $base_color, 20%));

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

  @include focus-ring();

  > rubberband { @extend rubberband; }                    // to avoid borders being overridden by the previously set props

  acceleditor > label { background-color: $selected_bg_color; }

  &:selected {
    outline-color: $alt_focus_border_color;
  }

  &.separator {
    min-height: 2px;
    color: rgba(black, 0.1);
  }

  &:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: mix($fg_color, $selected_bg_color, 50%);

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

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

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

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

  &.expander {
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');

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

    color: mix($fg_color, $base_color, 65%);

    &:hover { color: $fg_color; }

    &:selected {
      color: $text_color;

      &:hover { color: $fg_color; }
    }

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

  &.progressbar { // progress bar in treeviews
    color: $selected_fg_color;
    border-radius: 3px;
    background-color: $progress_color;
    background-image: image($progress_color);

    &:selected, &:selected:focus {
      color: $selected_bg_color;
      border-radius: 3px;
      box-shadow: none;
      background-color: $selected_fg_color;
      background-image: image($selected_fg_color);
    }
  }

  &.trough { // progress bar trough in treeviews
    color: $fg_color;
    background-color: $button_border;
    border-radius: 3px;
    border-width: 0;

    &:selected, &:selected:focus {
      color: $selected_fg_color;
      background-color: rgba(black, 0.2);
      border-radius: 3px;
      border-width: 0;
    }
  }

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

      min-height: 0;
      min-width: 0;
      padding: 3px 6px;
      font-weight: bold;

      color: $_column_header_color;
      background-color: $base_color;
      background-image: none;
      border-style: none solid none none;
      border-radius: 0;
      border-image: linear-gradient(to bottom,
                                    $base_color 20%,
                                    rgba(if($variant == 'light', black, white), 0.12) 20%,
                                    rgba(if($variant == 'light', black, white), 0.12) 80%,
                                    $base_color 80%) 0 1 0 0 / 0 1px 0 0 stretch;

      &:hover { color: $selected_bg_color; }
      &:active { color: $fg_color; }

      &:active, &:hover { background-color: $base_color; }
      &:active:hover { color: $fg_color; }

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

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

  button.dnd,
  header.button.dnd {
    &, &:selected, &:hover, &:active {
      padding: 0 6px;
      transition: none;
      color: $selected_fg_color;
      background-color: $selected_bg_color;
      border-radius: 0;
      border-style: none;
    }
  }
}

//
// Menus
//
menubar {
  padding: 0;
  background-color: opacify($header_bg, 1);
  color: $header_fg;

  @if $header == 'light' { box-shadow: inset 0 -1px $borders_color; }

  &:backdrop {
    color: rgba($header_fg, 0.7);
    //background-color: opacify($header_bg_backdrop, 1);
  }

  > item {
    transition: all 0.2s cubic-bezier(0.0, 0.0, 0.2, 1);
    padding: 6px 10px;
    border: none;
    border-radius: 0;
    min-height: 16px;

    &:selected { //Seems like it :hover even with keyboard focus
      background-color: $selected_bg_color;
      color: $selected_fg_color;
    }

    &:disabled {
      color: rgba($header_fg, 0.45);
      border-color: transparent;
    }
  }

  & > item popover.menu.background > contents {
    padding: 5px;
    border-radius: 0 0 3px 3px;
  }

  //nested submenus
  & > item popover.menu popover.menu {
    padding: 0 0 4px 0;
  }

  & > item popover.menu.background popover.menu.background > contents {
    margin: 0;
    border-radius: 3px; //including top
  }
}

//
// Popovers
//
popover.background {
  background-color: transparent;
  font: initial; // Decouple the font of popovers from their entry/textview
  padding: 0;
  color: $fg_color;

  > arrow,
  > contents {
    padding: 3px;
    border-radius: 3px;
    color: $fg_color;
    background-color: $menu_bg_color;
    background-clip: padding-box;
    border: 1px solid if($variant=='light', rgba(black, 0.15), rgba(black, 0.45));
    box-shadow: 0 2px 6px 0 if($variant=='light', rgba(black, 0.07), rgba(black, 0.35));
  }

  &:backdrop {
    background-color: transparent;
  }

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

    separator {
      background-color: mix($bg_color, $borders_color, 30%);
      margin: 3px 0;
    }

    list separator { margin: 0; }

    > scrolledwindow > viewport > stack > box {
      padding: 0;
    }

    listview {
      margin: 0;
      padding: 0;

      & > row {
        padding: 6px;
        border-radius: 2px;
        margin: 0;

        + row {
          margin-top: 2px;
        }
  
        &:selected {
          outline: none;
          color: $text_color;
          background-color: $menu_selected_color;
        }
      }
    }
  }

  label.separator {
    @extend .dim-label;

    color: $fg_color;
  } // Noice

  > list,
  > .view,
  > toolbar,
  > scrolledwindow > viewport > list {
    border-style: none;
    background-color: transparent;
  }

  > scrolledwindow > viewport > list {
    margin: 3px;

    row {
      padding: 6px 12px;
      border-radius: 2px;
    }
  }

  scale { // reset
    > trough { @extend %scale_trough; }

    > trough > highlight { @extend %scale_highlight; }

    > trough > fill {
      @extend %scale_trough;

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

  .osd &,
  &.touch-selection,
  &.magnifier {
    background-color: transparent;

    > arrow,
    > contents {
      @extend %osd;
      background-clip: padding-box;
      border: 1px solid $osd_borders_color;
      // box-shadow: none;
    }
  }

  &.touch-selection,
  &.magnifier {
    button { @extend %osd_button; }
  }
}

magnifier {
  background-color: $base_color;
}

///**********************
// * Popover Base Menus *
// **********************/

$_menu_padding: 6px; //inner menuitem padding

popover.menu {
  padding: 0;

  box.inline-buttons {
    padding: 0 $_menu_padding;

    button.image-button.model {
      @include button(undecorated);
      min-height: 30px;
      min-width: 30px;
      padding: 0;
      border: none;
      outline: none;
      transition: none;

      &:selected { background-image: image($menu_selected_color); }
    }
  }

  box.circular-buttons {
    padding: $_menu_padding;

    button.circular.image-button.model {
      @extend %list_button;
      padding: 10px;
      border: none;

      &:focus {
        background-color: $menu_selected_color;
      }

      &:active:focus {
        color: $fg_color;
        background-color: $menu_active_color;
      }
    }
  }

  accelerator {
    color: gtkalpha(currentColor, 0.55);

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

  //only menu radios have a border
  radio {
    border-color: $borders_color;

    &:active { border-color: transparentize($borders_color,0.5); }
  }

  arrow.left,
  radio.left,
  check.left {
    margin-left: -2px;
    margin-right: 6px;
  }

  arrow.right,
  radio.right,
  check.right {
    margin-left: 6px;
    margin-right: -2px;
  }

  modelbutton {
    min-height: 30px;
    min-width: 40px;
    padding: 0 $_menu_padding;
    border-radius: 2px;

    &:selected {
      color: $text_color;
      background-color: $menu_selected_color;
    }

    &:selected:active {
      color: $fg_color;
      background-color: $menu_active_color; // matching buttons
    }
  }

  label.title {
    font-weight: bold;
    padding: 4px ($_menu_padding + 20px); //this will fall apart with font sizing
  }
}

//
// Notebooks and Tabs
//
notebook {
  @include focus-ring("> header > tabs > tab:checked", $offset: -2px, $focus-state: 'focus:focus-visible');
  padding: 0;

  &.frame {
    border: 1px solid $borders_color;
  }

  > stack:not(:only-child) { // the :not(:only-child) is for "hidden" notebooks
    background-color: $base_color;
  }

  > header {
    padding: 0;
    background-color: $bg_color;

    @each $_pos, $_bpos in (top, bottom), (bottom, top), (right, left), (left, right) {
      // sizing and borders
      &.#{$_pos} {
        // padding-#{$_bpos}: 0;
        border-#{$_bpos}: 1px solid $borders_color;
  
        > tabs > tab {
          padding: 6px 16px;
          min-width: 16px;
          min-height: 16px;
          border-radius: 0;
          outline-offset: -4px;
          border: none;
          border-#{$_bpos}: none;
  
          // tab border shadows
          @if $_pos==top {
            &:not(:only-child) {
              &:first-child { margin-left: 6px; }
              &:last-child { margin-right: 6px; }
            }
            &:hover {
              box-shadow: inset 0 -2px gtkalpha($selected_bg_color, 0.6), 0 1px gtkalpha($selected_bg_color, 0.6);
            }
            &:checked {
              box-shadow: inset 0 -2px $selected_bg_color, 0 1px $selected_bg_color;
            }
          }

          @else if $_pos==bottom {
            &:not(:only-child) {
              &:first-child { margin-left: 6px; }
              &:last-child { margin-right: 6px; }
            }
            &:hover {
              box-shadow: inset 0 2px gtkalpha($selected_bg_color, 0.6), 0 -1px gtkalpha($selected_bg_color, 0.6);
            }
            &:checked {
              box-shadow: inset 0 2px $selected_bg_color, 0 -1px $selected_bg_color;
            }
          }

          @else if $_pos==left {
            &:not(:only-child) {
              &:first-child { margin-top: 6px; }
              &:last-child { margin-bottom: 6px; }
            }
            &:hover {
              box-shadow: inset -2px 0 gtkalpha($selected_bg_color, 0.6), 1px 0 gtkalpha($selected_bg_color, 0.6);
            }
            &:checked {
              box-shadow: inset -2px 0 $selected_bg_color, 1px 0 $selected_bg_color;
            }
          }

          @else if $_pos==right {
            &:not(:only-child) {
              &:first-child { margin-top: 6px; }
              &:last-child { margin-bottom: 6px; }
            }
            &:hover {
              box-shadow: inset 2px 0 gtkalpha($selected_bg_color, 0.6), -1px 0 gtkalpha($selected_bg_color, 0.6);
            }
            &:checked {
              box-shadow: inset 2px 0 $selected_bg_color, -1px 0 $selected_bg_color;
            }
          }
        }
      }
    }

    // overflow arrows
    &.top, &.bottom {
      > tabs > arrow.up {
        -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
        &:last-child { margin-left: 2px; }
      }

      > tabs > arrow.down {
        -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
        &:first-child { margin-right: 2px; }
      }
    }

    &.left, &.right {
      > tabs > arrow.up {
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        &:last-child { margin-top: 2px; }
      }

      > tabs > arrow.down {
        -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
        &:first-child { margin-bottom: 2px; }
      }
    }

    > tabs > arrow {
      color: $insensitive_fg_color;
  
      &:hover { color: mix($fg_color, $insensitive_fg_color, 50%); }
      &:active { color: $fg_color; }
      &:disabled { color: rgba($insensitive_fg_color, 0.7); }
    }

    > tabs {
      margin: 0;
      padding: 0;

      > tab {
        color: $insensitive_fg_color;
        background-color: rgba($bg_color, 0.0);
    
        &:hover:not(:checked) {
          color: mix($fg_color, $insensitive_fg_color, 50%);
          transition: 200ms $ease-out-quad;
        }

        &:checked {
          color: $fg_color;
          transition: 300ms $ease-out-quad;
        }

        // close button
        button.flat {
          border-radius: 100%;
          min-height: 16px;
          min-width: 16px;
          padding: 0;
          margin: 4px 0;
          color: mix($bg_color, $fg_color, 35%);
    
          &:hover {
            @extend %undecorated_button;
            color: lighten(red, 15%);
            background-color: darken($bg_color, 5%);
          }

          &:active, &:active:hover {
            @extend %undecorated_button;
            color: $selected_bg_color;
            background-color: darken($bg_color, 8%);
          }
        }
      }
    }

    // Button on notebook header
    button { margin: 2px; }
  }
}

//
// Scrollbars
//
$_scrollbar_bg_color: darken($base_color, 1%);

scrollbar {
  $_slider_min_length: 40px;

  background-color: $_scrollbar_bg_color;
  transition: 300ms $ease-out-quad;

  // scrollbar border
  &.top { border-bottom: 1px solid $borders_color; }
  &.bottom { border-top: 1px solid $borders_color; }
  &.left { border-right: 1px solid $borders_color; }
  &.right { border-left: 1px solid $borders_color; }

  button { border: none; }

  &.vertical button {
    &.down { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
    &.up { -gtk-icon-source: -gtk-icontheme('pan-up-symbolic'); }
  }

  &.horizontal button {
    &.down { -gtk-icon-source: -gtk-icontheme('pan-right-symbolic'); }
    &.up { -gtk-icon-source: -gtk-icontheme('pan-left-symbolic'); }
  }

  // slider
  > range > trough {
    background-color: transparent;
    padding: 0;
    margin: 0;
    border: none;
    outline: none;
    border-radius: 0;

    > slider {
      min-width: 6px;
      min-height: 6px;
      margin: -1px;
      padding: 0;
      border: 4px solid transparent;
      border-radius: 8px;
      background-clip: padding-box;
      background-color: mix($fg_color, $bg_color, 40%);
      box-shadow: none;
      outline: none;
  
      &:hover { background-color: mix($fg_color, $bg_color, 30%); }
  
      &:hover:active { background-color: $selected_bg_color;}
  
      &:disabled { background-color: transparent; }
    }
  }

  > range.fine-tune {
    > trough > slider {
      min-width: 4px;
      min-height: 4px;
    }

    &.horizontal > trough > slider { border-width: 5px 4px; }
    &.vertical > trough > slider { border-width: 4px 5px; }
  }

  &.overlay-indicator {
    &:not(.dragging):not(.hovering) {
      opacity: 0.4;
      border-color: transparent;
      background-color: transparent;

      > range > trough > slider {
        margin: 0;
        min-width: 4px;
        min-height: 4px;
        background-color: mix($fg_color, $bg_color, 70%);
        border: 1px solid if($variant == 'light', rgba(white, 0.6), rgba(black, 0.3));
      }

      &.horizontal > range > trough > slider {
        margin: 0 2px;
        min-width: $_slider_min_length;
      }

      &.vertical > range > trough > slider {
        margin: 2px 0;
        min-height: $_slider_min_length;
      }
    }

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

  &.horizontal > range > trough > slider { min-width: $_slider_min_length; }
  &.vertical > range > trough > slider { min-height: $_slider_min_length; }
}

treeview ~ scrollbar.vertical {
  border-top: 1px solid $borders_color;
  margin-top: -1px;
}

//
// Switches
//
switch {
  font-size: 0;
  min-width: 52px;
  min-height: 24px;
  background-size: 52px 24px;
  background-repeat: no-repeat;
  background-position: center center;
  transition: all 350ms $ease-out-quad;


  > slider {
    min-width: 0;
    min-height: 0;
    background-image: none;
  }

  &, > slider {
    padding: 0;
    margin: 0;
    background-color: transparent;
    outline: none;
    color: transparent;
    border: none;
    box-shadow: none;
  }
}

@each $k,$l in ('',''),
               (':checked','-active'),
               (':hover','-hover'),
               (':checked:hover','-active-hover'),
               (':disabled','-insensitive'),
               (':checked:disabled','-active-insensitive') {

  // load switch troughs from .png files in assets directory

  switch#{$k} {
    background-image: -gtk-scaled(url("assets/switch#{$l}#{$asset_suffix}.png"),url("assets/switch#{$l}#{$asset_suffix}@2.png"));
  }

  row:selected switch#{$k},
  infobar switch#{$k} {
    background-image: -gtk-scaled(url("assets/switch#{$l}-selected.png"),url("assets/switch#{$l}-selected@2.png"));
  }

  headerbar switch#{$k} {
    background-image: -gtk-scaled(url("assets/switch#{$l}-header#{$asset_suffix}.png"),url("assets/switch#{$l}-header#{$asset_suffix}@2.png"));
  }
}

//
// Check and Radio items
//
@each $w,$a in ('check', 'checkbox'),
               ('radio','radio') {

  //standard checks and radios
  @each $s,$as in ('','-unchecked'),
                  (':disabled','-unchecked-insensitive'),
                  (':indeterminate', '-mixed'),
                  (':indeterminate:disabled', '-mixed-insensitive'),
                  (':checked', '-checked'),
                  (':checked:disabled','-checked-insensitive') {
    #{$w}#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}#{$asset_suffix}.png"),
                                    url("assets/#{$a}#{$as}#{$asset_suffix}@2.png"));
    }

    .osd,
    %osd_check_radio {
      #{$w}#{$s} {
        -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}-dark.png"),
                                      url("assets/#{$a}#{$as}-dark@2.png"));
      }
    }

    // the borders of checks and radios are
    // too similar in luminosity to the selected background color, hence
    // we need special casing.
    .view #{$w}#{$s}:selected,
    row:selected #{$w}#{$s},
    infobar #{$w}#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}-selected.png"),
                                    url("assets/#{$a}#{$as}-selected@2.png"));
    }
  }
}

// Selectionmode
@each $s,$as in ('','-selectionmode'),
                  (':checked', '-checked-selectionmode') {
  .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;
  }
}

checkbutton, radiobutton {
  // this is for a nice focus on check and radios text
  &.text-button {
    padding: 2px 0;
    outline-offset: 0;
    &:hover { color: darken($fg_color, 15%); }
    &:disabled { color: $insensitive_fg_color; }
  }

  label:not(:only-child) {
    &:first-child { margin-left: 4px; }
    &:last-child { margin-right: 4px; }
  }
}

check,
radio {
  min-width: 16px;
  min-height: 16px;
  -gtk-icon-size: 16px;
  margin: 0 2px;
  padding: 0;

  &:only-child { margin: 0; }
}

//
// GtkScale
//

$_marks_length: 3px;
$_marks_distance: 1px;
$_scale_trough_bg: if($variant == 'light', rgba(black, 0.15), rgba(black, 0.25));

%scale_trough {
  border: none;
  border-radius: 3px;
  background-color: $_scale_trough_bg;

  // headerbar & { }

  &:disabled { background-color: if($variant == 'light', rgba(black, 0.08), rgba(black, 0.15)); }

  // row:selected & {
  //   &:disabled, & {
  //   }
  // }

  // OSD
  .osd & {
    background-color: rgba(black, 0.25);

    &:disabled { background-color: rgba(black, 0.1); }
  }
}

%scale_highlight {
  border: none;
  border-radius: 3px;
  background-color: $selected_bg_color;

  &:disabled {
    background-color: rgba($selected_bg_color, 0.5);
  }

  // ...on selected list rows
  // row:selected & { &:disabled, & { border-color: $selected_borders_color; }}

  // OSD
  // .osd & {
  // }
}

scale {
  min-height: 15px;
  min-width: 15px;
  padding: 3px;

  &.horizontal {
    trough { padding: 0 4px; }
    highlight, fill { margin: 0 -4px; }
  }

  &.vertical {
    trough { padding: 4px 0; }
    highlight, fill { margin: -4px 0; }
  }

  // Click-and-hold the slider to activate
  &.fine-tune {
    // Make the trough grow in fine-tune mode
    slider { margin: -4px; }

    fill,
    highlight,
    trough {
      border-radius: 5px;
    }
  }

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

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

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

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

  > trough > slider {
    min-height: 15px;
    min-width: 15px;
    margin: -6px; // The slider is inside the trough, negative margin to make it bigger
    background-color: $selected_fg_color;
    border: 1px solid $borders_color;
    border-radius: 100%;
    box-shadow: none;
    background-clip: padding-box;

    transition: $button_transition;
    transition-property: background, border;

    &:hover {
      background-clip: border-box;
      background-color: $selected_bg_color;
      border-color: darken($selected_bg_color, 3%);
    }

    &:active {
      background-clip: border-box;
      background-color: darken($selected_bg_color, 3%);
      border-color: darken($selected_bg_color, 6%);
    }

    &:disabled {
      background-color: darken($selected_fg_color, 10%);
      border-color: darken($borders_color, 5%);
    }

    // OSD sliders
    // .osd & { }
  }

  > value {
    color: gtkalpha(currentColor, 0.45);
    font-feature-settings: "tnum";
  }

  > marks {
    color: gtkalpha(currentColor, 0.45);

    @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);
      }
    }
  }

  &.fine-tune > marks {
    @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 - 1px);
        margin-#{$marks_pos}: -($_marks_distance + $_marks_length - 2px);
      }
    }
  }

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

    &.fine-tune indicator { min-height: ($_marks_length - 1px); }
  }

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

    &.fine-tune indicator { min-width: ($_marks_length - 1px); }
  }

  &:selected {
    trough { // Troughs in selected list-rows and infobars
      @extend %selected_scale;
    }
  }
}

%selected_scale {
  background-color: rgba(black, 0.2);

  highlight {
    background-color: $alt_selected_bg_color;

    &:disabled { background-color: mix($selected_fg_color, $selected_bg_color, 55%); }
  }

  &:disabled { background-color: rgba(black, 0.1); }
}

//
// Progress bars
//
progressbar {
  font-size: smaller;
  color: rgba($fg_color, 0.7);
  font-feature-settings: "tnum";

  // sizing
  &.horizontal {
    > trough {
      min-width: 150px;
      &, > progress {
        min-height: 4px;
        border-radius: 2px;
      }
    }
  }

  &.vertical {
    > trough {
      min-height: 80px;
      &, > progress {
        min-width: 4px;
        border-radius: 2px;
      }
    }
  }

  &.horizontal > trough > progress { margin: 0 -1px; } // the progress node is positioned after the trough border
  &.vertical > trough > progress { margin: -1px 0; }   // this moves it over it.

  &.osd {
    min-width: 4px;
    min-height: 4px;
    background-color: transparent;
    margin: 0;
    box-shadow: none;
    padding: 0;
    border-radius: 0;

    > trough {
      border-style: none;
      background-color: transparent;
      box-shadow: none;
    }

    > progress {
      border-style: none;
      border-radius: 0;
    }
  }

  // Moving bit
  > trough > progress {
    background-color: $progress_color;
    border: none;
    border-radius: 3px;
    box-shadow: none; //needed for clipping

    row:selected &,
    infobar & { background-color: $selected_fg_color; }

    &:disabled {
      background-color: $insensitive_fg_color;
      border-color: $insensitive_fg_color;
    }

    border-radius: 1.5px;
    $_progress-radius: 5px;

    &.left {
      border-top-left-radius: $_progress-radius;
      border-bottom-left-radius: $_progress-radius;
    }

    &.right {
      border-top-right-radius: $_progress-radius;
      border-bottom-right-radius: $_progress-radius;
    }

    &.top {
      border-top-right-radius: $_progress-radius;
      border-top-left-radius: $_progress-radius;
    }

    &.bottom {
      border-bottom-right-radius: $_progress-radius;
      border-bottom-left-radius: $_progress-radius;
    }
  }
  // Trough
  > trough {
    border: none;
    border-radius: 3px;
    background-color: if($variant == 'light', $button_border, darken($bg_color, 5%));

    row:selected &,
    infobar & { background-color: rgba(black, 0.2); }
  }
}

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

$_levelbar_size: 4px;
$_levelbar_border_radius: 3px;

levelbar {
  &.horizontal {
    trough > block {
      min-height: $_levelbar_size;
      border-radius: $_levelbar_border_radius;

      &:dir(rtl) {
        border-radius: 0 $_levelbar_border_radius $_levelbar_border_radius 0;
      }

      &:dir(ltr) {
        border-radius: $_levelbar_border_radius 0 0 $_levelbar_border_radius;
      }

      &.empty,&.full {
        border-radius: $_levelbar_border_radius;
      }
    }

    // segmented level bar
    &.discrete {
      trough > block {
        min-height: 2px;
        margin: 1px;
        min-width: 24px;
        border-radius:0;
        &:first-child {border-radius: 2px 0 0 2px;}
        &:last-child {
          border-radius: 0 2px 2px 0;
        }
      }
    }
  }

  &.vertical {
    trough > block {
      min-width: $_levelbar_size;
      border-radius: $_levelbar_border_radius;
    }

    &.discrete > trough > block {
      min-width: $_levelbar_size;
      margin: 1px 0;
      min-height: 32px;
    }
  }

  > trough {
    padding: 0;
  }

  // level bar colours
  > trough > block {
    border: 1px solid;

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

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

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

    &.empty {
      background-color: darken($bg_color, 5%);
      border-color: darken($bg_color, 5%);
    }
  }
}

//
// Print dialog
//
window.dialog.print {
  drawing {
    color: $fg_color;
    background: none;
    border: none;
    padding: 0;

    paper {
      border: 1px solid $borders_color;
      background: $base_color;
      padding: 0;
    }

  }

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

//
// Frames
//
frame,
.frame {
  border: 1px solid $borders_color;
}

frame {
  border-radius: 2px;

  > label {
    margin: 4px;
  }
}

scrolledwindow {
  // 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); }
  }

  // Overflow indication, works similarly to the overshoot, the size if fixed tho.
  > undershoot {
    &.top { @include undershoot(top); }
    &.bottom { @include undershoot(bottom); }
    &.left { @include undershoot(left); }
    &.right { @include undershoot(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: $_scrollbar_bg_color;

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

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

  &.spacer {
    background-color: transparent;
  }
}

//
// Lists
//

listview,
list {
  background-color: $base_color;
  border-color: $borders_color;
  border-radius: 2px;
  box-shadow: none;
  color: $fg_color;

  .content-pane & {
    background-color: if($variant =='light', $base_color, $bg_color);
    background-clip: border-box;
  }

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

  &.separators.horizontal { border-left: none; }
  &.separators:not(.horizontal) { border-bottom: none; }

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

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

listview > header {
  @extend .heading;
  padding: 2px;
  padding-top: 18px;
  padding-bottom: 6px;
}

%row_activatable {
  color: $text_color;
  outline: none;
  box-shadow: none;

  &:hover, &.has-open-popup {
    background-color: $menu_hover_color;
    color: $fg_color;
  }

  &:active {
    background-color: $menu_active_color;
    color: $fg_color;
  }

  &:disabled {
    background-color: transparent;
    color: $insensitive_fg_color;

    image { color: inherit; }
  }

  &:selected {
    background-color: $selected_bg_color;
    color: $selected_fg_color;
    outline: none;

    &:hover, &.has-open-popup {
      background-color: $alt_selected_bg_color;
      color: $selected_fg_color;
    }
  }
}

row {
  transition: none;
  @extend %row_activatable;

  &:selected {
    button { @extend %selected-button; }
  }

  &, &:hover, &:active, &:checked, &:selected, &:backdrop, &:disabled {
    listview, row {
      background-color: transparent;
      background-image: none;
      box-shadow: none;
      transition: none;
      animation: none;
      outline: none;
    }
  }
}

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

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

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

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

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

treeexpander {
  border-spacing: 4px;
}

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

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

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

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

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

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

  > header {
    padding-left: 12px;
    padding-right: 12px;
  }
}

// AdwActionRow
row {
  label.subtitle {
    font-size: smaller;
    @extend .dimmed;
  }

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

    > .icon:disabled {
      filter: Opacity(0.45);
    }

    > box.title {
      margin-top: 6px;
      margin-bottom: 6px;
      border-spacing: 3px;
      padding: 0;

      // Specificity bump for header bar
      &,
      > .title,
      > .subtitle {
        padding: 0;
        font-weight: inherit;
      }
    }

    > .prefixes,
    > .suffixes {
      border-spacing: 6px;

      > .suffixes {
        border-spacing: 6px;
      }
    }

    > .icon,
    > .prefixes {
      &:dir(ltr) { margin-right: 6px; }
      &:dir(rtl) { margin-left: 6px; }
    }
  }

  &.property > box.header > box.title > {
    .title {
      font-size: smaller;
      @extend .dimmed;
    }

    .subtitle {
      font-size: inherit;
      opacity: 1;
    }
  }

  &.property.monospace {
    font-family: inherit;
    font-size: inherit;
  }
}

// AdwEntryRow and AdwSpinRow
row.entry {
  &:disabled {
    text {
      opacity: 0.45;
    }

    .dimmed, .dim-label, .subtitle {
      opacity: 1;
    }
  }

  > box.header {
    border-spacing: 0;
    margin-left: 6px;
    margin-right: 6px;

    > .editable-area {
      padding: 0 6px;

      > .edit-icon, > .indicator {
        min-width: 24px;
        min-height: 24px;
        padding: 5px;
      }

      > .edit-icon, > .indicator, > .apply-button {
        &:dir(ltr) { margin-left: 6px; }
        &:dir(rtl) { margin-right: 6px; }
      }

      > .edit-icon:disabled {
        opacity: 0.55;
      }

      > .indicator {
        opacity: 0.65;
      }
    }

    > .prefixes {
      &:dir(ltr) { margin-left: 6px; }
      &:dir(rtl) { margin-right: 6px; }
    }

    > .suffixes {
      &:dir(ltr) { margin-right: 6px; }
      &:dir(rtl) { margin-left: 6px; }
    }
  }

  &.monospace {
    font-family: inherit;
    font-size: inherit;
  }
}

row.spin {
  spinbutton {
    border-spacing: 0;

    &, &:focus {
      outline: none;
    }
  }
}

$row_transition: background-color 200ms $ease-out-quad,
                 background-image 200ms $ease-out-quad,
                 border-radius 200ms $ease-out-quad;

row.entry,
row.spin {
  @include focus-ring($offset: -1px, $transition: $row_transition);

  &.activatable.focused {
    outline-offset: -1px;
  }

  &:not(:selected).activatable.focused:hover,
  &:not(:selected).activatable.focused:active {
    background-color: transparent;
  }

  @each $e_type, $e_color in (error, $error_color), (warning, $warning_color), (success, $success_color) {
    &.#{$e_type} {
      color: $e_color;

      .dimmed, .dim-label, .subtitle {
        opacity: 1;
      }
    }
  }
}

// AdwComboRow
row.combo {
  image.dropdown-arrow:disabled {
    filter: Opacity(0.45);
  }

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

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

  popover > contents {
    min-width: 120px;

    .combo-searchbar {
      margin: 6px;

      + scrolledwindow {
        @include undershoot(top);
      }
    }
  }
}

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

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

%boxed_list_row {
  @include focus-ring($offset: -1px, $transition: $row_transition);
  border-bottom: 1px solid $borders_color;

  &:not(:selected).activatable {
    &:hover, &.has-open-popup {
      background-color: $menu_hover_color;
    }

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

%card_list {
  background-color: $base_color;
  border: 1px solid $borders_color;
  border-radius: 2px;
  box-shadow: none;
  color: $fg_color;

  .content-pane & {
    background-color: if($variant =='light', $base_color, $bg_color);
    background-clip: border-box;
  }

  &.suggested-action {
    background-color: $suggested_color;
    color: $suggested_fg_color;
  }

  &.destructive-action {
    background-color: $destructive_color;
    color: $destructive_fg_color;
  }
}

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

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

  list.nested {
    background-color: gtkmix($base_color, $bg_color, 50%);
    color: inherit;
  }

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

  // AdwExpanderRow arrow rotation
  image.expander-row-arrow {
    @extend .dimmed;

    transition: -gtk-icon-transform 200ms $ease-out-quad;
    @include margin-start(3px);

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

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

    &:disabled {
      filter: Opacity(0.45);
    }
  }

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

    &:not(:disabled) {
      color: $selected_bg_color;
    }
  }

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

  &.property > box > list > row {
    @extend .property;
  }
}

// AdwButtonRow
row.button {
  > box {
    margin-left: 12px;
    margin-right: 12px;
    border-spacing: 6px;
    min-height: 40px;

    > .icon:disabled {
      filter: Opacity(0.45);
    }
  }

  .title {
    @extend .heading;
  }

  &.suggested-action {
    background-color: $suggested_color;
    color: $suggested_fg_color;

    @include focus-ring($outer: true, $offset: 1px, $transition: $row_transition);

    &:not(.expander):not(:selected).activatable {
      &:hover, &.has-open-popup {
        background-color: lighten($suggested_color, 10%);
        background-image: none;
      }

      &:active {
        background-color: darken($suggested_color, 3%);
        background-image: none;
      }
    }

    &:disabled {
      opacity: 0.45;

      > box > .icon:disabled,
      > box > label:disabled {
        filter: none;
      }
    }
  }

  &.destructive-action {
    background-color: $destructive_color;
    color: $destructive_fg_color;

    @include focus-ring($outer: true, $offset: 1px, $transition: $row_transition);

    &:not(.expander):not(:selected).activatable {
      &:hover, &.has-open-popup {
        background-color: lighten($destructive_color, 10%);
        background-image: none;
      }

      &:active {
        background-color: darken($destructive_color, 3%);
        background-image: none;
      }
    }

    &:disabled {
      opacity: 0.45;

      > box > .icon:disabled,
      > box > label:disabled {
        filter: none;
      }
    }
  }
}

list.boxed-list {
  @extend %card_list;

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

    &.expander {
      border: none;
    }

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

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

list.boxed-list-separate {
  background: none;
  border: none;
  box-shadow: none;
  color: $fg_color;

  > row {
    @extend %card_list;
    margin-bottom: 12px;

    &:last-child {
      margin-bottom: 0;
    }

    @include focus-ring($offset: -1px, $transition: $row_transition);

    &.expander {
      row.header {
        @extend %boxed_list_row;
        border-top-left-radius: 2px;
        border-top-right-radius: 2px;
      }

      &:not(:checked) row.header,
      &.expander:checked list.nested,
      &.expander:checked list.nested > row:last-child {
        border-bottom-left-radius: 2px;
        border-bottom-right-radius: 2px;
        border-bottom: none;
      }
    }
  }
}

//
// App Notifications
//
.app-notification {
  padding: 10px;
  color: $osd_fg_color;
  background-color: gtkalpha($osd_bg_color, 0.9);
  background-clip: border-box;
  border-radius: 0 0 2px 2px;
  border-width: 0 1px 1px 1px;
  border-style: solid;
  border-color: $osd_button_border;

  border { border: none; }

  button {
    @include button(osd);

    &:hover { @include button(osd-hover); }
    &:active, &:checked { @include button(osd-active); background-clip: padding-box; }
    &:disabled { @include button(osd-insensitive); }
  }

  button.flat {
    @extend %undecorated_button;

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

  .linked:not(.vertical) { @include linking_rules($b_border:$osd_button_border); }
}

//
// Expanders
//
expander {
  min-width: 16px;
  min-height: 16px;
  -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');

  &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }
  &:hover { color: lighten($fg_color,30%); } //only lightens the arrow
  &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
}

expander-widget {
  @include focus-ring("> box > title");

  > box > title {
    transition: $focus_transition;
    border-radius: 2px;

    &:hover > expander {
      color: lighten($fg_color, 30%); //only lightens the icon
    }
  }
}

.navigation-sidebar,
placessidebar,
stackswitcher,
expander-widget {
  &:not(decoration):not(window):drop(active):focus,
  &:not(decoration):not(window):drop(active) {
    box-shadow: none;
  }
}

//
// Calendar
//
calendar {
  color: $fg_color;
  border: 1px solid $borders_color;
  border-radius: 0;
  padding: 0;

  > header {
    color: $fg_color;
    border-bottom: 1px solid $borders_color;

    > button {
      border: none;
      box-shadow: none;
      background: none;
      border-radius: 0;

      &:hover { background-color: rgba($fg_color, 0.1); }
      &:active { background-color: $selected_bg_color; }
    }

    > button:backdrop {
      background: none;
    }
  }

  > grid {
    > label.day-name,
    > label.week-number {
      color: $text_color;
    }

    > label.today {
      background-color: rgba($fg_color, 0.15);
      border-radius: 3px;

      &:selected {
        box-shadow: none;
      }
    }

    > label:focus {
      outline-color: $focus_border_color;
      outline-offset: -2px;
      outline-width: 2px;
      outline-style: solid;
    }

    > label.day-number {
      padding: 4px;

      &:selected {
        @extend %selected_items;
        border-radius: 3px;
      }
    }

    > label.day-number.other-month {
      color: gtkalpha(currentColor, 0.3);
    }
  }
}

//
// Dialogs
//

window.dialog.message { // Message Dialog styling
  .titlebar {
    min-height: 20px;
    background-color: $bg_color;
    border: none;
    box-shadow: inset 0 1px $highlight;
  }

  box.dialog-vbox.vertical {
    border-spacing: 10px;
  }

  & label.title {
    font-weight: 800;
    font-size: 15pt;
  }

  .dialog-action-area:not(.vertical) > button {
    padding: 5px 10px;
    border-radius: 0;
    border: none;
    border-top: 1px solid $borders_color;

    &:active, &:checked {
      transition: background-color 0.00001s 0.2s;
      animation: ripple_effect 0.2s cubic-bezier(0.0, 0.0, 0.2, 1);
    }

    &, &:hover, &:active, &:checked, &:disabled {
      border-radius: 0;

      &:first-child {
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
      }

      &:last-child {
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
      }

      &:only-child {
        border-bottom-left-radius: 3px;
        border-bottom-right-radius: 3px;
      }
    }

    &:not(.suggested-action):not(.destructive-action) {
      &:hover { background-color: gtkalpha($fg_color, 0.06); }
      &:active, &:checked {
        background-color: gtkalpha($fg_color, 0.1);
        color: $fg_color;
      }
    }
  }

  &.csd { // rounded bottom border styling for csd version
    &.background {
      border-bottom-left-radius: 3px;
      border-bottom-right-radius: 3px;
      border: none;
    }

    .dialog-action-area:not(.vertical) > button {
      padding: 6px 10px 8px 10px;

      &, &:hover, &:active, &:checked, &:disabled {
        border-radius: 0;
        border-top: 1px solid $borders_color;
        border-right: none;
        border-bottom: none;

        &:first-child {
          border-bottom-left-radius: 3px;
          border-top-left-radius: 0;
          border-left: none;
          border-bottom: none;
        }

        &:last-child {
          border-bottom-right-radius: 3px;
          border-top-right-radius: 0;
          border-right: none;
          border-bottom: none;
        }

        &:only-child {
          border-bottom-left-radius: 3px;
          border-bottom-right-radius: 3px;
          border-left: none;
          border-right: none;
          border-bottom: none;
        }
      }
    }
  }
}

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

  #pathbarbox { border-bottom: 1px solid rgba($borders_color, 0.08); }
}

filechooserbutton > button > box {
  border-spacing: 6px;
}

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

//
// Sidebar
//
.sidebar {
  border-style: none;
  background-color: $bg_color;

  &:not(separator) {
    @at-root %sidebar_left,
    &:dir(ltr),
    &.left,
    &.left:dir(rtl) {
      border-right: 1px solid $borders_color;
      border-left-style: none;
    }

    @at-root %sidebar_right,
    &:dir(rtl),
    &.right {
      border-left: 1px solid $borders_color;
      border-right-style: none;
    }
  }

  listview.view,
  list { background-color: transparent; }

  paned & { &.left, &.right, &.left:dir(rtl), &:dir(rtl), &:dir(ltr), & { border-style: none; }}
}

stacksidebar {
  list.separators:not(.horizontal) > row:not(.separator) {
    border-bottom: none;
  }

  .sidebar-pane &.sidebar {
    border: none;
  }

  row {
    border-radius: 3px;
    padding: 4px 6px;

    > label {
      padding-left: 6px;
      padding-right: 6px;
    }

    &.needs-attention > label {
      @extend %needs_attention;
      background-size: 6px 6px, 0 0;
    }

    &:focus:focus-visible {
      outline: none;
    }
  }
}

///**********************
// * Navigation Sidebar *
// **********************/

.navigation-sidebar {
  padding: 6px; //only vertical padding. horizontal row size would clip
  border-radius: 0;

  > separator {
    margin: 3px 0;
  }

  > row {
    min-height: 36px;
    padding: 0 8px;
    border-radius: 2px;
    margin: 0;

    + row {
      margin-top: 3px;
    }

    &:focus-visible:focus-within {
      background-color: $menu_hover_color;
    }

    &:selected {
      &:focus-visible:focus-within {
        outline: none;
        color: $selected_fg_color;
        background-color: $selected_bg_color;

        &:hover { background-color: $alt_selected_bg_color; }
      }
    }
  }
}

%sidebar_button {
  min-width: 22px;
  min-height: 22px;
  margin-top: 2px;
  margin-bottom: 2px;
  padding: 0;
  border-radius: 100%;

  @extend %flat_button;

  &:not(:hover):not(:active) > image { opacity: 0.5 };
}

placessidebar {
  > viewport.frame { border-style: none; }

  .navigation-sidebar {
    padding: 0;
  }

  .navigation-sidebar > row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: 28px;
    padding: 2px 2px 2px 10px;
    border-radius: 0;
    // Using margins/padding directly in the SidebarRow
    // will make the animation of the new bookmark row jump
    > revealer {
      padding: 0 10px;
    }

    image.sidebar-icon {
      &:dir(ltr) { padding-right: 8px; }
      &:dir(rtl) { padding-left: 8px; }
    }

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

    button.sidebar-button {
      @extend %sidebar_button;
    }

    &.sidebar-placeholder-row {
      padding: 0 8px;
      min-height: 2px;
      background-image: _solid($drop_target_color);
      background-clip: content-box;
    }

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

    &:drop(active):not(:disabled) {
      color: $drop_target_color;
      box-shadow: inset 0 1px $drop_target_color,
                  inset 0 -1px $drop_target_color;

      &:selected {
        color: $selected_fg_color;
        background-color: $drop_target_color;
      }
    }
  }
}

//
// Placesview
//
placesview {
  .server-list-button > image {
    transition: 200ms $ease-out-quad;
    -gtk-icon-transform: rotate(0turn);
  }

  .server-list-button:checked > image {
    transition: 200ms $ease-out-quad;
    -gtk-icon-transform: rotate(-0.5turn);
  }

  // this selects the "connect to server" label
  > actionbar > revealer > box  > box{
    border-spacing: 6px;
  }
}

//
// Paned
//
paned {
  > separator {
    min-width: 1px;
    min-height: 1px;
    -gtk-icon-source: none;
    border-style: none;
    background-color: transparent;
    background-image: _solid($borders_color);
    background-size: 1px 1px;

    &:selected { background-image: _solid($selected_bg_color); }

    &.wide {
      min-width: 5px;
      min-height: 5px;
      background-color: $bg_color;
      background-image: _solid($borders_color), _solid($borders_color);
      background-size: 1px 1px, 1px 1px;
    }
  }

  &.horizontal > separator {
    background-repeat: repeat-y;
    &:dir(ltr) {
      margin: 0 -8px 0 0;
      padding: 0 8px 0 0;
      background-position: left;
    }
    &:dir(rtl) {
      margin: 0 0 0 -8px;
      padding: 0 0 0 8px;
      background-position: right;
    }

    &.wide {
      margin: 0;
      padding: 0;
      background-repeat: repeat-y, repeat-y;
      background-position: left, right;
    }
  }

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

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

///**************
// * GtkVideo *
// **************/

video {
  & image.osd {
    min-width: 64px;
    min-height: 64px;
    border-radius: 32px;
  }

  background: black;
}

//
// GtkInfoBar
//
infobar {
  border-style: none;

  &.info {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $selected_bg_color;
      selection { color: $selected_bg_color; }
    }
  }

  &.question {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $suggested_color;
      selection { color: $suggested_color; }
    }
  }

  &.warning {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $warning_color;
      selection { color: $warning_color; }
    }
  }

  &.error {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $error_color;
      selection { color: $error_color; }
    }
  }

  &.info,
  &.question,
  &.warning,
  &.error {
    & > revealer > box,
    &:hover > revealer > box,
    &:backdrop > revealer > box {
      color: $selected_fg_color;
      caret-color: currentColor;

      > button {
        min-height: 28px;
        @extend %selected-button;
      }

      selection {
        background-color: $selected_fg_color;
      }

      *:link { @extend %link_selected; }
    }

    trough {
      @extend %selected_scale;
    }
  }
}

//close button for info and searchbar (#3215)

infobar .close,
searchbar .close {
   @include button(undecorated);
   min-width: 16px;
   min-height: 16px;
   padding: 4px;
   border-radius: 1000px;

   &:hover { @include button(hover); }
}

//
// Titlebuttons
//
windowcontrols {
  border-spacing: 6px;

  &:not(.empty) {
    &.start:dir(ltr),
    &.end:dir(rtl) {
      margin-right: 7px;
    }

    &.start:dir(rtl),
    &.end:dir(ltr) {
      margin-left: 7px;
    }
  }

  button {
    margin: 0;
    padding: 0;
    @include button(undecorated);

    &.close, &.maximize, &.minimize { // csd windows control titlebuttons
      &, &:hover, &:active, &:active:hover {
        min-width: 30px;
        min-height: 28px;
        margin: 0;
        padding: 0;
        color: transparent;
        background-color: transparent;
        background-position: center;
        background-repeat: no-repeat;
        border-width: 0;
      }

      &:backdrop { opacity: 1; }
    }

    @each $k in ('close', 'maximize', 'minimize') {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {
        &.#{$k}#{$l} { background-image: -gtk-scaled(url('assets/titlebutton-#{$k}#{$m}#{$header_asset_suffix}.png'),
                                                     url('assets/titlebutton-#{$k}#{$m}#{$header_asset_suffix}@2.png')); }
      }
    }
  }

  .fullscreen &,
  .maximized & {
    button {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {
      &.maximize#{$l} { background-image: -gtk-scaled(url('assets/titlebutton-restore#{$m}#{$header_asset_suffix}.png'),
                                                      url('assets/titlebutton-restore#{$m}#{$header_asset_suffix}@2.png')); }
      }
    }
  }
}

//
// Buttons on selected backgrounds
//
%selected-button {
  color: $selected_fg_color;
  background-color: rgba($selected_fg_color, 0.0);
  border-color: rgba($selected_fg_color, 0.5);

  &.flat {
    @include button(undecorated);
    color: $selected_fg_color;
    background-color: rgba($selected_fg_color, 0.0);
  }

  &.flat:disabled {
    color: rgba($selected_fg_color, 0.42);
    label { color: rgba($selected_fg_color, 0.42); }
  }

  &:hover {
    color: $selected_fg_color;
    background-color: rgba($selected_fg_color, 0.2);
    border-color: rgba($selected_fg_color, 0.8);
  }

  &:active, &:active:hover, &:checked {
    color: $selected_bg_color;
    background-color: $selected_fg_color;
    border-color: $selected_fg_color;
  }

  &:disabled {
    color: rgba($selected_fg_color, 0.5);
    background-color: rgba($selected_fg_color, 0.0);
    border-color: rgba($selected_fg_color, 0.42);

    label { color: rgba($selected_fg_color, 0.5); }
  }

  &:disabled:active, &:disabled:checked {
    color: $selected_bg_color;
    background-color: rgba($selected_fg_color, 0.5);
    border-color: rgba($selected_fg_color, 0.42);
  }
}


//
// Tooltips
//
tooltip {
  &.background {
    // background-color needs to be set this way otherwise it gets drawn twice
    // see https://bugzilla.gnome.org/show_bug.cgi?id=736155 for details.
    background-color: rgba(black, 0.75);
    background-clip: padding-box;
    border: none;
    color: white;
  }

  &.csd {
    border-radius: 3px;
    box-shadow: none;
  }

  padding: 6px 10px;
  border-radius: 2px;
  box-shadow: none;

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

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

  $_colorswatch-radius: 2px;

  &, &:drop(active) { border-style: none; }

  // border rounding
  &.top {
    border-top-left-radius: $_colorswatch-radius + 0.5px;
    border-top-right-radius: $_colorswatch-radius + 0.5;

    overlay {
      border-top-left-radius: $_colorswatch-radius;
      border-top-right-radius: $_colorswatch-radius;
    }
  }
  &.bottom {
    border-bottom-left-radius: $_colorswatch-radius + 0.5px;
    border-bottom-right-radius: $_colorswatch-radius + 0.5;

    overlay {
      border-bottom-left-radius: $_colorswatch-radius;
      border-bottom-right-radius: $_colorswatch-radius;
    }
  }
  &.left, &:first-child:not(.top) {
    border-top-left-radius: $_colorswatch_radius + 0.5px;
    border-bottom-left-radius: $_colorswatch_radius + 0.5px;
    overlay {
      border-top-left-radius: $_colorswatch_radius;
      border-bottom-left-radius: $_colorswatch_radius;
    }
  }
  &.right, &:last-child:not(.bottom) {
    border-top-right-radius: $_colorswatch_radius + 0.5px;
    border-bottom-right-radius: $_colorswatch_radius + 0.5px;
    overlay {
      border-top-right-radius: $_colorswatch_radius;
      border-bottom-right-radius: $_colorswatch_radius;
    }
  }

  &.dark overlay {
    color: rgba(white, 0.37);
    &:hover {
      border-color: if($variant == 'light', rgba(black, 0.5), $borders_color);
    }
  }
  &.light overlay {
    color: rgba(black, 0.7);
    &:hover {
      border-color: if($variant == 'light', rgba(black, 0.3), $borders_color);
    }
  }

  overlay {
    border: 1px solid if($variant == 'light', rgba(black, 0.15), $borders_color);
    &:hover { background-color: rgba(white, 0.2) }
  }

  &:disabled {
    opacity: 0.5;
    overlay {
      border-color: rgba(black, 0.6);
      box-shadow: none;
    }
  }

  &#add-color-button {
    border-style: solid; // the borders are drawn by the overlay for standard colorswatches to have them semi
    border-width: 1px;   // translucent on the colored background, here it's not necessary so they need to be set
    @include button(normal);
    &:hover { @include button(hover); }
    overlay { @include button(undecorated); } // reset the overlay to not cover the button style underneath
  }
}

button.color {
  padding: 0;

  colorswatch:first-child:last-child {
    &, overlay {
      margin: 4px;
      border-radius: 0;
    }
  }
}

plane {
  transition: $focus_transition;

  @include focus-ring($offset: 2px, $outer: true);
}

// colorscale popup
colorchooser .popover.osd { border-radius: 3px; }

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

  &:hover { -gtk-icon-filter: brightness(1.2); }

  .tile {
    margin: 2px;
    background-color: if($variant=='light', transparent, black);
    border-radius: 0;
    padding: 0;

    &:active, &:selected { background-color: if($variant=='light', transparent, $selected_bg_color); }
    &:disabled { background-color: if($variant=='light', transparent, mix($bg_color, $base_color, 60%)); }
  }

  > rubberband { @extend rubberband; }
}

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

  .osd & button.flat {  //FIXME: quick hack, redo properly
    border-style: none;
    border-radius: 3px;
  }

  button { // +/- buttons on GtkVolumeButton popup
    &:hover {
      @include button(hover);
    }
  }
}

// Decouple the font of context menus from their entry/textview
.context-menu { font: initial; }
.monospace { font-family: Monospace; }

//
// Shortcuts Help
//
.keycap {
  min-width: 16px;
  min-height: 20px;

  padding: 3px 6px 4px 6px;

  color: $fg_color;
  background-color: $base_color;
  border: 1px solid $borders_color;
  border-radius: 2.5px;
  box-shadow: inset 0px -2px 0px if($variant=='light', rgba(black, 0.05), rgba(black, 0.15));
}

stackswitcher button {
  &.text-button { min-width: 80px; }
  &.circular { min-width: 0; }
}

//
// Window Decorations
//
$_wm_border: if($variant=='light', rgba(black, 0.15), rgba(black, 0.65));

window {
  border: none;
  outline: none;

  &.csd {
    margin: 0;
    border-radius: 3px;
    transition: none;
    box-shadow: 0 3px 5px if($variant == 'light', rgba(black, 0.15), rgba(black, 0.2)),
                0 5px 12px if($variant == 'light', rgba(black, 0.15), rgba(black, 0.2)),
                0 0 0 1px $_wm_border;

    &:backdrop {
      // the transparent shadow here is to enforce that the shadow extents don't
      // change when we go to backdrop, to prevent jumping windows
      box-shadow: 0 3px 5px if($variant == 'light', rgba(black, 0.15), rgba(black, 0.2)),
                  0 5px 12px if($variant == 'light', rgba(black, 0), rgba(black, 0)),
                  0 0 0 1px $_wm_border;
      transition: $backdrop_transition;
    }

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

    &.maximized,
    &.fullscreen {
      box-shadow: none;
    }
  }

  &.solid-csd {
    border: 1px solid $header_bg;
    border-radius: 0;
    margin: 0;
    background-color: $header_bg;
    box-shadow: none;
  }
}

///**********************
// * Touch Copy & Paste *
// *********************/
//touch selection handlebars for the Popover.osd above
cursor-handle {
  background-color: transparent;
  background-image: none;
  box-shadow: none;
  border-style: none;
  min-width: 20px;
  min-height: 24px;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 24px;
  padding-bottom: 24px;

  @each $s,$as in ('',''),
                  (':hover','-hover'),
                  (':active','-active') { //no need for insensitive and backdrop
    &.top#{$s}:dir(ltr), &.bottom#{$s}:dir(rtl) {
      $_url: 'assets/text-select-start#{$as}#{$asset_suffix}';
      -gtk-icon-source: -gtk-scaled(url('#{$_url}.png'),
                                    url('#{$_url}@2.png'));
    }

    &.bottom#{$s}:dir(ltr), &.top#{$s}:dir(rtl) {
      $_url: 'assets/text-select-end#{$as}#{$asset_suffix}';
      -gtk-icon-source: -gtk-scaled(url('#{$_url}.png'),
                                    url('#{$_url}@2.png'));
    }

    &.insertion-cursor#{$s}:dir(ltr), &.insertion-cursor#{$s}:dir(rtl) {
      $_url: 'assets/slider-horz-scale-has-marks-above#{$as}#{$asset_suffix}';
      -gtk-icon-source: -gtk-scaled(url('#{$_url}.png'),
                                    url('#{$_url}@2.png'));
    }
  }
}

shortcuts-section {
  margin: 20px;
}

.shortcuts-search-results {
  margin: 20px;
  border-spacing: 24px;
}

// shortcut window keys
shortcut {
  border-spacing: 6px;
}

shortcut > .keycap {
  min-width: 20px;
  min-height: 25px;
  margin-top: 2px;
  padding-bottom: 3px;
  padding-left: 6px;
  padding-right: 6px;

  color: $fg_color;
  background-color: $base_color;
  border: 1px solid;
  border-color: if($variant == 'light', mix($borders_color, $bg_color, 50%), $borders_color);
  border-radius: 5px;
  box-shadow: if($variant == 'light', inset 0 -3px mix($base_color, $bg_color, 20%), inset 0 -3px mix($borders_color, $base_color, 60%));
  font-size: smaller;

}

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

stackswitcher > button.text-button { min-width: 100px; } // FIXME aggregate with buttons

stackswitcher.circular {
  border-spacing: 12px;

  // FIXME aggregate with buttons
  > button.circular,
  > button.text-button.circular {
    min-width: 32px;
    min-height: 32px;
    padding: 0;
  }
}

///*************
// * App Icons *
// *************/
// Outline for low res icons
.lowres-icon {
    -gtk-icon-shadow: 0 -1px rgba(0,0,0,0.05),
      1px 0 rgba(0,0,0,0.1),
      0 1px rgba(0,0,0,0.3),
      -1px 0 rgba(0,0,0,0.1);
}

// Drapshadow for large icons
.icon-dropshadow {
  -gtk-icon-shadow: 0 1px 12px rgba(0,0,0,0.05),
      0 -1px rgba(0,0,0,0.05),
      1px 0 rgba(0,0,0,0.1),
      0 1px rgba(0,0,0,0.3),
      -1px 0 rgba(0,0,0,0.1);
}

// catch all extend
%selected_items {
  background-color: $selected_bg_color;
  color: $selected_fg_color;

  &:disabled { color: mix($selected_fg_color, $selected_bg_color, 50%); }
}

%normal_selected_items {
  background-color: $menu_selected_color;
  color: $fg_color;

  &:disabled { color: $insensitive_fg_color; }
}

%nobg_selected_items {
  color: $fg_color;

  &:disabled { color: $insensitive_fg_color; }
}

///*********
// * Emoji *
// *********/
popover.emoji-picker > contents {
  padding: 0;
}

.emoji-searchbar {
  padding: 6px;
  border-spacing: 6px;
  border-bottom: 1px solid $borders_color;
}

.emoji-toolbar {
  padding: 6px;
  border-spacing: 6px;
  border-top: 1px solid $borders_color;
}

button.emoji-section {
  border-color: transparent;
  border-width: 3px;
  border-style: solid none none;
  border-radius: 0;

  padding: 3px 0 0;
  min-width: 32px;
  min-height: 24px;

  /* reset props inherited from the button style */
  background: none;
  box-shadow: none;
  text-shadow: none;

  &:hover { border-color: if($variant == 'light', $borders_color, transparentize($fg_color, .9)); }

  &:focus { background: none; }

  &:active { color: $fg_color; }

  &:checked {
    color: $fg_color;
    border-color: $selected_bg_color;
  }
}

popover.emoji-picker emoji {
  font-size: x-large;
  padding: 6px;
  border-radius: 6px;

  &:focus,
  &:hover {
    background: $selected_bg_color;
  }
}

emoji-completion-row > box {
  border-spacing: 10px;
  padding: 2px 10px;
}

emoji-completion-row:focus,
emoji-completion-row:hover {
  background-color: $selected_bg_color;
  color: $selected_fg_color;
}

emoji-completion-row emoji:focus,
emoji-completion-row emoji:hover {
  background-color: $menu_selected_color;
}

popover.entry-completion > contents {
  padding: 0;
}

statusbar {
  padding: 6px 10px 6px 10px;
}
