/**
 * Product Variation Swatches
 * 产品变体选择器 - 颜色和图片样式
 */

/* =====================================
   基础设置
   ===================================== */

/* 隐藏 radio input */
.variation-radio-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* Swatch 标签基础样式 */
.swatch-label {
  display: inline-block;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

/* Swatch 元素基础 */
.swatch-element {
  display: block;
  transition: all 0.2s ease;
}

/* =====================================
   颜色 Swatch 样式
   ===================================== */

.swatch-type-color {
  max-width: calc((40px + 8px) * 10 - 8px); /* 一排10个 */
}

.swatch-type-color .swatch-label {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  overflow: visible;
}

.swatch-type-color .swatch-color {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #e0e0e0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
}

/* 颜色块内边框（增强对浅色的显示） */
.swatch-type-color .swatch-color::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

/* 颜色悬停效果 */
.swatch-type-color .swatch-label:hover .swatch-color {
  transform: scale(1.1);
  border-color: #999;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* 颜色选中状态 - 黑色边框 */
.swatch-type-color .variation-radio-input:checked + .swatch-label .swatch-color {
  border-color: #000;
  border-width: 3px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

/* 禁用状态 */
.swatch-type-color .variation-radio-input:disabled + .swatch-label {
  opacity: 0.4;
  cursor: not-allowed;
}

/* =====================================
   图片 Swatch 样式
   ===================================== */

.swatch-type-image {
  max-width: calc((56px + 8px) * 8 - 8px); /* 一排8个 */
}

.swatch-type-image .swatch-label {
  width: 56px;
  height: 56px;
  padding: 0;
  overflow: visible;
}

.swatch-type-image .swatch-image {
  width: 56px;
  height: 56px;
  border: 2px solid #e0e0e0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  background: #f5f5f5;
  position: relative;
}

.swatch-type-image .swatch-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

/* 图片悬停效果 */
.swatch-type-image .swatch-label:hover .swatch-image {
  transform: scale(1.05);
  border-color: #999;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.swatch-type-image .swatch-label:hover .swatch-image img {
  transform: scale(1.1);
}

/* 图片选中状态 - 黑色边框 1px */
.swatch-type-image .variation-radio-input:checked + .swatch-label .swatch-image {
  border-color: #000;
  border-width: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

/* 禁用状态 */
.swatch-type-image .variation-radio-input:disabled + .swatch-label {
  opacity: 0.4;
  cursor: not-allowed;
}

/* =====================================
   响应式设计
   ===================================== */

/* 平板 */
@media (max-width: 1024px) {
  .swatch-type-color {
    max-width: calc((38px + 8px) * 8 - 8px); /* 8个/行 */
  }
  
  .swatch-type-color .swatch-label,
  .swatch-type-color .swatch-color {
    width: 38px;
    height: 38px;
  }
  
  .swatch-type-image {
    max-width: calc((52px + 8px) * 6 - 8px); /* 6个/行 */
  }
  
  .swatch-type-image .swatch-label,
  .swatch-type-image .swatch-image {
    width: 52px;
    height: 52px;
  }
}

/* 手机 */
@media (max-width: 768px) {
  .product-form__input--swatch {
    gap: 6px !important;
  }
  
  .swatch-type-color {
    max-width: calc((36px + 6px) * 6 - 6px); /* 6个/行 */
  }
  
  .swatch-type-color .swatch-label,
  .swatch-type-color .swatch-color {
    width: 36px;
    height: 36px;
  }
  
  .swatch-type-image {
    max-width: calc((48px + 6px) * 5 - 6px); /* 5个/行 */
  }
  
  .swatch-type-image .swatch-label,
  .swatch-type-image .swatch-image {
    width: 48px;
    height: 48px;
  }
}

/* 小屏手机 */
@media (max-width: 480px) {
  .swatch-type-color {
    max-width: calc((32px + 6px) * 5 - 6px); /* 5个/行 */
  }
  
  .swatch-type-color .swatch-label,
  .swatch-type-color .swatch-color {
    width: 32px;
    height: 32px;
  }
  
  .swatch-type-image {
    max-width: calc((44px + 6px) * 4 - 6px); /* 4个/行 */
  }
  
  .swatch-type-image .swatch-label,
  .swatch-type-image .swatch-image {
    width: 44px;
    height: 44px;
  }
}

/* =====================================
   可访问性
   ===================================== */

/* 键盘焦点 */
.variation-radio-input:focus + .swatch-label .swatch-element {
  outline: 2px solid #4A90E2;
  outline-offset: 2px;
}

/* 触摸设备优化 */
@media (hover: none) {
  .swatch-label:active .swatch-element {
    transform: scale(0.95);
  }
}

/* =====================================
   Tooltip 提示（可选）
   ===================================== */

.swatch-label[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  background: #333;
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
  animation: tooltipFadeIn 0.2s ease;
}

.swatch-label[title]:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #333;
  z-index: 100;
  pointer-events: none;
  animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* =====================================
   打印样式
   ===================================== */

@media print {
  .swatch-color,
  .swatch-image {
    border: 1px solid #000 !important;
  }
  
  .variation-radio-input:checked + .swatch-label::after {
    content: ' [已选择]';
    position: static;
    display: block;
    font-size: 10px;
    margin-top: 2px;
  }
}
