/* モバイルUI統合修正 - z-index統一管理 */

/* ===== Z-INDEX階層定義 ===== */
:root {
    --z-sidebar: 1000;
    --z-overlay: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-toast: 1060;
}

/* ===== 基本リセット ===== */
* {
    -webkit-tap-highlight-color: transparent;
}

/* ===== サイドバー基本設定 ===== */
.sidebar,
.nyx-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    background-color: #2c3e50;
    color: #ecf0f1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.3s ease;
}

/* ===== モバイル専用設定 ===== */
@media (max-width: 768px) {
    /* サイドバー */
    .sidebar,
    .nyx-sidebar {
        transform: translateX(-100%);
        z-index: var(--z-sidebar);
        pointer-events: auto; /* サイドバー自体はクリック可能 */
    }
    
    /* サイドバー表示時 */
    .sidebar.show,
    .sidebar.active,
    .nyx-sidebar.show,
    .nyx-sidebar.active {
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }
    
    /* オーバーレイ */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: var(--z-overlay);
        pointer-events: auto; /* クリック可能のまま */
    }
    
    /* オーバーレイ表示 */
    body.sidebar-open .sidebar-overlay {
        display: block;
    }
    
    /* メインコンテンツ */
    .main-content,
    .nyx-main {
        margin-left: 0;
        pointer-events: auto;
        opacity: 1;
        filter: none;
        position: relative;
        z-index: calc(var(--z-overlay) + 1); /* オーバーレイより上に */
        transition: none;
    }
    
    /* グレーアウト防止 - bodyのoverflow制御を完全削除 */
    body.sidebar-open {
        /* overflow, position, width, height設定を一切行わない */
    }
    
    /* モバイルメニューボタン */
    .sidebar-toggle-btn,
    .mobile-menu-btn {
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: calc(var(--z-sidebar) + 1);
        width: 44px;
        height: 44px;
        background-color: #667eea;
        border: none;
        border-radius: 0.375rem;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
}

/* ===== デスクトップ設定 ===== */
@media (min-width: 769px) {
    .sidebar,
    .nyx-sidebar {
        transform: translateX(0);
        z-index: 100;
    }
    
    .main-content,
    .nyx-main {
        margin-left: 250px;
    }
    
    .sidebar-toggle-btn,
    .mobile-menu-btn,
    .sidebar-overlay {
        display: none;
    }
}

/* ===== モーダル設定 ===== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
}

.modal {
    position: fixed;
    z-index: var(--z-modal);
}

/* ===== トースト設定 ===== */
.toast-container {
    position: fixed;
    z-index: var(--z-toast);
}

/* ===== インタラクティブ要素の保護強化 ===== */
input,
textarea,
select,
button,
a,
.btn,
.form-control,
.form-select,
.card {
    pointer-events: auto !important;
    z-index: 10;
    position: relative;
    opacity: 1 !important;
}

/* ===== z-index階層管理の強化 ===== */
@media (max-width: 768px) {
    /* サイドバーが開いている時の階層管理 */
    body.sidebar-open {
        /* オーバーレイ（背景）*/
        .sidebar-overlay {
            z-index: var(--z-overlay); /* 1030 */
        }
        
        /* サイドバー本体 */
        .sidebar,
        .nyx-sidebar {
            z-index: calc(var(--z-overlay) + 10); /* 1040 */
        }
        
        /* メニューボタン */
        .sidebar-toggle-btn,
        .mobile-menu-btn {
            z-index: calc(var(--z-overlay) + 20); /* 1050 */
        }
    }
}

/* ===== ドロップダウン ===== */
.dropdown-menu {
    z-index: 1000;
}

/* ===== 不要な!importantを削除した後の優先度調整 ===== */
@media (max-width: 768px) {
    /* 優先度が必要な箇所のみ詳細度を上げる */
    body .sidebar.show,
    body .sidebar.active,
    body .nyx-sidebar.show,
    body .nyx-sidebar.active {
        transform: translateX(0);
    }
    
    body.sidebar-open .sidebar-overlay {
        display: block;
    }
}