@mixin _matcha-table-theme-container-shadow-property($theme) {
    box-shadow:
        0px -16px 0px 0px inset getSurface($theme),
        20px 0 16px -24px inset #000000,
        -20px 0 16px -24px inset #000000,
        0px 2px 2px 0px #00000009,
        0px 2px 2px 0px #00000009,
        0px 2px 2px 0px #00000009;
}

@mixin _matcha-table-theme-shadow-property($theme) {
    background: getSurface($theme);
    background: linear-gradient(
        90deg,
        getSurface($theme) 0px,
        getSurface($theme) 10px,
        rgba(255, 255, 255, 0) calc(0% + 110px),
        rgba(255, 255, 255, 0) calc(100% - 110px),
        getSurface($theme) calc(100% - 10px)
    );
    background: -moz-linear-gradient(
        90deg,
        getSurface($theme) 0px,
        getSurface($theme) 10px,
        rgba(255, 255, 255, 0) calc(0% + 110px),
        rgba(255, 255, 255, 0) calc(100% - 110px),
        getSurface($theme) calc(100% - 10px)
    );
    background: -webkit-linear-gradient(
        0deg,
        getSurface($theme) 0px,
        getSurface($theme) 10px,
        rgba(255, 255, 255, 0) calc(0% + 110px),
        rgba(255, 255, 255, 0) calc(100% - 110px),
        getSurface($theme) calc(100% - 10px)
    );
}

@mixin matcha-table-theme($theme) {
    $is-dark-theme: map-get($theme, is-dark);
    $primary: map-get($theme, primary);
    $accent: map-get($theme, accent);
    $warn: map-get($theme, warn);
    $background: map-get($theme, background);
    $foreground: map-get($theme, foreground);

    // Vai direto na tag body
    body.is-mobile {
        .table-container {
            .table-container-shadow {
                overflow: auto;
                @include _matcha-table-theme-container-shadow-property($theme);

                .mat-table,
                .mat-sort {
                    tbody {
                        @include _matcha-table-theme-shadow-property($theme);
                    }
                }
            }
        }
    }

    .table-container {
        width: 100%;

        .mat-table,
        .mat-sort {
            .published {
                color: map-get($foreground, green);
                // margin-top: 5px;
            }

            .notPublished {
                color: map-get($foreground, amber);
                // margin-top: 5px;
            }
        }

        .table-container-shadow {
            overflow: auto;
            background: map-get($background, card);
            border-radius: 8px;
            box-shadow:
                0px 2px 2px 0px #00000009,
                0px 2px 2px 0px #00000009,
                0px 2px 2px 0px #00000009;
            @include _matcha-table-theme-container-shadow-property($theme);

            .mat-table,
            .mat-sort {
                tbody {
                    @include _matcha-table-theme-shadow-property($theme);
                }
            }

            &.ps--active-x {
                @include _matcha-table-theme-container-shadow-property($theme);

                .mat-table,
                .mat-sort {
                    @include _matcha-table-theme-shadow-property($theme);
                }
            }
        }

        .mat-table,
        .mat-sort,
        .mat-expansion-panel {
            thead {
                background: getSurface($theme);

                th {
                    height: 64px;
                }
            }

            tr {
                &.mat-row {
                    // &:nth-child(even){background: map-get($background, card);}
                    &:nth-child(odd) {
                        background: getBackgroundAlpha($theme);
                    }
                }

                td,
                th {
                    touch-action: unset !important;
                    font-size: 14px;

                    &:first-child {
                        padding-left: 24px;
                    }

                    .clickable {
                        cursor: pointer;
                    }
                }
            }

            .td-duble-line {
                height: 48px;
            }

            .td-with-image,
            .td-with-checkbox,
            .td-with-icon,
            .td-duble-line {
                display: flex;
                align-items: center;

                .td-text-aside {
                    display: inline-block;
                    width: calc(100% - 48px);
                }

                .avatar {
                    width: 48px;
                    min-width: 48px;
                    height: 48px;
                    line-height: 48px;
                    border-width: 0;
                    margin-right: 24px;
                }

                .thumbnail {
                    width: 72px;
                    min-width: 72px;
                    height: 48px;
                    border-radius: 8px;
                    margin: 0 8px 0 0;

                    &-portrait {
                        width: 56px;
                        min-width: 56px;
                        height: 72px;
                        border-radius: 8px;
                        margin: 0 8px 0 0;
                    }
                }
            }

            .mat-header-cell {
                color: getForeground($theme);
                font-family: "CircularStd";
                font-weight: 700;
                font-size: 16px;
                padding-left: 8px;
                padding-right: 8px;
                border-bottom-width: 0px;
            }

            .mat-cell {
                color: getBlueGrey($theme);
                font-size: 14px;
                padding-left: 8px;
                padding-right: 8px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                text-align: start;
                border-bottom-width: 0px;

                &.cdk-column-menu {
                    text-align: left;
                }
            }

            .last {
                display: flex;
                justify-content: space-between;
                width: 100%;
                align-items: center;

                span {
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                mat-menu {
                    display: none;
                }
            }
        }

        table {
            width: 100%;
        }

        .badge {
            border-radius: 8px;
            padding: 8px;
            color: map-get($foreground, foreground-inverse);

            &.live-badge {
                background-color: map-get($background, cyan);
                font-size: 14px;
            }

            &.cell-badge {
                background-color: map-get($background, purple);
                font-size: 14px;
            }

            &.cult-badge {
                background-color: map-get($background, blue);
                font-size: 14px;
            }

            &.new-visitor-badge {
                background-color: map-get($primary, default);
                color: map-get($primary, default-contrast);
                font-size: 14px;
                line-height: 14px;
                display: inline-block;
                width: auto;
            }
        }
    }

    // X-Large devices (big desktops, 1440px and up < 1920)
    @media (min-width: 1440px) {
        .table-container {
            .mat-table,
            .mat-sort {
                .mat-cell {
                    font-size: 16px;
                }
            }
        }
    }

    //---------------------------------------------------------------------------
    // ESTILOS PARA O COMPONENTE MATCHA-TABLE
    //---------------------------------------------------------------------------
    // Estilos para tabelas nativas com a classe matcha-table

    .matcha-table {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 16px;
        border-collapse: collapse;
        border-spacing: 0;
    }

    // Vai direto na tag body
    body.is-mobile {
        .matcha-table {
            .matcha-table-container-shadow {
                overflow: auto;
                @include _matcha-table-theme-container-shadow-property($theme);
                table.matcha-table-content {
                    tbody {
                        @include _matcha-table-theme-shadow-property($theme);
                    }
                }
            }
        }
    }

// Estrutura
// matcha-table
//     matcha-table-container
//         matcha-table-container-shadow
//             table.matcha-table-content
//                 thead
//                 tbody

    --table-row-height: 80px;
    --table-shadow-alpha: rgba(0, 0, 0, 0.05);

    .matcha-table {
        .matcha-table-container-shadow {
            overflow: auto;
            background: getSurface($theme);
            border-radius: 8px;
            box-shadow:
            0px 2px 2px 0px #00000009,
            0px 2px 2px 0px #00000009,
            0px 2px 2px 0px #00000009;
            @include _matcha-table-theme-container-shadow-property($theme);

            table.matcha-table-content {
                width: 100%;
                border-collapse: collapse;
                border-spacing: 0;
                @include _matcha-table-theme-shadow-property($theme);
                thead {
                    th {
                        height: var(--table-row-height);
                        color: getForeground($theme);
                        font-weight: 700;
                        font-size: 16px;
                        text-align: left;
                        padding-left: 24px;
                        padding-right: 16px;
                        border-bottom-width: 0px;
                    }
                }

                tbody {
                    tr {
                        height: var(--table-row-height);
                        // &:nth-child(even){background: map-get($background, card);}
                        // &:nth-child(odd) {
                        //     background: getBackgroundAlpha($theme);
                        // }



                        td{
                            color: getBlueGrey($theme);
                            font-size: 16px;
                            padding-left: 8px;
                            padding-right: 8px;
                            white-space: nowrap;
                            text-overflow: ellipsis;
                            text-align: start;
                            border-bottom-width: 0px;
                            touch-action: unset !important;
                            min-width:120px;

                            &:first-child {
                                padding-left: 24px;
                            }

                        }
                    }

                    // esse é um caso especifico para as tabelas que tem aninhamento de itens
                    tr {
                        &.equal {

                            td,
                            th {
                                &:first-child {
                                    box-shadow: 4px 0 0 0 inset getBlue($theme), 10px 0 10px -10px getDisabled($theme);
                                }
                            }

                            &.child-item {

                                td,
                                th {
                                    &:first-child {
                                        box-shadow: 4px 0 0 0 inset getBlueAlpha($theme), 10px 0 10px -10px getDisabled($theme);
                                    }
                                }
                            }
                        }

                        &.plus {

                            td,
                            th {
                                &:first-child {
                                    box-shadow: 4px 0 0 0 inset getGreen($theme), 10px 0 10px -10px getDisabled($theme);
                                }
                            }

                            &.child-item {
                                td,
                                th {
                                    &:first-child {
                                        box-shadow: 4px 0 0 0 inset getGreenAlpha($theme), 10px 0 10px -10px getDisabled($theme);
                                    }
                                }
                            }
                        }

                        &.minus {

                            td,
                            th {
                                &:first-child {
                                    box-shadow: 4px 0 0 0 inset getRed($theme), 10px 0 10px -10px getDisabled($theme);
                                }
                            }

                            &.child-item {

                                td,
                                th {
                                    &:first-child {
                                        box-shadow: 4px 0 0 0 inset getRedAlpha($theme), 10px 0 10px -10px getDisabled($theme);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // X-Large devices (big desktops, 1440px and up < 1920)
    @media (min-width: 1440px) {
        .matcha-table {
            .matcha-table-container-shadow {
                table.matcha-table-content {
                    .td {
                        font-size: 16px;
                    }
                }
            }
        }
    }

    // Variações de tamanho/densidade
    .matcha-table-compact {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                --table-row-height: 48px;

                thead th {
                    height: var(--table-row-height);
                    padding-top: 8px;
                    padding-bottom: 8px;
                    font-size: 14px;
                }

                tbody tr {
                    height: var(--table-row-height);

                    td {
                        padding-top: 8px;
                        padding-bottom: 8px;
                        font-size: 14px;
                    }
                }
            }
        }
    }

    .matcha-table-comfortable {
        // Estilo padrão de densidade (já aplicado na estrutura base)
        .matcha-table-container-shadow {
            table.matcha-table-content {
                --table-row-height: 64px;

                thead th {
                    height: var(--table-row-height);
                    padding-top: 12px;
                    padding-bottom: 12px;
                }

                tbody tr {
                    height: var(--table-row-height);

                    td {
                        padding-top: 12px;
                        padding-bottom: 12px;
                    }
                }
            }
        }
    }

    .matcha-table-spacious {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                --table-row-height: 80px;

                thead th {
                    height: var(--table-row-height);
                    padding-top: 16px;
                    padding-bottom: 16px;
                    font-size: 18px;
                }

                tbody tr {
                    height: var(--table-row-height);

                    td {
                        padding-top: 16px;
                        padding-bottom: 16px;
                        font-size: 18px;
                    }
                }
            }
        }
    }

    // Linhas zebras
    .matcha-table-striped {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                tbody tr {
                    &:nth-child(odd) {
                        background: var(--table-shadow-alpha);
                    }

                    &:nth-child(even) {
                        background: transparent;
                    }
                }
            }
        }
    }

    // Hover nas linhas
    .matcha-table-hover {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                tbody tr {
                    transition: background-color 0.2s ease;

                    &:hover {
                        background: getPrimaryAlpha($theme) !important;
                    }
                }
            }
        }
    }

    // Bordas visíveis
    .matcha-table-bordered {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                border: 1px solid getDisabled($theme);

                thead th {
                    border-bottom: 1px solid getDisabled($theme);
                    border-right: 1px solid getDisabled($theme);

                    &:last-child {
                        border-right: none;
                    }
                }

                tbody tr {
                    td {
                        border-bottom: 1px solid getDisabled($theme);
                        border-right: 1px solid getDisabled($theme);

                        &:last-child {
                            border-right: none;
                        }
                    }

                    &:last-child td {
                        border-bottom: none;
                    }
                }
            }
        }
    }

    // Cabeçalho fixo (sticky)
    .matcha-table-sticky-header {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                thead {
                    position: sticky;
                    top: 0;
                    z-index: 10;
                    display: table-header-group;
                }

                thead th {
                    position: sticky;
                    top: 0;
                    z-index: 11;
                    box-shadow: 0 2px 4px var(--table-shadow-alpha);
                }
            }
        }
    }

    // Colunas fixas (sticky columns) - primeira coluna fixa por padrão quando há scroll
    .matcha-table-sticky-start {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                thead th:first-child,
                tbody tr td:first-child {
                    position: sticky;
                    left: 0;
                    z-index: 5;
                    background: getSurface($theme);
                }

                thead th:first-child {
                    z-index: 15;
                    box-shadow: 10px 0 10px -10px getDisabled($theme);

                }

                tbody tr td:first-child {
                    box-shadow: 10px 0 10px -10px getDisabled($theme);

                }
            }
        }

        // Para múltiplas colunas fixas no início
        &.matcha-table-sticky-start-2 {
            .matcha-table-container-shadow {
                table.matcha-table-content {
                    thead th:nth-child(1),
                    thead th:nth-child(2),
                    tbody tr td:nth-child(1),
                    tbody tr td:nth-child(2) {
                        position: sticky;
                        z-index: 5;
                        background: getSurface($theme);
                    }

                    thead th:nth-child(1),
                    tbody tr td:nth-child(1) {
                        left: 0;
                        z-index: 15;
                        box-shadow: 2px 0 4px var(--table-shadow-alpha);
                    }

                    thead th:nth-child(2),
                    tbody tr td:nth-child(2) {
                        left: 200px; // Ajustar conforme largura da primeira coluna
                        z-index: 14;
                        box-shadow: 2px 0 4px var(--table-shadow-alpha);
                    }
                }
            }
        }

        &.matcha-table-sticky-start-3 {
            .matcha-table-container-shadow {
                table.matcha-table-content {
                    thead th:nth-child(1),
                    thead th:nth-child(2),
                    thead th:nth-child(3),
                    tbody tr td:nth-child(1),
                    tbody tr td:nth-child(2),
                    tbody tr td:nth-child(3) {
                        position: sticky;
                        z-index: 5;
                        background: getSurface($theme);
                    }

                    thead th:nth-child(1),
                    tbody tr td:nth-child(1) {
                        left: 0;
                        z-index: 17;
                        box-shadow: 2px 0 4px var(--table-shadow-alpha);
                    }

                    thead th:nth-child(2),
                    tbody tr td:nth-child(2) {
                        left: 200px;
                        z-index: 16;
                        box-shadow: 2px 0 4px var(--table-shadow-alpha);
                    }

                    thead th:nth-child(3),
                    tbody tr td:nth-child(3) {
                        left: 400px;
                        z-index: 15;
                        box-shadow: 2px 0 4px var(--table-shadow-alpha);
                    }
                }
            }
        }
    }

    .matcha-table-sticky-end {
        .matcha-table-container-shadow {
            table.matcha-table-content {
                thead th:last-child,
                tbody tr td:last-child {
                    position: sticky;
                    right: 0;
                    z-index: 5;
                    background: getSurface($theme);
                }

                thead th:last-child {
                    z-index: 15;
                    box-shadow: -2px 0 4px var(--table-shadow-alpha);
                }

                tbody tr td:last-child {
                    box-shadow: -2px 0 2px var(--table-shadow-alpha);
                }
            }
        }

        // Para múltiplas colunas fixas no final
        &.matcha-table-sticky-end-2 {
            .matcha-table-container-shadow {
                table.matcha-table-content {
                    thead th:nth-last-child(1),
                    thead th:nth-last-child(2),
                    tbody tr td:nth-last-child(1),
                    tbody tr td:nth-last-child(2) {
                        position: sticky;
                        z-index: 5;
                        background: getSurface($theme);
                    }

                    thead th:nth-last-child(1),
                    tbody tr td:nth-last-child(1) {
                        right: 0;
                        z-index: 15;
                        box-shadow: -2px 0 4px var(--table-shadow-alpha);
                    }

                    thead th:nth-last-child(2),
                    tbody tr td:nth-last-child(2) {
                        right: 200px; // Ajustar conforme largura da última coluna
                        z-index: 14;
                        box-shadow: -2px 0 4px var(--table-shadow-alpha);
                    }
                }
            }
        }
    }
}
