/* ====================================
   PWA パフォーマンス改善用CSS
   - ローディングインジケーター
   - タップフィードバック
   - アニメーション最適化
   ==================================== */

/* ===== グローバルローディングインジケーター ===== */
/* ページ遷移時に表示される全画面ローディング */
.pwa-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.pwa-loading-overlay.active {
    display: flex;
    opacity: 1;
    animation: pwa-fadeIn 0.3s ease-in-out;
}

/* シンプルでモダンなローディングスピナー */
.pwa-spinner-container {
    position: relative;
    width: 60px;
    height: 60px;
}

.pwa-spinner {
    width: 60px;
    height: 60px;
    position: relative;
}

/* シンプルな単一円のスピナー */
.pwa-spinner::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #ffffff;
    animation: pwa-simple-spin 1s linear infinite;
    will-change: transform;
}

/* 内側のドット */
.pwa-spinner::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: pwa-dot-pulse 1.5s ease-in-out infinite;
}

@keyframes pwa-simple-spin {
    0% { 
        transform: rotate(0deg);
    }
    100% { 
        transform: rotate(360deg);
    }
}

@keyframes pwa-dot-pulse {
    0%, 100% { 
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    50% { 
        opacity: 0.3;
        transform: translate(-50%, -50%) scale(1.3);
    }
}

/* ローディングテキスト */
.pwa-loading-text {
    margin-top: 20px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
    letter-spacing: 0.5px;
    animation: pwa-text-fade 1.5s ease-in-out infinite;
}

@keyframes pwa-text-fade {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* PWA クローズボタン */
.pwa-close-button {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(62, 58, 57, 0.1);
    color: #3e3a39;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: 1px solid rgba(62, 58, 57, 0.2);
    z-index: 10000;
}

.pwa-close-button:hover {
    background: rgba(62, 58, 57, 0.2);
    transform: scale(1.1);
}

.pwa-close-button:active {
    transform: scale(0.95);
    background: rgba(62, 58, 57, 0.3);
}

/* タイムアウト警告メッセージ */
.pwa-loading-timeout-warning {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.9);
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: 80%;
    min-width: 300px;
}

.pwa-loading-timeout-warning.show {
    opacity: 1;
    animation: pwa-shake 0.5s ease;
}

.pwa-timeout-message {
    margin-bottom: 12px;
    line-height: 1.4;
}

/* 手動更新ボタン */
.pwa-refresh-button {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-weight: 500;
}

.pwa-refresh-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
}

.pwa-refresh-button:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.4);
}

@keyframes pwa-shake {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    25% { transform: translateX(-52%) translateY(0); }
    75% { transform: translateX(-48%) translateY(0); }
}

/* ミニローディングインジケーター（ボタン内用） */
.pwa-button-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: pwa-spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

/* タッチ最適化はSneatに任せる - 全て削除 */

/* ===== スケルトンローディング ===== */
/* コンテンツロード中のプレースホルダー */
.pwa-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: pwa-skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes pwa-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.pwa-skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.pwa-skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 16px;
    border-radius: 4px;
}

.pwa-skeleton-card {
    height: 100px;
    margin-bottom: 16px;
    border-radius: 8px;
}

/* ===== スムーススクロール ===== */
/* iOSのモメンタムスクロール有効化 */
.pwa-scrollable {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

/* ===== フェードイン効果 ===== */
/* ページ遷移時のスムーズな表示 */
.pwa-fade-in {
    animation: pwa-fadeIn 0.3s ease-in;
}

@keyframes pwa-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pwa-fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes pwa-scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes pwa-slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pwa-slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ===== プルトゥリフレッシュインジケーター ===== */
.pwa-ptr-container {
    position: relative;
}

.pwa-ptr-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease;
}

.pwa-ptr-pulling {
    transform: translateX(-50%) translateY(60px);
}

/* ===== パフォーマンス最適化 ===== */
/* GPUアクセラレーション強制 */
.pwa-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 画像の遅延読み込み用プレースホルダー */
.pwa-lazy-image {
    background: #f0f0f0;
    min-height: 100px;
}

.pwa-lazy-image.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: pwa-skeleton-loading 1.5s ease-in-out infinite;
}

/* ===== オフライン表示 ===== */
.pwa-offline-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ff5252;
    color: white;
    padding: 12px;
    text-align: center;
    z-index: 9998;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.pwa-offline-banner.show {
    transform: translateY(0);
}

/* d-noneクラスによる確実な非表示（Bootstrap併用） */
.pwa-offline-banner.d-none {
    display: none !important;
}

/* ===== レスポンシブ調整 ===== */
@media (max-width: 768px) {
    /* モバイルでのアニメーション軽量化 */
    * {
        animation-duration: 0.2s !important;
    }
    
    /* スクロールパフォーマンス改善 */
    body {
        scroll-behavior: smooth;
    }
    
    /* モバイル用クローズボタン調整 */
    .pwa-close-button {
        width: 44px;
        height: 44px;
        font-size: 18px;
        top: 16px;
        right: 16px;
    }
    
    /* モバイル用タイムアウト警告調整 */
    .pwa-loading-timeout-warning {
        bottom: 20px;
        left: 10px;
        right: 10px;
        transform: none;
        max-width: none;
        min-width: auto;
        width: calc(100% - 20px);
    }
    
    /* モバイル用手動更新ボタン */
    .pwa-refresh-button {
        padding: 10px 20px;
        font-size: 14px;
        border-radius: 8px;
    }
    
    /* モバイル用ローディング画面位置調整 */
    .pwa-loading-overlay {
        justify-content: flex-start;
        padding-top: 37vh;
    }
}

/* ===== ダークモード対応 ===== */
@media (prefers-color-scheme: dark) {
    .pwa-loading-overlay {
        background: linear-gradient(135deg, 
            rgba(17, 24, 39, 0.88) 0%, 
            rgba(31, 41, 55, 0.88) 50%, 
            rgba(17, 24, 39, 0.88) 100%);
    }
    
    .pwa-spinner::before {
        border: 3px solid rgba(255, 255, 255, 0.1);
        border-top-color: #60a5fa;
    }
    
    .pwa-spinner::after {
        background: rgba(96, 165, 250, 0.8);
    }
    
    .pwa-loading-text {
        color: rgba(255, 255, 255, 0.9);
    }
    
    .pwa-skeleton {
        background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    }
}