@use "../../theme";
@use "../../theme-color";
@use "../../shadow";
@use "drawing";

* {
  // padding: 0;

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

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

  -GtkScrolledWindow-scrollbar-spacing: 0;

  -GtkToolItemGroup-expander-size: 11;

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

  -GtkDialog-button-spacing: theme.$container-padding / 1px;
  -GtkDialog-action-area-border: theme.$container-padding / 1px;

  -gtk-secondary-caret-color: theme-color.$primary;

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

  outline: 2px solid transparent;
  outline-offset: -4px;
  -gtk-outline-radius: theme.$corner-radius;

  &:focus {
    outline-color: theme-color.focus-overlay(theme-color.$on-surface);
  }
}

/**
 * Base States
 */

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

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

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

.gtkstyle-fallback {
  background-color: theme-color.$surface-z0;
  color: theme-color.$on-surface;

  &:hover {
    background-color: theme-color.hover-overlay(theme-color.$on-surface, $on: theme-color.$surface-z0);
  }

  &:active {
    background-color: theme-color.pressed-overlay(theme-color.$on-surface, $on: theme-color.$surface-z0);
  }

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

  &:selected {
    background-color: theme-color.$primary;
    color: theme-color.$on-primary;
  }
}

.view {
  background-color: theme-color.$surface-z0;
  color: theme-color.$on-surface;

  &:hover {
    background-color: theme-color.hover-overlay(theme-color.$on-surface, $alt: true);
  }

  &:selected:hover {
    background-color: theme-color.hover-overlay(theme-color.$primary, $alt: true, $on: theme-color.$selected-overlay);
  }

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

  &:hover,
  &:selected {
    border-radius: theme.$corner-radius;
  }

  selection,
  &:selected {
    background-color: theme-color.$selected-overlay;
  }
}

textview {
  // FIXME: we need to override background-color to ensure text rendering
  text {
    background-color: theme-color.$surface-z0;
    caret-color: theme-color.$primary;

    frame:not(.flat) &,
    .frame & {
      background-color: theme-color.$surface-z1;
    }

    popover.background & {
      background-color: theme-color.$surface-z8;
    }

    messagedialog.background & {
      background-color: theme-color.$surface-z8;
    }
  }

  border {
    // background-color: $surface-z0;
    color: theme-color.hint(theme-color.$on-surface); // FIXME: not working
  }
}

iconview {
  // @extend .view;
}

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

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

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

flowbox {
  rubberband {
    @extend %rubberband;
  }

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

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

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

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

label {
  caret-color: theme-color.$primary; // this shouldn't be needed.

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

  &.error {
    color: theme-color.$error;
  }

  selection {
    background-color: theme-color.$selected-overlay;
  }

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

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

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

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

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

  .sidebar label {
    min-height: theme.$medium-size;
    margin: 0 4px;
    padding: 0 8px;
    border-radius: theme.$corner-radius;
    color: theme-color.disabled(theme-color.$on-surface);
    font-weight: 500;

    &.highlight {
      background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
    }
  }
}

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

/**
 * Spinner Animation
 */

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

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

  &:checked {
    opacity: 1;
  }

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$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: theme.$medium-size;
  padding: 0 8px;
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;

  @include drawing.entry(normal);

  &:focus {
    @include drawing.entry(checked);
  }

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

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

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

  // icons inside the entry
  image {
    color: theme-color.hint(theme-color.$on-surface);

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

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

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

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

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

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

  selection {
    background-color: theme-color.$selected-overlay;
  }

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

      &:focus {
        @include drawing.entry(checked, $color);
      }

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

  .osd & {
  }

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

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

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

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

  @include drawing.entry(raised-normal);

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

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

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

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

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

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

      image {
        color: theme-color.hint(theme-color.on($color));

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

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

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

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

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

  &:hover {
    background-image: image(theme-color.hover-overlay(theme-color.$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: theme-color.hint(theme-color.$on-surface);
  }
}

/**
 * Buttons
 */

// stuff for .needs-attention
@keyframes needs-attention {
  from {
    background-image:
      -gtk-gradient(
        radial,
        center center, 0,
        center center, .001,
        to(theme-color.$primary),
        to(transparent)
      );
  }

  to {
    background-image:
      -gtk-gradient(
        radial,
        center center, 0,
        center center, .5,
        to(theme-color.$primary),
        to(transparent)
      );
  }
}

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

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

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

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

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

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

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

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

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

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

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

  .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-flat-basic {
  color: theme-color.hint(theme-color.$on-surface);
  @include drawing.ink-color(theme-color.$on-surface, $button-style: "flat");

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

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

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

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

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

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

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

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

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

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

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

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

    &.image-button {
      padding: (theme.$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": theme-color.$primary, ".destructive-action": theme-color.$error) {
    &#{$class} {
      color: theme-color.on($color);
      @include drawing.ink-color(theme-color.on($color), $button-style: "raised", $on: $color);

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

      &:checked {
        $background-color: theme-color.activated-overlay(theme-color.on($color), $on: $color);
        @include drawing.ink-color(theme-color.on($color), $button-style: "raised", $on: $background-color);
      }

      &.flat {
        color: $color;
        @include drawing.ink-color($color, $button-style: "flat");

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

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

      .osd & {
      }
    }
  }

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

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

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

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

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

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

  &.close,
  &.circular { // The Bloody Circul Button
    border-radius: theme.$circular-radius;

    label {
      // padding: 0;
    }
  }
}

%button-small {
  min-height: theme.$small-size;
  min-width: theme.$small-size;
  padding: 0;
  border-radius: theme.$circular-radius;
}

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

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

// all the following is for the +|- buttons on inline toolbars, that way
// should really be deprecated...
.inline-toolbar toolbutton > button {
}

// More inline toolbar buttons
toolbar.inline-toolbar toolbutton {
  &:not(:first-child) > button.flat {
    // @extend %linked-not-first-child;
  }

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

%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: theme.$corner-radius;
    border-bottom-left-radius: theme.$corner-radius;
  }

  &:last-child {
    border-top-right-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

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

%linked-vertical-image-button {
  &:first-child {
    border-top-left-radius: theme.$corner-radius;
    border-top-right-radius: theme.$corner-radius;
  }

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

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

/* menu buttons */
modelbutton.flat,
.menuitem.button.flat {
  min-height: theme.$menu-item-dense-height;
  padding: 0 8px;
  border-radius: theme.$corner-radius;

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

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

modelbutton.flat arrow {
  transition: color theme.$state-duration theme.$ease-out;
  color: theme-color.hint(theme-color.$on-surface);

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

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

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

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

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

/**
 * Links
 */

*:link {
  color: theme-color.$primary;

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

*:visited {
  color: theme-color.$visited;

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

button.link {
  &:link {
    color: theme-color.$primary;
    @include drawing.ink-color(theme-color.$primary, $button-style: "flat");
  }

  &:visited {
    color: theme-color.$visited;
    @include drawing.ink-color(theme-color.$visited, $button-style: "flat");
  }

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

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

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

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

      // margin: $container-padding;
      border: solid theme.$container-padding transparent;
      background-clip: padding-box;

      // Remove unwanted focus indicator
      &:focus:not(:hover):not(:active) {
        background-color: transparent;
      }

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

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

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

    // FIXME: this should not be set at all, but otherwise it gets the wrong
    // color
    caret-color: theme-color.$primary;

    // FIXME: this should not be set at all, but otherwise it gets the wrong
    // color
    &:disabled {
      color: theme-color.disabled(theme-color.$on-surface);
    }

    entry {
      @extend %entry_raised;

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

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

      @extend %button-flat-basic;

      // Remove unwanted focus indicator
      &:focus:not(:hover):not(:active) {
        background-color: transparent;
      }

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

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

  // OSD vertical
  .osd &.vertical {
  }

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

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

/**
 * ComboBoxes
 */

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

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

  // workaround for menuitem selection
  decoration {
    transition: none;
  }

  // remove hard-coded 2px padding
  cellview {
    margin: -2px;
  }

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

    &:dir(rtl) {
      margin-right: -2px + 8px - (theme.$medium-size - 16px) / 2;
    }
  }

  menu {
    padding: 2px 0;

    menuitem {
      min-height: theme.$medium-size - 2px * 2;
      padding: 0 8px;
    }

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

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

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

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

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

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

    min-height: 16px;
    min-width: 16px;
    margin: (theme.$medium-size - theme.$small-size) / 2;
    padding: (theme.$small-size - 16px) / 2;
    border-radius: theme.$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;
  }
}

button.combo:only-child {
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  font-weight: normal;

  @include drawing.entry(normal);

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

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

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

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

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

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

/**
 * Toolbars
 */

toolbar {
  -GtkWidget-window-dragging: true;
  padding: 2px;

  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: 2px;
  }

  &.vertical > separator {
    margin: 2px;
  }

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

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

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

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

    switch {
      margin: 2px + theme.$container-padding 2px;
    }
  }
}

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

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

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

searchbar > revealer > box,
.location-bar {
  padding: theme.$container-padding;
  border-style: solid;
  border-width: 0 0 1px;
  border-color: theme-color.divider(theme-color.$on-surface);
}

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

/**
 * Header bars
 */

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

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

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

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

  .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 theme.$state-duration theme.$ease-out;
    color: theme-color.hint(theme-color.$on-titlebar);

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

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

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

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

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

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

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

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

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: theme.$corner-radius theme.$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),
        theme-color.$titlebar-indicator 0%,
        transparent 0%
      ) 0 0 0 / 0 0 0;
    background-color: transparent;
    color: theme-color.hint(theme-color.$on-titlebar);
    @include drawing.ink-color(theme-color.$on-titlebar, $button-style: "flat");

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

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

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

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

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

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

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

  button.suggested-action, button.destructive-action {
    &:disabled {
      background-color: theme-color.fill(theme-color.$on-titlebar);
      color: theme-color.disabled(theme-color.$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: (theme.$medium-size - 24px) / 2;
    padding-right: (theme.$medium-size - 24px) / 2;
  }

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

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

    .subtitle:link {
      color: theme-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 0;
      color: theme-color.$on-primary;

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

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

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

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

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

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

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

    .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: inset 0 1px theme-color.highlight(theme-color.$primary); // Avoid double shadows
    background-color: theme-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.$z1;
  }

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

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

    button.titlebutton {
      min-height: theme.$small-size;
      min-width: theme.$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.$z1; // just remove the highlight
    }
  }
}

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

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

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

  switch {
    margin-top: (theme.$large-size - 24px) / 2;
    margin-bottom: (theme.$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,
.path-bar.linked:not(.vertical) > button {
  padding-left: (theme.$medium-size - 24px) / 2;
  padding-right: (theme.$medium-size - 24px) / 2;
  border-image:
    radial-gradient(
      circle closest-corner at center calc(100% - 1px),
      theme-color.$primary 0%,
      transparent 0%
    ) 0 0 0 / 0 0 0;
  border-radius: theme.$corner-radius;
  color: theme-color.hint(theme-color.$on-surface);
  @include drawing.ink-color(theme-color.$on-surface, $button-style: "flat");

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

  &:checked {
    border-image:
      radial-gradient(
        circle closest-corner at center calc(100% - 1px),
        theme-color.$primary 100%,
        transparent 0%
      ) 0 0 2 / 0 0 2px;
    color: theme-color.$primary;
    @include drawing.ink-color(theme-color.$primary, $button-style: "flat");

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

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

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

  border-left-color: theme-color.stroke(theme-color.$on-surface); // this is actually the tree lines color,
  border-top-color: theme-color.divider(theme-color.$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;
  }

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

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

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

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

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

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

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

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

    color: theme-color.hint(theme-color.$on-surface);

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

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

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

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

  // progress bar trough in treeviews
  &.trough {
    border-bottom: 4px solid theme-color.disabled-stroke(theme-color.$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: theme-color.divider(theme-color.$on-surface);
      border-radius: 0;
      background-clip: padding-box;
      color: theme-color.hint(theme-color.$on-surface);
      @include drawing.ink-color(theme-color.$on-surface, $button-style: "flat", $hover-alt: true);
      @include drawing.list-item;

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

      &: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: theme-color.divider(theme-color.$on-surface);
    border-radius: 0;
    box-shadow: none;
    background-clip: padding-box;
    background-color: theme-color.$surface-z8;
    color: theme-color.$primary;
  }

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

/**
 * Menus
 */

menubar,
.menubar {
  -GtkWidget-window-dragging: true;
  padding: 0;
  // box-shadow: inset 0 -1px divider($on-surface);
  background-color: theme-color.$titlebar;
  color: theme-color.$on-titlebar;

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

  .csd & {
    transition: theme.$transition;
  }

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

    // Seems like it :hover even with keyboard focus
    &:hover {
      transition: none;
      background-color: theme-color.activated-overlay(theme-color.$on-titlebar);
      color: theme-color.$on-titlebar;
    }

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

// Needed to make the border-radius of menus work
// otherwise the background bleeds out of the menu edges
.background.popup {
  background-color: transparent;
}

menu,
.menu,
.context-menu {
  margin: 4px 0; // See https://bugzilla.gnome.org/show_bug.cgi?id=591258
  padding: 4px 0;
  border: 1px solid theme-color.divider(theme-color.$on-surface); // adds borders in a non composited env
  box-shadow: inset 0 1px theme-color.highlight(theme-color.$surface-z8);
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
  font: initial;
  text-shadow: none;

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

  menuitem {
    transition: background-color theme.$state-duration theme.$ease-out;
    min-height: 20px;
    min-width: 40px;
    padding: 4px 8px;

    &:hover {
      transition: none;
      background-color: theme-color.hover-overlay(theme-color.$on-surface);
    }

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

    // submenu indicators
    arrow {
      min-height: 16px;
      min-width: 16px;
      color: theme-color.hint(theme-color.$on-surface);

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

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

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

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

  // overflow arrows
  > arrow {
    min-height: 16px;
    min-width: 16px;
    padding: 4px;
    background-color: theme-color.$surface-z8;
    color: theme-color.hint(theme-color.$on-surface);

    &.top {
      margin-top: -4px;
      border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
      border-radius: theme.$corner-radius theme.$corner-radius 0 0;
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
    }

    &.bottom {
      margin-top: 4px * 2;
      margin-bottom: -4px * 3;
      border-top: 1px solid theme-color.divider(theme-color.$on-surface);
      border-radius: 0 0 theme.$corner-radius theme.$corner-radius;
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    }

    &:hover {
      background-image: image(theme-color.hover-overlay(theme-color.$on-surface));
    }

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

  separator {
    margin: 4px 0;
  }
}

menuitem {
  accelerator {
    color: theme-color.hint(theme-color.$on-surface);
  }

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

/**
 * Popovers
 */

popover.background {
  transition: theme.$transition-shadow;
  padding: 2px;
  box-shadow: shadow.$z4; // TODO: this should really have a highlight
  background-color: theme-color.$surface-z8;

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

  &,
  .csd & {
    border-style: solid;
    border-width: 1px;
    border-color: rgba(black, .1) rgba(black, .2) rgba(black, .3);
    border-radius: theme.$corner-radius + 1px;
    background-clip: padding-box;
  }

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

  > toolbar {
    margin: -2px;
  }

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

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

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

  &.menu button,
  button.model {
    @extend %button-flat;

    min-height: 32px;
    padding: 0 8px;
    border-radius: theme.$corner-radius;
  }

  separator {
    margin: 4px 0;
  }

  list separator {
    margin: 0;
  }
}

/**
 * Notebooks
 */

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

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

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

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

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

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

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

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

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

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

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

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

          &:checked {
            box-shadow: inset 2px 0 theme-color.$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: theme-color.hint(theme-color.$on-surface);
      @extend %ripple;
      @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);

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

    > tabs > tab {
      transition: theme.$transition,
                  background-size 0ms,
                  background-image 0ms;
      min-height: theme.$small-size;
      min-width: theme.$small-size;
      padding: theme.$container-padding 16px;
      outline: none;
      background-image: radial-gradient(circle, theme-color.$primary 10%, transparent 0%);
      background-repeat: no-repeat;
      background-position: center;
      background-size: 0% 0%;
      color: theme-color.hint(theme-color.$on-surface);
      font-weight: 500;

      &:hover {
        background-color: theme-color.hover-overlay(theme-color.$on-surface, $alt: true);
      }

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

      &:checked {
        transition: theme.$transition,
                    background-size theme.$ripple-duration theme.$ease-out,
                    background-image theme.$ripple-duration + theme.$ripple-fade-out-duration theme.$ease-out;
        background-color: transparent;
        background-image: radial-gradient(circle, transparent 10%, transparent 0%);
        background-size: 1000% 1000%;
        color: theme-color.$primary;

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

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

        &.dnd {
          background-color: theme-color.dragged-overlay(theme-color.$primary);
        }
      }

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

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

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

        &:last-child {
          margin-left: theme.$container-padding;
          margin-right: theme.$container-padding - 16px;
        }

        &:first-child {
          margin-left: theme.$container-padding - 16px;
          margin-right: theme.$container-padding;
        }
      }
    }
  }
}

/**
 * Scrollbars
 */

scrollbar {
  $_slider_min_length: 24px;

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

  transition: theme.$transition;
  // background-color: $surface-z0;
  background-clip: padding-box;

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

  // slider
  slider {
    transition: background-color theme.$state-duration theme.$ease-out;
    min-width: 8px;
    min-height: 8px;
    border: 4px solid transparent;
    border-radius: theme.$circular-radius;
    background-clip: padding-box;
    background-color: theme-color.scrollbar-thumb(theme-color.$on-surface);

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

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

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

  &.fine-tune {
    slider {
      min-width: 4px;
      min-height: 4px;
    }

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

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

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

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

      slider {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid rgba(theme-color.$surface-z1, .3);
      }

      button {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid rgba(theme-color.$surface-z1, .3);
        border-radius: theme.$circular-radius;
        background-color: theme-color.scrollbar-thumb(theme-color.$on-surface);
        background-clip: padding-box;
        -gtk-icon-source: none;

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

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

        button {
          min-width: 8px;
        }
      }

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

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

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

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

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

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

    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 theme.$state-duration theme.$ease-out;
  margin: theme.$container-padding 0;
  padding: 0 2px;
  border: 5px solid transparent;
  border-radius: theme.$circular-radius;
  background-color: theme-color.stroke(theme-color.$on-surface);
  background-clip: padding-box;
  font-size: 0;

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

  &:disabled {
    opacity: .5;
  }

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

  slider {
    transition: all theme.$state-duration theme.$ease-out;
    min-width: 20px;
    min-height: 20px;
    margin: -3px -2px;
    border-radius: theme.$circular-radius;
    outline: none;
    box-shadow: 0 0 0 10px transparent, shadow.$z1;
    background-color: theme-color.$surface-switch-thumb;
  }

  &:hover slider {
    box-shadow: 0 0 0 10px theme-color.hover-overlay(theme-color.$on-surface), shadow.$z1;
  }

  &:focus slider {
    box-shadow: 0 0 0 10px theme-color.focus-overlay(theme-color.$on-surface), shadow.$z1;
  }

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

  &:checked:hover slider {
    box-shadow: 0 0 0 10px theme-color.hover-overlay(theme-color.$primary), shadow.$z1;
  }

  &:checked:focus slider {
    box-shadow: 0 0 0 10px theme-color.focus-overlay(theme-color.$primary), shadow.$z1;
  }

  row:selected & {
  }
}

/**
 * Check and Radio items
 */

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

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

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

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

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

checkbutton,
radiobutton {
  outline: none;
}

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

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

$check-radio-size: 40px;

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

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

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

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

  popover modelbutton.flat & {
    &,
    &:focus,
    &:hover,
    &:focus:hover,
    &:active,
    &:disabled {
      transition: none; // FIXME: this is a workaround for a popover check/radio long transition issue
      background-color: transparent;
      background-image: none;
    }

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

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

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

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

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

    &,
    &:checked,
    &:indeterminate {
      &:hover,
      &:focus {
        background-color: transparent;
      }
    }
  }
}

%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:
    -gtk-gradient(
      radial,
      center center, 0,
      center center, .001,
      to(theme-color.$primary),
      to(transparent)
    );

  &:checked:not(:indeterminate) {
    border-image-source:
      -gtk-gradient(
        radial,
        center center, 0,
        center center, $radio-indicator-size,
        to(theme-color.$primary),
        to(transparent)
      );

    &:disabled {
      border-image-source:
        -gtk-gradient(
          radial,
          center center, 0,
          center center, $radio-indicator-size,
          to(theme-color.disabled-hint(theme-color.$on-surface)),
          to(transparent)
        );
    }
  }
}

%small_check,
menu menuitem check {
  min-height: 16px;
  min-width: 16px;
  border-radius: theme.$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,
menu menuitem 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: theme-color.hint(theme-color.$on-surface);

  &:checked,
  &:indeterminate {
    color: theme-color.$primary;
  }

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

  &,
  &:hover,
  &:selected,
  &:selected:hover {
    box-shadow: none;
    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: (theme.$medium-size - $trough_size) / 2 12px;
  }

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

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

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

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

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

  // the backing bit
  trough {
    transition: background-color theme.$state-duration theme.$ease-out;
    outline: none;
    background-color: theme-color.stroke(theme-color.$on-surface);

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

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

    &:disabled {
      background-color: theme-color.$surface-z0;
      background-image: image(theme-color.disabled-hint(theme-color.$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 theme.$state-duration theme.$ease-out;
    background-color: theme-color.stroke(theme-color.$on-surface);

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

  slider {
    transition: background-color theme.$state-duration theme.$ease-out,
                background-size theme.$ripple-fade-out-duration theme.$ease-out,
                background-image theme.$ripple-opacity-fade-out-duration theme.$ease-out;
    background-repeat: no-repeat;
    background-position: center;
    background-size: auto, 1000% 1000%;
    border-radius: 50%;
    color: theme-color.$primary;

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

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

    &:hover {
      background-color: theme-color.hover-overlay(theme-color.$primary);
    }

    &:focus {
      background-color: theme-color.focus-overlay(theme-color.$primary);
    }

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

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

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

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

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

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

            background-image:
              -gtk-scaled(url('#{$_scale_asset}.svg'), url('#{$_scale_asset}@2.svg')),
              radial-gradient(circle, theme-color.pressed-overlay(theme-color.$primary) 10%, transparent 0%);
          }
        }
      }
    }
  }

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

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

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

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

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

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

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

/**
 * Progress bars
 */

progressbar {
  // sizing
  &.horizontal {
    trough,
    progress {
      min-height: 4px;
    }
  }

  &.vertical {
    trough,
    progress {
      min-width: 4px;
    }
  }

  // FIXME: insensitive state missing and some other state should be set probably
  color: theme-color.hint(theme-color.$on-surface);
  font-size: smaller;

  trough {
    background-color: theme-color.disabled-stroke(theme-color.$on-surface);
  }

  progress {
    background-color: theme-color.$primary;
  }

  &.osd { // progressbar.osd used for epiphany page loading progress
    // min-width: 4px;
    // min-height: 4px;
    // 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 {
    block {
      min-height: 4px;
    }

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

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

  &.vertical {
    block {
      min-width: 4px;
    }

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

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

  trough {
  }

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

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

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

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

/**
 * Print dialog
 */

printdialog {
  paper {
    padding: 0;
    border: 1px solid theme-color.divider(theme-color.$on-surface);
    background-clip: padding-box;
    background-color: theme-color.$surface-z1;
    color: theme-color.$on-surface;
  }

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

/**
 * Frames
 */

frame > border,
.frame {
  margin: 0;
  padding: 0;
  border: 1px solid theme-color.divider(theme-color.$on-surface);
  border-radius: 0;
  box-shadow: none;
  background-clip: padding-box;
  background-color: theme-color.$surface-z1;

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

// for backward compatibility
frame.flat > border {
  border-style: none;
  background-color: transparent;
}

actionbar > revealer > box {
  padding: theme.$container-padding;
  border-top: 1px solid theme-color.divider(theme-color.$on-surface);
  // background-color: $surface-z1;

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

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

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

  // 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 drawing.overshoot(top); }

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

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

    &.right { @include drawing.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: theme-color.divider(theme-color.$on-surface);
    // background-color: $surface-z0;

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

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

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

/**
 * Lists
 */

list {
  border-color: theme-color.divider(theme-color.$on-surface);
  // background-color: $surface-z1;

  row {
    padding: 2px;
  }
}

row {
  background-clip: padding-box;

  &.activatable {
    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);
    @include drawing.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: theme-color.activated-overlay(theme-color.$on-surface);
    }
  }

  &:selected {
    @include drawing.ink-color(theme-color.$primary, $hover-alt: true, $on: theme-color.$selected-overlay);

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

/**
 * App Notifications
 */

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

  button {
    @extend %button-flat;

    &.text-button:not(:disabled) {
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary, $button-style: "flat");
    }
  }

  &.frame {
    border-style: none;
  }

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

/**
 * Expanders
 */

expander {
  title > arrow {
    transition: all theme.$state-duration theme.$ease-out;
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');

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

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

    color: theme-color.hint(theme-color.$on-surface);

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

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

/**
 * Calendar
 */

calendar {
  padding: 1px;
  border: 1px solid theme-color.divider(theme-color.$on-surface);
  background-clip: padding-box;
  background-color: theme-color.$surface-z1;
  color: theme-color.$on-surface;

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

  &:selected {
    border-radius: theme.$corner-radius + 1px;
    background-color: theme-color.$selected-overlay;
  }

  &.header {
    border-style: none none solid;
    border-color: theme-color.divider(theme-color.$on-surface);
    border-radius: 0;
  }

  &.button {
    border-radius: theme.$corner-radius + 1px;
    color: theme-color.hint(theme-color.$on-surface);

    &:hover {
      background-image: image(theme-color.hover-overlay(theme-color.$on-surface));
    }

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

  &.highlight {
    color: theme-color.hint(theme-color.$on-surface);
    font-weight: 500;
  }

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

/**
 * Dialogs
 */

// Message Dialog styling
messagedialog {
  &.background {
    background-color: theme-color.$surface-z8;
  }

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

    &:backdrop {
      background-color: theme-color.$surface-z8;
      color: theme-color.hint(theme-color.$on-surface);
    }
  }

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

  // Hint text
  box.vertical > label + label {
    color: theme-color.hint(theme-color.$on-surface);
  }

  .dialog-action-box {
    margin-top: -(theme.$container-padding);
    // padding: $container-padding;

    button {
      @extend %button-flat;

      &:not(:last-child) {
        margin-right: theme.$container-padding;
      }

      &:not(:disabled) {
        color: theme-color.$primary;
        @include drawing.ink-color(theme-color.$primary, $button-style: "flat");
      }

      &.suggested-action:not(:disabled) {
        // color: $primary;
        // @include ink-color($primary, $button-style: "flat");
      }

      &.destructive-action:not(:disabled) {
        color: theme-color.$error;
        @include drawing.ink-color(theme-color.$error, $button-style: "flat");
      }
    }
  }
}

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

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

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

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

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

/**
 * Sidebar
 */

.sidebar {
  border-style: none;
  background-color: theme-color.$sidebar-surface-z1;//transparent; Materia

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

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

  list {
    // background-color: transparent;
  }

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

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

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

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

  list {
    padding: 4px;
    // background-color: $surface-z0; // This should not be necessary, but the parent stacksidebar ignores background-color.
  }

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

    &:selected {
      $background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary, $on: $background-color, $hover-alt: true);
    }

    + row {
      margin-top: 4px;
    }

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

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

separator.sidebar {
  background-color: theme-color.divider(theme-color.$on-surface);

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

/**
 * File chooser
 */

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

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

placessidebar.sidebar {
  > viewport.frame {
    border-style: none;
    background-color: transparent;
  }

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

  row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: 32px;
    margin: -1px 4px; // Remove unwanted hard-coded vertical margins with -1px
    padding: 0;
    border-radius: theme.$corner-radius;

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

    &:selected {
      $background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
      font-weight: 500;
      @include drawing.ink-color(theme-color.$primary, $on: $background-color, $hover-alt: true);

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

    &:disabled {
      color: theme-color.disabled(theme-color.$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: theme-color.hover-overlay(theme-color.$on-surface);
    }

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

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

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

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

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

/**
 * Paned
 */

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

    &.wide {
      min-width: 6px;
      min-height: 6px;
      // background-color: $surface-z0;
      background-image: image(theme-color.divider(theme-color.$on-surface)), image(theme-color.divider(theme-color.$on-surface));
      background-size: 1px 1px, 1px 1px;
    }
  }

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

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

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

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

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

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

/**
 * GtkInfoBar
 */

infobar {
  border-style: none;

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

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

    button {
      @extend %button-flat;

      &.text-button:not(:disabled) {
        color: theme-color.$primary;
        @include drawing.ink-color(theme-color.$primary, $button-style: "flat");
      }
    }
  }

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

    button.flat {
      color: theme-color.$on-warning;
      @include drawing.ink-color(theme-color.$on-warning, $button-style: "flat");
    }

    selection {
    }

    *:link {
      color: theme-color.$on-warning;
    }
  }

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

    button.flat {
      color: theme-color.$on-error;
      @include drawing.ink-color(theme-color.$on-error, $button-style: "flat");
    }

    selection {
    }

    *:link {
      color: theme-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: theme-color.$tooltip;
    color: theme-color.$on-tooltip;
  }

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

  &:not(.csd):not(.unity-csd) {
    // border: 1px solid divider($on-surface);
    // border-radius: $corner-radius + 1px;
  }

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

  > box {
    margin: -6px; // Remove hard-coded 6px margin
    min-height: 32px - 4px * 2;
    padding: 4px 8px;
  }

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

  * {
    // workaround for Eclipse.
    // do not include any declaration here.
  }
}

/**
 * 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: theme.$corner-radius + .5px;
    border-top-right-radius: theme.$corner-radius + .5px;

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

  &.bottom {
    border-bottom-left-radius: theme.$corner-radius + .5px;
    border-bottom-right-radius: theme.$corner-radius + .5px;

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

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

    overlay {
      border-top-left-radius: theme.$corner-radius;
      border-bottom-left-radius: theme.$corner-radius;
    }
  }

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

    overlay {
      border-top-right-radius: theme.$corner-radius;
      border-bottom-right-radius: theme.$corner-radius;
    }
  }

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

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

  overlay {
    transition: theme.$transition-shadow;
    box-shadow: shadow.$z1;

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

  &#add-color-button {
    border-radius: theme.$corner-radius theme.$corner-radius 0 0;
    color: theme-color.$on-surface;

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

    overlay {
      background-color: theme-color.$surface-z8;
    }
  }

  &:disabled {
    opacity: .5;

    overlay {
      box-shadow: none;
    }
  }

  row:selected & {
  }

  &#editor-color-sample {
    border-radius: theme.$corner-radius + .5px;

    overlay {
      border-radius: theme.$corner-radius;

      &:hover {
        // box-shadow: $shadow-z1;
      }
    }
  }
}

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

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

/**
 * Misc
 */

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

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

  rubberband,
  .rubberband {
    @extend %rubberband;
  }
}

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

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

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

/**
 * Window Decorations
 */

decoration {
  transition: theme.$transition-shadow;
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  box-shadow: shadow.$z16, 0 16px (24px * .6) 2px transparent, 0 6px (30px * .6) 5px transparent;

  // FIXME rationalize shadows

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

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

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

  .popup & {
    box-shadow: none;
  }

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

  .csd.popup & {
    border-radius: theme.$corner-radius;
    box-shadow: shadow.$z4;
  }

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

  messagedialog.csd & {
    border-radius: theme.$corner-radius;
    // box-shadow: $shadow-z24, 0 24px (38px * .6) 3px transparent, 0 9px (46px * .6) 8px transparent;

    &:backdrop {
      // box-shadow: $shadow-z4, 0 24px (38px * .6) 3px transparent, 0 9px (46px * .6) 8px transparent;
    }
  }

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

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

// Window Close button
button.titlebutton {
  border-radius: theme.$circular-radius;

  .selection-mode & {
  }
}


// catch all extend :)

.monospace {
  font-family: monospace;
}

/**
 * Touch Copy & Paste
 */

// touch selection handlebars for the Popover.osd above
cursor-handle {
  color: theme-color.$primary;
  -gtk-icon-source: -gtk-recolor(url("icons/cursor-handle-symbolic.svg"));

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

  &.bottom:dir(ltr),
  &.top:dir(rtl) {
    -gtk-icon-transform: unset;
  }

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

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

// shortcut window keys
.keycap {
  min-width: 28px - 8px * 2;
  min-height: 28px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: theme.$corner-radius;
  box-shadow: shadow.$z1;
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
  font-size: smaller;
}

// workaround for clipped shadows of .keycap
shortcut:last-child {
  margin-bottom: 4px;
}

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

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

// FIXME aggregate with buttons
stackswitcher button.circular,
stackswitcher button.text-button.circular {
  min-width: theme.$medium-size;
  min-height: theme.$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 {
  padding: 0;

  entry {
    border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
    border-image: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
  }

  scrolledwindow {
    border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
  }
}

button.emoji-section {
  margin: 4px;

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

popover.emoji-picker .emoji {
  min-width: 3em;
  min-height: 3em;
  padding: 0 8px;
  // font-size: larger;

  widget {
    transition: theme.$transition;
    border-radius: theme.$corner-radius;

    &:hover {
      background-color: theme-color.hover-overlay(theme-color.$on-surface);
    }
  }
}

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

  arrow {
    border: none;
    background: none;
  }

  .emoji-completion-row {
    min-height: theme.$menu-item-dense-height;
    padding: 0 12px;
  }

  .emoji:hover {
    background-color: theme-color.hover-overlay(theme-color.$on-surface);
  }
}

@if theme.$darkest-theme {
  .titlebar:backdrop {
    color: #8CAAEE;
  }

  .titlebar button:not(.suggested-action):not(.destructive-action) {
    color: #ffffff;
  }

  .titlebar:backdrop button:not(.suggested-action):not(.destructive-action) {
    color: #8CAAEE;
  }
}

@if theme.$frappe-theme {
  .titlebar:backdrop {
    color: #f4b8e4;
  }

  .titlebar button:not(.suggested-action):not(.destructive-action) {
    color: #C6D0F5;
  }

  .titlebar:backdrop button:not(.suggested-action):not(.destructive-action) {
    color: #f4b8e4;
  }
}
