// 全局变量定义
$primary-color: #165DFF;
$primary-dark: #0d2f5e;
$secondary-color: #4E5BA6;
$success-color: #00B42A;
$warning-color: #FF7D00;
$danger-color: #F53F3F;
$text-primary: #1D2129;
$text-secondary: #4E5969;
$text-tertiary: #86909C;
$border-color: #E5E6EB;
$background-primary: #FFFFFF;
$background-secondary: #F2F3F5;
$background-tertiary: #F7F8FA;
$shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
$shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
$shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.16);
$border-radius: 12px;
$transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

// 主容器
.admin-dashboard {
  padding: 32px 0;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  min-height: 100vh;
}

// 编写按钮样式
.write-button {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, $primary-color, #7c3aed);
  border: none;
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(22, 93, 255, 0.3);
  cursor: pointer;
  transition: $transition;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  
  &:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 12px 32px rgba(22, 93, 255, 0.4);
  }
  
  &:active {
    transform: translateY(-2px) scale(1.02);
  }
  
  svg {
    width: 28px;
    height: 28px;
    fill: white;
  }
}

// 模态框样式
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: $background-primary;
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
  
  .modal-header {
    padding: 32px 32px 0;
    border-bottom: 1px solid $border-color;
    
    .modal-title {
      font-size: 24px;
      font-weight: 700;
      color: $text-primary;
      margin: 0 0 16px 0;
      background: linear-gradient(135deg, $primary-color, #7c3aed);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }
    
    .modal-subtitle {
      font-size: 16px;
      color: $text-secondary;
      margin: 0 0 24px 0;
    }
    
    .close-button {
      position: absolute;
      top: 24px;
      right: 24px;
      width: 40px;
      height: 40px;
      border: none;
      background: rgba(0, 0, 0, 0.05);
      border-radius: 50%;
      cursor: pointer;
      transition: $transition;
      display: flex;
      align-items: center;
      justify-content: center;
      
      &:hover {
        background: rgba(0, 0, 0, 0.1);
        transform: scale(1.1);
      }
      
      svg {
        width: 20px;
        height: 20px;
        fill: $text-secondary;
      }
    }
  }
  
  .modal-body {
    padding: 32px;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

  .page-title {
    font-size: 32px;
    font-weight: 700;
    color: $text-primary;
    margin: 0 0 12px 0;
    background: linear-gradient(135deg, $primary-color, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

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

// 统计卡片网格
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

// 统计卡片
.stat-card {
  background: $background-primary;
  border-radius: $border-radius;
  padding: 28px;
  box-shadow: $shadow-sm;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: $transition;
  border: 1px solid rgba(255, 255, 255, 0.8);
  position: relative;
  overflow: hidden;
  
  &.clickable {
    cursor: pointer;
    
    &:hover {
      box-shadow: $shadow-lg;
      transform: translateY(-6px);
      border-color: rgba($primary-color, 0.3);
    }
    
    &:active {
      transform: translateY(-2px);
    }
  }

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, $primary-color, $success-color);
    transform: scaleX(0);
    transition: $transition;
  }

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

  .stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    position: relative;

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: inherit;
      background: inherit;
      opacity: 0.1;
      transform: scale(1.3);
    }

    &.primary {
      background: linear-gradient(135deg, $primary-color, #4c9aff);
    }

    &.secondary {
      background: linear-gradient(135deg, $secondary-color, #6366f1);
    }

    &.success {
      background: linear-gradient(135deg, $success-color, #52c41a);
    }

    &.warning {
      background: linear-gradient(135deg, $warning-color, #ffa940);
    }

    &.danger {
      background: linear-gradient(135deg, $danger-color, #ff7875);
    }
  }

  .stat-content {
    flex: 1;

    .stat-value {
      font-size: 32px;
      font-weight: 800;
      color: $text-primary;
      margin-bottom: 6px;
      line-height: 1;
      letter-spacing: -0.02em;
    }

    .stat-label {
      font-size: 15px;
      color: $text-secondary;
      font-weight: 500;
    }
  }

  .stat-trend {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;

    &.positive {
      background: rgba(0, 180, 42, 0.1);
      color: $success-color;
    }

    &.negative {
      background: rgba(245, 63, 63, 0.1);
      color: $danger-color;
    }

    &.neutral {
      background: $background-tertiary;
      color: $text-secondary;
    }
  }
}

// 图表网格
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 32px;
  margin-bottom: 40px;
}

// 图表卡片
.chart-card {
  background: $background-primary;
  border-radius: $border-radius;
  box-shadow: $shadow-sm;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
  transition: $transition;

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

  .chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid $border-color;
    background: linear-gradient(135deg, rgba(22, 93, 255, 0.02), rgba(124, 58, 237, 0.02));

    h3 {
      font-size: 18px;
      font-weight: 700;
      color: $text-primary;
      margin: 0;
    }

    .chart-period {
      display: inline-flex;
      gap: 8px;
      .period-btn {
        padding: 6px 12px;
        border-radius: 8px;
        border: 1px solid rgba(0,0,0,0.06);
        background: #fff;
        color: #334155;
        font-size: 12px;
        &.active {
          background: #2563eb;
          color: #fff;
          border-color: #2563eb;
          box-shadow: 0 6px 14px rgba(37, 99, 235, 0.25);
        }
      }
    }
  }
  .chart-container {
    width: 100%;
    height: 320px;
  }
}

/* 抽屉样式 */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  justify-content: flex-end;
  z-index: 1000;
  .drawer-panel {
    width: min(720px, 92vw);
    height: 100%;
    background: #fff;
    border-top-left-radius: 16px;
    border-bottom-left-radius: 16px;
    box-shadow: -12px 0 30px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease;
  }
  .drawer-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    .drawer-title { font-size: 16px; font-weight: 600; color: #0f172a; }
    .drawer-close {
      border: none; background: transparent; font-size: 18px; cursor: pointer; color: #64748b;
      &:hover { color: #0f172a; }
    }
  }
  .drawer-body {
    padding: 16px 20px 24px;
    flex: 1;
    overflow: auto;
    #detailChart { width: 100%; height: 360px; }
    .drawer-toolbar {
      margin-top: 16px;
      padding: 12px 14px;
      background: #f8fafc;
      border-radius: 10px;
      border: 1px solid rgba(0,0,0,0.06);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      flex-wrap: wrap;
  
      .filters {
        display: flex;
        gap: 10px;
        align-items: center;
        flex-wrap: wrap;
  
        input[type="text"], input[type="date"], select {
          height: 34px;
          padding: 6px 10px;
          border-radius: 8px;
          border: 1px solid $border-color;
          outline: none;
          background: #fff;
          color: $text-primary;
          font-size: 13px;
          &:focus { box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.15); border-color: $primary-color; }
        }
        .date-sep { color: $text-secondary; }
        .btn.reset {
          height: 34px; padding: 6px 10px; border-radius: 8px; border: 1px solid $border-color; background: #fff; cursor: pointer; color: #0f172a; font-size: 13px;
          &:hover { background: #f1f5f9; }
        }
      }
  
      .actions {
        .btn.export {
          height: 34px; padding: 6px 12px; border-radius: 8px; border: 1px solid #2563eb; background: #2563eb; color: #fff; font-weight: 600; cursor: pointer;
          box-shadow: 0 6px 14px rgba(37,99,235,0.25);
          &:hover { filter: brightness(1.05); }
        }
      }
    }
  
    .detail-table-wrapper {
      margin-top: 12px;
      background: #fff;
      border: 1px solid rgba(0,0,0,0.06);
      border-radius: 12px;
      overflow: hidden;
  
      .detail-table {
        width: 100%;
        border-collapse: collapse;
        thead th {
          background: #f1f5f9;
          color: #0f172a;
          text-align: left;
          font-size: 13px;
          font-weight: 700;
          padding: 10px 12px;
          border-bottom: 1px solid rgba(0,0,0,0.06);
          white-space: nowrap;
        }
        tbody td {
          padding: 10px 12px;
          font-size: 13px;
          color: #334155;
          border-bottom: 1px solid rgba(0,0,0,0.04);
        }
        tbody tr:hover td { background: rgba(37,99,235,0.03); }
        .empty { text-align: center; color: $text-secondary; padding: 24px 0; }
      }
  
      .pagination {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        background: #fafafa;
        .info { font-size: 12px; color: #64748b; }
        .pager { display: inline-flex; gap: 6px; align-items: center; }
        .pager button { min-width: 30px; height: 30px; border-radius: 8px; border: 1px solid $border-color; background: #fff; font-size: 12px; cursor: pointer; }
        .pager button.num.active { background: #2563eb; color: #fff; border-color: #2563eb; box-shadow: 0 6px 14px rgba(37,99,235,0.25); }
        .pager button:disabled { opacity: 0.5; cursor: not-allowed; }
      }
    }
  }
}

@media (max-width: 768px) {
  .drawer .drawer-body {
    .drawer-toolbar { flex-direction: column; align-items: stretch; }
    .pagination { flex-direction: column; gap: 8px; align-items: flex-start; }
  }
}

@keyframes slideIn {
  from { transform: translateX(12px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

// 最近活动区域
.recent-activities {
  background: $background-primary;
  border-radius: $border-radius;
  padding: 32px;
  box-shadow: $shadow-sm;
  border: 1px solid rgba(255, 255, 255, 0.8);
  transition: $transition;
  
  &:hover {
    box-shadow: $shadow-md;
  }
  
  .activities-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid $border-color;
    
    h3 {
      font-size: 20px;
      font-weight: 700;
      color: $text-primary;
      margin: 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      &::before {
        content: '';
        width: 4px;
        height: 20px;
        background: linear-gradient(135deg, $primary-color, $success-color);
        border-radius: 2px;
      }
    }
    
    .view-all {
      font-size: 14px;
      color: $primary-color;
      text-decoration: none;
      font-weight: 600;
      padding: 8px 16px;
      border-radius: 8px;
      background: rgba(22, 93, 255, 0.1);
      transition: $transition;
      
      &:hover {
        background: rgba(22, 93, 255, 0.2);
        transform: translateY(-1px);
      }
    }
  }
  
  .activity-list {
    .activity-item {
      display: flex;
      align-items: center;
      padding: 16px 0;
      border-bottom: 1px solid rgba(229, 230, 235, 0.5);
      transition: $transition;
      
      &:last-child {
        border-bottom: none;
      }
      
      &:hover {
        background: rgba(22, 93, 255, 0.02);
        border-radius: 8px;
        margin: 0 -16px;
        padding: 16px;
      }
      
      .activity-icon {
        width: 40px;
        height: 40px;
        border-radius: 12px;
        background: linear-gradient(135deg, rgba(22, 93, 255, 0.1), rgba(124, 58, 237, 0.1));
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16px;
        
        svg {
          width: 20px;
          height: 20px;
          fill: $primary-color;
        }
      }
      
      .activity-content {
        flex: 1;
        
        .activity-text {
          font-size: 15px;
          color: $text-primary;
          margin-bottom: 6px;
          line-height: 1.4;
          
          .user {
            font-weight: 700;
            color: $primary-color;
          }
          
          .action {
            color: $text-secondary;
            font-weight: 500;
          }
          
          .target {
            color: $text-primary;
            font-weight: 600;
            background: rgba(22, 93, 255, 0.1);
            padding: 2px 6px;
            border-radius: 4px;
          }
        }
        
        .activity-time {
          font-size: 13px;
          color: $text-secondary;
          font-weight: 500;
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 1400px) {
  .admin-dashboard {
    .charts-grid {
      grid-template-columns: 1fr;
      gap: 24px;
    }
    
    .stats-grid {
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
  }
}

@media (max-width: 1024px) {
  .admin-dashboard {
    padding: 24px 0;
    
    .stats-grid {
      grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
      gap: 20px;
    }
    
    .stat-card {
      padding: 24px;
    }
  }
}

@media (max-width: 768px) {
  .admin-dashboard {
    padding: 20px 0;
  }

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

  .page-description {
    font-size: 15px !important;
  }

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

  .stat-card {
    padding: 20px;
    .stat-card.clickable {
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(0,0,0,0.08);
      }
    }
    .stat-icon {
      width: 44px;
      height: 44px;
    }
    .stat-value {
      font-size: 28px !important;
    }
  }
  // removed duplicated .stat-icon/.stat-value block here
  .chart-container {
    height: 280px !important;
  }
  .chart-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start !important;
  }
  .recent-activities {
    margin-top: 20px;
    padding: 24px;
  }
}

@media (max-width: 480px) {
  .admin-dashboard {
    padding: 16px 0;
  }

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

  .page-description {
    font-size: 14px !important;
  }

  .stats-grid {
    gap: 12px;
  }

  .stat-card {
    padding: 16px;
    
    .stat-icon {
      width: 40px;
      height: 40px;
    }
    
    .stat-value {
      font-size: 24px !important;
    }
    
    .stat-label {
      font-size: 14px;
    }
  }

  .chart-container {
    height: 240px !important;
    padding: 12px !important;
  }

  .recent-activities {
    padding: 20px;
    
    .activity-item {
      .activity-icon {
        width: 36px;
        height: 36px;
      }
      
      .activity-content {
        .activity-text {
          font-size: 14px;
        }
      }
    }
  }
}