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

.map-page {
  display: flex;
  position: relative;
  z-index: 99;
  flex: 1;
  min-height: 0;
  height: 100%;
  gap: 12px;
  overflow: hidden;
  padding: 20px 20px 36px 20px;
}

.map-page__sidebar {
  width: 320px;
  flex: 0 0 320px;
  min-height: 0;
}

.map-page__panel {
  height: 100%;
  border-radius: 20px;
  background: $color-surface;
  padding: 18px;

  display: flex;
  flex-direction: column;
  min-height: 0;

  h2 {
    margin: 0 0 14px;
    color: $color-text-strong;
    font-size: $font-size-20;
    font-weight: 600;
  }
}

.map-page__state {
  margin: 0;
  color: $gray50;
  font-size: $font-size-15;
}

.map-page__state--error {
  color: $red;
}

.map-page__count {
  margin: 0 0 14px;
  color: $gray50;
  font-size: $font-size-15;

  b {
    color: $color-text-strong;
  }
}

.map-page__list {
  display: flex;
  flex-direction: column;
  gap: 8px;

  overflow: auto;
  min-height: 0;

  scrollbar-width: thin;
  scrollbar-color: rgba($color-primary-rgb, 0.45) $transparent;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: $transparent;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba($color-primary-rgb, 0.35);
    border-radius: 999px;
  }
}

.map-device-link {
  padding: 12px;
  border-radius: 14px;
  background: $color-bg;

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

  text-decoration: none;
  transition: 0.2s ease;

  span {
    color: $color-text-strong;
    font-size: $font-size-15;
    font-weight: 600;
  }

  small {
    color: $gray50;
    font-size: $font-size-13;
  }

  &:hover {
    background: $gray20;

    span {
      color: $blue;
    }
  }
}

.map-page__map {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  background: $color-surface;
}

.map-page__map:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  background: $color-surface;
}

.map-page__leaflet {
  width: 100%;
  height: 100%;
}

.map-page__load-state {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 600;

  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: $color-surface-glass;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba($color-shadow-rgb, 0.16);

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

  color: $color-text-heading;
  font-size: $font-size-14;
  font-weight: 650;

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

.device-map-marker {
  background: $transparent;
  border: none;
}

.device-map-marker__pin {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba($color-primary-rgb, 0.18);

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

.device-map-marker__inner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: $blue;
  border: 3px solid $color-surface;
  box-shadow: 0 8px 18px rgba($color-primary-rgb, 0.35);
}

.device-map-marker.is-online {
  .device-map-marker__pin {
    background: rgba($color-success-rgb, 0.18);
  }

  .device-map-marker__inner {
    background: $green;
    box-shadow: 0 8px 18px rgba($color-success-rgb, 0.35);
  }
}

.device-map-marker.is-offline {
  .device-map-marker__pin {
    background: rgba($gray50-rgb, 0.18);
  }

  .device-map-marker__inner {
    background: $gray50;
    box-shadow: 0 8px 18px rgba($gray50-rgb, 0.28);
  }
}

.device-map-marker.is-lost {
  .device-map-marker__pin {
    background: rgba($color-danger-rgb, 0.16);
  }

  .device-map-marker__inner {
    background: $red;
    box-shadow: 0 8px 18px rgba($color-danger-rgb, 0.28);
  }
}

.leaflet-tooltip.map-marker-label {
  padding: 6px 9px;
  border: none;
  border-radius: 10px;
  background: $color-surface-glass;
  color: $color-text-heading;
  font-size: $font-size-12;
  font-weight: 650;
  line-height: 1.2;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba($color-shadow-rgb, 0.16);
}

.leaflet-tooltip-right.map-marker-label::before {
  border-right-color: $color-surface-glass;
}

.leaflet-tooltip-left.map-marker-label::before {
  border-left-color: $color-surface-glass;
}

.map-marker-label.is-online {
  color: $green;
}

.map-marker-label.is-offline {
  color: $gray50;
}

.map-marker-label.is-lost {
  color: $red;
}

.map-popup {
  min-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-popup__header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.map-popup__title {
  display: inline-block;

  color: $blue !important;
  font-size: $font-size-15;
  font-weight: 700;
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

.map-popup__status {
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;

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

  color: $color-text-heading;
  font-size: $font-size-11;
  font-weight: 700;
  text-transform: uppercase;

  &::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
  }

  &.is-online {
    background: rgba($color-success-rgb, 0.14);
    color: $green;
  }

  &.is-offline {
    background: $color-bg;
    color: $gray50;
  }

  &.is-lost {
    background: rgba($color-danger-rgb, 0.14);
    color: $red;
  }
}

.map-popup__row {
  display: flex;
  flex-direction: column;
  gap: 3px;

  span {
    color: $color-text-muted;
    font-size: $font-size-12;
  }

  b {
    color: $color-text-strong;
    font-size: $font-size-13;
    font-weight: 600;
  }
}

.map-popup__coords {
  padding-top: 2px;
  color: $color-text-muted;
  font-size: $font-size-12;
}

.map-selection-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 600;

  width: min(340px, calc(100% - 24px));

  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;

  pointer-events: none;

  > * {
    pointer-events: auto;
  }

  .map-track-filter {
    position: static;
    z-index: auto;
  }
}

.device-map-info-card {
  position: absolute;
  left: 12px;
  top: 70px;
  z-index: 430;

  width: min(180px, calc(100% - 24px));
  padding: 14px;
  border: 1px solid rgba($color-border-rgb, 0.72);
  border-radius: 16px;
  background: rgba($color-surface-rgb, 0.94);
  backdrop-filter: blur(14px);
  box-shadow: $shadow-popover;
  &--map-page{
    top: 120px !important;
  }
}


.device-map-info-card__close {
  position: absolute;
  top: 8px;
  right: 8px;

  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: $color-surface-muted;

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

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

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

.device-map-info-card__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 28px;
  margin-bottom: 12px;
  line-height: 1;
  text-align: left;

  b,
  span,
  .device-map-info-card__title {
    display: block;
  }

  b,
  .device-map-info-card__title {
    overflow: hidden;
    color: $color-text-heading;
    font-size: $font-size-15;
    font-weight: 600;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;

    &:hover {
      color: $blue;
    }
  }

  span {
    margin-top: 3px;
    overflow: hidden;
    color: $color-text-muted;
    font-size: $font-size-12;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.device-map-info-card__rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-map-info-card__row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  justify-content: flex-start;
  gap: 8px;

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

  svg {
    color: $color-primary;
  }

  span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
  }
}

.device-map-info-card__status {
  grid-column: 1 / -1;
  min-height: 22px;
  width: fit-content;
  padding: 0 8px;
  border-radius: 999px;

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

  color: $color-text-heading;
  font-size: $font-size-11;
  font-weight: 700;
  text-transform: uppercase;

  &::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
  }

  &.is-online {
    background: rgba($color-success-rgb, 0.14);
    color: $green;
  }

  &.is-offline {
    background: $color-bg;
    color: $gray50;
  }

  &.is-lost {
    background: rgba($color-danger-rgb, 0.14);
    color: $red;
  }
}

.map-track-filter {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 600;
  border-radius: 24px;

  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;

  pointer-events: none;

  > * {
    pointer-events: auto;
  }
}

.map-track-filter__reset {
  height: 36px;
  padding: 0 14px;

  border: none;
  border-radius: 999px;
  background: $color-surface-glass;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba($color-shadow-rgb, 0.16);

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

  color: $color-text-heading;
  font-size: $font-size-14;
  font-weight: 650;

  cursor: pointer;
  transition: 0.2s ease;

  svg {
    color: $blue;
  }

  &:hover {
    color: $blue;
    box-shadow:
      0 14px 32px rgba($color-shadow-rgb, 0.18),
      inset 0 0 0 1px rgba($color-primary-rgb, 0.14);
  }
}

.map-track-filter__state {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: $color-surface-glass;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba($color-shadow-rgb, 0.16);

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

  color: $color-text-heading;
  font-size: $font-size-13;
  font-weight: 650;

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

@include laptop-down {
  .map-page__sidebar {
    width: 280px;
    flex-basis: 280px;
  }

  .map-page__panel {
    padding: 16px;
  }

  .map-device-link {
    padding: 10px;
  }
}

@include tablet-down {
  .map-page {
    gap: 10px;
  }

  .map-page__sidebar {
    width: 260px;
    flex-basis: 260px;
  }

  .map-selection-panel,
  .map-track-filter {
    max-width: calc(100% - 24px);
  }

  .map-selection-panel > *,
  .map-track-filter > * {
    max-width: 100%;
  }
}
