@mixin headerbar_buttons($bg, $fg, $br)
{
  padding: 4px 8px;
  border-style: solid;
  border-width: 1px;
  border-radius: $button_radius;
  color: $fg;
  border-color: $br;
  border-top-color: gtkshade($br, 1.1);
  border-left-color: gtkshade($br, 1.05);
  border-right-color: gtkshade($br, 1.05);
  background-color: $bg;
  -gtk-outline-radius: $button_radius;

  &:hover {
    color: $fg;
    background-color: gtkshade($bg, 1.1);
  }

  &:active, &:checked {
    color: $selected_fg_color;
    border-color: gtkshade($br, 0.9);
    background-color: gtkmix($bg, $fg, 0.2);

    &:backdrop {}
    
    &:disabled {
      color: gtkmix($fg, $unfocused_disabled_fg_color, 0.1);
      border-color: gtkmix($fg, $disabled_bg_color, 0.85);
      background-color: gtkshade($disabled_bg_color, 0.9);
      
      &:backdrop {}
    }
  }

  &:disabled {
    color: gtkmix($fg, $unfocused_disabled_fg_color, 0.5);
    
    &:backdrop {}
  }

  &:backdrop {}
}

@mixin headerbar() {
  headerbar {
    padding: 4px 8px;
    min-height: 30px;
    color: $titlebar_fg_color;
    background-color: $titlebar_bg_color;

    &:backdrop { color: gtkalpha($titlebar_fg_color, 0.8); }

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

    .subtitle {
      font-size: smaller;
      padding-left: 12px;
      padding-right: 12px;
      color: gtkalpha(currentColor, 0.7);
    }

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

    entry { padding: 4px 8px; }
    &.titlebar, .titlebar & { border-radius: $csd_radius $csd_radius 0px 0px; }
    
    .titlebutton {
      &.close, &.maximize, &.minimize, &:not(separator) {
        min-width: 28px;
        min-height: 28px;
        padding: 0;
        border: none;
        color: transparent;
        background-color: transparent;
        -gtk-icon-shadow: none;
        border-radius: 100%;
        
        background-position: center center;
        background-repeat: no-repeat;
        
        &:hover, &:active { background-color: gtkalpha($base_color, 0.2); }
      }
      
      &.close {
        background: url('assets/close-normal.png') center center;

        &:hover, &:active { background-color: $error_color; }
        &:backdrop { background: url('assets/close-backdrop.png') center center; }
      }

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

        &:backdrop { background: url('assets/minimize-backdrop.png') center center; }
      }

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

        &:backdrop { background: url('assets/maximize-backdrop.png') center center; }
      }
    }
  }
}
