.required {
    padding: 0 0.25rem;
}

.pepperi-report-fields {
    height: inherit;

    span {
        display: block;
        @include ellipsis();
    }
}

// -----------------------------------------------------
//  Override material style
// -----------------------------------------------------
.mat-form-title {
    margin: 0;
    padding: $spacing-2xs 0;
    height: $form-field-title-height;
    line-height: 1rem;
    display: block;

    span {
        line-height: 0.875rem;
        vertical-align: top;

        .svg-icon {
            height: 0.6875rem;
            width: 0.6875rem;
        }
    }

    mat-label {
        @include ellipsis();
        display: inline-block; // WAS UNSET , CAUSE TO LABEL TO BE LONGER THEN THE CONTAINER - AVNER ,
        // Than was blocked - cause the label to catch 100% of the row -> prob whith limited line
        vertical-align: top;
    }

    .mat-button {
        min-width: unset;
        line-height: 1rem;
        padding: unset;
        width: 1rem;
        height: 1rem;

        .mat-icon {
            width: inherit;
            height: inherit;
            font-size: unset;
        }
    }
}

.mat-form-field {
    @include fix-inline-z-index();
    // display: unset;
    width: 100%;
    
    .mat-form-field-wrapper {
        width: inherit;
        margin: 0;
        padding-bottom: 0;

        .mat-form-field-flex {
            padding-left: $spacing-md;
            padding-right: $spacing-md;
            margin: 0;
            min-height: $form-field-height; // 2.5rem;
            align-items: center;

            .mat-form-field-outline {
                top: 0; // Override material default.
            }

            .mat-form-field-prefix,
            .mat-form-field-suffix {
                top: 0; // Override material default.
                display: flex;
                align-self: center;

                .mat-button {
                    min-width: unset;
                    line-height: unset;
                    padding: unset;

                    height: $form-field-button-size; // 1.5rem;
                    width: $form-field-button-size; // 1.5rem;
                
                    .mat-icon {
                        // height: calc(#{$form-field-button-size} - 2px); // - 2px is the border size
                        // width: calc(#{$form-field-button-size} - 2px); // - 2px is the border size
                        height: calc(#{$form-field-button-size});
                        width: calc(#{$form-field-button-size} );

                        .svg-icon {
                            height: $form-field-button-icon-size; // 1rem;
                            width: $form-field-button-icon-size; // 1rem;
                        }
                    }
                }

                .mat-icon {
                    font-size: unset; // override material default (150%).
                    // height: calc(#{$form-field-button-size} - 2px); // - 2px is the border size
                    // width: calc(#{$form-field-button-size} - 2px); // - 2px is the border size
                    height: calc(#{$form-field-button-size});
                    width: calc(#{$form-field-button-size}); 

                    .svg-icon {
                        height: $form-field-button-size; // 1.5rem;
                        width: $form-field-button-size; // 1.5rem;
                    }
                }
            }

            .mat-form-field-infix {
                border-top: 0;
                padding: 0;
                line-height: 2.5rem;
                width: 100%;
                display: flex;

                .mat-input-element {
                    // vertical-align: unset;
                    margin-top: unset;
                }

                .mat-form-field-label-wrapper {
                    display: none;
                }
            }
        }
        
        .mat-form-field-subscript-wrapper {
            position: relative;
            margin-top: 0;
            padding: 0;
            font-weight: $font-weight-bold;
            z-index: $z-index-medium;
            border-radius: $border-radius-md;
            
            .mat-error {
                padding: $spacing-xs $spacing-sm;
            }
        }
    }

    .mat-form-field-flex {
        border-radius: $border-radius-md;
    }
    
}

.mat-grid-tile {
    overflow: inherit !important;
}

/* make content to be on top (to be on the first row - if the field is declared on more than one row but it's UI is only on one row) */
.mat-grid-tile .mat-figure {
    justify-content: flex-start !important ;
    align-items: flex-start !important;
}

//  Form view
// ------------------------
.form-view {
    margin-top: $content-margin;
    margin-bottom: $content-margin;
}

//  Table view
// ------------------------
.table-total,
.table-header {
    position: -webkit-sticky;
    position: sticky;
    z-index: $z-index-medium;
    @include box-sizing(border-box);
    width: inherit;
    height: calc(#{$table-field-height} + #{$table-spacing} + #{$table-half-spacing});
    padding-top: $table-spacing;
    
    .row-selection {
        margin: 0 calc(#{$spacing-sm} + calc(#{$spacing-xs} / 2)); // 0 0.625rem;
        height: inherit;
        display: flex;
        align-items: center;
    }

    .table-header-fieldset {
        border-radius: $table-border-radius;
        height: $table-field-height; // 2rem;
        margin-bottom: $table-half-spacing; // 0.25rem;

        fieldset {
            height: inherit;
        }

        .header-column {
            padding: 0 $spacing-sm;
            box-sizing: border-box;
            //cursor: pointer;
            height: inherit;
            display: flex;
            align-items: center;

            .header-label {
                width: 100%;
                @include box-sizing(border-box);
                user-select: none;
                @include calc(max-width, '100% - 0');
                @include ellipsis();
                font-weight: 600 !important;
                line-height: 2rem !important;
                margin-bottom: 0;
                // cursor: text;
            }

            img {
                height: 1.5rem;
                width: 1.5rem;
                margin: -5px auto 0 auto;
                display: block;
            }

            &.support-sorting {
                .sortingBox {
                    display: none;
                    width: 1rem;
                    height: 1rem;
                    margin: 0.5rem 0;

                    .mat-icon {
                        background-repeat: no-repeat;
                        display: flex;
                        height: inherit;
                        width: inherit;

                        .svg-icon {
                            &.asc {
                                @include rotate(180deg);
                            }
                        }
                        
                        &:hover {
                            cursor: pointer;
                        }

                        &.sort-by {
                            display: none !important;
                        }
                    }

                    &.has-sorting {
                        display: block;
                    }
                }
            }

            .resizeBox {
                // display: none;
                cursor: w-resize;
                margin-right: -1.5rem; // header column padding.
                height: $table-field-height; // 2rem;

                .mat-icon {
                    width: 0.125rem;
                    height: 1.5rem;
                    line-height: $table-field-height; // 2rem;
                    padding: 0 0.125rem 0 0.375rem;
                    //margin: 0.15rem 0 0 0;
                }
            }

            &:hover {
                &.support-sorting {
                    cursor: pointer;
                    .header-label {
                        cursor: pointer;
                        padding-right: 1rem;
                        // @include calc(max-width, '100% - 2rem');
                    }

                    .sortingBox {
                        display: block;
                    }
                }
            }

            &.has-sorting {
                &.support-sorting {
                    .header-label {
                        padding-right: 1rem;
                        // @include calc(max-width, '100% - 2rem');
                    }
                }
            }

            &.is-resizing {
                .sortingBox {
                    display: block;
                }
            }

            &.is-first {
                border-radius: $table-border-radius 0 0 $table-border-radius;
            }

            &.is-last {
                border-radius: 0 $table-border-radius $table-border-radius 0;
                
                &:hover {
                    .resizeBox {
                        // width: 1rem;
                        border-radius: 0 $table-border-radius $table-border-radius 0;
                    }
                }
            }
        }
    }

    // .table-header-fieldset {
    //     height: 2rem;
    //     margin-top: 0.25rem;
    //     margin-bottom: 0.25rem;
    // }

    &:hover {
        .resizeBox {
            display: block !important;
        }
    }
}
[dir='rtl'] {
    .table-header {
        .table-header-fieldset {
            .header-column {
                .resizeBox {
                    margin-left: calc(#{$spacing-sm} * -1); // header column padding.

                    .mat-icon {
                        padding: 0 $spacing-sm 0 0;
                    }
                }

                &.is-first {
                    border-radius: 0 $table-border-radius $table-border-radius 0;
                }

                &.is-last {
                    border-radius: $table-border-radius 0 0 $table-border-radius;

                    &:hover {
                        .resizeBox {
                            border-radius: $table-border-radius 0 0 $table-border-radius;
                        }
                    }
                }
            }
        }
    }
}

.table-body {
    width: inherit;
    position: relative;

    .table-row {
        @include box-sizing(border-box);
        width: inherit;
        height: $table-row-height; // 3rem;
        padding: $table-half-spacing 0; // 0.25rem 0;
        border-radius: $table-border-radius;

        .row-selection {
            margin: 0 calc(#{$spacing-sm} + #{$spacing-2xs});
            height: $table-row-fieldset-height; // 2.5rem;
            display: flex;
            align-items: center;

            &.mat-radio-button {
                display: inline-flex;
            }
        }

        fieldset {
            height: $table-row-fieldset-height; // 2.5rem;
            border-radius: $table-border-radius;
            // padding: 0 $spacing-2xs;
            .table-cell {  
                box-sizing: border-box;  
                padding: 0 $spacing-2xs;

                &:first-of-type {
                    padding: 0 $spacing-2xs 0 $spacing-xs;
                }

                &:last-of-type {
                    padding: 0 $spacing-xs 0 $spacing-2xs;
                }
            }
            
            .pepperi-input {
                padding: 0 $spacing-md;
                height: $table-field-height; // 2rem;
            }

            // -----------------------------------------------------
            //  Override material style
            // -----------------------------------------------------
            .mat-form-field .mat-form-field-wrapper {
                .mat-form-field-flex {
                    min-height: $table-field-height; // 2rem;
                    height: $table-field-height; // 2rem;
                    padding: 0 $spacing-xs;
                }

                .mat-select-arrow {
                    margin-right: $spacing-xs;
                    margin-left: $spacing-xs;
                }
            }
        }
    }
}

[dir='rtl'] {
    .table-body {
        .table-row {
            fieldset {
                .table-cell {    
                    &:first-of-type {
                        padding: 0 $spacing-xs 0 $spacing-2xs;
                    }

                    &:last-of-type {
                        padding: 0 $spacing-2xs 0 $spacing-xs;
                    }
                }
            }
        }
    }
}

.table-total {
    // width: inherit;
    // height: $table-field-height; // 2rem;
    // margin-bottom: $spacing-xs;
    // z-index: $z-index-medium;
    // @include box-sizing(border-box);
    // border-radius: $table-border-radius;
    // padding: 0;

    padding-top: $table-half-spacing;

    .total-column {
        padding: 0 $spacing-sm;
        height: inherit;
        display: flex;
        align-items: center;

        .total-label {
            width: 100%;
            @include box-sizing(border-box);
            user-select: none;
            // @include calc(max-width, '100% - 0');
            max-width: 100%;
            @include ellipsis();
            font-weight: $font-weight-bold !important;
            line-height: $table-field-height; // 2rem !important;
            margin-bottom: 0;
        }
    }
}

//  Card view & Line view
// ------------------------
.cards-body {
    margin: 0 (calc(#{$content-margin} * -1) / 2); // -0.5rem;
    position: relative;
}

.line-view,
.card-view,
.cardView {
    margin: 0;
    padding: 0 !important;

    .card-selection {
        margin: $spacing-xs calc(#{$spacing-xs} * -1) 0 $spacing-xs;
        height: 1rem;
        width: 1rem;
        position: relative;
        z-index: $z-index-lowest;
    }

    fieldset {
        border-radius: $card-border-radius;
        margin: $spacing-md; // spacing between cards.
        position: relative;

        .card-spacing {
            margin: $spacing-lg !important; // spacing inside card.
        }

        // Showing two labels in the same row with ellipsis.                    
        .card-flex-container {
            display: flex;

            &.pepperi-button {
                background: unset; // Cancel the default background and shows background only on the declared states (hover, etc).
            }

            .title {
                // flex-grow: 0;
                flex-shrink: 5000;
                @include ellipsis();
                padding: $spacing-2xs;
                height: inherit;

                &.no-shrink {
                    flex-shrink: 1;
                    // white-space:normal;
                    // overflow: unset;
                }
            }

            .value {
                // flex-grow: 0;
                flex-shrink: 1;
                margin: 0 $spacing-xs;
                @include ellipsis();
                height: inherit;

                &.wrap {
                    white-space:normal;
                }
            }

            .card-edit-button {
                flex-basis: $card-field-button-size;
                flex-shrink: 0;
                
                &.self-end {
                    align-self: flex-end;
                }

                width: $card-field-button-size;
                height: $card-field-button-size;
                line-height: $card-field-button-size;
                min-width: unset;
                padding: 0;
                pointer-events: none;
                
                .mat-icon {
                    // line-height: 0.5rem !important;

                    .svg-icon {
                        width: $card-field-button-icon-size; // $card-field-button-size - 0.25rem !important;
                        // height: $card-field-button-size - 0.25rem !important;
                    }
                }
            }
        }

        // -----------------------------------------------------
        //  Override material style
        // -----------------------------------------------------
        .one-row {
            &.card-flex-container {
                align-items: center;
            }

            .pepperi-button:not(.card-edit-button) {
                // height: $card-field-height !important; // 1.5rem !important;
                // line-height: 1.5rem !important;
                padding: 0 $spacing-xs;
            }

            .mat-form-field .mat-form-field-wrapper {
                .mat-form-field-flex {
                    height: $card-field-height !important; // 1.5rem !important;
                    min-height: $card-field-height; // 1.5rem;
                    padding: 0 $spacing-xs;
                }

                .pepperi-button,
                .mat-select-trigger,
                .mat-form-field-infix {
                    height: $card-field-height !important; // 1.5rem !important;
                    // line-height: $card-field-height !important;
                }

                .mat-input-element {
                    font-size: $fs-sm !important;
                    // line-height: inherit !important;
                }
            }
        }
    }

    // For the campaign style.
    &.flat {
        fieldset {
            box-shadow: unset !important;
            margin: 0.25rem;

            mat-grid-list {
                margin: 0 !important;
            }
        }
    }
}

//  Card views type sizes
.line-view {
    width:100%;
}
.card-view {
    /* > XLarge */
    @media (min-width: $screen-max-size-xl) {
        @include calc(min-width, '100% / 6');
        
        &.small-card {
            @include calc(min-width, '100% / 8');
        }
    }
    /* Large - XLarge */
    @media (max-width: $screen-max-size-xl) and (min-width: $screen-max-size-lg) {
        @include calc(min-width, '100% / 4');

        &.small-card {
            @include calc(min-width, '100% / 6');
        }
    }
    /* Medium - Large */
    @media (max-width: $screen-max-size-lg) and (min-width: $screen-max-size-md) {
        @include calc(min-width, '100% / 3');

        &.small-card {
            @include calc(min-width, '100% / 4');
        }
    }
    /* Small - Medium */
    @media (max-width: $screen-max-size-md) and (min-width: $screen-max-size-sm) {
        @include calc(min-width, '100% / 3');

        &.small-card {
            @include calc(min-width, '100% / 4');
        }
    }
    /* Extra small - Small */
    @media (max-width: $screen-max-size-sm) and (min-width: $screen-max-size-xs) {
        @include calc(min-width, '100% / 2');

        &.small-card {
            @include calc(min-width, '100% / 3');
        }
    }
    /* < Extra small */
    @media (max-width: $screen-max-size-xs) {
        @include calc(min-width, '100% / 1');

        &.small-card {
            @include calc(min-width, '100% / 2');
        }
    }
}

[dir='rtl'] {
    .line-view,
    .card-view,
    .cardView {
        .card-selection {
            margin: 0.25rem 0.25rem 0 -2rem;
        }
    }
}

//  Custom field (added for stand alone field).
// ---------------------------------------------
.pepperi-field {
    min-height: $form-row-height;
    margin-bottom: $form-spacing;
}

@mixin pepperi-general-theme($pepperi-theme) {

    .required {
        color: get-pepperi-color($pepperi-theme, color-system-caution, color-base);

        .svg-icon {
            fill: get-pepperi-color($pepperi-theme, color-system-caution, color-base);
        }
    }

    .svg-icon {
        @include state-icon($pepperi-theme);
    }

    .pepperi-report-fields {
        .pepperi-input {
            background: transparent !important;
        }
    }

    // -----------------------------------------------------
    //  Override material style
    // -----------------------------------------------------
    .mat-form-title {
        &.disable {
            color: get-pepperi-color($pepperi-theme, color-text, color-dimmed);
        }
    }

    .mat-form-field-appearance-outline .mat-form-field-outline-end,
    .mat-form-field-appearance-outline .mat-form-field-outline-start {
        border-color: transparent; //red !important;
    }

    .mat-form-field-appearance-outline .mat-form-field-wrapper {
        margin-top: unset;
        margin-bottom: unset;
    }

    .mat-form-field {
        .mat-form-field-wrapper {
            .mat-form-field-prefix,
            .mat-form-field-suffix {
                color: get-pepperi-color($pepperi-theme, color-weak, color-flat-r-20);

                // For non icons symbols.
                .text-icon {
                    color: get-pepperi-color($pepperi-theme, color-weak, color-flat-r-20);
                }
            }

            .mat-form-field-infix {
                .mat-input-element {
                    &:disabled {
                        color: get-pepperi-color($pepperi-theme, color-text, color-dimmed);
                    }
                }
            }
        }

        .mat-form-field-flex {
            border-radius: $border-radius-md;
            @include state-weak-default($pepperi-theme);
        }

        &:hover .mat-form-field-flex {
            // cursor: pointer;
            @include state-weak-hover($pepperi-theme);
        }

        // Focused
        &.mat-focused .mat-form-field-flex {
            @include state-weak-focus($pepperi-theme);
        }

        // Active
        &:active .mat-form-field-flex {
            @include state-weak-active($pepperi-theme);
        }

        // Disabled
        &.mat-form-field-disabled .mat-form-field-flex {
            @include state-weak-disable($pepperi-theme);
        }

        // Invalid (Error)
        &.mat-form-field-invalid {
            .mat-form-field-wrapper {
                @include state-error-wrapper($pepperi-theme);

                .mat-form-field-flex {
                    @include state-error($pepperi-theme);
                }

                .mat-form-field-subscript-wrapper {
                    background: get-pepperi-color($pepperi-theme, color-system-caution, color-base);
                    
                    .mat-error {
                        color: get-pepperi-color($pepperi-theme, color-text, color-invert);
                    }
                }
            }

            // Focused & Error
            &.mat-focused .mat-form-field-wrapper {
                @include focus($pepperi-theme);
                z-index: $z-index-medium + 1; // To show error on table above the next row element.

                .mat-form-field-flex {
                    box-shadow: unset !important;
                }
            }
        }

        // &.regular {
        //     .mat-form-field-flex {
        //         @include state-regular-default($pepperi-theme, true);
        //     }

        //     // Focused
        //     &.mat-focused .mat-form-field-flex {
        //         @include state-regular-focus($pepperi-theme, true);
        //     }

        //     // Active
        //     &:active .mat-form-field-flex {
        //         //@include state-regular-active($pepperi-theme);
        //     }

        //     // Disabled
        //     &.mat-form-field-disabled .mat-form-field-flex {
        //         @include state-regular-disable($pepperi-theme, true);
        //     }

        //     // Hover
        //     :hover {
        //         .mat-form-field-flex {
        //             @include state-regular-hover($pepperi-theme);
        //         }
        //     }
        // }
    }
    
    //  Table view
    // ------------------------
    .table-total,
    .table-header {
        @include state-list-body-default($pepperi-theme);

        .table-header-fieldset {
            background-color: get-pepperi-color($pepperi-theme, color-weak, color-flat-r-30);
            color: get-pepperi-color($pepperi-theme, color-text, color-dimmed);

            .header-column {
                .sortingBox {
                    .mat-icon {
                        .svg-icon {
                            fill: get-pepperi-color($pepperi-theme, color-text, color-dimmed);
                        }
                    }
                }

                .resizeBox {
                    .mat-icon {
                        .svg-icon {
                            fill: get-pepperi-color($pepperi-theme, color-weak, color-tran-50);
                        }
                    }
                }

                &:hover {
                    color: get-pepperi-color($pepperi-theme, color-weak, color-tran-80);
                    background-color: get-pepperi-color($pepperi-theme, color-weak, color-tran-20);

                    .resizeBox {
                        background: get-pepperi-color($pepperi-theme, color-text, color-link-highlight);

                        .mat-icon {
                            .svg-icon {
                                fill: get-pepperi-color($pepperi-theme, color-weak, color-tran-80);
                            }
                        }

                        &:hover {
                            background: get-pepperi-color($pepperi-theme, color-text, color-link-focus);

                            .mat-icon {
                                .svg-icon {
                                    fill: get-pepperi-color($pepperi-theme, color-weak, color-base);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    .table-body {
        @include state-list-body-default($pepperi-theme);

        .table-row {
            .table-row-fieldset {
                @include state-table-row-default($pepperi-theme);
            }

            &:hover,
            &.highlighted {
                .table-row-fieldset {
                    @include state-table-row-hover($pepperi-theme);
                }
            }
    
            &:active {
                .table-row-fieldset {
                    @include state-table-row-active($pepperi-theme);
                }
            }

            &.selected {
                .table-row-fieldset {
                    @include state-table-row-selected($pepperi-theme);
                }
            }
        }
    }

    //  Card view & Line view
    // ------------------------
    .line-view,
    .card-view,
    .cardView {
        @include state-list-body-default($pepperi-theme);

        fieldset {
            @include state-card-default($pepperi-theme);

            &:hover {
                @include state-card-hover($pepperi-theme);
            }

            &:active {
                @include state-card-active($pepperi-theme);
            }

            .title {
                color: get-pepperi-color($pepperi-theme, color-text, color-dimmed);
            }
        }

        &.selected {
            fieldset {
                @include state-card-selected($pepperi-theme);
            }
        }

        // If we wand the blue focus to be only on specific .selectable class instead of &:active state.
        // &.selectable {
        //     fieldset {
        //         &:active {
        //             @include state-card-active($pepperi-theme);
        //         }
        //     }
        // }
    }

}