/**
 * レスポンシブデザイン強化CSS
 * Bootstrap 5をベースにモバイル体験を最適化
 */

/* ==============================================
   基本設定とタイポグラフィ
   ============================================== */
:root {
  --mobile-padding: 1rem;
  --mobile-margin: 0.75rem;
  --touch-target-size: 44px;
  --mobile-font-size: 0.9rem;
  --desktop-font-size: 1rem;
}

/* モバイル優先の基本スタイル */
body {
  font-size: var(--mobile-font-size);
  line-height: 1.6;
}

@media (min-width: 768px) {
  body {
    font-size: var(--desktop-font-size);
    line-height: 1.5;
  }
}

/* コンテナの余白最適化 */
@media (max-width: 767.98px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
  }

  h2 {
    font-size: 1.3rem;
    margin-bottom: 0.875rem;
  }

  h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }
}

/* ==============================================
   ナビゲーション・ヘッダー最適化
   ============================================== */
.navbar-toggler {
  min-width: var(--touch-target-size);
  min-height: var(--touch-target-size);
  padding: 0.5rem;
  border: 2px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.2);
  border-radius: 0.375rem;
  position: relative;
}

.navbar-toggler:focus {
  box-shadow: none;
  outline: none;
}

/* Bootstrapのデフォルトアイコンを非表示 */
.navbar-toggler-icon {
  display: none !important;
}

/* ハンバーガーアイコン */
.hamburger-icon {
  width: 24px;
  height: 18px;
  position: relative;
  display: inline-block;
  cursor: pointer;
}

.hamburger-icon .line {
  display: block;
  position: absolute;
  height: 2px;
  width: 100%;
  background: #fff;
  border-radius: 2px;
  opacity: 1;
  left: 0;
  transition: all 0.3s ease;
}

.hamburger-icon .line:nth-child(1) {
  top: 0;
}

.hamburger-icon .line:nth-child(2) {
  top: 8px;
}

.hamburger-icon .line:nth-child(3) {
  top: 16px;
}

/* メニューが開いている時のアニメーション */
.navbar-toggler[aria-expanded="true"] .hamburger-icon .line:nth-child(1) {
  top: 8px;
  transform: rotate(45deg);
}

.navbar-toggler[aria-expanded="true"] .hamburger-icon .line:nth-child(2) {
  opacity: 0;
  left: -60px;
}

.navbar-toggler[aria-expanded="true"] .hamburger-icon .line:nth-child(3) {
  top: 8px;
  transform: rotate(-45deg);
}

.btn-close:focus {
  box-shadow: none;
  outline: none;
}

/* オフキャンバスメニューをナビバーの下に表示 */
.offcanvas.offcanvas-end {
  top: 52px;
  height: calc(100% - 52px);
  border-top: 1px solid rgba(0,0,0,0.1);
}

.navbar-brand img {
  max-height: 40px;
  width: auto;
}

@media (max-width: 767.98px) {
  .navbar-brand {
    font-size: 1.1rem;
  }

  .navbar-nav .nav-link {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.1);
  }
}

/* ==============================================
   ボタン・フォーム要素の最適化
   ============================================== */
.btn {
  min-height: var(--touch-target-size);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease-in-out;
}

.btn:active {
  transform: scale(0.98);
}

/* フォーム要素のタッチ最適化 */
.form-control,
.form-select {
  min-height: var(--touch-target-size);
  font-size: 16px; /* iOS zoom防止 */
  border-radius: 0.5rem;
}

@media (max-width: 767.98px) {
  .form-control,
  .form-select {
    padding: 0.75rem;
  }

  .form-group {
    margin-bottom: 1.5rem;
  }
}

/* ==============================================
   テーブル・リストの最適化
   ============================================== */
.table-responsive {
  border: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.125);
  border-radius: 0.5rem;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
  .table {
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .table td,
  .table th {
    padding: 0.5rem 0.4rem;
    vertical-align: middle;
  }

  /* 横スクロール可能なテーブル用の視覚的ヒント */
  .table-responsive::after {
    content: "→";
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(to right, transparent, white 50%);
    padding: 0.5rem 1rem;
    pointer-events: none;
    opacity: 0.7;
    font-size: 1.2rem;
  }

  .table-responsive.scrolled::after {
    display: none;
  }

  /* スマホでのテーブルカード表示 */
  .table-mobile-cards {
    border: none;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards tbody tr {
    display: block;
    background: white;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 1rem;
  }

  .table-mobile-cards tbody td {
    display: block;
    border: none;
    padding: 0.25rem 0;
    text-align: left !important;
  }

  .table-mobile-cards tbody td::before {
    content: attr(data-label) ": ";
    font-weight: bold;
    color: var(--bs-primary);
  }

  /* リンクのタップ領域拡大 */
  .table a {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    margin: -0.25rem -0.5rem;
  }
}

/* ==============================================
   オートコンプリート機能
   ============================================== */
.autocomplete-suggestions {
  font-family: inherit;
  font-size: 0.9rem;
}

.autocomplete-item {
  transition: all 0.15s ease-in-out;
}

.autocomplete-item:hover {
  background-color: #f8f9fa !important;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item mark {
  background-color: #fff3cd;
  padding: 0;
  font-weight: 600;
}

.suggestion-name {
  margin-bottom: 0.25rem;
}

.suggestion-meta {
  font-size: 0.8rem;
  opacity: 0.8;
}

@media (max-width: 767.98px) {
  .autocomplete-suggestions {
    font-size: 0.875rem;
    max-height: 250px;
  }

  .autocomplete-item {
    padding: 0.75rem;
  }

  .suggestion-meta {
    font-size: 0.75rem;
  }
}

/* ==============================================
   検索・フィルター機能の最適化
   ============================================== */
.search-container {
  position: relative;
}

.search-input {
  padding-right: 3rem;
}

.search-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--bs-secondary);
  z-index: 10;
}

@media (max-width: 767.98px) {
  .search-container {
    margin-bottom: 1rem;
  }

  .search-input {
    font-size: 16px; /* iOS zoom防止 */
  }
}

/* ==============================================
   カード・コンテンツレイアウト
   ============================================== */
.card {
  border-radius: 0.75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: box-shadow 0.2s ease-in-out;
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@media (max-width: 767.98px) {
  .card {
    margin-bottom: 1rem;
  }

  .card-body {
    padding: 1rem;
  }
}

/* ==============================================
   マップ・地図表示の最適化
   ============================================== */
.map-container {
  position: relative;
  border-radius: 0.5rem;
  overflow: hidden;
}

.leaflet-container {
  font-family: inherit;
}

@media (max-width: 767.98px) {
  .map-container {
    height: 300px;
    margin: 1rem 0;
  }

  .leaflet-control-container {
    font-size: 0.875rem;
  }

  .leaflet-control-zoom {
    transform: scale(1.2);
  }
}

/* ==============================================
   ページネーション・ナビゲーション
   ============================================== */
.pagination {
  justify-content: center;
  flex-wrap: wrap;
}

@media (max-width: 767.98px) {
  .pagination {
    font-size: 0.875rem;
  }

  .page-link {
    min-width: var(--touch-target-size);
    min-height: var(--touch-target-size);
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ==============================================
   パンくずリスト
   ============================================== */
.breadcrumb {
  background: transparent;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

@media (max-width: 767.98px) {
  .breadcrumb {
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 0.75rem;
  }

  .breadcrumb-item {
    display: inline-block;
  }
}

/* ==============================================
   サイドバー・補助コンテンツ
   ============================================== */
@media (max-width: 991.98px) {
  aside#wrap-side {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--bs-border-color);
  }
}

/* ==============================================
   アクセシビリティ向上
   ============================================== */
/* フォーカス表示の改善 */
.btn:focus,
.form-control:focus,
.form-select:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
  outline: none;
}

/* アクティブ要素の視覚的フィードバック */
.btn:active,
.card:active {
  transform: translateY(1px);
}

/* ==============================================
   パフォーマンス最適化
   ============================================== */
/* スムーススクロール */
html {
  scroll-behavior: smooth;
}

/* 画像の最適化 */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* レイジーローディング対応 */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* ==============================================
   ユーティリティクラス
   ============================================== */
.mobile-hidden {
  display: none;
}

@media (min-width: 768px) {
  .mobile-hidden {
    display: block;
  }

  .mobile-only {
    display: none;
  }
}

.text-truncate-mobile {
  @media (max-width: 767.98px) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* タッチ操作の改善 */
.touch-action-manipulation {
  touch-action: manipulation;
}

/* スクロール可能エリアの改善 */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ==============================================
   アニメーション・トランジション
   ============================================== */
@media (prefers-reduced-motion: no-preference) {
  .fade-in {
    animation: fadeIn 0.3s ease-in-out;
  }

  .slide-up {
    animation: slideUp 0.3s ease-out;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* モーション設定を尊重 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}