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

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

.device-page--apps {
  flex: 1 1 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: visible;

  .device-page__motion-view {
    overflow: visible;
  }

  .device-page__apps-motion {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    flex-direction: column;
  }

  .device-apps-view {
    min-height: 0;
    height: 100%;
  }
}

.device-page__grid {
  display: grid;
  grid-template-columns: 340px 340px minmax(360px, 1fr);
  gap: 20px;
  align-items: start;
  width: 100%;
  //min-height: 100%;
}

.device-page__motion-view {
  display: flex;
  flex: 1 0 auto;
  min-height: 0;
  flex-direction: column;
}

.device-card {
  border-radius: 20px;
  background: $color-surface;
  backdrop-filter: blur(22px);
  padding: 20px;
  box-shadow: $shadow-card;
}

.device-card--main {
  grid-column: span 2;
}

.device-page__details-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  align-items: start;

  >.device-card,
  >.device-card-stats {
    min-width: 0;
  }
}

.device-main {
  display: flex;
  flex-direction: row;
  gap: 20px;
}

.device-main__image {
  height: calc(50% - 40px);
  width: 27.1%;
  padding: 20px;
  border-radius: 14px;
  background: $color-surface-subtle;

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

  background-color: $color-bg;

  img {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    width: auto;
    object-fit: contain;
  }
}

.device-main__info {
  display: flex;
  flex-direction: column;
  flex: 1;
  text-align: left;

  h2 {
    margin: 0 0 6px;
    color: $color-text-strong;
    font-size: $font-size-30;
    font-weight: 600;
    line-height: 1.1;
  }

  p {
    margin: 0;
    color: $gray50;
    font-size: $font-size-17;
    font-weight: 500;
    line-height: 1.3;
  }
}

.device-main__divider {
  height: 1px;
  margin: 12px 0 14px;
  background: $gray20;
}

.device-main__statuses {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.device-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;

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

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

  &.is-success svg {
    color: $green;
    background: $color-success-bg;
  }

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

  &.is-muted svg {
    color: $gray50;
  }
}

.device-main__bottom {
  margin-top: 18px;
}

.device-registered {
  width: 100%;
  padding: 0;

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

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

  .device-registered-info {
    display: flex;
    flex: 1;
    align-items: center;
    padding: 10px 0;
    height: inherit;
    justify-content: space-between;
    border-bottom: 1px solid $gray20;

    a {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 6px;
      color: $gray50;
      font-weight: 500;
      text-decoration: none;
      transition: color 0.2s ease;

      &:hover {
        color: $color-primary-hover;

        svg {
          color: $color-primary-hover;
        }
      }

      svg {
        padding: 0;
        background-color: transparent;
        height: 20px;
        width: auto;
        margin-bottom: 2px;
        transition: .2s ease;
      }
    }
  }

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

  b {
    color: $gray50;
    font-weight: 500;
  }

}

.device-card__actions {
  margin-top: 20px;

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

.device-history-btn {

  padding: 12px;

  border: none;
  border-radius: 12px;
  background: $color-primary-soft;

  color: $blue;
  font-size: $font-size-18;
  font-weight: 500;
  cursor: pointer;
  transition: .2s ease;
  line-height: 1;

  &:hover {
    background-color: $blue;
    color: $color-text-inverse;
    box-shadow: var(--shadow-primary);
  }
}

.device-delete-btn {
  padding: 12px;

  border: none;
  border-radius: 12px;
  background: $color-danger-bg-strong;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: $red;
  cursor: pointer;
  transition: .2s ease;

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

  &:hover {
    background-color: $red;
    color: $color-text-inverse;
    box-shadow: var(--shadow-danger);
  }
}

.device-card__header {
  margin-bottom: 14px;

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

  p {
    margin: 0;
    color: $color-text-muted;
    font-size: $font-size-15;
    font-weight: 500;
  }
}

.device-card__title {
  display: flex;
  align-items: center;
  gap: 10px;

  h3 {
    margin: 0;
    color: $color-text-heading;
    font-size: $font-size-18;
    font-weight: 600;
  }

  svg {
    padding: 4px;
    width: 24px;
    height: 24px;
    border-radius: 9px;
    background: $color-surface-hover;
    color: $color-text-heading;
  }
}

.device-map {
  display: flex;
  flex-direction: column;
  grid-column: span 1;
  min-height: 272px;
  height: calc(100% - 40px);
}


.device-permissions {
  padding: 10px 20px;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: space-between;
  height: calc(100% - 20px);
}

.device-permission {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;

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

  &:nth-child(1) {
    .device-permission__label {
      border-top: none;
    }
  }

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

.device-permission__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid $gray20;
}

.device-card-stats {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.device-battery {
  --device-battery-progress-empty: #cfd5df;
  --device-battery-progress-danger: #e00000;
  --device-battery-progress-warning: #ff8a34;
  --device-battery-progress-strong: #031d9a;

  h3 {
    text-align: left;
    line-height: 1;
    margin: 0 0 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid $gray20;

    color: $color-text-heading;
    font-size: $font-size-18;
    font-weight: 600;
  }

  .device-stats-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;

    &:nth-child(2) {
      .device-stats-text {
        border-top: 1px solid $gray20;
        border-bottom: 1px solid $gray20;
        padding: 8px 0;
      }
    }

    svg {
      width: 24px;
      height: 24px;
      padding: 4px;
      border-radius: 8px;
    }
  }

  .device-stats-text {
    display: flex;
    flex: 1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.device-battery__content {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 20px;
  align-items: center;
}

.device-battery__circle {
  position: relative;

  width: 120px;
  height: 120px;
  flex: 0 0 120px;

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

  overflow: visible;

  span {
    position: absolute;
    inset: 0;

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

    color: $color-text;
    font-size: $font-size-26;
    font-weight: 650;
    line-height: 1;
  }
}

.device-battery__circle-svg {
  width: 120px;
  height: 120px;
  display: block;
}

.device-battery__circle-track,
.device-battery__circle-progress {
  fill: none;
}

.device-battery__circle-track {
  stroke: $gray20;
  stroke-linecap: round;
}

.device-battery__circle-progress {
  stroke-linecap: round;
  transition:
    stroke-dashoffset 0.35s ease,
    stroke 0.25s ease;
}

.device-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;

  div {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    align-items: center;
    gap: 10px;

    color: $color-text-heading;
    font-size: $font-size-16;
    font-weight: 500;
  }

  svg {
    padding: 5px;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    color: $color-success-strong;
    background: $color-success-bg;
  }

  b {
    color: $color-text-heading;
    font-weight: 600;
  }
}

.device-impacts {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;

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

  .device-stats-text {
    display: flex;
    flex: 1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
  }

  svg {
    padding: 4px;
    width: 24px;
    height: 24px;
    border-radius: 9px;
    color: $green;
    background: $color-success-bg;
  }

  b {
    font-weight: 600;
  }
}

.device-page__empty {
  min-height: 260px;
  border-radius: 18px;
  background: $color-surface;

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

  h2 {
    margin: 0;
  }

  button {
    height: 40px;
    padding: 0 16px;
    border: none;
    border-radius: 12px;
    background: $blue;
    color: $color-text-inverse;
    cursor: pointer;
  }
}

[data-theme='dark'] {
  .device-battery {
    --device-battery-progress-empty: #36414f;
    --device-battery-progress-danger: #ff4f5e;
    --device-battery-progress-warning: #ff9f43;
    --device-battery-progress-strong: #2d8cff;
  }
}


@include desktop-down {
  .device-page__grid {
    display: grid;
    grid-template-columns: 280px 280px minmax(380px, 1fr);
    gap: 14px;
    align-items: start;

    .device-page__details-row {
      gap: 14px;
      grid-template-columns: 1.25fr 1fr 1.25fr;

      .device-card-stats {
        gap: 14px;
      }
    }

    .device-actions {
      button {
        font-size: var(--font-size-16);
        padding: 12px;
        gap: 12px;

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

      .future-label {
        font-size: var(--font-size-12);
        padding: 8px 12px;
      }
    }
  }

  .device-permission {
    font-size: var(--font-size-16) !important;

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

    &__label {
      padding: 8px 0;
    }
  }

  .device-permissions__icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .device-battery__content {
    grid-template-columns: 100px 1fr;
  }

  .device-battery__circle {
    width: 100px;
    height: 100px;

    span {
      font-size: var(--font-size-22);
    }
  }

  .device-stats {
    gap: 8px;

    div {
      font-size: var(--font-size-15);
    }

    .device-stats-card {
      svg {
        width: 20px;
        height: 20px;
      }
    }
  }

  .device-impacts {
    font-size: var(--font-size-16);

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

  .device-main {
    &__info {
      h2 {
        font-size: var(--font-size-28);
      }

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

  .device-main__image {
    width: 26.5%;
  }

  .device-status {
    font-size: var(--font-size-16);

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

  .device-registered {
    font-size: var(--font-size-16);

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

    .device-registered-info {
      padding: 8px 0;

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

  .device-card__actions {
    margin-top: 18px;
  }

  .device-history-btn {
    font-size: var(--font-size-16);
  }

  .device-delete-btn {
    svg {
      width: 16px;
      height: 16px;
    }
  }

  .history-period-tabs__item {
    font-size: var(--font-size-12);
    height: 30px;
  }

}

@include laptop-down {
  .device-page {
    gap: 14px;
  }

  .device-page__grid {
    grid-template-columns: 540px minmax(360px, 1fr);;
  }

  .device-card--main {
    grid-column: span 1;
  }

  .device-page__grid,
  .device-page__details-row {
    gap: $layout-card-gap;
  }

  .device-card {
    padding: 18px;
    height: calc(100% - 36px);
    border-radius: 16px;
  }
  .device-card-stats{
    height: calc(100%);
  }
  .device-impacts{
    flex: 0;
  }
  .device-battery{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
  }
  .device-permissions{
    height: calc(100% - 12px);
    padding: 8px 8px 4px 18px;
  }

  .device-main {
    gap: 16px;
  }

  .device-main__image {
    padding: 16px;
  }

  .device-map {
    min-height: 252px;
  }
  .history-period-tabs{
    display: none;
  }
  .device-card__title{
    gap: 8px;
    svg{
      width: 22px;
      height: 22px;
    }
    h3{
      font-size: var(--font-size-16);
    }
  }
  .device-card__header{
    p{
          font-size: var(--font-size-14);
    }
  }
}

@include tablet-down {
  .device-main {
    flex-direction: column;
  }

  .device-main__image {
    width: 100%;
    height: 178px;
    box-sizing: border-box;
  }

  .device-main__info {
    h2 {
      font-size: $font-size-26;
    }
  }

  .device-map {
    grid-column: span 1;
    min-height: 300px;
    height: auto;
  }

  .device-page__details-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .device-card__actions {
    gap: 10px;
  }
}
