.bd-table-nowrap {
    & > table {
        & > thead > tr,
        & > tbody > tr {
            td,
            th {
                white-space: nowrap;
            }
        }
    }
}

.bd-table {
    $row-height: 36px;
    border-spacing: 0;
    overflow: auto !important;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    position: relative;

    &.bd-table-full-width table {
        width: 100%;
    }

    &.bd-table-fixed > table {
        table-layout: fixed;
    }

    th,
    td {
        padding: 0 0.5rem;
        height: $row-height;

        &.selection-column {
            padding: 0 !important;
            width: 40px;
            min-width: 40px;
            text-align: center;
        }
    }

    .nothing-found {
        padding: 1rem;
        text-align: center;
        opacity: 0.6;
    }

    &.bd-table-compact {
        $row-height: 30px;

        th,
        td {
            padding: 0 0.35rem;
            height: $row-height;
        }
    }

    //
    //
    thead {
        position: sticky;
        top: 0;
        z-index: 1;
        border-bottom: 1px solid #000;
    }

    tfoot {
        position: sticky;
        bottom: 0;
    }

    thead th {
        margin-bottom: -1px;
        position: relative;

        &:before {
            content: "";
            position: absolute;
            top: 10px;
            bottom: 10px;
            @include positionStart(0);
            @include borderStart(1px solid currentColor);
        }

        &:first-child:before {
            display: none;
        }
    }

    tfoot {
        border-top: 1px solid #000;
    }

    tfoot tr {
        margin-top: -1px;
    }

    tfoot th {
        border-top: 1px solid #000;
    }

    th,
    td {
        border-bottom: 1px solid #000;
    }

    tr:last-child td,
    tfoot tr:last-child th {
        border-bottom-color: transparent !important;
    }

    &.has-whitespace {
        th:last-child,
        td:last-child {
            @include borderEnd(1px solid #000);
        }
    }

    &.cur-default {
        td,
        th {
            cursor: default;
            user-select: none;
        }
    }

    &.cur-pointer {
        td,
        th {
            cursor: pointer;
            user-select: none;
        }
    }
}

.bd-table-bottom {
    display: flex;
    align-items: center;
}

.bd-table-info {
    padding: 0.25rem;
    white-space: nowrap;
}

.bd-table-pagination {
    display: inline-flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
}

/*******************/
@mixin tableTheme($palette) {
    $text: map-get($palette, text, main);
    $bg: map-get($palette, bg, main);

    $primary-palette: map-get($palette, primary);
    $primary: map-get($primary-palette, main);

    $secondary-palette: map-get($palette, secondary);
    $secondary: map-get($secondary-palette, main);

    $focus-border: mix($bg, $primary, 10%); //#86b7fe

    $main-border: mix($text, $bg, 25%);
    $border: mix($text, $bg, 15%);

    $bg-header: mix($text, $bg, 6%);
    $bg-row: mix($text, $bg, 2.5%);
    $bg-selected: mix($primary, $bg, 15%);

    .bd-table {
        .bd-table-footer,
        thead,
        tfoot {
            background-color: $bg-header;
            border-color: $main-border;
        }
    }

    .bd-table {
        border-color: $main-border;

        &.border {
            border-color: $main-border !important;
        }

        th {
            background-color: $bg-header;
            border-color: $main-border;
        }

        th,
        td {
            border-left-color: $main-border;
            border-right-color: $main-border;
        }

        th:before {
            color: $main-border;
        }

        th:last-child,
        td:last-child {
            border-left-color: $main-border;
            border-right-color: $main-border;
        }

        td {
            border-color: $border;
        }

        &.has-whitespace {
            td {
                background-color: $bg;
            }

            tr:last-child td,
            tfoot tr:last-child th {
                border-bottom-color: $main-border !important;
            }
        }

        tbody tr.selected td {
            background-color: $bg-selected !important;
            border-bottom: 1px solid $primary !important;
        }
    }

    .bd-table-striped {
        & > table > tbody tr:nth-child(even) td {
            background-color: rgba($text, 5%);
        }
    }

    .bd-table-hover {
        & > table > tbody tr:hover td {
            background-color: rgba($text, 3%);
        }
        & > table > tbody tr:hover.selected td {
            background-color: mix($text, $bg-selected, 5%) !important;
        }
    }
}

/*******************/
.theme-bd.theme-light {
    $palette: map-get($theme, light);
    @include tableTheme($palette);
}

.theme-bd.theme-dark {
    $palette: map-get($theme, dark);
    @include tableTheme($palette);
}
