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

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

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

  -GtkScrolledWindow-scrollbar-spacing: 0;

  -GtkToolItemGroup-expander-size: 11;

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

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

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

  outline-style: solid;
  outline-width: 2px;
  outline-color: transparent;
  outline-offset: -4px;
  -gtk-outline-radius: $material_radius;

  -gtk-secondary-caret-color: $primary_color;
}

notebook:focus tab,
*:focus { outline-color: $fill_color; }


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

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

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

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

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

  &:disabled {
    background-color: $bg_color;
    color: $disabled_fg_color;
  }

  &:selected {
    background-color: $primary_color;
    color: $inverse_fg_color;
  }
}

.view {
  @extend row.activatable;

  background-color: $base_color;
  color: $fg_color;

  &:disabled { color: $disabled_fg_color; }

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

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

textview {
  // FIXME: we need to override background-color to ensure text rendering
  text { background-color: $base_color; }

  border {
    background-color: $alt_base_color;
    color: $hint_fg_color; // FIXME: not working
  }
}

// iconview { @extend .view; }

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

flowbox {
  rubberband { @extend rubberband; }

  flowboxchild {
    padding: 4px;
    border-radius: $material_radius;

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

.content-view .tile {
  // margin: 2px;
  // padding: 0;
  // border-radius: 0;
  // background-color: black;

  &:selected {
    background-color: transparent;
    color: inherit;
  }
}

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

  &.separator {
    @extend .dim-label;

    color: $fg_color;
  }

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

  selection {
    background-color: $primary_color;
    color: $inverse_fg_color;
  }

  &:disabled {
    color: $disabled_fg_color;

    selection { @extend %selected_items:disabled; }

    tab &,
    button & { color: inherit; }
  }
}

.dim-label { opacity: 0.6; }

assistant {
  .sidebar {
    padding: 4px 0;
    // background-color: $base_color;
    // border-top: 1px solid $border_color;
  }

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

  .sidebar label {
    min-height: $medium_size;
    padding: 0 12px;
    color: $hint_fg_color;
    font-weight: 500;

    &.highlight { color: $fg_color; }
  }
}

// %osd, .osd { opacity: 0.9; }


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

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

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

    &:disabled { opacity: 0.5; }
  }
}


/****************
 * Text Entries *
 ****************/
%entry,
entry {
  %entry_basic, & {
    min-height: $medium_size;
    padding: 0 8px;
    border-radius: $material_radius;

    @include entry(normal);

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

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

    &.flat {
      border-radius: 0;

      @include entry(flat-normal);

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

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

    image { // icons inside the entry
      // @extend %simple_flat_button;

      // min-height: $small_size;
      // min-width: $small_size;
      // border-radius: $circular_radius;
      // -gtk-outline-radius: $circular_radius;
      color: $secondary_fg_color;

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

      &:disabled { color: $hint_fg_color; }

      &.left {
        margin-left: ($medium_size - 16px) / 2 - 8px;
        margin-right: 6px;
      }

      &.right {
        margin-left: 6px;
        margin-right: ($medium_size - 16px) / 2 - 8px;
      }
    }

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

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

    selection { @extend %selected_items; }

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

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

        &.flat {
          @include entry(flat-normal, $e_color);

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

          &:disabled { @include entry(flat-disabled, $e_color); }
        }

        image {
          color: $inverse_secondary_fg_color;

          &:hover, &:active { color: $inverse_fg_color; }

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

    &:drop(active) {
      // box-shadow: inset 0 0 0 2px $secondary_color;
    }

    .osd & {
    }
  }

  progress {
    margin: 2px (2px - 8px);
    border-bottom: 2px solid $primary_color;
    background-color: transparent;
  }

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

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

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

%treeview_entry,
treeview entry {
  &.flat, & {
    min-height: 0;
    padding: 2px;
    border-radius: 0;
    background-color: $base_color;

    &, &:focus {
      border-image: none;
      box-shadow: none;
    }
  }
}

.entry-tag {
  margin: 2px;
  border-radius: $circular_radius;
  box-shadow: none;
  background-color: $divider_color;
  color: $fg_color;

  &:hover { background-image: image($divider_color); }

  // side margins: compensate the entry padding with a negative margin
  // then the negative margin itself
  :dir(ltr) & {
    margin-left: 4px;
    margin-right: 0;
    padding-left: 12px;
    padding-right: 8px;
  }

  :dir(rtl) & {
    margin-left: 0;
    margin-right: 4px;
    padding-left: 8px;
    padding-right: 12px;
  }

  // seems any sizing doesn't work
  &.button {
    box-shadow: none;
    background-color: transparent;

    &:not(:hover):not(:active) { color: $secondary_fg_color; }
  }
}


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

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

%button,
button {
  @at-root %button_basic, & {
    min-height: 24px;
    min-width: 16px;
    padding: ($medium_size - 24px) / 2 ($medium_size - 16px) / 2;
    border-radius: $material_radius;
    font-weight: 500;

    @include button(normal);

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

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

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

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

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

    @at-root %flat_button, &.flat {
      @at-root %simple_flat_button, & {
        @include button(flat-normal);

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

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

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

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

      &:checked:disabled { @include button(flat-checked-disabled); }
    }

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

    &.image-button {
      min-width: 24px;
      padding: ($medium_size - 24px) / 2;

      @extend %circular_button;
    }

    &.text-button.image-button {
      border-radius: $material_radius;
      -gtk-outline-radius: $material_radius;

      label {
        &:first-child { margin-left: 16px - ($medium_size - 24px) / 2; }

        &:last-child { margin-right: 16px - ($medium_size - 24px) / 2; }
      }

      image:not(:only-child) { margin: 0 (24px - 16px) / 2; }
    }

    .linked > & { @extend %linked; }

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

    .linked > &.flat,
    .linked.vertical > &.flat {
      border-radius: $material_radius;

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

      &.text-button.image-button {
        border-radius: $material_radius;
        -gtk-outline-radius: $material_radius;
      }
    }

    &:drop(active) {
      // box-shadow: inset 0 0 0 2px $secondary_color;
    }
  }

  @at-root %button_selected, row:selected & {
    &:disabled {
      background-color: $inverse_divider_color;
      color: $inverse_disabled_secondary_fg_color;
    }

    &.flat {
      color: $inverse_secondary_fg_color;

      &:hover, &:active { color: $inverse_fg_color; }

      &:disabled { color: $inverse_disabled_secondary_fg_color; }

      &:checked {
        background-color: $inverse_track_color;
        color: $inverse_fg_color;
      }

      &:checked:disabled {
        background-color: $inverse_divider_color;
        color: $inverse_disabled_fg_color;
      }
    }
  }

  // big standalone buttons like in Documents pager
  &.osd {
    padding: ($large_size - 24px) / 2 ($large_size - 16px) / 2;

    &.image-button { padding: ($large_size - 24px) / 2; }

    &:disabled { opacity: 0; }
  }

  // overlay / OSD style
  @at-root %osd_button,
  .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;

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

      &:checked { background-color: mix($inverse_fg_color, $b_color, percentage(0.3)); }

      &.flat {
        background-color: transparent;
        color: $b_color;

        &:disabled { @include button(flat-disabled, $b_color); }

        &:checked { background-color: rgba($b_color, 0.3); }
      }

      .osd & {
      }
    }
  }

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

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

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

    &.image-button {
      // we want image buttons to have a 1:1 aspect ratio, so compensation
      // of the padding added to the GtkImage is needed
      padding-left: ($medium_size - 16px) / 2 - 6px;
      padding-right: ($medium_size - 16px) / 2 - 6px;
    }

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

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

  // hide separators
  &.font,
  &.file { separator { @extend %hide_separators; }}

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

  // inline-toolbar buttons
  .inline-toolbar & {
    // @extend %button_basic.flat;

    &:not(.text-button) { @extend %circular_button; }
  }

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

  @at-root %circular_button,
  &.close,
  &.circular { // The Bloody Circul Button
    border-radius: $circular_radius;
    -gtk-outline-radius: $circular_radius;

    // label { padding: 0; }
  }

  @at-root %small_button {
    min-height: $small_size;
    min-width: $small_size;
    padding: 0;
    border-radius: $circular_radius;
    -gtk-outline-radius: $circular_radius;
  }
}

%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 toolbutton > button { // redefining the button look is
                                      // needed since those are flat...
}

// More inline toolbar buttons
toolbar.inline-toolbar toolbutton {
  // > 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 {
  border-radius: 0;
  -gtk-outline-radius: $material_radius;
}

%linked {
  @extend %linked_middle;

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

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

  &:only-child {
    border-radius: $material_radius;
  }
}

%linked_vertical_middle {
  border-radius: 0;
  -gtk-outline-radius: $material_radius;
}

%linked_vertical {
  @extend %linked_vertical_middle;

  &:first-child {
    border-top-left-radius: $material_radius;
    border-top-right-radius: $material_radius;
  }

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

  &:only-child {
    border-radius: $material_radius;
  }
}

/* menu buttons */
modelbutton.flat,
.menuitem.button.flat {
  min-height: $menuitem_size;
  padding: 0 8px;
  border-radius: $material_radius;
  color: inherit;

  @extend %simple_flat_button;

  &:selected { @extend %selected_items; }
}

modelbutton.flat arrow {
  background: none;

  &:hover { background: none; }

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

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

button.color {
  min-height: $small_size;
  min-width: $small_size;
  padding: $container_padding;

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


/*********
 * Links *
 *********/
*:link {
  &, &:hover, &:active { color: $link_color; }

  &:visited {
    &, &:hover, &:active { color: $visited_link_color; }
  }

  @at-root %link_selected,
  &:selected,
  *:selected & { color: $inverse_fg_color; }
}

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

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

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

    padding: 0;

    %spinbutton_entry,
    entry {
      min-width: $large_size - 8px * 2;
      // reset all the other props since the spinbutton node is styled here
      margin: 0;
      border-image: none;
      border-radius: 0;
      box-shadow: none;
      background-color: transparent;
      //
      // This will help to simplify spinbutton's code, but unfortunatelly
      // doesn't work properly in :dir(rtl). It needs z-index property.
      //
      // min-width: $large_size - 8px;
      //
      // $spinbuttons_width: $small_size * 2 + $container_padding * 3;
      //
      // &:dir(ltr) {
      //   margin-right: -$spinbuttons_width;
      //   padding-right: $spinbuttons_width;
      // }
      //
      // &:dir(rtl) {
      //   margin-left: -$spinbuttons_width;
      //   padding-left: $spinbuttons_width;
      // }
    }

    button {
      // margin: $container_padding;
      border: solid $container_padding transparent;

      @extend %simple_flat_button;

      @extend %small_button;

      &.up:dir(ltr),
      &.down:dir(rtl) { margin-left: -$container_padding / 2; }

      &.up:dir(rtl),
      &.down:dir(ltr) { margin-right: -$container_padding / 2; }
    }
  }

  // OSD horizontal
  .osd &:not(.vertical) {
    button {
    }
  }

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

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

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

    entry {
      min-height: $medium_size;
      min-width: $large_size;
      padding: 0;
    }

    button {
      min-height: $medium_size;
      min-width: $large_size;
      padding: 0;

      @extend %simple_flat_button;

      &.up { border-radius: $material_radius $material_radius 0 0; }

      &.down { border-radius: 0 0 $material_radius $material_radius; }
    }
  }

  // OSD vertical
  .osd &.vertical button:first-child {
  }

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

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


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

  decoration,
  button.combo:checked { transition: none; } // workaround for menuitem selection

  button.combo cellview {
    &:dir(ltr) { margin-left: 8px - ($medium_size - 16px) / 2; }
    &:dir(rtl) { margin-right: 8px - ($medium_size - 16px) / 2; }
  }

  #gtk-combobox-popup-menu {
    padding: 2px 0;

    menuitem {
      min-height: $medium_size - 2px * 2;
      padding: 0 8px;
    }

    // overflow arrows
    > arrow {
      &.top { margin-top: -2px; }

      &.bottom {
        margin-top: 2px * 2;
        margin-bottom: -2px * 3;
      }
    }
  }

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

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

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

// the combo is a composite widget so the way we do button linking doesn't
// work, special case needed. See
// https://bugzilla.gnome.org/show_bug.cgi?id=733979

.linked:not(.vertical) > combobox {
  > box > button.combo { @extend %linked_middle; }

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

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

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

.linked.vertical > combobox {
  > box > button.combo { @extend %linked_vertical_middle; }

  &:first-child > box > button.combo { @extend %linked_vertical:first-child; }

  &:last-child > box > button.combo { @extend %linked_vertical:last-child; }

  &:only-child > box > button.combo { @extend %linked_vertical:only-child; }
}

%combo_flat {
  border-radius: 0;
  background-image: none;
  font-weight: inherit;

  @include entry(flat-normal);

  &:hover { box-shadow: inset 0 -2px $hint_fg_color; }

  &:checked {
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $primary_color 100%,
                                  transparent 0%)
                                  0 0 2 / 0 0 2px;
  }

  &:disabled {
    box-shadow: inset 0 -1px $divider_color;
    color: $disabled_fg_color;
  }
}


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

  button { @extend %button_basic.flat; }

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

  // stand-alone OSD toolbars
  &.osd {
    transition: $shadow_transition;
    padding: $container_padding;
    border-radius: $material_radius;
    box-shadow: $shadow_2, inset 0 1px $highlight_color;
    background-color: $popup_bg_color;

    &:backdrop { box-shadow: $shadow_1, inset 0 1px $highlight_color; }

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

  // toolbar separators
  &.horizontal > separator { margin: 2px; }
  &.vertical > separator { margin: 2px; }

  &:not(.inline-toolbar):not(.osd) {
    scale,
    entry,
    spinbutton,
    button { margin: 2px; }

    .linked entry,
    .linked spinbutton,
    .linked button {
      &:not(:first-child) { margin-left: 0; }
      &:not(:last-child) { margin-right: 0; }
    }

    spinbutton {
      entry,
      button { margin: 0; }
    }

    switch { margin: 2px + $container_padding 2px; }
  }
}

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

searchbar > revealer > box,
.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;
}

searchbar > revealer > box {
  // workaround: undo the GtkContainer:border-width and use CSS padding instead
  margin: -6px;
  padding: $container_padding;
}


/***************
 * Header bars *
 ***************/
%titlebar,
headerbar {
  transition: background-color $shorter_duration $deceleration_curve, color $longer_duration $deceleration_curve;
  min-height: $large_size;
  padding: 0 $container_padding;
  box-shadow: $shadow_1, inset 0 1px $titlebar_highlight_color;
  background-color: $titlebar_bg_color;
  color: $titlebar_fg_color;

  &:disabled :not(button) > label { color: $titlebar_disabled_fg_color; }

  &:backdrop {
    color: $titlebar_secondary_fg_color;

    &:disabled :not(button) > label { color: $titlebar_disabled_secondary_fg_color; }
  }

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

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

    @extend .dim-label;
  }

  .linked:not(.vertical) > entry:not(.flat) { border-radius: $material_radius; }

  button:not(.suggested-action):not(.destructive-action) {
    @extend %button_basic.flat;

    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $titlebar_indicator_color 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    color: $titlebar_secondary_fg_color;

    &:hover, &:active { color: $titlebar_fg_color; }

    &:disabled { color: $titlebar_disabled_secondary_fg_color; }

    &:checked {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    $titlebar_indicator_color 100%,
                                    transparent 0%)
                                    0 0 2 / 0 0 2px;
      color: $titlebar_fg_color;

      &:disabled { color: $titlebar_disabled_fg_color; }

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

    &:backdrop {
      color: $titlebar_hint_fg_color;

      &:hover, &:active { color: $titlebar_secondary_fg_color; }

      &:disabled { color: $titlebar_disabled_secondary_fg_color; }

      &:checked {
        color: $titlebar_secondary_fg_color;

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

  button.suggested-action, button.destructive-action {
    &:disabled {
      background-color: $titlebar_divider_color;
      color: $titlebar_disabled_fg_color;
    }
  }

  &.selection-mode {
    // 0.00001s was a workaround for https://gitlab.gnome.org/GNOME/gtk/issues/698
    // but let's keep it for backwards compatibility.
    transition: background-color 0.00001s $longer_duration, color $longer_duration $deceleration_curve;
    animation: header_ripple_effect $longer_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:not(.suggested-action):not(.destructive-action) {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    currentColor 0%,
                                    transparent 0%)
                                    0 0 0 / 0 0 0px;
      color: $inverse_fg_color;

      &:disabled { color: $inverse_disabled_fg_color; }

      &:checked {
        border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                      currentColor 100%,
                                      transparent 0%)
                                      0 0 2 / 0 0 2px;
        color: $inverse_fg_color;

        &:disabled { color: $inverse_disabled_fg_color; }
      }

      &:backdrop {
        color: $inverse_secondary_fg_color;

        &:disabled { color: $inverse_disabled_secondary_fg_color; }

        &:checked {
          color: $inverse_secondary_fg_color;

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

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

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

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

  // squared corners when the window is maximized, tiled, or fullscreen
  .tiled &,
  .tiled-top &,
  .tiled-right &,
  .tiled-bottom &,
  .tiled-left &,
  .maximized &,
  .fullscreen & {
    border-radius: 0;
    box-shadow: $shadow_1;
  }

  &.default-decoration {
    min-height: $small_size;
    padding: $container_padding;
    box-shadow: inset 0 1px $titlebar_highlight_color;

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

    button.titlebutton {
      min-height: $small_size;
      min-width: $small_size;
      margin: 0;
      padding: 0;
    }

    // workaround for non-animatable buttons
    .background:not(.csd) & button.titlebutton:active { background-size: 1000% 1000%; }
  }

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

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

  switch {
    margin-top: ($large_size - 24px) / 2;
    margin-bottom: ($large_size - 24px) / 2;
  }

  // reset button margins of the spinbutton
  spinbutton button {
    margin-top: 0;
    margin-bottom: 0;
  }

  // FIXME: This is a hacky workaround.
  .entry-tag {
    margin-top: 5px;
    margin-bottom: 5px;
  }
}

.background .titlebar {
  border-top-left-radius: $material_radius;
  border-top-right-radius: $material_radius;
}

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

headerbar { // headerbar border rounding
  window separator:first-child + &, // tackles the paned container case
  window &:first-child { border-top-left-radius: $material_radius; }

  window &:last-child { border-top-right-radius: $material_radius; }

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

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

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

  > separator {
    background-color: $titlebar_bg_color;
    background-image: image($border_color);
  }

  @extend %titlebar;
}


/************
 * Pathbars *
 ************/
%pathbar_button,
.path-bar button {
  padding-left: ($medium_size - 24px) / 2;
  padding-right: ($medium_size - 24px) / 2;

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

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

  &.slider-button {
    padding-left: (24px - 16px) / 2;
    padding-right: (24px - 16px) / 2;
  }

  :not(headerbar) & {
    @extend %flat_button;

    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $primary_color 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    border-radius: $material_radius;

    &:checked {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    $primary_color 100%,
                                    transparent 0%)
                                    0 0 2 / 0 0 2px;

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


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

  border-left-color: $track_color; // this is actually the tree lines color,
  border-top-color: $border_color; // while this is the grid lines color, better then nothing

  &:selected { border-left-color: $inverse_track_color; }

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

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

  &.separator {
    min-height: 1px + 2px * 2;
    color: $border_color;
  }

  &:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $secondary_color;

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

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

  &.expander {
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    -gtk-icon-transform: rotate(-90deg);

    &:dir(rtl) { -gtk-icon-transform: rotate(90deg); }

    &:checked { -gtk-icon-transform: unset; }

    color: $secondary_fg_color;

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

    &:disabled { color: $disabled_secondary_fg_color; }

    &:selected {
      color: $inverse_secondary_fg_color;

      &:hover, &:active { color: $inverse_fg_color; }

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

  &.progressbar { // progress bar in treeviews
    border-bottom: $bar_size solid $primary_color;
    box-shadow: none;
    background-color: transparent;

    &:selected { border-bottom-color: $inverse_fg_color; }
  }

  &.trough { // progress bar trough in treeviews
    border-bottom: $bar_size solid rgba($primary_color, 0.3);
    box-shadow: none;
    background-color: transparent;

    &:selected { border-bottom-color: $inverse_track_color; }
  }

  header {
    button {
      @extend row.activatable;

      padding: 2px 6px;
      border-style: none solid solid none;
      border-width: 1px;
      border-color: $border_color;
      border-radius: 0;
      background-clip: border-box;

      &, &:hover, &:active { box-shadow: none; }

      &, &:disabled { background-color: $base_color; }

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

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    padding: 2px 6px;
    border-style: none solid solid;
    border-width: 1px;
    border-color: $border_color;
    border-radius: 0;
    box-shadow: none;
    background-color: $base_color;
    background-clip: border-box;
    color: $primary_color;
  }

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


/*********
 * Menus *
 *********/
menubar,
.menubar {
  -GtkWidget-window-dragging: true;
  padding: 0;
  // box-shadow: inset 0 -1px $border_color;
  background-color: $titlebar_bg_color;

  > menuitem {
    transition: $shorter_transition;
    min-height: 20px;
    padding: 4px 8px;
    color: $titlebar_secondary_fg_color;

    &:hover { // Seems like it :hover even with keyboard focus
      transition: none;
      background-color: $titlebar_divider_color;
      color: $titlebar_fg_color;
    }

    &:disabled { color: $titlebar_disabled_secondary_fg_color; }

    label:disabled { color: inherit; } // to inherit the above color
  }
}

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

menu,
.menu,
.context-menu {
  margin: 4px 0; // See https://bugzilla.gnome.org/show_bug.cgi?id=591258
  padding: 4px 0;
  box-shadow: inset 0 1px $highlight_color;
  background-color: $popup_bg_color;
  border: 1px solid $border_color; // adds borders in a non composited env

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

  menuitem {
    transition: background-color $shorter_duration $deceleration_curve;
    min-height: 20px;
    min-width: 40px;
    padding: 4px 8px;
    font: initial;
    text-shadow: none;

    &:hover {
      transition: none;
      background-color: $divider_color;
    }

    &:disabled { color: $disabled_fg_color; }

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

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

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

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

  // overflow arrows
  > arrow {
    min-height: 16px;
    min-width: 16px;
    padding: 4px;
    background-color: $popup_bg_color;
    color: $secondary_fg_color;

    &.top {
      margin-top: -4px;
      border-bottom: 1px solid $border_color;
      border-radius: $material_radius $material_radius 0 0;
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
    }

    &.bottom {
      margin-top: 4px * 2;
      margin-bottom: -4px * 3;
      border-top: 1px solid $border_color;
      border-radius: 0 0 $material_radius $material_radius;
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    }

    &:hover {
      background-image: image($divider_color);
      color: $fg_color;
    }

    &:disabled {
      border-color: transparent;
      background-color: transparent;
      color: transparent;
      // color: $disabled_secondary_fg_color;
    }
  }

  separator { margin: 4px 0; }
}

menuitem {
  accelerator { color: $secondary_fg_color; }
}

// FIXME: THIS IS A REALLY UGLY WORKAROUND!
// Electron/Atom render all translucent colors in opaque colors.
// It's a very critical issue for this theme and should be fixed by upstream...
.popup:not(.csd) menu {
  menuitem {
    color: $opaque_fg_color;

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

    &:disabled { color: $opaque_disabled_fg_color; } // separator/border also use this color.
  }

  // FIXME: not working this
  accelerator { color: $opaque_secondary_fg_color; }
}


/************
 * Popovers *
 ************/
popover.background {
  transition: $shadow_transition;
  padding: 2px;
  box-shadow: $shadow_2; // TODO: this should really have a highlight
  background-color: $popup_bg_color;

  &:backdrop { box-shadow: $shadow_1; }

  &, .csd & {
    border-style: solid;
    border-width: 1px;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.3);
    border-radius: $material_radius + 1px;
  }

  > stack { margin: -4px; } // remove extra padding from menu style popovers

  > toolbar { margin: -2px; }

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

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

  // entry { @extend %entry.flat; }

  // button.combo { @extend %combo_flat; }

  // button:not(.suggested-action):not(.destructive-action) { @extend %button_basic.flat; }

  &.menu button,
  button.model {
    @extend %simple_flat_button;

    min-height: 32px;
    padding: 0 8px;
    border-radius: $material_radius;

    &:checked { @extend %selected_items; }
  }

  separator { margin: 4px 0; }

  list separator { margin: 0; }
}

/*************
 * Notebooks *
 *************/
notebook {
  > header {
    border-width: 1px;
    border-color: $border_color;
    background-color: $bg_color;
    background-clip: border-box;

    &.top {
      border-bottom-style: solid;
      > tabs {
        margin-bottom: -1px;
        > tab {

          &:hover { box-shadow: inset 0 -2px $track_color; }

          &:checked { box-shadow: inset 0 -2px $primary_color; }
        }
      }
    }

    &.bottom {
      border-top-style: solid;
      > tabs {
        margin-top: -1px;
        > tab {

          &:hover { box-shadow: inset 0 2px $track_color; }

          &:checked { box-shadow: inset 0 2px $primary_color; }
        }
      }
    }

    &.left {
      border-right-style: solid;
      > tabs {
        margin-right: -1px;
        > tab {

          &:hover { box-shadow: inset -2px 0 $track_color; }

          &:checked { box-shadow: inset -2px 0 $primary_color; }
        }
      }
    }

    &.right {
      border-left-style: solid;
      > tabs {
        margin-left: -1px;
        > tab {

          &:hover { box-shadow: inset 2px 0 $track_color; }

          &:checked { box-shadow: inset 2px 0 $primary_color; }
        }
      }
    }

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

      border-top-style: none;
    }

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

      border-bottom-style: none;
    }

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

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

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

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

      border-left-style: none;
    }

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

      border-right-style: none;
    }

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

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

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

    > tabs > arrow {
      @extend %simple_flat_button;

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

    tab {
      transition: $longer_transition,
                  background-size 0,
                  background-image 0;
      min-height: $small_size;
      min-width: $small_size;
      padding: $container_padding 12px;

      outline-offset: -6px;

      border-width: 1px;         // for reorderable tabs
      border-color: transparent; //

      background-image: radial-gradient(circle farthest-corner at center,
                                        $primary_color 10%,
                                        transparent 0%);
      background-repeat: no-repeat;
      background-position: center;
      background-size: 0% 0%;

      color: $secondary_fg_color;
      font-weight: 500;

      &:hover {
        color: $fg_color;

        &.reorderable-page {
          border-color: $border_color;
          background-color: $alt_base_color;
        }
      }

      &:disabled { color: $disabled_secondary_fg_color; }

      &:checked {
        transition: $longer_transition,
                    background-size $longer_duration $deceleration_curve,
                    background-image $longer_duration + $ripple_duration $deceleration_curve;
        background-image: radial-gradient(circle farthest-corner at center,
                                          transparent 10%,
                                          transparent 0%);
        background-size: 1000% 1000%;
        color: $fg_color;

        &:disabled { color: $disabled_fg_color; }

        &.reorderable-page {
          border-color: $border_color;
          background-color: $base_color;
        }
      }

      // colors the button like the label, overridden otherwise
      button.flat {
        @extend %small_button;

        &:last-child {
          margin-left: $container_padding;
          margin-right: $container_padding - 12px;
        }

        &:first-child {
          margin-left: $container_padding - 12px;
          margin-right: $container_padding;
        }
      }
    }

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

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

        tab {
          &.reorderable-page {
            margin: 0 -1px;
            border-style: none solid;
          }
        }
      }
    }

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

        &:not(:only-child) {
          &:first-child { margin-top: 0; }
          &:last-child { margin-bottom: 0; }
        }

        tab {
          &.reorderable-page {
            margin: -1px 0;
            border-style: solid none;
          }
        }
      }
    }
  }

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

    entry:not(.search),
    spinbutton:not(.vertical) { @extend %entry.flat; }

    spinbutton:not(.vertical) entry { &, &:focus, &:disabled { @extend %spinbutton_entry; }}

    treeview entry:not(.search),
    treeview spinbutton:not(.vertical) { @extend %treeview_entry; }

    button.combo { @extend %combo_flat; }
  }
}


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

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

  transition: $longer_transition;
  background-color: $base_color;
  background-clip: $extra_background_clip;

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

  // slider
  slider {
    transition: $shorter_transition, margin 0, border-width 0;
    min-width: 8px;
    min-height: 8px;
    border: 4px solid transparent;
    border-radius: $circular_radius;
    background-clip: padding-box;
    background-color: $hint_fg_color;

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

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

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

  &.fine-tune {
    slider {
      transition: $shorter_transition, margin 0, border-width 0, min-width 0, min-height 0;
      min-width: 4px;
      min-height: 4px;
    }

    &.horizontal slider { margin: 2px 0; }

    &.vertical slider { margin: 0 2px; }
  }

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

      slider {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid rgba($base_color, 0.3);
      }

      button {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid rgba($base_color, 0.3);
        border-radius: $circular_radius;
        background-color: $hint_fg_color;
        background-clip: padding-box;
        -gtk-icon-source: none;

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

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

        button { min-width: 8px; }
      }

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

        button { min-height: 8px; }
      }
    }

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

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

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

  // button styling
  button {
    @extend %simple_flat_button;

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

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

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

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

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


/**********
 * Switch *
 **********/
switch {
  transition: background-color 100ms $deceleration_curve, opacity $longer_duration $deceleration_curve;
  margin: $container_padding 0;
  padding: 0 2px;
  border: 5px solid transparent;
  border-radius: $circular_radius;
  background-color: $track_color;
  background-clip: padding-box;
  font-size: 0;

  &:checked { background-color: rgba($secondary_color, 0.5); }

  &:disabled { opacity: 0.5; }

  slider {
    transition: all 100ms $deceleration_curve, box-shadow $longer_duration $deceleration_curve;
    min-width: 20px;
    min-height: 20px;
    margin: -3px -2px;
    border-radius: $circular_radius;
    box-shadow: 0 0 0 10px transparent, $shadow_1;
    background-color: $popup_bg_color;
    color: $secondary_fg_color;
  }

  &:hover slider { box-shadow: 0 0 0 10px gtkalpha(currentColor, 0.16), $shadow_1; }

  &:focus slider { box-shadow: 0 0 0 10px gtkalpha(currentColor, 0.2), $shadow_1; }

  &:focus:hover slider { box-shadow: 0 0 0 10px gtkalpha(currentColor, 0.24), $shadow_1; }

  &:checked slider {
    background-color: $secondary_color;
    color: $secondary_color;
  }

  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

// selection-mode
.view.content-view.check:not(list),
.content-view .tile check:not(list) {
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 0;
  box-shadow: none;
  background-color: transparent;
  background-image: none;
  -gtk-icon-shadow: $shadow_1;

  &:hover, &:active { -gtk-icon-shadow: $shadow_2; }

  @each $s, $as in ('', '-unchecked'),
                   (':checked', '-checked') {
    &#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/selectionmode-checkbox#{$as}#{$asset_suffix}.png"),
                                    url("assets/selectionmode-checkbox#{$as}#{$asset_suffix}@2.png"));
    }
  }
}

checkbutton,
radiobutton {
  outline: none;
}

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

  label:not(:only-child) { margin: 0 4px; }
}

$check_radio_size: 40px;

check,
radio {
  min-height: 24px;
  min-width: 24px;
  margin: -($check_radio_size - 24px) / 2;
  padding: ($check_radio_size - 24px) / 2;

  @extend %simple_flat_button;

  @extend %circular_button;

  &:focus { box-shadow: inset 0 0 0 9999px gtkalpha(currentColor, 0.2); }

  &:hover { box-shadow: inset 0 0 0 9999px $semi_fill_color; }

  &:checked, &:indeterminate {
    color: $secondary_color;

    &:disabled { color: $disabled_secondary_color; }
  }

  // &:only-child { margin: -12px; }

  row:selected &:not(:checked):not(:indeterminate) {
    color: $inverse_secondary_fg_color;

    &:hover, &:active { color: $inverse_fg_color; }

    &:disabled { color: $inverse_disabled_secondary_fg_color; }
  }

  popover & {
    &, &:focus, &:hover, &:active, &:disabled {
      transition: none; // FIXME: this is a workaround for a popover check/radio long transition issue
      box-shadow: none;
      background-image: none;
    }

    &:not(:checked):not(:indeterminate):not(:disabled) { color: $secondary_fg_color; }

    &.left:dir(rtl) {
      margin-left: -12px;
      margin-right: -4px;
    }

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

  menu menuitem & {
    transition: none;
    margin: 0; // this is a workaround for a menu check/radio size allocation issue
    padding: 0;

    &:dir(ltr) { margin-right: 8px; }

    &:dir(rtl) { margin-left: 8px; }

    &:not(:checked):not(:indeterminate):not(:disabled) { color: $secondary_fg_color; }

    &, &:hover, &:disabled {
      box-shadow: none;
      // color: inherit;
    }
  }
}

%check,
check {
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/checkbox-unchecked-symbolic.svg"));

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/checkbox-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/checkbox-mixed-symbolic.svg")); }
}

%radio,
radio {
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-unchecked-symbolic.svg"));

  // &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-mixed-symbolic.svg")); }

  border-image-slice: $check_radio_size / 2px;
  border-image-width: $check_radio_size / 2;

  $radio_indicator: 10px / $check_radio_size / 2;

  & {
    border-image-source: -gtk-gradient(radial,
                                       center center, 0,
                                       center center, 0.001,
                                       to($secondary_color),
                                       to(transparent));
  }

  &:checked:not(:indeterminate) {
    border-image-source: -gtk-gradient(radial,
                                       center center, 0,
                                       center center, $radio_indicator,
                                       to($secondary_color),
                                       to(transparent));
  }

  &:checked:not(:indeterminate):disabled {
    border-image-source: -gtk-gradient(radial,
                                       center center, 0,
                                       center center, $radio_indicator,
                                       to($disabled_secondary_color),
                                       to(transparent));
  }
}

%small_check,
menu menuitem check {
  & {
    min-height: 16px;
    min-width: 16px;
    border-radius: $material_radius;
    -gtk-outline-radius: $material_radius;
    -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-unchecked-symbolic.svg"));
  }

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-mixed-symbolic.svg")); }
}

%small_radio,
menu menuitem radio {
  & {
    min-height: 16px;
    min-width: 16px;
    border-image: none;
    -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-unchecked-symbolic.svg"));
  }

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-mixed-symbolic.svg")); }
}

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

// radio:not(:checked):active { -gtk-icon-transform: scale(0); }

check:not(:checked):indeterminate:active,
radio:not(:checked):indeterminate:active { -gtk-icon-transform: scaleX(-1); } // instead of rotateY(180deg)

check:not(:checked),
radio:not(:checked) {
  & {
    transition: $longer_transition,
                background-size $ripple_duration $deceleration_curve,
                background-image $ripple_opacity_duration $deceleration_curve,
                -gtk-icon-transform 0;
  }

  &:active {
    transition: $longer_transition,
                background-size 0,
                background-image 0,
                -gtk-icon-transform 0;
  }

  menu menuitem & { transition: none; }
}

treeview.view check,
treeview.view radio {
  padding: 0;

  &:hover {
    box-shadow: inset 0 0 0 9999px gtkalpha($fg_color, 0.05);

    &:disabled { box-shadow: none; }

    &:selected { box-shadow: inset 0 0 0 9999px gtkalpha($inverse_fg_color, 0.05); }
  }

  & {
    color: $secondary_fg_color;

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

    &:disabled { color: $disabled_secondary_fg_color; }

    &:checked, &:indeterminate { color: $secondary_color; }

    &:checked:disabled, &:indeterminate:disabled { color: $disabled_secondary_color; }
  }

  &:selected {
    color: $inverse_secondary_fg_color;

    &:hover, &:active { color: $inverse_fg_color; }

    &:disabled { color: $inverse_disabled_secondary_fg_color; }

    &:checked, &:indeterminate { color: $secondary_color; }

    &:checked:disabled, &:indeterminate:disabled { color: $disabled_secondary_color; }
  }
}

treeview.view radio:checked {
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-checked-symbolic.svg"));
  border-image: none;
}


/************
 * GtkScale *
 ************/
scale {
  // sizing
  $_marks_length: 8px;
  $_marks_distance: 7px;

  $trough_size: 2px;
  $finetune_trough_size: 4px;

  $slider_size: 32px;

  $slider_margin: -($slider_size - $trough_size) / 2;
  $finetune_slider_margin: -($slider_size - $finetune_trough_size) / 2;

  $color_slider_margin: -($slider_size) * 3 / 4;
  $color_marks_slider_margin: -($slider_size - 16px) - $color_slider_margin;

  min-height: $trough_size;
  min-width: $trough_size;

  &.horizontal { padding: ($medium_size - $trough_size) / 2 12px; }

  &.vertical { padding: 12px ($medium_size - $trough_size) / 2; }

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

  // click-and-hold the slider to activate
  &.fine-tune {
    &.horizontal {
      min-height: $finetune_trough_size;
      padding-top: ($medium_size - $finetune_trough_size) / 2;
      padding-bottom: ($medium_size - $finetune_trough_size) / 2;
    }

    &.vertical {
      min-width: $finetune_trough_size;
      padding-left: ($medium_size - $finetune_trough_size) / 2;
      padding-right: ($medium_size - $finetune_trough_size) / 2;
    }

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

  // the backing bit
  trough {
    transition: background-color $longer_duration $deceleration_curve;
    outline: none;
    background-color: $track_color;

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

  // the colored part of the backing bit
  highlight {
    transition: background-color $longer_duration $deceleration_curve;
    background-color: $secondary_color;

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

  // this is another differently styled part of the backing bit, the most relevant use case is for example
  // in media player to indicate how much video stream as been cached
  fill {
    transition: background-color $longer_duration $deceleration_curve;
    background-color: $track_color;

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

  slider {
    transition: background-color $longer_duration $deceleration_curve,
                background-size $ripple_duration $deceleration_curve,
                background-image $ripple_opacity_duration $deceleration_curve;
    background-repeat: no-repeat;
    background-position: center;
    background-size: auto, 1000% 1000%;
    border-radius: 50%;
    color: transparent;

    @each $s, $as in ('', ''),
                     (':disabled', '-disabled') {
      &#{$s} {
        $_url: 'assets/scale-slider#{$as}#{$asset_suffix}';

        background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                          radial-gradient(circle farthest-corner at center,
                                          currentColor 10%,
                                          transparent 0%);
      }
    }

    &:focus { background-color: rgba($secondary_color, 0.16); }

    &:hover { background-color: rgba($secondary_color, 0.12); }

    &:active {
      transition: background-color $longer_duration $deceleration_curve,
                  background-size 0,
                  background-image 0;
      animation: scale_ripple_effect $longer_duration $deceleration_curve forwards;
      background-size: auto, 0% 0%;
      background-color: rgba($secondary_color, 0.12);
      color: rgba($secondary_color, 0.12);
    }
  }

  marks label,
  value { color: $hint_fg_color; }

  marks {
    color: $track_color;

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

  &.fine-tune marks {
    @each $marks_class, $marks_pos, $marks_margin in (top, top, bottom),
                                                     (bottom, bottom, top),
                                                     (left, left, right),
                                                     (right, right, left) {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance - 1px;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_length - 1px);
      }
    }
  }

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

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

  // *WARNING* scale with marks madness following

  @each $dir_class, $dir_infix in ('horizontal', 'horz'),
                                  ('vertical', 'vert') {
    @each $marks_infix, $marks_class in ('marks-before', 'marks-before:not(.marks-after)'),
                                        ('marks-after', 'marks-after:not(.marks-before)') {
      &.#{$dir_class}.#{$marks_class} {
        slider {
          @each $state, $state_infix in ('', ''),
                                        (':disabled', '-disabled') {
            &#{$state} {
              $_scale_asset: 'assets/scale-#{$dir_infix}-#{$marks_infix}-slider#{$state_infix}#{$asset_suffix}';

              background-image: -gtk-scaled(url('#{$_scale_asset}.png'), url('#{$_scale_asset}@2.png')),
                                radial-gradient(circle farthest-corner at center,
                                                currentColor 10%,
                                                transparent 0%);
            }
          }
        }
      }
    }
  }

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

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

      slider {
        &:dir(ltr), &:dir(rtl) { // specificity bump
          margin-bottom: $color_slider_margin;
          margin-top: $color_marks_slider_margin;
        }
      }
    }

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

        slider {
          margin-left: $color_slider_margin;
          margin-right: $color_marks_slider_margin;
        }
      }

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

        slider {
          margin-right: $color_slider_margin;
          margin-left: $color_marks_slider_margin;
        }
      }
    }
  }
}


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

  &.vertical {
    trough,
    progress { min-width: $bar_size; }
  }

  // FIXME: insensitive state missing and some other state should be set probably
  color: $hint_fg_color;
  font-size: smaller;

  trough { background-color: rgba($primary_color, 0.3); }

  progress { background-color: $primary_color; }

  &.osd { // progressbar.osd used for epiphany page loading progress
    // min-width: $bar_size;
    // min-height: $bar_size;
    // background-color: transparent;

    // trough { background-color: transparent; }

    // progress { background-color: $primary_color; }
  }

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


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

    &.discrete block {
      min-width: $medium_size;

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

  &.vertical {
    block { min-width: $bar_size; }

    &.discrete block {
      min-height: $medium_size;

      &:not(:last-child) { margin-bottom: 2px; }
    }
  }

  // imitate the entry style
  trough {
    // padding: 2px;
    // border-radius: $material_radius;
    // box-shadow: $shadow_1;
    // background-color: $base_color;

    // &:disabled { background-color: $alt_base_color; }
  }

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

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

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

    &.empty { background-color: $divider_color; }
  }
}


/****************
 * Print dialog *
*****************/
printdialog {
  paper {
    padding: 0;
    border: 1px solid $border_color;
    background-color: $base_color;
    color: $fg_color;
  }

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


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

  &.flat { border-style: none; }
}

frame.flat > border { @extend .frame.flat; } // for backward compatibility

actionbar > revealer > box {
  padding: $container_padding;
  border-top: 1px solid $border_color;

  button:not(.suggested-action):not(.destructive-action):not(.server-list-button) { @extend %button_basic.flat; }
}

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

  // This is used when content is touch-dragged past boundaries.
  // draws a box on top of the content, the size changes programmatically.
  @at-root 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.
  @at-root undershoot {
    &.top { @include undershoot(top); }

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

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

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

  @at-root junction { // the small square between two scrollbars
    border-style: solid none none solid;
    border-width: 1px;
    border-color: $border_color;
    background-color: $base_color;

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

// vbox and hbox separators
separator {
  min-width: 1px;
  min-height: 1px;
  background-color: $border_color;
}

%hide_separators {
  min-width: 0;
  min-height: 0;
  background-color: transparent;
}


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

  row { padding: 2px; }
}

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

row {
  &.activatable {
    transition: $row_transition,
                background-size $ripple_duration $deceleration_curve,
                background-image $ripple_opacity_duration $deceleration_curve;
    box-shadow: inset 0 0 0 9999px transparent;
    background-image: radial-gradient(circle farthest-corner at center,
                                      transparent 10%,
                                      transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;

    &:hover {
      transition: $row_transition,
                  box-shadow 0,
                  background-size $ripple_duration $deceleration_curve,
                  background-image $ripple_opacity_duration $deceleration_curve;
      box-shadow: inset 0 0 0 9999px $row_fill_color;
    }

    &.has-open-popup, // this is for indicathing which row generated a popover see https://bugzilla.gnome.org/show_bug.cgi?id=754411
    &:active {
      transition: $row_transition,
                  background-size 0,
                  background-image 0;
      animation: ripple_effect $longer_duration $deceleration_curve forwards;
      box-shadow: inset 0 0 0 9999px $semi_fill_color;
      background-image: radial-gradient(circle farthest-corner at center,
                                        $semi_fill_color 10%,
                                        transparent 0%);
      background-size: 0% 0%;
    }
  }

  &:selected { @extend %selected_items; }
}


/*********************
 * App Notifications *
 *********************/
.app-notification {
  // @extend %osd;

  @extend toolbar.osd;

  margin: 8px;

  button { @extend %button_basic.flat; }

  &.frame,
  border { border-style: none; }
}


/*************
 * Expanders *
 *************/
expander {
  title > arrow {
    transition: all $shorter_duration $standard_curve;
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    -gtk-icon-transform: rotate(-90deg);

    &:dir(rtl) { -gtk-icon-transform: rotate(90deg); }

    &:checked { -gtk-icon-transform: unset; }

    color: $secondary_fg_color;

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

    &:disabled { color: $disabled_secondary_fg_color; }

    &:selected {
      color: $inverse_secondary_fg_color;

      &:hover, &:active { color: $inverse_fg_color; }

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


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

  &:disabled { color: $disabled_fg_color; }

  &:selected {
    @extend %selected_items;

    border-radius: $material_radius + 1px;
  }

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

  &.button { @extend %simple_flat_button; }

  &.highlight {
    color: $secondary_fg_color;
    font-weight: 500;
  }

  &:indeterminate { color: $disabled_secondary_fg_color; }
}


/***********
 * Dialogs *
 ***********/
messagedialog { // Message Dialog styling
  &.background { background-color: $popup_bg_color; }

  .titlebar {
    min-height: $small_size;
    border-style: none;
    box-shadow: inset 0 1px $highlight_color;
    background-color: $popup_bg_color;
    color: $fg_color;

    &:backdrop { color: $secondary_fg_color; }
  }

  &.csd { // rounded bottom border styling for csd version
    &.background {
      // bigger radius for better antialiasing
      border-bottom-left-radius: $material_radius;
      border-bottom-right-radius: $material_radius;
    }

    .dialog-action-area {
      margin-top: -$container_padding;
      padding: $container_padding;

      button {
        @extend %simple_flat_button;
        border-radius: $material_radius;

        &:not(:last-child) { margin-right: $container_padding; }

        &.suggested-action:not(:disabled) { color: $suggested_color; }

        &.destructive-action:not(:disabled) { color: $destructive_color; }
      }
    }
  }

  entry { @extend %entry.flat; }
}

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

  #pathbarbox {
    border-bottom: 1px solid $border_color;
    background-color: $bg_color;
  }
}

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


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

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

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

  list { background-color: transparent; }

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

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

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

  row {
    padding: 10px 4px;

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

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


/****************
 * File chooser *
 ****************/
// dim the sidebar icons, see bug #786613 for details on this oddity
row {
  image.sidebar-icon { color: $secondary_fg_color; }

  &:selected image.sidebar-icon { color: $inverse_secondary_fg_color; }
}

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

  list { padding: (4px - 3px) 0 4px; }

  row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: 32px;
    margin: -1px 0; // Remove unknown margins
    padding: 0;

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

    &:selected { color: $inverse_fg_color; }

    &:disabled { color: $disabled_fg_color; }

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

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

    @at-root button.sidebar-button {
      @extend %simple_flat_button;

      @extend %small_button;

      row:selected & { @extend %button_selected.flat; }
    }

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

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

    &:drop(active):not(:disabled) {
      box-shadow: inset 0 0 0 2px $secondary_color;

      &:selected {
        // background-color: $secondary_color;
        // color: $inverse_fg_color;
      }
    }
  }
}

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

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

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


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

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

  &.horizontal > separator {
    background-repeat: repeat-y;

    &:dir(ltr) {
      margin: 0 -8px 0 0;
      padding: 0 8px 0 0;
      background-position: left;
    }

    &:dir(rtl) {
      margin: 0 0 0 -8px;
      padding: 0 0 0 8px;
      background-position: right;
    }

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

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

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


/**************
 * GtkInfoBar *
 **************/
infobar {
  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 {
    > label, & { color: $inverse_fg_color; }

    button { @extend %button_selected; }

    selection {}

    *:link { @extend %link_selected; }
  }
}


/************
 * Tooltips *
 ************/
tooltip {
  &.background {
    // background-color needs to be set this way otherwise it gets drawn twice
    // see https://bugzilla.gnome.org/show_bug.cgi?id=736155 for details.
    // box-shadow: inset 0 1px $highlight_color;
    background-color: $tooltip_bg_color;
    color: $tooltip_fg_color;
  }

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

  &:not(.csd):not(.unity-csd) {
    // border: 1px solid $border_color;
    // border-radius: $material_radius + 1px;
    // background-clip: $extra_background_clip;
  }

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

  label {
    // tooltip label already seems to have 6px margins
    min-height: 32px - 6px * 2;
    padding: 0 8px - 6px;
  }

  * {
    // workaround for Eclipse.
    // do not include any declaration here.
    // padding: 0;
    // background-color: transparent;
    // color: inherit;
  }
}


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

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

  &.top {
    border-top-left-radius: $material_radius + 0.5px;
    border-top-right-radius: $material_radius + 0.5px;

    overlay {
      border-top-left-radius: $material_radius;
      border-top-right-radius: $material_radius;
    }
  }

  &.bottom {
    border-bottom-left-radius: $material_radius + 0.5px;
    border-bottom-right-radius: $material_radius + 0.5px;

    overlay {
      border-bottom-left-radius: $material_radius;
      border-bottom-right-radius: $material_radius;
    }
  }

  &.left,
  &:first-child:not(.top) {
    border-top-left-radius: $material_radius + 0.5px;
    border-bottom-left-radius: $material_radius + 0.5px;

    overlay {
      border-top-left-radius: $material_radius;
      border-bottom-left-radius: $material_radius;
    }
  }

  &.right,
  &:last-child:not(.bottom) {
    border-top-right-radius: $material_radius + 0.5px;
    border-bottom-right-radius: $material_radius + 0.5px;

    overlay {
      border-top-right-radius: $material_radius;
      border-bottom-right-radius: $material_radius;
    }
  }

  &.dark { color: $light_fg_color; }

  &.light { color: $dark_fg_color; }

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

    &.light overlay { box-shadow: $shadow_1, 0 0 0 2px $secondary_color; }

    &.dark overlay { box-shadow: $shadow_1, 0 0 0 2px $secondary_color; }
  }

  overlay {
    transition: $shadow_transition;
    box-shadow: $shadow_1;

    &:hover { box-shadow: $shadow_2; }
  }

  &#add-color-button {
    border-radius: $material_radius $material_radius 0 0;
    color: $light_fg_color;

    &:only-child { border-radius: $material_radius; }

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

  &:disabled {
    opacity: 0.5;

    overlay { box-shadow: none; }
  }

  row:selected & {
  }

  &#editor-color-sample {
    border-radius: $material_radius + 0.5px;

    overlay { border-radius: $material_radius; }

    // overlay:hover { box-shadow: $shadow_1; }
  }
}

// colorscale popup
colorchooser .popover.osd {
  transition: $shadow_transition;
  border-radius: $material_radius;
  box-shadow: $shadow_2, inset 0 1px $highlight_color;
  background-color: $popup_bg_color;

  &:backdrop { box-shadow: $shadow_1, inset 0 1px $highlight_color; }

  spinbutton:not(.vertical) { @extend %entry.flat; }
}


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

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

  rubberband, .rubberband { @extend rubberband; }
}

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

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

  button { // +/- buttons on GtkVolumeButton popup
  }
}


/**********************
 * Window Decorations *
 **********************/
decoration {
  transition: $shadow_transition;
  border-radius: $material_radius $material_radius 0 0;
  box-shadow: $shadow_4, 0 16px 16px transparent;

  // FIXME rationalize shadows

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

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

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

  .popup & { box-shadow: none; }

  // server-side decorations as used by mutter
  .ssd & { box-shadow: 0 3px 3px rgba(0, 0, 0, 0.16); } // just doing borders, wm draws actual shadows

  .csd.popup & {
    border-radius: $material_radius;
    box-shadow: $shadow_2;
  }

  tooltip.csd & {
    border-radius: $material_radius;
    box-shadow: none;
  }

  messagedialog.csd & {
    border-radius: $material_radius;
    // box-shadow: $shadow_4, 0 16px 16px transparent;

    // &:backdrop { box-shadow: $shadow_2, 0 16px 16px transparent; }
  }

  .solid-csd & {
    margin: 0;
    // padding: 4px;
    border-radius: 0;
    box-shadow: none;
    // box-shadow: inset 0 0 0 4px $titlebar_bg_color;
    background-color: $titlebar_bg_color;
  }
}

// Window Close button
button.titlebutton {
  // @extend %simple_flat_button;

  @extend %circular_button;

  .selection-mode & {
  }
}


// catch all extend :)

%selected_items {
  background-color: $primary_color;

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

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

.monospace { font-family: monospace; }


/**********************
 * Touch Copy & Paste *
 **********************/
// touch selection handlebars for the Popover.osd above
cursor-handle {
  border-radius: $circular_radius;
  background-color: $secondary_color;
  background-image: none;

  &.top:dir(ltr), &.bottom:dir(rtl) {
    padding-left: 6px;
    border-top-right-radius: 0;
  }

  &.bottom:dir(ltr), &.top:dir(rtl) {
    padding-right: 6px;
    border-top-left-radius: 0;
  }

  &.insertion-cursor:dir(ltr), &.insertion-cursor:dir(rtl) {
    -GtkWidget-text-handle-width: 24;
    -GtkWidget-text-handle-height: 30;

    $_url: 'assets/scale-horz-marks-before-slider#{$asset_suffix}';
    -gtk-icon-source: -gtk-scaled(url('#{$_url}.png'),
                                  url('#{$_url}@2.png'));
  }
}

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

// shortcut window keys
.keycap {
  min-width: 28px - 8px * 2;
  min-height: 28px - 2px;
  margin-top: 2px;
  padding-bottom: 2px;
  padding-left: 8px;
  padding-right: 8px;

  border: solid 1px $border_color;
  border-radius: $material_radius + 1px;
  box-shadow: inset 0 -2px $border_color;
  background-color: $popup_bg_color;
  color: $fg_color;
  font-size: smaller;
}

:not(decoration):not(window):drop(active) { // FIXME needs to be done widget by widget, this wildcard should really die
  transition: $longer_transition;
  box-shadow: $shadow_1, inset 0 0 0 2px $secondary_color;
  caret-color: $secondary_color;
}

stackswitcher button.text-button { min-width: 100px; } // FIXME aggregate with buttons

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


/*********
 * Emoji *
 *********/
popover.emoji-picker {
  padding: 0;

  entry {
    border-bottom: 1px solid $border_color;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
  }

  scrolledwindow { border-bottom: 1px solid $border_color; }
}

// mimic tab style
button.emoji-section {
  margin-top: -1px;
  padding: 0 8px;
  min-width: 24px;
  min-height: $medium_size;
  border-radius: 0;
  outline-offset: -6px;
  box-shadow: none;

  &:hover { box-shadow: inset 0 2px $track_color; }

  &:active {
    box-shadow: inset 0 2px $primary_color;
    background-image: radial-gradient(circle farthest-corner at center,
                                      rgba($primary_color, 0.7) 10%,
                                      transparent 0%);
  }

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

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

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

.emoji {
  min-width: 3em;
  min-height: 3em;
  padding: 0;
  // font-size: large;

  widget {
    transition: $shorter_transition;

    &:hover { font-size: larger; }
  }
}
