* { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- テーマ変数 ---- */
:root {
  --bg-page: #f5f5f5;
  --bg-surface: #fff;
  --bg-banner: #e8eaf6;
  --bg-hover: #f0f4ff;
  --bg-input: #fff;
  --bg-table-header: #f5f5f5;
  --bg-table-odd: #fafafa;
  --text-primary: #333;
  --text-secondary: #666;
  --text-muted: #888;
  --text-faint: #999;
  --accent: #1a237e;
  --accent-light: #e8eaf6;
  --accent-hover: #283593;
  --border: #e0e0e0;
  --border-light: #ddd;
  --shadow: rgba(0,0,0,0.12);
  --shadow-hover: rgba(0,0,0,0.15);
  --heat-very-cheap: #a5d6a7;
  --heat-cheap: #c8e6c9;
  --heat-normal: #fff9c4;
  --heat-expensive: #ffcc80;
  --heat-very-expensive: #ef9a9a;
  --heat-nodata: #f5f5f5;
  --compare-checked-bg: #e8f0fe;
  --compare-checked-border: #1a73e8;
  --btn-more-bg: #f5f5f5;
}

[data-theme="dark"] {
  --bg-page: #121220;
  --bg-surface: #1e1e30;
  --bg-banner: #1a1a2e;
  --bg-hover: #2a2a44;
  --bg-input: #2a2a3e;
  --bg-table-header: #1e1e30;
  --bg-table-odd: #1a1a2e;
  --text-primary: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #999;
  --text-faint: #777;
  --accent: #7986cb;
  --accent-light: #2a2a44;
  --accent-hover: #9fa8da;
  --border: #3a3a50;
  --border-light: #3a3a50;
  --shadow: rgba(0,0,0,0.3);
  --shadow-hover: rgba(0,0,0,0.5);
  --heat-very-cheap: #2e7d32;
  --heat-cheap: #388e3c;
  --heat-normal: #f9a825;
  --heat-expensive: #e65100;
  --heat-very-expensive: #c62828;
  --heat-nodata: #2a2a3e;
  --compare-checked-bg: #1a237e;
  --compare-checked-border: #7986cb;
  --btn-more-bg: #2a2a3e;
}

/* キーボードフォーカス時のアウトライン（グローバル） */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
}

/* ---- ヘッダー ---- */
header {
  background: #1a237e;
  color: #fff;
  padding: 1.5rem;
  text-align: center;
  position: relative;
}
[data-theme="dark"] header { background: #0d1442; }
header h1 { font-size: 1.6rem; }
header p { font-size: 0.85rem; opacity: 0.8; margin-top: 0.3rem; }

/* ---- テーマトグル ---- */
.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-size: 1.1rem;
  cursor: pointer;
  min-height: 40px;
  min-width: 40px;
  line-height: 1;
}
.theme-toggle:hover { background: rgba(255,255,255,0.25); }

/* ---- ダッシュボード要約バナー ---- */
.summary-banner {
  background: var(--bg-banner);
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-wrap: wrap;
}

.summary-card {
  background: var(--bg-surface);
  border-radius: 8px;
  box-shadow: 0 1px 4px var(--shadow);
  padding: 0.75rem 1.5rem;
  text-align: center;
  min-width: 140px;
  flex: 1 1 140px;
  max-width: 220px;
}

.summary-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--accent);
  line-height: 1.2;
}

.summary-unit {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- スティッキーナビゲーション ---- */
.sticky-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sticky-nav-list {
  display: flex;
  list-style: none;
  padding: 0 1rem;
  gap: 0;
  white-space: nowrap;
  min-width: max-content;
}

.sticky-nav-list li a {
  display: block;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s, color 0.15s;
}

.sticky-nav-list li a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

/* ナビアクティブリンク（IntersectionObserverで付与） */
.sticky-nav-list li a.active {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
  font-weight: 700;
  background: var(--accent-light);
}

/* ---- メインコンテンツ ---- */
main { max-width: 960px; margin: 0 auto; padding: 1rem; }

section { margin-bottom: 2.5rem; }

section h2 {
  font-size: 1.1rem;
  border-left: 4px solid var(--accent);
  padding-left: 0.5rem;
  margin-bottom: 1rem;
}

/* ---- details 折りたたみ（ヒートマップ・通知履歴共通） ---- */
details {
  background: var(--bg-surface);
  border-radius: 8px;
  border: 1px solid var(--border);
}

details summary {
  font-weight: bold;
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
  content: '+';
  display: inline-block;
  width: 1.2em;
  font-weight: bold;
  color: var(--accent);
  transition: transform 0.2s;
}

details[open] summary::before {
  content: '-';
}

details[open] summary {
  border-bottom: 1px solid var(--border);
}

/* ヒートマップ・通知の内部パディング */
#heatmap-container,
#notify-history-container,
#notify-more-container {
  padding: 0.75rem 1rem;
}

/* ---- 日付ピッカー ---- */
.date-picker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.date-picker-row input[type="date"] {
  padding: 0.4rem;
  font-size: 1rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-primary);
}
.date-picker-row button {
  padding: 0.4rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}
.date-picker-row button:hover { background: var(--accent-hover); }

/* ---- カードグリッド ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ---- カード共通 ---- */
.card {
  background: var(--bg-surface);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px var(--shadow);
  position: relative;
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: 0 4px 12px var(--shadow-hover); }

/* バッジとの重なり防止: 右側にバッジ分のスペースを確保 */
.card h3 { font-size: 1rem; margin-bottom: 0.5rem; padding-right: 3rem; }
.card .price { font-size: 1.5rem; font-weight: bold; color: var(--accent); }
.card .plan-name { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.card .meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.3rem; }
.card .btn-reserve {
  display: inline-flex;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  min-height: 40px;
  background: #c62828;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.85rem;
}
.card .btn-reserve:hover { background: #e53935; }

/* ---- ディスカウントバッジ（カード右上） ---- */
.discount-badge {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: #c62828;
  color: #fff;
  font-size: 0.72rem;
  font-weight: bold;
  border-radius: 50%;
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  text-align: center;
}

/* ---- スコアバッジ ---- */
.badge-score {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  color: #fff;
}
.badge-high { background: #2e7d32; }
.badge-mid { background: #ff8f00; }
.badge-low { background: #9e9e9e; }

.discount-positive { color: #2e7d32; font-weight: bold; }
.discount-negative { color: #c62828; }

/* ---- 曜日バッジ（お得アラートカード内） ---- */
.day-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: bold;
  color: #fff;
  background: var(--accent);
  margin-left: 0.3rem;
  vertical-align: middle;
}

/* ---- ホテルカード: 目標以下なら緑ボーダー ---- */
.card.card-on-target {
  border-left: 4px solid #2e7d32;
}

/* ---- ヒートマップテーブル ---- */
#heatmap-container { overflow-x: auto; }
.heatmap-table { border-collapse: collapse; font-size: 0.8rem; width: 100%; }
.heatmap-table th, .heatmap-table td {
  padding: 0.4rem;
  text-align: center;
  border: 1px solid var(--border);
  min-width: 60px;
}
.heatmap-table th { background: var(--bg-table-header); font-weight: 600; }

/* 5色グラデーション */
.heat-very-cheap   { background: var(--heat-very-cheap); }
.heat-cheap        { background: var(--heat-cheap); }
.heat-normal       { background: var(--heat-normal); }
.heat-expensive    { background: var(--heat-expensive); }
.heat-very-expensive { background: var(--heat-very-expensive); }
.heat-nodata       { background: var(--heat-nodata); color: var(--text-faint); }
[data-theme="dark"] .heatmap-table td { color: #fff; }

/* ---- チャートコントロール ---- */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.chart-controls label { font-size: 0.9rem; }
.chart-controls select {
  padding: 0.3rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  min-width: 180px;
  background: var(--bg-input);
  color: var(--text-primary);
}

/* ---- 比較モード ---- */
.compare-btn {
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid #1a73e8;
  border-radius: 4px;
  background: #fff;
  color: #1a73e8;
  cursor: pointer;
  min-height: 40px;
}
.compare-btn.active {
  background: #1a73e8;
  color: #fff;
}
.compare-panel {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.6rem;
  margin-bottom: 0.75rem;
  background: var(--bg-table-odd);
}
.compare-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.compare-clear-btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  min-height: 36px;
}
.compare-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.compare-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-surface);
  cursor: pointer;
  min-height: 36px;
}
.compare-checkboxes label.checked {
  border-color: var(--compare-checked-border);
  background: var(--compare-checked-bg);
}

/* ---- 通知履歴テーブル ---- */
#notify-history-container { overflow-x: auto; }
.notify-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
  min-width: 360px;
}
.notify-table th, .notify-table td {
  padding: 0.45rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.notify-table thead tr {
  background: #1a237e;
  color: #fff;
}
[data-theme="dark"] .notify-table thead tr { background: #0d1442; }
.notify-table tbody tr:hover { background: var(--bg-hover); }
.notify-table tbody tr.odd { background: var(--bg-table-odd); }
.notify-table tbody tr.odd:hover { background: var(--bg-hover); }

/* もっと見るボタン */
.btn-more {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.4rem 1rem;
  background: var(--btn-more-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.btn-more:hover { background: var(--accent-light); }

/* ---- エラーメッセージ ---- */
.error-message { color: #c62828; text-align: center; padding: 2rem; }

/* ---- ローディング ---- */
.loading { text-align: center; padding: 2rem; color: var(--text-secondary); }

/* ---- フッター ---- */
footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-top: 1rem;
}

/* ---- レスポンシブ: 768px ---- */
@media (max-width: 768px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-banner { gap: 0.75rem; padding: 0.75rem 1rem; }
  .summary-card { max-width: none; min-width: 120px; }
}

/* ---- レスポンシブ: 600px ---- */
@media (max-width: 600px) {
  header h1 { font-size: 1.1rem; }
  .card-grid { grid-template-columns: 1fr; }
  .summary-card { max-width: none; min-width: 100px; }
  .date-picker-row { flex-wrap: wrap; }
}
