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

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

  -GtkCheckButton-indicator-size: 24;
  -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: $visited_link_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: $fill_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: $disabled_fg_color;
  }
  &:selected {
    background-color: $primary_color;
    color: $inverse_fg_color;
  }
}

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

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

  &:insensitive {
    // background-color: $alt_base_color;
    color: $disabled_fg_color;
  }

  &:selected { @extend %selected_items; }
}

.rubberband {
  border: 1px solid $alt_primary_color;
  background-color: rgba($alt_primary_color, $lower_opacity);
}

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

.dim-label {
  opacity: $hint_opacity;
}

GtkAssistant {
  .sidebar {
    padding: 6px 0;
    // border-top: 1px solid $border_color;
    &:dir(ltr) { border-right: 1px solid $border_color; }
    &:dir(rtl) { border-left: 1px solid $border_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: $alt_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: $primary_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, $secondary_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_color),
                                    to(transparent));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to($accent_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: $inverse_fg_color;
      &:insensitive { @include button(insensitive, $b_color); }
      &:checked { background-color: mix($inverse_fg_color, $b_color, percentage($lower_opacity)); }
      &.flat {
        background-color: transparent;
        color: $b_color;
        &:insensitive { @include button(flat-insensitive, $b_color); }
        &:checked { background-color: $fill_color; }
      }
    }
  }

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

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

*:link {
  color: $link_color;
  &:hover, &:active { color: $link_color; }
  &:visited {
    color: $visited_link_color;
    &:hover, &:active { color: $visited_link_color; }
    *:selected & { color: mix($inverse_fg_color, $primary_color, 60%); }
  }
  &:selected, *:selected & {
    color: mix($inverse_fg_color, $primary_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: $disabled_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: $primary_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: border-image $shorter_duration $deceleration_curve;
    padding: $container_padding;
    border-style: solid;
    border-width: 8px;
    border-image: -gtk-scaled(url("assets/box-shadow#{$asset_suffix}.png"),
                              url("assets/box-shadow#{$asset_suffix}@2.png"))
                  10 / 10px stretch;
    border-radius: 2px;
    // box-shadow: $shadow_2, inset 0 1px $highlight_color;
    background-color: $base_color;
    &:backdrop {
      border-image: -gtk-scaled(url("assets/box-shadow-backdrop#{$asset_suffix}.png"),
                                url("assets/box-shadow-backdrop#{$asset_suffix}@2.png"))
                    10 / 10px stretch;
      // box-shadow: $shadow_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: $border_color;
  background-color: $alt_base_color;
}

.search-bar, .location-bar {
  padding: $container_padding;
  border-style: solid;
  border-width: 0 0 1px;
  border-color: $border_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: $shadow_1, inset 0 1px $titlebar_highlight_color;
  background-color: $titlebar_bg_color;
  color: $titlebar_fg_color;

  &:backdrop {
    color: $titlebar_secondary_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: $border_color;
  }

  & .button:not(.suggested-action):not(.destructive-action) {
    @extend %button.flat;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($titlebar_indicator_color),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    &:checked {
      border-image: -gtk-gradient(radial,
                                  center bottom, 0,
                                  center bottom, 0.5,
                                  to($titlebar_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: $shadow_1, inset 0 1px $alt_highlight_color;
    background-color: $primary_color;
    color: $inverse_fg_color;
    &:backdrop {
      color: $inverse_secondary_fg_color;
    }

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

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

      &:insensitive {
      }

      &:checked {
        border-image: -gtk-gradient(radial,
                                    center bottom, 0,
                                    center bottom, 0.5,
                                    to($inverse_fg_color),
                                    to(transparent))
                                    0 0 2 / 0 0 2px;
        color: $inverse_fg_color;
        &:insensitive {
          color: $inverse_disabled_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: $fill_color;  // this is actually the tree lines color,
  border-top-color: $border_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, $primary_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: $inverse_secondary_fg_color;
      &:hover, &:active { color: $inverse_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: rgba($primary_color, $lower_opacity);
    &:selected {
      border-color: $fill_color;
    }
  }
}

column-header {
  .button {
    @extend .list-row.activatable;
    padding: 3px 6px 4px;
    border-style: none solid solid none;
    border-width: 1px;
    border-color: $border_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: $primary_color;
}


/*********
 * Menus *
 *********/
.menubar {
  -GtkWidget-window-dragging: true;
  padding: 0;
  // box-shadow: inset 0 -1px $border_color;
  background-color: $titlebar_bg_color;
  & > .menuitem {
    transition: $shorter_transition;
    padding: 4px 8px;
    color: $titlebar_secondary_fg_color;
    &:hover { //Seems like it :hover even with keyboard focus
      transition: none;
      background-color: gtkalpha(currentColor, $lower_opacity / 2);
      color: $titlebar_fg_color;
    }
    &:insensitive {
      color: $titlebar_disabled_secondary_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 $border_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: $disabled_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 $border_color; }
    &.bottom { border-top: 1px solid $border_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: $lighter_bg_color;
  box-shadow:  $shadow_2; // TODO: this should really have a highlight
  &:backdrop { box-shadow: $shadow_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: $primary_color;
      color: $inverse_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 $border_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 $border_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 $border_color; // border
    }
    &.bottom {
      box-shadow: inset 0 1px $border_color;
    }
    &.right {
      box-shadow: inset 1px 0 $border_color;
    }
    &.left {
      box-shadow: inset -1px 0 $border_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 $fill_color; }
      &:active, &.active-page { box-shadow: inset 0 -2px $primary_color; }
    }
    &.bottom {
      &:hover, &.prelight-page { box-shadow: inset 0 2px $fill_color; }
      &:active, &.active-page { box-shadow: inset 0 2px $primary_color; }
    }
    &.left {
      &:hover, &.prelight-page { box-shadow: inset -2px 0 $fill_color; }
      &:active, &.active-page { box-shadow: inset -2px 0 $primary_color; }
    }
    &.right {
      &:hover, &.prelight-page { box-shadow: inset 2px 0 $fill_color; }
      &:active, &.active-page { box-shadow: inset 2px 0 $primary_color; }
    }
    @each $_tab, $_border in (top, bottom),
                             (bottom, top),
                             (left, right),
                             (right, left) {
      &.reorderable-page.#{$_tab} {
        border-color: transparent;
        &:hover, &.prelight-page {
          border-color: $border_color;
          border-#{$_border}-width: 0;
          border-#{$_border}-color: transparent;
          background-color: $alt_base_color;
        }
        &:active, &.active-page {
          border-color: $border_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, $secondary_opacity); }
    &:insensitive {
      color: $disabled_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 rgba($base_color, $lower_opacity);
        // background-clip: padding-box;
      }

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

    }

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

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

  // slider coloring
  .slider {
    background-color: $hint_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: 20px;
  -GtkSwitch-slider-height: 20px;

  outline-offset: -4px;
  outline-radius: 100px;
  font-size: 0;
  &.trough {
    // similar to the .scale
    border: 8px solid transparent;
    border-radius: 100px;
    background-color: $fill_color;
    // background-clip: padding-box;
    &:insensitive {
      color: gtkalpha(currentColor, $disabled_opacity);
    }
    &:active {
      background-color: rgba($accent_color, 0.5);
      &:insensitive {
        background-color: rgba($accent_color, 0.3);
      }
    }
  }
  &.slider {
    padding: 5px 4px;
    border-radius: 100px;
    @include entry(normal);
    &:hover { @include entry(focus); }
    &:active { background-color: $accent_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'),
                  (':hover', '-unchecked-hover'),
                  (':active', '-unchecked-active'),
                  (':insensitive', '-unchecked-disabled'),
                  (':inconsistent', '-mixed'),
                  (':inconsistent:hover', '-mixed-hover'),
                  (':inconsistent:active', '-mixed-active'),
                  (':inconsistent:insensitive', '-mixed-disabled'),
                  (':checked', '-checked'),
                  (':checked:hover', '-checked-hover'),
                  (':checked:active', '-checked-active'),
                  (':checked:insensitive', '-checked-disabled') {
    .#{$w}#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/#{$a}#{$as}#{$asset_suffix}.png"),
                                    url("assets/#{$a}#{$as}#{$asset_suffix}@2.png"));
      &.button.flat {}
    }
  }

  //menu
  @each $s,$as in ('', '-unchecked'),
                  (':insensitive', '-unchecked-disabled'),
                  (':inconsistent', '-mixed'),
                  (':inconsistent:insensitive', '-mixed-disabled'),
                  (':checked', '-checked'),
                  (':checked:insensitive', '-checked-disabled') {
    .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/menu-#{$a}#{$as}#{$asset_suffix}.png"),
                                    url("assets/menu-#{$a}#{$as}#{$asset_suffix}@2.png"));
    }
  }
}

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

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

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: $disabled_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: 60%; }
  }

  &.slider {
    // @include entry(normal);
    // border-radius: 50%;
    // background-color: $accent_color;
    @each $s,$as in ('', ''),
                    (':insensitive', '-disabled') {
      &.slider#{$s} {
        $_url: 'assets/scale-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;
        background-size: 70%;
        box-shadow: none;
      }
    }
    &:hover { background-size: 80%; }
    &:active { background-size: 90%; }
    &: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: 11px 12px;
    background-color: $fill_color;
    &.highlight {
      background-color: $accent_color;
      &:insensitive { background-color: $fill_color; }
    }
    &:insensitive { color: $disabled_fg_color; }
    &.vertical { margin: 12px 11px; }
    //OSD troughs
    .osd & {
    }
  }
  // marks color
  &.separator {
    color: $fill_color;
  }
  // scales on selected list rows
  .list-row:selected & {
  }
}

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

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

      @each $s,$as in ('', ''),
                      (':insensitive', '-disabled') {
        &.slider#{$s} {
          $_url: 'assets/scale-#{$dn}-#{$we}-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;
        }
      }
    }
  }
}

%marks-before-horz {
  .trough { margin: 16px 12px 11px; }
}
%marks-after-horz {
 .trough { margin: 11px 12px 16px; }
}
%marks-before-vert {
  .trough { margin: 12px 11px 12px 16px; }
}
%marks-after-vert {
  .trough { margin: 12px 16px 12px 11px; }
}

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

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

// moving bit
.progressbar {
  border-radius: 0;
  background-color: $primary_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: $primary_color;
    border-style: none;
    border-radius: 0;
  }
}


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

.level-bar {
  box-shadow: $shadow_1; // needs to be set here to avoid clipping
  color: $disabled_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: $primary_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: $fill_color;
    }
  }
}


/**********
 * Frames *
 **********/
.frame {
  border: 1px solid $border_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: $border_color;

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

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

.list {
  border-color: $border_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: $inverse_disabled_secondary_fg_color; }
    &.flat {
      color: $inverse_secondary_fg_color;
      &:hover, &:active { color: $inverse_fg_color; }
      &:insensitive { color: $inverse_disabled_secondary_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, $secondary_opacity); }
  &:selected { color: $inverse_fg_color; }
}

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

  &:insensitive { color: $disabled_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: $lighter_bg_color; }
  .titlebar {
    border-style: none;
    box-shadow: inset 0 1px $highlight_color;
    background-color: $lighter_bg_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 $border_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 $border_color;
  }
}

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

.sidebar {
  border: none;
  background-color: $lighter_bg_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 $primary_color;
  }

  .sidebar-new-bookmark-row {
    color: $accent_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;
  }
}


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

GtkPlacesView {
  .server-list-button > GtkImage { -gtk-icon-transform: rotate(0turn); }

  .server-list-button:checked > GtkImage { -gtk-icon-transform: rotate(-0.5turn); }
}


/*********
 * 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: $border_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: $border_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: $inverse_fg_color;
  .button {
    // @extend .list-row:selected.button;
    &:insensitive { color: $inverse_disabled_secondary_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: rgba($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: $shadow_1;

  // we need to re-set the shadow here since it get axed by the previous bit
  &:selected { }
  &:insensitive {
    opacity: $disabled_opacity;
    box-shadow: none;
  }

  // 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: $shadow_2; }

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

  // indicator and keynav outline colors
  &.color-dark {
    color: $light_fg_color;
  }
  &.color-light {
    color: $dark_fg_color;
  }

  // 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: $light_fg_color;
  }
}


/********
 * 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: $shadow_4;

  // FIXME rationalize window-frame shadows

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

  &:backdrop {
    box-shadow: $shadow_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: $shadow_2;
    }
    &.tooltip {
      border-radius: 2px;
      box-shadow: $shadow_2;
    }
    &.message-dialog {
      border-radius: 2px;
      box-shadow: $shadow_4;
      &:backdrop { box-shadow: $shadow_2; }
    }
  }
  &.solid-csd {
    border-radius: 0;
    margin: 0;
    background-color: $titlebar_bg_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: $primary_color;
  color: $inverse_fg_color;
  &:insensitive { color: $inverse_disabled_fg_color; }
}

.monospace {
  font: Monospace;
}

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

//touch selection handlebars for the Popover.osd above
.entry.cursor-handle,
.cursor-handle {
  background-color: $accent_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/scale-horz-marks-before-slider#{$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: $shadow_2;
  &:backdrop { box-shadow: $shadow_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);
  }
}
