/**
 * Base States
 */

.background {
  background-color: $surface-z0;
  color: $on-surface;
}

dnd {
  color: $on-surface;
}

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

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

image:disabled {
  -gtk-icon-filter: opacity(0.5);
}

.view {
  // background-color: $surface-z1;
  // color: $on-surface;

  > .cell:hover {
    background-color: overlay("hover-alt", $on-surface);
  }

  &:disabled {
    color: disabled($on-surface);
  }

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

    > .cell:selected:hover {
      background-color: overlay("hover-alt", $primary, $on: $overlay-selected);
    }
}

textview {
  caret-color: $primary;

  > text {
    > selection {
      background-color: $overlay-selected;
    }
  }

  > border {
    // background-color: $surface-z1-alt;
    color: hint($on-surface); // FIXME: not working
  }
}

iconview {
  > .cell {
    border-radius: $corner-radius;
  }

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

  > dndtarget:drop(active) {
    box-shadow: inset 0 0 0 2px $primary;
  }
}

%iconview-desktop {
  // background-color: $scrim;
  color: $on-dark;
  text-shadow: $text-shadow;

  > rubberband {
    border: 1px solid primary($on-dark);
    background-color: rgba(primary($on-dark), .24);
  }
}

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

flowbox {
  padding: 4px;
  border-spacing: 4px;

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

    @extend %ripple;
    @include ink-color($on-surface, $hover-alt: true);

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

      @include ink-color($primary, $hover-alt: true, $on: $overlay-selected);
    }
  }
}

gridview {
  padding: 4px;
  border-spacing: 4px;

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

    @extend %ripple;
    @include ink-color($on-surface, $hover-alt: true);

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

      @include ink-color($primary, $hover-alt: true, $on: $overlay-selected);
    }
  }
}

coverflow > cover {
  box-shadow: $shadow-z2;
  background-color: $surface-z8;
  color: $on-surface;
}

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

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

label {
  caret-color: $primary;

  &.separator {
    color: hint($on-surface);
  }

  &.error {
    color: $error;
  }

  > selection {
    background-color: $overlay-selected;
  }

  &:disabled {
    color: disabled($on-surface);

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

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

.dim-label {
  color: hint($on-surface);
}

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

    > label {
      min-height: $medium-size;
      padding: 0 12px;
      color: disabled($on-surface);
      font-weight: 500;

      &.highlight {
        color: $on-surface;
      }
    }
  }
}

window.aboutdialog > box > box > image.large-icons {
  -gtk-icon-size: 128px;
}

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

/**
 * Spinner Animation
 */

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

spinner {
  // background: none;
  opacity: 0; // non spinning spinner makes no sense
  color: $primary;
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');
  transition: opacity $duration * 4 $ease-out;
  animation: spin 1s linear infinite;

  &:checked {
    opacity: 1;
  }

  &:disabled {
    color: disabled-hint($on-surface);
  }
}

/**
 * General Typography
 */

@function pt($size: $font-size) {
  @return ($size * .75 / 1px) * 1pt;
}

.large-title {
  font-weight: 400;
  font-size: pt(48px);
}

.title-1 {
  font-weight: 400;
  font-size: pt(34px);
  letter-spacing: pt(.25px);
}

.title-2 {
  font-weight: 400;
  font-size: pt(24px);
}

.title-3 {
  font-weight: 500;
  font-size: pt(20px);
  letter-spacing: pt(.15px);
}

.title-4 {
  font-weight: 400;
  font-size: pt(16px);
  letter-spacing: pt(.5px);
}

.heading {
  font-weight: 500;
  font-size: 1em;
}

.body {
  font-weight: 400;
  font-size: 1em;
}

.caption-heading {
  font-weight: 500;
  font-size: pt(12px);
  letter-spacing: pt(1.5px);
}

.caption {
  font-weight: 400;
  font-size: pt(12px);
  letter-spacing: pt(.4px);
}

/**
 * Text Entries
 */

%entry,
entry {
  min-height: $medium-size;
  padding: 0 8px;
  border-spacing: $container-padding;
  border-radius: $corner-radius $corner-radius 0 0;

  @include entry(normal);

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

  &:focus-within {
    @include entry(checked);

    > text > placeholder {
      opacity: 0;
    }
  }

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

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

  > text {
    > placeholder {
      color: hint($on-surface);
    }

    > selection {
      background-color: $overlay-selected;
    }

    > block-cursor {
      background-color: $primary;
      color: $on-primary;
    }

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

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

  // icons inside the entry
  > image {
    min-width: $small-size;
    min-height: $small-size;
    border-radius: $circular-radius;
    @extend %ripple;
    @include ink-color($on-surface);
    color: hint($on-surface);
    margin-top: $container-padding;
    margin-bottom: $container-padding;

    &:disabled {
      color: disabled($on-surface);
    }

    &.left {
      margin-left: ($medium-size - $small-size) / 2 - 8px;
    }

    &.right {
      margin-right: ($medium-size - $small-size) / 2 - 8px;
    }
  }

  &.password > image.caps-lock-indicator {
  }

  // entry error and warning style
  @each $class, $color in (".error": $error, ".warning": $warning) {
    &#{$class} {
      @include entry(normal, $color);

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

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

  .osd & {
  }

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

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

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

%entry_raised {
  border-radius: $corner-radius;

  @include entry(raised-normal);

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

  &:drop(active) {
    @include entry(raised-hover);
  }

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

  // entry error and warning style
  @each $class, $color in (".error": $error, ".warning": $warning) {
    &#{$class} {
      @include entry(raised-normal, $color);

      &:focus-within {
        @include entry(raised-focus, $color);
      }

      &:disabled {
        @include entry(raised-disabled, $color);
      }

      image {
        color: hint(on($color));

        &:hover,
        &:active {
          color: on($color);
        }

        &:disabled {
          color: disabled(on($color));
        }
      }
    }
  }
}

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

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

.entry-tag {
  margin: 2px;
  border-radius: $circular-radius;
  box-shadow: none;
  background-color: fill($on-surface);
  color: $on-surface;

  &:hover {
    background-image: image(overlay("hover", $on-surface));
  }

  // 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;
    color: hint($on-surface);
  }
}

/**
 * Buttons
 */

// stuff for .needs-attention
@keyframes needs-attention {
  from {
    background-image: radial-gradient(farthest-side, $primary 0%, transparent 0%);
  }

  to {
    background-image: radial-gradient(farthest-side, $primary 100%, transparent 100%);
  }
}

%button,
button {
  min-height: 24px;
  min-width: 16px;
  padding: ($medium-size - 24px) / 2 ($medium-size - 16px) / 2;
  border-radius: $corner-radius;
  background-color: $surface-z8;
  color: $on-surface;
  font-weight: 500;

  @extend %ripple;
  @include ink-color($on-surface, $on: $surface-z8, $button-style: "raised");

  &:disabled {
    box-shadow: none;
    background-color: fill($on-surface);
    color: disabled($on-surface);
  }

  &:checked {
    $background-color: overlay("activated", $primary, $on: $surface-z8);
    color: $primary;
    @include ink-color($primary, $on: $background-color, $button-style: "raised");

    &:disabled {
      box-shadow: none;
      background-color: overlay("activated", $on-surface, $on: fill($on-surface));
      color: disabled($on-surface);
    }
  }

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

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

  // NOTE: Some image-only buttons use this as well
  &.text-button.image-button {
    min-width: 64px - 16px * 2;
    padding-left: 16px;
    padding-right: 16px;
    // 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;
      }
    }

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

    image {
      &:first-child {
        margin-left: 12px - 16px;
        margin-right: 8px;
      }

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

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

    &.image-button:not(.text-button) {
      // @extend %linked-image-button;
    }
  }

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

    &.image-button:not(.text-button) {
      // @extend %linked-vertical-image-button;
    }
  }
}

%button-outlined {
  background-color: transparent;
  @include ink-color($on-surface, $hover-alt: true, $button-style: "outlined");
}

%button-flat-basic {
  background-color: transparent;
  color: hint($on-surface);
  @include ink-color($on-surface, $button-style: "flat");

  &:disabled {
    background-color: transparent;
    color: disabled-hint($on-surface);
  }
}

%button-flat-activatable {
  @extend %button-flat-basic;

  &:checked {
    $background-color: overlay("activated", $primary);
    color: $primary;
    @include ink-color($primary, $on: $background-color, $button-style: "flat");

    &:disabled {
      color: disabled($on-surface);
    }
  }
}

%button-flat,
button.flat {
  @extend %button-flat-activatable;

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

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

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

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

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

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

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

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

    &:disabled {
      opacity: 0;
    }
  }

  // overlay / OSD style
  @at-root %osd_button,
  .osd & {
  }

  // Suggested and Destructive Action buttons
  @each $class, $color in (".suggested-action": $primary, ".destructive-action": $error) {
    &#{$class} {
      background-color: $color;
      color: on($color);
      @include ink-color(on($color), $on: $color, $button-style: "raised");

      &:disabled {
        box-shadow: none;
        background-color: fill($on-surface);
        color: disabled($on-surface);
      }

      &:checked {
        background-color: overlay("activated", on($color), $on: $color);
      }

      &.flat {
        background-color: transparent;
        @include ink-color($color);

        &:disabled {
          box-shadow: none;
          background-color: transparent;
          color: disabled-hint($on-surface);
        }

        &:checked {
          background-color: overlay("activated", $color);
        }
      }

      .osd & {
      }
    }
  }

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

  &.font > box {
    border-spacing: 6px;

    > box {
      > separator {
        @extend %hide_separators;
      }

      > label {
        // font-weight: bold;
      }
    }
  }

  // force circular button shape
  &.close,
  menubutton.circular > &,
  &.circular {
    border-radius: $circular-radius;
  }
}

%button-small {
  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:not(stackswitcher) {
  border-spacing: $container-padding;
}

.linked:not(.vertical) > button.radio {
  border-radius: 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;
  }

  &:not(:first-child) {
    margin-left: -$container-padding;
  }
}

.linked.vertical > button.radio {
  border-radius: 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;
  }

  &:not(:first-child) {
    margin-top: -$container-padding;
  }
}

%linked-not-first-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

%linked-not-last-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

%linked {
  &:not(:first-child) {
    @extend %linked-not-first-child;
  }

  &:not(:last-child) {
    @extend %linked-not-last-child;
  }
}

%linked-vertical-not-first-child {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

%linked-vertical-not-last-child {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

%linked-vertical {
  &:not(:first-child) {
    @extend %linked-vertical-not-first-child;
  }

  &:not(:last-child) {
    @extend %linked-vertical-not-last-child;
  }
}

%linked-image-button {
  &: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;
  }

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

%linked-vertical-image-button {
  &: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;
  }

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

/* menu buttons */
modelbutton.flat {
  // min-height: $menuitem-size;
  // padding: 0 8px;
  // border-radius: $corner-radius;

  @extend %ripple;
  @include ink-color($on-surface);

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

modelbutton.flat arrow {
  min-width: 16px;
  min-height: 16px;
  color: hint($on-surface);

  &:disabled {
    color: disabled-hint($on-surface);
  }

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

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

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

menubutton {
  > button > box > arrow {
    min-height: 16px;
    min-width: 16px;

    &.none {
      -gtk-icon-source: -gtk-icontheme('open-menu-symbolic');
    }

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

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

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

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

/**
 * Links
 */

link {
  color: $primary;

  &:visited {
    color: $visited;
  }
}

button.link {
  color: $primary;
  @include ink-color($primary);

  &:visited {
    color: $visited;
    @include ink-color($visited);
  }

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

/**
 * GtkSpinButton
 */

spinbutton {
  font-feature-settings: "tnum";

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

    > text {
      min-width: 32px;
    }

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

      margin: $container-padding 0;

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

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

      &.up:dir(ltr) {
        margin-right: ($medium-size - $small-size) / 2 - 8px;
      }

      &.up:dir(rtl) {
        margin-left: ($medium-size - $small-size) / 2 - 8px;
      }
    }
  }

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

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

    > text {
      @extend %entry_raised;

      min-height: $medium-size;
      min-width: $large-size;
      padding: 0;

      > selection {
        background-color: $overlay-selected;
      }
    }

    button {
      min-height: $medium-size;
      min-width: $large-size;
      padding: 0;

      @extend %button-flat-basic;

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

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

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

  // OSD vertical
  .osd &.vertical {
  }

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

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

/**
 * ComboBoxes
 */

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

  button:checked arrow {
    color: $primary;
    -gtk-icon-transform: rotate(-.5turn);
  }
}

dropdown {
  > button > box {
    border-spacing: 6px;
  }

  > popover.menu > contents {
    // allow search entries with no padding
    padding: 0;

    listview {
      padding: 6px 0;

      > row {
        min-height: 32px - 4px * 2;
        padding: 4px 8px;

        &:selected {
          background-color: overlay("focus", $on-surface);
        }
      }
    }
  }
}

// drodowns with searchboxes on top
.dropdown-searchbar {
  border-bottom: 1px solid divider($on-surface);

  > entry.search {
    border-image: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
  }
}

combobox {
  > box > button > box {
    border-spacing: 6px;
  }

  cellview {
    margin: -2px;
  }

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    padding-left: 8px;
    padding-right: 8px;
  }

  > .linked:not(.vertical) > entry:not(:only-child) {
    // border-radius: $corner-radius $corner-radius 0 0;

    &:first-child {
      margin-right: -($medium-size + $container-padding);
      padding-right: $medium-size;
    }

    &:last-child {
      margin-left: -($medium-size + $container-padding);
      padding-left: $medium-size;
    }
  }

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

    min-height: 16px;
    min-width: 16px;
    margin: ($medium-size - $small-size) / 2;
    padding: ($small-size - 16px) / 2;
    border-radius: $circular-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 {
  &:not(:first-child) > box > button.combo {
    // @extend %linked-not-first-child;
  }

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

.linked.vertical > combobox {
  &:not(:first-child) > box > button.combo {
    // @extend %linked-vertical-not-first-child;
  }

  &:not(:last-child) > box > button.combo {
    // @extend %linked-vertical-not-last-child;
  }
}

dropdown > button.toggle,
button.combo:only-child {
  padding-left: 8px;
  padding-right: 8px;
  border-radius: $corner-radius $corner-radius 0 0;
  font-weight: normal;

  @include entry(normal);

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

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

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

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

  arrow {
    transition: color $duration $ease-out;
    color: hint($on-surface);

    &:disabled {
      color: disabled-hint($on-surface);
    }
  }
}

/**
 * Toolbars
 */

.toolbar {
  padding: 4px;
  border-spacing: 4px;

  &.top { border-bottom: 1px solid divider($on-surface); }
  &.bottom { border-top: 1px solid divider($on-surface); }
  &.start { border-right: 1px solid divider($on-surface); }
  &.end { border-left: 1px solid divider($on-surface); }

  button {
    @extend %button-flat;
  }

  // on OSD
  .osd & {
  }

  // stand-alone OSD toolbars
  &.osd {
    @extend %toolbar-osd;

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

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

  // toolbar separators
  &.horizontal > separator {
    margin: 4px 0;
  }

  &.vertical > separator {
    margin: 0 4px;
  }
}

%toolbar-osd {
  transition: $transition-shadow;
  padding: $container-padding;
  border-spacing: $container-padding;
  border-radius: $corner-radius;
  box-shadow: $shadow-z4, inset 0 1px highlight($surface-z8);
  background-color: $surface-z8;

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

// searchbar, location-bar & inline-toolbar
.inline-toolbar {
  padding: $container-padding;
  border-style: solid;
  border-width: 0 1px 1px;
  border-color: divider($on-surface);
  background-color: $surface-z1;
}

searchbar > revealer > box {
  padding: $container-padding;
  border-spacing: $container-padding;
  border-bottom: 1px solid divider($on-surface);
}

/**
 * Title buttons
 */

windowcontrols {
  border-spacing: $container-padding;

  &:not(:only-child):not(.empty) {
    border-image:
      linear-gradient(
        to bottom,
        transparent 12px,
        divider($on-titlebar) 12px,
        divider($on-titlebar) calc(100% - 12px),
        transparent calc(100% - 12px)
      ) 1;

    &.start:dir(ltr),
    &.end:dir(rtl) {
      padding-right: $container-padding;
      border-right: 1px solid;
    }

    &.start:dir(rtl),
    &.end:dir(ltr) {
      padding-left: $container-padding;
      border-left: 1px solid;
    }
  }

  button {
  }
}

/**
 * Header bars
 */

.titlebar {
  transition: background-color $duration $ease-out, color $duration $ease-out;
  border-radius: $corner-radius $corner-radius 0 0;
  box-shadow: $shadow-z2, inset 0 1px highlight($titlebar);
  background-color: $titlebar;
  color: $on-titlebar;

  &:disabled {
    color: disabled($on-titlebar);
  }

  &:backdrop {
    background-color: $titlebar-backdrop;
    color: hint($on-titlebar);

    &:disabled {
      color: disabled-hint($on-titlebar);
    }
  }

  box.start,
  box.end {
    border-spacing: $container-padding;
  }

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

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

  .subtitle,
  .dim-label {
    transition: color $duration $ease-out;
    color: hint($on-titlebar);

    &:backdrop {
      color: disabled($on-titlebar);
    }
  }

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

  entry {
    box-shadow: inset 0 -1px stroke($on-titlebar);
    background-color: entry-fill($on-titlebar);
    color: $on-titlebar;

    &:disabled {
      box-shadow: inset 0 -1px disabled-stroke($on-titlebar);
      background-color: entry-fill($on-titlebar);
      color: disabled($on-titlebar);
    }

    image {
      color: hint($on-titlebar);

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

      &:disabled {
        color: disabled($on-titlebar);
      }
    }
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: $corner-radius $corner-radius 0 0;
  }

  @at-root %titlebar-button, & button:not(.suggested-action):not(.destructive-action) {
    @extend %button-flat;

    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $titlebar-indicator 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    background-color: transparent;
    color: hint($on-titlebar);
    @include ink-color($on-titlebar);

    &:disabled {
      color: disabled-hint($on-titlebar);
    }

    @at-root %titlebar-button-checked,
    &:checked {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    $titlebar-indicator 100%,
                                    transparent 100%)
                                    0 0 2 / 0 0 2px;
      background-color: transparent;
      color: $on-titlebar;
      @include ink-color($on-titlebar);

      &:disabled {
        background-color: transparent;
        color: disabled($on-titlebar);
      }
    }

    &:backdrop {
      color: disabled($on-titlebar);

      &:disabled {
        color: disabled-hint($on-titlebar);
      }

      &:checked {
        color: hint($on-titlebar);

        &:disabled {
          color: disabled-hint($on-titlebar);
        }
      }
    }
  }

  button.suggested-action,
  button.destructive-action {
    &:disabled {
      background-color: fill($on-titlebar);
      color: disabled($on-titlebar);
    }
  }

  // FIXME: Ugly overriding
  stackswitcher button:not(.suggested-action):not(.destructive-action).text-button {
    min-width: 120px - 8px * 2;
  }

  // FIXME: Ugly overriding
  .path-bar button:not(.suggested-action):not(.destructive-action).text-button {
    min-width: 0;
    padding-left: ($medium-size - 24px) / 2;
    padding-right: ($medium-size - 24px) / 2;
  }

  &.selection-mode {
    // 0.1ms was a workaround for https://gitlab.gnome.org/GNOME/gtk/issues/698
    // but let's keep it for backwards compatibility.
    transition: background-color 0.1ms $ripple-fade-in-duration, color $duration $ease-out;
    animation: ripple-on-headerbar $ripple-fade-in-duration $ease-out;
    box-shadow: $shadow-z2, inset 0 1px highlight($primary);
    background-color: $primary;
    color: $on-primary;

    &:backdrop {
      color: hint($on-primary);
    }

    .subtitle:link {
      color: $on-primary;
    }

    button:not(.suggested-action):not(.destructive-action) {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    currentColor 0%,
                                    transparent 0%)
                                    0 0 0 / 0 0 0px;
      color: $on-primary;

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

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

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

      &:backdrop {
        color: hint($on-primary);

        &:disabled {
          color: disabled-hint($on-primary);
        }

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

          &:disabled {
            color: disabled-hint($on-primary);
          }
        }
      }
    }

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

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

  .selection-mode {
    box-shadow: inset 0 1px highlight($primary); // 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;
    box-shadow: $shadow-z2;
  }

  &.default-decoration {
    min-height: $small-size;
    padding: $container-padding;
    box-shadow: inset 0 1px highlight($titlebar);

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

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

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

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

headerbar > windowhandle > box {
  // The sizing factor needs to be defined in the headerbar node for the case of split headerbars
  min-height: $large-size;
  padding: 0 $container-padding;
  border-spacing: $container-padding;

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

  separator.titlebutton {
    margin-top: $large-size / 4;
    margin-bottom: $large-size / 4;
    background-color: divider($on-titlebar);
  }

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

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

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

// Development versions of apps to use a differently styled headerbar
window.devel .titlebar:not(.selection-mode) {
}

/**
 * Pathbars
 */

%pathbar_button,
pathbar.linked:not(.vertical) > button {
  @extend %button-flat-basic;

  padding-left: ($medium-size - 24px) / 2;
  padding-right: ($medium-size - 24px) / 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 100%)
                                  0 0 2 / 0 0 2px;
    color: $on-surface;

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

/**
 * Tree Views
 */

columnview.view,
treeview.view {
  border-left-color: stroke($on-surface); // this is actually the tree lines color,
  border-top-color: divider($on-surface); // while this is the grid lines color, better then nothing

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

  // FIXME: Avoid transparency background-color being slightly darker
  &:selected {
    // background-color: $surface-z1;
    // background-image: image($overlay-selected);
  }

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

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

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

  > dndtarget:drop(active) {
    // FIXME: box-shadow, background-color and background-image are not available here.
    border-style: solid none;
    border-width: 9999px;
    border-color: overlay("hover", $on-surface);

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

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

  &.expander {
    // GtkTreeView uses the larger of the expander’s min-width and min-height
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    -gtk-icon-transform: rotate(-90deg);

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

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

    color: hint($on-surface);

    &:hover,
    &:active {
      color: $on-surface;
    }

    &:disabled {
      color: disabled-hint($on-surface);
    }
  }

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

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

  &.trough { // progress bar trough in treeviews
    border-bottom: $bar-size solid disabled-stroke($on-surface);
    background-color: transparent;

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

  > header {
    > button {
      padding: 2px 6px;
      border-style: none solid solid none;
      border-width: 1px;
      border-color: divider($on-surface);
      border-radius: 0;
      background-clip: padding-box;
      background-color: transparent;
      color: hint($on-surface);
      @include ink-color($on-surface, $hover-alt: true, $button-style: "flat");
      @include list-item;

      &:disabled {
        color: disabled-hint($on-surface);
      }

      &,
      &:disabled {
        // background-color: $surface-z1;
      }

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

      > box > sort-indicator {
        min-height: 16px;
        min-width: 16px;

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

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

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    padding: 2px 6px;
    border-style: none solid solid;
    border-width: 1px;
    border-color: divider($on-surface);
    border-radius: 0;
    box-shadow: none;
    // background-color: $surface-z1;
    background-clip: border-box;
    color: $primary;
  }

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

/**
 * Menus
 */

menubar {
  // box-shadow: inset 0 -1px divider($on-surface);
  background-color: $titlebar;
  color: $on-titlebar;

  &:backdrop {
    background-color: $titlebar-backdrop;
    color: hint($on-titlebar);
  }

  .csd & {
    transition: $transition;
  }

  > item {
    // transition: $transition;
    min-height: 20px;
    padding: 4px 8px;
    color: hint($on-titlebar);

    @extend %ripple;
    // @include ink-color($on-titlebar);

    &:hover {
      background-color: overlay("hover", $on-titlebar);
    }

    &:focus:not(:hover) {
      background-color: overlay("focus", $on-titlebar);
    }

    &:active {
      background-image: radial-gradient(circle, overlay("pressed", $on-titlebar) 10%, transparent 10%);
    }

    &:selected:not(:focus) {
      transition: none;
      background-color: overlay("activated", $on-titlebar);
      color: $on-titlebar;
    }

    &:disabled {
      color: disabled-hint($on-titlebar);
    }
  }
}

popover.menu {
  > contents {
    padding: 6px 0;
  }

  separator {
    margin: 6px 0;
  }

  label.title {
    min-height: 32px - 4px * 2;
    padding: 4px 32px; // this will fall apart with font sizing
    font-weight: bold;
  }

  modelbutton {
    // transition: background-color $duration $ease-out;
    min-height: 30px - 4px * 2;
    min-width: 40px;
    padding: 4px 32px;

    &:hover {
      // transition: none;
      // background-color: overlay("hover", $on-surface);
    }

    &:disabled {
      color: disabled($on-surface);
    }

    accelerator {
      color: hint($on-surface);

      &:dir(ltr) {
        margin-left: 24px;
        margin-right: 16px - 32px;
      }

      &:dir(rtl) {
        margin-left: 16px - 32px;
        margin-right: 24px;
      }
    }

    &:disabled accelerator {
      color: disabled-hint($on-surface);
    }
  }

  check,
  radio {
    &,
    &:focus,
    &:hover,
    &:active,
    &:disabled {
      // transition: none;
      background-color: transparent;
      background-image: none;
    }
  }

  arrow,
  check,
  radio {
    min-width: 16px;
    min-height: 16px;
    margin: 0;
    padding: 0;

    &.left {
      margin-left: 8px - 32px;
      margin-right: 8px;
    }

    &.right {
      margin-left: 8px;
      margin-right: 8px - 32px;
    }
  }

  button.model {
    @extend %button-flat;

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

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

  box.inline-buttons {
    padding: 0 8px;

    button.image-button.model {
    }
  }

  box.circular-buttons {
    padding: 4px 32px;

    button.circular.image-button.model {
      padding: 12px;
    }
  }
}

/**
 * Popovers
 */

popover {
  font: initial; // Decouple the font of popovers from their entry/textview

  &.background {
    background-color: transparent;
  }

  > arrow,
  > contents {
    transition: $transition-shadow;
    box-shadow: $shadow-z4;
    background-color: $surface-z8;
    color: $on-surface;

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

  @at-root %popover-border {
    border-width: 1px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.3);
    background-clip: padding-box;
  }

  > arrow {
    @extend %popover-border;
  }

  > contents {
    padding: 8px;

    @if $version >= 4.2 {
      border-radius: $corner-radius;
    } @else {
      @extend %popover-border;
      border-radius: $corner-radius + 1px;
    }

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

    separator {
      // margin: 4px 0;
    }

    list separator {
      // margin: 0;
    }
  }

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

  button {
    @extend %button-outlined;
  }

  frame,
  .frame {
    border: 1px solid divider($on-surface);
    box-shadow: none;
    background-color: transparent;
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    // border-radius: $corner-radius $corner-radius 0 0;
  }
}

/**
 * Notebooks
 */

notebook {
  &:focus:focus-visible > header > tabs > tab:checked {
    background-color: overlay("focus", $primary);
  }

  > header {
    &.top {
      box-shadow: inset 0 -1px divider($on-surface);

      > tabs {
        > tab {
          box-shadow: inset 0 -2px transparent;

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

    &.bottom {
      box-shadow: inset 0 1px divider($on-surface);

      > tabs {
        > tab {
          box-shadow: inset 0 2px transparent;

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

    &.left {
      box-shadow: inset -1px 0 divider($on-surface);

      > tabs {
        > tab {
          box-shadow: inset -2px 0 transparent;

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

    &.right {
      box-shadow: inset 1px 0 divider($on-surface);

      > tabs {
        > tab {
          box-shadow: inset 2px 0 transparent;

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

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

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

    @at-root %notebook_vert_arrows {
      &.down {
        -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
      }

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

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

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

    @at-root %notebook_horz_arrows {
      &.down {
        -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
      }

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

    > tabs > arrow {
      min-height: 16px;
      min-width: 16px;
      padding: 4px;
      border-radius: 0;
      color: hint($on-surface);
      @extend %ripple;
      @include ink-color($on-surface, $hover-alt: true);

      &:disabled {
        color: disabled-hint($on-surface);
      }
    }

    > tabs > tab {
      @extend %ripple;
      @include ink-color($on-surface, $hover-alt: true);
      min-height: $small-size;
      min-width: $small-size;
      padding: $container-padding 12px;
      color: hint($on-surface);
      font-weight: 500;

      &:hover {
        // background-color: overlay("hover-alt", $on-surface);
      }

      &:active {
        // background-image: radial-gradient(circle, overlay("pressed", $on-surface) 10%, transparent 10%);
      }

      &:disabled {
        color: disabled-hint($on-surface);
      }

      &:checked {
        @include ink-color($primary, $hover-alt: true);
        color: $primary;

        &:hover {
          // background-color: overlay("hover-alt", $primary);
        }

        &:active {
          // background-image: radial-gradient(circle, overlay("pressed", $primary) 10%, transparent 10%);
        }

        &:disabled {
          color: disabled-hint($on-surface);
        }

        &.reorderable-page {
          // border-color: divider($on-surface);
          // background-color: $surface-z1;
        }
      }

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

        &:drop(active) {
          background-color: overlay("hover", $on-surface);
        }
      }

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

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

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

/**
 * Scrollbars
 */

scrollbar {
  $_slider_min_length: 24px;

  transition: $transition;
  background-clip: padding-box;
  // background-color: $surface-z1;

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

  // slider
  > range > trough > slider {
    transition: background-color $duration $ease-out;
    min-width: 10px;
    min-height: 10px;
    border: 3px solid transparent;
    border-radius: $circular-radius;
    background-clip: padding-box;
    background-color: scrollbar-thumb($on-surface);

    &:hover {
      background-color: scrollbar-thumb($on-surface, "hover");
    }

    &:active {
      background-color: scrollbar-thumb($on-surface, "pressed");
    }

    &:disabled {
      background-color: scrollbar-thumb($on-surface, "disabled");
    }
  }

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

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

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

    &.horizontal > trough > slider {
      margin: 3px 0;
    }

    &.vertical > trough > slider {
      margin: 0 3px;
    }
  }

  &.overlay-indicator {
    > range:not(.fine-tune) > 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: 3px - 1px;
        border: 1px solid rgba($surface-z1, 0.3);
      }

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

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

    &.dragging,
    &.hovering {
      background-color: $surface-z8;
    }
  }
}

/**
 * Switch
 */

switch {
  transition: all $duration $ease-out;
  margin: $container-padding 0;
  padding: 0 2px;
  border: 5px solid transparent;
  border-radius: $circular-radius;
  background-color: stroke($on-surface);
  background-clip: padding-box;
  font-size: 0;

  &:checked {
    background-color: rgba($primary, .5);
  }

  &:disabled {
    opacity: .5;
  }

  // hide on/off icons for >=3.24.5
  > image {
    margin: -8px;
    -gtk-icon-transform: scale(0);
  }

  > slider {
    transition: all $duration $ease-out;
    min-width: 20px;
    min-height: 20px;
    margin: -3px -2px;
    border-radius: $circular-radius;
    box-shadow:
      0 0 0 10px transparent,
      0 0 0 -10px overlay("pressed", $on-surface),
      $shadow-z1;
    background-color: $surface-switch-thumb;
  }

  &:hover > slider {
    box-shadow:
      0 0 0 10px overlay("hover", $on-surface),
      0 0 0 -10px overlay("pressed", $on-surface),
      $shadow-z1;
  }

  &:focus > slider {
    box-shadow:
      0 0 0 10px overlay("focus", $on-surface),
      0 0 0 -10px overlay("pressed", $on-surface),
      $shadow-z1;
  }

  &:active > slider {
    box-shadow:
      0 0 0 10px overlay("hover", $on-surface),
      0 0 0 10px overlay("pressed", $on-surface),
      $shadow-z1;
  }

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

  &:checked:hover > slider {
    box-shadow:
      0 0 0 10px overlay("hover", $primary),
      0 0 0 -10px overlay("pressed", $primary),
      $shadow-z1;
  }

  &:checked:focus > slider {
    box-shadow:
      0 0 0 10px overlay("focus", $primary),
      0 0 0 -10px overlay("pressed", $primary),
      $shadow-z1;
  }

  &:checked:active > slider {
    box-shadow:
      0 0 0 10px overlay("hover", $primary),
      0 0 0 10px overlay("pressed", $primary),
      $shadow-z1;
  }

  row:selected & {
  }
}

/**
 * Check and Radio items
 */

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

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

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

  @each $class, $suffix in ("": "-unchecked", ":checked": "-checked") {
    &#{$class} {
      $_url: 'assets/selectionmode-checkbox#{$suffix}#{$asset-suffix}';

      -gtk-icon-source: -gtk-scaled(url("#{$_url}.png"), url("#{$_url}@2.png"));
    }
  }
}

checkbutton,
radiobutton {
  border-spacing: 4px;

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

$check-radio-size: 40px;

check,
radio {
  min-height: 24px;
  min-width: 24px;
  margin: -($check-radio-size - 24px) / 2;
  padding: ($check-radio-size - 24px) / 2;
  border-radius: $circular-radius;
  color: hint($on-surface);
  @extend %ripple;
  @include ink-color($on-surface);

  &:checked,
  &:indeterminate {
    color: $primary;
    @include ink-color($primary);
  }

  &:disabled {
    color: disabled-hint($on-surface);
  }
}

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

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

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

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

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

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

  border-image-slice: $check-radio-size / 2px;
  border-image-width: $check-radio-size / 2;

  $radio-indicator-size: 10px / $check-radio-size / 2;

  border-image-source: radial-gradient(circle, $primary 0%, transparent 0%);

  &:checked:not(:indeterminate) {
    border-image-source: radial-gradient(circle, $primary 4.5px, transparent 5px);

    &:disabled {
      border-image-source: radial-gradient(circle, disabled-hint($on-surface) 4.5px, transparent 5px);
    }
  }
}

%small_check,
popover.menu modelbutton check {
  min-height: 16px;
  min-width: 16px;
  border-radius: $corner-radius;
  -gtk-icon-source: -gtk-recolor(url("icons/small-checkbox-unchecked-symbolic.svg"));

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

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

%small_radio,
popover.menu modelbutton radio {
  min-height: 16px;
  min-width: 16px;
  border-image: none;
  -gtk-icon-source: -gtk-recolor(url("icons/small-radio-unchecked-symbolic.svg"));

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

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

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

// Otherwise, treeview.view styling will be applied...
treeview.view check,
treeview.view radio {
  padding: 0;
  color: hint($on-surface);

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

  &:disabled {
    color: disabled-hint($on-surface);
  }

  &,
  &:hover,
  &:selected,
  &:selected:hover {
    background-color: transparent;
  }
}

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

/**
 * GtkScale
 */

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

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

  $slider_size: 32px;

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

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

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

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

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

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

  // the backing bit
  > trough {
    transition: background-color $duration $ease-out;
    background-color: stroke($on-surface);

    &:disabled {
      background-color: disabled-stroke($on-surface);
    }

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

      &:disabled {
        background-color: $surface-z0;
        background-image: image(disabled-hint($on-surface));
      }
    }

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

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

    > slider {
      transition: background-color $duration $ease-out,
                  background-size $ripple-fade-out-duration $ease-out,
                  background-image $ripple-fade-out-opacity-duration $ease-out;
      min-width: $slider_size;
      min-height: $slider_size;
      // the slider is inside the trough, so to have make it bigger there's a negative margin
      margin: $slider_margin;
      border-radius: 50%;
      background-repeat: no-repeat;
      background-position: center;
      background-size: auto, 1000% 1000%;
      color: $primary;

      @each $class, $suffix in ("": "", ":disabled": "-disabled") {
        &#{$class} {
          $_url: 'assets/scale-slider#{$suffix}#{$asset-suffix}';

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

      &:hover {
        background-color: overlay("hover", $primary);
      }

      &:focus {
        background-color: overlay("focus", $primary);
      }

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

        transition: background-color $duration $ease-out,
                    background-size 0ms,
                    background-image 0ms;
        animation: ripple-on-slider $ripple-fade-in-duration $ease-out forwards;
        background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                          radial-gradient(circle, overlay("pressed", $primary) 10%, transparent 10%);
        background-size: auto, 0% 0%;
      }
    }
  }

  > marks,
  > value {
    color: hint($on-surface);
  }

  > value {
    font-feature-settings: "tnum";
  }

  indicator {
    background-color: stroke($on-surface);
  }

  //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_class, $marks_infix in (
      ".marks-before:not(.marks-after)": "-marks-before",
      ".marks-after:not(.marks-before)": "-marks-after"
    ) {
      &#{$dir_class}#{$marks_class} > trough > slider {
        @each $state_class, $state_infix in ("": "", ":disabled": "-disabled") {
          &#{$state_class} {
            $_scale_asset: 'assets/scale#{$dir_infix}#{$marks_infix}-slider#{$state_infix}#{$asset-suffix}';

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

        &: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')),
            radial-gradient(circle, overlay("pressed", $primary) 10%, transparent 10%);
        }
      }
    }
  }

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

    &.horizontal {
      // specificity bump
      &:dir(ltr),
      &:dir(rtl) {
        padding: 0 0 12px 0;

        slider {
          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 {
  // FIXME: insensitive state missing and some other state should be set probably
  color: hint($on-surface);
  font-size: smaller;
  font-feature-settings: "tnum";

  > trough {
    background-color: disabled-stroke($on-surface);

    > progress {
      background-color: $primary;
    }
  }

  // sizing
  &.horizontal > trough {
    min-width: 150px;

    &,
    > progress {
      min-height: $bar-size;
    }
  }

  &.vertical > trough {
    min-height: 80px;

    &,
    > progress {
      min-width: $bar-size;
    }
  }

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

    > trough {
      // background-color: transparent;

      > progress {
        // background-color: $primary;
      }
    }
  }

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

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

  > trough {
  }

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

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

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

    &.empty {
      background-color: disabled-stroke($on-surface);
    }
  }
}

/**
 * Print dialog
 */

window.dialog.print {
  paper {
    // padding: 0;
    // border: 1px solid divider($on-surface);
    border-radius: $corner-radius;
    box-shadow: $shadow-z1;
    background-color: $surface-z1;
    color: $on-surface;
  }

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

/**
 * Frames
 */

frame,
.frame {
  // border: 1px solid divider($on-surface);
  border-radius: $corner-radius;
  box-shadow: $shadow-z1;
  background-color: $surface-z1;
  color: $on-surface;

  button {
    @extend %button-outlined;
  }
}

frame > label {
  margin: 4px;
}

statusbar {
  padding: 6px 10px;
  // border-top: 1px solid divider($on-surface);
}

actionbar > revealer > box {
  padding: $container-padding;
  border-spacing: $container-padding;
  border-top: 1px solid divider($on-surface);
  // background-clip: border-box;

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

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: $corner-radius $corner-radius 0 0;
  }
}

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

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

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

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

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

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

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

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

  // the small square between two scrollbars
  @at-root junction {
    border-style: solid none none solid;
    border-width: 1px;
    border-color: divider($on-surface);
    // background-color: $surface-z1;

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

// vbox and hbox separators
separator {
  min-width: 1px;
  min-height: 1px;
  background-color: divider($on-surface);
}

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

/**
 * Lists
 */

listview,
list {
  // background-color: $surface-z1;
  // color: $on-surface;

  > row {
    padding: 2px;

    &.expander {
      padding: 0;

      .row-header {
        padding: 2px;
      }
    }
  }

  &.separators:not(.horizontal) > row:not(:first-child) {
    border-top: 1px solid divider($on-surface);
  }

  &.separators.horizontal > row:not(:first-child) {
    border-left: 1px solid divider($on-surface);
  }
}

row {
  background-clip: padding-box;

  &.activatable {
    @extend %ripple;
    @include ink-color($on-surface, $hover-alt: true);
    @include list-item;

    // this is for indicathing which row generated a popover
    // see https://bugzilla.gnome.org/show_bug.cgi?id=754411
    &.has-open-popup {
      background-color: overlay("activated", $on-surface);
    }
  }

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

    @include ink-color($primary, $hover-alt: true, $on: $overlay-selected);

    &.has-open-popup {
      background-color: overlay("activated", $primary, $on: $overlay-selected);
    }
  }
}

listview {
  > row {
    @extend %ripple;
    @include ink-color($on-surface, $hover-alt: true);
    @include list-item;
  }

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

    @include ink-color($primary, $hover-alt: true, $on: $overlay-selected);
  }
}

columnview {
  // move padding to child cells
  > listview > row {
    padding: 0;

    // align horizontal sizing with header buttons
    > cell {
      min-height: 24px;
      padding: 4px 6px;

      &:not(:last-child) {
        border-right: 1px solid transparent;
      }
    }
  }

  // make column separators visible when :show-column-separators is true
  &.column-separators > listview > row > cell {
    border-right-color: divider($on-surface);
  }

  // shrink vertically for .data-table
  &.data-table > listview > row > cell {
    padding-top: 2px;
    padding-bottom: 2px;
  }
}

// rich lists usually containing other widgets than just labels/text
.rich-list {
  > row {
    padding: 12px;
    min-height: $medium-size;

    > box {
      border-spacing: 12px;
    }
  }
}

/**
 * App Notifications
 */

.app-notification {
  @extend %toolbar-osd;
  margin: 8px;
  border-style: none;

  button {
    @extend %button-flat;

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

/**
 * Expanders
 */

expander {
  transition: all $duration $ease-out;
  min-width: 16px;
  min-height: 16px;
  padding: 4px;
  border-radius: $circular-radius;
  color: hint($on-surface);
  -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');

  @extend %ripple;
  @include ink-color($on-surface);

  &:disabled {
    color: disabled-hint($on-surface);
  }

  &:checked {
    &:dir(ltr) {
      -gtk-icon-transform: rotate(-180deg);
    }

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

indent {
  min-width: 16px;
  min-height: 16px;
  padding: 4px;
}

expander-widget {
  &:focus > box > title > expander {
    box-shadow: inset 0 0 0 9999px overlay("focus", $on-surface);
  }

  > box > title:drop(active) > expander,
  > box > title:hover > expander {
    box-shadow: inset 0 0 0 9999px overlay("hover", $on-surface);
  }

  > box > title:active > expander {
    transition-duration: $ripple-active-transition-duration;
    animation: ripple $ripple-fade-in-duration $ease-out forwards;
    background-size: 0% 0%;
    background-image: radial-gradient(circle, overlay("pressed", $on-surface) 10%, transparent 10%);
  }
}

/**
 * Calendar
 */

calendar {
  // border: 1px solid divider($on-surface);
  border-radius: $corner-radius;
  box-shadow: $shadow-z1;
  background-color: $surface-z1;
  color: $on-surface;

  &:disabled {
    color: disabled($on-surface);
  }

  > header {
    padding: 4px;
    border-spacing: 4px;
    border-bottom: 1px solid divider($on-surface);

    > button.image-button {
      padding: 0;
      min-width: 28px;
      min-height: 28px;
      border-radius: $circular-radius;
      background-color: transparent;
      color: hint($on-surface);
      @include ink-color($on-surface, $button-style: "flat");

      &:disabled {
        color: disabled-hint($on-surface);
      }
    }
  }

  > grid {
    padding: 4px;
    border-spacing: 4px;

    > label {
      // padding: 4px;
      padding: 0;
      min-width: 28px;
      min-height: 28px;
      border-radius: $circular-radius;
    }

    > label.day-name,
    > label.week-number {
      color: hint($on-surface);
      font-weight: 500;
    }

    > label.day-number {
      @extend %ripple;
      @include ink-color($on-surface);

      &.today {
        box-shadow: inset 0 0 0 1px hint($on-surface);
      }

      &.other-month {
        color: disabled-hint($on-surface);
      }

      &:selected {
        background-color: $overlay-selected;
        box-shadow: inset 0 0 0 1px transparent;
        @include ink-color($primary, $on: $overlay-selected);
      }
    }
  }
}

/**
 * Dialogs
 */

window.dialog.message { // Message Dialog styling
  &.csd.background {
    min-width: 280px;
    border-radius: $corner-radius; // rounded bottom border styling for csd version
    background-color: $surface-z8;
  }

  > .titlebar {
    min-height: 24px;
    box-shadow: inset 0 1px highlight($surface-z8);
    background-color: transparent;
    color: $on-surface;

    &:backdrop {
      background-color: transparent;
      color: hint($on-surface);
    }
  }

  > box.dialog-vbox.vertical {
    border-spacing: 20px;

    > box.vertical > box.horizontal {
      margin: 0 24px - 30px;
    }
  }

  label.title {
    font-weight: 500;
    font-size: pt(20px);
    letter-spacing: pt(.15px);
  }

  // Hint text
  label.title + label {
    color: hint($on-surface);
  }

  list,
  .view {
    background-color: transparent;
  }

  .dialog-action-area > button {
    @extend %button-flat;

    &:not(:disabled) {
        color: $primary;
      @include ink-color($primary);
    }

    &.suggested-action:not(:disabled) {
      background-color: transparent;
        // color: $primary;
      // @include ink-color($primary);
    }

    &.destructive-action:not(:disabled) {
      background-color: transparent;
        color: $error;
      @include ink-color($error);
    }
  }
}

.dialog-action-area {
  // margin-top: -$container-padding;
  padding: $container-padding;
  border-spacing: $container-padding;
}

filechooser {
  .dialog-action-box {
    border-top: 1px solid divider($on-surface);
  }

  #pathbarbox {
    border-bottom: 1px solid divider($on-surface);
    // background-color: $surface-z0;

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

      border-radius: $circular-radius;
    }
  }
}

filechooserbutton > button > box {
  border-spacing: 6px;
}

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

/**
 * Sidebar
 */

.sidebar {
  border-style: none;

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

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

  list {
    // background-color: transparent;
  }

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

stacksidebar.sidebar {
  list {
    padding: 4px;
  }

  list.separators:not(.horizontal) > row:not(:first-child) {
    border-top-style: none;
  }

  row {
    min-height: 32px;
    padding: 0 8px - 6px;
    border-radius: $corner-radius;
    color: hint($on-surface);
    font-weight: 500;

    &:selected {
      background-color: overlay("activated", $primary);
      color: $primary;
      @include ink-color($primary, $on: overlay("activated", $primary));
    }

    + row {
      margin-top: 4px;
    }

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

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

separator.sidebar {
  &.selection-mode,
  .selection-mode & {
    // background-color: divider($on-surface);
  }
}

/**
 * File chooser
 */

// dim the sidebar icons, see bug #786613 for details on this oddity
row image.sidebar-icon {
  transition: color $duration $ease-out;
  color: hint($on-surface);

  &:disabled {
    color: disabled-hint($on-surface);
  }
}

placessidebar.sidebar {
  list {
    padding: 4px 0;

    > separator {
      margin: 4px 0;
    }
  }

  row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: 32px;
    margin: 0 4px; // Remove unwanted hard-coded vertical margins with -1px
    padding: 0;
    border-radius: $corner-radius;
    color: hint($on-surface);
    font-weight: 500;

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

    &:selected {
      background-color: overlay("activated", $primary);
      color: $primary;
      @include ink-color($primary, $on: overlay("activated", $primary));

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

    &:disabled {
      color: disabled($on-surface);
    }

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

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

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

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

    @at-root button.sidebar-button {
      @extend %button-flat-basic;
      @extend %button-small;
    }

    &.sidebar-placeholder-row {
      background-color: overlay("hover", $on-surface);
    }

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

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

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

    &:checked > image {
      -gtk-icon-transform: rotate(-0.5turn);
    }
  }

  > actionbar > revealer > box > box {
    border-spacing: $container-padding;
  }

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

/**
 * Paned
 */

paned {
  > separator {
    background-clip: content-box;
    // -gtk-icon-source: none; // defeats the ugly default handle decoration

    &.wide {
      min-width: 4px;
      min-height: 4px;
      border: 1px solid divider($on-surface);
      background-color: transparent;
    }
  }

  &.horizontal > separator {
    &:not(.wide) {
      margin: 0 -4px;
      padding: 0 4px;
    }

    &.wide {
      border-style: none solid;
    }
  }

  &.vertical > separator {
    &:not(.wide) {
      margin: -4px 0;
      padding: 4px 0;
    }

    &.wide {
      border-style: solid none;
    }
  }
}

/**
 * GtkVideo
 */

video {
  background-color: black;

  image.osd {
    min-width: 64px;
    min-height: 64px;
    border-radius: 32px;
    background-color: $scrim;
    color: $on-scrim;
  }

  controls.osd {
    padding: 4px;
    background-image:
      linear-gradient(
        to bottom,
        transparent,
        rgba(black, .1) 30%,
        rgba(black, .2) 50%,
        rgba(black, .4)
      );
    color: on(black);

    button {
      background-color: transparent;
      color: hint(on(black));
      @include ink-color(on(black));
    }
  }
}

/**
 * GtkInfoBar
 */

infobar {
  > revealer > box {
    padding: 8px;
    border-spacing: 12px;
  }

  &.action:hover > revealer > box {
    background-image: image(overlay("hover", $on-surface));
  }

  &.info > revealer > box,
  &.question > revealer > box {
    border-bottom: 1px solid divider($on-surface);
    // background-color: $surface-z1;

    button {
      @extend %button-flat;

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

  &.warning > revealer > box {
    background-color: $warning;
    color: $on-warning;

    button.flat {
      color: $on-warning;
      @include ink-color($on-warning);
    }

    selection {
    }

    link {
      color: $on-warning;
    }
  }

  &.error > revealer > box {
    background-color: $error;
    color: $on-error;

    button.flat {
      color: $on-error;
      @include ink-color($on-error);
    }

    selection {
    }

    link {
      color: $on-error;
    }
  }

  // Remove ugly hard-coded padding
  button label {
    // margin: 0 -4px;
  }
}

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

  min-height: 32px - 4px * 2;
  padding: 4px 8px;
  border-radius: $corner-radius;

  &:not(.csd) {
    background-color: $tooltip;
  }

  > box {
    border-spacing: 6px;
  }

  .dim-label {
    color: hint($on-tooltip);
  }
}

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

  transition: $transition-shadow;
  box-shadow: $shadow-z1;

  &:drop(active),
  &.activatable:hover {
    box-shadow: $shadow-z3;
  }

  &:disabled {
    opacity: .5;
    // box-shadow: none;
  }

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

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

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

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

  &.dark {
    color: $on-dark;
  }

  &.light {
    color: $on-light;
  }

  &#add-color-button {
    // border-radius: $corner-radius 0 0 $corner-radius;
    background-color: $surface-z8;
    color: $on-surface;

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

  row:selected & {
  }

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

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

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

/**
 * Misc
 */

// content view (grid/list)
.content-view {
  // background-color: $surface-z0;

  &:hover {
    // -gtk-icon-filter: brightness(1.2);
  }
}

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

    button.flat {
    }
  }

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

/**
 * Window Decorations
 */

window {
  &.csd {
    transition: $transition-shadow;
    border-radius: $corner-radius $corner-radius 0 0;
    border-radius: $corner-radius;
    box-shadow: $shadow-z16, 0 16px 24px 2px transparent, 0 6px 30px 5px transparent;

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

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

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

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

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

// catch all extend :)

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

.monospace {
  font-family: monospace;
}

/**
 * Touch Copy & Paste
 */

// touch selection handlebars for the Popover.osd above
cursor-handle {
  min-width: 24px;
  min-height: 24px;
  border-radius: 50%;
  background-color: $primary;
  // -gtk-icon-source: -gtk-recolor(url("icons/cursor-handle-symbolic.svg"));

  &.top:dir(ltr),
  &.bottom:dir(rtl) {
    border-top-right-radius: 0;
    // -gtk-icon-transform: rotate(90deg);
  }

  &.bottom:dir(ltr),
  &.top:dir(rtl) {
    border-top-left-radius: 0;
    // -gtk-icon-transform: unset;
  }

  &.insertion-cursor:dir(ltr),
  &.insertion-cursor:dir(rtl) {
    margin-top: 6px;
    transform: rotate(45deg);
  }
}

shortcuts-section {
  margin: 20px;
}

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

// shortcut window keys
shortcut {
  border-spacing: 6px;
}

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

  // border: solid 1px divider($on-surface);
  // border-radius: $corner-radius + 1px;
  border-radius: $corner-radius;
  // box-shadow: inset 0 -2px divider($on-surface);
  box-shadow: $shadow-z1;
  background-color: $surface-z8;
  color: $on-surface;
  font-size: smaller;
}

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

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

stackswitcher.circular {
  border-spacing: 12px;

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

/**
 * App Icons
 */

// Outline for low res icons
.lowres-icon {
  // -gtk-icon-shadow: none;
}

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

/**
 * Emoji
 */

popover.emoji-picker > contents {
  padding: 0;

  emoji {
    min-width: 3em;
    min-height: 3em;
    // padding: 8px;
    border-radius: $corner-radius;
    // font-size: larger;

    @extend %ripple;
    @include ink-color($on-surface);
  }
}

.emoji-searchbar {
  border-bottom: 1px solid divider($on-surface);

  > entry.search {
    border-image: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
  }
}

.emoji-toolbar {
  padding: 4px;
  border-spacing: 4px;
  border-top: 1px solid divider($on-surface);

  > button.emoji-section {
    &:checked {
      background-color: overlay("activated", $primary);
      color: $primary;
      @include ink-color($primary, $on: overlay("activated", $primary));
    }
  }
}

popover.emoji-completion > contents {
  padding: 8px 0;

  emoji-completion-row {
    min-height: 32px;
    padding: 0 8px;
    @extend %ripple;
    @include ink-color($on-surface);

    > box {
      border-spacing: 8px;
    }
  }

  emoji {
    // min-width: 3em;
    // min-height: 3em;
    // padding: 8px;
    border-radius: $corner-radius;

    @extend %ripple;
    @include ink-color($on-surface);
  }
}

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

  treeview.view {
    min-height: 32px; // FIXME: should be in .cell
    padding: 8px 0;

    > .cell {
      padding: 0 4px; // FIXME: should be `0 8px`

      &:selected:hover {
        background-color: overlay("focus", $on-surface);
      }
    }
  }
}
