/* ===================================
   BackupManagerUI - バックアップ管理UI用CSS
   モーダル重複を解消してSafariスクロール問題を修正
   Safari検索バー動的調整対応
   =================================== */

/* モーダル表示時のbody制御強化 */
body.modal-open {
    overflow: hidden !important;
    /* JavaScript側での強制的な制御を削除したため、CSS側で最小限の制御のみ */
}

/* バックアップモーダル - Safari専用の構造に修正 */
.backup-modal {
    position: fixed;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important; /* フルスクリーン高さ */
    height: -webkit-fill-available !important; /* Safari専用の高さ */
    max-height: none; /* 高さ制限を削除 */
    min-height: fit-content; /* コンテンツに合わせる */
    background: #f8f9fa; /* 締め作業と同じ背景色 */
    overflow: hidden; /* モーダル自体はスクロールしない */
    margin: 0 !important;
    padding: 0 !important;
    animation: modalSlideIn 0.3s ease-out;
    z-index: 99999 !important; /* より高い値に設定 */
    display: flex; /* Flexboxレイアウト */
    flex-direction: column; /* 縦方向のレイアウト */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.backup-modal.show {
    display: flex; /* 表示時はflex */
    opacity: 1;
    visibility: visible;
}

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

.backup-content {
    flex: 1; /* 残りのスペースを全て使用 */
    padding: 24px; /* 締め作業と同じパディング */
    padding-bottom: 100px; /* ブラウザナビゲーションバー分の余白を追加 */
    height: auto; /* 固定高さを削除 */
    min-height: fit-content; /* コンテンツに合わせる */
    overflow-y: auto !important; /* コンテンツエリアでスクロール */
    -webkit-overflow-scrolling: touch !important; /* Safari専用のスムーズスクロール */
    overscroll-behavior: contain !important; /* Safari用のバウンス効果制御 */
    touch-action: pan-y !important; /* 縦スクロールのみ許可 */
    box-sizing: border-box;
}

.modal-header {
    background: white; /* 締め作業と同じヘッダー背景 */
    border-bottom: 1px solid #dee2e6; /* 締め作業と同じボーダー */
    padding: 20px 24px; /* 締め作業と同じパディング */
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* ヘッダーは縮まない */
}

.modal-header h2 {
    margin: 0;
    color: #2d4a3a; /* 締め作業と同じテキスト色 */
    font-size: 24px;
    font-weight: 700;
}

.close-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%; /* 丸い外枠 */
    font-size: 20px;
    color: #6c757d;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: #2d4a3a;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* バックアップ統計 - 締め作業のカードデザインに統一 */
.backup-stats {
    margin-bottom: 24px; /* 締め作業と同じマージン */
    padding: 24px; /* 締め作業と同じパディング */
    background: var(--bg-white); /* 締め作業と同じ背景色 */
    border: 2px solid var(--border-light); /* 締め作業と同じボーダー */
    border-radius: 12px; /* 締め作業と同じ角丸 */
    box-shadow: var(--shadow-soft); /* 締め作業と同じシャドウ */
}

.backup-stats h3 {
    margin: 0 0 16px 0; /* 締め作業と同じマージン */
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    font-size: 18px;
    font-weight: 700; /* 締め作業と同じフォントウェイト */
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr; /* 1列縦並び */
    gap: 12px; /* 項目間のギャップ */
}

.stat-item {
    background: var(--pale-green); /* 締め作業と同じ背景色 */
    padding: 16px; /* 締め作業と同じパディング */
    border-radius: 8px;
    border: 1px solid var(--border-light); /* 締め作業と同じボーダー */
    text-align: center;
    transition: all 0.3s ease; /* 締め作業と同じトランジション */
}

.stat-item:hover {
    border-color: var(--light-green); /* 締め作業と同じホバー色 */
    transform: translateY(-2px); /* 締め作業と同じホバー効果 */
    box-shadow: 0 8px 25px rgba(155, 196, 125, 0.15); /* 締め作業と同じホバーシャドウ */
}

.stat-label {
    font-size: 12px;
    color: var(--text-light); /* 締め作業と同じテキスト色 */
    margin-bottom: 5px;
    font-weight: 500;
}

.stat-value {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
}

/* 手動バックアップ - 締め作業のオプションカードデザインに統一 */
.manual-backup {
    margin-bottom: 24px; /* 締め作業と同じマージン */
    padding: 24px; /* 締め作業と同じパディング */
    background: var(--bg-white); /* 締め作業と同じ背景色 */
    border: 2px solid var(--border-light); /* 締め作業と同じボーダー */
    border-radius: 12px; /* 締め作業と同じ角丸 */
    box-shadow: var(--shadow-soft); /* 締め作業と同じシャドウ */
}

.manual-backup h3 {
    margin: 0 0 16px 0; /* 締め作業と同じマージン */
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    font-size: 18px;
    font-weight: 700; /* 締め作業と同じフォントウェイト */
}

.backup-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; /* 締め作業と同じギャップ */
}

.backup-buttons .btn {
    padding: 12px 24px; /* 締め作業と同じパディング */
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700; /* 締め作業と同じフォントウェイト */
    cursor: pointer;
    transition: all 0.3s ease; /* 締め作業と同じトランジション */
    min-height: 44px; /* 締め作業と同じ最小高さ */
}

.btn-primary {
    background: var(--primary-green); /* 締め作業と同じプライマリ色 */
    color: white;
}

.btn-primary:hover {
    background: var(--text-dark); /* 締め作業と同じホバー色 */
    transform: translateY(-1px); /* 締め作業と同じホバー効果 */
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
    transform: translateY(-1px);
}

.btn-test {
    background: #ffc107;
    color: #212529;
}

.btn-test:hover {
    background: #e0a800;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* バックアップ一覧 - 締め作業のカードデザインに統一 */
.backup-list {
    margin-bottom: 24px; /* 締め作業と同じマージン */
}

.backup-list h3 {
    margin: 0 0 16px 0; /* 締め作業と同じマージン */
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    font-size: 18px;
    font-weight: 700; /* 締め作業と同じフォントウェイト */
}

.backup-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: nowrap;
    justify-content: space-between;
    width: 100%;
    align-items: stretch;
}

.backup-controls .btn {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    font-size: 14px;
    min-height: 44px;
}

.btn-refresh {
    background: var(--primary-green); /* 締め作業と同じプライマリ色 */
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: var(--text-dark); /* 締め作業と同じホバー色 */
    transform: translateY(-1px);
}

.btn-cleanup {
    background: #ef5350; /* 締め作業と同じ危険色 */
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-cleanup:hover {
    background: #d32f2f; /* 締め作業と同じホバー色 */
    transform: translateY(-1px);
}

.backup-items {
    max-height: 300px;
    overflow-y: auto;
    border: 2px solid var(--border-light); /* 締め作業と同じボーダー */
    border-radius: 8px;
    background: var(--bg-white); /* 締め作業と同じ背景色 */
}

.backup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px; /* 締め作業と同じパディング */
    border-bottom: 1px solid var(--border-light); /* 締め作業と同じボーダー */
    background: transparent;
    transition: background-color 0.2s ease;
}

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

.backup-item:hover {
    background: var(--pale-green); /* 締め作業と同じホバー背景 */
}

.backup-item.completed {
    background: rgba(40, 167, 69, 0.05);
}

.backup-item.failed {
    background: rgba(220, 53, 69, 0.05);
}

.backup-item.in_progress {
    background: rgba(23, 162, 184, 0.05);
}

.backup-info {
    flex: 1;
    display: grid;
    grid-template-columns: 2fr 1.5fr 0.8fr 0.8fr 1fr;
    gap: 10px;
    align-items: center;
    text-align: left; /* 左寄せに戻す */
}

.backup-info > * {
    text-align: left; /* 左寄せに戻す */
}

.backup-id {
    font-family: monospace;
    font-size: 12px;
    color: #6c757d;
    word-break: break-all;
}

.backup-time {
    font-size: 13px;
    color: #495057;
}

.backup-type {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
    text-align: center;
    font-weight: 500;
}

.backup-item.completed .backup-type {
    background: #d4edda;
    color: #155724;
}

.backup-item.failed .backup-type {
    background: #f8d7da;
    color: #721c24;
}

.backup-item.in_progress .backup-type {
    background: #d1ecf1;
    color: #0c5460;
}

.backup-size {
    font-size: 12px;
    color: #6c757d;
    text-align: center;
}

.backup-status {
    font-size: 12px;
    font-weight: 500;
}

.backup-actions {
    display: flex;
    gap: 16px; /* 間隔を広げる */
    flex-direction: row; /* 横並びに戻す */
}

.btn-small {
    padding: 12px 20px; /* さらに大きく */
    font-size: 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    min-height: 40px;
    flex: 1; /* 横並びで均等に拡張 */
    font-weight: 500; /* 文字を太くして見やすく */
}

.btn-restore {
    background: #28a745;
    color: white;
}

.btn-restore:hover {
    background: #218838;
}

.btn-delete {
    background: #dc3545;
    color: white;
}

.btn-delete:hover {
    background: #c82333;
}

/* 設定 - 締め作業のカードデザインに統一 */
.backup-settings {
    padding: 24px; /* 締め作業と同じパディング */
    background: var(--bg-white); /* 締め作業と同じ背景色 */
    border: 2px solid var(--border-light); /* 締め作業と同じボーダー */
    border-radius: 12px; /* 締め作業と同じ角丸 */
    box-shadow: var(--shadow-soft); /* 締め作業と同じシャドウ */
    margin-bottom: 4px; /* 下部マージンを最小限に */
    padding-bottom: 120px; /* 下部パディングをさらに大幅に増加 */
}

.backup-settings h3 {
    margin: 0 0 16px 0; /* 締め作業と同じマージン */
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    font-size: 18px;
    font-weight: 700; /* 締め作業と同じフォントウェイト */
}

.settings-grid {
    display: grid;
    gap: 16px; /* 締め作業と同じギャップ */
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 12px; /* 締め作業と同じギャップ */
    margin-bottom: 32px; /* 各設定項目の下の余白をさらに増加 */
}

.setting-item:last-child {
    margin-bottom: 48px; /* 最後の項目により大きな余白を確保 */
}

.setting-item label {
    font-size: 14px;
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    font-weight: 500;
    min-width: 150px;
}

.setting-item input[type="checkbox"] {
    margin-right: 5px;
    accent-color: var(--primary-green); /* 締め作業と同じアクセント色 */
}

.setting-item select {
    padding: 8px 12px;
    border: 2px solid var(--border-light); /* 締め作業と同じボーダー */
    border-radius: 6px;
    font-size: 14px;
    background: white;
    min-width: 120px;
    color: var(--text-dark); /* 締め作業と同じテキスト色 */
    transition: border-color 0.2s ease;
}

.setting-item select:focus {
    outline: none;
    border-color: var(--primary-green); /* 締め作業と同じフォーカス色 */
    box-shadow: 0 0 0 3px rgba(90, 143, 106, 0.1);
}

/* 状態表示 */
.loading {
    text-align: center;
    padding: 20px;
    color: #6c757d;
    font-style: italic;
}

.no-data {
    text-align: center;
    padding: 20px;
    color: #6c757d;
    font-style: italic;
}

.error {
    text-align: center;
    padding: 20px;
    color: #dc3545;
    font-weight: 500;
}

/* iPhone 13/14/15 実機対応 */
@media screen and (max-height: 900px) and (max-width: 400px) {
    .backup-modal {
        height: auto !important; /* 固定高さを削除 */
    }
    
    .backup-content {
        height: auto; /* 固定高さを削除 */
        min-height: fit-content; /* コンテンツに合わせる */
        padding-bottom: 20px; /* 最小限の下部パディング */
    }
    
    .backup-settings {
        margin-bottom: 2px; /* モバイル用の余白を最小限に */
        padding-bottom: 116px; /* モバイル用の下部パディングをさらに大幅に増加 */
    }
    
    .setting-item {
        margin-bottom: 30px; /* モバイル用の設定項目余白をさらに増加 */
    }
    
    .setting-item:last-child {
        margin-bottom: 46px; /* モバイル用の最後の項目により大きな余白を確保 */
    }
}

/* より小さい画面用 */
@media screen and (max-height: 850px) and (max-width: 400px) {
    .backup-modal {
        height: auto !important; /* 固定高さを削除 */
    }
    
    .backup-content {
        height: auto; /* 固定高さを削除 */
        min-height: fit-content; /* コンテンツに合わせる */
        padding-bottom: 20px; /* 最小限の下部パディング */
    }
    
    .backup-settings {
        margin-bottom: 1px; /* より小さい画面用の余白 */
        padding-bottom: 112px; /* より小さい画面用の下部パディングをさらに大幅に増加 */
    }
    
    .setting-item {
        margin-bottom: 28px; /* より小さい画面用の設定項目余白をさらに増加 */
    }
    
    .setting-item:last-child {
        margin-bottom: 44px; /* より小さい画面用の最後の項目により大きな余白を確保 */
    }
}

/* Safari専用の追加修正 */
@supports (-webkit-touch-callout: none) {
    .backup-modal {
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    }
    
    .backup-content {
        max-height: calc(100vh - 80px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}

/* レスポンシブ対応 - Safari検索バー動的調整強化 */
@media (max-width: 768px) {
    .backup-modal {
        height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
        max-height: none;
        overflow: hidden; /* モーダル自体はスクロールしない */
        padding-bottom: 0; /* パディングを削除 */
        display: flex; /* Flexboxレイアウト */
        flex-direction: column; /* 縦方向のレイアウト */
    }
    
    .backup-content {
        flex: 1; /* 残りのスペースを全て使用 */
        padding: 16px; /* モバイル用パディング */
        padding-bottom: 120px; /* モバイル用の下部余白を増加 */
        height: auto; /* 固定高さを削除 */
        min-height: fit-content; /* コンテンツに合わせる */
        overflow-y: auto !important; /* コンテンツエリアでスクロール */
        -webkit-overflow-scrolling: touch !important; /* Safari専用のスムーズスクロール */
        overscroll-behavior: contain !important; /* Safari用のバウンス効果制御 */
        touch-action: pan-y !important; /* 縦スクロールのみ許可 */
        transition: padding-bottom 0.3s ease;
    }
    
    .modal-header {
        padding: 16px 20px; /* モバイル用パディング */
    }
    
    .stats-grid {
        grid-template-columns: 1fr; /* モバイルでも1列縦並び */
    }
    
    .backup-buttons {
        grid-template-columns: 1fr; /* モバイル用ボタンレイアウト */
    }
    
    .backup-info {
        grid-template-columns: 1fr; /* モバイル用情報レイアウト */
        gap: 8px;
    }
    
    .backup-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .backup-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .setting-item label {
        min-width: auto;
    }
    
    .backup-settings {
        margin-bottom: 0; /* 下部マージンを完全に削除 */
        padding-bottom: 0; /* 下部パディングを削除 */
    }
}

@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr; /* 小画面用グリッド */
    }
    
    .backup-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .backup-controls .btn {
        width: 100%;
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .backup-buttons .btn {
        width: 100%;
    }
    
    .backup-content {
        padding: 12px; /* 小画面用パディング */
        padding-bottom: 20px; /* 最小限の下部パディング */
        height: auto; /* 固定高さを削除 */
        min-height: fit-content; /* コンテンツに合わせる */
    }
}
