@mixin headerbar_buttons($bg, $fg, $br)
{
  padding: 4px 8px;
  border: none;
  border-radius: $button_radius;
  color: $fg;
  border-color: $br;
  background-color: $bg;
  
  outline-style: solid;
  outline-width: 2px;
  outline-offset: 0;
  -gtk-outline-radius: 0;

  &:hover {}

  &:active, &:checked {
    outline-color: gtkshade($selected_bg_color, 1.4);
    color: $selected_fg_color;

    &:disabled {
      color: gtkmix($selected_fg_color, $disabled_fg_color, 0.4);
      background-color: $bg;
    
      &:backdrop {
        color: gtkmix($selected_fg_color, $unfocused_disabled_fg_color, 0.4);
        background-color: $bg;
      }
    }

    &:backdrop { color: $unfocused_selected_fg_color; }
  }

  &:disabled {
    color: gtkmix($fg, $unfocused_disabled_fg_color, 0.1);
    background-color: $bg;
    
    &:backdrop {
      color: $unfocused_disabled_fg_color;
      background-color: transparent;
    }
  }

  &:backdrop {
    color: $unfocused_fg_color;
    background-color: transparent;
  }
}

@mixin headerbar() {
  headerbar {
    padding: 4px 8px;
    min-height: 30px;
    color: $titlebar_fg_color;
    background-color: $titlebar_bg_color;
    border-bottom: 1px solid gtkshade($titlebar_bg_color, 0.6);

    &:backdrop {
      background-color: $unfocused_bg_color;
      color: $unfocused_fg_color;
      border-color: $unfocused_borders;
    }

    .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, $headerbar_bg_color);
    }
    
    entry { padding: 4px 8px; }
    &.titlebar, .titlebar & { border-radius: $csd_radius $csd_radius 0px 0px; }

    .titlebutton {
      &.close, &.maximize, &.minimize, &:not(separator) {
        padding: 2px 2px;
        background-color: transparent;
        
        &:active {
          color: gtkshade($titlebar_fg_color, 0.85);
        }
      }
    }
  }
}
