@mixin headerbar_buttons($bg, $fg, $br)
{
  @include normal_buttons($bg, $fg, $br);
}

@mixin headerbar() {
  headerbar {
    padding: 4px 8px;
    min-height: 30px;
    color: $titlebar_fg_color;
    background-color: $titlebar_bg_color;
    background-image: linear-gradient(to bottom, gtkshade($titlebar_bg_color, 1.2), $titlebar_bg_color, gtkshade($titlebar_bg_color, 0.9));
    box-shadow: inset 0 1px gtkalpha($light_shadow, 0.6);
    border-bottom: 1px solid $dark_shadow;

    &:backdrop {
      background-image: linear-gradient(to bottom, gtkshade($unfocused_bg_color, 1.05), $unfocused_bg_color);
      box-shadow: none;
      border-bottom-color: gtkalpha($dark_shadow, 0.15);
    }

    .tiled &, .tiled &:backdrop,
    .maximized &, .maximized &:backdrop {
      border-radius: 0;
    }
    
    // Fixes split headerbars
    separator:first-child + &,
    &:first-child {
      &, &:backdrop {
        border-top-left-radius: $csd_radius;

        .maximized &,
        .tiled & { border-radius: 0; }
      }
    }

    &:last-child {
      &, &:backdrop {
        border-top-right-radius: $csd_radius;

        .maximized &,
        .tiled & { border-radius: 0; }
      }
    }
    
    .title {
      padding-left: 12px;
      padding-right: 12px;
      font-weight: bold;
      color: $titlebar_fg_color;
      text-shadow: 1px 1px $dark_shadow;
      
      &:backdrop {
        color: $unfocused_fg_color;
        text-shadow: none;
      }
    }

    .subtitle {
      font-size: smaller;
      padding-left: 12px;
      padding-right: 12px;
      color: gtkalpha($titlebar_fg_color, 0.7);
      
      &:backdrop {
        color: gtkalpha($unfocused_fg_color, 0.7);
      }
    }

    button {
      @include headerbar_buttons($headerbar_bg_color, $headerbar_fg_color, $borders);
    }

    entry { padding: 4px 8px; }
    &.titlebar, .titlebar & { border-radius: $csd_radius $csd_radius 0px 0px; }
    
    .titlebutton {
      &.close, &.maximize, &.minimize, &:not(separator) {
        min-width: 18px;
        min-height: 18px;
        padding: 0;
        color: transparent;
        background-image: none;
        -gtk-icon-shadow: none;
        
        background-color: gtkalpha($dark_shadow, 0.3);
        border-color: gtkalpha($light_shadow, 0.3);
        color: $titlebar_fg_color;
        
        &:hover {
          background-color: gtkalpha($dark_shadow, 0.15);
          border-color: gtkalpha($light_shadow, 0.45);
        }
        
        &:active {
          background-color: gtkalpha($dark_shadow, 0.5);
          border-color: gtkalpha($light_shadow, 0.5);
        }
        
        &:backdrop {
          background-color: gtkalpha($light_shadow, 0.3);
          border-color: gtkalpha($dark_shadow, 0.3);
          color: $unfocused_fg_color;
        }
      }
    }
  }
}
