.#{$prefix}column-header {
    border-right: $grid-column-header-border-width $grid-column-header-border-style $grid-header-border-color;

    @if not is-null($grid-column-header-color) {
        color: $grid-column-header-color;
    }
    font: $grid-column-header-font;

    // This is to remove default focused element styling in Firefox and IE
    outline: 0;

    @if not is-null($grid-header-background-gradient) {
        @include background-gradient($grid-header-background-color, $grid-header-background-gradient);
    }
    @if is-null($grid-header-background-gradient) {
        background-color: $grid-header-background-color;
    }
}

@if $include-rtl {
    .#{$prefix}rtl.#{$prefix}column-header {
        border-right: 0 none;
        border-left: $grid-column-header-border-width $grid-column-header-border-style $grid-header-border-color;
    }
}

.#{$prefix}group-sub-header {
    background: transparent;
    border-top: $grid-column-header-border-width $grid-column-header-border-style $grid-header-border-color;

    // Because the sub-header has a top border, the padding of the inner is reduced by the border width
    .#{$prefix}column-header-inner {
        padding: top($grid-header-padding) - $grid-column-header-border-width right($grid-header-padding) bottom($grid-header-padding) left($grid-header-padding);
    }
}

.#{$prefix}column-header-inner {
    padding: $grid-header-padding;
}

.#{$prefix}column-header-inner-empty {
    // The default text for an empty column header is a space.  It can trigger an ellipsis
    // if the column width is too small.  Ensure this does not happen by clipping overflow
    // of empty colum headers.
    text-overflow: clip;
}

// Compound selector here to increase the specificity
.#{$prefix}column-header.#{$prefix}column-header-focus {
    .#{$prefix}column-header-inner:after {
        content: "";
        position: absolute;
        z-index: 5; // focus border must overlay the trigger
        top: $grid-column-header-focus-border-inset;
        right: $grid-column-header-focus-border-inset;
        bottom: $grid-column-header-focus-border-inset;
        left: $grid-column-header-focus-border-inset;
        border: $grid-column-header-focus-border-width $grid-column-header-focus-border-style $grid-column-header-focus-border-color;
        pointer-events: none;
    }

    // For some reason without this rule the inner focus border on grouped column headers
    // looks 1px higher than it should. This does not apply to column headers outside a group
    &.#{$prefix}group-sub-header .#{$prefix}column-header-inner:before {
        bottom: 0px;
    }

    @if not is-null($grid-column-header-focus-color) {
        color: $grid-column-header-focus-color;
    }

    @if not is-null($grid-column-header-focus-background-color) {
        @include background-gradient($grid-column-header-focus-background-color, $grid-header-background-gradient);
    }
}

.#{$prefix}column-header-over {
    @include background-gradient($grid-header-over-background-color, $grid-header-over-background-gradient);
}

.#{$prefix}column-header-sort-ASC,
.#{$prefix}column-header-sort-DESC {
    @include background-gradient($grid-header-sorted-background-color, $grid-header-sorted-background-gradient);
}

@if $include-slicer-gradient {
    @if not is-null($grid-header-background-gradient) {
        .#{$prefix}nlg {
            .#{$prefix}grid-header-ct,
            .#{$prefix}column-header {
                background-image: slicer-background-image(column-header, 'grid/column-header-bg');
            }
        }
        $stretch: slicer-background-stretch(column-header, bottom);
    }

    @if not is-null($grid-header-over-background-gradient) {
        .#{$prefix}nlg {
            .#{$prefix}column-header-over,
            .#{$prefix}column-header-sort-ASC,
            .#{$prefix}column-header-sort-DESC {
                background-image: slicer-background-image(column-header-over, 'grid/column-header-over-bg');
            }
        }
        $stretch: slicer-background-stretch(column-header-over, bottom);
    }
}

.#{$prefix}column-header-open {
    background-color: $grid-header-open-background-color;

    .#{$prefix}column-header-trigger {
        background-color: $grid-header-trigger-background-color-open;
    }
}

.#{$prefix}column-header-over .#{$prefix}column-header-trigger,
.#{$prefix}column-header-open .#{$prefix}column-header-trigger {
    width: $grid-header-trigger-width;
    cursor: $grid-header-trigger-cursor;
    @if $enable-font-icons and ($grid-header-trigger-glyph != null) {
        @include font-icon($grid-header-trigger-glyph);
        color: $grid-header-trigger-glyph-color;

        &:before {
            // vertically center the glyph
            top: 50%;
            margin-top: -($grid-header-trigger-glyph-font-size / 2);
            text-align: center;
            position: relative;
            display: block;
        }
    } @else {
        background: $grid-header-trigger-background-color theme-background-image($grid-header-trigger-background-image) no-repeat $grid-header-trigger-background-position;
    }
}

@if $include-rtl {
    .#{$prefix}rtl.#{$prefix}column-header-trigger {
        background-position: rtl-background-position($grid-header-trigger-background-position);
    }
}

$grid-column-align-right-margin:
    $grid-header-trigger-width +
    $grid-header-trigger-spacing -
    right($grid-header-padding);

.#{$prefix}column-header-align-right .#{$prefix}column-header-text {
    margin-right: $grid-column-align-right-margin;
}

@if $include-rtl {
    .#{$prefix}column-header-align-right .#{$prefix}rtl.#{$prefix}column-header-text {
        margin-right: 0;
        margin-left: $grid-column-align-right-margin;
    }
}

// Sort direction indicator is a background of the text span.
.#{$prefix}column-header-sort-ASC,
.#{$prefix}column-header-sort-DESC {
    .#{$prefix}column-header-text-inner {
        @if $enable-font-icons and (($grid-header-sort-asc-glyph != null) or ($grid-header-sort-desc-glyph != null)) {
            &:after {
                display: inline-block;
                text-align: center;
                margin-left: $grid-header-sort-icon-spacing;
                width: $grid-header-sort-glyph-font-size;
            }
        } @else {
            padding-right: $grid-header-sort-icon-width + $grid-header-sort-icon-spacing;
        }
        background-position: $grid-header-sort-icon-position;
    }
}

@if $include-rtl {
    .#{$prefix}column-header-sort-ASC,
    .#{$prefix}column-header-sort-DESC {
        .#{$prefix}rtl.#{$prefix}column-header-text-inner {
            @if $enable-font-icons and (($grid-header-sort-asc-glyph != null) or ($grid-header-sort-desc-glyph != null)) {
                &:after {
                    margin-left: 0;
                    margin-right: $grid-header-sort-icon-spacing;
                }
            } @else {
                padding-right: 0;
                padding-left: $grid-header-sort-icon-width + $grid-header-sort-icon-spacing;
            }
            background-position: rtl-background-position($grid-header-sort-icon-position);
        }
    }
}

.#{$prefix}column-header-sort-ASC .#{$prefix}column-header-text-inner {
    @if $enable-font-icons and ($grid-header-sort-asc-glyph != null) {
        @include font-icon(
            $glyph: $grid-header-sort-asc-glyph,
            $pseudo: after,
            $color: $grid-header-sort-glyph-color,
            $style-pseudo: true
        );
    } @else {
        background-image: theme-background-image('grid/sort_asc');
    }
}
.#{$prefix}column-header-sort-DESC .#{$prefix}column-header-text-inner {
    @if $enable-font-icons and ($grid-header-sort-desc-glyph != null) {
        @include font-icon(
            $glyph: $grid-header-sort-desc-glyph,
            $pseudo: after,
            $color: $grid-header-sort-glyph-color,
            $style-pseudo: true
        );
    } @else {
        background-image: theme-background-image('grid/sort_desc');
    }
}

// A Grid with the x-no-header-borders class will show no header borders
.#{$prefix}no-header-borders .#{$prefix}column-header {
    border: 0 none;

    .#{$prefix}column-header-inner {
        padding-top: top($grid-header-padding);
    }
}


@include x-slicer(column-header);
@include x-slicer(column-header-over);
