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

* {
  padding: 0;
  -GtkToolButton-icon-spacing: 4;
  -GtkTextView-error-underline-color: $error_color;

  // The size for scrollbars. The slider is 2px smaller, but we keep it
  // up so that the whole area is sensitive to button presses for the
  // slider. The stepper button is larger in both directions, the slider
  // only in the width

  -GtkScrolledWindow-scrollbar-spacing: 0;

  -GtkToolItemGroup-expander-size: 11;

  -GtkWidget-text-handle-width: 20;
  -GtkWidget-text-handle-height: 24;

  -GtkDialog-button-spacing: 4;
  -GtkDialog-action-area-border: 0;

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

  outline-color: gtkalpha(currentColor, 0.3);
  outline-style: dashed;
  outline-offset: -3px;
  outline-width: 1px;
  -gtk-outline-radius: 0px;
  -gtk-secondary-caret-color: $selected_bg_color
}

$ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$asset_suffix: if($variant=='dark', '-dark', '');
$small_radius: 4px;
$medium_radius: 6px;
$large_radius: 12px;
$backdrop_transition: all 200ms ease-out;
$button_transition: all 0.4s ease-out;
$menu_shadow: 0 1px 2px transparentize(black, 0.8);
$popover_shadow: 0 2px 5px transparentize(black, 0.8);
$window_border: if($variant == 'light', transparentize(black, 0.96), transparentize(black, 0.8));
$menu_border: if($variant=='light', transparentize(black, 0.8), transparentize(white, 0.88));

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

  &:backdrop {
    color: $backdrop_fg_color;
    background-color: $backdrop_bg_color;
  }
}

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

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

.gtkstyle-fallback {
  color: $fg_color;
  background-color: $bg_color;

  &:hover {
    color: $fg_color;
    background-color: lighten($bg_color, 10%);
  }

  &:active {
    color: $fg_color;
    background-color: darken($bg_color, 10%);
  }

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

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

widget:selected { color: $selected_fg_color; }

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

  &:backdrop {
    color: $backdrop_text_color;
    background-color: $backdrop_base_color;
    &:disabled { color: $backdrop_insensitive_color; }
  }

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

  &:selected {
    /* below 'border-color' actually targets check/radio
     * border in a selected (orange) row. I could not find
     * a less generic way to target such widgets inside a .view.
     * NOTE: white is the right color for both light and dark variant. */
    border-color: white;

    &:focus, & {
      @extend %selected_items;
      /* border-radius change here caused issue 473: selected radio becomes squared
       * keeping the code since it is not clear if removing it can cause any side effect
       * border-radius: 3px; */
    }

  }
}

.view,
textview {
  text {
    @extend %view;
    selection { &:focus, & { @extend %selected_items; }}
  }
}

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

iconview { @extend .view; &:selected { border-radius: $small_radius; } }

.rubberband,
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;

    &:selected {
      @extend %selected_items;

      outline-offset: -2px;
    }
  }
}

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

  &:backdrop { background-color: if($variant=='light', transparent, transparent); }
  &:active, &:selected { background-color: if($variant=='light', transparent, transparent); }
  &:disabled { background-color: if($variant=='light', transparent, transparent); }
}

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

  &.separator {
    @extend .dim-label;

    color: $fg_color;

    &:backdrop { color: $backdrop_text_color; }
  }

  &:selected { @extend %nobg_selected_items; }

  selection {
    @extend %selected_items;
  }
  counter-label{background-color: $purple;}

  &:disabled {
    color: $insensitive_fg_color;

    selection { @extend %selected_items:disabled; }

    &:backdrop { color: $backdrop_insensitive_color; }
  }

  &:backdrop {
    color: $backdrop_text_color;

    selection { @extend %selected_items:backdrop; }
  }
}

.dim-label {
  opacity: 0.55;
}

//Used as update count in GNOME software
.counter-label {
  margin-top: 2px;
  margin-bottom: 2px;
  border-width: 0px;
  padding-left: 2px;
  padding-right: 2px;
  box-shadow: inset 0 0 10px 10px $success_color;
}
//Used as error count in GNOME logs
.compressed-entries-label { box-shadow: inset 0 0 10px 10px darken($bg_color,40%); }

assistant {
  .sidebar {
    background-color: $sidebar_bg_color;
    border-top: 1px solid $borders_color;

    &:backdrop {
      background-color: $backdrop_sidebar_bg_color;
      border-color: $backdrop_borders_color;
    }
  }

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

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

  .sidebar label.highlight { background-color: mix($bg_color, $fg_color, 80%); }
}

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


/*********************
 * Spinner Animation *
 *********************/
@keyframes spin {
  to { -gtk-icon-transform: rotate(1turn); }
}

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

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

    &:disabled { opacity: 0.5; }
  }

  &:backdrop { color: _backdrop_color($blue); }
}


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

%entry,
entry {
  %entry_basic, & {
    min-height: 24px;
    padding: 2px 6px;
    border: 1px solid;
    border-radius: $small_radius;
    caret-color: currentColor;

    @include entry(normal);

    image { // icons inside the entry
      &.left { margin-right: 6px; }
      &.right { margin-left: 6px; }
    }

    undershoot {
      &.left { @include undershoot(left); }
      &.right { @include undershoot(right); }
    }

    &.flat {
      &:focus, & {
        min-height: 0;
        padding: 2px;
        background-color: transparent;
        border-color: transparent;
        border-radius: 0;
      }
    }

    &:focus {
      @include entry(focus);
      transition: $button_transition;
    }

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

    &:backdrop {
      @include entry(backdrop);

      transition: $backdrop_transition;
    }

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

    selection {
      @extend %selected_items;
    }

    // entry error and warning style
    @each $e_type, $e_color in (error, $error_color),
                               (warning, $warning_color) {
      &.#{$e_type} {
        color: $e_color;
        border-color: entry_focus_border($e_color);

        &:focus { @include entry(focus, $e_color); }

        &:not(:focus) { border-color: $borders_color; }
        &:backdrop { border-color: $backdrop_borders_color; }
        selection { background-color: $e_color; }
      }
    }

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

      &:hover { color: $fg_color; }

      &:active { color: $selected_bg_color; }

      &:backdrop { color: mix($backdrop_fg_color, $backdrop_base_color, 80%); }
    }

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

    .osd & {
      @include entry(osd);

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

      &:backdrop { @include entry(osd-backdrop); }

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

  progress {
    margin: 2px -6px;
    background-color: transparent;
    background-image: none;
    border-radius: 0;
    border-width: 0 0 2px;
    border-color: $neutral_color;
    border-style: solid;
    box-shadow: none;

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

   // linked entries
  .linked:not(.vertical) > & { @extend %linked; }
  .linked:not(.vertical) > &:focus + &,
  .linked:not(.vertical) > &:focus + button,
  .linked:not(.vertical) > &:focus + combobox > box > button.combo { transition: $button_transition; border-left-color: entry_focus_border(); }

  .linked:not(.vertical) > &:focus.error + &,
  .linked:not(.vertical) > &:focus.error + button,
  .linked:not(.vertical) > &:focus.error + combobox > box > button.combo { transition: $button_transition; border-left-color: entry_focus_border($error_color); }

  .linked:not(.vertical) > &:focus.warning + &,
  .linked:not(.vertical) > &:focus.warning + button,
  .linked:not(.vertical) > &:focus.warning + combobox > box > button.combo { transition: $button_transition; border-left-color: entry_focus_border($warning_color); }

  .linked:not(.vertical) > &:drop(active) + &,
  .linked:not(.vertical) > &:drop(active) + button,
  .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%);

      &:backdrop { border-top-color: mix($backdrop_borders_color, $backdrop_base_color, 30%); }
    }

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

    // color back the top border of a linked focused entry following another entry.
    // :not(:only-child) is a specificity bump hack.
    + %entry:focus:not(:only-child),
    + entry:focus:not(:only-child) { border-top-color: entry_focus_border(); }

    + %entry:focus.error:not(:only-child),
    + entry:focus.error:not(:only-child) { border-top-color: entry_focus_border($error_color); }

    + %entry:focus.warning:not(:only-child),
    + entry:focus.warning:not(:only-child) { border-top-color: entry_focus_border($warning_color); }

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

    // this takes care of coloring the top border of the focused entry subsequent widget.
    // :not(:only-child) is a specificity bump hack.
    &:focus:not(:only-child) {
      + %entry,
      + entry,
      + button,
      + combobox > box > button.combo { border-top-color: entry_focus_border(); }
    }

    &:focus.error:not(:only-child) {
      + %entry,
      + entry,
      + button,
      + combobox > box > button.combo { border-top-color: entry_focus_border($error_color); }
    }

    &:focus.warning:not(:only-child) {
      + %entry,
      + entry,
      + button,
      + combobox > box > button.combo { border-top-color: entry_focus_border($warning_color); }
    }

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

treeview, row {
  &:focus {
    outline-color: transparentize(white, 0.2);
    outline-offset: -2px;
    -gtk-outline-radius: $small_radius;
  }

  &:backdrop:hover { background-color: lighten($base_hover_color, 20%); }
}

treeview entry {
  &:focus {
    &: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 { border-color: $selected_bg_color; }
  }
}

.entry-tag {
  // sizing
  padding: 5px;
  margin-top: 4px; 
  margin-bottom: 4px;
  // side margins: compensate the entry padding with a negative margin
  // then the negative margin itself
  :dir(ltr) & {
    margin-left: 8px;
    margin-right: -3px;
  }
  :dir(rtl) & {
    margin-left: -5px;
    margin-right: 8px;
  }
  border-color: transparent;
  background-color: $slate;
  color: darken($silk, 3%);
  &.button:hover { color: white; }
}

/***********
 * Buttons *
 ***********/
// stuff for .needs-attention
$_dot_color: if($variant=='light', $selected_bg_color,
                                   lighten($selected_bg_color,15%));
@keyframes needs_attention {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.01,
                                    to($_dot_color),
                                    to(transparent));
  }

  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($selected_bg_color),
                                    to(transparent));
  }
}

%button,
button {
  @at-root %button_basic, & {
    animation: shrink 1s linear infinite;
    min-height: 24px;
    min-width: 16px;
    padding: 2px 6px;
    border: 1px solid;
    border-radius: $small_radius;
    outline-style: dashed;
    outline-offset: -3px;
    -gtk-outline-radius: $small_radius;

    @include button(normal);

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

        &:active { transition: $button_transition; }
      }

      @each $state, $t in (":hover", "hover"), (":hover:backdrop", "backdrop-hover"),
      (":active, &:checked", "active"), (":disabled", "insensitive"),
      (":disabled:active, &:disabled:checked", "insensitive-active"), (":backdrop", "backdrop"),
      (":backdrop:active, &:backdrop:checked", 'backdrop-active'), (":backdrop:disabled", 'backdrop-insensitive'),
      (":backdrop:disabled:active, &:backdrop:disabled:checked", 'backdrop-insensitive-active') {
        &#{$state} { @include button($t, $flat:true); }
      }
    }

    &.default:not(.suggested-action):not(.destructive-action) {
        color: if($variant=='light', black, white);
    }

    &:hover {
      @include button(hover);
      -gtk-icon-effect: highlight;
      transition: $button_transition;

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

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

      transition-duration: 100ms;
    }

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

    &:backdrop {
      &.flat, & {
        @include button(backdrop);

        transition: $backdrop_transition;
        outline-color: gtkalpha(currentColor, 0.3);
        -gtk-icon-effect: none;

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

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

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

    &.flat { &:backdrop, &:disabled, &:backdrop:disabled { @include button(undecorated); }}

    &:disabled {
      @include button(insensitive);

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

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

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

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

      label {
        padding-left: 8px;
        padding-right: 8px;
      }
    }

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

  @at-root %button_selected, & {
    row:selected & {
      @if $variant == 'light' { border-color: _border_color($selected_bg_color); }

      &.flat:not(:active):not(:checked):not(:hover):not(disabled) {
        color: $selected_fg_color;
        border-color: transparent;

        &:backdrop { color: if($variant=='light', $backdrop_base_color, $backdrop_fg_color); }
      }
    }
  }


  // big standalone buttons like in Documents pager
  &.osd {
    min-width: 24px;
    min-height: 32px;

    &.image-button { min-width: 32px; }

    color: $osd_fg_color;
    border-radius: $small_radius;

    @include button(osd);

    border: none;
    box-shadow: none;

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

      border: none;
      box-shadow: none;
    }

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

      border: none;
      box-shadow: none;
    }

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

        border: none;
      }
    }

    &:backdrop {
      @include button(osd-backdrop);

      border: none;
    }
  }

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

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

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

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

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

    &.flat {
      @include button(undecorated);
      box-shadow: none; //FIXME respect no edge on the button mixin


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

      &:disabled {
        @include button(osd-insensitive);
        background-image: none;
        border-color: transparent;
        box-shadow: none;
      }

      &:backdrop { @include button(undecorated); }

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

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color in (suggested-action, $success_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} {
      @include button(normal, $b_color, white);

      &.flat {
        @include button(undecorated);

        color: $b_color; //FIXME: does it work on the dark variant?
      }

      &:hover { @include button(hover, $b_color, white); }

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

      &:backdrop,
      &.flat:backdrop {
        @include button(backdrop, $b_color, white);

        &:active,
        &:checked { @include button(backdrop-active, $b_color, white); }

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

          &:active,
          &:checked { @include button(backdrop-insensitive-active, $b_color, white); }
        }
      }

      &.flat {
        &:backdrop, &:disabled, &:backdrop:disabled {
          @include button(undecorated);

          color: transparentize($b_color, 0.2);
        }
      }

      &:disabled {
        @include button(insensitive);

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

      .osd & {
        @include button(osd, $b_color);

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

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

        &:disabled { &:backdrop, & { @include button(osd-insensitive, $b_color); }}

        &:backdrop { @include button(osd-backdrop, $b_color); }
      }
      &:focus { outline-color: white; }
    }
  }

  &.destructive-action image {
    -gtk-icon-shadow: 1px  0px 1px darken($destructive_color, 25%),
                      0px  1px 1px darken($destructive_color, 25%),
                      0px -1px 1px darken($destructive_color, 25%),
                     -1px  0px 1px darken($destructive_color, 25%);
    &:backdrop {
      -gtk-icon-shadow: 1px  0px 1px darken($destructive_color, 10%),
                        0px  1px 1px darken($destructive_color, 10%),
                        0px -1px 1px darken($destructive_color, 10%),
                       -1px  0px 1px darken($destructive_color, 10%);
    }
  }

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

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

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

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

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

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

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




  // hide separators
  &.font,
  &.file { separator { background-color: transparent; }}

  &.font { > box > box > label { font-weight: 500; }}

  // inline-toolbar buttons
  .inline-toolbar &, .inline-toolbar &:backdrop {
    border-radius: 2px;
    border-width: 1px;
    @extend %linked;
  }

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

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

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

  &.circular { // The Bloody Circul Button
    border-radius: 9999px;
    -gtk-outline-radius: 9999px;

    label { padding: 0; }

    // the followind code is needed since we use a darker bottom border on buttons, which looks pretty
    // bad with a 100% border radius (see https://bugzilla.gnome.org/show_bug.cgi?id=771205 for details),
    // so on relevant states we an additional background-image with a gradient clipped on the border-box,
    // so setting a transparent border would reveal it.
    // FIXME: take care of colored circular button.

    &:not(.flat):not(:checked):not(:active):not(:disabled):not(:backdrop),
    &:hover:not(:checked):not(:active):not(:disabled):not(:backdrop),
    &:checked, &:active {
      border-color: $borders_color;
      box-shadow: none;
    }

    &:not(.flat):not(:checked):not(:active):not(:disabled):not(:backdrop) {
      @include button(normal);
    }

    &:hover:not(:checked):not(:active):not(:disabled):not(:backdrop) {
      @include button(hover);
    }

    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
  }
}

%needs_attention {
  animation: needs_attention 150ms ease-in;
  $_dot_shadow: _text_shadow_color();
  $_dot_shadow_r: if($variant=='light',0.5,0.45);
  background-image: -gtk-gradient(radial,
                                  center center, 0,
                                  center center, 0.5,
                                  to($_dot_color),
                                  to(transparent)),
                    -gtk-gradient(radial,
                                  center center, 0,
                                  center center, $_dot_shadow_r,
                                  to($_dot_shadow),
                                  to(transparent));
  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; }
  }
}


// all the following is for the +|- buttons on inline toolbars, that way
// should really be deprecated...
.inline-toolbar toolbutton > button { // redefining the button look is
                                      // needed since those are flat...
  @include button(normal);

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

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

  &:disabled {
    @include button(insensitive);

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

  &:backdrop {
    @include button(backdrop);

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

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

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

// More inline toolbar buttons
toolbar.inline-toolbar toolbutton,
toolbar.inline-toolbar toolbutton:backdrop {
  > button.flat { @extend %linked_middle; }

  &:first-child > button.flat { @extend %linked:first-child; }

  &:not(:first-child) > button.flat {
    // linked buttons will have more defined border colors
    border-left-color: $borders_color;
    &:disabled { border-left-color: $insensitive_borders_color;}
  }

  &:last-child > button.flat { @extend %linked:last-child; }

  &:only-child > button.flat { @extend %linked:only-child; }
}

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

%linked {
  @extend %linked_middle;

  &:first-child {
    border-top-left-radius: $small_radius;
    border-bottom-left-radius: $small_radius;
    -gtk-outline-radius: $small_radius 0 0 $small_radius;

  }

  &:last-child {
    border-top-right-radius: $small_radius;
    border-bottom-right-radius: $small_radius;
    border-right-style: solid;
    -gtk-outline-radius: 0 $small_radius $small_radius 0;
  }

  &:only-child {
    border-radius: $small_radius;
    -gtk-outline-radius: $small_radius;
    border-style: solid;
  }
}

%linked_vertical_middle {
  border-style: solid solid none solid;
  border-radius: 0;
  -gtk-outline-radius: 0px;
}

%linked_vertical{
  @extend %linked_vertical_middle;

  &:not(:first-child) {
    // linked buttons will have more defined border colors
    border-top-color: $borders_color;
    &:disabled { border-top-color: $insensitive_borders_color;}
  }

  &:first-child {
    border-top-left-radius: $small_radius;
    border-top-right-radius: $small_radius;
    -gtk-outline-radius: $small_radius $small_radius 0 0;
  }

  &:last-child {
    border-bottom-left-radius: $small_radius;
    border-bottom-right-radius: $small_radius;
    -gtk-outline-radius: 0 0 $small_radius $small_radius;
    border-style: solid;
  }

  &:not(:last-child) {
    // only the last button will have the 3d effect
    box-shadow: none;
  }

  &:only-child {
    border-radius: $small_radius;
    -gtk-outline-radius: $small_radius;
    border-style: solid;
  }
}

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

%jet_popover_button {
  background-color: transparent;
  &.suggested-action:not(:disabled):not(:active):not(:hover) { background-color: $success_color; border-color: $success_color; }
  &.destructive-action:not(:disabled):not(:active):not(:hover) { background-color: $destructive_color; border-color: $destructive_color; }
  &, &:hover, &:active, &:checked { box-shadow: none; }
  &:hover, &:checked:hover { background-color: lighten($inkstone, 2%); border-color: lighten($inkstone, 2%); }
  &:checked { background-color: $inkstone; border-color: $inkstone; }
  &:active, &:checked:active { background-color: lighten($inkstone, 5%) }
  &:backdrop {
    check, radio { background-color: transparent; }
    &:hover { background-color: lighten($backdrop_menu_color, 2%); } 
  }
}

/* menu buttons */
modelbutton.flat,
.menuitem.button.flat {
  min-height: 26px;
  padding-left: 5px;
  padding-right: 5px;
  border-radius: 3px;
  -gtk-outline-radius: 3px;
  outline-offset: -2px;

  @extend %undecorated_button;

  &:hover { background-color: $base_hover_color; }
  &:active { background-color: $base_active_color; }

  &:selected { @extend %selected_items; }

  &:backdrop,
  &:backdrop:hover { @extend %undecorated_button; }
}

modelbutton.flat arrow {
  background: none;

  &:hover { background: none; }

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

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

button.color {
  padding: 4px;

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

    @if $variant == 'light' {
      box-shadow: 0 1px _text_shadow_color();

      .osd & { box-shadow: none; }
    }
  }

  @if $variant == 'light' {
    .osd &, & {
      &:disabled,
      &:backdrop,
      &:active,
      &:checked { colorswatch:only-child { box-shadow: none; }}
    }
  }
}


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

%link,
*:link {
  color: $link_color;

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

  &:backdrop { &:backdrop:hover, &:backdrop:hover:selected, & { color: _backdrop_color($link_color); }}

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

button:link,
button:visited {
  @extend %undecorated_button;
  @extend *:link;

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

  > label {
    @extend %link;
  }

  &:hover > label {
    text-decoration-line: underline;
  }

  &:backdrop:hover {
      background-color: transparent;
      border-color: transparent;
  }

}


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

    padding: 0;

    entry {
      min-width: 28px;
      // reset all the other props since the spinbutton node is styled here
      margin: 0;
      background: none;
      background-color: transparent;
      border: none;
      border-radius: 0;
      box-shadow: none;

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

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

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

      &:hover {
        background-color: if($light, darken($bg_color, 3%), lighten($bg_color, 15%));

        &:backdrop {
            background-color: lighten($backdrop_bg_color, 8%);
        }
      }

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

      &:active {
        background-color: transparentize(black, 0.9);
        box-shadow: inset 0 2px 3px -1px transparentize(black, 0.8);
      }

      &:backdrop {
        color: mix($backdrop_fg_color, $backdrop_base_color, 90%);
        background-color: transparent;
        border-color: $backdrop_borders_color;
        transition: $backdrop_transition;

        &:disabled {
            color: transparentize($insensitive_fg_color, 0.5);
            background-color: transparent;
            border-style: none none none solid; // It is needed or it gets overridden
            border-color: transparentize($backdrop_borders_color, 0.3);

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

      &:dir(ltr):last-child { border-radius: 0 $small_radius $small_radius 0; }

      &:dir(rtl):first-child { border-radius: $small_radius 0 0 $small_radius; }
    }
  }

  // OSD horizontal
  .osd &:not(.vertical) {
    button {
      @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;

      &: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: transparentize($osd_fg_color, 0.9);
        box-shadow: none;
      }

      &:backdrop {
        @include button(undecorated);

        color: $osd_fg_color;
        border-color: transparentize(opacify($osd_borders_color, 1), 0.5);
        box-shadow: none;
      }

      &:disabled {
        @include button(undecorated);

        color: $osd_insensitive_fg_color;
        border-color: transparentize(opacify($osd_borders_color, 1), 0.5);
        box-shadow: none;
      }

      &:dir(ltr):last-child { border-radius: 0 $small_radius $small_radius 0; }

      &:dir(rtl):first-child { border-radius: $small_radius 0 0 $small_radius; }
    }
  }

  // Vertical
  &.vertical {
    // in the vertical configuration, we treat the spinbutton
    // as a box, and tweak the style of the entry in the middle
    // so that it's linked

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

    &:backdrop:disabled { color: $backdrop_insensitive_color; }

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

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

      &:backdrop {
        border-color: $backdrop_borders_color;
        &:disabled { border-color: transparentize($backdrop_borders_color, 0.3); }
      }
      &:disabled { border-color: $insensitive_borders_color; }
    }

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

      &.up { @extend %top_button; }

      &.down { @extend %bottom_button; }
    }

    %top_button {
      border-radius: $small_radius $small_radius 0 0;
      border-style: solid solid none solid;
    }

    %bottom_button {
      border-radius: 0 0 $small_radius $small_radius;
      border-style: none solid solid solid;
    }
  }

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

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

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

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


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

  &.linked {
    button:nth-child(2) {
      &:dir(ltr) { @extend %linked:last-child; }
      &:dir(rtl) { @extend %linked:first-child; }
    }
  }

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

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

.linked > combobox > box > button.combo {
  // the combo is a composite widget so the way we do button linking doesn't
  // work, special case needed. See
  // https://bugzilla.gnome.org/show_bug.cgi?id=733979
  &:dir(ltr),
  &:dir(rtl) { @extend %linked_middle; } // specificity bump
}

.linked:not(.vertical) > combobox:first-child > box > button.combo { @extend %linked:first-child; }
.linked:not(.vertical) > combobox:last-child > box > button.combo { @extend %linked:last-child; }
.linked:not(.vertical) > combobox:only-child > box > button.combo { @extend %linked:only-child; }
.linked:not(.vertical) > combobox:not(:first-child) > box > button.combo {
  // linked buttons will have more defined border colors
  border-left-color: $borders_color;
  &:disabled { border-left-color: $insensitive_borders_color; }
}

.linked.vertical > combobox > box > button.combo { @extend %linked_vertical_middle; }
.linked.vertical > combobox:first-child > box > button.combo { @extend %linked_vertical:first-child;}
.linked.vertical > combobox:last-child > box > button.combo { @extend %linked_vertical:last-child; }
.linked.vertical > combobox:only-child > box > button.combo { @extend %linked_vertical:only-child; }
.linked.vertical > combobox:not(:first-child) > box > button.combo {
  // linked buttons will have more defined border colors
  border-top-color: $borders_color;
  &:disabled { border-top-color: $insensitive_borders_color; }
}


/************
 * Toolbars *
 ************/
%toolbar {
  -GtkWidget-window-dragging: true;
  padding: 4px;
  background-color: $bg_color;
}

toolbar {
  @extend %toolbar;

  padding: 4px 3px 3px 4px;

  button.flat {
    @each $state, $t, $is_flat in ("", "normal", true),
                                  (":hover, &:hover:checked", "hover", false),
                                  (":hover:backdrop, &:hover:backdrop:checked", "backdrop-hover", false),
                                  (":active, &:checked", "active", false),
                                  (":disabled", "insensitive", true),
                                  (":disabled:active, &:disabled:checked", "insensitive-active", false),
                                  (":backdrop", "backdrop", true),
                                  (":backdrop:active, &:backdrop:checked", 'backdrop-active', true),
                                  (":backdrop:disabled", 'backdrop-insensitive', true),
                                  (":backdrop:disabled:active, &:backdrop:disabled:checked", 'backdrop-insensitive-active', true) {
      &#{$state} { @include button($t, $c:$menu_color, $flat:$is_flat); }
    }

    &:hover, &:checked { border-color: $borders_color; }
    &, &:backdrop { &, &:disabled { background-color: transparent; border-color: transparent; } }
  }

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

  // stand-alone OSD toolbars
  &.osd {
    padding: 13px;
    border-radius: $small_radius;
    border: none;
    background-color: $osd_bg_color;

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

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

  // toolbar separators
  &.horizontal separator { margin: 0 7px 1px 6px; }
  &.vertical separator { margin: 6px 1px 7px 0; }

  &:not(.inline-toolbar):not(.osd) {
    switch,
    scale,
    entry,
    spinbutton,
    button {
      margin-right: 1px;
      margin-bottom: 1px;
    }
  }
  toolitem > box.linked.horizontal button { margin: 0; }
}

//searchbar, location-bar & inline-toolbar
.inline-toolbar {
  @extend %toolbar;

  @extend %darkbar;

  padding: 3px;
  border-width: 0 1px 1px;
  border-radius: 0  0 5px 5px;
}
.inline-toolbar.horizontal.sidebar-toolbar:backdrop { background-color: transparent; }

searchbar,
.location-bar {
  @extend %toolbar;

  @extend %darkbar;

  border-width: 0 0 1px;
  padding: 3px;
}

%darkbar {
  border-style: solid;
  border-color: $borders_color;
  $_bg: mix($bg_color, $borders_color, 70%);
  background-color: $sidebar_bg_color;

  &:backdrop {
    border-color: $backdrop_borders_color;
    background-color: $backdrop_sidebar_bg_color;
    box-shadow: none;
    transition: $backdrop_transition;
  }
}


/***************
 * Header bars *
 ***************/
%titlebar,
headerbar {
  padding: 0 6px;
  min-height: 40px;
  border-color: transparentize(_border_color($headerbar_bg_color), 0.7);
  border-top-color: $inkstone;
  border-style: solid;
  border-width: 0;
  border-top-width: 1px;
  border-radius: 0;
  background-color: $headerbar_bg_color;
  color: $headerbar_fg_color;
  @if $variant=='dark' {
    &:backdrop {
      box-shadow: inset 0 -1px 0 0 transparentize($backdrop_borders_color,0.2);
    }
  }

  &:backdrop {
    background-color: $backdrop_headerbar_bg_color;
    border-color: transparentize(_border_color($backdrop_headerbar_bg_color), 0.7);
    color: $backdrop_fg_color;
    transition: $backdrop_transition;
  }

  label:backdrop { color: inherit; } // make sure to inherit the backdrop label color

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

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

    @extend .dim-label;
  }

  & > separator {
      background-image: image(mix($inkstone, $headerbar_bg_color, 50%));
      &:backdrop { background-image: image(mix(darken($inkstone, 5%), $backdrop_headerbar_bg_color, 50%)); }
  }

  ~ separator, separator, separator.sidebar {
    &, &.titlebutton {
     &.horizontal, &.vertical {
        & { background-image: image(mix($inkstone, $headerbar_bg_color, 50%)); }
        &:backdrop { background-image: image(mix(darken($inkstone, 5%), $backdrop_headerbar_bg_color, 50%)); }
      }
    }
  }

  // GNOME 3.32+ responsive design headerbar separators
  separator, hdyleaflet separator {
    &, &.sidebar {
      &, &.vertical, &.horizontal {
        border-color: mix($inkstone, $headerbar_bg_color, 50%);
        &:backdrop { border-color: mix(darken($inkstone, 5%), $backdrop_headerbar_bg_color, 50%); }
      }
    }
  }

  & {
    // style headerbar buttons and entries using the appropriate headerbar colors
    $c: $headerbar_bg_color;
    $tc: $headerbar_fg_color;

    switch {
      @include switch(lighten($headerbar_bg_color, 25%));
      &, &:backdrop { &, &:hover, &:checked, &:checked:hover { border-top-color: transparent; box-shadow: none; } }
    }

    entry, %dark_entry {
      @include entry(normal, $c: $c, $tc: $tc);
      &:disabled { @include entry(insensitive, $c: $c, $tc: $tc); }

      &:backdrop {
        @include entry(backdrop, $c: $c, $tc: $tc);
        transition: $backdrop_transition;

        &:disabled { @include entry(backdrop-insensitive, $c: $c, $tc: $tc); }
      }
      image {
        color: $tc;
        &:hover { color: $backdrop_headerbar_text_color; }
      }
    }

    // default button and its labels needs dedicated styling in the headerbar
    .text-button:not(.suggested-action) {
      &:not(:hover) { border-color: $hb_button_bg_hover; }
      &.default {
        &, &:active, &:hover, &:focus {
          color: white;
        }
      }
    }
    button.default { label { color: white; } }

    button, button.flat, button.titlebutton.appmenu {
      @each $state, $t in ("", "normal"),
                          (":hover", "hover"),
                          (":hover:backdrop", "backdrop-hover"),
                          (":active, &:checked", "active"),
                          (":hover:checked", "active-hover"),
                          (":disabled", "insensitive"),
                          (":disabled:active, &:disabled:checked", "insensitive-active"),
                          (":backdrop", "backdrop"),
                          (":backdrop:active, &:backdrop:checked", 'backdrop-active'),
                          (":backdrop:disabled", 'backdrop-insensitive'),
                          (":backdrop:disabled:active, &:backdrop:disabled:checked", 'backdrop-insensitive-active') {
                            &#{$state} { @include button($t, $c, $tc, $flat:true); }
      }

      @each $b_type, $b_color in (suggested-action, $success_color),
                                  (destructive-action, $destructive_color) {
        &.#{$b_type} {
          // special buttons show their color when not interacted with
          @each $state, $t in ("", "normal"),
                              (":hover", "hover"),
                              (":hover:backdrop", "backdrop-hover"),
                              (":active, &:checked", "active"),
                              (":disabled", "insensitive"),
                              (":disabled:active, &:disabled:checked", "insensitive-active"),
                              (":backdrop", "backdrop"),
                              (":backdrop:active, &:backdrop:checked", 'backdrop-active'),
                              (":backdrop:disabled", 'backdrop-insensitive'),
                              (":backdrop:disabled:active, &:backdrop:disabled:checked", 'backdrop-insensitive-active') {
            &#{$state} { @include button($t, $b_color, white, $flat:true); &:not(:active) { border-color: $b_color; } }
          }
        }
      }
    }

    .linked:not(.path-bar):not(.stack-switcher):not(buttonbox) button, .linked:not(.vertical) entry {
      // force linked buttons and entries to be separate
      // this needs a lot of testing
      &:focus {
        & + entry { border-left-color: _border_color($graphite); }
        & + button { border-left-color: transparent; }

        & + entry,
        & + button {
          &:disabled { border-left-color: transparent; }
          &:backdrop { border-left-color: _border_color($headerbar_bg_color); }
        }
      }
      border-width: 1px;
      border-style: solid;
      border-radius: $small_radius;
      -gtk-outline-radius: $small_radius;

      &:not(:last-child) { margin-right: 4px; }
    }

    .stack-switcher.linked button,
    buttonbox.linked button,
    buttonbox.linked button.text-button ~ button {
      border-style: solid;
      border-color: lighten($inkstone, 5%);

      &:not(:only-child) { border-width: 1px 0; }
      &:first-child { border-width: 1px 0 1px 1px; }
      &:last-child { border-width: 1px 1px 1px 0; }

      &:backdrop {
        &, &:checked { border-color: lighten($inkstone, 3%); }
      }
    }
  }

  &.selection-mode {
    $c: $success_color;
    color: $selected_fg_color;
    border-color: _border_color($c);
    background-color: $c;

    ~ separator, separator {
      background-image: image(_border_color($c));
    }

    &:backdrop {
      $c: _backdrop_color($c);
      border-color: _border_color($c);
      background-color: $c;

      ~ separator, separator {
        background-image: image(_border_color($c));
      }
    }

    .subtitle:link { @extend *:link:selected;  }

    button {
        @each $state, $t in ("", "normal"),
                            (":hover", "hover"),
                            (":hover:backdrop", "backdrop-hover"),
                            (":active, &:checked", "active"),
                            (":disabled", "insensitive"),
                            (":disabled:active, &:disabled:checked", "insensitive-active"),
                            (":backdrop", "backdrop"),
                            (":backdrop:active, &:backdrop:checked", 'backdrop-active'),
                            (":backdrop:disabled", 'backdrop-insensitive'),
                            (":backdrop:disabled:active, &:backdrop:disabled:checked", 'backdrop-insensitive-active') {
          $c: $success_color;
          $tc: white;
          &, &.selection-menu {
            &#{$state} {
              @include button($t, $c, $tc, $flat:true);
              outline-color: white;
            }
          }
        }

      &.text-button:not(:hover) {
        border-color: transparentize(white, 0.7);
      }

      &.flat, &.selection-menu {
        &, &:backdrop {
          &, &:disabled { @include button(undecorated); }
        }
      }

      &.suggested-action {
        @each $state, $t in ("", "normal"), (":hover", "hover"), (":hover:backdrop", "backdrop-hover"),
        (":active", "active"), (":disabled", "insensitive"),
        (":backdrop", "backdrop"), (":backdrop:disabled", 'backdrop-insensitive') {
          $c: white;
          $tc: $success_color;
          &#{$state} { @include button($t, $c, $tc); } }
      }

      &.selection-menu {
        &:backdrop, & {
          padding-left: 10px;
          padding-right: 10px;

          arrow { -GtkArrow-arrow-scaling: 1; }

          .arrow {
            -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
          }
        }
      }
    }
  }

  // squared corners when the window is maximized, tiled, or fullscreen
  .tiled &,
  .tiled-top &,
  .tiled-right &,
  .tiled-bottom &,
  .tiled-left &,
  .maximized &,
  .fullscreen & {
    border-color: transparentize(_border_color($headerbar_bg_color), 0.7);
    &.selection-mode { border: none; }

    &:backdrop, & {
      border-radius: 0;
    }
  }

  &.default-decoration {
    min-height: 26px;
    padding: 4px 6px;

    button.titlebutton {
      min-width: 26px;
      min-height: 26px;
      margin: 0;
      padding: 0;
    }
  }

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

  // grey borders look fuzzy on dark backgrounds - thus cutting the border in headerbar
  scale slider { &, &:disabled { border-color: transparent; } }
}

headerbar {
  // add vertical margins to common widget on the headerbar to avoid them spanning the whole height
  entry,
  spinbutton,
  button {
    margin-top: 5px;
    margin-bottom: 5px;
  }
  switch, separator {
    margin-top: 8px;
    margin-bottom: 8px;
  }
}

.background .titlebar {
  &:backdrop, & {
    border-top-left-radius: 7px;
    border-top-right-radius: 7px;
  }
}

.background.tiled .titlebar,
.background.tiled-top .titlebar,
.background.tiled-right .titlebar,
.background.tiled-bottom .titlebar,
.background.tiled-left .titlebar,
.background.maximized .titlebar,
.background.solid-csd .titlebar {
  &:backdrop, & {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
}

headerbar { // headerbar border rounding

  window separator:first-child + &,
  window &:first-child { &:backdrop, & { border-top-left-radius: 7px; }}
  window &:last-child { &:backdrop, & { border-top-right-radius: 7px; }}

  window stack & { // tackles the stacked headerbars case
    &:first-child, &:last-child {
      &:backdrop, & {
        border-top-left-radius: 7px;
        border-top-right-radius: 7px;
      }
    }
  }

  window.tiled &,
  window.tiled-top &,
  window.tiled-right &,
  window.tiled-bottom &,
  window.tiled-left &,
  window.maximized &,
  window.fullscreen &,
  window.solid-csd & {
    &, &:backdrop {
      &,
      &:first-child,
      &:last-child,
      &:only-child {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
      }
    }
  }
}

.titlebar:not(headerbar) {
  window.csd > & {
    // in csd we assume every titlebar is a headerbar so reset anything, this is needed for split toolbars cases
    padding: 0;
    background-color: transparent;
    background-image: none;
    border-style: none;
    border-color: transparent;
    box-shadow: none;
  }

  > separator { background-color: $borders_color; }  // FIXME: use darker border?

  @extend %titlebar;
}


/************
 * Pathbars *
 ************/
%underline_focus_effect {
  // indeterminate is there to lazily force the style
  transition: 300ms ease;
  transition-property: box-shadow, color;
  border-color: transparent;

  &, &:backdrop { box-shadow: inset 0 -2px transparent; }
}

.path-bar button, .nautilus-path-bar button {  
    &, &:dir(ltr), &:dir(rtl) {
      &, &.text-button, &.image-button, &.image-button.text-button {  
      @extend %underline_focus_effect;
      background-color: transparent;
      color: $insensitive_fg_color;
      &:only-child, &:last-child {
        &, &:hover { color: $headerbar_fg_color; }
      }
      border-style: none;
      &, &:not(:first-child):not(:last-child), &:first-child, &:last-child { border-radius: 0; }
      box-shadow: none;

      &:hover { 
        box-shadow: inset 0 -2px transparentize($insensitive_fg_color, 0.5);
        background-color: transparent;
        color: $insensitive_fg_color; 
      }
      
      &:active { box-shadow: inset 0 -2px $insensitive_fg_color; }

      &:checked, &:checked:active {
        color: $headerbar_fg_color;
        background-color: transparent;
        &:hover { box-shadow: inset 0 -2px $insensitive_fg_color; }
        &:hover, &:backdrop { background-color: transparent; }
      }

      &:backdrop {
        background-color: transparent;
        color: $backdrop_insensitive_color;
        border-color: transparent;
        box-shadow: inset 0 -2px transparent;
        &:hover { 
          box-shadow: inset 0 -2px transparentize($insensitive_fg_color, 0.5); 
          background-color: transparent;
          color: $backdrop_insensitive_color;
        }
      }
    }
  }

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

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

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

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

  &.slider-button {
    padding-left: 0;
    padding-right: 0;
    box-shadow: none;

    &:hover { color: $selected_bg_color; }
    &:disabled image {
      // make disabled arrows less prominent
      opacity: 0.3;
    }
  }
}

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

  border-left-color: mix($fg_color, $base_color, 50%); // this is actually the tree lines color,
  border-top-color: transparentize($borders_color, 0.8); // while this is the grid lines color, better then nothing
  background-color: $base_color;

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

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

    &:backdrop, & {
      color: $selected_fg_color;
      /* TODO: What the following lines actually do? */
      border-left-color: mix($selected_fg_color, $selected_bg_color, 50%);
      border-top-color: transparentize($borders_color, 0.8); // doesn't work unfortunately
    }
  }

  &:disabled {
    color: $insensitive_fg_color;

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

    &:backdrop { color: $backdrop_insensitive_color; }
  }

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

    &:backdrop { color: transparentize($bg_color, 0.9); }
  }

  &:backdrop {
    border-left-color: mix($backdrop_fg_color, $backdrop_bg_color, 50%);
    border-top-color: transparentize($borders_color, 0.8);
    background-color: $backdrop_bg_color;
  }
  &:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: _border_color($selected_bg_color);

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

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

  &.expander {
    -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');

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

    color: lighten($text_color, 20%);

    &:hover { color: $text_color; }

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

      &:hover { color: $selected_fg_color; }

      &:backdrop { color: mix($backdrop_selected_fg_color, $selected_bg_color, 70%); }
    }

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

    &:backdrop { color: mix($backdrop_fg_color, $backdrop_base_color, 70%); }
  }

  &.progressbar { // progress bar in treeviews
    background-color: $neutral_color;
    border-radius: $small_radius 0 0 $small_radius;
    border: 1px solid $neutral_color;
    color: $text_color;

    &:selected {
      &:focus, & {
        background-color: $neutral_color;
        border-color: $selected_bg_color;
        border-style: solid none;
        border-width: 1px 0;
        border-radius: $small_radius 0 0 $small_radius;
      }
    }

    &:backdrop {
      color: $backdrop_text_color;
    }
  }

  &.trough { // progress bar trough in treeviews
    background-color: $dark_fill;
    border-radius: $small_radius;
    border: 1px solid $dark_fill;

    &:selected {
      &:focus, & {
        background-color: lighten($selected_bg_color, 15%);
        border-radius: $small_radius;
        border: 1px solid $selected_bg_color;
      }
    }
  }

  header {
    button {
      @extend %column_header_button;
      font-weight: 500;
      box-shadow: none;
      -gtk-outline-radius: 0;
    }
  }

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

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

%column_header_button {
  padding: 0 6px;
  background-image: none;
  border-style: none solid solid none;
  &:not(:hover), &:not(:active) { background-image: if($variant==light, image(white), image($bg_color)); }
  &:backdrop { background-image: image($backdrop_bg_color); }
  &:hover, &:active { background-image: image($bg_color); }
  border-color: $borders_color; // don't darken the bottom border color
  border-radius: 0;

  &:backdrop {
    border-style: none solid solid none;
    border-color: $backdrop_borders_color;
  }

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


/*********
 * Menus *
 *********/
menubar,
.menubar {
  -GtkWidget-window-dragging: true;
  $_border_color: _border_color($menubar_bg_color);

  background-color: $menubar_bg_color;
  border-color: transparentize($_border_color, 0.8);
  border-style: solid;
  border-width: 0px;
  box-shadow: inset 0 -1px transparentize($_border_color, 0.8);
  color: $headerbar_text_color;
  padding: 0px;

  &:backdrop {
    background-color: $backdrop_headerbar_bg_color;
    color: $backdrop_headerbar_text_color;
    & label { color: $backdrop_fg_color; }
  }

  > menuitem {
    transition: 100ms ease;
    transition-property: box-shadow, color;
    min-height: 16px;
    padding: 4px 8px;

    menu {
      border-radius: 0 0 $small_radius $small_radius;
      menu {
        border-radius: $small_radius;
      }
    }

    &:hover { //Seems like it :hover even with keyboard focus
      box-shadow: inset 0 -3px $selected_bg_color;
      color: $headerbar_fg_color;
    }

    &:disabled {
      color: $headerbar_insensitive_color;
      box-shadow: none;
    }
  }
}

.background.popup { background-color: transparent; }

menu,
.menu,
.context-menu {
  margin: 4px; // see https://bugzilla.gnome.org/show_bug.cgi?id=591258
  padding: 8px 0;
  background-color: $menu_color;
  color: $text_color;
  border: 1px solid $menu_border;
  border-radius: $small_radius;

  .csd & { border: none; }  // axes borders in a composited env

  &:backdrop { background-color: $backdrop_menu_color;  color: $backdrop_text_color; }

  menuitem {
    // a transition here causes no visible bg change for some popovers
    // transition: all 100ms $ease-out-quad; 
    min-height: 16px;
    min-width: 36px;
    padding: 5px 6px;
    border-radius: 0;

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

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

    &:backdrop,
    &:backdrop:hover {
      color: $backdrop_fg_color;
      background-color: transparent;
    }

    // submenu indicators
    arrow {
      min-height: 16px;
      min-width: 16px;

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

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

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

  // overflow arrows
  > arrow {
    @include button(undecorated);

    min-height: 16px;
    min-width: 16px;
    padding: 4px;
    border-radius: 0;

    &.top {
      border-bottom: 1px solid mix($fg_color, $base_color, 10%);
      border-top-right-radius: $small_radius;
      border-top-left-radius: $small_radius;
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
    }

    &.bottom {
      margin-bottom: -8px;
      border-top: 1px solid mix($fg_color, $base_color, 10%);
      border-bottom-right-radius: $small_radius;
      border-bottom-left-radius: $small_radius;
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    }

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

    &:backdrop { background-color: $backdrop_menu_color; }

    &:disabled {
      color: transparent;
      background-color: transparent;
      border-color: transparent ;
    }
  }
  @if $variant=='dark' { separator { background-color: lighten($menu_color, 6%); } }
}

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

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



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

popover.background {
  padding: 2px;
  color: $text_color;
  border-radius: $medium_radius;
  background-color: $menu_color;

  .csd &, & {
    border: 1px solid if($variant=='light', transparentize(black,0.75), transparentize(white, 0.8));
    &:backdrop { @if $variant=='light' { border-color: $backdrop_borders_color; } }
  }

  box-shadow: $popover_shadow;

  &:backdrop {
    background-color: $backdrop_bg_color;
    color: $backdrop_text_color;
    box-shadow: none;
  }

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

  .csd &, & {
    &.touch-selection,
    &.magnifier {
      @extend %osd;

      border: 1px solid transparentize(white, 0.9);

      button { @extend %osd_button };
    }

    &.osd { @extend %osd; }
  }

  modelbutton {
    min-height: 16px;
    min-width: 36px;
    padding: 5px 6px;
  }

  separator { margin: 3px; }

  list separator { margin: 0px; }

  radiobutton radio, checkbutton check {
    &:dir(ltr) { margin-right: 3px; }
    &:dir(rtl) { margin-left: 3px; }
  }

  @if $variant=='dark' {
    *:not(fill):not(highlight):not(trough):not(slider):not(switch):not(selection):not(menu) { background-color: transparent; }
    separator { background-image: image(darken($menu_border,13%)); }
    scrollbar slider { background-color: $scrollbar_slider_color; }
    entry:not(:focus), button { border-color: darken($inkstone,1%); &:backdrop { border-color: lighten($inkstone,5%); } }
    button, button.circular, button.flat, button.text-button, modelbutton { @extend %jet_popover_button; }
    switch { @include switch($dark_fill, $success_color); }
  }
}

/*************
 * Notebooks *
 *************/
notebook {
  > header {
    $_borders_color: if($light, transparentize($borders_color, 0.2), darken($slate, 8%));
    background: if($light, $porcelain, $headerbar_bg_color);
    border-color: $_borders_color;
    border-width: 1px;
    padding: 1px;

    &:backdrop {
      background-color: if($light, $backdrop_bg_color, $backdrop_headerbar_bg_color);
      border-color: $backdrop_borders_color;
    }

    tabs { margin: -1px; }

    &.top {
      border-bottom-style: solid;
      > tabs {
        padding-top: 4px;
        margin-bottom: -2px;

        > tab {
          border-radius: 4px 4px 0 0;
          &:checked { border-bottom-style: none; }
        }
      }
    }

    &.bottom {
      border-top-style: solid;
      > tabs {
        padding-bottom: 4px;
        margin-top: -2px;

        > tab {
          border-radius: 0 0 4px 4px;
          &:checked { border-top-style: none; }
        }
      }
    }

    &.left {
      border-right-style: solid;
      > tabs {
        padding-left: 4px;
        margin-right: -2px;

        > tab {
          border-radius: 4px 0 0 4px;
          &:checked { border-right-color: transparent; }
        }
      }
    }

    &.right {
      border-left-style: solid;
      > tabs {
        padding-right: 4px;
        margin-left: -2px;

        > tab {
          border-radius: 0 4px 4px 0;
          &:checked { border-left-color: transparent; }
        }
      }
    }

    &.top > tabs > arrow {
      @extend %notebook_vert_arrows;

      border-top-style: none;
    }

    &.bottom > tabs > arrow {
      @extend %notebook_vert_arrows;

      border-bottom-style: none;
    }

    @at-root %notebook_vert_arrows {
      margin-left: -5px;
      margin-right: -5px;
      padding-left: 4px;
      padding-right: 4px;

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

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

    &.left > tabs > arrow {
      @extend %notebook_horz_arrows;

      border-left-style: none;
    }

    &.right > tabs > arrow {
      @extend %notebook_horz_arrows;

      border-right-style: none;
    }

    @at-root %notebook_horz_arrows {
      margin-top: -5px;
      margin-bottom: -5px;
      padding-top: 4px;
      padding-bottom: 4px;

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

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

    > tabs > arrow {
      @extend %button_basic;

      @extend %button_basic.flat;

      min-height: 16px;
      min-width: 16px;
      border-radius: 0;

      &:hover:not(:active):not(:backdrop) {
        background-clip: padding-box;
        background-image: none;
        background-color: transparentize(white, 0.7);
        border-color: transparent;
        box-shadow: none;
      }

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

    tab {
      min-height: 24px;
      min-width: 24px;
      padding: 4px 12px;
      outline-offset: -3px;
      outline-style: dashed;
      -gtk-outline-radius: $small_radius;
      color: transparentize($text_color, 0.3);
      border: 1px solid transparent;

      &:hover:not(:active):not(:backdrop):not(:checked) {
        @if $light {
          background-color: mix($insensitive_bg_color, $base_color, 25%);
          border-color: mix($_borders_color, $base_color, 60%);
        } @else {
          background-color: $base_color;
          border-color: $_borders_color;
        }
      }

      &:backdrop {
        color: mix($backdrop_fg_color, $backdrop_bg_color, 60%);
        &:hover {
          border-color: mix($borders_color, $backdrop_bg_color, 65%);
        }
      }

      &:checked {
        color: $fg_color;
        background-color: $base_color;
        border-color: $_borders_color;
        & label {padding-bottom: 1px};
      }

      &:backdrop:checked {
        background-color: $backdrop_base_color;
        border-color: $backdrop_borders_color;
        color: $backdrop_fg_color;
        & label {padding-bottom: 1px};
      }

      // colors the button like the label, overridden otherwise
      button.flat {
        &:hover {
          color: currentColor;
          background-color: $base_color;
          border-color: $base_color;
        }

        &, &:backdrop { color: gtkalpha(currentColor, 0.3); }

        padding: 0;
        margin-top: 1px;
        margin-bottom: 1px;
        // FIXME: generalize .small-button?
        min-width: 20px;
        min-height: 20px;

        &:last-child {
          margin-left: 4px;
          margin-right: -8px;
        }

        &:first-child {
          margin-left: -8px;
          margin-right: 4px;
        }
      }
    }

    &.top,
    &.bottom {
      tabs {
        padding-left: 2px;
        padding-right: 2px;

        tab {
          margin-left: 2px;
          margin-right: 2px;
        }
      }
    }

    &.left,
    &.right {
      tabs {
        padding-top: 2px;
        padding-bottom: 2px;

        tab {
          margin-top: 2px;
          margin-bottom: 2px;
        }
      }
    }

    &.top tab { padding-top: 3px; }
    &.bottom tab { padding-bottom: 3px; }
  }

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

    &:backdrop { background-color: $backdrop_base_color; }
  }
}


/**************
 * Scrollbars *
 **************/
scrollbar {
  $_slider_min_length: 40px;

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

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

  &:backdrop {
    background-color: $backdrop_scrollbar_bg_color;
    border-color: $backdrop_borders_color;
    transition: $backdrop_transition;
  }

  // slider
  slider {
    min-width: 6px;
    min-height: 6px;
    margin: -1px;
    border: 4px solid transparent;
    border-radius: 8px;
    background-clip: padding-box;
    background-color: $scrollbar_slider_color;
    transition: 150ms linear;
    transition-property: min-height, min-width, border-color, background-color;

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

    &:hover:active { background-color: $scrollbar_slider_active_color; }

    &:backdrop { background-color: $backdrop_scrollbar_slider_color; }

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

  &.fine-tune {
    slider {
      min-width: 4px;
      min-height: 4px;
      transition: none; // to prevent jumping the size
    }

    &.horizontal slider { margin: 0 -1px; }
    &.vertical slider { margin: -1px 0; }
  }

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

      slider {
        margin: 2px;
        min-width: 3px;
        min-height: 3px;
        border: 1px solid if($variant == 'light', transparentize(white, 0.8), transparentize(black, 0.8));
      }

      button {
        min-width: 5px;
        min-height: 5px;
        background-color: $scrollbar_slider_color;
        background-clip: padding-box;
        border-radius: 100%;
        border: 1px solid if($variant == 'light', transparentize(white, 0.8), transparentize(black, 0.8));
        -gtk-icon-source: none;
      }

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

        button {
          margin: 1px 2px;
          min-width: 5px;
        }
      }

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

        button {
          margin: 2px 1px;
          min-height: 5px;
        }
      }
    }

    &.dragging,
    &.hovering {
      border-style: none;
      background-color: transparent;
      border-radius: $small_radius;

      &:backdrop { background-color: transparentize($backdrop_scrollbar_bg_color, 0.2); }
    }
  }

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

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

  // button styling
  button {
    padding: 0;
    min-width: 12px;
    min-height: 12px;
    border-style: none;
    border-radius: 0;
    transition-property: min-height, min-width, color;

    @include button(undecorated);

    color: $scrollbar_slider_color;

    &:hover {
      @include button(undecorated);

      color: $scrollbar_slider_hover_color;
    }
    &:active, &:checked {
      @include button(undecorated);

      color: $scrollbar_slider_active_color;
    }
    &:disabled {
      @include button(undecorated);

      color: transparentize($scrollbar_slider_color, 0.8);
    }
    &:backdrop {
      @include button(undecorated);

      color: $backdrop_scrollbar_slider_color;

      &:disabled {
        @include button(undecorated);

        color: transparentize($backdrop_scrollbar_slider_color, 0.8);
      }
    }
  }

  // button icons
  &.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-end-symbolic'); }

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

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

/**********
 * Switch *
 **********/
switch {
  transition: $button_transition;
  @include switch($dark_fill, $success_color);
}


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


//selection-mode
@each $s,$as in ('','-selectionmode'),
                  (':hover', '-hover-selectionmode'),
                  (':active', '-active-selectionmode'),
                  (':backdrop', '-backdrop-selectionmode'),
                  (':checked', '-checked-selectionmode'),
                  (':checked:hover', '-checked-hover-selectionmode'),
                  (':checked:active', '-checked-active-selectionmode'),
                  (':backdrop:checked', '-checked-backdrop-selectionmode') {
  .view.content-view.check#{$s}:not(list),
  .content-view .tile check#{$s}:not(list) {
    -gtk-icon-source: -gtk-scaled(url("assets/checkbox#{$as}.png"), url("assets/checkbox#{$as}@2.png"));
    background-color: transparent;
    min-width: 30px;
    min-height: 30px;
    background-image: none;
    transition: none;
    box-shadow: none;
    border-width: 0;
  }
}

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

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

check,
radio {
  margin: 0 4px;

  &:only-child { margin: 0; }

  popover & { // when in a popover add more space between the label and the check, reset the other side margin.
              // See https://bugzilla.gnome.org/show_bug.cgi?id=779570 for details.
    &.left:dir(rtl) {
      margin-left: 0;
      margin-right: 12px;
    }

    &.right:dir(ltr) {
      margin-left: 12px;
      margin-right: 0;
    }
  }

  min-height: 14px;
  min-width: 14px;
  padding: 1px;
  -gtk-icon-source: none;

  &:backdrop { transition: $backdrop_transition; }

  menu menuitem &, popover & {
    margin: 0; // this is a workaround for a menu check/radio size allocation issue
  }
}

%check, %radio, check, radio {
  & {
    // for unchecked
    border: 1px solid;
    $_c: if($light, white, $bg_color);

    @each $state, $t in ("", "normal"),
                        (":hover", "hover"),
                        (":hover:backdrop", "backdrop-hover"),
                        (":active", "active"),
                        (":disabled", "insensitive"),
                        (":backdrop", "backdrop"),
                        (":backdrop:disabled", 'backdrop-insensitive') {
      &#{$state} {
        @include check($t, $_c);
      }
    }
  }

  & {
    // for checked
    @each $t in (':checked:not(:indeterminate)'), (':indeterminate') {
      &#{$t} {
        @each $state, $t in ("", "normal"),
                            (":hover", "hover"),
                            (":hover:backdrop", "backdrop-hover"),
                            (":disabled", "insensitive"),
                            (":backdrop", "backdrop"),
                            (":backdrop:disabled", 'backdrop-insensitive') {
          &#{$state} {
            @include check($t, $success_color);
          }
        }
      }
    }
  }
}


%check,
check {
  border-radius: 3px;

  &:checked { -gtk-icon-source: image(-gtk-recolor(url("assets/check-symbolic.svg")),
                                      -gtk-recolor(url("assets/check-symbolic.symbolic.png"))); }

  &:indeterminate { -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
                                            -gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
}

%radio,
radio {
  border-radius: 100%;

  &:checked { -gtk-icon-source: image(-gtk-recolor(url("assets/bullet-symbolic.svg")),
                                      -gtk-recolor(url("assets/bullet-symbolic.symbolic.png"))); }

  &:indeterminate { -gtk-icon-source: image(-gtk-recolor(url("assets/dash-symbolic.svg")),
                                            -gtk-recolor(url("assets/dash-symbolic.symbolic.png"))); }
}


// ANIMATION:
// this is made with those pretty convoluted transitions, since checks and radios have to animate only on state changes,
// the transformation is set on the active state and it get reset on the checked state.
radio:not(:indeterminate):not(:checked):active:not(:backdrop) { -gtk-icon-transform: scale(0); }

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

radio,
check {
  &:active { -gtk-icon-transform: scale(0, 1); } // should tackle the indeterminate state, untested

  &:checked:not(:backdrop), &:indeterminate:not(:backdrop) {
    -gtk-icon-transform: unset;
    transition: 400ms;
  }
}

menu menuitem, popover, treeview.view {
  // make menuitem, popover and treeview checks and radios smaller
  check, radio {
    padding: 1px;
  }
}

treeview.view {
  radio, check {
    @each $t, $c in (':checked:not(:indeterminate)', $success_color),
                    (':indeterminate', $success_color) {
        &#{$t} {
        &, &:hover { background-color: $c; color: white }
        &:backdrop { background-color: _backdrop_color($c); }
      }
    }
  }
}

/************
 * GtkScale *
 ************/
%scale_trough {
  border-radius: 3px;
  background-color: $dark_fill;
  min-height: 2px;

  &:disabled { background-color: $insensitive_dark_fill; }

  &:backdrop {
    background-color: _backdrop_color($dark_fill);
    transition: $backdrop_transition;

    &:disabled { background-color: $backdrop_insensitive_dark_fill; }
  }

  // ...on selected list rows
  row:selected & { &:disabled, & { border-color: $neutral_color; }} // TODO: what program uses this so it can be tested out?

  // OSD
  .osd & { }
}

%scale_highlight {
  $c: $neutral_color;
  border-radius: 3px;
  background-color: $c;

  &:disabled {
    background-color: transparent;
  }

  &:backdrop {
    background-color: _backdrop_color($c);
    &:disabled {
      background-color: transparent;
    }
  }

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

  // OSD
  .osd & { }
}

scale {
  // sizing
  $_marks_lenght: 6px;
  $_marks_distance: 6px;

  min-height: 8px;
  min-width: 8px;
  padding: 12px;

  // the slider is inside the trough, so to have make it bigger there's a negative margin
  slider {
    min-height: 18px;
    min-width: 18px;
    margin: -9px;
  }

  &.horizontal slider { margin-top: -8px; }

  &.vertical slider { margin-left: -8px; }

  // click-and-hold the slider to activate
  &.fine-tune {
    &.horizontal {
      padding-top: 8px;
      padding-bottom: 8px;
      min-height: 16px;
    }

    &.vertical {
      padding-left: 8px;
      padding-right: 8px;
      min-width: 16px;
    }

    // to make the trough grow in fine-tune mode
    slider { margin: -8px; }

    &.horizontal slider { margin-top: -7px; }

    &.vertical slider { margin-left: -7px; }

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

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

    outline-offset: 3px;
    -gtk-outline-radius: 5px;
  }

  // the colored part of the backing bit
  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
  fill {
    @extend %scale_trough;

    &:backdrop, & { background-color: $borders_color; }

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

    // OSD
    .osd & { }
  }

  slider {
    $c: $neutral_color;
    $_bc: _border_color($dark_fill);
    @include button(normal, white);

    border: 1px solid if($variant=='light', $_bc, transparent);
    border-radius: 10px;
    background-clip: if($variant == "light", border-box, padding-box);
    transition: $button_transition;
    transition-property: background, border, box-shadow;

    &:hover {
      background-color: darken(white, 5%);
    }

    &:active { border-color: _border_color($c); }

    &:disabled {
      @include button(insensitive, if($variant == "light", white, darken(white, 20%)));
      border-color: if($variant=='light', lighten($_bc, 10%), transparent);
    }

    &:backdrop {
      transition: $backdrop_transition;
      background-color: mix($white, $backdrop_bg_color, 70%);
      &:disabled { background-color: mix($white, $backdrop_insensitive_color, 70%); border-color: $backdrop_insensitive_color; }
    }

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

    // OSD
    .osd & { }
  }

  value { color: gtkalpha(currentColor, 0.55); }

  marks {
    color: gtkalpha(currentColor, 0.55);

    @each $marks_class, $marks_pos, $marks_margin in (top, top, bottom),
                                                     (bottom, bottom, top),
                                                     (top, left, right),
                                                     (bottom, right, left) {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_lenght);
      }
    }
  }

  &.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;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_lenght - 1px);
      }
    }
  }

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

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

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

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

  // *WARNING* scale with marks madness following

  // FIXME: OSD and selected list rows missing, I don't feel like adding the other 144 assets needed for those...
  @each $dir_class, $dir_infix in ('horizontal', 'horz'),
                                  ('vertical', 'vert') {
    @each $marks_infix, $marks_class in ('scale-has-marks-above', 'marks-before:not(.marks-after)'),
                                        ('scale-has-marks-below', 'marks-after:not(.marks-before)') {
      @each $state, $state_infix in ('', ''),
                                    (':hover', '-hover'),
                                    (':active', '-active'),
                                    (':disabled', '-insensitive'),
                                    (':backdrop', '-backdrop'),
                                    (':backdrop:disabled', '-backdrop-insensitive') {
        &.#{$dir_class}.#{$marks_class} {

          slider {
            &#{$state} {
              // an asymmetric slider asset is used here, so the margins are uneven, the smaller
              // margin is set on the point side.
              margin: -9px;
              $_scale_asset: 'assets/slider-#{$dir_infix}-#{$marks_infix}#{$state_infix}';
              border-style: none;
              border-radius: 0;

              background-color: transparent;
              background-image: -gtk-scaled(url('#{$_scale_asset}.png'), url('#{$_scale_asset}@2.png'));

              $_scale_slider_bg_pos: center calc(100% - 2px);

              @if $dir_class == 'horizontal' {
                min-height: 26px;
                min-width: 22px;
                background-size: 16px 24px;

                @if $marks_infix == 'scale-has-marks-above' {
                  margin-top: -14px;

                  $_scale_slider_bg_pos: center 2px;
                }

                @else { margin-bottom: -14px; }
              }

              @else {
                min-height: 22px;
                min-width: 26px;
                background-size: 24px 16px;

                @if $marks_infix == 'scale-has-marks-above' {
                  margin-left: -14px;

                  $_scale_slider_bg_pos: calc(100% - 2px) center;
                }

                @else {
                  margin-right: -14px;

                  $_scale_slider_bg_pos: 2px center;
                }
              }

              background-position: $_scale_slider_bg_pos;
              background-repeat: no-repeat;
              box-shadow: none;
            }
          }

          &.fine-tune slider {
            // bigger negative margins to make the trough grow here as well
            margin: -8px;

            @if $dir_class == 'horizontal' {
              @if $marks_infix == 'scale-has-marks-above' { margin-top: -13px; }

              @else { margin-bottom: -13px; }
            }

            @else {
              @if $marks_infix == 'scale-has-marks-above' { margin-left: -13px; }

              @else { margin-right: -13px; }
            }
          }
        }
      }
    }
  }

  &.color {
    min-height: 0;
    min-width: 0;

    trough { }

    &.horizontal {
      padding: 0 0 12px 0;

      trough {
        padding-bottom: 3px;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
      }

      slider {
        &:dir(ltr), &:dir(rtl) { // specificity bumb
          &:hover, &:backdrop, &:disabled, &:backdrop:disabled, & {
            margin-bottom: -12px;
            margin-top: 5px;
          }
        }
      }
    }

    &.vertical {
      &:dir(ltr) {
        padding: 0 0 0 12px;

        trough {
          padding-left: 3px;
          border-bottom-right-radius: 0;
          border-top-right-radius: 0;
        }

        slider {
          &:hover, &:backdrop, &:disabled, &:backdrop:disabled, & {
            margin-left: -12px;
            margin-right: 5px;
          }
        }
      }

      &:dir(rtl) {
        padding: 0 12px 0 0;

        trough {
          padding-right: 3px;
          border-bottom-left-radius: 0;
          border-top-left-radius: 0;
        }

        slider {
          &:hover, &:backdrop, &:disabled, &:backdrop:disabled, & {
            margin-right: -12px;
            margin-left: 5px;
          }
        }
      }
    }

    &.fine-tune {
      &.horizontal {
        &:dir(ltr), &:dir(rtl) { // specificity bump
          padding: 0 0 10px 0;

          trough {
            padding-bottom: 5px;
          }

          slider {
            margin-bottom: -12px;
            margin-top: 5px;
          }
        }
      }

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

          trough {
            padding-left: 5px;
          }

          slider {
            margin-left: -12px;
            margin-right: 5px;
          }
        }

        &:dir(rtl) {
          padding: 0 10px 0 0;

          trough {
            padding-right: 5px;
          }

          slider {
            margin-right: -12px;
            margin-left: 5px;
          }
        }
      }
    }
  }
}


/*****************
 * Progress bars *
 *****************/
progressbar {
  // sizing
  &.horizontal {
    trough,
    progress { min-height: 3px; }
  }

  &.vertical {
    trough,
    progress { min-width: 3px; }
  }

  // FIXME: insensitive state missing and some other state should be set probably
  font-size: smaller;
  color: transparentize($fg_color, 0.6);

  &:backdrop {
    box-shadow: none;
    transition: $backdrop_transition;
  }

  trough { @extend %scale_trough; }

  &:backdrop trough { @extend %scale_trough:backdrop; } // looks like states are not passed to the trough component here

  %progressbar_highlight {
    $c: $neutral_color;
    border-radius: 3px;
    background-color: $c;

    &:disabled {
      background-color: transparent;
    }

    &:backdrop {
      background-color: _backdrop_color($c);

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

    // ...on selected nist rows
    row:selected & { &:disabled, & { border-color: $c; }} // TODO: what program uses this so it can be tested out?

    // OSD
    .osd & { }
  }
// TODO: maybe we can experiment with &:not(.full)
// so prgoress bars won't be rounded at the opposite end until they're full?
  progress {
    @extend %progressbar_highlight;

    border-radius: 1.5px;

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

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

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

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

  &:backdrop progress { @extend %progressbar_highlight:backdrop; } // states not passed here as well

  &.osd { // progressbar.osd used for epiphany page loading progress
    min-width: 3px;
    min-height: 3px;
    box-shadow: none;
    background-color: transparent;

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

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

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


/*************
 * Level Bar *
 *************/
levelbar {
  &.horizontal {
    block {
      min-height: 3px;
    }

    &.discrete block {
      margin: 0 1px;
      min-width: 32px;
    }
  }

  &.vertical {
    block {
      min-width: 3px;
    }

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

  &:backdrop { transition: $backdrop_transition; }

  trough {
    padding: 3px;
    border-radius: 3px;
    border: none;
    @include entry(normal, $c: $base_color);

    &:backdrop { @include entry(backdrop, $c: $base_color); }
    box-shadow: inset 0 0 0 1px $borders_color;
  }

  block {
    border-radius: 3px;

    @mixin block_highlight($c) {
      background-color: $c;

      &:backdrop { background-color: _backdrop_color($c); };
    }

    &.low {
      @include block_highlight($warning_color);
    }

    &.high,
    &:not(.empty) {
      @include block_highlight($neutral_color);
    }

    &.full {
      @include block_highlight($neutral_color);
    }

    &.empty {
      @include block_highlight($dark_fill);
    }
  }
}


/****************
 * Print dialog *
*****************/
printdialog {
  paper {
    color: $fg_color;
    border: 1px solid $borders_color;
    background: white;
    padding: 0;

    &:backdrop {
      color: $backdrop_fg_color;
      border-color: $backdrop_borders_color;
    }
  }

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


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

  &.flat { border-style: none; }

  &:backdrop { border-color: $backdrop_borders_color; }
}

actionbar > revealer >  box {
  padding: 6px;
  border-top: 1px solid $borders_color;

  &:backdrop { border-color: $backdrop_borders_color; }
}

scrolledwindow {
  viewport > list,
  viewport > stack list {
    background-color: $sidebar_bg_color;
    &:backdrop { background-color: $backdrop_sidebar_bg_color; }
  }
  viewport.frame { // avoid double borders when viewport inside scrolled window
    border-style: none;
  }

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

      &:backdrop { @include overshoot(top, backdrop); }
    }

    &.bottom {
      @include overshoot(bottom);

      &:backdrop { @include overshoot(bottom, backdrop); }
    }

    &.left {
      @include overshoot(left);

      &:backdrop { @include overshoot(left, backdrop); }
    }

    &.right {
      @include overshoot(right);

      &:backdrop { @include overshoot(right, backdrop); }
    }
  }

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

    &:backdrop {
      border-image-source: linear-gradient(to bottom, $backdrop_borders_color 1px, transparent 1px);
      background-color: $backdrop_scrollbar_bg_color;
      transition: $backdrop_transition;
    }
  }
}

//vbox and hbox separators
separator {
  background: transparentize($borders_color, 0.7);
  min-width: 1px;
  min-height: 1px;
}

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

  &:backdrop {
    background-color: $backdrop_base_color;
    border-color: $backdrop_borders_color;
  }

  row { padding: 2px; }

  separator {
    // separator within sidebar
    background-color: transparentize($borders_color, 0.5);
  }
}

row {
  outline-offset: -3px;
  transition: all 150ms $ease-out-quad;

  &:not(:selected) {
    outline-color: gtkalpha(currentColor, 0.3);
    &:not(:backdrop):hover { background-color: $base_hover_color; }
    &:not(:backdrop):active { background-color: $base_active_color; }
  }

  &:backdrop { transition: $backdrop_transition; }

  &.activatable:not(:backdrop) {
    &.has-open-popup, // this is for indicathing which row generated a popover see https://bugzilla.gnome.org/show_bug.cgi?id=754411

    &:active { box-shadow: inset 0 2px 2px -2px transparentize(black, 0.8); }

    &:not(:backdrop):selected {
      &:active { box-shadow: inset 2px 0 $selected_bg_color, inset 0 2px 3px -1px transparentize(black, 0.5); }

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

    }
  }

  &:selected { @extend %selected_items; }
}


/*********************
 * App Notifications *
 *********************/
.app-notification,
.app-notification.frame {
  padding: 10px;
  margin: 12px;
  color: $text_color;
  border-radius: $medium_radius;
  background-color: $menu_color;
  border: 1px solid $menu_border;
  box-shadow: $popover_shadow;

  &:backdrop {
    background-color: $backdrop_bg_color;
    color: $backdrop_text_color;
    box-shadow: none;
    transition: $backdrop_transition;
  }

  @if $variant=='dark' { 
    box button, button.flat, button.text-button { @extend %jet_popover_button; } 
    button.flat { border-color: transparent; } 
  }

  border { border: none; }
}


/*************
 * Expanders *
 *************/
expander {
  notebook {
    border: 1px solid $borders_color;
  }

  arrow {
    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'); }
  }
}


/************
 * Calendar *
 ***********/
calendar {
  color: $text_color;
  border: 1px solid $borders_color;

  &:selected {
    @extend %selected_items;

    border-radius: $small_radius;
  }

  &.header {
    border-bottom-color: $borders_color;

    &:backdrop { border-bottom-color: $borders_color; }
  }

  &.button {
    @extend %undecorated_button;

    color: transparentize($fg_color, 0.55);

    &:hover { color: $fg_color; }

    &:backdrop { color: transparentize($backdrop_fg_color,0.55); }

    &:disabled { color:  transparentize($insensitive_fg_color,0.55); }
  }

  &.highlight {
    color: $insensitive_fg_color;

    &:backdrop { color: $backdrop_insensitive_color; }
  }

  &:backdrop {
    color: $backdrop_text_color;
    border-color: $backdrop_borders_color;
  }

  &:indeterminate { color: gtkalpha(currentColor, 0.1); }
}


/***********
 * Dialogs *
 ***********/
messagedialog { // Message Dialog styling
  decoration {
    border-radius: $large_radius;
  }
  .titlebar {
    background-color: $base_color;
    background-image: none;
    border-color: $base_color;
    border-top-left-radius: $medium_radius;
    border-top-right-radius: $medium_radius;
    color: $fg_color;
    min-height: 20px;

    &:backdrop {
      background-color: $backdrop_bg_color;
    }
  }

  &.csd {
    background-color: $base_color;

    &.background {
      border-bottom-left-radius: $medium_radius;
      border-bottom-right-radius: $medium_radius;
    }

    .dialog-vbox { margin-top: 14px; }
    .dialog-action-area button {
      @extend %button;
      margin: 0 7px 7px;
    }
  }
}

filechooser {
  background-color: if($variant==light, white, $bg_color);

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

    &:backdrop { border-top-color: $backdrop_borders_color; }
  }

  #pathbarbox {
    $_bg: $bg_color;
    background: $_bg;
    border-bottom: 1px solid $borders_color;
    &:backdrop { background: if($variant==light, darken($backdrop_bg_color, 5%), $backdrop_bg_color);}

    .path-bar.linked button {
      background: if($variant==light, darken($_bg, 10%), darken($_bg, 5%));
      &, & label { color: $text_color; }
      &:checked label { font-weight: 500; }
      &:backdrop {
        background: transparent;
        label { color: $backdrop_text_color; }
      }
    }
    .slider-button { 
      &:first-child { border-radius: $small_radius 0 0 $small_radius; }
      &:last-child { border-radius: 0 $small_radius $small_radius  0; }
    }
  }

  & actionbar {
    background-color: $bg_color;
    &:backdrop{background: darken($backdrop_bg_color, 5%);}
  }
  // picture preview pane
  & placessidebar ~ box box > stack ~ box  {
    background-color: $bg_color; // fixed color won't work with dark theme
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-width: 0 1px;
    padding: 10px;
  }
}

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

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

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

  &:backdrop {
    background-color: $backdrop_sidebar_bg_color;
    border-color: $backdrop_borders_color;
    transition: $backdrop_transition;
  }

  list { background-color: transparent; }

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

stacksidebar {
  &.sidebar {
    &:dir(ltr),
    &.left,
    &.left:dir(rtl) { list { @extend %sidebar_left; }}

    &:dir(rtl),
    &.right { list { @extend %sidebar_right; }}
  }

  row {
    padding: 10px 4px;

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

    &:selected > label { padding-left: 9px; }

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

      background-size: 6px 6px, 0 0;
    }
  }
}


/****************
 * File chooser *
 ****************/
$_placesidebar_icons_opacity: 0.8;

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

placessidebar {
  > viewport.frame {
    background-color: $bg_color;
    border-style: none;

    &:backdrop { background-color: $backdrop_bg_color; };
  }

  > viewport > list { margin-top: -3px; }

  separator {
    // separator within sidebar
    background-color: transparentize($borders_color, 0.5);
  }

  row {
    // Needs overriding of the GtkListBoxRow padding
    margin: -1px 0;
    min-height: 36px;
    padding: 0px;

    // Using margins/padding directly in the SidebarRow
    // will make the animation of the new bookmark row jump
    > revealer { padding: 0 14px; }

    &:disabled { color: $insensitive_fg_color; }

    &:backdrop {
      color: $backdrop_text_color;

      &:disabled { color: $backdrop_insensitive_color; }
    }

    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;

      @extend %button_selected.flat;

      min-height: 26px;
      min-width: 26px;
      margin-top: 3px;
      margin-bottom: 3px;
      padding: 0;
      border-radius: 100%;
      -gtk-outline-radius: 100%;

      &:not(:hover):not(:active),
      &:backdrop { > image { opacity: $_placesidebar_icons_opacity; }}
    }

    // in the sidebar case it makes no sense to click the selected row
    &:selected:active { box-shadow: none; }

    &.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 {

  > stack > frame > scrolledwindow > viewport > list {
    background-color: $bg_color;
    &:backdrop { background-color: $backdrop_bg_color; }
  }

  .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 { background-color: transparent; }im

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


}


/*********
 * Paned *
 *********/
paned {
  > separator {
    min-width: 1px;
    min-height: 1px;
    -gtk-icon-source: none; // defeats the ugly default handle decoration
    border-style: none; // just to be sure
    background-color: transparent;
    // workaround, using background istead of a border since the border will get rendered twice (?)
    background-image: image($borders_color);
    background-size: 1px 1px;

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

    &:backdrop { background-image: image($backdrop_borders_color); }

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

      &:backdrop {
        background-color: $backdrop_bg_color;
        background-image: image($backdrop_borders_color),
                          image($backdrop_borders_color);
      }
    }
  }

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


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

 infobar {
  $_generic_bg: $bg_color;
  @each $t, $c in ("", $_generic_bg),
                  (".info", $_generic_bg),
                  (".question", $_generic_bg),
                  (".warning", $warning_color),
                  ('.error', $error_color) {
    &#{$t} {
      background-color: $c;
      color: $text_color;
      border-bottom: 1px solid $borders_color;
      selection { @extend %selected_items; }
    }
  }
  *:link:selected { @extend %link_selected; }
}

/************
 * 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: transparentize($jet, 0.1);
    background-clip: padding-box;
    border: 1px solid $osd_borders_color;     // this suble border is meant to
                                              // not make the tooltip melt with
                                              // very dark backgrounds
  }

  padding: 4px; /* not working */
  border-radius: 5px;
  box-shadow: none; // otherwise it gets inherited by windowframe.csd

  // FIXME: we need a border or tooltips vanish on black background.
  decoration { background-color: transparent; }

  > * { // Yeah this is ugly
    min-height: 32px - (6px - 1px) * 2; // tooltip has hard-coded 6px padding
    padding: 0 8px - (6px - 1px);       // and does not consider border-width
    background-color: transparent;
    color: $porcelain;
  }
}


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

  &:drop(active), & { border-style: none; } // FIXME: implement a proper drop(active) state

  outline-offset: -2px;

  &.dark {
    outline-color: transparentize(white, 0.4);

    overlay {
      color: white;

      &:hover { border-color: if($variant == 'light', transparentize(black, 0.2), $borders_color); }

      &:backdrop { color: transparentize(white, 0.5); }
      &:hover { border-color: if($variant == 'light', transparentize(black, 0.3), $borders_color); }
    }
  }

  &.light {
    outline-color: transparentize(black, 0.4);

    overlay {
      color: black;

      &:hover { border-color: if($variant == 'light', transparentize(black, 0.5), $borders_color); }

      &:backdrop { color: transparentize(black, 0.5); }
      &:backdrop:hover { border-color: if($variant == 'light', transparentize(black, 0.6), $borders_color); }
    }
  }

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

    &.light overlay {
      border-color: $drop_target_color;
      box-shadow: inset 0 0 0 2px if($variant == 'light', darken($drop_target_color, 7%), $borders_color),
                  inset 0 0 0 1px $drop_target_color;
    }

    &.dark overlay {
      border-color: $drop_target_color;
      box-shadow: inset 0 0 0 2px if($variant == 'light', transparentize(black, 0.7), $borders_color),
                  inset 0 0 0 1px $drop_target_color;
    }
  }

  overlay {
    border: 1px solid if($variant == 'light', transparentize(black, 0.7), $borders_color);

    //&:hover {
    //  box-shadow: inset 0 1px transparentize(white, 0.6),
    //              inset 0 -1px transparentize(black, 0.8);
    //}

    &:backdrop, &:backdrop:hover {
      border-color: if($variant == 'light', transparentize(black, 0.7), $borders_color);
      box-shadow: none;
    }
  }

  &#add-color-button {
    overlay {
      @include button(normal);

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

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

  &:disabled {
    opacity: 0.5;

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

  row:selected & { box-shadow: 0 0 0 2px $selected_fg_color; }

  &#editor-color-sample {
    border-radius: 4px;

    overlay { border-radius: 4.5px; }
  }
}

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

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

  &:hover { -gtk-icon-effect: highlight; }

  &:backdrop { background-color: $backdrop_bg_color; }

  rubberband, .rubberband { @extend rubberband; }
}

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

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

  button { // +/- buttons on GtkVolumeButton popup
    &:hover {
      @extend %undecorated_button;
      background-color: transparentize($fg_color,0.9);
      border-radius: $small_radius;
    }

    &:backdrop { &:hover, &:disabled, & { @extend %undecorated_button; }}
  }
}


/**********************
 * Window Decorations *
 *********************/
decoration {
  border-radius: 7px 7px 0 0;
  // lamefun trick to get rounded borders regardless of CSD use
  border-width: 0px;

  $window_decoration_shadow: 0 3px 9px 1px;
  box-shadow: 0 3px 9px 1px transparentize(black, 0.5),
              0 0 0 1px $window_border; //doing borders with box-shadow

  // FIXME rationalize shadows

  // this is used for the resize cursor area
  margin: 10px;

  &:backdrop {
    // the transparent shadow here is to enforce that the shadow extents don't
    // change when we go to backdrop, to prevent jumping windows.
    // The biggest shadow should be in the same order then in the active state
    // or the jumping will happen during the transition.
    box-shadow: $window_decoration_shadow transparent,
                0 2px 6px 2px transparentize(black, 0.8);
    transition: $backdrop_transition;
  }

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

  .popup & { box-shadow: none; }

  // server-side decorations as used by mutter
  //just doing borders, wm draws actual shadows
  .ssd & { box-shadow: 0 0 0 1px $window_border; }
  //These shadows are applied to the context-menu!
  .csd.popup & {
    border-radius: $small_radius;    
    box-shadow: $menu_shadow,
                0 0 0 1px $menu_border;
  }

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

  messagedialog.csd & {
    box-shadow: $window_decoration_shadow transparentize(black, 0.5);
  }

  .solid-csd & {
    margin: 0;
    padding: 4px;
    background-color: $borders_color;
    border: solid 1px $borders_color;
    border-radius: 0;
    box-shadow: inset 0 0 0 3px $headerbar_bg_color;

    &:backdrop { box-shadow: inset 0 0 0 3px $backdrop_headerbar_bg_color; }
  }
}

// Window Close button
button.titlebutton {
  $c: $headerbar_bg_color;
  $tc: $headerbar_fg_color;

  &, &:hover, &:active {
    headerbar &, .titlebar &, & {
      // spec bump otherwise :backdrop  will still have a bg
      &, &:backdrop {
        @extend %undecorated_button;
      }
    }
  }

  border-radius: $small_radius;
  min-height: 24px;
  min-width: 24px;
  padding: 2px;

  &:not(.close):not(.appmenu){
    &:hover {
      @include draw_circle($c);
    }
    &:active {
      @include draw_circle($c);
    }
  }

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

// catch all extend :)

%selected_items {
  $c: $selected_bg_color;
  $tc: $selected_fg_color;
  background-color: $c;

  &:backdrop { background-color: _backdrop_color($c); }

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

    &:disabled { color: mix($tc, $c, 50%); }

    &:backdrop {
      &, label { color: $backdrop_selected_fg_color; }

      &:disabled { color: mix($backdrop_selected_fg_color, $c, 30%); }
    }
  }
}

.monospace { font-family: monospace; }


/**********************
 * 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;

  @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'));
      padding-left: 10px;
    }

    &.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'));
      padding-right: 10px;
    }

    &.insertion-cursor#{$s}:dir(ltr), &.insertion-cursor#{$s}:dir(rtl) {
      $_url: 'assets/slider-horz-scale-has-marks-above#{$as}#{$asset_suffix}';
      -gtk-icon-source: none;
      background-repeat: no-repeat;
      background-size: 16px 24px;
      background-position: center -2px;
      background-image: -gtk-scaled(url('#{$_url}.png'),
                                    url('#{$_url}@2.png'));
    }
  }
}

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

// shortcut window keys
.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: $small_radius;
  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;

  &:backdrop {
    background-color: $backdrop_base_color;
    color: $backdrop_fg_color;
    transition: $backdrop_transition;
  }
}

: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 button.circular,
stackswitcher button.text-button.circular { // FIXME aggregate with buttons
  min-width: 32px;
  min-height: 32px;
  padding: 0;
}


/*********
 * Emoji *
 ********/

popover.emoji-picker {
  padding: 0;

  entry {
    border-bottom: 1px solid $borders_color;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
    border-width: 0 0 1px 0;
    padding: 4px 12px;

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

button.emoji-section {
  border-style: none;
  border-radius: 0;

  margin: 0;
  padding: 2px 5px;
  min-width: 32px;
  min-height: 28px;

  /* reset props inherited from the button style */
  background: none;
  box-shadow: inset 0 1px $borders_color;

  outline-offset: -5px;

  &:hover {
    box-shadow: inset 0 2px $borders_color;
    background-color: $base_hover_color;
  }

  &:active {
    box-shadow: inset 0 2px $selected_bg_color;
    background-color: $base_active_color;
  }

  &:checked {
    box-shadow: inset 0 2px $selected_bg_color;
    background-color: transparent;
    &:hover {
      box-shadow: inset 0 2px $selected_bg_color;
      background-color: $base_hover_color;
    }
  }

  label {
    padding: 0;
  }

  &:first-child { border-bottom-left-radius: $small_radius; }
  &:last-child { border-bottom-right-radius: $small_radius; }
}

.emoji {
  font-size: x-large;
  padding: 6px;

  :hover {
    background: $selected_bg_color;
    border-radius: 6px;
  }
}

.regular-button{
  @include button(normal);
  &:hover{@include button(hover)};
  &:active{@include button(active);}
  &:disabled{@include button(insensitive)}
}
