
/***************
 * Base States *
 ***************/
.background {
  background-color: $background;
  color: $text;

  &.csd { // Set csd windows botttom border radius
    border-radius: $window-radius;
  }

  &.maximized, &.tiled, &.fullscreen, &.solid-csd { // No radius when windows maximized
    border-radius: 0;
  }
}

#desktopwindow.background {
  background-color: transparent;
}

dnd {
  color: on($background);
}

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

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

.lowres-icon:not(.large-icons) {
  -gtk-icon-size: 16px;
}

spinner:disabled,
arrow:disabled,
scrollbar:disabled,
check:disabled,
radio:disabled,
treeview.expander:disabled { -gtk-icon-filter: opacity(0.5); }

%view, .view {
  background-color: $base;
  color: $text;

  &:disabled { color: $text-disabled; }

  &:selected {
    @extend %selected_items;
  }
}

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

  text {
    background-color: $base;
    selection { &:focus, & { @extend %selected_items_primary; }}
  }

  border {
    background-color: $base-alt;
    color: $text-secondary; // FIXME: not working
  }
}

iconview {
  @extend %view;
  &:hover, &:selected { border-radius: $corner-radius; }
}

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

flowbox {
  > rubberband { @extend rubberband; }

  > flowboxchild {
    padding: 4px;
    border-radius: $corner-radius;

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

.content-view .tile {
  &:selected {
    background-color: transparent;
  }
}

gridview {
  > rubberband { @extend rubberband; }

  > child {
    padding: 3px;

    &:selected {
      outline-color: $overlay-selected;

      @extend %selected_items;
    }

    box { //cells
      border-spacing: 8px; //label separation
      margin: 12px;
    }
  }
}

coverflow cover {
  color: $text;
  background-color: $base;
  border: 1px solid black;
}

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

  &.separator {
    color: $text-secondary;
  }

  > selection { @extend %selected_items_primary; }

  &:disabled {
    color: $text-disabled;

    // selection { color: $text-disabled; }

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

  &.osd {
    border-radius: $corner-radius;
    background-color: $tooltip;
    color: on($tooltip);
  }
}

.dim-label { color: $text-secondary; }

window.assistant {
  .sidebar {
    padding: 4px 0;
  }

  .sidebar label {
    min-height: $medium-size;
    padding: 0 12px;
    color: $text-disabled;
    font-weight: 500;

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

%osd {
  color: on($base);
  background-color: $base;
  background-clip: padding-box;
  border-radius: $corner-radius;
  border: none;
  box-shadow: $shadow-z6;
}

.osd {
  @extend %osd;
  padding: $space-size;
  margin: $space-size;

  &.circular { border-radius: $circular-radius; }
}

/*********************
 * Spinner Animation *
 *********************/
@keyframes spin {
  to { 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; }
  }
}

// General Typography
.large-title {
  font-weight: 300;
  font-size: 24pt;
}

.title {
  &-1 {
    font-weight: 800;
    font-size: 20pt;
  }

  &-2 {
     font-weight: 800;
     font-size: 15pt;
  }

  &-3 {
    font-weight: 700;
    font-size: 15pt;
  }

  &-4 {
    font-weight: 700;
    font-size: 13pt;
  }
}

.heading {
  font-weight: 700;
  font-size: 11pt;
}

.body {
  font-weight: 400;
  font-size: 11pt;
}

.caption {
  font-weight: 400;
  font-size: 9pt;

  &-heading {
    font-weight: 700;
    font-size: 9pt;
  }
}

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

%linked_round_entry {
  &:not(:only-child) {
    border-image-width: 4px 4px 4px 4px;
    border-image-slice: 4 4 4 4;
    border-image-repeat: stretch;
    border-image-source: -gtk-scaled(url("assets/linked-entry-normal#{$asset-suffix}.png"),url("assets/linked-entry-normal#{$asset-suffix}@2.png"));

    &:focus-within {
      border-image-source: -gtk-scaled(url("assets/linked-entry-focus#{$asset-suffix}.png"),url("assets/linked-entry-focus#{$asset-suffix}@2.png"));
    }

    &:disabled {
      border-image-source: -gtk-scaled(url("assets/linked-entry-disabled#{$asset-suffix}.png"),url("assets/linked-entry-disabled#{$asset-suffix}@2.png"));
    }
  }

  &:first-child {
    border-image-source: -gtk-scaled(url("assets/linked-entry-firstchild-normal#{$asset-suffix}.png"),url("assets/linked-entry-firstchild-normal#{$asset-suffix}@2.png"));

    &:focus-within {
      border-image-source: -gtk-scaled(url("assets/linked-entry-firstchild-focus#{$asset-suffix}.png"),url("assets/linked-entry-firstchild-focus#{$asset-suffix}@2.png"));
    }

    &:disabled {
      border-image-source: -gtk-scaled(url("assets/linked-entry-firstchild-disabled#{$asset-suffix}.png"),url("assets/linked-entry-firstchild-disabled#{$asset-suffix}@2.png"));
    }
  }

  &:last-child {
    border-image-source: -gtk-scaled(url("assets/linked-entry-lastchild-normal#{$asset-suffix}.png"),url("assets/linked-entry-lastchild-normal#{$asset-suffix}@2.png"));

    &:focus-within {
      border-image-source: -gtk-scaled(url("assets/linked-entry-lastchild-focus#{$asset-suffix}.png"),url("assets/linked-entry-lastchild-focus#{$asset-suffix}@2.png"));
    }

    &:disabled {
      border-image-source: -gtk-scaled(url("assets/linked-entry-lastchild-disabled#{$asset-suffix}.png"),url("assets/linked-entry-lastchild-disabled#{$asset-suffix}@2.png"));
    }
  }
}

%entry,
entry {
  min-height: $medium-size;
  padding: 0 8px;
  border-spacing: $space-size;
  border-radius: $corner-radius;
  caret-color: currentColor; // this shouldn't be needed.
  border: 1px solid $divider;
  background-clip: padding-box;

  @if $window == 'round' {
    @include entry(round-normal);
    &:hover, &:drop(active) { @include entry(round-hover); }
    &:focus-within { @include entry(round-focus); }
    &:disabled { @include entry(round-disabled); }
  } @else {
    @include entry(normal);
    &:hover, &:drop(active) { @include entry(hover); }
    &:focus-within { @include entry(focus); }
    &:disabled { @include entry(disabled); }
  }

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

  image { // icons inside the entry
    color: $text-secondary;

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

    &:disabled { color: $text-disabled; }

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

  > text > selection { @extend %selected_items_primary; }

  // entry error and warning style
  @each $e_type, $e_color in (error, $error),
                             (warning, $warning),
                             (success, $success) {
    &.#{$e_type} {
      @include entry(normal, $e_color);

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

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

  > progress,
  progress > trough > progress {
    margin: 2px -8px;
    border-bottom: 2px solid $primary;
    background-color: transparent;
  }

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

    @if $window == 'round' {
      @extend %linked_round_entry;
    }
  }

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

treeview entry {
  &.flat, & {
    background-color: $base;

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

%entry-tag,
.entry-tag {
  margin: 2px;
  border-radius: $corner-radius;
  box-shadow: none;
  background-color: $track-disabled;
  color: $text;

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

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


/***********
 * Buttons *
 ***********/
// stuff for .needs-attention
@keyframes needs-attention {
  from { background-image: radial-gradient(farthest-side, $primary 0%, transparentize($primary, 1) 0%); }
  to { background-image: radial-gradient(farthest-side, $primary 95%, transparentize($primary, 1)); }
}

%button-on-dark {
  color: on(dark, secondary);
  @extend %button-flat;

  &:focus, &:hover, &:active, &:checked { color: on(dark); }
  &:disabled { color: on(dark, secondary-disabled); }
  &:checked:disabled { color: on(dark, disabled); }
}

button {
  min-height: 24px;
  min-width: 16px;
  padding: ($medium-size - 24px) / 2 ($medium-size - 16px) / 2;
  border-radius: $corner-radius;
  font-weight: 500;
  border: 1px solid $border;
  background-clip: padding-box;
  @include button(normal);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  &.text-button {
    min-width: 64px - 16px * 2;
    padding-left: 16px;
    padding-right: 16px;

    &.flat {
      min-width: 64px - 8px * 2;
      padding-left: 8px;
      padding-right: 8px;
    }
  }

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

    // @extend %circular-button;
  }

  // NOTE: Some image-only buttons use this as well
  &.text-button.image-button {
    min-width: 24px;
    padding: ($medium-size - 24px) / 2;
    border-radius: $corner-radius;

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

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

    &.flat label {
      &:first-child { margin-left: 12px - ($medium-size - 24px) / 2; }

      &:last-child { margin-right: 12px - ($medium-size - 24px) / 2; }
    }

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

  .linked > &:not(:only-child) {
    &:focus {
      @include button(normal);
    }

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

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

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

  .linked:not(.vertical) > &.flat,
  .linked.vertical > &.flat {
    &:not(:only-child) { // specificity bump
      border-radius: $corner-radius;

      &.image-button:not(.text-button) { border-radius: $corner-radius; }
    }

    &:focus { box-shadow: inset 0 0 0 9999px $overlay-focus; }
  }

  // big standalone buttons like in Documents pager
  &.osd {
    box-shadow: none;
    background-color: rgba(black, 0.35);
    color: white;

    &, &.image-button {
      min-height: $medium-size;
      min-width: $medium-size;
      padding: 4px;
    }

    > image {
      padding: 0;
    }

    &.remove-button {
      padding: 0;
    }

    &:focus {
      outline-color: transparent;
    }

    &:hover {
      background-color: rgba(black, 0.45);
      color: white;
    }

    &:active {
      background-color: rgba(black, 0.65);
      color: white;
    }

    &:disabled {
      background-color: rgba(black, 0.15);
      color: rgba(white, 0.35);
    }
  }

  // overlay / OSD style
  // .osd & { }

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color in (suggested-action, $suggested),
                             (destructive-action, $destructive) {
    &.#{$b_type} {
      background-color: $b_color;
      color: on($b_color);
      box-shadow: none;
      border-color: $b_color;
      background-clip: border-box;

      &:disabled {
        @include button(disabled);
        border-color: transparent;
      }

      &:hover {
        box-shadow: inset 0 0 0 9999px transparent,
                    0 2px (4px * .6) -1px rgba($b_color, 0.2),
                    0 4px (5px * .6) 0 rgba($b_color, 0.14),
                    0 1px (10px * .6) 0 rgba($b_color, 0.12);
      }

      &:checked {
        background-clip: border-box;
        background-color: mix(on($b_color), $b_color, percentage(0.3));
        border-color: mix(on($b_color), $b_color, percentage(0.3));
      }

      &:checked:hover {
        box-shadow: inset 0 0 0 9999px transparent,
                    0 3px 3px -3px rgba($b_color, 0.3),
                    0 2px 3px -1px rgba($b_color, 0.24),
                    0 2px 5px 0 rgba($b_color, 0.12);
      }

      &:focus { box-shadow: 0 0 0 2px rgba($b_color, 0.35); }

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

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

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

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

    > label {
      margin: 0 -6px;
      padding: 0 6px;
    }

    > image {
      margin: -3px -6px;
      padding: 3px 6px;
    }

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

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

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

    > box { border-spacing: $space-size; }
    > box > box > label { font-weight: bold; }
  }

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

    label { padding: 0; }
  }

  @at-root %small-button {
    min-height: $small-size;
    min-width: $small-size;
    padding: 0;
    border-radius: $circular-radius;
  }
}

%needs-attention {
  animation: needs-attention $ripple-fade-in-duration $ease-out forwards;
  background-repeat: no-repeat;
  background-position: right 3px;
  background-size: 6px 6px;

  &:dir(rtl) { background-position: left 3px; }
}

%linked-solid {
  border-radius: 0;
  border-right-width: 0;

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

  &:last-child {
    border-top-right-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-right-width: 1px;
  }

  &:only-child {
    border-radius: $corner-radius;
    border-right-width: 1px;
  }
}

%linked-solid-vertical {
  border-radius: 0;
  border-bottom-width: 0;

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

  &:last-child {
    border-bottom-left-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-bottom-width: 1px;
  }

  &:only-child {
    border-radius: $corner-radius;
    border-bottom-width: 1px;
  }
}

%linked {
  border-radius: 0;
  border-left-width: 0;
  border-right-width: 0;

  &:first-child {
    border-top-left-radius: $corner-radius;
    border-bottom-left-radius: $corner-radius;
    border-left-width: 1px;
  }

  &:last-child {
    border-top-right-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-right-width: 1px;
  }

  &:only-child {
    border-radius: $corner-radius;
    border-left-width: 1px;
    border-right-width: 1px;
  }
}

%linked-vertical {
  border-radius: 0;
  border-top-width: 0;
  border-bottom-width: 0;

  &:first-child {
    border-top-left-radius: $corner-radius;
    border-top-right-radius: $corner-radius;
    border-top-width: 1px;
  }

  &:last-child {
    border-bottom-left-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-bottom-width: 1px;
  }

  &:only-child {
    border-radius: $corner-radius;
    border-top-width: 1px;
    border-bottom-width: 1px;
  }
}

//
// Linking stuff
//

@mixin linking_rules($vert:'false', $entry_rules:'true') {

  $_border: if($vert=='false', left, top);

  @if $entry_rules=='true' {
    > entry.error + entry,
    > entry + entry.error { border-#{$_border}-color: $error; }

    > entry.warning + entry,
    > entry + entry.warning { border-#{$_border}-color: $warning; }

    > entry.error + entry.warning,
    > entry.warning + entry.error { border-#{$_border}-color: mix($error, $warning, 50%); }

    > entry:not(:only-child) + button:not(.combo) { border-#{$_border}: 1px solid $divider; }

    @each $e_type, $e_color in (':focus-within', $track),
                               (':hover', $track),
                               (':drop(active)', $drop_target_color),
                               ('.warning:focus-within', $warning),
                               ('.error:focus-within', $error) {
      > entry#{$e_type} + entry { border-#{$_border}-color: $e_color; }
      > entry#{$e_type}:not(:only-child) + button:not(.combo) { border-#{$_border}: 1px solid $e_color; }
    }

    @each $e_type, $e_color in ('', $divider), (':focus-within', $track) {
      > spinbutton#{$e_type} + spinbutton,
      > spinbutton#{$e_type} + button { border-#{$_border}: 1px solid $e_color; }
    }

    > spinbutton + spinbutton:focus { border-#{$_border}: 1px solid $track; }
    > spinbutton + button:checked { border-#{$_border}: 1px solid $primary; }

    > button:active + entry,
    > button:checked + entry { border-#{$_border}-color: $primary; }
  }

  @if $entry_rules=='false' {
    @each $e_type in ('', ':focus-within', ':drop(active)', '.warning:focus-within', '.error:focus-within') {
      > entry#{$e_type}:not(:only-child) + button:not(.combo) { border-#{$_border}: none; }
    }

    > button:active + entry,
    > button:checked + entry { border-#{$_border}-color: $divider; }
  }
}

// Apply the rules defined above
.linked:not(.vertical) {
  &:not(.path-bar):not(.nautilus-path-bar) { @include linking_rules($entry_rules:'true'); }

  > button + button { margin: 0; }

  headerbar, .titlebar & {
    &:not(.path-bar):not(.nautilus-path-bar):not(.stack-switcher) {
      @include linking_rules($entry_rules:'false');
    }
  }
}

.linked.vertical { @include linking_rules($vert:'true'); }

// menu buttons
modelbutton.flat {
  min-height: $menuitem-size;
  padding: 0 $space-size * 1.5;
  border-radius: $corner-radius;
  color: $text;

  @extend %button-flat-simple;

  &:selected { @extend %selected_items; }
}

modelbutton.flat arrow {
  &.left { -gtk-icon-source: -gtk-icontheme("go-previous-symbolic"); }
  &.right { -gtk-icon-source: -gtk-icontheme("go-next-symbolic"); }
}

button.color {
  min-height: $small-size;
  min-width: $small-size;
  padding: $space-size;
}

%list_button,
list > row button.image-button:not(.flat) {
  @extend %button-flat-simple;

  @each $b_type, $b_color in (suggested-action, $suggested),
                             (destructive-action, $destructive) {
    &.#{$b_type} { // allow colored buttons in lists #3643
      background-color: $b_color;
      color: on($b_color);
    }
  }
}

/*********
 * Links *
 *********/
link, %links {
  color: $link;

  &:visited {
    color: $link-visited;
  }
}

button.link {
  &:link {
    &, &:focus, &:hover, &:active { color: $link; }
  }

  &:visited {
    &, &:focus, &:hover, &:active { color: $link-visited; }
  }

  > 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;
    border-spacing: 0;

    > text {
      min-width: $large-size - 8px * 2;
      // reset all the other props since the spinbutton node is styled here
      margin: 0;
      padding-left: $space-size * 2;
      border: none;
      border-image: none;
      border-radius: 0;
      box-shadow: none;
      background-color: transparent;
    }

    > button {
      @extend %button-flat-simple;
      @extend %small-button;

      // margin: $space-size;
      border: solid $space-size transparent;

      // Remove unwanted focus indicator
      &:focus:not(:hover):not(:active):not(:disabled) {
        box-shadow: inset 0 0 0 9999px transparent;
        color: $text-secondary;
      }

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

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

  // Vertical
  &.vertical {
    @extend %entry;

    padding: 0;

    &:disabled { color: $text-disabled; }

    > text {
      margin: 0;
      border: none;
      border-image: none;
      border-radius: 0;
      box-shadow: none;
      background-color: transparent;
      padding: 0;
    }

    > button {
      @extend %button-flat-simple;
      @extend %small-button;
      padding: 0;

      border: solid $space-size transparent;

      // Remove unwanted focus indicator
      &:focus:not(:hover):not(:active) {
        box-shadow: inset 0 0 0 9999px transparent;
        color: $text-secondary;
      }

      &.up { margin: 0 $space-size / 2; }

      &.down { margin: 0 $space-size / 2; }
    }
  }

  // Misc
  // treeview &:not(.vertical),
  list > row &:not(.vertical) {
    > button {
      margin: $space-size;

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

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


/**************
 * ComboBoxes *
 **************/
dropdown > popover.menu.background > contents { padding: 0; }
dropdown > button > box { border-spacing: $space-size; }

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

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    padding-left: $space-size * 1.5;
    padding-right: $space-size * 1.5;
  }

  // newstyle
  popover {
   margin-top: $space-size - 2px;
   padding: 0;

    // drodowns with searchboxes on top
    .dropdown-searchbar {
      padding: $space-size;
    }
  }

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

  &.linked {
    button:nth-child(2) {
      &: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:not(.vertical) > entry:not(:only-child) {
    border-radius: $corner-radius;
    border-right-width: 1px;

    @if $window == 'round' { // reset
      &, &:first-child, &:last-child {
        @include entry(round-normal);
        &:focus-within { @include entry(round-focus); }
        &:disabled { @include entry(round-disabled); }
      }
    }

    &:first-child {
      margin-right: -$medium-size;
      padding-right: $medium-size;
    }

    &:last-child {
      margin-left: -$medium-size;
      padding-left: $medium-size;
    }
  }

  > .linked:not(.vertical) > button:not(:only-child) {
    @extend %button-flat;
    // @extend %small-button;

    min-height: 16px;
    min-width: 16px;
    margin: ($medium-size - $small-size) / 2;
    padding: ($small-size - 16px) / 2;
    border-radius: $corner-radius;
  }
}

// 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 {
    border-radius: 0;
    border-left-width: 0;
    border-right-width: 0;

    &:focus {
      @include button(normal);
    }

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

  &:first-child > box > button.combo {
    border-top-left-radius: $corner-radius;
    border-bottom-left-radius: $corner-radius;
    border-left-width: 1px;
  }

  &:last-child > box > button.combo {
    border-top-right-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-right-width: 1px;
  }

  &:only-child > box > button.combo {
    border-radius: $corner-radius;
    border-left-width: 1px;
    border-right-width: 1px;
  }
}

.linked.vertical > combobox {
  > box > button.combo {
    border-radius: 0;
    border-top-width: 0;
    border-bottom-width: 0;
  }

  &:first-child > box > button.combo {
    border-top-left-radius: $corner-radius;
    border-top-right-radius: $corner-radius;
    border-top-width: 1px;
  }

  &:last-child > box > button.combo {
    border-bottom-left-radius: $corner-radius;
    border-bottom-right-radius: $corner-radius;
    border-bottom-width: 1px;
  }

  &:only-child > box > button.combo {
    border-radius: $corner-radius;
    border-top-width: 1px;
    border-bottom-width: 1px;
  }
}


/************
 * Toolbars *
 ************/
.toolbar,
toolbar {
  padding: $space-size / 2 $space-size;
  background-color: $background;
  border-spacing: $space-size;

  button { @extend %button-flat; }

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

  // stand-alone OSD toolbars
  @at-root %toolbar_osd, &.osd {
    transition: $transition-shadow;
    padding: $space-size;
    border-radius: $window-radius;
    box-shadow: $shadow-z4, inset 0 1px highlight($surface);
    background-color: $surface;
    border: none;
    color: $text;

    &:backdrop { box-shadow: $shadow-z2, inset 0 1px highlight($surface); }

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

    &.bottom {
      box-shadow: none;
      background-color: transparent;
      background-image: linear-gradient(to bottom,
                                        transparent,
                                        rgba(black, 0.1) 30%,
                                        rgba(black, 0.2) 50%,
                                        rgba(black, 0.4));
    }
  }

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

  &:not(.inline-toolbar):not(.osd):not(.primary-toolbar) {
    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 + $space-size 2px; }
  }
}

// oldstyle toolbar buttons
.toolbar button {
  margin: 1px;
  @extend %button-flat;
}

// searchbar
searchbar > revealer > box {
  padding: $space-size;
  border-spacing: $space-size;
  border-style: solid;
  border-width: 0 0 1px;
  border-color: $divider;
  background-color: $background;
  background-clip: border-box;
  box-shadow: none;

  entry { margin: 0; }
}


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

%titlebar-button {
  @extend %button-flat;
  color: $titlebar-text-secondary;
  border-radius: $corner-radius;

  .linked:not(.vertical) > & {
    border-radius: $corner-radius;
  }

  &:focus, &:hover, &:active, &:checked { color: $titlebar-text; }

  &:disabled { color: $titlebar-text-secondary-disabled; }

  &:checked {
    &:disabled {
      background-color: transparent;
      color: $titlebar-text-disabled;
    }
  }

  &:backdrop {
    color: $titlebar-text-disabled;

    &:focus, &:hover, &:active { color: $titlebar-text-secondary; }

    &:disabled { color: $titlebar-text-secondary-disabled; }

    &:checked {
      color: $titlebar-text-secondary;

      &:disabled { color: $titlebar-text-secondary-disabled; }
    }
  }
}

%titlebar-entry {
  background-color: if($topbar == 'light' and $variant == 'light', $base, $titlebar-divider);
  color: $titlebar-text;
  border: none;
  border-radius: 4px;
  box-shadow: 0 2px 3px rgba(black, 0.06);

  &:hover { box-shadow: 0 2px 3px rgba(black, 0.08), inset 0 0 0 1px $titlebar-divider; }

  &:focus-within {
    box-shadow: inset 0 0 0 2px $entry-highlight;
  }

  &:disabled {
    background-color: $titlebar-fill;
    color: $titlebar-text-disabled;
  }

  image {
    color: $titlebar-text-secondary;

    &:hover, &:active { color: $titlebar-text; }

    &:disabled { color: $titlebar-text-disabled; }
  }
}

%circular_titlebutton {
  min-height: $medium-size - 6px;
  min-width: $medium-size - 6px;
  padding: 3px 0;
  margin-left: $space-size / 2;
  margin-right: $space-size / 2;
  @extend %circular-button;

  > image { border-radius: 100%; }
}

%square_titlebutton {
  min-height: $large-size;
  min-width: $large-size;
  padding: 0;
  margin: 0;
  border-radius: 0;

  > image { border-radius: 0; }
}

headerbar {
  transition: background-color $duration $ease-out, color $duration $ease-out;
  box-shadow: inset 0 -1px $divider;
  color: $titlebar-text;
  min-height: $large-size;
  margin: 0;
  padding: 0;

  @if $outline == 'true' and $topbar == 'dark' and $variant == 'light' {
    box-shadow: inset 0 -1px $divider, inset 0 1px highlight($titlebar);
  }

  @if $opacity == 'solid' or $blur == 'true' {
    background-color: $titlebar;
  } @else {
    background-color: rgba($titlebar, 0.98);
  }

  &:disabled { color: $titlebar-text-disabled; }

  &:backdrop {
    background-color: $titlebar-backdrop;
    color: $titlebar-text-secondary;

    &:disabled { color: $titlebar-text-secondary-disabled; }
  }

  &.flat, &.flat:backdrop {
    background: none;
    box-shadow: none;
    transition: none;
  }

  .title {
    padding: 0 $space-size * 2;
    font-weight: bold;
  }

  .subtitle {
    padding: 0 $space-size * 2;
    font-size: smaller;
  }

  .subtitle,
  .dim-label {
    transition: color $duration $ease-out;
    color: $titlebar-text-secondary;

    &:backdrop { color: $titlebar-text-disabled; }
  }

  // Don't draw titlebar above titlebar
  .titlebar {
    background-color: transparent;
    box-shadow: none;
  }

  > windowhandle > box {
    padding: 0 $space-size;

    &,
    > box.start,
    > box.end {
      border-spacing: $space-size;
    }
  }

  // add vertical margins to common widget on the headerbar to avoid them spanning the whole height
  entry,
  spinbutton,
  button,
  menubutton,
  stackswitcher,
  separator:not(.sidebar) {
    margin-top: $space-size;
    margin-bottom: $space-size;
  }

  menubutton > button,
  spinbutton > button,
  splitbutton > button,
  splitbutton > menubutton,
  .linked > menubutton,
  entry > menubutton {
    margin-top: 0;
    margin-bottom: 0;
  }

  popover {
    entry,
    spinbutton,
    button,
    menubutton,
    stackswitcher {
      margin-top: 0;
      margin-bottom: 0;
    }
  }

  separator:not(.sidebar) {
    background-color: $titlebar-divider;
  }

  switch {
    margin-top: ($large-size - 24px) / 2;
    margin-bottom: ($large-size - 24px) / 2;
    box-shadow: inset 0 0 0 1px $titlebar-text-secondary-disabled;

    &:hover { box-shadow: inset 0 0 0 1px $titlebar-text-disabled; }

    checked { box-shadow: none; }

    slider { background-color: $titlebar-text-secondary-disabled; }
  }

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

  // The separator for split headerbars
  headerbar + separator {
    background-color: $titlebar-divider;
  }

  // Titlebar Entries
  entry {
    @extend %titlebar-entry;
    margin-left: 3px;
    margin-right: 3px;
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: 4px;
  }

  // Titlebar Buttons
  button:not(.suggested-action):not(.destructive-action) { @extend %titlebar-button; }

  button.suggested-action, button.destructive-action {
    border: none;

    &:disabled {
      background-color: $titlebar-fill;
      color: $titlebar-text-disabled;
    }
  }

  stackswitcher { // reset
    border-radius: $corner-radius;

    &.linked:not(.vertical) > button:not(.suggested-action):not(.destructive-action).text-button {
      border-radius: $corner-radius;
      margin: 0 0;
    }
  }

  &.selection-mode {
    transition: background-color 0.1ms $ripple-fade-in-duration, color $duration $ease-out;
    box-shadow: none;
    background-color: $primary;
    color: on($primary);

    &:backdrop {
      color: on($primary, secondary);
    }

    .subtitle:link { color: on($primary); }

    button:not(.suggested-action):not(.destructive-action) {
      @extend %button-on-dark;
    }

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

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

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

  .selection-mode {
    box-shadow: none; // Avoid double shadows
    background-color: $primary;
  }

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

  // Window button
  windowcontrols {
    @if $titlebutton == "circular" {
      border-spacing: $space-size;

      &:not(.empty) {
        &.start:dir(ltr),
        &.end:dir(rtl) {
          margin-right: $space-size;
        }
  
        &.start:dir(rtl),
        &.end:dir(ltr) {
          margin-left: $space-size;
        }
      }
    } @else {
      border-spacing: 0;

      &:not(.empty) {
        &.start:dir(ltr),
        &.end:dir(rtl) {
          margin-right: $space-size;
          margin-left: -$space-size;
        }
  
        &.start:dir(rtl),
        &.end:dir(ltr) {
          margin-left: $space-size;
          margin-right: -$space-size;
        }
      }
    }

    // Windows button
    > button:not(.suggested-action):not(.destructive-action) {
      @if $titlebutton == "circular" {
        @extend %circular_titlebutton;
      } @else {
        @extend %square_titlebutton;
      }

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

      > image {
        padding: 0;
        margin: 0;
        background-color: transparent;
      }

      &.minimize,
      &.maximize {
        &:hover > image {
          background-color: $overlay-hover;
          color: $titlebar-text;
        }

        &:active > image {
          background-color: $overlay-active;
          color: $titlebar-text;
        }
      }

      &.close {
        &:hover > image {
          background-color: $red-300;
          color: on($red-300);
        }

        &:active > image {
          background-color: $red-600;
          color: on($red-600);
        }
      }

      .selection-mode & { @extend %button-on-dark; }
    }
  }

  &.default-decoration {
    background-color: $titlebar;
    min-height: $medium-size;
    padding: 0;

    @if $outline == 'true' and $topbar == 'dark' and $variant == 'light' {
      box-shadow: inset 0 1px highlight($titlebar);
    } @else { box-shadow: none; }

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

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

    windowcontrols {
      > button:not(.suggested-action):not(.destructive-action),
      > menubutton {
        padding: 0;

        @if $titlebutton == "circular" {
          min-height: $small-size;
          min-width: $small-size;
          margin: 0 3px;
        } @else {
          min-height: $medium-size;
          min-width: $medium-size;
          margin: 0;
        }
      }
    }
  }

  .solid-csd & {
    &:dir(rtl), &:dir(ltr) { // specificity bump
      border-radius: 0;
      box-shadow: none; // just remove the highlight
    }
  }
}

// Development versions of apps to use a differently styled headerbar
window.devel {
  headerbar.titlebar {
    $c: $titlebar;
    $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
               linear-gradient(to right, transparent 65%, transparentize($primary, 0.8)),
               linear-gradient(to top, darken($c, 3%), $c 3px, lighten($c, 6%));
    @if $variant == 'dark' {
      $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                 linear-gradient(to right, transparent 65%, transparentize($primary, 0.9)),
                 linear-gradient(to top, lighten($c, 3%) 3px, lighten($c, 5%));
    }

    background: $titlebar $gradient;

    &:backdrop {
      background: $titlebar cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                  image($titlebar); /* background-color would flash */
    }
  }
}


/************
 * Pathbars *
 ************/
%pathbar_button,
pathbar > button {
  @extend %button-flat;

  padding-left: ($medium-size - 12px) / 2;
  padding-right: ($medium-size - 12px) / 2;
  border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                $primary 0%,
                                transparent 0%)
                                0 0 0 / 0 0 0px;
  border-radius: $corner-radius;

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

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

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

  &.text-button {
    min-width: 0;
  }

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

.pathbar {
  background-color: $fill;
  color: $text-secondary;
  border: none;
  border-radius: $corner-radius;
  padding: 2px;

  headerbar & {
    margin-top: $space-size;
    margin-bottom: $space-size;
    background-color: on($titlebar, fill);
    color: $titlebar-text-secondary;
  }

  > button {
    margin-top: 0;
    margin-bottom: 0;
    min-height: 20px;
    border-radius: $corner-radius - 2px;
    border: none;
    box-shadow: none;

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


/**************
 * Tree Views *
 **************/
columnview.view,
treeview.view {
  border-left-color: $solid-border; // this is actually the tree lines color,
  border-top-color: $solid-border; // while this is the grid lines color, better then nothing

  // FIXME: Avoid transparency background-color being slightly darker
  &:selected {
    background-color: $overlay-checked;
    color: $text;
  }

  &:hover, &:selected {
    border-radius: 0;
    box-shadow: none;
  }

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

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

  // FIXME: box-shadow, background-color and background-image are not available here.
  &:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: mix($text, $primary, 50%);

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

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

  > dndtarget:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $overlay-selected;

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

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

  &.expander {
    min-width: 16px;
    min-height: 16px;
    color: $text-secondary;
    -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'); }

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

    &:disabled { color: $text-secondary-disabled; }
  }

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

    &:selected:hover { box-shadow: none; }
  }

  &.trough { // progress bar trough in treeviews
    border-bottom: $bar-size solid $track-disabled;
    box-shadow: none;
    background-color: transparent;
    background-image: none;

    &:selected:hover { box-shadow: none; }
  }

  > header {
    > button {
      @extend %row_activatable;

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

      &:not(:focus):not(:hover):not(:active) { color: $text-secondary; }

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

      &: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: $divider;
    border-radius: 0;
    box-shadow: none;
    background-color: $base;
    background-clip: border-box;
    color: $primary;
  }

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


/*********
 * Menus *
 *********/
menubar {
  padding: 0;
  // box-shadow: inset 0 -1px $divider;
  background-color: $titlebar;
  color: $titlebar-text;

  &:backdrop {
    background-color: $titlebar-backdrop;
    color: $titlebar-text-secondary;
  }

  .csd & { transition: $transition; }

  > item {
    transition: background-color $duration $ease-out;
    min-height: 8px + $space-size * 2;
    padding: ($space-size - 2px) ($space-size + 2px);
    color: $titlebar-text-secondary;

    &:hover { // Seems like it :hover even with keyboard focus
      transition: none;
      background-color: $overlay-checked;
      color: $titlebar-text;
    }

    &:disabled { color: $titlebar-text-secondary-disabled; }

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

  //nested submenus
  & > item popover.menu popover.menu {
    margin-left: $space-size;
  }

  & > item popover.menu.background popover.menu.background > contents {
    margin: 0;
  }
}

/**********************
 * Popover Base Menus *
 **********************/
popover.menu {
  box.inline-buttons {
    padding: 0 $space-size;

    button.image-button.model {
      min-height: $menuitem-size;
      min-width: $menuitem-size;
      padding: 0;
      border: none;
      outline: none;
      transition: none;

      &:selected { background: image($overlay-selected); }
    }
  }

  box.circular-buttons {
    padding: $space-size;

    button.circular.image-button.model {
      @extend %small-button;
      padding: $space-size;

      &:focus {
        background-color: $overlay-selected;
      }
    }
  }

  &.background separator {
    margin: $space-size / 2 0;
  }

  arrow.left,
  radio.left,
  check.left {
    margin-left: 0;
    margin-right: 0;
  }

  arrow.right,
  radio.right,
  check.right {
    margin-left: 0;
    margin-right: 0;
  }

  modelbutton {
    transition: background-color $duration $ease-out;
    min-height: 8px + $space-size * 2;
    min-width: 40px;
    padding: ($space-size - 2px) ($space-size + 2px);
    color: $text;
    font: initial;
    text-shadow: none;

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

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

    &:focus {
      box-shadow: none;
      outline: none;
    }

    &:disabled { color: $text-disabled; }
  }
}


/************
 * Popovers *
 ************/
popover.background {
  font: initial;

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

  > arrow,
  > contents {
    transition: $transition-shadow;
    padding: $space-size;
    box-shadow: $shadow-z6; // TODO: this should really have a highlight
    background-color: $menu;
    border-radius: $menu-radius;
    color: on($menu);

    @if $outline == 'true' {
      @if $variant == 'light' {
        border: none;
        box-shadow: $shadow-z6, 0 0 0 1px $divider;
      } @else {
        border: 1px solid $divider;
        background-clip: border-box;
      }
    }
  }

  &:backdrop {
    > arrow,
    > contents {
      box-shadow: $shadow-z2;
    }
  }

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

    > scrolledwindow > viewport > stack > box { padding: 0; } // reset

    > box > button { margin: 0; }

    separator {
      background-color: $divider;
      margin: $space-size / 2 0;
    }

    list separator { margin: 0; }
  }

  // FIXME: Use the popover color instead of transparent as a workaround for .view
  list,
  .view:not(:selected),
  toolbar { background-color: $surface; }

  listview {
    margin: 0;
    padding: 0;

    > row {
      padding: $space-size $space-size * 2;
      margin: 0;
      border-radius: $corner-radius;

      &:selected {
        color: $text;
        background-color: $overlay-selected;
      }
    }
  }

  .linked > button:not(.radio) {
    border-radius: $corner-radius;

    &:first-child { border-radius: $corner-radius; }
    &:last-child { border-radius: $corner-radius; }
    &:only-child { border-radius: $corner-radius; }
  }

  &.menu button,
  button.model {
    @extend %button-flat;
    min-height: 32px;
    padding: 0 8px;
    border-radius: $corner-radius;

    &:focus {
      box-shadow: none;
      outline: none;
    }

    // &:checked { color: $primary; }
  }

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

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

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

  separator { margin: 4px 0; }
  list separator { margin: 0; }
}

magnifier {
  background-color: $base;
}

/*************
 * Notebooks *
 *************/

$tab-radius: $corner-radius;

%tabs_tab {
  transition: $transition,
              background-size 0ms,
              background-image 0ms;
  min-height: $small-size;
  min-width: $small-size;
  padding: ($space-size / 2) $space-size * 2;
  border: 1px solid transparent;
  border-bottom: 0;
  outline: none;
  background-clip: padding-box;
  color: $text-secondary;
  font-weight: 500;
  box-shadow: none;

  &:hover {
    background-color: if($variant == 'light', $divider, $fill);
    color: $text;
    box-shadow: none;
  }

  &:disabled { color: $text-secondary-disabled; }

  &:checked, &:selected {
    transition: $transition;
    background-clip: padding-box;
    border-color: $solid-border;
    color: $text;
    box-shadow: none;

    &, &:hover {
      background-color: $base;
    }

    &:disabled { color: $text-disabled; }

    &.reorderable-page {
      background-color: $base;
    }
  }
}

notebook {
  frame > paned > & > header,
  &.frame > header { background-color: $base-alt; }

  &, &.frame {
    background-color: $base;
    border-radius: $corner-radius;
  }

  &.frame frame {
    > border {
      border: none;
      border-radius: $corner-radius;
    }

    > list {
      // @extend %circular_list;

      row.activatable { border-radius: $corner-radius; }
    }
  }

  &:focus tab:checked { box-shadow: none; }

  > header {
    border-width: 1px;
    border-color: $divider;
    background-color: $background;
    background-clip: border-box;

    &.top {
      border-bottom-style: solid;
      border-radius: $corner-radius $corner-radius 0 0;

      > tabs {
        margin-bottom: -1px;
        margin-top: $space-size / 2;

        > tab {
          border-radius: $tab-radius $tab-radius 0 0;
          border-bottom: none;
        }
      }
    }

    &.bottom {
      border-top-style: solid;
      border-radius: 0 0 $corner-radius $corner-radius;

      > tabs {
        margin-top: -1px;
        margin-bottom: $space-size / 2;

        > tab {
          border-radius: 0 0 $tab-radius $tab-radius;
          border-top: none;
        }
      }
    }

    &.left {
      border-right-style: solid;
      border-radius: $corner-radius 0 0 $corner-radius;

      > tabs {
        margin-left: $space-size / 2;
        margin-right: -1px;

        > tab {
          border-radius: $tab-radius 0 0 $tab-radius;
          border-right: none;
        }
      }
    }

    &.right {
      border-left-style: solid;
      border-radius: 0 $corner-radius $corner-radius 0;

      > tabs {
        margin-left: -1px;
        margin-right: $space-size / 2;

        > tab {
          border-radius: 0 $tab-radius $tab-radius 0;
          border-left: none;
        }
      }
    }

    &.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 %button-flat-simple;

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

    tab {
      @extend %tabs_tab;

      // FIXME: The tab node doesn't have :drop(active), instead its child box has it.
      > box {
        transition: background-color $duration $ease-out;
        margin: -$space-size -12px;
        padding: $space-size 12px;

        &:drop(active) {
          background-color: $divider;
          color: $text;
        }
      }

      // colors the button like the label, overridden otherwise
      button.flat {
        min-width: 18px;
        min-height: 18px;
        padding: 0 0;
        margin: 2px 0;

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

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

    &.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 { border-style: 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 { border-style: solid; }
      }
    }
  }

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

tabbar {
  .box {
    min-height: $medium-size;
    border-bottom: none;
    background-color: $background;
    background-clip: border-box;
    box-shadow: inset 0 -1px $divider;
    padding: 0;
  }

  &:backdrop .box {
    background-color: $background;

    > scrolledwindow,
    > .start-action,
    > .end-action {
      filter: opacity(0.5);
    }
  }

  tabbox {
    padding: 0;
    margin: 0;

    > tabboxchild {
      padding: 0;
      margin: 0;
    }

    tab {
      @extend %tabs_tab;
      padding: $space-size / 2 $space-size;
      border-bottom: none;
      margin-bottom: -1px;
    }

    .start-action,
    .end-action {
      padding: $space-size;
    }

    .start-action:dir(ltr),
    .end-action:dir(rtl) {
      padding-right: 0;
    }

    .start-action:dir(rtl),
    .end-action:dir(ltr) {
      padding-left: 0;
    }
  }
}


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

  transition: $transition;
  background-color: $base;
  outline: none;

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

  // slider
  > range > trough {
    background: none;
    border: none;
    outline: none;
    padding: 0;
    margin: 0;

    > slider {
      transition: background-color $duration $ease-out;
      min-width: if($window == 'round', $space-size, ($space-size + 4px));
      min-height: if($window == 'round', $space-size, ($space-size + 4px));
      border: none;
      border-radius: if($window == 'round', $circular_radius, 0);
      background-clip: padding-box;
      background-color: $track;
      box-shadow: none;
      outline: none;

      &:hover { background-color: $text-secondary-disabled; }

      &:active { background-color: $text-disabled; }

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

  &.horizontal > range > trough > slider { margin: $space-size / 2 0; }

  &.vertical > range > trough > slider { margin: 0 $space-size / 2; }

  > range.fine-tune {
    > trough > slider {
      min-width: 4px;
      min-height: 4px;
    }

    &.horizontal > trough > slider { margin: $space-size / 2 0; }

    &.vertical > trough > slider { margin: 0 $space-size / 2; }
  }

  &.overlay-indicator {
    &:not(.fine-tune) > range > trough > slider {
      transition-property: background-color, min-height, min-width;
    }

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

      > range > trough > slider {
        min-width: 4px;
        min-height: 4px;
        margin: if($window == 'round', 0, $space-size / 2);
        border: 1px solid rgba($base, 0.3);
      }

      button {
        min-width: 4px;
        min-height: 4px;
        margin: 3px;
        border: 1px solid rgba($base, 0.3);
        border-radius: $circular-radius;
        background-color: $text-disabled;
        background-clip: padding-box;
        -gtk-icon-source: none;

        &:disabled { background-color: $text-secondary-disabled; }
      }

      &.horizontal {
        > range > trough > 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($surface, 0.9); }
  }

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

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

  // button styling
  button {
    @extend %button-flat-simple;

    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: all $duration $ease-out;
  min-width: $small-size;
  margin: $space-size 0;
  padding: 0;
  border: 0 solid transparent;
  border-radius: $circular-radius;
  background-color: transparent;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px $text-disabled;
  font-size: 0;
  color: transparent;

  &:hover { box-shadow: inset 0 0 0 1px $text-secondary; }

  &:checked {
    box-shadow: none;
    background-color: $primary;

    &:hover {
      box-shadow: none;
      background-color: lighten($primary, 5%);
    }
  }

  &:disabled { opacity: 0.5; }

  // hide on/off icons for >=3.24.5
  image { margin: -8px; }

  > slider {
    transition: all $duration $ease-out;
    min-width: $space-size + 6px;
    min-height: $space-size + 6px;
    margin: 5px;
    border-radius: $circular-radius;
    outline: none;
    box-shadow: none;
    background-color: $text-secondary;
  }

  &:checked > slider {
    background-color: on($primary);
    color: on($primary);
  }
}


/*************************
 * 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
checkbutton.selection-mode {
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  background-color: transparent;
  background-image: none;
  -gtk-icon-shadow: $icon-shadow-z2;

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

  check, radio {
    padding: 0;
    border-radius: 0;
  }

  label {
    &:dir(ltr) { margin-right: $space-size; }
    &:dir(rtl) { margin-left: $space-size; }
  }

  @each $s, $as in ('', '-unchecked'),
                   (':checked', '-checked') {
    check#{$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;
  border-spacing: 4px;
}

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 {
  min-height: 24px;
  min-width: 24px;
  @extend %button-flat-simple;
  transition: background-image 0;

  &, &:hover, &:focus {
    background: none;
    box-shadow: none;
    transition: color $duration $ease-out;
  }

  &:checked, &:indeterminate {
    color: $primary;
    background-image: image(on($primary));
    background-size: 12px 12px;
    background-position: center center;
    background-repeat: no-repeat;
    animation: none;
    transition: background-image 0;

    &:hover {
      color: darken($primary, 10%);
    }

    &:disabled {
      color: $text-secondary-disabled;
      background-image: none;
    }
  }

  &:not(:hover):focus { box-shadow: inset 0 0 0 9999px transparent; }

  popover modelbutton.flat & {
    &, &:focus, &:hover, &: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;
    }

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

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

  popover.menu & {
    transition: none;
    margin: 0; // this is a workaround for a menu check/radio size allocation issue
    padding: 0;
    background-size: 10px 10px;

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

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

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

  treeview.view & {
    padding: 0;
    color: $text-secondary;

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

    &:disabled { color: $text-secondary-disabled; }

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

    &:checked:disabled, &:indeterminate:disabled { color: $text-secondary-disabled; }

    &:hover, &:focus, &:selected, &:selected:hover, &:checked:hover, &:indeterminate:hover {
      box-shadow: none;
      background-color: transparent;
    }
  }
}

%check,
check {
  -gtk-icon-size: 24px;
  -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-size: 24px;
  -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")); }
}

%small_check,
popover.menu check {
  & {
    min-height: 16px;
    min-width: 16px;
    -gtk-icon-size: 16px;
    border-radius: $corner-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,
popover.menu radio {
  & {
    min-height: 16px;
    min-width: 16px;
    -gtk-icon-size: 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")); }
}

treeview.view radio:checked,
columnview.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: 26px;

  $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 backing bit
  > trough {
    transition: background-color $duration $ease-out;
    outline: none;
    background-color: $track;

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

  // the colored part of the backing bit
  > trough > highlight {
    transition: background-image $duration $ease-out;
    background-image: image($primary);

    &:disabled {
      background-color: $background;
      background-image: image($text-secondary-disabled);
    }
  }

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

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

  > trough > slider {
    min-height: $slider_size;
    min-width: $slider_size;
    margin: $slider_margin;
    box-shadow: none;
    outline: none;
    border: none;
    background-color: transparent;
    transition: background-image $duration $ease-out;
    border-radius: 50%;
    color: $primary;
    background-repeat: no-repeat;
    background-size: auto;
    background-position: center;

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

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

  // 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
    > trough > slider { margin: $finetune_slider_margin; }
  }

  > marks,
  > value { color: $text-secondary; }

  indicator {
    background-color: $track;
    color: transparent;
  }

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

    &.#{$scale_orient}.fine-tune marks {
      &.#{$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 {
          transform: none;
          min-height: 38px;
          min-width: 38px;
          margin: -18px;
          border-radius: 50%;
          background-color: transparent;

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

          &:active {
            $_scale_asset: 'assets/scale-#{$dir_infix}-#{$marks_infix}-slider#{$asset-suffix}';

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

  &.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 {
      min-width: 150px;
      &, > progress { min-height: $bar-size; }
    }
  }

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

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

  > trough {
    border-radius: $corner-radius;
    background-color: $track-disabled;
  }

  > trough > progress {
    border-radius: $corner-radius;
    background-color: $primary;
  }

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

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

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

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


/*************
 * Level Bar *
 *************/
levelbar {
  &.horizontal {
    trough > block { min-height: $bar-size; }

    &.discrete trough > block {
      min-width: $medium-size;

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

  &.vertical {
    trough > block { min-width: $bar-size; }

    &.discrete trough > block {
      min-height: $medium-size;

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

  // imitate the entry style
  > trough {
    // padding: 2px;
    border-radius: $corner-radius;
  }

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

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

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

    &.empty { background-color: $track-disabled; }
  }
}


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

    paper {
      padding: 0;
      border: 1px solid $divider;
      background-color: $base;
      color: $text;
    }
  }

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


/**********
 * Frames *
 **********/

%frame {
  margin: 0;
  padding: 0;
  border: 1px solid $divider;
  border-radius: 0;
  box-shadow: none;
}

frame,
.frame {
  @extend %frame;

  > list { border: none; }

  &.view { border-radius: $corner-radius; }

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

frame {
  border-radius: $corner-radius;

  > label {
    margin: 4px;
  }

  &.flat > border,
  statusbar & > border { border: none; } // for backward compatibility
}

actionbar > revealer > box {
  padding: $space-size;
  border-spacing: $space-size;
  border-top: 1px solid $divider;
  background-color: $base;
  background-clip: border-box;
  box-shadow: none;

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

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

  stack &.frame {
    // border-radius: $corner-radius;

    viewport.frame list { border: none; }
  }

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

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

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

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

  &.undershoot-top {
    @include undershoot(top);
  }

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

  &.undershoot-start {
    &:dir(ltr) { @include undershoot(left); }
    &:dir(rtl) { @include undershoot(right); }
  }

  &.undershoot-end {
    &:dir(ltr) { @include undershoot(right); }
    &:dir(rtl) { @include undershoot(left); }
  }
}

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

  &.spacer {
    min-width: 0;
    min-height: 0;
    background-color: transparent;
  }
}

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


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

listview,
list {
  border-color: $divider;
  background-color: $base;
  color: $text;
  box-shadow: none;

  row { padding: 2px; }

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

row {
  @at-root %row_activatable, &.activatable {
    transition: $transition;
    outline: none;
    box-shadow: inset 0 0 0 2px transparent;
    color: $text-secondary;

    &:focus:not(:selected) {
      box-shadow: inset 0 0 0 2px $overlay-focus;
      color: $text;
    }

    &:hover:not(:active):not(.has-open-popup) {
      transition: $transition,
                  box-shadow 0ms;
      background-color: $overlay-hover;
      box-shadow: none;
      color: $text;
    }

    &.has-open-popup,
    &:active {
      transition: $transition;
      background-color: $overlay-active;
      box-shadow: none;
      color: $text;
    }
  }

  &:selected {
    @extend %selected_items;
    color: inherit; // for overlays

    image,
    label { color: $text; }

    button image,
    button label { color: inherit; }

    &:disabled {
      image,
      label { color: $text-disabled; }
    }
  }
}

treeexpander {
  border-spacing: 4px;
}

columnview {
  row:not(:selected) cell editablelabel {
    &:not(.editing):focus-within {
      outline: 2px solid $overlay-selected;
    }

    &.editing:focus-within {
      outline: 2px solid $primary;
    }

    &.editing text selection {
      color: on($primary);
      background-color: $primary;
    }
  }
}

.rich-list { /* rich lists usually containing other widgets than just labels/text */
  & > row {
    padding: $space-size * 1.5 $space-size * 2;
    min-height: $medium-size; /* should be tall even when only containing a label */

    & > box {
      border-spacing: $space-size * 2;
    }
  }
}

/*********************
 * App Notifications *
 *********************/
.app-notification {
  @extend %toolbar_osd;
  margin: $space-size;
  border-spacing: 0;
  padding: 0;
  border: none;

  button {
    @extend %button-flat;

    &.text-button:not(:disabled) { color: $primary; }
  }

  > box > label { margin-left: $space-size; }

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


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

expander {
  transition: all $duration $ease-out;
  min-width: 16px;
  min-height: 16px;
  color: $text-secondary;
  -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'); }

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

  &:disabled { color: $text-secondary-disabled; }
}

expander-widget {
  > box > title {
    border-radius: $corner-radius;

    &:hover > expander {
      color: $text-secondary; //only lightens the icon
    }
  }
}

.navigation-sidebar,
placessidebar,
stackswitcher,
expander-widget {
  &:not(decoration):not(window):drop(active):focus,
  &:not(decoration):not(window):drop(active) {
    box-shadow: none;
  }
}

/************
 * Calendar *
 ************/

calendar {
  padding: 0;
  border: 1px solid $divider;
  border-radius: $corner-radius;
  color: $text;

  &:disabled { color: $text-disabled; }

  &:selected {
    @extend %selected_items;

    border-radius: $corner-radius;
  }

  > header {
    padding: $space-size / 2;
    border-bottom: 1px solid $divider;

    > button {
      min-height: $small-size;

      @extend %button-flat-simple;
    }
  }

  > grid {
    margin: $space-size / 2;

    > label {
      border-radius: $circular-radius;
      margin: 0;
    }

    > label.today {
      @extend %selected_items_color;

      &:selected {
        box-shadow: none;
        @extend %selected_items_primary;
      }
    }

    > label:focus {
      outline-style: none;
    }

    > label.day-number {
      padding: $space-size*1.5;

      &:selected {
        @extend %selected_items;
      }
    }

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


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

window.dialog.message { // Message Dialog styling
  &.background { background-color: $surface; }

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

  .titlebar {
    min-height: $small-size;
    border-style: none;
    box-shadow: inset 0 1px highlight($surface);
    background-color: $surface;
    color: $text;

    &:backdrop {
      background-color: $surface;
      color: $text-secondary;
    }
  }

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

    .dialog-action-area {
      margin-top: -$space-size;
      // padding: $space-size;

      > button {
        @extend %button-flat;

        &, &:first-child, &:last-child { border-radius: $corner-radius; }

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

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

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

filechooser {
  .csd & {
    background-color: $base;
    border-radius: 0 0 $window-radius $window-radius;
  }

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

  #pathbarbox {
    border-bottom: 1px solid $divider;
    background-color: $background;

    > stack > box > button { // The new folder button
      @extend %button-flat;
      @extend %circular-button;
    }
  }
}

filechooserbutton > button > box {
  border-spacing: $space-size;
}

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

// aboutdialog
window.aboutdialog {
  stack scrolledwindow.frame {
    &,
    & > .view,
    & > .view > text {
      border-radius: $corner-radius;
    }
  }

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

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

.sidebar {
  border-style: none;
  background-color: $base-alt;

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

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

  list { background-color: transparent; }

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

stacksidebar {
  + separator.vertical,
  separator.horizontal { @extend %hide_separators; }

  list {
    padding: 0;
    background-color: $base-alt; // This should not be necessary, but the parent stacksidebar ignores background-color.
  }

  row {
    min-height: 32px;
    padding: 0 8px - 6px;
    border-radius: $bar-size;

    &:selected {
      background-color: $overlay-checked;
      color: $primary;
      font-weight: 500;
    }

    + row { margin-top: 4px; }

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

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

separator.sidebar {
  background-color: $divider;
}

/**********************
 * Navigation Sidebar *
 **********************/

.navigation-sidebar {
  padding: $space-size 0; //only vertical padding. horizontal row size would clip
  border-right: none;

  > row {
    min-height: $medium-size;
    padding: $space-size $space-size * 1.5;
    border-radius: $corner-radius;
    margin: 2px $space-size;

    &:selected {
      background-color: $overlay-checked;
      color: $text;
      font-weight: 500;
      background-image: url("assets/selected-line.png"), url("assets/selected-line@2.png");
      background-position: ($space-size / 2) center;
      background-repeat: no-repeat;
      background-size: 3px 16px;

      &:hover {
        background-color: $overlay-focus-hover;
      }

      &:focus-visible:focus-within {
        outline: none;
        background-color: $overlay-focus;

        &:hover { background-color: $overlay-focus-hover; }
      }
    }

    &:disabled { color: $text-disabled; }
  }

  > separator {
    background-color: $border;
    margin: $space-size 0;
  }
}

/****************
 * File chooser *
 ****************/
// dim the sidebar icons, see bug #786613 for details on this oddity
row image.sidebar-icon {
  transition: color $duration $ease-out;
  color: $text-secondary;

  &:disabled { color: $text-secondary-disabled; }
}

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

  list { padding: $space-size 0; }

  .navigation-sidebar > row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: $medium-size;
    margin: 0 $space-size; // Remove unwanted hard-coded vertical margins with -1px
    padding: 0;
    border-radius: $corner-radius;
    transition: background-image 0, box-shadow 0;

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

    &:selected {
      background-color: $overlay-checked;
      color: $text;
      font-weight: 500;
      background-image: url("assets/selected-line.png"), url("assets/selected-line@2.png");
      background-position: ($space-size / 2) center;
      background-repeat: no-repeat;
      background-size: 3px 20px;
      transition: background-image 0, box-shadow 0;
    }

    &:disabled { color: $text-disabled; }

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

    label.sidebar-label {
      color: inherit;

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

    button.sidebar-button {
      @extend %button-flat-simple;
      @extend %small-button;
    }

    &.sidebar-placeholder-row { background-color: $overlay-hover; }

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

      image.sidebar-icon { color: $primary; }
    }

    &:drop(active) {
      transition: $transition,
                  box-shadow 0ms;
      box-shadow: inset 0 0 0 9999px $overlay-hover;
    }
  }
}

placesview {
  .server-list-button > image {
    transition: 200ms $ease-out;
    -gtk-icon-transform: rotate(0turn);
  }

  .server-list-button:checked > image {
    transition: 200ms $ease-out;
    -gtk-icon-transform: rotate(-0.5turn);
  }

  // this selects the "connect to server" label
  > actionbar > revealer > box > label {
    border-spacing: $space-size;
  }
}


/*********
 * 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($divider);
    background-size: 1px 1px;
    background-clip: content-box; // avoids borders image being rendered twice (?)

    &.wide {
      min-width: 6px;
      min-height: 6px;
      background-color: $background;
      background-image: image($divider), image($divider);
      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;
    }
  }
}

/************
 * GtkVideo *
 ************/

video {
  & image.osd {
    min-width: 64px;
    min-height: 64px;
    border-radius: $circular-radius;
    border: none;
  }

  background: black;
  border-radius: $corner-radius;
}

/**************
 * GtkInfoBar *
 **************/
infobar {
  border: none;
  margin-bottom: 0;

  > revealer > box {
    padding: $space-size;
    border-spacing: $space-size * 2;
  }

  &.info {
    & > revealer > box,
    &:hover > revealer > box,
    &:backdrop > revealer > box {
      background-color: $base;
      color: $text;

      button {
        &, &.text-button:not(:disabled) { color: $primary; }
      }
    }
  }

  &.action,
  &.question {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $primary;
      color: on($primary);

      button {
        @extend %button-on-dark;

        &, &:hover, &:focus, &:active, &:checked, &.text-button:not(:disabled) { color: on($primary); }
      }

      *:link { color: on($primary); }
    }
  }

  &.warning {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $warning;
      color: on($warning);

      button {
        @extend %button-on-dark;

        &, &:hover, &:focus, &:active, &:checked, &.text-button:not(:disabled) { color: on($warning); }
      }

      *:link { color: on($warning); }
    }
  }

  &.error {
    & > revealer > box,
    &:backdrop > revealer > box {
      background-color: $error;
      color: on($error);

      button {
        @extend %button-on-dark;

        &, &:hover, &:focus, &:active, &:checked, &.text-button:not(:disabled) { color: on($error); }
      }

      *:link { color: on($error); }
    }
  }
}


/************
 * Tooltips *
 ************/
tooltip {
  &.background {
    // background-color needs to be set this way otherwise it gets drawn twice
    // see https://bugzilla.gnome.org/show_bug.cgi?id=736155 for details.
    background-color: $tooltip;
    color: on($tooltip);
    box-shadow: $shadow-z4;
    border-radius: $window-radius;
    margin: 2px 6px 8px 6px;
  }

  padding: $space-size $space-size * 2;
  box-shadow: none; // otherwise it gets inherited by windowframe.csd
  border: none;

  > box {
    border-spacing: $space-size;
  }
}


/*****************
 * 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: $menu-radius;
    border-top-right-radius: $menu-radius;

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

  &.bottom {
    border-bottom-left-radius: $menu-radius;
    border-bottom-right-radius: $menu-radius;

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

  &.left,
  &:first-child:not(.top) {
    border-top-left-radius: $menu-radius;
    border-bottom-left-radius: $menu-radius;

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

  &.right,
  &:last-child:not(.bottom) {
    border-top-right-radius: $menu-radius;
    border-bottom-right-radius: $menu-radius;

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

  &.dark { color: on(dark); }

  &.light { color: on(light); }

  &#add-color-button {
    border-radius: $menu-radius $menu-radius 0 0;
    color: $text;

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

    overlay {
      background-color: $surface;
    }
  }

  &:disabled {
    opacity: 0.5;

    overlay { box-shadow: none; }
  }

  &#editor-color-sample {
    border-radius: $menu-radius;

    overlay { border-radius: $menu-radius; }
  }
}

// colorscale popup
colorchooser .popover.osd {
  transition: $transition-shadow;
  border-radius: $corner-radius;
  box-shadow: $shadow-z4, inset 0 1px highlight($surface);
  background-color: $surface;

  &:backdrop { box-shadow: $shadow-z2, inset 0 1px highlight($surface); }
}


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

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

window {
  border: none;

  &.csd {
    border-radius: $window-radius;
    margin: 0;
    outline: none;
    transition: none;

    @if $outline == 'false' {
      box-shadow: $shadow-z16, 0 0 0 36px transparent;
    } @else {
      box-shadow: $shadow-z16, 0 0 0 1px $divider, 0 0 0 36px transparent;
    }
  
    &:backdrop {
      transition: $transition-shadow;

      // 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.
  
      @if $outline == 'false' {
        box-shadow: $shadow-z4, 0 0 0 36px transparent;
      } @else {
        box-shadow: $shadow-z4, 0 0 0 1px $divider, 0 0 0 36px transparent;
      }
    }

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

    &.tiled,
    &.tiled-top,
    &.tiled-right,
    &.tiled-bottom,
    &.tiled-left {
      @if $outline == 'false' {
        box-shadow: 0 0 6px rgba(black, 0.1);
      } @else {
        box-shadow: 0 0 6px rgba(black, 0.1), 0 0 0 1px $divider;
      }

      &:backdrop {
        @if $outline == 'false' {
          box-shadow: 0 0 6px rgba(black, 0.05);
        } @else {
          box-shadow: 0 0 6px rgba(black, 0.05), 0 0 0 1px $divider;
        }
      }
    }

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

  &.solid-csd {
    margin: 0;
    padding: 2px;
    border-radius: 0;
    border: none;
    box-shadow: none;
    box-shadow: inset 0 1px highlight($titlebar);
    background-color: $titlebar;

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

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

  &.ssd {
    @if $outline == 'false' {
      box-shadow: none;
    } @else {
      box-shadow: 0 0 0 1px $divider;
    }
  }
}

// catch all extend :)

%selected_items {
  background-color: $overlay-selected;
}

%selected_items_color {
  color: $primary;
  background-color: rgba($primary, 0.2);
}

%selected_items_primary {
  color: on($primary);
  background-color: $primary;
}

.monospace { font-family: monospace; }


/**********************
 * Touch Copy & Paste *
 **********************/
// touch selection handlebars for the Popover.osd above
cursor-handle {
  color: $primary;
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/cursor-handle-symbolic.svg"));

  &.insertion-cursor:dir(ltr), &.insertion-cursor:dir(rtl) {
    padding-top: 6px;
  }
}

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

// shortcut window keys
shortcuts-section {
  margin: 20px;
}

.shortcuts-search-results {
  margin: 20px;
  border-spacing: 24px;
}

shortcut {
  border-spacing: 6px;
}

shortcut > .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 $divider;
  border-radius: $corner-radius + 1px;
  box-shadow: inset 0 -2px $divider;
  background-color: $surface;
  color: $text;
  font-size: smaller;
}

:not(decoration):not(window):drop(active) { // FIXME needs to be done widget by widget, this wildcard should really die
  caret-color: $primary;
}

stackswitcher {
  min-height: 0;
  padding: 0;
  margin: $space-size 0;
  border-radius: $corner-radius;
  background-color: $overlay-normal;

  &.linked:not(.vertical) > button:not(.suggested-action):not(.destructive-action) {
    margin: 0 0;
    border-radius: $corner-radius;
    background-color: transparent;
    border: none;

    &.text-button { min-width: 100px; }

    &:focus { box-shadow: inset 0 0 0 2px $overlay-focus; }

    &:active {
      box-shadow: inset 0 0 0 9999px gtkalpha($primary, 0.08);
      background-image: radial-gradient(circle, gtkalpha($primary, 0.08) 10%, transparent 0%);
    }

    &:checked {
      background-color: $primary;
      color: on($primary);
    }
  }

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

  &.circular {
    border-spacing: $space-size * 2;

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


/*************
 * App Icons *
 *************/
// Outline for low res icons
.lowres-icon {
  -gtk-icon-shadow: $shadow-z3;
}

// Drapshadow for large icons
.icon-dropshadow {
  -gtk-icon-shadow: $shadow-z6;
}


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

  > contents {
    padding: 0;
  }
}

.emoji-searchbar {
  padding: $space-size;
  border-spacing: $space-size;
  border-bottom: 1px solid $divider;
  background: none;

  entry {
    text {
      background: none;
      box-shadow: none;
    }
  }
}

.emoji-toolbar {
  padding: 0;
  border-spacing: $space-size/2;
  border-top: 1px solid $divider;
  background: none;
}

button.emoji-section {
  margin: 0;
  padding: $space-size;
  border-radius: $corner-radius;

  &:checked {
    color: $primary;
  }
}

popover.emoji-picker emoji {
  font-size: x-large;
  padding: $space-size;
  transition: $transition;
  border-radius: $corner-radius;

  &:focus,
  &:hover {
    background: $overlay-hover;
  }
}

emoji-completion-row {
  min-height: $menuitem-size;
  padding: 0 $space-size*2;

  > box {
    border-spacing: $space-size;
    padding: 2px $space-size;
  }

  &:focus, &:hover,
  emoji:hover, emoji:focus {
    background-color: $overlay-hover;
    color: $text;
  }
}

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

statusbar {
  padding: $space-size $space-size * 2;
}
