$headerbar_border_opacity: if($contrast == 'high', .5, .15);

headerbar {
  min-height: 47px;
  background-color: $headerbar_bg_color;
  color: $headerbar_fg_color;
  box-shadow: inset 0 -1px gtkalpha($headerbar_border_color, $headerbar_border_opacity),
              inset  1px 0 gtkalpha($headerbar_border_color, $headerbar_border_opacity),
              inset -1px 0 gtkalpha($headerbar_border_color, $headerbar_border_opacity);

  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: $bg_color;

    transition: $backdrop_transition;

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

      transition: $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;
      }
    }
  }

  &.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: $borders_color; }  // FIXME: use darker border?
}

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

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

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

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