$asset_suffix: if($variant=='dark', '-dark', '');
$extra_background_clip: if($variant == 'light', padding-box, border-box);

$small_size: 24px;
$medium_size: 36px;
$large_size: 48px;

$container_padding: 6px;

$bar_size: 4px;
$menuitem_size: 28px;

$md_radius: 2px;
$circular_radius: 100px;

$shorter_duration: 0.2s;
$longer_duration: 0.3s;

$standard_curve: cubic-bezier(0.4, 0.0, 0.2, 1);
$deceleration_curve: cubic-bezier(0.0, 0.0, 0.2, 1);
$acceleration_curve: cubic-bezier(0.4, 0.0, 1, 1);
$sharp_curve: cubic-bezier(0.4, 0.0, 0.6, 1);

$shorter_transition: all $shorter_duration $deceleration_curve;
$longer_transition: all $longer_duration $deceleration_curve;
$shadow_transition: box-shadow $shorter_duration $deceleration_curve;
$shadow_image_transition: border-image $shorter_duration $deceleration_curve;

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

  -GtkToolButton-icon-spacing: 4;
  -GtkTextView-error-underline-color: $error_color;

  -GtkCheckButton-indicator-size: 20;
  -GtkCheckMenuItem-indicator-size: 16;

  // 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;
  -GtkScrolledWindow-scrollbars-within-bevel: 1;

  -GtkToolItemGroup-expander-size: 11;
  -GtkExpander-expander-size: 16;
  -GtkTreeView-expander-size: 11;

  -GtkTreeView-horizontal-separator: 4;

  -GtkMenu-horizontal-padding: 0;
  -GtkMenu-vertical-padding: 0;

  -GtkWidget-link-color: $link_color;
  -GtkWidget-visited-link-color: $link_visited_color;

  -GtkWidget-focus-padding: 2;    // FIXME: do we still need these?
  -GtkWidget-focus-line-width: 1; //

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

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

  -GtkStatusbar-shadow-type: none;

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

  outline-style: solid;
  outline-width: 2px;
  outline-color: $track_color;
  outline-offset: -4px;
  outline-radius: 2px;
}


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

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

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

*:insensitive {
  -gtk-image-effect: dim;
}

.gtkstyle-fallback {
  background-color: $bg_color;
  color: $fg_color;
  &:prelight {
    background-color: darken($bg_color, 5%);
    color: $fg_color;
  }
  &:active {
    background-color: darken($bg_color, 10%);
    color: $fg_color;
  }
  &:insensitive {
    background-color: $bg_color;
    color: $insensitive_fg_color;
  }
  &:selected {
    background-color: $selected_bg_color;
    color: $selected_fg_color;
  }
}

.view {
  @extend .list-row.activatable;
  background-color: $base_color;
  color: $fg_color;

  &:hover, &:active, &:selected { border-radius: 2px; }

  &:insensitive {
    // background-color: $secondary_base_color;
    color: $insensitive_fg_color;
  }

  &:selected { @extend %selected_items; }
}

.rubberband {
  border: 1px solid $secondary_selected_bg_color;
  background-color: scale-alpha($secondary_selected_bg_color, $lower_opacity);
}

.label {
  &.separator {
    color: $fg_color;
    @extend .dim-label;
  }
  &:selected {
    @extend %selected_items;
  }
  &:insensitive {
    color: $insensitive_fg_color;
  }
}

.dim-label {
  opacity: $hint_opacity;
}

GtkAssistant {
  .sidebar {
    padding: 6px 0;
    // border-top: 1px solid $borders_color;
    &:dir(ltr) { border-right: 1px solid $borders_color; }
    &:dir(rtl) { border-left: 1px solid $borders_color; }
  }
  // &.csd .sidebar { border-top-style: none; }
  .sidebar .label {
    opacity: $hint_opacity;
    padding: 5px 12px 6px;
    font-weight: 500;
  }
  .sidebar .label.highlight {
    opacity: 1;
  }
}

GtkTextView { // This will get overridden by .view, needed by gedit line numbers
  background-color: $secondary_base_color;
}

.grid-child {
  // outline-offset: -2px;
  padding: 4px;
  border-radius: 2px;
  &:selected { @extend %selected_items; }
}

%osd, .osd { opacity: $higher_opacity; }

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

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

.spinner {
  background-color: blue;
  background-image: none;
  opacity: 0; // non spinning spinner makes no sense
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');
  &:active {
    opacity: 1;
    animation: spin 1s linear infinite;
    &:insensitive {
      opacity: $disabled_opacity;
    }
  }
}

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

.entry {
  padding: 7px 8px 8px;
  border-radius: 2px;
  @include entry(normal);
  &:focus { @include entry(focus); }
  &:insensitive { @include entry(insensitive); }
  &.flat {
    border-radius: 0;
    @include entry(flat-normal);
    &:focus { @include entry(flat-focus); }
    &:insensitive { @include entry(flat-insensitive); }
  }

  &:selected { @extend %selected_items; }

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

  &.progressbar {
    margin: 2px;
    border-style: none none solid;
    border-width: 2px;
    border-color: $selected_bg_color;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
    background-image: none;
  }

  .linked > & { @extend %linked; }

  .linked.vertical > & { @extend %linked_vertical; }

  .linked > &.flat,
  .linked.vertical > &.flat { border-radius: 0; }

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

  &.image { // entry icons colors
    &:not(:hover):not(:active) { color: gtkalpha(currentColor, $enabled_opacity); }
    &:insensitive { color: gtkalpha(currentColor, $hint_opacity); }
  }

  .osd & {
  }

  GtkTreeView &:not(:selected) {
    &, &:focus {
      padding: 2px;
      border-image: none;
      border-radius: 0;
      box-shadow: none;
      background-color: $base_color;
    }
  }
}


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

// stuff for .needs-attention
@keyframes needs_attention {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to($accent_bg_color),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($accent_bg_color),
                                    to(transparent));
  }
}


%button,
.button {
  padding: 7px 10px 8px;
  border-radius: 2px;
  background-repeat: no-repeat;
  background-position: center, center;
  background-size: ($medium_size * 2 / 0.8) ($medium_size * 2 / 0.8), auto;
  font-weight: 500;
  @include button(normal);
  &:hover { @include button(hover); }
  &:active { @include button(active); }
  &:insensitive { @include button(insensitive); }
  &:checked { @include button(checked); }
  &:checked:insensitive { @include button(checked-insensitive); }
  @at-root %flat_button, &.flat {
    @at-root %simple_flat_button, & {
      @include button(flat-normal);
      &:hover { @include button(flat-hover); }
      &:active { @include button(flat-active); }
      &:insensitive { @include button(flat-insensitive); }
    }
    &:checked { @include button(flat-checked); }
    &:checked:insensitive { @include button(flat-checked-insensitive); }
  }
  // big standalone buttons like in Documents pager
  &.osd {
    &.image-button {
      padding: 16px;
      background-size: ($large_size / 0.8) ($large_size / 0.8), auto;
    }
    &:insensitive { opacity: 0; }
  }
  //overlay / OSD style
  .osd & {
  }

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color in (suggested-action, $suggested_color),
                             (destructive-action, $destructive_color) {
    &.#{$b_type} {
      background-color: $b_color;
      color: $selected_fg_color;
      // @include button(normal, $b_color, white);
      // &:hover { @include button(hover, $b_color, white); }
      // &:active, &:checked { @include button(active, $b_color, white); }
      &:insensitive { @include button(insensitive, $b_color, white); }
      &:checked { background-color: mix($selected_fg_color, $b_color, percentage($lower_opacity)); }
      &.flat {
        background-color: transparent;
        color: $b_color;
        // @include button(flat-normal, $b_color, white);
        // &:hover { @include button(flat-hover, $b_color, white); }
        // &:active, &:checked { @include button(flat-active, $b_color, white); }
        &:insensitive { @include button(flat-insensitive, $b_color, white); }
      }
    }
  }

  &.image-button { @extend %image_button; }

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

  &.text-button.image-button {
    // those buttons needs uneven horizontal padding, we want the icon side
    // to have the image-button padding, while the text side the text-button
    // one, so we're adding the missing padding to the label depending on
    // its position inside the button
    padding: 7px 10px 8px; // same as .button
    outline-radius: 2px;
    border-radius: 2px;
    background-size: ($medium_size * 2 / 0.8) ($medium_size * 2 / 0.8), auto;
    .label:first-child { padding-left: 6px; }
    .label:last-child { padding-right: 6px; }
  }

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

    outline-offset: -4px; // needs to be set or it gets overriden by GtkRadioButton outline-offset

    > .label {
      padding-left: 6px;  // label padding
      padding-right: 6px; //
    }
    > GtkImage {
      padding-left: 6px;   // image padding
      padding-right: 6px;  //
      padding-top: 3px;    //
      padding-bottom: 3px; //
    }
    &.text-button {
      padding: 7px 10px 8px; // needed or it will get overridden
    }
    &.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: 7px 4px;
    }
    &.needs-attention > .label,
    &.needs-attention > GtkImage { @extend %needs_attention; }
    &.needs-attention:checked > .label,
    &.needs-attention:checked > GtkImage {
      animation: none;
      background-image: none;
    }
  }

  //inline-toolbar buttons
  .inline-toolbar & {
    // @extend %button.flat;
    @extend %image_button;
  }

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

  .linked > & { @extend %linked; }

  .linked.vertical > & { @extend %linked_vertical; }

  .linked > &.flat,
  .linked.vertical > &.flat {
    border-radius: 2px;

    &.image-button {
      outline-radius: $circular_radius;
      border-radius: $circular_radius;
    }

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

%image_button {
  padding: 10px;
  outline-radius: 100px;
  border-radius: 100px;
  background-size: ($medium_size / 0.8) ($medium_size / 0.8), auto;
}

%needs_attention {
  animation: needs_attention $longer_duration $deceleration_curve forwards;
  background-repeat: no-repeat;
  background-position: right 3px;
  background-size: 6px 6px;
  &:dir(rtl) { background-position: left 3px; }
}


// all the following is for the +|- buttons on inline toolbars, that way
// should really be deprecated...
.inline-toolbar GtkToolButton > .button { // redefining the button look is
                                          // needed since those are flat...
}

// More inline toolbar buttons
.inline-toolbar.toolbar GtkToolButton {
  // & > .button.flat { @extend %linked_middle; }
  // &:first-child > .button.flat { @extend %linked:first-child; }
  // &:last-child > .button.flat { @extend %linked:last-child; }
  // &:only-child > .button.flat { @extend %linked:only-child; }
}

%linked_middle {
  outline-radius: 2px;
  border-radius: 0;
}

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

%linked_vertical_middle {
  outline-radius: 2px;
  border-radius: 0;
}

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

/* menu buttons */
.menuitem.button.flat {
  &:selected { @extend %selected_items; }
}


GtkColorButton.button {
  padding: 7px 8px 8px; // Uniform padding on the GtkColorButton

  GtkColorSwatch:first-child:last-child { // :first-child:last-child for a specificity bump, it gets overridden by the
                                          // colorpicker style, otherwise
    border-radius: 2px;
    box-shadow: $z-depth-1;
  }
}

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

*:link {
  color: $link_color;
  &:hover, &:active { color: $link_color; }
  &:visited {
    color: $link_visited_color;
    &:hover, &:active { color: $link_visited_color; }
    *:selected & { color: mix($selected_fg_color, $selected_bg_color, 60%); }
  }
  &:selected, *:selected & {
    color: mix($selected_fg_color, $selected_bg_color, 80%);
  }
}

.button:link, .button:visited {
  @extend *:link;
  & > .label {
    text-decoration-line: underline;
  }
}

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

.spinbutton {
  .button {
    padding: 4px;
    border: solid $container_padding transparent;
    color: $secondary_fg_color;
    &:hover, &:active { color: $fg_color; }
    &:insensitive { color: $insensitive_secondary_fg_color; }
    &:active { // add fallback
      background-color: gtkalpha(currentColor, $lower_opacity);
    }
    @extend %image_button;
    @extend %simple_flat_button;
  }
  .osd & {
    .button {
    }
  }
  &.vertical { //FIXME: try using linking templates for vertically linked stuff
    .button {
      padding-top: 10px;    //  Same vertical padding as image-buttons
      padding-bottom: 10px; //
      border: none;
      &:first-child {
        border-radius: 2px 2px 0 0;
      }
      &:last-child {
        border-radius: 0 0 2px 2px;
      }
    }
    &.entry {
    }
  }
  GtkTreeView & {
    &.entry, &.entry:focus {
      // padding: 1px;
      // border-width: 1px 0;
      // border-color: $selected_bg_color;
      // border-radius: 0;
      // box-shadow: none;
    }
  }
}

/**************
 * ComboBoxes *
 **************/
GtkComboBox {
  > .the-button-in-the-combobox { padding: 5px 6px 6px; } // Otherwise combos
                                                          // are bigger then
                                                          // buttons
  -GtkComboBox-arrow-scaling: 0.5;
  -GtkComboBox-shadow-type: none;

  .menu { padding: 2px 0; }
  .menu .menuitem { padding: 5px 6px 6px; }
  .separator.vertical {
    // always disable separators
    -GtkWidget-wide-separators: true;
  }
  &.combobox-entry .entry {
    &:dir(ltr) {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
    &:dir(rtl) {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
  }
  &.combobox-entry .button {
    padding: 10px;
    &:dir(ltr) {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
    &:dir(rtl) {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
  }
}

.linked > GtkComboBox > .the-button-in-the-combobox,
.linked > GtkComboBoxText > .the-button-in-the-combobox {
  // the combo is a composite widget so the way we do button linkind 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 > GtkComboBox:first-child > .the-button-in-the-combobox,
.linked > GtkComboBoxText:first-child > .the-button-in-the-combobox {
  @extend %linked:first-child;
}
.linked > GtkComboBox:last-child > .the-button-in-the-combobox,
.linked > GtkComboBoxText:last-child > .the-button-in-the-combobox {
  @extend %linked:last-child;
}
.linked > GtkComboBox:only-child > .the-button-in-the-combobox,
.linked > GtkComboBoxText:only-child > .the-button-in-the-combobox {
  @extend %linked:only-child;
}

.linked.vertical > GtkComboBoxText > .the-button-in-the-combobox,
.linked.vertical > GtkComboBox > .the-button-in-the-combobox { @extend %linked_vertical_middle; }
.linked.vertical > GtkComboBoxText:first-child > .the-button-in-the-combobox,
.linked.vertical > GtkComboBox:first-child > .the-button-in-the-combobox { @extend %linked_vertical:first-child; }
.linked.vertical > GtkComboBoxText:last-child > .the-button-in-the-combobox,
.linked.vertical > GtkComboBox:last-child > .the-button-in-the-combobox { @extend %linked_vertical:last-child; }
.linked.vertical > GtkComboBoxText:only-child > .the-button-in-the-combobox,
.linked.vertical > GtkComboBox:only-child > .the-button-in-the-combobox { @extend %linked_vertical:only-child; }

/************
 * Toolbars *
 ************/
.toolbar {
  -GtkWidget-window-dragging: true;
  padding: 4px;
  background-color: $bg_color;
  &:not(.search-bar) .button { @extend %button.flat; }
  .osd &, &.osd {
    transition: $shadow_image_transition;
    padding: $container_padding;
    border-style: solid;
    border-width: 8px;
    border-image: -gtk-scaled(url("assets/osd-shadow#{$asset_suffix}.png"),
                              url("assets/osd-shadow#{$asset_suffix}@2.png"))
                  10 / 10px stretch;
    border-radius: 2px;
    // box-shadow: $z-depth-2, inset 0 1px $highlight_color;
    background-color: $base_color;
    &:backdrop {
      border-image: -gtk-scaled(url("assets/osd-shadow-backdrop#{$asset_suffix}.png"),
                                url("assets/osd-shadow-backdrop#{$asset_suffix}@2.png"))
                    10 / 10px stretch;
      // box-shadow: $z-depth-1, inset 0 1px $highlight_color;
    }
  }
}

//searchbar, location-bar & inline-toolbar
.inline-toolbar {
  padding: $container_padding;
  border-style: solid;
  border-width: 0 1px 1px;
  border-color: $borders_color;
  background-color: $secondary_base_color;
}

.search-bar, .location-bar {
  padding: $container_padding;
  border-style: solid;
  border-width: 0 0 1px;
  border-color: $borders_color;
  background-color: $bg_color;
  background-clip: border-box;
}

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

.titlebar,
.header-bar {
  transition: background-color $shorter_duration $deceleration_curve;
  padding: $container_padding;
  border-radius: 2px 2px 0 0;
  box-shadow: $z-depth-1, inset 0 1px $topbar_highlight_color;
  background-color: $headerbar_color;
  color: $topbar_fg_color;

  &:backdrop {
    color: $secondary_topbar_fg_color;
  }

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

  .subtitle {
    transition: $longer_transition;
    @extend .dim-label;
    padding-left: 12px;
    padding-right: 12px;
    font-size: smaller;
  }

  .header-bar-separator,
  & > GtkBox > .separator.vertical {
    -GtkWidget-wide-separators: true;
    -GtkWidget-separator-width: 1px;
    border-style: solid;
    border-width: 0 1px;
    border-color: $borders_color;
  }

  & .button:not(.suggested-action):not(.destructive-action) {
    @extend %button.flat;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($topbar_indicator_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    &:checked {
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($topbar_indicator_color),
                                  to(transparent))
                                  0 0 2 / 0 0 2px;
      &, &:insensitive {
        background-color: transparent;
      }
    }
  }

  .button.suggested-action, .button.destructive-action {
    &:insensitive {
      color: gtkalpha(currentColor, $disabled_opacity);

      > .label { color: inherit; }
    }
  }

  &.selection-mode {
    // transition: background-color $shorter_duration $deceleration_curve;
    box-shadow: $z-depth-1, inset 0 1px $secondary_highlight_color;
    background-color: $selected_bg_color;
    color: $selected_fg_color;
    &:backdrop {
      color: $secondary_selected_fg_color;
    }

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

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

      &:insensitive {
      }

      &:checked {
        border-image: -gtk-gradient(radial,
                                    center bottom, 0,
                                    center bottom, 0.5,
                                    to($selected_fg_color),
                                    to(transparent))
                                    0 0 2 / 0 0 2px;
        color: $selected_fg_color;
        &:insensitive {
          color: $insensitive_selected_fg_color;
          > .label { color: inherit; }
        }
      }
      &.suggested-action {
        // NOTE: do not use @extend .button;
        @include button(normal);
        &:hover { @include button(hover); }
        &:active { @include button(active); }
        &:insensitive { @include button(insensitive); }
      }
    }

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

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

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

  .tiled &, .maximized & {
    border-radius: 0; // squared corners when the window is max'd or tiled
    box-shadow: none;
  }

  &.default-decoration {
    padding: $container_padding;
    border-width: 0;
    .button { padding: 4px; }
  }
}

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

.path-bar .button {
  padding: 7px 6px 8px;

  // the following is for spacing the icon and the label inside the home button
  .label:last-child { padding-left: 2px; }
  .label:first-child { padding-right: 2px; }
  // .label:only-child { padding-right: 0; padding-left: 0; }

  GtkImage { padding-top: 1px; }
  GtkImage:only-child { padding-right: 4px; padding-left: 4px; }
}

/**************
 * Tree Views *
 **************/
GtkTreeView.view {
  -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: $track_color;  // this is actually the tree lines color,
  border-top-color: $borders_color; // while this is the grid lines color, better then nothing

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

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

  &:hover, &:active, &:selected { border-radius: 0; }

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

  &.expander {
    -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
    &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }
    &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
    &:selected {
      color: scale-alpha($selected_fg_color, $enabled_opacity);
      &:hover, &:active { color: $selected_fg_color; }
    }
  }

  &.progressbar { // progress bar in treeviews
    @extend .entry.progressbar;
    border-width: 4px;
    &:selected {
      border-color: currentColor;
    }
  }

  &.trough { // progress bar trough in treeviews
    @extend .entry.progressbar;
    border-width: 4px;
    border-color: scale-alpha($selected_bg_color, $lower_opacity);
    &:selected {
      border-color: $track_color;
    }
  }
}

column-header {
  .button {
    @extend .list-row.activatable;
    padding: 3px 6px 4px;
    border-style: none solid solid none;
    border-width: 1px;
    border-color: $borders_color;
    border-radius: 0;
    box-shadow: none;
    background-color: $base_color;
    // font-weight: bold;
    &:hover, &:active {
      box-shadow: none;
    }
    &:insensitive {
      background-color: $base_color;
    }
    &.dnd {
      @extend column-header.button.dnd;
    }
  }
  &:last-child .button,
  &:last-child.button { //treeview-like derived widgets in Banshee and Evolution
    border-right-style: none;
  }
}

column-header.button.dnd { // for treeview-like derive widgets
  border-left-style: solid;
  background-clip: $extra_background_clip;
  color: $selected_bg_color;
}


/*********
 * Menus *
 *********/
.menubar {
  -GtkWidget-window-dragging: true;
  padding: 0;
  // box-shadow: inset 0 -1px $borders_color;
  background-color: $headerbar_color;
  & > .menuitem {
    transition: $shorter_transition;
    padding: 4px 8px;
    color: $secondary_topbar_fg_color;
    &:hover { //Seems like it :hover even with keyboard focus
      transition: none;
      background-color: gtkalpha(currentColor, $lower_opacity / 2);
      color: $topbar_fg_color;
    }
    &:insensitive {
      color: $insensitive_secondary_topbar_fg_color;
      box-shadow: none;
    }
  }
}

.menu {
  margin: 4px 0;
  padding: 4px 0;
  box-shadow: inset 0 1px $highlight_color;
  background-color: $base_color;
  border: 1px solid $borders_color; // adds borders in a non composited env
  .csd & {
    border: none; // axes borders in a composited env
    border-radius: 2px;
  }
  .menuitem {
    transition: $shorter_transition;
    padding: 3px 4px 4px;
    font: initial;
    text-shadow: none;
    &:hover {
      transition: none;
      background-color: gtkalpha(currentColor, $lower_opacity / 2);
    }
    &:insensitive {
      color: $insensitive_fg_color;
    }
    //submenu indicators
    &.arrow { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic'); }
    &.arrow:dir(rtl) {-gtk-icon-source:-gtk-icontheme('pan-end-symbolic-rtl'); }
  }
  &.button { // overlow buttons
    border-style: none;
    border-radius: 0;
    box-shadow: none;
    &.top { border-bottom: 1px solid $borders_color; }
    &.bottom { border-top: 1px solid $borders_color; }
    &:hover { background-color: gtkalpha(currentColor, $lower_opacity / 2); }
    &:insensitive {
      background-color: transparent;
      border-color: transparent;
    }
  }
}

.menuitem .accelerator { color: gtkalpha(currentColor, $hint_opacity); }

.csd.popup { border-radius: 2px; }


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

.popover {
  transition: $shadow_transition;
  padding: 2px;
  border: 1px solid;
  border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.3);
  border-radius: 2px + 1px;
  background-color: $light_color;
  box-shadow:  $z-depth-2; // TODO: this should really have a highlight
  &:backdrop { box-shadow: $z-depth-1; }

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

  .button.flat {
    padding: 5px 8px 6px;
    background-color: transparent;
    background-size: (128px / 0.8) (128px / 0.8), auto;
    color: $fg_color;
    font: initial;
  }

  .linked > .button {
    border-radius: 2px;
    @extend %simple_flat_button;
    &:checked {
      background-color: $selected_bg_color;
      color: $selected_fg_color;
    }
    &.image-button {
      padding: 8px;
      background-size: ($medium_size * 2 / 0.8) ($medium_size * 2 / 0.8), auto;
    }
  }

  &.osd { @extend %osd; }
}

/*****************
 * Notebooks and *
 * Tabs          *
 *****************/

.notebook {
  // Through me you go to the grief wracked city;
  // Through me you go to everlasting pain;
  // Through me you go a pass among lost souls.
  // ...
  // Abandon all hope — Ye Who Enter Here
  padding: 0;
  background-color: $base_color;
  -GtkNotebook-initial-gap: 8;
  -GtkNotebook-arrow-spacing: 5;
  -GtkNotebook-tab-curvature: 0;
  -GtkNotebook-tab-overlap: 1;
  -GtkNotebook-has-tab-gap: false;
  -GtkWidget-focus-padding: 0;
  -GtkWidget-focus-line-width: 0;
  &.frame {
    border: 1px solid $borders_color;
    // FIXME doesn't work
    &.top { border-top-width: 0; }
    &.bottom { border-bottom-width: 0; }
    &.right { border-right-width: 0; }
    &.left { border-left-width: 0; }
  }
  &.header {
    // FIXME: double borders in some case, can't fix it w/o a class tho
    // FIXME: doesn't work on dark var
    background-color: $bg_color;

    // this is the shading of the header behind the tabs
    &.frame {
      border: 1px solid $borders_color;
      &.top { border-bottom-width: 0; }
      &.bottom { border-top-width: 0; }
      &.right { border-left-width: 0; }
      &.left { border-right-width: 0; }
    }

    &.top {
      box-shadow: inset 0 -1px $borders_color; // border
    }
    &.bottom {
      box-shadow: inset 0 1px $borders_color;
    }
    &.right {
      box-shadow: inset 1px 0 $borders_color;
    }
    &.left {
      box-shadow: inset -1px 0 $borders_color;
    }
  }
  tab {
    border-width: 0;
    border-style: solid;
    border-color: transparent;
    background-color: transparent;

    outline-offset: 0;

    $tab_indicator_size: 2px;
    // vertical tab sizing
    $vt_vpadding: 8px;
    $vt_hpadding: 12px;
    // horizontal tab sizing
    $ht_vpadding: 8px;
    $ht_hpadding: 12px;

    //FIXME: we get double border in some cases, not considering the broken
    //notebook content frame...
    &.top, &.bottom { padding: $vt_vpadding $vt_hpadding; }
    &.left, &.right { padding: $ht_vpadding $ht_hpadding; }


    /* works for testnotebookdnd, but there's a superfluous border
       in gedit or web, commented out for now, needs gtk fixes
    &.reorderable-page {
      &.top {
        padding-top: ($vt_vpadding - 1px);
        border-top-width: 1px;
        border-left-width: 1px;
        border-right-width: 1px;
      }
      &.bottom {
        padding-bottom: ($vt_vpadding - 1px);
        border-bottom-width: 1px;
        border-left-width: 1px;
        border-right-width: 1px;
      }
      &.left {
        padding-left: ($ht_hpadding - 1px);
        border-left-width: 1px;
        border-top-width: 1px;
        border-bottom-width: 1px;
      }
      &.right {
        padding-right: ($ht_hpadding - 1px);
        border-right-width: 1px;
        border-top-width: 1px;
        border-bottom-width: 1px;
      }
    }
    */
    &.reorderable-page {
      -GtkNotebook-tab-overlap: 1;
      &.top, &.bottom {
        padding-left: 12px;  // for a nicer close button
        padding-right: 12px; // placement
        border-left-width: 1px;
        border-right-width: 1px;
      }
      &.left, &.right {
        border-bottom-width: 1px;
        border-top-width: 1px;
      }
    }
    &.top {
      &:hover, &.prelight-page { box-shadow: inset 0 -2px $track_color; }
      &:active, &.active-page { box-shadow: inset 0 -2px $selected_bg_color; }
    }
    &.bottom {
      &:hover, &.prelight-page { box-shadow: inset 0 2px $track_color; }
      &:active, &.active-page { box-shadow: inset 0 2px $selected_bg_color; }
    }
    &.left {
      &:hover, &.prelight-page { box-shadow: inset -2px 0 $track_color; }
      &:active, &.active-page { box-shadow: inset -2px 0 $selected_bg_color; }
    }
    &.right {
      &:hover, &.prelight-page { box-shadow: inset 2px 0 $track_color; }
      &:active, &.active-page { box-shadow: inset 2px 0 $selected_bg_color; }
    }
    @each $_tab, $_border in (top, bottom),
                             (bottom, top),
                             (left, right),
                             (right, left) {
      &.reorderable-page.#{$_tab} {
        border-color: transparent;
        &:hover, &.prelight-page {
          border-color: $borders_color;
          border-#{$_border}-width: 0;
          border-#{$_border}-color: transparent;
          background-color: $secondary_base_color;
        }
        &:active, &.active-page {
          border-color: $borders_color;
          border-#{$_border}-width: 0;
          border-#{$_border}-color: transparent;
          background-color: $base_color;
        }
      }
    }
    .label { //tab text
      padding: 0 2px; // needed for a nicer focus ring
      font-weight: 500;
      color: $secondary_fg_color;
    }
    .prelight-page .label, .label.prelight-page {
      // prelight tab text
      color: $fg_color;
    }
    .active-page .label, .label.active-page {
      // active tab text
      color: $fg_color;
    }
    .button { //tab close button
      padding: 0;
      @extend %image_button;
      background-size: ($small_size / 0.8) ($small_size / 0.8), auto;
      @extend %simple_flat_button;
      & > GtkImage { // this is a hack which makes tabs grow
        padding: 4px;
      }
    }
  }
  &.arrow {
    &:not(:hover):not(:active) { color: gtkalpha(currentColor, $enabled_opacity); }
    &:insensitive {
      color: $insensitive_fg_color;
    }
  }
  GtkGrid > .entry {
    @extend .entry.flat;
  }
}

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

$_slider_margin: 4px;
$_slider_fine_tune_margin: 6px;

.scrollbar {
  -GtkRange-slider-width: 8 + $_slider_margin * 2 + 1;
  -GtkRange-trough-border: 0;
  -GtkScrollbar-has-backward-stepper: false;
  -GtkScrollbar-has-forward-stepper: false;
  -GtkScrollbar-min-slider-length: 24 + $_slider_margin * 2;
                                       // minimum size for the slider.
                                       // sadly can't be in '.slider'
                                       // where it belongs
  -GtkRange-stepper-spacing: 0;
  -GtkRange-trough-under-steppers: 1;

  .button {
    border: none;
  }

  &.overlay-indicator {
    &:not(.dragging):not(.hovering) { // Overlay scrolling indicator
      -GtkRange-slider-width: 4 + $_slider_margin * 2;

      .slider {
        margin: $_slider_margin - 1px;
        border: 1px solid scale-alpha($base_color, $lower_opacity);
        // background-clip: padding-box;
      }

      .trough {
        border-style: none;
        background-color: transparent;
      }

    }

    &.dragging,
    &.hovering {
      .trough {
        background-color: scale-alpha($base_color, $higher_opacity);
      }
    }
  }

  // trough coloring
  .trough {
    border: 1px none $borders_color;
    background-color: $base_color;
    background-clip: $extra_background_clip;
  }

  // slider coloring
  .slider {
    background-color: $tertiary_fg_color;
    &:hover { background-color: $secondary_fg_color; }
    &:active { background-color: $fg_color; }
    &:insensitive {
      opacity: $disabled_opacity;
    }
  }


  // sizing
  .slider {
    border-radius: 100px;
    margin: $_slider_margin;
  }

  &.fine-tune .slider { margin: $_slider_fine_tune_margin; }

  &.vertical {

    .slider {
      margin-left: 1px + $_slider_margin;

      &:dir(rtl) {
        margin-left: $_slider_margin;
        margin-right: 1px + $_slider_margin;
      }
    }

    &.fine-tune .slider {
      margin-left: 1px + $_slider_fine_tune_margin;

      &:dir(rtl) {
        margin-left: $_slider_fine_tune_margin;
        margin-right: 1px + $_slider_fine_tune_margin;
      }
    }

    .trough {
      border-left-style: solid;

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

  &.horizontal {

    .slider { margin-top: 1px + $_slider_margin; }

    &.fine-tune .slider { margin-top: 1px + $_slider_fine_tune_margin; }

    .trough { border-top-style: solid; }
  }
}

.scrollbars-junction,
.scrollbars-junction.frame { // the small square between two scrollbars
  border-style: solid none none solid;
  background-color: $base_color;

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


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

GtkSwitch {
  -GtkSwitch-slider-width: $small_size;
  -GtkSwitch-slider-height: $small_size;

  outline-offset: -4px;
  outline-radius: 100px;
  font-size: 0;
  &.trough {
    // similar to the .scale
    border: 8px solid transparent;
    border-radius: 100px;
    background-color: $track_color;
    // background-clip: padding-box;
    &:insensitive {
      color: gtkalpha(currentColor, $disabled_opacity);
    }
    &:active {
      background-color: scale-alpha($accent_bg_color, 0.5);
      &:insensitive {
        background-color: scale-alpha($accent_bg_color, 0.5 * $disabled_opacity);
      }
    }
  }
  &.slider {
    padding: 4px;
    border-radius: 100px;
    @include entry(normal);
    &:hover { @include entry(focus); }
    &:active { background-color: $accent_bg_color; }
    &:insensitive { @include entry(insensitive); }
  }
  .list-row:selected & {
  }

}

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

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

  //standard checks and radios
  @each $s,$as in ('','-unchecked'),
                  (':active', '-unchecked-active'),
                  (':insensitive','-unchecked-insensitive'),
                  (':inconsistent', '-mixed'),
                  (':inconsistent:active', '-mixed-active'),
                  (':inconsistent:insensitive', '-mixed-insensitive'),
                  (':checked', '-checked'),
                  (':checked:active', '-checked-active'),
                  (':checked:insensitive','-checked-insensitive') {
    .#{$w}#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}#{$asset_suffix}.png"),
                                    url("assets/#{$a}#{$as}#{$asset_suffix}@2.png"));
      icon-shadow: $z-depth-1;
      &:hover, &:active { icon-shadow: $z-depth-2; }
      &:insensitive { icon-shadow: none; }
      &.button.flat {  }
    }
  }

  //menu
  @each $s,$as in ('',''),
                  // (':active', '-checked'),
                  (':insensitive','-insensitive'),
                  (':inconsistent', '-mixed'),
                  // (':inconsistent:active', '-mixed'),
                  (':inconsistent:insensitive', '-mixed-insensitive'),
                  (':checked', '-checked'),
                  // (':checked:active', '-checked'),
                  (':checked:insensitive','-checked-insensitive') {
    .menu .menuitem.#{$w}#{$s} {
      // color: gtkalpha(currentColor, $hint_opacity);
      // -gtk-icon-source: -gtk-icontheme('#{$a}-symbolic');
      // &:active, &:checked { -gtk-icon-source: -gtk-icontheme('#{$a}-checked-symbolic'); }
      // &:inconsistent { -gtk-icon-source: -gtk-icontheme('#{$a}-mixed-symbolic'); }
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}-symbolic#{$asset_suffix}.png"),
                                    url("assets/#{$a}#{$as}-symbolic#{$asset_suffix}@2.png"));
      icon-shadow: none;
    }
  }
}

//treeview and list-rows
.view.check, .view.radio,
.list-row .check, list-row .radio {
}

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

GtkCheckButton.text-button, GtkRadioButton.text-button {
  // this is for a nice focus on check and radios text
  padding: 2px 4px;
  outline-offset: 0;
  &:insensitive,
  &:insensitive:active,
  &:insensitive:inconsistent {
    // set insensitive color, which is overriden otherwise
    // color: $insensitive_fg_color;
  }
}

/************
 * GtkScale *
 ************/
.scale,
.scale.scale-has-marks-above.scale-has-marks-below,
.scale.vertical.scale-has-marks-above.scale-has-marks-below {
  // FIXME: rationalize
  -GtkScale-slider-length: 20;
  -GtkRange-slider-width: 20;
  -GtkRange-trough-border: 2;
  outline-offset: -8px;
  outline-radius: 100px;

  &.fine-tune {
    &.slider { background-size: 80%; }
  }

  &.slider {
    &:not(:hover):not(:active) { background-size: 80%; }
    // @include entry(normal);
    // border-radius: 50%;
    // background-color: $accent_bg_color;
    @each $s,$as in ('',''),
                    // (':hover','-hover'),
                    // (':active','-active'),
                    (':insensitive','-insensitive') {
      &.slider#{$s} {
        $_url: 'assets/slider#{$as}#{$asset_suffix}';
        border-style: none;
        border-radius: 0;
        background-color: transparent;
        background-image: -gtk-scaled(url('#{$_url}.png'),
                          url('#{$_url}@2.png'));
        background-repeat: no-repeat;
        background-position: center;
        box-shadow: none;
      }
    }
    &:hover {
      // @include entry(focus);
      // border-radius: 50%; // needed for double marks scales
    }
    &:insensitive {
      // @include entry(insensitive);
      // border-radius: 50%;  // overridden
    }
    //OSD sliders
    .osd & {
    }
  }
  &.trough {
    margin: 10px 12px;
    background-color: $track_color;
    &.highlight {
      background-color: $accent_bg_color;
      &:insensitive { background-color: $track_color; }
    }
    &:insensitive { color: $insensitive_fg_color; }
    &.vertical { margin: 12px 10px; }
    //OSD troughs
    .osd & {
    }
  }
  // marks color
  &.separator {
    color: $track_color;
  }
  // scales on selected list rows
  .list-row:selected & {
  }
}

@each $d,$dn in ('', 'horz'),
                ('.vertical', 'vert') {
  @each $w,$we in  ('scale-has-marks-below','scale_marks_below'),
                   ('scale-has-marks-above','scale_marks_above') {
    .scale#{$d}.#{$w} {
      -GtkScale-slider-length: 20;
      -GtkRange-slider-width: 25;
      -GtkRange-trough-border: 2;

      @extend %#{$we}_#{$dn};

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

%scale_marks_above_horz {
  .trough { margin: 15px 12px 10px; }
}
%scale_marks_below_horz {
 .trough { margin: 10px 12px 15px; }
}
%scale_marks_above_vert {
  .trough { margin: 12px 10px 12px 15px; }
}
%scale_marks_below_vert {
  .trough { margin: 12px 15px 12px 10px; }
}

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

GtkProgressBar {
  -GtkProgressBar-min-horizontal-bar-height: 4;
  -GtkProgressBar-min-vertical-bar-width: 4;
  padding: 0;
  font-size: smaller;
  color: $tertiary_fg_color;
  &.osd {
    -GtkProgressBar-xspacing: 0;
    -GtkProgressBar-yspacing: 0;
    -GtkProgressBar-min-horizontal-bar-height: 4;
  }
  &.trough {  // background
    border-radius: 0;
    background-color: scale-alpha($selected_bg_color, $lower_opacity);
    &.osd {
      border-style: none;
      box-shadow: none;
      // background-color: transparent;
    }
  }
}

// moving bit
.progressbar {
  border-radius: 0;
  background-color: $selected_bg_color;
  &.left {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  &.right {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
  &.left.right {
    box-shadow: none;
  }
  &.vertical {
    &.bottom {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
      box-shadow: none;
    }
    &.top {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
  }
  &.osd {
    background-image: none;
    background-color: $selected_bg_color;
    border-style: none;
    border-radius: 0;
  }
}


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

.level-bar {
  box-shadow: $z-depth-1; // needs to be set here to avoid clipping
  color: $insensitive_fg_color;
  -GtkLevelBar-min-block-width: 36;
  -GtkLevelBar-min-block-height: 4;
  &.vertical {
    -GtkLevelBar-min-block-width: 4;
    -GtkLevelBar-min-block-height: 36;
  }
  &.trough {
    padding: 2px;
    border-radius: 2px;
    @include entry(normal);
    &:insensitive { @include entry(insensitive); }
    &.indicator-discrete {
      &.horizontal { padding: 2px 1px; }
      &.vertical { padding: 1px 2px; }
    }
  }
  &.fill-block {
    // FIXME: it would be nice to set make fill blocks bigger, but we'd need
    // :nth-child working on discrete indicators
    background-color: $selected_bg_color;
    border-radius: 0;
    box-shadow: none;
    &.indicator-discrete {
      &.horizontal { margin: 0 1px; }
      &.vertical { margin: 1px 0; }
    }
    &.level-high {
      background-color: $success_color;
    }
    &.level-low {
      background-color: $warning_color;
    }
    &.empty-fill-block {
      background-color: $track_color;
    }
  }
}


/**********
 * Frames *
 **********/
.frame {
  border: 1px solid $borders_color;
  &.flat { border-style: none; }
  padding: 0;
  &.action-bar {
    padding: $container_padding;
    border-width: 1px 0 0;
    .button:not(.suggested-action):not(.destructive-action) { @extend %button.flat; }
  }
}

GtkScrolledWindow {
  GtkViewport.frame { // avoid double borders when viewport inside
                      // scrolled window
    border-style: none;
  }
}

//vbox and hbox separators
.separator {
  // always disable separators
  // -GtkWidget-wide-separators: true;
  color: $borders_color;

  // Font and File button separators
  GtkFileChooserButton &.vertical,
  GtkFontButton &.vertical {
    // always disable separators
    -GtkWidget-wide-separators: true;
  }
}

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

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

.list-row,
.grid-child {
  padding: 2px;
}

// FIXME
$row_transition: $longer_transition, background-color 0, color 0;

.list-row.activatable {
  transition: $row_transition;
  box-shadow: inset 0 0 0 10000px gtkalpha(currentColor, 0);
  background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
  background-repeat: no-repeat;
  background-position: center, center;
  background-size: (192px / 0.8) (192px / 0.8), auto;
  &:hover {
    transition: $row_transition, box-shadow 0;
    box-shadow: inset 0 0 0 10000px gtkalpha(currentColor, 0.05);
  }
  &:active {
    transition: $row_transition, background-image 0;
    animation: list_ripple_effect $longer_duration $deceleration_curve forwards;
    box-shadow: inset 0 0 0 10000px gtkalpha(currentColor, $lower_opacity / 2);
  }
}

.list-row:selected {
  @extend %selected_items;
  .button {
    &:insensitive { color: $insensitive_secondary_selected_fg_color; }
    &.flat {
      color: $secondary_selected_fg_color;
      &:hover, &:active { color: $selected_fg_color; }
      &:insensitive { color: $insensitive_secondary_selected_fg_color; }
    }
  }
}

// transition
.list-row {
  // &:hover { transition-duration: 0; }
}


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

.app-notification,
.app-notification.frame {
  @extend %osd;
  @extend .toolbar.osd;
  .button { @extend %button.flat; }
}

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

.expander {
  -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
  &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }
  &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
  &:not(:hover):not(:active) { color: gtkalpha(currentColor, $enabled_opacity); }
  &:selected { color: $selected_fg_color; }
}

/************
 * Calendar *
 ***********/
GtkCalendar {
  padding: 1px;
  border: 1px solid $borders_color;
  color: $fg_color;

  &:insensitive { color: $insensitive_fg_color; }

  &:selected {
    @extend .view:selected;

    border-radius: 2px + 1px;
  }

  &.header {
    border-style: none none solid;
    border-radius: 0;
  }

  &.button {
    @extend %simple_flat_button;
  }

  &:inconsistent { color: gtkalpha(currentColor, $disabled_opacity); }
  &.highlight {
    font-size: smaller;
    color: gtkalpha(currentColor, $hint_opacity);
  }
}

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

.message-dialog .dialog-action-area .button {
  padding: 8px;
}

.message-dialog { // Message Dialog styling
  &.background { background-color: $light_color; }
  .titlebar {
    border-style: none;
    box-shadow: inset 0 1px $highlight_color;
    background-color: $light_color;
  }
  &.csd { // rounded bottom border styling for csd version
    &.background {
      // bigger radius for better antialiasing
      border-bottom-left-radius: 2px;
      border-bottom-right-radius: 2px;
    }
    .dialog-action-area .button {
      @extend %simple_flat_button;
      padding: 9px 16px 10px;
      border-top: 1px solid $borders_color;
      border-radius: 0;
      background-size: (192px / 0.8) (192px / 0.8), auto;
      // &:first-child{ border-bottom-left-radius: 2px; }
      // &:last-child { border-bottom-right-radius: 2px; }
      &:first-child{ border-radius: 0 0 0 2px; }
      &:last-child { border-radius: 0 0 2px 0; }
    }
  }
}

GtkFileChooserDialog {
  .search-bar {
    // background-color: $base_color;
    // border-color: $bg_color;
  }
  .dialog-action-box {
    border-top: 1px solid $borders_color;
  }
}

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

.sidebar {
  border: none;
  background-color: $light_color;

  &:selected {
    @extend %selected_items;
  }
}

GtkSidebarRow {
  // Needs overriding of the GtkListBoxRow padding
  &.list-row {
    padding: 0px;
  }
  // Using margins/padding directly in the SidebarRow
  // will make the animation of the new bookmark row jump
  .sidebar-revealer {
    padding: 4px 14px 4px 12px;
  }
  .sidebar-icon {
    opacity: $hint_opacity; // dim the device icons
    &:dir(ltr) { padding-right: 8px; }
    &:dir(rtl) { padding-left: 8px; }
  }
  .sidebar-label {
    &:dir(ltr) { padding-right: 2px; }
    &:dir(rtl) { padding-left: 2px; }
  }
}

GtkPlacesSidebar.sidebar {
  // looks like the label doesn't get all the states so work around
  .list-row:selected:insensitive .label { @extend %selected_items:insensitive; }

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

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

  @at-root .sidebar-button.button { // @at-root needded to not change the specificity making button styling inheritance broken
                                    // so istead of "GtkPlacesSidebar.sidebar .sidebar-button.button" [specificity 0,0,3,1]
                                    // the extended selector ".sidebar-button.button" [specificity 0,0,2,0]

    &.image-button { padding: 4px; }

    @extend %simple_flat_button;
  }
  // this is for indicating which sidebar row generated a popover
  // see https://bugzilla.gnome.org/show_bug.cgi?id=754411
  .has-open-popup { @extend .list-row.activatable:active; }
}

.sidebar-item {
  padding: 10px 4px;
  > .label {
    padding-left: 6px;
    padding-right: 6px;
  }
  &.needs-attention > .label {
    @extend %needs_attention;
  }
}

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

GtkPaned { // this is for the standard paned separator

  -GtkPaned-handle-size: 1; // sets separator width

  -gtk-icon-source: none; // removes handle decoration
  margin: 0 8px 8px 0; // drag area of the separator, not a real margin
  &:dir(rtl) {
    margin-right: 0;
    margin-left: 8px;
  }
  .pane-separator {
    background-color: $borders_color;
  }
}

GtkPaned.wide { // this is for the paned with wide separator
  -GtkPaned-handle-size: 6; // wider separator here
  margin: 0; // no need of the invisible drag area so, reset margin
  .pane-separator {
    background-color: transparent;
    border-style: none solid;
    border-color: $borders_color;
    border-width: 1px;
  }
  &.vertical .pane-separator { border-style: solid none;}
}


/**************
 * GtkInfoBar *
 **************/
GtkInfoBar {
  border-style: none;
}

.info {
  background-color: $info_bg_color;
}

.question {
  background-color: $question_bg_color;
}

.warning {
  background-color: $warning_bg_color;
}

.error {
  background-color: $error_bg_color;
}

.info,
.question,
.warning,
.error {
  color: $selected_fg_color;
  .button {
    // @extend .list-row:selected.button;
    &:insensitive { color: $insensitive_secondary_selected_fg_color; }
  }
  .label: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.
    box-shadow: inset 0 1px $highlight_color;
    background-color: scale-alpha($base_color, $higher_opacity);
  }

  // @extend %osd;
  color: $fg_color;
  padding: 4px; /* not working */
  border-radius: 2px;
  box-shadow: none; // otherwise it gets inherited by windowframe.csd
  // FIXME: we need a border or tooltips vanish on black background.
  &.window-frame.csd {
    background-color: transparent;
  }
}

.tooltip * { //Yeah this is ugly
  padding: 4px;
  background-color: transparent;
  color: inherit; // just to be sure
}

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

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

  transition: $shadow_transition;
  box-shadow: $z-depth-1;

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

  // base color corners rounding
  // to avoid the artifacts caused by rounded corner anti-aliasing the base color
  // sports a bigger radius.
  // nth-child is needed by the custom color strip.
  // The :not() madness is needed since actually the overlay is selectable by GtkColorSwatch > .overlay
  // and GtkColorSwatch.overlay, I know it's weird, but this is gtk+, not a browser.
  &.top {
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
  }
  &.bottom {
    border-bottom-left-radius: 2px;
    border-bottom-right-radius: 2px;
  }
  &.left, &:first-child:not(.overlay):not(.top) {
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
  }
  &.right, &:last-child:not(.overlay):not(.bottom) {
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;
  }
  &:only-child:not(.overlay) { border-radius: 2px; }

  // overlay corner rounding
  &.top > .overlay {
    border-top-left-radius: 2px;
    border-top-right-radius: 2px;
  }
  &.bottom > .overlay {
    border-bottom-left-radius: 2px;
    border-bottom-right-radius: 2px;
  }
  &:first-child:not(.top) > .overlay {
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
  }
  &:last-child:not(.bottom) > .overlay {
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;
  }
  &:only-child > .overlay { border-radius: 2px; }

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

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

  // indicator and keynav outline colors
  &.color-dark {
    color: white;
  }
  &.color-light {
    color: scale-alpha(black, 0.8);
  }

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

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


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

//content view (grid/list)
.content-view {
  background-color: $bg_color;
  // &:hover { -gtk-image-effect: highlight; }
  &.rubberband { @extend .rubberband; }
}

.scale-popup {

   .osd & { @extend %osd; }

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

  .button { // +/- buttons on GtkVolumeButton popup
    padding: 10px;
  }
}

GtkScaleButton.button,
GtkVolumeButton.button {
  // I assume both are image-button *by default*
  // with the image-button/text-button classes automagically applied depending on the button child these selectors can be deleted.
  @extend %image_button;

  &.text-button { @extend .text-button }
}

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

.window-frame {
  transition: $shadow_transition;
  border-radius: 2px 2px 0 0;
  box-shadow: $z-depth-4;

  // FIXME rationalize window-frame shadows

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

  &:backdrop {
    box-shadow: $z-depth-2;
  }
  &.tiled {
    border-radius: 0;
  }
  &.popup {
    box-shadow: none;
  }
  // server-side decorations as used by mutter
  &.ssd {
    box-shadow: 0 3px 3px rgba(0, 0, 0, 0.16); //just doing borders, wm draws actual shadows
  }
  &.csd {
    &.popup {
      border-radius: 2px;
      box-shadow: $z-depth-2;
    }
    &.tooltip {
      border-radius: 2px;
      box-shadow: $z-depth-2;
    }
    &.message-dialog {
      border-radius: 2px;
      box-shadow: $z-depth-4;
      &:backdrop { box-shadow: $z-depth-2; }
    }
  }
  &.solid-csd {
    border-radius: 0;
    margin: 4px;
    background-color: $warning_color;
    // border: solid 1px $borders_color;
    box-shadow: none;
  }
}

// Window Close button
.header-bar .button.titlebutton,
.titlebar .button.titlebutton {
  // @extend %simple_flat_button;
  @extend %image_button;

  &:active { // add fallback
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.4,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, $lower_opacity / 2));
  }
}

// catch all extend :)

%selected_items {
  background-color: $selected_bg_color;
  color: $selected_fg_color;
  &:insensitive { color: $insensitive_selected_fg_color; }
}

.monospace {
  font: Monospace;
}

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

//touch selection handlebars for the Popover.osd above
.entry.cursor-handle,
.cursor-handle {
  background-color: $accent_bg_color;
  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: -gtk-scaled(url('#{$_url}.png'),
                                        url('#{$_url}@2.png'));
     }
  }
}

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

.touch-selection {
  font: initial;
  color: $fg_color;
  background-color: $base_color;
  box-shadow: $z-depth-2;
  &:backdrop { box-shadow: $z-depth-1; }
  .button {
  }
}

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

// Overflow indication, works similarly to the overshoot, the size if fixed tho.
.undershoot {
  &.top {
    @include undershoot(top);
  }

  &.bottom {
    @include undershoot(bottom);
  }

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

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