.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 20px;
}

.modal-container {
  background: white;
  border-radius: 12px;
  max-width: 1200px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-shrink: 0;

  .header-left {
    flex: 1;
    min-width: 0;

    .modal-title {
      font-size: 24px;
      font-weight: 600;
      color: #1f2937;
      margin: 0 0 12px 0;
      display: flex;
      align-items: center;
      gap: 8px;

      .title-icon {
        width: 28px;
        height: 28px;
        color: #3b82f6;
      }
    }

    .file-stats {
      display: flex;
      gap: 16px;
      flex-wrap: wrap;

      .stat-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-width: 50px;

        .stat-number {
          font-size: 18px;
          font-weight: 600;
          color: #1f2937;
          line-height: 1;
        }

        .stat-label {
          font-size: 12px;
          color: #6b7280;
          margin-top: 2px;
        }
      }
    }
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;

    .view-toggle {
      display: flex;
      border: 1px solid #e5e7eb;
      border-radius: 6px;
      overflow: hidden;

      .toggle-btn {
        background: white;
        border: none;
        padding: 8px 12px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        color: #6b7280;

        svg {
          width: 18px;
          height: 18px;
        }

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

        &.active {
          background-color: #3b82f6;
          color: white;
        }

        &:not(:last-child) {
          border-right: 1px solid #e5e7eb;
        }
      }
    }

    .search-box {
      position: relative;
      display: flex;
      align-items: center;

      .search-icon {
        position: absolute;
        left: 12px;
        width: 18px;
        height: 18px;
        color: #6b7280;
      }

      .search-input {
        padding: 8px 12px 8px 36px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        font-size: 14px;
        width: 200px;
        outline: none;
        transition: border-color 0.2s ease;

        &:focus {
          border-color: #3b82f6;
          box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }
      }
    }

    .filter-select {
      padding: 8px 12px;
      border: 1px solid #e5e7eb;
      border-radius: 6px;
      font-size: 14px;
      outline: none;
      cursor: pointer;
      transition: border-color 0.2s ease;

      &:focus {
        border-color: #3b82f6;
      }
    }

    .close-btn {
      background: none;
      border: none;
      padding: 8px;
      border-radius: 6px;
      cursor: pointer;
      color: #6b7280;
      transition: all 0.2s ease;
      display: flex;
      align-items: center;
      justify-content: center;

      svg {
        width: 20px;
        height: 20px;
      }

      &:hover {
        background-color: #f3f4f6;
        color: #374151;
      }
    }
  }
}

.modal-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-height: 0;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #6b7280;

  .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
  }

  p {
    margin: 0;
    font-size: 16px;
  }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;

  .empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    opacity: 0.3;
  }

  h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #374151;
  }

  p {
    margin: 0;
    font-size: 14px;
  }
}

.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.file-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    border-color: #3b82f6;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }

  .file-preview {
    aspect-ratio: 16/9;
    background-color: #f9fafb;
    position: relative;
    overflow: hidden;

    .preview-image {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .preview-placeholder {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100%;
      padding: 20px;

      .file-icon {
        font-size: 48px;
        margin-bottom: 8px;
        opacity: 0.6;
      }

      .file-extension {
        font-size: 14px;
        font-weight: 600;
        color: #6b7280;
        background-color: #f3f4f6;
        padding: 4px 8px;
        border-radius: 4px;
      }
    }
  }

  .file-info {
    padding: 16px;

    .file-name {
      font-size: 14px;
      font-weight: 600;
      color: #1f2937;
      margin: 0 0 8px 0;
      line-height: 1.4;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .file-meta {
      display: flex;
      gap: 8px;
      margin-bottom: 8px;
      font-size: 12px;
      color: #6b7280;

      .file-size {
        font-weight: 500;
      }
    }

    .file-description {
      margin-bottom: 12px;

      p {
        font-size: 12px;
        color: #6b7280;
        margin: 0;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
    }

    .file-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .uploader-info {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
        min-width: 0;

        .uploader-avatar {
          width: 24px;
          height: 24px;
          border-radius: 50%;
          object-fit: cover;
        }

        .uploader-name {
          font-size: 12px;
          color: #374151;
          font-weight: 500;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .source-badge {
          font-size: 10px;
          padding: 2px 6px;
          border-radius: 10px;
          font-weight: 500;
          white-space: nowrap;

          &.source-wxwork {
            background-color: #dcfce7;
            color: #166534;
          }

          &.source-manual {
            background-color: #dbeafe;
            color: #1e40af;
          }

          &.source-default {
            background-color: #f3f4f6;
            color: #6b7280;
          }
        }
      }

      .file-actions {
        .action-btn {
          background: none;
          border: none;
          padding: 6px;
          border-radius: 4px;
          cursor: pointer;
          color: #6b7280;
          transition: all 0.2s ease;
          display: flex;
          align-items: center;
          justify-content: center;

          svg {
            width: 16px;
            height: 16px;
          }

          &:hover {
            background-color: #f3f4f6;
            color: #374151;

            &.download-btn {
              background-color: #eff6ff;
              color: #3b82f6;
            }
          }

          &.download-btn:hover {
            background-color: #eff6ff;
            color: #3b82f6;
          }
        }
      }
    }
  }
}

.files-list {
  .file-list-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background-color 0.2s ease;

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

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

    .list-file-icon {
      width: 48px;
      height: 48px;
      border-radius: 6px;
      overflow: hidden;
      background-color: #f3f4f6;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;

      .list-preview-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      .list-icon {
        font-size: 24px;
      }
    }

    .list-file-info {
      flex: 1;
      min-width: 0;

      .list-file-name {
        font-size: 14px;
        font-weight: 600;
        color: #1f2937;
        margin-bottom: 4px;
      }

      .list-file-meta {
        display: flex;
        gap: 12px;
        font-size: 12px;
        color: #6b7280;
        flex-wrap: wrap;

        .source-badge {
          font-size: 10px;
          padding: 2px 6px;
          border-radius: 10px;
          font-weight: 500;

          &.source-wxwork {
            background-color: #dcfce7;
            color: #166534;
          }

          &.source-manual {
            background-color: #dbeafe;
            color: #1e40af;
          }

          &.source-default {
            background-color: #f3f4f6;
            color: #6b7280;
          }
        }
      }

      .list-file-description {
        font-size: 12px;
        color: #6b7280;
        margin-top: 4px;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
    }

    .list-file-actions {
      .action-btn {
        background: none;
        border: none;
        padding: 8px;
        border-radius: 4px;
        cursor: pointer;
        color: #6b7280;
        transition: all 0.2s ease;

        svg {
          width: 18px;
          height: 18px;
        }

        &:hover {
          background-color: #f3f4f6;
          color: #374151;

          &.download-btn {
            background-color: #eff6ff;
            color: #3b82f6;
          }
        }
      }
    }
  }
}

// 预览模态框
.preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.preview-container {
  background: white;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  .preview-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h3 {
      font-size: 18px;
      font-weight: 600;
      color: #1f2937;
      margin: 0;
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .preview-close {
      background: none;
      border: none;
      padding: 8px;
      border-radius: 6px;
      cursor: pointer;
      color: #6b7280;
      transition: all 0.2s ease;

      svg {
        width: 20px;
        height: 20px;
      }

      &:hover {
        background-color: #f3f4f6;
        color: #374151;
      }
    }
  }

  .preview-content {
    flex: 1;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f9fafb;
    min-height: 300px;

    .preview-full-image {
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
      border-radius: 8px;
    }

    .preview-video {
      max-width: 100%;
      max-height: 100%;
      border-radius: 8px;
    }

    .preview-no-preview {
      text-align: center;
      color: #6b7280;

      .preview-icon-large {
        font-size: 64px;
        margin-bottom: 16px;
        opacity: 0.6;
      }

      p {
        margin: 0 0 16px 0;
        font-size: 16px;
      }

      .preview-download-btn {
        background: #3b82f6;
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background: #2563eb;
        }
      }
    }
  }

  .preview-footer {
    padding: 20px;
    border-top: 1px solid #e5e7eb;
    background-color: #f9fafb;

    .preview-meta {
      display: flex;
      gap: 16px;
      margin-bottom: 16px;
      font-size: 14px;
      color: #6b7280;
      flex-wrap: wrap;

      .source-badge {
        font-size: 12px;
        padding: 4px 8px;
        border-radius: 12px;
        font-weight: 500;

        &.source-wxwork {
          background-color: #dcfce7;
          color: #166534;
        }

        &.source-manual {
          background-color: #dbeafe;
          color: #1e40af;
        }

        &.source-default {
          background-color: #f3f4f6;
          color: #6b7280;
        }
      }
    }

    .preview-description {
      .description-textarea {
        width: 100%;
        min-height: 60px;
        padding: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        font-size: 14px;
        font-family: inherit;
        resize: vertical;
        outline: none;
        transition: border-color 0.2s ease;

        &:focus {
          border-color: #3b82f6;
          box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }

        &::placeholder {
          color: #9ca3af;
        }
      }
    }
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// 响应式设计
@media (max-width: 768px) {
  .modal-overlay {
    padding: 0;
  }

  .modal-container {
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-header {
    padding: 16px;
    flex-direction: column;
    gap: 16px;

    .header-left {
      .modal-title {
        font-size: 20px;
      }

      .file-stats {
        justify-content: center;
        gap: 12px;
      }
    }

    .header-right {
      width: 100%;
      flex-direction: column;
      gap: 12px;

      .search-box .search-input {
        width: 100%;
      }
    }
  }

  .modal-content {
    padding: 16px;
  }

  .files-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }

  .file-card {
    .file-info {
      padding: 12px;
    }

    .file-footer {
      flex-direction: column;
      gap: 8px;
      align-items: stretch;

      .uploader-info {
        justify-content: center;
      }

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

  .files-list {
    .file-list-item {
      padding: 12px;
      gap: 12px;

      .list-file-icon {
        width: 40px;
        height: 40px;
      }
    }
  }

  .preview-overlay {
    padding: 0;
  }

  .preview-container {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
}

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

  .modal-header {
    .header-right {
      .view-toggle {
        justify-content: center;
      }

      .filter-select {
        width: 100%;
      }
    }
  }
}

.file-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.download-btn, .analyze-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.download-btn {
  background: #1976d2;
  color: #fff;
}

.analyze-btn {
  background: #6a1b9a;
  color: #fff;
}