@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-size: 1px 100%;
    background-image: url('assets/titlebar-focused-middle.png');

    &:backdrop {
      color: $unfocused_fg_color;
      background-color: $unfocused_bg_color;
      background-image: url('assets/titlebar-unfocused-middle.png');
    }

    // 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;
      padding: 0 12px;
      text-shadow: 1px 1px gtkalpha($dark_shadow, 0.3);
      
      &:backdrop {
        text-shadow: none;
        color: gtkalpha($titlebar_fg_color, 0.3);
      }
    }

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

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

    entry { padding: 6px 8px; }
    &.titlebar, .titlebar & { border-radius: $csd_radius $csd_radius 0px 0px; }
    
    .titlebutton {
      &.close, &.maximize, &.minimize, &:not(separator) {
        padding: 2px 2px;
        border: none;
        box-shadow: none;
        color: transparent;
        background-color: transparent;
        -gtk-icon-shadow: none;
        
        background-position: center;
        background-repeat: no-repeat;
      }
      &.close {
        background: url('assets/close-normal.png') 100% 100%;

        &:hover { background: url('assets/close-hover.png') 100% 100%; }
        &:active { background: url('assets/close-active.png') 100% 100%; }

        &:backdrop {
          background: url('assets/close-backdrop.png') 100% 100%;
          
          &:hover { background: url('assets/close-backdrop-hover.png') 100% 100%; }
          &:active { background: url('assets/close-active.png') 100% 100%; }
        }
      }

      &.minimize {
        background: url('assets/minimize-normal.png') 100% 100%;

        &:hover { background: url('assets/minimize-hover.png') 100% 100%; }
        &:active { background: url('assets/minimize-active.png') 100% 100%; }

        &:backdrop {
          background: url('assets/minimize-backdrop.png') 100% 100%;
          
          &:hover { background: url('assets/minimize-backdrop-hover.png') 100% 100%; }
          &:active { background: url('assets/minimize-active.png') 100% 100%; }
        }
      }

      &.maximize {
        background: url('assets/maximize-normal.png') 100% 100%;

        &:hover { background: url('assets/maximize-hover.png') 100% 100%; }
        &:active { background: url('assets/maximize-active.png') 100% 100%; }

        &:backdrop {
          background: url('assets/maximize-backdrop.png') 100% 100%;
          
          &:hover { background: url('assets/maximize-backdrop-hover.png') 100% 100%; }
          &:active { background: url('assets/maximize-active.png') 100% 100%; }
        }
      }
      
      .maximized &.maximize {
        background: url('assets/restore-normal.png') 100% 100%;

        &:hover { background: url('assets/restore-hover.png') 100% 100%; }
        &:active { background: url('assets/restore-active.png') 100% 100%; }

        &:backdrop {
          background: url('assets/restore-backdrop.png') 100% 100%;
          
          &:hover { background: url('assets/restore-backdrop-hover.png') 100% 100%; }
          &:active { background: url('assets/restore-active.png') 100% 100%; }
        }
      }
    }
  }
}
