/**
 * Select2カスタムスタイル
 * 堺市給排水設備工事管理システム用
 */

/* ===========================================
   Select2基本スタイル
   =========================================== */
.select2-container {
    width: 100% !important;
    max-width: 500px;
}

.select2-container--default .select2-selection--single {
    height: calc(1.5em + 0.5rem + 1px);
    padding: 0.25rem;
    border: 0.5px solid #666;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    background-color: white;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: calc(1.5em + 0.5rem - 1px);
    padding-left: 0;
    padding-right: 20px;
    padding-top: 0;
    padding-bottom: 0;
    color: #333;
    display: flex;
    align-items: center;
    height: 100%;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: calc(1.5em + 0.5rem - 1px);
    right: 1px;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #0056b3 !important;
    outline: 3px solid rgba(0, 86, 179, 0.25) !important;
    outline-offset: 0 !important;
    box-shadow: none !important;
}

/* ===========================================
   ドロップダウンスタイル
   =========================================== */
.select2-dropdown {
    border: 1px solid #666;
    border-radius: 0.25rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.select2-container--default .select2-search--dropdown {
    padding: 4px;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ccc;
    border-radius: 0.25rem;
    padding: 0.25rem;
    font-size: 0.875rem;
}

.select2-container--default .select2-results__option {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #3E7092 !important;
    color: white !important;
}

.select2-container--default .select2-results__option--highlighted {
    background-color: #3E7092 !important;
    color: white !important;
}

.select2-container--default .select2-results__option:hover {
    background-color: #3E7092 !important;
    color: white !important;
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #e9ecef !important;
    color: #333 !important;
}

.select2-container--default .select2-results__option[aria-selected=true]:hover {
    background-color: #3E7092 !important;
    color: white !important;
}

/* ===========================================
   無効化状態のスタイル
   =========================================== */
.select2-container--default.select2-container--disabled .select2-selection--single {
    background-color: #F2F2F2;
    color: #666;
    cursor: not-allowed;
}

.select2-container--default.select2-container--disabled .select2-selection__arrow {
    display: none;
}

/* ===========================================
   テーブル内のSelect2
   =========================================== */
.meter-table .select2-container,
.attachment-table .select2-container {
    max-width: 100%;
}

.meter-table .select2-container--default .select2-selection--single,
.attachment-table .select2-container--default .select2-selection--single {
    height: auto;
    min-height: 25px;
    padding: 0.125rem;
    font-size: 0.875rem;
}

.meter-table .select2-container--default .select2-selection--single .select2-selection__rendered,
.attachment-table .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.2;
    padding-left: 0;
    padding-right: 15px;
    padding-top: 0;
    padding-bottom: 0;
    display: flex;
    align-items: center;
    height: 100%;
}

.meter-table .select2-container--default .select2-selection--single .select2-selection__arrow,
.attachment-table .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 23px;
    right: 1px;
}

/* テーブル内のクリアボタンの位置調整 */
.meter-table .select2-container--default .select2-selection__clear,
.attachment-table .select2-container--default .select2-selection__clear {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 0;
    line-height: 1;
}

/* ===========================================
   既設メーター表の口径用Select2（表示値を中央揃え）
   ===========================================
   meter-table クラスは「新設/既設/工事用」の複数テーブルに付くため、
   中央揃えは既設メーター表のtbody(#meterExistingTable)配下だけに限定する。
   select2 は元の <select> の直後に .select2-container を兄弟として生成するため、
   隣接兄弟セレクタ(select + .select2-container)で口径のcontainerを狙う。
   幅・高さ・枠線などの見た目は既存の .meter-table ルールに任せ、ここでは中央揃えのみ指定する。 */
#meterExistingTable select.diameter-select + .select2-container--default .select2-selection--single .select2-selection__rendered {
    /* 表示値を中央揃えにする。右の矢印スペースと左右対称にするため左にも同じ余白を設ける */
    padding-left: 15px;
    padding-right: 15px;
    justify-content: center;
    text-align: center;
}

/* 口径表示用のフレックスコンテナ */
.diameter-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.diameter-container span {
    white-space: nowrap;
}

.diameter-unit {
    font-size: 0.875rem;
    color: #333;
    white-space: nowrap;
}

/* ===========================================
   プレースホルダーのスタイル
   =========================================== */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #999;
}

/* ===========================================
   検索結果なしのメッセージ
   =========================================== */
.select2-results__message {
    padding: 0.75rem;
    color: #666;
    font-size: 0.875rem;
    text-align: center;
}

/* ===========================================
   レスポンシブ対応
   =========================================== */
@media (max-width: 768px) {
    .select2-container {
        max-width: 100%;
    }
    
    .select2-dropdown {
        width: 100% !important;
    }
}

/* ===========================================
   フォーカス時のアクセシビリティ
   =========================================== */
.select2-container--default .select2-selection--single:focus {
    outline: 3px solid rgba(0, 86, 179, 0.25) !important;
    outline-offset: 0 !important;
}

/* ===========================================
   クリア機能のスタイル
   =========================================== */
.select2-container--default .select2-selection__clear {
    color: #999;
    cursor: pointer;
    float: right;
    font-weight: bold;
    margin-right: 10px;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
    line-height: 1;
}

.select2-container--default .select2-selection__clear:hover {
    color: #333;
}