/**
 * 커스텀 드롭다운 디자인
 * - 네이티브 select를 완전히 감싸는 래퍼 방식
 * - 기존 기능 코드에 영향 없이 시각적으로만 개선
 * - AR 모달 및 모든 기능 유지
 */

/* ============================================
   1. 커스텀 드롭다운 컨테이너
   ============================================ */
.custom-dropdown-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    z-index: 1;
}

/* 열렸을 때 z-index 최상위로 */
.custom-dropdown-wrapper.open {
    z-index: 99999;
    overflow: visible !important;
}

/* 드롭다운이 잘리지 않도록 부모 요소들 overflow 해제 */
.form-group:has(.custom-dropdown-wrapper.open) {
    overflow: visible !important;
}

.content-section:has(.custom-dropdown-wrapper.open) {
    overflow: visible !important;
}

/* :has() 미지원 브라우저를 위한 fallback */
#add-edit-exhibition-view .content-section,
#add-edit-artwork-view .content-section,
#add-edit-user-view .content-section,
#add-edit-client-view .content-section {
    overflow: visible !important;
}

/* 원본 select를 완전히 숨김 (커스텀 UI만 사용) */
.custom-dropdown-wrapper select {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: -1;
}

/* ============================================
   2. 커스텀 드롭다운 UI (시각적 요소)
   ============================================ */
.custom-dropdown-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    min-height: 46px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    position: relative;
    z-index: 1;
}

.custom-dropdown-display:hover {
    border-color: var(--primary-color);
    background-color: rgba(109, 152, 134, 0.02);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.custom-dropdown-wrapper select:focus + .custom-dropdown-display {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(109, 152, 134, 0.15);
}

/* ============================================
   3. 선택된 텍스트 표시
   ============================================ */
.custom-dropdown-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary-color);
    font-size: var(--font-size-base);
}

.custom-dropdown-text.placeholder {
    color: var(--text-secondary-color);
    opacity: 0.7;
}

/* ============================================
   4. 화살표 아이콘
   ============================================ */
.custom-dropdown-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 12px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.custom-dropdown-arrow::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--primary-color);
}

/* select가 열려있을 때 (focus) 화살표 회전 */
.custom-dropdown-wrapper select:focus + .custom-dropdown-display .custom-dropdown-arrow,
.custom-dropdown-wrapper.open .custom-dropdown-display .custom-dropdown-arrow {
    transform: rotate(180deg);
}

/* ============================================
   5. 커스텀 옵션 리스트 (완전 커스텀)
   ============================================ */

/* 커스텀 옵션 리스트 컨테이너 */
.custom-dropdown-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--surface-color);
    border: 1px solid var(--primary-color);
    border-top: none;
    border-bottom-left-radius: var(--border-radius-md);
    border-bottom-right-radius: var(--border-radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 99999;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-25px) scaleY(0.5);
    transform-origin: top center;
    transition: visibility 0s linear 0.35s,
                max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(10px);
}

/* 드롭다운 열렸을 때 - 주르륵 내려오는 애니메이션 */
.custom-dropdown-wrapper.open .custom-dropdown-options {
    visibility: visible;
    max-height: 350px;
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0) scaleY(1);
    transition: visibility 0s,
                max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 옵션 열렸을 때 display 스타일 변경 */
.custom-dropdown-wrapper.open .custom-dropdown-display {
    border-color: var(--primary-color);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 0 0 3px rgba(109, 152, 134, 0.15);
}

/* 개별 옵션 항목 */
.custom-dropdown-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary-color);
    position: relative;
    overflow: hidden;
}

/* 옵션 순차 애니메이션 */
.custom-dropdown-wrapper.open .custom-dropdown-option {
    animation: slideInOption 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(1) { animation-delay: 0.02s; }
.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(2) { animation-delay: 0.04s; }
.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(3) { animation-delay: 0.06s; }
.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(4) { animation-delay: 0.08s; }
.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(5) { animation-delay: 0.10s; }
.custom-dropdown-wrapper.open .custom-dropdown-option:nth-child(n+6) { animation-delay: 0.12s; }

@keyframes slideInOption {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 옵션 호버 */
.custom-dropdown-option:hover {
    background-color: rgba(109, 152, 134, 0.08);
    padding-left: 24px;
    color: var(--primary-dark);
}

/* 왼쪽 그라디언트 바 */
.custom-dropdown-option::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: linear-gradient(90deg, var(--primary-color), transparent);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-dropdown-option:hover::before {
    width: 4px;
}

/* 선택된 옵션 */
.custom-dropdown-option.selected {
    background-color: rgba(109, 152, 134, 0.12);
    color: var(--primary-dark);
    font-weight: var(--font-weight-medium);
}

/* 체크마크 아이콘 */
.custom-dropdown-option.selected::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--primary-color);
    font-size: 16px;
    font-weight: bold;
    animation: checkmarkPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes checkmarkPop {
    0% {
        transform: scale(0) rotate(-45deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* 비활성화된 옵션 */
.custom-dropdown-option[data-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* 옵션 구분선 */
.custom-dropdown-option + .custom-dropdown-option {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* 빈 옵션 숨기기 */
.custom-dropdown-option[data-value=""] {
    display: none;
}

/* 스크롤바 커스텀 */
.custom-dropdown-options::-webkit-scrollbar {
    width: 6px;
}

.custom-dropdown-options::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.custom-dropdown-options::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.custom-dropdown-options::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ============================================
   6. 작은 크기 변형 (modern-select용)
   ============================================ */
.custom-dropdown-wrapper.small .custom-dropdown-display {
    padding: 8px 14px;
    min-height: 38px;
    font-size: var(--font-size-sm);
}

.custom-dropdown-wrapper.small .custom-dropdown-text {
    font-size: var(--font-size-sm);
}

/* ============================================
   7. 비활성화 상태
   ============================================ */
.custom-dropdown-wrapper select:disabled + .custom-dropdown-display {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: rgba(0, 0, 0, 0.05);
}

/* ============================================
   8. 애니메이션 효과
   ============================================ */

/* 드롭다운 열릴 때 살짝 튕기는 효과 */
@keyframes dropdownBounce {
    0% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-2px);
    }
    100% {
        transform: translateY(0);
    }
}

.custom-dropdown-wrapper select:focus + .custom-dropdown-display {
    animation: dropdownBounce 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 텍스트 변경 시 페이드 효과 */
.custom-dropdown-text.changing {
    animation: textFade 0.3s ease-in-out;
}

@keyframes textFade {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

/* ============================================
   9. 반응형
   ============================================ */
@media (max-width: 768px) {
    .custom-dropdown-display {
        padding: 10px 14px;
        min-height: 42px;
    }
    
    .custom-dropdown-text {
        font-size: var(--font-size-sm);
    }
}

/* ============================================
   10. 접근성
   ============================================ */

/* 키보드 네비게이션 시 포커스 표시 강화 */
.custom-dropdown-wrapper select:focus-visible + .custom-dropdown-display {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ============================================
   11. 성능 최적화
   ============================================ */
.custom-dropdown-wrapper,
.custom-dropdown-display,
.custom-dropdown-arrow {
    will-change: transform;
}


