/* =========================================
  ▼ フォントサイズは編集画面の設定を継承
  ========================================= */

/* =========================================
  ▼ 基本・テーブル関連スタイル
  ========================================= */
.comparison-table .compare-row {
  border-top: 2px solid #eee;
}

.comparison-table .compare-row td {
  text-align: center;
  padding: 10px;
  position: relative;
}

.comparison-table .compare-row td:first-child {
  text-align: center;
  font-weight: bold;
}

/* 行型比較表（比較項目が行に並ぶタイプ） */
.comparison-table-row thead th {
  min-width: 100px; /* 列の最小幅 */
}

.comparison-table-row tbody td:first-child {
  min-width: 120px; /* 項目名列の最小幅 */
}

/* =========================================
  ▼ チェックボックス関連（強化版）
  ========================================= */
.compare-checkbox-wrap {
  position: relative !important;
  padding-top: 30px !important; /* チェックボックス用のスペース確保 */
}

/* より汎用的なセレクタでチェックボックスを確実に配置 */
.comparison-table-row tbody tr td:first-child,
.comparison-table-row tbody tr th:first-child,
.comparison-table-column thead tr th:not(:first-child) {
  position: relative !important;
}

.compare-checkbox {
  margin: 0 !important;
  cursor: pointer !important;
  width: 20px !important;
  height: 20px !important;
  position: absolute !important;
  top: 8px !important;
  right: 8px !important;
  z-index: 9999 !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  display: block !important;
  visibility: visible !important;
  background: white !important;
  border: 2px solid #ccc !important;
  border-radius: 3px !important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

.compare-checkbox:checked {
  /* JavaScriptで動的に色を設定 */
}

.compare-checkbox:checked::after {
  content: "✓" !important;
  color: white !important;
  font-size: 14px !important;
  font-weight: bold !important;
  position: absolute !important;
  top: -2px !important;
  left: 2px !important;
  pointer-events: none !important;
  display: block !important;
}

/* 列型・行型比較表のチェックボックス位置を確実に設定 */
.comparison-table-column th .compare-checkbox,
.comparison-table-row td .compare-checkbox,
.comparison-table-row th .compare-checkbox {
  top: 8px !important;
  right: 8px !important;
  position: absolute !important;
  z-index: 9999 !important;
}

/* =========================================
  ▼ 比較バー（画面下部に固定表示するエリア）
  ========================================= */
.compare-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  transform: translateY(100%);
  transition: transform 0.3s ease;
  z-index: 100;
}

.compare-bar.active {
  transform: translateY(0);
}

.compare-bar-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.selected-items {
  display: flex;
  gap: 10px;
  white-space: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE, Edge */
}

.selected-items::-webkit-scrollbar {
  display: none;
}

.selected-item {
  background: #f0f0f0;
  padding: 5px 10px;
  border-radius: 4px;
  flex-shrink: 0;
}

.compare-bar-buttons {
  display: flex;
  gap: 10px;
}

.compare-button,
.reset-button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  min-width: 100px;
}

.compare-button {
  background: var(--wp--preset--color--primary, var(--theme-color-primary, var(--primary-color, #007cba)));
  color: #fff;
}

.compare-button:hover {
  filter: brightness(0.9);
}

.reset-button {
  background: #f0f0f0;
  color: #333;
}

.reset-button:hover {
  background: #e0e0e0;
}

/* =========================================
  ▼ ポップアップ関連
  ========================================= */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.comparison-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 40px 20px 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  width: 95%;
  max-width: 1200px;
  max-height: 90vh;
  overflow: hidden; /* 外側のスクロールを無効化 */
}

/* Gutenbergのテーブルブロック対策 */
.comparison-popup .wp-block-table {
  margin: 0;
  overflow-x: auto !important; /* 横スクロールを有効化 */
  overflow-y: hidden;
  max-height: calc(90vh - 120px); /* ポップアップの高さ制限 */
  -webkit-overflow-scrolling: touch;
}

.comparison-popup table {
  width: auto !important; /* 自動幅調整 */
  min-width: 600px !important; /* 最小幅を確保 */
  border-collapse: collapse !important;
  margin: 0 !important;
  table-layout: auto !important; /* 自動レイアウト */
}

.comparison-popup table th,
.comparison-popup table td {
  padding: 10px 15px !important; /* より広いパディング */
  border: 1px solid #ddd !important;
  vertical-align: top !important;
  /* 適切な幅設定 */
  min-width: 90px !important;
  white-space: normal !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  line-height: 1.4 !important;
}

.comparison-popup table th:first-child,
.comparison-popup table td:first-child {
  /* 項目名列は適切な幅を確保 */
  min-width: 120px !important;
  max-width: 180px !important;
  font-weight: bold !important;
  background-color: #f8f9fa !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

/* 2列目以降の適切な幅設定 */
.comparison-popup table th:not(:first-child),
.comparison-popup table td:not(:first-child) {
  min-width: 100px !important;
  max-width: 200px !important;
  text-align: center !important;
}

/* 画像を含むセルの調整 */
.comparison-popup table td img {
  max-width: 60px !important;
  height: auto !important;
  display: block !important;
  margin: 0 auto 8px auto !important;
}

/* 長いテキスト用のセル（最後の列など） */
.comparison-popup table td:last-child {
  text-align: left !important;
  max-width: 250px !important;
  min-width: 150px !important;
}

.comparison-popup .popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #f5f5f5;
  transition: background-color 0.2s;
}

.popup-close:hover {
  background: #e0e0e0;
}

/* =========================================
  ▼ 比較表の横スクロール & セル幅制御
  ========================================= */
.comparison-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.comparison-scroll-wrapper table {
  table-layout: fixed;
  min-width: 800px;
  width: auto;
}

/* 1列目を改行させない */
.comparison-table tbody td:first-child {
  white-space: nowrap !important;
}

/* 2列目以降 */
.comparison-table tbody th:not(:first-child),
.comparison-table tbody td:not(:first-child) {
  min-width: 100px !important;
  max-width: 400px !important;
  white-space: normal;
  word-wrap: break-word;
  word-break: break-word;
}

/* =========================================
  ▼ レスポンシブ対応 (768px以下)
  ========================================= */
@media (max-width: 768px) {
  .compare-bar-content {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .selected-items {
    width: 100%;
    margin-bottom: 4px;
    padding: 4px 0;
  }

  .compare-bar-buttons {
    width: 100%;
    flex-direction: column;
    gap: 8px;
  }

  .compare-button,
  .reset-button {
    width: 100%;
    padding: 12px;
    text-align: center;
  }
  
  .compare-button:hover {
    filter: brightness(0.85) !important;
  }

  .comparison-popup {
    width: 90%;
    padding: 35px 15px 15px;
    max-width: none;
    max-height: 85vh;
  }

  .comparison-popup .wp-block-table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    display: block;
    max-width: 100%;
    max-height: calc(85vh - 100px);
  }

  .comparison-popup table {
    min-width: 500px !important;
    width: auto !important;
  }

  .comparison-popup table th,
  .comparison-popup table td {
    padding: 8px 10px !important;
    min-width: 80px !important;
  }

  .comparison-popup table th:first-child,
  .comparison-popup table td:first-child {
    min-width: 100px !important;
    max-width: 140px !important;
  }
  
  .comparison-popup table th:not(:first-child),
  .comparison-popup table td:not(:first-child) {
    min-width: 90px !important;
    max-width: 160px !important;
  }

  .popup-close {
    top: 5px;
    right: 5px;
    width: 28px;
    height: 28px;
    font-size: 20px;
  }
}