/**
 * Checkbox Assistant v2 - スタイルシート
 * レスポンシブ対応、グループレイアウト、モーダル
 */

/* ========================================
   ラッパー
   ======================================== */

.checkbox-v2-wrapper {
  margin: 0.25rem 0;
  padding: 0.25rem;
}

/* カートドロワー用ラッパー（ちらつき防止・レイアウトシフト防止） */
.checkbox-v2-drawer-wrapper {
  min-height: 40px; /* チェックボックス1行分の高さを確保（レイアウトシフト防止） */
  text-align: left;
  position: relative;
  z-index: 1;

  /* 挿入時: fade-in アニメーション */
  opacity: 0;
  animation: fadeInCheckbox 0.15s ease-in-out forwards;

  /* ブラウザ最適化: GPU アクセラレーション */
  will-change: opacity, transform;
}

@keyframes fadeInCheckbox {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 削除時: fade-out アニメーション */
.checkbox-v2-drawer-wrapper.fade-out {
  animation: fadeOutCheckbox 0.15s ease-in-out forwards;
}

@keyframes fadeOutCheckbox {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-2px);
  }
}

.checkbox-v2-drawer-wrapper.checkbox-v2-hidden {
  opacity: 0;
}

/* ========================================
   ラベル
   ======================================== */

.checkbox-v2-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

/* ========================================
   チェックボックス
   ======================================== */

input.checkbox-v2-input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0 !important;
  margin-block: 0 !important;
  margin-inline: 0 !important;
  padding: 0 !important;
  padding-block: 0 !important;
  padding-inline: 0 !important;
  vertical-align: middle;
  align-self: center;
  cursor: pointer;
}

/* ========================================
   テキスト
   ======================================== */

.checkbox-v2-text {
  font-size: 14px;
  color: inherit;
}

.checkbox-v2-text a {
  text-decoration: underline;
  color: inherit;
}

/* ========================================
   グループモード
   ======================================== */

.checkbox-v2-group {
  margin: 0.25rem 0;
  margin-bottom: 1rem;
  width: 100%;
}

.checkbox-v2-group-title {
  font-weight: 600;
  margin-bottom: 0.75rem;
  font-size: 1.125rem;
}

/* グループリスト */
.checkbox-v2-group-list {
  display: flex;
  flex-direction: column;
}

.checkbox-v2-group-list.layout-horizontal {
  flex-direction: row;
  flex-wrap: wrap;
}

.checkbox-v2-group-list.layout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* スペーシング */
.checkbox-v2-group-list.spacing-tight {
  gap: 0.5rem;
}

.checkbox-v2-group-list.spacing-normal {
  gap: 0.75rem;
}

.checkbox-v2-group-list.spacing-loose {
  gap: 1.5rem;
}

/* グループアイテム */
.checkbox-v2-group-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
}

.checkbox-v2-group-item > label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ========================================
   モーダル
   ======================================== */

.checkbox-v2-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.checkbox-v2-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
}

.checkbox-v2-modal-content {
  position: relative;
  background: white;
  padding: 2rem;
  border-radius: 0.5rem;
  max-width: 90%;
  width: 400px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.checkbox-v2-modal-message {
  margin-bottom: 0;
  line-height: 1.6;
}

.checkbox-v2-modal-close {
  width: 100%;
  padding: 0.75rem;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

.checkbox-v2-modal-close:hover {
  background: #333;
}

.checkbox-v2-modal-x-button {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.checkbox-v2-modal-x-button::before,
.checkbox-v2-modal-x-button::after {
  content: none !important;
  display: none !important;
}

.checkbox-v2-modal-x-button:hover {
  background: rgba(0, 0, 0, 0.1) !important;
}

.checkbox-v2-modal-x-button svg {
  fill: #666;
}

.checkbox-v2-modal-x-button:hover svg {
  fill: #000;
}

/* ========================================
   ポップアップ（v1互換）
   ======================================== */

.checkbox-v2-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.checkbox-v2-popup-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.15);
}

.checkbox-v2-popup-content {
  position: relative;
  background: white;
  padding: 2rem;
  border-radius: 0.75rem;
  max-width: 90%;
  width: 400px;
  border: 1px solid #ddd;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  animation: popupFadeIn 0.3s ease-out;
}

@keyframes popupFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.checkbox-v2-popup-message {
  margin-bottom: 1rem;
  line-height: 1.6;
  color: #333;
}

.checkbox-v2-popup-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.checkbox-v2-popup-close::before,
.checkbox-v2-popup-close::after {
  content: none !important;
  display: none !important;
}

.checkbox-v2-popup-close:hover {
  background: rgba(0, 0, 0, 0.1) !important;
}

.checkbox-v2-popup-close svg {
  fill: #666;
}

.checkbox-v2-popup-close:hover svg {
  fill: #000;
}

/* ========================================
   ポップアップダイアログ（Top Layer対応）
   ======================================== */

.checkbox-v2-popup-dialog {
  border: none;
  outline: none;
  padding: 0;
  background: transparent;
  max-width: 90%;
  width: 400px;
  margin: auto;
  border-radius: 0.5rem;
}

.checkbox-v2-popup-dialog::backdrop {
  background: rgba(0, 0, 0, 0.15);
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-content {
  background: white;
  padding: 3rem 2.5rem;
  border-radius: 0.5rem;
  border: 1px solid #ddd;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  animation: popupFadeIn 0.3s ease-out;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-message {
  margin: 0;
  line-height: 1.6;
  color: #333;
  text-align: center; /* 中央揃え */
  width: 100%;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
  z-index: 1;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button::before,
.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button::after {
  content: none !important;
  display: none !important;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button:hover {
  background: rgba(0, 0, 0, 0.1) !important;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button svg {
  fill: #666;
}

.checkbox-v2-popup-dialog .checkbox-v2-popup-x-button:hover svg {
  fill: #000;
}

/* ========================================
   モーダルダイアログ（Top Layer対応）
   ======================================== */

.checkbox-v2-modal-dialog {
  border: none;
  outline: none;
  padding: 0;
  background: transparent;
  max-width: 90%;
  width: 400px;
  margin: auto;
  border-radius: 0.75rem;
}

.checkbox-v2-modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-content {
  background: white;
  padding: 3rem 2.5rem;
  border-radius: 0.75rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-message {
  margin: 0;
  line-height: 1.6;
  color: #333;
  text-align: center;
  width: 100%;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
  z-index: 1;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button::before,
.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button::after {
  content: none !important;
  display: none !important;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button:hover {
  background: rgba(0, 0, 0, 0.1) !important;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button svg {
  fill: #666;
}

.checkbox-v2-modal-dialog .checkbox-v2-modal-x-button:hover svg {
  fill: #000;
}

/* ========================================
   インラインアラート
   ======================================== */

.checkbox-v2-inline-alert {
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
  padding: 0.25rem;
  color: #c00;
  border-radius: 0.25rem;
  font-size: 12px;
  animation: fadeIn 0.3s ease-in-out;
  width: 100%;
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   ボタン無効化
   ======================================== */

[data-checkbox-v2-controlled] {
  transition: opacity 0.2s ease-in-out; /* ちらつき防止: 滑らかなopacity変化 */
  will-change: opacity; /* ブラウザ最適化: GPU アクセラレーション */
}

[data-checkbox-v2-controlled].checkbox-v2-disabled {
  opacity: 0.5 !important;
  cursor: pointer !important;
  pointer-events: none !important;
}

/* ========================================
   ボタンラッパーとオーバーレイ
   ======================================== */

.checkbox-v2-button-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.checkbox-v2-button-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  background: transparent;
  cursor: pointer;
  transition: opacity 0.15s ease-in-out; /* ちらつき防止: 滑らかな表示/非表示 */
  will-change: opacity; /* ブラウザ最適化: GPU アクセラレーション */
}

/* ========================================
   レスポンシブ
   ======================================== */

@media (max-width: 768px) {
  .checkbox-v2-modal-content {
    width: 90%;
    padding: 1.5rem;
  }

  .checkbox-v2-group-list.layout-grid {
    grid-template-columns: 1fr;
  }

  .checkbox-v2-group-list.layout-horizontal {
    flex-direction: column;
  }
}

/* ========================================
   非表示
   ======================================== */

[hidden] {
  display: none !important;
}

/* ========================================
   ウォーターマーク（無料プラン・開発ストア）
   ======================================== */

.checkbox-v2-watermark {
  margin-top: 0.25rem;
  text-align: left;
  font-size: 0.6rem;
  color: #bbb;
}

.checkbox-v2-watermark a {
  color: #bbb;
  text-decoration: none;
  transition: color 0.2s ease;
}

.checkbox-v2-watermark a:hover {
  color: #999;
  text-decoration: underline;
}
