/* ============================================================================
 * regional-stats.css - MAPRISE 地域統計ヒートマップ機能 スタイル
 *   役割: サイドバーUI + 右ランキングパネル + フロート凡例 + タイムライン
 *   全クラス rstat- プレフィックス (鉄則116-A 自己完結 + CSS 衝突回避)
 *   設計: REGIONALSTATS-UI-001 指示書 §12 確定版 + UIモック v3 由来
 *   作成: 2026-05-26
 * ========================================================================== */

/* ---- 1. サイドバー サブグループ (foreign-pop と同位置帯、暗色作法準拠) ---- */
/* UX 改善 (UX ダブルチェック後):
 *   - 補助テキスト色 #6f7884 → #9aa3b0 (WCAG AA 4.5:1 確保)
 *   - rocker トグル 38x21 → 36x20 (foreign-pop 既存と統一)
 *   - .rstat-tg / select / .rstat-opt に :focus-visible outline 追加 (キーボード対応)
 *   - .rstat-slider クリック領域 5px → 24px (.rstat-slider-wrap で内包)
 */
.rstat-cat { color: #1FBF8F; }
.rstat-label {
  font-size: 11px; color: #9aa3b0; font-weight: 700; margin: 8px 0 6px;
}
.rstat-hl {
  background: #1c2230; border: 1px solid #262d39;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
}
.rstat-hl-top { display: flex; align-items: center; gap: 9px; }
.rstat-sw {
  width: 13px; height: 13px; border-radius: 3px;
  flex: 0 0 auto; background: #1FBF8F;
}
.rstat-name { font-size: 12px; font-weight: 700; color: #e9ebee; }

/* 親トグル (seismic-master-toggle / fp-toggle 互換の rocker switch、寸法統一) */
.rstat-tg {
  width: 36px; height: 20px; border-radius: 11px;
  background: #3a3d4a; position: relative; flex: 0 0 auto;
  margin-left: auto; cursor: pointer; transition: background .18s;
  outline: none;
}
.rstat-tg::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #e8eaed; transition: left .18s;
}
.rstat-tg.rstat-on { background: #1FBF8F; }
.rstat-tg.rstat-on::after { left: 18px; }
.rstat-tg:focus-visible {
  box-shadow: 0 0 0 2px #0e1116, 0 0 0 4px #1FBF8F;
}

.rstat-ds {
  font-size: 10.5px; color: #9aa3b0;
  margin-top: 8px; line-height: 1.5;
}
.rstat-ds b { color: #c7ccd3; font-weight: 700; letter-spacing: .5px; }

/* 選択フィールド (カテゴリ・品目セレクタ) */
.rstat-field { margin: 9px 0; }
.rstat-field > label {
  display: block; font-size: 11px; color: #9aa3b0;
  font-weight: 700; margin-bottom: 4px;
}
.rstat-field select {
  width: 100%; font-size: 12.5px; padding: 8px 9px;
  border: 1px solid #262d39; border-radius: 8px;
  background: #10141b; color: #e9ebee;
  cursor: pointer;
  outline-offset: 2px;
}
.rstat-field select:disabled { opacity: .55; cursor: not-allowed; }
.rstat-field select:focus-visible {
  outline: 2px solid #1FBF8F;
  border-color: #1FBF8F;
}

/* セグメントコントロール (値種別・年度) */
.rstat-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.rstat-opt {
  font-size: 11.5px; padding: 6px 11px;
  border-radius: 7px; background: #222b38; color: #c0c8d2;
  border: 1px solid transparent; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  outline: none;
  user-select: none;
}
.rstat-opt:hover { background: #2a3343; color: #e9ebee; }
.rstat-opt:focus-visible {
  outline: 2px solid #1FBF8F;
  outline-offset: 2px;
}
.rstat-opt.rstat-on {
  color: #5fffd0; border-color: #1FBF8F;
  background: rgba(31,191,143,.18);
}

/* 透過度スライダー (クリック領域 24px 確保、内部の bar は 5px のまま) */
.rstat-opa {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: #c0c8d2; margin: 10px 0 4px;
}
.rstat-opa .rstat-pct { margin-left: auto; color: #e9ebee; font-variant-numeric: tabular-nums; }
.rstat-slider {
  /* WCAG 2.5.5: クリック領域は 24px、視覚バーは 5px。padding で吸収 */
  height: 24px;
  position: relative; cursor: pointer;
  display: flex; align-items: center;
  background: transparent;
  outline: none;
}
.rstat-slider::before {
  /* 視覚バー部分 (実 5px) */
  content: ""; display: block; width: 100%; height: 5px;
  background: #2a313d; border-radius: 3px;
}
.rstat-slider .rstat-f {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  height: 5px; width: 100%; background: #1FBF8F; border-radius: 3px;
}
.rstat-slider .rstat-k {
  position: absolute; right: -7px; top: 50%;
  transform: translateY(-50%); width: 14px; height: 14px;
  border-radius: 50%; background: #1FBF8F;
  border: 2px solid #0e1116; pointer-events: none;
}
.rstat-slider:focus-visible {
  box-shadow: 0 0 0 2px #0e1116, 0 0 0 4px #1FBF8F;
  border-radius: 4px;
}

/* カバレッジ注記 (WCAG コントラスト改善) */
.rstat-cov {
  font-size: 10.5px; color: #f5c97a;
  background: rgba(245,158,11,.10);
  border: 1px solid rgba(245,158,11,.35);
  border-radius: 7px; padding: 7px 10px; margin-top: 9px;
  line-height: 1.5;
}

/* 子エリア (トグル OFF 時の disabled 表示) */
.rstat-child-area { transition: opacity .15s; }
.rstat-child-area.rstat-disabled {
  opacity: .45; pointer-events: none;
}

/* ---- 2. 右ランキングパネル (フロート) ---- */
.rstat-rank-panel {
  position: absolute; top: 92px; right: 12px;
  width: 250px; max-height: calc(100% - 110px);
  overflow-y: auto;
  background: rgba(14,17,22,0.94);
  border: 1px solid #262d39; border-radius: 10px;
  padding: 12px 13px; color: #e9ebee;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  z-index: 5; display: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
}
.rstat-rank-panel.rstat-visible { display: block; }
.rstat-rank-title {
  font-size: 12.5px; font-weight: 700; color: #1FBF8F;
  margin-bottom: 8px; letter-spacing: .3px;
}
.rstat-rank-metric {
  font-size: 10.5px; color: #aab2bb; margin-bottom: 10px;
  line-height: 1.4;
}
.rstat-rank-hero {
  background: #1c2230; border: 1px solid #262d39;
  border-radius: 8px; padding: 9px 10px; margin-bottom: 10px;
  text-align: center;
}
.rstat-rank-hero-val { font-size: 22px; font-weight: 800; color: #1FBF8F; }
.rstat-rank-hero-lab { font-size: 10px; color: #6f7884; margin-top: 2px; }

.rstat-rank-section { margin-bottom: 12px; }
.rstat-rank-section-title {
  font-size: 10.5px; font-weight: 700; color: #6f7884;
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: 6px;
}
.rstat-rank-list { list-style: none; padding: 0; margin: 0; }
.rstat-rank-row {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; padding: 4px 0;
}
.rstat-rank-medal {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #0e1116; flex: 0 0 auto;
}
.rstat-rank-medal.rstat-gold   { background: #f5c542; }
.rstat-rank-medal.rstat-silver { background: #cdd0d6; }
.rstat-rank-medal.rstat-bronze { background: #c98a4b; }
.rstat-rank-medal.rstat-bottom { background: #5a6577; color: #e9ebee; }
.rstat-rank-name { flex: 1; color: #e9ebee; }
.rstat-rank-val { color: #aab2bb; font-variant-numeric: tabular-nums; }

.rstat-rank-bar {
  height: 3px; background: #2a313d; border-radius: 2px;
  margin-top: 2px; overflow: hidden;
}
.rstat-rank-bar > div {
  height: 100%; background: #1FBF8F; border-radius: 2px;
}

.rstat-rank-trivia {
  font-size: 10.5px; color: #c7ccd3;
  background: rgba(31,191,143,.06);
  border-left: 2px solid #1FBF8F;
  padding: 7px 9px; margin-top: 8px; line-height: 1.5;
  border-radius: 4px;
}
.rstat-rank-kyushu {
  display: inline-block; font-size: 10px;
  background: rgba(31,191,143,.12); color: #1FBF8F;
  border: 1px solid rgba(31,191,143,.4);
  padding: 2px 7px; border-radius: 9px; margin-top: 6px;
}
.rstat-rank-empty {
  text-align: center; padding: 18px 6px;
  color: #6f7884; font-size: 11px; line-height: 1.55;
}

/* ---- 3. フロート凡例 (#legend0..3 に append) ---- */
.legend-section[data-rstat-injected="1"] .legend-title { color: #1FBF8F; }
.rstat-legend-bar {
  height: 8px; border-radius: 3px;
  background: linear-gradient(to right, #e6f6ee, #b9e4cf, #6bc3a0, #2b9b73, #0e6748);
  margin: 4px 0;
}
.rstat-legend-labels {
  display: flex; justify-content: space-between;
  font-size: 9px; color: #aab2bb;
}

/* ---- 4. タイムライン (年度セグメント) ----
 *   UX 改善 (2026-05-28、v18):
 *     - 旧設計 (max-height:56px + overflow-y:auto) は 21 年度のうち 8 年度のみ可視で
 *       スクロールバーに気づきにくく「注意書きが邪魔で 2013-2025 が見えない」と誤認される。
 *     - 5 列固定 CSS grid に変更し、21 年度を 5 行 × 5 列 (最終行 1) で常時全表示。
 *     - ボタン padding 縮小 + 高さ揃え (min-height) でコンパクト化。
 *     - max-height / overflow-y は撤廃 (鉄則 116-A: 自己完結 + UX 優先)。
 */
.rstat-timeline-wrap {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  /* max-height / overflow-y は撤廃: 全 21 年度を常時全表示 */
}
.rstat-timeline-wrap .rstat-opt {
  font-size: 10.5px;
  padding: 5px 4px;
  text-align: center;
  min-width: 0;  /* grid 内では auto 幅を許容 */
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

/* カバレッジ注記 (視認性改善 v3/Phase4: 10px → 11px、年度ボタンとは色帯で分離) */
.rstat-cov {
  font-size: 11px;
  padding: 7px 9px;
  margin-top: 10px;
  line-height: 1.45;
}

/* 右パネル 出典・注記 (実データ。旧サンプル注記 9.5px → 11.5px に視認性改善、要件4) */
.rstat-rank-note {
  font-size: 11.5px; color: #e0c98f;
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.42);
  border-radius: 7px; padding: 7px 9px; margin-bottom: 10px;
  line-height: 1.5;
}
.rstat-rank-note .rstat-rank-src {
  display: block; margin-top: 3px; font-size: 10.5px; color: #aab2bb;
}

/* ---- 5. ご当地統計 ポップアップ (MapLibre popup リセット + ダークテーマ統一) ---- */
.rstat-popup .maplibregl-popup-content {
  padding: 0;
  background: transparent;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
  border-radius: 10px;
}
/* tip (吹き出し三角) の色を背景に合わせる */
.rstat-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #1c2230; }
.rstat-popup.maplibregl-popup-anchor-top    .maplibregl-popup-tip { border-bottom-color: #1c2230; }
.rstat-popup.maplibregl-popup-anchor-left   .maplibregl-popup-tip { border-right-color:  #1c2230; }
.rstat-popup.maplibregl-popup-anchor-right  .maplibregl-popup-tip { border-left-color:   #1c2230; }
/* 閉じるボタンをダークテーマに合わせる */
.rstat-popup .maplibregl-popup-close-button {
  color: #9aa3b0; font-size: 16px; top: 6px; right: 8px;
  background: none; border: none; cursor: pointer;
  line-height: 1;
}
.rstat-popup .maplibregl-popup-close-button:hover { color: #e9ebee; }

/* ---- 6. レスポンシブ ---- */
@media (max-width: 720px) {
  .rstat-rank-panel { width: 215px; right: 6px; top: 80px; }
  .rstat-rank-hero-val { font-size: 18px; }
  /* モバイルでは 4 列に縮退 (狭幅で 5 列だと文字が窮屈) */
  .rstat-timeline-wrap { grid-template-columns: repeat(4, 1fr); }
}
