/* 颜色变量 */
$primary-color: #007aff;
$primary-dark: #0051a8;
$success-color: #34c759;
$warning-color: #ff9500;
$error-color: #ff3b30;
$text-primary: #1d1d1f;
$text-secondary: #86868b;
$text-muted: #a1a1aa;
$background-light: #f5f5f7;
$border-color: #d2d2d7;
$white: #ffffff;

// Gray colors
$gray-50: #f9fafb;
$gray-100: #f3f4f6;
$gray-200: #e5e7eb;
$gray-300: #d1d5db;
$gray-400: #9ca3af;
$gray-500: #6b7280;
$gray-600: #4b5563;

// Green colors
$green-200: #bbf7d0;
$green-600: #16a34a;

// Red colors
$red-500: #ef4444;

.case-library-container {
  padding: 24px;
  max-width: 1440px;
  margin: 0 auto;
  
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    
    h1 {
      font-size: 28px;
      font-weight: 600;
      color: $text-primary;
      margin: 0;
    }
    
    .header-actions {
      .btn {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        border-radius: 8px;
        font-weight: 500;
        transition: all 0.2s ease;
        
        &:hover {
          transform: translateY(-1px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
      }
    }
  }
  
  .stats-panel {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    color: white;
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
    
    .stats-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 20px;
      
      .stat-card {
        background: rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 16px;
        backdrop-filter: blur(10px);
        
        h3 {
          margin: 0 0 16px 0;
          font-size: 16px;
          font-weight: 600;
        }
        
        .stat-list {
          .stat-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            
            &:last-child {
              border-bottom: none;
            }
            
            .case-name, .style-name, .designer-name {
              font-weight: 500;
            }
            
            .stat-value {
              color: rgba(255, 255, 255, 0.8);
              font-size: 14px;
            }
          }
        }
      }
    }
  }
  
  .filter-bar {
    background: white;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 32px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid $border-color;
    position: sticky;
    top: 20px;
    z-index: 100;
    transition: all 0.3s ease;
    
    .filter-group {
      display: flex;
      gap: 16px;
      margin-bottom: 16px;
      flex-wrap: wrap;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      @media (max-width: 768px) {
        flex-direction: column;
        gap: 12px;
        
        .search-box {
          min-width: unset;
          max-width: unset;
        }
        
        .filter-select {
          min-width: unset;
        }
      }
      
      .search-box {
        position: relative;
        flex: 1;
        min-width: 250px;
        max-width: 400px;
        
        .search-input {
          width: 100%;
          padding: 12px 16px 12px 40px;
          border: 1px solid $border-color;
          border-radius: 8px;
          font-size: 14px;
          transition: border-color 0.2s ease;
          
          &:focus {
            outline: none;
            border-color: $primary-color;
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
          }
        }
        
        .search-icon {
          position: absolute;
          left: 16px;
          top: 50%;
          transform: translateY(-50%);
          color: $text-secondary;
        }
      }
      
      .filter-select {
        padding: 12px 16px;
        border: 1px solid $border-color;
        border-radius: 8px;
        font-size: 14px;
        background: white;
        min-width: 140px;
        cursor: pointer;
        transition: border-color 0.2s ease;
        
        &:focus {
          outline: none;
          border-color: $primary-color;
        }
      }
    }
    
    .filter-actions {
      display: flex;
      gap: 12px;
      justify-content: flex-end;
      
      @media (max-width: 768px) {
        justify-content: stretch;
        
        .btn {
          flex: 1;
        }
      }
      
      .btn {
        padding: 10px 20px;
        border-radius: 8px;
        font-weight: 500;
        transition: all 0.2s ease;
        
        &:hover {
          transform: translateY(-1px);
        }
        
        &.btn-secondary {
          background: white;
          border: 1px solid $border-color;
          color: $text-primary;
          
          &:hover {
            background: $gray-50;
          }
        }
        
        &.btn-primary {
          background: $primary-color;
          border: 1px solid $primary-color;
          color: white;
          
          &:hover {
          background: #0051a8; // 手动计算的深色版本
        }
        }
      }
    }
  }
  
  .cases-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
    
    .case-card {
      background: white;
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
      transition: all 0.3s ease;
      border: 1px solid $border-color;
      
      &:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        
        .case-image {
          transform: scale(1.05);
        }
        
        .image-overlay {
          opacity: 1;
        }
      }
      
      .case-image-container {
        position: sticky;
        top: 20px; /* 距离顶部20px */
        z-index: 10;
        overflow: hidden;
        height: 240px;
        
        .case-image {
          width: 100%;
          height: 100%;
          object-fit: cover;
          transition: transform 0.3s ease;
          cursor: pointer;
        }
        
        .image-overlay {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background: linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.3) 0%,
            rgba(0, 0, 0, 0.1) 50%,
            rgba(0, 0, 0, 0.8) 100%
          );
          opacity: 0;
          transition: opacity 0.3s ease;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          padding: 16px;
          
          .case-badges {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
            
            .badge {
              padding: 4px 8px;
              border-radius: 4px;
              font-size: 12px;
              font-weight: 500;
              color: white;
              
              &.project-type {
                background: rgba(79, 70, 229, 0.9);
              }
              
              &.space-type {
                background: rgba(245, 158, 11, 0.9);
              }
              
              &.rendering-level {
                background: rgba(16, 185, 129, 0.9);
              }
            }
          }
          
          .action-buttons {
            display: flex;
            gap: 12px;
            justify-content: flex-end;
            
            .btn-icon {
              width: 40px;
              height: 40px;
              border-radius: 50%;
              border: none;
              background: rgba(255, 255, 255, 0.9);
              color: $text-primary;
              display: flex;
              align-items: center;
              justify-content: center;
              cursor: pointer;
              transition: all 0.2s ease;
              backdrop-filter: blur(10px);
              
              &:hover {
                background: white;
                transform: scale(1.1);
                box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
              }
              
              &.favorite-btn {
                &.active {
                  background: $red-500;
                  color: white;
                }
                
                &:hover:not(.active) {
                  color: $red-500;
                }
              }
              
              &.share-btn {
                &:hover {
                  background: $primary-color;
                  color: white;
                }
              }
            }
          }
        }
      }
      
      .case-info {
        padding: 20px;
        
        .case-header {
          display: flex;
          justify-content: space-between;
          align-items: flex-start;
          margin-bottom: 12px;
          
          .case-name {
            font-size: 18px;
            font-weight: 600;
            color: $text-primary;
            margin: 0;
            cursor: pointer;
            transition: color 0.2s ease;
            flex: 1;
            margin-right: 12px;
            
            &:hover {
              color: $primary-color;
            }
          }
          
          .info-share-btn {
            width: 32px;
            height: 32px;
            border-radius: 6px;
            border: 1px solid $border-color;
            background: white;
            color: $text-muted;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s ease;
            flex-shrink: 0;
            
            &:hover {
              background: $primary-color;
              color: white;
              border-color: $primary-color;
              transform: scale(1.05);
            }
            
            svg {
              stroke-width: 2;
            }
          }
        }
        
        .case-meta {
          display: flex;
          flex-direction: column;
          gap: 8px;
          margin-bottom: 16px;
          
          .meta-item {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 14px;
            color: $text-secondary;
            
            svg {
              color: $text-muted;
            }
            
            .team-badge {
              background: $gray-100;
              color: $text-secondary;
              padding: 2px 6px;
              border-radius: 4px;
              font-size: 12px;
              margin-left: 8px;
            }
          }
        }
        
        .case-tags {
          display: flex;
          flex-wrap: wrap;
          gap: 6px;
          margin-bottom: 16px;
          
          .tag {
            background: $gray-100;
            color: $text-secondary;
            padding: 4px 8px;
            border-radius: 16px;
            font-size: 12px;
            font-weight: 500;
          }
        }
        
        .customer-review {
          background: $gray-50;
          padding: 12px;
          border-radius: 8px;
          border-left: 4px solid $primary-color;
          margin-bottom: 16px;
          
          .review-text {
            margin: 0;
            font-size: 14px;
            color: $text-secondary;
            font-style: italic;
            line-height: 1.5;
          }
        }
        
        .internal-info {
          border-top: 1px solid $border-color;
          padding-top: 16px;
          
          .internal-badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
            margin-bottom: 8px;
            
            &.excellent {
              background: rgba(34, 197, 94, 0.1);
              color: $green-600;
              border: 1px solid $green-200;
            }
            
            &:not(.excellent) {
              background: $gray-100;
              color: $text-secondary;
            }
          }
          
          .internal-stats {
            display: flex;
            gap: 16px;
            font-size: 12px;
            color: $text-muted;
            
            span {
              display: flex;
              align-items: center;
              gap: 4px;
            }
          }
        }

        .case-actions {
          display: flex;
          gap: 8px;
          margin-top: 16px;
          padding-top: 16px;
          border-top: 1px solid $border-color;

          .btn {
            flex: 1;
            padding: 8px 16px;
            border-radius: 6px;
            font-size: 14px;
            font-weight: 500;
            text-align: center;
            transition: all 0.2s ease;
            cursor: pointer;
            border: none;

            &.btn-outline {
              background: white;
              border: 1px solid $border-color;
              color: $text-secondary;

              &:hover {
                background: $gray-50;
                border-color: $primary-color;
                color: $primary-color;
              }
            }

            &.btn-primary {
              background: $primary-color;
              color: white;

              &:hover {
                background: #0051a8;
                transform: translateY(-1px);
                box-shadow: 0 2px 8px rgba(0, 102, 204, 0.3);
              }
            }
          }
        }
      }
    }
  }
  
  .empty-state {
    text-align: center;
    padding: 80px 20px;
    color: $text-secondary;
    
    svg {
      color: $gray-300;
      margin-bottom: 16px;
    }
    
    h3 {
      font-size: 20px;
      font-weight: 600;
      margin: 0 0 8px 0;
    }
    
    p {
      margin: 0 0 24px 0;
      font-size: 16px;
    }
  }
  
  .pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 32px;
    
    .pagination-btn {
      padding: 10px 20px;
      border: 1px solid $border-color;
      border-radius: 8px;
      background: white;
      color: $text-primary;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      
      &:hover:not(:disabled) {
        background: $gray-50;
        border-color: $gray-300;
      }
      
      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }
    
    .page-info {
      color: $text-secondary;
      font-size: 14px;
    }
  }
  
  .share-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    animation: modalFadeIn 0.3s ease;
    
    .share-content {
      background: #f8f9fa;
      border-radius: 16px;
      padding: 0;
      max-width: 380px;
      width: 90%;
      box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
      overflow: hidden;
      
      .share-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px 24px 16px;
        background: white;
        border-bottom: 1px solid #e5e5ea;
        
        h3 {
          margin: 0;
          font-size: 18px;
          font-weight: 600;
          color: #000;
        }
        
        .close-btn {
          background: none;
          border: none;
          font-size: 28px;
          cursor: pointer;
          color: #8e8e93;
          padding: 0;
          width: 44px;
          height: 44px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          transition: background-color 0.2s ease;
          
          &:hover {
            background: #f1f1f1;
          }
        }
      }
      
      .share-options {
        padding: 24px;
        background: white;
        
        .qr-code {
          text-align: center;
          margin-bottom: 24px;
          padding: 20px;
          background: #f8f9fa;
          border-radius: 12px;
          
          img {
            width: 140px;
            height: 140px;
            margin-bottom: 16px;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
          }
          
          p {
            margin: 0;
            font-size: 15px;
            color: #8e8e93;
            font-weight: 500;
          }
        }
        
        .share-links {
          .share-link {
            display: flex;
            gap: 12px;
            margin-bottom: 20px;
            
            .link-input {
              flex: 1;
              padding: 14px 16px;
              border: 1px solid #c7c7cc;
              border-radius: 10px;
              font-size: 15px;
              background: white;
              color: #000;
              font-family: -apple-system, BlinkMacSystemFont, sans-serif;
              
              &:focus {
                outline: none;
                border-color: #007aff;
              }
            }
            
            .btn {
              padding: 14px 20px;
              border-radius: 10px;
              font-weight: 500;
              font-size: 15px;
              font-family: -apple-system, BlinkMacSystemFont, sans-serif;
              
              &.btn-secondary {
                background: #007aff;
                border: none;
                color: white;
                
                &:hover {
                  background: #0056d6;
                }
              }
            }
          }
          
          .social-share {
            .btn {
              display: flex;
              align-items: center;
              gap: 12px;
              width: 100%;
              justify-content: center;
              padding: 16px;
              background: #007aff;
              border: none;
              border-radius: 12px;
              color: white;
              font-weight: 500;
              font-size: 16px;
              font-family: -apple-system, BlinkMacSystemFont, sans-serif;
              transition: background-color 0.2s ease;
              
              &:hover {
                background: #0056d6;
              }
              
              svg {
                width: 20px;
                height: 20px;
              }
            }
          }
        }
      }
    }
  }
  
  @keyframes modalFadeIn {
    from {
      opacity: 0;
      backdrop-filter: blur(0px);
    }
    to {
      opacity: 1;
      backdrop-filter: blur(8px);
    }
  }
}

// 响应式设计
@media (max-width: 1024px) {
  .case-library-container {
    padding: 16px;
    
    .cases-grid {
      grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
      gap: 20px;
    }
    
    .filter-bar {
      .filter-group {
        .search-box {
          min-width: 250px;
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .case-library-container {
    .page-header {
      flex-direction: column;
      gap: 16px;
      align-items: stretch;
      
      .header-actions {
        .btn {
          width: 100%;
          justify-content: center;
        }
      }
    }
    
    .stats-panel {
      .stats-grid {
        grid-template-columns: 1fr;
      }
    }
    
    .filter-bar {
      .filter-group {
        .search-box {
          min-width: 100%;
        }
        
        .filter-select {
          min-width: 120px;
        }
      }
      
      .filter-actions {
        justify-content: stretch;
        
        .btn {
          flex: 1;
        }
      }
    }
    
    .cases-grid {
      grid-template-columns: 1fr;
    }
    
    .share-modal {
      .share-content {
        .share-options {
          grid-template-columns: 1fr;
          gap: 20px;
          
          .qr-code {
            order: 2;
          }
          
          .share-links {
            order: 1;
          }
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .case-library-container {
    padding: 12px;
    
    .filter-bar {
      padding: 16px;
      
      .filter-group {
        .filter-select {
          min-width: 100px;
          font-size: 13px;
        }
      }
    }
    
    .case-card {
      .case-image-container {
        height: 200px;
      }
      
      .case-info {
        padding: 16px;
      }
    }
  }
}