// 全局变量定义
$primary-color: #165DFF;
$secondary-color: #6B7280;
$success-color: #00B42A;
$warning-color: #FFAA00;
$error-color: #F53F3F;
$text-primary: #333333;
$text-secondary: #666666;
$text-tertiary: #999999;
$border-color: #E5E7EB;
$bg-light: #F9FAFB;
$bg-white: #FFFFFF;
$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);

// 主容器
.logs {
  padding: 24px;
  min-height: 100vh;
  background-color: $bg-light;
}

// 页面标题区域
.page-header {
  display: flex;
  flex-direction: column;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid $border-color;

  .page-title {
    font-size: 24px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 4px 0;
  }

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

// 搜索区域
.search-filter-section {
  margin-bottom: 24px;

  .search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background-color: $bg-white;
    border-radius: 8px;
    box-shadow: $shadow-sm;
    overflow: hidden;

    .search-icon {
      position: absolute;
      left: 16px;
      color: $text-tertiary;
      z-index: 1;
    }

    .search-input {
      flex: 1;
      padding: 12px 16px 12px 48px;
      border: none;
      background-color: transparent;
      font-size: 14px;
      color: $text-primary;
      outline: none;

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

    .clear-search-btn,
    .search-btn {
      padding: 12px 16px;
      color: $text-secondary;
      min-width: auto;

      &:hover {
        background-color: $bg-light;
        color: $text-primary;
      }
    }
  }
}

// 高级筛选区域
.advanced-filters {
  background-color: $bg-white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: $shadow-sm;
  margin-bottom: 24px;

  .filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;

    .filter-item {
      .filter-field {
        width: 100%;
        .mat-form-field-wrapper {
          .mat-form-field-flex {
            border-radius: 6px;
          }

          .mat-form-field-outline {
            border-radius: 6px;
          }

          .mat-form-field-infix {
            padding: 8px 0;

            .mat-input-element {
              font-size: 14px;
              color: $text-primary;
            }
          }

          .mat-form-field-label {
            font-size: 14px;
            color: $text-secondary;
          }

          .mat-form-field-suffix {
            .mat-icon {
              color: $text-tertiary;
            }
          }
        }
      }
    }
  }

  .date-range-filter {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;

    .date-filter-item {
      .date-field {
        width: 200px;
        .mat-form-field-wrapper {
          .mat-form-field-flex {
            border-radius: 6px;
          }

          .mat-form-field-outline {
            border-radius: 6px;
          }

          .mat-form-field-infix {
            padding: 8px 0;

            .mat-input-element {
              font-size: 14px;
              color: $text-primary;
            }
          }

          .mat-form-field-label {
            font-size: 14px;
            color: $text-secondary;
          }
        }
      }
    }
  }

  .filter-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;

    .clear-btn,
    .expand-btn {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 8px 16px;
      font-size: 14px;
      color: $text-secondary;
      border: 1px solid $border-color;
      border-radius: 6px;
      background-color: $bg-white;
      transition: all 0.2s ease;

      &:hover {
        background-color: $bg-light;
        border-color: $text-tertiary;
        color: $text-primary;
      }
    }
  }
}

// 操作按钮区域
.log-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;

  .logs-summary {
    font-size: 14px;
    color: $text-secondary;

    .highlight {
      font-weight: 600;
      color: $primary-color;
    }
  }

  .action-buttons {
    display: flex;
    gap: 12px;

    .export-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 10px 20px;
      font-size: 14px;
      font-weight: 500;
      background-color: $primary-color;
      color: $bg-white;
      border-radius: 6px;
      transition: all 0.2s ease;
      box-shadow: $shadow-sm;

      &:hover:not(:disabled) {
        background-color: #0E4BD8;
        box-shadow: $shadow-md;
        transform: translateY(-1px);
      }

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        transform: none;
        box-shadow: none;
      }
    }
  }
}

// 日志表格容器
.logs-table-container {
  background-color: $bg-white;
  border-radius: 12px;
  box-shadow: $shadow-sm;
  overflow: hidden;
  margin-bottom: 24px;

  .logs-table {
    width: 100%;
    border-collapse: collapse;

    .table-header {
      background-color: $bg-light;
      font-weight: 600;
      color: $text-secondary;
      font-size: 13px;
      text-align: left;
      padding: 14px 16px;
      border-bottom: 1px solid $border-color;
      cursor: pointer;
      transition: background-color 0.2s ease;

      &:hover {
        background-color: #F3F4F6;
      }

      .header-content {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .sort-icon {
        opacity: 0.5;
      }
    }

    .table-cell {
      padding: 12px 16px;
      border-bottom: 1px solid $border-color;
      font-size: 13px;
      color: $text-primary;
      vertical-align: middle;

      &.details-cell {
        max-width: 300px;

        .details-content {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }

      .status-badge {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 4px 12px;
        border-radius: 16px;
        font-size: 12px;
        font-weight: 500;
        color: $bg-white;
        text-align: center;
        white-space: nowrap;

        .status-icon {
          font-size: 14px;
        }
      }

      .user-info {
        .user-name {
          font-weight: 500;
        }
      }

      .action-badge,
      .resource-badge {
        display: inline-block;
        padding: 4px 12px;
        border-radius: 16px;
        font-size: 12px;
        font-weight: 500;
        background-color: #E6F0FF;
        color: $primary-color;
        white-space: nowrap;
      }

      .ip-address {
        font-family: 'Courier New', monospace;
        color: $text-secondary;
      }
    }

    tr:last-child .table-cell {
      border-bottom: none;
    }

    tr:hover .table-cell {
      background-color: $bg-light;
    }
  }

  // 无数据状态
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;

    svg {
      margin-bottom: 16px;
      opacity: 0.5;
    }

    p {
      font-size: 16px;
      color: $text-tertiary;
      margin-bottom: 24px;
    }

    button {
      border-radius: 8px;
      padding: 8px 24px;
      font-size: 14px;
      font-weight: 500;
    }
  }
}

// 分页控件
.pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: $bg-white;
  border-radius: 12px;
  box-shadow: $shadow-sm;

  .pagination-info {
    font-size: 14px;
    color: $text-tertiary;
  }

  .pagination-buttons {
    display: flex;
    align-items: center;
    gap: 8px;

    button {
      padding: 6px 12px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 500;
      transition: all 0.2s ease;
      min-width: auto;

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }

      &.active {
        background-color: $primary-color;
        color: $bg-white;
      }
    }

    .page-numbers {
      display: flex;
      gap: 4px;
    }
  }
}

// 日志统计卡片
.log-stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 32px;

  .stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background-color: $bg-white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: $shadow-sm;
    transition: all 0.2s ease;

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

    .stat-icon {
      width: 48px;
      height: 48px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: $bg-white;

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

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

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

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

    .stat-content {
      flex: 1;

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

      .stat-label {
        font-size: 14px;
        color: $text-tertiary;
      }
    }
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .logs-table {
    .table-header,
    .table-cell {
      padding: 12px;
    }
  }

  .date-range-filter {
    flex-direction: column;
    gap: 16px !important;

    .date-field {
      width: 100% !important;
    }
  }
}

@media (max-width: 992px) {
  .logs {
    padding: 16px;
  }

  .filter-grid {
    grid-template-columns: 1fr !important;
  }

  .logs-table-container {
    overflow-x: auto;
  }

  .pagination-controls {
    flex-direction: column;
    gap: 16px;

    .pagination-buttons {
      flex-wrap: wrap;
      justify-content: center;
    }
  }

  .log-stats-cards {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (max-width: 768px) {
  .advanced-filters {
    padding: 16px;
  }

  .log-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .action-buttons {
    justify-content: center;
  }

  .stat-card {
    padding: 20px;

    .stat-icon {
      width: 40px;
      height: 40px;
    }

    .stat-value {
      font-size: 24px;
    }
  }
}

@media (max-width: 480px) {
  .logs {
    padding: 12px;
  }

  .page-title {
    font-size: 20px !important;
  }

  .log-stats-cards {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

// 滚动条样式
.logs-table-container,
.advanced-filters {
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: $bg-light;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: $border-color;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: $text-tertiary;
  }
}