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

.organisation-policy-card {
  //height: 100%;
  padding: 20px;
  border-radius: 20px;
  min-width: 500px;
  background: $color-surface;
  display: flex;
  flex-direction: column;
  //flex: 1;
  //margin-top: 20px;
  box-shadow: var(--shadow-card);
}

.organisation-policy-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  margin-bottom: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid $gray20;

  >div:first-child {
    min-width: 0;
  }

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

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

.organisation-policy-card--form {
  //height: 100%;
  padding: 16px;
  border-radius: 18px;
  background: $color-surface-muted;
  box-shadow: none;
  outline: 1px solid $color-border-strong;

  .organisation-policy-card__header {
    margin-bottom: 6px;
    padding-bottom: 12px;
  }

  .organisation-policy-card__header h3 {
    font-size: $font-size-18;
    line-height: 1.15;
  }

  .organisation-policy-card__header p {
    margin-top: 4px;
    font-size: $font-size-13;
  }

  .organisation-policy-item {
    font-size: $font-size-15;
  }

  .organisation-policy-item__content {
    min-height: 48px;
  }

  .organisation-policy-item__controls {
    width: auto;
    min-width: 280px;
    gap: 10px;
  }

  .organisation-policy-editability {
    min-width: 122px;
  }

  .offline-threshold {
    font-size: $font-size-15;
  }

  .offline-threshold__content {
    padding-top: 12px;
  }
}

.organisation-policy-card__title {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.organisation-policy-card__help {
  position: relative;
  width: 18px;
  height: 18px;

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

  color: $color-text-muted;
  cursor: help;
  outline: none;
  transition: color 0.18s ease;

  svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.2;
    transition: 0.2s ease;
  }

  &:hover,
  &:focus-visible {
    color: $blue;
  }

  &:hover .organisation-policy-card__help-tooltip,
  &:focus-visible .organisation-policy-card__help-tooltip {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: translateY(8px);
  }
}

.organisation-policy-card__help-tooltip {
  position: absolute;
  z-index: 30;
  top: 100%;
  left: -34px;

  width: 400px;
  padding: 11px;
  border-radius: 12px;
  background: rgba($color-surface-rgb, 0.94);
  backdrop-filter: blur(18px);
  box-shadow:
    0 14px 30px rgba($color-shadow-rgb, 0.16),
    inset 0 0 0 1px rgba($color-primary-rgb, 0.08);

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

  display: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(2px);
  transition:
    opacity 0.18s ease,
    visibility 0.18s ease,
    transform 0.18s ease;

  &::before {
    content: '';
    position: absolute;
    left: 38px;
    bottom: 100%;
    width: 9px;
    height: 9px;
    background: rgba($color-surface-rgb, 0.94);
    box-shadow: -1px -1px 0 rgba($color-primary-rgb, 0.08);
    transform: translateY(5px) rotate(45deg);
  }
}

.organisation-policy-card__help-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 9px;
  align-items: center;

  >svg {
    margin-top: 1px;
    width: 20px;
    height: 20px;
    color: $blue;
  }

  span {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 2px;
  }

  b {
    color: $color-text-heading;
    font-size: $font-size-14;
    font-weight: 700;
    line-height: 1.2;
  }

  small {
    color: $color-text-muted;
    font-size: $font-size-13;
    font-weight: 500;
    line-height: 1.28;
  }
}

.organisation-policy-card {
  .device-permissions__header-actions {
    position: relative;
    width: 82px;
    height: 36px;
    flex: 0 0 82px;
  }

  .device-permissions__icon-btn {
    position: absolute;
    top: 0;
    right: 0;

    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 12px;
    background: $color-bg;

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

    color: $gray50;
    cursor: pointer;
    transition:
      background-color 0.18s ease,
      color 0.18s ease,
      opacity 0.18s ease,
      transform 0.18s ease,
      box-shadow 0.18s ease;

    &:hover:not(:disabled) {
      background: $gray20;
      color: $color-text;
    }

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

  .device-permissions__icon-btn--edit {
    z-index: 2;
    background: $blue20;
    color: $blue;

    &:hover:not(:disabled) {
      background: $blue;
      color: $color-text-inverse;
      box-shadow: 0 8px 20px rgba($color-primary-rgb, 0.18);
    }
  }

  .device-permissions__icon-btn--reset {
    z-index: 1;
    opacity: 0;
    pointer-events: none;
    transform: translateX(0) scale(0.92);
    transition:
      background-color 0.18s ease,
      color 0.18s ease,
      opacity 0.18s ease,
      transform 0.28s cubic-bezier(0.34, 1.42, 0.64, 1);
  }

  &.is-editing {
    .device-permissions__icon-btn--reset {
      opacity: 1;
      pointer-events: auto;
      transform: translateX(-46px) scale(1);

      &:disabled {
        opacity: 0.45;
        pointer-events: none;
      }
    }
  }

  &:not(.is-policy-editing) {
    .organisation-policy-item:not(.is-disabled) {
      opacity: 0.72;
    }

    .organisation-policy-switch,
    .organisation-policy-editability {
      pointer-events: none;
      cursor: not-allowed;
    }
  }
}

.organisation-policy-card__list {
  display: flex;
  flex-direction: column;
}

.organisation-policy-item {
  display: flex;
  align-items: center;
  gap: 10px;

  color: $color-text;
  font-size: $font-size-18;
  font-weight: 500;
  transition:
    opacity 0.2s ease,
    filter 0.2s ease;

  svg {
    width: 24px;
    height: 24px;
    padding: 4px;
    border-radius: 8px;
    color: $blue;
    background: $color-bg;
  }

  &:first-child {
    .organisation-policy-item__content {
      border-top: none;
    }
  }

  &.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;

    svg,
    span,
    button {
      pointer-events: none;
    }

    .organisation-policy-switch {
      cursor: not-allowed;
      box-shadow: inset 0 0 0 1px rgba($gray50-rgb, 0.08);

      &:disabled {
        cursor: not-allowed;
      }
    }
  }
}

.organisation-policy-item__content {
  min-height: 52px;
  flex: 1;
  border-top: 1px solid $gray20;

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

.organisation-policy-item__label {
  min-width: 0;
  //flex: 1 1 auto;
}

.organisation-policy-item__controls {
  //flex: 1 1 auto;
  width: 70%;
  justify-content: space-between;
  display: flex;
  align-items: center;
  gap: 20px;
}

.organisation-policy-editability {
  height: 34px;
  min-width: 174px;
  padding: 0 8px;
  border: none;
  border-radius: 999px;
  background: $color-bg;

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

  color: $gray50;
  font-size: $font-size-13;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;

  .icon-title{
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  svg {
    width: 15px;
    height: 15px;
    margin-bottom: 1px;
    padding: 0;
    border-radius: 0;
    background: $transparent;
    color: currentColor;
  }

  &.is-editable {
    color: $blue;
    box-shadow: inset 0 0 0 1px rgba($color-primary-rgb, 0.1);
  }

  &.is-fixed {
    color: $color-text-muted;
    box-shadow: inset 0 0 0 1px rgba($gray50-rgb, 0.1);
  }

  &:hover:not(:disabled) {
    background: $gray20;
    color: $color-text;
  }

  &:active:not(:disabled) {
    transform: scale(0.96);
  }

  &:disabled {
    cursor: default;
  }
}

.organisation-policy-editability-menu {
  z-index: 160;
  width: 300px;
  padding: 6px;
  border-radius: 14px;
  background: $color-surface;
  box-shadow: $shadow-popover-soft;
  animation: organisationPolicyMenuShow 0.16s ease;
}

.organisation-policy-editability-menu__item {
  min-height: 58px;
  padding: 8px;
  border-radius: 10px;
  outline: none;

  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 8px;

  color: $color-text;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;

  &[data-highlighted] {
    background: $gray20;
  }

  &.is-selected {
    color: $blue;
  }
}

.organisation-policy-editability-menu__icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: $color-bg;

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

  color: currentColor;

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

.organisation-policy-editability-menu__text {
  min-width: 0;

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

  strong {
    color: currentColor;
    font-size: $font-size-14;
    font-weight: 700;
    line-height: 1.15;
  }

  small {
    color: $gray50;
    font-size: $font-size-12;
    font-weight: 500;
    line-height: 1.25;
  }
}

.organisation-policy-editability-menu__check {
  justify-self: end;
  color: $blue;
}

@keyframes organisationPolicyMenuShow {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.organisation-policy-switch {
  position: relative;

  width: 118px;
  height: 28px;
  flex: 0 0 118px;
  padding: 3px;
  border: none;
  outline: none;

  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;

  border-radius: 999px;
  background: $color-bg;
  box-shadow: inset 0 0 0 1px rgba($gray50-rgb, 0.08);

  cursor: pointer;
  user-select: none;

  transition:
    background-color 0.28s ease,
    box-shadow 0.28s ease,
    transform 0.18s ease;

  &--service {
    width: 118px;
    flex-basis: 118px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  &--component {
    width: 78px;
    flex-basis: 78px;
    grid-template-columns: repeat(2, minmax(0, 1fr));

    .organisation-policy-switch__thumb {
      width: calc((100% - 6px) / 2) !important;
    }
  }

  .organisation-policy-switch__thumb {
    position: absolute;
    top: 3px;
    left: 3px;

    width: calc((100% - 6px) / 3);
    height: calc(100% - 6px);
    border-radius: 100px;
    background: $color-surface;

    box-shadow:
      0 2px 5px rgba($color-shadow-rgb, 0.18),
      0 1px 1px rgba($color-shadow-rgb, 0.08);

    transition:
      transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
      box-shadow 0.28s ease,
      width 0.18s ease;
  }

  .organisation-policy-switch__option {
    position: relative;
    z-index: 1;

    min-width: 0;
    padding: 0;
    border: none;
    background: $transparent;

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

    color: $gray50;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: $transparent;

    &:focus-visible {
      border-radius: 999px;
    }
  }

  .organisation-policy-switch__option[aria-disabled='true'] {
    cursor: not-allowed;
  }

  .organisation-policy-switch__label {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: $blue;
    transition:
      color 0.2s ease,
      opacity 0.2s ease;

    svg {
      width: 14px;
      height: 14px;
      padding: 0;
      border-radius: 0;
      color: inherit;
      background: transparent;
      stroke-width: 2.35;
    }
  }

  &.is-unspecified,
  &.is-changeable {
    box-shadow: inset 0 0 0 1px rgba($color-primary-rgb, 0.1);

    .organisation-policy-switch__thumb {
      transform: translateX(100%);
      background: $blue20;
      box-shadow:
        0 3px 7px -4px rgba($color-primary-rgb),
        0 1px 1px rgba($color-shadow-rgb, 0.08);
    }

    .organisation-policy-switch__option.is-active .organisation-policy-switch__label {
      color: $blue;
    }
  }

  &.is-enabled,
  &.is-allowed {
    background: rgba($color-primary-rgb, 0.1);
    box-shadow: inset 0 0 0 1px rgba($color-primary-rgb, 0.12);

    .organisation-policy-switch__thumb {
      background: $blue;
      box-shadow:
        0 3px 7px rgba($color-primary-rgb, 0.24),
        0 1px 1px rgba($color-shadow-rgb, 0.08);
    }

    .organisation-policy-switch__option.is-active .organisation-policy-switch__label {
      color: $color-text-inverse;

      svg {
        color: $white;
      }
    }
  }

  &.is-enabled {
    .organisation-policy-switch__thumb {
      transform: translateX(200%);
    }
  }

  &.is-allowed {
    .organisation-policy-switch__thumb {
      transform: translateX(100%);
    }
  }

  &.is-disabled,
  &.is-disallowed {
    .organisation-policy-switch__option.is-active .organisation-policy-switch__label {
      color: $blue !important;
    }
  }

  &:hover:not(.is-disabled) {
    box-shadow:
      inset 0 0 0 1px rgba($gray50-rgb, 0.12),
      //0 4px 10px rgba($color-shadow-rgb, 0.06);
  }

  &:active:not(.is-disabled) {
    transform: scale(0.96);
  }

  &:focus-within {
    //box-shadow:
      //0 0 0 3px rgba($color-primary-rgb, 0.18),
      //inset 0 0 0 1px rgba($color-primary-rgb, 0.18);
  }

  &.is-disabled {
    cursor: default;
  }
}

.policy-mode-prototype {
  display: flex;
  align-items: center;
  gap: 10px;

  color: $color-text;
  font-size: $font-size-18;
  font-weight: 500;

  >svg {
    width: 24px;
    height: 24px;
    padding: 4px;
    border-radius: 8px;
    color: $blue;
    background: $color-bg;
  }
}

.policy-mode-prototype__content {
  min-height: 58px;
  padding: 10px 0;
  flex: 1;
  border-top: 1px solid $gray20;

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

  >span {
    flex: 0 0 auto;
  }
}

.policy-mode-prototype-switch {
  width: min(320px, 100%);
  min-width: 250px;
  min-height: 44px;
  flex: 0 1 320px;
  padding: 4px;
  border-radius: 999px;
  //background: $color-surface-muted;

  display: grid;
  gap: 4px;

  box-shadow:
    inset 0 0 0 1px rgba($gray50-rgb, .4),
    0 8px 24px rgba($color-shadow-rgb, 0.08);
  transition: grid-template-columns 0.28s cubic-bezier(0.34, 1.2, 0.4, 1);

  &.is-enabled {
    grid-template-columns: minmax(58px, 0.68fr) minmax(0, 1.85fr);
  }

  &.is-disabled {
    grid-template-columns: minmax(0, 1.85fr) minmax(58px, 0.68fr);
  }
}

.policy-mode-prototype-switch__segment {
  min-width: 0;
  min-height: 36px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: $transparent;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  color: $gray50;
  font-size: $font-size-14;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease,
    transform 0.18s ease;

  &:hover {
    //color: $color-text;
    //background: rgba($white, 0.6);
  }

  &:active {
    transform: scale(0.98);
  }

  &.is-active {
    padding: 0;
    justify-content: stretch;
    color: $color-text-inverse;
    cursor: default;
    background: $blue;
    box-shadow:
      //0 9px 18px rgba($color-shadow-rgb, 0.18),
      inset 0 0 0 1px rgba($white, 0.12);

    &:hover,
    &:active {
      color: $color-text-inverse;
      background: $blue;
      transform: none;
    }
  }
}

.policy-mode-prototype-switch__edit {
  width: 100%;
  min-height: 36px;
  padding: 4px;
  border-radius: 999px;
  background: $transparent;

  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;

  button {
    min-width: 0;
    height: 36px;
    padding: 0 10px;
    border: none;
    border-radius: 999px;
    background: $transparent;

    color: rgba($white, 0.54);
    font-size: $font-size-14;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition:
      background-color 0.18s ease,
      color 0.18s ease,
      box-shadow 0.18s ease;

    &:hover {
      color: $color-text-inverse;
    }

    &.is-selected {
      color: $color-text-strong;
      background: $color-surface;
    }
  }
}

.offline-threshold {
  display: flex;
  align-items: center;
  gap: 10px;
  color: $color-text;
  font-size: $font-size-18;
  font-weight: 500;

  .offline-threshold-svg {
    width: 24px;
    height: 24px;
    padding: 4px;
    margin-top: 14px;
    border-radius: 8px;
    color: $blue;
    background: $color-bg;
    transition: .18s ease;

    &.is-disabled {
      opacity: .72;
    }
  }
}

.offline-threshold__content {
  //min-height: 52px;
  flex: 1;
  border-top: 1px solid $gray20;
  padding-top: 14px;

  display: flex;
  flex-direction: row;
  height: fit-content;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.offline-threshold__title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: .18s ease;

  &.is-disabled {
    //opacity: .72;
    svg{
      opacity: .72;
    }
    label{
      opacity: .72;
    }
  }
}

.offline-threshold__help {
  position: relative;
  width: 18px;
  height: 18px;

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

  color: $gray50;
  cursor: help;
  outline: none;

  svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.2;
  }

  &:hover,
  &:focus-visible {
    color: $blue;
  }

  &:hover .offline-threshold__tooltip,
  &:focus-visible .offline-threshold__tooltip {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -8px);
    backdrop-filter: blur(20px);
  }
}

.offline-threshold__tooltip {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 100%;

  width: 300px;
  padding: 9px 11px;
  border-radius: 10px;
  //background-color: $color-surface;
  box-shadow:
    0 12px 28px rgba($color-shadow-rgb, 0.1),
    inset 0 0 0 1px rgba($color-primary-rgb, 0.08);

  color: $color-text-heading;
  font-size: $font-size-14;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;

  opacity: 0;
  display: none;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -2px);
  transition:
    opacity 0.18s ease,
    visibility 0.18s ease,
    transform 0.18s ease;
    
  backdrop-filter: blur(20px);

  &::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    width: 9px;
    height: 9px;
    background: $color-surface;
    box-shadow: 1px 1px 0 rgba($color-primary-rgb, 0.08);
    transform: translate(-50%, -5px) rotate(45deg);
    
  backdrop-filter: blur(20px);
  }
}

.offline-threshold__picker {
  margin-top: -2px;
}

.organisation-policy-card__footer {
  min-height: 42px;
  margin-top: 16px;

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

  &:empty {
    display: none;
  }
}

.organisation-policy-card__error {
  color: $red;
  font-size: $font-size-14;
  text-align: left;
  line-height: 1.2;
  background-color: rgba($color-danger-rgb, .1);
  width: fit-content;
  border-radius: 8px;
  padding: 4px 8px;
  height: 100%;
  font-weight: 600;
}

[data-theme='dark'] {

  .organisation-policy-card .device-permissions__icon-btn--reset {
    background: $color-surface-hover;
    color: $color-text-muted;
  }

  .organisation-policy-card .device-permissions__icon-btn:not(.device-permissions__icon-btn--edit):hover:not(:disabled) {
    background: $color-surface-hover;
    color: $color-text-heading;
  }

  .organisation-policy-card .device-permissions__icon-btn--reset:hover:not(:disabled) {
    background: $color-surface-active;
    color: $color-text-heading;
  }

  .organisation-policy-card .device-permissions__icon-btn--edit:hover:not(:disabled) {
    background: $blue;
    color: $color-text-inverse;
    box-shadow: 0 8px 20px rgba($color-primary-rgb, 0.18);
  }

  .organisation-policy-editability {
    background: $color-surface-muted;

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

  .organisation-policy-editability-menu {
    box-shadow: none;
    outline: 1px solid rgba($gray50-rgb, 0.08);
  }

  .organisation-policy-editability-menu__item[data-highlighted] {
    background: $color-surface-hover;
  }

  .organisation-policy-editability-menu__icon {
    background: $color-surface-muted;
  }

  .organisation-policy-switch:hover:not(.is-disabled) {
    box-shadow:
      inset 0 0 0 1px rgba($gray50-rgb, 0.16),
      0 4px 10px rgba($color-shadow-rgb, 0.08);
  }

  .organisation-policy-switch:not(.is-enabled):not(.is-allowed):not(.is-unspecified):not(.is-changeable) {
    svg {
      color: $blue !important;
      stroke-width: 3px;
    }

    .organisation-policy-switch__thumb {
      background: $white;
    }
  }

  .organisation-policy-switch.is-disabled,
  .organisation-policy-switch.is-disallowed {
    .organisation-policy-switch__option.is-active .organisation-policy-switch__label {
      color: $neutral-900;
    }
  }

  .policy-mode-prototype-switch {
    box-shadow: inset 0 0 0 1px rgba($gray50-rgb, 0.12);
  }

  .policy-mode-prototype-switch__edit button:hover {
    background: rgba($white, 0.08);
  }

  .policy-mode-prototype-switch__edit button.is-selected {
    background: $white;
    color: $neutral-900;
  }
}

@include laptop-down {
  .organisation-policy-card {
    padding: 18px;
    min-width: 444px;
  }

  .organisation-policy-card__header {
    gap: 10px;
  }

  .organisation-policy-item {
    gap: 8px;
  }

  .organisation-policy-item__content {
    gap: 10px;
  }

  .organisation-policy-item__controls {
    width: auto;
    min-width: 292px;
    flex: 0 0 auto;
    gap: 8px;
  }

  .organisation-policy-editability {
    min-width: 166px;
    padding-inline: 7px;
  }

  .organisation-policy-switch {
    width: 112px;
    flex-basis: 112px;

    &--service {
      width: 112px;
      flex-basis: 112px;
    }

    &--component {
      width: 76px;
      flex-basis: 76px;
    }
  }

  .offline-threshold__content {
    gap: 10px;
  }
}
