/* Selection Modal CSS */

/* 背景スクロール防止 */
body.modal-no-scroll {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    overflow: hidden;
}

/* モーダルオーバーレイ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow: hidden; /* オーバーレイ自体のスクロール防止 */
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* モーダルコンテナ */
.modal-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 95vw;
    max-height: 100vh;
    min-height: 50vh;
    width: 1200px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    overflow: hidden; /* コンテナのオーバーフロー制御 */
}

.modal-overlay.show .modal-container {
    transform: scale(1);
}

/* モーダルヘッダー */
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.modal-close-btn:hover {
    color: #374151;
    background-color: #f3f4f6;
}

.modal-close-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* モーダルボディ（スクロール可能エリア） */
.modal-body {
    padding: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    max-height: calc(90vh - 140px); /* ヘッダーとフッターの高さを引く */
    /* モバイルでのスクロール最適化 */
    -webkit-overflow-scrolling: touch;
    text-align: left;
}

/* 検索エリア */
.modal-search {
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    padding-bottom: 10px;
    border-bottom: 1px solid #f3f4f6;
}

.modal-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-search-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 検索結果なしメッセージ */
.modal-no-results {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
    font-size: 16px;
}

/* カテゴリリスト */
.modal-categories {
    list-style: none;
    padding: 0;
    margin: 0;
}

.modal-category {
    margin-bottom: 8px;
}

.modal-category:last-child {
    margin-bottom: 0;
}

.modal-category-name {
    font-weight: 600;
    font-size: 16px;
    color: #1f2937;
    margin-bottom: 8px;
    display: block;
}

/* アイテムグリッド */
.modal-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-content: flex-start;
    align-items: flex-start;
}

.modal-item {
    margin-bottom: 5px;
}

.modal-item .radio-btn {
    visibility: hidden;
}

.modal-item .radio-label {
    text-align: left;
}

.modal-item-input {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.modal-item-label {
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    transition: color 0.2s ease;
    user-select: none;
    line-height: 1.4;
}

.modal-item-label:hover {
    color: #1f2937;
}

/* ラジオボタンのカスタムスタイル */
.modal-item-input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: 2px solid #d1d5db;
    border-radius: 50%;
    background-color: white;
    position: relative;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.modal-item-input[type="radio"]:checked {
    border-color: #3b82f6;
    background-color: #3b82f6;
}

.modal-item-input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background-color: white;
    border-radius: 50%;
}

.modal-item-input[type="radio"]:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* モーダルフッター */
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.modal-footer-btn {
    padding: 8px 16px;
    background-color: #6b7280;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modal-footer-btn:hover {
    background-color: #4b5563;
}

.modal-footer-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* レスポンシブ対応 */
@media (max-width: 1024px) {
    .modal-container {
        width: 90vw;
        height: 80vh;
        min-height: 60vh;
    }

    .modal-body {
        max-height: calc(80vh - 140px);
    }

    .modal-item {
        min-width: 100px;
        max-width: 250px;
    }
}

@media (max-width: 768px) {
    .modal-container {
        width: 95vw;
        max-width: none;
        margin: 20px;
        height: 75vh;
        min-height: 50vh;
    }

    .modal-body {
        padding: 20px;
        max-height: calc(75vh - 120px);
    }

    .modal-header {
        padding: 16px 20px;
    }

    .modal-footer {
        padding: 12px 20px;
    }

    .modal-items {
        flex-direction: column;
        padding-left: 12px;
    }

    .modal-item {
        min-width: auto;
        max-width: none;
        flex: none;
    }
}

@media (max-width: 480px) {
    .modal-container {
        width: 98vw;
        height: 70vh;
        min-height: 45vh;
        margin: 10px;
    }

    .modal-body {
        padding: 16px;
        max-height: calc(70vh - 100px);
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-footer {
        padding: 10px 16px;
    }
}

/* 縦長画面（高さが十分ある場合）の最適化 */
@media (min-height: 900px) {
    .modal-container {
        height: 90vh;
        min-height: 600px;
    }

    .modal-body {
        max-height: calc(90vh - 120px);
    }
}

/* 横長画面（幅が十分ある場合）の最適化 */
@media (min-width: 1400px) {
    .modal-container {
        width: 1400px;
        height: 95vh;
    }
}

/* 小さな画面での縦向き対応 */
@media (max-height: 600px) {
    .modal-container {
        height: 95vh;
        min-height: 400px;
    }

    .modal-body {
        max-height: calc(95vh - 100px);
        padding: 16px;
    }

    .modal-header {
        padding: 12px 20px;
    }

    .modal-footer {
        padding: 8px 20px;
    }
}

/* タッチデバイス対応 */
@media (hover: none) and (pointer: coarse) {
    .modal-body {
        -webkit-overflow-scrolling: touch;
    }

    /* モバイルでのタッチスクロール最適化 */
    .modal-overlay {
        -webkit-overflow-scrolling: touch;
    }
}

/* iOS Safariでのスクロール問題対応 */
@supports (-webkit-touch-callout: none) {
    .modal-body {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* アニメーション用のキーフレーム */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* アクセシビリティ改善 */
.modal-container:focus {
    outline: none;
}

/* フォーカス可能要素のアウトライン改善 */
.modal-container *:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* スクロールバーのスタイリング（Webkit系ブラウザ） */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Firefox用スクロールバースタイル */
.modal-body {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

/* 高コントラストモード対応 */
@media (prefers-contrast: high) {
    .modal-overlay {
        background-color: rgba(0, 0, 0, 0.8);
    }

    .modal-container {
        border: 2px solid #000;
    }

    .modal-item-input[type="radio"] {
        border-width: 3px;
    }
}

/* 動きの軽減を好むユーザー向け */
@media (prefers-reduced-motion: reduce) {
    .modal-overlay,
    .modal-container,
    .modal-item-input,
    .modal-close-btn,
    .modal-footer-btn {
        transition: none;
    }

    .modal-container {
        transform: none;
    }

    .modal-overlay.show .modal-container {
        transform: none;
    }
}
