@function gtkalpha($c,$a) {
  @return unquote("alpha(#{$c},#{$a})");
}

$ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$asset_suffix: if($variant=='dark', '-dark', ''); // use dark assets in dark variant

//
// Base States
//
.background {
  color: $fg_color;
  background-color: transparentize($bg_color, 0.001);
}

dnd {
  color: $fg_color;
}

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

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

image:disabled {
  -gtk-icon-filter: opacity(0.5);
}

.view,
%view {
  color: $text_color;
  background-color: $base_color;

  &:selected {
    &, &:focus {
      @extend %selected_items;
      border-radius: 2px;
    }
  }
}

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();

  &: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: transparentize(darken($selected_bg_color, 10%), 0.8);
}

flowbox {
  > rubberband { @extend rubberband; }

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

    @include focus-ring();

    &:selected {
      @extend %selected_items;
    }
  }
}

gridview {
  > rubberband { @extend rubberband; }

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

    @include focus-ring();

    &:selected {
      @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;

    color: $fg_color;
  }

  row:selected &,
  &:selected {
    @extend %nobg_selected_items;
  }

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

  &:disabled {
    color: $insensitive_fg_color;

    button & { color: inherit; }

    > selection { @extend %selected_items_disabled; }
  }

  &.error {
   color: $error_color;

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

.dim-label {
  color: $dim_label_fg_color;
}

window.assistant {
  .sidebar {
    background-color: $base_color;
    border-top: 1px solid $borders_color;
    &:dir(ltr) { border-right: 1px solid $borders_color; }
    &:dir(rtl) { border-left: 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;
  }
}

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

%osd,
.osd {
  color: $osd_fg_color;
  border: none;
  background-color: $osd_bg_color;
  background-clip: padding-box;
  box-shadow: none;
}

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

spinner {
  background-image: 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;
}

$vert_padding: 5px;
//
// Text Entries
//
%entry,
entry {
  %entry_basic, & {
    border: 1px solid;
    padding: 5px 8px;

    caret-color: currentColor;
    border-radius: 3px;
    transition: all 200ms $ease-out-quad;

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

    @include entry(normal);

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

      &.left {
        padding-left: 0;
        padding-right: 5px;
      }
      &.right {
        padding-right: 0;
        padding-left: 5px;
      }
    }

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

    > text > block-cursor {
      @include entry(block_cursor);
    }

    &.flat {
      &, &:focus-within, &:disabled {
        padding: 2px;
        @include entry(normal);
        border: none;
        border-radius: 0;
      }
    }

    &:focus-within {
      background-clip: border-box;
      @include entry(focus);
      > placeholder {
        opacity: 0; /* We hide placeholders on focus */
      }
    }

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

    > text > selection { @extend %selected_items; }

    @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, $entry_border);
        background-color: mix($e_color, $base_color, 60%);

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

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

    &:drop(active) {
      &:focus, & {
        border-color: $drop_target_color;
        box-shadow: none;
      }
    }

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

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

  > progress {
    margin-bottom: 2px;
  }

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

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

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

  &.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: $selected_bg_color;

@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_transition: all 200ms $ease-out-quad;

%button,
button {
    @at-root %button_basic, & {
    min-height: 22px;
    min-width: 20px;
    transition: $button_transition;
    border: 1px solid;
    border-radius: 3px;
    padding: 5px 8px;

    @include button(normal);

    @include focus-ring();

    // separator { margin: 4px 1px; }

    // @at-root %button_basic_flat,
    // &.flat {
    //   @include button(undecorated);
    //   // to avoid adiacent buttons borders clashing when transitioning, the transition on the normal state is set
    //   // to none, while it's added back in the hover state, so the button decoration will fade in on hover, but
    //   // it won't fade out when the pointer leave the button allocation area. To make the transition more evident
    //   // in this case the duration is increased.
    //   transition: none;

    //   &:hover {
    //     transition: $button_transition;
    //     transition-duration: 350ms;

    //     &:active { transition: $button_transition; }
    //   }
    // }

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

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

      background-clip: if($variant=='light', border-box, padding-box);
      transition-duration: 50ms;

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

    // @at-root %button_basic_flat,
    // &.flat:disabled { @include button(undecorated); }

    &:disabled {
      @include button(insensitive);
      -gtk-icon-filter: opacity(0.5);

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

    @at-root %button_basic_flat,
    &.flat {
      @include button(undecorated);
      // to avoid adiacent buttons borders clashing when transitioning, the transition on the normal state is set
      // to none, while it's added back in the hover state, so the button decoration will fade in on hover, but
      // it won't fade out when the pointer leave the button allocation area. To make the transition more evident
      // in this case the duration is increased.
      transition: none;

      &:hover {
        @include button(hover);
        transition: $button_transition;
        transition-duration: 350ms;
      }

      &.keyboard-activating,
      &:active,
      &:checked {
        @include button(active);
        transition: $button_transition;
      }
      &:disabled { @include button(undecorated); }
    }

    &.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; }
    }

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

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

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

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

    &.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
  .osd & {
    @include button(osd);

    &: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 in (suggested-action, $suggested_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} {
      @include button(suggested_destructive, $b_color);
      @include focus-ring();

      &.flat {
        @include button(undecorated);
        color: $b_color;
      }
      &:hover {
        @include button(suggested_destructive, lighten($b_color, 10%));
      }
      &:active, &:checked {
        @include button(suggested_destructive, darken($b_color, 10%));
      }
      &.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.

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

  %needs_attention {
    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; }
    &:dir(rtl) {
      @if $variant == 'light' { background-position: left 3px, left 4px; }
      @else { background-position: left 3px, left 2px; }
    }
  }

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

  .linked:not(.vertical) > &,
  .linked:not(.vertical) > &:hover,
  .linked:not(.vertical) > &:active,
  .linked:not(.vertical) > &:checked {
    @extend %linked;
  }

  .linked.vertical > &,
  .linked.vertical > &:hover,
  .linked.vertical > &:active,
  .linked.vertical > &:checked {
    @extend %linked_vertical;
  }

  %circular_button,
  menubutton.circular &,
  &.circular { // force circular button shape
    min-width: 24px;
    min-height: 24px;
    padding: 2px;
    border-radius: 9999px;

    label { padding: 0; }
  }
}

%linked_middle {
  border-radius: 0;
  border-right-style: none;
}

%linked_left {
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

%linked_right {
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-right-style: solid;
}

%linked_only_child {
  border-radius: 3px;
  border-style: solid;
}

%linked {
  @extend %linked_middle;

  &:first-child { @extend %linked_left; }
  &:last-child { @extend %linked_right; }
  &:only-child { @extend %linked_only_child; }
}

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

%linked_vertical_top {
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
}

%linked_vertical_bottom {
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
  border-bottom-style: solid;
}

%linked_vertical_only_child {
  border-radius: 3px;
  border-style: solid;
}

%linked_vertical {
  @extend %linked_vertical_middle;

  &:first-child { @extend %linked_vertical_top; }
  &:last-child { @extend %linked_vertical_bottom; }
  &:only-child { @extend %linked_vertical_only_child; }
}

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

// menu buttons
modelbutton.flat {
  transition: none;
  min-height: 24px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: 2px;

  @extend %undecorated_button;

  &:hover { background-color: $menu_selected_bg_color; }
  &:active, &:selected { &, arrow { background-color: $menu_selected_bg_color; } }
  &:checked { color: $fg_color; }
}

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

/* oldstyle toolbar buttons */

.toolbar > button,
.toolbar > :not(.linked) > button,
.toolbar :not(.linked) > menubutton > button,
.toolbar :not(.linked) > scalebutton > button,
.toolbar :not(.linked) > dropdown > button,
.toolbar :not(.linked) > colorbutton > button,
.toolbar :not(.linked) > fontbutton > button,
.toolbar :not(.linked) > appchooserbutton > button,
.toolbar :not(.linked) > combobox > box > button {
  margin: 1px 0;
  @extend %button_basic_flat;
}

button.color {
  padding: 2px;

  > colorswatch:only-child {
    &, > overlay { border-radius: 0; }
  }
}

/* list buttons */
%list_button,
list > row button.image-button:not(.flat) {
  &:hover { @include button(hover); }
  &:active,
  &:checked { @include button(active); }

  @each $b_type, $b_color in (suggested-action, $suggested_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} {
      @include button(suggested_destructive, $b_color);
    }
  }
}

//
// Links
//
%link,
link {
  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%); }
  }
  &:disabled { color: transparentize(desaturate($link_color, 100%), 0.2); }

  @at-root %link_selected,
  &:selected,
  *:selected & {
    color: mix($selected_fg_color, $selected_bg_color, 80%);
  }
}

link {
  @include focus-ring();
}

button.link {
  @extend %link;

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

    text-shadow: none;
  }

  > label {
    text-decoration: underline;
  }
}

//
// Spinbuttons
//
spinbutton {

  &:disabled { color: $insensitive_fg_color; }

  text { @extend %entry; }

  &:not(.vertical) {
    text { min-width: 28px; }

    button, text { @extend %linked; }

    &:dir(ltr) text,
    &:dir(rtl) button.up { border-radius: 3px 0 0 3px; }

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

    > button + button,
    > button:hover:not(:active),
    > button:hover + button { box-shadow: inset 1px 0 $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 transparentize($button_border, 0.5); }

    > button:first-child:hover:not(:active),
    > button.up:dir(rtl):hover:not(:active),
    > text + button:not(:active):hover { box-shadow: none; }

    > text:focus + button { border-left-color: if($variant=='light', $selected_bg_color, $entry_border); }

    > text:drop(active) + button { border-left-color: $drop_target_color; }

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

      > button:first-child:hover:not(:active),
      > button.up:dir(rtl):hover:not(:active),
      > text + button:not(:active):hover { box-shadow: none; }

      > text:focus + button { border-left-color: $osd_button_border; }
    }
  }

  &.vertical {
    button, text {
      padding-left: 4px;
      padding-right: 4px;
      min-width: 0;

      @extend %linked_vertical;
    }

    button.up { border-radius: 3px 3px 0 0; }

    > text:focus + button { border-top-color: if($variant=='light', $selected_bg_color, $entry_border); }

    > text:drop(active) + button { border-top-color: $drop_target_color; }
  }

  font-feature-settings: "tnum";
}

//
// Comboboxes
//

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

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

  > stack > row.activatable:hover {
    background: none;
    box-shadow: none;
  }
}

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

  > popover.background.menu > contents {
    padding: 4px 0;
    border-radius: 2px;
  }

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    min-height: 16px;
    padding: 5px 6px;
    border-radius: 0;
  }

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

  // newstyle
  popover {
    padding: 0;

    listview.view {
      margin: 4px 0;
      background-color: transparent;

      & > row {
        min-height: 16px;
        padding: 5px 6px;

        &:selected {
          &, &:hover {
            color: $selected_fg_color;
            background-color: $selected_bg_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; }
  }

  .linked:not(.vertical) > &:first-child > box > button.combo { @extend %linked_left; }
  .linked:not(.vertical) > &:last-child > box > button.combo { @extend %linked_right; }
  .linked:not(.vertical) > &:only-child > box > button.combo { @extend %linked_only_child; }

  .linked.vertical > & > box > button.combo { @extend %linked_vertical_middle; }
  .linked.vertical > &:first-child > box > button.combo { @extend %linked_vertical_top; }
  .linked.vertical > &:last-child > box > button.combo { @extend %linked_vertical_bottom; }
  .linked.vertical > &:only-child > box > button.combo { @extend %linked_vertical_only_child; }
}

//
// Toolbars
//
%toolbar {
  padding: 4px;
  border-spacing: 1px;
  background-color: $bg_color;
}

.toolbar {
  @extend %toolbar;

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

  .osd & { background-color: transparent; }

  &.osd {
    padding: 7px;
    border: 1px solid transparentize(black, 0.5);
    border-radius: 3px;
    background-color: transparentize($osd_bg_color, 0.1);

    &.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; }
  }
}

//searchbar & location-bar
searchbar > revealer > box {
  padding: 6px;
  border-spacing: 6px;
  @extend %toolbar;

  border-width: 0 0 1px;
}

//
// Titlebuttons
//

windowcontrols {
  $_wm_backdrop_icon_color: if($variant == 'light', darken($wm_icon_unfocused_bg, 5%), lighten($wm_icon_unfocused_bg, 5%));

  border-spacing: 6px;

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

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

  button {
    min-width: 20px;
    min-height: 20px;
    @extend .image-button;

    padding: 5px 2px;

    @include button(undecorated);
    // &:hover, &:active, &:checked { background-color: transparent; }

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

    &.close, &.maximize, &.minimize {
      &, &:hover, &:active, &:checked {
        background-color: transparent;
        background-size: 20px 20px;
        background-position: center;
        background-repeat: no-repeat;
        border-width: 0;
      }
    }

    &.close {
      &, &:hover, &:active, &:backdrop {
        color: $selected_fg_color;
      }
      @include draw_circle($selected_bg_color);

      &:backdrop { @include draw-circle($_wm_backdrop_icon_color); }
      &:hover { @include draw-circle(lighten($selected_bg_color, 5%)); }
      &:active { @include draw-circle(darken($selected_bg_color, 5%)); }
    }

    &.maximize,
    &.minimize {
      &:backdrop {
        color: $_wm_backdrop_icon_color;
      }
      &:hover,
      &:hover:backdrop {
        color: $fg_color;
        @include draw-circle($wm_button_hover_bg);
      }
      &:active,
      &:active:backdrop {
        @include draw-circle($wm_button_active_bg);
      }
    }
  }
}

//
// Headerbars
//
headerbar,
%titlebar {
  min-height: 46px;
  padding: 0 6px;

  border-width: 0 0 1px;
  border-style: solid;
  border-radius: 0;
  border-color: opacify($header_border, 1);

  color: $header_fg;
  background-color: opacify($header_bg, 1);
  box-shadow: inset 0 1px $header_highlight;

  .csd & {  // Transparent header-bars only in csd windows
    background-color: $header_bg;
    border-color: $header_border;
  }

  &:backdrop {
    color: transparentize($header_fg, 0.4);
  }

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

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

  .tiled &,
  .tiled-top &,
  .tiled-right &,
  .tiled-bottom &,
  .tiled-left &,
  .maximized &,
  .fullscreen & {
    &:backdrop, & {
      border-radius: 0; // squared corners when the window is max'd or tiled
    }
  }

  &.default-decoration {
    min-height: 28px;
    padding: 2px 6px;
    border-bottom-width: 0;

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

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

headerbar {
  @extend %header_widgets;

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

  entry, button, separator {
    margin-top: 6px;
    margin-bottom: 6px;
  }
}

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

  separator { background-image: _solid($header_border); }

  @extend %titlebar;
}

// Development versions of apps to use a differently styled headerbar
window.devel {
  headerbar.titlebar {
    background-image: cross-fade(20% -gtk-icontheme("system-run-symbolic"), image(transparent));
    background-position: 90% 2%;
    background-size: 256px 256px;
    background-repeat: no-repeat;
  }
}

%header_separator {
  min-width: 1px;
  min-height: 1px;
  border-width: 0 1px;
  border-image: linear-gradient(to bottom,
                                transparentize($header_fg, 1) 25%,
                                transparentize($header_fg, 0.65) 25%,
                                transparentize($header_fg, 0.65) 75%,
                                transparentize($header_fg, 1) 75%) 0 1/0 1px stretch;

  &:backdrop { opacity: 0.6; }
}

%header_widgets {
  // Headerbar Entries
  entry {
    @include entry(header-normal);

    &:backdrop { opacity: 0.85; }

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

      image { color: transparentize($header_fg, 0.15); }
    }
    &:disabled { @include entry(header-insensitive); }

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

    progress {
      border-color: $selected_bg_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 {
          color: $e_fg_color;
          background-color: $e_color;
        }
        selection, selection:focus {
          background-color: $e_fg_color;
          color: $e_color;
        }
      }
    }
  }

  // Headerbar Buttons
  button {

    @include button(header-normal);

    &:backdrop { opacity: 0.7; }

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

  &.selection-mode button {

    &, &.flat {
      @include button(undecorated);
      color: $selected_bg_color;
      background-color: transparentize($selected_bg_color, 1);
    }
    &:hover { @extend %selected_button_normal; }
    &:active, &:checked { @extend %selected_button_active; }

    &:disabled {
      @extend %selected_button_flat_disabled;

      &:checked, &:active { @extend %selected_button_disabled_checked; }
    }
  }

  // Linking stuff

  // Disconnect linked buttons
  .linked:not(.vertical):not(.path-bar):not(stackswitcher) {
    button:not(:last-child):not(:only-child) { margin-right: 1px; }
  }

  // Reset buttons
  .linked:not(.vertical):not(.path-bar) > button {
    &, &:hover, &:active, &:checked, &:disabled {
      border-radius: 3px;
      border-style: solid;
    }
  }
  .linked:not(.vertical):not(.path-bar) {
    $_uncolored_button: 'button:not(:checked):not(:active):not(.suggested-action):not(.destructive-action)';

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

  // special case for path-bars and stack-switchers
  stackswitcher.linked:not(.vertical):not(.path-bar),
  .linked:not(.vertical).path-bar {

    > button {
      @include button(header-hover);

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

      &, &:hover, &:active, &:checked, &:disabled { @extend %linked; }
    }
  }

  // special case widgets like the linked entry and button in mintinstall toolbar
  .linked:not(.vertical) entry {
    box-shadow: none;

    &:focus {
      @include entry(header-normal);
      background-clip: padding-box;
    }

    & + button:last-child {
      @include button(header-hover);

        &:hover { background-color: lighten($header_button_bg, 15%); }
        &:active, &:checked { @include button(header-active); }
        &:disabled {
          color: transparentize($header_fg, 0.4);
          background-color: transparentize($header_button_bg, 0.2);
          border-color: $header_button_border;

          &:checked {
            background-color: transparentize($selected_bg_color, 0.35);
            color: transparentize($selected_fg_color, 0.25);
          }
        }

        &, &:hover, &:active, &:checked, &:disabled { @extend %linked; }
    }
  }

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

      &.flat {
        @include button(undecorated);
        color: $b_color;
        outline-color: transparentize($b_color, 0.7);
      }
      &:hover {
        @include button(suggested_destructive, lighten($b_color, 10%));
      }
      &:active, &:checked {
        @include button(suggested_destructive, darken($b_color, 10%));
      }
      &.flat:disabled,
      &:disabled { @include button(header-insensitive); }
    }
    button.#{$b_type}:backdrop,
    button.#{$b_type}:backdrop {
      opacity: 0.8;
    }
  }

  // Headerbar Spinbuttons
  & spinbutton {

    &:focus button {
      color: $selected_fg_color;

      &:hover { background-color: transparentize($selected_fg_color, 0.9); border-color: transparent; }
      &:disabled { color: transparentize($selected_fg_color, 0.6); }
    }
    button {
      color: $header_fg;

      &:hover { background-color: transparentize($header_fg, 0.75); border-color: transparent; }
      &:disabled { color: transparentize($header_fg, 0.3); }
      &:active { background-color: rgba(0,0,0,0.1); }
    }
  }

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

    > .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: none; }
        @if $variant=='light' { &:focus { box-shadow: 1px 0 $selected_bg_color; } }
      }
      &:dir(rtl) {
        border-left-style: none;

        &:focus { box-shadow: none; }
        @if $variant=='light' { &: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', opacify($header_button_border, 0.05), $header_button_border); }

    &:backdrop { opacity: 0.75; }
  }

  // Headerbar Scale
  scale {
    $_trough_bg: if($variant=='light', opacify($header_button_border, 0.05), $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', transparentize($_trough_bg, 0.05), transparentize($_trough_bg, 0.1)); }
    }
  }
}

//
// Pathbars
//
pathbar  > button {
  &.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
//
columnview.view,
treeview.view {
  border-left-color: transparentize($fg_color, 0.65);   // this is actually the tree lines color,
  border-top-color: transparentize($fg_color, 0.65);    // while this is the grid lines color, better then nothing

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

  &:selected {
    &, &:focus {
      border-radius: 0;
      border-left-color: mix($selected_fg_color, $selected_bg_color, 50%);
      border-top-color: transparentize($fg_color, 0.9);   // doesn't work unfortunatelly

      @extend %selected_items;
    }
  }

  &:disabled {
    color: $insensitive_fg_color;

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

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

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

  > dndtarget: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; }
  }

  &.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, 50%);

    &:hover { color: $fg_color; }

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

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

  &.progressbar, &.progressbar:focus { // progress bar in treeviews
    color: $selected_fg_color;
    border-radius: 2px;
    background-color: $selected_bg_color;

    &:selected, &:selected:focus {
      color: $selected_bg_color;
      box-shadow: none;
      background-color: $selected_fg_color;
    }
  }
  &.trough { // progress bar trough in treeviews
    color: $fg_color;
    background-color: $trough_color_treeview;
    border-radius: 2px;
    border: 1px solid $button_border;

    &:selected, &:selected:focus {
      color: $selected_fg_color;
      background-color: transparentize(black, 0.8);
      border-radius: 2px;
      border-width: 0;
    }
  }

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

      padding: 3px 6px;
      font-weight: bold;

      color: $_column_header_color;
      background-color: darken($bg_color, 1%);
      background-image: none;
      border-style: none solid solid none;
      border-radius: 0;
      border-color: $borders_color;

      &:active, &:hover { background-color: lighten($bg_color, 2%); }
      &:active:hover { color: $fg_color; }
      &:disabled {
        border-color: $bg_color;
        background-image: none;
      }
      &:last-child {
        border-right-style: none;
      }

      sort-indicator {
        &.ascending {
          -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
        }
        &.descending {
          -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        }

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

  button.dnd,
  header.button.dnd {
    &, &:selected, &:hover, &:active {
      transition: none;
      color: $selected_bg_color;
      box-shadow: inset 1px 1px 0 1px $selected_bg_color,
                  inset -1px 0 0 1px $selected_bg_color,
                  inset 1px 1px $base_color, inset -1px 0 $base_color;
    }
  }

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

//
// Popovers
//
$_popover_bg: if($variant == 'light', $base_color, $bg_color);

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

  > arrow,
  > contents {
    background-color: $_popover_bg;
    background-clip: border-box;
    border: 1px solid darken($borders_color, 5%);
    box-shadow: 0 2px 6px 1px if($variant!='dark', transparentize(black, 0.93), transparentize(black, 0.65));
  }

  > contents {
    padding: 8px;
    border-radius: 3px;

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

    separator {
      background-color: $_popover_bg;
      margin: 2px 0;
    }

    list separator { margin: 2px 0; }
  }

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

    > arrow,
    > contents {
      @extend %osd;
    }
  }

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

magnifier {
  background-color: $base_color;
}

//
// Popover Base Menus
//

$_menu-padding: 8px; //inner menuitem padding
//global $menu-margin for outside menuitems

popover.menu {
  padding: 0;

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

    button.image-button.model {
      @include button(normal);

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

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

  box.circular-buttons {
    padding: $_menu-padding $_menu-padding 6px;

    button.circular.image-button.model {
      @extend %list_button;

      padding: 11px;

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

  accelerator {
    color: gtkalpha(currentColor,0.55);

    &:dir(ltr) { margin-left: 22px; }//$_menu-padding;
    &:dir(rtl) { margin-right: 22px; }//$_menu-padding;
  }

  arrow.left,
  radio.left,
  check.left {
    margin-left: -1px;
    margin-right: 7px;
  }

  arrow.right,
  radio.right,
  check.right {
    margin-left: 7px;
    margin-right: -1px;
  }

  scale {
    padding: 5px $_menu-padding;
  }

  modelbutton {
    min-height: 16px;
    min-width: 40px;
    padding: 5px $_menu-padding;
    border-radius: 2px;
  }

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

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

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

  > item {
    padding: 6px 8px;
    border: solid transparent;
    border-width: 0;

    &:selected { //Seems like it :hover even with keyboard focus
      background-color: $menu_selected_bg_color;
      color: $fg_color;
    }
    &:disabled {
      color: transparentize($header_fg, 0.6);
      border-color: transparent;
    }
  }

  & > item popover.menu modelbutton {
    border-radius: 0;
  }

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

  //nested submenus
  & > item popover.menu popover.menu {
    margin-top: -5px;
  }
}

//
// Notebooks and Tabs
//
notebook {
  padding: 0;

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

    > header {
      // ugly hack to hide the borders around the header
      margin: -1px;
      &.top { margin-bottom: 0; }
      &.bottom { margin-top: 0; }
      &.left { margin-right: 0; }
      &.right { margin-left: 0; }

      &.top, &.bottom { padding-left: 0; padding-right: 0; }
      &.left, &.right { padding-top: 0; padding-bottom: 0; }
    }
  }

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

  > header {
    padding: 2px;
    background-color: $bg_color;

    &.top {    box-shadow: inset  0  -1px $borders_color; }
    &.bottom { box-shadow: inset  0   1px $borders_color; }
    &.right {  box-shadow: inset  1px 0   $borders_color; }
    &.left {   box-shadow: inset -1px 0   $borders_color; }

    @each $_pos, $_bpos in (top, bottom), (bottom, top), (right, left), (left, right) {
      // sizing and borders
      &.#{$_pos} {
        padding-#{$_bpos}: 0;

        > tabs > tab {
          padding: 2px 10px;
          min-width: 20px;
          min-height: 20px;

          outline-offset: -4px;

          border: 1px solid transparent;
          border-#{$_bpos}: none;

          // tab overlap
          + tab {
            @if $_pos==top or $_pos==bottom { margin-left: -1px; }
            @else { margin-top: -1px; }
          }

          // tab border radius
          @if $_pos==top { border-radius: 1px 1px 0 0; }
          @else if $_pos==bottom { border-radius: 0 0 1px 1px; }
          @else if $_pos==left { border-radius: 1px 0 0 1px; }
          @else if $_pos==right { border-radius: 0 1px 1px 0; }
        }
      }
    }
    // 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: transparentize($insensitive_fg_color,0.3); }
    }

    // tab colors

    &.top > tabs > tab:hover:not(:checked) { box-shadow: inset 0 -1px $borders_color; }
    &.bottom > tabs > tab:hover:not(:checked) { box-shadow: inset 0 1px $borders_color; }
    &.left > tabs > tab:hover:not(:checked) { box-shadow: inset -1px 0 $borders_color; }
    &.right > tabs > tab:hover:not(:checked) { box-shadow: inset 1px 0 $borders_color; }

    > tabs > tab {
      color: $insensitive_fg_color;
      background-color: transparentize($base_color, 1);

      &:hover:not(:checked) {
        color: mix($fg_color, $insensitive_fg_color, 50%);
        background-color: transparentize($base_color, 0.5);
        border-color: $borders_color;
      }
      &:checked {
        color: $fg_color;
        background-color: $base_color;
        border-color: $borders_color;
      }
      // close button
      button.flat {
        min-height: 22px;
        min-width: 16px;
        padding: 0;
        color: mix($bg_color, $fg_color, 35%);

        &:hover {
          @extend %undecorated_button;
          color: lighten(red, 15%);
        }
        &:active, &:active:hover {
          @extend %undecorated_button;
          color: $selected_bg_color;
        }
      }
    }

    /* button in headers */
    button.flat { padding: 2px; }
  }
}

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

scrollbar {
  $_slider_min_length: 40px;

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

  &.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; }

  // slider
  slider {
    min-width: 6px;
    min-height: 6px;
    margin: -1px;
    border: 4px solid transparent;
    border-radius: 8px;
    background-clip: padding-box;
    background-color: mix($fg_color, $bg_color, 40%);

    &:hover { background-color: mix($fg_color, $bg_color, 30%); }
    &:hover:active { background-color: $selected_bg_color; }
    &:disabled { background-color: transparent; }
  }

  &.fine-tune {
    slider {
      min-width: 4px;
      min-height: 4px;
    }

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

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

      slider {
        margin: 0;
        min-width: 4px;
        min-height: 4px;
        background-color: mix($fg_color, $bg_color, 70%);
        border: 1px solid if($variant == 'light', transparentize(white, 0.4), transparentize(black, 0.7));
        // background-clip: padding-box;
      }

      // w/o the following margin tweaks the slider shrinks when hovering/dragging
      &.vertical slider {
        margin: 2px 0;
        min-height: $_slider_min_length;
      }

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

    }

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

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

//
// Switches
//
switch {
  font-size: 1px;
  min-width: 52px;
  min-height: 24px;
  background-size: 52px 24px;
  background-repeat: no-repeat;
  background-position: center center;

  > slider {
    min-width: 1px;
    min-height: 1px;
  }

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

@each $k,$l in ('',''),
               (':checked','-active'),
               (':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"));
  }

  modelbutton:hover switch#{$k},
  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},
  .primary-toolbar switch#{$k},
  .primary-toolbar toolbar 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},
    #{$w}#{$s},
    treeview.#{$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,
    treeview.#{$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"));
    }
  }
}

checkbutton, radiobutton {
  // this is for a nice focus on check and radios text
  &.text-button {
      padding: 2px 0;
      outline-offset: 0;
    }

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

check,
radio {
  min-width: 16px;
  min-height: 16px;
  margin: 0 2px;

  &:only-child,
  menu menuitem & { margin: 0; }
}

//
// GtkScale
//
$_scale_trough_bg: if($variant == 'light', $button_border, darken($bg_color, 5%));

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

  &:disabled {
   background-color: transparentize($_scale_trough_bg, 0.45);
  }

  // ...on selected list-rows and infobars
  modelbutton:hover &,
  row:selected &,
  infobar & {
    background-color: transparentize(black, 0.8);

    &:disabled {
      background-color: transparentize(black, 0.9);
    }
  }

  // OSD
  .osd & {
    background-color: if($variant == 'lighter', $osd_button_border, lighten($osd_bg_color, 7%));

    &:disabled {  }
  }
}

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

  &:disabled {
    background-color: transparentize($selected_bg_color, 0.45);
  }

  // ...on selected list-rows and infobars
  modelbutton:hover &,
  row:selected &,
  infobar & {
    background-color: $selected_fg_color;

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

  // OSD
  .osd & {
    background-color: $selected_bg_color;

    &:disabled {  }
  }
}

scale {
  $_marks_length: 3px;
  $_marks_distance: 1px;

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

  @include focus-ring();

  // The slider is inside the trough, negative margin to make it bigger
  slider {
    min-height: 15px;
    min-width: 15px;
    margin: -6px;
  }

  // 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 backing bit, 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;

    background-color: transparentize($selected_bg_color, 0.5);

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

  > trough > slider {
    $_slider_border: if($variant=='light', transparentize(darken($button_border,25%), 0.5), darken($button_border,2%));

    background-clip: border-box;
    background-color: $button_bg;
    border: 1px solid $_slider_border;
    border-radius: 50%;
    box-shadow: none;

    &:disabled {
      background-color: mix($entry_bg, $bg_color, 55%);
      border-color: transparentize($_slider_border, 0.2);
    }
    &:active {
      background-color: $selected_bg_color;
      border-color: $selected_bg_color;
    }
    //OSD sliders
    .osd & {
      background-color: $osd_bg_color;
      border-color: $selected_bg_color;

      &:hover { background-color: $selected_bg_color; }
      &:active {
        background-color: darken($selected_bg_color, 10%);
        border-color: darken($selected_bg_color, 10%);
      }
    }
    //selected list-row and infobar sliders
    modelbutton:hover &,
    row:selected &,
    infobar & {
      background-color: $selected_fg_color;
      border-color: $selected_fg_color;

      &:hover {
        background-color: mix($selected_fg_color, $selected_bg_color, 85%);
        border-color: mix($selected_fg_color, $selected_bg_color, 85%);
      }
      &:active {
        background-color: mix($selected_fg_color, $selected_bg_color, 50%);
        border-color: mix($selected_fg_color, $selected_bg_color, 50%);
      }
      &:disabled {
        background-color: mix($selected_fg_color, $selected_bg_color, 55%);
        border-color: mix($selected_fg_color, $selected_bg_color, 55%);
      }
    }
  }

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

  &.horizontal {
    > marks {
      color: gtkalpha(currentColor, 0.4);
      &.top {
        margin-bottom: $_marks_distance;
        margin-top: -($_marks_distance + $_marks_length);
      }
      &.bottom {
        margin-top: $_marks_distance;
        margin-bottom: -($_marks_distance + $_marks_length);
      }

      indicator {
        background-color: currentColor;
        min-height: $_marks_length;
        min-width: 1px;
      }
    }

    &.fine-tune > marks {
      &.top {
        margin-bottom: ($_marks_distance - 1px);
        margin-top: -($_marks_distance + $_marks_length - 2px);
      }
      &.bottom {
        margin-top: ($_marks_distance - 1px);
        margin-bottom: -($_marks_distance + $_marks_length - 2px);
      }

      indicator { min-height: ($_marks_length - 1px); }
    }
  }

  &.vertical {
    > marks {
      color: gtkalpha(currentColor, 0.4);
      &.top {
        margin-right: $_marks_distance;
        margin-left: -($_marks_distance + $_marks_length);
      }
      &.bottom {
        margin-left: $_marks_distance;
        margin-right: -($_marks_distance + $_marks_length);
      }

      indicator {
        background-color: currentColor;
        min-height: 1px;
        min-width: $_marks_length;
      }
    }

    &.fine-tune > marks {
      &.top {
        margin-right: ($_marks_distance - 1px);
        margin-left: -($_marks_distance + $_marks_length - 2px);
      }
      &.bottom {
        margin-left: ($_marks_distance - 1px);
        margin-right: -($_marks_distance + $_marks_length - 2px);
      }

      indicator { min-height: ($_marks_length - 1px); }
    }
  }
}

//
// Progress bars
//
progressbar {
  // sizing
  &.horizontal {
    > trough {
      min-width: 150px;
      &, > progress { min-height: 6px; }
    }
  }

  &.vertical {
    > trough {
      min-height: 80px;
      &, > progress { min-width: 6px; }
    }
  }

  > trough {
    @extend %scale_trough;

    border-radius: 3px;
  }

  > trough > progress {
    @extend %scale_highlight;

    border-radius: 3px;
  }

  padding: 0;
  font-size: smaller;
  color: transparentize($fg_color, 0.3);
  font-feature-settings: "tnum";

  &.osd {
    min-width: 3px;
    min-height: 3px;
    background-color: transparent;

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

  > trough.empty > progress { all: unset; } // makes the progress indicator disappear, when the fraction is 0
}

//
// Level Bar
//
levelbar {
  &.horizontal {
    trough > block {
      min-height: 1px;
    }

    // segmented level bar
    &.discrete {
      trough > block {
        margin: 0 1px;
        min-width: 32px;
      }
    }
  }

  &.vertical {
    trough > block {
      min-width: 1px;
    }

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

  > trough {
    border: none;
    padding: 3px;
    border-radius: 3px;
    background-color: if($variant == 'light', $button_border, darken($bg_color, 5%));
  }

  // level bar colours
  > trough > block {
    &:not(.empty) {
      border: 1px solid $selected_bg_color;
      background-color: $selected_bg_color;
      border-radius: 2px;
    }
    &.low {
      border-color: $warning_color;
      background-color: $warning_color;
    }
    &.high {
      border-color: $selected_bg_color;
      background-color: $selected_bg_color;
    }
    &.full {
      border-color: $success_color;
      background-color: $success_color;
    }
    &.empty {
      background-color: if($variant!='dark', transparentize($fg_color,0.8), $base_color);
      border-color: if($variant!='dark', transparentize($fg_color,0.8), $base_color);
    }
  }
}

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

    paper {
      background: white;
      color: #5c616c;
      border: 1px solid $borders_color;
    }

  }

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

//
// Frames
//

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

frame {
  border-radius: 0;

  > label {
    margin: 4px;
  }
}

actionbar > revealer > box {
  padding: 5px;
  border-top: 1px solid $borders_color;
  background-color: darken($bg_color, 3%);

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

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

  > junction { // the small square between two scrollbars
    // Only color the top-left (or top right in RTL) pixel, to visually connect
    // the borders of the two scrollbars.

    background: $borders_color,
                linear-gradient(to bottom, transparent 1px, $_scrollbar_bg_color 1px),
                linear-gradient(to right, transparent 1px, $_scrollbar_bg_color 1px);

    &:dir(rtl) {
      background: $borders_color,
                  linear-gradient(to bottom, transparent 1px, $_scrollbar_bg_color 1px),
                  linear-gradient(to left, transparent 1px, $_scrollbar_bg_color 1px);
    }
  }
}

//vbox and hbox separators
separator {
  background-color: transparentize(black, 0.9);
  min-width: 1px;
  min-height: 1px;
}

//
// Lists
//
listview,
list {
  color: $text_color;
  background-color: $base_color;
  border-color: $borders_color;

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

  &.horizontal row.separator,
  &.separators.horizontal > row:not(.separator) {
    border-left: 1px solid transparentize(black, 0.9);
  }
  &:not(.horizontal) row.separator,
  &.separators:not(.horizontal) > row:not(.separator) {
    border-bottom: 1px solid transparentize(black, 0.9);
  }
}

row {
  @include focus-ring();

  &:not(:hover) { transition: all 150ms $ease-out-quad; }

  &:selected {
    @extend %selected_items;

    button { @extend %selected_button; }
  }

  &.activatable {
    &.has-open-popup,
    &:hover { background-color: if($variant == 'light', transparentize(black, 0.97), transparentize(white, 0.95)); }

    &:active { color: $fg_color; }
    &:disabled {
      color: $insensitive_fg_color;
      image { color: inherit; }
    }

    &:selected {
      &:active { color: $selected_fg_color; }

      &.has-open-popup,
      &:hover { background-color: mix(black, $selected_bg_color, 10%); }
    }
  }
}

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: transparentize(black, 0.9);
  }

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

treeexpander {
  border-spacing: 4px;
}

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

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

  border { border: none; }

  button {
    @include button(osd);
    &.flat {
      @extend %undecorated_button;
      border-color: transparentize($selected_bg_color, 1);
      &:disabled { @extend %undecorated_button; }
    }
    &:hover { @include button(osd-hover); }
    &:active, &:checked { @include button(osd-active); background-clip: padding-box; }
    &:disabled { @include button(osd-insensitive);
    }
  }
}

//
// 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 {
    border-radius: 3px;

    &: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: 3px;
  padding: 2px;

  > header {
    color: $fg_color;
    border: none;

    > button {
      &, &:hover, &:active, &:disabled {
        @extend %undecorated_button;
      }

      color: transparentize($fg_color,0.55);

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

  > grid {
    > label.day-name {
    }

    > label.week-number {
    }

    > label.today {
      &, &:selected, &:focus {
        @extend %selected_items;
      }
    }

    > label:focus {
      background-color: transparentize(black, 0.9);
    }

    > label.day-number {
      padding: 4px;
      border-radius: 3px;
      &:selected{
        background-color: transparentize(black, 0.85);
      }
    }

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

//
// Dialogs
//
.dialog-action-area {
  margin: 6px;

  button.text-button {
    padding: 6px 16px;
  }

  button {
    border-radius: 0;
    border-right-style: none;

    &:first-child {
      border-radius: 3px 0 0 3px;
      border-right-style: none;
    }

    &:last-child {
      border-radius: 0 3px 3px 0;
      border-style: solid;
    }
  }
}

window.dialog.message { // Message Dialog styling
  .titlebar {
    min-height: 20px;
    background-image: none;
    background-color: $header_bg;
    border-bottom: 1px solid darken($header_bg, 7%);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
  }

  .dialog-action-area button { padding: 8px; min-height: 0; }

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

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

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

    // .dialog-action-area { @include linking_rules(); }

    // }

    .dialog-action-area button {
      border-radius: 0;
      border-bottom-style: none;
      border-right-style: none;

      &:first-child {
        border-bottom-left-radius: 2px;
        border-left-style: none;
      }

      &:last-child {
        border-bottom-right-radius: 2px;
      }
    }
  }
}

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

  #pathbarbox {
    background-color: $filechooser_bg;
    border-bottom: 1px solid $borders_color;
  }
}

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

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

//
// Sidebar
//
.sidebar {
  border-style: none;
  background-color: lighten($bg_color, 2%);

  &: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: $base_color; }

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

stacksidebar {
  //not a regular list
  list.separators:not(.horizontal) > row:not(.separator) {
    border-bottom: none;
  }
  row {
    padding: 10px 4px;
    @include focus-ring();

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

    &.needs-attention > label {
      @extend %needs_attention;
       background-size: 6px 6px, 0 0;
    }
    &:hover {
      background-color: if($variant != 'dark', transparentize(black, 0.95), transparentize(white, 0.97));
    }
    &:selected {
      background-color: $selected_bg_color;
      border-radius: 0;
      color: $selected_fg_color;
    }
    &:selected:hover:dir(ltr), &:selected:hover:dir(rtl) {
      background-color: mix(black, $selected_bg_color, 10%);
    }
  }
}

separator.sidebar {
  background-color: $borders_color;

  .titlebar & {
    background-color: $header_border;
    margin: 0;
  }
}

//
// Navigation Sidebar
//

.navigation-sidebar {
  padding: 0;

  > separator {
    margin: 0;
  }

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

    @include focus-ring($focus-state: 'focus-visible:focus-within');
    &:hover {
      background-color: if($variant != 'dark', transparentize(black, 0.95), transparentize(white, 0.97));
    }

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

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

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

//
// File Chooser
//

$_placesidebar_icons_opacity: 0.7;

row image.sidebar-icon { opacity: $_placesidebar_icons_opacity; } // dim the sidebar icons
                                                                  // see bug #786613 for details
                                                                  // on this oddity

/* this should be more generic, only using .navigation-sidebar
   https://gitlab.gnome.org/GNOME/gtk/-/issues/2929
*/

placessidebar {
  .navigation-sidebar > row {
    // Needs overriding of the `.navigation-sidebar > row` padding
    padding: 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; }
    }

    @at-root button.sidebar-button {
      @extend %button_basic_flat;
      min-height: 22px;
      min-width: 22px;
      margin-top: 2px;
      margin-bottom: 2px;
      padding: 0;
      border-radius: 100%;
    }

    &.sidebar-placeholder-row {
      padding: 0 8px;
      min-height: 2px;
      background-image: image($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 {
  .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);
  }

  row.activatable:hover {  }

  > 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: transparent;
    }
  }

  &.horizontal > separator {
    background-repeat: repeat-y;
    margin: 0 -3px 0 -3px;
    padding: 0 3px 0 3px;
    background-position: center;

    &.wide {
      margin: 0;
      padding: 0;
      background-repeat: no-repeat;
      background-position: center;
      background-image: -gtk-scaled(url("assets/pane-separator-vertical.png"), url("assets/pane-separator-vertical@2.png"));
      background-size: 2px 24px;
    }
  }

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

    &.wide {
      margin: 0;
      padding: 0;
      background-repeat: no-repeat;
      background-position: center;
      background-image: -gtk-scaled(url("assets/pane-separator.png"), url("assets/pane-separator@2.png"));
      background-size: 24px 2px;
    }
  }
}

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

  &.info,
  &.question,
  &.warning,
  &.error {
    background-color: $selected_bg_color;
    color: $selected_fg_color;
    caret-color: currentColor;

    button { @extend %selected_button }

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

    *:link { @extend %link_selected; }

    &:disabled {
      label, image { color: transparentize($selected_fg_color, 0.5); }
    }
  }

  &.warning { background-color: $warning_color; }
  &.error { background-color: $destructive_color; }
  &.question { background-color: $question_color; }
}

//
// GtkVideo
//

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

//
// Buttons on selected backgrounds
//
%selected_button {

  @at-root %selected_button_normal, & {
    color: $selected_fg_color;
    background-color: transparentize($selected_fg_color, 1);
    border-color: transparentize($selected_fg_color, 0.5);
  }

  &.flat {
    @include button(undecorated);
    color: $selected_fg_color;
    background-color: transparentize($selected_fg_color, 1);

    @at-root %selected_button_flat_disabled,
    &:disabled {
      &, label { color: transparentize($selected_fg_color, 0.6); }
    }
  }
  &:hover {
    color: $selected_fg_color;
    background-color: transparentize($selected_fg_color, 0.8);
    border-color: transparentize($selected_fg_color, 0.2);
  }
  @at-root %selected_button_active,
  &:active, &:active:hover, &:checked {
    color: $selected_bg_color;
    background-color: $selected_fg_color;
    border-color: $selected_fg_color;
  }
  &:disabled {
    &, label { color: transparentize($selected_fg_color, 0.5); }
    background-color: transparentize($selected_fg_color, 1);
    border-color: transparentize($selected_fg_color, 0.6);

    @at-root %selected_button_disabled_checked,
    &:active, &:checked {
      color: $selected_bg_color;
      background-color: transparentize($selected_fg_color, 0.5);
      border-color: transparentize($selected_fg_color, 0.6);
    }
  }
}

//
// 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: $tooltip_bg_color;
    background-clip: padding-box;
    color: $tooltip_fg_color;
    padding: 6px 10px;
    label { padding: 4px; }
  }

  border-radius: 5px;
  border: none;
}

//
// 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.

  @include focus-ring();

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

  // border rounding
  &.top {
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;

    overlay {
      border-top-left-radius: 3px;
      border-top-right-radius: 3px;
    }
  }
  &.bottom {
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;

    overlay {
      border-bottom-left-radius: 3px;
      border-bottom-right-radius: 3px;
    }
  }
  &.left, &:first-child:not(.top) {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;

    overlay {
      border-top-left-radius: 3px;
      border-bottom-left-radius: 3px;
    }
  }
  &.right, &:last-child:not(.bottom) {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;

    overlay {
      border-top-right-radius: 3px;
      border-bottom-right-radius: 3px;
    }
  }
  &.dark overlay {
    color: transparentize(white, 0.3);
    &:hover {
      border-color: if($variant == 'light', transparentize(black, 0.5), $borders_color);
    }
  }
  &.light overlay {
    color: transparentize(black, 0.3);
    &:hover {
      border-color: if($variant == 'light', transparentize(black, 0.7), $borders_color);
    }
  }

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

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

  // make the add color button looks like, well, a button
  &#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;
    }
  }
}

// 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); }
  > rubberband { @extend rubberband; }

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

    &:active, &:selected { background-color: if($variant!='dark', transparent, $selected_bg_color); }
    &:disabled { background-color: if($variant!='dark', transparent, $insensitive_bg_color); }
  }
}

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

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

//
// Window Decorations
//
window {
  // border-radius: 8px 8px 0 0;
  border-width: 0px;

  $_wm_border: if($variant=='light', transparentize(black, 0.77), transparentize(black, 0.25));
  $_wm_border_backdrop: if($variant=='light', transparentize(black, 0.82), transparentize(black, 0.25));

  &.csd {
    box-shadow: 0 3px 9px 1px transparentize(black, 0.5),
                0 0 0 1px $_wm_border; //doing borders with box-shadow

    // this is used for the resize cursor area
    margin: 0;
    border-radius: 8px 8px 0 0;

    &: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 9px 1px transparent,
                  0 2px 6px 2px transparentize(black, 0.8),
                  0 0 0 1px $_wm_border_backdrop;
    }

    &.popup {
      border-radius: 8px;
      box-shadow: 0 3px 9px 1px transparentize(black, 0.5),
                  0 0 0 1px $_wm_border;
    }

    &.dialog.message {
      border-radius: 8px 8px 0 0;
    }
  }

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

  &.tiled,
  &.tiled-top,
  &.tiled-right,
  &.tiled-bottom,
  &.tiled-left {
    border-radius: 0;
    box-shadow: 0 0 0 1px $_wm_border,
                0 0 0 20px transparent; //transparent control workaround -- #3670

    &:backdrop { box-shadow: 0 0 0 1px $_wm_border_backdrop,
                             0 0 0 20px transparent; // #3670
    }
  }

  &.popup {
    box-shadow: none;
    border-radius: 0;
  }
  // server-side decorations as used by mutter
  &.ssd { box-shadow: 0 0 0 1px $_wm_border; }
  &.ssd:backdrop { box-shadow: 0 0 0 1px $_wm_border_backdrop; }
  &.ssd.maximized,
  &.ssd.maximized:backdrop { box-shadow: none; }

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

tooltip.csd {
    border-radius: 5px;
    box-shadow: none;
  }

// catch all extend
%selected_items {
  background-color: $selected_bg_color;

  @at-root %nobg_selected_items, & {
    color: $selected_fg_color;

    @at-root %selected_items_disabled,
    &:disabled { color: mix($selected_fg_color, $selected_bg_color, 50%); }
  }
}

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.circular {
  border-spacing: 12px;

  // FIXME aggregate with buttons
  > button.circular,
  > button.text-button.circular {
    min-width: 0;
    min-height: 0;
    padding: 0;
  }
}

//
// App Icons
//

/* Outline for low res icons */
.lowres-icon {
  -gtk-icon-shadow: none;
}

/* Drapshadow for large icons */
.icon-dropshadow {
  -gtk-icon-shadow: none;
}

//
// Emoji
//

popover.emoji-picker > contents {
  padding: 0;
}

.emoji-searchbar {
  padding: 5px;
  border-spacing: 6px;
  border-bottom: 1px solid $borders_color;
}

.emoji-toolbar {
  padding: 5px;
  border-spacing: 6px;
  border-top: 1px solid $borders_color;
}

button.emoji-section {
  &:active, &:checked { border-color: transparent; }
}

popover.emoji-picker emoji {
  font-size: x-large;
  padding: 5px;
  border-radius: 2px;

  &:focus,
  &:hover {
    background: $selected_bg_color;
  }
}

emoji-completion-row > box {
  border-spacing: 8px;
  padding: 2px 8px;
}

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: $selected_bg_color;
  color: $selected_fg_color;
}

popover.entry-completion > contents {
  padding: 0;
}

statusbar {
  padding: 5px 8px 5px 8px;
}

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

  arrow {
    min-height: 16px;
    min-width: 16px;
    &.none {
      -gtk-icon-source: -gtk-icontheme('open-menu-symbolic');
    }
    &.down {
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    }
    &.up {
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
    }
    &.left {
      -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
    }
    &.right {
      -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
    }
  }
}
