/* ========================================
   MyCatLog モバイル専用スタイル
   ======================================== */

/* ========================================
   1. モバイル向け基本設定 (768px以下)
   ======================================== */
@media (max-width: 768px) {
  /* ========================================
     1.1 タッチ操作に適したボタンサイズ
     ======================================== */
  .btn {
    min-height: 44px; /* iOS推奨の最小タッチターゲットサイズ */
    padding: 12px 16px; /* 十分なパディングでタップしやすく */
    font-size: 16px; /* ズームを防ぐための最小フォントサイズ */
  }

  /* ========================================
     1.2 ナビゲーション最適化
     ======================================== */
  .navbar-brand {
    font-size: 1.2rem; /* モバイルに適したブランドサイズ */
  }

  /* ========================================
     1.3 ヘッダーの猫プロフィール写真
     ======================================== */
  .header-cats-container {
    display: flex;
    align-items: center;
    gap: 8px; /* 適度な間隔 */
  }

  .header-cat-profile {
    width: 36px;
    height: 36px;
    border-radius: 50%; /* 円形プロフィール */
    overflow: hidden;
    flex-shrink: 0; /* 縮小を防ぐ */
  }

  .header-cat-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* アスペクト比を保ちながらカバー */
  }

  .header-cat-placeholder {
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
  }

  .header-cats-badge {
    display: flex;
    align-items: center;
  }

  .header-cats-badge .badge {
    font-size: 12px;
    padding: 4px 8px;
  }

  /* ========================================
     1.4 猫詳細画面のモバイル最適化
     ======================================== */
  .cat-detail-header {
    flex-direction: column; /* 縦並びレイアウト */
    align-items: flex-start;
    gap: 12px;
  }

  /* デスクトップでは従来の横並びレイアウト */
  @media (min-width: 768px) {
    .cat-detail-header {
      flex-direction: row;
      align-items: center;
      gap: 0;
    }

    .cat-detail-header .d-flex.flex-column {
      flex-direction: row;
      align-items: center;
    }

    .cat-detail-header .badge {
      margin-left: 12px;
    }
  }

  .cat-detail-buttons {
    display: flex;
    gap: 8px;
    width: 100%; /* 全幅使用 */
  }

  .cat-detail-buttons .btn {
    flex: 1; /* 均等に配置 */
    font-size: 14px;
    padding: 10px 12px;
  }

  /* ========================================
     1.5 基本情報カード
     ======================================== */
  .info-card {
    margin-bottom: 16px;
  }

  .info-card .card-body {
    padding: 16px;
  }

  .info-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
  }

  .info-item:last-child {
    border-bottom: none; /* 最後のアイテムはボーダーなし */
  }

  .info-icon {
    width: 24px;
    margin-right: 12px;
    color: #6c757d;
  }

  .info-label {
    font-weight: 500;
    min-width: 80px; /* ラベルの最小幅を確保 */
    margin-right: 12px;
  }

  .info-value {
    flex: 1; /* 残りのスペースを使用 */
    color: #495057;
  }

  /* ========================================
     1.6 アルバムページのモバイル最適化
     ======================================== */
  .d-flex.justify-content-between.align-items-center {
    flex-direction: column; /* 縦並びに変更 */
    align-items: flex-start;
    gap: 16px;
  }

  .d-flex.justify-content-between.align-items-center > div:last-child {
    display: flex;
    gap: 8px;
    width: 100%; /* 全幅使用 */
  }

  .d-flex.justify-content-between.align-items-center .btn {
    flex: 1; /* 均等に配置 */
    font-size: 14px;
    padding: 10px 12px;
  }

  /* ========================================
     1.7 写真アルバムのモバイル最適化
     ======================================== */
  .album-container {
    margin-top: 16px;
  }

  .album-item {
    margin-bottom: 20px;
  }

  .album-date {
    font-size: 14px;
    color: #6c757d;
    margin-bottom: 8px;
  }

  .album-photos {
    display: grid;
    grid-template-columns: 1fr; /* 1列表示 */
    gap: 8px;
  }

  .album-photo {
    aspect-ratio: 1; /* 正方形 */
    border-radius: 8px;
    overflow: hidden;
    position: relative;
  }

  .album-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* アスペクト比を保ちながらカバー */
  }

  /* ========================================
     1.8 フォーム入力の最適化
     ======================================== */
  .form-control,
  .form-select {
    min-height: 44px; /* タッチ操作に適したサイズ */
    font-size: 16px; /* ズームを防ぐ */
    padding: 12px;
  }

  .form-label {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
  }

  /* チェックボックスとラジオボタンの最適化 */
  .form-check-input {
    width: 20px;
    height: 20px;
    margin-top: 0;
  }

  .form-check-label {
    font-size: 16px;
    padding-left: 8px;
    line-height: 1.4;
  }

  /* フォームグループの間隔調整 */
  .mb-3 {
    margin-bottom: 1.5rem !important;
  }

  /* アラートの最適化 */
  .alert {
    font-size: 14px;
    padding: 12px;
  }

  /* ボタングループの最適化 */
  .d-grid.gap-2 {
    gap: 12px !important;
  }

  /* 必須項目の表示改善 */
  .form-label.required::after {
    content: " *";
    color: #dc3545;
    font-weight: bold;
    font-size: 18px;
  }

  /* ========================================
     1.9 カードのモバイル最適化
     ======================================== */
  .card {
    border-radius: 12px; /* モダンな角丸 */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .card-body {
    padding: 16px;
  }

  /* ========================================
     1.10 フローティングアクションボタン
     ======================================== */
  .fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: #007bff;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
  }

  .fab:hover {
    background-color: #0056b3;
    transform: scale(1.05);
  }

  /* ========================================
     1.11 スワイプ可能な写真ギャラリー
     ======================================== */
  .swipe-gallery {
    overflow-x: auto;
    scroll-snap-type: x mandatory; /* スナップスクロール */
    -webkit-overflow-scrolling: touch;
  }

  .swipe-gallery-item {
    scroll-snap-align: start;
    flex-shrink: 0;
    width: 100%;
  }

  /* ========================================
     1.12 モバイルでのホバーエフェクト無効化
     ======================================== */
  .cat-card:hover,
  .photo-card:hover {
    transform: none; /* ホバーエフェクトを無効化 */
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
  }

  /* ========================================
     1.13 写真オーバーレイカードのモバイル最適化
     ======================================== */

  /* オーバーレイ全体 */
  .photo-detail-overlay {
    background-color: rgba(0, 0, 0, 0.5); /* 50%透明の背景 */
    z-index: 1050; /* 高いz-indexで最前面に */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
    transition: none !important; /* モバイルではアニメーションを無効化 */
  }

  .photo-detail-overlay.show {
    opacity: 1;
    visibility: visible;
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
    transition: none !important; /* モバイルではアニメーションを無効化 */
  }

  /* オーバーレイカード */
  .photo-detail-card {
    width: 95vw;
    max-width: 800px;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    border-radius: 12px 12px 0 0; /* 上部のみ角丸 */
    background-color: white;
    position: relative;
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
  }

  /* カード本体 */
  .photo-detail-card .card {
    height: 100vh;
    max-height: 100vh;
    border: none;
    border-radius: 12px 12px 0 0;
    background-color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
  }

  /* 写真表示エリア */
  .photo-detail-image-container {
    flex: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background-color: #000; /* 黒背景 */
    height: 70vh; /* 写真エリアの高さを調整 */
    max-height: 70vh;
    border-radius: 12px 12px 0 0; /* 上部の角丸 */
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
  }

  /* 写真画像 */
  .photo-detail-image-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* アスペクト比を保持 */
    transform: none !important; /* タップ時のサイズ変更を完全に無効化 */
  }

  /* ========================================
     1.15 3点メニューの最適化
     ======================================== */
  .photo-actions {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
  }

  /* ========================================
     1.16 オーバーレイ内の全要素のアニメーション無効化
     ======================================== */
  .photo-detail-overlay *,
  .photo-detail-overlay *:active,
  .photo-detail-overlay *:hover,
  .photo-detail-overlay *:focus {
    transform: none !important;
    transition: none !important;
    animation: none !important;
    -webkit-transform: none !important;
    -webkit-transition: none !important;
    -webkit-animation: none !important;
  }

  /* 3点メニューのアニメーションも無効化 */
  .photo-actions {
    transition: none !important;
    -webkit-transition: none !important;
  }

  /* ========================================
     1.17 オーバーレイ内のボタン専用設定
     ======================================== */
  .photo-detail-overlay .btn,
  .photo-detail-overlay .btn:active,
  .photo-detail-overlay .btn:hover,
  .photo-detail-overlay .btn:focus {
    transform: none !important;
    -webkit-transform: none !important;
    pointer-events: auto !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
    cursor: pointer !important;
  }

  .photo-actions .btn {
    background-color: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transform: none !important; /* タップ時のサイズ変更を無効化 */
    pointer-events: auto !important; /* クリックイベントを確実に有効化 */
    user-select: none; /* テキスト選択を無効化 */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .photo-actions .btn:active {
    background-color: rgba(0, 0, 0, 0.9);
    transform: none !important; /* タップ時のサイズ変更を無効化 */
  }

  /* メモエリア内の3点メニュー */
  .custom-overlay-body .photo-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 15; /* メモエリア内で最前面 */
  }

  .custom-overlay-body .photo-actions .btn {
    background-color: rgba(255, 255, 255, 0.9); /* 白背景 */
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    font-size: 14px;
    transform: none !important; /* タップ時のサイズ変更を無効化 */
    pointer-events: auto !important; /* クリックイベントを確実に有効化 */
    user-select: none; /* テキスト選択を無効化 */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .custom-overlay-body .photo-actions .btn:hover {
    background-color: rgba(255, 255, 255, 1);
  }

  .custom-overlay-body .photo-actions .btn:active {
    background-color: rgba(240, 240, 240, 1);
    transform: none !important; /* タップ時のサイズ変更を無効化 */
  }

  /* ========================================
     1.16 メモエリアの最適化
     ======================================== */
  .photo-detail-card .custom-overlay-body {
    background-color: rgba(255, 255, 255, 0.95); /* 半透明白背景 */
    backdrop-filter: blur(10px); /* 背景ブラー効果 */
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
    /* 初期状態は非表示 */
    height: 0;
    min-height: 0;
    opacity: 0;
    transform: translateY(100%); /* 下に隠す */
  }

  /* 折りたたみ状態 */
  .photo-detail-card .custom-overlay-body.collapsed {
    height: 0;
    min-height: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(100%);
  }

  /* 展開状態 */
  .photo-detail-card .custom-overlay-body:not(.collapsed) {
    height: auto;
    min-height: 30vh; /* 最小高さを増加 */
    opacity: 1;
    transform: translateY(0); /* 元の位置に */
  }

  /* ========================================
     1.17 ボタンの表示/非表示切り替え
     ======================================== */
  .photo-actions.hidden {
    opacity: 0;
    pointer-events: none; /* クリックを無効化 */
    transform: scale(0.8); /* 少し小さく */
  }

  .photo-actions:not(.hidden) {
    opacity: 1;
    pointer-events: auto; /* クリックを有効化 */
    transform: scale(1);
  }
}

/* ========================================
   2. 小さい画面向けの追加調整 (576px以下)
   ======================================== */
@media (max-width: 576px) {
  /* ========================================
     2.1 基本レイアウト調整
     ======================================== */
  .container {
    padding-left: 12px;
    padding-right: 12px;
  }

  .btn {
    font-size: 14px;
    padding: 10px 12px;
  }

  .card-body {
    padding: 12px;
  }

  /* ========================================
     2.2 情報表示の調整
     ======================================== */
  .info-item {
    padding: 8px 0;
  }

  .info-label {
    min-width: 70px;
    font-size: 14px;
  }

  .info-value {
    font-size: 14px;
  }

  /* ========================================
     2.3 ナビゲーションのさらなる簡素化
     ======================================== */
  .header-cats-container {
    gap: 4px; /* より狭い間隔 */
  }

  .header-cat-profile {
    width: 32px; /* より小さなプロフィール */
    height: 32px;
  }

  /* ========================================
     2.4 写真アルバムの1列表示
     ======================================== */
  .album-photos {
    grid-template-columns: 1fr; /* 1列表示 */
  }

  .album-photo {
    max-width: 100%;
  }

  /* ========================================
     2.5 写真オーバーレイのさらなる最適化
     ======================================== */

  .photo-actions {
    top: 12px;
    right: 12px;
  }

  .photo-actions .btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
}

/* ========================================
   3. タッチ操作の改善
   ======================================== */
@media (hover: none) and (pointer: coarse) {
  /* ========================================
     3.1 タッチデバイスでのホバーエフェクト無効化
     ======================================== */
  .cat-card:hover,
  .photo-card:hover,
  .btn:hover {
    transform: none; /* ホバーエフェクトを無効化 */
    box-shadow: inherit;
  }

  /* ========================================
     3.2 タッチフィードバック
     ======================================== */
  .btn:active:not(.photo-detail-overlay *),
  .card:active:not(.photo-detail-overlay *) {
    transform: scale(0.98); /* タップ時の軽い縮小効果 */
  }

  /* ========================================
     3.3 オーバーレイ内のボタン専用タッチ設定
     ======================================== */
  .photo-detail-overlay .btn:active {
    transform: none !important;
    -webkit-transform: none !important;
  }
}
