/* custom_variant.css — カラースワッチ表示 (Phase 1)
 * 対象: 自由入力1にマッピングを持つ商品のみ (JSが .cv- 要素を描画した場合のみ効く)
 * 他商品・他ページへの影響なし (すべて cv- プレフィックスで名前空間化) */

/* スワッチ有効時はネイティブの select 行を隠す (要素自体は同期用に残す) */
#option_types.cv-native-hidden .option_type {
  display: none !important;
}

/* ---- スワッチグリッド ---- */
.cv-swatch {
  margin: 10px 0 4px;
}
.cv-swatch__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
}
.cv-swatch__item {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 2px;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
}
.cv-swatch__item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cv-swatch__item:hover {
  border-color: #aa2317;
}

/* 選択状態: 赤枠 + 中央チェックマーク (Figma準拠) */
.cv-swatch__item--selected {
  outline: 2px solid #aa2317;
  outline-offset: 1px;
  border-color: #aa2317;
}
.cv-swatch__item--selected::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #aa2317
    url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E")
    center / 13px 13px no-repeat;
  box-shadow: 0 0 0 2px #fff;
}

/* 画像なしフォールバック: グレーのチップ + 絶対配置ラベル (正方形を維持) */
.cv-swatch__item--noimg {
  background: #f4f4f4;
}
.cv-swatch__label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  font-size: 9px;
  line-height: 1.15;
  text-align: center;
  color: #555;
  overflow: hidden;
  word-break: break-word;
}

/* マッピングにあるが規格値が未登録 */
.cv-swatch__item--nomatch {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---- 見出し: カラー ※複数色を選択できます ---- */
.cv-swatch__head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}
.cv-swatch__head-label {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
}
.cv-swatch__head-note {
  font-size: 12px;
  color: #888;
}

/* ---- 選択中のカラー(N色) リスト (Phase 2 / Figma 53-300) ---- */
.cv-selected {
  margin-top: 20px;
}
.cv-selected__head {
  padding-bottom: 10px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 14px;
  color: #1a1a1a;
}
.cv-selected__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.cv-selected__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}
.cv-selected__thumb {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border: 1px solid #ddd;
  border-radius: 2px;
}
.cv-selected__name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: #1a1a1a;
  overflow-wrap: anywhere;
}

/* 狭い画面(〜480px)では色名が1文字ずつ縦に割れないよう、
   数量・削除を次の行へ回してレイアウトを崩さない */
@media (max-width: 480px) {
  .cv-selected__row {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .cv-selected__name {
    flex: 1 1 calc(100% - 56px); /* サムネ(44)+gap(12) を除いた残り = 1行目いっぱい */
  }
  .cv-selected__qty-label {
    margin-left: 56px; /* 2行目: サムネ幅ぶん字下げして色名と揃える */
  }
}
.cv-selected__qty-label {
  flex: 0 0 auto;
  font-size: 13px;
  color: #333;
}
.cv-selected__qty {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  border: 1px solid #ccc;
  border-radius: 2px;
  background: #fff;
}
.cv-selected__qty-btn {
  width: 30px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  font-size: 15px;
  line-height: 1;
  color: #333;
  cursor: pointer;
}
.cv-selected__qty-input {
  width: 44px;
  height: 32px;
  padding: 0;
  border: none;
  border-left: 1px solid #eee;
  border-right: 1px solid #eee;
  text-align: center;
  font-size: 14px;
  -moz-appearance: textfield;
  appearance: textfield;
}
.cv-selected__qty-input::-webkit-inner-spin-button,
.cv-selected__qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.cv-selected__remove {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  font-size: 17px;
  line-height: 1;
  color: #333;
  cursor: pointer;
}
.cv-selected__remove:hover {
  color: #aa2317;
}

/* スワッチ有効商品(自由入力1にマッピングあり)は単品数量セレクタを常に隠す。
   数量は色ごとの「選択中のカラー」リストで管理するため。 */
.c-product_info.cv-swatch-mode .c-product_info__form__quantity {
  display: none;
}

/* ---- カート追加ボタン無効時 ---- */
.cv-btn-disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* カート追加処理中 */
.cv-busy {
  opacity: 0.6;
  pointer-events: none;
}

/* ---- SKU画像ストリップ (スライダー外の独立要素) ---- */
/* スワッチ有効時はプラットフォームのサムネイルスライダーを隠しストリップに置き換える */
.c-product_img.cv-active .c-product_img__slider--thumbnail {
  display: none;
}

.cv-sku-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
}
.cv-sku-strip__list {
  display: flex;
  flex: 1;
  gap: 10px;
  margin: 0;
  padding: 2px;
  list-style: none;
  overflow-x: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.cv-sku-strip__item {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  border: 1px solid #ddd;
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
}
.cv-sku-strip__item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cv-sku-strip__item:hover {
  border-color: #aa2317;
}
.cv-sku-strip__item--active {
  outline: 2px solid #aa2317;
  outline-offset: -1px;
}
/* 矢印: Figma準拠 (ボタン40x40 / アイコン18x18を中央配置, 透明, 枠なし, opacity 0.5) */
.cv-sku-strip__arrow {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  opacity: 0.5;
  cursor: pointer;
}
.cv-sku-strip__arrow:hover {
  opacity: 1;
}
.cv-sku-strip__arrow svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: #000;
}
.cv-sku-strip__arrow--prev svg {
  transform: scaleX(-1);
}
@media (max-width: 720px) {
  .cv-sku-strip__arrow {
    display: none;
  }
  .cv-sku-strip__item {
    width: 60px;
    height: 60px;
  }
}

/* ============================================================
 * Phase 3: 同じカラーの別サイズ (OTHER SIZE) + 別商品モーダル
 * ============================================================ */

/* ---- セクション: テーマの RECOMMEND (.p-recommend_product) と同じ余白・見出しに合わせる ---- */
.cv-other-size {
  margin: 0 auto;
  max-width: 1200px; /* テーマの .p-product_content__inner と同じ (本文と左右を揃える) */
  width: 100%;
  padding: 80px 0 100px; /* RECOMMEND: padding-top 80 / padding-bottom 100 */
}
.cv-other-size__header {
  text-align: center;
  margin-bottom: 30px;
}
.cv-other-size__title {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: 4px;
  font-weight: 400;
  line-height: 30px;
  color: #1a1a1a;
}
.cv-other-size__subtitle {
  display: block;
  font-size: 16px;
  letter-spacing: 0.8px;
  font-weight: 400;
  line-height: 24px;
  color: #1a1a1a;
}
.cv-other-size__list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 60px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cv-other-size__card {
  cursor: pointer;
}
.cv-other-size__thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #f2f2f2 center / cover no-repeat;
  border-radius: 2px;
}
.cv-other-size__card:hover .cv-other-size__thumb {
  opacity: 0.85;
}
.cv-other-size__name {
  margin-top: 14px;
  font-size: 14px;
  color: #1a1a1a;
  line-height: 1.5;
}
.cv-other-size__price {
  margin-top: 4px;
  font-size: 13px;
  color: #333;
}
.cv-other-size__card--error {
  opacity: 0.5;
  cursor: default;
}
@media (max-width: 720px) {
  .cv-other-size {
    padding: 48px 0 60px;
  }
  .cv-other-size__header {
    margin-bottom: 24px;
  }
  .cv-other-size__subtitle {
    font-size: 14px;
  }
  .cv-other-size__list {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }
}

/* ---- モーダル ---- */
.cv-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
}
.cv-modal--open {
  display: block;
}
body.cv-modal-lock {
  overflow: hidden;
}
.cv-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.cv-modal__dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 94%;
  max-width: 526px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
}
/* ヘッダー: 商品名(左) + 閉じる(右) + 下線 */
.cv-modal__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 25px;
  border-bottom: 1px solid #e5e5e5;
}
.cv-modal__htitle {
  font-size: 15px;
  color: #1a1a1a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cv-modal__close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: #333;
  cursor: pointer;
}
.cv-modal__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 25px;
  -webkit-overflow-scrolling: touch;
}
/* 画像: 300x300 中央寄せ (Figma) */
.cv-modal__image {
  width: 300px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto 24px;
  background: #f2f2f2;
  border-radius: 2px;
  overflow: hidden;
}
.cv-modal__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cv-modal__name {
  margin: 0 0 8px;
  font-size: 15px;
  color: #1a1a1a;
}
.cv-modal__price {
  margin-bottom: 20px;
  font-size: 14px;
  color: #333;
}
.cv-modal__add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 60px;
  margin-top: 28px;
  padding: 0;
  border: none;
  border-radius: 2px;
  text-align: center;
  font-size: 15px;
  cursor: pointer;
}
.cv-modal__add:disabled {
  opacity: 0.4;
  pointer-events: none;
}
.cv-modal__view {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 60px;
  margin-top: 16px;
  border: 1px solid #aa2317;
  border-radius: 2px;
  text-align: center;
  color: #aa2317;
  text-decoration: none;
  font-size: 15px;
}
.cv-modal__view:hover {
  background: #fbeceb;
}
.cv-modal__alert {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 2px;
  font-size: 13px;
}
.cv-modal__alert--success {
  background: #e7f5ec;
  color: #0e7a3d;
}
.cv-modal__alert--error {
  background: #fdeceb;
  color: #b3261e;
}
.cv-selected__thumb--noimg {
  display: inline-block;
  background: #eee;
}

/* モーダル: デフォルト表示(option01マッピング無し)のドロップダウン */
.cv-modal__field {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.cv-modal__field-label {
  flex: 0 0 auto;
  font-size: 14px;
  color: #1a1a1a;
}
.cv-modal__select-wrap {
  position: relative;
  flex: 1;
}
.cv-modal__select-wrap::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 14px;
  width: 8px;
  height: 8px;
  border-right: 1px solid #333;
  border-bottom: 1px solid #333;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.cv-modal__select {
  width: 100%;
  height: 44px;
  padding: 0 36px 0 14px;
  border: 1px solid #ccc;
  border-radius: 2px;
  background: #fff;
  font-size: 14px;
  color: #1a1a1a;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
