@use '../../shared/styles/variables' as *;

.devices-page {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 20px 20px 36px;
    //overflow: hidden;
}

.devices-table-container {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    //overflow: hidden;
    //gap: 20px;
}

.devices-table-container .employees-table-shadow {
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

.devices-table-filter-container {
    --devices-filters-width: 292px;
    --devices-filters-gap: 20px;
    --devices-filters-duration: 360ms;
    --devices-filters-easing: cubic-bezier(0.22, 1, 0.36, 1);

    display: flex;
    gap: 0;
    flex: 1;
    min-height: 0;
    min-width: 0;
    //overflow: hidden;
}

.devices-filters-slot {
    flex: 0 0 0;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    pointer-events: none;
    will-change: flex-basis;
    transition:
        flex-basis var(--devices-filters-duration) var(--devices-filters-easing);
}

.devices-filters-slot--open {
    flex-basis: calc(var(--devices-filters-width) + var(--devices-filters-gap));
    pointer-events: auto;
}

.devices-filters-slot--visible {
    overflow: visible;
}

.devices-filters-drawer__overlay {
    position: fixed;
    inset: 0;
    z-index: 820;
    background: $color-backdrop-soft;
    backdrop-filter: blur(4px);

    &[data-state='open'] {
        animation: devicesFiltersOverlayShow 0.18s ease both;
    }

    &[data-state='closed'] {
        animation: devicesFiltersOverlayHide 0.18s ease both;
    }
}

.devices-filters-drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 821;

    width: min(360px, calc(100vw - 28px));
    padding: 18px;
    margin: 20px;
    border-radius: 20px;
    border: none;
    outline: none;
    background: $color-bg;
    box-shadow: $shadow-modal-dark;
    overflow: hidden;

    display: flex;
    flex-direction: column;
    gap: 14px;

    &[data-state='open'] {
        animation: devicesFiltersDrawerShow 0.24s cubic-bezier(0.34, 1.02, 0.64, 1) both;
    }

    &[data-state='closed'] {
        animation: devicesFiltersDrawerHide 0.2s cubic-bezier(0.4, 0, 0.2, 1) both;
    }

    .devices-filters {
        width: 100%;
        min-width: 0;
        margin-left: 0;
        opacity: 1;
        visibility: visible;
        transform: none;
        pointer-events: auto;
    }
}

.devices-filters-drawer__scroll {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;

    .simplebar-content {
        min-height: 100%;
    }

    .simplebar-track.simplebar-vertical {
        width: 10px;
        right: -12px;
    }

    .simplebar-scrollbar::before {
        background: $gray50;
        opacity: 0.55;
    }
}

.devices-filters-drawer__header {
    flex: 0 0 auto;
    min-height: 34px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    h2 {
        margin: 0;
    }
}

.devices-filters-drawer__header [data-radix-dialog-title],
.devices-filters-drawer__header h2 {
    color: $color-text-heading;
    font-size: $font-size-20;
    font-weight: 650;
    line-height: 1.1;
}

.devices-filters-drawer__close {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 12px;
    background: $color-surface;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: $color-text-muted;
    cursor: pointer;
    transition: 0.2s ease;

    &:hover {
        background: $color-surface-hover;
        color: $color-text-heading;
    }
}

.devices-table-card {
    position: relative;
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
    //overflow: hidden;
    max-height: 100%;
    height: 100%;
    border-radius: 20px;
    background: $color-surface;
    min-height: 0px;

    .simplebar-wrapper,
    .simplebar-mask,
    .simplebar-offset,
    .simplebar-content-wrapper,
    .simplebar-content {
        min-width: 0;
        max-width: 100%;
    }

    .simplebar-content-wrapper{
        border-radius: 20px;
    }
    .simplebar-track.simplebar-vertical {
        top: 48px;
        bottom: 14px;
        width: 14px;
        right: -7px;
        overflow: visible;
    }

    .simplebar-scrollbar::before {
        background: color-mix(in srgb, var(--gray50) 85%, transparent);
        backdrop-filter: blur(10px);
        border-radius: 4px;
        box-shadow: inset 0 0 0 1px var(--gray30), -2px 4px 12px rgba(0, 0, 0, 0.1);
        opacity: 1;
    }

    .simplebar-track.simplebar-horizontal {
        left: 12px;
        right: 12px;
        height: 8px;
    }

    &.is-updating {
        .devices-table {
            opacity: 0.55;
            pointer-events: none;
        }
    }
}

.devices-state {
    min-height: 260px;
    height: 100%;
    padding: 32px;

    display: flex;
    align-items: center;
    justify-content: center;

    color: $gray50;
    font-size: $font-size-16;
    font-weight: 600;
    text-align: center;
}

.devices-state--error {
    color: $red;
}

.devices-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;

    &__row {
        transition: .2s ease;
        cursor: pointer;

        &:hover {
            background-color: $color-primary-tint-soft;
            box-shadow: inset 3px 0 0 rgba($color-primary-rgb, 0.8);

            .device-info__number {
                color: $blue;
            }
        }
    }

    th {
        //height: 36px;
        padding: 14px 20px;
        line-height: 1;
        border-bottom: 1px solid $color-border;

        color: $gray50;
        font-size: $font-size-16;
        font-weight: 450;
        text-align: left;
    }

    td {
        height: 68px;
        padding: 14px 20px;
        border-bottom: 1px solid $gray20;
        vertical-align: middle;
        text-align: left;

        color: $color-text-strong;
        font-size: $font-size-18;
        font-weight: 400;
    }

    th:nth-child(1),
    td:nth-child(1) {
        width: 52px;
    }

    th:nth-child(2),
    td:nth-child(2) {
        width: 31%;
    }

    th:nth-child(3),
    td:nth-child(3) {
        width: 23%;
    }

    th:nth-child(4),
    td:nth-child(4) {
        width: 23%;
    }

    th:nth-child(5),
    td:nth-child(5) {
        width: 146px;
    }

    th:nth-child(6),
    td:nth-child(6) {
        width: 146px;
    }
}

.devices-table__id {
    color: $color-text-strong;
    text-align: left;
}

.device-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.device-info__number {
    color: $color-text-strong;
    font-size: $font-size-18;
    font-weight: 600;
    transition: .2s ease;
}

.device-info__imei,
.device-info__employee {
    color: $color-text-muted;
    font-size: $font-size-18;
    font-weight: 400;
}

.device-info__work {
    display: flex;
    align-items: center;
    gap: 5px;

    color: $color-text-muted;
    font-size: $font-size-18;
    font-weight: 400;
}

.devices-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    color: $color-text-strong;
    font-size: $font-size-14;
    padding: 0px 8px;
    border-radius: 12px;
    font-weight: 550;

    &--green {
        background-color: $color-success-tint;
        color: $green;
    }

    &--gray {
        background-color: $color-bg;
        color: $gray50;
    }

    &--red {
        background-color: $color-danger-status-bg;
        color: $red;
    }
}

.devices-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: 0 0 7px;
}

.devices-dot--green {
    background: $green;
}

.devices-dot--red {
    background: $red;
}

.devices-dot--gray {
    background: $gray50;
}

.device-icons {
    display: grid;
    grid-template-columns: repeat(4, 20px);
    gap: 4px 8px;
    align-items: center;

    color: $gray50;

    svg {
        background-color: $color-bg;
        width: 20px;
        height: auto;
        color: $gray50;
        stroke-width: 2;
        padding: 2px;
        border-radius: 6px;
    }

    .is-active {
        color: $blue;
        background-color: $blue20;
    }

    .is-danger {
        color: $red;
        background-color: $color-danger-bg;
    }
}

.devices-map-btn {
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: $gray20;

    display: inline-flex;
    align-items: center;
    gap: 8px;

    color: $color-text-strong;
    font-size: $font-size-16;
    font-weight: 500;
    cursor: pointer;
    transition: .2s ease;

    &:hover {
        background-color: $blue20;
        color: $blue;
    }

    svg {
        height: 18px;
        width: auto;
    }
}

.devices-pagination {
    position: relative;
    z-index: 100;
    padding: 12px 14px 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    color: $color-text-muted;
    font-size: $font-size-16;
}

.devices-pagination__controls {
    display: flex;
    align-items: center;
    gap: 6px;

    button {
        min-width: 30px;
        height: 30px;
        padding: 0 12px;

        border: none;
        border-radius: 10px;
        background: $color-surface-active;

        color: $color-text-muted;
        font-size: $font-size-17;
        cursor: pointer;

        &.is-active {
            background: $color-primary;
            color: $color-text-inverse;
        }

        &:disabled {
            opacity: 0.5;
            cursor: default;
        }
    }
}

[data-theme='dark'] {
    .devices-table__row:hover {
        background-color: rgba($color-primary-rgb, 0.03);
        box-shadow: inset 3px 0 0 rgba($color-primary-rgb, 0.36);
    }

    .device-icons svg:not(.is-active):not(.is-danger) {
        background-color: rgba($gray50-rgb, .15);
    }

    .devices-map-btn:hover {
        background-color: $color-surface-active;
        color: $color-primary-hover;
    }

    .devices-pagination__controls button {
        background: $color-surface-muted;

        &:hover:not(:disabled):not(.is-active) {
            background: $color-surface-hover;
            color: $color-text-heading;
        }

        &.is-active {
            background: $color-primary;
            color: $color-text-inverse;
        }
    }
}

@include wide-down {
.devices-table-filter-container {
        --devices-filters-width: 264px;
        --devices-filters-gap: 14px;
    }
    .devices-filters-slot {
        display: none;
    }

    .devices-table {
        min-width: 980px;

        th,
        td {
            padding-inline: 16px;
        }
    }
}

@include laptop-down {
    .devices-table-filter-container {
        --devices-filters-width: 264px;
        --devices-filters-gap: 14px;
    }

    .devices-filters-slot {
        display: none;
    }

    .devices-table {
        min-width: 980px;

        th,
        td {
            padding-inline: 16px;
        }
    }
}

@include tablet-down {
    .devices-table {
        min-width: 980px;
    }
}

@keyframes devicesFiltersOverlayShow {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes devicesFiltersOverlayHide {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes devicesFiltersDrawerShow {
    from {
        opacity: 0;
        transform: translateX(18px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes devicesFiltersDrawerHide {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(18px);
    }
}
