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

.device-apps-view {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  gap: 14px;
}

.device-apps-view__header {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 180px;
  align-items: center;
  gap: 16px;
  min-height: 42px;
}

.device-apps-view__back,
.device-apps-view__install {
  height: 42px;
  padding: 0 14px;
  border: none;
  border-radius: 12px;
  text-wrap: nowrap;

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

  font-size: $font-size-16;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}

.device-apps-view__back {
  background: $color-surface;
  color: $color-text-heading;
  box-shadow: 5px 5px 40px -10px rgba($gray50-rgb, 0.2);
  width: fit-content;
  padding: 0 14px 0 8px;

  svg {
    color: $blue;
    width: 24px;
    height: auto;
  }

  &:hover {
    color: $blue;
  }
}

.device-apps-view__install {
  background: $color-bg;
  color: $gray50;
  cursor: not-allowed;
  justify-self: end;
}

.device-apps-view__title {
  height: 42px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;

  h2 {
    margin: 0;
    color: $color-text-heading;
    font-size: $font-size-22;
    font-weight: 650;
    line-height: 1.05;
  }

  span {
    display: block;
    max-width: 100%;
    margin-top: 1px;
    color: $gray50;
    font-size: $font-size-13;
    font-weight: 500;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.device-apps-view__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.device-apps-view__search {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: $color-surface;
  box-shadow: 5px 5px 40px -10px rgba($gray50-rgb, 0.2);

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

  svg {
    flex: 0 0 auto;
    color: $gray50;
  }

  input {
    width: 100%;
    border: none;
    outline: none;
    background: $transparent;
    color: $color-text-heading;
    font: inherit;
    font-size: $font-size-15;
    font-weight: 500;

    &::placeholder {
      color: $gray50;
    }
  }
}

.device-apps-view__toolbar-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.device-apps-view__sort {
  height: 44px;
  padding: 0 13px 0 15px;
  border: none;
  border-radius: 14px;
  background: $color-surface;
  box-shadow: 5px 5px 40px -10px rgba($gray50-rgb, 0.2);

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

  color: $gray50;
  font-size: $font-size-14;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.2s ease;

  svg {
    transition: .2s ease;
    color: $gray50;
  }

  &:hover,
  &[data-state='open'] {
    color: $blue;
    background: $blue20;

    svg {
      color: $blue;
    }
  }
}

.device-apps-view__sort-menu {
  z-index: 200;
  min-width: 210px;
  padding: 6px;
  border-radius: 16px;
  background: $color-surface;
  box-shadow: $shadow-popover;
  animation: deviceAppsSortMenuShow 0.16s ease;
}

.device-apps-view__sort-item {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 10px;

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

  color: $color-text-heading;
  font-size: $font-size-14;
  font-weight: 500;
  outline: none;
  cursor: pointer;

  &[data-highlighted] {
    background: $color-surface-subtle;
    color: $blue;
  }
}

.device-apps-view__sort-check {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: $blue;
  flex: 0 0 7px;
}

.device-apps-view__summary {
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: $color-surface;
  box-shadow: 5px 5px 40px -10px rgba($gray50-rgb, 0.2);

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

  color: $gray50;
  font-size: $font-size-14;
  font-weight: 600;
  white-space: nowrap;

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

.device-apps-view__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  flex: 1 1 0;
  border-radius: 20px;
  background: $color-surface;
  box-shadow: 5px 5px 40px -10px rgba($gray50-rgb, 0.2);
}

.device-apps-view__scroll {
  position: relative;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  border-radius: 20px;
  background: $color-surface;

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

  .simplebar-content-wrapper {
    border-radius: 20px;
  }

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

  .simplebar-track.simplebar-vertical {
    top: 14px;
    right: -7px;
    bottom: 14px;
    width: 14px;
  }

  .simplebar-scrollbar::before {
    background: color-mix(in srgb, var(--gray50) 85%, transparent);
    border-radius: 6px;
    opacity: 1;
  }
}

.device-apps-view__reveal {
  display: block;
  min-height: 100%;

  .reveal-content__fallback,
  .reveal-content__content {
    display: block;
    min-height: 100%;
  }
}

.device-apps-view__state {
  min-height: 220px;
  padding: 24px;

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

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

  &.is-error {
    color: $red;
  }
}

.device-apps-view__list {
  display: flex;
  flex-direction: column;
}

.device-apps-view__item {
  border-bottom: 1px solid $gray20;

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

.device-apps-view__item-header {
  margin: 0;
}

.device-apps-view__trigger {
  width: 100%;
  min-height: 72px;
  padding: 14px 20px;
  border: none;
  background: $color-surface;

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

  text-align: left;
  cursor: pointer;
  outline: none;
  transition: 0.2s ease;

  &:hover {
    background: $color-surface-muted;
  }

  &:focus-visible {
    box-shadow: inset 0 0 0 2px rgba($color-primary-rgb, 0.16);
  }

  &[data-state='open'] {
    background: $color-surface-muted;

    .device-apps-view__chevron {
      transform: rotate(180deg);
    }
  }
}

.device-apps-view__app-main {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.device-apps-view__app-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 14px;
  background: $color-bg;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: $blue;

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

  &.is-fallback {
    background: $blue20;
  }
}

.device-apps-view__app-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;

  strong,
  small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  strong {
    color: $color-text-heading;
    font-size: $font-size-17;
    font-weight: 650;
  }

  small {
    color: $gray50;
    font-size: $font-size-14;
    font-weight: 500;
  }
}

.device-apps-view__app-meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;

  span {
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: $color-bg;

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

    color: $gray50;
    font-size: $font-size-13;
    font-weight: 650;
  }
}

.device-apps-view__chevron {
  color: $gray50;
  transition: transform 0.2s ease;
}

.device-apps-view__content {
  overflow: hidden;

  &[data-state='open'] {
    animation: deviceAppsViewDown 0.2s ease;
  }

  &[data-state='closed'] {
    animation: deviceAppsViewUp 0.2s ease;
  }
}

.device-apps-view__details {
  padding: 0 20px 18px 76px;
}

.device-apps-view__details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.device-apps-view__detail-card {
  min-width: 0;
  //min-height: 58px;
  padding: 9px 12px;
  border-radius: 14px;
  background: $color-surface-muted;
  box-shadow: inset 0 0 0 1px rgba($gray20-rgb, 0.8);

  display: flex;
  align-items: center;
  gap: 11px;
}

.device-apps-view__detail-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: $color-bg;
  flex: 0 0 40px;

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

  color: $blue;
  svg{
    width: 20px;
    height: auto;
  }
}

.device-apps-view__detail-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;

  small {
    color: $gray50;
    font-size: $font-size-14;
    font-weight: 500;
    line-height: 1.2;
  }

  b {
    min-width: 0;
    color: $color-text-heading;
    font-size: $font-size-16;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.device-apps-view__stats {
  margin-top: 10px;
  padding: 14px;
  border-radius: 14px;
  background: $color-surface;
  border: 1px dashed $color-border-accent;

  text-align: left;

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

  p {
    margin-top: 4px;
    color: $gray50;
    font-size: $font-size-14;
    font-weight: 500;
  }
}

.device-apps-view__actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;

  button {
    height: 36px;
    padding: 0 12px;
    border: none;
    border-radius: 11px;
    background: $color-bg;

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

    color: $gray50;
    font-size: $font-size-14;
    font-weight: 650;
    cursor: not-allowed;
  }
}

@keyframes deviceAppsViewDown {
  from {
    height: 0;
    opacity: 0;
  }

  to {
    height: var(--radix-accordion-content-height);
    opacity: 1;
  }
}

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

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

@keyframes deviceAppsViewUp {
  from {
    height: var(--radix-accordion-content-height);
    opacity: 1;
  }

  to {
    height: 0;
    opacity: 0;
  }
}

[data-theme='dark'] {
  .device-apps-view__back,
  .device-apps-view__search,
  .device-apps-view__sort,
  .device-apps-view__summary,
  .device-apps-view__panel {
    box-shadow: none;
    outline: 1px solid rgba($gray50-rgb, 0.08);
  }

  .device-apps-view__sort:hover,
  .device-apps-view__sort[data-state='open'] {
    background: $color-surface-hover;
    color: $color-primary-hover;

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

  .device-apps-view__trigger:hover {
    background: rgba($color-surface-rgb, 0.42);
  }

  .device-apps-view__trigger[data-state='open'] {
    background: $color-surface-hover;
  }

  .device-apps-view__detail-card {
    background: rgba($color-surface-rgb, 0.58);
    box-shadow: none;
    outline: 1px solid rgba($gray50-rgb, 0.08);
  }

  .device-apps-view__stats {
    background: rgba($color-surface-rgb, 0.58);
  }
}

@include laptop-down {
  .device-apps-view__header {
    grid-template-columns: 160px minmax(0, 1fr) 160px;
    gap: 12px;
  }

  .device-apps-view__toolbar {
    gap: 12px;
  }

  .device-apps-view__summary {
    padding-inline: 12px;
    gap: 10px;
  }
}

@include tablet-down {
  .device-apps-view__header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
  }

  .device-apps-view__back,
  .device-apps-view__install {
    padding-inline: 12px;
  }

  .device-apps-view__toolbar {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .device-apps-view__search {
    flex-basis: 100%;
  }

  .device-apps-view__toolbar-right {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .device-apps-view__trigger {
    padding-inline: 16px;
  }

  .device-apps-view__app-meta {
    gap: 8px;
  }

  .device-apps-view__details {
    padding: 0 16px 16px 72px;
  }

  .device-apps-view__details-grid {
    grid-template-columns: 1fr;
  }
}
