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

.machine-page {
  max-height: none;
}

.machine-page-topbar button {
  display: flex;
  align-items: center;
  padding: 0 14px;
  width: fit-content;
  gap: 12px;
  border-radius: 12px;
    color: $color-text-muted;
    font-size: $font-size-18;
    font-weight: 500;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;

  &:hover {
    background: $gray30;
    //color: $color-text-heading;
  }

  [data-theme='dark'] &:hover {
    background: $color-surface-hover;
  }

}

.machine-page-back {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;

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

  color: $color-text-muted;
  cursor: pointer;
}

.machine-page-passport {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
  text-align: left;
}

.machine-page-passport__header {
  padding-bottom: 18px;
  border-bottom: 1px solid $gray20;

  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 24px;
}

.machine-page-passport__summary {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 24px;
}

.machine-page-icon {
  width: 120px;
  min-height: 120px;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba($color-primary-rgb, 0.16), $transparent 72%),
    $color-bg;

  display: flex;
  flex: 0 0 120px;
  align-items: center;
  justify-content: center;

  color: $blue;

  svg {
    width: 60px;
    height: 60px;
    stroke-width: 1.8;
  }
}

.machine-page-passport__title {
  min-width: 0;
  text-align: left;

  h2 {
    margin: 0;
    color: $color-text-heading;
    font-size: $font-size-30;
    font-weight: 760;
    line-height: 1.15;
  }
}

.machine-page-passport__chips {
  margin-top: 20px;

  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.machine-status-badge {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;

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

  font-size: $font-size-15;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;

  svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    stroke-width: 2;
  }
}

.machine-status-badge--compact {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: $font-size-14;
  font-weight: 650;

  svg {
    width: 16px;
    height: 16px;
    flex-basis: 16px;
  }
}

.machine-status-badge--green {
  background: $color-success-tint;
  color: $color-success;
}

.machine-status-badge--blue {
  background: $color-primary-tint;
  color: $color-primary;
}

.machine-status-badge--gray {
  background: $color-bg;
  color: $gray50;
}

.machine-status-badge--red {
  background: $color-danger-tint-strong;
  color: $red;
}

.machine-page-last-data-chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  background: $color-bg;

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

  color: $color-text-strong;
  font-size: $font-size-15;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;

  svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    color: $color-text-muted;
  }
}

.machine-page-actions {
  margin-top: 0;

  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;

  .device-history-btn,
  .machine-page-action,
  .machine-page-delete-btn {
    min-height: 44px;
    padding: 0 18px;
    border-radius: 10px;

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

    font-size: $font-size-15;
    font-weight: 700;
    line-height: 1;
    transition:
      background-color 0.2s ease,
      border-color 0.2s ease,
      color 0.2s ease,
      box-shadow 0.2s ease;
  }

  .device-history-btn {
    border: 1px solid rgba($color-primary-rgb, 0.62);
    background: transparent;
    color: $blue;

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

  .machine-page-delete-btn {
    border: 1px solid rgba($color-danger-rgb, 0.62);
    background: transparent;
    color: $red;

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

.machine-page-action {
  border: none;
  cursor: pointer;
}

.machine-page-action--link {
  border: 1px solid rgba($color-warning-rgb, 0.62);
  background: transparent;
  color: $orange;

  &:hover {
    background: $orange;
    border-color: $orange;
    color: $color-text-inverse;
    box-shadow: 0 6px 20px -6px color-mix(in srgb, var(--color-warning) 85%, transparent);
  }
}

.machine-page-passport__details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.machine-page-passport__column {
  min-width: 0;
  padding: 0 20px;
  border-radius: 10px;
  background: $color-bg;

  display: flex;
  flex-direction: column;
}

.machine-passport-field {
  min-width: 0;
  text-align: left;

  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: center;

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

  >div:last-child {
    min-width: 0;
    padding: 20px 0;
    border-bottom: 1px solid $color-surface-hover;

    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    text-align: left;
  }

  span {
    color: $color-text-muted;
    font-size: $font-size-14;
    font-weight: 600;
    line-height: 1.25;
  }

  b {
    min-width: 0;
    overflow-wrap: anywhere;
    color: $color-text-heading;
    font-size: $font-size-16;
    font-weight: 650;
    line-height: 1.35;
  }
}

.machine-passport-field__icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba($color-primary-rgb, 0.1);

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

  color: $color-text-muted;

  svg {
    width: 21px;
    height: 21px;
    stroke-width: 1.9;
  }
}

.machine-page-description-card {
  flex: 1;
  min-width: 0;
  padding: 20px 0px;
  border-radius: 8px;
  //background: $color-surface-hover;

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

  span {
    color: $color-text-muted;
    font-size: $font-size-14;
    font-weight: 650;
    line-height: 1.25;
  }

  p {
    margin: 0;
    color: $color-text-heading;
    font-size: $font-size-16;
    font-weight: 650;
    line-height: 1.45;
  }
}

.machine-page-tabs {
  align-self: flex-start;
  padding: 4px;
  border-radius: 12px;
  background: $color-surface;
  box-shadow: $shadow-card-soft;

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

  button {
    height: 36px;
    padding: 0 16px;
    border: none;
    border-radius: 9px;
    background: transparent;

    color: $color-text-muted;
    font-size: $font-size-15;
    font-weight: 700;
    cursor: pointer;
    transition:
      background-color 0.2s ease,
      color 0.2s ease,
      box-shadow 0.2s ease;

    &:hover {
      color: $color-text-heading;
      background: $color-surface-hover;
    }

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

.machine-page-overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.62fr);
  gap: 16px;
  align-items: stretch;
  text-align: left;
}

.machine-page-overview__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.machine-stats-card,
.machine-history-card,
.machine-recent-history-card,
.machine-notes-card {
  min-width: 0;
}

.machine-page-period {
  color: $color-text-muted;
  font-size: $font-size-14;
  font-weight: 600;
  white-space: nowrap;
}

.machine-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.machine-stat-item {
  min-width: 0;
  //min-height: 76px;
  padding: 12px;
  border-radius: 10px;
  background: $color-bg;

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

  svg {
    width: 28px;
    height: 28px;
    padding: 8px;
    border-radius: 10px;
    color: $blue;
    background: $blue20;
  }

  div {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  span {
    overflow: hidden;
    color: $color-text-muted;
    font-size: $font-size-13;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  b {
    color: $color-text-heading;
    font-size: $font-size-16;
    font-weight: 760;
    line-height: 1.15;
  }
}

.machine-stat-item--moving svg {
  background: $color-success-tint;
  color: $color-success;
}

.machine-stat-item--engine-on svg {
  background: $color-warning-tint;
  color: $color-warning;
}

.machine-stat-item--idle svg {
  background: $blue20;
  color: $blue;
}

.machine-stat-item--no-data svg {
  background: rgba($gray50-rgb, 0.15);
  color: $color-text-muted;
}

.machine-recent-list {
  display: flex;
  flex-direction: column;
}

.machine-recent-item {
  min-width: 0;
  padding: 10px 0;
  border-bottom: 1px solid $gray20;

  display: grid;
  grid-template-columns: minmax(145px, 0.9fr) minmax(0, 1.55fr) auto;
  align-items: center;
  gap: 16px;

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

  strong {
    color: $color-text-strong;
    font-size: $font-size-14;
    font-weight: 650;
    text-align: right;
    white-space: nowrap;
  }
}

.machine-recent-item__state {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;

  color: $color-text-strong;
  font-size: $font-size-14;
  font-weight: 600;
}

.machine-recent-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: $color-text-muted;
}

.machine-recent-dot.machines-status--green {
  background: $color-success;
}

.machine-recent-dot.machines-status--blue {
  background: $blue;
}

.machine-recent-dot.machines-status--red {
  background: $red;
}

.machine-recent-dot.machines-status--gray {
  background: $color-text-muted;
}

.machine-recent-item__period {
  min-width: 0;
  overflow: hidden;
  color: $color-text-muted;
  font-size: $font-size-14;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.machine-history-link {
  margin-top: 14px;
  padding: 0;
  border: none;
  background: transparent;

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

  color: $blue;
  font-size: $font-size-14;
  font-weight: 650;
  cursor: pointer;

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

.machine-notes-card__body {
  padding-top: 8px;
  color: $color-text-muted;
  font-size: $font-size-16;
  font-weight: 600;
}

.machine-page-empty-row {
  padding: 18px;
  border-radius: 14px;
  background: $color-bg;
  color: $color-text-muted;
  font-size: $font-size-15;
  font-weight: 600;
  text-align: center;
}

.machine-history-card {
  overflow: hidden;
}

.machine-history-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;

  th,
  td {
    padding: 14px 16px;
    border-bottom: 1px solid $gray20;
    text-align: left;
  }

  th {
    color: $color-text-muted;
    font-size: $font-size-15;
    font-weight: 550;
  }

  td {
    color: $color-text-strong;
    font-size: $font-size-15;
    font-weight: 500;
  }

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

.machine-page__grid {
  grid-template-columns: minmax(420px, 1.2fr) minmax(320px, 0.9fr) minmax(360px, 1fr);
}

.machine-page__loading {
  min-height: 220px;
  background:
    linear-gradient(90deg,
      $color-surface 0%,
      $color-surface-hover 45%,
      $color-surface 90%);
  background-size: 220% 100%;
  animation: machine-page-loading 1.2s ease-in-out infinite;
}

.machine-page__loading-stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@keyframes machine-page-loading {
  from {
    background-position: 0 0;
  }

  to {
    background-position: -220% 0;
  }
}

@include laptop-down {
  .machine-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@include tablet-down {
  .machine-page-passport__header,
  .machine-page-overview {
    grid-template-columns: minmax(0, 1fr);
  }

  .machine-page-passport__summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .machine-page-actions {
    justify-content: flex-start;
  }

  .machine-page-passport__details {
    grid-template-columns: minmax(0, 1fr);
  }

  .machine-page-passport__column {
    padding: 14px;
  }

  .machine-page-tabs {
    overflow-x: auto;
  }

  .machine-page-icon {
    width: 104px;
    min-height: 104px;
    flex-basis: 104px;
  }

  .machine-stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .machine-recent-item {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;

    strong {
      text-align: left;
    }
  }
}
