/**
 * 现代化头像上传组件样式
 * 包含拖拽效果、进度指示器、响应式设计和无障碍支持
 */

/* 主容器 */
.avatar-uploader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  position: relative;
}

/* 上传区域 */
.upload-area {
  border: 2px dashed #e1e5e9;
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  background: #fafbfc;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.upload-area:hover {
  border-color: #4f46e5;
  background: #f8faff;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(79, 70, 229, 0.1);
}

.upload-area.drag-over {
  border-color: #4f46e5;
  background: linear-gradient(135deg, #f8faff 0%, #e0e7ff 100%);
  transform: scale(1.02);
  box-shadow: 0 12px 35px rgba(79, 70, 229, 0.15);
}

.avatar-uploader.uploading .upload-area {
  pointer-events: none;
  opacity: 0.7;
}

/* 上传内容 */
.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: #6b7280;
  transition: all 0.3s ease;
}

.upload-area:hover .upload-icon {
  color: #4f46e5;
  transform: translateY(-2px);
}

.upload-area.drag-over .upload-icon {
  color: #4f46e5;
  transform: scale(1.1) translateY(-2px);
}

.upload-text {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upload-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #374151;
  margin: 0;
  transition: color 0.3s ease;
}

.upload-area:hover .upload-title {
  color: #4f46e5;
}

.upload-subtitle {
  font-size: 0.875rem;
  color: #6b7280;
  margin: 0;
}

/* 预览区域 */
.preview-area {
  background: #ffffff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e7eb;
}

.preview-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-image-wrapper {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.preview-image-wrapper:hover .preview-image {
  transform: scale(1.05);
}

/* 预览覆盖层 */
.preview-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.preview-image-wrapper:hover .preview-overlay {
  opacity: 1;
}

.preview-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #374151;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
}

.preview-btn:hover {
  background: #ffffff;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.preview-btn.crop-btn:hover {
  color: #4f46e5;
}

.preview-btn.remove-btn:hover {
  color: #ef4444;
}

/* 图片信息 */
.image-info {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.info-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.info-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
}

/* 进度条 */
.progress-container {
  margin-top: 1rem;
  padding: 1rem;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.75rem;
  position: relative;
}

/* 响应式进度条 */
@media (max-width: 480px) {
  .progress-bar {
    height: 10px;
    border-radius: 5px;
  }
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4f46e5 0%, #7c3aed 100%);
  border-radius: 4px;
  transition: width 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: shimmer 2s infinite;
}

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

.progress-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.progress-text span:first-child {
  color: #374151;
  font-weight: 500;
}

.progress-text span:last-child {
  color: #4f46e5;
  font-weight: 600;
}

/* 错误消息 */
.error-message {
  margin-top: 1rem;
  padding: 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  word-wrap: break-word;
  hyphens: auto;
}

/* 响应式错误消息 */
@media (max-width: 480px) {
  .error-message {
    padding: 0.875rem;
    margin-top: 0.875rem;
    border-radius: 6px;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

.error-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.error-icon {
  color: #ef4444;
  flex-shrink: 0;
}

.error-message span {
  color: #dc2626;
  font-size: 0.875rem;
  font-weight: 500;
}

.error-close {
  background: none;
  border: none;
  color: #dc2626;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.error-close:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* 裁剪模态框 */
.crop-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.crop-modal-content {
  background: #ffffff;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  width: 600px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.crop-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.crop-modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #374151;
}

.crop-modal-close {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.crop-modal-close:hover {
  background: #f3f4f6;
  color: #374151;
}

.crop-modal-body {
  padding: 1.5rem;
  flex: 1;
  overflow: hidden;
}

.crop-container {
  width: 100%;
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.crop-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.crop-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.5rem;
  border-top: 1px solid #e5e7eb;
}

/* 按钮样式 */
.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

.btn-secondary:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.btn-primary {
  background: #4f46e5;
  color: #ffffff;
}

.btn-primary:hover {
  background: #4338ca;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* 响应式设计 */
/* 移动设备优先的响应式设计 */
@media (max-width: 768px) {
  .avatar-uploader {
    max-width: 100%;
  }
  
  .upload-area {
    padding: 1.5rem 1rem;
  }
  
  .preview-image-wrapper {
    width: 150px;
    height: 150px;
  }
  
  .crop-modal-content {
    width: 95vw;
    margin: 1rem;
  }
  
  .crop-container {
    height: 300px;
  }
  
  .image-info {
    flex-direction: column;
    gap: 1rem;
  }
  
  .info-item {
    flex-direction: row;
    justify-content: space-between;
  }
}

/* 大屏幕设备 */
@media (min-width: 1200px) {
  .avatar-uploader {
    max-width: 600px;
  }
  
  .upload-area {
    padding: 2.5rem;
  }
  
  .preview-image-wrapper {
    width: 250px;
    height: 250px;
  }
  
  .crop-modal-content {
    max-width: 700px;
  }
  
  .crop-container {
    height: 500px;
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
    padding: 0.875rem 1.5rem;
  }
  
  .upload-area {
    border-width: 3px;
  }
  
  .preview-btn {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 480px) {
  .upload-area {
    padding: 1rem;
  }
  
  .upload-icon {
    width: 36px;
    height: 36px;
  }
  
  .upload-title {
    font-size: 1rem;
  }
  
  .upload-subtitle {
    font-size: 0.8rem;
  }
  
  .preview-image-wrapper {
    width: 120px;
    height: 120px;
  }
  
  .preview-btn {
    width: 36px;
    height: 36px;
  }
  
  .crop-modal-header,
  .crop-modal-body,
  .crop-modal-footer {
    padding: 1rem;
  }
  
  .crop-container {
    height: 250px;
  }
}

/* 无障碍支持 */
@media (prefers-reduced-motion: reduce) {
  .avatar-uploader *,
  .avatar-uploader *::before,
  .avatar-uploader *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
  .upload-area {
    border-color: #000000;
    background: #ffffff;
  }
  
  .upload-area:hover,
  .upload-area.drag-over {
    border-color: #0000ff;
    background: #f0f0ff;
  }
  
  .preview-btn {
    background: #ffffff;
    border: 2px solid #000000;
  }
  
  .btn-primary {
    background: #0000ff;
    border: 2px solid #000000;
  }
}

/* 焦点样式 */
.upload-area:focus-visible,
.preview-btn:focus-visible,
.btn:focus-visible,
.crop-modal-close:focus-visible,
.error-close:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

/* 深色主题支持 */
@media (prefers-color-scheme: dark) {
  .avatar-uploader[data-theme="auto"] .upload-area {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }
  
  .avatar-uploader[data-theme="auto"] .upload-area:hover {
    background: #111827;
    border-color: #6366f1;
  }
  
  .avatar-uploader[data-theme="auto"] .preview-area {
    background: #1f2937;
    border-color: #374151;
  }
  
  .avatar-uploader[data-theme="auto"] .image-info {
    background: #111827;
    border-color: #374151;
  }
  
  .avatar-uploader[data-theme="auto"] .progress-container {
    background: #1f2937;
    border-color: #374151;
  }
  
  .avatar-uploader[data-theme="auto"] .crop-modal-content {
    background: #1f2937;
    color: #f9fafb;
  }
}

/* 打印样式 */
@media print {
  .avatar-uploader {
    break-inside: avoid;
  }
  
  .crop-modal {
    display: none !important;
  }
  
  .preview-overlay {
    display: none !important;
  }
}