/* ================================================================
   accident_map — 共通スタイルシート (common.css)
   フォント、コントラスト修正、アクセシビリティ、ローディング、reduced-motion
   ================================================================ */

/* ---- フォント読み込み ---- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700&family=Fira+Code:wght@400;500;600;700&display=swap');

/* ---- CSS変数 ---- */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --accent-red: #e94560;
  --accent-cyan: #7ec8e3;
  --accent-green: #27ae60;
  --text-primary: #eee;
  --text-secondary: #bbb;    /* was #aaa → 5.3:1 contrast on #1a1a2e */
  --text-muted: #999;        /* for decorative/non-essential text only */
  --text-on-dark: #ccc;      /* was #aaa in body text → 4.8:1 */
  --border-color: #0f3460;
  --font-sans: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  --font-mono: 'Fira Code', monospace;
}

/* ---- ベースリセット ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ---- フォーカスリング（アクセシビリティ） ---- */
:focus-visible {
  outline: 3px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* フォーカスリングを非キーボード操作では非表示 */
:focus:not(:focus-visible) {
  outline: none;
}

/* ---- リンク ---- */
a { color: var(--accent-cyan); }
a:hover { text-decoration: underline; }

/* ---- スキップリンク ---- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--accent-cyan);
  color: #111;
  padding: 8px 16px;
  border-radius: 0 0 6px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 10000;
  text-decoration: none;
}
.skip-link:focus {
  top: 0;
}

/* ---- Lucide SVGアイコン共通 ---- */
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: inline-block;
  flex-shrink: 0;
}
.icon-sm { width: 16px; height: 16px; }
.icon-md { width: 20px; height: 20px; }
.icon-lg { width: 24px; height: 24px; }

/* ---- ローディングスピナー ---- */
.loading-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(22,33,62,0.95);
  padding: 18px 28px;
  border-radius: 8px;
  z-index: 2000;
  font-size: 0.85rem;
  color: var(--text-secondary);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* スケルトンプレースホルダー */
.skeleton {
  background: linear-gradient(90deg, #16213e 25%, #1e2d4a 50%, #16213e 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- 空状態 ---- */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 0.88rem;
}
.empty-state .empty-icon {
  font-size: 2rem;
  margin-bottom: 10px;
  display: block;
}
.empty-state p {
  line-height: 1.7;
}

/* ---- エラー状態 ---- */
.error-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--accent-red);
  font-size: 0.85rem;
}
.error-state .btn-retry {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 20px;
  background: var(--bg-tertiary);
  color: var(--accent-cyan);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  min-height: 44px;
}
.error-state .btn-retry:hover {
  background: #1a3a5c;
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-red);
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  animation: toast-in 0.3s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- 数値データ用フォント ---- */
.num, .stat-item .num, .stat-card .num {
  font-family: var(--font-mono);
}

/* ---- ヘッダー共通 ---- */
.common-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}
.breadcrumb { font-size: 0.75rem; color: var(--text-secondary); }
.breadcrumb a { color: var(--accent-cyan); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---- フッター共通 ---- */
.common-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 16px 20px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.8;
}
.common-footer a { color: var(--accent-cyan); text-decoration: none; }

/* ---- Leafletポップアップ上書き ---- */
.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 6px !important;
}
.leaflet-popup-tip { background: var(--bg-secondary) !important; }
.leaflet-popup-content { margin: 10px 14px !important; }

/* ---- prefers-reduced-motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: none; border-top-color: var(--accent-cyan); }
  .skeleton { animation: none; background: #16213e; }
}

/* ---- 共通ヘッダーナビゲーション ---- */
.app-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}
.app-nav a {
  padding: 8px 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-on-dark);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.app-nav a:hover, .app-nav a:focus-visible {
  background: var(--bg-tertiary);
  color: var(--accent-cyan);
}
.app-nav a.active {
  color: var(--accent-cyan);
  font-weight: 600;
  background: rgba(126, 200, 227, 0.08);
}
@media (max-width: 480px) {
  .app-nav a { padding: 8px 8px; font-size: 0.75rem; }
}

/* ---- ヒーローCTA ---- */
.hero-cta {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}
.hero-cta a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 22px;
  min-height: 44px;
  background: var(--accent-cyan);
  color: #111;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.hero-cta a.secondary {
  background: transparent;
  color: var(--accent-cyan);
  border: 1px solid var(--accent-cyan);
}
.hero-cta a:hover { opacity: 0.85; transform: translateY(-1px); }
.hero-cta a:active { transform: translateY(0); }

/* ---- 共通の最低タッチサイズ ---- */
.sort-btn, .tab-btn, button {
  min-height: 44px;
}

/* ---- 値の上下インジケーター ---- */
.diff-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.diff-indicator .arrow {
  width: 12px;
  height: 12px;
  display: inline-block;
}

/* ---- スクリーンリーダー専用テキスト ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
