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

.organisation-page {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    height: auto;
    min-height: calc(80% - 40px);
    max-height: calc(100% - 40px);
    overflow: visible;
    padding: 20px 20px 36px 20px;
}

.organisation-page__top {
    display: grid;
    grid-template-columns: 540px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 20px;
    align-items: stretch;
    flex: 1 0 auto;
    width: 100%;
    height: auto;
    min-height: 100%;
    overflow: visible;

    .employees-table-shadow {
        position: relative;
        flex: 1 1 0;
        min-height: 0;
        height: 100%;
        max-height: 100%;
        display: flex;
        flex-direction: column;
        border-radius: 20px;
        background: $color-surface;
        overflow: hidden;
    }
}

.organisation-container-info {
    display: flex;
    flex-direction: column;
    //flex: 1;
    min-width: 0;
    min-height: 0;
    //max-width: 520px;

    gap: 20px;
}

.organisation-card {
    padding: 20px;
    border-radius: 20px;
    background: $color-surface;

    display: flex;
    flex-direction: column;
    gap: 20px;
    height: fit-content;

    box-shadow: $shadow-card;
}

.organisation-card__main {
    display: flex;
    align-items: center;
    gap: 16px;
}

.organisation-card__avatar {
    width: 96px;
    height: 96px;
    flex: 0 0 96px;
    border-radius: 28px;

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

    background:
        radial-gradient(circle at 25% 20%, rgba($white, 0.1), $transparent 32%),
        linear-gradient(135deg, $blue, $color-primary-hover);
    color: $color-text-inverse;
    font-size: $font-size-28;
    font-weight: 750;
    letter-spacing: 0.04em;
    overflow: hidden;

    &.transparent-backdrop {
        background: transparent;
    }

    img {
        width: 100%;
        height: 100%;
        display: block;
        object-fit: cover;
    }

    span {
        line-height: 1;
    }
}

.organisation-card__info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    gap: 0px;

    h2 {
        margin: 0px 0 4px;
        color: $color-text;
        font-size: $font-size-30;
        font-weight: 650;
        line-height: 1.1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
        max-width: 100%;

        span {
            margin: 0 0 0 8px;
            color: $gray50;
            font-size: $font-size-16;
            font-weight: 500;
        }
    }

    p {
        margin: 0px 0 0;
        color: $gray50;
        font-size: $font-size-15;
        font-weight: 500;
    }
}

.organisation-card__actions {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.organisation-action-btn {
    height: 38px;
    padding: 0 12px;

    border: none;
    border-radius: 12px;

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

    font-size: $font-size-14;
    font-weight: 600;
    cursor: pointer;
    opacity: 0.88;

    box-shadow: inset 0 0 0 $transparent;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        opacity 0.2s ease,
        box-shadow 0.2s ease;

    &:hover {
        opacity: 1;
    }
}

.organisation-action-btn--edit {
    background: $blue20;
    color: $blue;

    &:hover {
        background-color: $blue;
        color: $white;
        box-shadow: inset 0 0 0 1px $blue, 0 8px 20px -8px rgba(var(--color-primary-rgb), 0.8);
    }
}

.organisation-action-btn--delete {
    background: rgba($color-danger-rgb, 0.12);
    color: $red;

    &:hover {
        background-color: $red;
        color: $white;
        box-shadow: inset 0 0 0 1px $red, 0 8px 20px -8px rgba(var(--color-danger-rgb), 0.8);
    }
}

.organisation-tables-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    min-width: 0;
    //align-self: stretch;
    border-radius: 20px;
    background: $transparent;
    max-height: none;
    overflow: visible;
}

.organisation-tables-carousel {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    border-radius: 20px;
    background: $color-surface;
    box-shadow: $shadow-card;
}

.organisation-tables-track {
    width: 200%;
    height: 100%;
    min-height: 0;
    display: flex;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);

    &.is-devices {
        transform: translateX(-50%);
    }
}

.organisation-table-slide {
    width: 50%;
    min-width: 0;
    min-height: 0;
    height: 100%;
    flex: 0 0 50%;

    display: flex;
    flex-direction: column;
}

.organisation-tables-footer {
    min-height: 50px;
    flex: 0 0 auto;

    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.organisation-table-tabs {
    height: 38px;
    padding: 0;

    display: flex;
    align-items: center;
    gap: 6px;

    button {
        height: 38px;
        padding: 0 14px;
        border: none;
        border-radius: 10px;
        background: $gray20;

        color: $gray50;
        font-size: $font-size-15;
        font-weight: 550;
        cursor: pointer;
        transition: .2s ease;

        &:hover {
            background-color: rgba($color-primary-rgb, 0.1);
            color: $blue;
        }

        &.is-active {
            background: $blue;
            color: $color-text-inverse;
            box-shadow: inset 0 0 0 1px $blue, 0 8px 20px -8px rgba(var(--color-primary-rgb), 0.8);
        }
    }
}

.organisation-tables-pagination {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    .employees-pagination {
        padding: 0;
    }
}

.organisation-employees-card__header {
    padding: 18px 20px;
    border-bottom: 1px solid $gray20;

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

    h3 {
        margin: 0;
        color: $color-text;
        font-size: $font-size-22;
        font-weight: 650;
    }

    p {
        margin: 6px 0 0;
        color: $gray50;
        font-size: $font-size-15;
        font-weight: 500;
    }

    >span {
        min-width: 38px;
        height: 32px;
        padding: 0 12px;
        border-radius: 999px;
        background: $blue20;

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

        color: $blue;
        font-size: $font-size-16;
        font-weight: 650;
    }
}

.organisation-employees-table-card {
    position: absolute;
    inset: 0;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 20px;
    background: $color-surface;
    overflow: visible;

    //overflow: auto;

    .simplebar-wrapper,
    .simplebar-mask,
    .simplebar-offset {
        border-radius: 20px;
    }

    .simplebar-content-wrapper {
        height: 100% !important;
        max-height: 100% !important;
        overflow: auto !important;
        border-radius: 20px;
    }

    .simplebar-track.simplebar-vertical {
        top: 48px;
        bottom: 14px;
        width: 16px;
        right: -9px;
    }

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

        opacity: 1;
    }

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

}

.organisation-employees-table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
    table-layout: fixed;

    thead {
        position: sticky;
        top: 0;
        z-index: 2;
        background: $color-surface;
    }

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

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

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

        color: $color-text;
        font-size: $font-size-17;
        font-weight: 400;
    }

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

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

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

    th:nth-child(4),
    td:nth-child(4) {
        width: 180px;
    }

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

    tbody tr {
        transition: 0.2s ease;
        box-shadow: inset 0 0 0 $transparent;

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

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

.organisation-devices-table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
    table-layout: fixed;

    thead {
        position: sticky;
        top: 0;
        z-index: 2;
        background: $color-surface;
    }

    th {
        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;
        background: $color-surface;
    }

    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: 146px;
    }

    th:nth-child(4),
    td:nth-child(4) {
        width: 230px;
    }

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

.organisation-devices-table__row {
    cursor: pointer;
    transition: .2s ease;

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

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

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

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

.organisation-device-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
    min-width: 0;
}

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

.organisation-device-info__imei {
    color: $color-text-muted;
    font-size: $font-size-16;
    font-weight: 400;
}

.organisation-device-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
    border-radius: 12px;

    color: $color-text-strong;
    font-size: $font-size-14;
    font-weight: 550;
    text-transform: uppercase;
    white-space: nowrap;

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

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

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

.organisation-device-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;
    }
}

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

    color: $gray50;

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

        color: $gray50;
        stroke-width: 2;

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

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

.organisation-employee-person {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;

    span {
        color: $color-text;
        font-size: $font-size-17;
        font-weight: 500;
        line-height: 1.2;
    }
}

.organisation-employee-org {
    color: $gray50;
    font-size: $font-size-16;
    font-weight: 500;
}

.organisation-employee-role {
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;

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

    background: $color-primary-tint;
    color: $blue;

    font-size: $font-size-16;
    font-weight: 500;
}

.organisation-employee-role--admin {
    background: $color-warning-tint;
    color: $orange;
}

.organisation-employee-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.organisation-employee-action-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 12px;

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

    cursor: pointer;
    opacity: 0.88;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        opacity 0.2s ease,
        box-shadow 0.2s ease;

    &:hover {
        opacity: 1;
    }
}

.organisation-employee-action-btn--edit {
    background: $color-primary-tint;
    color: $blue;

    &:hover {
        background-color: $blue;
        color: $white;
        box-shadow: inset 0 0 0 1px $blue, 0 8px 20px -8px rgba(var(--color-primary-rgb), 0.8);
    }
}

.organisation-employee-action-btn--delete {
    background: $color-danger-tint-strong;
    color: $red;

    &:hover {
        background-color: $red;
        color: $white;
        box-shadow: inset 0 0 0 1px $red, 0 8px 20px -8px rgba(var(--color-danger-rgb), 0.8);
    }
}

.organisation-page__state,
.organisation-page__empty {
    min-height: 220px;
    border-radius: 20px;
    background: $color-surface;

    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;

    color: $gray50;
    font-size: $font-size-16;
    font-weight: 500;

    h2 {
        margin: 0;
        color: $color-text;
        font-size: $font-size-24;
    }

    a {
        color: $blue;
        text-decoration: none;
        font-weight: 600;
    }
}

.organisation-page__state {
    border-radius: 0;
}

.organisation-page__state--error,
.organisation-page__empty--error {
    color: $red;
}

[data-theme='dark'] {
    .organisation-table-tabs button {
        background: $color-surface-muted;

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

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

    .organisation-devices-table__row:hover {
        background-color: rgba($color-primary-rgb, 0.03);
        box-shadow: inset 3px 0 0 rgba($color-primary-rgb, 0.36);
    }

    .organisation-employees-table tbody tr:hover {
        background-color: rgba($color-primary-rgb, 0.03);
        box-shadow: inset 3px 0 0 rgba($color-primary-rgb, 0.36);
    }

    .organisation-device-icons svg:not(.is-active):not(.is-danger) {
        background-color: $color-surface-active;
    }
}

@include desktop-down {
    .organisation-page {
        gap: 16px;
    }

    .organisation-tables-card {
        gap: 8px;
    }

    .organisation-page__top {
        grid-template-columns: minmax(500px, 460px) minmax(1fr, 1fr);
        gap: $layout-card-gap;
    }

    .organisation-card__info {
        h2 {
            font-size: var(--font-size-26);
        }

        p {
            font-size: var(--font-size-14);
        }
    }

    .organisation-action-btn {
        height: 34px;
        font-size: var(--font-size-14);
    }

    .organisation-policy-card__header {
        h3 {
            font-size: var(--font-size-20);
        }

        p {
            font-size: var(--font-size-14);
        }
    }

    .organisation-policy-item {
        font-size: var(--font-size-16);

        svg {
            width: 20px;
            height: 20px;
        }
    }

    .organisation-policy-editability {
        svg {
            width: 14px;
            height: 14px;
        }
    }

    .offline-threshold {
        font-size: var(--font-size-16);
    }

    .duration-picker__input {
        font-size: var(--font-size-15);
    }

    .duration-picker__unit {
        font-size: var(--font-size-14);
    }


    .organisation-container-info {
        gap: $layout-card-gap;
    }

    .organisation-tables-footer {
        min-height: 0;
    }

    .organisation-employees-table {
        min-width: 840px;

        th {
            padding: 12px 16px;
            font-size: $font-size-14;
        }

        td {
            height: 62px;
            padding: 12px 16px;
            font-size: $font-size-14;
        }

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

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

            .organisation-employee-person span {
                font-size: var(--font-size-14);
            }
        }

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

            .organisation-employee-org {
                font-size: var(--font-size-14);
            }
        }

        th:nth-child(4),
        td:nth-child(4) {
            width: 140px;

            .organisation-employee-role {
                font-size: var(--font-size-14);
            }
        }

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

        tbody tr {
            transition: 0.2s ease;
            box-shadow: inset 0 0 0 $transparent;

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

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

    .organisation-devices-table {
        min-width: 860px;

        th {
            padding: 12px 16px;
            font-size: $font-size-14;
        }

        td {
            height: 64px;
            font-size: $font-size-14;
        }

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

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

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

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

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

@include laptop-down {
    .organisation-page__top {
        grid-template-columns: minmax(360px, 480px) minmax(0, 1fr);
    }

    .organisation-card {
        padding: 18px;
    }

    .organisation-card__avatar {
        width: 84px;
        height: 84px;
        flex-basis: 84px;
        border-radius: 24px;
    }

    .organisation-employees-table,
    .organisation-devices-table {

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

@media (max-width: 1180px) {
    .organisation-page__top {
        grid-template-columns: 1fr;
    }
}

@include tablet-down {
    .organisation-page {
        gap: 14px;
        overflow: visible;
    }

    .organisation-page__top {
        flex: 0 0 auto;
        height: auto;
    }

    .organisation-tables-card {
        min-height: 520px;
    }

    .organisation-tables-footer {
        min-height: auto;
        align-items: center;
        flex-wrap: wrap;
    }

    .organisation-table-tabs {
        order: 1;
    }

    .organisation-tables-pagination {
        order: 2;
        margin-left: auto;
    }

    .organisation-employees-table {
        min-width: 820px;
    }

    .organisation-devices-table {
        min-width: 800px;
    }
}