/**
 * Tom Select Custom Styles
 * 관리자 페이지를 위한 커스텀 스타일
 */

/* 기본 컨트롤 스타일 */
.ts-control {
    background-color: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 0.625rem 0.75rem;
    min-height: 44px;
    font-size: 14px;
    line-height: 1.5;
    color: #0f172a;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    overflow: hidden;
}

/* 다중 선택은 높이 자동 */
.ts-wrapper.multi .ts-control {
    max-height: none;
    min-height: 44px;
}

.ts-control:hover {
    border-color: #94a3b8;
}

/* 포커스 스타일 */
.ts-control.focus {
    border-color: #111827;
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
    outline: none;
}

/* 드롭다운 스타일 */
.ts-dropdown {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12), 0 4px 12px rgba(15, 23, 42, 0.08);
    background: white;
    margin-top: 4px;
    overflow: hidden;
    z-index: 1000;
    transform-origin: top center;
    will-change: opacity, transform;
}

/* 위로 펼친 드롭다운(ts-init positionDropdown) — 아래로 열릴 때의 4px 간격을 위쪽으로 뒤집는다. */
.ts-dropdown.ts-dropdown--up {
    margin-top: -4px;
    transform-origin: bottom center;
}

.ts-dropdown.ts-dropdown--opening {
    animation: ts-dropdown-fade-in 120ms ease-out both;
}

.ts-dropdown.ts-dropdown--closing {
    display: block !important;
    pointer-events: none;
    animation: ts-dropdown-fade-out 110ms ease-in both;
}

@keyframes ts-dropdown-fade-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ts-dropdown-fade-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ts-dropdown.ts-dropdown--opening,
    .ts-dropdown.ts-dropdown--closing {
        animation: none;
    }
}

/* 옵션 스타일 */
.ts-dropdown .option {
    position: relative;
    padding: 0.75rem 2.5rem 0.75rem 0.875rem;
    color: #334155;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.35;
}

.ts-dropdown .option:hover {
    background-color: #f8fafc;
}

.ts-dropdown .option.active {
    background-color: #eaf6ff;
    color: #0284c7;
}

.ts-dropdown .option.selected {
    background-color: #eaf6ff;
    color: #0284c7;
}

.ts-dropdown .option.selected::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 0.875rem;
    width: 8px;
    height: 4px;
    border-left: 1.5px solid #0ea5e9;
    border-bottom: 1.5px solid #0ea5e9;
    transform: translateY(-65%) rotate(-45deg);
}

/* 옵션 + 인라인 설명 ────────────────────────────
   설명이 있는 옵션은 라벨 아래 보조 텍스트로 두 줄 노출 (풍선 미사용).
   Notion/Linear 류 셀렉터처럼 정보를 항상 보이게 둬서 호버 부담을 0으로. */
.ts-option-with-tooltip {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    min-width: 0;
}

.ts-option-with-tooltip__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    line-height: 1.35;
}

.ts-option-with-tooltip__description {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-desc, #999);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    letter-spacing: -0.01em;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

/* hover/active 시 설명도 한 단계 진해지게 (label 색상 변화에 묻히지 않도록 명시 톤 유지) */
.ts-dropdown .option:hover .ts-option-with-tooltip__description,
.ts-dropdown .option.active .ts-option-with-tooltip__description,
.ts-dropdown .option.selected .ts-option-with-tooltip__description {
    color: var(--text-sub, #666);
}

/* 다크 모드 — surface 위에서도 라벨/설명 위계 유지 */
body.theme-dark .ts-option-with-tooltip__description {
    color: var(--text-desc, #6e8197);
}

body.theme-dark .ts-dropdown .option:hover .ts-option-with-tooltip__description,
body.theme-dark .ts-dropdown .option.active .ts-option-with-tooltip__description,
body.theme-dark .ts-dropdown .option.selected .ts-option-with-tooltip__description {
    color: var(--text-sub, #94a3b8);
}

/* 선택된 아이템 (다중 선택) */
.ts-wrapper.multi .ts-control .item {
    background-color: #6366f1;
    color: white;
    padding: 2px 8px;
    border-radius: 0.25rem;
    margin-right: 4px;
    margin-bottom: 2px;
    display: inline-flex;
    align-items: center;
    font-size: 13px;
}

.ts-wrapper.multi .ts-control .item .remove {
    margin-left: 6px;
    padding: 0;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.7;
}

.ts-wrapper.multi .ts-control .item .remove:hover {
    opacity: 1;
}

/* 비활성화 상태 */
.ts-control.disabled {
    background-color: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.ts-control.disabled .item {
    opacity: 0.5;
}

/* 검색 입력 */
.ts-dropdown .ts-dropdown-content {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 260px;
}

.ts-control input {
    border: none;
    outline: none;
    background: transparent;
    padding: 0;
    margin: 0;
    width: 100%;
    font-size: inherit;
}

/* v2: 단일 선택에서 값이 있을 때 입력을 최소화 (타이핑 중이 아닐 때만) */
.ts-wrapper.single.has-items:not(.input-active) .ts-control input {
    width: 0 !important;
    min-width: 0 !important;
    flex: 0 0 0 !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -10000px !important;
}

/* 단일 선택 모드에서 선택된 아이템 스타일 */
.ts-wrapper.single .ts-control .item {
    background: transparent;
    border: none;
    padding: 0;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    padding-right: 0;
}

/* 컨트롤을 항상 1행 플렉스로 - 줄바꿈 방지 */
.ts-control {
    height: 100%;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    min-width: 0; /* ellipsis 동작 보장 */
}

/* v2: 타이핑 중에는 선택 아이템을 숨겨 UI 겹침/줄바꿈 방지 */
.ts-wrapper.single.has-items.input-active .ts-control .item {
    display: none !important;
}

select[data-ts-searchable="false"] + .ts-wrapper.single.has-items .ts-control > input {
    width: 0 !important;
    min-width: 0 !important;
    flex: 0 0 0 !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -10000px !important;
}

select[data-ts-searchable="false"] + .ts-wrapper.single.has-items.input-active .ts-control .item {
    display: block !important;
}

/* 단일 선택은 높이를 고정합니다. */
.ts-wrapper.single .ts-control {
    height: 44px;
}

/* Focus 해제 후 부드러운 전환 */
.ts-control {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* v2: 선택 후 불필요한 outline 제거 */
.ts-wrapper.single.has-items .ts-control:focus {
    outline: none;
}

/* 단일 선택 화살표 */
.ts-wrapper.single .ts-control:not(.loading)::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 14px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid #94a3b8;
    border-bottom: 1.5px solid #94a3b8;
    transform: translateY(-65%) rotate(45deg);
    transform-origin: 50% 50%;
    transition: transform 0.15s ease, border-color 0.15s ease;
    pointer-events: none;
}

.ts-wrapper.single.dropdown-active .ts-control:not(.loading)::after {
    border-color: #64748b;
    transform: translateY(-35%) rotate(225deg);
}

.ts-wrapper.single .ts-control {
    padding-right: 40px;
    position: relative;
}

/* 지우기 버튼: 벤더 기본값은 hover/focus에만 보여 존재를 모른다 — 선택이 있으면 항상 노출, 화살표(right 14px) 왼쪽에 둔다 */
.ts-wrapper.plugin-clear_button.has-items .ts-control .clear-button {
    opacity: 1;
    right: 34px;
    font-size: 16px;
    color: #94a3b8;
}

.ts-wrapper.plugin-clear_button.has-items .ts-control {
    padding-right: 56px;
}

/* v2: 단일 선택 시 커서 스타일 */
.ts-wrapper.single.has-items .ts-control {
    cursor: pointer;
}

/* 검색 결과 없음 */
.ts-dropdown .no-results {
    padding: 0.75rem;
    color: #6b7280;
    text-align: center;
    font-size: 14px;
}

/* Required 필드 스타일 */
.ts-control[required] {
    border-color: #d1d5db;
}

.ts-control[required].focus {
    border-color: #6366f1;
}

/* 에러 상태 */
.ts-control.error {
    border-color: #ef4444;
}

.ts-control.error.focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* 로딩 상태 */
.ts-control.loading::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #d1d5db;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* 반응형 처리 */
@media (max-width: 640px) {
    .ts-control {
        font-size: 16px; /* iOS 자동 줌 방지 */
    }

    .ts-dropdown .ts-dropdown-content {
        max-height: 250px;
    }
}

/* 다크모드 — 컨트롤 */
body.theme-dark .ts-control {
    background-color: var(--surface-glass, rgba(255, 255, 255, 0.04));
    border-color: var(--border-default, rgba(255, 255, 255, 0.1));
    color: var(--text-main, #fff);
}

body.theme-dark .ts-control:hover {
    border-color: var(--gray-400, #64748B);
}

body.theme-dark .ts-control.focus {
    border-color: var(--border-focus, #3B82F6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

body.theme-dark .ts-control input,
body.theme-dark .ts-control input[type="text"],
body.theme-dark .ts-control input[type="search"] {
    color: var(--text-main, #fff);
    -webkit-text-fill-color: var(--text-main, #fff);
}

body.theme-dark .ts-control input::placeholder {
    color: var(--text-desc, #64748B);
    -webkit-text-fill-color: var(--text-desc, #64748B);
}

body.theme-dark .ts-wrapper.single .ts-control .item {
    color: var(--text-main, #fff);
}

body.theme-dark .ts-wrapper.single .ts-control:not(.loading)::after {
    border-right-color: var(--text-sub, #94A3B8);
    border-bottom-color: var(--text-sub, #94A3B8);
}

/* 다크모드 — 다중 선택 아이템 */
body.theme-dark .ts-wrapper.multi .ts-control .item {
    background-color: var(--surface-3, #2A2A2E);
    color: var(--text-main, #fff);
    border-color: var(--border-default, rgba(255, 255, 255, 0.1));
}

body.theme-dark .ts-wrapper.multi .ts-control .item .remove {
    color: var(--text-sub, #94A3B8);
}

body.theme-dark .ts-wrapper.multi .ts-control .item .remove:hover {
    color: var(--text-main, #fff);
}

/* 다크모드 — 드롭다운 */
body.theme-dark .ts-dropdown {
    background-color: var(--surface-2, #1e1e1e);
    border-color: var(--border-default, rgba(255, 255, 255, 0.1));
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

body.theme-dark .ts-dropdown .option {
    color: var(--text-main, #fff);
}

body.theme-dark .ts-dropdown .option:hover {
    background-color: var(--surface-glass-hover, rgba(255, 255, 255, 0.08));
}

body.theme-dark .ts-dropdown .option.active,
body.theme-dark .ts-dropdown .option.selected {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93C5FD;
}

body.theme-dark .ts-dropdown .no-results {
    color: var(--text-desc, #64748B);
}

body.theme-dark .ts-dropdown .optgroup-header {
    color: var(--text-desc, #64748B);
    background-color: var(--surface-1, #18181B);
}

/* 다크모드 — 비활성 */
body.theme-dark .ts-control.disabled,
body.theme-dark .ts-wrapper.disabled .ts-control {
    background-color: var(--surface-1, #18181B);
    color: var(--text-desc, #64748B);
    opacity: 0.6;
}

/* 다크모드 — 로딩 */
body.theme-dark .ts-control.loading::after {
    border-color: var(--border-default, rgba(255, 255, 255, 0.1));
    border-top-color: var(--border-focus, #3B82F6);
}

/* 관리자 페이지 특별 스타일 */
.admin-layout .ts-control {
    border-radius: 4px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.admin-layout .ts-control.focus {
    border-color: #5b21b6;
    box-shadow: 0 0 0 3px rgba(91, 33, 182, 0.1);
}

.admin-layout .ts-dropdown .option.active {
    background-color: #5b21b6;
}

/* 관리자 페이지 다크모드 */
body.theme-dark .admin-layout .ts-control.focus {
    border-color: var(--border-focus, #3B82F6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

body.theme-dark .admin-layout .ts-dropdown .option.active {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93C5FD;
}

/* form-control 클래스와 호환 */
.ts-wrapper.form-control {
    display: block;
}

.ts-wrapper.form-control .ts-control {
    height: 100%;
    max-height: inherit;
    min-height: 100%;
    width: 100%;
}

/* 인라인 폼 스타일 */
.form-inline .ts-control {
    display: inline-block;
    width: auto;
    vertical-align: middle;
}

/* 그룹 스타일 (장르, 지역 등) */
/* .select-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
} */

.select-group .ts-wrapper {
    flex: 1;
    min-width: 150px;
}
