﻿div.acc-table-container {
    border-radius: 0.5rem;

    > table {
        width: 100%;
        border-collapse: collapse;
        border: none;
        margin-bottom: 1rem;

        :where(td, th) {
            padding: 0.5rem;
            border: 1px solid var(--acc-table-border-color);
        }

        > thead > tr {
            background-color: var(--acc-table-even-row-background-color);
            color: var(--acc-table-text-color);
            font-weight: bold;

            > th {
                font-weight: bold;
                text-align: start;
            }
        }

        > tbody {
            > tr {
                > td {
                    color: var(--acc-table-text-color);
                    font-weight: normal;

                    &:last-of-type {
                        display: flex;
                        gap: 0.5rem;
                        flex-wrap: wrap;
                        border-bottom: none;

                        > a {
                            font-size: small;
                            border-radius: 0.25rem;
                            border-width: 1px;
                            border-style: solid;
                            padding: 0.2rem 0.6rem;
                            display: inline-flex;
                            align-items: center;
                            justify-content: center;
                            text-align: center;
                            user-select: none;
                            cursor: pointer;
                            position: relative;

                            > i {
                                display: flex;
                                padding: 0.25rem 0;
                            }

                            &::after {
                                content: attr(data-title);
                                position: absolute;
                                top: -32px;
                                padding: 0.2rem 0.4rem;
                                color: var(--tw-gray-100);
                                font-size: smaller;
                                border-radius: 0.75rem;
                                z-index: 2;
                                white-space: nowrap;
                                scale: 0;
                                transition: scale 0.2s ease;
                            }

                            &:hover {
                                &::after {
                                    scale: 1;
                                }

                                &::before {
                                    scale: 1.75 1;
                                }
                            }

                            &::before {
                                content: "▲";
                                rotate: 180deg;
                                display: flex;
                                position: absolute;
                                top: -20px;
                                scale: 0;
                                transition: scale 0.2s ease;
                            }

                            &.details {
                                border-color: var(--tw-yellow-600);
                                color: var(--tw-yellow-600);

                                &:not(.custom) > i::before {
                                    font-family: 'bootstrap-icons';
                                    content: "\f479";
                                }

                                &:hover {
                                    background-color: color-mix(40% var(--tw-yellow-500), 60% transparent);

                                    &::after {
                                        background-color: var(--tw-yellow-600);
                                    }
                                }

                                &:focus {
                                    box-shadow: 0 0 0 3px var(--tw-yellow-300);
                                }
                            }

                            &.update {
                                border-color: var(--tw-blue-600);
                                color: var(--tw-blue-600);

                                &:not(.custom) > i::before {
                                    content: "\f4cb";
                                }

                                &:hover {
                                    background-color: color-mix(40% var(--tw-blue-500), 60% transparent);

                                    &::after {
                                        background-color: var(--tw-blue-600);
                                    }
                                }

                                &:focus {
                                    box-shadow: 0 0 0 3px var(--tw-blue-300);
                                }
                            }

                            &.delete {
                                border-color: var(--tw-red-600);
                                color: var(--tw-red-600);

                                form {
                                    display: none;
                                }

                                &:not(.custom) > i::before {
                                    content: "\f5de";
                                }

                                &[data-status=locked] > i::before {
                                    content: "\f47b";
                                }

                                &[data-status=pending] > i::before {
                                    content: "\f130";
                                    animation: spinner-border 3s linear infinite;
                                }

                                &:hover {
                                    background-color: color-mix(40% var(--tw-red-500), 60% transparent);

                                    &::after {
                                        background-color: var(--tw-red-600);
                                    }
                                }

                                &:focus {
                                    box-shadow: 0 0 0 3px var(--tw-red-300);
                                }
                            }

                            &.master {
                                border-color: var(--tw-gray-600);
                                color: var(--tw-gray-600);

                                &:not(.custom) > i::before {
                                    content: "\f4da";
                                }

                                &:hover {
                                    background-color: color-mix(40% var(--tw-gray-600), 60% transparent);

                                    &::after {
                                        background-color: var(--tw-gray-600);
                                    }
                                }

                                &:focus {
                                    box-shadow: 0 0 0 3px var(--tw-gray-300);
                                }
                            }

                            &.apply {
                                border-color: var(--tw-purple-600);
                                color: var(--tw-purple-600);

                                &:not(.custom) > i::before {
                                    content: "\f675";
                                }

                                &:hover {
                                    background-color: color-mix(40% var(--tw-purple-600), 60% transparent);

                                    &::after {
                                        background-color: var(--tw-purple-600);
                                    }
                                }

                                &:focus {
                                    box-shadow: 0 0 0 3px var(--tw-purple-300);
                                }
                            }
                        }
                    }
                }

                &[ondblclick] {
                    cursor: pointer;
                }

                &.primary > td {
                    color: var(--acc-primary-color);
                }

                &.success > td {
                    color: var(--acc-success-color);
                }

                &.warning > td {
                    color: var(--acc-warning-color);
                }

                &.ptn-special > td {
                    color: var(--acc-primary-color);
                }

                &.danger > td {
                    color: var(--acc-danger-color);
                }

                &:nth-child(odd) {
                    background-color: var(--acc-table-odd-row-background-color);
                }

                &:nth-child(even) {
                    background-color: var(--acc-table-even-row-background-color);
                }

                &:hover {
                    background-color: var(--acc-table-hover-row-background-color);
                }
            }
        }

        > tfoot > tr > td {
            width: 100%;

            > div {
                display: flex;
                justify-content: space-between;

                > a {
                    display: flex;
                    cursor: pointer;
                    gap: 0.5rem;
                    align-items: center;
                    justify-content: center;

                    > i {
                        display: inline-flex;
                    }
                }

                > ul {
                    display: flex;
                    list-style-type: none;
                    gap: 1rem;
                    margin: 0;

                    > li {
                        border: 1px solid var(--tw-gray-200);
                        cursor: pointer;
                        aspect-ratio: 1 !important;
                        width: 24px;
                        max-height: 24px;
                        display: inline-flex;
                        align-items: center;
                        justify-content: center;
                        border-radius: 50%;
                        padding: 0.25rem;

                        > a {
                            font-family: fadigits !important;
                        }

                        &.active {
                            background-color: var(--tw-blue-300);
                        }
                    }
                }
            }
        }

        > tfoot > * {
            user-select: none;
            color: var(--tw-gray-600);
        }

        &.acc-table img {
            aspect-ratio: 1;
            min-width: 2rem;
            width: 2rem;
            max-width: 2rem;
            min-height: 2rem;
            height: 2rem;
            max-height: 2rem;
            object-fit: cover;
            border-radius: 0.25rem;
        }

        &.form {
            & * {
                width: 100%;
            }
            tbody {
                vertical-align: top;
            }

            fieldset {
                & > label {
                    display: none;
                }
                textarea {
                    overflow:hidden;
                }
            }
        }
    }
}

@media screen and (max-width: 640px) {
    table.acc-table {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        border: none;

        > thead {
            display: none;
        }

        :where(td, th) {
            border: none;
        }

        > tbody {
            display: flex;
            flex-direction: column;
            gap: 1rem;

            > tr {
                display: flex;
                flex-direction: column;
                border: 1px solid var(--acc-table-border-color);
                border-radius: 0.25rem;
                padding: 1rem;

                > td {
                    display: flex;
                    border: none !important;
                    border-bottom: 1px solid var(--acc-table-border-color) !important;
                    align-items: center;
                    width: 100%;

                    &:last-of-type {
                        border: none !important;
                    }

                    &::before {
                        content: attr(data-title);
                        display: inline-block;
                        padding-inline-end: 0.5rem;
                        width: 8rem;
                        min-width: 8rem;
                        color: var(--tw-gray-400);
                    }
                }
            }
        }
    }
}

.table-fixed {
    table-layout: fixed;
}
