// 自定义主题
$primary-color: #1e40af; // 深蓝主色，传递可靠感
$primary-light: #3b82f6; // 浅蓝色，用于悬停效果
$secondary-color: #0d9488; // 薄荷绿，作为强调色
$success-color: #10b981; // 成功色
$warning-color: #f59e0b; // 警告色
$error-color: #ef4444; // 错误色
$info-color: #3b82f6; // 信息色
$text-primary: #1f2937; // 主要文本色
$text-secondary: #4b5563; // 次要文本色
$text-tertiary: #9ca3af; // 辅助文本色
$bg-primary: #ffffff; // 主背景色
$bg-secondary: #f9fafb; // 次要背景色
$bg-tertiary: #f3f4f6; // 辅助背景色
$border-color: #e5e7eb; // 边框色
$shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
$shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
$shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
$border-radius: 8px;
$transition: all 0.2s ease;

// 主容器样式
.assets-stats-container {
  padding: 24px;
  min-height: 100vh;
  background-color: $bg-secondary;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

// 页面标题
.page-header {
  margin-bottom: 32px;
  text-align: center;

  h1 {
    font-size: 32px;
    font-weight: 700;
    color: $text-primary;
    margin: 0 0 8px 0;
    letter-spacing: -0.5px;
  }

  .page-description {
    font-size: 16px;
    color: $text-secondary;
    margin: 0;
  }
}

// 资产分类筛选栏
.filter-bar {
  background-color: $bg-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;
  padding: 20px;
  margin-bottom: 24px;
  transition: $transition;

  &:hover {
    box-shadow: $shadow-md;
  }

  .search-container {
    position: relative;
    max-width: 400px;
    margin: 0 auto 20px;

    .search-icon {
      position: absolute;
      left: 12px;
      top: 50%;
      transform: translateY(-50%);
      color: $text-tertiary;
      z-index: 1;
    }

    .search-input {
      width: 100%;
      padding: 12px 12px 12px 40px;
      border: 1px solid $border-color;
      border-radius: $border-radius;
      font-size: 14px;
      color: $text-primary;
      background-color: $bg-primary;
      transition: $transition;
      box-sizing: border-box;

      &:focus {
        outline: none;
        border-color: $primary-color;
        box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
        transform: scale(1.01);
      }

      &::placeholder {
        color: $text-tertiary;
      }
    }

    .clear-search {
      position: absolute;
      right: 8px;
      top: 50%;
      transform: translateY(-50%);
      color: $text-tertiary;
      padding: 4px;
      transition: $transition;

      &:hover {
        color: $text-primary;
        background-color: $bg-tertiary;
        border-radius: 50%;
      }
    }
  }

  .filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    align-items: end;

    .filter-group {
      display: flex;
      flex-direction: column;
      gap: 6px;
      min-width: 150px;

      label {
        font-size: 12px;
        font-weight: 500;
        color: $text-secondary;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }

      .filter-select {
        padding: 10px 12px;
        border: 1px solid $border-color;
        border-radius: $border-radius;
        font-size: 14px;
        color: $text-primary;
        background-color: $bg-primary;
        transition: $transition;
        cursor: pointer;
        min-width: 150px;

        &:focus {
          outline: none;
          border-color: $primary-color;
          box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
        }

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

    .reset-btn {
      padding: 8px 16px;
      border-radius: $border-radius;
      font-size: 14px;
      font-weight: 500;
      color: $primary-color;
      transition: $transition;

      &:hover {
        background-color: color-mix(in srgb, $primary-color 5%, transparent);
      }
    }

    .export-btn {
      padding: 8px 16px;
      border-radius: $border-radius;
      font-size: 14px;
      font-weight: 500;
      background-color: $primary-color;
      color: white;
      transition: $transition;

      &:hover {
        background-color: $primary-light;
        transform: translateY(-1px);
        box-shadow: $shadow-md;
      }

      &:active {
        transform: scale(0.98);
        box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.1);
      }
    }
  }
}

// 视图切换和统计卡片
.view-stats-section {
  margin-bottom: 24px;
}

.view-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 12px 20px;
  background-color: $bg-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;

  .view-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: $border-radius;
    font-size: 14px;
    font-weight: 500;
    color: $text-secondary;
    transition: $transition;

    &.active {
      background-color: $primary-color;
      color: white;
      box-shadow: $shadow-sm;
    }

    &:not(.active):hover {
      background-color: $bg-tertiary;
      color: $text-primary;
    }
  }

  .asset-count {
    margin-left: auto;
    font-size: 14px;
    color: $text-secondary;
    font-weight: 500;
  }
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;

  .stat-card {
    background-color: $bg-primary;
    border-radius: $border-radius;
    padding: 20px;
    box-shadow: $shadow-sm;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: $transition;
    position: relative;
    overflow: hidden;

    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 4px;
      height: 100%;
      background-color: $primary-color;
    }

    &:hover {
      transform: translateY(-4px);
      box-shadow: $shadow-md;
    }

    .stat-icon {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background-color: color-mix(in srgb, $primary-color 10%, transparent);
      display: flex;
      align-items: center;
      justify-content: center;
      color: $primary-color;
      flex-shrink: 0;
    }

    .stat-content {
      flex: 1;

      .stat-value {
        font-size: 24px;
        font-weight: 700;
        color: $text-primary;
        margin-bottom: 4px;
        line-height: 1;
      }

      .stat-label {
        font-size: 12px;
        color: $text-secondary;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }

      .stat-percentage {
        font-size: 12px;
        color: $text-tertiary;
        margin-top: 4px;
      }
    }

    &.occupied {
      &::before {
        background-color: $primary-color;
      }

      .stat-icon {
        background-color: color-mix(in srgb, $primary-color 10%, transparent);
        color: $primary-color;
      }
    }

    &.idle {
      &::before {
        background-color: $secondary-color;
      }

      .stat-icon {
        background-color: color-mix(in srgb, $secondary-color 10%, transparent);
        color: $secondary-color;
      }
    }

    &.faulty {
      &::before {
        background-color: $error-color;
      }

      .stat-icon {
        background-color: color-mix(in srgb, $error-color 10%, transparent);
        color: $error-color;
      }
    }

    &.repairing {
      &::before {
        background-color: $warning-color;
      }

      .stat-icon {
        background-color: color-mix(in srgb, $warning-color 10%, transparent);
        color: $warning-color;
      }
    }

    &.value {
      &::before {
        background-color: $success-color;
      }

      .stat-icon {
        background-color: color-mix(in srgb, $success-color 10%, transparent);
        color: $success-color;
      }
    }
  }
}

// 资产列表/网格视图
.assets-view {
  margin-bottom: 32px;
}

// 网格视图
.assets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.asset-card {
  background-color: $bg-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;
  padding: 20px;
  transition: $transition;
  position: relative;
  overflow: hidden;

  &:hover {
    transform: translateY(-4px);
    box-shadow: $shadow-md;
  }

  &.faulty {
    animation: faulty-pulse 2s infinite;
  }

  .asset-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;

    .asset-type-icon {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      background-color: $bg-tertiary;
      color: $primary-color;
      transition: $transition;

      &.电脑 {
        background-color: color-mix(in srgb, $primary-color 10%, $bg-tertiary);
        color: $primary-color;
      }

      &.外设 {
        background-color: color-mix(in srgb, $secondary-color 10%, $bg-tertiary);
        color: $secondary-color;
      }

      &.软件账号 {
        background-color: color-mix(in srgb, $info-color 10%, $bg-tertiary);
        color: $info-color;
      }

      &.域名 {
        background-color: color-mix(in srgb, $warning-color 10%, $bg-tertiary);
        color: $warning-color;
      }

      &.其他 {
        background-color: color-mix(in srgb, $text-secondary 10%, $bg-tertiary);
        color: $text-secondary;
      }
    }

    .asset-status {
      padding: 6px 12px;
      border-radius: 16px;
      font-size: 12px;
      font-weight: 500;
      text-align: center;
      min-width: 60px;
      transition: $transition;

      &.status-idle {
        background-color: color-mix(in srgb, $secondary-color 15%, transparent);
        color: $secondary-color;
      }

      &.status-occupied {
        background-color: color-mix(in srgb, $primary-color 15%, transparent);
        color: $primary-color;
      }

      &.status-faulty {
        background-color: color-mix(in srgb, $error-color 15%, transparent);
        color: $error-color;
      }

      &.status-repairing {
        background-color: color-mix(in srgb, $warning-color 15%, transparent);
        color: $warning-color;
      }
    }
  }

  .asset-content {
    margin-bottom: 16px;

    .asset-name {
      font-size: 18px;
      font-weight: 600;
      color: $text-primary;
      margin: 0 0 12px 0;
      line-height: 1.3;
    }

    .asset-info {
      display: flex;
      flex-direction: column;
      gap: 8px;

      .info-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid $border-color;

        .info-label {
          font-size: 12px;
          color: $text-tertiary;
          font-weight: 500;
        }

        .info-value {
          font-size: 12px;
          color: $text-secondary;
          font-weight: 500;
        }
      }

      .info-item.faulty-notice {
        background-color: color-mix(in srgb, $error-color 5%, transparent);
        border-radius: 6px;
        padding: 8px 12px;
        border: none;

        .info-value {
          color: $error-color;
        }
      }
    }
  }

  .asset-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid $border-color;

    .action-btn {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      color: $text-secondary;
      background-color: $bg-tertiary;
      transition: $transition;

      &:hover {
        background-color: $border-color;
        color: $text-primary;
        transform: scale(1.1);
      }

      &.primary {
        color: $primary-color;
        background-color: color-mix(in srgb, $primary-color 10%, $bg-tertiary);

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

      &.warning {
        color: $error-color;
        background-color: color-mix(in srgb, $error-color 10%, $bg-tertiary);

        &:hover {
          background-color: $error-color;
          color: white;
        }
      }
    }
  }
}

// 列表视图
.assets-list {
  background-color: $bg-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;
  overflow: hidden;
}

.assets-table {
  width: 100%;
  min-width: 800px;

  .mat-header-row {
    background-color: $bg-tertiary;

    th {
      font-size: 12px;
      font-weight: 600;
      color: $text-secondary;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      padding: 12px 16px;
      text-align: left;
      border-bottom: 1px solid $border-color;
    }
  }

  .mat-row {
    transition: $transition;

    &:hover {
      background-color: $bg-tertiary;
      transform: translateX(2px);
    }

    td {
      padding: 12px 16px;
      border-bottom: 1px solid $border-color;
      font-size: 14px;
      color: $text-primary;
    }

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

  .asset-name-list {
    display: flex;
    align-items: center;
    gap: 8px;

    .asset-type-icon-small {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      background-color: $bg-tertiary;
      color: $primary-color;

      &.电脑 {
        background-color: color-mix(in srgb, $primary-color 10%, $bg-tertiary);
        color: $primary-color;
      }

      &.外设 {
        background-color: color-mix(in srgb, $secondary-color 10%, $bg-tertiary);
        color: $secondary-color;
      }

      &.软件账号 {
        background-color: color-mix(in srgb, $info-color 10%, $bg-tertiary);
        color: $info-color;
      }

      &.域名 {
        background-color: color-mix(in srgb, $warning-color 10%, $bg-tertiary);
        color: $warning-color;
      }

      &.其他 {
        background-color: color-mix(in srgb, $text-secondary 10%, $bg-tertiary);
        color: $text-secondary;
      }
    }
  }

  .status-badge {
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    display: inline-block;
    transition: $transition;

    &.status-idle {
      background-color: color-mix(in srgb, $secondary-color 15%, transparent);
      color: $secondary-color;
    }

    &.status-occupied {
      background-color: color-mix(in srgb, $primary-color 15%, transparent);
      color: $primary-color;
    }

    &.status-faulty {
      background-color: color-mix(in srgb, $error-color 15%, transparent);
      color: $error-color;
    }

    &.status-repairing {
      background-color: color-mix(in srgb, $warning-color 15%, transparent);
      color: $warning-color;
    }
  }

  .actions-column {
    text-align: right;
  }

  .action-buttons-list {
    display: flex;
    justify-content: flex-end;
    gap: 4px;

    .action-btn {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      color: $text-secondary;
      background-color: $bg-tertiary;
      transition: $transition;

      &:hover {
        background-color: $border-color;
        color: $text-primary;
        transform: scale(1.1);
      }

      &.primary {
        color: $primary-color;
        background-color: color-mix(in srgb, $primary-color 10%, $bg-tertiary);

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

      &.warning {
        color: $error-color;
        background-color: color-mix(in srgb, $error-color 10%, $bg-tertiary);

        &:hover {
          background-color: $error-color;
          color: white;
        }
      }
    }
  }

  .no-data {
    text-align: center;
    padding: 60px 20px;

    .empty-state {
      display: flex;
      flex-direction: column;
      align-items: center;

      mat-icon {
        font-size: 48px;
        color: $text-tertiary;
        margin-bottom: 16px;
      }

      p {
        color: $text-secondary;
        font-size: 16px;
        margin: 0;
      }
    }
  }
}

// 统计图表区
.stats-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.stats-card {
  background-color: $bg-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;
  padding: 24px;
  transition: $transition;

  &:hover {
    transform: translateY(-2px);
    box-shadow: $shadow-md;
  }

  .card-header {
    margin-bottom: 24px;

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

  .chart-content {
    min-height: 200px;
  }

  // 类型统计
  .type-stats {
    display: flex;
    flex-direction: column;
    gap: 16px;

    .type-stat-item {
      display: flex;
      align-items: center;
      gap: 12px;

      .type-info {
        flex: 0 0 120px;

        .type-name {
          font-size: 14px;
          font-weight: 500;
          color: $text-primary;
          display: block;
        }

        .type-count {
          font-size: 12px;
          color: $text-tertiary;
          display: block;
          margin-top: 2px;
        }
      }

      .progress-bar {
        flex: 1;
        height: 12px;
        background-color: $bg-tertiary;
        border-radius: 6px;
        overflow: hidden;
        position: relative;

        .progress-fill {
          height: 100%;
          background-color: $primary-color;
          border-radius: 6px;
          transition: width 0.8s ease-out;
          position: relative;
          overflow: hidden;

          &::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
            animation: progressAnimation 1.5s infinite;
          }
        }
      }

      .type-value {
        font-size: 14px;
        font-weight: 600;
        color: $text-primary;
        min-width: 100px;
        text-align: right;
      }
    }
  }

  // 部门统计
  .department-stats {
    display: flex;
    flex-direction: column;
    gap: 16px;

    .department-stat-item {
      display: flex;
      align-items: center;
      gap: 12px;

      .department-info {
        flex: 0 0 150px;

        .department-name {
          font-size: 14px;
          font-weight: 500;
          color: $text-primary;
          display: block;
        }

        .department-count {
          font-size: 12px;
          color: $text-tertiary;
          display: block;
          margin-top: 2px;
        }
      }

      .progress-bar {
        flex: 1;
        height: 12px;
        background-color: $bg-tertiary;
        border-radius: 6px;
        overflow: hidden;
        position: relative;

        .progress-fill {
          height: 100%;
          background-color: $secondary-color;
          border-radius: 6px;
          transition: width 0.8s ease-out;
          position: relative;
          overflow: hidden;

          &::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
            animation: progressAnimation 1.5s infinite;
          }
        }
      }

      .department-value {
        font-size: 14px;
        font-weight: 600;
        color: $text-primary;
        min-width: 100px;
        text-align: right;
      }
    }
  }

  // 使用时长统计
  .usage-stats {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    height: 200px;
    padding-top: 20px;

    .usage-stat-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;

      .usage-info {
        text-align: center;

        .usage-type {
          font-size: 12px;
          color: $text-secondary;
          font-weight: 500;
        }
      }

      .bar-container {
        position: relative;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: flex-end;
        justify-content: center;
      }

      .usage-bar {
        width: 40px;
        background-color: $primary-color;
        border-radius: 4px 4px 0 0;
        position: relative;
        overflow: hidden;
        transition: height 1s ease-out;
        cursor: pointer;

        &::after {
          content: '';
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent);
        }

        &:hover {
          background-color: $primary-light;
          transform: scaleY(1.02);
        }

        .usage-value {
          position: absolute;
          top: -24px;
          left: 50%;
          transform: translateX(-50%);
          font-size: 12px;
          font-weight: 600;
          color: $text-primary;
        }
      }
    }
  }
}

// 动画定义
@keyframes faulty-pulse {
  0%, 100% {
    box-shadow: $shadow-sm, 0 0 0 0 rgba(239, 68, 68, 0);
  }
  50% {
    box-shadow: $shadow-md, 0 0 0 4px rgba(239, 68, 68, 0.3);
  }
}

@keyframes progressAnimation {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .assets-stats-container {
    padding: 16px;
  }

  .stats-section {
    grid-template-columns: 1fr;
  }

  .assets-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
}

@media (max-width: 768px) {
  .assets-stats-container {
    padding: 12px;
  }

  .page-header {
    margin-bottom: 20px;

    h1 {
      font-size: 24px;
    }
  }

  .filter-bar {
    padding: 16px;
  }

  .filter-controls {
    flex-direction: column;
    align-items: stretch;

    .filter-group {
      min-width: auto;
    }
  }

  .view-toggle {
    flex-wrap: wrap;
    justify-content: center;

    .asset-count {
      margin-left: 0;
      width: 100%;
      text-align: center;
    }
  }

  .stats-cards {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .asset-card {
    padding: 16px;

    .asset-header {
      flex-direction: column;
      align-items: flex-start;
      gap: 12px;
    }

    .asset-actions {
      justify-content: center;
    }
  }

  .assets-list {
    overflow-x: auto;
  }

  .stats-section {
    gap: 16px;
  }

  .stats-card {
    padding: 16px;
  }

  .usage-stats {
    height: 150px;
    gap: 8px;
  }

  .usage-bar {
    width: 24px;
  }
}

@media (max-width: 480px) {
  .stats-cards {
    grid-template-columns: 1fr 1fr;
  }

  .assets-grid {
    grid-template-columns: 1fr;
  }
}