headerbar {
  min-height: 47px;
  background-color: $headerbar_bg_color;
  color: $headerbar_fg_color;
  box-shadow: inset 0 -1px if($contrast == 'high', $headerbar_border_color, $headerbar_shade_color),
              inset  1px 0 $headerbar_border_color,
              inset -1px 0 $headerbar_border_color;

  margin-left: -1px;
  margin-right: -1px;

  @extend %toolbar;

  > windowhandle > box {
    padding: 0 7px 1px 7px;

    &,
    > box.start,
    > box.end {
      border-spacing: 6px;
    }
  }

  &:backdrop {
    background-color: $headerbar_backdrop_color;
    transition: background-color $backdrop_transition;

    > windowhandle {
      // opacity looks weird with GtkSwitch, but filter works fine
      filter: opacity(0.5);

      transition: filter $backdrop_transition;
    }
  }

  &.default-decoration {
    min-height: 37px;

    > windowhandle > box {
      padding: 0 4px 1px 4px;
    }

    windowcontrols {
      > button {
        min-height: 22px;
        min-width: 22px;
        margin: 0;
        padding: 4px;
      }

      > .icon {
        margin: 7px;
      }
    }
  }

  &.flat {
    background: none;
    box-shadow: none;
    color: inherit;

    min-height: 46px;

    > windowhandle > box {
      padding-bottom: 0;
    }

    &.default-decoration {
      min-height: 36px;
    }
  }

  .solid-csd & {
    &:backdrop, & {
      &:dir(rtl), &:dir(ltr) { // specificity bump
        margin-top: -1px;

        > windowhandle > box { padding-top: 1px; }
      }
    }
  }
}

.titlebar:not(headerbar) {
  separator { background-color: $headerbar_border_color; }
}

/*********************
 * GtkWindowControls *
 *********************/

windowcontrols {
  border-spacing: 3px;

  > button {
    min-width: 24px;
    padding: 5px;
    margin: 0;
    box-shadow: none;

    > image {
      background-color: $button_color;
      border-radius: 100%;
      padding: 2px;
      transition: $button_transition;
      @if $contrast == 'high' {
        box-shadow: inset 0 0 0 1px $border_color;
      }
    }

    &, &:hover, &:active {
      background: none;
    }

    &:hover > image { background-color: $button_hover_color; }
    &:active > image { background-color: $button_active_color; }
  }

  > .icon {
    margin: 9px;
  }
}

/******************
 * AdwWindowTitle *
 ******************/

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

  .subtitle {
    font-size: smaller;
    padding-left: 12px;
    padding-right: 12px;
    @extend .dim-label;
  }
}

// Development versions of apps to use a differently styled headerbar

window.devel {
  headerbar > windowhandle {
    background-image: cross-fade(5% -gtk-recolor(url("assets/devel-symbolic.svg")),
                                 image(transparent));
    background-repeat: repeat-x;
  }
}
